@blaxel/core 0.2.49-dev.211 → 0.2.49-dev.212

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/common/settings.js +2 -2
  3. package/dist/cjs/sandbox/codegen/codegen-ws.js +30 -0
  4. package/dist/cjs/sandbox/filesystem/filesystem-ws.js +106 -0
  5. package/dist/cjs/sandbox/network/network-ws.js +12 -0
  6. package/dist/cjs/sandbox/process/process-ws.js +139 -0
  7. package/dist/cjs/sandbox/sandbox.js +67 -10
  8. package/dist/cjs/sandbox/websocket/client.js +275 -0
  9. package/dist/cjs/sandbox/websocket/index.js +17 -0
  10. package/dist/cjs/types/sandbox/codegen/codegen-ws.d.ts +10 -0
  11. package/dist/cjs/types/sandbox/filesystem/filesystem-ws.d.ts +35 -0
  12. package/dist/cjs/types/sandbox/network/network-ws.d.ts +7 -0
  13. package/dist/cjs/types/sandbox/process/process-ws.d.ts +27 -0
  14. package/dist/cjs/types/sandbox/sandbox.d.ts +12 -6
  15. package/dist/cjs/types/sandbox/types.d.ts +3 -0
  16. package/dist/cjs/types/sandbox/websocket/client.d.ts +49 -0
  17. package/dist/cjs/types/sandbox/websocket/index.d.ts +1 -0
  18. package/dist/cjs-browser/.tsbuildinfo +1 -1
  19. package/dist/cjs-browser/common/settings.js +2 -2
  20. package/dist/cjs-browser/sandbox/codegen/codegen-ws.js +30 -0
  21. package/dist/cjs-browser/sandbox/filesystem/filesystem-ws.js +106 -0
  22. package/dist/cjs-browser/sandbox/network/network-ws.js +12 -0
  23. package/dist/cjs-browser/sandbox/process/process-ws.js +139 -0
  24. package/dist/cjs-browser/sandbox/sandbox.js +67 -10
  25. package/dist/cjs-browser/sandbox/websocket/client.js +275 -0
  26. package/dist/cjs-browser/sandbox/websocket/index.js +17 -0
  27. package/dist/cjs-browser/types/sandbox/codegen/codegen-ws.d.ts +10 -0
  28. package/dist/cjs-browser/types/sandbox/filesystem/filesystem-ws.d.ts +35 -0
  29. package/dist/cjs-browser/types/sandbox/network/network-ws.d.ts +7 -0
  30. package/dist/cjs-browser/types/sandbox/process/process-ws.d.ts +27 -0
  31. package/dist/cjs-browser/types/sandbox/sandbox.d.ts +12 -6
  32. package/dist/cjs-browser/types/sandbox/types.d.ts +3 -0
  33. package/dist/cjs-browser/types/sandbox/websocket/client.d.ts +49 -0
  34. package/dist/cjs-browser/types/sandbox/websocket/index.d.ts +1 -0
  35. package/dist/esm/.tsbuildinfo +1 -1
  36. package/dist/esm/common/settings.js +2 -2
  37. package/dist/esm/sandbox/codegen/codegen-ws.js +26 -0
  38. package/dist/esm/sandbox/filesystem/filesystem-ws.js +102 -0
  39. package/dist/esm/sandbox/network/network-ws.js +8 -0
  40. package/dist/esm/sandbox/process/process-ws.js +135 -0
  41. package/dist/esm/sandbox/sandbox.js +67 -10
  42. package/dist/esm/sandbox/websocket/client.js +271 -0
  43. package/dist/esm/sandbox/websocket/index.js +1 -0
  44. package/dist/esm-browser/.tsbuildinfo +1 -1
  45. package/dist/esm-browser/common/settings.js +2 -2
  46. package/dist/esm-browser/sandbox/codegen/codegen-ws.js +26 -0
  47. package/dist/esm-browser/sandbox/filesystem/filesystem-ws.js +102 -0
  48. package/dist/esm-browser/sandbox/network/network-ws.js +8 -0
  49. package/dist/esm-browser/sandbox/process/process-ws.js +135 -0
  50. package/dist/esm-browser/sandbox/sandbox.js +67 -10
  51. package/dist/esm-browser/sandbox/websocket/client.js +271 -0
  52. package/dist/esm-browser/sandbox/websocket/index.js +1 -0
  53. package/package.json +2 -2
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebSocketClient = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const node_js_1 = require("../../common/node.js");
6
+ class WebSocketClient {
7
+ ws = null;
8
+ WebSocketClass = null;
9
+ url;
10
+ headers;
11
+ reconnect;
12
+ reconnectInterval;
13
+ maxReconnectAttempts;
14
+ reconnectAttempts = 0;
15
+ pendingRequests = new Map();
16
+ streamHandlers = new Map();
17
+ isClosing = false;
18
+ connectionPromise = null;
19
+ heartbeatInterval = null;
20
+ reconnectTimeout = null;
21
+ lastPongReceived = Date.now();
22
+ constructor(options) {
23
+ this.url = options.url;
24
+ this.headers = options.headers || {};
25
+ this.reconnect = options.reconnect ?? true;
26
+ this.reconnectInterval = options.reconnectInterval ?? 5000;
27
+ this.maxReconnectAttempts = options.maxReconnectAttempts ?? 5;
28
+ }
29
+ async connect() {
30
+ if (this.connectionPromise) {
31
+ return this.connectionPromise;
32
+ }
33
+ this.connectionPromise = this.initializeConnection();
34
+ return this.connectionPromise;
35
+ }
36
+ async initializeConnection() {
37
+ return new Promise((resolve, reject) => {
38
+ // Get WebSocket class and connect
39
+ void (async () => {
40
+ try {
41
+ // Get WebSocket class if not already loaded
42
+ if (!this.WebSocketClass) {
43
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
44
+ this.WebSocketClass = await (0, node_js_1.getWebSocket)();
45
+ }
46
+ // Convert http/https URL to ws/wss
47
+ let wsUrl = this.url;
48
+ if (wsUrl.startsWith("http://")) {
49
+ wsUrl = wsUrl.replace("http://", "ws://");
50
+ }
51
+ else if (wsUrl.startsWith("https://")) {
52
+ wsUrl = wsUrl.replace("https://", "wss://");
53
+ }
54
+ // Add /ws endpoint if not present
55
+ if (!wsUrl.endsWith("/ws")) {
56
+ wsUrl = `${wsUrl}/ws`;
57
+ }
58
+ // Create WebSocket with headers (if supported by the environment)
59
+ const wsOptions = {};
60
+ if (Object.keys(this.headers).length > 0) {
61
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
62
+ wsOptions.headers = this.headers;
63
+ }
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
65
+ this.ws = new this.WebSocketClass(wsUrl, wsOptions);
66
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
67
+ this.ws.onopen = () => {
68
+ this.reconnectAttempts = 0;
69
+ this.startHeartbeat();
70
+ resolve();
71
+ };
72
+ this.ws.onmessage = (event) => {
73
+ this.handleMessage(event);
74
+ };
75
+ this.ws.onerror = (error) => {
76
+ console.error("WebSocket error:", error);
77
+ reject(new Error("WebSocket connection error"));
78
+ };
79
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
80
+ this.ws.onclose = () => {
81
+ this.stopHeartbeat();
82
+ this.connectionPromise = null;
83
+ if (!this.isClosing && this.reconnect && this.reconnectAttempts < this.maxReconnectAttempts) {
84
+ this.reconnectAttempts++;
85
+ this.reconnectTimeout = setTimeout(() => {
86
+ this.connect().catch(console.error);
87
+ }, this.reconnectInterval);
88
+ // Allow process to exit even if reconnect timeout is pending
89
+ if (this.reconnectTimeout.unref) {
90
+ this.reconnectTimeout.unref();
91
+ }
92
+ }
93
+ else {
94
+ // Reject all pending requests
95
+ this.pendingRequests.forEach(({ reject }) => {
96
+ reject(new Error("WebSocket connection closed"));
97
+ });
98
+ this.pendingRequests.clear();
99
+ }
100
+ };
101
+ // Handle pong messages for heartbeat
102
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
103
+ if (typeof this.ws.on === 'function') {
104
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
105
+ this.ws.on('pong', () => {
106
+ this.lastPongReceived = Date.now();
107
+ });
108
+ }
109
+ }
110
+ catch (error) {
111
+ reject(error instanceof Error ? error : new Error(String(error)));
112
+ }
113
+ })();
114
+ });
115
+ }
116
+ startHeartbeat() {
117
+ // Send ping every 30 seconds
118
+ this.heartbeatInterval = setInterval(() => {
119
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
120
+ if (this.ws && this.WebSocketClass && this.ws.readyState === this.WebSocketClass.OPEN) {
121
+ // Check if we received a pong recently (within 60 seconds)
122
+ if (Date.now() - this.lastPongReceived > 60000) {
123
+ console.warn("WebSocket heartbeat timeout, closing connection");
124
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
125
+ this.ws.close();
126
+ return;
127
+ }
128
+ // Send ping
129
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
130
+ if (typeof this.ws.ping === 'function') {
131
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
132
+ this.ws.ping();
133
+ }
134
+ }
135
+ }, 30000);
136
+ // Allow process to exit even if heartbeat interval is active
137
+ if (this.heartbeatInterval.unref) {
138
+ this.heartbeatInterval.unref();
139
+ }
140
+ }
141
+ stopHeartbeat() {
142
+ if (this.heartbeatInterval) {
143
+ clearInterval(this.heartbeatInterval);
144
+ this.heartbeatInterval = null;
145
+ }
146
+ }
147
+ handleMessage(event) {
148
+ try {
149
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
150
+ const response = JSON.parse(String(event.data));
151
+ // Check if this is a streaming response
152
+ if (response.stream) {
153
+ const streamHandler = this.streamHandlers.get(response.id);
154
+ if (streamHandler) {
155
+ // Call the data handler with the response data
156
+ streamHandler.onData(response.data);
157
+ // If stream is done, call end handler and clean up
158
+ if (response.done) {
159
+ streamHandler.onEnd();
160
+ this.streamHandlers.delete(response.id);
161
+ }
162
+ }
163
+ return;
164
+ }
165
+ // Regular request-response handling
166
+ const pending = this.pendingRequests.get(response.id);
167
+ if (pending) {
168
+ this.pendingRequests.delete(response.id);
169
+ if (response.success) {
170
+ pending.resolve(response.data);
171
+ }
172
+ else {
173
+ pending.reject(new Error(response.error || "Unknown error"));
174
+ }
175
+ }
176
+ }
177
+ catch (error) {
178
+ console.error("Failed to parse WebSocket message:", error);
179
+ }
180
+ }
181
+ async send(operation, data = {}) {
182
+ // Ensure we're connected
183
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
184
+ if (!this.ws || !this.WebSocketClass || this.ws.readyState !== this.WebSocketClass.OPEN) {
185
+ await this.connect();
186
+ }
187
+ return new Promise((resolve, reject) => {
188
+ const id = (0, uuid_1.v4)();
189
+ const message = {
190
+ id,
191
+ operation,
192
+ data,
193
+ };
194
+ // Store the promise handlers
195
+ this.pendingRequests.set(id, { resolve, reject });
196
+ // Set a timeout for the request (60 seconds)
197
+ setTimeout(() => {
198
+ if (this.pendingRequests.has(id)) {
199
+ this.pendingRequests.delete(id);
200
+ reject(new Error("Request timeout"));
201
+ }
202
+ }, 60000);
203
+ // Send the message
204
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
205
+ if (this.ws && this.WebSocketClass && this.ws.readyState === this.WebSocketClass.OPEN) {
206
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
207
+ this.ws.send(JSON.stringify(message));
208
+ }
209
+ else {
210
+ this.pendingRequests.delete(id);
211
+ reject(new Error("WebSocket not connected"));
212
+ }
213
+ });
214
+ }
215
+ sendStream(operation, data, onData, onEnd) {
216
+ // Ensure we're connected
217
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
218
+ if (!this.ws || !this.WebSocketClass || this.ws.readyState !== this.WebSocketClass.OPEN) {
219
+ throw new Error("WebSocket not connected");
220
+ }
221
+ const id = (0, uuid_1.v4)();
222
+ const message = {
223
+ id,
224
+ operation,
225
+ data,
226
+ };
227
+ // Store the stream handlers
228
+ this.streamHandlers.set(id, { onData, onEnd });
229
+ // Send the message
230
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
231
+ this.ws.send(JSON.stringify(message));
232
+ return id;
233
+ }
234
+ cancelStream(id) {
235
+ this.streamHandlers.delete(id);
236
+ }
237
+ close() {
238
+ this.isClosing = true;
239
+ this.reconnect = false;
240
+ this.stopHeartbeat();
241
+ // Clear reconnect timeout if any
242
+ if (this.reconnectTimeout) {
243
+ clearTimeout(this.reconnectTimeout);
244
+ this.reconnectTimeout = null;
245
+ }
246
+ if (this.ws) {
247
+ // In Node.js (ws package), use terminate() to forcefully close the connection
248
+ // This immediately closes the socket without waiting for the close handshake
249
+ // In browser, terminate() doesn't exist, so we fall back to close()
250
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
251
+ if (typeof this.ws.terminate === 'function') {
252
+ // Node.js ws package - force immediate close
253
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
254
+ this.ws.terminate();
255
+ }
256
+ else {
257
+ // Browser WebSocket - graceful close
258
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
259
+ this.ws.close();
260
+ }
261
+ this.ws = null;
262
+ }
263
+ // Reject all pending requests
264
+ this.pendingRequests.forEach(({ reject }) => {
265
+ reject(new Error("WebSocket client closed"));
266
+ });
267
+ this.pendingRequests.clear();
268
+ this.connectionPromise = null;
269
+ }
270
+ get isConnected() {
271
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
272
+ return this.ws !== null && this.WebSocketClass !== null && this.ws.readyState === this.WebSocketClass.OPEN;
273
+ }
274
+ }
275
+ exports.WebSocketClient = WebSocketClient;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./client.js"), exports);
@@ -0,0 +1,10 @@
1
+ import { Sandbox } from "../../client/types.gen.js";
2
+ import { SandboxAction } from "../action.js";
3
+ import { WebSocketClient } from "../websocket/index.js";
4
+ import { ApplyEditResponse, RerankingResponse } from "../client/types.gen.js";
5
+ export declare class SandboxCodegenWebSocket extends SandboxAction {
6
+ private wsClient;
7
+ constructor(sandbox: Sandbox, wsClient: WebSocketClient);
8
+ fastapply(path: string, codeEdit: string, model?: string): Promise<ApplyEditResponse>;
9
+ reranking(path: string, query: string, scoreThreshold?: number, tokenLimit?: number, filePattern?: string): Promise<RerankingResponse>;
10
+ }
@@ -0,0 +1,35 @@
1
+ import { SandboxAction } from "../action.js";
2
+ import { WebSocketClient } from "../websocket/index.js";
3
+ import { Directory, SuccessResponse } from "../client/index.js";
4
+ import { SandboxProcess } from "../process/index.js";
5
+ import { SandboxProcessWebSocket } from "../process/process-ws.js";
6
+ import { CopyResponse, SandboxFilesystemFile, WatchEvent } from "./types.js";
7
+ import { SandboxConfiguration } from "../types.js";
8
+ export declare class SandboxFileSystemWebSocket extends SandboxAction {
9
+ private process;
10
+ private wsClient;
11
+ private httpClient;
12
+ constructor(sandbox: SandboxConfiguration, process: SandboxProcess | SandboxProcessWebSocket, wsClient: WebSocketClient);
13
+ mkdir(path: string, permissions?: string): Promise<SuccessResponse>;
14
+ write(path: string, content: string): Promise<SuccessResponse>;
15
+ writeBinary(path: string, content: Buffer | Blob | File | Uint8Array | string): Promise<SuccessResponse>;
16
+ writeTree(files: SandboxFilesystemFile[], destinationPath?: string | null): Promise<Directory>;
17
+ read(path: string): Promise<string>;
18
+ readBinary(path: string): Promise<Blob>;
19
+ download(src: string, destinationPath: string, options?: {
20
+ mode?: number;
21
+ }): Promise<void>;
22
+ rm(path: string, recursive?: boolean): Promise<SuccessResponse>;
23
+ ls(path: string): Promise<Directory>;
24
+ cp(source: string, destination: string, { maxWait }?: {
25
+ maxWait?: number;
26
+ }): Promise<CopyResponse>;
27
+ watch(path: string, callback: (fileEvent: WatchEvent) => void | Promise<void>, options?: {
28
+ onError?: (error: Error) => void;
29
+ withContent: boolean;
30
+ ignore?: string[];
31
+ }): {
32
+ close: () => void;
33
+ };
34
+ private formatPath;
35
+ }
@@ -0,0 +1,7 @@
1
+ import { Sandbox } from "../../client/types.gen.js";
2
+ import { SandboxAction } from "../action.js";
3
+ import { WebSocketClient } from "../websocket/index.js";
4
+ export declare class SandboxNetworkWebSocket extends SandboxAction {
5
+ private wsClient;
6
+ constructor(sandbox: Sandbox, wsClient: WebSocketClient);
7
+ }
@@ -0,0 +1,27 @@
1
+ import { Sandbox } from "../../client/types.gen.js";
2
+ import { SandboxAction } from "../action.js";
3
+ import { WebSocketClient } from "../websocket/index.js";
4
+ import { ProcessRequest, ProcessResponse, SuccessResponse } from "../client/index.js";
5
+ import { ProcessRequestWithLog, ProcessResponseWithLog } from "../types.js";
6
+ export declare class SandboxProcessWebSocket extends SandboxAction {
7
+ private wsClient;
8
+ private httpClient;
9
+ constructor(sandbox: Sandbox, wsClient: WebSocketClient);
10
+ streamLogs(identifier: string, options: {
11
+ onLog?: (log: string) => void;
12
+ onStdout?: (stdout: string) => void;
13
+ onStderr?: (stderr: string) => void;
14
+ }): {
15
+ close: () => void;
16
+ };
17
+ exec(process: ProcessRequest | ProcessRequestWithLog): Promise<ProcessResponse | ProcessResponseWithLog>;
18
+ wait(identifier: string, { maxWait, interval }?: {
19
+ maxWait?: number;
20
+ interval?: number;
21
+ }): Promise<ProcessResponse>;
22
+ get(identifier: string): Promise<ProcessResponse>;
23
+ list(): Promise<ProcessResponse[]>;
24
+ stop(identifier: string): Promise<SuccessResponse>;
25
+ kill(identifier: string): Promise<SuccessResponse>;
26
+ logs(identifier: string, type?: "stdout" | "stderr" | "all"): Promise<string>;
27
+ }
@@ -1,19 +1,24 @@
1
1
  import { Sandbox as SandboxModel } from "../client/index.js";
2
2
  import { SandboxFileSystem } from "./filesystem/index.js";
3
+ import { SandboxFileSystemWebSocket } from "./filesystem/filesystem-ws.js";
3
4
  import { SandboxNetwork } from "./network/index.js";
5
+ import { SandboxNetworkWebSocket } from "./network/network-ws.js";
4
6
  import { SandboxPreviews } from "./preview.js";
5
7
  import { SandboxProcess } from "./process/index.js";
8
+ import { SandboxProcessWebSocket } from "./process/process-ws.js";
6
9
  import { SandboxCodegen } from "./codegen/index.js";
10
+ import { SandboxCodegenWebSocket } from "./codegen/codegen-ws.js";
7
11
  import { SandboxSessions } from "./session.js";
8
12
  import { SandboxConfiguration, SandboxCreateConfiguration, SandboxUpdateMetadata, SessionWithToken } from "./types.js";
9
13
  export declare class SandboxInstance {
10
14
  private sandbox;
11
- fs: SandboxFileSystem;
12
- network: SandboxNetwork;
13
- process: SandboxProcess;
15
+ fs: SandboxFileSystem | SandboxFileSystemWebSocket;
16
+ network: SandboxNetwork | SandboxNetworkWebSocket;
17
+ process: SandboxProcess | SandboxProcessWebSocket;
14
18
  previews: SandboxPreviews;
15
19
  sessions: SandboxSessions;
16
- codegen: SandboxCodegen;
20
+ codegen: SandboxCodegen | SandboxCodegenWebSocket;
21
+ private wsClient?;
17
22
  constructor(sandbox: SandboxConfiguration);
18
23
  get metadata(): import("../client/types.gen.js").Metadata | undefined;
19
24
  get status(): string | undefined;
@@ -23,12 +28,13 @@ export declare class SandboxInstance {
23
28
  maxWait?: number;
24
29
  interval?: number;
25
30
  }): Promise<this>;
31
+ closeConnection(): void;
26
32
  static create(sandbox?: SandboxModel | SandboxCreateConfiguration, { safe }?: {
27
33
  safe?: boolean;
28
34
  }): Promise<SandboxInstance>;
29
- static get(sandboxName: string): Promise<SandboxInstance>;
35
+ static get(sandboxName: string, connectionType?: "http" | "websocket"): Promise<SandboxInstance>;
30
36
  static list(): Promise<SandboxInstance[]>;
31
- static delete(sandboxName: string): Promise<SandboxModel>;
37
+ static delete(sandboxName: string, instance?: SandboxInstance): Promise<SandboxModel>;
32
38
  static updateMetadata(sandboxName: string, metadata: SandboxUpdateMetadata): Promise<SandboxInstance>;
33
39
  static createIfNotExists(sandbox: SandboxModel | SandboxCreateConfiguration): Promise<SandboxInstance>;
34
40
  static fromSession(session: SessionWithToken): Promise<SandboxInstance>;
@@ -20,10 +20,12 @@ export interface VolumeBinding {
20
20
  mountPath: string;
21
21
  readOnly?: boolean;
22
22
  }
23
+ export type ConnectionType = "http" | "websocket";
23
24
  export type SandboxConfiguration = {
24
25
  forceUrl?: string;
25
26
  headers?: Record<string, string>;
26
27
  params?: Record<string, string>;
28
+ connectionType?: ConnectionType;
27
29
  } & Sandbox;
28
30
  export type SandboxUpdateMetadata = {
29
31
  labels?: Record<string, string>;
@@ -41,6 +43,7 @@ export type SandboxCreateConfiguration = {
41
43
  region?: string;
42
44
  lifecycle?: SandboxLifecycle;
43
45
  snapshotEnabled?: boolean;
46
+ connectionType?: ConnectionType;
44
47
  };
45
48
  export declare function normalizePorts(ports?: (Port | Record<string, any>)[]): Port[] | undefined;
46
49
  export declare function normalizeEnvs(envs?: EnvVar[]): EnvVar[] | undefined;
@@ -0,0 +1,49 @@
1
+ export interface WebSocketMessage {
2
+ id: string;
3
+ operation: string;
4
+ data: Record<string, any>;
5
+ }
6
+ export interface WebSocketResponse {
7
+ id: string;
8
+ success: boolean;
9
+ data?: any;
10
+ error?: string;
11
+ status?: number;
12
+ stream?: boolean;
13
+ done?: boolean;
14
+ }
15
+ export interface WebSocketClientOptions {
16
+ url: string;
17
+ headers?: Record<string, string>;
18
+ reconnect?: boolean;
19
+ reconnectInterval?: number;
20
+ maxReconnectAttempts?: number;
21
+ }
22
+ export declare class WebSocketClient {
23
+ private ws;
24
+ private WebSocketClass;
25
+ private url;
26
+ private headers;
27
+ private reconnect;
28
+ private reconnectInterval;
29
+ private maxReconnectAttempts;
30
+ private reconnectAttempts;
31
+ private pendingRequests;
32
+ private streamHandlers;
33
+ private isClosing;
34
+ private connectionPromise;
35
+ private heartbeatInterval;
36
+ private reconnectTimeout;
37
+ private lastPongReceived;
38
+ constructor(options: WebSocketClientOptions);
39
+ connect(): Promise<void>;
40
+ private initializeConnection;
41
+ private startHeartbeat;
42
+ private stopHeartbeat;
43
+ private handleMessage;
44
+ send<T = any>(operation: string, data?: Record<string, any>): Promise<T>;
45
+ sendStream(operation: string, data: Record<string, any>, onData: (data: any) => void, onEnd: () => void): string;
46
+ cancelStream(id: string): void;
47
+ close(): void;
48
+ get isConnected(): boolean;
49
+ }
@@ -0,0 +1 @@
1
+ export * from "./client.js";