@blaxel/core 0.2.45-preview.99 → 0.2.46-dev.204

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 (41) 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 +4 -1
  4. package/dist/cjs/common/internal.js +40 -0
  5. package/dist/cjs/common/settings.js +5 -2
  6. package/dist/cjs/jobs/jobs.js +2 -2
  7. package/dist/cjs/sandbox/action.js +1 -2
  8. package/dist/cjs/sandbox/sandbox.js +8 -3
  9. package/dist/cjs/tools/mcpTool.js +2 -2
  10. package/dist/cjs/types/common/internal.d.ts +2 -0
  11. package/dist/cjs/types/common/settings.d.ts +1 -0
  12. package/dist/cjs-browser/.tsbuildinfo +1 -1
  13. package/dist/cjs-browser/agents/index.js +2 -2
  14. package/dist/cjs-browser/authentication/clientcredentials.js +4 -1
  15. package/dist/cjs-browser/common/internal.js +40 -0
  16. package/dist/cjs-browser/common/settings.js +5 -2
  17. package/dist/cjs-browser/jobs/jobs.js +2 -2
  18. package/dist/cjs-browser/sandbox/action.js +1 -2
  19. package/dist/cjs-browser/sandbox/sandbox.js +8 -3
  20. package/dist/cjs-browser/tools/mcpTool.js +2 -2
  21. package/dist/cjs-browser/types/common/internal.d.ts +2 -0
  22. package/dist/cjs-browser/types/common/settings.d.ts +1 -0
  23. package/dist/esm/.tsbuildinfo +1 -1
  24. package/dist/esm/agents/index.js +3 -3
  25. package/dist/esm/authentication/clientcredentials.js +4 -1
  26. package/dist/esm/common/internal.js +38 -0
  27. package/dist/esm/common/settings.js +5 -2
  28. package/dist/esm/jobs/jobs.js +3 -3
  29. package/dist/esm/sandbox/action.js +2 -3
  30. package/dist/esm/sandbox/sandbox.js +8 -3
  31. package/dist/esm/tools/mcpTool.js +3 -3
  32. package/dist/esm-browser/.tsbuildinfo +1 -1
  33. package/dist/esm-browser/agents/index.js +3 -3
  34. package/dist/esm-browser/authentication/clientcredentials.js +4 -1
  35. package/dist/esm-browser/common/internal.js +38 -0
  36. package/dist/esm-browser/common/settings.js +5 -2
  37. package/dist/esm-browser/jobs/jobs.js +3 -3
  38. package/dist/esm-browser/sandbox/action.js +2 -3
  39. package/dist/esm-browser/sandbox/sandbox.js +8 -3
  40. package/dist/esm-browser/tools/mcpTool.js +3 -3
  41. package/package.json +2 -2
@@ -5,6 +5,8 @@ exports.getAlphanumericLimitedHash = getAlphanumericLimitedHash;
5
5
  exports.getGlobalUniqueHash = getGlobalUniqueHash;
6
6
  exports.pluralize = pluralize;
7
7
  exports.getForcedUrl = getForcedUrl;
8
+ exports.getWorkloadTypeShort = getWorkloadTypeShort;
9
+ exports.generateInternalUrl = generateInternalUrl;
8
10
  const env_js_1 = require("./env.js");
9
11
  // Pure JS MD5 implementation that matches standard crypto MD5
10
12
  function md5(input) {
@@ -186,3 +188,41 @@ function getForcedUrl(type, name) {
186
188
  }
187
189
  return null;
188
190
  }
191
+ function getWorkloadTypeShort(type) {
192
+ const lowerType = type.toLowerCase();
193
+ switch (lowerType) {
194
+ case 'agent':
195
+ case 'agents':
196
+ return 'agt';
197
+ case 'mcp':
198
+ case 'mcps':
199
+ case 'function':
200
+ case 'functions':
201
+ return 'mcp';
202
+ case 'sandbox':
203
+ case 'sandboxes':
204
+ return 'sbx';
205
+ case 'job':
206
+ case 'jobs':
207
+ return 'job';
208
+ case 'model':
209
+ case 'models':
210
+ return 'mdl';
211
+ default:
212
+ // fallback to first 3 letters of type
213
+ return lowerType.substring(0, 3);
214
+ }
215
+ }
216
+ function generateInternalUrl(workspace, type, name, env, protocol, hostname, blCloud, workspaceId) {
217
+ if (blCloud && workspaceId) {
218
+ // New cloud format: bl-ENV-WORKLOAD_CALLED_NAME-WORKLOAD_TYPE_SHORT-WORKSPACE_ID
219
+ const workloadTypeShort = getWorkloadTypeShort(type);
220
+ const subdomain = `bl-${env}-${name}-${workloadTypeShort}-${workspaceId}`;
221
+ return `${protocol}://${subdomain}.${hostname}`;
222
+ }
223
+ else {
224
+ // Legacy format: bl-ENV-HASH.internalhostname
225
+ const hash = getGlobalUniqueHash(workspace, type, name);
226
+ return `${protocol}://bl-${env}-${hash}.${hostname}`;
227
+ }
228
+ }
@@ -10,7 +10,7 @@ function getPackageVersion() {
10
10
  if (typeof require !== "undefined") {
11
11
  // Try to require package.json (Node.js only, gracefully fails in browser)
12
12
  // eslint-disable-next-line @typescript-eslint/no-require-imports
13
- const packageJson = {"version":"0.2.45-preview.99","commit":"0b49fa5e3d23661750353c7693b8b8b4057f4142"};
13
+ const packageJson = {"version":"0.2.46-dev.204","commit":"6df4b9634c31339747c2d6a37c0810466e5114da"};
14
14
  return packageJson.version || "unknown";
15
15
  }
16
16
  else {
@@ -62,7 +62,7 @@ function getCommitHash() {
62
62
  if (typeof require !== "undefined") {
63
63
  // Try to require package.json and look for commit field (set during build)
64
64
  // eslint-disable-next-line @typescript-eslint/no-require-imports
65
- const packageJson = {"version":"0.2.45-preview.99","commit":"0b49fa5e3d23661750353c7693b8b8b4057f4142"};
65
+ const packageJson = {"version":"0.2.46-dev.204","commit":"6df4b9634c31339747c2d6a37c0810466e5114da"};
66
66
  // Check for commit in various possible locations
67
67
  const commit = packageJson.commit || packageJson.buildInfo?.commit;
68
68
  if (commit) {
@@ -165,6 +165,9 @@ class Settings {
165
165
  get blCloud() {
166
166
  return env_js_1.env.BL_CLOUD === "true";
167
167
  }
168
+ get workspaceId() {
169
+ return env_js_1.env.BL_WORKSPACE_ID || "";
170
+ }
168
171
  get generation() {
169
172
  return env_js_1.env.BL_GENERATION || "";
170
173
  }
@@ -20,8 +20,8 @@ class BlJob {
20
20
  return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/jobs/${this.jobName}`);
21
21
  }
22
22
  get internalUrl() {
23
- const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, "job", this.jobName);
24
- return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
23
+ const url = (0, internal_js_1.generateInternalUrl)(settings_js_1.settings.workspace, "job", this.jobName, settings_js_1.settings.env, settings_js_1.settings.runInternalProtocol, settings_js_1.settings.runInternalHostname, settings_js_1.settings.blCloud, settings_js_1.settings.workspaceId);
24
+ return new URL(url);
25
25
  }
26
26
  get forcedUrl() {
27
27
  return (0, internal_js_1.getForcedUrl)('job', this.jobName);
@@ -48,8 +48,7 @@ class SandboxAction {
48
48
  return this.sandbox.metadata?.url ?? `${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/sandboxes/${this.name}`;
49
49
  }
50
50
  get internalUrl() {
51
- const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, "sandbox", this.name);
52
- return `${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`;
51
+ return (0, internal_js_1.generateInternalUrl)(settings_js_1.settings.workspace, "sandbox", this.name, settings_js_1.settings.env, settings_js_1.settings.runInternalProtocol, settings_js_1.settings.runInternalHostname, settings_js_1.settings.blCloud, settings_js_1.settings.workspaceId);
53
52
  }
54
53
  get client() {
55
54
  if (this.sandbox.forceUrl) {
@@ -4,7 +4,6 @@ exports.SandboxInstance = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  const index_js_1 = require("../client/index.js");
6
6
  const logger_js_1 = require("../common/logger.js");
7
- const settings_js_1 = require("../common/settings.js");
8
7
  const index_js_2 = require("./filesystem/index.js");
9
8
  const index_js_3 = require("./network/index.js");
10
9
  const preview_js_1 = require("./preview.js");
@@ -44,9 +43,8 @@ class SandboxInstance {
44
43
  return this;
45
44
  }
46
45
  static async create(sandbox, { safe = true } = {}) {
47
- const env = settings_js_1.settings.env;
48
46
  const defaultName = `sandbox-${(0, uuid_1.v4)().replace(/-/g, '').substring(0, 8)}`;
49
- const defaultImage = `blaxel/${env}-base:latest`;
47
+ const defaultImage = `blaxel/base:latest`;
50
48
  const defaultMemory = 4096;
51
49
  // Handle SandboxCreateConfiguration or simple dict with name/image/memory/ports/envs/volumes keys
52
50
  if (!sandbox ||
@@ -167,7 +165,14 @@ class SandboxInstance {
167
165
  if (!name) {
168
166
  throw new Error("Sandbox name is required");
169
167
  }
168
+ // Get the existing sandbox to check its status
170
169
  const sandboxInstance = await SandboxInstance.get(name);
170
+ // If the sandbox is TERMINATED, treat it as not existing
171
+ if (sandboxInstance.status === "TERMINATED") {
172
+ // Create a new sandbox - backend will handle cleanup of the terminated one
173
+ return await SandboxInstance.create(sandbox);
174
+ }
175
+ // Otherwise return the existing running sandbox
171
176
  return sandboxInstance;
172
177
  }
173
178
  throw e;
@@ -58,8 +58,8 @@ class McpTool {
58
58
  return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/${this.pluralType}/${this.name}`);
59
59
  }
60
60
  get internalUrl() {
61
- const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, this.type, this.name);
62
- return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
61
+ const url = (0, internal_js_1.generateInternalUrl)(settings_js_1.settings.workspace, this.type, this.name, settings_js_1.settings.env, settings_js_1.settings.runInternalProtocol, settings_js_1.settings.runInternalHostname, settings_js_1.settings.blCloud, settings_js_1.settings.workspaceId);
62
+ return new URL(url);
63
63
  }
64
64
  get forcedUrl() {
65
65
  return (0, internal_js_1.getForcedUrl)(this.type, this.name);
@@ -2,3 +2,5 @@ export declare function getAlphanumericLimitedHash(input: string, maxSize?: numb
2
2
  export declare function getGlobalUniqueHash(workspace: string, type: string, name: string): string;
3
3
  export declare function pluralize(type: string): string;
4
4
  export declare function getForcedUrl(type: string, name: string): import("url").URL | null;
5
+ export declare function getWorkloadTypeShort(type: string): string;
6
+ export declare function generateInternalUrl(workspace: string, type: string, name: string, env: string, protocol: string, hostname: string, blCloud: boolean, workspaceId: string): string;
@@ -23,6 +23,7 @@ declare class Settings {
23
23
  get runInternalHostname(): string;
24
24
  get runInternalProtocol(): string;
25
25
  get blCloud(): boolean;
26
+ get workspaceId(): string;
26
27
  get generation(): string;
27
28
  get loggerType(): string;
28
29
  authenticate(): Promise<void>;