@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 +1 -1
- package/dist/authentication/index.js +2 -4
- package/dist/cache/index.js +0 -1
- package/dist/common/env.js +6 -4
- package/dist/common/internal.js +1 -0
- package/dist/common/node.d.ts +2 -1
- package/dist/common/node.js +4 -1
- package/dist/jobs/batches.d.ts +32 -0
- package/dist/jobs/batches.js +40 -0
- package/dist/jobs/job.d.ts +33 -0
- package/dist/jobs/job.js +51 -0
- package/dist/jobs/jobs.js +1 -1
- package/dist/mcp/client.d.ts +2 -0
- package/dist/mcp/client.js +115 -52
- package/dist/sandbox/action.js +3 -3
- package/dist/sandbox/filesystem/filesystem.d.ts +1 -3
- package/dist/sandbox/filesystem/filesystem.js +0 -151
- package/dist/sandbox/filesystem/types.d.ts +0 -113
- package/dist/sandbox/filesystem/types.js +0 -24
- package/dist/sandbox/filesystem.d.ts +30 -0
- package/dist/sandbox/filesystem.js +207 -0
- package/dist/sandbox/network.d.ts +5 -0
- package/dist/sandbox/network.js +10 -0
- package/dist/sandbox/process/index.d.ts +0 -1
- package/dist/sandbox/process/index.js +0 -1
- package/dist/sandbox/process/process.d.ts +0 -3
- package/dist/sandbox/process/process.js +0 -128
- package/dist/sandbox/process.d.ts +23 -0
- package/dist/sandbox/process.js +138 -0
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +2 -2
- package/dist/tools/mcpTool.d.ts +3 -1
- package/dist/tools/mcpTool.js +16 -8
- package/package.json +1 -1
|
@@ -4,7 +4,6 @@ exports.SandboxProcess = void 0;
|
|
|
4
4
|
const settings_js_1 = require("../../common/settings.js");
|
|
5
5
|
const action_js_1 = require("../action.js");
|
|
6
6
|
const index_js_1 = require("../client/index.js");
|
|
7
|
-
const types_js_1 = require("./types.js");
|
|
8
7
|
class SandboxProcess extends action_js_1.SandboxAction {
|
|
9
8
|
constructor(sandbox) {
|
|
10
9
|
super(sandbox);
|
|
@@ -141,132 +140,5 @@ class SandboxProcess extends action_js_1.SandboxAction {
|
|
|
141
140
|
}
|
|
142
141
|
throw new Error("Unsupported log type");
|
|
143
142
|
}
|
|
144
|
-
get toolsWithoutExecute() {
|
|
145
|
-
return {
|
|
146
|
-
exec: {
|
|
147
|
-
description: "Execute a process in the sandbox",
|
|
148
|
-
parameters: types_js_1.ExecParamsSchema,
|
|
149
|
-
},
|
|
150
|
-
wait: {
|
|
151
|
-
description: "Wait for a process to finish by identifier",
|
|
152
|
-
parameters: types_js_1.WaitParamsSchema,
|
|
153
|
-
},
|
|
154
|
-
get: {
|
|
155
|
-
description: "Get process info by identifier",
|
|
156
|
-
parameters: types_js_1.GetParamsSchema,
|
|
157
|
-
},
|
|
158
|
-
list: {
|
|
159
|
-
description: "List all processes in the sandbox",
|
|
160
|
-
parameters: types_js_1.ListParamsSchema,
|
|
161
|
-
},
|
|
162
|
-
stop: {
|
|
163
|
-
description: "Stop a process by identifier",
|
|
164
|
-
parameters: types_js_1.StopParamsSchema,
|
|
165
|
-
},
|
|
166
|
-
kill: {
|
|
167
|
-
description: "Kill a process by identifier",
|
|
168
|
-
parameters: types_js_1.KillParamsSchema,
|
|
169
|
-
},
|
|
170
|
-
logs: {
|
|
171
|
-
description: "Get logs for a process by identifier",
|
|
172
|
-
parameters: types_js_1.LogsParamsSchema,
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
get tools() {
|
|
177
|
-
return {
|
|
178
|
-
exec: {
|
|
179
|
-
description: "Execute a process in the sandbox",
|
|
180
|
-
parameters: types_js_1.ExecParamsSchema,
|
|
181
|
-
execute: async (args) => {
|
|
182
|
-
try {
|
|
183
|
-
const result = await this.exec(args.process);
|
|
184
|
-
return JSON.stringify(result);
|
|
185
|
-
}
|
|
186
|
-
catch (e) {
|
|
187
|
-
return JSON.stringify({ message: e.message, process: args.process });
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
wait: {
|
|
192
|
-
description: "Wait for a process to finish by identifier",
|
|
193
|
-
parameters: types_js_1.WaitParamsSchema,
|
|
194
|
-
execute: async (args) => {
|
|
195
|
-
try {
|
|
196
|
-
const result = await this.wait(args.identifier, { maxWait: args.maxWait, interval: args.interval });
|
|
197
|
-
return JSON.stringify(result);
|
|
198
|
-
}
|
|
199
|
-
catch (e) {
|
|
200
|
-
return JSON.stringify({ message: e.message, identifier: args.identifier });
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
get: {
|
|
205
|
-
description: "Get process info by identifier",
|
|
206
|
-
parameters: types_js_1.GetParamsSchema,
|
|
207
|
-
execute: async (args) => {
|
|
208
|
-
try {
|
|
209
|
-
const result = await this.get(args.identifier);
|
|
210
|
-
return JSON.stringify(result);
|
|
211
|
-
}
|
|
212
|
-
catch (e) {
|
|
213
|
-
return JSON.stringify({ message: e.message, identifier: args.identifier });
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
list: {
|
|
218
|
-
description: "List all processes in the sandbox",
|
|
219
|
-
parameters: types_js_1.ListParamsSchema,
|
|
220
|
-
execute: async () => {
|
|
221
|
-
try {
|
|
222
|
-
const result = await this.list();
|
|
223
|
-
return JSON.stringify(result);
|
|
224
|
-
}
|
|
225
|
-
catch (e) {
|
|
226
|
-
return JSON.stringify({ message: e.message });
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
stop: {
|
|
231
|
-
description: "Stop a process by identifier",
|
|
232
|
-
parameters: types_js_1.StopParamsSchema,
|
|
233
|
-
execute: async (args) => {
|
|
234
|
-
try {
|
|
235
|
-
const result = await this.stop(args.identifier);
|
|
236
|
-
return JSON.stringify(result);
|
|
237
|
-
}
|
|
238
|
-
catch (e) {
|
|
239
|
-
return JSON.stringify({ message: e.message, identifier: args.identifier });
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
kill: {
|
|
244
|
-
description: "Kill a process by identifier",
|
|
245
|
-
parameters: types_js_1.KillParamsSchema,
|
|
246
|
-
execute: async (args) => {
|
|
247
|
-
try {
|
|
248
|
-
const result = await this.kill(args.identifier);
|
|
249
|
-
return JSON.stringify(result);
|
|
250
|
-
}
|
|
251
|
-
catch (e) {
|
|
252
|
-
return JSON.stringify({ message: e.message, identifier: args.identifier });
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
logs: {
|
|
257
|
-
description: "Get logs for a process by identifier",
|
|
258
|
-
parameters: types_js_1.LogsParamsSchema,
|
|
259
|
-
execute: async (args) => {
|
|
260
|
-
try {
|
|
261
|
-
const result = await this.logs(args.identifier, args.type || "all");
|
|
262
|
-
return JSON.stringify({ logs: result });
|
|
263
|
-
}
|
|
264
|
-
catch (e) {
|
|
265
|
-
return JSON.stringify({ message: e.message, identifier: args.identifier });
|
|
266
|
-
}
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
143
|
}
|
|
272
144
|
exports.SandboxProcess = SandboxProcess;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Sandbox } from "../client/types.gen.js";
|
|
2
|
+
import { SandboxAction } from "./action.js";
|
|
3
|
+
import { DeleteProcessByIdentifierKillResponse, DeleteProcessByIdentifierResponse, GetProcessByIdentifierResponse, GetProcessResponse, PostProcessResponse, ProcessRequest } from "./client/index.js";
|
|
4
|
+
export declare class SandboxProcess extends SandboxAction {
|
|
5
|
+
constructor(sandbox: Sandbox);
|
|
6
|
+
streamLogs(identifier: string, options: {
|
|
7
|
+
onLog?: (log: string) => void;
|
|
8
|
+
onStdout?: (stdout: string) => void;
|
|
9
|
+
onStderr?: (stderr: string) => void;
|
|
10
|
+
}): {
|
|
11
|
+
close: () => void;
|
|
12
|
+
};
|
|
13
|
+
exec(process: ProcessRequest): Promise<PostProcessResponse>;
|
|
14
|
+
wait(identifier: string, { maxWait, interval }?: {
|
|
15
|
+
maxWait?: number;
|
|
16
|
+
interval?: number;
|
|
17
|
+
}): Promise<GetProcessByIdentifierResponse>;
|
|
18
|
+
get(identifier: string): Promise<GetProcessByIdentifierResponse>;
|
|
19
|
+
list(): Promise<GetProcessResponse>;
|
|
20
|
+
stop(identifier: string): Promise<DeleteProcessByIdentifierResponse>;
|
|
21
|
+
kill(identifier: string): Promise<DeleteProcessByIdentifierKillResponse>;
|
|
22
|
+
logs(identifier: string, type?: "stdout" | "stderr"): Promise<string>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxProcess = void 0;
|
|
4
|
+
const settings_js_1 = require("../common/settings.js");
|
|
5
|
+
const action_js_1 = require("./action.js");
|
|
6
|
+
const index_js_1 = require("./client/index.js");
|
|
7
|
+
class SandboxProcess extends action_js_1.SandboxAction {
|
|
8
|
+
constructor(sandbox) {
|
|
9
|
+
super(sandbox);
|
|
10
|
+
}
|
|
11
|
+
streamLogs(identifier, options) {
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
(async () => {
|
|
14
|
+
try {
|
|
15
|
+
const headers = this.sandbox.forceUrl ? this.sandbox.headers : settings_js_1.settings.headers;
|
|
16
|
+
const stream = await fetch(`${this.url}/process/${identifier}/logs/stream`, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
signal: controller.signal,
|
|
19
|
+
headers,
|
|
20
|
+
});
|
|
21
|
+
if (stream.status !== 200) {
|
|
22
|
+
throw new Error(`Failed to stream logs: ${await stream.text()}`);
|
|
23
|
+
}
|
|
24
|
+
if (!stream.body)
|
|
25
|
+
throw new Error('No stream body');
|
|
26
|
+
const reader = stream.body.getReader();
|
|
27
|
+
const decoder = new TextDecoder();
|
|
28
|
+
let buffer = '';
|
|
29
|
+
while (true) {
|
|
30
|
+
const { done, value } = await reader.read();
|
|
31
|
+
if (done)
|
|
32
|
+
break;
|
|
33
|
+
buffer += decoder.decode(value, { stream: true });
|
|
34
|
+
let lines = buffer.split(/\r?\n/);
|
|
35
|
+
buffer = lines.pop();
|
|
36
|
+
for (const line of lines) {
|
|
37
|
+
if (line.startsWith('stdout:')) {
|
|
38
|
+
options.onStdout?.(line.slice(7));
|
|
39
|
+
options.onLog?.(line.slice(7));
|
|
40
|
+
}
|
|
41
|
+
else if (line.startsWith('stderr:')) {
|
|
42
|
+
options.onStderr?.(line.slice(7));
|
|
43
|
+
options.onLog?.(line.slice(7));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
options.onLog?.(line);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
if (err && err.name !== 'AbortError') {
|
|
53
|
+
console.error("Stream error:", err);
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
return {
|
|
59
|
+
close: () => controller.abort(),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async exec(process) {
|
|
63
|
+
const { response, data, error } = await (0, index_js_1.postProcess)({
|
|
64
|
+
body: process,
|
|
65
|
+
baseUrl: this.url,
|
|
66
|
+
client: this.client,
|
|
67
|
+
});
|
|
68
|
+
this.handleResponseError(response, data, error);
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
async wait(identifier, { maxWait = 60000, interval = 1000 } = {}) {
|
|
72
|
+
const startTime = Date.now();
|
|
73
|
+
let status = "running";
|
|
74
|
+
let data = await this.get(identifier);
|
|
75
|
+
while (status === "running") {
|
|
76
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
77
|
+
try {
|
|
78
|
+
data = await this.get(identifier);
|
|
79
|
+
status = data.status ?? "running";
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
if (Date.now() - startTime > maxWait) {
|
|
85
|
+
throw new Error("Process did not finish in time");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
async get(identifier) {
|
|
91
|
+
const { response, data, error } = await (0, index_js_1.getProcessByIdentifier)({
|
|
92
|
+
path: { identifier },
|
|
93
|
+
baseUrl: this.url,
|
|
94
|
+
client: this.client,
|
|
95
|
+
});
|
|
96
|
+
this.handleResponseError(response, data, error);
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
async list() {
|
|
100
|
+
const { response, data, error } = await (0, index_js_1.getProcess)({
|
|
101
|
+
baseUrl: this.url,
|
|
102
|
+
client: this.client,
|
|
103
|
+
});
|
|
104
|
+
this.handleResponseError(response, data, error);
|
|
105
|
+
return data;
|
|
106
|
+
}
|
|
107
|
+
async stop(identifier) {
|
|
108
|
+
const { response, data, error } = await (0, index_js_1.deleteProcessByIdentifier)({
|
|
109
|
+
path: { identifier },
|
|
110
|
+
baseUrl: this.url,
|
|
111
|
+
client: this.client,
|
|
112
|
+
});
|
|
113
|
+
this.handleResponseError(response, data, error);
|
|
114
|
+
return data;
|
|
115
|
+
}
|
|
116
|
+
async kill(identifier) {
|
|
117
|
+
const { response, data, error } = await (0, index_js_1.deleteProcessByIdentifierKill)({
|
|
118
|
+
path: { identifier },
|
|
119
|
+
baseUrl: this.url,
|
|
120
|
+
client: this.client,
|
|
121
|
+
});
|
|
122
|
+
this.handleResponseError(response, data, error);
|
|
123
|
+
return data;
|
|
124
|
+
}
|
|
125
|
+
async logs(identifier, type = "stdout") {
|
|
126
|
+
const { response, data, error } = await (0, index_js_1.getProcessByIdentifierLogs)({
|
|
127
|
+
path: { identifier },
|
|
128
|
+
baseUrl: this.url,
|
|
129
|
+
client: this.client,
|
|
130
|
+
});
|
|
131
|
+
this.handleResponseError(response, data, error);
|
|
132
|
+
if (data && type in data) {
|
|
133
|
+
return data[type];
|
|
134
|
+
}
|
|
135
|
+
throw new Error("Unsupported log type");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.SandboxProcess = SandboxProcess;
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Function } from "../client/client.js";
|
|
2
2
|
import { Tool } from "./types.js";
|
|
3
|
-
export declare const getTool: (name: string) => Promise<Tool[]>;
|
|
3
|
+
export declare const getTool: (name: string, ms?: number) => Promise<Tool[]>;
|
|
4
4
|
export declare class BLTools {
|
|
5
5
|
toolNames: string[];
|
|
6
6
|
constructor(toolNames: string[]);
|
package/dist/tools/index.js
CHANGED
|
@@ -5,8 +5,8 @@ const index_js_1 = require("../cache/index.js");
|
|
|
5
5
|
const client_js_1 = require("../client/client.js");
|
|
6
6
|
const env_js_1 = require("../common/env.js");
|
|
7
7
|
const mcpTool_js_1 = require("./mcpTool.js");
|
|
8
|
-
const getTool = async (name) => {
|
|
9
|
-
return await (0, mcpTool_js_1.getMcpTool)(name);
|
|
8
|
+
const getTool = async (name, ms) => {
|
|
9
|
+
return await (0, mcpTool_js_1.getMcpTool)(name, ms);
|
|
10
10
|
};
|
|
11
11
|
exports.getTool = getTool;
|
|
12
12
|
class BLTools {
|
package/dist/tools/mcpTool.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Tool } from "./types.js";
|
|
2
2
|
export declare class McpTool {
|
|
3
3
|
private name;
|
|
4
|
+
private type;
|
|
5
|
+
private pluralType;
|
|
4
6
|
private client;
|
|
5
7
|
private transport?;
|
|
6
8
|
private timer?;
|
|
@@ -18,4 +20,4 @@ export declare class McpTool {
|
|
|
18
20
|
listTools(): Promise<Tool[]>;
|
|
19
21
|
call(toolName: string, args: Record<string, unknown> | undefined): Promise<unknown>;
|
|
20
22
|
}
|
|
21
|
-
export declare const getMcpTool: (name: string) => Promise<Tool[]>;
|
|
23
|
+
export declare const getMcpTool: (name: string, ms?: number) => Promise<Tool[]>;
|
package/dist/tools/mcpTool.js
CHANGED
|
@@ -13,6 +13,8 @@ const zodSchema_js_1 = require("./zodSchema.js");
|
|
|
13
13
|
const McpToolCache = new Map();
|
|
14
14
|
class McpTool {
|
|
15
15
|
name;
|
|
16
|
+
type;
|
|
17
|
+
pluralType;
|
|
16
18
|
client;
|
|
17
19
|
transport;
|
|
18
20
|
timer;
|
|
@@ -20,6 +22,13 @@ class McpTool {
|
|
|
20
22
|
startPromise;
|
|
21
23
|
constructor(name, ms = 5000) {
|
|
22
24
|
this.name = name;
|
|
25
|
+
this.type = "function";
|
|
26
|
+
this.pluralType = "functions";
|
|
27
|
+
if (name.startsWith("sandbox/") || name.startsWith("sandboxes/")) {
|
|
28
|
+
this.name = name.split("/")[1];
|
|
29
|
+
this.type = "sandbox";
|
|
30
|
+
this.pluralType = "sandboxes";
|
|
31
|
+
}
|
|
23
32
|
if (env_js_1.env.BL_CLOUD) {
|
|
24
33
|
this.ms = 0;
|
|
25
34
|
}
|
|
@@ -42,16 +51,16 @@ class McpTool {
|
|
|
42
51
|
return null;
|
|
43
52
|
}
|
|
44
53
|
get externalUrl() {
|
|
45
|
-
return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}
|
|
54
|
+
return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/${this.pluralType}/${this.name}`);
|
|
46
55
|
}
|
|
47
56
|
get internalUrl() {
|
|
48
|
-
const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace,
|
|
57
|
+
const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, this.type, this.name);
|
|
49
58
|
return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
|
|
50
59
|
}
|
|
51
60
|
get forcedUrl() {
|
|
52
61
|
const envVar = this.name.replace(/-/g, "_").toUpperCase();
|
|
53
|
-
if (env_js_1.env[`
|
|
54
|
-
return new URL(env_js_1.env[`
|
|
62
|
+
if (env_js_1.env[`BL_${this.pluralType.toUpperCase()}_${envVar}_URL`]) {
|
|
63
|
+
return new URL(env_js_1.env[`BL_${this.pluralType.toUpperCase()}_${envVar}_URL`]);
|
|
55
64
|
}
|
|
56
65
|
return null;
|
|
57
66
|
}
|
|
@@ -68,7 +77,7 @@ class McpTool {
|
|
|
68
77
|
this.startPromise = this.startPromise || (async () => {
|
|
69
78
|
await (0, index_js_2.authenticate)();
|
|
70
79
|
try {
|
|
71
|
-
logger_js_1.logger.debug(`MCP:${this.name}:Connecting`);
|
|
80
|
+
logger_js_1.logger.debug(`MCP:${this.name}:Connecting::${this.url.toString()}`);
|
|
72
81
|
this.transport = new client_js_1.BlaxelMcpClientTransport(this.url.toString(), settings_js_1.settings.headers);
|
|
73
82
|
await this.client.connect(this.transport);
|
|
74
83
|
logger_js_1.logger.debug(`MCP:${this.name}:Connected`);
|
|
@@ -121,7 +130,6 @@ class McpTool {
|
|
|
121
130
|
logger_js_1.logger.debug(`MCP:${this.name}:Listing tools`);
|
|
122
131
|
await this.start();
|
|
123
132
|
const { tools } = (await this.client.listTools());
|
|
124
|
-
logger_js_1.logger.debug(`MCP:${this.name}:Listed tools result`, tools);
|
|
125
133
|
await this.close();
|
|
126
134
|
const result = tools.map((tool) => {
|
|
127
135
|
return {
|
|
@@ -181,11 +189,11 @@ class McpTool {
|
|
|
181
189
|
}
|
|
182
190
|
}
|
|
183
191
|
exports.McpTool = McpTool;
|
|
184
|
-
const getMcpTool = async (name) => {
|
|
192
|
+
const getMcpTool = async (name, ms) => {
|
|
185
193
|
let tool = McpToolCache.get(name);
|
|
186
194
|
if (!tool) {
|
|
187
195
|
logger_js_1.logger.debug(`MCP:${name}:Creating new tool`);
|
|
188
|
-
tool = new McpTool(name);
|
|
196
|
+
tool = new McpTool(name, ms);
|
|
189
197
|
McpToolCache.set(name, tool);
|
|
190
198
|
}
|
|
191
199
|
return await tool.listTools();
|