fix(events): use global WebSocket in Node ESM - #362
Conversation
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
There was a problem hiding this comment.
Thank you for looking into this, TBH I think maybe we could upgrade to Node 24+ and not worry about 22… We had a small discussion on Slack here on upgrading support, though I forgot about it TBH
(my agent will have some explaining to do! why wasn’t it in my morning coffee newsletter?)
e72d616 to
710dfb5
Compare
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
|
Closing in favour of #370, which contains this change and deletes the dead On not worrying about 22: the bump alone doesn't fix this one. |
HUMAN:
Ran the built ESM reproduction on Node 22.22.2 and confirmed the client selected the global
WebSocketconstructor without reporting a missing implementation.Why
The package is emitted as ESM. In Node 22, both WebSocket clients ignore the standards-compatible
globalThis.WebSocket, check the absentwindow.WebSocket, then attempt the unavailablerequire('ws'). Starting either client reports that no WebSocket implementation is available.This follows #157, which stopped ESM package imports from throwing by deferring the missing-WebSocket error until
start(). The built ESM socket path still ignored Node's nativeglobalThis.WebSocket.Summary
globalThis.WebSocketin the conversation and bash event clients.wsfallback for environments where CommonJSrequireis available.Issue Number
Closes OpenHands/software-agent-sdk#4764.
How to Test
The built ESM package can also be checked directly:
node --input-type=module -e "const {WebSocketCallbackClient}=await import('./dist/events/websocket-client.js'); const client=new WebSocketCallbackClient({host:'http://127.0.0.1:9',conversationId:'test',callback:()=>{},onError:console.error}); client.start(); console.log(client.ws?.constructor?.name); client.stop()"On Node 22, this prints
WebSocketinstead of reporting a missing implementation.Video/Screenshots
Not applicable.
Type
Notes
Older Node ESM runtimes without a global WebSocket still follow the existing fallback behavior.