@blaxel/core 0.2.10-dev.86 → 0.2.10-dev1

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Blaxel Typescript SDK
2
2
 
3
3
  <p align="center">
4
- <img src="https://blaxel.ai/logo.png" alt="Blaxel"/>
4
+ <img src="https://blaxel.ai/logo-bg.png" alt="Blaxel"/>
5
5
  </p>
6
6
 
7
7
  **Blaxel is a computing platform for AI agent builders, with all the services and infrastructure to build and deploy agents efficiently.** This repository contains the TypeScript SDK to create and manage resources on Blaxel.
@@ -4,8 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.authentication = authentication;
7
- /* eslint-disable */
8
- const path_1 = require("path");
9
7
  const yaml_1 = __importDefault(require("yaml"));
10
8
  const env_js_1 = require("../common/env.js");
11
9
  const node_js_1 = require("../common/node.js");
@@ -26,12 +24,12 @@ function getCredentials() {
26
24
  workspace: env_js_1.env.BL_WORKSPACE,
27
25
  };
28
26
  }
29
- if (node_js_1.os === null || node_js_1.fs === null) {
27
+ if (node_js_1.os === null || node_js_1.fs === null || node_js_1.path === null) {
30
28
  return null;
31
29
  }
32
30
  try {
33
31
  const homeDir = node_js_1.os.homedir();
34
- const config = node_js_1.fs.readFileSync((0, path_1.join)(homeDir, ".blaxel/config.yaml"), "utf8");
32
+ const config = node_js_1.fs.readFileSync(node_js_1.path.join(homeDir, ".blaxel/config.yaml"), "utf8");
35
33
  const configJson = yaml_1.default.parse(config);
36
34
  const workspaceName = env_js_1.env.BL_WORKSPACE || configJson.context.workspace;
37
35
  const credentials = configJson.workspaces.find((wk) => wk.name === workspaceName)?.credentials;
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.findFromCache = findFromCache;
7
- /* eslint-disable */
8
7
  const yaml_1 = __importDefault(require("yaml"));
9
8
  const node_js_1 = require("../common/node.js");
10
9
  const cache = new Map();
@@ -5,12 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.env = void 0;
7
7
  /* eslint-disable */
8
- const dotenv_1 = __importDefault(require("dotenv"));
9
8
  const toml_1 = __importDefault(require("toml"));
10
9
  const node_js_1 = require("./node.js");
11
10
  const secretEnv = {};
12
11
  const configEnv = {};
13
- if (node_js_1.fs !== null) {
12
+ if (node_js_1.fs !== null && node_js_1.dotenv !== null) {
14
13
  try {
15
14
  const configFile = node_js_1.fs.readFileSync("blaxel.toml", "utf8");
16
15
  const configInfos = toml_1.default.parse(configFile);
@@ -21,7 +20,7 @@ if (node_js_1.fs !== null) {
21
20
  catch (error) { }
22
21
  try {
23
22
  const secretFile = node_js_1.fs.readFileSync(".env", "utf8");
24
- const parsed = dotenv_1.default.parse(secretFile);
23
+ const parsed = node_js_1.dotenv.parse(secretFile);
25
24
  Object.assign(secretEnv, parsed);
26
25
  }
27
26
  catch (error) { }
@@ -34,7 +33,10 @@ const env = new Proxy({}, {
34
33
  if (configEnv[prop]) {
35
34
  return configEnv[prop];
36
35
  }
37
- return process.env[prop];
36
+ if (typeof process !== "undefined" && process.env) {
37
+ return process.env[prop];
38
+ }
39
+ return undefined;
38
40
  },
39
41
  });
40
42
  exports.env = env;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAlphanumericLimitedHash = getAlphanumericLimitedHash;
4
4
  exports.getGlobalUniqueHash = getGlobalUniqueHash;
5
+ /* eslint-disable */
5
6
  // Pure JS MD5 implementation (public domain, compact)
6
7
  function md5(input) {
7
8
  function cmn(q, a, b, x, s, t) {
@@ -1,5 +1,6 @@
1
1
  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
+ declare let dotenv: typeof import("dotenv") | null;
4
5
  declare let FormData: typeof import("form-data") | null;
5
- export { FormData, fs, os, path };
6
+ export { dotenv, FormData, fs, os, path };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.path = exports.os = exports.fs = exports.FormData = void 0;
3
+ exports.path = exports.os = exports.fs = exports.FormData = exports.dotenv = void 0;
4
4
  /* eslint-disable */
5
5
  const isNode = typeof process !== "undefined" &&
6
6
  process.versions != null &&
@@ -11,6 +11,8 @@ let os = null;
11
11
  exports.os = os;
12
12
  let path = null;
13
13
  exports.path = path;
14
+ let dotenv = null;
15
+ exports.dotenv = dotenv;
14
16
  let FormData = null;
15
17
  exports.FormData = FormData;
16
18
  if (isNode) {
@@ -18,6 +20,7 @@ if (isNode) {
18
20
  exports.fs = fs = eval("require")("fs");
19
21
  exports.os = os = eval("require")("os");
20
22
  exports.path = path = eval("require")("path");
23
+ exports.dotenv = dotenv = eval("require")("dotenv");
21
24
  exports.FormData = FormData = eval("require")("form-data");
22
25
  }
23
26
  catch (e) {
@@ -0,0 +1,32 @@
1
+ declare class BlBatch {
2
+ /**
3
+ * Lists all remote batch jobs for a given name
4
+ * @param name - The name of the job to list
5
+ */
6
+ list(name: string): void;
7
+ /**
8
+ * Creates a new remote batch job configuration.
9
+ * This is used for remote execution management, not for local execution.
10
+ * @param name - The name of the job
11
+ * @param args - Array of argument arrays for each job in the batch
12
+ * @returns The batch configuration object
13
+ */
14
+ create(name: string, args: any[][]): {
15
+ name: string;
16
+ args: any[][];
17
+ };
18
+ /**
19
+ * Kills a remote batch job
20
+ * @param name - The name of the job
21
+ * @param batchId - The ID of the batch to kill
22
+ */
23
+ kill(name: string, batchId: string): void;
24
+ /**
25
+ * Retrieves information about a remote batch job
26
+ * @param name - The name of the job
27
+ * @param batchId - The ID of the batch to get information for
28
+ */
29
+ get(name: string, batchId: string): void;
30
+ }
31
+ export declare const blBatch: BlBatch;
32
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blBatch = void 0;
4
+ class BlBatch {
5
+ /**
6
+ * Lists all remote batch jobs for a given name
7
+ * @param name - The name of the job to list
8
+ */
9
+ list(name) {
10
+ }
11
+ /**
12
+ * Creates a new remote batch job configuration.
13
+ * This is used for remote execution management, not for local execution.
14
+ * @param name - The name of the job
15
+ * @param args - Array of argument arrays for each job in the batch
16
+ * @returns The batch configuration object
17
+ */
18
+ create(name, args) {
19
+ const batch = {
20
+ name,
21
+ args,
22
+ };
23
+ return batch;
24
+ }
25
+ /**
26
+ * Kills a remote batch job
27
+ * @param name - The name of the job
28
+ * @param batchId - The ID of the batch to kill
29
+ */
30
+ kill(name, batchId) {
31
+ }
32
+ /**
33
+ * Retrieves information about a remote batch job
34
+ * @param name - The name of the job
35
+ * @param batchId - The ID of the batch to get information for
36
+ */
37
+ get(name, batchId) {
38
+ }
39
+ }
40
+ exports.blBatch = new BlBatch();
@@ -0,0 +1,33 @@
1
+ declare class BlJob {
2
+ start(func: (...args: any[]) => Promise<void>): void;
3
+ /**
4
+ * Lists all remote batch jobs for a given name
5
+ * @param name - The name of the job to list
6
+ */
7
+ list(name: string): void;
8
+ /**
9
+ * Creates a new remote batch job configuration.
10
+ * This is used for remote execution management, not for local execution.
11
+ * @param name - The name of the job
12
+ * @param args - Array of argument arrays for each job in the batch
13
+ * @returns The batch configuration object
14
+ */
15
+ create(name: string, args: any[][]): {
16
+ name: string;
17
+ args: any[][];
18
+ };
19
+ /**
20
+ * Kills a remote batch job
21
+ * @param name - The name of the job
22
+ * @param batchId - The ID of the batch to kill
23
+ */
24
+ kill(name: string, batchId: string): void;
25
+ /**
26
+ * Retrieves information about a remote batch job
27
+ * @param name - The name of the job
28
+ * @param batchId - The ID of the batch to get information for
29
+ */
30
+ get(name: string, batchId: string): void;
31
+ }
32
+ export declare const blJob: BlJob;
33
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.blJob = void 0;
4
+ function retrieveArguments() {
5
+ const args = process.argv.slice(2);
6
+ return args;
7
+ }
8
+ class BlJob {
9
+ /*
10
+ Run a job defined in a function, it's run in the current process
11
+ */
12
+ start(func) {
13
+ const args = retrieveArguments();
14
+ func(...args);
15
+ }
16
+ /**
17
+ * Lists all remote batch jobs for a given name
18
+ * @param name - The name of the job to list
19
+ */
20
+ list(name) {
21
+ }
22
+ /**
23
+ * Creates a new remote batch job configuration.
24
+ * This is used for remote execution management, not for local execution.
25
+ * @param name - The name of the job
26
+ * @param args - Array of argument arrays for each job in the batch
27
+ * @returns The batch configuration object
28
+ */
29
+ create(name, args) {
30
+ const batch = {
31
+ name,
32
+ args,
33
+ };
34
+ return batch;
35
+ }
36
+ /**
37
+ * Kills a remote batch job
38
+ * @param name - The name of the job
39
+ * @param batchId - The ID of the batch to kill
40
+ */
41
+ kill(name, batchId) {
42
+ }
43
+ /**
44
+ * Retrieves information about a remote batch job
45
+ * @param name - The name of the job
46
+ * @param batchId - The ID of the batch to get information for
47
+ */
48
+ get(name, batchId) {
49
+ }
50
+ }
51
+ exports.blJob = new BlJob();
package/dist/jobs/jobs.js CHANGED
@@ -39,7 +39,7 @@ class BlJob {
39
39
  return this.externalUrl;
40
40
  }
41
41
  async call(url, tasks) {
42
- let body = {
42
+ const body = {
43
43
  tasks: tasks
44
44
  };
45
45
  const response = await fetch(url + "/executions", {
@@ -2,11 +2,13 @@ import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
2
2
  import { JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js";
3
3
  /**
4
4
  * Client transport for WebSocket: this will connect to a server over the WebSocket protocol.
5
+ * Works in both browser and Node.js environments.
5
6
  */
6
7
  export declare class BlaxelMcpClientTransport implements Transport {
7
8
  private _socket?;
8
9
  private _url;
9
10
  private _headers;
11
+ private _isBrowser;
10
12
  onclose?: () => void;
11
13
  onerror?: (error: Error) => void;
12
14
  onmessage?: (message: JSONRPCMessage) => void;
@@ -1,12 +1,22 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.BlaxelMcpClientTransport = void 0;
7
4
  const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
8
- const ws_1 = __importDefault(require("ws"));
9
5
  const logger_js_1 = require("../common/logger.js");
6
+ const settings_js_1 = require("../common/settings.js");
7
+ // 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
+ }
10
20
  //const SUBPROTOCOL = "mcp";
11
21
  const MAX_RETRIES = 3;
12
22
  const RETRY_DELAY_MS = 1000;
@@ -14,17 +24,20 @@ const RETRY_DELAY_MS = 1000;
14
24
  const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
15
25
  /**
16
26
  * Client transport for WebSocket: this will connect to a server over the WebSocket protocol.
27
+ * Works in both browser and Node.js environments.
17
28
  */
18
29
  class BlaxelMcpClientTransport {
19
30
  _socket;
20
31
  _url;
21
32
  _headers;
33
+ _isBrowser;
22
34
  onclose;
23
35
  onerror;
24
36
  onmessage;
25
37
  constructor(url, headers) {
26
38
  this._url = new URL(url.replace("http", "ws"));
27
39
  this._headers = headers ?? {};
40
+ this._isBrowser = isBrowser;
28
41
  }
29
42
  async start() {
30
43
  if (this._socket) {
@@ -51,52 +64,93 @@ class BlaxelMcpClientTransport {
51
64
  }
52
65
  _connect() {
53
66
  return new Promise((resolve, reject) => {
54
- this._socket = new ws_1.default(this._url, {
55
- //protocols: SUBPROTOCOL,
56
- headers: this._headers,
57
- });
58
- this._socket.onerror = (event) => {
59
- const error = "error" in event
60
- ? event.error
61
- : new Error(`WebSocket error: ${JSON.stringify(event)}`);
62
- reject(error);
63
- this.onerror?.(error);
64
- };
65
- this._socket.onopen = () => {
66
- resolve();
67
- };
68
- this._socket.onclose = () => {
69
- this.onclose?.();
70
- this._socket = undefined;
71
- };
72
- this._socket.onmessage = (event) => {
73
- let message;
74
- try {
75
- let dataString;
76
- if (typeof event.data === "string") {
77
- dataString = event.data;
78
- }
79
- else if (event.data instanceof Buffer) {
80
- dataString = event.data.toString("utf-8");
81
- }
82
- else {
83
- throw new Error("Unsupported data type for event.data");
67
+ try {
68
+ if (this._isBrowser) {
69
+ // Use native browser WebSocket
70
+ const url = `${this._url.toString()}?token=${settings_js_1.settings.token}`;
71
+ this._socket = new WebSocket(url);
72
+ }
73
+ else {
74
+ // Use Node.js WebSocket
75
+ if (!NodeWebSocket) {
76
+ throw new Error("WebSocket library not available in Node.js environment");
84
77
  }
85
- message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(dataString));
78
+ this._socket = new NodeWebSocket(this._url, {
79
+ //protocols: SUBPROTOCOL,
80
+ headers: this._headers,
81
+ });
86
82
  }
87
- catch (error) {
88
- logger_js_1.logger.error(`Error parsing message: ${typeof event.data === "object"
89
- ? JSON.stringify(event.data)
90
- : event.data}`);
83
+ this._socket.onerror = (event) => {
84
+ console.error(event);
85
+ const error = this._isBrowser
86
+ ? new Error(`WebSocket error: ${event.message}`)
87
+ : "error" in event
88
+ ? event.error
89
+ : new Error(`WebSocket error: ${event.message}`);
90
+ reject(error);
91
91
  this.onerror?.(error);
92
- return;
92
+ };
93
+ this._socket.onopen = () => {
94
+ resolve();
95
+ };
96
+ this._socket.onclose = () => {
97
+ this.onclose?.();
98
+ this._socket = undefined;
99
+ };
100
+ this._socket.onmessage = (event) => {
101
+ let message;
102
+ try {
103
+ let dataString;
104
+ if (this._isBrowser) {
105
+ // Browser WebSocket MessageEvent
106
+ const browserEvent = event;
107
+ dataString = typeof browserEvent.data === "string"
108
+ ? browserEvent.data
109
+ : browserEvent.data.toString();
110
+ }
111
+ else {
112
+ // Node.js WebSocket MessageEvent
113
+ const nodeEvent = event;
114
+ if (typeof nodeEvent.data === "string") {
115
+ dataString = nodeEvent.data;
116
+ }
117
+ else if (nodeEvent.data instanceof Buffer) {
118
+ dataString = nodeEvent.data.toString("utf-8");
119
+ }
120
+ else {
121
+ throw new Error("Unsupported data type for event.data");
122
+ }
123
+ }
124
+ message = types_js_1.JSONRPCMessageSchema.parse(JSON.parse(dataString));
125
+ }
126
+ catch (error) {
127
+ logger_js_1.logger.error(`Error parsing message: ${typeof event.data === "object"
128
+ ? JSON.stringify(event.data)
129
+ : event.data}`);
130
+ this.onerror?.(error);
131
+ return;
132
+ }
133
+ this.onmessage?.(message);
134
+ };
135
+ }
136
+ catch (error) {
137
+ if (error instanceof Error && error.message.includes("ws does not work in the browser")) {
138
+ this._isBrowser = true;
139
+ return this._connect().then(resolve).catch(reject);
93
140
  }
94
- this.onmessage?.(message);
95
- };
141
+ reject(error);
142
+ }
96
143
  });
97
144
  }
98
145
  get isConnected() {
99
- return this._socket?.readyState === ws_1.default.OPEN;
146
+ if (!this._socket)
147
+ return false;
148
+ if (this._isBrowser) {
149
+ return this._socket.readyState === 1; // WebSocket.OPEN = 1
150
+ }
151
+ else {
152
+ return this._socket.readyState === 1; // WebSocket.OPEN = 1
153
+ }
100
154
  }
101
155
  async close() {
102
156
  this._socket?.close();
@@ -108,7 +162,7 @@ class BlaxelMcpClientTransport {
108
162
  let attempts = 0;
109
163
  while (attempts < MAX_RETRIES) {
110
164
  try {
111
- if (!this._socket || this._socket.readyState !== ws_1.default.OPEN) {
165
+ if (!this._socket || !this.isConnected) {
112
166
  if (!this._socket) {
113
167
  // Only try to start if socket doesn't exist
114
168
  await this.start();
@@ -119,14 +173,23 @@ class BlaxelMcpClientTransport {
119
173
  }
120
174
  await new Promise((resolve, reject) => {
121
175
  try {
122
- this._socket?.send(JSON.stringify(message), (error) => {
123
- if (error) {
124
- reject(error);
125
- }
126
- else {
127
- resolve();
128
- }
129
- });
176
+ const messageStr = JSON.stringify(message);
177
+ if (this._isBrowser) {
178
+ // Browser WebSocket
179
+ this._socket?.send(messageStr);
180
+ resolve();
181
+ }
182
+ else {
183
+ // Node.js WebSocket
184
+ this._socket?.send(messageStr, (error) => {
185
+ if (error) {
186
+ reject(error);
187
+ }
188
+ else {
189
+ resolve();
190
+ }
191
+ });
192
+ }
130
193
  }
131
194
  catch (error) {
132
195
  reject(error);
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SandboxAction = exports.ResponseError = void 0;
4
4
  const client_fetch_1 = require("@hey-api/client-fetch");
5
- const process_1 = require("process");
5
+ const env_js_1 = require("../common/env.js");
6
6
  const internal_js_1 = require("../common/internal.js");
7
7
  const settings_js_1 = require("../common/settings.js");
8
8
  const client_gen_js_1 = require("./client/client.gen.js");
@@ -66,8 +66,8 @@ class SandboxAction {
66
66
  return this.sandbox.forceUrl;
67
67
  const envVar = this.name.replace(/-/g, "_").toUpperCase();
68
68
  const envName = `BL_SANDBOX_${envVar}_URL`;
69
- if (process_1.env[envName]) {
70
- return process_1.env[envName];
69
+ if (env_js_1.env[envName]) {
70
+ return env_js_1.env[envName];
71
71
  }
72
72
  return null;
73
73
  }
@@ -1,7 +1,7 @@
1
1
  import { Sandbox } from "../../client/types.gen.js";
2
2
  import { SandboxAction } from "../action.js";
3
3
  import { Directory, SuccessResponse } from "../client/index.js";
4
- import { CopyResponse, SandboxFilesystemFile, ToolWithExecute, ToolWithoutExecute, WatchEvent } from "./types.js";
4
+ import { CopyResponse, SandboxFilesystemFile, WatchEvent } from "./types.js";
5
5
  export declare class SandboxFileSystem extends SandboxAction {
6
6
  constructor(sandbox: Sandbox);
7
7
  mkdir(path: string, permissions?: string): Promise<SuccessResponse>;
@@ -20,6 +20,4 @@ export declare class SandboxFileSystem extends SandboxAction {
20
20
  close: () => void;
21
21
  };
22
22
  private formatPath;
23
- get toolsWithoutExecute(): ToolWithoutExecute;
24
- get tools(): ToolWithExecute;
25
23
  }