@computesdk/cli 2.3.1 → 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 +124 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
839
|
-
if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(maxBid) || !Number.isFinite(
|
|
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:
|
|
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
|
|
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
|
|
1406
|
-
if (!USD_RE.test(usdText) || !Number.isFinite(
|
|
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
|
|
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
|
|
1528
|
-
return
|
|
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;
|
|
@@ -1594,8 +1687,9 @@ function formatBook(book) {
|
|
|
1594
1687
|
if (book.bids.length === 0) lines.push(pc2.dim(" no open offers"));
|
|
1595
1688
|
for (const bid of book.bids) {
|
|
1596
1689
|
const where = bid.region ? safeTerm(bid.region) : "anywhere";
|
|
1690
|
+
const yours = bid.mine ? pc2.cyan(" (yours)") : "";
|
|
1597
1691
|
lines.push(
|
|
1598
|
-
` ${lane(bid.useCase)} pays up to ${formatRate(bid.maxUsd, bid.per)} ${safeTerm(bid.size)} ${where} ${pc2.dim(`posted ${bid.createdAt}`)}`
|
|
1692
|
+
` ${lane(bid.useCase)} pays up to ${formatRate(bid.maxUsd, bid.per)} ${safeTerm(bid.size)} ${where} ${pc2.dim(`posted ${bid.createdAt}`)}${yours}`
|
|
1599
1693
|
);
|
|
1600
1694
|
}
|
|
1601
1695
|
lines.push("");
|
|
@@ -1610,7 +1704,7 @@ function formatBook(book) {
|
|
|
1610
1704
|
return lines.join("\n");
|
|
1611
1705
|
}
|
|
1612
1706
|
function formatReplacedFill(fill) {
|
|
1613
|
-
const settled =
|
|
1707
|
+
const settled = formatMoney(fill.settledMicroUsd / 1e6);
|
|
1614
1708
|
const job = fill.jobRequeued ? pc2.dim(" \u2014 job re-places on the buyer's next provider") : "";
|
|
1615
1709
|
return `replaced ${pc2.cyan(fill.fillId)} settled ${settled}${job}`;
|
|
1616
1710
|
}
|
|
@@ -1638,8 +1732,8 @@ function formatSettlementRow(s) {
|
|
|
1638
1732
|
return [
|
|
1639
1733
|
pc2.dim(period),
|
|
1640
1734
|
`${s.vcpuSeconds.toLocaleString("en-US")} vCPU\xB7s`,
|
|
1641
|
-
`gross ${
|
|
1642
|
-
`net ${
|
|
1735
|
+
`gross ${formatMoney(s.grossUsd)}`,
|
|
1736
|
+
`net ${formatMoney(s.netUsd)}`,
|
|
1643
1737
|
paid
|
|
1644
1738
|
].join(" ");
|
|
1645
1739
|
}
|
|
@@ -1897,8 +1991,8 @@ function parseMaxPrice(value, per) {
|
|
|
1897
1991
|
}
|
|
1898
1992
|
unit = inline;
|
|
1899
1993
|
}
|
|
1900
|
-
const
|
|
1901
|
-
if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(usdText) || !Number.isFinite(
|
|
1994
|
+
const usd = Number(usdText);
|
|
1995
|
+
if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(usdText) || !Number.isFinite(usd) || usd <= 0) {
|
|
1902
1996
|
throw new Error(`Invalid --max-price "${value}". Expected a positive dollar amount like 0.12/hour.`);
|
|
1903
1997
|
}
|
|
1904
1998
|
if (unit !== "second" && unit !== "minute" && unit !== "hour") {
|
|
@@ -1906,7 +2000,7 @@ function parseMaxPrice(value, per) {
|
|
|
1906
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."
|
|
1907
2001
|
);
|
|
1908
2002
|
}
|
|
1909
|
-
return { usd
|
|
2003
|
+
return { usd, per: unit };
|
|
1910
2004
|
}
|
|
1911
2005
|
function shellQuote(arg) {
|
|
1912
2006
|
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
@@ -1923,7 +2017,7 @@ function printSandbox(s) {
|
|
|
1923
2017
|
const p2 = s.placement;
|
|
1924
2018
|
const box = p2.box ? ` / ${p2.box.sizeName ?? "custom"}${p2.box.resources ? ` (${p2.box.resources.cpus ?? "?"} vCPU / ${p2.box.resources.memoryMb ?? "?"} MB)` : ""}` : "";
|
|
1925
2019
|
console.log(
|
|
1926
|
-
` provider: ${p2.box?.provider ?? s.provider ?? "\u2014"}${box} size: ${p2.size ?? "\u2014"} order: ${p2.orderType ?? "\u2014"} rate:
|
|
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)}` : ""}`
|
|
1927
2021
|
);
|
|
1928
2022
|
}
|
|
1929
2023
|
if (attach !== void 0) {
|
|
@@ -1932,7 +2026,8 @@ function printSandbox(s) {
|
|
|
1932
2026
|
);
|
|
1933
2027
|
}
|
|
1934
2028
|
}
|
|
1935
|
-
var
|
|
2029
|
+
var perHour = (n) => n === void 0 ? "\u2014" : formatRateAllUnits(rateAllUnits({ usd: n, per: "hour" }));
|
|
2030
|
+
var usdAmount = (n) => n === void 0 ? "\u2014" : formatMoney(n);
|
|
1936
2031
|
function printQuote(q, timeoutMs) {
|
|
1937
2032
|
console.log(`quote: ${q.ok ? pc3.green("ok") : pc3.red(q.reason ?? "unfillable")}`);
|
|
1938
2033
|
const box = q.placement?.box;
|
|
@@ -1941,15 +2036,18 @@ function printQuote(q, timeoutMs) {
|
|
|
1941
2036
|
);
|
|
1942
2037
|
console.log(` order type: ${q.orderType} order: ${q.providerOrder.join(", ")}`);
|
|
1943
2038
|
if (q.rateUsd) {
|
|
1944
|
-
console.log(` rate: ${
|
|
2039
|
+
console.log(` rate: ${formatRateAllUnits(q.rateUsd)}`);
|
|
1945
2040
|
} else if (q.rate) {
|
|
1946
|
-
console.log(` rate:
|
|
2041
|
+
console.log(` rate: ${formatUsdPer(q.rate)}`);
|
|
1947
2042
|
}
|
|
2043
|
+
console.log(` cheapest live: ${perHour(q.cheapestLiveUsdPerHour)}`);
|
|
2044
|
+
console.log(` reference: ${perHour(q.referenceUsdPerHour)}`);
|
|
1948
2045
|
const timeout = timeoutMs !== void 0 ? ` for ${timeoutMs}ms` : "";
|
|
1949
|
-
console.log(` est. cost${timeout}: ${usd(q.estimatedCostUsd)} required hold: ${usd(q.requiredHoldUsd)}`);
|
|
1950
2046
|
console.log(
|
|
1951
|
-
`
|
|
2047
|
+
` est. cost${timeout}: ${usdAmount(q.estimatedCostUsd)} required hold: ${usdAmount(q.requiredHoldUsd)} balance: ${usdAmount(q.creditBalanceUsd)}`
|
|
1952
2048
|
);
|
|
2049
|
+
console.log(` cap: ${q.maxPrice ? formatUsdPer(q.maxPrice) : perHour(q.marketCapUsdPerHour)}`);
|
|
2050
|
+
console.log(` protection limit: ${perHour(q.protectionLimitUsdPerHour)}`);
|
|
1953
2051
|
if (!q.ok && q.topUpPath) console.log(` ${pc3.dim(`\u2192 ${q.topUpPath}`)}`);
|
|
1954
2052
|
if (q.liveAskDepth !== void 0) console.log(` ${pc3.dim(`live asks: ${q.liveAskDepth}`)}`);
|
|
1955
2053
|
}
|