@computesdk/cli 2.5.4 → 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 +333 -12
- 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
|
@@ -67,6 +67,7 @@ function getProviderStatus() {
|
|
|
67
67
|
// src/actions.ts
|
|
68
68
|
import pc2 from "picocolors";
|
|
69
69
|
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
70
|
+
import { spawnSync } from "child_process";
|
|
70
71
|
|
|
71
72
|
// src/settings.ts
|
|
72
73
|
import pc from "picocolors";
|
|
@@ -183,6 +184,15 @@ var ActionsClient = class {
|
|
|
183
184
|
});
|
|
184
185
|
return this.parse(res);
|
|
185
186
|
}
|
|
187
|
+
/** POST a raw text body (e.g. a unified diff to `/api/v1/actions/patches`). */
|
|
188
|
+
async postText(path, body, contentType) {
|
|
189
|
+
const res = await this.fetchImpl(`${this.auth.baseUrl}${path}`, {
|
|
190
|
+
method: "POST",
|
|
191
|
+
headers: { ...this.headers(), "content-type": contentType },
|
|
192
|
+
body
|
|
193
|
+
});
|
|
194
|
+
return this.parse(res);
|
|
195
|
+
}
|
|
186
196
|
async put(path, body = {}) {
|
|
187
197
|
const res = await this.fetchImpl(`${this.auth.baseUrl}${path}`, {
|
|
188
198
|
method: "PUT",
|
|
@@ -1018,27 +1028,39 @@ function printDiscovery(d) {
|
|
|
1018
1028
|
}
|
|
1019
1029
|
console.log(pc2.dim(`discovery: ${d.workflowsFound ? "workflows found" : "no workflows yet"}${d.seeded ? ", cursors seeded" : ""}`));
|
|
1020
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
|
+
}
|
|
1021
1042
|
function dispatchBody(workflow, opts) {
|
|
1022
|
-
|
|
1043
|
+
const patched = isPatchedWorkflowTarget(workflow);
|
|
1044
|
+
if (!patched && !workflow.dispatchable && !opts.manual) {
|
|
1023
1045
|
throw new ActionsCliError(
|
|
1024
1046
|
"invalid_argument",
|
|
1025
1047
|
`Workflow "${workflow.path}" does not declare workflow_dispatch. Pass --manual to run it anyway (no inputs).`
|
|
1026
1048
|
);
|
|
1027
1049
|
}
|
|
1028
|
-
if (!workflow.dispatchable && opts.inputs !== void 0 && opts.inputs.length > 0) {
|
|
1050
|
+
if (!patched && !workflow.dispatchable && opts.inputs !== void 0 && opts.inputs.length > 0) {
|
|
1029
1051
|
throw new ActionsCliError(
|
|
1030
1052
|
"invalid_argument",
|
|
1031
1053
|
`Workflow "${workflow.path}" has no workflow_dispatch inputs; --manual runs of it take no --inputs.`
|
|
1032
1054
|
);
|
|
1033
1055
|
}
|
|
1034
|
-
const ref = opts.ref ?? workflow.refs[0];
|
|
1056
|
+
const ref = opts.ref ?? (patched ? void 0 : workflow.refs[0]);
|
|
1035
1057
|
if (!ref) throw new ActionsCliError("invalid_argument", "No --ref given and the workflow has no watched refs.");
|
|
1036
1058
|
if (opts.providerRegion !== void 0 && opts.provider === void 0) {
|
|
1037
1059
|
throw new ActionsCliError("invalid_argument", "--provider-region requires --provider.");
|
|
1038
1060
|
}
|
|
1039
1061
|
const maxPrice = maxPriceFields(opts.maxBid, opts.maxBidPer);
|
|
1040
1062
|
return {
|
|
1041
|
-
workflowId: workflow.id,
|
|
1063
|
+
...patched ? { repoFullName: workflow.repoFullName, workflowPath: workflow.workflowPath } : { workflowId: workflow.id },
|
|
1042
1064
|
ref,
|
|
1043
1065
|
inputs: parseInputs(opts.inputs),
|
|
1044
1066
|
...opts.manual && { manual: true },
|
|
@@ -1046,9 +1068,69 @@ function dispatchBody(workflow, opts) {
|
|
|
1046
1068
|
provider: opts.provider,
|
|
1047
1069
|
...opts.providerRegion !== void 0 && { providerRegion: opts.providerRegion }
|
|
1048
1070
|
},
|
|
1049
|
-
...maxPrice !== void 0 && maxPrice
|
|
1071
|
+
...maxPrice !== void 0 && maxPrice,
|
|
1072
|
+
...opts.patchId !== void 0 && { patchId: opts.patchId }
|
|
1050
1073
|
};
|
|
1051
1074
|
}
|
|
1075
|
+
var runGit = (args) => {
|
|
1076
|
+
const r = spawnSync("git", args, { encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
1077
|
+
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
1078
|
+
};
|
|
1079
|
+
function remoteNamesRepo(remote, repo) {
|
|
1080
|
+
const normalized = remote.trim().replace(/\.git$/, "").replace(/\/+$/, "");
|
|
1081
|
+
return normalized.toLowerCase().endsWith(`/${repo.toLowerCase()}`) || normalized.toLowerCase().endsWith(`:${repo.toLowerCase()}`);
|
|
1082
|
+
}
|
|
1083
|
+
function currentBranch(git = runGit) {
|
|
1084
|
+
const r = git(["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
1085
|
+
if (r.status !== 0) return null;
|
|
1086
|
+
const name = r.stdout.trim();
|
|
1087
|
+
return name === "" || name === "HEAD" ? null : name;
|
|
1088
|
+
}
|
|
1089
|
+
function hasLocalChanges(git = runGit) {
|
|
1090
|
+
const r = git(["status", "--porcelain", "--untracked-files=all"]);
|
|
1091
|
+
return r.status === 0 && r.stdout.trim() !== "";
|
|
1092
|
+
}
|
|
1093
|
+
function localChangesPatch(ref, git = runGit, repo) {
|
|
1094
|
+
const branch = ref.replace(/^refs\/heads\//, "");
|
|
1095
|
+
const base = `origin/${branch}`;
|
|
1096
|
+
if (repo !== void 0) {
|
|
1097
|
+
const remote = git(["remote", "get-url", "origin"]).stdout.trim();
|
|
1098
|
+
if (!remoteNamesRepo(remote, repo)) {
|
|
1099
|
+
throw new ActionsCliError(
|
|
1100
|
+
"invalid_argument",
|
|
1101
|
+
`--with-changes sends this checkout's changes, but its origin (${remote || "none"}) is not ${repo}. Run it from a checkout of ${repo}.`
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
const fetched = git(["fetch", "--quiet", "origin", branch]);
|
|
1106
|
+
if (fetched.status !== 0) {
|
|
1107
|
+
throw new ActionsCliError("invalid_argument", `git fetch origin ${branch} failed: ${fetched.stderr.trim() || "is the branch pushed?"}`);
|
|
1108
|
+
}
|
|
1109
|
+
if (git(["rev-parse", "--verify", "--quiet", `${base}^{commit}`]).status !== 0) {
|
|
1110
|
+
throw new ActionsCliError(
|
|
1111
|
+
"invalid_argument",
|
|
1112
|
+
`--with-changes diffs against ${base}, which does not exist locally. Push the branch (or run \`git fetch origin ${branch}\`), or pass --ref <branch that exists on origin>.`
|
|
1113
|
+
);
|
|
1114
|
+
}
|
|
1115
|
+
const tracked = git(["diff", "--no-color", "--no-ext-diff", "--src-prefix=a/", "--dst-prefix=b/", base, "--"]);
|
|
1116
|
+
if (tracked.status !== 0) {
|
|
1117
|
+
throw new ActionsCliError("invalid_argument", `git diff against ${base} failed: ${tracked.stderr.trim()}`);
|
|
1118
|
+
}
|
|
1119
|
+
const parts = [tracked.stdout];
|
|
1120
|
+
const topLevel = git(["rev-parse", "--show-toplevel"]).stdout.replace(/\r?\n$/, "");
|
|
1121
|
+
const untracked = git(["-C", topLevel, "ls-files", "--others", "--exclude-standard", "-z"]);
|
|
1122
|
+
for (const file of untracked.stdout.split("\0").filter((f) => f !== "")) {
|
|
1123
|
+
const d = git(["-C", topLevel, "diff", "--no-color", "--no-ext-diff", "--no-index", "--src-prefix=a/", "--dst-prefix=b/", "--", "/dev/null", file]);
|
|
1124
|
+
if (d.stdout !== "") parts.push(d.stdout);
|
|
1125
|
+
}
|
|
1126
|
+
const patch = parts.filter((p2) => p2 !== "").join("");
|
|
1127
|
+
if (patch.trim() === "") return null;
|
|
1128
|
+
if (patch.includes("\0") || /^Binary files .* differ$/m.test(patch)) {
|
|
1129
|
+
throw new ActionsCliError("invalid_argument", "Local changes include a binary file; --with-changes sends text diffs only.");
|
|
1130
|
+
}
|
|
1131
|
+
const files = patch.match(/^\+\+\+ /gm)?.length ?? 0;
|
|
1132
|
+
return { patch, files, base };
|
|
1133
|
+
}
|
|
1052
1134
|
function maxPriceFields(maxBid, maxBidPer) {
|
|
1053
1135
|
if (maxBidPer !== void 0 && maxBid === void 0) {
|
|
1054
1136
|
throw new ActionsCliError("invalid_argument", "--max-bid-per requires --max-bid.");
|
|
@@ -1138,32 +1220,53 @@ function registerActionsCommands(program2) {
|
|
|
1138
1220
|
const actions = program2.command("actions").alias("ci").description("Drive the benchmarks-platform Actions API").configureOutput({ outputError: usageErrorOutput });
|
|
1139
1221
|
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");
|
|
1140
1222
|
common(
|
|
1141
|
-
actions.command("dispatch").description("Dispatch a workflow_dispatch run (or any workflow with --manual)").argument("<repo>", "repository in owner/repo format").requiredOption("--workflow <path|name>", "workflow path or name").option("--ref <ref>", "git ref to run (default: the workflow's first watched ref)").option("--inputs <pairs...>", "workflow inputs as key=value (workflow_dispatch inputs only)").option("--manual", "run a workflow even if it does not declare workflow_dispatch (such runs take no --inputs)").option("--provider <id>", "place the run on one provider (e.g. namespace, vercel:sfo1) instead of the org provider order").option("--provider-region <region>", "region for --provider (same as --provider <id>:<region>)").option("--max-bid <usd>", "max price per vCPU for a market fill (e.g. 0.12); unfilled jobs fall through to the next provider").option("--max-bid-per <unit>", "time unit --max-bid is priced in: second, minute, or hour (default: second)")
|
|
1223
|
+
actions.command("dispatch").description("Dispatch a workflow_dispatch run (or any workflow with --manual)").argument("<repo>", "repository in owner/repo format").requiredOption("--workflow <path|name>", "workflow path or name").option("--ref <ref>", "git ref to run (default: the workflow's first watched ref)").option("--inputs <pairs...>", "workflow inputs as key=value (workflow_dispatch inputs only)").option("--manual", "run a workflow even if it does not declare workflow_dispatch (such runs take no --inputs)").option("--provider <id>", "place the run on one provider (e.g. namespace, vercel:sfo1) instead of the org provider order").option("--provider-region <region>", "region for --provider (same as --provider <id>:<region>)").option("--max-bid <usd>", "max price per vCPU for a market fill (e.g. 0.12); unfilled jobs fall through to the next provider").option("--max-bid-per <unit>", "time unit --max-bid is priced in: second, minute, or hour (default: second)").option("--with-changes", "run your local changes: everything the working tree has beyond origin/<ref> is sent as a diff and applied after checkout (default --ref: the current branch)")
|
|
1142
1224
|
).action(async (repo, opts) => {
|
|
1143
1225
|
try {
|
|
1144
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
|
+
}
|
|
1145
1236
|
const { workflows } = await c.get(
|
|
1146
1237
|
"/api/v1/actions/workflows",
|
|
1147
1238
|
{ repo }
|
|
1148
1239
|
);
|
|
1149
|
-
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);
|
|
1150
1241
|
if (!workflow) {
|
|
1151
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." : "";
|
|
1152
1244
|
throw new ActionsCliError(
|
|
1153
1245
|
"workflow_not_found",
|
|
1154
|
-
`No workflow "${opts.workflow}" in ${repo}. Available: ${choices}`
|
|
1246
|
+
`No workflow "${opts.workflow}" in ${repo}. Available: ${choices}${hint}`
|
|
1155
1247
|
);
|
|
1156
1248
|
}
|
|
1157
|
-
|
|
1249
|
+
let patch;
|
|
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`));
|
|
1259
|
+
}
|
|
1260
|
+
const body = dispatchBody(workflow, { ...opts, ref, patchId: patch?.patchId });
|
|
1158
1261
|
const result = await c.post(
|
|
1159
1262
|
"/api/v1/actions/dispatch",
|
|
1160
1263
|
body
|
|
1161
1264
|
);
|
|
1162
1265
|
const org2 = await c.org();
|
|
1163
1266
|
const url = `${c.baseUrl}/${org2.slug}/actions/runs/${result.runId}`;
|
|
1164
|
-
output(opts, { ...result, url }, (r) => {
|
|
1267
|
+
output(opts, { ...result, url, ...patch && { patch } }, (r) => {
|
|
1165
1268
|
console.log(`${r.created ? "dispatched" : "already running"} ${pc2.cyan(r.runId)}`);
|
|
1166
|
-
console.log(`sha: ${r.headSha}`);
|
|
1269
|
+
console.log(`sha: ${r.headSha}${r.patch ? ` + ${r.patch.files} changed file${r.patch.files === 1 ? "" : "s"} (uncommitted)` : ""}`);
|
|
1167
1270
|
console.log(`url: ${r.url}`);
|
|
1168
1271
|
});
|
|
1169
1272
|
} catch (e) {
|
|
@@ -1937,8 +2040,78 @@ function formatSettlementRow(s) {
|
|
|
1937
2040
|
paid
|
|
1938
2041
|
].join(" ");
|
|
1939
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
|
+
}
|
|
1940
2113
|
function registerMarketCommands(program2) {
|
|
1941
|
-
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 });
|
|
1942
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");
|
|
1943
2116
|
common(
|
|
1944
2117
|
market.command("listings").alias("list").description("Your listings \u2014 live, paused, expired, and withdrawn")
|
|
@@ -2111,6 +2284,154 @@ function registerMarketCommands(program2) {
|
|
|
2111
2284
|
fail(e, opts);
|
|
2112
2285
|
}
|
|
2113
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
|
+
});
|
|
2114
2435
|
const credential = market.command("credential").description("Connect the credential your listings fill under");
|
|
2115
2436
|
common(
|
|
2116
2437
|
credential.command("connect").description(
|