@tensorlakeai/tensorlake 0.5.153 → 0.5.154

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.
@@ -186,10 +186,27 @@ var init_native_binding = __esm({
186
186
  }
187
187
  });
188
188
 
189
+ // src/enum.ts
190
+ function enumValue(values, value) {
191
+ return typeof value === "string" && Object.values(values).includes(value) ? value : values.UNKNOWN;
192
+ }
193
+ function withRaw(value, raw) {
194
+ return Object.defineProperty(value, "raw", { value: raw, enumerable: false, configurable: true });
195
+ }
196
+ var init_enum = __esm({
197
+ "src/enum.ts"() {
198
+ "use strict";
199
+ init_esm_shims();
200
+ }
201
+ });
202
+
189
203
  // src/image-builds.ts
190
204
  import path3 from "path";
191
205
  import os from "os";
192
206
  import { existsSync as existsSync2, mkdtempSync, rmSync } from "fs";
207
+ function isConfirmedCancellation(outcome) {
208
+ return outcome === "cancelled" /* CANCELLED */ || outcome === "already_cancelled" /* ALREADY_CANCELLED */ || outcome === "already_failed" /* ALREADY_FAILED */;
209
+ }
193
210
  function camelize(key) {
194
211
  return key.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
195
212
  }
@@ -207,48 +224,73 @@ function toImageBuildError(error) {
207
224
  if (key === "category") continue;
208
225
  details[camelize(key)] = value;
209
226
  }
227
+ details.code = enumValue(ImageBuildErrorCode, details.code || "internal" /* INTERNAL */);
228
+ if ("activeKind" in details) details.activeKind = details.activeKind ? enumValue(ImageBuildKind, details.activeKind) : null;
229
+ if ("activeStatus" in details) details.activeStatus = details.activeStatus ? enumValue(ImageBuildStatus, details.activeStatus) : null;
230
+ if ("outcome" in details) details.outcome = details.outcome ? enumValue(ImageBuildCancellationOutcome, details.outcome) : null;
231
+ if ("info" in details) details.info = buildInfoOrNull(details.info);
210
232
  const typed = details;
211
- switch (typed.code) {
212
- case "not_found":
213
- return new ImageBuildNotFoundError(typed);
214
- case "image_build_in_progress":
215
- return new ImageBuildInProgressError(typed);
216
- case "failed":
217
- return new ImageBuildFailedError(typed);
218
- case "cancelled":
219
- return new ImageBuildCancelledError(typed);
220
- case "timeout":
221
- return new ImageBuildTimeoutError(typed);
222
- case "interrupted":
223
- return new ImageBuildInterruptedError(typed);
224
- default:
225
- return new ImageBuildError(typed);
226
- }
233
+ const errors = {
234
+ not_found: ImageBuildNotFoundError,
235
+ image_build_in_progress: ImageBuildInProgressError,
236
+ failed: ImageBuildFailedError,
237
+ cancelled: ImageBuildCancelledError,
238
+ timeout: ImageBuildTimeoutError,
239
+ interrupted: ImageBuildInterruptedError
240
+ };
241
+ const ErrorClass = errors[typed.code] ?? ImageBuildError;
242
+ return withRaw(new ErrorClass(typed), payload);
227
243
  }
228
244
  function camelizeRecord(value) {
229
245
  const out = {};
230
246
  for (const [key, inner] of Object.entries(value)) out[camelize(key)] = inner;
231
247
  return out;
232
248
  }
233
- function parseBuildInfo(raw) {
249
+ function buildInfoOrNull(value) {
250
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
251
+ try {
252
+ return parseBuildInfo(value);
253
+ } catch (error) {
254
+ if (error instanceof ImageBuildError) return null;
255
+ throw error;
256
+ }
257
+ }
258
+ function decodeResponse(value) {
259
+ try {
260
+ const raw = typeof value === "string" ? JSON.parse(value) : value;
261
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new TypeError("expected a response object");
262
+ return raw;
263
+ } catch (error) {
264
+ throw withRaw(new ImageBuildError({ code: "service" /* SERVICE */, message: `Invalid image-build response: ${String(error)}` }), { response: value });
265
+ }
266
+ }
267
+ function parseBuildInfo(value) {
268
+ const raw = decodeResponse(value);
269
+ if (raw.status == null) {
270
+ throw withRaw(new ImageBuildError({ code: "service" /* SERVICE */, message: "Invalid image-build response: missing status" }), { response: value });
271
+ }
272
+ const attempt = raw.attempt_no ?? 0;
273
+ const attemptNo = Number(attempt);
274
+ if (typeof attempt !== "number" && typeof attempt !== "string" || typeof attempt === "string" && attempt.trim() === "" || !Number.isSafeInteger(attemptNo)) {
275
+ throw withRaw(new ImageBuildError({ code: "service" /* SERVICE */, message: "Invalid image-build attempt_no" }), { response: value });
276
+ }
234
277
  const camel = camelizeRecord(raw);
235
278
  const result = raw.result && typeof raw.result === "object" ? camelizeRecord(raw.result) : null;
236
- return {
279
+ return withRaw({
237
280
  buildId: String(raw.build_id ?? ""),
238
281
  clientRequestId: camel.clientRequestId ?? null,
239
- kind: String(raw.kind ?? ""),
282
+ kind: raw.kind ? enumValue(ImageBuildKind, raw.kind) : null,
240
283
  name: raw.name ?? null,
241
- status: String(raw.status ?? ""),
242
- phase: raw.phase ?? null,
243
- attemptNo: Number(raw.attempt_no ?? 0),
284
+ status: enumValue(ImageBuildStatus, raw.status),
285
+ phase: raw.phase ? enumValue(ImageBuildPhase, raw.phase) : null,
286
+ attemptNo,
244
287
  builderSandboxId: camel.builderSandboxId ?? null,
245
288
  error: raw.error ?? null,
246
289
  result,
247
290
  operationDeadlineMs: camel.operationDeadlineMs ?? null,
248
291
  createdAtMs: camel.createdAtMs ?? null,
249
- updatedAtMs: camel.updatedAtMs ?? null,
250
- raw
251
- };
292
+ updatedAtMs: camel.updatedAtMs ?? null
293
+ }, raw);
252
294
  }
253
295
  async function __runWithInterrupt(signal, run) {
254
296
  const binding = __imageBuildInternals.loadNativeBinding();
@@ -272,13 +314,65 @@ async function __runWithInterrupt(signal, run) {
272
314
  binding.releaseImageBuildInterrupt(interruptId);
273
315
  }
274
316
  }
275
- var ImageBuildError, ImageBuildNotFoundError, ImageBuildInProgressError, ImageBuildFailedError, ImageBuildCancelledError, ImageBuildTimeoutError, ImageBuildInterruptedError;
317
+ var ImageBuildStatus, ImageBuildPhase, ImageBuildKind, ImageBuildCancellationOutcome, ImageBuildErrorCode, ImageBuildError, ImageBuildNotFoundError, ImageBuildInProgressError, ImageBuildFailedError, ImageBuildCancelledError, ImageBuildTimeoutError, ImageBuildInterruptedError;
276
318
  var init_image_builds = __esm({
277
319
  "src/image-builds.ts"() {
278
320
  "use strict";
279
321
  init_esm_shims();
322
+ init_enum();
280
323
  init_image();
281
324
  init_sandbox_image();
325
+ ImageBuildStatus = /* @__PURE__ */ ((ImageBuildStatus2) => {
326
+ ImageBuildStatus2["PENDING"] = "pending";
327
+ ImageBuildStatus2["RUNNING"] = "running";
328
+ ImageBuildStatus2["SUCCEEDED"] = "succeeded";
329
+ ImageBuildStatus2["FAILED"] = "failed";
330
+ ImageBuildStatus2["CANCELLED"] = "cancelled";
331
+ ImageBuildStatus2["UNKNOWN"] = "unknown";
332
+ return ImageBuildStatus2;
333
+ })(ImageBuildStatus || {});
334
+ ImageBuildPhase = /* @__PURE__ */ ((ImageBuildPhase2) => {
335
+ ImageBuildPhase2["AWAITING_CONTEXT"] = "awaiting_context";
336
+ ImageBuildPhase2["STARTING_BUILDER"] = "starting_builder";
337
+ ImageBuildPhase2["EXECUTING"] = "executing";
338
+ ImageBuildPhase2["SNAPSHOTTING"] = "snapshotting";
339
+ ImageBuildPhase2["PUBLISHING"] = "publishing";
340
+ ImageBuildPhase2["FINISHED"] = "finished";
341
+ ImageBuildPhase2["UNKNOWN"] = "unknown";
342
+ return ImageBuildPhase2;
343
+ })(ImageBuildPhase || {});
344
+ ImageBuildKind = /* @__PURE__ */ ((ImageBuildKind2) => {
345
+ ImageBuildKind2["DOCKERFILE"] = "dockerfile";
346
+ ImageBuildKind2["IMPORT"] = "import";
347
+ ImageBuildKind2["DIRECT"] = "direct";
348
+ ImageBuildKind2["UNKNOWN"] = "unknown";
349
+ return ImageBuildKind2;
350
+ })(ImageBuildKind || {});
351
+ ImageBuildCancellationOutcome = /* @__PURE__ */ ((ImageBuildCancellationOutcome2) => {
352
+ ImageBuildCancellationOutcome2["CANCELLED"] = "cancelled";
353
+ ImageBuildCancellationOutcome2["ALREADY_CANCELLED"] = "already_cancelled";
354
+ ImageBuildCancellationOutcome2["ALREADY_COMPLETED"] = "already_completed";
355
+ ImageBuildCancellationOutcome2["ALREADY_FAILED"] = "already_failed";
356
+ ImageBuildCancellationOutcome2["NOT_ADMITTED"] = "not_admitted";
357
+ ImageBuildCancellationOutcome2["UNCONFIRMED"] = "unconfirmed";
358
+ ImageBuildCancellationOutcome2["UNKNOWN"] = "unknown";
359
+ return ImageBuildCancellationOutcome2;
360
+ })(ImageBuildCancellationOutcome || {});
361
+ ImageBuildErrorCode = /* @__PURE__ */ ((ImageBuildErrorCode2) => {
362
+ ImageBuildErrorCode2["USAGE"] = "usage";
363
+ ImageBuildErrorCode2["AUTH"] = "auth";
364
+ ImageBuildErrorCode2["NOT_FOUND"] = "not_found";
365
+ ImageBuildErrorCode2["IMAGE_BUILD_IN_PROGRESS"] = "image_build_in_progress";
366
+ ImageBuildErrorCode2["CLIENT_REQUEST_ID_MISMATCH"] = "client_request_id_mismatch";
367
+ ImageBuildErrorCode2["FAILED"] = "failed";
368
+ ImageBuildErrorCode2["CANCELLED"] = "cancelled";
369
+ ImageBuildErrorCode2["TIMEOUT"] = "timeout";
370
+ ImageBuildErrorCode2["INTERRUPTED"] = "interrupted";
371
+ ImageBuildErrorCode2["SERVICE"] = "service";
372
+ ImageBuildErrorCode2["INTERNAL"] = "internal";
373
+ ImageBuildErrorCode2["UNKNOWN"] = "unknown";
374
+ return ImageBuildErrorCode2;
375
+ })(ImageBuildErrorCode || {});
282
376
  ImageBuildError = class extends Error {
283
377
  code;
284
378
  buildId;
@@ -288,7 +382,11 @@ var init_image_builds = __esm({
288
382
  super(details.message);
289
383
  this.name = "ImageBuildError";
290
384
  this.code = details.code;
291
- this.details = details;
385
+ this.details = { ...details };
386
+ withRaw(this, {});
387
+ if ("confirmed" in details) {
388
+ this.details.confirmed = details.confirmed === true && isConfirmedCancellation(details.outcome);
389
+ }
292
390
  if (details.buildId) this.buildId = details.buildId;
293
391
  if (details.clientRequestId) this.clientRequestId = details.clientRequestId;
294
392
  }
@@ -320,7 +418,7 @@ var init_image_builds = __esm({
320
418
  super(details);
321
419
  this.name = "ImageBuildFailedError";
322
420
  this.error = details.error ?? "no error recorded";
323
- if (details.info) this.info = parseBuildInfo(details.info);
421
+ if (details.info) this.info = details.info;
324
422
  }
325
423
  };
326
424
  ImageBuildCancelledError = class extends ImageBuildError {
@@ -328,7 +426,7 @@ var init_image_builds = __esm({
328
426
  constructor(details) {
329
427
  super(details);
330
428
  this.name = "ImageBuildCancelledError";
331
- if (details.info) this.info = parseBuildInfo(details.info);
429
+ if (details.info) this.info = details.info;
332
430
  }
333
431
  };
334
432
  ImageBuildTimeoutError = class extends ImageBuildError {
@@ -344,8 +442,8 @@ var init_image_builds = __esm({
344
442
  constructor(details) {
345
443
  super(details);
346
444
  this.name = "ImageBuildInterruptedError";
347
- this.outcome = details.outcome ?? "unconfirmed";
348
- this.confirmed = details.confirmed === true;
445
+ this.outcome = details.outcome ?? "unconfirmed" /* UNCONFIRMED */;
446
+ this.confirmed = this.details.confirmed === true;
349
447
  if (details.result) this.result = details.result;
350
448
  }
351
449
  };
@@ -2399,7 +2497,7 @@ init_image();
2399
2497
 
2400
2498
  // src/defaults.ts
2401
2499
  init_esm_shims();
2402
- var SDK_VERSION = "0.5.153";
2500
+ var SDK_VERSION = "0.5.154";
2403
2501
  var API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
2404
2502
  var API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
2405
2503
  var NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -3207,7 +3305,7 @@ function createWorkerBinding(runtime) {
3207
3305
  };
3208
3306
  }
3209
3307
  var runtimeKey = /* @__PURE__ */ Symbol.for(
3210
- `tensorlake.native.worker.${false ? "source" : "0.5.153"}.v1`
3308
+ `tensorlake.native.worker.${false ? "source" : "0.5.154"}.v1`
3211
3309
  );
3212
3310
  var runtimes = globalThis;
3213
3311
  function workerBinding() {