@blaxel/core 0.2.50-dev.215 → 0.2.50-preview.115

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.
Files changed (85) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/agents/index.js +2 -2
  3. package/dist/cjs/authentication/clientcredentials.js +1 -4
  4. package/dist/cjs/common/internal.js +0 -40
  5. package/dist/cjs/common/settings.js +2 -5
  6. package/dist/cjs/jobs/jobs.js +2 -2
  7. package/dist/cjs/jobs/start.js +1 -32
  8. package/dist/cjs/sandbox/action.js +2 -1
  9. package/dist/cjs/sandbox/sandbox.js +10 -67
  10. package/dist/cjs/tools/mcpTool.js +2 -2
  11. package/dist/cjs/types/common/internal.d.ts +0 -2
  12. package/dist/cjs/types/common/settings.d.ts +0 -1
  13. package/dist/cjs/types/sandbox/sandbox.d.ts +6 -12
  14. package/dist/cjs/types/sandbox/types.d.ts +0 -3
  15. package/dist/cjs-browser/.tsbuildinfo +1 -1
  16. package/dist/cjs-browser/agents/index.js +2 -2
  17. package/dist/cjs-browser/authentication/clientcredentials.js +1 -4
  18. package/dist/cjs-browser/common/internal.js +0 -40
  19. package/dist/cjs-browser/common/settings.js +2 -5
  20. package/dist/cjs-browser/jobs/jobs.js +2 -2
  21. package/dist/cjs-browser/jobs/start.js +1 -32
  22. package/dist/cjs-browser/sandbox/action.js +2 -1
  23. package/dist/cjs-browser/sandbox/sandbox.js +10 -67
  24. package/dist/cjs-browser/tools/mcpTool.js +2 -2
  25. package/dist/cjs-browser/types/common/internal.d.ts +0 -2
  26. package/dist/cjs-browser/types/common/settings.d.ts +0 -1
  27. package/dist/cjs-browser/types/sandbox/sandbox.d.ts +6 -12
  28. package/dist/cjs-browser/types/sandbox/types.d.ts +0 -3
  29. package/dist/esm/.tsbuildinfo +1 -1
  30. package/dist/esm/agents/index.js +3 -3
  31. package/dist/esm/authentication/clientcredentials.js +1 -4
  32. package/dist/esm/common/internal.js +0 -38
  33. package/dist/esm/common/settings.js +2 -5
  34. package/dist/esm/jobs/jobs.js +3 -3
  35. package/dist/esm/jobs/start.js +1 -32
  36. package/dist/esm/sandbox/action.js +3 -2
  37. package/dist/esm/sandbox/sandbox.js +10 -67
  38. package/dist/esm/tools/mcpTool.js +3 -3
  39. package/dist/esm-browser/.tsbuildinfo +1 -1
  40. package/dist/esm-browser/agents/index.js +3 -3
  41. package/dist/esm-browser/authentication/clientcredentials.js +1 -4
  42. package/dist/esm-browser/common/internal.js +0 -38
  43. package/dist/esm-browser/common/settings.js +2 -5
  44. package/dist/esm-browser/jobs/jobs.js +3 -3
  45. package/dist/esm-browser/jobs/start.js +1 -32
  46. package/dist/esm-browser/sandbox/action.js +3 -2
  47. package/dist/esm-browser/sandbox/sandbox.js +10 -67
  48. package/dist/esm-browser/tools/mcpTool.js +3 -3
  49. package/package.json +2 -2
  50. package/dist/cjs/sandbox/codegen/codegen-ws.js +0 -30
  51. package/dist/cjs/sandbox/filesystem/filesystem-ws.js +0 -106
  52. package/dist/cjs/sandbox/network/network-ws.js +0 -12
  53. package/dist/cjs/sandbox/process/process-ws.js +0 -139
  54. package/dist/cjs/sandbox/websocket/client.js +0 -269
  55. package/dist/cjs/sandbox/websocket/index.js +0 -17
  56. package/dist/cjs/types/sandbox/codegen/codegen-ws.d.ts +0 -10
  57. package/dist/cjs/types/sandbox/filesystem/filesystem-ws.d.ts +0 -35
  58. package/dist/cjs/types/sandbox/network/network-ws.d.ts +0 -7
  59. package/dist/cjs/types/sandbox/process/process-ws.d.ts +0 -27
  60. package/dist/cjs/types/sandbox/websocket/client.d.ts +0 -48
  61. package/dist/cjs/types/sandbox/websocket/index.d.ts +0 -1
  62. package/dist/cjs-browser/sandbox/codegen/codegen-ws.js +0 -30
  63. package/dist/cjs-browser/sandbox/filesystem/filesystem-ws.js +0 -106
  64. package/dist/cjs-browser/sandbox/network/network-ws.js +0 -12
  65. package/dist/cjs-browser/sandbox/process/process-ws.js +0 -139
  66. package/dist/cjs-browser/sandbox/websocket/client.js +0 -269
  67. package/dist/cjs-browser/sandbox/websocket/index.js +0 -17
  68. package/dist/cjs-browser/types/sandbox/codegen/codegen-ws.d.ts +0 -10
  69. package/dist/cjs-browser/types/sandbox/filesystem/filesystem-ws.d.ts +0 -35
  70. package/dist/cjs-browser/types/sandbox/network/network-ws.d.ts +0 -7
  71. package/dist/cjs-browser/types/sandbox/process/process-ws.d.ts +0 -27
  72. package/dist/cjs-browser/types/sandbox/websocket/client.d.ts +0 -48
  73. package/dist/cjs-browser/types/sandbox/websocket/index.d.ts +0 -1
  74. package/dist/esm/sandbox/codegen/codegen-ws.js +0 -26
  75. package/dist/esm/sandbox/filesystem/filesystem-ws.js +0 -102
  76. package/dist/esm/sandbox/network/network-ws.js +0 -8
  77. package/dist/esm/sandbox/process/process-ws.js +0 -135
  78. package/dist/esm/sandbox/websocket/client.js +0 -265
  79. package/dist/esm/sandbox/websocket/index.js +0 -1
  80. package/dist/esm-browser/sandbox/codegen/codegen-ws.js +0 -26
  81. package/dist/esm-browser/sandbox/filesystem/filesystem-ws.js +0 -102
  82. package/dist/esm-browser/sandbox/network/network-ws.js +0 -8
  83. package/dist/esm-browser/sandbox/process/process-ws.js +0 -135
  84. package/dist/esm-browser/sandbox/websocket/client.js +0 -265
  85. 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-dev.215","commit":"833c34cbba3735060a62bdd3594fa917160f3d3c"};
10
+ const packageJson = {"version":"0.2.50-preview.115","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-dev.215","commit":"833c34cbba3735060a62bdd3594fa917160f3d3c"};
62
+ const packageJson = {"version":"0.2.50-preview.115","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 { generateInternalUrl, getForcedUrl } from "../common/internal.js";
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 url = generateInternalUrl(settings.workspace, "job", this.jobName, settings.env, settings.runInternalProtocol, settings.runInternalHostname, settings.blCloud, settings.workspaceId);
21
- return new URL(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 this.fetchWithRetry(env.BL_EXECUTION_DATA_URL);
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 { generateInternalUrl, getForcedUrl } from "../common/internal.js";
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
- return generateInternalUrl(settings.workspace, "sandbox", this.name, settings.env, settings.runInternalProtocol, settings.runInternalHostname, settings.blCloud, settings.workspaceId);
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
- // If connection type is websocket, initialize WebSocket client and use WebSocket transport layers
28
- if (sandbox.connectionType === "websocket") {
29
- const url = sandbox.forceUrl || sandbox.metadata?.url || "";
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
- // Add connection type to configuration
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, connectionType) {
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
- // Add connection type to configuration
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, instance) {
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, connectionType);
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 { generateInternalUrl, getForcedUrl } from "../common/internal.js";
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 url = generateInternalUrl(settings.workspace, this.type, this.name, settings.env, settings.runInternalProtocol, settings.runInternalHostname, settings.blCloud, settings.workspaceId);
55
- return new URL(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);