@computesdk/cli 1.0.14 → 1.0.16

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
@@ -2474,16 +2474,27 @@ function printSandbox(s) {
2474
2474
  const attach = "attach" in s ? s.attach : void 0;
2475
2475
  console.log(`${pc3.cyan(s.id)} ${s.status} ${s.provider ?? "\u2014"} ${s.providerSandboxId ?? "\u2014"}`);
2476
2476
  console.log(` label: ${s.label ?? "\u2014"} commands: ${s.commandCount} created: ${s.createdAt}`);
2477
+ if (s.image !== void 0) {
2478
+ console.log(` image: ${s.image ?? "\u2014"}${s.requestedImage !== null && s.requestedImage !== s.image ? ` ${pc3.dim(`(requested: ${s.requestedImage})`)}` : ""}`);
2479
+ }
2477
2480
  if (s.destroyError) console.log(` destroyError: ${pc3.red(s.destroyError)}`);
2478
2481
  if (attach !== void 0) {
2479
2482
  console.log(
2480
- attach === null ? " attach: none (market fill or ambient provider \u2014 platform drive only)" : ` attach: ${attach.provider} / ${attach.providerSandboxId}`
2483
+ attach === null ? " attach: none (market fill or ambient provider \u2014 platform drive only)" : ` attach: ${attach.provider} / ${attach.providerSandboxId}${attach.region ? ` (${attach.region})` : ""}`
2481
2484
  );
2482
2485
  }
2483
2486
  }
2484
2487
  function printProcess(p5) {
2485
2488
  const exit = p5.status === "exited" ? `exit=${p5.exitCode ?? "?"}${p5.signal ? ` (${p5.signal})` : ""}` : "";
2486
- console.log(`${pc3.cyan(p5.jobId)} ${p5.status}${exit ? " " + exit : ""} ${p5.command}`);
2489
+ const stdin = p5.stdin && p5.status === "running" ? " [stdin open]" : "";
2490
+ console.log(`${pc3.cyan(p5.jobId)} ${p5.status}${exit ? " " + exit : ""}${stdin} ${p5.command}`);
2491
+ }
2492
+ function printSnapshot(s) {
2493
+ const state = s.deletedAt !== null ? ` ${pc3.dim(`(deleted ${s.deletedAt})`)}` : "";
2494
+ console.log(`${pc3.cyan(s.id)} ${s.providerSnapshotId}${state}`);
2495
+ console.log(
2496
+ ` provider: ${s.provider}${s.region ? ` (${s.region})` : ""} label: ${s.label ?? "\u2014"} created: ${s.createdAt}${s.expiresAt ? ` expires: ${s.expiresAt}` : ""}`
2497
+ );
2487
2498
  }
2488
2499
  function registerSandboxesCommands(program2) {
2489
2500
  const cmd = program2.command("sandboxes").alias("sbx").description("Create and drive sandboxes through the platform").configureOutput({ outputError: usageErrorOutput });
@@ -2561,7 +2572,7 @@ function registerSandboxesCommands(program2) {
2561
2572
  fail(e, opts);
2562
2573
  }
2563
2574
  });
2564
- cmd.command("spawn <sandboxId> <command...>").description("Start a detached process that outlives this request").option("--cwd <dir>", "working directory").option("-e, --env <key=value>", "environment variable (repeatable)", (v, a) => a.concat(v), []).option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (sandboxId, command, opts) => {
2575
+ cmd.command("spawn <sandboxId> <command...>").description("Start a detached process that outlives this request").option("--cwd <dir>", "working directory").option("-e, --env <key=value>", "environment variable (repeatable)", (v, a) => a.concat(v), []).option("--stdin", "keep the process's stdin pipe open for `stdin`/`close-stdin`").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (sandboxId, command, opts) => {
2565
2576
  try {
2566
2577
  const c = await client(opts);
2567
2578
  const res = await c.post(
@@ -2569,7 +2580,8 @@ function registerSandboxesCommands(program2) {
2569
2580
  {
2570
2581
  command: command.map(shellQuote).join(" "),
2571
2582
  ...opts.cwd ? { cwd: opts.cwd } : {},
2572
- ...opts.env && opts.env.length > 0 ? { env: parseInputs(opts.env) } : {}
2583
+ ...opts.env && opts.env.length > 0 ? { env: parseInputs(opts.env) } : {},
2584
+ ...opts.stdin ? { stdin: true } : {}
2573
2585
  }
2574
2586
  );
2575
2587
  output(opts, res.process, printProcess);
@@ -2634,6 +2646,50 @@ function registerSandboxesCommands(program2) {
2634
2646
  fail(e, opts);
2635
2647
  }
2636
2648
  });
2649
+ cmd.command("stdin <sandboxId> <jobId>").description("Write to a process's stdin pipe (spawn with --stdin; --data, --file, or piped)").option("--data <text>", "data to write").option("--file <local>", "read data from a local file").option("--base64", "base64-encode the input before sending (binary-safe)").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (sandboxId, jobId, opts) => {
2650
+ try {
2651
+ let data = opts.data;
2652
+ if (data === void 0 && opts.file) {
2653
+ const { readFile } = await import("fs/promises");
2654
+ data = opts.base64 ? (await readFile(opts.file)).toString("base64") : await readFile(opts.file, "utf8");
2655
+ }
2656
+ if (data === void 0 && !process.stdin.isTTY) {
2657
+ const piped = await new Promise((resolve) => {
2658
+ const chunks = [];
2659
+ process.stdin.on("data", (chunk) => chunks.push(chunk));
2660
+ process.stdin.on("end", () => resolve(Buffer.concat(chunks)));
2661
+ });
2662
+ data = opts.base64 ? piped.toString("base64") : piped.toString("utf8");
2663
+ }
2664
+ if (data === void 0 || data === "") {
2665
+ console.error(pc3.red("Pass --data, --file, or pipe stdin"));
2666
+ process.exit(1);
2667
+ }
2668
+ if (opts.base64 && opts.data !== void 0) {
2669
+ data = Buffer.from(data).toString("base64");
2670
+ }
2671
+ const c = await client(opts);
2672
+ const res = await c.post(
2673
+ `/api/v1/sandboxes/${sandboxId}/processes/${jobId}/stdin`,
2674
+ { data, ...opts.base64 ? { encoding: "base64" } : {} }
2675
+ );
2676
+ output(opts, res, () => console.log(`wrote ${data.length} chars to ${jobId}`));
2677
+ } catch (e) {
2678
+ fail(e, opts);
2679
+ }
2680
+ });
2681
+ cmd.command("close-stdin <sandboxId> <jobId>").description("Close a process's stdin pipe").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (sandboxId, jobId, opts) => {
2682
+ try {
2683
+ const c = await client(opts);
2684
+ const res = await c.post(
2685
+ `/api/v1/sandboxes/${sandboxId}/processes/${jobId}/close-stdin`,
2686
+ {}
2687
+ );
2688
+ output(opts, res, () => console.log(`closed stdin on ${jobId}`));
2689
+ } catch (e) {
2690
+ fail(e, opts);
2691
+ }
2692
+ });
2637
2693
  cmd.command("ls <sandboxId> [path]").description("List a directory (or stat a path) inside the sandbox").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (sandboxId, path5, opts) => {
2638
2694
  try {
2639
2695
  const c = await client(opts);
@@ -2733,6 +2789,40 @@ function registerSandboxesCommands(program2) {
2733
2789
  fail(e, opts);
2734
2790
  }
2735
2791
  });
2792
+ cmd.command("snapshots <sandboxId>").description("List the sandbox's snapshots").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (sandboxId, opts) => {
2793
+ try {
2794
+ const c = await client(opts);
2795
+ const res = await c.get(
2796
+ `/api/v1/sandboxes/${sandboxId}/snapshots`
2797
+ );
2798
+ output(opts, res.snapshots, (list) => list.forEach(printSnapshot));
2799
+ } catch (e) {
2800
+ fail(e, opts);
2801
+ }
2802
+ });
2803
+ cmd.command("snapshot <sandboxId>").description("Snapshot a running sandbox through its provider").option("--label <label>", "label for the snapshot").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (sandboxId, opts) => {
2804
+ try {
2805
+ const c = await client(opts);
2806
+ const res = await c.post(
2807
+ `/api/v1/sandboxes/${sandboxId}/snapshots`,
2808
+ opts.label ? { label: opts.label } : {}
2809
+ );
2810
+ output(opts, res.snapshot, printSnapshot);
2811
+ } catch (e) {
2812
+ fail(e, opts);
2813
+ }
2814
+ });
2815
+ cmd.command("snapshot-delete <sandboxId> <snapshotId>").description("Delete a snapshot's provider artifact").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (sandboxId, snapshotId, opts) => {
2816
+ try {
2817
+ const c = await client(opts);
2818
+ const res = await c.del(
2819
+ `/api/v1/sandboxes/${sandboxId}/snapshots/${snapshotId}`
2820
+ );
2821
+ output(opts, res, () => console.log(`deleted snapshot ${snapshotId}`));
2822
+ } catch (e) {
2823
+ fail(e, opts);
2824
+ }
2825
+ });
2736
2826
  }
2737
2827
  async function followProcess(c, sandboxId, jobId) {
2738
2828
  let exitCode = 0;