@blaxel/core 0.2.15 → 0.2.16-dev.100
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/common/node.d.ts +2 -1
- package/dist/common/node.js +5 -2
- package/dist/jobs/jobs.js +1 -1
- package/dist/jobs/start.js +1 -1
- package/dist/mcp/client.js +19 -21
- 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/common/node.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ declare let fs: typeof import("fs") | null;
|
|
|
2
2
|
declare let os: typeof import("os") | null;
|
|
3
3
|
declare let path: typeof import("path") | null;
|
|
4
4
|
declare let dotenv: typeof import("dotenv") | null;
|
|
5
|
-
|
|
5
|
+
declare let ws: typeof import("ws") | null;
|
|
6
|
+
export { dotenv, fs, os, path, ws };
|
package/dist/common/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.path = exports.os = exports.fs = exports.dotenv = void 0;
|
|
3
|
+
exports.ws = exports.path = exports.os = exports.fs = exports.dotenv = void 0;
|
|
4
4
|
/* eslint-disable */
|
|
5
5
|
const isNode = typeof process !== "undefined" &&
|
|
6
6
|
process.versions != null &&
|
|
@@ -13,14 +13,17 @@ let path = null;
|
|
|
13
13
|
exports.path = path;
|
|
14
14
|
let dotenv = null;
|
|
15
15
|
exports.dotenv = dotenv;
|
|
16
|
+
let ws = null;
|
|
17
|
+
exports.ws = ws;
|
|
16
18
|
if (isNode) {
|
|
17
19
|
try {
|
|
18
20
|
exports.fs = fs = eval("require")("fs");
|
|
19
21
|
exports.os = os = eval("require")("os");
|
|
20
22
|
exports.path = path = eval("require")("path");
|
|
21
23
|
exports.dotenv = dotenv = eval("require")("dotenv");
|
|
24
|
+
exports.ws = ws = eval("require")("ws");
|
|
22
25
|
}
|
|
23
26
|
catch (e) {
|
|
24
|
-
console.warn("fs
|
|
27
|
+
console.warn("fs, os, path, dotenv, ws are not available in this environment");
|
|
25
28
|
}
|
|
26
29
|
}
|
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
|
@@ -3,20 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BlaxelMcpClientTransport = void 0;
|
|
4
4
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
5
5
|
const logger_js_1 = require("../common/logger.js");
|
|
6
|
+
const node_js_1 = require("../common/node.js");
|
|
6
7
|
const settings_js_1 = require("../common/settings.js");
|
|
7
8
|
// Detect environment
|
|
8
|
-
const isBrowser = typeof globalThis !== "undefined" && globalThis.window !== undefined;
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// Dynamic import for Node.js environment
|
|
14
|
-
NodeWebSocket = require("ws");
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
// ws is not available
|
|
18
|
-
}
|
|
19
|
-
}
|
|
9
|
+
const isBrowser = typeof globalThis !== "undefined" && globalThis && globalThis.window !== undefined;
|
|
10
|
+
// Add Cloudflare detection
|
|
11
|
+
const isCloudflare = typeof globalThis !== "undefined" &&
|
|
12
|
+
typeof globalThis.WebSocket !== "undefined" &&
|
|
13
|
+
!globalThis.window;
|
|
20
14
|
//const SUBPROTOCOL = "mcp";
|
|
21
15
|
const MAX_RETRIES = 3;
|
|
22
16
|
const RETRY_DELAY_MS = 1000;
|
|
@@ -65,17 +59,20 @@ class BlaxelMcpClientTransport {
|
|
|
65
59
|
_connect() {
|
|
66
60
|
return new Promise((resolve, reject) => {
|
|
67
61
|
try {
|
|
62
|
+
let url = this._url.toString();
|
|
68
63
|
if (this._isBrowser) {
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
url += `?token=${settings_js_1.settings.token}`;
|
|
65
|
+
}
|
|
66
|
+
if (isCloudflare || this._isBrowser) {
|
|
67
|
+
// Use native WebSocket (works in both browser and Cloudflare)
|
|
71
68
|
this._socket = new WebSocket(url);
|
|
72
69
|
}
|
|
73
70
|
else {
|
|
74
71
|
// Use Node.js WebSocket
|
|
75
|
-
if (!
|
|
72
|
+
if (!node_js_1.ws) {
|
|
76
73
|
throw new Error("WebSocket library not available in Node.js environment");
|
|
77
74
|
}
|
|
78
|
-
this._socket = new
|
|
75
|
+
this._socket = new node_js_1.ws(this._url, {
|
|
79
76
|
//protocols: SUBPROTOCOL,
|
|
80
77
|
headers: this._headers,
|
|
81
78
|
});
|
|
@@ -106,7 +103,7 @@ class BlaxelMcpClientTransport {
|
|
|
106
103
|
const browserEvent = event;
|
|
107
104
|
dataString = typeof browserEvent.data === "string"
|
|
108
105
|
? browserEvent.data
|
|
109
|
-
: browserEvent.data
|
|
106
|
+
: String(browserEvent.data);
|
|
110
107
|
}
|
|
111
108
|
else {
|
|
112
109
|
// Node.js WebSocket MessageEvent
|
|
@@ -124,9 +121,10 @@ class BlaxelMcpClientTransport {
|
|
|
124
121
|
message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(dataString));
|
|
125
122
|
}
|
|
126
123
|
catch (error) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
const eventData = 'data' in event ? event.data : 'Unknown data';
|
|
125
|
+
logger_js_1.logger.error(`Error parsing message: ${typeof eventData === "object" && eventData !== null
|
|
126
|
+
? JSON.stringify(eventData)
|
|
127
|
+
: String(eventData)}`);
|
|
130
128
|
this.onerror?.(error);
|
|
131
129
|
return;
|
|
132
130
|
}
|
|
@@ -136,7 +134,7 @@ class BlaxelMcpClientTransport {
|
|
|
136
134
|
catch (error) {
|
|
137
135
|
if (error instanceof Error && error.message.includes("ws does not work in the browser")) {
|
|
138
136
|
this._isBrowser = true;
|
|
139
|
-
|
|
137
|
+
this._connect().then(resolve).catch(reject);
|
|
140
138
|
}
|
|
141
139
|
reject(error);
|
|
142
140
|
}
|
|
@@ -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.100",
|
|
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",
|