@blaxel/core 0.2.50-dev.215 → 0.2.50-preview.115
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.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/agents/index.js +2 -2
- package/dist/cjs/authentication/clientcredentials.js +1 -4
- package/dist/cjs/common/internal.js +0 -40
- package/dist/cjs/common/settings.js +2 -5
- package/dist/cjs/jobs/jobs.js +2 -2
- package/dist/cjs/jobs/start.js +1 -32
- package/dist/cjs/sandbox/action.js +2 -1
- package/dist/cjs/sandbox/sandbox.js +10 -67
- package/dist/cjs/tools/mcpTool.js +2 -2
- package/dist/cjs/types/common/internal.d.ts +0 -2
- package/dist/cjs/types/common/settings.d.ts +0 -1
- package/dist/cjs/types/sandbox/sandbox.d.ts +6 -12
- package/dist/cjs/types/sandbox/types.d.ts +0 -3
- package/dist/cjs-browser/.tsbuildinfo +1 -1
- package/dist/cjs-browser/agents/index.js +2 -2
- package/dist/cjs-browser/authentication/clientcredentials.js +1 -4
- package/dist/cjs-browser/common/internal.js +0 -40
- package/dist/cjs-browser/common/settings.js +2 -5
- package/dist/cjs-browser/jobs/jobs.js +2 -2
- package/dist/cjs-browser/jobs/start.js +1 -32
- package/dist/cjs-browser/sandbox/action.js +2 -1
- package/dist/cjs-browser/sandbox/sandbox.js +10 -67
- package/dist/cjs-browser/tools/mcpTool.js +2 -2
- package/dist/cjs-browser/types/common/internal.d.ts +0 -2
- package/dist/cjs-browser/types/common/settings.d.ts +0 -1
- package/dist/cjs-browser/types/sandbox/sandbox.d.ts +6 -12
- package/dist/cjs-browser/types/sandbox/types.d.ts +0 -3
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/agents/index.js +3 -3
- package/dist/esm/authentication/clientcredentials.js +1 -4
- package/dist/esm/common/internal.js +0 -38
- package/dist/esm/common/settings.js +2 -5
- package/dist/esm/jobs/jobs.js +3 -3
- package/dist/esm/jobs/start.js +1 -32
- package/dist/esm/sandbox/action.js +3 -2
- package/dist/esm/sandbox/sandbox.js +10 -67
- package/dist/esm/tools/mcpTool.js +3 -3
- package/dist/esm-browser/.tsbuildinfo +1 -1
- package/dist/esm-browser/agents/index.js +3 -3
- package/dist/esm-browser/authentication/clientcredentials.js +1 -4
- package/dist/esm-browser/common/internal.js +0 -38
- package/dist/esm-browser/common/settings.js +2 -5
- package/dist/esm-browser/jobs/jobs.js +3 -3
- package/dist/esm-browser/jobs/start.js +1 -32
- package/dist/esm-browser/sandbox/action.js +3 -2
- package/dist/esm-browser/sandbox/sandbox.js +10 -67
- package/dist/esm-browser/tools/mcpTool.js +3 -3
- package/package.json +2 -2
- package/dist/cjs/sandbox/codegen/codegen-ws.js +0 -30
- package/dist/cjs/sandbox/filesystem/filesystem-ws.js +0 -106
- package/dist/cjs/sandbox/network/network-ws.js +0 -12
- package/dist/cjs/sandbox/process/process-ws.js +0 -139
- package/dist/cjs/sandbox/websocket/client.js +0 -269
- package/dist/cjs/sandbox/websocket/index.js +0 -17
- package/dist/cjs/types/sandbox/codegen/codegen-ws.d.ts +0 -10
- package/dist/cjs/types/sandbox/filesystem/filesystem-ws.d.ts +0 -35
- package/dist/cjs/types/sandbox/network/network-ws.d.ts +0 -7
- package/dist/cjs/types/sandbox/process/process-ws.d.ts +0 -27
- package/dist/cjs/types/sandbox/websocket/client.d.ts +0 -48
- package/dist/cjs/types/sandbox/websocket/index.d.ts +0 -1
- package/dist/cjs-browser/sandbox/codegen/codegen-ws.js +0 -30
- package/dist/cjs-browser/sandbox/filesystem/filesystem-ws.js +0 -106
- package/dist/cjs-browser/sandbox/network/network-ws.js +0 -12
- package/dist/cjs-browser/sandbox/process/process-ws.js +0 -139
- package/dist/cjs-browser/sandbox/websocket/client.js +0 -269
- package/dist/cjs-browser/sandbox/websocket/index.js +0 -17
- package/dist/cjs-browser/types/sandbox/codegen/codegen-ws.d.ts +0 -10
- package/dist/cjs-browser/types/sandbox/filesystem/filesystem-ws.d.ts +0 -35
- package/dist/cjs-browser/types/sandbox/network/network-ws.d.ts +0 -7
- package/dist/cjs-browser/types/sandbox/process/process-ws.d.ts +0 -27
- package/dist/cjs-browser/types/sandbox/websocket/client.d.ts +0 -48
- package/dist/cjs-browser/types/sandbox/websocket/index.d.ts +0 -1
- package/dist/esm/sandbox/codegen/codegen-ws.js +0 -26
- package/dist/esm/sandbox/filesystem/filesystem-ws.js +0 -102
- package/dist/esm/sandbox/network/network-ws.js +0 -8
- package/dist/esm/sandbox/process/process-ws.js +0 -135
- package/dist/esm/sandbox/websocket/client.js +0 -265
- package/dist/esm/sandbox/websocket/index.js +0 -1
- package/dist/esm-browser/sandbox/codegen/codegen-ws.js +0 -26
- package/dist/esm-browser/sandbox/filesystem/filesystem-ws.js +0 -102
- package/dist/esm-browser/sandbox/network/network-ws.js +0 -8
- package/dist/esm-browser/sandbox/process/process-ws.js +0 -135
- package/dist/esm-browser/sandbox/websocket/client.js +0 -265
- package/dist/esm-browser/sandbox/websocket/index.js +0 -1
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SandboxProcessWebSocket = void 0;
|
|
4
|
-
const action_js_1 = require("../action.js");
|
|
5
|
-
const process_js_1 = require("./process.js");
|
|
6
|
-
class SandboxProcessWebSocket extends action_js_1.SandboxAction {
|
|
7
|
-
wsClient;
|
|
8
|
-
httpClient;
|
|
9
|
-
constructor(sandbox, wsClient) {
|
|
10
|
-
super(sandbox);
|
|
11
|
-
this.wsClient = wsClient;
|
|
12
|
-
// Create HTTP client for fallback operations
|
|
13
|
-
this.httpClient = new process_js_1.SandboxProcess(sandbox);
|
|
14
|
-
}
|
|
15
|
-
streamLogs(identifier, options) {
|
|
16
|
-
const streamId = this.wsClient.sendStream("process:logs:stream:start", { identifier }, (data) => {
|
|
17
|
-
// Handle streaming log data
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
19
|
-
if (data && data.log) {
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
21
|
-
const log = String(data.log);
|
|
22
|
-
// Parse log format: "stdout:" or "stderr:" prefix
|
|
23
|
-
if (log.startsWith('stdout:')) {
|
|
24
|
-
const stdout = log.slice(7);
|
|
25
|
-
options.onStdout?.(stdout);
|
|
26
|
-
options.onLog?.(stdout);
|
|
27
|
-
}
|
|
28
|
-
else if (log.startsWith('stderr:')) {
|
|
29
|
-
const stderr = log.slice(7);
|
|
30
|
-
options.onStderr?.(stderr);
|
|
31
|
-
options.onLog?.(stderr);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
options.onLog?.(log);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}, () => {
|
|
38
|
-
// Stream ended
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
close: () => this.wsClient.cancelStream(streamId),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async exec(process) {
|
|
45
|
-
let onLog;
|
|
46
|
-
if ('onLog' in process && process.onLog) {
|
|
47
|
-
onLog = process.onLog;
|
|
48
|
-
delete process.onLog;
|
|
49
|
-
}
|
|
50
|
-
// Store original wait_for_completion setting
|
|
51
|
-
const shouldWaitForCompletion = process.waitForCompletion;
|
|
52
|
-
// Always start process without wait_for_completion to avoid server-side blocking
|
|
53
|
-
if (shouldWaitForCompletion && onLog) {
|
|
54
|
-
process.waitForCompletion = false;
|
|
55
|
-
}
|
|
56
|
-
const data = await this.wsClient.send("process:execute", process);
|
|
57
|
-
let result = data;
|
|
58
|
-
// Handle wait_for_completion with parallel log streaming
|
|
59
|
-
if (shouldWaitForCompletion && onLog) {
|
|
60
|
-
const streamControl = this.streamLogs(result.pid, { onLog });
|
|
61
|
-
try {
|
|
62
|
-
// Wait for process completion
|
|
63
|
-
result = await this.wait(result.pid, { interval: 500, maxWait: 1000 * 60 * 60 });
|
|
64
|
-
}
|
|
65
|
-
finally {
|
|
66
|
-
// Clean up log streaming
|
|
67
|
-
if (streamControl) {
|
|
68
|
-
streamControl.close();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// For non-blocking execution, set up log streaming immediately if requested
|
|
74
|
-
if (onLog) {
|
|
75
|
-
const streamControl = this.streamLogs(result.pid, { onLog });
|
|
76
|
-
return {
|
|
77
|
-
...result,
|
|
78
|
-
close() {
|
|
79
|
-
if (streamControl) {
|
|
80
|
-
streamControl.close();
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return { ...result, close: () => { } };
|
|
87
|
-
}
|
|
88
|
-
async wait(identifier, { maxWait = 60000, interval = 1000 } = {}) {
|
|
89
|
-
const startTime = Date.now();
|
|
90
|
-
let status = "running";
|
|
91
|
-
let data = await this.get(identifier);
|
|
92
|
-
while (status === "running") {
|
|
93
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
94
|
-
try {
|
|
95
|
-
data = await this.get(identifier);
|
|
96
|
-
status = data.status ?? "running";
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
if (Date.now() - startTime > maxWait) {
|
|
102
|
-
throw new Error("Process did not finish in time");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return data;
|
|
106
|
-
}
|
|
107
|
-
async get(identifier) {
|
|
108
|
-
const data = await this.wsClient.send("process:get", { identifier });
|
|
109
|
-
return data;
|
|
110
|
-
}
|
|
111
|
-
async list() {
|
|
112
|
-
const data = await this.wsClient.send("process:list", {});
|
|
113
|
-
return data.processes || [];
|
|
114
|
-
}
|
|
115
|
-
async stop(identifier) {
|
|
116
|
-
const data = await this.wsClient.send("process:stop", { identifier });
|
|
117
|
-
return data;
|
|
118
|
-
}
|
|
119
|
-
async kill(identifier) {
|
|
120
|
-
const data = await this.wsClient.send("process:kill", { identifier });
|
|
121
|
-
return data;
|
|
122
|
-
}
|
|
123
|
-
async logs(identifier, type = "all") {
|
|
124
|
-
const data = await this.wsClient.send("process:logs", {
|
|
125
|
-
identifier,
|
|
126
|
-
});
|
|
127
|
-
if (type === "all") {
|
|
128
|
-
return data.logs || "";
|
|
129
|
-
}
|
|
130
|
-
else if (type === "stdout") {
|
|
131
|
-
return data.stdout || "";
|
|
132
|
-
}
|
|
133
|
-
else if (type === "stderr") {
|
|
134
|
-
return data.stderr || "";
|
|
135
|
-
}
|
|
136
|
-
throw new Error("Unsupported log type");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.SandboxProcessWebSocket = SandboxProcessWebSocket;
|
|
@@ -1,269 +0,0 @@
|
|
|
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;
|
|
@@ -1,17 +0,0 @@
|
|
|
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);
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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,48 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./client.js";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { SandboxAction } from "../action.js";
|
|
2
|
-
export class SandboxCodegenWebSocket extends SandboxAction {
|
|
3
|
-
wsClient;
|
|
4
|
-
constructor(sandbox, wsClient) {
|
|
5
|
-
super(sandbox);
|
|
6
|
-
this.wsClient = wsClient;
|
|
7
|
-
}
|
|
8
|
-
async fastapply(path, codeEdit, model) {
|
|
9
|
-
const data = await this.wsClient.send("codegen:fastapply", {
|
|
10
|
-
path,
|
|
11
|
-
codeEdit,
|
|
12
|
-
model,
|
|
13
|
-
});
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
async reranking(path, query, scoreThreshold, tokenLimit, filePattern) {
|
|
17
|
-
const data = await this.wsClient.send("codegen:reranking", {
|
|
18
|
-
path,
|
|
19
|
-
query,
|
|
20
|
-
scoreThreshold,
|
|
21
|
-
tokenLimit,
|
|
22
|
-
filePattern,
|
|
23
|
-
});
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
}
|