@blaxel/core 0.2.15 → 0.2.16-dev.101
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/jobs/jobs.js +1 -1
- package/dist/jobs/start.js +1 -1
- package/dist/mcp/client.js +16 -2
- package/dist/sandbox/client/types.gen.js +0 -1
- package/dist/sandbox/filesystem/filesystem.js +8 -8
- package/dist/sandbox/process/process.js +9 -7
- package/dist/sandbox/sandbox.js +1 -0
- package/package.json +2 -1
package/dist/jobs/jobs.js
CHANGED
package/dist/jobs/start.js
CHANGED
|
@@ -37,7 +37,7 @@ class BlJobWrapper {
|
|
|
37
37
|
return env_js_1.env.BL_TASK_KEY ?? "TASK_INDEX";
|
|
38
38
|
}
|
|
39
39
|
get index() {
|
|
40
|
-
return env_js_1.env[this.indexKey] ? Number(env_js_1.env[this.indexKey])
|
|
40
|
+
return env_js_1.env[this.indexKey] ? Number(env_js_1.env[this.indexKey]) : 0;
|
|
41
41
|
}
|
|
42
42
|
/*
|
|
43
43
|
Run a job defined in a function, it's run in the current process
|
package/dist/mcp/client.js
CHANGED
|
@@ -5,15 +5,18 @@ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
|
5
5
|
const logger_js_1 = require("../common/logger.js");
|
|
6
6
|
const settings_js_1 = require("../common/settings.js");
|
|
7
7
|
// Detect environment
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
8
9
|
const isBrowser = typeof globalThis !== "undefined" && globalThis.window !== undefined;
|
|
9
10
|
// Conditional import for Node.js WebSocket
|
|
10
11
|
let NodeWebSocket;
|
|
11
12
|
if (!isBrowser) {
|
|
12
13
|
try {
|
|
13
14
|
// Dynamic import for Node.js environment
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports
|
|
14
16
|
NodeWebSocket = require("ws");
|
|
15
17
|
}
|
|
16
|
-
catch
|
|
18
|
+
catch {
|
|
19
|
+
console.warn("ws is not available in this environment");
|
|
17
20
|
// ws is not available
|
|
18
21
|
}
|
|
19
22
|
}
|
|
@@ -63,6 +66,7 @@ class BlaxelMcpClientTransport {
|
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
_connect() {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
66
70
|
return new Promise((resolve, reject) => {
|
|
67
71
|
try {
|
|
68
72
|
if (this._isBrowser) {
|
|
@@ -75,6 +79,7 @@ class BlaxelMcpClientTransport {
|
|
|
75
79
|
if (!NodeWebSocket) {
|
|
76
80
|
throw new Error("WebSocket library not available in Node.js environment");
|
|
77
81
|
}
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
78
83
|
this._socket = new NodeWebSocket(this._url, {
|
|
79
84
|
//protocols: SUBPROTOCOL,
|
|
80
85
|
headers: this._headers,
|
|
@@ -83,9 +88,12 @@ class BlaxelMcpClientTransport {
|
|
|
83
88
|
this._socket.onerror = (event) => {
|
|
84
89
|
console.error(event);
|
|
85
90
|
const error = this._isBrowser
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
86
92
|
? new Error(`WebSocket error: ${event.message}`)
|
|
87
93
|
: "error" in event
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
88
95
|
? event.error
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
89
97
|
: new Error(`WebSocket error: ${event.message}`);
|
|
90
98
|
reject(error);
|
|
91
99
|
this.onerror?.(error);
|
|
@@ -104,8 +112,10 @@ class BlaxelMcpClientTransport {
|
|
|
104
112
|
if (this._isBrowser) {
|
|
105
113
|
// Browser WebSocket MessageEvent
|
|
106
114
|
const browserEvent = event;
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
107
116
|
dataString = typeof browserEvent.data === "string"
|
|
108
117
|
? browserEvent.data
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
109
119
|
: browserEvent.data.toString();
|
|
110
120
|
}
|
|
111
121
|
else {
|
|
@@ -124,8 +134,12 @@ class BlaxelMcpClientTransport {
|
|
|
124
134
|
message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(dataString));
|
|
125
135
|
}
|
|
126
136
|
catch (error) {
|
|
127
|
-
logger_js_1.logger.error(`Error parsing message: ${
|
|
137
|
+
logger_js_1.logger.error(`Error parsing message: ${
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
139
|
+
typeof event.data === "object"
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
128
141
|
? JSON.stringify(event.data)
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
129
143
|
: event.data}`);
|
|
130
144
|
this.onerror?.(error);
|
|
131
145
|
return;
|
|
@@ -185,7 +185,7 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
|
185
185
|
watch(path, callback, options) {
|
|
186
186
|
path = this.formatPath(path);
|
|
187
187
|
let closed = false;
|
|
188
|
-
|
|
188
|
+
const controller = new AbortController();
|
|
189
189
|
const start = async () => {
|
|
190
190
|
const query = {};
|
|
191
191
|
if (options?.ignore) {
|
|
@@ -200,7 +200,7 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
|
200
200
|
signal: controller.signal,
|
|
201
201
|
});
|
|
202
202
|
if (error)
|
|
203
|
-
throw error;
|
|
203
|
+
throw new Error(error instanceof Error ? error.message : JSON.stringify(error));
|
|
204
204
|
const stream = data ?? response.body;
|
|
205
205
|
if (!stream)
|
|
206
206
|
throw new Error('No stream returned');
|
|
@@ -213,7 +213,7 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
|
213
213
|
if (done)
|
|
214
214
|
break;
|
|
215
215
|
buffer += decoder.decode(value, { stream: true });
|
|
216
|
-
|
|
216
|
+
const lines = buffer.split('\n');
|
|
217
217
|
buffer = lines.pop();
|
|
218
218
|
for (const line of lines) {
|
|
219
219
|
const trimmed = line.trim();
|
|
@@ -232,7 +232,7 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
|
232
232
|
const content = await this.read(filePath);
|
|
233
233
|
await callback({ ...fileEvent, content });
|
|
234
234
|
}
|
|
235
|
-
catch
|
|
235
|
+
catch {
|
|
236
236
|
await callback({ ...fileEvent, content: undefined });
|
|
237
237
|
}
|
|
238
238
|
}
|
|
@@ -248,18 +248,18 @@ class SandboxFileSystem extends action_js_1.SandboxAction {
|
|
|
248
248
|
};
|
|
249
249
|
start().catch((err) => {
|
|
250
250
|
// Suppress AbortError when closing
|
|
251
|
-
if (!(err && err.name === 'AbortError')) {
|
|
251
|
+
if (!(err && typeof err === 'object' && 'name' in err && err.name === 'AbortError')) {
|
|
252
252
|
if (options?.onError) {
|
|
253
|
-
options.onError(err);
|
|
253
|
+
options.onError(err instanceof Error ? err : new Error(String(err)));
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
closed = true;
|
|
257
|
-
controller
|
|
257
|
+
controller.abort();
|
|
258
258
|
});
|
|
259
259
|
return {
|
|
260
260
|
close: () => {
|
|
261
261
|
closed = true;
|
|
262
|
-
controller
|
|
262
|
+
controller.abort();
|
|
263
263
|
},
|
|
264
264
|
};
|
|
265
265
|
}
|
|
@@ -10,7 +10,7 @@ class SandboxProcess extends action_js_1.SandboxAction {
|
|
|
10
10
|
}
|
|
11
11
|
streamLogs(identifier, options) {
|
|
12
12
|
const controller = new AbortController();
|
|
13
|
-
(async () => {
|
|
13
|
+
void (async () => {
|
|
14
14
|
try {
|
|
15
15
|
const headers = this.sandbox.forceUrl ? this.sandbox.headers : settings_js_1.settings.headers;
|
|
16
16
|
const stream = await fetch(`${this.url}/process/${identifier}/logs/stream`, {
|
|
@@ -27,11 +27,13 @@ class SandboxProcess extends action_js_1.SandboxAction {
|
|
|
27
27
|
const decoder = new TextDecoder();
|
|
28
28
|
let buffer = '';
|
|
29
29
|
while (true) {
|
|
30
|
-
const
|
|
31
|
-
if (done)
|
|
30
|
+
const result = await reader.read();
|
|
31
|
+
if (result.done)
|
|
32
32
|
break;
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
if (result.value && result.value instanceof Uint8Array) {
|
|
34
|
+
buffer += decoder.decode(result.value, { stream: true });
|
|
35
|
+
}
|
|
36
|
+
const lines = buffer.split(/\r?\n/);
|
|
35
37
|
buffer = lines.pop();
|
|
36
38
|
for (const line of lines) {
|
|
37
39
|
if (line.startsWith('stdout:')) {
|
|
@@ -49,9 +51,9 @@ class SandboxProcess extends action_js_1.SandboxAction {
|
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
catch (err) {
|
|
52
|
-
if (err && err.name !== 'AbortError') {
|
|
54
|
+
if (err && typeof err === 'object' && 'name' in err && err.name !== 'AbortError') {
|
|
53
55
|
console.error("Stream error:", err);
|
|
54
|
-
throw err;
|
|
56
|
+
throw new Error(err instanceof Error ? err.message : 'Unknown stream error');
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
})();
|
package/dist/sandbox/sandbox.js
CHANGED
|
@@ -106,6 +106,7 @@ class SandboxInstance {
|
|
|
106
106
|
throw e;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
/* eslint-disable */
|
|
109
110
|
static async fromSession(session) {
|
|
110
111
|
return new SandboxInstance({ forceUrl: session.url, params: { bl_preview_token: session.token }, headers: { "X-Blaxel-Preview-Token": session.token } });
|
|
111
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16-dev.101",
|
|
4
4
|
"description": "Blaxel Core SDK for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blaxel, INC (https://blaxel.ai)",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"@eslint/js": "^9.26.0",
|
|
70
70
|
"@testing-library/dom": "^9.3.0",
|
|
71
71
|
"@types/ws": "^8.18.1",
|
|
72
|
+
"eslint": "^9.27.0",
|
|
72
73
|
"jsdom": "^26.1.0",
|
|
73
74
|
"typescript": "^5.0.0",
|
|
74
75
|
"typescript-eslint": "^8.31.1",
|