@blaxel/core 0.2.48 → 0.2.49-dev.206

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/filesystem/filesystem.js +3 -14
  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/filesystem/filesystem.js +3 -14
  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/filesystem/filesystem.js +3 -14
  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/filesystem/filesystem.js +3 -14
  40. package/dist/esm-browser/tools/mcpTool.js +3 -3
  41. package/package.json +2 -2
@@ -180,3 +180,41 @@ 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.48","commit":"64cc47af878d72bbb58982333bcae814e3878759"};
10
+ const packageJson = {"version":"0.2.49-dev.206","commit":"017e4a324642a0030cb54183ad590a845ec9694e"};
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.48","commit":"64cc47af878d72bbb58982333bcae814e3878759"};
62
+ const packageJson = {"version":"0.2.49-dev.206","commit":"017e4a324642a0030cb54183ad590a845ec9694e"};
63
63
  // Check for commit in various possible locations
64
64
  const commit = packageJson.commit || packageJson.buildInfo?.commit;
65
65
  if (commit) {
@@ -162,6 +162,9 @@ 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
+ }
165
168
  get generation() {
166
169
  return env.BL_GENERATION || "";
167
170
  }
@@ -1,4 +1,4 @@
1
- import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
1
+ import { generateInternalUrl, getForcedUrl } 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 hash = getGlobalUniqueHash(settings.workspace, "job", this.jobName);
21
- return new URL(`${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`);
20
+ const url = generateInternalUrl(settings.workspace, "job", this.jobName, settings.env, settings.runInternalProtocol, settings.runInternalHostname, settings.blCloud, settings.workspaceId);
21
+ return new URL(url);
22
22
  }
23
23
  get forcedUrl() {
24
24
  return getForcedUrl('job', this.jobName);
@@ -1,5 +1,5 @@
1
1
  import { createClient } from "@hey-api/client-fetch";
2
- import { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
2
+ import { generateInternalUrl, getForcedUrl } 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,8 +44,7 @@ export class SandboxAction {
44
44
  return this.sandbox.metadata?.url ?? `${settings.runUrl}/${settings.workspace}/sandboxes/${this.name}`;
45
45
  }
46
46
  get internalUrl() {
47
- const hash = getGlobalUniqueHash(settings.workspace, "sandbox", this.name);
48
- return `${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`;
47
+ return generateInternalUrl(settings.workspace, "sandbox", this.name, settings.env, settings.runInternalProtocol, settings.runInternalHostname, settings.blCloud, settings.workspaceId);
49
48
  }
50
49
  get client() {
51
50
  if (this.sandbox.forceUrl) {
@@ -5,7 +5,7 @@ import { deleteFilesystemByPath, getFilesystemByPath, getWatchFilesystemByPath,
5
5
  // Multipart upload constants
6
6
  const MULTIPART_THRESHOLD = 5 * 1024 * 1024; // 5MB
7
7
  const CHUNK_SIZE = 5 * 1024 * 1024; // 5MB per part
8
- const MAX_PARALLEL_UPLOADS = 3; // Number of parallel part uploads
8
+ const MAX_PARALLEL_UPLOADS = 10; // Number of parallel part uploads
9
9
  export class SandboxFileSystem extends SandboxAction {
10
10
  process;
11
11
  constructor(sandbox, process) {
@@ -301,7 +301,6 @@ export class SandboxFileSystem extends SandboxAction {
301
301
  // Multipart upload helper methods
302
302
  async initiateMultipartUpload(path, permissions = "0644") {
303
303
  path = this.formatPath(path);
304
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
305
304
  const { data } = await postFilesystemMultipartInitiateByPath({
306
305
  path: { path },
307
306
  body: { permissions },
@@ -312,7 +311,6 @@ export class SandboxFileSystem extends SandboxAction {
312
311
  return data;
313
312
  }
314
313
  async uploadPart(uploadId, partNumber, fileBlob) {
315
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
316
314
  const { data } = await putFilesystemMultipartByUploadIdPart({
317
315
  path: { uploadId },
318
316
  query: { partNumber },
@@ -324,7 +322,6 @@ export class SandboxFileSystem extends SandboxAction {
324
322
  return data;
325
323
  }
326
324
  async completeMultipartUpload(uploadId, parts) {
327
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
328
325
  const { data } = await postFilesystemMultipartByUploadIdComplete({
329
326
  path: { uploadId },
330
327
  body: { parts },
@@ -335,19 +332,17 @@ export class SandboxFileSystem extends SandboxAction {
335
332
  return data;
336
333
  }
337
334
  async abortMultipartUpload(uploadId) {
338
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
339
- await deleteFilesystemMultipartByUploadIdAbort({
335
+ const { data } = await deleteFilesystemMultipartByUploadIdAbort({
340
336
  path: { uploadId },
341
337
  baseUrl: this.url,
342
338
  client: this.client,
343
339
  throwOnError: true,
344
340
  });
341
+ return data;
345
342
  }
346
343
  async uploadWithMultipart(path, blob, permissions = "0644") {
347
344
  // Initiate multipart upload
348
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
349
345
  const initResponse = await this.initiateMultipartUpload(path, permissions);
350
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
351
346
  const uploadId = initResponse.uploadId;
352
347
  if (!uploadId) {
353
348
  throw new Error("Failed to get upload ID from initiate response");
@@ -364,26 +359,20 @@ export class SandboxFileSystem extends SandboxAction {
364
359
  const start = (partNumber - 1) * CHUNK_SIZE;
365
360
  const end = Math.min(start + CHUNK_SIZE, size);
366
361
  const chunk = blob.slice(start, end);
367
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
368
362
  batch.push(this.uploadPart(uploadId, partNumber, chunk));
369
363
  }
370
364
  // Wait for batch to complete
371
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
372
365
  const batchResults = await Promise.all(batch);
373
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
374
366
  parts.push(...batchResults.map((r) => ({ partNumber: r.partNumber, etag: r.etag })));
375
367
  }
376
368
  // Sort parts by partNumber to ensure correct order
377
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
378
369
  parts.sort((a, b) => (a.partNumber ?? 0) - (b.partNumber ?? 0));
379
370
  // Complete the upload
380
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
381
371
  return await this.completeMultipartUpload(uploadId, parts);
382
372
  }
383
373
  catch (error) {
384
374
  // Abort the upload on failure
385
375
  try {
386
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
387
376
  await this.abortMultipartUpload(uploadId);
388
377
  }
389
378
  catch (abortError) {
@@ -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 { getForcedUrl, getGlobalUniqueHash } from "../common/internal.js";
3
+ import { generateInternalUrl, getForcedUrl } 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";
@@ -55,8 +55,8 @@ export class McpTool {
55
55
  return new URL(`${settings.runUrl}/${settings.workspace}/${this.pluralType}/${this.name}`);
56
56
  }
57
57
  get internalUrl() {
58
- const hash = getGlobalUniqueHash(settings.workspace, this.type, this.name);
59
- return new URL(`${settings.runInternalProtocol}://bl-${settings.env}-${hash}.${settings.runInternalHostname}`);
58
+ const url = generateInternalUrl(settings.workspace, this.type, this.name, settings.env, settings.runInternalProtocol, settings.runInternalHostname, settings.blCloud, settings.workspaceId);
59
+ return new URL(url);
60
60
  }
61
61
  get forcedUrl() {
62
62
  return getForcedUrl(this.type, this.name);