@computesdk/cli 2.6.5 → 2.6.7
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 +62 -443
- package/dist/index.js +413 -227
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import "dotenv/config";
|
|
5
|
-
import { Command } from "commander";
|
|
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";
|
|
@@ -65,11 +65,13 @@ function getProviderStatus() {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// src/actions.ts
|
|
68
|
+
import { Option as Option2 } from "commander";
|
|
68
69
|
import pc7 from "picocolors";
|
|
69
70
|
import { mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
70
71
|
import { spawnSync } from "child_process";
|
|
71
72
|
|
|
72
73
|
// src/settings.ts
|
|
74
|
+
import { Option } from "commander";
|
|
73
75
|
import pc2 from "picocolors";
|
|
74
76
|
|
|
75
77
|
// src/actions-client.ts
|
|
@@ -107,45 +109,6 @@ var ActionsClient = class extends PlatformClient {
|
|
|
107
109
|
}
|
|
108
110
|
};
|
|
109
111
|
|
|
110
|
-
// src/rate-display.ts
|
|
111
|
-
var SECONDS_PER_MINUTE = 60;
|
|
112
|
-
var SECONDS_PER_HOUR = 3600;
|
|
113
|
-
function rateAllUnits(rate) {
|
|
114
|
-
const perSecond = rate.per === "second" ? rate.usd : rate.per === "minute" ? rate.usd / SECONDS_PER_MINUTE : rate.usd / SECONDS_PER_HOUR;
|
|
115
|
-
return {
|
|
116
|
-
perSecond,
|
|
117
|
-
perMinute: perSecond * SECONDS_PER_MINUTE,
|
|
118
|
-
perHour: perSecond * SECONDS_PER_HOUR
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function formatUsd(usd) {
|
|
122
|
-
if (!Number.isFinite(usd)) return "$\u2014";
|
|
123
|
-
if (usd === 0) return "$0";
|
|
124
|
-
const decimals = Math.min(100, Math.max(0, 3 - Math.floor(Math.log10(Math.abs(usd)))));
|
|
125
|
-
const fixed = usd.toFixed(decimals);
|
|
126
|
-
const trimmed = fixed.includes(".") ? fixed.replace(/0+$/, "").replace(/\.$/, "") : fixed;
|
|
127
|
-
return `$${trimmed}`;
|
|
128
|
-
}
|
|
129
|
-
function formatMoney(usd) {
|
|
130
|
-
if (!Number.isFinite(usd)) return "$\u2014";
|
|
131
|
-
const sign = usd < 0 ? "-" : "";
|
|
132
|
-
const abs = Math.abs(usd);
|
|
133
|
-
if (abs !== 0 && abs < 0.01) {
|
|
134
|
-
return `${sign}${formatUsd(abs)}`;
|
|
135
|
-
}
|
|
136
|
-
const s = abs.toLocaleString("en-US", {
|
|
137
|
-
minimumFractionDigits: 2,
|
|
138
|
-
maximumFractionDigits: 2
|
|
139
|
-
});
|
|
140
|
-
return `${sign}$${s}`;
|
|
141
|
-
}
|
|
142
|
-
function formatRateAllUnits(rate) {
|
|
143
|
-
return `${formatUsd(rate.perHour)}/hr \xB7 ${formatUsd(rate.perMinute)}/min \xB7 ${formatUsd(rate.perSecond)}/s`;
|
|
144
|
-
}
|
|
145
|
-
function formatUsdPer(rate) {
|
|
146
|
-
return formatRateAllUnits(rateAllUnits(rate));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
112
|
// src/term.ts
|
|
150
113
|
import pc from "picocolors";
|
|
151
114
|
function safeTerm(s) {
|
|
@@ -267,24 +230,28 @@ function formatResources(r) {
|
|
|
267
230
|
if (r.ephemeralDiskMb) parts.push(`${r.ephemeralDiskMb} MB disk`);
|
|
268
231
|
return parts.join(" / ") || "\u2014";
|
|
269
232
|
}
|
|
270
|
-
var
|
|
271
|
-
var
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
233
|
+
var BYOK_MODES = ["off", "first", "fallback", "only"];
|
|
234
|
+
var BYOK_MODE_HELP = {
|
|
235
|
+
off: "not used: managed accounts only",
|
|
236
|
+
first: "your keys first, then managed accounts",
|
|
237
|
+
fallback: "managed accounts first, then your keys",
|
|
238
|
+
only: "your keys only, never managed accounts"
|
|
239
|
+
};
|
|
240
|
+
var arrow = (list) => list.join(" \u2192 ");
|
|
241
|
+
function printLaneRouting(r, lane) {
|
|
242
|
+
const label = (text) => text.padEnd(12);
|
|
243
|
+
const managed = r.managed.length > 0 ? arrow(r.managed) : pc2.dim("no managed account is live");
|
|
244
|
+
console.log(
|
|
245
|
+
`${label("Routing")}${r.routing === "default" ? `ComputeSDK default ${pc2.dim(`(${managed})`)}` : `custom: ${managed}`}`
|
|
246
|
+
);
|
|
247
|
+
console.log(`${label("BYOK")}${r.byok.mode} ${pc2.dim(`(${BYOK_MODE_HELP[r.byok.mode]})`)}`);
|
|
248
|
+
if (r.byok.mode !== "off") {
|
|
249
|
+
const list = r.byok.order.length > 0 ? arrow(r.byok.order) : "\u2014";
|
|
250
|
+
const order = lane === "sandboxes" && r.byok.inherits === true ? `${list} ${pc2.dim("(inherited from the Actions router)")}` : r.byok.order.length > 0 ? list : pc2.dim("none set \u2014 add keys with `compute byok configure`");
|
|
251
|
+
console.log(`${label("BYOK order")}${order}`);
|
|
285
252
|
}
|
|
286
|
-
|
|
287
|
-
|
|
253
|
+
}
|
|
254
|
+
function printLaneSettings(s) {
|
|
288
255
|
const resources = Object.entries(s.providerResources ?? {});
|
|
289
256
|
console.log("resources:");
|
|
290
257
|
if (resources.length === 0) console.log(" \u2014");
|
|
@@ -331,33 +298,43 @@ function settingsFail(e, opts, lane, verb, deps) {
|
|
|
331
298
|
}
|
|
332
299
|
return deps.fail(e, opts);
|
|
333
300
|
}
|
|
301
|
+
function providerList(flag, value) {
|
|
302
|
+
const list = value.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
303
|
+
if (list.length === 0) throw new Error(`${flag} "${value}" names no providers \u2014 pass a comma-separated list.`);
|
|
304
|
+
return list;
|
|
305
|
+
}
|
|
334
306
|
function registerSettingsCommands(group, lane, common2, deps) {
|
|
307
|
+
const routerName = lane === "sandboxes" ? "Sandboxes" : "Actions";
|
|
308
|
+
const show = async (c) => {
|
|
309
|
+
const [routing, settings2] = await Promise.all([
|
|
310
|
+
c.get(`/api/v1/${lane}/routing`),
|
|
311
|
+
c.get(`/api/v1/${lane}/settings`)
|
|
312
|
+
]);
|
|
313
|
+
return { routing, settings: settings2 };
|
|
314
|
+
};
|
|
315
|
+
const print = ({ routing, settings: settings2 }) => {
|
|
316
|
+
printLaneRouting(routing, lane);
|
|
317
|
+
printLaneSettings(settings2);
|
|
318
|
+
};
|
|
335
319
|
const settings = common2(
|
|
336
|
-
group.command("settings").description(`Show the
|
|
320
|
+
group.command("settings").description(`Show the ${routerName} router: managed routing, BYOK use, sizes and pools`).configureOutput({
|
|
337
321
|
outputError: (str, write) => deps.usageErrorOutput(str, write)
|
|
338
322
|
})
|
|
339
323
|
).action(async (opts) => {
|
|
340
324
|
try {
|
|
341
|
-
|
|
342
|
-
const res = await c.get(`/api/v1/${lane}/settings`);
|
|
343
|
-
deps.output(opts, res, (s) => printLaneSettings(s, lane));
|
|
325
|
+
deps.output(opts, await show(await deps.client(opts)), print);
|
|
344
326
|
} catch (e) {
|
|
345
327
|
settingsFail(e, opts, lane, "view", deps);
|
|
346
328
|
}
|
|
347
329
|
});
|
|
348
330
|
const set = common2(
|
|
349
|
-
settings.command("set").description(`
|
|
350
|
-
"--
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
lane === "sandboxes" ? "market order type: limit | market | inherit (the Actions value)" : "market order type: limit | market"
|
|
357
|
-
).option(
|
|
358
|
-
"--order <providers>",
|
|
359
|
-
lane === "sandboxes" ? 'provider order, comma-separated (e.g. "market,blaxel,vercel"); "inherit" restores the Actions order' : 'provider order, comma-separated (e.g. "market,blaxel,vercel"); "default" restores the platform default'
|
|
360
|
-
)
|
|
331
|
+
settings.command("set").description(`Change the ${routerName} router (owner/admin)`).option(
|
|
332
|
+
"--routing <default|providers>",
|
|
333
|
+
'managed routing: "default" for ComputeSDK routing, or your own managed-account order (e.g. daytona,e2b)'
|
|
334
|
+
).option("--byok <mode>", `use your own keys: ${BYOK_MODES.join(" | ")}`).option(
|
|
335
|
+
"--byok-order <providers>",
|
|
336
|
+
lane === "sandboxes" ? 'your own providers in order (e.g. tensorlake,blaxel); "inherit" uses the Actions BYOK order' : "your own providers in order (e.g. tensorlake,blaxel)"
|
|
337
|
+
).addOption(new Option("--order <providers>").hideHelp())
|
|
361
338
|
);
|
|
362
339
|
set.option(
|
|
363
340
|
"--resources <provider=preset>",
|
|
@@ -366,55 +343,58 @@ function registerSettingsCommands(group, lane, common2, deps) {
|
|
|
366
343
|
[]
|
|
367
344
|
).option(
|
|
368
345
|
"--warm-pool <provider[:region]=n>",
|
|
369
|
-
`warm pool size per
|
|
346
|
+
`warm pool size per BYOK entry, 0..${MAX_WARM_POOL_SIZE}; 0 clears it (repeatable)`,
|
|
370
347
|
(v, a) => a.concat(v),
|
|
371
348
|
[]
|
|
372
349
|
);
|
|
373
350
|
if (lane === "actions") {
|
|
374
351
|
set.option(
|
|
375
352
|
"--snapshot-pool <provider[:region]=n>",
|
|
376
|
-
`snapshot cap per
|
|
353
|
+
`snapshot cap per BYOK entry, 0..${MAX_SNAPSHOT_POOL_SIZE}; 0 clears it (repeatable)`,
|
|
377
354
|
(v, a) => a.concat(v),
|
|
378
355
|
[]
|
|
379
356
|
);
|
|
380
357
|
}
|
|
358
|
+
set.addOption(new Option("--cap <size=rate>").hideHelp().argParser((v, a = []) => a.concat(v)).default([])).addOption(new Option("--general-cap <rate|none>").hideHelp()).addOption(new Option("--order-type <type>").hideHelp());
|
|
381
359
|
set.action(async (opts) => {
|
|
382
360
|
try {
|
|
383
|
-
const
|
|
361
|
+
const routing = {};
|
|
362
|
+
if (opts.routing !== void 0) {
|
|
363
|
+
routing.routing = opts.routing === "default" ? "default" : providerList("--routing", opts.routing);
|
|
364
|
+
}
|
|
365
|
+
if (opts.byok !== void 0) {
|
|
366
|
+
if (!BYOK_MODES.includes(opts.byok)) {
|
|
367
|
+
throw new Error(`--byok must be one of ${BYOK_MODES.join(", ")}.`);
|
|
368
|
+
}
|
|
369
|
+
routing.byok = opts.byok;
|
|
370
|
+
}
|
|
371
|
+
if (opts.byokOrder !== void 0 && opts.order !== void 0) {
|
|
372
|
+
throw new Error("--order is the old name of --byok-order; pass one.");
|
|
373
|
+
}
|
|
374
|
+
const byokOrder = opts.byokOrder ?? opts.order;
|
|
375
|
+
if (byokOrder !== void 0) {
|
|
376
|
+
const flag = opts.byokOrder !== void 0 ? "--byok-order" : "--order";
|
|
377
|
+
routing.byokOrder = byokOrder === "inherit" && lane === "sandboxes" || byokOrder === "default" && lane === "actions" ? [] : providerList(flag, byokOrder);
|
|
378
|
+
}
|
|
379
|
+
const settingsBody = {};
|
|
384
380
|
if (opts.cap.length > 0) {
|
|
385
381
|
const caps = {};
|
|
386
382
|
for (const entry of opts.cap) {
|
|
387
383
|
const { size, cap } = parseSizeCap(entry);
|
|
388
384
|
caps[size] = cap;
|
|
389
385
|
}
|
|
390
|
-
|
|
386
|
+
settingsBody.marketCaps = caps;
|
|
391
387
|
}
|
|
392
388
|
if (opts.generalCap !== void 0) {
|
|
393
|
-
|
|
389
|
+
settingsBody.marketCap = opts.generalCap === "none" ? null : parseMaxPrice(opts.generalCap, void 0);
|
|
394
390
|
}
|
|
395
391
|
if (opts.orderType !== void 0) {
|
|
396
392
|
if (lane === "sandboxes" && opts.orderType === "inherit") {
|
|
397
|
-
|
|
393
|
+
settingsBody.marketOrderType = null;
|
|
398
394
|
} else if (opts.orderType === "limit" || opts.orderType === "market") {
|
|
399
|
-
|
|
395
|
+
settingsBody.marketOrderType = opts.orderType;
|
|
400
396
|
} else {
|
|
401
|
-
throw new Error(
|
|
402
|
-
lane === "sandboxes" ? "--order-type must be limit, market, or inherit." : "--order-type must be limit or market."
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
if (opts.order !== void 0) {
|
|
407
|
-
if (opts.order === "inherit" && lane === "sandboxes") {
|
|
408
|
-
body.providerOrder = [];
|
|
409
|
-
} else if (opts.order === "default" && lane === "actions") {
|
|
410
|
-
body.providerOrder = [];
|
|
411
|
-
} else {
|
|
412
|
-
body.providerOrder = opts.order.split(",").map((s) => s.trim()).filter(Boolean);
|
|
413
|
-
if (body.providerOrder.length === 0) {
|
|
414
|
-
throw new Error(
|
|
415
|
-
lane === "sandboxes" ? `--order "${opts.order}" names no providers \u2014 pass a comma-separated list or "inherit".` : `--order "${opts.order}" names no providers \u2014 pass a comma-separated list or "default".`
|
|
416
|
-
);
|
|
417
|
-
}
|
|
397
|
+
throw new Error("--order-type must be limit or market.");
|
|
418
398
|
}
|
|
419
399
|
}
|
|
420
400
|
if (opts.resources && opts.resources.length > 0) {
|
|
@@ -423,22 +403,28 @@ function registerSettingsCommands(group, lane, common2, deps) {
|
|
|
423
403
|
const { provider, preset } = parseResourcesFlag(entry);
|
|
424
404
|
resources[provider] = preset;
|
|
425
405
|
}
|
|
426
|
-
|
|
406
|
+
settingsBody.providerResources = resources;
|
|
427
407
|
}
|
|
428
408
|
if (opts.warmPool && opts.warmPool.length > 0) {
|
|
429
|
-
|
|
409
|
+
settingsBody.warmPool = poolPatch(opts.warmPool, parseWarmPoolFlag);
|
|
430
410
|
}
|
|
431
411
|
if (opts.snapshotPool && opts.snapshotPool.length > 0) {
|
|
432
|
-
|
|
412
|
+
settingsBody.snapshotPool = poolPatch(opts.snapshotPool, parseSnapshotPoolFlag);
|
|
413
|
+
}
|
|
414
|
+
if (Object.keys(routing).length > 0 && Object.keys(settingsBody).length > 0) {
|
|
415
|
+
throw new Error(
|
|
416
|
+
"Change routing (--routing, --byok, --byok-order) and sizes or pools in separate commands."
|
|
417
|
+
);
|
|
433
418
|
}
|
|
434
|
-
if (Object.keys(
|
|
419
|
+
if (Object.keys(routing).length === 0 && Object.keys(settingsBody).length === 0) {
|
|
435
420
|
throw new Error(
|
|
436
|
-
lane === "sandboxes" ? "Nothing to change \u2014 pass --
|
|
421
|
+
lane === "sandboxes" ? "Nothing to change \u2014 pass --routing, --byok, --byok-order, --resources, or --warm-pool." : "Nothing to change \u2014 pass --routing, --byok, --byok-order, --resources, --warm-pool, or --snapshot-pool."
|
|
437
422
|
);
|
|
438
423
|
}
|
|
439
424
|
const c = await deps.client(opts);
|
|
440
|
-
|
|
441
|
-
|
|
425
|
+
if (Object.keys(routing).length > 0) await c.patch(`/api/v1/${lane}/routing`, routing);
|
|
426
|
+
if (Object.keys(settingsBody).length > 0) await c.patch(`/api/v1/${lane}/settings`, settingsBody);
|
|
427
|
+
deps.output(opts, await show(c), print);
|
|
442
428
|
} catch (e) {
|
|
443
429
|
settingsFail(e, opts, lane, "change", deps);
|
|
444
430
|
}
|
|
@@ -832,7 +818,7 @@ function registerWorkflowsCommands(actions, common2, deps) {
|
|
|
832
818
|
});
|
|
833
819
|
}
|
|
834
820
|
common2(
|
|
835
|
-
workflows.command("set").description("Set a workflow's provider order and snapshot cap (owner/admin)").argument("<repo>", "repository in owner/repo format").argument("<workflow>", "workflow path, name, file name (ci.yml) or id").option("--order <providers>",
|
|
821
|
+
workflows.command("set").description("Set a workflow's provider order and snapshot cap (owner/admin)").argument("<repo>", "repository in owner/repo format").argument("<workflow>", "workflow path, name, file name (ci.yml) or id").option("--order <providers>", "this workflow walks exactly these BYOK providers instead of the Actions router (e.g. e2b,blaxel)").option("--inherit-order", "drop the workflow's order: it follows the Actions router").option("--snapshot-cap <n>", "most snapshots this workflow keeps (0 turns them off)").option("--dynamic-snapshots", "drop the cap: the workflow uses the dynamic snapshot pool").option("-y, --yes", "skip the confirmation")
|
|
836
822
|
).action(async (repo, selector, opts) => {
|
|
837
823
|
try {
|
|
838
824
|
const controls = setControls(opts);
|
|
@@ -1884,7 +1870,7 @@ function registerActionsCommands(program2) {
|
|
|
1884
1870
|
const actions = program2.command("actions").alias("ci").description("Drive the benchmarks-platform Actions API").configureOutput({ outputError: usageErrorOutput });
|
|
1885
1871
|
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");
|
|
1886
1872
|
common2(
|
|
1887
|
-
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); also finds a workflow file only this ref has").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
|
|
1873
|
+
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); also finds a workflow file only this ref has").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 Actions router").option("--provider-region <region>", "region for --provider (same as --provider <id>:<region>)").addOption(new Option2("--max-bid <usd>").hideHelp()).addOption(new Option2("--max-bid-per <unit>").hideHelp()).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)")
|
|
1888
1874
|
).action(async (repo, opts) => {
|
|
1889
1875
|
try {
|
|
1890
1876
|
const c = await client(opts);
|
|
@@ -2349,6 +2335,47 @@ function registerActionsCommands(program2) {
|
|
|
2349
2335
|
|
|
2350
2336
|
// src/byok.ts
|
|
2351
2337
|
import pc8 from "picocolors";
|
|
2338
|
+
|
|
2339
|
+
// src/rate-display.ts
|
|
2340
|
+
var SECONDS_PER_MINUTE = 60;
|
|
2341
|
+
var SECONDS_PER_HOUR = 3600;
|
|
2342
|
+
function rateAllUnits(rate) {
|
|
2343
|
+
const perSecond = rate.per === "second" ? rate.usd : rate.per === "minute" ? rate.usd / SECONDS_PER_MINUTE : rate.usd / SECONDS_PER_HOUR;
|
|
2344
|
+
return {
|
|
2345
|
+
perSecond,
|
|
2346
|
+
perMinute: perSecond * SECONDS_PER_MINUTE,
|
|
2347
|
+
perHour: perSecond * SECONDS_PER_HOUR
|
|
2348
|
+
};
|
|
2349
|
+
}
|
|
2350
|
+
function formatUsd(usd) {
|
|
2351
|
+
if (!Number.isFinite(usd)) return "$\u2014";
|
|
2352
|
+
if (usd === 0) return "$0";
|
|
2353
|
+
const decimals = Math.min(100, Math.max(0, 3 - Math.floor(Math.log10(Math.abs(usd)))));
|
|
2354
|
+
const fixed = usd.toFixed(decimals);
|
|
2355
|
+
const trimmed = fixed.includes(".") ? fixed.replace(/0+$/, "").replace(/\.$/, "") : fixed;
|
|
2356
|
+
return `$${trimmed}`;
|
|
2357
|
+
}
|
|
2358
|
+
function formatMoney(usd) {
|
|
2359
|
+
if (!Number.isFinite(usd)) return "$\u2014";
|
|
2360
|
+
const sign = usd < 0 ? "-" : "";
|
|
2361
|
+
const abs = Math.abs(usd);
|
|
2362
|
+
if (abs !== 0 && abs < 0.01) {
|
|
2363
|
+
return `${sign}${formatUsd(abs)}`;
|
|
2364
|
+
}
|
|
2365
|
+
const s = abs.toLocaleString("en-US", {
|
|
2366
|
+
minimumFractionDigits: 2,
|
|
2367
|
+
maximumFractionDigits: 2
|
|
2368
|
+
});
|
|
2369
|
+
return `${sign}$${s}`;
|
|
2370
|
+
}
|
|
2371
|
+
function formatRateAllUnits(rate) {
|
|
2372
|
+
return `${formatUsd(rate.perHour)}/hr \xB7 ${formatUsd(rate.perMinute)}/min \xB7 ${formatUsd(rate.perSecond)}/s`;
|
|
2373
|
+
}
|
|
2374
|
+
function formatUsdPer(rate) {
|
|
2375
|
+
return formatRateAllUnits(rateAllUnits(rate));
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
// src/byok.ts
|
|
2352
2379
|
var RATE_UNITS = ["second", "minute", "hour"];
|
|
2353
2380
|
var MAX_RATE_USD = 1e3;
|
|
2354
2381
|
function providerPath(provider, rest = "") {
|
|
@@ -2811,7 +2838,7 @@ function formatCredits(b) {
|
|
|
2811
2838
|
const lines = [`available ${formatMoney(b.balanceMicroUsd / MICRO_USD)}`];
|
|
2812
2839
|
if (b.holds.length > 0) {
|
|
2813
2840
|
lines.push(
|
|
2814
|
-
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"}`)
|
|
2815
2842
|
);
|
|
2816
2843
|
}
|
|
2817
2844
|
return lines.join("\n");
|
|
@@ -2840,7 +2867,7 @@ function formatPurchaseRow(p2) {
|
|
|
2840
2867
|
].filter((part) => part !== "").join(" ");
|
|
2841
2868
|
}
|
|
2842
2869
|
function registerMarketCommands(program2) {
|
|
2843
|
-
const market = program2.command("market").description("Buy and sell compute capacity on the compute market").configureOutput({ outputError: usageErrorOutput });
|
|
2870
|
+
const market = program2.command("market", { hidden: true }).description("Buy and sell compute capacity on the compute market").configureOutput({ outputError: usageErrorOutput });
|
|
2844
2871
|
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");
|
|
2845
2872
|
common2(
|
|
2846
2873
|
market.command("listings").alias("list").description("Your listings \u2014 live, paused, expired, and withdrawn")
|
|
@@ -3135,7 +3162,7 @@ function registerMarketCommands(program2) {
|
|
|
3135
3162
|
const page = await (await client(opts)).get("/api/v1/billing/ledger", { limit: opts.limit, cursor: opts.cursor });
|
|
3136
3163
|
output(opts, page, (p2) => {
|
|
3137
3164
|
if (p2.entries.length === 0) {
|
|
3138
|
-
console.log("No credit activity yet \u2014 add
|
|
3165
|
+
console.log("No credit activity yet \u2014 add credit with `compute credits topup <usd>`.");
|
|
3139
3166
|
return;
|
|
3140
3167
|
}
|
|
3141
3168
|
for (const entry of p2.entries) console.log(formatLedgerRow(entry));
|
|
@@ -3223,13 +3250,71 @@ ${hints}`
|
|
|
3223
3250
|
});
|
|
3224
3251
|
}
|
|
3225
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
|
+
|
|
3226
3310
|
// src/sandboxes.ts
|
|
3227
3311
|
import * as fs from "fs";
|
|
3228
3312
|
import * as os from "os";
|
|
3229
3313
|
import * as path from "path";
|
|
3230
3314
|
import * as readline from "readline";
|
|
3231
3315
|
import { Readable } from "stream";
|
|
3232
|
-
import
|
|
3316
|
+
import { Option as Option3 } from "commander";
|
|
3317
|
+
import pc11 from "picocolors";
|
|
3233
3318
|
import * as tar from "tar";
|
|
3234
3319
|
|
|
3235
3320
|
// src/current-instance.ts
|
|
@@ -3391,6 +3476,16 @@ function shellQuote(arg) {
|
|
|
3391
3476
|
function shortRate(rate) {
|
|
3392
3477
|
return `${formatUsd(rateAllUnits(rate).perHour)}/h`;
|
|
3393
3478
|
}
|
|
3479
|
+
function placementLane(source) {
|
|
3480
|
+
if (source === "house") return "managed";
|
|
3481
|
+
if (source === "own-key") return "BYOK";
|
|
3482
|
+
return source ?? "\u2014";
|
|
3483
|
+
}
|
|
3484
|
+
function billedBy(source, provider) {
|
|
3485
|
+
if (source === "house") return "billed from your ComputeSDK credit";
|
|
3486
|
+
if (source === "own-key") return `billed by ${provider} to your account`;
|
|
3487
|
+
return "billed from your ComputeSDK credit";
|
|
3488
|
+
}
|
|
3394
3489
|
function formatLocalTime(iso) {
|
|
3395
3490
|
const d = new Date(iso);
|
|
3396
3491
|
if (Number.isNaN(d.getTime())) return iso;
|
|
@@ -3400,63 +3495,77 @@ function formatLocalTime(iso) {
|
|
|
3400
3495
|
function printSandbox(s, verbose = false) {
|
|
3401
3496
|
const p2 = s.placement;
|
|
3402
3497
|
console.log(
|
|
3403
|
-
`${
|
|
3498
|
+
`${pc11.cyan(s.id)} ${s.status} ${p2?.box?.provider ?? s.provider ?? "\u2014"} \xB7 ${placementLane(p2?.source)} ${p2?.size ?? "\u2014"} ${p2 ? shortRate(p2.rate) : "\u2014"}`
|
|
3404
3499
|
);
|
|
3405
3500
|
if (s.label) {
|
|
3406
3501
|
console.log(` label: ${s.label} created: ${formatLocalTime(s.createdAt)}`);
|
|
3407
3502
|
}
|
|
3408
|
-
if (s.destroyError) console.log(` destroyError: ${
|
|
3503
|
+
if (s.destroyError) console.log(` destroyError: ${pc11.red(s.destroyError)}`);
|
|
3409
3504
|
if (!verbose) return;
|
|
3410
3505
|
console.log(` providerSandboxId: ${s.providerSandboxId ?? "\u2014"} commands: ${s.commandCount}`);
|
|
3411
3506
|
if (s.image !== void 0) {
|
|
3412
|
-
console.log(` image: ${s.image ?? "\u2014"}${s.requestedImage !== null && s.requestedImage !== s.image ? ` ${
|
|
3507
|
+
console.log(` image: ${s.image ?? "\u2014"}${s.requestedImage !== null && s.requestedImage !== s.image ? ` ${pc11.dim(`(requested: ${s.requestedImage})`)}` : ""}`);
|
|
3413
3508
|
}
|
|
3414
3509
|
if (p2) {
|
|
3415
3510
|
const box = p2.box ? ` / ${p2.box.sizeName ?? "custom"}${p2.box.resources ? ` (${p2.box.resources.cpus ?? "?"} vCPU / ${p2.box.resources.memoryMb ?? "?"} MB)` : ""}` : "";
|
|
3511
|
+
const provider = p2.box?.provider ?? s.provider ?? "the provider";
|
|
3416
3512
|
console.log(
|
|
3417
|
-
` placement: ${p2.source}${box}
|
|
3513
|
+
` placement: ${placementLane(p2.source)}${box} rate: ${formatUsdPer(p2.rate)} ${pc11.dim(billedBy(p2.source, provider))}`
|
|
3418
3514
|
);
|
|
3419
3515
|
}
|
|
3420
3516
|
const attach = "attach" in s ? s.attach : void 0;
|
|
3421
3517
|
if (attach !== void 0) {
|
|
3422
3518
|
console.log(
|
|
3423
|
-
attach === null ? " attach: none (
|
|
3519
|
+
attach === null ? " attach: none (managed account or platform provider \u2014 drive it through ComputeSDK)" : ` attach: ${attach.provider} / ${attach.providerSandboxId}${attach.region ? ` (${attach.region})` : ""}`
|
|
3424
3520
|
);
|
|
3425
3521
|
}
|
|
3426
3522
|
}
|
|
3427
|
-
var perHour = (n) => n === void 0 ? "\u2014" : formatRateAllUnits(rateAllUnits({ usd: n, per: "hour" }));
|
|
3428
3523
|
var usdAmount = (n) => n === void 0 ? "\u2014" : formatMoney(n);
|
|
3524
|
+
function walkEntry(entry) {
|
|
3525
|
+
if (entry.startsWith("managed/")) return `${entry.slice("managed/".length)} (managed)`;
|
|
3526
|
+
if (entry === "market" || entry.startsWith("market:")) return entry;
|
|
3527
|
+
return `${entry} (BYOK)`;
|
|
3528
|
+
}
|
|
3529
|
+
function quoteRefusal(q) {
|
|
3530
|
+
switch (q.reason) {
|
|
3531
|
+
case "insufficient_credits":
|
|
3532
|
+
return `not enough ComputeSDK credit for the hold (need ${usdAmount(q.requiredHoldUsd)}, have ${usdAmount(q.creditBalanceUsd)})`;
|
|
3533
|
+
case "no_provider_configured":
|
|
3534
|
+
return "nothing in the router can place this size: no live managed account prices it, and no BYOK key covers it";
|
|
3535
|
+
default:
|
|
3536
|
+
return q.reason ?? "nothing in the router can place it";
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3429
3539
|
function printQuote(q, timeoutMs) {
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
if (q.liveAskDepth !== void 0) console.log(` ${pc10.dim(`live asks: ${q.liveAskDepth}`)}`);
|
|
3540
|
+
const row = (label, value) => console.log(`${label.padEnd(10)} ${value}`);
|
|
3541
|
+
if (!q.ok || !q.placement) {
|
|
3542
|
+
row("Lands on", pc11.red(`nowhere \u2014 ${quoteRefusal(q)}`));
|
|
3543
|
+
if (q.reason === "insufficient_credits" && q.topUpPath) row("Top up", q.topUpPath);
|
|
3544
|
+
} else {
|
|
3545
|
+
const p2 = q.placement;
|
|
3546
|
+
const provider = p2.box?.provider ?? p2.provider;
|
|
3547
|
+
row("Lands on", `${provider} \xB7 ${placementLane(p2.source)} \xB7 ${p2.size ?? p2.box?.sizeName ?? "custom size"}`);
|
|
3548
|
+
row("Rate", q.rateUsd ? formatRateAllUnits(q.rateUsd) : q.rate ? formatUsdPer(q.rate) : "\u2014");
|
|
3549
|
+
if (p2.source === "own-key") {
|
|
3550
|
+
row("Billing", `billed by ${provider} to your account`);
|
|
3551
|
+
} else if (q.requiredHoldUsd !== void 0) {
|
|
3552
|
+
const timeout = timeoutMs !== void 0 ? ` for ${timeoutMs}ms` : " for the timeout";
|
|
3553
|
+
row("Billing", `from your ComputeSDK credit: ${usdAmount(q.requiredHoldUsd)} held${timeout}, settled at actual runtime (balance ${usdAmount(q.creditBalanceUsd)})`);
|
|
3554
|
+
} else {
|
|
3555
|
+
row("Billing", `from your ComputeSDK credit (balance ${usdAmount(q.creditBalanceUsd)})`);
|
|
3556
|
+
if (q.estimatedCostUsd !== void 0) row("Estimate", usdAmount(q.estimatedCostUsd));
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
row("Tries", q.providerOrder.map(walkEntry).join(" \u2192 ") || "\u2014");
|
|
3451
3560
|
}
|
|
3452
3561
|
function printProcess(p2) {
|
|
3453
3562
|
const exit = p2.status === "exited" ? `exit=${p2.exitCode ?? "?"}${p2.signal ? ` (${p2.signal})` : ""}` : "";
|
|
3454
3563
|
const stdin = p2.stdin && p2.status === "running" ? " [stdin open]" : "";
|
|
3455
|
-
console.log(`${
|
|
3564
|
+
console.log(`${pc11.cyan(p2.jobId)} ${p2.status}${exit ? " " + exit : ""}${stdin} ${p2.command}`);
|
|
3456
3565
|
}
|
|
3457
3566
|
function printSnapshot(s) {
|
|
3458
|
-
const state = s.deletedAt !== null ? ` ${
|
|
3459
|
-
console.log(`${
|
|
3567
|
+
const state = s.deletedAt !== null ? ` ${pc11.dim(`(deleted ${s.deletedAt})`)}` : "";
|
|
3568
|
+
console.log(`${pc11.cyan(s.id)} ${s.providerSnapshotId}${state}`);
|
|
3460
3569
|
console.log(
|
|
3461
3570
|
` provider: ${s.provider}${s.region ? ` (${s.region})` : ""} label: ${s.label ?? "\u2014"} created: ${s.createdAt}${s.expiresAt ? ` expires: ${s.expiresAt}` : ""}`
|
|
3462
3571
|
);
|
|
@@ -3559,7 +3668,7 @@ function resolveSandbox(argId, opts) {
|
|
|
3559
3668
|
if (!r) throw new Error(NO_INSTANCE_HINT);
|
|
3560
3669
|
if (r.source !== "argument" && !opts.json && !opts.quiet) {
|
|
3561
3670
|
console.error(
|
|
3562
|
-
|
|
3671
|
+
pc11.dim(
|
|
3563
3672
|
`instance ${shortId(r.id)} (${r.source === "env" ? "COMPUTE_INSTANCE" : `current for ${r.dir}`})`
|
|
3564
3673
|
)
|
|
3565
3674
|
);
|
|
@@ -3570,7 +3679,7 @@ function resolveSandbox(argId, opts) {
|
|
|
3570
3679
|
clearStale: (error) => {
|
|
3571
3680
|
if (r.source === "file" && error instanceof PlatformApiError && error.status === 404 && readFileCurrent(org2) === r.id) {
|
|
3572
3681
|
clearCurrentInstance(org2);
|
|
3573
|
-
console.error(
|
|
3682
|
+
console.error(pc11.dim(`cleared stale current instance ${shortId(r.id)}`));
|
|
3574
3683
|
}
|
|
3575
3684
|
}
|
|
3576
3685
|
};
|
|
@@ -3592,7 +3701,16 @@ function resolveTwoArgTarget(argId, resourceId, opts, label) {
|
|
|
3592
3701
|
return { resolved: resolveSandbox(argId, opts), resource: resourceId };
|
|
3593
3702
|
}
|
|
3594
3703
|
function addCreateFlags(c) {
|
|
3595
|
-
return c.option("--
|
|
3704
|
+
return c.option("--provider <names>", "place only on these providers, through your router (its BYOK mode and order), e.g. daytona or daytona,e2b").option("--byok", "use only your own keys for this create").option("--managed", "use only ComputeSDK managed accounts for this create").addOption(new Option3("--order <providers>").hideHelp()).option("--size <size>", "platform size: small (1 vCPU/2 GB), medium, large, xlarge (8/16 GB); default medium").option("--label <label>", "label for the sandbox").option("--image <image>", "container image to boot").option("--snapshot-id <id>", "provider snapshot to resume").option("--cpus <n>", "CPU cores (raw resources \u2014 mutually exclusive with --size)").option("--memory-mb <n>", "memory in MB (raw resources)").option("--disk-mb <n>", "ephemeral disk in MB (raw resources)").addOption(new Option3("--max-price <usd/unit>").hideHelp()).addOption(new Option3("--max-price-per <unit>").hideHelp()).addOption(new Option3("--market").hideHelp()).addOption(new Option3("--order-type <type>").hideHelp()).option("--timeout-ms <ms>", "sandbox timeout in ms (provider minimums apply, e.g. blaxel \u22655m)").option("--secret <name>", "vault secret name to inject (repeatable)", (v, a) => a.concat(v), []);
|
|
3705
|
+
}
|
|
3706
|
+
function providerNames(value) {
|
|
3707
|
+
const names = value.split(",").map((name) => name.trim()).filter(Boolean);
|
|
3708
|
+
if (names.length === 0) throw new Error(`--provider "${value}" names no providers.`);
|
|
3709
|
+
return names;
|
|
3710
|
+
}
|
|
3711
|
+
function accountMode(opts) {
|
|
3712
|
+
if (opts.byok && opts.managed) throw new Error("--byok and --managed are mutually exclusive.");
|
|
3713
|
+
return opts.byok ? "only" : opts.managed ? "off" : void 0;
|
|
3596
3714
|
}
|
|
3597
3715
|
function buildCreateBody(opts) {
|
|
3598
3716
|
const resources = {};
|
|
@@ -3600,6 +3718,15 @@ function buildCreateBody(opts) {
|
|
|
3600
3718
|
if (opts.memoryMb) resources.memoryMb = Number(opts.memoryMb);
|
|
3601
3719
|
if (opts.diskMb) resources.ephemeralDiskMb = Number(opts.diskMb);
|
|
3602
3720
|
const body = {};
|
|
3721
|
+
if (opts.provider && opts.order) {
|
|
3722
|
+
throw new Error("--provider narrows your router; --order skips it. Pass one.");
|
|
3723
|
+
}
|
|
3724
|
+
if (opts.provider) body.only = providerNames(opts.provider);
|
|
3725
|
+
const mode = accountMode(opts);
|
|
3726
|
+
if (mode !== void 0) {
|
|
3727
|
+
if (opts.order) throw new Error("--byok/--managed apply to your router; --order skips it.");
|
|
3728
|
+
body.byok = mode;
|
|
3729
|
+
}
|
|
3603
3730
|
if (opts.order) body.providerOrder = opts.order.split(",").map((s) => s.trim());
|
|
3604
3731
|
if (opts.size) body.size = opts.size;
|
|
3605
3732
|
if (opts.label) body.label = opts.label;
|
|
@@ -3642,19 +3769,25 @@ function listQuery(opts) {
|
|
|
3642
3769
|
cursor: opts.cursor
|
|
3643
3770
|
};
|
|
3644
3771
|
}
|
|
3645
|
-
function
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
).option("--no-use", "do not mark the new instance as this directory's current instance").option("-q, --quiet", "print only the new instance ID").option("--verbose", "print the full instance details").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("--json", "print the raw response").action(async (opts) => {
|
|
3772
|
+
function registerCreate(command2, { providerShorthand = false } = {}) {
|
|
3773
|
+
addCreateFlags(command2).option("--no-use", "do not mark the new instance as this directory's current instance").option("-q, --quiet", "print only the new instance ID").option("--verbose", "print the full instance details").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("--json", "print the raw response").action(async (...args) => {
|
|
3774
|
+
const operands = providerShorthand ? args[0] : [];
|
|
3775
|
+
const opts = args[providerShorthand ? 1 : 0];
|
|
3650
3776
|
try {
|
|
3651
3777
|
checkQuietJson(opts);
|
|
3778
|
+
const named = shorthandProviders(operands);
|
|
3779
|
+
if (named.length > 0) {
|
|
3780
|
+
if (opts.provider) throw new Error("Name providers either as words/flags or with --provider, not both.");
|
|
3781
|
+
opts.provider = named.join(",");
|
|
3782
|
+
}
|
|
3783
|
+
const body = buildCreateBody(opts);
|
|
3652
3784
|
const c = await client(opts);
|
|
3653
|
-
|
|
3785
|
+
if (!opts.json && !opts.quiet) await previewPlacement(c, opts);
|
|
3786
|
+
const res = await c.post("/api/v1/sandboxes", body);
|
|
3654
3787
|
if (opts.use !== false) {
|
|
3655
3788
|
setCurrentInstance(res.sandbox.id, orgKey(opts));
|
|
3656
3789
|
if (!opts.json && !opts.quiet) {
|
|
3657
|
-
console.error(
|
|
3790
|
+
console.error(pc11.dim(`instance ${shortId(res.sandbox.id)} (current for ${dirKey()})`));
|
|
3658
3791
|
}
|
|
3659
3792
|
}
|
|
3660
3793
|
emitResult(opts, res.sandbox, (s) => s.id, (s) => printSandbox(s, opts.verbose));
|
|
@@ -3662,35 +3795,87 @@ function registerSandboxesCommands(program2) {
|
|
|
3662
3795
|
fail(e, opts);
|
|
3663
3796
|
}
|
|
3664
3797
|
});
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3798
|
+
}
|
|
3799
|
+
async function previewPlacement(c, opts) {
|
|
3800
|
+
if (opts.order || opts.market || opts.orderType || opts.maxPrice) return;
|
|
3801
|
+
const mode = accountMode(opts);
|
|
3802
|
+
const params = {
|
|
3803
|
+
size: opts.size,
|
|
3804
|
+
cpus: opts.cpus,
|
|
3805
|
+
memoryMb: opts.memoryMb,
|
|
3806
|
+
ephemeralDiskMb: opts.diskMb,
|
|
3807
|
+
timeoutMs: opts.timeoutMs,
|
|
3808
|
+
only: opts.provider === void 0 ? void 0 : providerNames(opts.provider).join(","),
|
|
3809
|
+
byok: mode
|
|
3810
|
+
};
|
|
3811
|
+
let quote;
|
|
3812
|
+
try {
|
|
3813
|
+
quote = (await c.get("/api/v1/sandboxes/quote", params)).quote;
|
|
3814
|
+
} catch {
|
|
3815
|
+
return;
|
|
3816
|
+
}
|
|
3817
|
+
if (!quote.ok || !quote.placement) {
|
|
3818
|
+
console.error(pc11.dim(`\u2192 the router can't place this: ${quoteRefusal(quote)}`));
|
|
3819
|
+
return;
|
|
3820
|
+
}
|
|
3821
|
+
const p2 = quote.placement;
|
|
3822
|
+
const provider = p2.box?.provider ?? p2.provider;
|
|
3823
|
+
console.error(
|
|
3824
|
+
pc11.dim(`\u2192 placing on ${provider} \xB7 ${placementLane(p2.source)} \xB7 ${p2.size ?? p2.box?.sizeName ?? "custom size"} (${billedBy(p2.source, provider)}) \u2026`)
|
|
3825
|
+
);
|
|
3826
|
+
}
|
|
3827
|
+
function shorthandProviders(operands) {
|
|
3828
|
+
return operands.map((operand) => {
|
|
3829
|
+
const name = operand.startsWith("--") ? operand.slice(2) : operand;
|
|
3830
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) {
|
|
3831
|
+
throw new Error(`"${operand}" isn't a provider name \u2014 use e.g. \`compute new vercel\` or \`compute new --vercel\`.`);
|
|
3692
3832
|
}
|
|
3833
|
+
return name;
|
|
3693
3834
|
});
|
|
3835
|
+
}
|
|
3836
|
+
function registerSandboxesCommands(program2) {
|
|
3837
|
+
const cmd = program2.command("instances").alias("sandboxes").alias("sbx").description("Create and drive compute instances through the platform").enablePositionalOptions().configureOutput({ outputError: usageErrorOutput });
|
|
3838
|
+
registerCreate(
|
|
3839
|
+
cmd.command("create").description("Create a sandbox through your Sandboxes router (`compute sandboxes route` shows where it lands)")
|
|
3840
|
+
);
|
|
3841
|
+
registerCreate(
|
|
3842
|
+
program2.command("new").description("Create a sandbox (short for `compute sandboxes create`); `compute new vercel` or `--vercel` picks the provider").argument("[providers...]", "only these providers, through your router (vercel, --vercel, e2b, \u2026)").allowUnknownOption().configureOutput({ outputError: usageErrorOutput }),
|
|
3843
|
+
{ providerShorthand: true }
|
|
3844
|
+
);
|
|
3845
|
+
for (const name of ["route", "quote"]) {
|
|
3846
|
+
const command2 = cmd.command(name, { hidden: name === "quote" }).description("Show where a sandbox create would land, how it is billed, and the price \u2014 creates nothing").option("--size <size>", "platform size: small, medium (default), large, xlarge").option("--provider <names>", "only these providers, through your router (e.g. daytona)").option("--byok", "only your own keys").option("--managed", "only ComputeSDK managed accounts").option("--cpus <n>", "CPU cores (raw resources instead of --size)").option("--memory-mb <n>", "memory in MB").option("--disk-mb <n>", "ephemeral disk in MB").option("--region <region>", "pin the placement region").option("--timeout-ms <ms>", "sandbox timeout in ms; a managed account holds credit for it").addOption(new Option3("--order-type <type>").hideHelp()).addOption(new Option3("--market").hideHelp()).addOption(new Option3("--max-price <usd/unit>").hideHelp()).addOption(new Option3("--max-price-per <unit>").hideHelp()).option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response");
|
|
3847
|
+
command2.action(async (opts) => {
|
|
3848
|
+
try {
|
|
3849
|
+
const c = await client(opts);
|
|
3850
|
+
const params = {
|
|
3851
|
+
size: opts.size,
|
|
3852
|
+
only: opts.provider === void 0 ? void 0 : providerNames(opts.provider).join(","),
|
|
3853
|
+
byok: accountMode(opts),
|
|
3854
|
+
cpus: opts.cpus,
|
|
3855
|
+
memoryMb: opts.memoryMb,
|
|
3856
|
+
ephemeralDiskMb: opts.diskMb,
|
|
3857
|
+
region: opts.region,
|
|
3858
|
+
timeoutMs: opts.timeoutMs,
|
|
3859
|
+
orderType: opts.market ? "market" : opts.orderType
|
|
3860
|
+
};
|
|
3861
|
+
if (opts.orderType && opts.market) {
|
|
3862
|
+
throw new Error("--market and --order-type are mutually exclusive.");
|
|
3863
|
+
}
|
|
3864
|
+
const maxPrice = parseMaxPrice(opts.maxPrice, opts.maxPricePer);
|
|
3865
|
+
if (maxPrice) {
|
|
3866
|
+
params.maxPriceUsd = String(maxPrice.usd);
|
|
3867
|
+
params.maxPricePer = maxPrice.per;
|
|
3868
|
+
}
|
|
3869
|
+
const res = await c.get(
|
|
3870
|
+
"/api/v1/sandboxes/quote",
|
|
3871
|
+
params
|
|
3872
|
+
);
|
|
3873
|
+
output(opts, res.quote, (quote) => printQuote(quote, opts.timeoutMs));
|
|
3874
|
+
} catch (e) {
|
|
3875
|
+
fail(e, opts);
|
|
3876
|
+
}
|
|
3877
|
+
});
|
|
3878
|
+
}
|
|
3694
3879
|
cmd.command("list").description("List sandboxes").option("--status <status>", "active (not destroyed) | creating | running | destroyed").option("--customer-only", "exclude idle platform sandboxes (warm pool, CI sync, snapshot builds); Actions job sandboxes stay").option("--search <text>", "match label, id, provider, provider sandbox id or product (Sandboxes, Actions)").option("--sort <column>", "created (default, newest first) | name | cost | runtime").option("--direction <dir>", "asc | desc (default: asc for name, desc for the others)").option("--limit <n>", "page size").option("--cursor <cursor>", "page cursor from a previous response (pass the same --sort and --direction)").option("-q, --quiet", "print only instance IDs, one per line").option("--verbose", "print the full instance details").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (opts) => {
|
|
3695
3880
|
try {
|
|
3696
3881
|
checkQuietJson(opts);
|
|
@@ -3705,7 +3890,7 @@ function registerSandboxesCommands(program2) {
|
|
|
3705
3890
|
(page) => page.sandboxes.map((s) => s.id).join("\n"),
|
|
3706
3891
|
(page) => {
|
|
3707
3892
|
page.sandboxes.forEach((s) => printSandbox(s, opts.verbose));
|
|
3708
|
-
if (page.nextCursor) console.log(
|
|
3893
|
+
if (page.nextCursor) console.log(pc11.dim(`nextCursor: ${page.nextCursor}`));
|
|
3709
3894
|
}
|
|
3710
3895
|
);
|
|
3711
3896
|
} catch (e) {
|
|
@@ -3778,7 +3963,7 @@ function registerSandboxesCommands(program2) {
|
|
|
3778
3963
|
if (readFileCurrent(org2) === resolved.id) {
|
|
3779
3964
|
clearCurrentInstance(org2);
|
|
3780
3965
|
if (!opts.json) {
|
|
3781
|
-
console.error(
|
|
3966
|
+
console.error(pc11.dim(`cleared current instance ${shortId(resolved.id)}`));
|
|
3782
3967
|
}
|
|
3783
3968
|
}
|
|
3784
3969
|
output(opts, res.sandbox, printSandbox);
|
|
@@ -3971,7 +4156,7 @@ function registerSandboxesCommands(program2) {
|
|
|
3971
4156
|
data = opts.base64 ? piped.toString("base64") : piped.toString("utf8");
|
|
3972
4157
|
}
|
|
3973
4158
|
if (data === void 0 || data === "") {
|
|
3974
|
-
console.error(
|
|
4159
|
+
console.error(pc11.red("Pass --data, --file, or pipe stdin"));
|
|
3975
4160
|
process.exit(1);
|
|
3976
4161
|
}
|
|
3977
4162
|
if (opts.base64 && opts.data !== void 0) {
|
|
@@ -4019,7 +4204,7 @@ function registerSandboxesCommands(program2) {
|
|
|
4019
4204
|
output(opts, res, (view) => {
|
|
4020
4205
|
if (view.type === "directory") {
|
|
4021
4206
|
for (const e of view.entries) {
|
|
4022
|
-
console.log(`${e.type === "directory" ?
|
|
4207
|
+
console.log(`${e.type === "directory" ? pc11.blue("d") : " "} ${e.name}${e.size !== void 0 ? ` ${pc11.dim(String(e.size))}` : ""}`);
|
|
4023
4208
|
}
|
|
4024
4209
|
} else {
|
|
4025
4210
|
console.log(`${view.path} file ${view.content.length} chars`);
|
|
@@ -4046,7 +4231,7 @@ function registerSandboxesCommands(program2) {
|
|
|
4046
4231
|
const res = await c.get(`/api/v1/sandboxes/${resolved.id}/files`, { path: p2 });
|
|
4047
4232
|
output(opts, res, (view) => {
|
|
4048
4233
|
if (view.type !== "file") {
|
|
4049
|
-
console.error(
|
|
4234
|
+
console.error(pc11.red(`${view.path} is a directory`));
|
|
4050
4235
|
process.exit(1);
|
|
4051
4236
|
}
|
|
4052
4237
|
process.stdout.write(view.content);
|
|
@@ -4083,7 +4268,7 @@ function registerSandboxesCommands(program2) {
|
|
|
4083
4268
|
});
|
|
4084
4269
|
}
|
|
4085
4270
|
if (content === void 0) {
|
|
4086
|
-
console.error(
|
|
4271
|
+
console.error(pc11.red("Pass --content, --file, or pipe stdin"));
|
|
4087
4272
|
process.exit(1);
|
|
4088
4273
|
}
|
|
4089
4274
|
const c = await client(opts);
|
|
@@ -4219,11 +4404,11 @@ async function followProcess(c, sandboxId, jobId) {
|
|
|
4219
4404
|
exitCode = typeof payload.exitCode === "number" ? payload.exitCode : 128;
|
|
4220
4405
|
return finish();
|
|
4221
4406
|
} else if (event === "error") {
|
|
4222
|
-
console.error(
|
|
4407
|
+
console.error(pc11.red(`Error: ${String(payload.error ?? "stream error")}`));
|
|
4223
4408
|
return finish(1);
|
|
4224
4409
|
}
|
|
4225
4410
|
}
|
|
4226
|
-
console.error(
|
|
4411
|
+
console.error(pc11.yellow("stream ended before the process exited"));
|
|
4227
4412
|
return finish(2);
|
|
4228
4413
|
function finish(code) {
|
|
4229
4414
|
if (code !== void 0) exitCode = code;
|
|
@@ -4244,7 +4429,7 @@ async function runInstanceCommand(command2, opts) {
|
|
|
4244
4429
|
const created = await c.post("/api/v1/sandboxes", buildCreateBody(opts));
|
|
4245
4430
|
const sandbox = created.sandbox;
|
|
4246
4431
|
const org2 = orgKey(opts);
|
|
4247
|
-
console.error(
|
|
4432
|
+
console.error(pc11.dim(`instance ${sandbox.id}`));
|
|
4248
4433
|
const spawned = await c.post(
|
|
4249
4434
|
`/api/v1/sandboxes/${sandbox.id}/processes`,
|
|
4250
4435
|
{ command: command2.map(shellQuote).join(" ") }
|
|
@@ -4322,7 +4507,7 @@ async function runInstanceCommand(command2, opts) {
|
|
|
4322
4507
|
setCurrentInstance(sandbox.id, org2);
|
|
4323
4508
|
if (opts.quiet) console.log(sandbox.id);
|
|
4324
4509
|
else {
|
|
4325
|
-
console.error(
|
|
4510
|
+
console.error(pc11.dim(`kept instance ${shortId(sandbox.id)} (current for ${dirKey()})`));
|
|
4326
4511
|
console.log(sandbox.id);
|
|
4327
4512
|
}
|
|
4328
4513
|
} else {
|
|
@@ -4330,7 +4515,7 @@ async function runInstanceCommand(command2, opts) {
|
|
|
4330
4515
|
await c.del(`/api/v1/sandboxes/${sandbox.id}`);
|
|
4331
4516
|
} catch (e) {
|
|
4332
4517
|
console.error(
|
|
4333
|
-
|
|
4518
|
+
pc11.red(`destroy failed for ${sandbox.id}: ${e instanceof Error ? e.message : String(e)}`)
|
|
4334
4519
|
);
|
|
4335
4520
|
if (exitCode === null || exitCode === 0) exitCode = 1;
|
|
4336
4521
|
}
|
|
@@ -4358,7 +4543,7 @@ async function serveInstanceCommand(id, command2, port, opts) {
|
|
|
4358
4543
|
if (!opts.json) {
|
|
4359
4544
|
const logs = `${proc.stdout}${proc.stderr}`.trimEnd().split("\n");
|
|
4360
4545
|
if (logs.length > 0 && logs[0] !== "") {
|
|
4361
|
-
console.error(
|
|
4546
|
+
console.error(pc11.dim("--- last log lines ---"));
|
|
4362
4547
|
for (const line of logs.slice(-50)) console.error(safeTerm(line));
|
|
4363
4548
|
}
|
|
4364
4549
|
}
|
|
@@ -4413,9 +4598,9 @@ async function serveInstanceCommand(id, command2, port, opts) {
|
|
|
4413
4598
|
});
|
|
4414
4599
|
}
|
|
4415
4600
|
function printServeJobFooter(sandboxId, jobId) {
|
|
4416
|
-
console.error(
|
|
4417
|
-
console.error(
|
|
4418
|
-
console.error(
|
|
4601
|
+
console.error(pc11.dim(` job ${jobId}`));
|
|
4602
|
+
console.error(pc11.dim(` logs: compute instances logs ${sandboxId} ${jobId}`));
|
|
4603
|
+
console.error(pc11.dim(` kill: compute instances kill ${sandboxId} ${jobId}`));
|
|
4419
4604
|
}
|
|
4420
4605
|
var CP_PROGRESS_MIN_BYTES = 10 * 1024 * 1024;
|
|
4421
4606
|
function assertTransferUrl(raw) {
|
|
@@ -4573,7 +4758,7 @@ function formatBytes(n) {
|
|
|
4573
4758
|
}
|
|
4574
4759
|
|
|
4575
4760
|
// src/agents.ts
|
|
4576
|
-
import
|
|
4761
|
+
import pc12 from "picocolors";
|
|
4577
4762
|
import { readFileSync as readFileSync4 } from "fs";
|
|
4578
4763
|
function formatLocalTime2(iso) {
|
|
4579
4764
|
if (iso === null) return "\u2014";
|
|
@@ -4584,7 +4769,7 @@ function formatLocalTime2(iso) {
|
|
|
4584
4769
|
}
|
|
4585
4770
|
function printAgent(a) {
|
|
4586
4771
|
console.log(
|
|
4587
|
-
`${
|
|
4772
|
+
`${pc12.cyan(safeTerm(a.name))} ${a.id.slice(0, 8)} ${a.harness}${a.model ? ` ${safeTerm(a.model)}` : ""} sessions: ${a.sessionCount} created: ${formatLocalTime2(a.createdAt)}`
|
|
4588
4773
|
);
|
|
4589
4774
|
}
|
|
4590
4775
|
function printAgentDetail(a) {
|
|
@@ -4595,13 +4780,13 @@ function printAgentDetail(a) {
|
|
|
4595
4780
|
}
|
|
4596
4781
|
function printSession(s) {
|
|
4597
4782
|
console.log(
|
|
4598
|
-
`${
|
|
4783
|
+
`${pc12.cyan(s.id)} ${s.status} sandbox: ${s.sandboxId ?? "\u2014"} ${formatLocalTime2(s.createdAt)}${s.error ? ` ${pc12.red(safeTerm(s.error))}` : ""}`
|
|
4599
4784
|
);
|
|
4600
4785
|
}
|
|
4601
4786
|
function printEvent(e) {
|
|
4602
4787
|
const payload = e.payload ?? {};
|
|
4603
4788
|
if (e.kind === "user") {
|
|
4604
|
-
console.log(`${
|
|
4789
|
+
console.log(`${pc12.green("you")} #${e.seq} ${safeTerm(String(payload.message ?? ""))}`);
|
|
4605
4790
|
return;
|
|
4606
4791
|
}
|
|
4607
4792
|
if (e.kind === "turn") {
|
|
@@ -4609,12 +4794,12 @@ function printEvent(e) {
|
|
|
4609
4794
|
for (const ev of events) {
|
|
4610
4795
|
const o = ev;
|
|
4611
4796
|
const text = o.text ?? o.message ?? o.content;
|
|
4612
|
-
if (typeof text === "string") console.log(
|
|
4613
|
-
else console.log(
|
|
4797
|
+
if (typeof text === "string") console.log(pc12.dim(`#${e.seq}`) + ` ${safeTerm(text)}`);
|
|
4798
|
+
else console.log(pc12.dim(`#${e.seq} ${safeTerm(JSON.stringify(o))}`));
|
|
4614
4799
|
}
|
|
4615
4800
|
return;
|
|
4616
4801
|
}
|
|
4617
|
-
console.log(
|
|
4802
|
+
console.log(pc12.dim(`#${e.seq} ${e.kind} ${safeTerm(JSON.stringify(payload))}`));
|
|
4618
4803
|
}
|
|
4619
4804
|
function authOpts(cmd) {
|
|
4620
4805
|
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");
|
|
@@ -4665,7 +4850,7 @@ function registerAgentsCommands(program2) {
|
|
|
4665
4850
|
});
|
|
4666
4851
|
output(opts, res, (r) => {
|
|
4667
4852
|
printAgentDetail(r.agent);
|
|
4668
|
-
console.error(
|
|
4853
|
+
console.error(pc12.dim(`agent ${r.agent.name} created \u2014 run it with \`compute agents run ${r.agent.name} "\u2026"\``));
|
|
4669
4854
|
});
|
|
4670
4855
|
} catch (e) {
|
|
4671
4856
|
fail(e, opts);
|
|
@@ -4719,7 +4904,7 @@ function registerAgentsCommands(program2) {
|
|
|
4719
4904
|
const c = await client(opts);
|
|
4720
4905
|
if (!opts.yes) {
|
|
4721
4906
|
const res = await c.get(`/api/v1/agents/${encodeURIComponent(ref)}`);
|
|
4722
|
-
console.error(`Deleting agent ${
|
|
4907
|
+
console.error(`Deleting agent ${pc12.cyan(res.agent.name)} (${res.agent.id}). Pass -y to confirm.`);
|
|
4723
4908
|
process.exit(1);
|
|
4724
4909
|
}
|
|
4725
4910
|
await c.del(`/api/v1/agents/${encodeURIComponent(ref)}`);
|
|
@@ -4756,7 +4941,7 @@ function registerAgentsCommands(program2) {
|
|
|
4756
4941
|
output(opts, res, (r) => {
|
|
4757
4942
|
printSession(r.session);
|
|
4758
4943
|
for (const e of r.events) printEvent(e);
|
|
4759
|
-
console.error(
|
|
4944
|
+
console.error(pc12.dim(`session ${r.session.id} \u2014 continue with \`compute agents send ${r.session.id} "\u2026"\``));
|
|
4760
4945
|
});
|
|
4761
4946
|
} catch (e) {
|
|
4762
4947
|
fail(e, opts);
|
|
@@ -5152,7 +5337,7 @@ function registerManifestCommand(program2, options) {
|
|
|
5152
5337
|
}
|
|
5153
5338
|
|
|
5154
5339
|
// src/org-members.ts
|
|
5155
|
-
import
|
|
5340
|
+
import pc13 from "picocolors";
|
|
5156
5341
|
var ORG_PATH = "/api/v1/organizations/current";
|
|
5157
5342
|
var MEMBER_ROLES = ["member", "admin"];
|
|
5158
5343
|
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.";
|
|
@@ -5191,10 +5376,10 @@ function fail2(error, opts = {}) {
|
|
|
5191
5376
|
process.stderr.write(JSON.stringify(envelope) + "\n");
|
|
5192
5377
|
} else if (error instanceof PlatformApiError) {
|
|
5193
5378
|
const code = error.code !== codeForStatus(error.status) ? ` ${error.code}` : "";
|
|
5194
|
-
console.error(
|
|
5195
|
-
if (hint) console.error(
|
|
5379
|
+
console.error(pc13.red(`Error (${error.status}${code}): ${error.message}`));
|
|
5380
|
+
if (hint) console.error(pc13.dim(`hint: ${hint}`));
|
|
5196
5381
|
} else {
|
|
5197
|
-
console.error(
|
|
5382
|
+
console.error(pc13.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
5198
5383
|
}
|
|
5199
5384
|
process.exit(1);
|
|
5200
5385
|
}
|
|
@@ -5246,7 +5431,7 @@ function printUserInvitations(res) {
|
|
|
5246
5431
|
safeTerm(i.organization.name)
|
|
5247
5432
|
])
|
|
5248
5433
|
);
|
|
5249
|
-
console.log(
|
|
5434
|
+
console.log(pc13.dim("Accept with `compute invitations accept <id>`; decline with `compute invitations decline <id> -y`."));
|
|
5250
5435
|
}
|
|
5251
5436
|
function printInvitationDetail(inv) {
|
|
5252
5437
|
const rows = [
|
|
@@ -5267,7 +5452,7 @@ function printInvite(res) {
|
|
|
5267
5452
|
console.log(`Emailed ${safeTerm(inv.email)} the invitation link.`);
|
|
5268
5453
|
} else {
|
|
5269
5454
|
const reason = res.emailError ? ` (${safeTerm(res.emailError)})` : "";
|
|
5270
|
-
console.log(
|
|
5455
|
+
console.log(pc13.yellow(`The invitation email was not sent${reason}; share the link instead.`));
|
|
5271
5456
|
}
|
|
5272
5457
|
console.log(`Link: ${safeTerm(inv.url)}`);
|
|
5273
5458
|
}
|
|
@@ -5391,7 +5576,7 @@ function registerOrgMemberCommands(org2) {
|
|
|
5391
5576
|
output(opts, res, () => {
|
|
5392
5577
|
console.log(`Left ${org3 ?? "the organization"}.`);
|
|
5393
5578
|
console.log(
|
|
5394
|
-
|
|
5579
|
+
pc13.dim("If your login was granted for that organization, it no longer works: run `compute login` again.")
|
|
5395
5580
|
);
|
|
5396
5581
|
});
|
|
5397
5582
|
} catch (e) {
|
|
@@ -5430,7 +5615,7 @@ function registerInvitationsCommands(program2) {
|
|
|
5430
5615
|
output(opts, res, (r) => {
|
|
5431
5616
|
const slug = safeTerm(r.organization.slug);
|
|
5432
5617
|
console.log(`Joined ${slug} as ${safeTerm(r.member.role)}.`);
|
|
5433
|
-
console.log(
|
|
5618
|
+
console.log(pc13.dim(`Switch to it with \`compute org use ${slug}\`, or pass --org ${slug}.`));
|
|
5434
5619
|
});
|
|
5435
5620
|
} catch (e) {
|
|
5436
5621
|
fail2(e, opts);
|
|
@@ -5472,7 +5657,7 @@ process.stderr.on("error", (err) => {
|
|
|
5472
5657
|
if (err.code === "EPIPE") return;
|
|
5473
5658
|
throw err;
|
|
5474
5659
|
});
|
|
5475
|
-
var program = new
|
|
5660
|
+
var program = new Command4();
|
|
5476
5661
|
program.name("compute").description("ComputeSDK CLI").version(VERSION).enablePositionalOptions().passThroughOptions();
|
|
5477
5662
|
async function printSessionLine(options) {
|
|
5478
5663
|
try {
|
|
@@ -5504,18 +5689,18 @@ async function runLogout() {
|
|
|
5504
5689
|
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) => {
|
|
5505
5690
|
if (opts.logout) {
|
|
5506
5691
|
console.log();
|
|
5507
|
-
p.intro(
|
|
5692
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5508
5693
|
await runLogout();
|
|
5509
5694
|
p.log.success("Logged out. Stored credentials removed.");
|
|
5510
|
-
p.outro(
|
|
5695
|
+
p.outro(pc14.green("Done!"));
|
|
5511
5696
|
process.exit(0);
|
|
5512
5697
|
}
|
|
5513
5698
|
if (opts.login) {
|
|
5514
5699
|
console.log();
|
|
5515
|
-
p.intro(
|
|
5700
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5516
5701
|
await runLogin();
|
|
5517
5702
|
await printSessionLine();
|
|
5518
|
-
p.outro(
|
|
5703
|
+
p.outro(pc14.green("Authenticated!"));
|
|
5519
5704
|
process.exit(0);
|
|
5520
5705
|
}
|
|
5521
5706
|
program.help();
|
|
@@ -5526,23 +5711,23 @@ program.hook("preAction", (thisCommand) => {
|
|
|
5526
5711
|
});
|
|
5527
5712
|
program.command("providers").description("List all providers and their configuration status").action(async () => {
|
|
5528
5713
|
console.log();
|
|
5529
|
-
p.intro(
|
|
5714
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5530
5715
|
const statuses = getProviderStatus();
|
|
5531
5716
|
console.log();
|
|
5532
5717
|
for (const status of statuses) {
|
|
5533
|
-
const icon = status.ready ?
|
|
5534
|
-
const name = status.ready ?
|
|
5535
|
-
const detail = status.ready ?
|
|
5718
|
+
const icon = status.ready ? pc14.green("\u25CF") : pc14.gray("\u25CB");
|
|
5719
|
+
const name = status.ready ? pc14.white(status.name) : pc14.gray(status.name);
|
|
5720
|
+
const detail = status.ready ? pc14.green("ready") : pc14.gray(`missing: ${status.missing.join(", ")}`);
|
|
5536
5721
|
console.log(` ${icon} ${name} ${detail}`);
|
|
5537
5722
|
}
|
|
5538
5723
|
console.log();
|
|
5539
5724
|
});
|
|
5540
5725
|
program.command("login").description("Authenticate with ComputeSDK (OAuth device flow)").option("--base-url <url>", "platform URL to authenticate against").action(async (opts) => {
|
|
5541
5726
|
console.log();
|
|
5542
|
-
p.intro(
|
|
5727
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5543
5728
|
await runLogin({ baseUrl: opts.baseUrl });
|
|
5544
5729
|
await printSessionLine({ baseUrl: opts.baseUrl });
|
|
5545
|
-
p.outro(
|
|
5730
|
+
p.outro(pc14.green("Authenticated!"));
|
|
5546
5731
|
});
|
|
5547
5732
|
program.command("logout").description("Clear stored credentials").option("--json", "print machine-readable JSON").action(async (opts) => {
|
|
5548
5733
|
await runLogout();
|
|
@@ -5551,9 +5736,9 @@ program.command("logout").description("Clear stored credentials").option("--json
|
|
|
5551
5736
|
return;
|
|
5552
5737
|
}
|
|
5553
5738
|
console.log();
|
|
5554
|
-
p.intro(
|
|
5739
|
+
p.intro(pc14.cyan(`@computesdk/cli v${VERSION}`));
|
|
5555
5740
|
p.log.success("Logged out. Stored credentials removed.");
|
|
5556
|
-
p.outro(
|
|
5741
|
+
p.outro(pc14.green("Done!"));
|
|
5557
5742
|
});
|
|
5558
5743
|
async function printWhoami(options = {}) {
|
|
5559
5744
|
const me = await fetchWhoami(await benchAuth({ baseUrl: options.baseUrl }));
|
|
@@ -5573,8 +5758,8 @@ org.command("list").description("List your organizations").option("--json", "pri
|
|
|
5573
5758
|
return;
|
|
5574
5759
|
}
|
|
5575
5760
|
for (const o of organizations) {
|
|
5576
|
-
const marker = o.id === me.activeOrganizationId ?
|
|
5577
|
-
console.log(`${marker} ${
|
|
5761
|
+
const marker = o.id === me.activeOrganizationId ? pc14.green("*") : " ";
|
|
5762
|
+
console.log(`${marker} ${pc14.cyan(o.slug)} ${o.name ?? ""} ${pc14.dim(o.id)}`);
|
|
5578
5763
|
}
|
|
5579
5764
|
});
|
|
5580
5765
|
org.command("use <slug>").description("Set the active organization (persisted to the stored login)").action(async (slug) => {
|
|
@@ -5610,6 +5795,7 @@ registerInvitationsCommands(program);
|
|
|
5610
5795
|
registerActionsCommands(program);
|
|
5611
5796
|
registerByokCommands(program);
|
|
5612
5797
|
registerMarketCommands(program);
|
|
5798
|
+
registerCreditsCommands(program);
|
|
5613
5799
|
registerSandboxesCommands(program);
|
|
5614
5800
|
registerAgentsCommands(program);
|
|
5615
5801
|
program.command("bench").description("Benchmarks platform CLI (run, auth, org, benchmarks, runs, results, fork, artifacts, export, ...)").allowUnknownOption().helpOption(false).action(() => {
|
|
@@ -5627,7 +5813,7 @@ async function main() {
|
|
|
5627
5813
|
await program.parseAsync(process.argv);
|
|
5628
5814
|
}
|
|
5629
5815
|
main().catch((error) => {
|
|
5630
|
-
console.error(
|
|
5816
|
+
console.error(pc14.red(`
|
|
5631
5817
|
Error: ${error.message}`));
|
|
5632
5818
|
process.exit(1);
|
|
5633
5819
|
});
|