fix(events): use the WebSocket global and drop the ws dependency - #4799
Open
georgeglarson wants to merge 3 commits into
Open
fix(events): use the WebSocket global and drop the ws dependency#4799georgeglarson wants to merge 3 commits into
georgeglarson wants to merge 3 commits into
Conversation
The package is emitted as ESM, and Node 22 provides a standards-compatible
globalThis.WebSocket. The conversation and bash event clients only checked
window.WebSocket, then attempted require('ws'), which is unavailable in
ESM — so starting either client in a Node ESM process reported "WebSocket
implementation not available" even though the global exists.
Every runtime this package supports supplies the global (browsers, and
Node.js since 22.4), so read globalThis.WebSocket directly and drop the ws
dependency. The "no implementation" condition stays deferred to connect()
time and is still surfaced through the existing onError callback, so
importing the package barrel never throws.
Co-authored-by: openhands <openhands@all-hands.dev>
georgeglarson
marked this pull request as ready for review
September 1, 2026 08:43
Collaborator
|
🚦 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. |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
Human verified, Screenshot attached.
AGENT:
Ported from OpenHands/typescript-client#370 (closed unmerged when that repo was archived and the client moved here; the moved files are byte-identical to the pre-fix versions, so the bug crossed repos untouched). Verified end-to-end from
clients/typescript:mainfirst:npm ci && npm run build, then the repro from the linked issue —onErrorreceivesWebSocket implementation not availableon Node 22.22.2 despiteglobalThis.WebSocketexisting.npx jest src/__tests__/package-import.test.ts→ 8 passed, including new cases asserting each client opens the exact expected URL against a fakeglobalThis.WebSocket.npm test→ 311 passed, 18 suites.npm run lint→ 0 errors (and two fewer pre-existinganywarnings in these files).npm run format:check→ clean.npm run build→ clean.Why
The package is emitted as ESM, and Node 22 provides a standards-compatible
globalThis.WebSocket. The conversation and bash event clients only checkedwindow.WebSocket, then attemptedrequire('ws')— which is unavailable in ESM — so starting either client in a Node ESM process reportedWebSocket implementation not availableeven though the global exists. Full repro in the linked issue.Summary
globalThis.WebSocketdirectly in both event clients and drop thewsdependency (every supported runtime supplies the global: browsers, and Node.js since 22.4).connect()time and surfaced via the existingonErrorcallback, so importing the package barrel still never throws.ws, and add coverage pinning the URL each client opens.Issue Number
Fixes #4846.
How to Test
On
mainthis printsONERROR: ... WebSocket implementation not available; on this branch it does not. Thennpm testandnpx jest src/__tests__/package-import.test.ts.Video/Screenshots
Design Doc
N/A — small runtime-detection fix.
Type
Notes
The same change was previously reviewed as OpenHands/typescript-client#370 and went unmerged only because that repository was archived on 2026-08-30 when the client moved into this repo (OpenHands/typescript-client#371). Consumers on Node < 22.4 would lose the
wsfallback, but the package already requires Node 22-era tooling throughout its CI and the global has been unflagged since Node 22.4.