Skip to content

An open-source, faster Devin alternative

TypeScript

Fix SDK WebSocket auth for control plane and browser compatibility

motatoesbe3f360b50ff
diff --git a/sdks/typescript/src/agent.ts b/sdks/typescript/src/agent.ts
index c594e17b..6daf46ee 100644
--- a/sdks/typescript/src/agent.ts
+++ b/sdks/typescript/src/agent.ts
@@ -100,8 +100,12 @@ export class Agent {
const wsUrl = this.apiUrl
.replace("http://", "ws://")
.replace("https://", "wss://");
- const tokenParam = this.token ? `?token=${encodeURIComponent(this.token)}` : "";
- const wsEndpoint = `${wsUrl}/sandboxes/${this.sandboxId}/exec/${sessionId}${tokenParam}`;
+ const authParam = this.token
+ ? `?token=${encodeURIComponent(this.token)}`
+ : this.apiKey
+ ? `?api_key=${encodeURIComponent(this.apiKey)}`
+ : "";
+ const wsEndpoint = `${wsUrl}/sandboxes/${this.sandboxId}/exec/${sessionId}${authParam}`;
const ws = new WebSocket(wsEndpoint);
ws.binaryType = "arraybuffer";
diff --git a/sdks/typescript/src/exec.ts b/sdks/typescript/src/exec.ts
index fa4f59a2..6aedf0de 100644
--- a/sdks/typescript/src/exec.ts
+++ b/sdks/typescript/src/exec.ts
@@ -99,8 +99,14 @@ export class Exec {
const wsUrl = this.apiUrl
.replace("http://", "ws://")
.replace("https://", "wss://");
- const tokenParam = this.token ? `?token=${encodeURIComponent(this.token)}` : "";
- const wsEndpoint = `${wsUrl}/sandboxes/${this.sandboxId}/exec/${sessionId}${tokenParam}`;
+ // WebSocket can't set custom headers, so pass credentials as query params.
+ // Prefer JWT token (direct worker access); fall back to API key (control plane).
+ const authParam = this.token
+ ? `?token=${encodeURIComponent(this.token)}`
+ : this.apiKey
+ ? `?api_key=${encodeURIComponent(this.apiKey)}`
+ : "";
+ const wsEndpoint = `${wsUrl}/sandboxes/${this.sandboxId}/exec/${sessionId}${authParam}`;
const ws = new WebSocket(wsEndpoint);
ws.binaryType = "arraybuffer";
diff --git a/sdks/typescript/src/index.ts b/sdks/typescript/src/index.ts
index 5a6b13a2..62315abd 100644
--- a/sdks/typescript/src/index.ts
+++ b/sdks/typescript/src/index.ts
@@ -3,5 +3,8 @@ export { Agent, type AgentEvent, type AgentConfig, type AgentStartOpts, type Age
export { Filesystem, type EntryInfo } from "./filesystem.js";
export { Exec, type ProcessResult, type RunOpts, type ExecSession, type ExecSessionInfo, type ExecStartOpts, type ExecAttachOpts } from "./exec.js";
export { Pty, type PtySession, type PtyOpts } from "./pty.js";
-export { Image, type ImageManifest, type ImageStep } from "./image.js";
-export { Snapshots, type SnapshotInfo, type CreateSnapshotOpts } from "./snapshot.js";
+// Node.js-only modules (use crypto, fs, path) — import directly if needed:
+// import { Image } from "@opencomputer/sdk/dist/image.js";
+// import { Snapshots } from "@opencomputer/sdk/dist/snapshot.js";
+export type { ImageManifest, ImageStep } from "./image.js";
+export type { SnapshotInfo, CreateSnapshotOpts } from "./snapshot.js";
diff --git a/sdks/typescript/src/pty.ts b/sdks/typescript/src/pty.ts
index 30748c33..e33abb51 100644
--- a/sdks/typescript/src/pty.ts
+++ b/sdks/typescript/src/pty.ts
@@ -50,8 +50,12 @@ export class Pty {
const wsUrl = this.apiUrl
.replace("http://", "ws://")
.replace("https://", "wss://");
- const tokenParam = this.token ? `?token=${encodeURIComponent(this.token)}` : "";
- const wsEndpoint = `${wsUrl}/sandboxes/${this.sandboxId}/pty/${sessionId}${tokenParam}`;
+ const authParam = this.token
+ ? `?token=${encodeURIComponent(this.token)}`
+ : this.apiKey
+ ? `?api_key=${encodeURIComponent(this.apiKey)}`
+ : "";
+ const wsEndpoint = `${wsUrl}/sandboxes/${this.sandboxId}/pty/${sessionId}${authParam}`;
const ws = new WebSocket(wsEndpoint);
ws.binaryType = "arraybuffer";