@blaxel/core 0.2.15 → 0.2.16-dev.98

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.
@@ -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
- export { dotenv, fs, os, path };
5
+ declare let ws: typeof import("ws") | null;
6
+ export { dotenv, fs, os, path, ws };
@@ -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,12 +13,15 @@ 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
27
  console.warn("fs and os are not available in this environment");
package/dist/jobs/jobs.js CHANGED
@@ -42,7 +42,7 @@ class BlJob {
42
42
  const body = {
43
43
  tasks: tasks
44
44
  };
45
- const response = await fetch(url + "/executions", {
45
+ const response = await fetch(url.toString() + "/executions", {
46
46
  method: "POST",
47
47
  headers: {
48
48
  ...settings_js_1.settings.headers,
@@ -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]) ?? 0 : 0;
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
@@ -3,20 +3,10 @@ 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
- // Conditional import for Node.js WebSocket
10
- let NodeWebSocket;
11
- if (!isBrowser) {
12
- try {
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;
20
10
  //const SUBPROTOCOL = "mcp";
21
11
  const MAX_RETRIES = 3;
22
12
  const RETRY_DELAY_MS = 1000;
@@ -72,10 +62,10 @@ class BlaxelMcpClientTransport {
72
62
  }
73
63
  else {
74
64
  // Use Node.js WebSocket
75
- if (!NodeWebSocket) {
65
+ if (!node_js_1.ws) {
76
66
  throw new Error("WebSocket library not available in Node.js environment");
77
67
  }
78
- this._socket = new NodeWebSocket(this._url, {
68
+ this._socket = new node_js_1.ws(this._url, {
79
69
  //protocols: SUBPROTOCOL,
80
70
  headers: this._headers,
81
71
  });
@@ -106,7 +96,7 @@ class BlaxelMcpClientTransport {
106
96
  const browserEvent = event;
107
97
  dataString = typeof browserEvent.data === "string"
108
98
  ? browserEvent.data
109
- : browserEvent.data.toString();
99
+ : String(browserEvent.data);
110
100
  }
111
101
  else {
112
102
  // Node.js WebSocket MessageEvent
@@ -124,9 +114,10 @@ class BlaxelMcpClientTransport {
124
114
  message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(dataString));
125
115
  }
126
116
  catch (error) {
127
- logger_js_1.logger.error(`Error parsing message: ${typeof event.data === "object"
128
- ? JSON.stringify(event.data)
129
- : event.data}`);
117
+ const eventData = 'data' in event ? event.data : 'Unknown data';
118
+ logger_js_1.logger.error(`Error parsing message: ${typeof eventData === "object" && eventData !== null
119
+ ? JSON.stringify(eventData)
120
+ : String(eventData)}`);
130
121
  this.onerror?.(error);
131
122
  return;
132
123
  }
@@ -136,7 +127,7 @@ class BlaxelMcpClientTransport {
136
127
  catch (error) {
137
128
  if (error instanceof Error && error.message.includes("ws does not work in the browser")) {
138
129
  this._isBrowser = true;
139
- return this._connect().then(resolve).catch(reject);
130
+ this._connect().then(resolve).catch(reject);
140
131
  }
141
132
  reject(error);
142
133
  }
@@ -1,4 +1,3 @@
1
1
  "use strict";
2
- /* eslint-disable */
3
2
  // This file is auto-generated by @hey-api/openapi-ts
4
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
- let controller = new AbortController();
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
- let lines = buffer.split('\n');
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 (e) {
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?.abort();
257
+ controller.abort();
258
258
  });
259
259
  return {
260
260
  close: () => {
261
261
  closed = true;
262
- controller?.abort();
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 { done, value } = await reader.read();
31
- if (done)
30
+ const result = await reader.read();
31
+ if (result.done)
32
32
  break;
33
- buffer += decoder.decode(value, { stream: true });
34
- let lines = buffer.split(/\r?\n/);
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
  })();
@@ -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.15",
3
+ "version": "0.2.16-dev.98",
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",