@tensorlakeai/tensorlake 0.5.157 → 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`. */
@@ -897,7 +899,10 @@ interface CreateAndConnectOptions extends CreateSandboxOptions {
897
899
  * false: throw `SandboxPending` and leave the sandbox queued.
898
900
  */
899
901
  cancelOnTimeout?: boolean;
900
- /** 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
+ */
901
906
  pollInterval?: number;
902
907
  }
903
908
  /**
@@ -1115,8 +1120,8 @@ declare class Sandbox {
1115
1120
  *
1116
1121
  * Covers both fresh sandbox creation and restore-from-snapshot (set
1117
1122
  * `snapshotId`). With `wait` unset or `true` it blocks until the sandbox
1118
- * is `Running`: the create is sent with `wait: false` and the sandbox is
1119
- * 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.
1120
1125
  *
1121
1126
  * With `wait: false` it returns a {@link PendingSandbox} at once:
1122
1127
  * `pending.ready()` waits for it, `pending.status()` looks at it, and
@@ -1669,10 +1674,9 @@ declare class SandboxClient {
1669
1674
  /**
1670
1675
  * Create a sandbox, wait for it to reach `Running`, and return a connected handle.
1671
1676
  *
1672
- * This is `create({ wait: false })` followed by `PendingSandbox.ready()`
1673
- * polling every `pollInterval` seconds, with `requestTimeout` as the wait
1674
- * budget, in one call. The returned `Sandbox` auto-terminates when
1675
- * `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.
1676
1680
  *
1677
1681
  * **When the wait runs out the sandbox is not deleted.** A `SandboxPending`
1678
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`. */
@@ -897,7 +899,10 @@ interface CreateAndConnectOptions extends CreateSandboxOptions {
897
899
  * false: throw `SandboxPending` and leave the sandbox queued.
898
900
  */
899
901
  cancelOnTimeout?: boolean;
900
- /** 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
+ */
901
906
  pollInterval?: number;
902
907
  }
903
908
  /**
@@ -1115,8 +1120,8 @@ declare class Sandbox {
1115
1120
  *
1116
1121
  * Covers both fresh sandbox creation and restore-from-snapshot (set
1117
1122
  * `snapshotId`). With `wait` unset or `true` it blocks until the sandbox
1118
- * is `Running`: the create is sent with `wait: false` and the sandbox is
1119
- * 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.
1120
1125
  *
1121
1126
  * With `wait: false` it returns a {@link PendingSandbox} at once:
1122
1127
  * `pending.ready()` waits for it, `pending.status()` looks at it, and
@@ -1669,10 +1674,9 @@ declare class SandboxClient {
1669
1674
  /**
1670
1675
  * Create a sandbox, wait for it to reach `Running`, and return a connected handle.
1671
1676
  *
1672
- * This is `create({ wait: false })` followed by `PendingSandbox.ready()`
1673
- * polling every `pollInterval` seconds, with `requestTimeout` as the wait
1674
- * budget, in one call. The returned `Sandbox` auto-terminates when
1675
- * `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.
1676
1680
  *
1677
1681
  * **When the wait runs out the sandbox is not deleted.** A `SandboxPending`
1678
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.157";
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.157"}.v1`
512
+ `tensorlake.native.worker.${false ? "source" : "0.5.158"}.v1`
513
513
  );
514
514
  runtimes = globalThis;
515
515
  }
@@ -5472,10 +5472,9 @@ var init_client = __esm({
5472
5472
  /**
5473
5473
  * Create a sandbox, wait for it to reach `Running`, and return a connected handle.
5474
5474
  *
5475
- * This is `create({ wait: false })` followed by `PendingSandbox.ready()`
5476
- * polling every `pollInterval` seconds, with `requestTimeout` as the wait
5477
- * budget, in one call. The returned `Sandbox` auto-terminates when
5478
- * `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.
5479
5478
  *
5480
5479
  * **When the wait runs out the sandbox is not deleted.** A `SandboxPending`
5481
5480
  * is thrown with the sandbox id, and the sandbox keeps its place in the
@@ -5497,11 +5496,10 @@ var init_client = __esm({
5497
5496
  pool_id: options?.poolId
5498
5497
  });
5499
5498
  const requestedName = options?.poolId != null ? null : options?.name ?? null;
5500
- let sandboxId;
5501
- let traceId;
5502
5499
  const createStart = nowMs();
5500
+ let result;
5503
5501
  if (options?.poolId != null) {
5504
- const result = await requestClient.claim(options.poolId, {
5502
+ result = await requestClient.claim(options.poolId, {
5505
5503
  fileSystems: options.fileSystems
5506
5504
  });
5507
5505
  logSdkTiming("sandbox.create", "claim_response", createStart, {
@@ -5509,84 +5507,55 @@ var init_client = __esm({
5509
5507
  status: result.status,
5510
5508
  server_trace_id: result.traceId
5511
5509
  });
5512
- if (result.status === "running" /* RUNNING */) {
5513
- const explicitProxyUrl = options?.proxyUrl ?? explicitProxyUrlOverride() ?? void 0;
5514
- const selectedProxyUrl = await this.native.selectSandboxProxyUrl(
5515
- result.sandboxId,
5516
- result.sandboxUrl ?? null,
5517
- result.ingressEndpoint ?? null,
5518
- explicitProxyUrl ?? null
5519
- );
5520
- const sandbox2 = requestClient.connect(
5521
- result.sandboxId,
5522
- selectedProxyUrl,
5523
- result.routingHint,
5524
- requestTimeout,
5525
- explicitProxyUrl
5526
- );
5527
- sandbox2._setOwner(requestClient);
5528
- sandbox2.traceId = result.traceId;
5529
- sandbox2._setLifecycleIdentifier(result.sandboxId);
5530
- sandbox2._setName(result.name ?? requestedName);
5531
- logSdkTiming("sandbox.create", "complete", opStart, {
5532
- sandbox_id: result.sandboxId,
5533
- status: "running" /* RUNNING */,
5534
- server_trace_id: result.traceId
5535
- });
5536
- return sandbox2;
5537
- }
5538
- if (result.status === "suspended" /* SUSPENDED */ || result.status === "terminated" /* TERMINATED */ || result.status === "failed" /* FAILED */) {
5539
- throw startupFailure(result.sandboxId, result.status, {
5540
- errorDetails: result.errorDetails,
5541
- terminationReason: result.terminationReason ?? result.reason
5542
- });
5543
- }
5544
- sandboxId = result.sandboxId;
5545
- traceId = result.traceId;
5546
5510
  } else {
5547
- const pending = await requestClient.requestPending(options, {
5548
- ownsSandbox: true
5511
+ const body = _SandboxClient.buildCreateRequestBody({
5512
+ ...options,
5513
+ wait: void 0
5549
5514
  });
5515
+ result = await requestClient.tracedJson(
5516
+ () => requestClient.native.createSandboxAndWait(JSON.stringify(body)),
5517
+ "sandboxId"
5518
+ );
5550
5519
  logSdkTiming("sandbox.create", "create_response", createStart, {
5551
- sandbox_id: pending.sandboxId,
5552
- status: pending.state,
5553
- 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
5554
5555
  });
5555
- sandboxId = pending.sandboxId;
5556
- traceId = pending.traceId;
5557
- if (pending.state === "running" /* RUNNING */) {
5558
- const explicitProxyUrl = options?.proxyUrl ?? explicitProxyUrlOverride() ?? void 0;
5559
- const selectedProxyUrl = await this.native.selectSandboxProxyUrl(
5560
- sandboxId,
5561
- pending.sandboxUrl ?? null,
5562
- pending.ingressEndpoint ?? null,
5563
- explicitProxyUrl ?? null
5564
- );
5565
- const sandbox2 = requestClient.connect(
5566
- sandboxId,
5567
- selectedProxyUrl,
5568
- pending.routingHint,
5569
- requestTimeout,
5570
- explicitProxyUrl
5571
- );
5572
- sandbox2._setOwner(requestClient);
5573
- sandbox2.traceId = traceId;
5574
- sandbox2._setLifecycleIdentifier(sandboxId);
5575
- sandbox2._setName(pending.name ?? requestedName);
5576
- logSdkTiming("sandbox.create", "complete", opStart, {
5577
- sandbox_id: sandboxId,
5578
- status: "running" /* RUNNING */,
5579
- server_trace_id: traceId
5580
- });
5581
- return sandbox2;
5582
- }
5583
- if (pending.state === "terminated" /* TERMINATED */ || pending.state === "failed" /* FAILED */) {
5584
- throw startupFailure(sandboxId, pending.state, {
5585
- errorDetails: pending.errorDetails,
5586
- terminationReason: pending.terminationReason ?? pending.reason
5587
- });
5588
- }
5589
5556
  }
5557
+ const sandboxId = result.sandboxId;
5558
+ const traceId = result.traceId;
5590
5559
  const remaining = Math.max(0, (deadline - Date.now()) / 1e3);
5591
5560
  const observed = await requestClient.waitForSandbox(
5592
5561
  sandboxId,