@blaxel/core 0.2.18-dev.157 → 0.2.18-preview.39

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.
@@ -733,9 +733,7 @@ export type JobMetrics = {
733
733
  /**
734
734
  * Job specification
735
735
  */
736
- export type JobSpec = CoreSpec & {
737
- triggers?: Triggers;
738
- };
736
+ export type JobSpec = CoreSpec & unknown;
739
737
  /**
740
738
  * Jobs chart
741
739
  */
@@ -2441,7 +2439,12 @@ export type TraceIdsResponse = {
2441
2439
  * Trigger configuration
2442
2440
  */
2443
2441
  export type Trigger = {
2444
- configuration?: TriggerConfiguration;
2442
+ /**
2443
+ * The configuration of the trigger
2444
+ */
2445
+ configuration?: {
2446
+ [key: string]: unknown;
2447
+ };
2445
2448
  /**
2446
2449
  * The id of the trigger
2447
2450
  */
@@ -2451,27 +2454,6 @@ export type Trigger = {
2451
2454
  */
2452
2455
  type?: string;
2453
2456
  };
2454
- /**
2455
- * Trigger configuration
2456
- */
2457
- export type TriggerConfiguration = {
2458
- /**
2459
- * The authentication type of the trigger
2460
- */
2461
- authenticationType?: string;
2462
- /**
2463
- * The path of the trigger
2464
- */
2465
- path?: string;
2466
- /**
2467
- * The retry of the trigger
2468
- */
2469
- retry?: number;
2470
- /**
2471
- * The schedule of the trigger, cron expression * * * * *
2472
- */
2473
- schedule?: string;
2474
- };
2475
2457
  /**
2476
2458
  * Triggers to use your agent
2477
2459
  */
@@ -1,23 +1,23 @@
1
1
  export type Directory = {
2
- files: Array<File>;
3
- name: string;
4
- path: string;
2
+ files?: Array<File>;
3
+ name?: string;
4
+ path?: string;
5
5
  /**
6
6
  * @name Subdirectories
7
7
  */
8
- subdirectories: Array<Subdirectory>;
8
+ subdirectories?: Array<Subdirectory>;
9
9
  };
10
10
  export type ErrorResponse = {
11
- error: string;
11
+ error?: string;
12
12
  };
13
13
  export type File = {
14
- group: string;
15
- lastModified: string;
16
- name: string;
17
- owner: string;
18
- path: string;
19
- permissions: string;
20
- size: number;
14
+ group?: string;
15
+ lastModified?: string;
16
+ name?: string;
17
+ owner?: string;
18
+ path?: string;
19
+ permissions?: string;
20
+ size?: number;
21
21
  };
22
22
  export type FileRequest = {
23
23
  content?: string;
@@ -25,14 +25,14 @@ export type FileRequest = {
25
25
  permissions?: string;
26
26
  };
27
27
  export type FileWithContent = {
28
- content: string;
29
- group: string;
30
- lastModified: string;
31
- name: string;
32
- owner: string;
33
- path: string;
34
- permissions: string;
35
- size: number;
28
+ content?: string;
29
+ group?: string;
30
+ lastModified?: string;
31
+ name?: string;
32
+ owner?: string;
33
+ path?: string;
34
+ permissions?: string;
35
+ size?: number;
36
36
  };
37
37
  export type PortMonitorRequest = {
38
38
  /**
@@ -41,9 +41,9 @@ export type PortMonitorRequest = {
41
41
  callback?: string;
42
42
  };
43
43
  export type ProcessLogs = {
44
- logs: string;
45
- stderr: string;
46
- stdout: string;
44
+ logs?: string;
45
+ stderr?: string;
46
+ stdout?: string;
47
47
  };
48
48
  export type ProcessRequest = {
49
49
  command: string;
@@ -57,23 +57,22 @@ export type ProcessRequest = {
57
57
  workingDir?: string;
58
58
  };
59
59
  export type ProcessResponse = {
60
- command: string;
61
- completedAt: string;
62
- exitCode: number;
63
- logs: string;
64
- name: string;
65
- pid: string;
66
- startedAt: string;
67
- status: 'failed' | 'killed' | 'stopped' | 'running' | 'completed';
68
- workingDir: string;
60
+ command?: string;
61
+ completedAt?: string;
62
+ exitCode?: number;
63
+ name?: string;
64
+ pid?: string;
65
+ startedAt?: string;
66
+ status?: 'failed' | 'killed' | 'stopped' | 'running' | 'completed';
67
+ workingDir?: string;
69
68
  };
70
69
  export type Subdirectory = {
71
- name: string;
72
- path: string;
70
+ name?: string;
71
+ path?: string;
73
72
  };
74
73
  export type SuccessResponse = {
75
- message: string;
76
- path: string;
74
+ message?: string;
75
+ path?: string;
77
76
  };
78
77
  export type DeleteFilesystemByPathData = {
79
78
  body?: never;
@@ -1,3 +1,4 @@
1
1
  "use strict";
2
+ /* eslint-disable */
2
3
  // This file is auto-generated by @hey-api/openapi-ts
3
4
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -10,7 +10,7 @@ export declare class SandboxProcess extends SandboxAction {
10
10
  }): {
11
11
  close: () => void;
12
12
  };
13
- exec(process: ProcessRequest, onLog?: (log: string) => void): Promise<PostProcessResponse>;
13
+ exec(process: ProcessRequest): Promise<PostProcessResponse>;
14
14
  wait(identifier: string, { maxWait, interval }?: {
15
15
  maxWait?: number;
16
16
  interval?: number;
@@ -61,44 +61,14 @@ class SandboxProcess extends action_js_1.SandboxAction {
61
61
  close: () => controller.abort(),
62
62
  };
63
63
  }
64
- async exec(process, onLog) {
65
- // Store original wait_for_completion setting
66
- const shouldWaitForCompletion = process.waitForCompletion;
67
- // Always start process without wait_for_completion to avoid server-side blocking
68
- if (shouldWaitForCompletion && onLog) {
69
- process.waitForCompletion = false;
70
- }
64
+ async exec(process) {
71
65
  const { response, data, error } = await (0, index_js_1.postProcess)({
72
66
  body: process,
73
67
  baseUrl: this.url,
74
68
  client: this.client,
75
69
  });
76
70
  this.handleResponseError(response, data, error);
77
- let result = data;
78
- // Handle wait_for_completion with parallel log streaming
79
- if (shouldWaitForCompletion) {
80
- let streamControl;
81
- if (onLog) {
82
- streamControl = this.streamLogs(result.pid, { onLog });
83
- }
84
- try {
85
- // Wait for process completion
86
- result = await this.wait(result.pid, { interval: 50 });
87
- }
88
- finally {
89
- // Clean up log streaming
90
- if (streamControl) {
91
- streamControl.close();
92
- }
93
- }
94
- }
95
- else {
96
- // For non-blocking execution, set up log streaming immediately if requested
97
- if (onLog) {
98
- this.streamLogs(result.pid, { onLog });
99
- }
100
- }
101
- return result;
71
+ return data;
102
72
  }
103
73
  async wait(identifier, { maxWait = 60000, interval = 1000 } = {}) {
104
74
  const startTime = Date.now();
@@ -4,7 +4,7 @@ import { SandboxNetwork } from "./network/index.js";
4
4
  import { SandboxPreviews } from "./preview.js";
5
5
  import { SandboxProcess } from "./process/index.js";
6
6
  import { SandboxSessions } from "./session.js";
7
- import { SandboxConfiguration, SandboxCreateConfiguration, SessionWithToken } from "./types.js";
7
+ import { SandboxConfiguration, SessionWithToken } from "./types.js";
8
8
  export declare class SandboxInstance {
9
9
  private sandbox;
10
10
  fs: SandboxFileSystem;
@@ -21,10 +21,10 @@ export declare class SandboxInstance {
21
21
  maxWait?: number;
22
22
  interval?: number;
23
23
  }): Promise<void>;
24
- static create(sandbox?: SandboxModel | SandboxCreateConfiguration): Promise<SandboxInstance>;
24
+ static create(sandbox: SandboxModel): Promise<SandboxInstance>;
25
25
  static get(sandboxName: string): Promise<SandboxInstance>;
26
26
  static list(): Promise<SandboxInstance[]>;
27
27
  static delete(sandboxName: string): Promise<SandboxModel>;
28
- static createIfNotExists(sandbox: SandboxModel | SandboxCreateConfiguration): Promise<SandboxInstance>;
28
+ static createIfNotExists(sandbox: SandboxModel): Promise<SandboxInstance>;
29
29
  static fromSession(session: SessionWithToken): Promise<SandboxInstance>;
30
30
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SandboxInstance = void 0;
4
- const uuid_1 = require("uuid");
5
4
  const index_js_1 = require("../client/index.js");
6
5
  const logger_js_1 = require("../common/logger.js");
7
6
  const index_js_2 = require("./filesystem/index.js");
@@ -62,36 +61,11 @@ class SandboxInstance {
62
61
  }
63
62
  }
64
63
  static async create(sandbox) {
65
- const defaultName = `sandbox-${(0, uuid_1.v4)().replace(/-/g, '').substring(0, 8)}`;
66
- const defaultImage = "blaxel/prod-base:latest";
67
- const defaultMemory = 4096;
68
- if (!sandbox || 'name' in sandbox || 'image' in sandbox || 'memory' in sandbox) {
69
- if (!sandbox)
70
- sandbox = {};
71
- if (!sandbox.name)
72
- sandbox.name = defaultName;
73
- if (!sandbox.image)
74
- sandbox.image = defaultImage;
75
- if (!sandbox.memory)
76
- sandbox.memory = defaultMemory;
77
- sandbox = {
78
- metadata: { name: sandbox.name },
79
- spec: { runtime: { image: sandbox.image, memory: sandbox.memory, generation: "mk3" } }
80
- };
64
+ if (sandbox.spec?.runtime?.generation == undefined) {
65
+ sandbox.spec = sandbox.spec ?? { runtime: {} };
66
+ sandbox.spec.runtime = sandbox.spec.runtime ?? {};
67
+ sandbox.spec.runtime.generation = "mk3";
81
68
  }
82
- sandbox = sandbox;
83
- if (!sandbox.metadata) {
84
- sandbox.metadata = { name: crypto.randomUUID().replace(/-/g, '') };
85
- }
86
- if (!sandbox.spec) {
87
- sandbox.spec = { runtime: { image: "blaxel/prod-base:latest" } };
88
- }
89
- if (!sandbox.spec.runtime) {
90
- sandbox.spec.runtime = { image: defaultImage, memory: defaultMemory };
91
- }
92
- sandbox.spec.runtime.image = sandbox.spec.runtime.image || defaultImage;
93
- sandbox.spec.runtime.memory = sandbox.spec.runtime.memory || defaultMemory;
94
- sandbox.spec.runtime.generation = sandbox.spec.runtime.generation || "mk3";
95
69
  const { data } = await (0, index_js_1.createSandbox)({
96
70
  body: sandbox,
97
71
  throwOnError: true,
@@ -122,11 +96,7 @@ class SandboxInstance {
122
96
  }
123
97
  static async createIfNotExists(sandbox) {
124
98
  try {
125
- const name = 'name' in sandbox ? sandbox.name : sandbox.metadata?.name;
126
- if (!name) {
127
- throw new Error("Sandbox name is required");
128
- }
129
- const sandboxInstance = await SandboxInstance.get(name);
99
+ const sandboxInstance = await SandboxInstance.get(sandbox.metadata?.name ?? "");
130
100
  return sandboxInstance;
131
101
  }
132
102
  catch (e) {
@@ -138,16 +108,7 @@ class SandboxInstance {
138
108
  }
139
109
  /* eslint-disable */
140
110
  static async fromSession(session) {
141
- // Create a minimal sandbox configuration for session-based access
142
- const sandboxName = session.name.includes("-") ? session.name.split("-")[0] : session.name;
143
- const sandbox = {
144
- metadata: { name: sandboxName },
145
- forceUrl: session.url,
146
- headers: { "X-Blaxel-Preview-Token": session.token },
147
- params: { bl_preview_token: session.token }
148
- };
149
- // Create instance using constructor instead of direct property assignment
150
- return new SandboxInstance(sandbox);
111
+ return new SandboxInstance({ forceUrl: session.url, params: { bl_preview_token: session.token }, headers: { "X-Blaxel-Preview-Token": session.token } });
151
112
  }
152
113
  }
153
114
  exports.SandboxInstance = SandboxInstance;
@@ -15,8 +15,3 @@ export type SandboxConfiguration = {
15
15
  headers?: Record<string, string>;
16
16
  params?: Record<string, string>;
17
17
  } & Sandbox;
18
- export type SandboxCreateConfiguration = {
19
- name?: string;
20
- image?: string;
21
- memory?: number;
22
- };
@@ -20,7 +20,7 @@ export interface BlaxelSpan {
20
20
  /** Record an error on the span */
21
21
  recordException(error: Error): void;
22
22
  /** Set the status of the span */
23
- setStatus(status: "ok" | "error", message?: string): void;
23
+ setStatus(status: 'ok' | 'error', message?: string): void;
24
24
  /** End the span */
25
25
  end(): void;
26
26
  /** Get the span context (for passing to child spans) */
@@ -34,15 +34,22 @@ export interface BlaxelTelemetryProvider {
34
34
  startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
35
35
  /** Flush the telemetry provider */
36
36
  flush(): Promise<void>;
37
- /** Extract context from headers for manual context propagation */
38
- extractContextFromHeaders?(headers: Record<string, string | string[]>): unknown;
39
37
  }
40
38
  /**
41
- * Registry for telemetry providers
39
+ * Registry for managing the global telemetry provider
42
40
  */
43
41
  declare class TelemetryRegistry {
42
+ private static instance;
44
43
  private provider;
44
+ private constructor();
45
+ static getInstance(): TelemetryRegistry;
46
+ /**
47
+ * Register a telemetry provider implementation
48
+ */
45
49
  registerProvider(provider: BlaxelTelemetryProvider): void;
50
+ /**
51
+ * Get the current telemetry provider
52
+ */
46
53
  getProvider(): BlaxelTelemetryProvider;
47
54
  }
48
55
  export declare const telemetryRegistry: TelemetryRegistry;
@@ -51,18 +58,5 @@ export declare const telemetryRegistry: TelemetryRegistry;
51
58
  */
52
59
  export declare function startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
53
60
  export declare function withSpan<T>(name: string, fn: () => Promise<T>, options?: BlaxelSpanOptions): Promise<T>;
54
- /**
55
- * Extract context from headers - useful for manual context propagation
56
- * when you have traceparent headers but no active span
57
- */
58
- export declare function extractContextFromHeaders(headers: Record<string, string | string[]>): unknown;
59
- /**
60
- * Create a span with extracted context from headers
61
- * This is useful when you need to manually establish trace context
62
- */
63
- export declare function startSpanWithHeaders(name: string, headers: Record<string, string | string[]>, options?: Omit<BlaxelSpanOptions, "parentContext">): BlaxelSpan;
64
- /**
65
- * Flush the telemetry provider
66
- */
67
61
  export declare function flush(): Promise<void>;
68
62
  export {};
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.telemetryRegistry = void 0;
5
5
  exports.startSpan = startSpan;
6
6
  exports.withSpan = withSpan;
7
- exports.extractContextFromHeaders = extractContextFromHeaders;
8
- exports.startSpanWithHeaders = startSpanWithHeaders;
9
7
  exports.flush = flush;
10
8
  /**
11
9
  * No-operation implementation of Span
@@ -16,9 +14,7 @@ class NoopSpan {
16
14
  recordException() { }
17
15
  setStatus() { }
18
16
  end() { }
19
- getContext() {
20
- return null;
21
- }
17
+ getContext() { return null; }
22
18
  }
23
19
  /**
24
20
  * No-operation implementation of TelemetryProvider
@@ -27,25 +23,38 @@ class NoopTelemetryProvider {
27
23
  startSpan() {
28
24
  return new NoopSpan();
29
25
  }
30
- async flush() { }
31
- extractContextFromHeaders() {
32
- return null;
26
+ flush() {
27
+ return Promise.resolve();
33
28
  }
34
29
  }
35
30
  /**
36
- * Registry for telemetry providers
31
+ * Registry for managing the global telemetry provider
37
32
  */
38
33
  class TelemetryRegistry {
34
+ static instance;
39
35
  provider = new NoopTelemetryProvider();
36
+ constructor() { }
37
+ static getInstance() {
38
+ if (!TelemetryRegistry.instance) {
39
+ TelemetryRegistry.instance = new TelemetryRegistry();
40
+ }
41
+ return TelemetryRegistry.instance;
42
+ }
43
+ /**
44
+ * Register a telemetry provider implementation
45
+ */
40
46
  registerProvider(provider) {
41
47
  this.provider = provider;
42
48
  }
49
+ /**
50
+ * Get the current telemetry provider
51
+ */
43
52
  getProvider() {
44
53
  return this.provider;
45
54
  }
46
55
  }
47
- // Global instance
48
- exports.telemetryRegistry = new TelemetryRegistry();
56
+ // Export singleton instance
57
+ exports.telemetryRegistry = TelemetryRegistry.getInstance();
49
58
  // Convenience functions that delegate to the provider
50
59
  /**
51
60
  * Create a span with the registered provider
@@ -66,31 +75,6 @@ async function withSpan(name, fn, options) {
66
75
  throw error;
67
76
  }
68
77
  }
69
- /**
70
- * Extract context from headers - useful for manual context propagation
71
- * when you have traceparent headers but no active span
72
- */
73
- function extractContextFromHeaders(headers) {
74
- const provider = exports.telemetryRegistry.getProvider();
75
- if (provider.extractContextFromHeaders) {
76
- return provider.extractContextFromHeaders(headers);
77
- }
78
- return null;
79
- }
80
- /**
81
- * Create a span with extracted context from headers
82
- * This is useful when you need to manually establish trace context
83
- */
84
- function startSpanWithHeaders(name, headers, options) {
85
- const extractedContext = extractContextFromHeaders(headers);
86
- return startSpan(name, {
87
- ...options,
88
- parentContext: extractedContext || undefined,
89
- });
90
- }
91
- /**
92
- * Flush the telemetry provider
93
- */
94
78
  async function flush() {
95
- return exports.telemetryRegistry.getProvider().flush();
79
+ await exports.telemetryRegistry.getProvider().flush();
96
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.18-dev.157",
3
+ "version": "0.2.18-preview.39",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",