@tensorlakeai/tensorlake 0.5.153 → 0.5.156

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.
Files changed (35) hide show
  1. package/dist/applications/index.cjs +260 -71
  2. package/dist/applications/index.cjs.map +1 -1
  3. package/dist/applications/index.d.cts +3 -3
  4. package/dist/applications/index.d.ts +3 -3
  5. package/dist/applications/index.js +260 -71
  6. package/dist/applications/index.js.map +1 -1
  7. package/dist/function-agent/main.cjs +1 -1
  8. package/dist/function-agent/main.js +1 -1
  9. package/dist/function-executor/main.cjs +2 -2
  10. package/dist/function-executor/main.js +2 -2
  11. package/dist/index.cjs +344 -106
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +95 -38
  14. package/dist/index.d.ts +95 -38
  15. package/dist/index.js +339 -106
  16. package/dist/index.js.map +1 -1
  17. package/dist/{remote-B3vn4tt1.d.cts → remote-CEs4GFGP.d.cts} +1 -1
  18. package/dist/{remote-DqBUuciu.d.ts → remote-DYBXCTNC.d.ts} +1 -1
  19. package/dist/{sandbox-image-BMiFlzAs.d.cts → sandbox-image-C2GTVnx3.d.cts} +99 -52
  20. package/dist/{sandbox-image-BMiFlzAs.d.ts → sandbox-image-C2GTVnx3.d.ts} +99 -52
  21. package/dist/sandbox-image.cjs +248 -61
  22. package/dist/sandbox-image.cjs.map +1 -1
  23. package/dist/sandbox-image.d.cts +1 -1
  24. package/dist/sandbox-image.d.ts +1 -1
  25. package/dist/sandbox-image.js +248 -61
  26. package/dist/sandbox-image.js.map +1 -1
  27. package/package.json +7 -7
  28. package/runtime/function-executor/manifest.json +5 -5
  29. package/runtime/function-executor/package/dist/function-executor/main.js +2 -2
  30. package/runtime/function-executor/package/npm-shrinkwrap.json +2 -2
  31. package/runtime/function-executor/package/package.json +1 -1
  32. package/runtime/typescript-function-runner/manifest.json +5 -5
  33. package/runtime/typescript-function-runner/package/dist/function-agent/main.js +1 -1
  34. package/runtime/typescript-function-runner/package/npm-shrinkwrap.json +26 -26
  35. package/runtime/typescript-function-runner/package/package.json +7 -7
@@ -1,6 +1,6 @@
1
- import { A as ApplicationCapability, J as JSONSchema, R as RegisteredDefinition } from '../remote-B3vn4tt1.cjs';
2
- export { a as ApplicationOptions, F as File, b as FunctionOptions, c as Future, H as Headers, d as HeadersInit, e as HttpBody, I as Infer, L as LocalRequest, P as Parameter, f as ParameterValues, g as RegisteredFunction, h as RemoteOptions, i as RemoteRequest, j as RequestContext, k as RequestContextValue, S as Schema, l as SimpleApplicationOptions, m as SimpleFunctionOptions, T as TailCall, W as WaitOptions, n as WaitResult, r as registerApplication, o as registerFunction, p as remoteOptions, q as retries, s as runLocal, t as runRemote, u as schema } from '../remote-B3vn4tt1.cjs';
3
- export { I as Image } from '../sandbox-image-BMiFlzAs.cjs';
1
+ import { A as ApplicationCapability, J as JSONSchema, R as RegisteredDefinition } from '../remote-CEs4GFGP.cjs';
2
+ export { a as ApplicationOptions, F as File, b as FunctionOptions, c as Future, H as Headers, d as HeadersInit, e as HttpBody, I as Infer, L as LocalRequest, P as Parameter, f as ParameterValues, g as RegisteredFunction, h as RemoteOptions, i as RemoteRequest, j as RequestContext, k as RequestContextValue, S as Schema, l as SimpleApplicationOptions, m as SimpleFunctionOptions, T as TailCall, W as WaitOptions, n as WaitResult, r as registerApplication, o as registerFunction, p as remoteOptions, q as retries, s as runLocal, t as runRemote, u as schema } from '../remote-CEs4GFGP.cjs';
3
+ export { I as Image } from '../sandbox-image-C2GTVnx3.cjs';
4
4
 
5
5
  declare const SDK_VERSION: string;
6
6
 
@@ -1,6 +1,6 @@
1
- import { A as ApplicationCapability, J as JSONSchema, R as RegisteredDefinition } from '../remote-DqBUuciu.js';
2
- export { a as ApplicationOptions, F as File, b as FunctionOptions, c as Future, H as Headers, d as HeadersInit, e as HttpBody, I as Infer, L as LocalRequest, P as Parameter, f as ParameterValues, g as RegisteredFunction, h as RemoteOptions, i as RemoteRequest, j as RequestContext, k as RequestContextValue, S as Schema, l as SimpleApplicationOptions, m as SimpleFunctionOptions, T as TailCall, W as WaitOptions, n as WaitResult, r as registerApplication, o as registerFunction, p as remoteOptions, q as retries, s as runLocal, t as runRemote, u as schema } from '../remote-DqBUuciu.js';
3
- export { I as Image } from '../sandbox-image-BMiFlzAs.js';
1
+ import { A as ApplicationCapability, J as JSONSchema, R as RegisteredDefinition } from '../remote-DYBXCTNC.js';
2
+ export { a as ApplicationOptions, F as File, b as FunctionOptions, c as Future, H as Headers, d as HeadersInit, e as HttpBody, I as Infer, L as LocalRequest, P as Parameter, f as ParameterValues, g as RegisteredFunction, h as RemoteOptions, i as RemoteRequest, j as RequestContext, k as RequestContextValue, S as Schema, l as SimpleApplicationOptions, m as SimpleFunctionOptions, T as TailCall, W as WaitOptions, n as WaitResult, r as registerApplication, o as registerFunction, p as remoteOptions, q as retries, s as runLocal, t as runRemote, u as schema } from '../remote-DYBXCTNC.js';
3
+ export { I as Image } from '../sandbox-image-C2GTVnx3.js';
4
4
 
5
5
  declare const SDK_VERSION: string;
6
6
 
@@ -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
  };
@@ -408,16 +506,58 @@ function defaultRegisteredName(dockerfilePath) {
408
506
  const parsed = path4.parse(dockerfilePath);
409
507
  if (parsed.name.toLowerCase() === "dockerfile") {
410
508
  const parentName = path4.basename(path4.dirname(dockerfilePath)).trim();
411
- return parentName || "sandbox-image";
509
+ return parentName || DEFAULT_SANDBOX_IMAGE_NAME;
510
+ }
511
+ return parsed.name || DEFAULT_SANDBOX_IMAGE_NAME;
512
+ }
513
+ function registeredImageName(explicit, generated, cas, fallback = DEFAULT_SANDBOX_IMAGE_NAME) {
514
+ if (explicit || generated === void 0) {
515
+ const name = explicit ?? "";
516
+ return cas ? canonicalCasImageName(name) : name;
412
517
  }
413
- return parsed.name || "sandbox-image";
518
+ return cas ? casImageNameFrom(generated, fallback) : generated;
519
+ }
520
+ function canonicalCasImageName(name) {
521
+ return name.replace(/[A-Z]/g, (c) => c.toLowerCase());
522
+ }
523
+ function casImageNameFrom(raw, fallback) {
524
+ const lowered = canonicalCasImageName(raw);
525
+ if (isAddressableCasImageName(lowered)) {
526
+ return lowered;
527
+ }
528
+ let name = "";
529
+ for (const original of lowered) {
530
+ const ch = /^[a-z0-9._-]$/.test(original) ? original : "-";
531
+ const previous = name[name.length - 1];
532
+ if (CAS_NAME_SEPARATORS.includes(ch) && previous !== void 0 && CAS_NAME_SEPARATORS.includes(previous)) {
533
+ continue;
534
+ }
535
+ name += ch;
536
+ }
537
+ name = name.replace(/^[._-]+|[._-]+$/g, "").slice(0, MAX_CAS_IMAGE_NAME_LENGTH).replace(/[._-]+$/, "");
538
+ return isAddressableCasImageName(name) ? name : fallback;
539
+ }
540
+ function isAddressableCasImageName(name) {
541
+ if (name.length === 0 || name.length > MAX_CAS_IMAGE_NAME_LENGTH || RESERVED_IMAGE_NAME_PREFIXES.some((prefix) => name.startsWith(prefix)) || /^[0-9a-f]{64}$/.test(name)) {
542
+ return false;
543
+ }
544
+ const colon = name.indexOf(":");
545
+ const repository = colon === -1 ? name : name.slice(0, colon);
546
+ if (!repository.split("/").every((component) => /^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(component))) {
547
+ return false;
548
+ }
549
+ if (colon === -1) {
550
+ return true;
551
+ }
552
+ const tag = name.slice(colon + 1);
553
+ return tag.length > 0 && tag.length <= 128 && /^[a-z0-9._-]+$/.test(tag) && !tag.startsWith(".") && !tag.startsWith("-");
414
554
  }
415
555
  function defaultRegisteredNameFromImage(imageReference) {
416
556
  const withoutDigest = imageReference.split("@", 1)[0] ?? imageReference;
417
557
  const lastSegment = withoutDigest.split("/").pop() ?? withoutDigest;
418
558
  const colonIndex = lastSegment.lastIndexOf(":");
419
559
  const name = colonIndex > 0 && colonIndex < lastSegment.length - 1 ? lastSegment.slice(0, colonIndex) : lastSegment;
420
- return name || "imported-image";
560
+ return name || DEFAULT_IMPORTED_IMAGE_NAME;
421
561
  }
422
562
  function noopEmit(_event) {
423
563
  }
@@ -520,7 +660,11 @@ async function createSandboxImage(source, options = {}, deps = {}) {
520
660
  if (!text.endsWith("\n")) text += "\n";
521
661
  dockerfileText = text;
522
662
  nativeContextDir = resolvedContext;
523
- effectiveName = options.registeredName ?? source.name;
663
+ effectiveName = registeredImageName(
664
+ options.registeredName ?? source.name,
665
+ void 0,
666
+ options.cas ?? true
667
+ );
524
668
  } else if (typeof source === "string") {
525
669
  const resolvedPath = path4.resolve(source);
526
670
  if (!existsSync3(resolvedPath)) {
@@ -529,7 +673,11 @@ async function createSandboxImage(source, options = {}, deps = {}) {
529
673
  dockerfilePath = resolvedPath;
530
674
  dockerfileText = void 0;
531
675
  nativeContextDir = void 0;
532
- effectiveName = options.registeredName ?? defaultRegisteredName(resolvedPath);
676
+ effectiveName = registeredImageName(
677
+ options.registeredName,
678
+ defaultRegisteredName(resolvedPath),
679
+ options.cas ?? true
680
+ );
533
681
  } else {
534
682
  throw new TypeError(
535
683
  `source must be an Image or a Dockerfile path, got ${typeof source}`
@@ -553,12 +701,16 @@ async function createSandboxImage(source, options = {}, deps = {}) {
553
701
  deps._allowPat ? "Missing TENSORLAKE_API_KEY or TENSORLAKE_PAT credentials." : "Missing TENSORLAKE_API_KEY credentials."
554
702
  );
555
703
  }
556
- if (options.signal !== void 0 && !options.cas) {
704
+ const cas = options.cas ?? true;
705
+ if (options.signal !== void 0 && !cas) {
557
706
  throw new Error(
558
- "signal is only supported for CAS image builds (cas: true); a legacy build has no Image Service build operation to cancel"
707
+ "signal is not supported for legacy image builds (cas: false): a legacy image build has no build operation to cancel"
559
708
  );
560
709
  }
561
- emit({ type: "status", message: `Building image '${effectiveName}'...` });
710
+ emit({
711
+ type: "status",
712
+ message: `Building ${cas ? "CAS" : "legacy"} image '${effectiveName}'...`
713
+ });
562
714
  const binding = loadNativeBinding();
563
715
  let emitError;
564
716
  const nativeOptions = {
@@ -580,7 +732,7 @@ async function createSandboxImage(source, options = {}, deps = {}) {
580
732
  dockerConfigJson: options.dockerConfigJson,
581
733
  dockerfileText,
582
734
  contextDir: nativeContextDir,
583
- cas: options.cas ?? false,
735
+ cas,
584
736
  buildArgs: options.buildArgs
585
737
  };
586
738
  const forward = (event) => {
@@ -590,7 +742,7 @@ async function createSandboxImage(source, options = {}, deps = {}) {
590
742
  emitError ??= error;
591
743
  }
592
744
  };
593
- const resultJson = options.cas ? await __runWithInterrupt(
745
+ const resultJson = cas ? await __runWithInterrupt(
594
746
  options.signal,
595
747
  (interruptId) => binding.buildSandboxImage(nativeOptions, forward, interruptId)
596
748
  ) : await binding.buildSandboxImage(nativeOptions, forward);
@@ -621,7 +773,12 @@ async function importSandboxImage(imageReference, options = {}, deps = {}) {
621
773
  }
622
774
  const reference = imageReference.trim();
623
775
  const context = buildContextFromEnv();
624
- const effectiveName = options.registeredName ?? defaultRegisteredNameFromImage(reference);
776
+ const effectiveName = registeredImageName(
777
+ options.registeredName,
778
+ defaultRegisteredNameFromImage(reference),
779
+ options.cas ?? true,
780
+ DEFAULT_IMPORTED_IMAGE_NAME
781
+ );
625
782
  if (effectiveName === DEFAULT_IMAGE_NAME) {
626
783
  console.warn(
627
784
  `Importing sandbox image with the default name "${DEFAULT_IMAGE_NAME}". Pass \`registeredName\` to avoid collisions with other default-named images in this project.`
@@ -639,14 +796,15 @@ async function importSandboxImage(imageReference, options = {}, deps = {}) {
639
796
  deps._allowPat ? "Missing TENSORLAKE_API_KEY or TENSORLAKE_PAT credentials." : "Missing TENSORLAKE_API_KEY credentials."
640
797
  );
641
798
  }
642
- if (options.signal !== void 0 && !options.cas) {
799
+ const cas = options.cas ?? true;
800
+ if (options.signal !== void 0 && !cas) {
643
801
  throw new Error(
644
- "signal is only supported for CAS image imports (cas: true); a legacy import has no Image Service build operation to cancel"
802
+ "signal is not supported for legacy image imports (cas: false): a legacy image import has no build operation to cancel"
645
803
  );
646
804
  }
647
805
  emit({
648
806
  type: "status",
649
- message: `Importing image '${reference}' as '${effectiveName}'...`
807
+ message: `Importing '${reference}' as ${cas ? "CAS" : "legacy"} image '${effectiveName}'...`
650
808
  });
651
809
  const binding = loadNativeBinding();
652
810
  let emitError;
@@ -667,7 +825,7 @@ async function importSandboxImage(imageReference, options = {}, deps = {}) {
667
825
  userAgent: void 0,
668
826
  dockerCompat: options.dockerCompat ?? false,
669
827
  dockerConfigJson: options.dockerConfigJson,
670
- cas: options.cas ?? false
828
+ cas
671
829
  };
672
830
  const forward = (event) => {
673
831
  try {
@@ -676,7 +834,7 @@ async function importSandboxImage(imageReference, options = {}, deps = {}) {
676
834
  emitError ??= error;
677
835
  }
678
836
  };
679
- const resultJson = options.cas ? await __runWithInterrupt(
837
+ const resultJson = cas ? await __runWithInterrupt(
680
838
  options.signal,
681
839
  (interruptId) => binding.importSandboxImage(nativeOptions, forward, interruptId)
682
840
  ) : await binding.importSandboxImage(nativeOptions, forward);
@@ -733,15 +891,29 @@ async function deleteSandboxImage(imageName) {
733
891
  if (typeof imageName !== "string" || imageName.length === 0) {
734
892
  throw new TypeError("imageName must be a non-empty string");
735
893
  }
736
- await loadNativeBinding().deleteSandboxImage(catalogOptionsFromEnv(), imageName);
894
+ warnIncompleteLegacyCleanup(
895
+ await loadNativeBinding().deleteSandboxImage(catalogOptionsFromEnv(), imageName)
896
+ );
737
897
  }
738
898
  async function deleteSandboxImageWithCredentials(credentials, imageName) {
739
899
  if (typeof imageName !== "string" || imageName.length === 0) {
740
900
  throw new TypeError("imageName must be a non-empty string");
741
901
  }
742
- await loadNativeBinding().deleteSandboxImage(
743
- catalogOptionsFromCredentials(credentials),
744
- imageName
902
+ warnIncompleteLegacyCleanup(
903
+ await loadNativeBinding().deleteSandboxImage(
904
+ catalogOptionsFromCredentials(credentials),
905
+ imageName
906
+ )
907
+ );
908
+ }
909
+ function warnIncompleteLegacyCleanup(failure) {
910
+ if (failure == null) {
911
+ return;
912
+ }
913
+ const legacyImageId = failure.legacyImageId ?? void 0;
914
+ const label = legacyImageId ? ` (${legacyImageId})` : "";
915
+ console.warn(
916
+ `Deleted CAS image '${failure.legacyImageName}', but could not delete the legacy image of the same name${label}, which can no longer start sandboxes: ${failure.error}. Delete it with deleteSandboxImage("${legacyImageId ?? failure.legacyImageName}").`
745
917
  );
746
918
  }
747
919
  async function findSandboxImageByName(imageName) {
@@ -785,13 +957,14 @@ async function runCreateSandboxImageCli(argv = process.argv.slice(2)) {
785
957
  disk_mb: { type: "string" },
786
958
  builder_disk_mb: { type: "string" },
787
959
  docker_compat: { type: "boolean", default: false },
788
- public: { type: "boolean", default: false }
960
+ public: { type: "boolean", default: false },
961
+ "no-cas": { type: "boolean", default: false }
789
962
  }
790
963
  });
791
964
  const dockerfilePath = parsed.positionals[0];
792
965
  if (!dockerfilePath) {
793
966
  throw new Error(
794
- "Usage: tensorlake-create-sandbox-image <dockerfile_path> [--name NAME] [--cpus N] [--memory MiB] [--disk_mb MiB] [--builder_disk_mb MiB] [--docker_compat] [--public]"
967
+ "Usage: tensorlake-create-sandbox-image <dockerfile_path> [--name NAME] [--cpus N] [--memory MiB] [--disk_mb MiB] [--builder_disk_mb MiB] [--docker_compat] [--public] [--no-cas]"
795
968
  );
796
969
  }
797
970
  const cpus = parsed.values.cpus != null ? Number(parsed.values.cpus) : void 0;
@@ -823,7 +996,8 @@ async function runCreateSandboxImageCli(argv = process.argv.slice(2)) {
823
996
  diskMb,
824
997
  builderDiskMb,
825
998
  dockerCompat: parsed.values.docker_compat,
826
- isPublic: parsed.values.public
999
+ isPublic: parsed.values.public,
1000
+ cas: !parsed.values["no-cas"]
827
1001
  },
828
1002
  { emit: ndjsonStdoutEmit, _allowPat: true }
829
1003
  );
@@ -839,13 +1013,14 @@ async function runImportSandboxImageCli(argv = process.argv.slice(2)) {
839
1013
  disk_mb: { type: "string" },
840
1014
  builder_disk_mb: { type: "string" },
841
1015
  docker_compat: { type: "boolean", default: false },
842
- public: { type: "boolean", default: false }
1016
+ public: { type: "boolean", default: false },
1017
+ "no-cas": { type: "boolean", default: false }
843
1018
  }
844
1019
  });
845
1020
  const imageReference = parsed.positionals[0];
846
1021
  if (!imageReference) {
847
1022
  throw new Error(
848
- "Usage: tensorlake-import-sandbox-image <image_reference> [--name NAME] [--cpus N] [--memory MiB] [--disk_mb MiB] [--builder_disk_mb MiB] [--docker_compat] [--public]"
1023
+ "Usage: tensorlake-import-sandbox-image <image_reference> [--name NAME] [--cpus N] [--memory MiB] [--disk_mb MiB] [--builder_disk_mb MiB] [--docker_compat] [--public] [--no-cas]"
849
1024
  );
850
1025
  }
851
1026
  const cpus = parsed.values.cpus != null ? Number(parsed.values.cpus) : void 0;
@@ -877,12 +1052,13 @@ async function runImportSandboxImageCli(argv = process.argv.slice(2)) {
877
1052
  diskMb,
878
1053
  builderDiskMb,
879
1054
  dockerCompat: parsed.values.docker_compat,
880
- isPublic: parsed.values.public
1055
+ isPublic: parsed.values.public,
1056
+ cas: !parsed.values["no-cas"]
881
1057
  },
882
1058
  { emit: ndjsonStdoutEmit, _allowPat: true }
883
1059
  );
884
1060
  }
885
- var cachedNativeBinding, cachedNativeBindingError, DEFAULT_IMAGE_NAME, __imageBuildInternals;
1061
+ var cachedNativeBinding, cachedNativeBindingError, DEFAULT_IMAGE_NAME, DEFAULT_SANDBOX_IMAGE_NAME, DEFAULT_IMPORTED_IMAGE_NAME, CAS_NAME_SEPARATORS, RESERVED_IMAGE_NAME_PREFIXES, MAX_CAS_IMAGE_NAME_LENGTH, __imageBuildInternals;
886
1062
  var init_sandbox_image = __esm({
887
1063
  "src/sandbox-image.ts"() {
888
1064
  "use strict";
@@ -891,6 +1067,11 @@ var init_sandbox_image = __esm({
891
1067
  init_native_binding();
892
1068
  init_image_builds();
893
1069
  DEFAULT_IMAGE_NAME = "default";
1070
+ DEFAULT_SANDBOX_IMAGE_NAME = "sandbox-image";
1071
+ DEFAULT_IMPORTED_IMAGE_NAME = "imported-image";
1072
+ CAS_NAME_SEPARATORS = "._-";
1073
+ RESERVED_IMAGE_NAME_PREFIXES = ["sandbox_template_", "image_", "cas-v1:"];
1074
+ MAX_CAS_IMAGE_NAME_LENGTH = 255;
894
1075
  __imageBuildInternals = {
895
1076
  loadNativeBinding: () => loadNativeBinding(),
896
1077
  buildContextFromEnv: () => buildContextFromEnv(),
@@ -899,7 +1080,12 @@ var init_sandbox_image = __esm({
899
1080
  eventToEmitDict: (event) => eventToEmitDict(event),
900
1081
  imageRequiresContext: (image) => imageRequiresContext(image),
901
1082
  defaultRegisteredName: (dockerfilePath) => defaultRegisteredName(dockerfilePath),
902
- defaultRegisteredNameFromImage: (reference) => defaultRegisteredNameFromImage(reference)
1083
+ defaultRegisteredNameFromImage: (reference) => defaultRegisteredNameFromImage(reference),
1084
+ registeredImageName: (explicit, generated, cas, fallback) => registeredImageName(explicit, generated, cas, fallback),
1085
+ casImageNameFrom: (raw, fallback) => casImageNameFrom(raw, fallback),
1086
+ canonicalCasImageName: (name) => canonicalCasImageName(name),
1087
+ isAddressableCasImageName: (name) => isAddressableCasImageName(name),
1088
+ defaultImportedImageName: DEFAULT_IMPORTED_IMAGE_NAME
903
1089
  };
904
1090
  }
905
1091
  });
@@ -1012,10 +1198,11 @@ var init_image = __esm({
1012
1198
  });
1013
1199
  }
1014
1200
  /**
1015
- * Build this image as a sandbox template and register it.
1201
+ * Build this image and register it as a CAS sandbox image (the default) or,
1202
+ * with `cas: false`, a legacy sandbox image.
1016
1203
  *
1017
1204
  * Materializes the image in a build sandbox, snapshots the filesystem,
1018
- * and registers the snapshot as a named sandbox template.
1205
+ * and registers the snapshot under the image's name.
1019
1206
  */
1020
1207
  async build(options = {}) {
1021
1208
  const { createSandboxImage: createSandboxImage2 } = await Promise.resolve().then(() => (init_sandbox_image(), sandbox_image_exports));
@@ -2399,7 +2586,7 @@ init_image();
2399
2586
 
2400
2587
  // src/defaults.ts
2401
2588
  init_esm_shims();
2402
- var SDK_VERSION = "0.5.153";
2589
+ var SDK_VERSION = "0.5.156";
2403
2590
  var API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
2404
2591
  var API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
2405
2592
  var NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -3207,7 +3394,7 @@ function createWorkerBinding(runtime) {
3207
3394
  };
3208
3395
  }
3209
3396
  var runtimeKey = /* @__PURE__ */ Symbol.for(
3210
- `tensorlake.native.worker.${false ? "source" : "0.5.153"}.v1`
3397
+ `tensorlake.native.worker.${false ? "source" : "0.5.156"}.v1`
3211
3398
  );
3212
3399
  var runtimes = globalThis;
3213
3400
  function workerBinding() {
@@ -3483,10 +3670,12 @@ var CloudClient = class _CloudClient {
3483
3670
  );
3484
3671
  }
3485
3672
  /**
3486
- * Delete a registered sandbox image by name or id through the merged
3487
- * catalog, with this client's credentials: an `image_` id or a name the
3488
- * Image Service knows deletes a CAS image, a `sandbox_template_` id or a
3489
- * name registered only in the platform registry deletes a legacy image.
3673
+ * Delete a registered CAS or legacy sandbox image by name or id through the
3674
+ * merged catalog, with this client's credentials: an `image_` id or a name
3675
+ * the CAS image registry knows deletes a CAS image, a `sandbox_template_` id
3676
+ * or a name registered only in the legacy image registry deletes a legacy
3677
+ * image.
3678
+ * A name is deleted from both the CAS and the legacy image registries.
3490
3679
  * Rejects when neither catalog knows the reference. The same semantics
3491
3680
  * and accepted differences as the module-level `deleteSandboxImage`.
3492
3681
  */
@@ -3494,10 +3683,10 @@ var CloudClient = class _CloudClient {
3494
3683
  await deleteSandboxImageWithCredentials(this.catalogCredentials(), imageName);
3495
3684
  }
3496
3685
  /**
3497
- * Look up a registered sandbox image by name or id through the merged
3498
- * catalog, with this client's credentials. Returns the image in the
3499
- * sandbox-template shape, or `null` when neither the Image Service nor the
3500
- * platform registry knows the reference. An explicit organization/project
3686
+ * Look up a registered CAS or legacy sandbox image by name or id through
3687
+ * the merged catalog, with this client's credentials. Returns the image in
3688
+ * the sandbox-template shape, or `null` when neither the CAS nor the legacy
3689
+ * image registry knows the reference. An explicit organization/project
3501
3690
  * scope (the client's, or the call's override) addresses that project's
3502
3691
  * routes directly, as before; without one the key's own scope applies.
3503
3692
  */