@blaxel/core 0.2.73 → 0.2.74

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.
@@ -3,8 +3,8 @@ import { authentication } from "../authentication/index.js";
3
3
  import { env } from "../common/env.js";
4
4
  import { fs, os, path } from "../common/node.js";
5
5
  // Build info - these placeholders are replaced at build time by build:replace-imports
6
- const BUILD_VERSION = "0.2.73";
7
- const BUILD_COMMIT = "ca69d9d46e02efafefc83f2fe96e377b857b493a";
6
+ const BUILD_VERSION = "0.2.74";
7
+ const BUILD_COMMIT = "796e20f3a5a0e5f67783655f1d75250b32fd8694";
8
8
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
9
9
  // Cache for config.yaml tracking value
10
10
  let configTrackingValue = null;
@@ -29,54 +29,40 @@ export class CodeInterpreter extends SandboxInstance {
29
29
  return new CodeInterpreter(config);
30
30
  }
31
31
  static async create(sandbox, { safe = true } = {}) {
32
- const payload = {
32
+ // Build a SandboxCreateConfiguration with CodeInterpreter defaults
33
+ const defaults = {
33
34
  image: CodeInterpreter.DEFAULT_IMAGE,
34
35
  ports: CodeInterpreter.DEFAULT_PORTS,
35
36
  lifecycle: CodeInterpreter.DEFAULT_LIFECYCLE,
36
37
  };
37
- const allowedCopyKeys = new Set(["name", "envs", "memory", "region", "headers", "labels"]);
38
- if (sandbox && typeof sandbox === "object") {
39
- if (Array.isArray(sandbox)) {
40
- // Skip arrays
41
- }
42
- else if ("metadata" in sandbox || "spec" in sandbox) {
43
- // It's a Sandbox object
38
+ let merged;
39
+ if (sandbox && typeof sandbox === "object" && !Array.isArray(sandbox)) {
40
+ if ("metadata" in sandbox || "spec" in sandbox) {
41
+ // It's a Sandbox object - inject defaults into spec
44
42
  const sandboxObj = sandbox;
45
- if (sandboxObj.metadata.name) {
46
- payload["name"] = sandboxObj.metadata.name;
47
- }
48
- if (sandboxObj.metadata.labels) {
49
- payload["labels"] = sandboxObj.metadata.labels;
50
- }
51
- if (sandboxObj.spec.runtime) {
52
- if (sandboxObj.spec.runtime.envs) {
53
- payload["envs"] = sandboxObj.spec.runtime.envs;
54
- }
55
- if (sandboxObj.spec.runtime.memory) {
56
- payload["memory"] = sandboxObj.spec.runtime.memory;
57
- }
58
- }
59
- if (sandboxObj.spec.region) {
60
- payload["region"] = sandboxObj.spec.region;
61
- }
43
+ merged = {
44
+ ...sandboxObj,
45
+ spec: {
46
+ ...sandboxObj.spec,
47
+ runtime: {
48
+ image: defaults.image,
49
+ ports: defaults.ports,
50
+ ...sandboxObj.spec?.runtime,
51
+ },
52
+ lifecycle: sandboxObj.spec?.lifecycle || defaults.lifecycle,
53
+ },
54
+ };
62
55
  }
63
- else if ("name" in sandbox || "image" in sandbox || "memory" in sandbox) {
64
- // It's a SandboxCreateConfiguration or dict-like object
65
- const sandboxDict = sandbox;
66
- for (const k of allowedCopyKeys) {
67
- const value = sandboxDict[k];
68
- if (value !== null && value !== undefined) {
69
- payload[k] = value;
70
- }
71
- }
56
+ else {
57
+ // It's a SandboxCreateConfiguration or dict-like object - merge with defaults
58
+ merged = { ...defaults, ...sandbox };
72
59
  }
73
60
  }
74
- // Auto-fill region with BL_REGION if not set
75
- if (!payload["region"] && settings.region) {
76
- payload["region"] = settings.region;
61
+ else {
62
+ merged = defaults;
77
63
  }
78
- const baseInstance = await SandboxInstance.create(payload, { safe });
79
- // Create config from the instance - preserve any forceUrl/headers if provided in input
64
+ const baseInstance = await super.create(merged, { safe });
65
+ // Create config from the instance
80
66
  const config = {
81
67
  metadata: baseInstance.metadata,
82
68
  spec: baseInstance.spec,
@@ -84,7 +70,7 @@ export class CodeInterpreter extends SandboxInstance {
84
70
  events: baseInstance.events,
85
71
  h2Session: baseInstance.h2Session,
86
72
  };
87
- // Preserve forceUrl and headers from input if it was a dict-like object
73
+ // Preserve forceUrl, headers, and params from input if provided
88
74
  if (sandbox && typeof sandbox === "object" && !Array.isArray(sandbox)) {
89
75
  if ("forceUrl" in sandbox && typeof sandbox.forceUrl === "string") {
90
76
  config.forceUrl = sandbox.forceUrl;
@@ -98,6 +84,9 @@ export class CodeInterpreter extends SandboxInstance {
98
84
  }
99
85
  return new CodeInterpreter(config);
100
86
  }
87
+ static async createIfNotExists(sandbox) {
88
+ return await super.createIfNotExists(sandbox);
89
+ }
101
90
  get _jupyterUrl() {
102
91
  return this.process.url;
103
92
  }
@@ -243,7 +243,7 @@ export class SandboxInstance {
243
243
  }
244
244
  static async createIfNotExists(sandbox) {
245
245
  try {
246
- return await SandboxInstance.create(sandbox);
246
+ return await this.create(sandbox);
247
247
  }
248
248
  catch (e) {
249
249
  if (typeof e === "object" && e !== null && "code" in e && (e.code === 409 || e.code === 'SANDBOX_ALREADY_EXISTS')) {
@@ -252,11 +252,11 @@ export class SandboxInstance {
252
252
  throw new Error("Sandbox name is required");
253
253
  }
254
254
  // Get the existing sandbox to check its status
255
- const sandboxInstance = await SandboxInstance.get(name);
255
+ const sandboxInstance = await this.get(name);
256
256
  // If the sandbox is TERMINATED, treat it as not existing
257
257
  if (sandboxInstance.status === "TERMINATED") {
258
258
  // Create a new sandbox - backend will handle cleanup of the terminated one
259
- return await SandboxInstance.create(sandbox);
259
+ return await this.create(sandbox);
260
260
  }
261
261
  // Otherwise return the existing running sandbox
262
262
  return sandboxInstance;