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

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 +269 -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 +48 -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 +269 -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 +48 -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 +265 -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 +265 -0
  52. package/dist/esm-browser/sandbox/websocket/index.js +1 -0
  53. package/package.json +2 -2
@@ -0,0 +1,269 @@
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
+ const settings_js_1 = require("../../common/settings.js");
7
+ class WebSocketClient {
8
+ ws = null;
9
+ WebSocketClass = null;
10
+ url;
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.reconnect = options.reconnect ?? true;
25
+ this.reconnectInterval = options.reconnectInterval ?? 5000;
26
+ this.maxReconnectAttempts = options.maxReconnectAttempts ?? 5;
27
+ }
28
+ async connect() {
29
+ if (this.connectionPromise) {
30
+ return this.connectionPromise;
31
+ }
32
+ this.connectionPromise = this.initializeConnection();
33
+ return this.connectionPromise;
34
+ }
35
+ async initializeConnection() {
36
+ return new Promise((resolve, reject) => {
37
+ // Get WebSocket class and connect
38
+ void (async () => {
39
+ try {
40
+ // Get WebSocket class if not already loaded
41
+ if (!this.WebSocketClass) {
42
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
43
+ this.WebSocketClass = await (0, node_js_1.getWebSocket)();
44
+ }
45
+ // Convert http/https URL to ws/wss
46
+ let wsUrl = this.url;
47
+ if (wsUrl.startsWith("http://")) {
48
+ wsUrl = wsUrl.replace("http://", "ws://");
49
+ }
50
+ else if (wsUrl.startsWith("https://")) {
51
+ wsUrl = wsUrl.replace("https://", "wss://");
52
+ }
53
+ // Add /ws endpoint if not present
54
+ if (!wsUrl.endsWith("/ws")) {
55
+ wsUrl = `${wsUrl}/ws`;
56
+ }
57
+ wsUrl = `${wsUrl}?token=${settings_js_1.settings.token}`;
58
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
59
+ this.ws = new this.WebSocketClass(wsUrl);
60
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
61
+ this.ws.onopen = () => {
62
+ this.reconnectAttempts = 0;
63
+ this.startHeartbeat();
64
+ resolve();
65
+ };
66
+ this.ws.onmessage = (event) => {
67
+ this.handleMessage(event);
68
+ };
69
+ this.ws.onerror = (error) => {
70
+ console.error("WebSocket error:", error);
71
+ reject(new Error("WebSocket connection error"));
72
+ };
73
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
74
+ this.ws.onclose = () => {
75
+ this.stopHeartbeat();
76
+ this.connectionPromise = null;
77
+ if (!this.isClosing && this.reconnect && this.reconnectAttempts < this.maxReconnectAttempts) {
78
+ this.reconnectAttempts++;
79
+ this.reconnectTimeout = setTimeout(() => {
80
+ this.connect().catch(console.error);
81
+ }, this.reconnectInterval);
82
+ // Allow process to exit even if reconnect timeout is pending
83
+ if (this.reconnectTimeout.unref) {
84
+ this.reconnectTimeout.unref();
85
+ }
86
+ }
87
+ else {
88
+ // Reject all pending requests
89
+ this.pendingRequests.forEach(({ reject }) => {
90
+ reject(new Error("WebSocket connection closed"));
91
+ });
92
+ this.pendingRequests.clear();
93
+ }
94
+ };
95
+ // Handle pong messages for heartbeat
96
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
97
+ if (typeof this.ws.on === 'function') {
98
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
99
+ this.ws.on('pong', () => {
100
+ this.lastPongReceived = Date.now();
101
+ });
102
+ }
103
+ }
104
+ catch (error) {
105
+ reject(error instanceof Error ? error : new Error(String(error)));
106
+ }
107
+ })();
108
+ });
109
+ }
110
+ startHeartbeat() {
111
+ // Send ping every 30 seconds
112
+ this.heartbeatInterval = setInterval(() => {
113
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
114
+ if (this.ws && this.WebSocketClass && this.ws.readyState === this.WebSocketClass.OPEN) {
115
+ // Check if we received a pong recently (within 60 seconds)
116
+ if (Date.now() - this.lastPongReceived > 60000) {
117
+ console.warn("WebSocket heartbeat timeout, closing connection");
118
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
119
+ this.ws.close();
120
+ return;
121
+ }
122
+ // Send ping
123
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
124
+ if (typeof this.ws.ping === 'function') {
125
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
126
+ this.ws.ping();
127
+ }
128
+ }
129
+ }, 30000);
130
+ // Allow process to exit even if heartbeat interval is active
131
+ if (this.heartbeatInterval.unref) {
132
+ this.heartbeatInterval.unref();
133
+ }
134
+ }
135
+ stopHeartbeat() {
136
+ if (this.heartbeatInterval) {
137
+ clearInterval(this.heartbeatInterval);
138
+ this.heartbeatInterval = null;
139
+ }
140
+ }
141
+ handleMessage(event) {
142
+ try {
143
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
144
+ const response = JSON.parse(String(event.data));
145
+ // Check if this is a streaming response
146
+ if (response.stream) {
147
+ const streamHandler = this.streamHandlers.get(response.id);
148
+ if (streamHandler) {
149
+ // Call the data handler with the response data
150
+ streamHandler.onData(response.data);
151
+ // If stream is done, call end handler and clean up
152
+ if (response.done) {
153
+ streamHandler.onEnd();
154
+ this.streamHandlers.delete(response.id);
155
+ }
156
+ }
157
+ return;
158
+ }
159
+ // Regular request-response handling
160
+ const pending = this.pendingRequests.get(response.id);
161
+ if (pending) {
162
+ this.pendingRequests.delete(response.id);
163
+ if (response.success) {
164
+ pending.resolve(response.data);
165
+ }
166
+ else {
167
+ pending.reject(new Error(response.error || "Unknown error"));
168
+ }
169
+ }
170
+ }
171
+ catch (error) {
172
+ console.error("Failed to parse WebSocket message:", error);
173
+ }
174
+ }
175
+ async send(operation, data = {}) {
176
+ // Ensure we're connected
177
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
178
+ if (!this.ws || !this.WebSocketClass || this.ws.readyState !== this.WebSocketClass.OPEN) {
179
+ await this.connect();
180
+ }
181
+ return new Promise((resolve, reject) => {
182
+ const id = (0, uuid_1.v4)();
183
+ const message = {
184
+ id,
185
+ operation,
186
+ data,
187
+ };
188
+ // Store the promise handlers
189
+ this.pendingRequests.set(id, { resolve, reject });
190
+ // Set a timeout for the request (60 seconds)
191
+ setTimeout(() => {
192
+ if (this.pendingRequests.has(id)) {
193
+ this.pendingRequests.delete(id);
194
+ reject(new Error("Request timeout"));
195
+ }
196
+ }, 60000);
197
+ // Send the message
198
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
199
+ if (this.ws && this.WebSocketClass && this.ws.readyState === this.WebSocketClass.OPEN) {
200
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
201
+ this.ws.send(JSON.stringify(message));
202
+ }
203
+ else {
204
+ this.pendingRequests.delete(id);
205
+ reject(new Error("WebSocket not connected"));
206
+ }
207
+ });
208
+ }
209
+ sendStream(operation, data, onData, onEnd) {
210
+ // Ensure we're connected
211
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
212
+ if (!this.ws || !this.WebSocketClass || this.ws.readyState !== this.WebSocketClass.OPEN) {
213
+ throw new Error("WebSocket not connected");
214
+ }
215
+ const id = (0, uuid_1.v4)();
216
+ const message = {
217
+ id,
218
+ operation,
219
+ data,
220
+ };
221
+ // Store the stream handlers
222
+ this.streamHandlers.set(id, { onData, onEnd });
223
+ // Send the message
224
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
225
+ this.ws.send(JSON.stringify(message));
226
+ return id;
227
+ }
228
+ cancelStream(id) {
229
+ this.streamHandlers.delete(id);
230
+ }
231
+ close() {
232
+ this.isClosing = true;
233
+ this.reconnect = false;
234
+ this.stopHeartbeat();
235
+ // Clear reconnect timeout if any
236
+ if (this.reconnectTimeout) {
237
+ clearTimeout(this.reconnectTimeout);
238
+ this.reconnectTimeout = null;
239
+ }
240
+ if (this.ws) {
241
+ // In Node.js (ws package), use terminate() to forcefully close the connection
242
+ // This immediately closes the socket without waiting for the close handshake
243
+ // In browser, terminate() doesn't exist, so we fall back to close()
244
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
245
+ if (typeof this.ws.terminate === 'function') {
246
+ // Node.js ws package - force immediate close
247
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
248
+ this.ws.terminate();
249
+ }
250
+ else {
251
+ // Browser WebSocket - graceful close
252
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
253
+ this.ws.close();
254
+ }
255
+ this.ws = null;
256
+ }
257
+ // Reject all pending requests
258
+ this.pendingRequests.forEach(({ reject }) => {
259
+ reject(new Error("WebSocket client closed"));
260
+ });
261
+ this.pendingRequests.clear();
262
+ this.connectionPromise = null;
263
+ }
264
+ get isConnected() {
265
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
266
+ return this.ws !== null && this.WebSocketClass !== null && this.ws.readyState === this.WebSocketClass.OPEN;
267
+ }
268
+ }
269
+ 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,48 @@
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 reconnect;
27
+ private reconnectInterval;
28
+ private maxReconnectAttempts;
29
+ private reconnectAttempts;
30
+ private pendingRequests;
31
+ private streamHandlers;
32
+ private isClosing;
33
+ private connectionPromise;
34
+ private heartbeatInterval;
35
+ private reconnectTimeout;
36
+ private lastPongReceived;
37
+ constructor(options: WebSocketClientOptions);
38
+ connect(): Promise<void>;
39
+ private initializeConnection;
40
+ private startHeartbeat;
41
+ private stopHeartbeat;
42
+ private handleMessage;
43
+ send<T = any>(operation: string, data?: Record<string, any>): Promise<T>;
44
+ sendStream(operation: string, data: Record<string, any>, onData: (data: any) => void, onEnd: () => void): string;
45
+ cancelStream(id: string): void;
46
+ close(): void;
47
+ get isConnected(): boolean;
48
+ }
@@ -0,0 +1 @@
1
+ export * from "./client.js";