@computesdk/cli 2.6.5 → 2.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
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
7
  import pc13 from "picocolors";
8
8
  import { readFileSync as readFileSync6 } from "fs";
@@ -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 fmtRate = (cap) => cap ? formatUsdPer(cap) : "\u2014";
271
- var fmtRef = (ref) => ref ? ` ${pc2.dim(`reference ${formatUsdPer(ref)}`)}` : "";
272
- function printLaneSettings(s, lane) {
273
- const sandbox = lane === "sandboxes";
274
- const orderType = s.marketOrderType ?? (sandbox ? "inherit" : "\u2014");
275
- const orderSuffix = sandbox && s.marketOrderType == null ? pc2.dim(` (Actions: ${s.actionsMarketOrderType ?? "\u2014"})`) : "";
276
- console.log(`order type: ${orderType}${orderSuffix}`);
277
- const capSuffix = sandbox && s.marketCap == null ? pc2.dim(` (inherits Actions: ${fmtRate(s.actionsMarketCap)})`) : "";
278
- console.log(`general cap: ${fmtRate(s.marketCap)}${capSuffix}`);
279
- console.log("per-size caps:");
280
- for (const size of PLATFORM_SIZES) {
281
- const cap = s.marketCaps?.[size];
282
- console.log(
283
- ` ${size.padEnd(7)} ${fmtRate(cap)}${cap ? "" : fmtRef(s.referencePrices?.[size])}`
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
- const orderText2 = s.providerOrder.length > 0 ? s.providerOrder.join(", ") : sandbox ? pc2.dim(`inherit (Actions: ${(s.actionsProviderOrder ?? []).join(", ") || "\u2014"})`) : s.defaultProviderOrder && s.defaultProviderOrder.length > 0 ? pc2.dim(`default (${s.defaultProviderOrder.join(", ")})`) : "\u2014";
287
- console.log(`provider order: ${orderText2}`);
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 org's ${lane} routing policy (order, caps, sizes, pools)`).configureOutput({
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
- const c = await deps.client(opts);
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(`Update the org's ${lane} routing policy`).option(
350
- "--cap <size=rate>",
351
- "per-size cap: <size>=<usd>/<unit> or <size>=none to clear (repeatable)",
352
- (v, a) => a.concat(v),
353
- []
354
- ).option("--general-cap <rate|none>", 'whole-lane price cap (e.g. 0.40/hour); "none" clears it').option(
355
- "--order-type <type>",
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 placement entry, 0..${MAX_WARM_POOL_SIZE}; 0 clears it (repeatable)`,
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 placement entry, 0..${MAX_SNAPSHOT_POOL_SIZE}; 0 clears it (repeatable)`,
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 body = {};
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
- body.marketCaps = caps;
386
+ settingsBody.marketCaps = caps;
391
387
  }
392
388
  if (opts.generalCap !== void 0) {
393
- body.marketCap = opts.generalCap === "none" ? null : parseMaxPrice(opts.generalCap, void 0);
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
- body.marketOrderType = null;
393
+ settingsBody.marketOrderType = null;
398
394
  } else if (opts.orderType === "limit" || opts.orderType === "market") {
399
- body.marketOrderType = opts.orderType;
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
- body.providerResources = resources;
406
+ settingsBody.providerResources = resources;
427
407
  }
428
408
  if (opts.warmPool && opts.warmPool.length > 0) {
429
- body.warmPool = poolPatch(opts.warmPool, parseWarmPoolFlag);
409
+ settingsBody.warmPool = poolPatch(opts.warmPool, parseWarmPoolFlag);
430
410
  }
431
411
  if (opts.snapshotPool && opts.snapshotPool.length > 0) {
432
- body.snapshotPool = poolPatch(opts.snapshotPool, parseSnapshotPoolFlag);
412
+ settingsBody.snapshotPool = poolPatch(opts.snapshotPool, parseSnapshotPoolFlag);
433
413
  }
434
- if (Object.keys(body).length === 0) {
414
+ if (Object.keys(routing).length > 0 && Object.keys(settingsBody).length > 0) {
435
415
  throw new Error(
436
- lane === "sandboxes" ? "Nothing to change \u2014 pass --cap, --general-cap, --order-type, --order, --resources, or --warm-pool." : "Nothing to change \u2014 pass --cap, --general-cap, --order-type, --order, --resources, --warm-pool, or --snapshot-pool."
416
+ "Change routing (--routing, --byok, --byok-order) and sizes or pools in separate commands."
417
+ );
418
+ }
419
+ if (Object.keys(routing).length === 0 && Object.keys(settingsBody).length === 0) {
420
+ throw new Error(
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
- const res = await c.patch(`/api/v1/${lane}/settings`, body);
441
- deps.output(opts, res, (s) => printLaneSettings(s, lane));
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>", 'provider order for this workflow, comma-separated (e.g. "market,blaxel,vercel")').option("--inherit-order", "drop the workflow's order: it follows the org order").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")
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 org provider order").option("--provider-region <region>", "region for --provider (same as --provider <id>:<region>)").option("--max-bid <usd>", "max price per vCPU for a market fill (e.g. 0.12); unfilled jobs fall through to the next provider").option("--max-bid-per <unit>", "time unit --max-bid is priced in: second, minute, or hour (default: second)").option("--with-changes", "run your local changes: everything the working tree has beyond origin/<ref> is sent as a diff and applied after checkout (default --ref: the current branch)")
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 = "") {
@@ -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")
@@ -3229,6 +3256,7 @@ import * as os from "os";
3229
3256
  import * as path from "path";
3230
3257
  import * as readline from "readline";
3231
3258
  import { Readable } from "stream";
3259
+ import { Option as Option3 } from "commander";
3232
3260
  import pc10 from "picocolors";
3233
3261
  import * as tar from "tar";
3234
3262
 
@@ -3391,6 +3419,16 @@ function shellQuote(arg) {
3391
3419
  function shortRate(rate) {
3392
3420
  return `${formatUsd(rateAllUnits(rate).perHour)}/h`;
3393
3421
  }
3422
+ function placementLane(source) {
3423
+ if (source === "house") return "managed";
3424
+ if (source === "own-key") return "BYOK";
3425
+ return source ?? "\u2014";
3426
+ }
3427
+ function billedBy(source, provider) {
3428
+ if (source === "house") return "billed from your ComputeSDK credit";
3429
+ if (source === "own-key") return `billed by ${provider} to your account`;
3430
+ return "billed from your ComputeSDK credit";
3431
+ }
3394
3432
  function formatLocalTime(iso) {
3395
3433
  const d = new Date(iso);
3396
3434
  if (Number.isNaN(d.getTime())) return iso;
@@ -3400,7 +3438,7 @@ function formatLocalTime(iso) {
3400
3438
  function printSandbox(s, verbose = false) {
3401
3439
  const p2 = s.placement;
3402
3440
  console.log(
3403
- `${pc10.cyan(s.id)} ${s.status} ${p2?.box?.provider ?? s.provider ?? "\u2014"} ${p2?.size ?? "\u2014"} ${p2 ? shortRate(p2.rate) : "\u2014"}`
3441
+ `${pc10.cyan(s.id)} ${s.status} ${p2?.box?.provider ?? s.provider ?? "\u2014"} \xB7 ${placementLane(p2?.source)} ${p2?.size ?? "\u2014"} ${p2 ? shortRate(p2.rate) : "\u2014"}`
3404
3442
  );
3405
3443
  if (s.label) {
3406
3444
  console.log(` label: ${s.label} created: ${formatLocalTime(s.createdAt)}`);
@@ -3413,41 +3451,55 @@ function printSandbox(s, verbose = false) {
3413
3451
  }
3414
3452
  if (p2) {
3415
3453
  const box = p2.box ? ` / ${p2.box.sizeName ?? "custom"}${p2.box.resources ? ` (${p2.box.resources.cpus ?? "?"} vCPU / ${p2.box.resources.memoryMb ?? "?"} MB)` : ""}` : "";
3454
+ const provider = p2.box?.provider ?? s.provider ?? "the provider";
3416
3455
  console.log(
3417
- ` placement: ${p2.source}${box} order: ${p2.orderType ?? "\u2014"} rate: ${formatUsdPer(p2.rate)}${p2.maxPrice ? ` max price: ${formatUsdPer(p2.maxPrice)}` : ""}`
3456
+ ` placement: ${placementLane(p2.source)}${box} rate: ${formatUsdPer(p2.rate)} ${pc10.dim(billedBy(p2.source, provider))}`
3418
3457
  );
3419
3458
  }
3420
3459
  const attach = "attach" in s ? s.attach : void 0;
3421
3460
  if (attach !== void 0) {
3422
3461
  console.log(
3423
- attach === null ? " attach: none (market fill or ambient provider \u2014 platform drive only)" : ` attach: ${attach.provider} / ${attach.providerSandboxId}${attach.region ? ` (${attach.region})` : ""}`
3462
+ attach === null ? " attach: none (managed account or platform provider \u2014 drive it through ComputeSDK)" : ` attach: ${attach.provider} / ${attach.providerSandboxId}${attach.region ? ` (${attach.region})` : ""}`
3424
3463
  );
3425
3464
  }
3426
3465
  }
3427
- var perHour = (n) => n === void 0 ? "\u2014" : formatRateAllUnits(rateAllUnits({ usd: n, per: "hour" }));
3428
3466
  var usdAmount = (n) => n === void 0 ? "\u2014" : formatMoney(n);
3467
+ function walkEntry(entry) {
3468
+ if (entry.startsWith("managed/")) return `${entry.slice("managed/".length)} (managed)`;
3469
+ if (entry === "market" || entry.startsWith("market:")) return entry;
3470
+ return `${entry} (BYOK)`;
3471
+ }
3472
+ function quoteRefusal(q) {
3473
+ switch (q.reason) {
3474
+ case "insufficient_credits":
3475
+ return `not enough ComputeSDK credit for the hold (need ${usdAmount(q.requiredHoldUsd)}, have ${usdAmount(q.creditBalanceUsd)})`;
3476
+ case "no_provider_configured":
3477
+ return "nothing in the router can place this size: no live managed account prices it, and no BYOK key covers it";
3478
+ default:
3479
+ return q.reason ?? "nothing in the router can place it";
3480
+ }
3481
+ }
3429
3482
  function printQuote(q, timeoutMs) {
3430
- console.log(`quote: ${q.ok ? pc10.green("ok") : pc10.red(q.reason ?? "unfillable")}`);
3431
- const box = q.placement?.box;
3432
- console.log(
3433
- ` size: ${q.placement?.size ?? "\u2014"} provider: ${q.placement?.provider ?? "\u2014"}` + (box ? ` box: ${box.sizeName ?? "custom"} (${box.provider}${box.resources ? `, ${box.resources.cpus ?? "?"} vCPU / ${box.resources.memoryMb ?? "?"} MB` : ""})` : "")
3434
- );
3435
- console.log(` order type: ${q.orderType} order: ${q.providerOrder.join(", ")}`);
3436
- if (q.rateUsd) {
3437
- console.log(` rate: ${formatRateAllUnits(q.rateUsd)}`);
3438
- } else if (q.rate) {
3439
- console.log(` rate: ${formatUsdPer(q.rate)}`);
3440
- }
3441
- console.log(` cheapest live: ${perHour(q.cheapestLiveUsdPerHour)}`);
3442
- console.log(` reference: ${perHour(q.referenceUsdPerHour)}`);
3443
- const timeout = timeoutMs !== void 0 ? ` for ${timeoutMs}ms` : "";
3444
- console.log(
3445
- ` est. cost${timeout}: ${usdAmount(q.estimatedCostUsd)} required hold: ${usdAmount(q.requiredHoldUsd)} balance: ${usdAmount(q.creditBalanceUsd)}`
3446
- );
3447
- console.log(` cap: ${q.maxPrice ? formatUsdPer(q.maxPrice) : perHour(q.marketCapUsdPerHour)}`);
3448
- console.log(` protection limit: ${perHour(q.protectionLimitUsdPerHour)}`);
3449
- if (!q.ok && q.topUpPath) console.log(` ${pc10.dim(`\u2192 ${q.topUpPath}`)}`);
3450
- if (q.liveAskDepth !== void 0) console.log(` ${pc10.dim(`live asks: ${q.liveAskDepth}`)}`);
3483
+ const row = (label, value) => console.log(`${label.padEnd(10)} ${value}`);
3484
+ if (!q.ok || !q.placement) {
3485
+ row("Lands on", pc10.red(`nowhere \u2014 ${quoteRefusal(q)}`));
3486
+ if (q.reason === "insufficient_credits" && q.topUpPath) row("Top up", q.topUpPath);
3487
+ } else {
3488
+ const p2 = q.placement;
3489
+ const provider = p2.box?.provider ?? p2.provider;
3490
+ row("Lands on", `${provider} \xB7 ${placementLane(p2.source)} \xB7 ${p2.size ?? p2.box?.sizeName ?? "custom size"}`);
3491
+ row("Rate", q.rateUsd ? formatRateAllUnits(q.rateUsd) : q.rate ? formatUsdPer(q.rate) : "\u2014");
3492
+ if (p2.source === "own-key") {
3493
+ row("Billing", `billed by ${provider} to your account`);
3494
+ } else if (q.requiredHoldUsd !== void 0) {
3495
+ const timeout = timeoutMs !== void 0 ? ` for ${timeoutMs}ms` : " for the timeout";
3496
+ row("Billing", `from your ComputeSDK credit: ${usdAmount(q.requiredHoldUsd)} held${timeout}, settled at actual runtime (balance ${usdAmount(q.creditBalanceUsd)})`);
3497
+ } else {
3498
+ row("Billing", `from your ComputeSDK credit (balance ${usdAmount(q.creditBalanceUsd)})`);
3499
+ if (q.estimatedCostUsd !== void 0) row("Estimate", usdAmount(q.estimatedCostUsd));
3500
+ }
3501
+ }
3502
+ row("Tries", q.providerOrder.map(walkEntry).join(" \u2192 ") || "\u2014");
3451
3503
  }
3452
3504
  function printProcess(p2) {
3453
3505
  const exit = p2.status === "exited" ? `exit=${p2.exitCode ?? "?"}${p2.signal ? ` (${p2.signal})` : ""}` : "";
@@ -3592,7 +3644,16 @@ function resolveTwoArgTarget(argId, resourceId, opts, label) {
3592
3644
  return { resolved: resolveSandbox(argId, opts), resource: resourceId };
3593
3645
  }
3594
3646
  function addCreateFlags(c) {
3595
- return c.option("--order <providers>", 'provider order, comma-separated (e.g. "market,blaxel,vercel")').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)").option("--max-price <usd/unit>", "max price for a market fill (e.g. 0.12/hour); makes the create a limit order").option("--max-price-per <unit>", "unit for a bare --max-price usd (second, minute, or hour)").option("--market", 'place the create on the compute market (order type "market")').option("--order-type <type>", "explicit market order type: market or limit").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), []);
3647
+ 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), []);
3648
+ }
3649
+ function providerNames(value) {
3650
+ const names = value.split(",").map((name) => name.trim()).filter(Boolean);
3651
+ if (names.length === 0) throw new Error(`--provider "${value}" names no providers.`);
3652
+ return names;
3653
+ }
3654
+ function accountMode(opts) {
3655
+ if (opts.byok && opts.managed) throw new Error("--byok and --managed are mutually exclusive.");
3656
+ return opts.byok ? "only" : opts.managed ? "off" : void 0;
3596
3657
  }
3597
3658
  function buildCreateBody(opts) {
3598
3659
  const resources = {};
@@ -3600,6 +3661,15 @@ function buildCreateBody(opts) {
3600
3661
  if (opts.memoryMb) resources.memoryMb = Number(opts.memoryMb);
3601
3662
  if (opts.diskMb) resources.ephemeralDiskMb = Number(opts.diskMb);
3602
3663
  const body = {};
3664
+ if (opts.provider && opts.order) {
3665
+ throw new Error("--provider narrows your router; --order skips it. Pass one.");
3666
+ }
3667
+ if (opts.provider) body.only = providerNames(opts.provider);
3668
+ const mode = accountMode(opts);
3669
+ if (mode !== void 0) {
3670
+ if (opts.order) throw new Error("--byok/--managed apply to your router; --order skips it.");
3671
+ body.byok = mode;
3672
+ }
3603
3673
  if (opts.order) body.providerOrder = opts.order.split(",").map((s) => s.trim());
3604
3674
  if (opts.size) body.size = opts.size;
3605
3675
  if (opts.label) body.label = opts.label;
@@ -3642,15 +3712,21 @@ function listQuery(opts) {
3642
3712
  cursor: opts.cursor
3643
3713
  };
3644
3714
  }
3645
- function registerSandboxesCommands(program2) {
3646
- const cmd = program2.command("instances").alias("sandboxes").alias("sbx").description("Create and drive compute instances through the platform").enablePositionalOptions().configureOutput({ outputError: usageErrorOutput });
3647
- addCreateFlags(
3648
- cmd.command("create").description('Place a sandbox (provider order walks 1,2,3; "market" bids first)')
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) => {
3715
+ function registerCreate(command2, { providerShorthand = false } = {}) {
3716
+ 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) => {
3717
+ const operands = providerShorthand ? args[0] : [];
3718
+ const opts = args[providerShorthand ? 1 : 0];
3650
3719
  try {
3651
3720
  checkQuietJson(opts);
3721
+ const named = shorthandProviders(operands);
3722
+ if (named.length > 0) {
3723
+ if (opts.provider) throw new Error("Name providers either as words/flags or with --provider, not both.");
3724
+ opts.provider = named.join(",");
3725
+ }
3726
+ const body = buildCreateBody(opts);
3652
3727
  const c = await client(opts);
3653
- const res = await c.post("/api/v1/sandboxes", buildCreateBody(opts));
3728
+ if (!opts.json && !opts.quiet) await previewPlacement(c, opts);
3729
+ const res = await c.post("/api/v1/sandboxes", body);
3654
3730
  if (opts.use !== false) {
3655
3731
  setCurrentInstance(res.sandbox.id, orgKey(opts));
3656
3732
  if (!opts.json && !opts.quiet) {
@@ -3662,35 +3738,87 @@ function registerSandboxesCommands(program2) {
3662
3738
  fail(e, opts);
3663
3739
  }
3664
3740
  });
3665
- cmd.command("quote").description("Quote a sandbox create: placement, rate, caps and credits \u2014 creates nothing").option("--size <size>", "platform size (or raw resource flags; default medium)").option("--cpus <n>", "CPU cores").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 (provider minimums apply, e.g. blaxel \u22655m)").option("--order-type <type>", "market order type: market or limit").option("--market", "quote a market order (fills at the live price, protection-bounded)").option("--max-price <usd/unit>", "max price for a market fill (e.g. 0.12/hour)").option("--max-price-per <unit>", "unit for a bare --max-price usd (second, minute, or hour)").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (opts) => {
3666
- try {
3667
- const c = await client(opts);
3668
- const params = {
3669
- size: opts.size,
3670
- cpus: opts.cpus,
3671
- memoryMb: opts.memoryMb,
3672
- ephemeralDiskMb: opts.diskMb,
3673
- region: opts.region,
3674
- timeoutMs: opts.timeoutMs,
3675
- orderType: opts.market ? "market" : opts.orderType
3676
- };
3677
- if (opts.orderType && opts.market) {
3678
- throw new Error("--market and --order-type are mutually exclusive.");
3679
- }
3680
- const maxPrice = parseMaxPrice(opts.maxPrice, opts.maxPricePer);
3681
- if (maxPrice) {
3682
- params.maxPriceUsd = String(maxPrice.usd);
3683
- params.maxPricePer = maxPrice.per;
3684
- }
3685
- const res = await c.get(
3686
- "/api/v1/sandboxes/quote",
3687
- params
3688
- );
3689
- output(opts, res.quote, (quote) => printQuote(quote, opts.timeoutMs));
3690
- } catch (e) {
3691
- fail(e, opts);
3741
+ }
3742
+ async function previewPlacement(c, opts) {
3743
+ if (opts.order || opts.market || opts.orderType || opts.maxPrice) return;
3744
+ const mode = accountMode(opts);
3745
+ const params = {
3746
+ size: opts.size,
3747
+ cpus: opts.cpus,
3748
+ memoryMb: opts.memoryMb,
3749
+ ephemeralDiskMb: opts.diskMb,
3750
+ timeoutMs: opts.timeoutMs,
3751
+ only: opts.provider === void 0 ? void 0 : providerNames(opts.provider).join(","),
3752
+ byok: mode
3753
+ };
3754
+ let quote;
3755
+ try {
3756
+ quote = (await c.get("/api/v1/sandboxes/quote", params)).quote;
3757
+ } catch {
3758
+ return;
3759
+ }
3760
+ if (!quote.ok || !quote.placement) {
3761
+ console.error(pc10.dim(`\u2192 the router can't place this: ${quoteRefusal(quote)}`));
3762
+ return;
3763
+ }
3764
+ const p2 = quote.placement;
3765
+ const provider = p2.box?.provider ?? p2.provider;
3766
+ console.error(
3767
+ pc10.dim(`\u2192 placing on ${provider} \xB7 ${placementLane(p2.source)} \xB7 ${p2.size ?? p2.box?.sizeName ?? "custom size"} (${billedBy(p2.source, provider)}) \u2026`)
3768
+ );
3769
+ }
3770
+ function shorthandProviders(operands) {
3771
+ return operands.map((operand) => {
3772
+ const name = operand.startsWith("--") ? operand.slice(2) : operand;
3773
+ if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) {
3774
+ throw new Error(`"${operand}" isn't a provider name \u2014 use e.g. \`compute new vercel\` or \`compute new --vercel\`.`);
3692
3775
  }
3776
+ return name;
3693
3777
  });
3778
+ }
3779
+ function registerSandboxesCommands(program2) {
3780
+ const cmd = program2.command("instances").alias("sandboxes").alias("sbx").description("Create and drive compute instances through the platform").enablePositionalOptions().configureOutput({ outputError: usageErrorOutput });
3781
+ registerCreate(
3782
+ cmd.command("create").description("Create a sandbox through your Sandboxes router (`compute sandboxes route` shows where it lands)")
3783
+ );
3784
+ registerCreate(
3785
+ 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 }),
3786
+ { providerShorthand: true }
3787
+ );
3788
+ for (const name of ["route", "quote"]) {
3789
+ 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");
3790
+ command2.action(async (opts) => {
3791
+ try {
3792
+ const c = await client(opts);
3793
+ const params = {
3794
+ size: opts.size,
3795
+ only: opts.provider === void 0 ? void 0 : providerNames(opts.provider).join(","),
3796
+ byok: accountMode(opts),
3797
+ cpus: opts.cpus,
3798
+ memoryMb: opts.memoryMb,
3799
+ ephemeralDiskMb: opts.diskMb,
3800
+ region: opts.region,
3801
+ timeoutMs: opts.timeoutMs,
3802
+ orderType: opts.market ? "market" : opts.orderType
3803
+ };
3804
+ if (opts.orderType && opts.market) {
3805
+ throw new Error("--market and --order-type are mutually exclusive.");
3806
+ }
3807
+ const maxPrice = parseMaxPrice(opts.maxPrice, opts.maxPricePer);
3808
+ if (maxPrice) {
3809
+ params.maxPriceUsd = String(maxPrice.usd);
3810
+ params.maxPricePer = maxPrice.per;
3811
+ }
3812
+ const res = await c.get(
3813
+ "/api/v1/sandboxes/quote",
3814
+ params
3815
+ );
3816
+ output(opts, res.quote, (quote) => printQuote(quote, opts.timeoutMs));
3817
+ } catch (e) {
3818
+ fail(e, opts);
3819
+ }
3820
+ });
3821
+ }
3694
3822
  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
3823
  try {
3696
3824
  checkQuietJson(opts);
@@ -5472,7 +5600,7 @@ process.stderr.on("error", (err) => {
5472
5600
  if (err.code === "EPIPE") return;
5473
5601
  throw err;
5474
5602
  });
5475
- var program = new Command();
5603
+ var program = new Command4();
5476
5604
  program.name("compute").description("ComputeSDK CLI").version(VERSION).enablePositionalOptions().passThroughOptions();
5477
5605
  async function printSessionLine(options) {
5478
5606
  try {