@blaxel/core 0.2.18 → 0.2.19-dev.158

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.
@@ -1,3 +1,4 @@
1
- export { deleteFilesystemByPath, deleteNetworkProcessByPidMonitor, deleteProcessByIdentifier, deleteProcessByIdentifierKill, Directory, ErrorResponse, File, FileRequest, FileWithContent, getFilesystemByPath, getNetworkProcessByPidPorts, getProcess, getProcessByIdentifier, getProcessByIdentifierLogs, getProcessByIdentifierLogsStream, PortMonitorRequest, postNetworkProcessByPidMonitor, postProcess, ProcessRequest, ProcessResponse, putFilesystemByPath, SuccessResponse } from "./client/index.js";
1
+ export { Directory, ErrorResponse, File, FileRequest, FileWithContent, PortMonitorRequest, ProcessRequest, ProcessResponse, SuccessResponse, deleteFilesystemByPath, deleteNetworkProcessByPidMonitor, deleteProcessByIdentifier, deleteProcessByIdentifierKill, getFilesystemByPath, getNetworkProcessByPidPorts, getProcess, getProcessByIdentifier, getProcessByIdentifierLogs, getProcessByIdentifierLogsStream, postNetworkProcessByPidMonitor, postProcess, putFilesystemByPath } from "./client/index.js";
2
2
  export * from "./filesystem/index.js";
3
3
  export * from "./sandbox.js";
4
+ export * from "./types.js";
@@ -32,4 +32,5 @@ Object.defineProperty(exports, "postProcess", { enumerable: true, get: function
32
32
  Object.defineProperty(exports, "putFilesystemByPath", { enumerable: true, get: function () { return index_js_1.putFilesystemByPath; } });
33
33
  __exportStar(require("./filesystem/index.js"), exports);
34
34
  __exportStar(require("./sandbox.js"), exports);
35
+ __exportStar(require("./types.js"), exports);
35
36
  // Re-export everything from client except ClientOptions to avoid conflict
@@ -9,6 +9,7 @@ const index_js_3 = require("./network/index.js");
9
9
  const preview_js_1 = require("./preview.js");
10
10
  const index_js_4 = require("./process/index.js");
11
11
  const session_js_1 = require("./session.js");
12
+ const types_js_1 = require("./types.js");
12
13
  class SandboxInstance {
13
14
  sandbox;
14
15
  fs;
@@ -65,7 +66,8 @@ class SandboxInstance {
65
66
  const defaultName = `sandbox-${(0, uuid_1.v4)().replace(/-/g, '').substring(0, 8)}`;
66
67
  const defaultImage = "blaxel/prod-base:latest";
67
68
  const defaultMemory = 4096;
68
- if (!sandbox || 'name' in sandbox || 'image' in sandbox || 'memory' in sandbox) {
69
+ // Handle SandboxCreateConfiguration or simple dict with name/image/memory/ports keys
70
+ if (!sandbox || 'name' in sandbox || 'image' in sandbox || 'memory' in sandbox || 'ports' in sandbox) {
69
71
  if (!sandbox)
70
72
  sandbox = {};
71
73
  if (!sandbox.name)
@@ -74,9 +76,17 @@ class SandboxInstance {
74
76
  sandbox.image = defaultImage;
75
77
  if (!sandbox.memory)
76
78
  sandbox.memory = defaultMemory;
79
+ const ports = (0, types_js_1.normalizePorts)(sandbox.ports);
77
80
  sandbox = {
78
81
  metadata: { name: sandbox.name },
79
- spec: { runtime: { image: sandbox.image, memory: sandbox.memory, generation: "mk3" } }
82
+ spec: {
83
+ runtime: {
84
+ image: sandbox.image,
85
+ memory: sandbox.memory,
86
+ ports: ports,
87
+ generation: "mk3"
88
+ }
89
+ }
80
90
  };
81
91
  }
82
92
  sandbox = sandbox;
@@ -1,4 +1,4 @@
1
- import { Sandbox } from "../client/types.gen";
1
+ import { Port, Sandbox } from "../client/types.gen";
2
2
  export interface SessionCreateOptions {
3
3
  expiresAt?: Date;
4
4
  responseHeaders?: Record<string, string>;
@@ -19,4 +19,6 @@ export type SandboxCreateConfiguration = {
19
19
  name?: string;
20
20
  image?: string;
21
21
  memory?: number;
22
+ ports?: (Port | Record<string, any>)[];
22
23
  };
24
+ export declare function normalizePorts(ports?: (Port | Record<string, any>)[]): Port[] | undefined;
@@ -1,2 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizePorts = normalizePorts;
4
+ function normalizePorts(ports) {
5
+ if (!ports || ports.length === 0) {
6
+ return undefined;
7
+ }
8
+ const portObjects = [];
9
+ for (const port of ports) {
10
+ if (typeof port === 'object' && port !== null) {
11
+ if ('name' in port || 'target' in port || 'protocol' in port) {
12
+ // It's a Port-like object, ensure protocol defaults to HTTP
13
+ const normalizedPort = {
14
+ name: typeof port.name === 'string' ? port.name : undefined,
15
+ target: typeof port.target === 'number' ? port.target : undefined,
16
+ protocol: typeof port.protocol === 'string' ? port.protocol : "HTTP"
17
+ };
18
+ portObjects.push(normalizedPort);
19
+ }
20
+ else {
21
+ throw new Error(`Invalid port type: ${typeof port}. Expected Port object or object with port properties.`);
22
+ }
23
+ }
24
+ else {
25
+ throw new Error(`Invalid port type: ${typeof port}. Expected Port object or object with port properties.`);
26
+ }
27
+ }
28
+ return portObjects;
29
+ }
@@ -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,22 +34,15 @@ 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;
37
39
  }
38
40
  /**
39
- * Registry for managing the global telemetry provider
41
+ * Registry for telemetry providers
40
42
  */
41
43
  declare class TelemetryRegistry {
42
- private static instance;
43
44
  private provider;
44
- private constructor();
45
- static getInstance(): TelemetryRegistry;
46
- /**
47
- * Register a telemetry provider implementation
48
- */
49
45
  registerProvider(provider: BlaxelTelemetryProvider): void;
50
- /**
51
- * Get the current telemetry provider
52
- */
53
46
  getProvider(): BlaxelTelemetryProvider;
54
47
  }
55
48
  export declare const telemetryRegistry: TelemetryRegistry;
@@ -58,5 +51,18 @@ export declare const telemetryRegistry: TelemetryRegistry;
58
51
  */
59
52
  export declare function startSpan(name: string, options?: BlaxelSpanOptions): BlaxelSpan;
60
53
  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
+ */
61
67
  export declare function flush(): Promise<void>;
62
68
  export {};
@@ -4,6 +4,8 @@ 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;
7
9
  exports.flush = flush;
8
10
  /**
9
11
  * No-operation implementation of Span
@@ -14,7 +16,9 @@ class NoopSpan {
14
16
  recordException() { }
15
17
  setStatus() { }
16
18
  end() { }
17
- getContext() { return null; }
19
+ getContext() {
20
+ return null;
21
+ }
18
22
  }
19
23
  /**
20
24
  * No-operation implementation of TelemetryProvider
@@ -23,38 +27,25 @@ class NoopTelemetryProvider {
23
27
  startSpan() {
24
28
  return new NoopSpan();
25
29
  }
26
- flush() {
27
- return Promise.resolve();
30
+ async flush() { }
31
+ extractContextFromHeaders() {
32
+ return null;
28
33
  }
29
34
  }
30
35
  /**
31
- * Registry for managing the global telemetry provider
36
+ * Registry for telemetry providers
32
37
  */
33
38
  class TelemetryRegistry {
34
- static instance;
35
39
  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
- */
46
40
  registerProvider(provider) {
47
41
  this.provider = provider;
48
42
  }
49
- /**
50
- * Get the current telemetry provider
51
- */
52
43
  getProvider() {
53
44
  return this.provider;
54
45
  }
55
46
  }
56
- // Export singleton instance
57
- exports.telemetryRegistry = TelemetryRegistry.getInstance();
47
+ // Global instance
48
+ exports.telemetryRegistry = new TelemetryRegistry();
58
49
  // Convenience functions that delegate to the provider
59
50
  /**
60
51
  * Create a span with the registered provider
@@ -75,6 +66,31 @@ async function withSpan(name, fn, options) {
75
66
  throw error;
76
67
  }
77
68
  }
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
+ */
78
94
  async function flush() {
79
- await exports.telemetryRegistry.getProvider().flush();
95
+ return exports.telemetryRegistry.getProvider().flush();
80
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.18",
3
+ "version": "0.2.19-dev.158",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",