From 8bf8319042fda111ea3b382d93142616f796431b Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Sat, 7 Mar 2026 17:44:24 -0800 Subject: [PATCH] Fix terminal WebSocket ready state checks --- sdks/typescript/src/client.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sdks/typescript/src/client.ts b/sdks/typescript/src/client.ts index e4bbb2d..9db9762 100644 --- a/sdks/typescript/src/client.ts +++ b/sdks/typescript/src/client.ts @@ -681,7 +681,7 @@ export class ProcessTerminalSession { } close(): void { - if (this.socket.readyState === WebSocket.CONNECTING) { + if (this.socket.readyState === WS_READY_STATE_CONNECTING) { this.socket.addEventListener( "open", () => { @@ -692,7 +692,7 @@ export class ProcessTerminalSession { return; } - if (this.socket.readyState === WebSocket.OPEN) { + if (this.socket.readyState === WS_READY_STATE_OPEN) { if (!this.closeSignalSent) { this.closeSignalSent = true; this.sendFrame({ type: "close" }); @@ -701,7 +701,7 @@ export class ProcessTerminalSession { return; } - if (this.socket.readyState !== WebSocket.CLOSED) { + if (this.socket.readyState !== WS_READY_STATE_CLOSED) { this.socket.close(); } } @@ -743,7 +743,7 @@ export class ProcessTerminalSession { } private sendFrame(frame: ProcessTerminalClientFrame): void { - if (this.socket.readyState !== WebSocket.OPEN) { + if (this.socket.readyState !== WS_READY_STATE_OPEN) { return; } @@ -757,6 +757,10 @@ export class ProcessTerminalSession { } } +const WS_READY_STATE_CONNECTING = 0; +const WS_READY_STATE_OPEN = 1; +const WS_READY_STATE_CLOSED = 3; + export class SandboxAgent { private readonly baseUrl: string; private readonly token?: string;