tensorlake 0.5.6 → 0.5.7

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 +1 @@
1
- export { A as CreateSandboxImageOptions, E as DockerfileBuildPlan, F as DockerfileInstruction, V as SandboxImageSource, Z as createSandboxImage, $ as defaultRegisteredName, a0 as loadDockerfilePlan, a1 as loadImagePlan, a2 as logicalDockerfileLines, a3 as runCreateSandboxImageCli } from './sandbox-image-BmhjX2bC.cjs';
1
+ export { A as CreateSandboxImageOptions, E as DockerfileBuildPlan, F as DockerfileInstruction, V as SandboxImageSource, Z as createSandboxImage, $ as defaultRegisteredName, a0 as loadDockerfilePlan, a1 as loadImagePlan, a2 as logicalDockerfileLines, a3 as runCreateSandboxImageCli } from './sandbox-image-BMDaNpZ2.cjs';
@@ -1 +1 @@
1
- export { A as CreateSandboxImageOptions, E as DockerfileBuildPlan, F as DockerfileInstruction, V as SandboxImageSource, Z as createSandboxImage, $ as defaultRegisteredName, a0 as loadDockerfilePlan, a1 as loadImagePlan, a2 as logicalDockerfileLines, a3 as runCreateSandboxImageCli } from './sandbox-image-BmhjX2bC.js';
1
+ export { A as CreateSandboxImageOptions, E as DockerfileBuildPlan, F as DockerfileInstruction, V as SandboxImageSource, Z as createSandboxImage, $ as defaultRegisteredName, a0 as loadDockerfilePlan, a1 as loadImagePlan, a2 as logicalDockerfileLines, a3 as runCreateSandboxImageCli } from './sandbox-image-BMDaNpZ2.js';
@@ -61,7 +61,7 @@ var SDK_VERSION, API_URL, API_KEY, NAMESPACE, SANDBOX_PROXY_URL, DEFAULT_HTTP_TI
61
61
  var init_defaults = __esm({
62
62
  "src/defaults.ts"() {
63
63
  "use strict";
64
- SDK_VERSION = "0.4.49";
64
+ SDK_VERSION = "0.5.7";
65
65
  API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
66
66
  API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
67
67
  NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -242,6 +242,9 @@ var init_http = __esm({
242
242
  if (options.hostHeader) {
243
243
  this.headers["Host"] = options.hostHeader;
244
244
  }
245
+ if (options.sandboxIdHeader) {
246
+ this.headers["X-Tensorlake-Sandbox-Id"] = options.sandboxIdHeader;
247
+ }
245
248
  if (options.routingHint) {
246
249
  this.headers["X-Tensorlake-Route-Hint"] = options.routingHint;
247
250
  }
@@ -2868,21 +2871,36 @@ function resolveProxyTarget(proxyUrl, sandboxId) {
2868
2871
  if (host === "localhost" || host === "127.0.0.1") {
2869
2872
  return {
2870
2873
  baseUrl: trimTrailingSlashes(proxyUrl),
2871
- hostHeader: `${sandboxId}.local`
2874
+ hostHeader: `${sandboxId}.local`,
2875
+ sandboxIdHeader: void 0
2872
2876
  };
2873
2877
  }
2874
2878
  const port = parsed.port ? `:${parsed.port}` : "";
2875
2879
  return {
2876
- baseUrl: `${parsed.protocol}//${sandboxId}.${host}${port}`,
2877
- hostHeader: void 0
2880
+ baseUrl: `${parsed.protocol}//${host}${port}`,
2881
+ hostHeader: void 0,
2882
+ sandboxIdHeader: sandboxId
2878
2883
  };
2879
2884
  } catch {
2880
2885
  return {
2881
2886
  baseUrl: `${trimTrailingSlashes(proxyUrl)}/${sandboxId}`,
2882
- hostHeader: void 0
2887
+ hostHeader: void 0,
2888
+ sandboxIdHeader: void 0
2883
2889
  };
2884
2890
  }
2885
2891
  }
2892
+ function resolveSandboxLifecycleUrl(apiUrl) {
2893
+ if (isLocalhost(apiUrl)) return apiUrl;
2894
+ try {
2895
+ const parsed = new URL(apiUrl);
2896
+ if (parsed.hostname.startsWith("api.")) {
2897
+ parsed.hostname = "sandbox." + parsed.hostname.slice(4);
2898
+ return parsed.toString().replace(/\/$/, "");
2899
+ }
2900
+ } catch {
2901
+ }
2902
+ return apiUrl;
2903
+ }
2886
2904
  function lifecyclePath(path2, isLocal, namespace) {
2887
2905
  if (isLocal) {
2888
2906
  return `/v1/namespaces/${namespace}/${path2}`;
@@ -3109,7 +3127,7 @@ var init_sandbox = __esm({
3109
3127
  this.sandboxId = options.sandboxId;
3110
3128
  this.lifecycleIdentifier = options.sandboxId;
3111
3129
  const proxyUrl = options.proxyUrl ?? SANDBOX_PROXY_URL;
3112
- const { baseUrl, hostHeader } = resolveProxyTarget(proxyUrl, options.sandboxId);
3130
+ const { baseUrl, hostHeader, sandboxIdHeader } = resolveProxyTarget(proxyUrl, options.sandboxId);
3113
3131
  this.baseUrl = baseUrl;
3114
3132
  this.wsHeaders = {};
3115
3133
  if (options.apiKey) {
@@ -3124,12 +3142,16 @@ var init_sandbox = __esm({
3124
3142
  if (hostHeader) {
3125
3143
  this.wsHeaders.Host = hostHeader;
3126
3144
  }
3145
+ if (sandboxIdHeader) {
3146
+ this.wsHeaders["X-Tensorlake-Sandbox-Id"] = sandboxIdHeader;
3147
+ }
3127
3148
  this.http = new HttpClient({
3128
3149
  baseUrl,
3129
3150
  apiKey: options.apiKey,
3130
3151
  organizationId: options.organizationId,
3131
3152
  projectId: options.projectId,
3132
3153
  hostHeader,
3154
+ sandboxIdHeader,
3133
3155
  routingHint: options.routingHint
3134
3156
  });
3135
3157
  }
@@ -3170,8 +3192,8 @@ var init_sandbox = __esm({
3170
3192
  /**
3171
3193
  * Attach to an existing sandbox and return a connected handle.
3172
3194
  *
3173
- * Verifies the sandbox exists via a server GET call, then returns a handle
3174
- * in whatever state the sandbox is in. Does **not** auto-resume a suspended
3195
+ * Returns immediately without contacting the server. Call `sandbox.info()`
3196
+ * to fetch the current state on demand. Does **not** auto-resume a suspended
3175
3197
  * sandbox — call `sandbox.resume()` explicitly.
3176
3198
  */
3177
3199
  static async connect(options) {
@@ -3181,15 +3203,12 @@ var init_sandbox = __esm({
3181
3203
  /* _internal */
3182
3204
  true
3183
3205
  );
3184
- const info = await client.get(options.sandboxId);
3185
3206
  const sandbox = client.connect(
3186
- info.sandboxId,
3207
+ options.sandboxId,
3187
3208
  options.proxyUrl,
3188
- options.routingHint ?? info.routingHint
3209
+ options.routingHint
3189
3210
  );
3190
3211
  sandbox.lifecycleClient = client;
3191
- sandbox._setLifecycleIdentifier(info.sandboxId);
3192
- sandbox._setName(info.name ?? null);
3193
3212
  return sandbox;
3194
3213
  }
3195
3214
  // --- Static snapshot management ---
@@ -3213,6 +3232,26 @@ var init_sandbox = __esm({
3213
3232
  );
3214
3233
  await client.deleteSnapshot(snapshotId);
3215
3234
  }
3235
+ /** List all sandboxes. No sandbox handle needed. */
3236
+ static async list(options) {
3237
+ const { SandboxClient: SandboxClient2 } = await Promise.resolve().then(() => (init_client(), client_exports));
3238
+ const client = new SandboxClient2(
3239
+ options,
3240
+ /* _internal */
3241
+ true
3242
+ );
3243
+ return client.list();
3244
+ }
3245
+ /** List all snapshots in the project. No sandbox handle needed. */
3246
+ static async listSnapshots(options) {
3247
+ const { SandboxClient: SandboxClient2 } = await Promise.resolve().then(() => (init_client(), client_exports));
3248
+ const client = new SandboxClient2(
3249
+ options,
3250
+ /* _internal */
3251
+ true
3252
+ );
3253
+ return client.listSnapshots();
3254
+ }
3216
3255
  // --- Instance lifecycle methods ---
3217
3256
  requireLifecycleClient(operation) {
3218
3257
  if (!this.lifecycleClient) {
@@ -3222,6 +3261,14 @@ var init_sandbox = __esm({
3222
3261
  }
3223
3262
  return this.lifecycleClient;
3224
3263
  }
3264
+ /** Fetch the current sandbox information from the server on demand. */
3265
+ async info() {
3266
+ const client = this.requireLifecycleClient("info");
3267
+ const info = await client.get(this.lifecycleIdentifier);
3268
+ this._setLifecycleIdentifier(info.sandboxId);
3269
+ this._setName(info.name ?? null);
3270
+ return info;
3271
+ }
3225
3272
  /**
3226
3273
  * Fetch the current sandbox status from the server.
3227
3274
  *
@@ -3329,6 +3376,7 @@ var init_sandbox = __esm({
3329
3376
  "/api/v1/processes/run",
3330
3377
  { json: body }
3331
3378
  );
3379
+ const traceId = sseStream.traceId;
3332
3380
  const stdoutLines = [];
3333
3381
  const stderrLines = [];
3334
3382
  let exitCode = -1;
@@ -3347,11 +3395,10 @@ var init_sandbox = __esm({
3347
3395
  }
3348
3396
  }
3349
3397
  }
3350
- return {
3351
- exitCode,
3352
- stdout: stdoutLines.join("\n"),
3353
- stderr: stderrLines.join("\n")
3354
- };
3398
+ return Object.assign(
3399
+ { exitCode, stdout: stdoutLines.join("\n"), stderr: stderrLines.join("\n") },
3400
+ { traceId }
3401
+ );
3355
3402
  }
3356
3403
  // --- Process management ---
3357
3404
  /**
@@ -3381,7 +3428,7 @@ var init_sandbox = __esm({
3381
3428
  "/api/v1/processes",
3382
3429
  { body: payload }
3383
3430
  );
3384
- return fromSnakeKeys(raw);
3431
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3385
3432
  }
3386
3433
  /** List all processes (running and exited) tracked by the sandbox daemon. */
3387
3434
  async listProcesses() {
@@ -3398,7 +3445,7 @@ var init_sandbox = __esm({
3398
3445
  "GET",
3399
3446
  `/api/v1/processes/${pid}`
3400
3447
  );
3401
- return fromSnakeKeys(raw);
3448
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3402
3449
  }
3403
3450
  /** Send SIGKILL to a process. */
3404
3451
  async killProcess(pid) {
@@ -3411,7 +3458,7 @@ var init_sandbox = __esm({
3411
3458
  `/api/v1/processes/${pid}/signal`,
3412
3459
  { body: { signal } }
3413
3460
  );
3414
- return fromSnakeKeys(raw);
3461
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3415
3462
  }
3416
3463
  // --- Process I/O ---
3417
3464
  /** Write bytes to a process's stdin. The process must have been started with `stdinMode: StdinMode.PIPE`. */
@@ -3431,7 +3478,7 @@ var init_sandbox = __esm({
3431
3478
  "GET",
3432
3479
  `/api/v1/processes/${pid}/stdout`
3433
3480
  );
3434
- return fromSnakeKeys(raw);
3481
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3435
3482
  }
3436
3483
  /** Return all captured stderr lines produced so far by a process. */
3437
3484
  async getStderr(pid) {
@@ -3439,7 +3486,7 @@ var init_sandbox = __esm({
3439
3486
  "GET",
3440
3487
  `/api/v1/processes/${pid}/stderr`
3441
3488
  );
3442
- return fromSnakeKeys(raw);
3489
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3443
3490
  }
3444
3491
  /** Return all captured stdout+stderr lines produced so far by a process. */
3445
3492
  async getOutput(pid) {
@@ -3447,7 +3494,7 @@ var init_sandbox = __esm({
3447
3494
  "GET",
3448
3495
  `/api/v1/processes/${pid}/output`
3449
3496
  );
3450
- return fromSnakeKeys(raw);
3497
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3451
3498
  }
3452
3499
  // --- Streaming (SSE) ---
3453
3500
  /** Stream stdout events from a process until it exits. Yields one `OutputEvent` per line. */
@@ -3521,7 +3568,7 @@ var init_sandbox = __esm({
3521
3568
  "GET",
3522
3569
  `/api/v1/files/list?path=${encodeURIComponent(path2)}`
3523
3570
  );
3524
- return fromSnakeKeys(raw);
3571
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3525
3572
  }
3526
3573
  // --- PTY ---
3527
3574
  /** Create an interactive PTY session. Returns a `sessionId` and `token` for WebSocket connection via `connectPty()`. */
@@ -3539,7 +3586,7 @@ var init_sandbox = __esm({
3539
3586
  "/api/v1/pty",
3540
3587
  { body: payload }
3541
3588
  );
3542
- return fromSnakeKeys(raw);
3589
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3543
3590
  }
3544
3591
  /** Create a PTY session and connect to it immediately. Cleans up the session if the WebSocket connection fails. */
3545
3592
  async createPty(options) {
@@ -3658,15 +3705,15 @@ var init_sandbox = __esm({
3658
3705
  "GET",
3659
3706
  "/api/v1/health"
3660
3707
  );
3661
- return fromSnakeKeys(raw);
3708
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3662
3709
  }
3663
3710
  /** Get sandbox daemon info (version, uptime, process counts). */
3664
- async info() {
3711
+ async daemonInfo() {
3665
3712
  const raw = await this.http.requestJson(
3666
3713
  "GET",
3667
3714
  "/api/v1/info"
3668
3715
  );
3669
- return fromSnakeKeys(raw);
3716
+ return Object.assign(fromSnakeKeys(raw), { traceId: raw.traceId });
3670
3717
  }
3671
3718
  };
3672
3719
  }
@@ -3759,7 +3806,7 @@ var init_client = __esm({
3759
3806
  this.namespace = options?.namespace ?? NAMESPACE;
3760
3807
  this.local = isLocalhost(this.apiUrl);
3761
3808
  this.http = new HttpClient({
3762
- baseUrl: this.apiUrl,
3809
+ baseUrl: resolveSandboxLifecycleUrl(this.apiUrl),
3763
3810
  apiKey: this.apiKey,
3764
3811
  organizationId: this.organizationId,
3765
3812
  projectId: this.projectId,
@@ -3827,7 +3874,7 @@ var init_client = __esm({
3827
3874
  "GET",
3828
3875
  this.path(`sandboxes/${sandboxId}`)
3829
3876
  );
3830
- return fromSnakeKeys(raw, "sandboxId");
3877
+ return Object.assign(fromSnakeKeys(raw, "sandboxId"), { traceId: raw.traceId });
3831
3878
  }
3832
3879
  /** List all sandboxes in the namespace. */
3833
3880
  async list() {
@@ -3858,7 +3905,7 @@ var init_client = __esm({
3858
3905
  this.path(`sandboxes/${sandboxId}`),
3859
3906
  { body }
3860
3907
  );
3861
- return fromSnakeKeys(raw, "sandboxId");
3908
+ return Object.assign(fromSnakeKeys(raw, "sandboxId"), { traceId: raw.traceId });
3862
3909
  }
3863
3910
  /** Get the current proxy port settings for a sandbox. */
3864
3911
  async getPortAccess(sandboxId) {
@@ -4000,7 +4047,7 @@ var init_client = __esm({
4000
4047
  "GET",
4001
4048
  this.path(`snapshots/${snapshotId}`)
4002
4049
  );
4003
- return fromSnakeKeys(raw, "snapshotId");
4050
+ return Object.assign(fromSnakeKeys(raw, "snapshotId"), { traceId: raw.traceId });
4004
4051
  }
4005
4052
  /** List all snapshots in the namespace. */
4006
4053
  async listSnapshots() {