@computesdk/cli 2.6.6 → 2.6.8
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/cli-manifest.json +55 -1
- package/dist/index.js +140 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/cli-manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"bin": "compute",
|
|
4
4
|
"package": "@computesdk/cli",
|
|
5
|
-
"version": "2.6.
|
|
5
|
+
"version": "2.6.8",
|
|
6
6
|
"source": {
|
|
7
7
|
"repo": "computesdk/computesdk",
|
|
8
8
|
"released": false
|
|
@@ -1690,6 +1690,60 @@
|
|
|
1690
1690
|
],
|
|
1691
1691
|
"summary": "Drop a provider's custom rate; its costs report at the platform rate again (owner/admin)"
|
|
1692
1692
|
},
|
|
1693
|
+
{
|
|
1694
|
+
"path": [
|
|
1695
|
+
"credits"
|
|
1696
|
+
],
|
|
1697
|
+
"aliases": [],
|
|
1698
|
+
"args": [],
|
|
1699
|
+
"flags": [
|
|
1700
|
+
"--api-key",
|
|
1701
|
+
"--base-url",
|
|
1702
|
+
"--org",
|
|
1703
|
+
"--allow-untrusted-host",
|
|
1704
|
+
"--json",
|
|
1705
|
+
"--help"
|
|
1706
|
+
],
|
|
1707
|
+
"summary": "Your prepaid credit — managed accounts bill from it: balance, ledger, top-ups"
|
|
1708
|
+
},
|
|
1709
|
+
{
|
|
1710
|
+
"path": [
|
|
1711
|
+
"credits",
|
|
1712
|
+
"ledger"
|
|
1713
|
+
],
|
|
1714
|
+
"aliases": [],
|
|
1715
|
+
"args": [],
|
|
1716
|
+
"flags": [
|
|
1717
|
+
"--limit",
|
|
1718
|
+
"--cursor",
|
|
1719
|
+
"--api-key",
|
|
1720
|
+
"--base-url",
|
|
1721
|
+
"--org",
|
|
1722
|
+
"--allow-untrusted-host",
|
|
1723
|
+
"--json",
|
|
1724
|
+
"--help"
|
|
1725
|
+
],
|
|
1726
|
+
"summary": "Credit history, newest first: top-ups, grants, holds, charges, refunds"
|
|
1727
|
+
},
|
|
1728
|
+
{
|
|
1729
|
+
"path": [
|
|
1730
|
+
"credits",
|
|
1731
|
+
"topup"
|
|
1732
|
+
],
|
|
1733
|
+
"aliases": [],
|
|
1734
|
+
"args": [
|
|
1735
|
+
"<usd>"
|
|
1736
|
+
],
|
|
1737
|
+
"flags": [
|
|
1738
|
+
"--api-key",
|
|
1739
|
+
"--base-url",
|
|
1740
|
+
"--org",
|
|
1741
|
+
"--allow-untrusted-host",
|
|
1742
|
+
"--json",
|
|
1743
|
+
"--help"
|
|
1744
|
+
],
|
|
1745
|
+
"summary": "Add credit — prints a Stripe checkout link to pay in your browser (owner/admin)"
|
|
1746
|
+
},
|
|
1693
1747
|
{
|
|
1694
1748
|
"path": [
|
|
1695
1749
|
"instances"
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import "dotenv/config";
|
|
5
5
|
import { Command as Command4 } from "commander";
|
|
6
6
|
import * as p from "@clack/prompts";
|
|
7
|
-
import
|
|
7
|
+
import pc14 from "picocolors";
|
|
8
8
|
import { readFileSync as readFileSync6 } from "fs";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import { dirname as dirname3, join as join5 } from "path";
|
|
@@ -2838,7 +2838,7 @@ function formatCredits(b) {
|
|
|
2838
2838
|
const lines = [`available ${formatMoney(b.balanceMicroUsd / MICRO_USD)}`];
|
|
2839
2839
|
if (b.holds.length > 0) {
|
|
2840
2840
|
lines.push(
|
|
2841
|
-
pc9.dim(`reserved ${formatMoney(b.heldMicroUsd / MICRO_USD)} across ${b.holds.length} running job${b.holds.length === 1 ? "" : "s"}`)
|
|
2841
|
+
pc9.dim(`reserved ${formatMoney(b.heldMicroUsd / MICRO_USD)} across ${b.holds.length} running sandbox${b.holds.length === 1 ? "" : "es"} or job${b.holds.length === 1 ? "" : "s"}`)
|
|
2842
2842
|
);
|
|
2843
2843
|
}
|
|
2844
2844
|
return lines.join("\n");
|
|
@@ -3162,7 +3162,7 @@ function registerMarketCommands(program2) {
|
|
|
3162
3162
|
const page = await (await client(opts)).get("/api/v1/billing/ledger", { limit: opts.limit, cursor: opts.cursor });
|
|
3163
3163
|
output(opts, page, (p2) => {
|
|
3164
3164
|
if (p2.entries.length === 0) {
|
|
3165
|
-
console.log("No credit activity yet \u2014 add
|
|
3165
|
+
console.log("No credit activity yet \u2014 add credit with `compute credits topup <usd>`.");
|
|
3166
3166
|
return;
|
|
3167
3167
|
}
|
|
3168
3168
|
for (const entry of p2.entries) console.log(formatLedgerRow(entry));
|
|
@@ -3250,6 +3250,79 @@ ${hints}`
|
|
|
3250
3250
|
});
|
|
3251
3251
|
}
|
|
3252
3252
|
|
|
3253
|
+
// src/credits.ts
|
|
3254
|
+
import pc10 from "picocolors";
|
|
3255
|
+
var MICRO_USD2 = 1e6;
|
|
3256
|
+
function registerCreditsCommands(program2) {
|
|
3257
|
+
const common2 = (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");
|
|
3258
|
+
const credits = common2(
|
|
3259
|
+
program2.command("credits").description("Your prepaid credit \u2014 managed accounts bill from it: balance, ledger, top-ups").configureOutput({ outputError: usageErrorOutput })
|
|
3260
|
+
).action(async (opts) => {
|
|
3261
|
+
try {
|
|
3262
|
+
const balance = await (await client(opts)).get("/api/v1/billing/balance");
|
|
3263
|
+
output(opts, balance, (b) => console.log(formatCredits(b)));
|
|
3264
|
+
} catch (e) {
|
|
3265
|
+
fail(e, opts);
|
|
3266
|
+
}
|
|
3267
|
+
});
|
|
3268
|
+
common2(
|
|
3269
|
+
credits.command("ledger").description("Credit history, newest first: top-ups, grants, holds, charges, refunds").option("--limit <n>", "entries per page (max 200, default 50)").option("--cursor <cursor>", "continue from a previous page")
|
|
3270
|
+
).action(async (opts) => {
|
|
3271
|
+
try {
|
|
3272
|
+
const page = await (await client(opts)).get(
|
|
3273
|
+
"/api/v1/billing/ledger",
|
|
3274
|
+
{ limit: opts.limit, cursor: opts.cursor }
|
|
3275
|
+
);
|
|
3276
|
+
output(opts, page, (p2) => {
|
|
3277
|
+
if (p2.entries.length === 0) {
|
|
3278
|
+
console.log("No credit activity yet \u2014 add credit with `compute credits topup <usd>`.");
|
|
3279
|
+
return;
|
|
3280
|
+
}
|
|
3281
|
+
for (const entry of p2.entries) console.log(formatLedgerRow(entry));
|
|
3282
|
+
if (p2.nextCursor) console.log(pc10.dim(`more: --cursor ${p2.nextCursor}`));
|
|
3283
|
+
});
|
|
3284
|
+
} catch (e) {
|
|
3285
|
+
fail(e, opts);
|
|
3286
|
+
}
|
|
3287
|
+
});
|
|
3288
|
+
common2(
|
|
3289
|
+
credits.command("topup").description("Add credit \u2014 prints a Stripe checkout link to pay in your browser (owner/admin)").argument("<usd>", "amount to pay in USD (e.g. 50)")
|
|
3290
|
+
).action(async (amount, opts) => {
|
|
3291
|
+
try {
|
|
3292
|
+
const result = await (await client(opts)).post("/api/v1/billing/topups", {
|
|
3293
|
+
amountUsd: parseTopupAmount(amount)
|
|
3294
|
+
});
|
|
3295
|
+
output(opts, result, (r) => {
|
|
3296
|
+
const pay = formatMoney(r.amountMicroUsd / MICRO_USD2);
|
|
3297
|
+
if (r.creditMicroUsd !== void 0 && r.feeBps !== void 0 && r.feeBps > 0) {
|
|
3298
|
+
console.log(`Pay ${pay} for ${formatMoney(r.creditMicroUsd / MICRO_USD2)} of credit (${r.feeBps / 100}% top-up fee) at:`);
|
|
3299
|
+
} else {
|
|
3300
|
+
console.log(`Pay ${pay} at:`);
|
|
3301
|
+
}
|
|
3302
|
+
console.log(r.url ?? pc10.dim("(no checkout link returned)"));
|
|
3303
|
+
});
|
|
3304
|
+
} catch (e) {
|
|
3305
|
+
fail(e, opts);
|
|
3306
|
+
}
|
|
3307
|
+
});
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3310
|
+
// src/option-inheritance.ts
|
|
3311
|
+
var GIVEN = /* @__PURE__ */ new Set(["cli", "env"]);
|
|
3312
|
+
function inheritParentOptions(program2) {
|
|
3313
|
+
return program2.hook("preAction", (_hooked, actionCommand) => {
|
|
3314
|
+
const declared = new Set(actionCommand.options.map((option) => option.attributeName()));
|
|
3315
|
+
for (let parent = actionCommand.parent; parent; parent = parent.parent) {
|
|
3316
|
+
for (const [key, value] of Object.entries(parent.opts())) {
|
|
3317
|
+
if (!declared.has(key) || value === void 0) continue;
|
|
3318
|
+
if (!GIVEN.has(parent.getOptionValueSource(key) ?? "")) continue;
|
|
3319
|
+
if (GIVEN.has(actionCommand.getOptionValueSource(key) ?? "")) continue;
|
|
3320
|
+
actionCommand.setOptionValueWithSource(key, value, parent.getOptionValueSource(key));
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
});
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3253
3326
|
// src/sandboxes.ts
|
|
3254
3327
|
import * as fs from "fs";
|
|
3255
3328
|
import * as os from "os";
|
|
@@ -3257,7 +3330,7 @@ import * as path from "path";
|
|
|
3257
3330
|
import * as readline from "readline";
|
|
3258
3331
|
import { Readable } from "stream";
|
|
3259
3332
|
import { Option as Option3 } from "commander";
|
|
3260
|
-
import
|
|
3333
|
+
import pc11 from "picocolors";
|
|
3261
3334
|
import * as tar from "tar";
|
|
3262
3335
|
|
|
3263
3336
|
// src/current-instance.ts
|
|
@@ -3438,22 +3511,22 @@ function formatLocalTime(iso) {
|
|
|
3438
3511
|
function printSandbox(s, verbose = false) {
|
|
3439
3512
|
const p2 = s.placement;
|
|
3440
3513
|
console.log(
|
|
3441
|
-
`${
|
|
3514
|
+
`${pc11.cyan(s.id)} ${s.status} ${p2?.box?.provider ?? s.provider ?? "\u2014"} \xB7 ${placementLane(p2?.source)} ${p2?.size ?? "\u2014"} ${p2 ? shortRate(p2.rate) : "\u2014"}`
|
|
3442
3515
|
);
|
|
3443
3516
|
if (s.label) {
|
|
3444
3517
|
console.log(` label: ${s.label} created: ${formatLocalTime(s.createdAt)}`);
|
|
3445
3518
|
}
|
|
3446
|
-
if (s.destroyError) console.log(` destroyError: ${
|
|
3519
|
+
if (s.destroyError) console.log(` destroyError: ${pc11.red(s.destroyError)}`);
|
|
3447
3520
|
if (!verbose) return;
|
|
3448
3521
|
console.log(` providerSandboxId: ${s.providerSandboxId ?? "\u2014"} commands: ${s.commandCount}`);
|
|
3449
3522
|
if (s.image !== void 0) {
|
|
3450
|
-
console.log(` image: ${s.image ?? "\u2014"}${s.requestedImage !== null && s.requestedImage !== s.image ? ` ${
|
|
3523
|
+
console.log(` image: ${s.image ?? "\u2014"}${s.requestedImage !== null && s.requestedImage !== s.image ? ` ${pc11.dim(`(requested: ${s.requestedImage})`)}` : ""}`);
|
|
3451
3524
|
}
|
|
3452
3525
|
if (p2) {
|
|
3453
3526
|
const box = p2.box ? ` / ${p2.box.sizeName ?? "custom"}${p2.box.resources ? ` (${p2.box.resources.cpus ?? "?"} vCPU / ${p2.box.resources.memoryMb ?? "?"} MB)` : ""}` : "";
|
|
3454
3527
|
const provider = p2.box?.provider ?? s.provider ?? "the provider";
|
|
3455
3528
|
console.log(
|
|
3456
|
-
` placement: ${placementLane(p2.source)}${box} rate: ${formatUsdPer(p2.rate)} ${
|
|
3529
|
+
` placement: ${placementLane(p2.source)}${box} rate: ${formatUsdPer(p2.rate)} ${pc11.dim(billedBy(p2.source, provider))}`
|
|
3457
3530
|
);
|
|
3458
3531
|
}
|
|
3459
3532
|
const attach = "attach" in s ? s.attach : void 0;
|
|
@@ -3482,7 +3555,7 @@ function quoteRefusal(q) {
|
|
|
3482
3555
|
function printQuote(q, timeoutMs) {
|
|
3483
3556
|
const row = (label, value) => console.log(`${label.padEnd(10)} ${value}`);
|
|
3484
3557
|
if (!q.ok || !q.placement) {
|
|
3485
|
-
row("Lands on",
|
|
3558
|
+
row("Lands on", pc11.red(`nowhere \u2014 ${quoteRefusal(q)}`));
|
|
3486
3559
|
if (q.reason === "insufficient_credits" && q.topUpPath) row("Top up", q.topUpPath);
|
|
3487
3560
|
} else {
|
|
3488
3561
|
const p2 = q.placement;
|
|
@@ -3504,11 +3577,11 @@ function printQuote(q, timeoutMs) {
|
|
|
3504
3577
|
function printProcess(p2) {
|
|
3505
3578
|
const exit = p2.status === "exited" ? `exit=${p2.exitCode ?? "?"}${p2.signal ? ` (${p2.signal})` : ""}` : "";
|
|
3506
3579
|
const stdin = p2.stdin && p2.status === "running" ? " [stdin open]" : "";
|
|
3507
|
-
console.log(`${
|
|
3580
|
+
console.log(`${pc11.cyan(p2.jobId)} ${p2.status}${exit ? " " + exit : ""}${stdin} ${p2.command}`);
|
|
3508
3581
|
}
|
|
3509
3582
|
function printSnapshot(s) {
|
|
3510
|
-
const state = s.deletedAt !== null ? ` ${
|
|
3511
|
-
console.log(`${
|
|
3583
|
+
const state = s.deletedAt !== null ? ` ${pc11.dim(`(deleted ${s.deletedAt})`)}` : "";
|
|
3584
|
+
console.log(`${pc11.cyan(s.id)} ${s.providerSnapshotId}${state}`);
|
|
3512
3585
|
console.log(
|
|
3513
3586
|
` provider: ${s.provider}${s.region ? ` (${s.region})` : ""} label: ${s.label ?? "\u2014"} created: ${s.createdAt}${s.expiresAt ? ` expires: ${s.expiresAt}` : ""}`
|
|
3514
3587
|
);
|
|
@@ -3611,7 +3684,7 @@ function resolveSandbox(argId, opts) {
|
|
|
3611
3684
|
if (!r) throw new Error(NO_INSTANCE_HINT);
|
|
3612
3685
|
if (r.source !== "argument" && !opts.json && !opts.quiet) {
|
|
3613
3686
|
console.error(
|
|
3614
|
-
|
|
3687
|
+
pc11.dim(
|
|
3615
3688
|
`instance ${shortId(r.id)} (${r.source === "env" ? "COMPUTE_INSTANCE" : `current for ${r.dir}`})`
|
|
3616
3689
|
)
|
|
3617
3690
|
);
|
|
@@ -3622,7 +3695,7 @@ function resolveSandbox(argId, opts) {
|
|
|
3622
3695
|
clearStale: (error) => {
|
|
3623
3696
|
if (r.source === "file" && error instanceof PlatformApiError && error.status === 404 && readFileCurrent(org2) === r.id) {
|
|
3624
3697
|
clearCurrentInstance(org2);
|
|
3625
|
-
console.error(
|
|
3698
|
+
console.error(pc11.dim(`cleared stale current instance ${shortId(r.id)}`));
|
|
3626
3699
|
}
|
|
3627
3700
|
}
|
|
3628
3701
|
};
|
|
@@ -3730,7 +3803,7 @@ function registerCreate(command2, { providerShorthand = false } = {}) {
|
|
|
3730
3803
|
if (opts.use !== false) {
|
|
3731
3804
|
setCurrentInstance(res.sandbox.id, orgKey(opts));
|
|
3732
3805
|
if (!opts.json && !opts.quiet) {
|
|
3733
|
-
console.error(
|
|
3806
|
+
console.error(pc11.dim(`instance ${shortId(res.sandbox.id)} (current for ${dirKey()})`));
|
|
3734
3807
|
}
|
|
3735
3808
|
}
|
|
3736
3809
|
emitResult(opts, res.sandbox, (s) => s.id, (s) => printSandbox(s, opts.verbose));
|
|
@@ -3758,13 +3831,13 @@ async function previewPlacement(c, opts) {
|
|
|
3758
3831
|
return;
|
|
3759
3832
|
}
|
|
3760
3833
|
if (!quote.ok || !quote.placement) {
|
|
3761
|
-
console.error(
|
|
3834
|
+
console.error(pc11.dim(`\u2192 the router can't place this: ${quoteRefusal(quote)}`));
|
|
3762
3835
|
return;
|
|
3763
3836
|
}
|
|
3764
3837
|
const p2 = quote.placement;
|
|
3765
3838
|
const provider = p2.box?.provider ?? p2.provider;
|
|
3766
3839
|
console.error(
|
|
3767
|
-
|
|
3840
|
+
pc11.dim(`\u2192 placing on ${provider} \xB7 ${placementLane(p2.source)} \xB7 ${p2.size ?? p2.box?.sizeName ?? "custom size"} (${billedBy(p2.source, provider)}) \u2026`)
|
|
3768
3841
|
);
|
|
3769
3842
|
}
|
|
3770
3843
|
function shorthandProviders(operands) {
|
|
@@ -3833,7 +3906,7 @@ function registerSandboxesCommands(program2) {
|
|
|
3833
3906
|
(page) => page.sandboxes.map((s) => s.id).join("\n"),
|
|
3834
3907
|
(page) => {
|
|
3835
3908
|
page.sandboxes.forEach((s) => printSandbox(s, opts.verbose));
|
|
3836
|
-
if (page.nextCursor) console.log(
|
|
3909
|
+
if (page.nextCursor) console.log(pc11.dim(`nextCursor: ${page.nextCursor}`));
|
|
3837
3910
|
}
|
|
3838
3911
|
);
|
|
3839
3912
|
} catch (e) {
|
|
@@ -3906,7 +3979,7 @@ function registerSandboxesCommands(program2) {
|
|
|
3906
3979
|
if (readFileCurrent(org2) === resolved.id) {
|
|
3907
3980
|
clearCurrentInstance(org2);
|
|
3908
3981
|
if (!opts.json) {
|
|
3909
|
-
console.error(
|
|
3982
|
+
console.error(pc11.dim(`cleared current instance ${shortId(resolved.id)}`));
|
|
3910
3983
|
}
|
|
3911
3984
|
}
|
|
3912
3985
|
output(opts, res.sandbox, printSandbox);
|
|
@@ -4099,7 +4172,7 @@ function registerSandboxesCommands(program2) {
|
|
|
4099
4172
|
data = opts.base64 ? piped.toString("base64") : piped.toString("utf8");
|
|
4100
4173
|
}
|
|
4101
4174
|
if (data === void 0 || data === "") {
|
|
4102
|
-
console.error(
|
|
4175
|
+
console.error(pc11.red("Pass --data, --file, or pipe stdin"));
|
|
4103
4176
|
process.exit(1);
|
|
4104
4177
|
}
|
|
4105
4178
|
if (opts.base64 && opts.data !== void 0) {
|
|
@@ -4147,7 +4220,7 @@ function registerSandboxesCommands(program2) {
|
|
|
4147
4220
|
output(opts, res, (view) => {
|
|
4148
4221
|
if (view.type === "directory") {
|
|
4149
4222
|
for (const e of view.entries) {
|
|
4150
|
-
console.log(`${e.type === "directory" ?
|
|
4223
|
+
console.log(`${e.type === "directory" ? pc11.blue("d") : " "} ${e.name}${e.size !== void 0 ? ` ${pc11.dim(String(e.size))}` : ""}`);
|
|
4151
4224
|
}
|
|
4152
4225
|
} else {
|
|
4153
4226
|
console.log(`${view.path} file ${view.content.length} chars`);
|
|
@@ -4174,7 +4247,7 @@ function registerSandboxesCommands(program2) {
|
|
|
4174
4247
|
const res = await c.get(`/api/v1/sandboxes/${resolved.id}/files`, { path: p2 });
|
|
4175
4248
|
output(opts, res, (view) => {
|
|
4176
4249
|
if (view.type !== "file") {
|
|
4177
|
-
console.error(
|
|
4250
|
+
console.error(pc11.red(`${view.path} is a directory`));
|
|
4178
4251
|
process.exit(1);
|
|
4179
4252
|
}
|
|
4180
4253
|
process.stdout.write(view.content);
|
|
@@ -4211,7 +4284,7 @@ function registerSandboxesCommands(program2) {
|
|
|
4211
4284
|
});
|
|
4212
4285
|
}
|
|
4213
4286
|
if (content === void 0) {
|
|
4214
|
-
console.error(
|
|
4287
|
+
console.error(pc11.red("Pass --content, --file, or pipe stdin"));
|
|
4215
4288
|
process.exit(1);
|
|
4216
4289
|
}
|
|
4217
4290
|
const c = await client(opts);
|
|
@@ -4347,11 +4420,11 @@ async function followProcess(c, sandboxId, jobId) {
|
|
|
4347
4420
|
exitCode = typeof payload.exitCode === "number" ? payload.exitCode : 128;
|
|
4348
4421
|
return finish();
|
|
4349
4422
|
} else if (event === "error") {
|
|
4350
|
-
console.error(
|
|
4423
|
+
console.error(pc11.red(`Error: ${String(payload.error ?? "stream error")}`));
|
|
4351
4424
|
return finish(1);
|
|
4352
4425
|
}
|
|
4353
4426
|
}
|
|
4354
|
-
console.error(
|
|
4427
|
+
console.error(pc11.yellow("stream ended before the process exited"));
|
|
4355
4428
|
return finish(2);
|
|
4356
4429
|
function finish(code) {
|
|
4357
4430
|
if (code !== void 0) exitCode = code;
|
|
@@ -4372,7 +4445,7 @@ async function runInstanceCommand(command2, opts) {
|
|
|
4372
4445
|
const created = await c.post("/api/v1/sandboxes", buildCreateBody(opts));
|
|
4373
4446
|
const sandbox = created.sandbox;
|
|
4374
4447
|
const org2 = orgKey(opts);
|
|
4375
|
-
console.error(
|
|
4448
|
+
console.error(pc11.dim(`instance ${sandbox.id}`));
|
|
4376
4449
|
const spawned = await c.post(
|
|
4377
4450
|
`/api/v1/sandboxes/${sandbox.id}/processes`,
|
|
4378
4451
|
{ command: command2.map(shellQuote).join(" ") }
|
|
@@ -4450,7 +4523,7 @@ async function runInstanceCommand(command2, opts) {
|
|
|
4450
4523
|
setCurrentInstance(sandbox.id, org2);
|
|
4451
4524
|
if (opts.quiet) console.log(sandbox.id);
|
|
4452
4525
|
else {
|
|
4453
|
-
console.error(
|
|
4526
|
+
console.error(pc11.dim(`kept instance ${shortId(sandbox.id)} (current for ${dirKey()})`));
|
|
4454
4527
|
console.log(sandbox.id);
|
|
4455
4528
|
}
|
|
4456
4529
|
} else {
|
|
@@ -4458,7 +4531,7 @@ async function runInstanceCommand(command2, opts) {
|
|
|
4458
4531
|
await c.del(`/api/v1/sandboxes/${sandbox.id}`);
|
|
4459
4532
|
} catch (e) {
|
|
4460
4533
|
console.error(
|
|
4461
|
-
|
|
4534
|
+
pc11.red(`destroy failed for ${sandbox.id}: ${e instanceof Error ? e.message : String(e)}`)
|
|
4462
4535
|
);
|
|
4463
4536
|
if (exitCode === null || exitCode === 0) exitCode = 1;
|
|
4464
4537
|
}
|
|
@@ -4486,7 +4559,7 @@ async function serveInstanceCommand(id, command2, port, opts) {
|
|
|
4486
4559
|
if (!opts.json) {
|
|
4487
4560
|
const logs = `${proc.stdout}${proc.stderr}`.trimEnd().split("\n");
|
|
4488
4561
|
if (logs.length > 0 && logs[0] !== "") {
|
|
4489
|
-
console.error(
|
|
4562
|
+
console.error(pc11.dim("--- last log lines ---"));
|
|
4490
4563
|
for (const line of logs.slice(-50)) console.error(safeTerm(line));
|
|
4491
4564
|
}
|
|
4492
4565
|
}
|
|
@@ -4541,9 +4614,9 @@ async function serveInstanceCommand(id, command2, port, opts) {
|
|
|
4541
4614
|
});
|
|
4542
4615
|
}
|
|
4543
4616
|
function printServeJobFooter(sandboxId, jobId) {
|
|
4544
|
-
console.error(
|
|
4545
|
-
console.error(
|
|
4546
|
-
console.error(
|
|
4617
|
+
console.error(pc11.dim(` job ${jobId}`));
|
|
4618
|
+
console.error(pc11.dim(` logs: compute instances logs ${sandboxId} ${jobId}`));
|
|
4619
|
+
console.error(pc11.dim(` kill: compute instances kill ${sandboxId} ${jobId}`));
|
|
4547
4620
|
}
|
|
4548
4621
|
var CP_PROGRESS_MIN_BYTES = 10 * 1024 * 1024;
|
|
4549
4622
|
function assertTransferUrl(raw) {
|
|
@@ -4701,7 +4774,7 @@ function formatBytes(n) {
|
|
|
4701
4774
|
}
|
|
4702
4775
|
|
|
4703
4776
|
// src/agents.ts
|
|
4704
|
-
import
|
|
4777
|
+
import pc12 from "picocolors";
|
|
4705
4778
|
import { readFileSync as readFileSync4 } from "fs";
|
|
4706
4779
|
function formatLocalTime2(iso) {
|
|
4707
4780
|
if (iso === null) return "\u2014";
|
|
@@ -4712,7 +4785,7 @@ function formatLocalTime2(iso) {
|
|
|
4712
4785
|
}
|
|
4713
4786
|
function printAgent(a) {
|
|
4714
4787
|
console.log(
|
|
4715
|
-
`${
|
|
4788
|
+
`${pc12.cyan(safeTerm(a.name))} ${a.id.slice(0, 8)} ${a.harness}${a.model ? ` ${safeTerm(a.model)}` : ""} sessions: ${a.sessionCount} created: ${formatLocalTime2(a.createdAt)}`
|
|
4716
4789
|
);
|
|
4717
4790
|
}
|
|
4718
4791
|
function printAgentDetail(a) {
|
|
@@ -4723,13 +4796,13 @@ function printAgentDetail(a) {
|
|
|
4723
4796
|
}
|
|
4724
4797
|
function printSession(s) {
|
|
4725
4798
|
console.log(
|
|
4726
|
-
`${
|
|
4799
|
+
`${pc12.cyan(s.id)} ${s.status} sandbox: ${s.sandboxId ?? "\u2014"} ${formatLocalTime2(s.createdAt)}${s.error ? ` ${pc12.red(safeTerm(s.error))}` : ""}`
|
|
4727
4800
|
);
|
|
4728
4801
|
}
|
|
4729
4802
|
function printEvent(e) {
|
|
4730
4803
|
const payload = e.payload ?? {};
|
|
4731
4804
|
if (e.kind === "user") {
|
|
4732
|
-
console.log(`${
|
|
4805
|
+
console.log(`${pc12.green("you")} #${e.seq} ${safeTerm(String(payload.message ?? ""))}`);
|
|
4733
4806
|
return;
|
|
4734
4807
|
}
|
|
4735
4808
|
if (e.kind === "turn") {
|
|
@@ -4737,12 +4810,12 @@ function printEvent(e) {
|
|
|
4737
4810
|
for (const ev of events) {
|
|
4738
4811
|
const o = ev;
|
|
4739
4812
|
const text = o.text ?? o.message ?? o.content;
|
|
4740
|
-
if (typeof text === "string") console.log(
|
|
4741
|
-
else console.log(
|
|
4813
|
+
if (typeof text === "string") console.log(pc12.dim(`#${e.seq}`) + ` ${safeTerm(text)}`);
|
|
4814
|
+
else console.log(pc12.dim(`#${e.seq} ${safeTerm(JSON.stringify(o))}`));
|
|
4742
4815
|
}
|
|
4743
4816
|
return;
|
|
4744
4817
|
}
|
|
4745
|
-
console.log(
|
|
4818
|
+
console.log(pc12.dim(`#${e.seq} ${e.kind} ${safeTerm(JSON.stringify(payload))}`));
|
|
4746
4819
|
}
|
|
4747
4820
|
function authOpts(cmd) {
|
|
4748
4821
|
return cmd.option("--api-key <key>", "platform API key (or COMPUTE_API_KEY)").option("--base-url <url>", "platform base URL").option("--allow-untrusted-host", "allow non-computesdk.com base URLs").option("--org <slug>", "organization slug (or COMPUTE_ORG)").option("--json", "print the raw response");
|
|
@@ -4793,7 +4866,7 @@ function registerAgentsCommands(program2) {
|
|
|
4793
4866
|
});
|
|
4794
4867
|
output(opts, res, (r) => {
|
|
4795
4868
|
printAgentDetail(r.agent);
|
|
4796
|
-
console.error(
|
|
4869
|
+
console.error(pc12.dim(`agent ${r.agent.name} created \u2014 run it with \`compute agents run ${r.agent.name} "\u2026"\``));
|
|
4797
4870
|
});
|
|
4798
4871
|
} catch (e) {
|
|
4799
4872
|
fail(e, opts);
|
|
@@ -4847,7 +4920,7 @@ function registerAgentsCommands(program2) {
|
|
|
4847
4920
|
const c = await client(opts);
|
|
4848
4921
|
if (!opts.yes) {
|
|
4849
4922
|
const res = await c.get(`/api/v1/agents/${encodeURIComponent(ref)}`);
|
|
4850
|
-
console.error(`Deleting agent ${
|
|
4923
|
+
console.error(`Deleting agent ${pc12.cyan(res.agent.name)} (${res.agent.id}). Pass -y to confirm.`);
|
|
4851
4924
|
process.exit(1);
|
|
4852
4925
|
}
|
|
4853
4926
|
await c.del(`/api/v1/agents/${encodeURIComponent(ref)}`);
|
|
@@ -4884,7 +4957,7 @@ function registerAgentsCommands(program2) {
|
|
|
4884
4957
|
output(opts, res, (r) => {
|
|
4885
4958
|
printSession(r.session);
|
|
4886
4959
|
for (const e of r.events) printEvent(e);
|
|
4887
|
-
console.error(
|
|
4960
|
+
console.error(pc12.dim(`session ${r.session.id} \u2014 continue with \`compute agents send ${r.session.id} "\u2026"\``));
|
|
4888
4961
|
});
|
|
4889
4962
|
} catch (e) {
|
|
4890
4963
|
fail(e, opts);
|
|
@@ -5280,7 +5353,7 @@ function registerManifestCommand(program2, options) {
|
|
|
5280
5353
|
}
|
|
5281
5354
|
|
|
5282
5355
|
// src/org-members.ts
|
|
5283
|
-
import
|
|
5356
|
+
import pc13 from "picocolors";
|
|
5284
5357
|
var ORG_PATH = "/api/v1/organizations/current";
|
|
5285
5358
|
var MEMBER_ROLES = ["member", "admin"];
|
|
5286
5359
|
var USER_LOGIN_HINT = "This needs a user login, and org API keys have no user: run `compute login`, and drop --api-key / unset COMPUTE_API_KEY.";
|
|
@@ -5319,10 +5392,10 @@ function fail2(error, opts = {}) {
|
|
|
5319
5392
|
process.stderr.write(JSON.stringify(envelope) + "\n");
|
|
5320
5393
|
} else if (error instanceof PlatformApiError) {
|
|
5321
5394
|
const code = error.code !== codeForStatus(error.status) ? ` ${error.code}` : "";
|
|
5322
|
-
console.error(
|
|
5323
|
-
if (hint) console.error(
|
|
5395
|
+
console.error(pc13.red(`Error (${error.status}${code}): ${error.message}`));
|
|
5396
|
+
if (hint) console.error(pc13.dim(`hint: ${hint}`));
|
|
5324
5397
|
} else {
|
|
5325
|
-
console.error(
|
|
5398
|
+
console.error(pc13.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
5326
5399
|
}
|
|
5327
5400
|
process.exit(1);
|
|
5328
5401
|
}
|
|
@@ -5374,7 +5447,7 @@ function printUserInvitations(res) {
|
|
|
5374
5447
|
safeTerm(i.organization.name)
|
|
5375
5448
|
])
|
|
5376
5449
|
);
|
|
5377
|
-
console.log(
|
|
5450
|
+
console.log(pc13.dim("Accept with `compute invitations accept <id>`; decline with `compute invitations decline <id> -y`."));
|
|
5378
5451
|
}
|
|
5379
5452
|
function printInvitationDetail(inv) {
|
|
5380
5453
|
const rows = [
|
|
@@ -5395,7 +5468,7 @@ function printInvite(res) {
|
|
|
5395
5468
|
console.log(`Emailed ${safeTerm(inv.email)} the invitation link.`);
|
|
5396
5469
|
} else {
|
|
5397
5470
|
const reason = res.emailError ? ` (${safeTerm(res.emailError)})` : "";
|
|
5398
|
-
console.log(
|
|
5471
|
+
console.log(pc13.yellow(`The invitation email was not sent${reason}; share the link instead.`));
|
|
5399
5472
|
}
|
|
5400
5473
|
console.log(`Link: ${safeTerm(inv.url)}`);
|
|
5401
5474
|
}
|
|
@@ -5519,7 +5592,7 @@ function registerOrgMemberCommands(org2) {
|
|
|
5519
5592
|
output(opts, res, () => {
|
|
5520
5593
|
console.log(`Left ${org3 ?? "the organization"}.`);
|
|
5521
5594
|
console.log(
|
|
5522
|
-
|
|
5595
|
+
pc13.dim("If your login was granted for that organization, it no longer works: run `compute login` again.")
|
|
5523
5596
|
);
|
|
5524
5597
|
});
|
|
5525
5598
|
} catch (e) {
|
|
@@ -5558,7 +5631,7 @@ function registerInvitationsCommands(program2) {
|
|
|
5558
5631
|
output(opts, res, (r) => {
|
|
5559
5632
|
const slug = safeTerm(r.organization.slug);
|
|
5560
5633
|
console.log(`Joined ${slug} as ${safeTerm(r.member.role)}.`);
|
|
5561
|
-
console.log(
|
|
5634
|
+
console.log(pc13.dim(`Switch to it with \`compute org use ${slug}\`, or pass --org ${slug}.`));
|
|
5562
5635
|
});
|
|
5563
5636
|
} catch (e) {
|
|
5564
5637
|
fail2(e, opts);
|
|
@@ -5601,6 +5674,7 @@ process.stderr.on("error", (err) => {
|
|
|
5601
5674
|
throw err;
|
|
5602
5675
|
});
|
|
5603
5676
|
var program = new Command4();
|
|
5677
|
+
inheritParentOptions(program);
|
|
5604
5678
|
program.name("compute").description("ComputeSDK CLI").version(VERSION).enablePositionalOptions().passThroughOptions();
|
|
5605
5679
|
async function printSessionLine(options) {
|
|
5606
5680
|
try {
|
|
@@ -5632,18 +5706,18 @@ async function runLogout() {
|
|
|
5632
5706
|
program.option("--login", "force re-authentication").option("--logout", "clear stored credentials").option("--org <slug>", "organization slug override for this invocation (or $COMPUTE_ORG)").action(async (opts) => {
|
|
5633
5707
|
if (opts.logout) {
|
|
5634
5708
|
console.log();
|
|
5635
|
-
p.intro(
|
|
5709
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5636
5710
|
await runLogout();
|
|
5637
5711
|
p.log.success("Logged out. Stored credentials removed.");
|
|
5638
|
-
p.outro(
|
|
5712
|
+
p.outro(pc14.green("Done!"));
|
|
5639
5713
|
process.exit(0);
|
|
5640
5714
|
}
|
|
5641
5715
|
if (opts.login) {
|
|
5642
5716
|
console.log();
|
|
5643
|
-
p.intro(
|
|
5717
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5644
5718
|
await runLogin();
|
|
5645
5719
|
await printSessionLine();
|
|
5646
|
-
p.outro(
|
|
5720
|
+
p.outro(pc14.green("Authenticated!"));
|
|
5647
5721
|
process.exit(0);
|
|
5648
5722
|
}
|
|
5649
5723
|
program.help();
|
|
@@ -5654,23 +5728,23 @@ program.hook("preAction", (thisCommand) => {
|
|
|
5654
5728
|
});
|
|
5655
5729
|
program.command("providers").description("List all providers and their configuration status").action(async () => {
|
|
5656
5730
|
console.log();
|
|
5657
|
-
p.intro(
|
|
5731
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5658
5732
|
const statuses = getProviderStatus();
|
|
5659
5733
|
console.log();
|
|
5660
5734
|
for (const status of statuses) {
|
|
5661
|
-
const icon = status.ready ?
|
|
5662
|
-
const name = status.ready ?
|
|
5663
|
-
const detail = status.ready ?
|
|
5735
|
+
const icon = status.ready ? pc14.green("\u25CF") : pc14.gray("\u25CB");
|
|
5736
|
+
const name = status.ready ? pc14.white(status.name) : pc14.gray(status.name);
|
|
5737
|
+
const detail = status.ready ? pc14.green("ready") : pc14.gray(`missing: ${status.missing.join(", ")}`);
|
|
5664
5738
|
console.log(` ${icon} ${name} ${detail}`);
|
|
5665
5739
|
}
|
|
5666
5740
|
console.log();
|
|
5667
5741
|
});
|
|
5668
5742
|
program.command("login").description("Authenticate with ComputeSDK (OAuth device flow)").option("--base-url <url>", "platform URL to authenticate against").action(async (opts) => {
|
|
5669
5743
|
console.log();
|
|
5670
|
-
p.intro(
|
|
5744
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5671
5745
|
await runLogin({ baseUrl: opts.baseUrl });
|
|
5672
5746
|
await printSessionLine({ baseUrl: opts.baseUrl });
|
|
5673
|
-
p.outro(
|
|
5747
|
+
p.outro(pc14.green("Authenticated!"));
|
|
5674
5748
|
});
|
|
5675
5749
|
program.command("logout").description("Clear stored credentials").option("--json", "print machine-readable JSON").action(async (opts) => {
|
|
5676
5750
|
await runLogout();
|
|
@@ -5679,9 +5753,9 @@ program.command("logout").description("Clear stored credentials").option("--json
|
|
|
5679
5753
|
return;
|
|
5680
5754
|
}
|
|
5681
5755
|
console.log();
|
|
5682
|
-
p.intro(
|
|
5756
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5683
5757
|
p.log.success("Logged out. Stored credentials removed.");
|
|
5684
|
-
p.outro(
|
|
5758
|
+
p.outro(pc14.green("Done!"));
|
|
5685
5759
|
});
|
|
5686
5760
|
async function printWhoami(options = {}) {
|
|
5687
5761
|
const me = await fetchWhoami(await benchAuth({ baseUrl: options.baseUrl }));
|
|
@@ -5701,8 +5775,8 @@ org.command("list").description("List your organizations").option("--json", "pri
|
|
|
5701
5775
|
return;
|
|
5702
5776
|
}
|
|
5703
5777
|
for (const o of organizations) {
|
|
5704
|
-
const marker = o.id === me.activeOrganizationId ?
|
|
5705
|
-
console.log(`${marker} ${
|
|
5778
|
+
const marker = o.id === me.activeOrganizationId ? pc14.green("*") : " ";
|
|
5779
|
+
console.log(`${marker} ${pc14.cyan(o.slug)} ${o.name ?? ""} ${pc14.dim(o.id)}`);
|
|
5706
5780
|
}
|
|
5707
5781
|
});
|
|
5708
5782
|
org.command("use <slug>").description("Set the active organization (persisted to the stored login)").action(async (slug) => {
|
|
@@ -5738,6 +5812,7 @@ registerInvitationsCommands(program);
|
|
|
5738
5812
|
registerActionsCommands(program);
|
|
5739
5813
|
registerByokCommands(program);
|
|
5740
5814
|
registerMarketCommands(program);
|
|
5815
|
+
registerCreditsCommands(program);
|
|
5741
5816
|
registerSandboxesCommands(program);
|
|
5742
5817
|
registerAgentsCommands(program);
|
|
5743
5818
|
program.command("bench").description("Benchmarks platform CLI (run, auth, org, benchmarks, runs, results, fork, artifacts, export, ...)").allowUnknownOption().helpOption(false).action(() => {
|
|
@@ -5755,7 +5830,7 @@ async function main() {
|
|
|
5755
5830
|
await program.parseAsync(process.argv);
|
|
5756
5831
|
}
|
|
5757
5832
|
main().catch((error) => {
|
|
5758
|
-
console.error(
|
|
5833
|
+
console.error(pc14.red(`
|
|
5759
5834
|
Error: ${error.message}`));
|
|
5760
5835
|
process.exit(1);
|
|
5761
5836
|
});
|