@computesdk/cli 2.3.2 → 2.4.0

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
@@ -835,15 +835,15 @@ function maxPriceFields(maxBid, maxBidPer) {
835
835
  throw new ActionsCliError("invalid_argument", "--max-bid-per requires --max-bid.");
836
836
  }
837
837
  if (maxBid === void 0) return void 0;
838
- const usd2 = Number(maxBid);
839
- if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(maxBid) || !Number.isFinite(usd2) || usd2 <= 0) {
838
+ const usd = Number(maxBid);
839
+ if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(maxBid) || !Number.isFinite(usd) || usd <= 0) {
840
840
  throw new ActionsCliError("invalid_argument", `Invalid --max-bid "${maxBid}". Expected a positive dollar amount (e.g. 0.12).`);
841
841
  }
842
842
  const per = maxBidPer ?? "second";
843
843
  if (per !== "second" && per !== "minute" && per !== "hour") {
844
844
  throw new ActionsCliError("invalid_argument", `--max-bid-per must be second, minute, or hour, got "${maxBidPer}".`);
845
845
  }
846
- return { maxPriceUsd: usd2, maxPricePer: per };
846
+ return { maxPriceUsd: usd, maxPricePer: per };
847
847
  }
848
848
  function parseVaultKind(kind) {
849
849
  if (kind === void 0 || kind === "secret" || kind === "variable") return kind ?? "secret";
@@ -871,10 +871,44 @@ function vaultSetBody(name, value, opts) {
871
871
  ...opts.labels !== void 0 && opts.labels.length > 0 && { labels: opts.labels }
872
872
  };
873
873
  }
874
+ function vaultDeliveryLabels(opts) {
875
+ if (opts.proxy && opts.inject) {
876
+ throw new ActionsCliError("invalid_argument", "--proxy and --inject are mutually exclusive.");
877
+ }
878
+ const hosts = (opts.hosts ?? []).flatMap((host) => host.split(/[\s,]+/)).map((host) => host.trim().toLowerCase()).filter((host) => host !== "");
879
+ if (opts.inject) {
880
+ if (hosts.length > 0) {
881
+ throw new ActionsCliError(
882
+ "invalid_argument",
883
+ "--inject takes no --hosts \u2014 host rules only apply to --proxy."
884
+ );
885
+ }
886
+ return ["materialize"];
887
+ }
888
+ if (!opts.proxy) {
889
+ throw new ActionsCliError("invalid_argument", "Pick a delivery: --proxy (with --hosts) or --inject.");
890
+ }
891
+ if (hosts.length === 0) {
892
+ throw new ActionsCliError(
893
+ "invalid_argument",
894
+ "--proxy needs --hosts \u2014 the hosts the real value may be attached to."
895
+ );
896
+ }
897
+ return [`hosts:${hosts.join(",")}`];
898
+ }
899
+ function vaultSetLabels(opts) {
900
+ const flagged = opts.proxy === true || opts.inject === true || (opts.hosts?.length ?? 0) > 0;
901
+ if (flagged && (opts.labels?.length ?? 0) > 0) {
902
+ throw new ActionsCliError("invalid_argument", "Use --labels or --proxy/--inject --hosts, not both.");
903
+ }
904
+ if (!flagged) return opts.labels;
905
+ return vaultDeliveryLabels(opts);
906
+ }
874
907
  function formatVaultRow(item) {
875
908
  const flags = [
876
909
  item.kind,
877
910
  ...item.revealable && item.kind === "secret" ? ["revealable"] : [],
911
+ ...item.labels.map(safeTerm),
878
912
  `v${item.version}`,
879
913
  ...item.source === "organization" ? ["inherited"] : [],
880
914
  ...item.overridesOrganization ? ["overrides org"] : []
@@ -1227,7 +1261,7 @@ function registerActionsCommands(program2) {
1227
1261
  }
1228
1262
  });
1229
1263
  vaultScope(
1230
- vault.command("set").description("Store a value, read from stdin (or --from-file) and sent exactly as read").argument("<name>", "item name, e.g. NPM_TOKEN").option("--from-file <path>", "read the value from a file instead of stdin").option("--revealable", "let the value be read back with `vault get` (secrets; fixed at creation)").option("--description <text>", "what the item is for").option("--labels <labels...>", "labels (fixed at creation)")
1264
+ vault.command("set").description("Store a value, read from stdin (or --from-file) and sent exactly as read").argument("<name>", "item name, e.g. NPM_TOKEN").option("--from-file <path>", "read the value from a file instead of stdin").option("--revealable", "let the value be read back with `vault get` (secrets; fixed at creation)").option("--description <text>", "what the item is for").option("--labels <labels...>", "labels (fixed at creation)").option("--proxy", "hand the job a placeholder; the value is attached to requests for --hosts at egress").option("--inject", "inject the real value into the job environment (the default)").option("--hosts <hosts...>", "hosts the proxied value may be attached to (comma or space separated, *.example.com covers subdomains)")
1231
1265
  ).action(async (name, opts) => {
1232
1266
  try {
1233
1267
  if (opts.fromFile === void 0 && process.stdin.isTTY) {
@@ -1238,7 +1272,8 @@ function registerActionsCommands(program2) {
1238
1272
  }
1239
1273
  const value = readFileSync(opts.fromFile ?? 0, "utf8");
1240
1274
  const kind = parseVaultKind(opts.kind);
1241
- const body = vaultSetBody(name, value, { ...opts, kind });
1275
+ const labels = vaultSetLabels(opts);
1276
+ const body = vaultSetBody(name, value, { ...opts, kind, labels });
1242
1277
  const result = await (await vaultValueClient(opts)).put(
1243
1278
  vaultPath("/api/v1/vault", { repo: opts.repo }),
1244
1279
  body
@@ -1268,6 +1303,26 @@ function registerActionsCommands(program2) {
1268
1303
  fail(e, opts);
1269
1304
  }
1270
1305
  });
1306
+ vaultScope(
1307
+ vault.command("delivery").description("Reclassify how a secret reaches a job \u2014 labels only, no value needed").argument("<name>", "item name").option("--proxy", "hand the job a placeholder; the value is attached to requests for --hosts at egress").option("--inject", "inject the real value into the job environment").option("--hosts <hosts...>", "hosts the proxied value may be attached to (comma or space separated, *.example.com covers subdomains)")
1308
+ ).action(async (name, opts) => {
1309
+ try {
1310
+ const kind = parseVaultKind(opts.kind);
1311
+ const labels = vaultDeliveryLabels(opts);
1312
+ const result = await (await client(opts)).patch(
1313
+ vaultPath("/api/v1/vault", { repo: opts.repo }),
1314
+ { name, kind, labels }
1315
+ );
1316
+ output(opts, result, (r) => {
1317
+ const where = opts.repo ? safeTerm(opts.repo) : "org";
1318
+ console.log(
1319
+ `reclassified ${pc.cyan(safeTerm(r.item.name))} ${pc.dim(`(labels: ${r.item.labels.join(", ") || "none"}, v${r.item.version}, ${where})`)}`
1320
+ );
1321
+ });
1322
+ } catch (e) {
1323
+ fail(e, opts);
1324
+ }
1325
+ });
1271
1326
  vaultScope(
1272
1327
  vault.command("rm").description("Delete an item (with --repo, only the repo's override)").argument("<name>", "item name")
1273
1328
  ).action(async (name, opts) => {
@@ -1371,6 +1426,47 @@ function registerActionsCommands(program2) {
1371
1426
 
1372
1427
  // src/market.ts
1373
1428
  import pc2 from "picocolors";
1429
+
1430
+ // src/rate-display.ts
1431
+ var SECONDS_PER_MINUTE = 60;
1432
+ var SECONDS_PER_HOUR = 3600;
1433
+ function rateAllUnits(rate) {
1434
+ const perSecond = rate.per === "second" ? rate.usd : rate.per === "minute" ? rate.usd / SECONDS_PER_MINUTE : rate.usd / SECONDS_PER_HOUR;
1435
+ return {
1436
+ perSecond,
1437
+ perMinute: perSecond * SECONDS_PER_MINUTE,
1438
+ perHour: perSecond * SECONDS_PER_HOUR
1439
+ };
1440
+ }
1441
+ function formatUsd(usd) {
1442
+ if (!Number.isFinite(usd)) return "$\u2014";
1443
+ if (usd === 0) return "$0";
1444
+ const decimals = Math.min(100, Math.max(0, 3 - Math.floor(Math.log10(Math.abs(usd)))));
1445
+ const fixed = usd.toFixed(decimals);
1446
+ const trimmed = fixed.includes(".") ? fixed.replace(/0+$/, "").replace(/\.$/, "") : fixed;
1447
+ return `$${trimmed}`;
1448
+ }
1449
+ function formatMoney(usd) {
1450
+ if (!Number.isFinite(usd)) return "$\u2014";
1451
+ const sign = usd < 0 ? "-" : "";
1452
+ const abs = Math.abs(usd);
1453
+ if (abs !== 0 && abs < 0.01) {
1454
+ return `${sign}${formatUsd(abs)}`;
1455
+ }
1456
+ const s = abs.toLocaleString("en-US", {
1457
+ minimumFractionDigits: 2,
1458
+ maximumFractionDigits: 2
1459
+ });
1460
+ return `${sign}$${s}`;
1461
+ }
1462
+ function formatRateAllUnits(rate) {
1463
+ return `${formatUsd(rate.perHour)}/hr \xB7 ${formatUsd(rate.perMinute)}/min \xB7 ${formatUsd(rate.perSecond)}/s`;
1464
+ }
1465
+ function formatUsdPer(rate) {
1466
+ return formatRateAllUnits(rateAllUnits(rate));
1467
+ }
1468
+
1469
+ // src/market.ts
1374
1470
  var USD_RE = /^\d+(\.\d+)?([eE][+-]?\d+)?$/;
1375
1471
  var RATE_UNITS = ["second", "minute", "hour"];
1376
1472
  var MARKET_LANES = ["actions", "sandbox"];
@@ -1402,8 +1498,8 @@ function parseRate(price, per) {
1402
1498
  }
1403
1499
  unit = inline;
1404
1500
  }
1405
- const usd2 = Number(usdText);
1406
- if (!USD_RE.test(usdText) || !Number.isFinite(usd2) || usd2 <= 0) {
1501
+ const usd = Number(usdText);
1502
+ if (!USD_RE.test(usdText) || !Number.isFinite(usd) || usd <= 0) {
1407
1503
  throw new ActionsCliError(
1408
1504
  "invalid_argument",
1409
1505
  `Invalid --price "${price}". Expected a positive dollar amount (e.g. 0.12/hour).`
@@ -1421,7 +1517,7 @@ function parseRate(price, per) {
1421
1517
  `The unit must be second, minute, or hour, got "${unit}".`
1422
1518
  );
1423
1519
  }
1424
- return { usd: usd2, per: unit };
1520
+ return { usd, per: unit };
1425
1521
  }
1426
1522
  function parseCapacity(value) {
1427
1523
  if (value === void 0) return void 0;
@@ -1524,11 +1620,8 @@ function credentialBody(fields, values) {
1524
1620
  }
1525
1621
  return { fields: values };
1526
1622
  }
1527
- function formatUsd(usd2) {
1528
- return `$${usd2.toFixed(6).replace(/\.?0+$/, "")}`;
1529
- }
1530
- function formatRate(usd2, per) {
1531
- return `${formatUsd(usd2)}/${per}`;
1623
+ function formatRate(usd, per) {
1624
+ return formatUsdPer({ usd, per });
1532
1625
  }
1533
1626
  function formatListingStatus(ask) {
1534
1627
  let label;
@@ -1611,7 +1704,7 @@ function formatBook(book) {
1611
1704
  return lines.join("\n");
1612
1705
  }
1613
1706
  function formatReplacedFill(fill) {
1614
- const settled = formatUsd(fill.settledMicroUsd / 1e6);
1707
+ const settled = formatMoney(fill.settledMicroUsd / 1e6);
1615
1708
  const job = fill.jobRequeued ? pc2.dim(" \u2014 job re-places on the buyer's next provider") : "";
1616
1709
  return `replaced ${pc2.cyan(fill.fillId)} settled ${settled}${job}`;
1617
1710
  }
@@ -1639,8 +1732,8 @@ function formatSettlementRow(s) {
1639
1732
  return [
1640
1733
  pc2.dim(period),
1641
1734
  `${s.vcpuSeconds.toLocaleString("en-US")} vCPU\xB7s`,
1642
- `gross ${formatUsd(s.grossUsd)}`,
1643
- `net ${formatUsd(s.netUsd)}`,
1735
+ `gross ${formatMoney(s.grossUsd)}`,
1736
+ `net ${formatMoney(s.netUsd)}`,
1644
1737
  paid
1645
1738
  ].join(" ");
1646
1739
  }
@@ -1898,8 +1991,8 @@ function parseMaxPrice(value, per) {
1898
1991
  }
1899
1992
  unit = inline;
1900
1993
  }
1901
- const usd2 = Number(usdText);
1902
- if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(usdText) || !Number.isFinite(usd2) || usd2 <= 0) {
1994
+ const usd = Number(usdText);
1995
+ if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(usdText) || !Number.isFinite(usd) || usd <= 0) {
1903
1996
  throw new Error(`Invalid --max-price "${value}". Expected a positive dollar amount like 0.12/hour.`);
1904
1997
  }
1905
1998
  if (unit !== "second" && unit !== "minute" && unit !== "hour") {
@@ -1907,7 +2000,7 @@ function parseMaxPrice(value, per) {
1907
2000
  "--max-price needs a unit \u2014 write it as <usd>/<unit> (e.g. --max-price 0.12/hour) or pass --max-price-per hour."
1908
2001
  );
1909
2002
  }
1910
- return { usd: usd2, per: unit };
2003
+ return { usd, per: unit };
1911
2004
  }
1912
2005
  function shellQuote(arg) {
1913
2006
  return `'${arg.replace(/'/g, `'\\''`)}'`;
@@ -1924,7 +2017,7 @@ function printSandbox(s) {
1924
2017
  const p2 = s.placement;
1925
2018
  const box = p2.box ? ` / ${p2.box.sizeName ?? "custom"}${p2.box.resources ? ` (${p2.box.resources.cpus ?? "?"} vCPU / ${p2.box.resources.memoryMb ?? "?"} MB)` : ""}` : "";
1926
2019
  console.log(
1927
- ` provider: ${p2.box?.provider ?? s.provider ?? "\u2014"}${box} size: ${p2.size ?? "\u2014"} order: ${p2.orderType ?? "\u2014"} rate: $${p2.rate.usd}/${p2.rate.per}`
2020
+ ` provider: ${p2.box?.provider ?? s.provider ?? "\u2014"}${box} size: ${p2.size ?? "\u2014"} order: ${p2.orderType ?? "\u2014"} rate: ${formatUsdPer(p2.rate)}${p2.maxPrice ? ` max price: ${formatUsdPer(p2.maxPrice)}` : ""}`
1928
2021
  );
1929
2022
  }
1930
2023
  if (attach !== void 0) {
@@ -1933,7 +2026,8 @@ function printSandbox(s) {
1933
2026
  );
1934
2027
  }
1935
2028
  }
1936
- var usd = (n, suffix = "") => n === void 0 ? "\u2014" : `$${n.toFixed(4).replace(/0+$/, "").replace(/\.$/, ".00")}${suffix}`;
2029
+ var perHour = (n) => n === void 0 ? "\u2014" : formatRateAllUnits(rateAllUnits({ usd: n, per: "hour" }));
2030
+ var usdAmount = (n) => n === void 0 ? "\u2014" : formatMoney(n);
1937
2031
  function printQuote(q, timeoutMs) {
1938
2032
  console.log(`quote: ${q.ok ? pc3.green("ok") : pc3.red(q.reason ?? "unfillable")}`);
1939
2033
  const box = q.placement?.box;
@@ -1942,15 +2036,18 @@ function printQuote(q, timeoutMs) {
1942
2036
  );
1943
2037
  console.log(` order type: ${q.orderType} order: ${q.providerOrder.join(", ")}`);
1944
2038
  if (q.rateUsd) {
1945
- console.log(` rate: ${usd(q.rateUsd.perHour, "/hour")} cheapest live: ${usd(q.cheapestLiveUsdPerHour, "/hr")} reference: ${usd(q.referenceUsdPerHour, "/hr")}`);
2039
+ console.log(` rate: ${formatRateAllUnits(q.rateUsd)}`);
1946
2040
  } else if (q.rate) {
1947
- console.log(` rate: $${q.rate.usd}/${q.rate.per}`);
2041
+ console.log(` rate: ${formatUsdPer(q.rate)}`);
1948
2042
  }
2043
+ console.log(` cheapest live: ${perHour(q.cheapestLiveUsdPerHour)}`);
2044
+ console.log(` reference: ${perHour(q.referenceUsdPerHour)}`);
1949
2045
  const timeout = timeoutMs !== void 0 ? ` for ${timeoutMs}ms` : "";
1950
- console.log(` est. cost${timeout}: ${usd(q.estimatedCostUsd)} required hold: ${usd(q.requiredHoldUsd)}`);
1951
2046
  console.log(
1952
- ` cap: ${q.maxPrice ? `$${q.maxPrice.usd}/${q.maxPrice.per}` : usd(q.marketCapUsdPerHour, "/hr")} protection limit: ${usd(q.protectionLimitUsdPerHour, "/hr")} balance: ${usd(q.creditBalanceUsd)}`
2047
+ ` est. cost${timeout}: ${usdAmount(q.estimatedCostUsd)} required hold: ${usdAmount(q.requiredHoldUsd)} balance: ${usdAmount(q.creditBalanceUsd)}`
1953
2048
  );
2049
+ console.log(` cap: ${q.maxPrice ? formatUsdPer(q.maxPrice) : perHour(q.marketCapUsdPerHour)}`);
2050
+ console.log(` protection limit: ${perHour(q.protectionLimitUsdPerHour)}`);
1954
2051
  if (!q.ok && q.topUpPath) console.log(` ${pc3.dim(`\u2192 ${q.topUpPath}`)}`);
1955
2052
  if (q.liveAskDepth !== void 0) console.log(` ${pc3.dim(`live asks: ${q.liveAskDepth}`)}`);
1956
2053
  }