@computesdk/cli 2.5.5 → 2.5.6
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/README.md +1 -1
- package/dist/index.js +256 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ tokens renew automatically.
|
|
|
25
25
|
|
|
26
26
|
```
|
|
27
27
|
compute actions … # Actions API — repos, dispatch, runs, logs, vault
|
|
28
|
-
compute market … # sell
|
|
28
|
+
compute market … # buy and sell on the compute market (cap, bids, credits, listings)
|
|
29
29
|
compute sandboxes … # platform sandbox control plane
|
|
30
30
|
compute bench … # benchmarks CLI (run, auth, org, results, …)
|
|
31
31
|
compute providers # sandbox provider credential status
|
package/dist/index.js
CHANGED
|
@@ -1028,27 +1028,39 @@ function printDiscovery(d) {
|
|
|
1028
1028
|
}
|
|
1029
1029
|
console.log(pc2.dim(`discovery: ${d.workflowsFound ? "workflows found" : "no workflows yet"}${d.seeded ? ", cursors seeded" : ""}`));
|
|
1030
1030
|
}
|
|
1031
|
+
function isPatchedWorkflowTarget(target) {
|
|
1032
|
+
return "workflowPath" in target;
|
|
1033
|
+
}
|
|
1034
|
+
function patchTouches(patch, path) {
|
|
1035
|
+
const plain = `+++ b/${path}`;
|
|
1036
|
+
const quoted = `+++ "b/${path}"`;
|
|
1037
|
+
return patch.split("\n").some((line) => {
|
|
1038
|
+
const header = line.replace(/\t.*$/, "");
|
|
1039
|
+
return header === plain || header === quoted;
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1031
1042
|
function dispatchBody(workflow, opts) {
|
|
1032
|
-
|
|
1043
|
+
const patched = isPatchedWorkflowTarget(workflow);
|
|
1044
|
+
if (!patched && !workflow.dispatchable && !opts.manual) {
|
|
1033
1045
|
throw new ActionsCliError(
|
|
1034
1046
|
"invalid_argument",
|
|
1035
1047
|
`Workflow "${workflow.path}" does not declare workflow_dispatch. Pass --manual to run it anyway (no inputs).`
|
|
1036
1048
|
);
|
|
1037
1049
|
}
|
|
1038
|
-
if (!workflow.dispatchable && opts.inputs !== void 0 && opts.inputs.length > 0) {
|
|
1050
|
+
if (!patched && !workflow.dispatchable && opts.inputs !== void 0 && opts.inputs.length > 0) {
|
|
1039
1051
|
throw new ActionsCliError(
|
|
1040
1052
|
"invalid_argument",
|
|
1041
1053
|
`Workflow "${workflow.path}" has no workflow_dispatch inputs; --manual runs of it take no --inputs.`
|
|
1042
1054
|
);
|
|
1043
1055
|
}
|
|
1044
|
-
const ref = opts.ref ?? workflow.refs[0];
|
|
1056
|
+
const ref = opts.ref ?? (patched ? void 0 : workflow.refs[0]);
|
|
1045
1057
|
if (!ref) throw new ActionsCliError("invalid_argument", "No --ref given and the workflow has no watched refs.");
|
|
1046
1058
|
if (opts.providerRegion !== void 0 && opts.provider === void 0) {
|
|
1047
1059
|
throw new ActionsCliError("invalid_argument", "--provider-region requires --provider.");
|
|
1048
1060
|
}
|
|
1049
1061
|
const maxPrice = maxPriceFields(opts.maxBid, opts.maxBidPer);
|
|
1050
1062
|
return {
|
|
1051
|
-
workflowId: workflow.id,
|
|
1063
|
+
...patched ? { repoFullName: workflow.repoFullName, workflowPath: workflow.workflowPath } : { workflowId: workflow.id },
|
|
1052
1064
|
ref,
|
|
1053
1065
|
inputs: parseInputs(opts.inputs),
|
|
1054
1066
|
...opts.manual && { manual: true },
|
|
@@ -1212,36 +1224,38 @@ function registerActionsCommands(program2) {
|
|
|
1212
1224
|
).action(async (repo, opts) => {
|
|
1213
1225
|
try {
|
|
1214
1226
|
const c = await client(opts);
|
|
1227
|
+
let ref = opts.ref;
|
|
1228
|
+
let local = null;
|
|
1229
|
+
if (opts.withChanges) {
|
|
1230
|
+
ref ?? (ref = currentBranch() ?? void 0);
|
|
1231
|
+
if (!ref) throw new ActionsCliError("invalid_argument", "--with-changes needs a branch: check one out or pass --ref.");
|
|
1232
|
+
local = localChangesPatch(ref, void 0, repo);
|
|
1233
|
+
} else if (!opts.json && hasLocalChanges()) {
|
|
1234
|
+
console.error(pc2.dim("You have uncommitted changes. Add --with-changes to run them."));
|
|
1235
|
+
}
|
|
1215
1236
|
const { workflows } = await c.get(
|
|
1216
1237
|
"/api/v1/actions/workflows",
|
|
1217
1238
|
{ repo }
|
|
1218
1239
|
);
|
|
1219
|
-
const workflow = matchWorkflow(workflows, opts.workflow);
|
|
1240
|
+
const workflow = matchWorkflow(workflows, opts.workflow) ?? (local && patchTouches(local.patch, opts.workflow) ? { repoFullName: repo, workflowPath: opts.workflow } : void 0);
|
|
1220
1241
|
if (!workflow) {
|
|
1221
1242
|
const choices = workflows.map((w) => `${w.path} (${w.name})`).join(", ") || "none";
|
|
1243
|
+
const hint = !opts.withChanges && hasLocalChanges() && /^\.github\/workflows\//.test(opts.workflow) ? " If it only exists in your working tree, add --with-changes." : "";
|
|
1222
1244
|
throw new ActionsCliError(
|
|
1223
1245
|
"workflow_not_found",
|
|
1224
|
-
`No workflow "${opts.workflow}" in ${repo}. Available: ${choices}`
|
|
1246
|
+
`No workflow "${opts.workflow}" in ${repo}. Available: ${choices}${hint}`
|
|
1225
1247
|
);
|
|
1226
1248
|
}
|
|
1227
1249
|
let patch;
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
"text/x-patch; charset=utf-8"
|
|
1238
|
-
);
|
|
1239
|
-
patch = { patchId: uploaded.patchId, files: uploaded.files, bytes: uploaded.bytes };
|
|
1240
|
-
} else if (!opts.json) {
|
|
1241
|
-
console.error(pc2.dim(`no local changes beyond origin/${ref.replace(/^refs\/heads\//, "")}; running the ref as is`));
|
|
1242
|
-
}
|
|
1243
|
-
} else if (!opts.json && hasLocalChanges()) {
|
|
1244
|
-
console.error(pc2.dim("You have uncommitted changes. Add --with-changes to run them."));
|
|
1250
|
+
if (local) {
|
|
1251
|
+
const uploaded = await c.postText(
|
|
1252
|
+
"/api/v1/actions/patches",
|
|
1253
|
+
local.patch,
|
|
1254
|
+
"text/x-patch; charset=utf-8"
|
|
1255
|
+
);
|
|
1256
|
+
patch = { patchId: uploaded.patchId, files: uploaded.files, bytes: uploaded.bytes };
|
|
1257
|
+
} else if (opts.withChanges && !opts.json && ref) {
|
|
1258
|
+
console.error(pc2.dim(`no local changes beyond origin/${ref.replace(/^refs\/heads\//, "")}; running the ref as is`));
|
|
1245
1259
|
}
|
|
1246
1260
|
const body = dispatchBody(workflow, { ...opts, ref, patchId: patch?.patchId });
|
|
1247
1261
|
const result = await c.post(
|
|
@@ -2026,8 +2040,78 @@ function formatSettlementRow(s) {
|
|
|
2026
2040
|
paid
|
|
2027
2041
|
].join(" ");
|
|
2028
2042
|
}
|
|
2043
|
+
var MICRO_USD = 1e6;
|
|
2044
|
+
function bidBody(opts) {
|
|
2045
|
+
const rate = parseRate(opts.price, opts.per);
|
|
2046
|
+
const expiresInHours = parseExpiresIn(opts.expiresIn);
|
|
2047
|
+
return {
|
|
2048
|
+
size: opts.size,
|
|
2049
|
+
...opts.region !== void 0 && { region: opts.region },
|
|
2050
|
+
maxUsd: rate.usd,
|
|
2051
|
+
per: rate.per,
|
|
2052
|
+
...expiresInHours !== void 0 && { expiresInHours },
|
|
2053
|
+
useCase: parseMarketLane(opts.useCase)
|
|
2054
|
+
};
|
|
2055
|
+
}
|
|
2056
|
+
function parseTopupAmount(value) {
|
|
2057
|
+
const usd = Number(value.replace(/^\$/, ""));
|
|
2058
|
+
if (!USD_RE.test(value.replace(/^\$/, "")) || !Number.isFinite(usd) || usd <= 0) {
|
|
2059
|
+
throw new ActionsCliError(
|
|
2060
|
+
"invalid_argument",
|
|
2061
|
+
`Invalid amount "${value}". Expected a positive dollar amount (e.g. 50).`
|
|
2062
|
+
);
|
|
2063
|
+
}
|
|
2064
|
+
return usd;
|
|
2065
|
+
}
|
|
2066
|
+
function formatCap(cap) {
|
|
2067
|
+
return cap === null ? "No market cap \u2014 market-placed jobs need their own bid to fill." : `market cap ${formatRate(cap.usd, cap.per)}`;
|
|
2068
|
+
}
|
|
2069
|
+
function formatBidRow(bid) {
|
|
2070
|
+
const status = bid.status === "open" ? pc3.green("open") : bid.status === "filled" ? pc3.cyan("filled") : pc3.gray("cancelled");
|
|
2071
|
+
return [
|
|
2072
|
+
bid.id,
|
|
2073
|
+
status,
|
|
2074
|
+
pc3.dim(bid.useCase === "sandbox" ? "sandbox" : "actions"),
|
|
2075
|
+
safeTerm(bid.size),
|
|
2076
|
+
safeTerm(bid.region ?? "any region"),
|
|
2077
|
+
`\u2264 ${formatRate(bid.maxUsd, bid.per)}`,
|
|
2078
|
+
pc3.dim(bid.expiresAt ? `expires ${bid.expiresAt}` : "standing")
|
|
2079
|
+
].join(" ");
|
|
2080
|
+
}
|
|
2081
|
+
function formatCredits(b) {
|
|
2082
|
+
const lines = [`available ${formatMoney(b.balanceMicroUsd / MICRO_USD)}`];
|
|
2083
|
+
if (b.holds.length > 0) {
|
|
2084
|
+
lines.push(
|
|
2085
|
+
pc3.dim(`reserved ${formatMoney(b.heldMicroUsd / MICRO_USD)} across ${b.holds.length} running job${b.holds.length === 1 ? "" : "s"}`)
|
|
2086
|
+
);
|
|
2087
|
+
}
|
|
2088
|
+
return lines.join("\n");
|
|
2089
|
+
}
|
|
2090
|
+
function formatLedgerRow(e) {
|
|
2091
|
+
const usd = e.microUsd / MICRO_USD;
|
|
2092
|
+
const amount = usd < 0 ? `-${formatMoney(-usd)}` : `+${formatMoney(usd)}`;
|
|
2093
|
+
return [
|
|
2094
|
+
pc3.dim(e.createdAt.slice(0, 19).replace("T", " ")),
|
|
2095
|
+
(usd < 0 ? pc3.red : pc3.green)(amount.padStart(10)),
|
|
2096
|
+
safeTerm(e.label),
|
|
2097
|
+
pc3.dim(e.jobId ? `job ${e.jobId}` : "")
|
|
2098
|
+
].join(" ").trimEnd();
|
|
2099
|
+
}
|
|
2100
|
+
function formatPurchaseRow(p2) {
|
|
2101
|
+
const cost = p2.costMicroUsd !== null ? formatMoney(p2.costMicroUsd / MICRO_USD) : p2.status === "live" ? pc3.yellow("running") : "-";
|
|
2102
|
+
return [
|
|
2103
|
+
pc3.dim(p2.startedAt.slice(0, 19).replace("T", " ")),
|
|
2104
|
+
cost.padStart(10),
|
|
2105
|
+
pc3.cyan(safeTerm(p2.sellerName)),
|
|
2106
|
+
pc3.dim(`${safeTerm(p2.provider)}/${safeTerm(p2.region ?? "any")}`),
|
|
2107
|
+
formatRate(p2.usd, p2.per),
|
|
2108
|
+
p2.secondsBilled !== null ? pc3.dim(`${p2.secondsBilled}s`) : "",
|
|
2109
|
+
p2.status === "replaced" ? pc3.yellow("replaced") : "",
|
|
2110
|
+
pc3.dim(p2.runId ? `run ${p2.runId}` : p2.sandboxId ? `sandbox ${p2.sandboxId}` : "")
|
|
2111
|
+
].filter((part) => part !== "").join(" ");
|
|
2112
|
+
}
|
|
2029
2113
|
function registerMarketCommands(program2) {
|
|
2030
|
-
const market = program2.command("market").description("
|
|
2114
|
+
const market = program2.command("market").description("Buy and sell compute capacity on the compute market").configureOutput({ outputError: usageErrorOutput });
|
|
2031
2115
|
const common = (cmd) => cmd.option("--api-key <key>", "API key (default: $COMPUTE_API_KEY)").option("--base-url <url>", "API base URL (default: https://platform.computesdk.com)").option("--org <slug>", "organization slug for this command (or $COMPUTE_ORG)").option("--allow-untrusted-host", "send an explicit --api-key/env key to a non-computesdk, non-localhost --base-url (stored login credentials are never sent)").option("--json", "print machine-readable JSON");
|
|
2032
2116
|
common(
|
|
2033
2117
|
market.command("listings").alias("list").description("Your listings \u2014 live, paused, expired, and withdrawn")
|
|
@@ -2200,6 +2284,154 @@ function registerMarketCommands(program2) {
|
|
|
2200
2284
|
fail(e, opts);
|
|
2201
2285
|
}
|
|
2202
2286
|
});
|
|
2287
|
+
const cap = market.command("cap").description("The org market cap: the most a market-placed job pays without its own bid");
|
|
2288
|
+
common(cap.command("show", { isDefault: true }).description("Show the current cap")).action(
|
|
2289
|
+
async (opts) => {
|
|
2290
|
+
try {
|
|
2291
|
+
const { marketCap } = await (await client(opts)).get(
|
|
2292
|
+
"/api/v1/market/bids"
|
|
2293
|
+
);
|
|
2294
|
+
output(opts, marketCap, (c) => console.log(formatCap(c)));
|
|
2295
|
+
} catch (e) {
|
|
2296
|
+
fail(e, opts);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
);
|
|
2300
|
+
common(
|
|
2301
|
+
cap.command("set").description("Set the cap").requiredOption("--price <usd/unit>", "max price per unit of time (e.g. 0.40/hour)").option("--per <unit>", "unit for a bare --price usd (second, minute, or hour)")
|
|
2302
|
+
).action(async (opts) => {
|
|
2303
|
+
try {
|
|
2304
|
+
const rate = parseRate(opts.price, opts.per);
|
|
2305
|
+
const { marketCap } = await (await client(opts)).post(
|
|
2306
|
+
"/api/v1/market/bids",
|
|
2307
|
+
{ marketCap: rate }
|
|
2308
|
+
);
|
|
2309
|
+
output(opts, marketCap, (c) => console.log(formatCap(c)));
|
|
2310
|
+
} catch (e) {
|
|
2311
|
+
fail(e, opts);
|
|
2312
|
+
}
|
|
2313
|
+
});
|
|
2314
|
+
common(
|
|
2315
|
+
cap.command("clear").description("Remove the cap (refused while your placement order still names market)")
|
|
2316
|
+
).action(async (opts) => {
|
|
2317
|
+
try {
|
|
2318
|
+
const { marketCap } = await (await client(opts)).post(
|
|
2319
|
+
"/api/v1/market/bids",
|
|
2320
|
+
{ marketCap: null }
|
|
2321
|
+
);
|
|
2322
|
+
output(opts, marketCap, (c) => console.log(formatCap(c)));
|
|
2323
|
+
} catch (e) {
|
|
2324
|
+
fail(e, opts);
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
common(
|
|
2328
|
+
market.command("bids").description("Your org's standing bids \u2014 open, filled, and cancelled")
|
|
2329
|
+
).action(async (opts) => {
|
|
2330
|
+
try {
|
|
2331
|
+
const { bids } = await (await client(opts)).get(
|
|
2332
|
+
"/api/v1/market/bids"
|
|
2333
|
+
);
|
|
2334
|
+
output(opts, bids, (rows) => {
|
|
2335
|
+
if (rows.length === 0) {
|
|
2336
|
+
console.log("No bids yet \u2014 post one with `compute market bid`.");
|
|
2337
|
+
return;
|
|
2338
|
+
}
|
|
2339
|
+
for (const bid of rows) console.log(formatBidRow(bid));
|
|
2340
|
+
});
|
|
2341
|
+
} catch (e) {
|
|
2342
|
+
fail(e, opts);
|
|
2343
|
+
}
|
|
2344
|
+
});
|
|
2345
|
+
common(
|
|
2346
|
+
market.command("bid").description("Post a standing bid: the most you will pay for a size tier").requiredOption("--size <tier>", "size tier to buy (e.g. xlarge)").requiredOption("--price <usd/unit>", "max price per unit of time (e.g. 0.40/hour)").option("--per <unit>", "unit for a bare --price usd (second, minute, or hour)").option("--region <region>", "only fill in this region (default: any)").option("--use-case <lane>", "lane to buy on: actions or sandbox (default: actions)").option("--expires-in <hours>", "cancel after this many hours (default: standing)")
|
|
2347
|
+
).action(async (opts) => {
|
|
2348
|
+
try {
|
|
2349
|
+
const result = await (await client(opts)).post(
|
|
2350
|
+
"/api/v1/market/bids",
|
|
2351
|
+
bidBody(opts)
|
|
2352
|
+
);
|
|
2353
|
+
output(opts, result, (r) => {
|
|
2354
|
+
console.log(`bid placed ${pc3.cyan(r.bid.id)}`);
|
|
2355
|
+
console.log(formatBidRow(r.bid));
|
|
2356
|
+
});
|
|
2357
|
+
} catch (e) {
|
|
2358
|
+
fail(e, opts);
|
|
2359
|
+
}
|
|
2360
|
+
});
|
|
2361
|
+
common(
|
|
2362
|
+
market.command("cancel-bid").description("Cancel an open standing bid").argument("<bid-id>", "bid ID")
|
|
2363
|
+
).action(async (bidId, opts) => {
|
|
2364
|
+
try {
|
|
2365
|
+
const result = await (await client(opts)).del(
|
|
2366
|
+
`/api/v1/market/bids?id=${encodeURIComponent(bidId)}`
|
|
2367
|
+
);
|
|
2368
|
+
output(opts, result, (r) => console.log(`cancelled ${pc3.cyan(r.bid.id)}`));
|
|
2369
|
+
} catch (e) {
|
|
2370
|
+
fail(e, opts);
|
|
2371
|
+
}
|
|
2372
|
+
});
|
|
2373
|
+
common(
|
|
2374
|
+
market.command("purchases").description("What the market ran for you: seller, price, duration, and cost, newest first").option("--limit <n>", "purchases per page (max 200, default 50)").option("--cursor <cursor>", "continue from a previous page")
|
|
2375
|
+
).action(async (opts) => {
|
|
2376
|
+
try {
|
|
2377
|
+
const page = await (await client(opts)).get("/api/v1/market/purchases", { limit: opts.limit, cursor: opts.cursor });
|
|
2378
|
+
output(opts, page, (p2) => {
|
|
2379
|
+
if (p2.purchases.length === 0) {
|
|
2380
|
+
console.log("No market purchases yet.");
|
|
2381
|
+
return;
|
|
2382
|
+
}
|
|
2383
|
+
for (const row of p2.purchases) console.log(formatPurchaseRow(row));
|
|
2384
|
+
if (p2.nextCursor) console.log(pc3.dim(`more: --cursor ${p2.nextCursor}`));
|
|
2385
|
+
});
|
|
2386
|
+
} catch (e) {
|
|
2387
|
+
fail(e, opts);
|
|
2388
|
+
}
|
|
2389
|
+
});
|
|
2390
|
+
common(
|
|
2391
|
+
market.command("credits").description("Prepaid market credits: available balance and reserved holds")
|
|
2392
|
+
).action(async (opts) => {
|
|
2393
|
+
try {
|
|
2394
|
+
const balance = await (await client(opts)).get(
|
|
2395
|
+
"/api/v1/billing/balance"
|
|
2396
|
+
);
|
|
2397
|
+
output(opts, balance, (b) => console.log(formatCredits(b)));
|
|
2398
|
+
} catch (e) {
|
|
2399
|
+
fail(e, opts);
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
common(
|
|
2403
|
+
market.command("ledger").description("Credit history, newest first: top-ups, charges, holds, refunds").option("--limit <n>", "entries per page (max 200, default 50)").option("--cursor <cursor>", "continue from a previous page")
|
|
2404
|
+
).action(async (opts) => {
|
|
2405
|
+
try {
|
|
2406
|
+
const page = await (await client(opts)).get("/api/v1/billing/ledger", { limit: opts.limit, cursor: opts.cursor });
|
|
2407
|
+
output(opts, page, (p2) => {
|
|
2408
|
+
if (p2.entries.length === 0) {
|
|
2409
|
+
console.log("No credit activity yet \u2014 add credits with `compute market topup`.");
|
|
2410
|
+
return;
|
|
2411
|
+
}
|
|
2412
|
+
for (const entry of p2.entries) console.log(formatLedgerRow(entry));
|
|
2413
|
+
if (p2.nextCursor) console.log(pc3.dim(`more: --cursor ${p2.nextCursor}`));
|
|
2414
|
+
});
|
|
2415
|
+
} catch (e) {
|
|
2416
|
+
fail(e, opts);
|
|
2417
|
+
}
|
|
2418
|
+
});
|
|
2419
|
+
common(
|
|
2420
|
+
market.command("topup").description("Buy prepaid credits \u2014 prints a Stripe checkout link to pay in your browser").argument("<usd>", "amount in USD (e.g. 50)")
|
|
2421
|
+
).action(async (amount, opts) => {
|
|
2422
|
+
try {
|
|
2423
|
+
const result = await (await client(opts)).post(
|
|
2424
|
+
"/api/v1/billing/topups",
|
|
2425
|
+
{ amountUsd: parseTopupAmount(amount) }
|
|
2426
|
+
);
|
|
2427
|
+
output(opts, result, (r) => {
|
|
2428
|
+
console.log(`Pay ${formatMoney(r.amountMicroUsd / MICRO_USD)} at:`);
|
|
2429
|
+
console.log(r.url);
|
|
2430
|
+
});
|
|
2431
|
+
} catch (e) {
|
|
2432
|
+
fail(e, opts);
|
|
2433
|
+
}
|
|
2434
|
+
});
|
|
2203
2435
|
const credential = market.command("credential").description("Connect the credential your listings fill under");
|
|
2204
2436
|
common(
|
|
2205
2437
|
credential.command("connect").description(
|