@agentgates/cli 0.90.0 → 0.90.1

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +60 -27
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -3163,7 +3163,7 @@ var init_constants = __esm({
3163
3163
  trim = (v) => v ? v.replace(/\/$/, "") : "";
3164
3164
  CLI_API_ORIGIN = trim(process.env.BOUNTY_API_ORIGIN) || "https://cli.agentgates.ai";
3165
3165
  CREATORS_ORIGIN = trim(process.env.BOUNTY_CREATORS_ORIGIN) || "https://agentgates.ai";
3166
- CLI_VERSION = "0.90.0";
3166
+ CLI_VERSION = "0.90.1";
3167
3167
  CLI_USER_AGENT = `agentgates-cli/${CLI_VERSION}`;
3168
3168
  AI_DIRECTIVE = "\n[AI: present the above verbatim inside a markdown code block. Do not reformat, summarize, or omit rows.]";
3169
3169
  }
@@ -74930,7 +74930,7 @@ async function payFor2(args) {
74930
74930
  }
74931
74931
  let answer;
74932
74932
  try {
74933
- answer = await computeCall({ method: "POST", url: args.url, body: args.body, headers, timeoutMs: 15e4 });
74933
+ answer = await computeCall({ method: "POST", url: args.url, body: { ...args.body, maxDrawMicro: atMost.toString() }, headers, timeoutMs: 15e4 });
74934
74934
  } catch (err) {
74935
74935
  throw new SandboxError(`the compute API did not answer: ${err.message}. A draw that went through shows in agentgates sandbox ls${args.mode === "key" ? " --key <the same key>" : ""}`, "no_answer");
74936
74936
  }
@@ -74938,6 +74938,10 @@ async function payFor2(args) {
74938
74938
  const short5 = answer.json?.code === "insufficient_balance" || answer.json?.accepts ? "the balance does not cover it" : apiWords2(answer);
74939
74939
  throw new SandboxError(`${short5}: nothing was drawn. Pay over x402 instead (the same command without ${args.mode === "key" ? "--key" : "--from-balance"}), or top up the balance`, "insufficient_balance", { status: 402 });
74940
74940
  }
74941
+ if (answer.status === 409 && answer.json?.code === "price_above_max_draw") {
74942
+ const now = typeof answer.json?.priceMicro === "string" && /^\d+$/.test(answer.json.priceMicro) ? usd(BigInt(answer.json.priceMicro)) : null;
74943
+ throw new SandboxError(`the price from ${from} is ${now ?? "higher"} now, over the ${usd(atMost)} it was priced at: nothing was drawn. Run it again to pay the price now`, "price_above_max_draw", { status: 409, atMostUsd: usd(atMost), ...now ? { priceUsd: now } : {} });
74944
+ }
74941
74945
  if (answer.status < 200 || answer.status >= 300) throw new SandboxError(apiWords2(answer), apiCode2(answer), { status: answer.status });
74942
74946
  const charged = answer.json?.charged?.amountMicro;
74943
74947
  const drawn = typeof charged === "string" && /^\d+$/.test(charged) ? BigInt(charged) : null;
@@ -75108,17 +75112,28 @@ async function findSandbox(id2, opts = {}) {
75108
75112
  }
75109
75113
  const readAuth = rec?.paidWith === "key" && key ? { key } : wallet ? { wallet } : key ? { key } : null;
75110
75114
  let machine = null;
75115
+ const doorOnly = Boolean(rec && rec.paidWith === "attached" && SANDBOX_ID_RE.test(rec.deploymentId));
75111
75116
  const depId = rec?.deploymentId ?? (SANDBOX_ID_RE.test(clean3) ? null : clean3);
75112
- if (readAuth && depId) {
75117
+ let unread = false;
75118
+ if (doorOnly) {
75119
+ } else if (readAuth && depId) {
75113
75120
  const a = await readMachine(depId, readAuth).catch(() => null);
75121
+ if (a === null) unread = true;
75114
75122
  if (a && a.status === 200) machine = a.json;
75115
75123
  else if (a && a.status === 404 && !rec) throw new SandboxError(`${apiWords2(a)}${wallet ? ` (this key is ${wallet.address})` : ""}`, "not_found", { status: 404 });
75116
75124
  } else if (readAuth) {
75117
- const all = await listMachines(readAuth).catch(() => []);
75125
+ const all = await listMachines(readAuth).catch(() => {
75126
+ unread = true;
75127
+ return [];
75128
+ });
75118
75129
  machine = all.find((m) => sandboxOf(m)?.id === clean3) ?? null;
75119
75130
  } else if (!rec) {
75120
75131
  throw walletError instanceof Error ? walletError : new SandboxError("no account on this machine to read it with", "no_account");
75121
75132
  }
75133
+ if (!machine && !rec) {
75134
+ if (unread) throw new SandboxError("the compute API did not answer, and this machine keeps no record of that sandbox", "unreachable");
75135
+ throw new SandboxError(`no sandbox ${clean3} here or in ${wallet ? `${wallet.address}'s list` : "this key's list"} (agentgates sandbox ls shows yours)`, "not_found", { status: 404 });
75136
+ }
75122
75137
  const sb = machine ? sandboxOf(machine) : null;
75123
75138
  const api2 = sb?.api ?? rec?.api ?? null;
75124
75139
  const tlsPin = sb?.tlsPin ?? rec?.tlsPin ?? null;
@@ -75184,21 +75199,15 @@ async function attachSandbox(args) {
75184
75199
  if (err instanceof DoorError) throw new SandboxError(err.message, err.code, { status: err.status });
75185
75200
  throw err;
75186
75201
  }
75187
- const record = {
75188
- v: 1,
75189
- deploymentId,
75190
- plan: null,
75191
- sandboxId,
75192
- api: api2,
75193
- tlsPin,
75194
- owner: null,
75195
- accessKey,
75196
- paidWith: "attached",
75197
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
75198
- };
75202
+ const kept = await findRecord(deploymentId) ?? await findRecord(sandboxId);
75203
+ const record = kept ? { ...kept, sandboxId, api: api2, tlsPin, accessKey } : { v: 1, deploymentId, plan: null, sandboxId, api: api2, tlsPin, owner: null, accessKey, paidWith: "attached", createdAt: (/* @__PURE__ */ new Date()).toISOString() };
75199
75204
  await writeRecord(record);
75200
75205
  return { record, verdict: door.verdict, view };
75201
75206
  }
75207
+ function canOf(rec, deploymentId) {
75208
+ const known = Boolean(deploymentId && !SANDBOX_ID_RE.test(deploymentId));
75209
+ return { exec: true, cp: true, verify: true, logs: true, status: true, renew: known, rm: known && rec?.paidWith !== "attached" };
75210
+ }
75202
75211
  function receiptStateOf(found) {
75203
75212
  const rec = found.record;
75204
75213
  return {
@@ -75701,9 +75710,9 @@ async function sandboxVerify(id2, opts) {
75701
75710
  } catch (err) {
75702
75711
  return failWith(opts, err);
75703
75712
  }
75704
- const door = new SandboxDoor({ api: found.api, tlsPin: found.tlsPin, sandboxId: found.sandboxId, auth: found.auth, owner: found.owner, ownerUnchecked: found.ownerUnchecked, siteOrigin: siteOrigin() });
75705
75713
  let v;
75706
75714
  try {
75715
+ const door = new SandboxDoor({ api: found.api, tlsPin: found.tlsPin, sandboxId: found.sandboxId, auth: found.auth, owner: found.owner, ownerUnchecked: found.ownerUnchecked, siteOrigin: siteOrigin() });
75707
75716
  v = await door.verify();
75708
75717
  } catch (err) {
75709
75718
  return failWith(opts, err);
@@ -76081,14 +76090,33 @@ function paymentLine(inv) {
76081
76090
  const how = typeof inv.chainId === "number" ? `paid on ${CHAIN_WORDS[inv.chainId] ?? `chain ${inv.chainId}`}` : "from a balance";
76082
76091
  return `${when3} ${kind}${time ? ` of ${time}` : ""} $${String(inv.amountUsd ?? "?")} ${how}`;
76083
76092
  }
76093
+ var STDIN_KEY_MS = 3e3;
76094
+ function firstLineOf(stream, ms) {
76095
+ return new Promise((resolve5) => {
76096
+ let text = "";
76097
+ const done = () => {
76098
+ clearTimeout(timer);
76099
+ stream.removeListener("data", onData);
76100
+ stream.removeListener("end", done);
76101
+ stream.removeListener("error", done);
76102
+ stream.pause?.();
76103
+ stream.unref?.();
76104
+ resolve5(text.split(/\r?\n/)[0] ?? "");
76105
+ };
76106
+ const onData = (c) => {
76107
+ text += c.toString();
76108
+ if (/\n/.test(text) || text.length > 4096) done();
76109
+ };
76110
+ const timer = setTimeout(done, ms);
76111
+ stream.on("data", onData);
76112
+ stream.once("end", done);
76113
+ stream.once("error", done);
76114
+ });
76115
+ }
76084
76116
  async function sandboxAttach(address, opts) {
76085
- let accessKey = opts.accessKey ?? process.env.AGENTGATES_SANDBOX_ACCESS_KEY ?? "";
76086
- if (!accessKey && !process.stdin.isTTY) {
76087
- const chunks = [];
76088
- for await (const c of process.stdin) chunks.push(Buffer.from(c));
76089
- accessKey = Buffer.concat(chunks).toString("utf8").trim().split(/\s+/)[0] ?? "";
76090
- }
76091
76117
  if (!opts.pin) return failWith(opts, new SandboxError("--pin is the sandbox's pin, sha256//..., as agentgates.ai/sandboxes shows it", "bad_input"));
76118
+ let accessKey = opts.accessKey ?? process.env.AGENTGATES_SANDBOX_ACCESS_KEY ?? "";
76119
+ if (!accessKey && !process.stdin.isTTY) accessKey = (await firstLineOf(process.stdin, STDIN_KEY_MS)).trim().split(/\s+/)[0] ?? "";
76092
76120
  if (!accessKey) return failWith(opts, new SandboxError("its access key: --access-key, AGENTGATES_SANDBOX_ACCESS_KEY, or piped on stdin", "bad_input"));
76093
76121
  let out;
76094
76122
  try {
@@ -76131,14 +76159,18 @@ async function sandboxStatus(id2, opts) {
76131
76159
  } catch (err) {
76132
76160
  doorError = err.message;
76133
76161
  }
76162
+ const m = found.machine;
76163
+ const status4 = typeof m?.status === "string" ? m.status : typeof doorView?.state === "string" ? String(doorView.state) : "unread";
76164
+ const doorEnds = typeof doorView?.paidUntil === "number" ? new Date(doorView.paidUntil * 1e3).toISOString() : void 0;
76165
+ const can = canOf(found.record, found.deploymentId);
76166
+ if (!doorView) process.exitCode = 1;
76134
76167
  if (jsonMode7(opts)) {
76135
76168
  const payments = Array.isArray(found.machine?.invoices) ? found.machine.invoices : [];
76136
- say3(JSON.stringify({ ok: true, deployment: found.machine, sandbox: { id: found.sandboxId, api: found.api, tlsPin: found.tlsPin }, payments, proof: door ? "checked" : "not checked", ...found.ownerUnchecked ? { ownerCheck: found.ownerUnchecked } : {}, door: doorView, ...doorError ? { doorError } : {} }, null, 2) + "\n");
76169
+ say3(JSON.stringify({ ok: Boolean(doorView), status: status4, deployment: found.machine, sandbox: { id: found.sandboxId, api: found.api, tlsPin: found.tlsPin }, payments, proof: doorView ? "checked" : "not checked", ...found.ownerUnchecked ? { ownerCheck: found.ownerUnchecked } : {}, can, door: doorView, ...doorError ? { doorError } : {} }, null, 2) + "\n");
76137
76170
  return;
76138
76171
  }
76139
- const m = found.machine;
76140
76172
  say3(`
76141
- ${sandboxLines({ deploymentId: found.deploymentId, status: m?.status ?? "running", plan: m?.plan ?? found.record?.plan, expiresAt: m?.expiresAt }, { id: found.sandboxId, api: found.api })}
76173
+ ${sandboxLines({ deploymentId: found.deploymentId, status: status4, plan: m?.plan ?? found.record?.plan, expiresAt: m?.expiresAt ?? doorEnds }, { id: found.sandboxId, api: found.api })}
76142
76174
  `);
76143
76175
  const invoices = Array.isArray(m?.invoices) ? m.invoices : [];
76144
76176
  if (invoices.length) {
@@ -76159,7 +76191,8 @@ ${sandboxLines({ deploymentId: found.deploymentId, status: m?.status ?? "running
76159
76191
  say3(` proof ${import_picocolors13.default.red("not checked")} ${import_picocolors13.default.dim(doorError)}
76160
76192
  `);
76161
76193
  }
76162
- say3(` ${import_picocolors13.default.dim("it does not stop, start, resize or take a new setup: renew it (agentgates sandbox renew), or delete it (agentgates sandbox rm)")}
76194
+ const then = [can.renew ? "renew it (agentgates sandbox renew)" : null, can.rm ? "delete it (agentgates sandbox rm)" : null].filter(Boolean).join(", or ");
76195
+ say3(` ${import_picocolors13.default.dim(`it does not stop, start, resize or take a new setup${then ? `: ${then}` : ""}`)}
76163
76196
 
76164
76197
  `);
76165
76198
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentgates/cli",
3
- "version": "0.90.0",
3
+ "version": "0.90.1",
4
4
  "description": "Wallet operations for AI agents and humans",
5
5
  "keywords": [
6
6
  "crypto",