@blaxel/core 0.2.73 → 0.2.74-preview.114

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.
@@ -9,8 +9,8 @@ const index_js_1 = require("../authentication/index.js");
9
9
  const env_js_1 = require("../common/env.js");
10
10
  const node_js_1 = require("../common/node.js");
11
11
  // Build info - these placeholders are replaced at build time by build:replace-imports
12
- const BUILD_VERSION = "0.2.73";
13
- const BUILD_COMMIT = "ca69d9d46e02efafefc83f2fe96e377b857b493a";
12
+ const BUILD_VERSION = "0.2.74-preview.114";
13
+ const BUILD_COMMIT = "796e20f3a5a0e5f67783655f1d75250b32fd8694";
14
14
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
15
15
  // Cache for config.yaml tracking value
16
16
  let configTrackingValue = null;
@@ -32,54 +32,40 @@ class CodeInterpreter extends sandbox_js_1.SandboxInstance {
32
32
  return new CodeInterpreter(config);
33
33
  }
34
34
  static async create(sandbox, { safe = true } = {}) {
35
- const payload = {
35
+ // Build a SandboxCreateConfiguration with CodeInterpreter defaults
36
+ const defaults = {
36
37
  image: CodeInterpreter.DEFAULT_IMAGE,
37
38
  ports: CodeInterpreter.DEFAULT_PORTS,
38
39
  lifecycle: CodeInterpreter.DEFAULT_LIFECYCLE,
39
40
  };
40
- const allowedCopyKeys = new Set(["name", "envs", "memory", "region", "headers", "labels"]);
41
- if (sandbox && typeof sandbox === "object") {
42
- if (Array.isArray(sandbox)) {
43
- // Skip arrays
44
- }
45
- else if ("metadata" in sandbox || "spec" in sandbox) {
46
- // It's a Sandbox object
41
+ let merged;
42
+ if (sandbox && typeof sandbox === "object" && !Array.isArray(sandbox)) {
43
+ if ("metadata" in sandbox || "spec" in sandbox) {
44
+ // It's a Sandbox object - inject defaults into spec
47
45
  const sandboxObj = sandbox;
48
- if (sandboxObj.metadata.name) {
49
- payload["name"] = sandboxObj.metadata.name;
50
- }
51
- if (sandboxObj.metadata.labels) {
52
- payload["labels"] = sandboxObj.metadata.labels;
53
- }
54
- if (sandboxObj.spec.runtime) {
55
- if (sandboxObj.spec.runtime.envs) {
56
- payload["envs"] = sandboxObj.spec.runtime.envs;
57
- }
58
- if (sandboxObj.spec.runtime.memory) {
59
- payload["memory"] = sandboxObj.spec.runtime.memory;
60
- }
61
- }
62
- if (sandboxObj.spec.region) {
63
- payload["region"] = sandboxObj.spec.region;
64
- }
46
+ merged = {
47
+ ...sandboxObj,
48
+ spec: {
49
+ ...sandboxObj.spec,
50
+ runtime: {
51
+ image: defaults.image,
52
+ ports: defaults.ports,
53
+ ...sandboxObj.spec?.runtime,
54
+ },
55
+ lifecycle: sandboxObj.spec?.lifecycle || defaults.lifecycle,
56
+ },
57
+ };
65
58
  }
66
- else if ("name" in sandbox || "image" in sandbox || "memory" in sandbox) {
67
- // It's a SandboxCreateConfiguration or dict-like object
68
- const sandboxDict = sandbox;
69
- for (const k of allowedCopyKeys) {
70
- const value = sandboxDict[k];
71
- if (value !== null && value !== undefined) {
72
- payload[k] = value;
73
- }
74
- }
59
+ else {
60
+ // It's a SandboxCreateConfiguration or dict-like object - merge with defaults
61
+ merged = { ...defaults, ...sandbox };
75
62
  }
76
63
  }
77
- // Auto-fill region with BL_REGION if not set
78
- if (!payload["region"] && settings_js_1.settings.region) {
79
- payload["region"] = settings_js_1.settings.region;
64
+ else {
65
+ merged = defaults;
80
66
  }
81
- const baseInstance = await sandbox_js_1.SandboxInstance.create(payload, { safe });
82
- // Create config from the instance - preserve any forceUrl/headers if provided in input
67
+ const baseInstance = await super.create(merged, { safe });
68
+ // Create config from the instance
83
69
  const config = {
84
70
  metadata: baseInstance.metadata,
85
71
  spec: baseInstance.spec,
@@ -87,7 +73,7 @@ class CodeInterpreter extends sandbox_js_1.SandboxInstance {
87
73
  events: baseInstance.events,
88
74
  h2Session: baseInstance.h2Session,
89
75
  };
90
- // Preserve forceUrl and headers from input if it was a dict-like object
76
+ // Preserve forceUrl, headers, and params from input if provided
91
77
  if (sandbox && typeof sandbox === "object" && !Array.isArray(sandbox)) {
92
78
  if ("forceUrl" in sandbox && typeof sandbox.forceUrl === "string") {
93
79
  config.forceUrl = sandbox.forceUrl;
@@ -101,6 +87,9 @@ class CodeInterpreter extends sandbox_js_1.SandboxInstance {
101
87
  }
102
88
  return new CodeInterpreter(config);
103
89
  }
90
+ static async createIfNotExists(sandbox) {
91
+ return await super.createIfNotExists(sandbox);
92
+ }
104
93
  get _jupyterUrl() {
105
94
  return this.process.url;
106
95
  }
@@ -279,7 +279,7 @@ class SandboxInstance {
279
279
  }
280
280
  static async createIfNotExists(sandbox) {
281
281
  try {
282
- return await SandboxInstance.create(sandbox);
282
+ return await this.create(sandbox);
283
283
  }
284
284
  catch (e) {
285
285
  if (typeof e === "object" && e !== null && "code" in e && (e.code === 409 || e.code === 'SANDBOX_ALREADY_EXISTS')) {
@@ -288,11 +288,11 @@ class SandboxInstance {
288
288
  throw new Error("Sandbox name is required");
289
289
  }
290
290
  // Get the existing sandbox to check its status
291
- const sandboxInstance = await SandboxInstance.get(name);
291
+ const sandboxInstance = await this.get(name);
292
292
  // If the sandbox is TERMINATED, treat it as not existing
293
293
  if (sandboxInstance.status === "TERMINATED") {
294
294
  // Create a new sandbox - backend will handle cleanup of the terminated one
295
- return await SandboxInstance.create(sandbox);
295
+ return await this.create(sandbox);
296
296
  }
297
297
  // Otherwise return the existing running sandbox
298
298
  return sandboxInstance;
@@ -11,6 +11,7 @@ export declare class CodeInterpreter extends SandboxInstance {
11
11
  static create(sandbox?: Sandbox | SandboxCreateConfiguration | Record<string, any> | null, { safe }?: {
12
12
  safe?: boolean;
13
13
  }): Promise<CodeInterpreter>;
14
+ static createIfNotExists(sandbox: Sandbox | SandboxCreateConfiguration): Promise<CodeInterpreter>;
14
15
  get _jupyterUrl(): string;
15
16
  private _fetch;
16
17
  static OutputMessage: {