@tuned-tensor/cli 0.28.0 → 0.28.1

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.js CHANGED
@@ -12462,17 +12462,17 @@ function registerEndpointCommands(parent) {
12462
12462
  if (isJsonMode()) return printJson(data3);
12463
12463
  printDetail([["Inference key (save securely)", data3.inference_key]]);
12464
12464
  });
12465
- endpoints.command("invoke <id>").requiredOption("--payload <file>", "Complete model request as a JSON object (up to 128 KiB)").option("--request-id <uuid>", "Reuse this ID to retry without a second charge").action(async (id, options) => {
12465
+ endpoints.command("invoke <id>").requiredOption("--payload <file>", "Complete model request as a JSON object (up to 128 KiB)").option("--request-id <uuid>", "Same-payload transport/in-progress retry ID (new ID after failure/refund)").action(async (id, options) => {
12466
12466
  z.uuid().parse(id);
12467
12467
  const requestId = options.requestId ?? randomUUID10();
12468
12468
  z.uuid().parse(requestId);
12469
12469
  const payload = readInferencePayload(options.payload);
12470
- if (!isJsonMode()) console.error(`Request ID: ${requestId} (reuse with --request-id when retrying)`);
12470
+ if (!isJsonMode()) console.error(`Request ID: ${requestId} (reuse for the same payload after connection loss or while still running; use a new ID for a failed/refunded request)`);
12471
12471
  try {
12472
12472
  const { data: data3 } = await post(`/endpoints/${id}/invoke`, payload, parent.optsWithGlobals(), { "Idempotency-Key": requestId });
12473
12473
  printJson({ request_id: requestId, data: data3 });
12474
12474
  } catch (error) {
12475
- throw new Error(`Request ${requestId}: ${error instanceof Error ? error.message : "inference failed"}. Retry with --request-id ${requestId}.`, { cause: error });
12475
+ throw new Error(`Request ${requestId}: ${error instanceof Error ? error.message : "inference failed"}. For connection loss or a request still running, retry the same payload with --request-id ${requestId}. A failed/refunded request needs a new request ID.`, { cause: error });
12476
12476
  }
12477
12477
  });
12478
12478
  }
@@ -12483,9 +12483,13 @@ import { createHash as createHash9 } from "crypto";
12483
12483
  import {
12484
12484
  existsSync as existsSync10,
12485
12485
  mkdirSync as mkdirSync5,
12486
+ mkdtempSync,
12487
+ linkSync,
12488
+ renameSync,
12489
+ copyFileSync,
12490
+ constants as constants2,
12486
12491
  statSync as statSync5,
12487
12492
  createWriteStream,
12488
- unlinkSync,
12489
12493
  readFileSync as readFileSync13,
12490
12494
  writeFileSync as writeFileSync6,
12491
12495
  readdirSync,
@@ -13602,7 +13606,7 @@ function createDownloadProgress(totalBytes, enabled) {
13602
13606
  }
13603
13607
  return { render, stop };
13604
13608
  }
13605
- async function downloadUrlToFile(url, outputPath) {
13609
+ async function downloadUrlToFile(url, outputPath, force = false) {
13606
13610
  const res = await fetch(url);
13607
13611
  if (!res.ok) {
13608
13612
  throw new Error(`Download failed: ${res.status} ${res.statusText}`);
@@ -13611,7 +13615,9 @@ async function downloadUrlToFile(url, outputPath) {
13611
13615
  throw new Error("Download failed: response body was empty");
13612
13616
  }
13613
13617
  mkdirSync5(dirname13(outputPath), { recursive: true });
13614
- const file = createWriteStream(outputPath);
13618
+ const stagingDir = mkdtempSync(join17(dirname13(outputPath), ".tt-download-"));
13619
+ const stagedPath = join17(stagingDir, "artifact");
13620
+ const file = createWriteStream(stagedPath, { flags: "wx", mode: 384 });
13615
13621
  const contentLength = parseContentLength(res.headers.get("content-length"));
13616
13622
  const progress = createDownloadProgress(
13617
13623
  contentLength,
@@ -13628,15 +13634,27 @@ async function downloadUrlToFile(url, outputPath) {
13628
13634
  try {
13629
13635
  progress.render(0, true);
13630
13636
  await pipeline(Readable.fromWeb(res.body), progressStream, file);
13637
+ if (force) {
13638
+ renameSync(stagedPath, outputPath);
13639
+ } else {
13640
+ try {
13641
+ try {
13642
+ linkSync(stagedPath, outputPath);
13643
+ } catch (err) {
13644
+ if (!["EPERM", "ENOTSUP", "EOPNOTSUPP", "EXDEV", "ENOSYS"].includes(err.code ?? "")) throw err;
13645
+ copyFileSync(stagedPath, outputPath, constants2.COPYFILE_EXCL);
13646
+ }
13647
+ } catch (err) {
13648
+ if (err.code === "EEXIST") {
13649
+ throw new Error(`Output file already exists: ${outputPath}. Use --force to overwrite.`);
13650
+ }
13651
+ throw err;
13652
+ }
13653
+ }
13631
13654
  progress.render(downloadedBytes, true);
13655
+ } finally {
13632
13656
  progress.stop();
13633
- } catch (err) {
13634
- progress.stop();
13635
- try {
13636
- unlinkSync(outputPath);
13637
- } catch {
13638
- }
13639
- throw err;
13657
+ rmSync(stagingDir, { recursive: true, force: true });
13640
13658
  }
13641
13659
  return contentLength;
13642
13660
  }
@@ -13838,7 +13856,7 @@ async function resolveServeTarget(target, opts, cacheDir, forceDownload) {
13838
13856
  const archivePath = join17(modelCacheDir, data3.filename);
13839
13857
  const extractDir = join17(modelCacheDir, "model");
13840
13858
  if (!existsSync10(archivePath) || forceDownload) {
13841
- await downloadUrlToFile(data3.url, archivePath);
13859
+ await downloadUrlToFile(data3.url, archivePath, forceDownload);
13842
13860
  }
13843
13861
  extractArchive(archivePath, extractDir, forceDownload);
13844
13862
  return {
@@ -14110,7 +14128,7 @@ function registerModelsCommands(parent) {
14110
14128
  if (existsSync10(outputPath) && !cmdOpts.force) {
14111
14129
  throw new Error(`Output file already exists: ${outputPath}. Use --force to overwrite.`);
14112
14130
  }
14113
- const bytes = await downloadUrlToFile(data3.url, outputPath);
14131
+ const bytes = await downloadUrlToFile(data3.url, outputPath, Boolean(cmdOpts.force));
14114
14132
  if (isJsonMode()) {
14115
14133
  return printJson({
14116
14134
  id: fullId,
@@ -14532,7 +14550,7 @@ Use \`tt balance\` for cloud training credits.`);
14532
14550
 
14533
14551
  // src/commands/upgrade.ts
14534
14552
  import { spawn as spawn6 } from "child_process";
14535
- import { accessSync, constants as constants2, existsSync as existsSync11, readFileSync as readFileSync16, realpathSync } from "fs";
14553
+ import { accessSync, constants as constants3, existsSync as existsSync11, readFileSync as readFileSync16, realpathSync } from "fs";
14536
14554
  import { dirname as dirname15, join as join19, win32 } from "path";
14537
14555
  import chalk14 from "chalk";
14538
14556
 
@@ -14738,7 +14756,7 @@ function resolveGlobalInstall(entrypoint, platform = process.platform) {
14738
14756
  function prefixIsWritable(prefix, platform) {
14739
14757
  const modules = platform === "win32" ? join19(prefix, "node_modules") : join19(prefix, "lib", "node_modules");
14740
14758
  try {
14741
- accessSync(existsSync11(modules) ? modules : prefix, constants2.W_OK);
14759
+ accessSync(existsSync11(modules) ? modules : prefix, constants3.W_OK);
14742
14760
  return true;
14743
14761
  } catch {
14744
14762
  return false;
@@ -14790,7 +14808,7 @@ function formatCommand(args2, platform) {
14790
14808
  if (platform === "win32") {
14791
14809
  return ["npm.cmd", ...args2].map((arg) => /^[a-zA-Z0-9_@./:\\+=-]+$/.test(arg) ? arg : "'" + arg.replaceAll("'", "''") + "'").join(" ");
14792
14810
  }
14793
- return ["npm", ...args2].map((arg) => /\s/.test(arg) ? JSON.stringify(arg) : arg).join(" ");
14811
+ return ["npm", ...args2].map((arg) => /^[a-zA-Z0-9_@./:+=-]+$/.test(arg) ? arg : "'" + arg.replaceAll("'", "'\\''") + "'").join(" ");
14794
14812
  }
14795
14813
  function registerUpgradeCommand(program, deps) {
14796
14814
  program.command("upgrade").alias("update").description("Upgrade tt to the latest release").argument("[version]", "Version or npm dist-tag to install (default: latest)").option("--check", "Only report whether an update is available").addHelpText(
@@ -15318,7 +15336,7 @@ ${formatCliUpdateNotice(update)}
15318
15336
  }
15319
15337
 
15320
15338
  // src/index.ts
15321
- runCli("0.28.0").catch((err) => {
15339
+ runCli("0.28.1").catch((err) => {
15322
15340
  reportError(err);
15323
15341
  process.exit(1);
15324
15342
  });