@blaxel/core 0.2.50-dev.215 → 0.2.50
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/agents/index.js +2 -2
- package/dist/cjs/authentication/clientcredentials.js +1 -4
- package/dist/cjs/common/internal.js +0 -40
- package/dist/cjs/common/settings.js +2 -5
- package/dist/cjs/jobs/jobs.js +2 -2
- package/dist/cjs/jobs/start.js +1 -32
- package/dist/cjs/sandbox/action.js +2 -1
- package/dist/cjs/sandbox/sandbox.js +10 -67
- package/dist/cjs/tools/mcpTool.js +2 -2
- package/dist/cjs/types/common/internal.d.ts +0 -2
- package/dist/cjs/types/common/settings.d.ts +0 -1
- package/dist/cjs/types/sandbox/sandbox.d.ts +6 -12
- package/dist/cjs/types/sandbox/types.d.ts +0 -3
- package/dist/cjs-browser/.tsbuildinfo +1 -1
- package/dist/cjs-browser/agents/index.js +2 -2
- package/dist/cjs-browser/authentication/clientcredentials.js +1 -4
- package/dist/cjs-browser/common/internal.js +0 -40
- package/dist/cjs-browser/common/settings.js +2 -5
- package/dist/cjs-browser/jobs/jobs.js +2 -2
- package/dist/cjs-browser/jobs/start.js +1 -32
- package/dist/cjs-browser/sandbox/action.js +2 -1
- package/dist/cjs-browser/sandbox/sandbox.js +10 -67
- package/dist/cjs-browser/tools/mcpTool.js +2 -2
- package/dist/cjs-browser/types/common/internal.d.ts +0 -2
- package/dist/cjs-browser/types/common/settings.d.ts +0 -1
- package/dist/cjs-browser/types/sandbox/sandbox.d.ts +6 -12
- package/dist/cjs-browser/types/sandbox/types.d.ts +0 -3
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/agents/index.js +3 -3
- package/dist/esm/authentication/clientcredentials.js +1 -4
- package/dist/esm/common/internal.js +0 -38
- package/dist/esm/common/settings.js +2 -5
- package/dist/esm/jobs/jobs.js +3 -3
- package/dist/esm/jobs/start.js +1 -32
- package/dist/esm/sandbox/action.js +3 -2
- package/dist/esm/sandbox/sandbox.js +10 -67
- package/dist/esm/tools/mcpTool.js +3 -3
- package/dist/esm-browser/.tsbuildinfo +1 -1
- package/dist/esm-browser/agents/index.js +3 -3
- package/dist/esm-browser/authentication/clientcredentials.js +1 -4
- package/dist/esm-browser/common/internal.js +0 -38
- package/dist/esm-browser/common/settings.js +2 -5
- package/dist/esm-browser/jobs/jobs.js +3 -3
- package/dist/esm-browser/jobs/start.js +1 -32
- package/dist/esm-browser/sandbox/action.js +3 -2
- package/dist/esm-browser/sandbox/sandbox.js +10 -67
- package/dist/esm-browser/tools/mcpTool.js +3 -3
- package/package.json +2 -2
- package/dist/cjs/sandbox/codegen/codegen-ws.js +0 -30
- package/dist/cjs/sandbox/filesystem/filesystem-ws.js +0 -106
- package/dist/cjs/sandbox/network/network-ws.js +0 -12
- package/dist/cjs/sandbox/process/process-ws.js +0 -139
- package/dist/cjs/sandbox/websocket/client.js +0 -269
- package/dist/cjs/sandbox/websocket/index.js +0 -17
- package/dist/cjs/types/sandbox/codegen/codegen-ws.d.ts +0 -10
- package/dist/cjs/types/sandbox/filesystem/filesystem-ws.d.ts +0 -35
- package/dist/cjs/types/sandbox/network/network-ws.d.ts +0 -7
- package/dist/cjs/types/sandbox/process/process-ws.d.ts +0 -27
- package/dist/cjs/types/sandbox/websocket/client.d.ts +0 -48
- package/dist/cjs/types/sandbox/websocket/index.d.ts +0 -1
- package/dist/cjs-browser/sandbox/codegen/codegen-ws.js +0 -30
- package/dist/cjs-browser/sandbox/filesystem/filesystem-ws.js +0 -106
- package/dist/cjs-browser/sandbox/network/network-ws.js +0 -12
- package/dist/cjs-browser/sandbox/process/process-ws.js +0 -139
- package/dist/cjs-browser/sandbox/websocket/client.js +0 -269
- package/dist/cjs-browser/sandbox/websocket/index.js +0 -17
- package/dist/cjs-browser/types/sandbox/codegen/codegen-ws.d.ts +0 -10
- package/dist/cjs-browser/types/sandbox/filesystem/filesystem-ws.d.ts +0 -35
- package/dist/cjs-browser/types/sandbox/network/network-ws.d.ts +0 -7
- package/dist/cjs-browser/types/sandbox/process/process-ws.d.ts +0 -27
- package/dist/cjs-browser/types/sandbox/websocket/client.d.ts +0 -48
- package/dist/cjs-browser/types/sandbox/websocket/index.d.ts +0 -1
- package/dist/esm/sandbox/codegen/codegen-ws.js +0 -26
- package/dist/esm/sandbox/filesystem/filesystem-ws.js +0 -102
- package/dist/esm/sandbox/network/network-ws.js +0 -8
- package/dist/esm/sandbox/process/process-ws.js +0 -135
- package/dist/esm/sandbox/websocket/client.js +0 -265
- package/dist/esm/sandbox/websocket/index.js +0 -1
- package/dist/esm-browser/sandbox/codegen/codegen-ws.js +0 -26
- package/dist/esm-browser/sandbox/filesystem/filesystem-ws.js +0 -102
- package/dist/esm-browser/sandbox/network/network-ws.js +0 -8
- package/dist/esm-browser/sandbox/process/process-ws.js +0 -135
- package/dist/esm-browser/sandbox/websocket/client.js +0 -265
- package/dist/esm-browser/sandbox/websocket/index.js +0 -1
|
@@ -180,41 +180,3 @@ export function getForcedUrl(type, name) {
|
|
|
180
180
|
}
|
|
181
181
|
return null;
|
|
182
182
|
}
|
|
183
|
-
export function getWorkloadTypeShort(type) {
|
|
184
|
-
const lowerType = type.toLowerCase();
|
|
185
|
-
switch (lowerType) {
|
|
186
|
-
case 'agent':
|
|
187
|
-
case 'agents':
|
|
188
|
-
return 'agt';
|
|
189
|
-
case 'mcp':
|
|
190
|
-
case 'mcps':
|
|
191
|
-
case 'function':
|
|
192
|
-
case 'functions':
|
|
193
|
-
return 'mcp';
|
|
194
|
-
case 'sandbox':
|
|
195
|
-
case 'sandboxes':
|
|
196
|
-
return 'sbx';
|
|
197
|
-
case 'job':
|
|
198
|
-
case 'jobs':
|
|
199
|
-
return 'job';
|
|
200
|
-
case 'model':
|
|
201
|
-
case 'models':
|
|
202
|
-
return 'mdl';
|
|
203
|
-
default:
|
|
204
|
-
// fallback to first 3 letters of type
|
|
205
|
-
return lowerType.substring(0, 3);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
export function generateInternalUrl(workspace, type, name, env, protocol, hostname, blCloud, workspaceId) {
|
|
209
|
-
if (blCloud && workspaceId) {
|
|
210
|
-
// New cloud format: bl-ENV-WORKLOAD_CALLED_NAME-WORKLOAD_TYPE_SHORT-WORKSPACE_ID
|
|
211
|
-
const workloadTypeShort = getWorkloadTypeShort(type);
|
|
212
|
-
const subdomain = `bl-${env}-${name}-${workloadTypeShort}-${workspaceId}`;
|
|
213
|
-
return `${protocol}://${subdomain}.${hostname}`;
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
// Legacy format: bl-ENV-HASH.internalhostname
|
|
217
|
-
const hash = getGlobalUniqueHash(workspace, type, name);
|
|
218
|
-
return `${protocol}://bl-${env}-${hash}.${hostname}`;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
@@ -7,7 +7,7 @@ function getPackageVersion() {
|
|
|
7
7
|
if (typeof require !== "undefined") {
|
|
8
8
|
// Try to require package.json (Node.js only, gracefully fails in browser)
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
10
|
-
const packageJson = {"version":"0.2.50
|
|
10
|
+
const packageJson = {"version":"0.2.50","commit":"a4290fe191702ee91d8ae3fcc45c094d86be553c"};
|
|
11
11
|
return packageJson.version || "unknown";
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
@@ -59,7 +59,7 @@ function getCommitHash() {
|
|
|
59
59
|
if (typeof require !== "undefined") {
|
|
60
60
|
// Try to require package.json and look for commit field (set during build)
|
|
61
61
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
62
|
-
const packageJson = {"version":"0.2.50
|
|
62
|
+
const packageJson = {"version":"0.2.50","commit":"a4290fe191702ee91d8ae3fcc45c094d86be553c"};
|
|
63
63
|
// Check for commit in various possible locations
|
|
64
64
|
const commit = packageJson.commit || packageJson.buildInfo?.commit;
|
|
65
65
|
if (commit) {
|
|
@@ -162,9 +162,6 @@ class Settings {
|
|
|
162
162
|
get blCloud() {
|
|
163
163
|
return env.BL_CLOUD === "true";
|
|
164
164
|
}
|
|
165
|
-
get workspaceId() {
|
|
166
|
-
return env.BL_WORKSPACE_ID || "";
|
|
167
|
-
}
|
|
168
165
|
get generation() {
|
|
169
166
|
return env.BL_GENERATION || "";
|
|
170
167
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
|
|
2
2
|
import { logger } from "../common/logger.js";
|
|
3
3
|
import { settings } from "../common/settings.js";
|
|
4
4
|
import { startSpan } from '../telemetry/telemetry.js';
|
|
@@ -17,8 +17,8 @@ class BlJob {
|
|
|
17
17
|
return new URL(`${settings.runUrl}/${settings.workspace}/jobs/${this.jobName}`);
|
|
18
18
|
}
|
|
19
19
|
get internalUrl() {
|
|
20
|
-
const
|
|
21
|
-
return new URL(
|
|
20
|
+
const hash = getGlobalUniqueHash(settings.workspace, "job", this.jobName);
|
|
21
|
+
return new URL(`${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`);
|
|
22
22
|
}
|
|
23
23
|
get forcedUrl() {
|
|
24
24
|
return getForcedUrl('job', this.jobName);
|
|
@@ -2,43 +2,12 @@ import { authenticate } from '../common/autoload.js';
|
|
|
2
2
|
import { env } from '../common/env.js';
|
|
3
3
|
import { flush } from '../telemetry/telemetry.js';
|
|
4
4
|
class BlJobWrapper {
|
|
5
|
-
async fetchWithRetry(url, maxRetries = 3) {
|
|
6
|
-
let lastError;
|
|
7
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
8
|
-
try {
|
|
9
|
-
const response = await fetch(url);
|
|
10
|
-
// If the response is successful, return it
|
|
11
|
-
if (response.ok) {
|
|
12
|
-
return response;
|
|
13
|
-
}
|
|
14
|
-
// If it's not the last attempt and the status is retriable, retry
|
|
15
|
-
if (attempt < maxRetries && (response.status >= 500 || response.status === 429)) {
|
|
16
|
-
lastError = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
// For non-retriable errors or last attempt, return the response
|
|
20
|
-
return response;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
25
|
-
// If this is the last attempt, throw the error
|
|
26
|
-
if (attempt === maxRetries) {
|
|
27
|
-
throw lastError;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// Calculate exponential backoff delay: 2^attempt * 1000ms (1s, 2s, 4s)
|
|
31
|
-
const delay = Math.pow(2, attempt) * 1000;
|
|
32
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
33
|
-
}
|
|
34
|
-
throw lastError || new Error('Failed to fetch after retries');
|
|
35
|
-
}
|
|
36
5
|
async getArguments() {
|
|
37
6
|
if (!env.BL_EXECUTION_DATA_URL) {
|
|
38
7
|
const args = this.parseCommandLineArgs();
|
|
39
8
|
return args;
|
|
40
9
|
}
|
|
41
|
-
const response = await
|
|
10
|
+
const response = await fetch(env.BL_EXECUTION_DATA_URL);
|
|
42
11
|
const data = await response.json();
|
|
43
12
|
return data.tasks[this.index] ?? {};
|
|
44
13
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createClient } from "@hey-api/client-fetch";
|
|
2
|
-
import {
|
|
2
|
+
import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
|
|
3
3
|
import { settings } from "../common/settings.js";
|
|
4
4
|
import { client as defaultClient } from "./client/client.gen.js";
|
|
5
5
|
export class ResponseError extends Error {
|
|
@@ -44,7 +44,8 @@ export class SandboxAction {
|
|
|
44
44
|
return this.sandbox.metadata?.url ?? `${settings.runUrl}/${settings.workspace}/sandboxes/${this.name}`;
|
|
45
45
|
}
|
|
46
46
|
get internalUrl() {
|
|
47
|
-
|
|
47
|
+
const hash = getGlobalUniqueHash(settings.workspace, "sandbox", this.name);
|
|
48
|
+
return `${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`;
|
|
48
49
|
}
|
|
49
50
|
get client() {
|
|
50
51
|
if (this.sandbox.forceUrl) {
|
|
@@ -2,16 +2,11 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
2
2
|
import { createSandbox, deleteSandbox, getSandbox, listSandboxes, updateSandbox } from "../client/index.js";
|
|
3
3
|
import { logger } from "../common/logger.js";
|
|
4
4
|
import { SandboxFileSystem } from "./filesystem/index.js";
|
|
5
|
-
import { SandboxFileSystemWebSocket } from "./filesystem/filesystem-ws.js";
|
|
6
5
|
import { SandboxNetwork } from "./network/index.js";
|
|
7
|
-
import { SandboxNetworkWebSocket } from "./network/network-ws.js";
|
|
8
6
|
import { SandboxPreviews } from "./preview.js";
|
|
9
7
|
import { SandboxProcess } from "./process/index.js";
|
|
10
|
-
import { SandboxProcessWebSocket } from "./process/process-ws.js";
|
|
11
8
|
import { SandboxCodegen } from "./codegen/index.js";
|
|
12
|
-
import { SandboxCodegenWebSocket } from "./codegen/codegen-ws.js";
|
|
13
9
|
import { SandboxSessions } from "./session.js";
|
|
14
|
-
import { WebSocketClient } from "./websocket/index.js";
|
|
15
10
|
import { normalizeEnvs, normalizePorts, normalizeVolumes } from "./types.js";
|
|
16
11
|
export class SandboxInstance {
|
|
17
12
|
sandbox;
|
|
@@ -21,32 +16,14 @@ export class SandboxInstance {
|
|
|
21
16
|
previews;
|
|
22
17
|
sessions;
|
|
23
18
|
codegen;
|
|
24
|
-
wsClient;
|
|
25
19
|
constructor(sandbox) {
|
|
26
20
|
this.sandbox = sandbox;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.wsClient = new WebSocketClient({
|
|
31
|
-
url,
|
|
32
|
-
headers: sandbox.headers,
|
|
33
|
-
});
|
|
34
|
-
// Initialize WebSocket-based action handlers
|
|
35
|
-
this.process = new SandboxProcessWebSocket(sandbox, this.wsClient);
|
|
36
|
-
this.fs = new SandboxFileSystemWebSocket(sandbox, this.process, this.wsClient);
|
|
37
|
-
this.network = new SandboxNetworkWebSocket(sandbox, this.wsClient);
|
|
38
|
-
this.codegen = new SandboxCodegenWebSocket(sandbox, this.wsClient);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
// Default to HTTP-based action handlers
|
|
42
|
-
this.process = new SandboxProcess(sandbox);
|
|
43
|
-
this.fs = new SandboxFileSystem(sandbox, this.process);
|
|
44
|
-
this.network = new SandboxNetwork(sandbox);
|
|
45
|
-
this.codegen = new SandboxCodegen(sandbox);
|
|
46
|
-
}
|
|
47
|
-
// These are always HTTP-based
|
|
21
|
+
this.process = new SandboxProcess(sandbox);
|
|
22
|
+
this.fs = new SandboxFileSystem(sandbox, this.process);
|
|
23
|
+
this.network = new SandboxNetwork(sandbox);
|
|
48
24
|
this.previews = new SandboxPreviews(sandbox);
|
|
49
25
|
this.sessions = new SandboxSessions(sandbox);
|
|
26
|
+
this.codegen = new SandboxCodegen(sandbox);
|
|
50
27
|
}
|
|
51
28
|
get metadata() {
|
|
52
29
|
return this.sandbox.metadata;
|
|
@@ -65,17 +42,10 @@ export class SandboxInstance {
|
|
|
65
42
|
logger.warn("⚠️ Warning: sandbox.wait() is deprecated. You don't need to wait for the sandbox to be deployed anymore.");
|
|
66
43
|
return this;
|
|
67
44
|
}
|
|
68
|
-
closeConnection() {
|
|
69
|
-
if (this.wsClient) {
|
|
70
|
-
this.wsClient.close();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
45
|
static async create(sandbox, { safe = true } = {}) {
|
|
74
46
|
const defaultName = `sandbox-${uuidv4().replace(/-/g, '').substring(0, 8)}`;
|
|
75
47
|
const defaultImage = `blaxel/base-image:latest`;
|
|
76
48
|
const defaultMemory = 4096;
|
|
77
|
-
// Store connection type if provided
|
|
78
|
-
let connectionType;
|
|
79
49
|
// Handle SandboxCreateConfiguration or simple dict with name/image/memory/ports/envs/volumes keys
|
|
80
50
|
if (!sandbox ||
|
|
81
51
|
'name' in sandbox ||
|
|
@@ -85,8 +55,7 @@ export class SandboxInstance {
|
|
|
85
55
|
'envs' in sandbox ||
|
|
86
56
|
'volumes' in sandbox ||
|
|
87
57
|
'lifecycle' in sandbox ||
|
|
88
|
-
'snapshotEnabled' in sandbox
|
|
89
|
-
'connectionType' in sandbox) {
|
|
58
|
+
'snapshotEnabled' in sandbox) {
|
|
90
59
|
if (!sandbox)
|
|
91
60
|
sandbox = {};
|
|
92
61
|
if (!sandbox.name)
|
|
@@ -95,7 +64,6 @@ export class SandboxInstance {
|
|
|
95
64
|
sandbox.image = defaultImage;
|
|
96
65
|
if (!sandbox.memory)
|
|
97
66
|
sandbox.memory = defaultMemory;
|
|
98
|
-
connectionType = sandbox.connectionType;
|
|
99
67
|
const ports = normalizePorts(sandbox.ports);
|
|
100
68
|
const envs = normalizeEnvs(sandbox.envs);
|
|
101
69
|
const volumes = normalizeVolumes(sandbox.volumes);
|
|
@@ -144,16 +112,7 @@ export class SandboxInstance {
|
|
|
144
112
|
body: sandbox,
|
|
145
113
|
throwOnError: true,
|
|
146
114
|
});
|
|
147
|
-
|
|
148
|
-
const config = {
|
|
149
|
-
...data,
|
|
150
|
-
connectionType: connectionType || "http",
|
|
151
|
-
};
|
|
152
|
-
const instance = new SandboxInstance(config);
|
|
153
|
-
// Connect WebSocket if needed
|
|
154
|
-
if (connectionType === "websocket" && instance.wsClient) {
|
|
155
|
-
await instance.wsClient.connect();
|
|
156
|
-
}
|
|
115
|
+
const instance = new SandboxInstance(data);
|
|
157
116
|
// TODO remove this part once we have a better way to handle this
|
|
158
117
|
if (safe) {
|
|
159
118
|
try {
|
|
@@ -163,34 +122,20 @@ export class SandboxInstance {
|
|
|
163
122
|
}
|
|
164
123
|
return instance;
|
|
165
124
|
}
|
|
166
|
-
static async get(sandboxName
|
|
125
|
+
static async get(sandboxName) {
|
|
167
126
|
const { data } = await getSandbox({
|
|
168
127
|
path: {
|
|
169
128
|
sandboxName,
|
|
170
129
|
},
|
|
171
130
|
throwOnError: true,
|
|
172
131
|
});
|
|
173
|
-
|
|
174
|
-
const config = {
|
|
175
|
-
...data,
|
|
176
|
-
connectionType: connectionType || "http",
|
|
177
|
-
};
|
|
178
|
-
const instance = new SandboxInstance(config);
|
|
179
|
-
// Connect WebSocket if needed
|
|
180
|
-
if (connectionType === "websocket" && instance.wsClient) {
|
|
181
|
-
await instance.wsClient.connect();
|
|
182
|
-
}
|
|
183
|
-
return instance;
|
|
132
|
+
return new SandboxInstance(data);
|
|
184
133
|
}
|
|
185
134
|
static async list() {
|
|
186
135
|
const { data } = await listSandboxes({ throwOnError: true });
|
|
187
136
|
return data.map((sandbox) => new SandboxInstance(sandbox));
|
|
188
137
|
}
|
|
189
|
-
static async delete(sandboxName
|
|
190
|
-
// Close WebSocket connection if instance is provided
|
|
191
|
-
if (instance && instance.wsClient) {
|
|
192
|
-
instance.closeConnection();
|
|
193
|
-
}
|
|
138
|
+
static async delete(sandboxName) {
|
|
194
139
|
const { data } = await deleteSandbox({
|
|
195
140
|
path: {
|
|
196
141
|
sandboxName,
|
|
@@ -220,10 +165,8 @@ export class SandboxInstance {
|
|
|
220
165
|
if (!name) {
|
|
221
166
|
throw new Error("Sandbox name is required");
|
|
222
167
|
}
|
|
223
|
-
// Get connection type if specified
|
|
224
|
-
const connectionType = 'connectionType' in sandbox ? sandbox.connectionType : undefined;
|
|
225
168
|
// Get the existing sandbox to check its status
|
|
226
|
-
const sandboxInstance = await SandboxInstance.get(name
|
|
169
|
+
const sandboxInstance = await SandboxInstance.get(name);
|
|
227
170
|
// If the sandbox is TERMINATED, treat it as not existing
|
|
228
171
|
if (sandboxInstance.status === "TERMINATED") {
|
|
229
172
|
// Create a new sandbox - backend will handle cleanup of the terminated one
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client as ModelContextProtocolClient } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { env } from "../common/env.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
|
|
4
4
|
import { logger } from "../common/logger.js";
|
|
5
5
|
import { settings } from "../common/settings.js";
|
|
6
6
|
import { authenticate } from "../index.js";
|
|
@@ -51,8 +51,8 @@ export class McpTool {
|
|
|
51
51
|
return new URL(`${settings.runUrl}/${settings.workspace}/${this.pluralType}/${this.name}`);
|
|
52
52
|
}
|
|
53
53
|
get internalUrl() {
|
|
54
|
-
const
|
|
55
|
-
return new URL(
|
|
54
|
+
const hash = getGlobalUniqueHash(settings.workspace, this.type, this.name);
|
|
55
|
+
return new URL(`${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`);
|
|
56
56
|
}
|
|
57
57
|
get forcedUrl() {
|
|
58
58
|
return getForcedUrl(this.type, this.name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaxel/core",
|
|
3
|
-
"version": "0.2.50
|
|
3
|
+
"version": "0.2.50",
|
|
4
4
|
"description": "Blaxel Core SDK for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Blaxel, INC (https://blaxel.ai)",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"vite": "^5.2.0",
|
|
75
75
|
"vitest": "^1.5.0"
|
|
76
76
|
},
|
|
77
|
-
"commit": "
|
|
77
|
+
"commit": "a4290fe191702ee91d8ae3fcc45c094d86be553c",
|
|
78
78
|
"scripts": {
|
|
79
79
|
"lint": "eslint src/",
|
|
80
80
|
"dev": "tsc --watch",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SandboxCodegenWebSocket = void 0;
|
|
4
|
-
const action_js_1 = require("../action.js");
|
|
5
|
-
class SandboxCodegenWebSocket extends action_js_1.SandboxAction {
|
|
6
|
-
wsClient;
|
|
7
|
-
constructor(sandbox, wsClient) {
|
|
8
|
-
super(sandbox);
|
|
9
|
-
this.wsClient = wsClient;
|
|
10
|
-
}
|
|
11
|
-
async fastapply(path, codeEdit, model) {
|
|
12
|
-
const data = await this.wsClient.send("codegen:fastapply", {
|
|
13
|
-
path,
|
|
14
|
-
codeEdit,
|
|
15
|
-
model,
|
|
16
|
-
});
|
|
17
|
-
return data;
|
|
18
|
-
}
|
|
19
|
-
async reranking(path, query, scoreThreshold, tokenLimit, filePattern) {
|
|
20
|
-
const data = await this.wsClient.send("codegen:reranking", {
|
|
21
|
-
path,
|
|
22
|
-
query,
|
|
23
|
-
scoreThreshold,
|
|
24
|
-
tokenLimit,
|
|
25
|
-
filePattern,
|
|
26
|
-
});
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.SandboxCodegenWebSocket = SandboxCodegenWebSocket;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SandboxFileSystemWebSocket = void 0;
|
|
4
|
-
const action_js_1 = require("../action.js");
|
|
5
|
-
const filesystem_js_1 = require("./filesystem.js");
|
|
6
|
-
class SandboxFileSystemWebSocket extends action_js_1.SandboxAction {
|
|
7
|
-
process;
|
|
8
|
-
wsClient;
|
|
9
|
-
httpClient;
|
|
10
|
-
constructor(sandbox, process, wsClient) {
|
|
11
|
-
super(sandbox);
|
|
12
|
-
this.process = process;
|
|
13
|
-
this.wsClient = wsClient;
|
|
14
|
-
// Create HTTP client for fallback operations
|
|
15
|
-
this.httpClient = new filesystem_js_1.SandboxFileSystem(sandbox, process);
|
|
16
|
-
}
|
|
17
|
-
async mkdir(path, permissions = "0755") {
|
|
18
|
-
path = this.formatPath(path);
|
|
19
|
-
const data = await this.wsClient.send("filesystem:create", {
|
|
20
|
-
path,
|
|
21
|
-
isDirectory: true,
|
|
22
|
-
permissions,
|
|
23
|
-
});
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
async write(path, content) {
|
|
27
|
-
path = this.formatPath(path);
|
|
28
|
-
const data = await this.wsClient.send("filesystem:create", {
|
|
29
|
-
path,
|
|
30
|
-
content,
|
|
31
|
-
isDirectory: false,
|
|
32
|
-
});
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
async writeBinary(path, content) {
|
|
36
|
-
return this.httpClient.writeBinary(path, content);
|
|
37
|
-
}
|
|
38
|
-
async writeTree(files, destinationPath = null) {
|
|
39
|
-
const path = this.formatPath(destinationPath ?? "");
|
|
40
|
-
const filesMap = files.reduce((acc, file) => {
|
|
41
|
-
acc[file.path] = file.content;
|
|
42
|
-
return acc;
|
|
43
|
-
}, {});
|
|
44
|
-
const data = await this.wsClient.send("filesystem:tree:create", {
|
|
45
|
-
path,
|
|
46
|
-
files: filesMap,
|
|
47
|
-
});
|
|
48
|
-
return data;
|
|
49
|
-
}
|
|
50
|
-
async read(path) {
|
|
51
|
-
path = this.formatPath(path);
|
|
52
|
-
const data = await this.wsClient.send("filesystem:get", { path });
|
|
53
|
-
return data.content;
|
|
54
|
-
}
|
|
55
|
-
async readBinary(path) {
|
|
56
|
-
// Binary downloads are better suited for HTTP
|
|
57
|
-
// Fall back to HTTP client for binary operations
|
|
58
|
-
return this.httpClient.readBinary(path);
|
|
59
|
-
}
|
|
60
|
-
async download(src, destinationPath, options = {}) {
|
|
61
|
-
// File downloads are better suited for HTTP
|
|
62
|
-
// Fall back to HTTP client
|
|
63
|
-
return this.httpClient.download(src, destinationPath, options);
|
|
64
|
-
}
|
|
65
|
-
async rm(path, recursive = false) {
|
|
66
|
-
path = this.formatPath(path);
|
|
67
|
-
const data = await this.wsClient.send("filesystem:delete", {
|
|
68
|
-
path,
|
|
69
|
-
recursive,
|
|
70
|
-
});
|
|
71
|
-
return data;
|
|
72
|
-
}
|
|
73
|
-
async ls(path) {
|
|
74
|
-
path = this.formatPath(path);
|
|
75
|
-
const data = await this.wsClient.send("filesystem:get", { path });
|
|
76
|
-
return data;
|
|
77
|
-
}
|
|
78
|
-
async cp(source, destination, { maxWait = 180000 } = {}) {
|
|
79
|
-
// Copy operation is typically done via process execution
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
81
|
-
let process = await this.process.exec({
|
|
82
|
-
command: `cp -r ${source} ${destination}`,
|
|
83
|
-
});
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
|
|
85
|
-
process = await this.process.wait(process.pid, { maxWait, interval: 100 });
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
87
|
-
if (process.status === "failed") {
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
89
|
-
throw new Error(`Could not copy ${source} to ${destination} cause: ${process.logs}`);
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
message: "Files copied",
|
|
93
|
-
source,
|
|
94
|
-
destination,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
watch(path, callback, options) {
|
|
98
|
-
// File watching uses HTTP streaming which is already optimized
|
|
99
|
-
// Fall back to HTTP client
|
|
100
|
-
return this.httpClient.watch(path, callback, options);
|
|
101
|
-
}
|
|
102
|
-
formatPath(path) {
|
|
103
|
-
return path;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.SandboxFileSystemWebSocket = SandboxFileSystemWebSocket;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SandboxNetworkWebSocket = void 0;
|
|
4
|
-
const action_js_1 = require("../action.js");
|
|
5
|
-
class SandboxNetworkWebSocket extends action_js_1.SandboxAction {
|
|
6
|
-
wsClient;
|
|
7
|
-
constructor(sandbox, wsClient) {
|
|
8
|
-
super(sandbox);
|
|
9
|
-
this.wsClient = wsClient;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.SandboxNetworkWebSocket = SandboxNetworkWebSocket;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SandboxProcessWebSocket = void 0;
|
|
4
|
-
const action_js_1 = require("../action.js");
|
|
5
|
-
const process_js_1 = require("./process.js");
|
|
6
|
-
class SandboxProcessWebSocket extends action_js_1.SandboxAction {
|
|
7
|
-
wsClient;
|
|
8
|
-
httpClient;
|
|
9
|
-
constructor(sandbox, wsClient) {
|
|
10
|
-
super(sandbox);
|
|
11
|
-
this.wsClient = wsClient;
|
|
12
|
-
// Create HTTP client for fallback operations
|
|
13
|
-
this.httpClient = new process_js_1.SandboxProcess(sandbox);
|
|
14
|
-
}
|
|
15
|
-
streamLogs(identifier, options) {
|
|
16
|
-
const streamId = this.wsClient.sendStream("process:logs:stream:start", { identifier }, (data) => {
|
|
17
|
-
// Handle streaming log data
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
19
|
-
if (data && data.log) {
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
21
|
-
const log = String(data.log);
|
|
22
|
-
// Parse log format: "stdout:" or "stderr:" prefix
|
|
23
|
-
if (log.startsWith('stdout:')) {
|
|
24
|
-
const stdout = log.slice(7);
|
|
25
|
-
options.onStdout?.(stdout);
|
|
26
|
-
options.onLog?.(stdout);
|
|
27
|
-
}
|
|
28
|
-
else if (log.startsWith('stderr:')) {
|
|
29
|
-
const stderr = log.slice(7);
|
|
30
|
-
options.onStderr?.(stderr);
|
|
31
|
-
options.onLog?.(stderr);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
options.onLog?.(log);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}, () => {
|
|
38
|
-
// Stream ended
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
close: () => this.wsClient.cancelStream(streamId),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async exec(process) {
|
|
45
|
-
let onLog;
|
|
46
|
-
if ('onLog' in process && process.onLog) {
|
|
47
|
-
onLog = process.onLog;
|
|
48
|
-
delete process.onLog;
|
|
49
|
-
}
|
|
50
|
-
// Store original wait_for_completion setting
|
|
51
|
-
const shouldWaitForCompletion = process.waitForCompletion;
|
|
52
|
-
// Always start process without wait_for_completion to avoid server-side blocking
|
|
53
|
-
if (shouldWaitForCompletion && onLog) {
|
|
54
|
-
process.waitForCompletion = false;
|
|
55
|
-
}
|
|
56
|
-
const data = await this.wsClient.send("process:execute", process);
|
|
57
|
-
let result = data;
|
|
58
|
-
// Handle wait_for_completion with parallel log streaming
|
|
59
|
-
if (shouldWaitForCompletion && onLog) {
|
|
60
|
-
const streamControl = this.streamLogs(result.pid, { onLog });
|
|
61
|
-
try {
|
|
62
|
-
// Wait for process completion
|
|
63
|
-
result = await this.wait(result.pid, { interval: 500, maxWait: 1000 * 60 * 60 });
|
|
64
|
-
}
|
|
65
|
-
finally {
|
|
66
|
-
// Clean up log streaming
|
|
67
|
-
if (streamControl) {
|
|
68
|
-
streamControl.close();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// For non-blocking execution, set up log streaming immediately if requested
|
|
74
|
-
if (onLog) {
|
|
75
|
-
const streamControl = this.streamLogs(result.pid, { onLog });
|
|
76
|
-
return {
|
|
77
|
-
...result,
|
|
78
|
-
close() {
|
|
79
|
-
if (streamControl) {
|
|
80
|
-
streamControl.close();
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return { ...result, close: () => { } };
|
|
87
|
-
}
|
|
88
|
-
async wait(identifier, { maxWait = 60000, interval = 1000 } = {}) {
|
|
89
|
-
const startTime = Date.now();
|
|
90
|
-
let status = "running";
|
|
91
|
-
let data = await this.get(identifier);
|
|
92
|
-
while (status === "running") {
|
|
93
|
-
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
94
|
-
try {
|
|
95
|
-
data = await this.get(identifier);
|
|
96
|
-
status = data.status ?? "running";
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
if (Date.now() - startTime > maxWait) {
|
|
102
|
-
throw new Error("Process did not finish in time");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return data;
|
|
106
|
-
}
|
|
107
|
-
async get(identifier) {
|
|
108
|
-
const data = await this.wsClient.send("process:get", { identifier });
|
|
109
|
-
return data;
|
|
110
|
-
}
|
|
111
|
-
async list() {
|
|
112
|
-
const data = await this.wsClient.send("process:list", {});
|
|
113
|
-
return data.processes || [];
|
|
114
|
-
}
|
|
115
|
-
async stop(identifier) {
|
|
116
|
-
const data = await this.wsClient.send("process:stop", { identifier });
|
|
117
|
-
return data;
|
|
118
|
-
}
|
|
119
|
-
async kill(identifier) {
|
|
120
|
-
const data = await this.wsClient.send("process:kill", { identifier });
|
|
121
|
-
return data;
|
|
122
|
-
}
|
|
123
|
-
async logs(identifier, type = "all") {
|
|
124
|
-
const data = await this.wsClient.send("process:logs", {
|
|
125
|
-
identifier,
|
|
126
|
-
});
|
|
127
|
-
if (type === "all") {
|
|
128
|
-
return data.logs || "";
|
|
129
|
-
}
|
|
130
|
-
else if (type === "stdout") {
|
|
131
|
-
return data.stdout || "";
|
|
132
|
-
}
|
|
133
|
-
else if (type === "stderr") {
|
|
134
|
-
return data.stderr || "";
|
|
135
|
-
}
|
|
136
|
-
throw new Error("Unsupported log type");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.SandboxProcessWebSocket = SandboxProcessWebSocket;
|