@tensorlakeai/tensorlake 0.5.156 → 0.5.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.
package/dist/index.d.cts CHANGED
@@ -67,6 +67,8 @@ interface NativeSandboxProxyClient {
67
67
  }
68
68
  interface NativeSandboxClient {
69
69
  createSandbox(requestJson: string): Promise<TracedJson>;
70
+ /** Blocking create for createAndConnect: a `running`, `failed` or `timeout` record. */
71
+ createSandboxAndWait(requestJson: string): Promise<TracedJson>;
70
72
  /** Wait-free create (`wait: false`, ADR 0086). */
71
73
  createSandboxNoWait(requestJson: string): Promise<TracedJson>;
72
74
  /** Poll the sandbox until it leaves `pending` or the budget runs out; resolves with the last `SandboxInfo`. */
@@ -89,6 +91,7 @@ interface NativeSandboxClient {
89
91
  createSnapshot(sandboxId: string, snapshotType?: string | null): Promise<TracedJson>;
90
92
  getSnapshot(snapshotId: string): Promise<TracedJson>;
91
93
  listSnapshots(): Promise<TracedJson>;
94
+ listSandboxSnapshots(sandboxId: string): Promise<TracedJson>;
92
95
  deleteSnapshot(snapshotId: string): Promise<string>;
93
96
  createPool(requestJson: string): Promise<TracedJson>;
94
97
  getPool(poolId: string): Promise<TracedJson>;
@@ -896,7 +899,10 @@ interface CreateAndConnectOptions extends CreateSandboxOptions {
896
899
  * false: throw `SandboxPending` and leave the sandbox queued.
897
900
  */
898
901
  cancelOnTimeout?: boolean;
899
- /** Seconds between readiness polls. Default: 2. */
902
+ /**
903
+ * Seconds between readiness polls once the server's own wait has run out.
904
+ * Default: 2.
905
+ */
900
906
  pollInterval?: number;
901
907
  }
902
908
  /**
@@ -1114,8 +1120,8 @@ declare class Sandbox {
1114
1120
  *
1115
1121
  * Covers both fresh sandbox creation and restore-from-snapshot (set
1116
1122
  * `snapshotId`). With `wait` unset or `true` it blocks until the sandbox
1117
- * is `Running`: the create is sent with `wait: false` and the sandbox is
1118
- * polled every two seconds, with `requestTimeout` as the wait budget.
1123
+ * is `Running`: the server waits and answers as soon as it runs, with
1124
+ * `requestTimeout` as the wait budget.
1119
1125
  *
1120
1126
  * With `wait: false` it returns a {@link PendingSandbox} at once:
1121
1127
  * `pending.ready()` waits for it, `pending.status()` looks at it, and
@@ -1629,6 +1635,11 @@ declare class SandboxClient {
1629
1635
  getSnapshot(snapshotId: string): Promise<Traced<SnapshotInfo>>;
1630
1636
  /** List all snapshots in the namespace. */
1631
1637
  listSnapshots(): Promise<Traced<SnapshotInfo[]>>;
1638
+ /**
1639
+ * List snapshots taken from one sandbox (its ID or name), from the
1640
+ * sandbox's own listing rather than the whole namespace's.
1641
+ */
1642
+ listSandboxSnapshots(sandboxId: string): Promise<Traced<SnapshotInfo[]>>;
1632
1643
  /** Delete a snapshot by ID. */
1633
1644
  deleteSnapshot(snapshotId: string): Promise<void>;
1634
1645
  /**
@@ -1663,10 +1674,9 @@ declare class SandboxClient {
1663
1674
  /**
1664
1675
  * Create a sandbox, wait for it to reach `Running`, and return a connected handle.
1665
1676
  *
1666
- * This is `create({ wait: false })` followed by `PendingSandbox.ready()`
1667
- * polling every `pollInterval` seconds, with `requestTimeout` as the wait
1668
- * budget, in one call. The returned `Sandbox` auto-terminates when
1669
- * `terminate()` is called.
1677
+ * The create waits on the server, which answers as soon as the sandbox
1678
+ * runs, with `requestTimeout` as the wait budget. The returned `Sandbox`
1679
+ * auto-terminates when `terminate()` is called.
1670
1680
  *
1671
1681
  * **When the wait runs out the sandbox is not deleted.** A `SandboxPending`
1672
1682
  * is thrown with the sandbox id, and the sandbox keeps its place in the
package/dist/index.d.ts CHANGED
@@ -67,6 +67,8 @@ interface NativeSandboxProxyClient {
67
67
  }
68
68
  interface NativeSandboxClient {
69
69
  createSandbox(requestJson: string): Promise<TracedJson>;
70
+ /** Blocking create for createAndConnect: a `running`, `failed` or `timeout` record. */
71
+ createSandboxAndWait(requestJson: string): Promise<TracedJson>;
70
72
  /** Wait-free create (`wait: false`, ADR 0086). */
71
73
  createSandboxNoWait(requestJson: string): Promise<TracedJson>;
72
74
  /** Poll the sandbox until it leaves `pending` or the budget runs out; resolves with the last `SandboxInfo`. */
@@ -89,6 +91,7 @@ interface NativeSandboxClient {
89
91
  createSnapshot(sandboxId: string, snapshotType?: string | null): Promise<TracedJson>;
90
92
  getSnapshot(snapshotId: string): Promise<TracedJson>;
91
93
  listSnapshots(): Promise<TracedJson>;
94
+ listSandboxSnapshots(sandboxId: string): Promise<TracedJson>;
92
95
  deleteSnapshot(snapshotId: string): Promise<string>;
93
96
  createPool(requestJson: string): Promise<TracedJson>;
94
97
  getPool(poolId: string): Promise<TracedJson>;
@@ -896,7 +899,10 @@ interface CreateAndConnectOptions extends CreateSandboxOptions {
896
899
  * false: throw `SandboxPending` and leave the sandbox queued.
897
900
  */
898
901
  cancelOnTimeout?: boolean;
899
- /** Seconds between readiness polls. Default: 2. */
902
+ /**
903
+ * Seconds between readiness polls once the server's own wait has run out.
904
+ * Default: 2.
905
+ */
900
906
  pollInterval?: number;
901
907
  }
902
908
  /**
@@ -1114,8 +1120,8 @@ declare class Sandbox {
1114
1120
  *
1115
1121
  * Covers both fresh sandbox creation and restore-from-snapshot (set
1116
1122
  * `snapshotId`). With `wait` unset or `true` it blocks until the sandbox
1117
- * is `Running`: the create is sent with `wait: false` and the sandbox is
1118
- * polled every two seconds, with `requestTimeout` as the wait budget.
1123
+ * is `Running`: the server waits and answers as soon as it runs, with
1124
+ * `requestTimeout` as the wait budget.
1119
1125
  *
1120
1126
  * With `wait: false` it returns a {@link PendingSandbox} at once:
1121
1127
  * `pending.ready()` waits for it, `pending.status()` looks at it, and
@@ -1629,6 +1635,11 @@ declare class SandboxClient {
1629
1635
  getSnapshot(snapshotId: string): Promise<Traced<SnapshotInfo>>;
1630
1636
  /** List all snapshots in the namespace. */
1631
1637
  listSnapshots(): Promise<Traced<SnapshotInfo[]>>;
1638
+ /**
1639
+ * List snapshots taken from one sandbox (its ID or name), from the
1640
+ * sandbox's own listing rather than the whole namespace's.
1641
+ */
1642
+ listSandboxSnapshots(sandboxId: string): Promise<Traced<SnapshotInfo[]>>;
1632
1643
  /** Delete a snapshot by ID. */
1633
1644
  deleteSnapshot(snapshotId: string): Promise<void>;
1634
1645
  /**
@@ -1663,10 +1674,9 @@ declare class SandboxClient {
1663
1674
  /**
1664
1675
  * Create a sandbox, wait for it to reach `Running`, and return a connected handle.
1665
1676
  *
1666
- * This is `create({ wait: false })` followed by `PendingSandbox.ready()`
1667
- * polling every `pollInterval` seconds, with `requestTimeout` as the wait
1668
- * budget, in one call. The returned `Sandbox` auto-terminates when
1669
- * `terminate()` is called.
1677
+ * The create waits on the server, which answers as soon as the sandbox
1678
+ * runs, with `requestTimeout` as the wait budget. The returned `Sandbox`
1679
+ * auto-terminates when `terminate()` is called.
1670
1680
  *
1671
1681
  * **When the wait runs out the sandbox is not deleted.** A `SandboxPending`
1672
1682
  * is thrown with the sandbox id, and the sandbox keeps its place in the
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ var init_defaults = __esm({
46
46
  "src/defaults.ts"() {
47
47
  "use strict";
48
48
  init_esm_shims();
49
- SDK_VERSION = "0.5.156";
49
+ SDK_VERSION = "0.5.158";
50
50
  API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
51
51
  API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
52
52
  NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -509,7 +509,7 @@ var init_native_worker_client = __esm({
509
509
  }
510
510
  };
511
511
  runtimeKey = /* @__PURE__ */ Symbol.for(
512
- `tensorlake.native.worker.${false ? "source" : "0.5.156"}.v1`
512
+ `tensorlake.native.worker.${false ? "source" : "0.5.158"}.v1`
513
513
  );
514
514
  runtimes = globalThis;
515
515
  }
@@ -4085,9 +4085,7 @@ var init_sandbox = __esm({
4085
4085
  */
4086
4086
  async listSnapshots() {
4087
4087
  const client = this.requireLifecycleClient("listSnapshots");
4088
- const all = await client.listSnapshots();
4089
- const filtered = all.filter((s) => s.sandboxId === this.lifecycleIdentifier);
4090
- return Object.assign(filtered, { traceId: all.traceId });
4088
+ return client.listSandboxSnapshots(this.lifecycleIdentifier);
4091
4089
  }
4092
4090
  /** Close the proxy connection. The sandbox keeps running. */
4093
4091
  close() {
@@ -4635,6 +4633,18 @@ function validateResizeWait(options) {
4635
4633
  throw new SandboxError("pollInterval must be finite and positive");
4636
4634
  }
4637
4635
  }
4636
+ function parseSnapshotList({ traceId, json }) {
4637
+ const parsed = JSON.parse(json);
4638
+ if (parsed !== null && (typeof parsed !== "object" || Array.isArray(parsed))) {
4639
+ throw new SandboxError("Invalid snapshot list response: expected an object");
4640
+ }
4641
+ const records = parsed?.snapshots ?? [];
4642
+ if (!Array.isArray(records)) {
4643
+ throw new SandboxError("Invalid snapshot list response: snapshots must be an array");
4644
+ }
4645
+ const snapshots = records.map((s) => parseSnapshot(s));
4646
+ return Object.assign(snapshots, { traceId });
4647
+ }
4638
4648
  var DEFAULT_WAIT_POLL_INTERVAL_SEC, GPU_MODELS, SandboxClient, RESERVED_SANDBOX_MANAGEMENT_PORT;
4639
4649
  var init_client = __esm({
4640
4650
  "src/client.ts"() {
@@ -5304,19 +5314,18 @@ var init_client = __esm({
5304
5314
  }
5305
5315
  /** List all snapshots in the namespace. */
5306
5316
  async listSnapshots() {
5307
- const { traceId, json } = await callNative(
5308
- () => this.native.listSnapshots()
5317
+ return parseSnapshotList(
5318
+ await callNative(() => this.native.listSnapshots())
5319
+ );
5320
+ }
5321
+ /**
5322
+ * List snapshots taken from one sandbox (its ID or name), from the
5323
+ * sandbox's own listing rather than the whole namespace's.
5324
+ */
5325
+ async listSandboxSnapshots(sandboxId) {
5326
+ return parseSnapshotList(
5327
+ await callNative(() => this.native.listSandboxSnapshots(sandboxId))
5309
5328
  );
5310
- const parsed = JSON.parse(json);
5311
- if (parsed !== null && (typeof parsed !== "object" || Array.isArray(parsed))) {
5312
- throw new SandboxError("Invalid snapshot list response: expected an object");
5313
- }
5314
- const records = parsed?.snapshots ?? [];
5315
- if (!Array.isArray(records)) {
5316
- throw new SandboxError("Invalid snapshot list response: snapshots must be an array");
5317
- }
5318
- const snapshots = records.map((s) => parseSnapshot(s));
5319
- return Object.assign(snapshots, { traceId });
5320
5329
  }
5321
5330
  /** Delete a snapshot by ID. */
5322
5331
  async deleteSnapshot(snapshotId) {
@@ -5463,10 +5472,9 @@ var init_client = __esm({
5463
5472
  /**
5464
5473
  * Create a sandbox, wait for it to reach `Running`, and return a connected handle.
5465
5474
  *
5466
- * This is `create({ wait: false })` followed by `PendingSandbox.ready()`
5467
- * polling every `pollInterval` seconds, with `requestTimeout` as the wait
5468
- * budget, in one call. The returned `Sandbox` auto-terminates when
5469
- * `terminate()` is called.
5475
+ * The create waits on the server, which answers as soon as the sandbox
5476
+ * runs, with `requestTimeout` as the wait budget. The returned `Sandbox`
5477
+ * auto-terminates when `terminate()` is called.
5470
5478
  *
5471
5479
  * **When the wait runs out the sandbox is not deleted.** A `SandboxPending`
5472
5480
  * is thrown with the sandbox id, and the sandbox keeps its place in the
@@ -5488,11 +5496,10 @@ var init_client = __esm({
5488
5496
  pool_id: options?.poolId
5489
5497
  });
5490
5498
  const requestedName = options?.poolId != null ? null : options?.name ?? null;
5491
- let sandboxId;
5492
- let traceId;
5493
5499
  const createStart = nowMs();
5500
+ let result;
5494
5501
  if (options?.poolId != null) {
5495
- const result = await requestClient.claim(options.poolId, {
5502
+ result = await requestClient.claim(options.poolId, {
5496
5503
  fileSystems: options.fileSystems
5497
5504
  });
5498
5505
  logSdkTiming("sandbox.create", "claim_response", createStart, {
@@ -5500,84 +5507,55 @@ var init_client = __esm({
5500
5507
  status: result.status,
5501
5508
  server_trace_id: result.traceId
5502
5509
  });
5503
- if (result.status === "running" /* RUNNING */) {
5504
- const explicitProxyUrl = options?.proxyUrl ?? explicitProxyUrlOverride() ?? void 0;
5505
- const selectedProxyUrl = await this.native.selectSandboxProxyUrl(
5506
- result.sandboxId,
5507
- result.sandboxUrl ?? null,
5508
- result.ingressEndpoint ?? null,
5509
- explicitProxyUrl ?? null
5510
- );
5511
- const sandbox2 = requestClient.connect(
5512
- result.sandboxId,
5513
- selectedProxyUrl,
5514
- result.routingHint,
5515
- requestTimeout,
5516
- explicitProxyUrl
5517
- );
5518
- sandbox2._setOwner(requestClient);
5519
- sandbox2.traceId = result.traceId;
5520
- sandbox2._setLifecycleIdentifier(result.sandboxId);
5521
- sandbox2._setName(result.name ?? requestedName);
5522
- logSdkTiming("sandbox.create", "complete", opStart, {
5523
- sandbox_id: result.sandboxId,
5524
- status: "running" /* RUNNING */,
5525
- server_trace_id: result.traceId
5526
- });
5527
- return sandbox2;
5528
- }
5529
- if (result.status === "suspended" /* SUSPENDED */ || result.status === "terminated" /* TERMINATED */ || result.status === "failed" /* FAILED */) {
5530
- throw startupFailure(result.sandboxId, result.status, {
5531
- errorDetails: result.errorDetails,
5532
- terminationReason: result.terminationReason ?? result.reason
5533
- });
5534
- }
5535
- sandboxId = result.sandboxId;
5536
- traceId = result.traceId;
5537
5510
  } else {
5538
- const pending = await requestClient.requestPending(options, {
5539
- ownsSandbox: true
5511
+ const body = _SandboxClient.buildCreateRequestBody({
5512
+ ...options,
5513
+ wait: void 0
5540
5514
  });
5515
+ result = await requestClient.tracedJson(
5516
+ () => requestClient.native.createSandboxAndWait(JSON.stringify(body)),
5517
+ "sandboxId"
5518
+ );
5541
5519
  logSdkTiming("sandbox.create", "create_response", createStart, {
5542
- sandbox_id: pending.sandboxId,
5543
- status: pending.state,
5544
- server_trace_id: pending.traceId
5520
+ sandbox_id: result.sandboxId,
5521
+ status: result.status,
5522
+ server_trace_id: result.traceId
5523
+ });
5524
+ }
5525
+ if (result.status === "running" /* RUNNING */) {
5526
+ const explicitProxyUrl = options?.proxyUrl ?? explicitProxyUrlOverride() ?? void 0;
5527
+ const selectedProxyUrl = await this.native.selectSandboxProxyUrl(
5528
+ result.sandboxId,
5529
+ result.sandboxUrl ?? null,
5530
+ result.ingressEndpoint ?? null,
5531
+ explicitProxyUrl ?? null
5532
+ );
5533
+ const sandbox2 = requestClient.connect(
5534
+ result.sandboxId,
5535
+ selectedProxyUrl,
5536
+ result.routingHint,
5537
+ requestTimeout,
5538
+ explicitProxyUrl
5539
+ );
5540
+ sandbox2._setOwner(requestClient);
5541
+ sandbox2.traceId = result.traceId;
5542
+ sandbox2._setLifecycleIdentifier(result.sandboxId);
5543
+ sandbox2._setName(result.name ?? requestedName);
5544
+ logSdkTiming("sandbox.create", "complete", opStart, {
5545
+ sandbox_id: result.sandboxId,
5546
+ status: "running" /* RUNNING */,
5547
+ server_trace_id: result.traceId
5548
+ });
5549
+ return sandbox2;
5550
+ }
5551
+ if (result.status === "suspended" /* SUSPENDED */ || result.status === "terminated" /* TERMINATED */ || result.status === "failed" /* FAILED */) {
5552
+ throw startupFailure(result.sandboxId, result.status, {
5553
+ errorDetails: result.errorDetails,
5554
+ terminationReason: result.terminationReason ?? result.reason
5545
5555
  });
5546
- sandboxId = pending.sandboxId;
5547
- traceId = pending.traceId;
5548
- if (pending.state === "running" /* RUNNING */) {
5549
- const explicitProxyUrl = options?.proxyUrl ?? explicitProxyUrlOverride() ?? void 0;
5550
- const selectedProxyUrl = await this.native.selectSandboxProxyUrl(
5551
- sandboxId,
5552
- pending.sandboxUrl ?? null,
5553
- pending.ingressEndpoint ?? null,
5554
- explicitProxyUrl ?? null
5555
- );
5556
- const sandbox2 = requestClient.connect(
5557
- sandboxId,
5558
- selectedProxyUrl,
5559
- pending.routingHint,
5560
- requestTimeout,
5561
- explicitProxyUrl
5562
- );
5563
- sandbox2._setOwner(requestClient);
5564
- sandbox2.traceId = traceId;
5565
- sandbox2._setLifecycleIdentifier(sandboxId);
5566
- sandbox2._setName(pending.name ?? requestedName);
5567
- logSdkTiming("sandbox.create", "complete", opStart, {
5568
- sandbox_id: sandboxId,
5569
- status: "running" /* RUNNING */,
5570
- server_trace_id: traceId
5571
- });
5572
- return sandbox2;
5573
- }
5574
- if (pending.state === "terminated" /* TERMINATED */ || pending.state === "failed" /* FAILED */) {
5575
- throw startupFailure(sandboxId, pending.state, {
5576
- errorDetails: pending.errorDetails,
5577
- terminationReason: pending.terminationReason ?? pending.reason
5578
- });
5579
- }
5580
5556
  }
5557
+ const sandboxId = result.sandboxId;
5558
+ const traceId = result.traceId;
5581
5559
  const remaining = Math.max(0, (deadline - Date.now()) / 1e3);
5582
5560
  const observed = await requestClient.waitForSandbox(
5583
5561
  sandboxId,