tensorlake 0.5.127 → 0.5.129

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
@@ -158,7 +158,9 @@ declare enum SandboxStatus {
158
158
  SUSPENDING = "suspending",
159
159
  SUSPENDED = "suspended",
160
160
  TERMINATED = "terminated",
161
- TIMEOUT = "timeout"
161
+ TIMEOUT = "timeout",
162
+ /** Terminal status used by blocking create/claim responses. */
163
+ FAILED = "failed"
162
164
  }
163
165
  declare enum SnapshotStatus {
164
166
  IN_PROGRESS = "in_progress",
@@ -2083,7 +2085,12 @@ declare class PoolInUseError extends SandboxError {
2083
2085
  /** Raised when the remote API returns an error. */
2084
2086
  declare class RemoteAPIError extends SandboxError {
2085
2087
  readonly statusCode: number;
2088
+ /** Original response body, retained for compatibility and diagnostics. */
2086
2089
  readonly responseMessage: string;
2090
+ readonly sandboxId?: string;
2091
+ /** Server reason, including unknown future reasons. */
2092
+ readonly reason?: string;
2093
+ readonly errorDetails?: unknown;
2087
2094
  constructor(statusCode: number, message: string);
2088
2095
  }
2089
2096
  /** Raised when request output is fetched before the request has completed. */
package/dist/index.d.ts CHANGED
@@ -158,7 +158,9 @@ declare enum SandboxStatus {
158
158
  SUSPENDING = "suspending",
159
159
  SUSPENDED = "suspended",
160
160
  TERMINATED = "terminated",
161
- TIMEOUT = "timeout"
161
+ TIMEOUT = "timeout",
162
+ /** Terminal status used by blocking create/claim responses. */
163
+ FAILED = "failed"
162
164
  }
163
165
  declare enum SnapshotStatus {
164
166
  IN_PROGRESS = "in_progress",
@@ -2083,7 +2085,12 @@ declare class PoolInUseError extends SandboxError {
2083
2085
  /** Raised when the remote API returns an error. */
2084
2086
  declare class RemoteAPIError extends SandboxError {
2085
2087
  readonly statusCode: number;
2088
+ /** Original response body, retained for compatibility and diagnostics. */
2086
2089
  readonly responseMessage: string;
2090
+ readonly sandboxId?: string;
2091
+ /** Server reason, including unknown future reasons. */
2092
+ readonly reason?: string;
2093
+ readonly errorDetails?: unknown;
2087
2094
  constructor(statusCode: number, message: string);
2088
2095
  }
2089
2096
  /** Raised when request output is fetched before the request has completed. */
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.127";
49
+ SDK_VERSION = "0.5.129";
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";
@@ -81,6 +81,27 @@ function describeError(err) {
81
81
  if (parts.length > 0) return parts.join(": ");
82
82
  return err instanceof Error ? err.message : String(err);
83
83
  }
84
+ function formatErrorDetails(errorDetails) {
85
+ if (errorDetails == null) return void 0;
86
+ if (typeof errorDetails === "string") {
87
+ const detail = errorDetails.trim();
88
+ return detail || void 0;
89
+ }
90
+ if (Array.isArray(errorDetails)) {
91
+ const parts = errorDetails.map((item) => formatErrorDetails(item)).filter((item) => Boolean(item));
92
+ return parts.length > 0 ? parts.join("; ") : JSON.stringify(errorDetails);
93
+ }
94
+ if (typeof errorDetails === "object") {
95
+ for (const key of ["message", "detail", "error", "reason"]) {
96
+ const value = errorDetails[key];
97
+ if (typeof value === "string" && value.trim()) {
98
+ return value.trim();
99
+ }
100
+ }
101
+ return JSON.stringify(errorDetails);
102
+ }
103
+ return String(errorDetails);
104
+ }
84
105
  var SandboxException, SandboxError, SandboxConnectionError, SandboxNotFoundError, PoolNotFoundError, PoolInUseError, RemoteAPIError, RequestNotFinishedError, RequestFailedError, RequestExecutionError;
85
106
  var init_errors = __esm({
86
107
  "src/errors.ts"() {
@@ -132,9 +153,39 @@ var init_errors = __esm({
132
153
  };
133
154
  RemoteAPIError = class extends SandboxError {
134
155
  statusCode;
156
+ /** Original response body, retained for compatibility and diagnostics. */
135
157
  responseMessage;
158
+ sandboxId;
159
+ /** Server reason, including unknown future reasons. */
160
+ reason;
161
+ errorDetails;
136
162
  constructor(statusCode, message) {
137
- super(`API error (status ${statusCode}): ${message}`);
163
+ let failure;
164
+ try {
165
+ const payload = JSON.parse(message);
166
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
167
+ const record = payload;
168
+ if (typeof record.sandbox_id === "string" && record.sandbox_id.trim() && (record.status === "failed" || record.status === "terminated"))
169
+ failure = record;
170
+ }
171
+ } catch {
172
+ }
173
+ const sandboxId = failure?.sandbox_id;
174
+ const rawReason = failure?.reason ?? failure?.termination_reason;
175
+ const reason = typeof rawReason === "string" ? rawReason : void 0;
176
+ const errorDetails = failure?.error_details;
177
+ let displayMessage = message;
178
+ if (failure) {
179
+ displayMessage = `Sandbox ${sandboxId} ${failure.status}`;
180
+ if (reason) displayMessage += ` (${reason})`;
181
+ const detail = formatErrorDetails(errorDetails);
182
+ if (detail) displayMessage += `: ${detail}`;
183
+ if (!reason && !detail) displayMessage = message;
184
+ }
185
+ super(`API error (status ${statusCode}): ${displayMessage}`);
186
+ this.sandboxId = sandboxId;
187
+ this.reason = reason;
188
+ this.errorDetails = errorDetails;
138
189
  this.name = "RemoteAPIError";
139
190
  this.statusCode = statusCode;
140
191
  this.responseMessage = message;
@@ -421,7 +472,7 @@ var init_native_worker_client = __esm({
421
472
  }
422
473
  };
423
474
  runtimeKey = /* @__PURE__ */ Symbol.for(
424
- `tensorlake.native.worker.${false ? "source" : "0.5.127"}.v1`
475
+ `tensorlake.native.worker.${false ? "source" : "0.5.129"}.v1`
425
476
  );
426
477
  runtimes = globalThis;
427
478
  }
@@ -642,6 +693,7 @@ var init_models = __esm({
642
693
  SandboxStatus2["SUSPENDED"] = "suspended";
643
694
  SandboxStatus2["TERMINATED"] = "terminated";
644
695
  SandboxStatus2["TIMEOUT"] = "timeout";
696
+ SandboxStatus2["FAILED"] = "failed";
645
697
  return SandboxStatus2;
646
698
  })(SandboxStatus || {});
647
699
  SnapshotStatus = /* @__PURE__ */ ((SnapshotStatus2) => {
@@ -4488,37 +4540,16 @@ function snapshotStatusSatisfiesWaitCondition(status, waitUntil) {
4488
4540
  return status === "completed" /* COMPLETED */;
4489
4541
  }
4490
4542
  function formatStartupFailureMessage(sandboxId, status, options) {
4491
- const prefix = status === "terminated" /* TERMINATED */ ? `Sandbox ${sandboxId} terminated during startup` : `Sandbox ${sandboxId} became ${status} during startup`;
4543
+ let prefix = status === "terminated" /* TERMINATED */ ? `Sandbox ${sandboxId} terminated during startup` : `Sandbox ${sandboxId} became ${status} during startup`;
4544
+ if (options.terminationReason) {
4545
+ prefix += ` (${options.terminationReason})`;
4546
+ }
4492
4547
  const detail = formatErrorDetails(options.errorDetails);
4493
4548
  if (detail) {
4494
4549
  return `${prefix}: ${detail}`;
4495
4550
  }
4496
- if (options.terminationReason) {
4497
- return `${prefix}: termination reason: ${options.terminationReason}`;
4498
- }
4499
4551
  return prefix;
4500
4552
  }
4501
- function formatErrorDetails(errorDetails) {
4502
- if (errorDetails == null) return void 0;
4503
- if (typeof errorDetails === "string") {
4504
- const detail = errorDetails.trim();
4505
- return detail || void 0;
4506
- }
4507
- if (Array.isArray(errorDetails)) {
4508
- const parts = errorDetails.map((item) => formatErrorDetails(item)).filter((item) => Boolean(item));
4509
- return parts.length > 0 ? parts.join("; ") : JSON.stringify(errorDetails);
4510
- }
4511
- if (typeof errorDetails === "object") {
4512
- for (const key of ["message", "detail", "error", "reason"]) {
4513
- const value = errorDetails[key];
4514
- if (typeof value === "string" && value.trim()) {
4515
- return value.trim();
4516
- }
4517
- }
4518
- return JSON.stringify(errorDetails);
4519
- }
4520
- return String(errorDetails);
4521
- }
4522
4553
  function normalizeUserPorts(ports) {
4523
4554
  return dedupeAndSortPorts(ports.map(validateUserPort));
4524
4555
  }
@@ -5200,11 +5231,11 @@ var init_client = __esm({
5200
5231
  result.sandboxUrl
5201
5232
  );
5202
5233
  }
5203
- if (result.status === "suspended" /* SUSPENDED */ || result.status === "terminated" /* TERMINATED */) {
5234
+ if (result.status === "suspended" /* SUSPENDED */ || result.status === "terminated" /* TERMINATED */ || result.status === "failed" /* FAILED */) {
5204
5235
  throw new SandboxError(
5205
5236
  formatStartupFailureMessage(result.sandboxId, result.status, {
5206
5237
  errorDetails: result.errorDetails,
5207
- terminationReason: result.terminationReason
5238
+ terminationReason: result.terminationReason ?? result.reason
5208
5239
  })
5209
5240
  );
5210
5241
  }