@agentgates/cli 0.90.1 → 0.90.3
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/cli.mjs +187 -38
- 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.
|
|
3166
|
+
CLI_VERSION = "0.90.3";
|
|
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
|
}
|
|
@@ -33126,6 +33126,8 @@ var sandbox_door_exports = {};
|
|
|
33126
33126
|
__export(sandbox_door_exports, {
|
|
33127
33127
|
DEFAULT_CWD: () => DEFAULT_CWD,
|
|
33128
33128
|
DoorError: () => DoorError,
|
|
33129
|
+
PROOF_BUSY_MAX_MS: () => PROOF_BUSY_MAX_MS,
|
|
33130
|
+
PROOF_BUSY_TRIES: () => PROOF_BUSY_TRIES,
|
|
33129
33131
|
SandboxDoor: () => SandboxDoor,
|
|
33130
33132
|
filePath: () => filePath,
|
|
33131
33133
|
localWalkDoor: () => localWalkDoor,
|
|
@@ -33133,6 +33135,7 @@ __export(sandbox_door_exports, {
|
|
|
33133
33135
|
pinToHex: () => pinToHex,
|
|
33134
33136
|
pinnedConnect: () => pinnedConnect,
|
|
33135
33137
|
pinnedRequest: () => pinnedRequest,
|
|
33138
|
+
retryAfterMs: () => retryAfterMs,
|
|
33136
33139
|
walletAuthHeader: () => walletAuthHeader
|
|
33137
33140
|
});
|
|
33138
33141
|
import { connect as tlsConnect } from "node:tls";
|
|
@@ -33223,6 +33226,12 @@ function jsonOf(buf) {
|
|
|
33223
33226
|
function truncatedNote(check, cut) {
|
|
33224
33227
|
return check.ok && cut ? { ok: true, note: "output not checked: truncated (the answer keeps the first 1 MiB of each; a streamed run checks all of it)" } : check;
|
|
33225
33228
|
}
|
|
33229
|
+
function retryAfterMs(header2) {
|
|
33230
|
+
const raw = Array.isArray(header2) ? header2[0] : header2;
|
|
33231
|
+
const n2 = Number(raw);
|
|
33232
|
+
const ms = Number.isFinite(n2) && n2 > 0 ? n2 * 1e3 : 1e3;
|
|
33233
|
+
return Math.min(PROOF_BUSY_MAX_MS, Math.max(500, Math.round(ms)));
|
|
33234
|
+
}
|
|
33226
33235
|
function localWalkDoor(api2, env = process.env) {
|
|
33227
33236
|
if (env.AGENTGATES_SANDBOX_LOCAL_WALK !== "1") return false;
|
|
33228
33237
|
const host2 = api2.hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
@@ -33239,7 +33248,7 @@ function filePath(path12) {
|
|
|
33239
33248
|
if (segments.some((s) => s === "." || s === "..")) throw new DoorError(`"${p}" names . or .. : give the path itself`, "bad_path");
|
|
33240
33249
|
return `/${segments.map((s) => encodeURIComponent(s)).join("/")}`;
|
|
33241
33250
|
}
|
|
33242
|
-
var DEFAULT_CWD, DoorError, pinnedConnect, SandboxDoor, openSealedForTests;
|
|
33251
|
+
var DEFAULT_CWD, DoorError, pinnedConnect, PROOF_BUSY_TRIES, PROOF_BUSY_MAX_MS, SandboxDoor, openSealedForTests;
|
|
33243
33252
|
var init_sandbox_door = __esm({
|
|
33244
33253
|
"src/lib/sandbox-door.ts"() {
|
|
33245
33254
|
"use strict";
|
|
@@ -33293,6 +33302,8 @@ var init_sandbox_door = __esm({
|
|
|
33293
33302
|
reject(new DoorError(`the sandbox's door could not be reached: ${err.message}`, "unreachable"));
|
|
33294
33303
|
});
|
|
33295
33304
|
});
|
|
33305
|
+
PROOF_BUSY_TRIES = 4;
|
|
33306
|
+
PROOF_BUSY_MAX_MS = 1e4;
|
|
33296
33307
|
SandboxDoor = class {
|
|
33297
33308
|
constructor(opts) {
|
|
33298
33309
|
this.opts = opts;
|
|
@@ -33335,14 +33346,22 @@ var init_sandbox_door = __esm({
|
|
|
33335
33346
|
let answer = null;
|
|
33336
33347
|
let tlsKey = "";
|
|
33337
33348
|
try {
|
|
33338
|
-
|
|
33339
|
-
|
|
33340
|
-
|
|
33341
|
-
|
|
33342
|
-
|
|
33343
|
-
|
|
33344
|
-
|
|
33345
|
-
|
|
33349
|
+
for (let tries = 1; ; tries += 1) {
|
|
33350
|
+
const a = await pinnedRequest({ url: this.url("/proof", { nonce }), method: "GET", headers: { accept: "application/json" }, pinHex: this.pinHex, answerTimeoutMs: 3e4, connector: this.opts.connector });
|
|
33351
|
+
tlsKey = a.tlsKeySha256;
|
|
33352
|
+
const buf = await readAll(a.body, 4 * 1024 * 1024);
|
|
33353
|
+
if (a.status === 429 && tries < PROOF_BUSY_TRIES) {
|
|
33354
|
+
await new Promise((r) => setTimeout(r, retryAfterMs(a.headers["retry-after"])));
|
|
33355
|
+
continue;
|
|
33356
|
+
}
|
|
33357
|
+
if (a.status !== 200) {
|
|
33358
|
+
const j = jsonOf(buf);
|
|
33359
|
+
const code = a.status === 503 ? "proof_not_ready" : a.status === 429 ? "proof_busy" : "proof_refused";
|
|
33360
|
+
throw new DoorError(`the proof door answered ${a.status}${typeof j?.error === "string" ? `: ${j.error}` : ""}${a.status === 429 ? `: ask again in ${Math.ceil(retryAfterMs(a.headers["retry-after"]) / 1e3)} s` : ""}`, code, a.status, j);
|
|
33361
|
+
}
|
|
33362
|
+
answer = jsonOf(buf);
|
|
33363
|
+
break;
|
|
33364
|
+
}
|
|
33346
33365
|
} catch (err) {
|
|
33347
33366
|
this.checked = null;
|
|
33348
33367
|
throw err;
|
|
@@ -66227,6 +66246,7 @@ async function sendPaid(args) {
|
|
|
66227
66246
|
let last = null;
|
|
66228
66247
|
let why = "";
|
|
66229
66248
|
let tried = 0;
|
|
66249
|
+
const answers = [];
|
|
66230
66250
|
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
66231
66251
|
let answer = null;
|
|
66232
66252
|
tried = attempt;
|
|
@@ -66244,6 +66264,7 @@ async function sendPaid(args) {
|
|
|
66244
66264
|
} catch (err) {
|
|
66245
66265
|
why = err?.message || String(err);
|
|
66246
66266
|
}
|
|
66267
|
+
answers.push(answer);
|
|
66247
66268
|
if (answer) {
|
|
66248
66269
|
last = answer;
|
|
66249
66270
|
if (answer.status >= 200 && answer.status < 300) return { kind: "served", answer, attempts: attempt };
|
|
@@ -66257,7 +66278,7 @@ async function sendPaid(args) {
|
|
|
66257
66278
|
args.onRetry?.(why, attempt, waitMs);
|
|
66258
66279
|
await sleep4(waitMs);
|
|
66259
66280
|
}
|
|
66260
|
-
return { kind: "no_answer", error: why, attempts: tried, last };
|
|
66281
|
+
return { kind: "no_answer", error: why, attempts: tried, last, answers };
|
|
66261
66282
|
}
|
|
66262
66283
|
async function ownerGet(wallet, path12, opts = {}) {
|
|
66263
66284
|
const header2 = await ownerAuthHeader(wallet, "GET", path12);
|
|
@@ -74680,6 +74701,7 @@ function printNext(put) {
|
|
|
74680
74701
|
|
|
74681
74702
|
// src/commands/sandbox.ts
|
|
74682
74703
|
var import_picocolors13 = __toESM(require_picocolors(), 1);
|
|
74704
|
+
import { createInterface as createInterface6 } from "node:readline/promises";
|
|
74683
74705
|
import { promises as fs11, createReadStream as createReadStream2, createWriteStream } from "node:fs";
|
|
74684
74706
|
import * as path7 from "node:path";
|
|
74685
74707
|
import { pipeline } from "node:stream/promises";
|
|
@@ -74745,6 +74767,9 @@ function machinesOf(answer) {
|
|
|
74745
74767
|
if (Array.isArray(a?.deployments)) return a.deployments;
|
|
74746
74768
|
return answer && typeof answer === "object" ? [answer] : [];
|
|
74747
74769
|
}
|
|
74770
|
+
function pendingIdOf(accessKeyHash) {
|
|
74771
|
+
return `pending-${accessKeyHash.slice(0, 40)}`;
|
|
74772
|
+
}
|
|
74748
74773
|
function sandboxesDir() {
|
|
74749
74774
|
return path5.join(agentgatesHome(), "sandboxes");
|
|
74750
74775
|
}
|
|
@@ -74804,6 +74829,15 @@ var SandboxError = class extends Error {
|
|
|
74804
74829
|
code;
|
|
74805
74830
|
detail;
|
|
74806
74831
|
};
|
|
74832
|
+
var QUOTED_FOR_LESS = /, instead of the .+ asked$/;
|
|
74833
|
+
function mayHaveCharged(a) {
|
|
74834
|
+
if (a.status < 500) return false;
|
|
74835
|
+
const words7 = typeof a.json?.error === "string" ? a.json.error : "";
|
|
74836
|
+
if (/\bnothing was (charged|drawn)\b/i.test(words7)) return false;
|
|
74837
|
+
return !["at_capacity", "provider_capacity", "quote_unread", "sol_price_unread", "screen_refused", "payments_unconfigured", "not_available"].includes(String(a.json?.code ?? ""));
|
|
74838
|
+
}
|
|
74839
|
+
var MAY_STILL_LAND = /send the same payment again|not confirmed within|settlement failed/i;
|
|
74840
|
+
var SUPPORT_ADDRESS = "support@agentgates.ai";
|
|
74807
74841
|
var COLD_START_WORDS = "it waits for a seat on a host and runs once one has room: about two minutes after its payment when a host must start for it (135 s measured on production), longer when many wait at once";
|
|
74808
74842
|
var KEY_RE = /^agc_[0-9a-f]{64}$/;
|
|
74809
74843
|
function computeKeyOf(given) {
|
|
@@ -74905,7 +74939,9 @@ async function payFor2(args) {
|
|
|
74905
74939
|
}
|
|
74906
74940
|
if (ask.status !== 402) throw new SandboxError(apiWords2(ask), apiCode2(ask), { status: ask.status });
|
|
74907
74941
|
const offer2 = ask.json;
|
|
74908
|
-
const
|
|
74942
|
+
const usdcLegs = (offer2.accepts ?? []).filter((l) => !isSolLeg(l));
|
|
74943
|
+
const asked = usdcLegs.filter((l) => !QUOTED_FOR_LESS.test(String(l.description ?? "")));
|
|
74944
|
+
const amounts = (asked.length > 0 ? asked : usdcLegs).map((l) => {
|
|
74909
74945
|
try {
|
|
74910
74946
|
return BigInt(l.maxAmountRequired ?? "");
|
|
74911
74947
|
} catch {
|
|
@@ -74929,20 +74965,21 @@ async function payFor2(args) {
|
|
|
74929
74965
|
headers = { "x-wallet-auth": await ownerAuthHeader(wallet2, "POST", args.path) };
|
|
74930
74966
|
}
|
|
74931
74967
|
let answer;
|
|
74968
|
+
args.onSent?.();
|
|
74932
74969
|
try {
|
|
74933
74970
|
answer = await computeCall({ method: "POST", url: args.url, body: { ...args.body, maxDrawMicro: atMost.toString() }, headers, timeoutMs: 15e4 });
|
|
74934
74971
|
} catch (err) {
|
|
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");
|
|
74972
|
+
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", { mayHaveCharged: true });
|
|
74936
74973
|
}
|
|
74937
74974
|
if (answer.status === 402) {
|
|
74938
74975
|
const short5 = answer.json?.code === "insufficient_balance" || answer.json?.accepts ? "the balance does not cover it" : apiWords2(answer);
|
|
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 });
|
|
74976
|
+
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, nothingDrawn: true });
|
|
74940
74977
|
}
|
|
74941
74978
|
if (answer.status === 409 && answer.json?.code === "price_above_max_draw") {
|
|
74942
74979
|
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 } : {} });
|
|
74980
|
+
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), nothingDrawn: true, ...now ? { priceUsd: now } : {} });
|
|
74944
74981
|
}
|
|
74945
|
-
if (answer.status < 200 || answer.status >= 300) throw new SandboxError(apiWords2(answer), apiCode2(answer), { status: answer.status });
|
|
74982
|
+
if (answer.status < 200 || answer.status >= 300) throw new SandboxError(apiWords2(answer), apiCode2(answer), { status: answer.status, mayHaveCharged: mayHaveCharged(answer) });
|
|
74946
74983
|
const charged = answer.json?.charged?.amountMicro;
|
|
74947
74984
|
const drawn = typeof charged === "string" && /^\d+$/.test(charged) ? BigInt(charged) : null;
|
|
74948
74985
|
return { kind: "served", answer, paid: { network: "balance", amountUsd: drawn === null ? null : usd(drawn), atMostUsd: usd(atMost), from }, mode: args.mode, payer };
|
|
@@ -75001,16 +75038,23 @@ async function payFor2(args) {
|
|
|
75001
75038
|
const signed2 = await signLeg(leg, wallet.privateKey);
|
|
75002
75039
|
const paid = { network: leg.network, amountUsd: usd(leg.amountMicro), amountAtomic: leg.amountMicro.toString(), from: signed2.from, nonce: signed2.nonce };
|
|
75003
75040
|
args.onPaid?.(paid);
|
|
75041
|
+
args.onSent?.();
|
|
75004
75042
|
const outcome = await sendPaid({ url: args.url, body: args.body, payment: signed2.header, onRetry: args.onRetry, ...args.budgetMs !== void 0 ? { budgetMs: args.budgetMs } : {} });
|
|
75043
|
+
const list = args.listWords ?? "agentgates sandbox ls";
|
|
75005
75044
|
if (outcome.kind === "no_answer") {
|
|
75006
|
-
const
|
|
75007
|
-
|
|
75045
|
+
const before = outcome.answers.length > 0 && outcome.answers.every((a) => a !== null && a.status >= 500 && !mayHaveCharged(a));
|
|
75046
|
+
if (before && outcome.last) throw new SandboxError(apiWords2(outcome.last), apiCode2(outcome.last), { status: outcome.last.status, paid, mayHaveCharged: false });
|
|
75047
|
+
throw new SandboxError(`no clear answer after ${outcome.attempts} ${outcome.attempts === 1 ? "try" : "tries"} (${outcome.error}). The payment (nonce ${signed2.nonce}) may still settle: do not pay again; ${list} shows what it bought`, "no_answer", { paid, nonce: signed2.nonce, mayHaveCharged: true });
|
|
75008
75048
|
}
|
|
75009
75049
|
if (outcome.kind === "refused") {
|
|
75010
75050
|
const a = outcome.answer;
|
|
75011
|
-
|
|
75012
|
-
|
|
75013
|
-
|
|
75051
|
+
if (a.status === 409 && a.json?.code === "payment_already_spent") {
|
|
75052
|
+
throw new SandboxError(`paid; no sandbox found for it yet: write to ${SUPPORT_ADDRESS} with its payment (nonce ${signed2.nonce}). Do not pay again; ${list} shows it once found`, "payment_already_spent", { status: 409, paid, nonce: signed2.nonce, mayHaveCharged: true, support: SUPPORT_ADDRESS });
|
|
75053
|
+
}
|
|
75054
|
+
const maybe = outcome.attempts > 1 || MAY_STILL_LAND.test(apiWords2(a));
|
|
75055
|
+
const then = maybe ? `. It may still settle: do not pay again; ${list} shows what it bought` : "";
|
|
75056
|
+
if (a.status === 402) throw new SandboxError(`the payment was refused: ${apiWords2(a)}${then}`, apiCode2(a) === "http_402" ? "payment_refused" : apiCode2(a), { status: a.status, paid, mayHaveCharged: maybe });
|
|
75057
|
+
throw new SandboxError(apiWords2(a), apiCode2(a), { status: a.status, paid, mayHaveCharged: outcome.attempts > 1 || mayHaveCharged(a) });
|
|
75014
75058
|
}
|
|
75015
75059
|
return { kind: "served", answer: outcome.answer, paid, mode: "x402", payer: wallet.address };
|
|
75016
75060
|
}
|
|
@@ -75025,8 +75069,44 @@ async function createSandboxes(args) {
|
|
|
75025
75069
|
const count = typeof body.count === "number" ? body.count : 1;
|
|
75026
75070
|
const time = body.minutes !== void 0 ? `${String(body.minutes)} min` : `${String(body.hours)} h`;
|
|
75027
75071
|
const what = `${count > 1 ? `${count} x ` : ""}${String(body.plan)}, ${time}, ${typeof body.image === "string" ? body.image : "base"}`;
|
|
75028
|
-
const
|
|
75029
|
-
if (
|
|
75072
|
+
const pendingId = access && !args.consent.quoteOnly ? pendingIdOf(access.hash) : null;
|
|
75073
|
+
if (pendingId && access) {
|
|
75074
|
+
const payer = args.mode === "key" ? `agc_...${String(args.key ?? "").slice(-4)}` : await payingWallet().then((w) => w.address, () => null);
|
|
75075
|
+
await writeRecord({
|
|
75076
|
+
v: 1,
|
|
75077
|
+
deploymentId: pendingId,
|
|
75078
|
+
plan: String(body.plan),
|
|
75079
|
+
sandboxId: null,
|
|
75080
|
+
api: null,
|
|
75081
|
+
tlsPin: null,
|
|
75082
|
+
owner: null,
|
|
75083
|
+
accessKey: access.secret,
|
|
75084
|
+
paidWith: args.mode,
|
|
75085
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
75086
|
+
pending: { accessKeyHash: access.hash, at: (/* @__PURE__ */ new Date()).toISOString(), count, payer }
|
|
75087
|
+
});
|
|
75088
|
+
}
|
|
75089
|
+
let sent = false;
|
|
75090
|
+
let out;
|
|
75091
|
+
try {
|
|
75092
|
+
out = await payFor2({ url: `${computeOrigin()}${DEPLOYMENTS_PATH}`, path: DEPLOYMENTS_PATH, body, mode: args.mode, key: args.key, consent: args.consent, what, onPaid: args.onPaid, onRetry: args.onRetry, onSent: () => {
|
|
75093
|
+
sent = true;
|
|
75094
|
+
}, budgetMs: args.budgetMs, listWords: args.listWords });
|
|
75095
|
+
} catch (err) {
|
|
75096
|
+
if (pendingId) {
|
|
75097
|
+
const nothingDrawn = err instanceof SandboxError && err.detail.nothingDrawn === true;
|
|
75098
|
+
if (sent && !nothingDrawn) {
|
|
75099
|
+
const e = err instanceof SandboxError ? err : new SandboxError(err?.message ?? String(err), "error");
|
|
75100
|
+
throw new SandboxError(`${e.message}. Its access key is kept here: ${args.listWords ?? "agentgates sandbox ls"} binds it to the sandbox it bought (agentgates sandbox rm ${pendingId} --yes drops it)`, e.code, { ...e.detail, pending: pendingId });
|
|
75101
|
+
}
|
|
75102
|
+
await removeRecord(pendingId);
|
|
75103
|
+
}
|
|
75104
|
+
throw err;
|
|
75105
|
+
}
|
|
75106
|
+
if (out.kind === "quote") {
|
|
75107
|
+
if (pendingId) await removeRecord(pendingId);
|
|
75108
|
+
return { quote: { description: out.description, legs: out.legs } };
|
|
75109
|
+
}
|
|
75030
75110
|
const machines = machinesOf(out.answer.json);
|
|
75031
75111
|
const owner = args.mode === "key" ? null : out.payer;
|
|
75032
75112
|
const sandboxes = [];
|
|
@@ -75057,6 +75137,7 @@ async function createSandboxes(args) {
|
|
|
75057
75137
|
});
|
|
75058
75138
|
}
|
|
75059
75139
|
if (sandboxes.length === 0) throw new SandboxError("the API answered with no sandbox", "bad_answer", { answer: out.answer.json });
|
|
75140
|
+
if (pendingId) await removeRecord(pendingId);
|
|
75060
75141
|
const note2 = typeof out.answer.json?.note === "string" ? out.answer.json.note : null;
|
|
75061
75142
|
return { status: out.answer.status, paid: out.paid, mode: out.mode, accessKey: access?.secret ?? null, sandboxes, note: note2, notices: out.answer.json?.notices ?? null };
|
|
75062
75143
|
}
|
|
@@ -75102,6 +75183,7 @@ async function findSandbox(id2, opts = {}) {
|
|
|
75102
75183
|
const clean3 = String(id2 ?? "").trim();
|
|
75103
75184
|
if (!/^[A-Za-z0-9_-]{1,64}$/.test(clean3)) throw new SandboxError(`"${id2}" is not a sandbox id (agentgates sandbox ls shows yours)`, "bad_input");
|
|
75104
75185
|
const rec = await findRecord(clean3);
|
|
75186
|
+
if (rec?.pending) throw new SandboxError(`${rec.deploymentId} is ${PENDING_STATUS_WORDS}`, "pending", { status: "pending", paidBy: rec.pending.payer ?? null });
|
|
75105
75187
|
const key = opts.key ?? null;
|
|
75106
75188
|
let wallet;
|
|
75107
75189
|
let walletError = null;
|
|
@@ -75118,7 +75200,7 @@ async function findSandbox(id2, opts = {}) {
|
|
|
75118
75200
|
if (doorOnly) {
|
|
75119
75201
|
} else if (readAuth && depId) {
|
|
75120
75202
|
const a = await readMachine(depId, readAuth).catch(() => null);
|
|
75121
|
-
if (a === null) unread = true;
|
|
75203
|
+
if (a === null || a.status !== 200 && a.status !== 404) unread = true;
|
|
75122
75204
|
if (a && a.status === 200) machine = a.json;
|
|
75123
75205
|
else if (a && a.status === 404 && !rec) throw new SandboxError(`${apiWords2(a)}${wallet ? ` (this key is ${wallet.address})` : ""}`, "not_found", { status: 404 });
|
|
75124
75206
|
} else if (readAuth) {
|
|
@@ -75144,6 +75226,7 @@ async function findSandbox(id2, opts = {}) {
|
|
|
75144
75226
|
throw new SandboxError(`that sandbox is ${status4}${machine?.killReason ? ` (${String(machine.killReason)})` : ""}: it has no door to call`, "not_running", { status: status4 });
|
|
75145
75227
|
}
|
|
75146
75228
|
if (!deploymentId || !sandboxId || !api2 || !tlsPin) {
|
|
75229
|
+
if (unread && !machine) throw new SandboxError("the compute API did not answer, and this machine keeps no address for that sandbox: nothing was read", "unreachable", { status: null, unread: true });
|
|
75147
75230
|
throw new SandboxError("that sandbox has no address yet: wait for it (agentgates sandbox status shows it)", "not_ready", { status: status4 });
|
|
75148
75231
|
}
|
|
75149
75232
|
if (rec && (rec.api !== api2 || rec.tlsPin !== tlsPin || rec.sandboxId !== sandboxId)) await writeRecord({ ...rec, api: api2, tlsPin, sandboxId });
|
|
@@ -75253,6 +75336,7 @@ async function renewSandbox(args) {
|
|
|
75253
75336
|
}
|
|
75254
75337
|
async function deleteSandbox(id2) {
|
|
75255
75338
|
const rec = await findRecord(id2);
|
|
75339
|
+
if (rec?.pending) throw new SandboxError(PENDING_RM_WORDS, "pending_key", { pending: rec.deploymentId });
|
|
75256
75340
|
if (rec?.paidWith === "attached") throw new SandboxError(ATTACHED_DELETE_WORDS, "needs_owner");
|
|
75257
75341
|
let depId = rec?.deploymentId ?? id2;
|
|
75258
75342
|
const wallet = await payingWallet();
|
|
@@ -75290,10 +75374,42 @@ async function listSandboxes(opts = {}) {
|
|
|
75290
75374
|
errors.push(err.message);
|
|
75291
75375
|
}
|
|
75292
75376
|
}
|
|
75293
|
-
|
|
75294
|
-
const
|
|
75377
|
+
let current = recs;
|
|
75378
|
+
for (const p of recs.filter((r) => r.pending)) {
|
|
75379
|
+
const pending = p.pending;
|
|
75380
|
+
const mine = [...seen.values()].filter((m) => m.accessKeyHash === pending.accessKeyHash);
|
|
75381
|
+
if (mine.length === 0) continue;
|
|
75382
|
+
for (const m of mine) {
|
|
75383
|
+
const sb = sandboxOf(m);
|
|
75384
|
+
await writeRecord({
|
|
75385
|
+
v: 1,
|
|
75386
|
+
deploymentId: String(m.deploymentId),
|
|
75387
|
+
plan: typeof m.plan === "string" ? m.plan : p.plan,
|
|
75388
|
+
sandboxId: sb?.id ?? null,
|
|
75389
|
+
api: sb?.api ?? null,
|
|
75390
|
+
tlsPin: sb?.tlsPin ?? null,
|
|
75391
|
+
owner: p.paidWith === "key" ? null : pending.payer && /^0x[0-9a-fA-F]{40}$/.test(pending.payer) ? pending.payer : wallet?.address ?? null,
|
|
75392
|
+
accessKey: p.accessKey,
|
|
75393
|
+
paidWith: p.paidWith,
|
|
75394
|
+
createdAt: p.createdAt
|
|
75395
|
+
});
|
|
75396
|
+
}
|
|
75397
|
+
await removeRecord(p.deploymentId);
|
|
75398
|
+
current = current.filter((r) => r.deploymentId !== p.deploymentId);
|
|
75399
|
+
}
|
|
75400
|
+
const after = current === recs ? recs : await readRecords();
|
|
75401
|
+
const rows = [...seen.values()].map((m) => ({ machine: m, record: after.find((r) => r.deploymentId === m.deploymentId) ?? null }));
|
|
75402
|
+
const onlyHere = after.filter((r) => !seen.has(r.deploymentId)).map((r) => ({ machine: null, record: r }));
|
|
75295
75403
|
return { owner: wallet?.address ?? null, rows: [...rows, ...onlyHere], errors };
|
|
75296
75404
|
}
|
|
75405
|
+
async function dropPendingKey(id2) {
|
|
75406
|
+
const rec = await findRecord(String(id2 ?? "").trim());
|
|
75407
|
+
if (!rec?.pending) throw new SandboxError(`no kept access key "${id2}" here (agentgates sandbox ls shows them as pending)`, "not_found");
|
|
75408
|
+
await removeRecord(rec.deploymentId);
|
|
75409
|
+
return rec;
|
|
75410
|
+
}
|
|
75411
|
+
var PENDING_STATUS_WORDS = "a purchase's kept access key with no sandbox found yet: agentgates sandbox ls binds it to the sandbox carrying its hash once that sandbox is listed (with --key <the compute key> when one paid)";
|
|
75412
|
+
var PENDING_RM_WORDS = "that is a purchase's kept access key with no sandbox found yet: agentgates sandbox ls binds it once its sandbox is listed; agentgates sandbox rm <its id> --yes drops the key, after which a sandbox it bought would not open from here";
|
|
75297
75413
|
|
|
75298
75414
|
// src/commands/sandbox.ts
|
|
75299
75415
|
init_sandbox_door();
|
|
@@ -75979,6 +76095,33 @@ function report(opts, r) {
|
|
|
75979
76095
|
`);
|
|
75980
76096
|
}
|
|
75981
76097
|
async function sandboxRm(id2, opts) {
|
|
76098
|
+
const rec = await findRecord(String(id2 ?? "").trim()).catch(() => null);
|
|
76099
|
+
if (rec?.pending) {
|
|
76100
|
+
if (!opts.yes) {
|
|
76101
|
+
const interactive = !jsonMode7(opts) && Boolean(process.stdin.isTTY);
|
|
76102
|
+
let answer = "";
|
|
76103
|
+
if (interactive) {
|
|
76104
|
+
const rl = createInterface6({ input: process.stdin, output: process.stderr });
|
|
76105
|
+
try {
|
|
76106
|
+
answer = (await rl.question(` Drop the kept access key of ${rec.deploymentId}? A sandbox it bought would not open from here. [y/N] `)).trim().toLowerCase();
|
|
76107
|
+
} catch {
|
|
76108
|
+
answer = "";
|
|
76109
|
+
} finally {
|
|
76110
|
+
rl.close();
|
|
76111
|
+
}
|
|
76112
|
+
}
|
|
76113
|
+
if (answer !== "y" && answer !== "yes") return fail3(opts, interactive ? "kept: nothing dropped" : `${rec.deploymentId} is a purchase's kept access key: --yes drops it (a sandbox it bought would not open from here after)`, interactive ? "declined" : "yes_required");
|
|
76114
|
+
}
|
|
76115
|
+
try {
|
|
76116
|
+
const r = await dropPendingKey(rec.deploymentId);
|
|
76117
|
+
if (jsonMode7(opts)) say3(JSON.stringify({ ok: true, dropped: r.deploymentId }, null, 2) + "\n");
|
|
76118
|
+
else say3(` ${import_picocolors13.default.green("ok")} ${r.deploymentId}: its kept access key dropped
|
|
76119
|
+
`);
|
|
76120
|
+
} catch (err) {
|
|
76121
|
+
failWith(opts, err);
|
|
76122
|
+
}
|
|
76123
|
+
return;
|
|
76124
|
+
}
|
|
75982
76125
|
try {
|
|
75983
76126
|
const r = await deleteSandbox(id2);
|
|
75984
76127
|
if (jsonMode7(opts)) say3(JSON.stringify({ ok: true, deploymentId: r.deploymentId, answer: r.answer }, null, 2) + "\n");
|
|
@@ -76049,11 +76192,12 @@ async function sandboxLs(opts) {
|
|
|
76049
76192
|
owner: list.owner,
|
|
76050
76193
|
sandboxes: list.rows.map((r) => ({
|
|
76051
76194
|
deploymentId: r.machine?.deploymentId ?? r.record?.deploymentId,
|
|
76052
|
-
status: r.machine?.status ?? "unread",
|
|
76195
|
+
status: r.machine?.status ?? (r.record?.pending ? "pending" : "unread"),
|
|
76053
76196
|
plan: r.machine?.plan ?? r.record?.plan ?? null,
|
|
76054
76197
|
expiresAt: r.machine?.expiresAt ?? null,
|
|
76055
76198
|
sandbox: (r.machine && sandboxOf(r.machine)) ?? (r.record?.api ? { id: r.record.sandboxId, api: r.record.api, tlsPin: r.record.tlsPin } : null),
|
|
76056
|
-
accessKeyHere: Boolean(r.record?.accessKey)
|
|
76199
|
+
accessKeyHere: Boolean(r.record?.accessKey),
|
|
76200
|
+
...r.record?.pending && !r.machine ? { paidBy: r.record.pending.payer ?? null } : {}
|
|
76057
76201
|
})),
|
|
76058
76202
|
...list.errors.length ? { errors: list.errors } : {}
|
|
76059
76203
|
},
|
|
@@ -76073,7 +76217,9 @@ async function sandboxLs(opts) {
|
|
|
76073
76217
|
for (const r of list.rows) {
|
|
76074
76218
|
const m = r.machine;
|
|
76075
76219
|
const sb = (m && sandboxOf(m)) ?? (r.record?.api && r.record.sandboxId ? { id: r.record.sandboxId, api: r.record.api } : null);
|
|
76076
|
-
|
|
76220
|
+
const paidBy = !m && r.record?.pending ? `
|
|
76221
|
+
paid by ${r.record.pending.payer ?? "?"}` : "";
|
|
76222
|
+
say3(`${sandboxLines({ deploymentId: m?.deploymentId ?? r.record?.deploymentId, status: m?.status ?? (r.record?.pending ? "pending" : "unread"), plan: m?.plan ?? r.record?.plan, expiresAt: m?.expiresAt, killReason: m?.killReason }, m?.status === "running" || !m ? sb : null)}${paidBy}
|
|
76077
76223
|
|
|
76078
76224
|
`);
|
|
76079
76225
|
}
|
|
@@ -76142,8 +76288,8 @@ async function sandboxStatus(id2, opts) {
|
|
|
76142
76288
|
try {
|
|
76143
76289
|
found = await findSandbox(id2, { key: computeKeyOf(opts.key) });
|
|
76144
76290
|
} catch (err) {
|
|
76145
|
-
if (err instanceof SandboxError && (err.code === "not_running" || err.code === "not_ready")) {
|
|
76146
|
-
if (jsonMode7(opts)) say3(JSON.stringify({ ok: true, status: err.detail.status
|
|
76291
|
+
if (err instanceof SandboxError && (err.code === "not_running" || err.code === "not_ready" || err.code === "pending") && typeof err.detail.status === "string") {
|
|
76292
|
+
if (jsonMode7(opts)) say3(JSON.stringify({ ok: true, status: err.detail.status, note: err.message }, null, 2) + "\n");
|
|
76147
76293
|
else say3(` ${err.message}
|
|
76148
76294
|
`);
|
|
76149
76295
|
return;
|
|
@@ -76206,7 +76352,7 @@ init_passwords_wire();
|
|
|
76206
76352
|
init_passwords_seal();
|
|
76207
76353
|
|
|
76208
76354
|
// src/lib/mcp-stdio.ts
|
|
76209
|
-
import { createInterface as
|
|
76355
|
+
import { createInterface as createInterface7 } from "node:readline";
|
|
76210
76356
|
var MCP_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
76211
76357
|
var McpToolError = class extends Error {
|
|
76212
76358
|
constructor(message, detail = {}) {
|
|
@@ -76320,7 +76466,7 @@ async function serve(tools, info, { input = process.stdin, output: output2 = pro
|
|
|
76320
76466
|
`);
|
|
76321
76467
|
};
|
|
76322
76468
|
const inFlight = /* @__PURE__ */ new Set();
|
|
76323
|
-
const lines =
|
|
76469
|
+
const lines = createInterface7({ input, crlfDelay: Infinity });
|
|
76324
76470
|
for await (const line2 of lines) {
|
|
76325
76471
|
const parsed = parseLine(line2);
|
|
76326
76472
|
if (!parsed) continue;
|
|
@@ -77574,7 +77720,7 @@ async function filesRm(target, opts) {
|
|
|
77574
77720
|
|
|
77575
77721
|
// src/commands/card.ts
|
|
77576
77722
|
var import_picocolors16 = __toESM(require_picocolors(), 1);
|
|
77577
|
-
import { createInterface as
|
|
77723
|
+
import { createInterface as createInterface8 } from "node:readline/promises";
|
|
77578
77724
|
|
|
77579
77725
|
// src/lib/memory-address.ts
|
|
77580
77726
|
var ADDRESS_FOLDER = "profile";
|
|
@@ -78116,7 +78262,7 @@ var QUESTIONS = [
|
|
|
78116
78262
|
{ field: "zip", ask: "ZIP code", abroad: "Postal code" }
|
|
78117
78263
|
];
|
|
78118
78264
|
async function askAddress() {
|
|
78119
|
-
const rl =
|
|
78265
|
+
const rl = createInterface8({ input: process.stdin, output: process.stdout });
|
|
78120
78266
|
const answers = { country: "US", line1: "", line2: "", city: "", region: "", zip: "" };
|
|
78121
78267
|
try {
|
|
78122
78268
|
process.stdout.write(`
|
|
@@ -78579,10 +78725,13 @@ function sandboxTools(wait2 = readWait) {
|
|
|
78579
78725
|
owner: list.owner,
|
|
78580
78726
|
sandboxes: list.rows.map((r) => ({
|
|
78581
78727
|
deploymentId: r.machine?.deploymentId ?? r.record?.deploymentId,
|
|
78582
|
-
status: r.machine?.status ?? "unread",
|
|
78728
|
+
status: r.machine?.status ?? (r.record?.pending ? "pending" : "unread"),
|
|
78583
78729
|
plan: r.machine?.plan ?? r.record?.plan ?? null,
|
|
78584
78730
|
expiresAt: r.machine?.expiresAt ?? null,
|
|
78585
|
-
sandbox: (r.machine && sandboxOf(r.machine)) ?? null
|
|
78731
|
+
sandbox: (r.machine && sandboxOf(r.machine)) ?? null,
|
|
78732
|
+
// A purchase's kept access key, no sandbox found yet: bound
|
|
78733
|
+
// here once its sandbox is listed; never dropped by a read.
|
|
78734
|
+
...r.record?.pending && !r.machine ? { paidBy: r.record.pending.payer ?? null } : {}
|
|
78586
78735
|
})),
|
|
78587
78736
|
...list.errors.length ? { errors: list.errors } : {}
|
|
78588
78737
|
};
|
|
@@ -86335,7 +86484,7 @@ sandbox.command("renew <id>").description("Add paid minutes to its end. Any wall
|
|
|
86335
86484
|
sandbox.command("attach <address>").description("Keep a sandbox bought on agentgates.ai here, from what its page showed once: its address, its pin and its access key. Its proof is checked and its door opened first; then exec, cp, verify, logs and status reach it. A delete still takes the wallet that bought it.").option("--pin <pin>", "its pin, sha256//..., as the page shows it").option("--access-key <key>", "its access key, sbxk_... (or AGENTGATES_SANDBOX_ACCESS_KEY, or piped on stdin)").option("--id <deployment-id>", "its deployment id, when you have it").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (address, opts) => {
|
|
86336
86485
|
await sandboxAttach(address, opts);
|
|
86337
86486
|
});
|
|
86338
|
-
sandbox.command("rm <id>").description("Delete it now: it ends with its disk, and its unused minutes are not refunded. Signed by the owner's key.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (id2, opts) => {
|
|
86487
|
+
sandbox.command("rm <id>").description("Delete it now: it ends with its disk, and its unused minutes are not refunded. Signed by the owner's key. On a pending id (a purchase's kept access key, no sandbox found yet), drops that key.").option("--yes", "drop a pending id's kept access key without asking").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (id2, opts) => {
|
|
86339
86488
|
await sandboxRm(id2, opts);
|
|
86340
86489
|
});
|
|
86341
86490
|
sandbox.command("logs <id> <pid>").description("A background command's output, and its exit and receipt once it ends.").option("--follow", "keep reading until it ends").option("--key <agc_key>", "the compute key it was bought with (or AGENTGATES_COMPUTE_KEY)").option("--json", "machine-readable output").action(async (id2, pid, opts) => {
|