@agentgates/cli 0.20.0 → 0.22.0
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 +823 -507
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -6875,7 +6875,7 @@ var require_package = __commonJS({
|
|
|
6875
6875
|
"package.json"(exports, module) {
|
|
6876
6876
|
module.exports = {
|
|
6877
6877
|
name: "@agentgates/cli",
|
|
6878
|
-
version: "0.
|
|
6878
|
+
version: "0.22.0",
|
|
6879
6879
|
description: "Wallet operations for AI agents and humans",
|
|
6880
6880
|
keywords: [
|
|
6881
6881
|
"crypto",
|
|
@@ -17475,10 +17475,10 @@ var require_dist = __commonJS({
|
|
|
17475
17475
|
if (coerce2) {
|
|
17476
17476
|
value = struct2.coercer(value, ctx2);
|
|
17477
17477
|
}
|
|
17478
|
-
let
|
|
17478
|
+
let status4 = "valid";
|
|
17479
17479
|
for (const failure of struct2.validator(value, ctx2)) {
|
|
17480
17480
|
failure.explanation = options.message;
|
|
17481
|
-
|
|
17481
|
+
status4 = "not_valid";
|
|
17482
17482
|
yield [failure, void 0];
|
|
17483
17483
|
}
|
|
17484
17484
|
for (let [k, v, s] of struct2.entries(value, ctx2)) {
|
|
@@ -17491,7 +17491,7 @@ var require_dist = __commonJS({
|
|
|
17491
17491
|
});
|
|
17492
17492
|
for (const t of ts) {
|
|
17493
17493
|
if (t[0]) {
|
|
17494
|
-
|
|
17494
|
+
status4 = t[0].refinement != null ? "not_refined" : "not_valid";
|
|
17495
17495
|
yield [t[0], void 0];
|
|
17496
17496
|
} else if (coerce2) {
|
|
17497
17497
|
v = t[1];
|
|
@@ -17508,14 +17508,14 @@ var require_dist = __commonJS({
|
|
|
17508
17508
|
}
|
|
17509
17509
|
}
|
|
17510
17510
|
}
|
|
17511
|
-
if (
|
|
17511
|
+
if (status4 !== "not_valid") {
|
|
17512
17512
|
for (const failure of struct2.refiner(value, ctx2)) {
|
|
17513
17513
|
failure.explanation = options.message;
|
|
17514
|
-
|
|
17514
|
+
status4 = "not_refined";
|
|
17515
17515
|
yield [failure, void 0];
|
|
17516
17516
|
}
|
|
17517
17517
|
}
|
|
17518
|
-
if (
|
|
17518
|
+
if (status4 === "valid") {
|
|
17519
17519
|
yield [void 0, value];
|
|
17520
17520
|
}
|
|
17521
17521
|
}
|
|
@@ -18903,8 +18903,8 @@ var require_tr46 = __commonJS({
|
|
|
18903
18903
|
var len = countSymbols(domain_name);
|
|
18904
18904
|
for (var i = 0; i < len; ++i) {
|
|
18905
18905
|
var codePoint = domain_name.codePointAt(i);
|
|
18906
|
-
var
|
|
18907
|
-
switch (
|
|
18906
|
+
var status4 = findStatus(codePoint);
|
|
18907
|
+
switch (status4[1]) {
|
|
18908
18908
|
case "disallowed":
|
|
18909
18909
|
hasError = true;
|
|
18910
18910
|
processed += String.fromCodePoint(codePoint);
|
|
@@ -18912,11 +18912,11 @@ var require_tr46 = __commonJS({
|
|
|
18912
18912
|
case "ignored":
|
|
18913
18913
|
break;
|
|
18914
18914
|
case "mapped":
|
|
18915
|
-
processed += String.fromCodePoint.apply(String,
|
|
18915
|
+
processed += String.fromCodePoint.apply(String, status4[2]);
|
|
18916
18916
|
break;
|
|
18917
18917
|
case "deviation":
|
|
18918
18918
|
if (processing_option === PROCESSING_OPTIONS.TRANSITIONAL) {
|
|
18919
|
-
processed += String.fromCodePoint.apply(String,
|
|
18919
|
+
processed += String.fromCodePoint.apply(String, status4[2]);
|
|
18920
18920
|
} else {
|
|
18921
18921
|
processed += String.fromCodePoint(codePoint);
|
|
18922
18922
|
}
|
|
@@ -18929,7 +18929,7 @@ var require_tr46 = __commonJS({
|
|
|
18929
18929
|
hasError = true;
|
|
18930
18930
|
processed += String.fromCodePoint(codePoint);
|
|
18931
18931
|
} else {
|
|
18932
|
-
processed += String.fromCodePoint.apply(String,
|
|
18932
|
+
processed += String.fromCodePoint.apply(String, status4[2]);
|
|
18933
18933
|
}
|
|
18934
18934
|
break;
|
|
18935
18935
|
case "disallowed_STD3_valid":
|
|
@@ -18957,8 +18957,8 @@ var require_tr46 = __commonJS({
|
|
|
18957
18957
|
}
|
|
18958
18958
|
var len = countSymbols(label);
|
|
18959
18959
|
for (var i = 0; i < len; ++i) {
|
|
18960
|
-
var
|
|
18961
|
-
if (processing === PROCESSING_OPTIONS.TRANSITIONAL &&
|
|
18960
|
+
var status4 = findStatus(label.codePointAt(i));
|
|
18961
|
+
if (processing === PROCESSING_OPTIONS.TRANSITIONAL && status4[1] !== "valid" || processing === PROCESSING_OPTIONS.NONTRANSITIONAL && status4[1] !== "valid" && status4[1] !== "deviation") {
|
|
18962
18962
|
error = true;
|
|
18963
18963
|
break;
|
|
18964
18964
|
}
|
|
@@ -21205,7 +21205,7 @@ var require_lib3 = __commonJS({
|
|
|
21205
21205
|
let body = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
|
|
21206
21206
|
let opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
21207
21207
|
Body.call(this, body, opts);
|
|
21208
|
-
const
|
|
21208
|
+
const status4 = opts.status || 200;
|
|
21209
21209
|
const headers = new Headers(opts.headers);
|
|
21210
21210
|
if (body != null && !headers.has("Content-Type")) {
|
|
21211
21211
|
const contentType = extractContentType(body);
|
|
@@ -21215,8 +21215,8 @@ var require_lib3 = __commonJS({
|
|
|
21215
21215
|
}
|
|
21216
21216
|
this[INTERNALS$1] = {
|
|
21217
21217
|
url: opts.url,
|
|
21218
|
-
status:
|
|
21219
|
-
statusText: opts.statusText || STATUS_CODES[
|
|
21218
|
+
status: status4,
|
|
21219
|
+
statusText: opts.statusText || STATUS_CODES[status4],
|
|
21220
21220
|
headers,
|
|
21221
21221
|
counter: opts.counter
|
|
21222
21222
|
};
|
|
@@ -25454,7 +25454,7 @@ var require_eventemitter3 = __commonJS({
|
|
|
25454
25454
|
if (listeners.fn) return 1;
|
|
25455
25455
|
return listeners.length;
|
|
25456
25456
|
};
|
|
25457
|
-
EventEmitter.prototype.emit = function
|
|
25457
|
+
EventEmitter.prototype.emit = function emit6(event, a1, a2, a3, a4, a5) {
|
|
25458
25458
|
var evt = prefix ? prefix + event : event;
|
|
25459
25459
|
if (!this._events[evt]) return false;
|
|
25460
25460
|
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
@@ -30611,9 +30611,9 @@ Message: ${transactionMessage}.
|
|
|
30611
30611
|
minContextSlot: options.minContextSlot
|
|
30612
30612
|
};
|
|
30613
30613
|
const signature2 = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
30614
|
-
let
|
|
30614
|
+
let status4;
|
|
30615
30615
|
if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
|
|
30616
|
-
|
|
30616
|
+
status4 = (await connection.confirmTransaction({
|
|
30617
30617
|
abortSignal: options?.abortSignal,
|
|
30618
30618
|
signature: signature2,
|
|
30619
30619
|
blockhash: transaction.recentBlockhash,
|
|
@@ -30624,7 +30624,7 @@ Message: ${transactionMessage}.
|
|
|
30624
30624
|
nonceInstruction
|
|
30625
30625
|
} = transaction.nonceInfo;
|
|
30626
30626
|
const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
|
|
30627
|
-
|
|
30627
|
+
status4 = (await connection.confirmTransaction({
|
|
30628
30628
|
abortSignal: options?.abortSignal,
|
|
30629
30629
|
minContextSlot: transaction.minNonceContextSlot,
|
|
30630
30630
|
nonceAccountPubkey,
|
|
@@ -30635,17 +30635,17 @@ Message: ${transactionMessage}.
|
|
|
30635
30635
|
if (options?.abortSignal != null) {
|
|
30636
30636
|
console.warn("sendAndConfirmTransaction(): A transaction with a deprecated confirmation strategy was supplied along with an `abortSignal`. Only transactions having `lastValidBlockHeight` or a combination of `nonceInfo` and `minNonceContextSlot` are abortable.");
|
|
30637
30637
|
}
|
|
30638
|
-
|
|
30638
|
+
status4 = (await connection.confirmTransaction(signature2, options && options.commitment)).value;
|
|
30639
30639
|
}
|
|
30640
|
-
if (
|
|
30640
|
+
if (status4.err) {
|
|
30641
30641
|
if (signature2 != null) {
|
|
30642
30642
|
throw new SendTransactionError({
|
|
30643
30643
|
action: "send",
|
|
30644
30644
|
signature: signature2,
|
|
30645
|
-
transactionMessage: `Status: (${JSON.stringify(
|
|
30645
|
+
transactionMessage: `Status: (${JSON.stringify(status4)})`
|
|
30646
30646
|
});
|
|
30647
30647
|
}
|
|
30648
|
-
throw new Error(`Transaction ${signature2} failed (${JSON.stringify(
|
|
30648
|
+
throw new Error(`Transaction ${signature2} failed (${JSON.stringify(status4)})`);
|
|
30649
30649
|
}
|
|
30650
30650
|
return signature2;
|
|
30651
30651
|
}
|
|
@@ -33824,15 +33824,15 @@ Message: ${transactionMessage}.
|
|
|
33824
33824
|
} else {
|
|
33825
33825
|
let signatureStatus;
|
|
33826
33826
|
while (true) {
|
|
33827
|
-
const
|
|
33828
|
-
if (
|
|
33827
|
+
const status4 = await this.getSignatureStatus(signature2);
|
|
33828
|
+
if (status4 == null) {
|
|
33829
33829
|
break;
|
|
33830
33830
|
}
|
|
33831
|
-
if (
|
|
33831
|
+
if (status4.context.slot < (outcome.slotInWhichNonceDidAdvance ?? minContextSlot)) {
|
|
33832
33832
|
await sleep3(400);
|
|
33833
33833
|
continue;
|
|
33834
33834
|
}
|
|
33835
|
-
signatureStatus =
|
|
33835
|
+
signatureStatus = status4;
|
|
33836
33836
|
break;
|
|
33837
33837
|
}
|
|
33838
33838
|
if (signatureStatus?.value) {
|
|
@@ -37759,16 +37759,16 @@ Message: ${transactionMessage}.
|
|
|
37759
37759
|
const signature2 = await connection.sendRawTransaction(rawTransaction, sendOptions);
|
|
37760
37760
|
const commitment = options && options.commitment;
|
|
37761
37761
|
const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature2, commitment);
|
|
37762
|
-
const
|
|
37763
|
-
if (
|
|
37762
|
+
const status4 = (await confirmationPromise).value;
|
|
37763
|
+
if (status4.err) {
|
|
37764
37764
|
if (signature2 != null) {
|
|
37765
37765
|
throw new SendTransactionError({
|
|
37766
37766
|
action: sendOptions?.skipPreflight ? "send" : "simulate",
|
|
37767
37767
|
signature: signature2,
|
|
37768
|
-
transactionMessage: `Status: (${JSON.stringify(
|
|
37768
|
+
transactionMessage: `Status: (${JSON.stringify(status4)})`
|
|
37769
37769
|
});
|
|
37770
37770
|
}
|
|
37771
|
-
throw new Error(`Raw transaction ${signature2} failed (${JSON.stringify(
|
|
37771
|
+
throw new Error(`Raw transaction ${signature2} failed (${JSON.stringify(status4)})`);
|
|
37772
37772
|
}
|
|
37773
37773
|
return signature2;
|
|
37774
37774
|
}
|
|
@@ -37891,9 +37891,9 @@ var AI_DIRECTIVE = "\n[AI: present the above verbatim inside a markdown code blo
|
|
|
37891
37891
|
|
|
37892
37892
|
// src/lib/api.ts
|
|
37893
37893
|
var ApiError = class extends Error {
|
|
37894
|
-
constructor(
|
|
37894
|
+
constructor(status4, code, message, body) {
|
|
37895
37895
|
super(message);
|
|
37896
|
-
this.status =
|
|
37896
|
+
this.status = status4;
|
|
37897
37897
|
this.code = code;
|
|
37898
37898
|
this.body = body;
|
|
37899
37899
|
this.name = "ApiError";
|
|
@@ -39111,222 +39111,6 @@ async function inferenceAsk() {
|
|
|
39111
39111
|
|
|
39112
39112
|
// src/commands/phone.ts
|
|
39113
39113
|
var import_picocolors5 = __toESM(require_picocolors(), 1);
|
|
39114
|
-
var SITE3 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
|
|
39115
|
-
var usd2 = (v) => {
|
|
39116
|
-
const n2 = Number(v);
|
|
39117
|
-
if (Number.isInteger(n2)) return `$${n2}`;
|
|
39118
|
-
const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
|
|
39119
|
-
return `$${whole}.${frac.padEnd(2, "0")}`;
|
|
39120
|
-
};
|
|
39121
|
-
function phoneSlice(body) {
|
|
39122
|
-
const { booth, ...rest } = body;
|
|
39123
|
-
const out = {
|
|
39124
|
-
...rest,
|
|
39125
|
-
products: (body.products ?? []).filter((p) => p.id === "phone"),
|
|
39126
|
-
rungs: (body.rungs ?? []).filter((r) => r.product === "phone"),
|
|
39127
|
-
prices: (body.prices ?? []).filter((p) => p.product === "phone")
|
|
39128
|
-
};
|
|
39129
|
-
if (booth?.call) out.booth = { brief: booth.brief, call: booth.call };
|
|
39130
|
-
delete out.payg;
|
|
39131
|
-
delete out.sendOverflow;
|
|
39132
|
-
return out;
|
|
39133
|
-
}
|
|
39134
|
-
async function phonePricing(opts) {
|
|
39135
|
-
const res = await fetch(`${SITE3}/api/identity/catalog`, { headers: { accept: "application/json" } });
|
|
39136
|
-
if (!res.ok) throw new Error(`phone catalog: HTTP ${res.status}`);
|
|
39137
|
-
const body = await res.json();
|
|
39138
|
-
const slice = phoneSlice(body);
|
|
39139
|
-
if (opts.json) {
|
|
39140
|
-
process.stdout.write(JSON.stringify(slice, null, 2) + "\n");
|
|
39141
|
-
return;
|
|
39142
|
-
}
|
|
39143
|
-
const product = slice.products?.[0];
|
|
39144
|
-
if (!product || product.available === false) {
|
|
39145
|
-
process.stdout.write(` ${import_picocolors5.default.dim(product?.brief || "Phone numbers are not on sale right now.")}
|
|
39146
|
-
`);
|
|
39147
|
-
return;
|
|
39148
|
-
}
|
|
39149
|
-
const plans = slice.prices ?? [];
|
|
39150
|
-
process.stdout.write(`
|
|
39151
|
-
${import_picocolors5.default.bold("PHONE NUMBERS")} ${import_picocolors5.default.dim("texts and calls, on a wallet plan")}
|
|
39152
|
-
|
|
39153
|
-
`);
|
|
39154
|
-
for (const p of plans) {
|
|
39155
|
-
const count = p.phones ?? 1;
|
|
39156
|
-
const price = usd2(p.priceUsd).padStart(4);
|
|
39157
|
-
const term = `/${p.units} days`.padEnd(9);
|
|
39158
|
-
process.stdout.write(` ${import_picocolors5.default.bold(p.rung.padEnd(11))} ${import_picocolors5.default.cyan(price)}${import_picocolors5.default.dim(term)} ${import_picocolors5.default.dim(`${count} number${count === 1 ? "" : "s"}`)}
|
|
39159
|
-
`);
|
|
39160
|
-
}
|
|
39161
|
-
if (plans.length === 0) process.stdout.write(` ${import_picocolors5.default.dim("no plan rungs are priced right now")}
|
|
39162
|
-
`);
|
|
39163
|
-
const u = slice.phoneUsage;
|
|
39164
|
-
if (u) {
|
|
39165
|
-
const meter = [
|
|
39166
|
-
u.textUsd ? `text ${usd2(u.textUsd)}` : "",
|
|
39167
|
-
u.minuteUsd ? `call minute ${usd2(u.minuteUsd)}` : "",
|
|
39168
|
-
u.waitCodeUsd !== void 0 ? `wait-code ${Number(u.waitCodeUsd) === 0 ? "free" : usd2(u.waitCodeUsd)}` : ""
|
|
39169
|
-
].filter(Boolean).join(" \xB7 ");
|
|
39170
|
-
process.stdout.write(`
|
|
39171
|
-
${import_picocolors5.default.dim(`usage, from the prepaid balance: ${meter}`)}
|
|
39172
|
-
`);
|
|
39173
|
-
if (u.sendingNote) process.stdout.write(` ${import_picocolors5.default.dim(u.sendingNote)}
|
|
39174
|
-
`);
|
|
39175
|
-
}
|
|
39176
|
-
const call = slice.booth?.call;
|
|
39177
|
-
const windows = call?.windows ?? [];
|
|
39178
|
-
if (call?.available && windows.length) {
|
|
39179
|
-
process.stdout.write(`
|
|
39180
|
-
${import_picocolors5.default.bold("PAYPHONE")} ${import_picocolors5.default.dim("no plan, no number: one payment, one call")}
|
|
39181
|
-
|
|
39182
|
-
`);
|
|
39183
|
-
const ladder = windows.map((w) => `${w.minutes} min ${usd2(w.priceUsd)}`).join(" ");
|
|
39184
|
-
process.stdout.write(` ${import_picocolors5.default.dim(ladder)}
|
|
39185
|
-
`);
|
|
39186
|
-
}
|
|
39187
|
-
const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
|
|
39188
|
-
if (nets.length) process.stdout.write(`
|
|
39189
|
-
${import_picocolors5.default.dim(`USDC on ${nets.join(", ")}`)}
|
|
39190
|
-
|
|
39191
|
-
`);
|
|
39192
|
-
else process.stdout.write("\n");
|
|
39193
|
-
}
|
|
39194
|
-
async function phoneCall() {
|
|
39195
|
-
process.stdout.write(
|
|
39196
|
-
`
|
|
39197
|
-
A call signs an x402 payment, and this CLI has no signer yet.
|
|
39198
|
-
Call from the wallet, one biometric: ${import_picocolors5.default.cyan(`${SITE3}/phone`)}
|
|
39199
|
-
Prices from here: ${import_picocolors5.default.dim("agentgates phone pricing")}
|
|
39200
|
-
|
|
39201
|
-
`
|
|
39202
|
-
);
|
|
39203
|
-
}
|
|
39204
|
-
|
|
39205
|
-
// src/commands/email.ts
|
|
39206
|
-
var import_picocolors6 = __toESM(require_picocolors(), 1);
|
|
39207
|
-
var SITE4 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
|
|
39208
|
-
var usd3 = (v) => {
|
|
39209
|
-
const n2 = Number(v);
|
|
39210
|
-
if (Number.isInteger(n2)) return `$${n2}`;
|
|
39211
|
-
const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
|
|
39212
|
-
return `$${whole}.${frac.padEnd(2, "0")}`;
|
|
39213
|
-
};
|
|
39214
|
-
var family = (rung) => {
|
|
39215
|
-
const base = rung.replace(/-?(month|year)$/, "");
|
|
39216
|
-
return base === "" ? "Starter" : base.charAt(0).toUpperCase() + base.slice(1);
|
|
39217
|
-
};
|
|
39218
|
-
function emailSlice(body) {
|
|
39219
|
-
const out = {
|
|
39220
|
-
...body,
|
|
39221
|
-
products: (body.products ?? []).filter((p) => p.id === "inbox"),
|
|
39222
|
-
rungs: (body.rungs ?? []).filter((r) => r.product === "inbox"),
|
|
39223
|
-
prices: (body.prices ?? []).filter((p) => p.product === "inbox")
|
|
39224
|
-
};
|
|
39225
|
-
for (const k of ["booth", "phoneUsage", "voices", "operator", "countries"]) {
|
|
39226
|
-
delete out[k];
|
|
39227
|
-
}
|
|
39228
|
-
return out;
|
|
39229
|
-
}
|
|
39230
|
-
async function emailPricing(opts) {
|
|
39231
|
-
const res = await fetch(`${SITE4}/api/identity/catalog`, { headers: { accept: "application/json" } });
|
|
39232
|
-
if (!res.ok) throw new Error(`email catalog: HTTP ${res.status}`);
|
|
39233
|
-
const body = await res.json();
|
|
39234
|
-
const slice = emailSlice(body);
|
|
39235
|
-
const product = slice.products?.[0];
|
|
39236
|
-
if (opts.json) {
|
|
39237
|
-
process.stdout.write(JSON.stringify(slice, null, 2) + "\n");
|
|
39238
|
-
if (!product || product.available === false) process.exitCode = 1;
|
|
39239
|
-
return;
|
|
39240
|
-
}
|
|
39241
|
-
if (!product || product.available === false) {
|
|
39242
|
-
process.stdout.write(` ${import_picocolors6.default.dim(product?.note || product?.brief || "Inboxes are not on sale right now.")}
|
|
39243
|
-
`);
|
|
39244
|
-
process.exitCode = 1;
|
|
39245
|
-
return;
|
|
39246
|
-
}
|
|
39247
|
-
process.stdout.write(`
|
|
39248
|
-
${import_picocolors6.default.bold("EMAIL")} ${import_picocolors6.default.dim(product.brief || "an inbox on your wallet")}
|
|
39249
|
-
|
|
39250
|
-
`);
|
|
39251
|
-
const freeInboxes = slice.payg?.inboxes;
|
|
39252
|
-
if (freeInboxes) {
|
|
39253
|
-
const at = product.domain ? ` @ ${product.domain}` : "";
|
|
39254
|
-
process.stdout.write(
|
|
39255
|
-
` ${import_picocolors6.default.bold("free".padEnd(11))} ${import_picocolors6.default.cyan("$0".padStart(4))}${"".padEnd(11)} ${import_picocolors6.default.dim(`${freeInboxes} inbox${freeInboxes === 1 ? "" : "es"}${at}, behind a funded balance`)}
|
|
39256
|
-
`
|
|
39257
|
-
);
|
|
39258
|
-
}
|
|
39259
|
-
const plans = slice.prices ?? [];
|
|
39260
|
-
const families = [];
|
|
39261
|
-
const byFamily = /* @__PURE__ */ new Map();
|
|
39262
|
-
for (const p of plans) {
|
|
39263
|
-
const f2 = family(p.rung);
|
|
39264
|
-
if (!byFamily.has(f2)) {
|
|
39265
|
-
byFamily.set(f2, []);
|
|
39266
|
-
families.push(f2);
|
|
39267
|
-
}
|
|
39268
|
-
byFamily.get(f2).push(p);
|
|
39269
|
-
}
|
|
39270
|
-
for (const f2 of families) {
|
|
39271
|
-
const rows = byFamily.get(f2).sort((a, b2) => a.units - b2.units);
|
|
39272
|
-
const cells = rows.map((p) => `${import_picocolors6.default.cyan(usd3(p.priceUsd).padStart(4))}${import_picocolors6.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
|
|
39273
|
-
const lead = rows[0];
|
|
39274
|
-
const cap = [
|
|
39275
|
-
lead.inboxes ? `${lead.inboxes} inbox${lead.inboxes === 1 ? "" : "es"}` : "",
|
|
39276
|
-
lead.sendsPerDay ? `${lead.sendsPerDay} sends/day` : ""
|
|
39277
|
-
].filter(Boolean).join(" \xB7 ");
|
|
39278
|
-
process.stdout.write(` ${import_picocolors6.default.bold(f2.padEnd(11))} ${cells} ${import_picocolors6.default.dim(cap)}
|
|
39279
|
-
`);
|
|
39280
|
-
}
|
|
39281
|
-
if (plans.length === 0) process.stdout.write(` ${import_picocolors6.default.dim("no plan rungs are priced right now")}
|
|
39282
|
-
`);
|
|
39283
|
-
const send2 = slice.sendOverflow?.priceUsd;
|
|
39284
|
-
const wait2 = body.phoneUsage?.waitCodeUsd;
|
|
39285
|
-
const meter = [
|
|
39286
|
-
send2 ? `send ${usd3(send2)}` : "",
|
|
39287
|
-
wait2 !== void 0 ? `wait-code ${Number(wait2) === 0 ? "free" : usd3(wait2)}` : ""
|
|
39288
|
-
].filter(Boolean).join(" \xB7 ");
|
|
39289
|
-
if (meter) process.stdout.write(`
|
|
39290
|
-
${import_picocolors6.default.dim(`usage, from the prepaid balance: ${meter}`)}
|
|
39291
|
-
`);
|
|
39292
|
-
process.stdout.write(` ${import_picocolors6.default.dim("receiving costs nothing; the plan sells inboxes and sends per day")}
|
|
39293
|
-
`);
|
|
39294
|
-
const bal = slice.balance;
|
|
39295
|
-
if (bal?.note) process.stdout.write(` ${import_picocolors6.default.dim(bal.note)}
|
|
39296
|
-
`);
|
|
39297
|
-
else if (bal?.minTopUpUsd) process.stdout.write(` ${import_picocolors6.default.dim(`top up any amount from ${usd3(bal.minTopUpUsd)}`)}
|
|
39298
|
-
`);
|
|
39299
|
-
const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
|
|
39300
|
-
if (nets.length) process.stdout.write(`
|
|
39301
|
-
${import_picocolors6.default.dim(`USDC on ${nets.join(", ")}`)}
|
|
39302
|
-
|
|
39303
|
-
`);
|
|
39304
|
-
else process.stdout.write("\n");
|
|
39305
|
-
}
|
|
39306
|
-
function emailDoor(first) {
|
|
39307
|
-
process.stdout.write(
|
|
39308
|
-
`
|
|
39309
|
-
${first}, and this CLI has no signer yet.
|
|
39310
|
-
Do it from the wallet, one biometric: ${import_picocolors6.default.cyan(`${SITE4}/email`)}
|
|
39311
|
-
Prices from here: ${import_picocolors6.default.dim("agentgates email pricing")}
|
|
39312
|
-
|
|
39313
|
-
`
|
|
39314
|
-
);
|
|
39315
|
-
}
|
|
39316
|
-
async function emailCreate() {
|
|
39317
|
-
emailDoor("An inbox is created under your wallet's own signature");
|
|
39318
|
-
}
|
|
39319
|
-
async function emailSend() {
|
|
39320
|
-
emailDoor("A send signs with your wallet and draws from its balance");
|
|
39321
|
-
}
|
|
39322
|
-
|
|
39323
|
-
// src/commands/passwords.ts
|
|
39324
|
-
var import_picocolors8 = __toESM(require_picocolors(), 1);
|
|
39325
|
-
import { readFileSync } from "node:fs";
|
|
39326
|
-
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
39327
|
-
|
|
39328
|
-
// src/commands/session.ts
|
|
39329
|
-
var import_picocolors7 = __toESM(require_picocolors(), 1);
|
|
39330
39114
|
|
|
39331
39115
|
// src/lib/passwords-key.ts
|
|
39332
39116
|
import { promises as fs7 } from "node:fs";
|
|
@@ -52510,7 +52294,7 @@ var TransactionReceipt = class {
|
|
|
52510
52294
|
logsBloom,
|
|
52511
52295
|
logs,
|
|
52512
52296
|
//byzantium,
|
|
52513
|
-
status:
|
|
52297
|
+
status: status4,
|
|
52514
52298
|
root
|
|
52515
52299
|
} = this;
|
|
52516
52300
|
return {
|
|
@@ -52530,7 +52314,7 @@ var TransactionReceipt = class {
|
|
|
52530
52314
|
logs,
|
|
52531
52315
|
logsBloom,
|
|
52532
52316
|
root,
|
|
52533
|
-
status:
|
|
52317
|
+
status: status4,
|
|
52534
52318
|
to
|
|
52535
52319
|
};
|
|
52536
52320
|
}
|
|
@@ -62870,9 +62654,9 @@ function siteOrigin() {
|
|
|
62870
62654
|
}
|
|
62871
62655
|
var LANE = "/api/identity";
|
|
62872
62656
|
var WireError = class extends Error {
|
|
62873
|
-
constructor(
|
|
62657
|
+
constructor(status4, code, message, body) {
|
|
62874
62658
|
super(message);
|
|
62875
|
-
this.status =
|
|
62659
|
+
this.status = status4;
|
|
62876
62660
|
this.code = code;
|
|
62877
62661
|
this.body = body;
|
|
62878
62662
|
this.name = "WireError";
|
|
@@ -62906,7 +62690,7 @@ function lastAuthVia() {
|
|
|
62906
62690
|
function loginKeyWasRevoked() {
|
|
62907
62691
|
return revokedNoticed;
|
|
62908
62692
|
}
|
|
62909
|
-
var
|
|
62693
|
+
var SIGNED_DOORS = /\/keys(\/|$)|\/passwords\/[A-Za-z0-9_-]{1,64}\/use$/;
|
|
62910
62694
|
async function signedFetch(wallet, method, path7, body, timeoutMs = 13e4) {
|
|
62911
62695
|
const once = async (viaKey) => {
|
|
62912
62696
|
const headers = {
|
|
@@ -62936,7 +62720,7 @@ async function signedFetch(wallet, method, path7, body, timeoutMs = 13e4) {
|
|
|
62936
62720
|
lastVia = viaKey && loginKey ? "key" : "signature";
|
|
62937
62721
|
return { status: res.status, body: json2, text };
|
|
62938
62722
|
};
|
|
62939
|
-
const useKey = !!loginKey && !
|
|
62723
|
+
const useKey = !!loginKey && !SIGNED_DOORS.test(path7);
|
|
62940
62724
|
const answer = await once(useKey);
|
|
62941
62725
|
if (useKey && answer.status === 401) {
|
|
62942
62726
|
const signed2 = await once(false);
|
|
@@ -63147,10 +62931,483 @@ async function requirePasswordsKey() {
|
|
|
63147
62931
|
const fromEnv = (process.env.AGENTGATES_PASSWORDS_SEED || "").trim();
|
|
63148
62932
|
if (fromEnv) return keysOf(stateOf(normaliseSeed(fromEnv, "AGENTGATES_PASSWORDS_SEED")));
|
|
63149
62933
|
const existing = await loadPasswordsKey();
|
|
63150
|
-
if (!existing) throw new Error("no
|
|
62934
|
+
if (!existing) throw new Error("no account on this machine yet: run `agentgates init` first, or set AGENTGATES_PASSWORDS_SEED to twelve words.");
|
|
63151
62935
|
return existing;
|
|
63152
62936
|
}
|
|
63153
62937
|
|
|
62938
|
+
// src/lib/phone-wire.ts
|
|
62939
|
+
var TERMINAL = /* @__PURE__ */ new Set(["done", "failed", "no_answer"]);
|
|
62940
|
+
async function readOperator() {
|
|
62941
|
+
let res;
|
|
62942
|
+
try {
|
|
62943
|
+
res = await fetch(`${siteOrigin()}/api/identity/catalog`, { headers: { accept: "application/json", "user-agent": CLI_USER_AGENT } });
|
|
62944
|
+
} catch (err) {
|
|
62945
|
+
throw new WireError(0, "network_error", `could not reach ${siteOrigin()}: ${err.message}`, null);
|
|
62946
|
+
}
|
|
62947
|
+
if (!res.ok) throw new WireError(res.status, null, `identity catalog: HTTP ${res.status}`, null);
|
|
62948
|
+
const body = await res.json();
|
|
62949
|
+
return { operator: body.operator ?? null, countries: body.countries ?? [] };
|
|
62950
|
+
}
|
|
62951
|
+
function expect(answer, what) {
|
|
62952
|
+
if (answer.status >= 200 && answer.status < 300 && answer.body) return answer.body;
|
|
62953
|
+
const body = answer.body ?? null;
|
|
62954
|
+
const sentence = typeof body?.error === "string" ? body.error : answer.text.slice(0, 300) || `${what}: HTTP ${answer.status}`;
|
|
62955
|
+
const code = typeof body?.code === "string" ? body.code : null;
|
|
62956
|
+
throw new WireError(answer.status, code, sentence, answer.body);
|
|
62957
|
+
}
|
|
62958
|
+
async function listNumbers(wallet) {
|
|
62959
|
+
const answer = await signedFetch(wallet, "GET", `${LANE}/booths`);
|
|
62960
|
+
return (expect(answer, "numbers").phones ?? []).filter((p) => p.status === "active");
|
|
62961
|
+
}
|
|
62962
|
+
async function placeCall(wallet, phoneId, body) {
|
|
62963
|
+
const path7 = phoneId ? `${LANE}/phones/${encodeURIComponent(phoneId)}/calls` : `${LANE}/calls`;
|
|
62964
|
+
const answer = await signedFetch(wallet, "POST", path7, body);
|
|
62965
|
+
const out = expect(answer, "call");
|
|
62966
|
+
return { callId: out.callId, call: out.call, perMinuteUsd: out.perMinuteUsd ?? "", from: phoneId ? "number" : "house" };
|
|
62967
|
+
}
|
|
62968
|
+
async function readCall(wallet, phoneId, id2) {
|
|
62969
|
+
const path7 = phoneId ? `${LANE}/phones/${encodeURIComponent(phoneId)}/calls/${encodeURIComponent(id2)}` : `${LANE}/calls/${encodeURIComponent(id2)}`;
|
|
62970
|
+
const answer = await signedFetch(wallet, "GET", path7);
|
|
62971
|
+
return expect(answer, "call").call;
|
|
62972
|
+
}
|
|
62973
|
+
async function listCalls(wallet, phoneId) {
|
|
62974
|
+
const path7 = phoneId ? `${LANE}/phones/${encodeURIComponent(phoneId)}/calls` : `${LANE}/calls`;
|
|
62975
|
+
const answer = await signedFetch(wallet, "GET", path7);
|
|
62976
|
+
return expect(answer, "calls").calls ?? [];
|
|
62977
|
+
}
|
|
62978
|
+
async function waitForCall(wallet, phoneId, id2, { maxSeconds = 720, everyMs = 5e3, onTick } = {}) {
|
|
62979
|
+
const until = Date.now() + maxSeconds * 1e3;
|
|
62980
|
+
for (; ; ) {
|
|
62981
|
+
const call = await readCall(wallet, phoneId, id2);
|
|
62982
|
+
onTick?.(call);
|
|
62983
|
+
if (TERMINAL.has(call.status) || Date.now() >= until) return call;
|
|
62984
|
+
await new Promise((r) => setTimeout(r, everyMs));
|
|
62985
|
+
}
|
|
62986
|
+
}
|
|
62987
|
+
function toE164(raw, countryCode) {
|
|
62988
|
+
const t = raw.trim();
|
|
62989
|
+
if (/^\+\d{7,15}$/.test(t)) return t;
|
|
62990
|
+
const digits = t.replace(/[\s().-]/g, "");
|
|
62991
|
+
if (/^\+\d{7,15}$/.test(digits)) return digits;
|
|
62992
|
+
if (/^\d{10}$/.test(digits) && countryCode) return `${countryCode}${digits}`;
|
|
62993
|
+
if (/^1\d{10}$/.test(digits) && countryCode === "+1") return `+${digits}`;
|
|
62994
|
+
return null;
|
|
62995
|
+
}
|
|
62996
|
+
function countryCodeFor(countries) {
|
|
62997
|
+
const first = countries[0];
|
|
62998
|
+
if (!first) return null;
|
|
62999
|
+
return first === "US" || first === "CA" ? "+1" : null;
|
|
63000
|
+
}
|
|
63001
|
+
function transcriptLines(raw) {
|
|
63002
|
+
if (!raw) return [];
|
|
63003
|
+
try {
|
|
63004
|
+
const parsed = JSON.parse(raw);
|
|
63005
|
+
if (!Array.isArray(parsed)) return [];
|
|
63006
|
+
return parsed.filter((l) => !!l && typeof l === "object" && typeof l.role === "string" && typeof l.text === "string" && l.text.length > 0).map((l) => ({ role: l.role, text: l.text }));
|
|
63007
|
+
} catch {
|
|
63008
|
+
return [];
|
|
63009
|
+
}
|
|
63010
|
+
}
|
|
63011
|
+
|
|
63012
|
+
// src/commands/phone.ts
|
|
63013
|
+
var SITE3 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
|
|
63014
|
+
var jsonMode = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
63015
|
+
function emit2(opts, data4, human) {
|
|
63016
|
+
if (jsonMode(opts)) {
|
|
63017
|
+
process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
|
|
63018
|
+
return;
|
|
63019
|
+
}
|
|
63020
|
+
human();
|
|
63021
|
+
}
|
|
63022
|
+
function refuse(opts, error, code, extra = {}) {
|
|
63023
|
+
if (jsonMode(opts)) {
|
|
63024
|
+
process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
|
|
63025
|
+
} else {
|
|
63026
|
+
process.stderr.write(` ${error}${code ? import_picocolors5.default.dim(` (${code})`) : ""}
|
|
63027
|
+
`);
|
|
63028
|
+
}
|
|
63029
|
+
process.exit(1);
|
|
63030
|
+
}
|
|
63031
|
+
function failFrom(opts, err) {
|
|
63032
|
+
if (err instanceof WireError) return refuse(opts, err.message, err.code, { status: err.status });
|
|
63033
|
+
return refuse(opts, err.message ?? String(err), null);
|
|
63034
|
+
}
|
|
63035
|
+
var usd2 = (v) => {
|
|
63036
|
+
const n2 = Number(v);
|
|
63037
|
+
if (Number.isInteger(n2)) return `$${n2}`;
|
|
63038
|
+
const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
|
|
63039
|
+
return `$${whole}.${frac.padEnd(2, "0")}`;
|
|
63040
|
+
};
|
|
63041
|
+
var when = (iso) => iso ? iso.replace("T", " ").slice(0, 16) : "";
|
|
63042
|
+
var seconds = (s) => s > 0 ? s >= 60 ? `${Math.floor(s / 60)}m ${s % 60}s` : `${s}s` : "";
|
|
63043
|
+
var STATUS_COLOR = {
|
|
63044
|
+
queued: import_picocolors5.default.dim,
|
|
63045
|
+
active: import_picocolors5.default.cyan,
|
|
63046
|
+
done: import_picocolors5.default.green,
|
|
63047
|
+
failed: import_picocolors5.default.red,
|
|
63048
|
+
no_answer: import_picocolors5.default.dim
|
|
63049
|
+
};
|
|
63050
|
+
var STATUS_WORD = { queued: "dialing", active: "on the line", done: "ended", failed: "failed", no_answer: "no answer" };
|
|
63051
|
+
var status = (s) => (STATUS_COLOR[s] ?? import_picocolors5.default.dim)((STATUS_WORD[s] ?? s).padEnd(12));
|
|
63052
|
+
function phoneSlice(body) {
|
|
63053
|
+
const { booth, ...rest } = body;
|
|
63054
|
+
const out = {
|
|
63055
|
+
...rest,
|
|
63056
|
+
products: (body.products ?? []).filter((p) => p.id === "phone"),
|
|
63057
|
+
rungs: (body.rungs ?? []).filter((r) => r.product === "phone"),
|
|
63058
|
+
prices: (body.prices ?? []).filter((p) => p.product === "phone")
|
|
63059
|
+
};
|
|
63060
|
+
if (booth?.call) out.booth = { brief: booth.brief, call: booth.call };
|
|
63061
|
+
delete out.payg;
|
|
63062
|
+
delete out.sendOverflow;
|
|
63063
|
+
return out;
|
|
63064
|
+
}
|
|
63065
|
+
async function phonePricing(opts) {
|
|
63066
|
+
const res = await fetch(`${SITE3}/api/identity/catalog`, { headers: { accept: "application/json" } });
|
|
63067
|
+
if (!res.ok) throw new Error(`phone catalog: HTTP ${res.status}`);
|
|
63068
|
+
const body = await res.json();
|
|
63069
|
+
const slice = phoneSlice(body);
|
|
63070
|
+
if (opts.json) {
|
|
63071
|
+
process.stdout.write(JSON.stringify(slice, null, 2) + "\n");
|
|
63072
|
+
return;
|
|
63073
|
+
}
|
|
63074
|
+
const product = slice.products?.[0];
|
|
63075
|
+
if (!product || product.available === false) {
|
|
63076
|
+
process.stdout.write(` ${import_picocolors5.default.dim(product?.brief || "Phone numbers are not on sale right now.")}
|
|
63077
|
+
`);
|
|
63078
|
+
return;
|
|
63079
|
+
}
|
|
63080
|
+
const plans = slice.prices ?? [];
|
|
63081
|
+
process.stdout.write(`
|
|
63082
|
+
${import_picocolors5.default.bold("PHONE NUMBERS")} ${import_picocolors5.default.dim("texts and calls, on a wallet plan")}
|
|
63083
|
+
|
|
63084
|
+
`);
|
|
63085
|
+
for (const p of plans) {
|
|
63086
|
+
const count = p.phones ?? 1;
|
|
63087
|
+
const price = usd2(p.priceUsd).padStart(4);
|
|
63088
|
+
const term = `/${p.units} days`.padEnd(9);
|
|
63089
|
+
process.stdout.write(` ${import_picocolors5.default.bold(p.rung.padEnd(11))} ${import_picocolors5.default.cyan(price)}${import_picocolors5.default.dim(term)} ${import_picocolors5.default.dim(`${count} number${count === 1 ? "" : "s"}`)}
|
|
63090
|
+
`);
|
|
63091
|
+
}
|
|
63092
|
+
if (plans.length === 0) process.stdout.write(` ${import_picocolors5.default.dim("no plan rungs are priced right now")}
|
|
63093
|
+
`);
|
|
63094
|
+
const u = slice.phoneUsage;
|
|
63095
|
+
if (u) {
|
|
63096
|
+
const meter = [
|
|
63097
|
+
u.textUsd ? `text ${usd2(u.textUsd)}` : "",
|
|
63098
|
+
u.minuteUsd ? `call minute ${usd2(u.minuteUsd)}` : "",
|
|
63099
|
+
u.waitCodeUsd !== void 0 ? `wait-code ${Number(u.waitCodeUsd) === 0 ? "free" : usd2(u.waitCodeUsd)}` : ""
|
|
63100
|
+
].filter(Boolean).join(" \xB7 ");
|
|
63101
|
+
process.stdout.write(`
|
|
63102
|
+
${import_picocolors5.default.dim(`usage, from the prepaid balance: ${meter}`)}
|
|
63103
|
+
`);
|
|
63104
|
+
if (u.sendingNote) process.stdout.write(` ${import_picocolors5.default.dim(u.sendingNote)}
|
|
63105
|
+
`);
|
|
63106
|
+
}
|
|
63107
|
+
const op = slice.operator;
|
|
63108
|
+
if (op?.available && op.minuteUsd) {
|
|
63109
|
+
process.stdout.write(`
|
|
63110
|
+
${import_picocolors5.default.bold("THE OPERATOR")} ${import_picocolors5.default.dim("our brain, voice and ears on the line; the transcript and the outcome back")}
|
|
63111
|
+
|
|
63112
|
+
`);
|
|
63113
|
+
process.stdout.write(` ${import_picocolors5.default.cyan(usd2(op.minuteUsd))} ${import_picocolors5.default.dim(`a minute, all in, up to ${op.maxMinutes ?? "?"} minutes a call, from the prepaid balance`)}
|
|
63114
|
+
`);
|
|
63115
|
+
process.stdout.write(` ${import_picocolors5.default.dim(op.house ? 'on your number, or from the house number with none: agentgates call <number> "<what to get done>"' : 'on your number: agentgates call <number> "<what to get done>"')}
|
|
63116
|
+
`);
|
|
63117
|
+
} else if (op?.note) {
|
|
63118
|
+
process.stdout.write(`
|
|
63119
|
+
${import_picocolors5.default.dim(op.note)}
|
|
63120
|
+
`);
|
|
63121
|
+
}
|
|
63122
|
+
const call = slice.booth?.call;
|
|
63123
|
+
const windows = call?.windows ?? [];
|
|
63124
|
+
if (call?.available && windows.length) {
|
|
63125
|
+
process.stdout.write(`
|
|
63126
|
+
${import_picocolors5.default.bold("PAYPHONE")} ${import_picocolors5.default.dim("no plan, no number, no account: one x402 payment, one call")}
|
|
63127
|
+
|
|
63128
|
+
`);
|
|
63129
|
+
const ladder = windows.map((w) => `${w.minutes} min ${usd2(w.priceUsd)}${w.operatorPriceUsd ? import_picocolors5.default.dim(` (${usd2(w.operatorPriceUsd)} with the operator)`) : ""}`).join(" ");
|
|
63130
|
+
process.stdout.write(` ${ladder}
|
|
63131
|
+
`);
|
|
63132
|
+
}
|
|
63133
|
+
const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
|
|
63134
|
+
if (nets.length) process.stdout.write(`
|
|
63135
|
+
${import_picocolors5.default.dim(`USDC on ${nets.join(", ")}`)}
|
|
63136
|
+
|
|
63137
|
+
`);
|
|
63138
|
+
else process.stdout.write("\n");
|
|
63139
|
+
}
|
|
63140
|
+
function printCall(c, from, perMinuteUsd, full) {
|
|
63141
|
+
process.stdout.write(`
|
|
63142
|
+
${status(c.status)} ${import_picocolors5.default.bold(c.id)} ${import_picocolors5.default.dim(c.peer)}${from ? import_picocolors5.default.dim(` from ${from}`) : ""}${seconds(c.seconds) ? import_picocolors5.default.dim(` ${seconds(c.seconds)}`) : ""}
|
|
63143
|
+
`);
|
|
63144
|
+
if (c.task) process.stdout.write(` ${c.task}
|
|
63145
|
+
`);
|
|
63146
|
+
if (perMinuteUsd) process.stdout.write(` ${import_picocolors5.default.dim(`${usd2(perMinuteUsd)} a minute, from the balance`)}
|
|
63147
|
+
`);
|
|
63148
|
+
if (c.billedUsd) process.stdout.write(` ${import_picocolors5.default.dim(`billed ${usd2(c.billedUsd)}`)}
|
|
63149
|
+
`);
|
|
63150
|
+
const lines = transcriptLines(c.transcript);
|
|
63151
|
+
const outcome = lines.find((l) => l.role === "outcome");
|
|
63152
|
+
if (outcome) process.stdout.write(`
|
|
63153
|
+
${import_picocolors5.default.bold("Outcome")}
|
|
63154
|
+
${outcome.text}
|
|
63155
|
+
`);
|
|
63156
|
+
if (full) {
|
|
63157
|
+
const said = lines.filter((l) => l.role !== "outcome");
|
|
63158
|
+
if (said.length) {
|
|
63159
|
+
process.stdout.write(`
|
|
63160
|
+
${import_picocolors5.default.bold("Transcript")}
|
|
63161
|
+
`);
|
|
63162
|
+
for (const l of said) process.stdout.write(` ${import_picocolors5.default.dim((l.role === "agent" ? "operator" : l.role).padEnd(9))} ${l.text}
|
|
63163
|
+
`);
|
|
63164
|
+
}
|
|
63165
|
+
if (c.recordingUrl) process.stdout.write(`
|
|
63166
|
+
${import_picocolors5.default.dim("recording:")} ${c.recordingUrl}
|
|
63167
|
+
`);
|
|
63168
|
+
}
|
|
63169
|
+
process.stdout.write("\n");
|
|
63170
|
+
}
|
|
63171
|
+
async function phoneCall(toRaw, words7, opts) {
|
|
63172
|
+
const task = words7.join(" ").trim();
|
|
63173
|
+
const brain = opts.brain === "yours" ? "yours" : "ours";
|
|
63174
|
+
if (!task && brain === "ours") return refuse(opts, 'say what the call is for: agentgates call +14155550142 "ask if they have a table for two at 8"', "bad_request");
|
|
63175
|
+
if (brain === "yours" && !opts.webhook) return refuse(opts, "--brain yours needs --webhook <url>: the transcript is POSTed there and the reply is the next sentence", "bad_request");
|
|
63176
|
+
if (opts.from && opts.house) return refuse(opts, "--from names one of your numbers and --house forces the house number: one or the other", "bad_request");
|
|
63177
|
+
try {
|
|
63178
|
+
const { operator, countries } = await readOperator();
|
|
63179
|
+
if (!operator?.available) return refuse(opts, operator?.note ?? "the AI operator is not open on this deployment", "calls_dark");
|
|
63180
|
+
const to = toE164(toRaw, countryCodeFor(countries));
|
|
63181
|
+
if (!to) return refuse(opts, `"${toRaw}" is not a number this lane dials: E.164 (+14155550142), or ten digits in ${countries[0] ?? "the lane's country"}`, "bad_request");
|
|
63182
|
+
const keys2 = await requirePasswordsKey();
|
|
63183
|
+
let phoneId = null;
|
|
63184
|
+
let fromNumber = null;
|
|
63185
|
+
if (!opts.house) {
|
|
63186
|
+
const numbers = await listNumbers(keys2.wallet);
|
|
63187
|
+
const picked = opts.from ? numbers.find((n2) => n2.id === opts.from || n2.number === opts.from) ?? null : numbers[0] ?? null;
|
|
63188
|
+
if (opts.from && !picked) return refuse(opts, `no active number "${opts.from}" under this account: agentgates phone calls lists them`, "not_found");
|
|
63189
|
+
if (picked) {
|
|
63190
|
+
phoneId = picked.id;
|
|
63191
|
+
fromNumber = picked.number;
|
|
63192
|
+
}
|
|
63193
|
+
}
|
|
63194
|
+
if (!phoneId && operator.house === false) {
|
|
63195
|
+
return refuse(opts, "no number under this account and no house number stands right now: a phone plan (agentgates phone pricing) puts one on it", "pool_empty");
|
|
63196
|
+
}
|
|
63197
|
+
const body = { to, task, brain, persona: { name: "Riley" } };
|
|
63198
|
+
if (opts.webhook) body.webhook = opts.webhook;
|
|
63199
|
+
if (opts.greeting) body.greeting = opts.greeting.slice(0, 300);
|
|
63200
|
+
if (opts.voice) body.voice = opts.voice;
|
|
63201
|
+
const placed = await placeCall(keys2.wallet, phoneId, body);
|
|
63202
|
+
const from = fromNumber ?? "the house number";
|
|
63203
|
+
if (!opts.wait) {
|
|
63204
|
+
emit2(opts, { ok: true, from: placed.from, phoneId, callId: placed.callId, call: placed.call, perMinuteUsd: placed.perMinuteUsd, via: lastAuthVia(), loginKeyRevoked: loginKeyWasRevoked() }, () => {
|
|
63205
|
+
printCall(placed.call, from, placed.perMinuteUsd, false);
|
|
63206
|
+
process.stdout.write(` ${import_picocolors5.default.dim(`read it back: agentgates calls ${placed.callId} --wait`)}
|
|
63207
|
+
|
|
63208
|
+
`);
|
|
63209
|
+
});
|
|
63210
|
+
return;
|
|
63211
|
+
}
|
|
63212
|
+
const maxSeconds = typeof opts.wait === "string" ? Math.max(10, Number(opts.wait) || 0) : Math.max(120, (operator.maxMinutes ?? 10) * 60 + 60);
|
|
63213
|
+
let last = "";
|
|
63214
|
+
const ended = await waitForCall(keys2.wallet, phoneId, placed.callId, {
|
|
63215
|
+
maxSeconds,
|
|
63216
|
+
onTick: (c) => {
|
|
63217
|
+
if (jsonMode(opts) || c.status === last) return;
|
|
63218
|
+
last = c.status;
|
|
63219
|
+
process.stderr.write(` ${import_picocolors5.default.dim(STATUS_WORD[c.status] ?? c.status)}
|
|
63220
|
+
`);
|
|
63221
|
+
}
|
|
63222
|
+
});
|
|
63223
|
+
emit2(opts, { ok: TERMINAL.has(ended.status), from: placed.from, phoneId, callId: ended.id, call: ended, perMinuteUsd: placed.perMinuteUsd }, () => {
|
|
63224
|
+
printCall(ended, from, placed.perMinuteUsd, true);
|
|
63225
|
+
if (!TERMINAL.has(ended.status)) process.stdout.write(` ${import_picocolors5.default.dim(`still ${STATUS_WORD[ended.status] ?? ended.status}; read it later: agentgates calls ${ended.id} --wait`)}
|
|
63226
|
+
|
|
63227
|
+
`);
|
|
63228
|
+
});
|
|
63229
|
+
if (ended.status === "failed") process.exitCode = 1;
|
|
63230
|
+
} catch (err) {
|
|
63231
|
+
failFrom(opts, err);
|
|
63232
|
+
}
|
|
63233
|
+
}
|
|
63234
|
+
async function phoneCalls(id2, opts) {
|
|
63235
|
+
try {
|
|
63236
|
+
const keys2 = await requirePasswordsKey();
|
|
63237
|
+
const numbers = opts.house ? [] : await listNumbers(keys2.wallet);
|
|
63238
|
+
const picked = opts.from ? numbers.find((n2) => n2.id === opts.from || n2.number === opts.from) ?? null : numbers[0] ?? null;
|
|
63239
|
+
if (opts.from && !picked) return refuse(opts, `no active number "${opts.from}" under this account`, "not_found");
|
|
63240
|
+
const phoneId = picked?.id ?? null;
|
|
63241
|
+
const from = picked?.number ?? "the house number";
|
|
63242
|
+
if (id2) {
|
|
63243
|
+
let door = phoneId;
|
|
63244
|
+
const read = async () => {
|
|
63245
|
+
try {
|
|
63246
|
+
return await readCall(keys2.wallet, door, id2);
|
|
63247
|
+
} catch (err) {
|
|
63248
|
+
if (door && err instanceof WireError && err.status === 404) {
|
|
63249
|
+
door = null;
|
|
63250
|
+
return readCall(keys2.wallet, null, id2);
|
|
63251
|
+
}
|
|
63252
|
+
throw err;
|
|
63253
|
+
}
|
|
63254
|
+
};
|
|
63255
|
+
const first = await read();
|
|
63256
|
+
const call = opts.wait && !TERMINAL.has(first.status) ? await waitForCall(keys2.wallet, door, id2, { maxSeconds: typeof opts.wait === "string" ? Math.max(10, Number(opts.wait) || 0) : 720 }) : first;
|
|
63257
|
+
emit2(opts, { ok: true, call, from: door ? "number" : "house" }, () => printCall(call, door ? from : "the house number", null, true));
|
|
63258
|
+
return;
|
|
63259
|
+
}
|
|
63260
|
+
const calls = await listCalls(keys2.wallet, phoneId);
|
|
63261
|
+
emit2(opts, { ok: true, wallet: keys2.wallet.address, from: phoneId ? "number" : "house", phoneId, numbers: numbers.map((n2) => ({ id: n2.id, number: n2.number })), calls }, () => {
|
|
63262
|
+
process.stdout.write(`
|
|
63263
|
+
${import_picocolors5.default.bold("YOUR CALLS")} ${import_picocolors5.default.dim(`${keys2.wallet.address} \xB7 ${from}`)}
|
|
63264
|
+
|
|
63265
|
+
`);
|
|
63266
|
+
if (calls.length === 0) {
|
|
63267
|
+
process.stdout.write(` ${import_picocolors5.default.dim('none yet: agentgates call <number> "<what to get done>"')}
|
|
63268
|
+
|
|
63269
|
+
`);
|
|
63270
|
+
return;
|
|
63271
|
+
}
|
|
63272
|
+
for (const c of calls) {
|
|
63273
|
+
process.stdout.write(` ${status(c.status)} ${c.id} ${import_picocolors5.default.dim(c.peer.padEnd(16))} ${import_picocolors5.default.dim(seconds(c.seconds).padEnd(8))} ${import_picocolors5.default.dim(when(c.startedAt ?? c.createdAt))}
|
|
63274
|
+
`);
|
|
63275
|
+
if (c.task) process.stdout.write(` ${c.task.length > 90 ? `${c.task.slice(0, 89)}\u2026` : c.task}
|
|
63276
|
+
`);
|
|
63277
|
+
}
|
|
63278
|
+
process.stdout.write("\n");
|
|
63279
|
+
});
|
|
63280
|
+
} catch (err) {
|
|
63281
|
+
failFrom(opts, err);
|
|
63282
|
+
}
|
|
63283
|
+
}
|
|
63284
|
+
|
|
63285
|
+
// src/commands/email.ts
|
|
63286
|
+
var import_picocolors6 = __toESM(require_picocolors(), 1);
|
|
63287
|
+
var SITE4 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
|
|
63288
|
+
var usd3 = (v) => {
|
|
63289
|
+
const n2 = Number(v);
|
|
63290
|
+
if (Number.isInteger(n2)) return `$${n2}`;
|
|
63291
|
+
const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
|
|
63292
|
+
return `$${whole}.${frac.padEnd(2, "0")}`;
|
|
63293
|
+
};
|
|
63294
|
+
var family = (rung) => {
|
|
63295
|
+
const base = rung.replace(/-?(month|year)$/, "");
|
|
63296
|
+
return base === "" ? "Starter" : base.charAt(0).toUpperCase() + base.slice(1);
|
|
63297
|
+
};
|
|
63298
|
+
function emailSlice(body) {
|
|
63299
|
+
const out = {
|
|
63300
|
+
...body,
|
|
63301
|
+
products: (body.products ?? []).filter((p) => p.id === "inbox"),
|
|
63302
|
+
rungs: (body.rungs ?? []).filter((r) => r.product === "inbox"),
|
|
63303
|
+
prices: (body.prices ?? []).filter((p) => p.product === "inbox")
|
|
63304
|
+
};
|
|
63305
|
+
for (const k of ["booth", "phoneUsage", "voices", "operator", "countries"]) {
|
|
63306
|
+
delete out[k];
|
|
63307
|
+
}
|
|
63308
|
+
return out;
|
|
63309
|
+
}
|
|
63310
|
+
async function emailPricing(opts) {
|
|
63311
|
+
const res = await fetch(`${SITE4}/api/identity/catalog`, { headers: { accept: "application/json" } });
|
|
63312
|
+
if (!res.ok) throw new Error(`email catalog: HTTP ${res.status}`);
|
|
63313
|
+
const body = await res.json();
|
|
63314
|
+
const slice = emailSlice(body);
|
|
63315
|
+
const product = slice.products?.[0];
|
|
63316
|
+
if (opts.json) {
|
|
63317
|
+
process.stdout.write(JSON.stringify(slice, null, 2) + "\n");
|
|
63318
|
+
if (!product || product.available === false) process.exitCode = 1;
|
|
63319
|
+
return;
|
|
63320
|
+
}
|
|
63321
|
+
if (!product || product.available === false) {
|
|
63322
|
+
process.stdout.write(` ${import_picocolors6.default.dim(product?.note || product?.brief || "Inboxes are not on sale right now.")}
|
|
63323
|
+
`);
|
|
63324
|
+
process.exitCode = 1;
|
|
63325
|
+
return;
|
|
63326
|
+
}
|
|
63327
|
+
process.stdout.write(`
|
|
63328
|
+
${import_picocolors6.default.bold("EMAIL")} ${import_picocolors6.default.dim(product.brief || "an inbox on your wallet")}
|
|
63329
|
+
|
|
63330
|
+
`);
|
|
63331
|
+
const freeInboxes = slice.payg?.inboxes;
|
|
63332
|
+
if (freeInboxes) {
|
|
63333
|
+
const at = product.domain ? ` @ ${product.domain}` : "";
|
|
63334
|
+
process.stdout.write(
|
|
63335
|
+
` ${import_picocolors6.default.bold("free".padEnd(11))} ${import_picocolors6.default.cyan("$0".padStart(4))}${"".padEnd(11)} ${import_picocolors6.default.dim(`${freeInboxes} inbox${freeInboxes === 1 ? "" : "es"}${at}, behind a funded balance`)}
|
|
63336
|
+
`
|
|
63337
|
+
);
|
|
63338
|
+
}
|
|
63339
|
+
const plans = slice.prices ?? [];
|
|
63340
|
+
const families = [];
|
|
63341
|
+
const byFamily = /* @__PURE__ */ new Map();
|
|
63342
|
+
for (const p of plans) {
|
|
63343
|
+
const f2 = family(p.rung);
|
|
63344
|
+
if (!byFamily.has(f2)) {
|
|
63345
|
+
byFamily.set(f2, []);
|
|
63346
|
+
families.push(f2);
|
|
63347
|
+
}
|
|
63348
|
+
byFamily.get(f2).push(p);
|
|
63349
|
+
}
|
|
63350
|
+
for (const f2 of families) {
|
|
63351
|
+
const rows = byFamily.get(f2).sort((a, b2) => a.units - b2.units);
|
|
63352
|
+
const cells = rows.map((p) => `${import_picocolors6.default.cyan(usd3(p.priceUsd).padStart(4))}${import_picocolors6.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
|
|
63353
|
+
const lead = rows[0];
|
|
63354
|
+
const cap = [
|
|
63355
|
+
lead.inboxes ? `${lead.inboxes} inbox${lead.inboxes === 1 ? "" : "es"}` : "",
|
|
63356
|
+
lead.sendsPerDay ? `${lead.sendsPerDay} sends/day` : ""
|
|
63357
|
+
].filter(Boolean).join(" \xB7 ");
|
|
63358
|
+
process.stdout.write(` ${import_picocolors6.default.bold(f2.padEnd(11))} ${cells} ${import_picocolors6.default.dim(cap)}
|
|
63359
|
+
`);
|
|
63360
|
+
}
|
|
63361
|
+
if (plans.length === 0) process.stdout.write(` ${import_picocolors6.default.dim("no plan rungs are priced right now")}
|
|
63362
|
+
`);
|
|
63363
|
+
const send2 = slice.sendOverflow?.priceUsd;
|
|
63364
|
+
const wait2 = body.phoneUsage?.waitCodeUsd;
|
|
63365
|
+
const meter = [
|
|
63366
|
+
send2 ? `send ${usd3(send2)}` : "",
|
|
63367
|
+
wait2 !== void 0 ? `wait-code ${Number(wait2) === 0 ? "free" : usd3(wait2)}` : ""
|
|
63368
|
+
].filter(Boolean).join(" \xB7 ");
|
|
63369
|
+
if (meter) process.stdout.write(`
|
|
63370
|
+
${import_picocolors6.default.dim(`usage, from the prepaid balance: ${meter}`)}
|
|
63371
|
+
`);
|
|
63372
|
+
process.stdout.write(` ${import_picocolors6.default.dim("receiving costs nothing; the plan sells inboxes and sends per day")}
|
|
63373
|
+
`);
|
|
63374
|
+
const bal = slice.balance;
|
|
63375
|
+
if (bal?.note) process.stdout.write(` ${import_picocolors6.default.dim(bal.note)}
|
|
63376
|
+
`);
|
|
63377
|
+
else if (bal?.minTopUpUsd) process.stdout.write(` ${import_picocolors6.default.dim(`top up any amount from ${usd3(bal.minTopUpUsd)}`)}
|
|
63378
|
+
`);
|
|
63379
|
+
const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
|
|
63380
|
+
if (nets.length) process.stdout.write(`
|
|
63381
|
+
${import_picocolors6.default.dim(`USDC on ${nets.join(", ")}`)}
|
|
63382
|
+
|
|
63383
|
+
`);
|
|
63384
|
+
else process.stdout.write("\n");
|
|
63385
|
+
}
|
|
63386
|
+
function emailDoor(first) {
|
|
63387
|
+
process.stdout.write(
|
|
63388
|
+
`
|
|
63389
|
+
${first}, and this CLI has no signer yet.
|
|
63390
|
+
Do it from the wallet, one biometric: ${import_picocolors6.default.cyan(`${SITE4}/email`)}
|
|
63391
|
+
Prices from here: ${import_picocolors6.default.dim("agentgates email pricing")}
|
|
63392
|
+
|
|
63393
|
+
`
|
|
63394
|
+
);
|
|
63395
|
+
}
|
|
63396
|
+
async function emailCreate() {
|
|
63397
|
+
emailDoor("An inbox is created under your wallet's own signature");
|
|
63398
|
+
}
|
|
63399
|
+
async function emailSend() {
|
|
63400
|
+
emailDoor("A send signs with your wallet and draws from its balance");
|
|
63401
|
+
}
|
|
63402
|
+
|
|
63403
|
+
// src/commands/passwords.ts
|
|
63404
|
+
var import_picocolors8 = __toESM(require_picocolors(), 1);
|
|
63405
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
63406
|
+
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
63407
|
+
|
|
63408
|
+
// src/commands/session.ts
|
|
63409
|
+
var import_picocolors7 = __toESM(require_picocolors(), 1);
|
|
63410
|
+
|
|
63154
63411
|
// src/lib/session-bridge.ts
|
|
63155
63412
|
import { createServer } from "node:http";
|
|
63156
63413
|
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
@@ -63185,12 +63442,12 @@ function readBody(req, limit = 4096) {
|
|
|
63185
63442
|
req.on("error", reject);
|
|
63186
63443
|
});
|
|
63187
63444
|
}
|
|
63188
|
-
function json(res,
|
|
63189
|
-
res.writeHead(
|
|
63445
|
+
function json(res, status4, body) {
|
|
63446
|
+
res.writeHead(status4, { "content-type": "application/json", "cache-control": "no-store" });
|
|
63190
63447
|
res.end(JSON.stringify(body));
|
|
63191
63448
|
}
|
|
63192
|
-
function html(res,
|
|
63193
|
-
res.writeHead(
|
|
63449
|
+
function html(res, status4, body) {
|
|
63450
|
+
res.writeHead(status4, {
|
|
63194
63451
|
"content-type": "text/html; charset=utf-8",
|
|
63195
63452
|
"cache-control": "no-store",
|
|
63196
63453
|
"referrer-policy": "no-referrer",
|
|
@@ -63362,9 +63619,9 @@ function handoffCode(code, port) {
|
|
|
63362
63619
|
}
|
|
63363
63620
|
|
|
63364
63621
|
// src/commands/session.ts
|
|
63365
|
-
var
|
|
63366
|
-
function
|
|
63367
|
-
if (
|
|
63622
|
+
var jsonMode2 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
63623
|
+
function refuse2(opts, error, code = null) {
|
|
63624
|
+
if (jsonMode2(opts)) process.stdout.write(JSON.stringify({ ok: false, code, error }, null, 2) + "\n");
|
|
63368
63625
|
else process.stderr.write(` ${error}${code ? import_picocolors7.default.dim(` (${code})`) : ""}
|
|
63369
63626
|
`);
|
|
63370
63627
|
process.exit(1);
|
|
@@ -63382,10 +63639,10 @@ async function sessionOpen(opts) {
|
|
|
63382
63639
|
try {
|
|
63383
63640
|
keys2 = await requirePasswordsKey();
|
|
63384
63641
|
} catch (err) {
|
|
63385
|
-
return
|
|
63642
|
+
return refuse2(opts, err.message, "no_key");
|
|
63386
63643
|
}
|
|
63387
63644
|
const words7 = keys2.state.mnemonic;
|
|
63388
|
-
if (!words7) return
|
|
63645
|
+
if (!words7) return refuse2(opts, "this key was made without words (a bare key); only a twelve-word account can be handed to a browser. Mint one with init --replace.", "bare_key");
|
|
63389
63646
|
const address = keys2.wallet.address;
|
|
63390
63647
|
try {
|
|
63391
63648
|
await serveWordsOnce({
|
|
@@ -63393,7 +63650,7 @@ async function sessionOpen(opts) {
|
|
|
63393
63650
|
address,
|
|
63394
63651
|
waitMs,
|
|
63395
63652
|
onUrl: (url, port) => {
|
|
63396
|
-
if (
|
|
63653
|
+
if (jsonMode2(opts)) {
|
|
63397
63654
|
process.stdout.write(JSON.stringify({ ok: true, status: "waiting", url, port, address, waitSeconds: waitMs / 1e3 }) + "\n");
|
|
63398
63655
|
} else {
|
|
63399
63656
|
process.stdout.write(`
|
|
@@ -63408,12 +63665,12 @@ async function sessionOpen(opts) {
|
|
|
63408
63665
|
});
|
|
63409
63666
|
}
|
|
63410
63667
|
});
|
|
63411
|
-
if (
|
|
63668
|
+
if (jsonMode2(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "handed", address }) + "\n");
|
|
63412
63669
|
else process.stdout.write(` ${import_picocolors7.default.green("\u2713")} handed over; the browser is this account now.
|
|
63413
63670
|
|
|
63414
63671
|
`);
|
|
63415
63672
|
} catch (err) {
|
|
63416
|
-
return
|
|
63673
|
+
return refuse2(opts, err.message, "not_taken");
|
|
63417
63674
|
}
|
|
63418
63675
|
}
|
|
63419
63676
|
async function sessionReceive(opts) {
|
|
@@ -63423,7 +63680,7 @@ async function sessionReceive(opts) {
|
|
|
63423
63680
|
waitMs,
|
|
63424
63681
|
onCode: (code, port) => {
|
|
63425
63682
|
const typed = handoffCode(code, port);
|
|
63426
|
-
if (
|
|
63683
|
+
if (jsonMode2(opts)) {
|
|
63427
63684
|
process.stdout.write(JSON.stringify({ ok: true, status: "waiting", code: typed, port, waitSeconds: waitMs / 1e3 }) + "\n");
|
|
63428
63685
|
} else {
|
|
63429
63686
|
process.stdout.write(`
|
|
@@ -63437,14 +63694,14 @@ async function sessionReceive(opts) {
|
|
|
63437
63694
|
}
|
|
63438
63695
|
});
|
|
63439
63696
|
const { state } = await importPasswordsSeed({ seed: words7, replace: opts.replace === true });
|
|
63440
|
-
if (
|
|
63697
|
+
if (jsonMode2(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "received", address: state.address, path: passwordsKeyPath() }) + "\n");
|
|
63441
63698
|
else process.stdout.write(` ${import_picocolors7.default.green("\u2713")} this CLI is ${import_picocolors7.default.bold(state.address)} now
|
|
63442
63699
|
${import_picocolors7.default.dim(passwordsKeyPath())}
|
|
63443
63700
|
|
|
63444
63701
|
`);
|
|
63445
63702
|
} catch (err) {
|
|
63446
63703
|
const message = err.message;
|
|
63447
|
-
return
|
|
63704
|
+
return refuse2(opts, message, /already exists/.test(message) ? "key_exists" : "not_received");
|
|
63448
63705
|
}
|
|
63449
63706
|
}
|
|
63450
63707
|
|
|
@@ -63468,7 +63725,8 @@ var KDF_VERSIONS = Object.keys(KDF_SALTS).map(Number).sort((a, b2) => b2 - a);
|
|
|
63468
63725
|
var VAULT_WALLET_MESSAGE_V1 = "Agentgates Passwords vault key v1\nagentgates.ai\nThis signature encrypts your stored passwords. Sign it only here.";
|
|
63469
63726
|
var SECRET_KINDS = ["login", "api_key", "totp", "raw", "session", "oauth"];
|
|
63470
63727
|
var CLI_SECRET_KINDS = ["login", "api_key", "totp", "raw"];
|
|
63471
|
-
var USE_KINDS = ["header", "totp", "login"];
|
|
63728
|
+
var USE_KINDS = ["header", "totp", "login", "session", "reveal"];
|
|
63729
|
+
var ACTING_USES = ["header", "totp", "login"];
|
|
63472
63730
|
var SECRET_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
63473
63731
|
var HOSTNAME_RE = /^(?=.{1,253}$)([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
|
|
63474
63732
|
var MAX_HOSTS_PER_SECRET = 8;
|
|
@@ -63684,7 +63942,7 @@ function validatePermitRequest(owner, m, nowSeconds = Math.floor(Date.now() / 1e
|
|
|
63684
63942
|
if (m.uses.length < 1 || m.uses.length > USE_KINDS.length) throw new PasswordsSealError("name at least one use");
|
|
63685
63943
|
const seen = /* @__PURE__ */ new Set();
|
|
63686
63944
|
for (const u of m.uses) {
|
|
63687
|
-
if (!USE_KINDS.includes(u) || seen.has(u)) throw new PasswordsSealError(
|
|
63945
|
+
if (!USE_KINDS.includes(u) || seen.has(u)) throw new PasswordsSealError(`--uses takes distinct entries of ${USE_KINDS.join(", ")}`);
|
|
63688
63946
|
seen.add(u);
|
|
63689
63947
|
}
|
|
63690
63948
|
if (!Number.isInteger(m.expiresAt) || m.expiresAt <= nowSeconds) throw new PasswordsSealError("that expiry has already passed");
|
|
@@ -63811,16 +64069,16 @@ function loginKeyLines(login2) {
|
|
|
63811
64069
|
`;
|
|
63812
64070
|
}
|
|
63813
64071
|
var SITE5 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
|
|
63814
|
-
var
|
|
63815
|
-
function
|
|
63816
|
-
if (
|
|
64072
|
+
var jsonMode3 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
64073
|
+
function emit3(opts, data4, human) {
|
|
64074
|
+
if (jsonMode3(opts)) {
|
|
63817
64075
|
process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
|
|
63818
64076
|
return;
|
|
63819
64077
|
}
|
|
63820
64078
|
human();
|
|
63821
64079
|
}
|
|
63822
|
-
function
|
|
63823
|
-
if (
|
|
64080
|
+
function refuse3(opts, error, code, extra = {}) {
|
|
64081
|
+
if (jsonMode3(opts)) {
|
|
63824
64082
|
process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
|
|
63825
64083
|
} else {
|
|
63826
64084
|
process.stderr.write(` ${error}${code ? import_picocolors8.default.dim(` (${code})`) : ""}
|
|
@@ -63828,10 +64086,10 @@ function refuse2(opts, error, code, extra = {}) {
|
|
|
63828
64086
|
}
|
|
63829
64087
|
process.exit(1);
|
|
63830
64088
|
}
|
|
63831
|
-
function
|
|
63832
|
-
if (err instanceof WireError) return
|
|
63833
|
-
if (err instanceof PasswordsSealError) return
|
|
63834
|
-
return
|
|
64089
|
+
function failFrom2(opts, err) {
|
|
64090
|
+
if (err instanceof WireError) return refuse3(opts, err.message, err.code, { status: err.status });
|
|
64091
|
+
if (err instanceof PasswordsSealError) return refuse3(opts, err.message, "refused");
|
|
64092
|
+
return refuse3(opts, err.message ?? String(err), null);
|
|
63835
64093
|
}
|
|
63836
64094
|
var short = (addr) => `${addr.slice(0, 6)}\u2026${addr.slice(-4)}`;
|
|
63837
64095
|
var splitList = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
@@ -63843,6 +64101,17 @@ function parseUses(raw, dflt) {
|
|
|
63843
64101
|
}
|
|
63844
64102
|
return list;
|
|
63845
64103
|
}
|
|
64104
|
+
function parseGets(raw) {
|
|
64105
|
+
const v = (raw ?? "box").trim().toLowerCase();
|
|
64106
|
+
if (v === "box" || v === "session" || v === "password") return v;
|
|
64107
|
+
throw new PasswordsSealError("--gets is one of box, session, password");
|
|
64108
|
+
}
|
|
64109
|
+
function withLevel(uses, gets) {
|
|
64110
|
+
const out = uses.filter((u) => u !== "session" && u !== "reveal");
|
|
64111
|
+
if (gets !== "box") out.push("session");
|
|
64112
|
+
if (gets === "password") out.push("reveal");
|
|
64113
|
+
return out;
|
|
64114
|
+
}
|
|
63846
64115
|
function parseInt10(raw, name, dflt, min, max) {
|
|
63847
64116
|
if (raw === void 0 || raw === "") return dflt;
|
|
63848
64117
|
const n2 = Number(raw);
|
|
@@ -63949,7 +64218,7 @@ async function passwordsInit(opts) {
|
|
|
63949
64218
|
try {
|
|
63950
64219
|
if (opts.import) {
|
|
63951
64220
|
const { state: state2 } = await importPasswordsKey(opts.import, opts.replace === true);
|
|
63952
|
-
|
|
64221
|
+
emit3(opts, { ok: true, address: state2.address, created: false, imported: true, path: passwordsKeyPath() }, () => {
|
|
63953
64222
|
process.stdout.write(`
|
|
63954
64223
|
${import_picocolors8.default.green("\u2713")} key imported: ${import_picocolors8.default.bold(state2.address)}
|
|
63955
64224
|
${import_picocolors8.default.dim(passwordsKeyPath())}
|
|
@@ -63961,7 +64230,7 @@ async function passwordsInit(opts) {
|
|
|
63961
64230
|
if (opts.seed) {
|
|
63962
64231
|
const brought = await importPasswordsSeed({ seed: opts.seed, replace: opts.replace === true });
|
|
63963
64232
|
const login3 = await mintLoginKeyIfMissing(brought);
|
|
63964
|
-
|
|
64233
|
+
emit3(opts, { ok: true, address: brought.state.address, created: false, imported: true, words: SEED_WORDS, path: passwordsKeyPath(), ...loginKeyFields(login3) }, () => {
|
|
63965
64234
|
process.stdout.write(`
|
|
63966
64235
|
${import_picocolors8.default.green("\u2713")} twelve words taken: ${import_picocolors8.default.bold(brought.state.address)}
|
|
63967
64236
|
${import_picocolors8.default.dim(passwordsKeyPath())}
|
|
@@ -63972,7 +64241,7 @@ async function passwordsInit(opts) {
|
|
|
63972
64241
|
if (opts.revealSeed) {
|
|
63973
64242
|
const { state: state2 } = await requirePasswordsKey();
|
|
63974
64243
|
if (!state2.mnemonic) throw new Error("this key was made without words (a bare key); mint a new one with init --replace, or bring words with init --seed.");
|
|
63975
|
-
|
|
64244
|
+
emit3(opts, { ok: true, address: state2.address, seed: state2.mnemonic }, () => {
|
|
63976
64245
|
process.stdout.write(`
|
|
63977
64246
|
${state2.mnemonic}
|
|
63978
64247
|
|
|
@@ -63985,7 +64254,7 @@ async function passwordsInit(opts) {
|
|
|
63985
64254
|
const made = await loadOrCreatePasswordsKey();
|
|
63986
64255
|
const { state, created, minted } = made;
|
|
63987
64256
|
const login2 = await mintLoginKeyIfMissing(made);
|
|
63988
|
-
|
|
64257
|
+
emit3(opts, { ok: true, address: state.address, created, path: passwordsKeyPath(), ...minted ? { seed: minted.seed } : {}, ...loginKeyFields(login2) }, () => {
|
|
63989
64258
|
process.stdout.write(
|
|
63990
64259
|
`
|
|
63991
64260
|
${import_picocolors8.default.green("\u2713")} ${created ? "key minted" : "key already here"}: ${import_picocolors8.default.bold(state.address)}
|
|
@@ -64005,7 +64274,7 @@ async function passwordsInit(opts) {
|
|
|
64005
64274
|
);
|
|
64006
64275
|
});
|
|
64007
64276
|
} catch (err) {
|
|
64008
|
-
|
|
64277
|
+
failFrom2(opts, err);
|
|
64009
64278
|
}
|
|
64010
64279
|
}
|
|
64011
64280
|
async function passwordsAdd(opts) {
|
|
@@ -64047,7 +64316,7 @@ async function passwordsAdd(opts) {
|
|
|
64047
64316
|
cvmBlob,
|
|
64048
64317
|
cvmKeyId: att.keyId
|
|
64049
64318
|
});
|
|
64050
|
-
|
|
64319
|
+
emit3(opts, { ok: true, id: row.id, label: row.label, kind: row.kind, hosts: row.hosts, username: row.username ?? null, owner: wallet.address }, () => {
|
|
64051
64320
|
process.stdout.write(
|
|
64052
64321
|
`
|
|
64053
64322
|
${import_picocolors8.default.green("\u2713")} stored ${import_picocolors8.default.bold(row.label)} for ${row.hosts.join(", ")}
|
|
@@ -64061,7 +64330,7 @@ async function passwordsAdd(opts) {
|
|
|
64061
64330
|
);
|
|
64062
64331
|
});
|
|
64063
64332
|
} catch (err) {
|
|
64064
|
-
|
|
64333
|
+
failFrom2(opts, err);
|
|
64065
64334
|
}
|
|
64066
64335
|
}
|
|
64067
64336
|
async function passwordsAllow(opts) {
|
|
@@ -64076,14 +64345,14 @@ async function passwordsAllow(opts) {
|
|
|
64076
64345
|
secretIds,
|
|
64077
64346
|
hosts: splitList(opts.hosts),
|
|
64078
64347
|
usesPerDay: parseInt10(opts.perDay, "--per-day", 0, 0, 1e6),
|
|
64079
|
-
uses: parseUses(opts.uses, [...
|
|
64348
|
+
uses: withLevel(parseUses(opts.uses, [...ACTING_USES]), parseGets(opts.gets)),
|
|
64080
64349
|
expiresAt: Math.floor(Date.now() / 1e3) + days * 86400,
|
|
64081
64350
|
approveEachUse: opts.askMe === true
|
|
64082
64351
|
};
|
|
64083
64352
|
const self2 = agent.toLowerCase() === wallet.address.toLowerCase();
|
|
64084
64353
|
const signed2 = await signPermit(wallet, request);
|
|
64085
64354
|
const permit = await postPermit(wallet, signed2);
|
|
64086
|
-
|
|
64355
|
+
emit3(opts, { ok: true, permitId: permit.id, agent: permit.agent, self: self2, secretIds: permit.secretIds, hosts: permit.hosts, uses: permit.uses, usesPerDay: permit.usesPerDay, approveEachUse: permit.approveEachUse, expiresAt: permit.expiresAt }, () => {
|
|
64087
64356
|
process.stdout.write(
|
|
64088
64357
|
`
|
|
64089
64358
|
${import_picocolors8.default.green("\u2713")} ${self2 ? "you may use" : `${short(permit.agent)} may use`} ${permit.secretIds[0] === "*" ? "every login this key holds" : `${permit.secretIds.length} login${permit.secretIds.length === 1 ? "" : "s"}`} for ${permit.uses.join(", ")} until ${permit.expiresAt.slice(0, 10)}
|
|
@@ -64093,14 +64362,14 @@ async function passwordsAllow(opts) {
|
|
|
64093
64362
|
);
|
|
64094
64363
|
});
|
|
64095
64364
|
} catch (err) {
|
|
64096
|
-
|
|
64365
|
+
failFrom2(opts, err);
|
|
64097
64366
|
}
|
|
64098
64367
|
}
|
|
64099
64368
|
async function passwordsList(opts) {
|
|
64100
64369
|
try {
|
|
64101
64370
|
const { wallet } = await requirePasswordsKey();
|
|
64102
64371
|
const { passwords: passwords2, permitted } = await listRows(wallet);
|
|
64103
|
-
|
|
64372
|
+
emit3(opts, { ok: true, address: wallet.address, passwords: passwords2, permitted }, () => {
|
|
64104
64373
|
process.stdout.write(`
|
|
64105
64374
|
${import_picocolors8.default.bold(short(wallet.address))}
|
|
64106
64375
|
|
|
@@ -64126,7 +64395,7 @@ async function passwordsList(opts) {
|
|
|
64126
64395
|
process.stdout.write("\n");
|
|
64127
64396
|
});
|
|
64128
64397
|
} catch (err) {
|
|
64129
|
-
|
|
64398
|
+
failFrom2(opts, err);
|
|
64130
64399
|
}
|
|
64131
64400
|
}
|
|
64132
64401
|
async function rowForUrl(wallet, url) {
|
|
@@ -64144,16 +64413,37 @@ async function rowForUrl(wallet, url) {
|
|
|
64144
64413
|
if (lent) return lent.id;
|
|
64145
64414
|
throw new PasswordsSealError(`no login this key holds or may use covers ${host2}; pass --row <id>, or add one`);
|
|
64146
64415
|
}
|
|
64147
|
-
function printUseAnswer(opts,
|
|
64148
|
-
const data4 = { ok: body.ok === true, status:
|
|
64149
|
-
|
|
64150
|
-
|
|
64416
|
+
function printUseAnswer(opts, status4, body) {
|
|
64417
|
+
const data4 = { ok: body.ok === true, status: status4, ...body };
|
|
64418
|
+
const cookies = status4 === 200 && Array.isArray(body.result?.cookies) ? body.result.cookies : null;
|
|
64419
|
+
if (cookies && opts.cookiesOut) {
|
|
64420
|
+
writeFileSync(opts.cookiesOut, JSON.stringify(cookies, null, 2), { mode: 384 });
|
|
64421
|
+
data4.cookiesOut = opts.cookiesOut;
|
|
64422
|
+
}
|
|
64423
|
+
emit3(opts, data4, () => {
|
|
64424
|
+
if (status4 === 200) {
|
|
64151
64425
|
const result = body.result ?? {};
|
|
64152
64426
|
const code = typeof result.code === "string" ? result.code : "ok";
|
|
64153
64427
|
const digest = typeof result.digest === "string" ? result.digest : "";
|
|
64154
64428
|
process.stdout.write(`
|
|
64155
64429
|
${import_picocolors8.default.green("\u2713")} ${code}${body.seconds ? import_picocolors8.default.dim(` ${body.seconds}s`) : ""}${body.chargedUsd && body.chargedUsd !== "0.00" ? import_picocolors8.default.dim(` $${body.chargedUsd}`) : ""}
|
|
64156
64430
|
`);
|
|
64431
|
+
if (cookies) {
|
|
64432
|
+
process.stdout.write(` ${cookies.length} cookie${cookies.length === 1 ? "" : "s"} for ${import_picocolors8.default.bold(String(result.url ?? ""))}${opts.cookiesOut ? import_picocolors8.default.dim(` \u2192 ${opts.cookiesOut}`) : import_picocolors8.default.dim(" (--cookies-out <file> writes them; --json prints them)")}
|
|
64433
|
+
|
|
64434
|
+
`);
|
|
64435
|
+
return;
|
|
64436
|
+
}
|
|
64437
|
+
if (result.secret && typeof result.secret === "object") {
|
|
64438
|
+
process.stdout.write(` ${import_picocolors8.default.dim("the permit hands this key the secret itself; it is on your screen now")}
|
|
64439
|
+
`);
|
|
64440
|
+
for (const [k, v] of Object.entries(result.secret)) process.stdout.write(` ${import_picocolors8.default.dim(k.padEnd(10))} ${v}
|
|
64441
|
+
`);
|
|
64442
|
+
if (typeof result.username === "string" && result.username) process.stdout.write(` ${import_picocolors8.default.dim("username".padEnd(10))} ${result.username}
|
|
64443
|
+
`);
|
|
64444
|
+
process.stdout.write("\n");
|
|
64445
|
+
return;
|
|
64446
|
+
}
|
|
64157
64447
|
if (digest) process.stdout.write(`
|
|
64158
64448
|
${digest.split("\n").map((l) => ` ${l}`).join("\n")}
|
|
64159
64449
|
`);
|
|
@@ -64164,7 +64454,7 @@ ${digest.split("\n").map((l) => ` ${l}`).join("\n")}
|
|
|
64164
64454
|
return;
|
|
64165
64455
|
}
|
|
64166
64456
|
process.stdout.write(`
|
|
64167
|
-
${body.error ?? `HTTP ${
|
|
64457
|
+
${body.error ?? `HTTP ${status4}`}${body.code ? import_picocolors8.default.dim(` (${body.code})`) : ""}
|
|
64168
64458
|
${body.useId ? ` ${import_picocolors8.default.dim("use")} ${body.useId}
|
|
64169
64459
|
` : ""}
|
|
64170
64460
|
`);
|
|
@@ -64191,29 +64481,47 @@ async function passwordsUse(opts) {
|
|
|
64191
64481
|
throw new PasswordsSealError("--steps-json is not JSON");
|
|
64192
64482
|
}
|
|
64193
64483
|
}
|
|
64194
|
-
if (use !== "totp" && typeof request.url !== "string") throw new PasswordsSealError("--url is the https URL the use targets");
|
|
64484
|
+
if (use !== "totp" && use !== "reveal" && typeof request.url !== "string") throw new PasswordsSealError("--url is the https URL the use targets");
|
|
64195
64485
|
const rowId = opts.row ?? await rowForUrl(wallet, request.url);
|
|
64196
64486
|
const waitCap = opts.wait !== void 0 ? parseInt10(opts.wait, "--wait", 0, 0, 3600) : null;
|
|
64197
|
-
|
|
64487
|
+
const firstBody = { use, request: use === "totp" && Object.keys(request).length === 0 ? void 0 : request };
|
|
64488
|
+
let lastBody = firstBody;
|
|
64489
|
+
let answer = await postUse(wallet, rowId, firstBody);
|
|
64198
64490
|
const startedAt = Date.now();
|
|
64199
|
-
|
|
64491
|
+
const boxBudgetEnd = waitCap !== null ? startedAt + waitCap * 1e3 : startedAt + 24e4;
|
|
64492
|
+
while (!opts.noWait) {
|
|
64200
64493
|
const body2 = answer.body ?? {};
|
|
64201
|
-
if (
|
|
64202
|
-
|
|
64203
|
-
|
|
64204
|
-
|
|
64205
|
-
|
|
64206
|
-
|
|
64207
|
-
|
|
64208
|
-
|
|
64494
|
+
if (answer.status === 202) {
|
|
64495
|
+
if (!body2.useId) break;
|
|
64496
|
+
const expiresAt = body2.expiresAt ? Date.parse(body2.expiresAt) : NaN;
|
|
64497
|
+
const deadline = Math.min(
|
|
64498
|
+
Number.isFinite(expiresAt) ? expiresAt : Date.now() + 6e5,
|
|
64499
|
+
waitCap !== null ? startedAt + waitCap * 1e3 : Number.POSITIVE_INFINITY
|
|
64500
|
+
);
|
|
64501
|
+
if (Date.now() >= deadline) break;
|
|
64502
|
+
if (!jsonMode3(opts)) process.stderr.write(` ${import_picocolors8.default.dim(body2.error ?? "waiting for the owner")}
|
|
64503
|
+
`);
|
|
64504
|
+
lastBody = { ...firstBody, useId: body2.useId, wait: 25 };
|
|
64505
|
+
answer = await postUse(wallet, rowId, lastBody);
|
|
64506
|
+
continue;
|
|
64507
|
+
}
|
|
64508
|
+
const named = body2.startingInSeconds ?? body2.retryInSeconds;
|
|
64509
|
+
if (answer.status === 503 && typeof named === "number") {
|
|
64510
|
+
const seconds2 = Math.min(120, Math.max(5, Math.ceil(named)));
|
|
64511
|
+
if (Date.now() + seconds2 * 1e3 > boxBudgetEnd) break;
|
|
64512
|
+
if (!jsonMode3(opts)) process.stderr.write(` ${import_picocolors8.default.dim(`${body2.error ?? "the box is not ready"}; trying again in ${seconds2}s`)}
|
|
64209
64513
|
`);
|
|
64210
|
-
|
|
64514
|
+
await new Promise((r) => setTimeout(r, seconds2 * 1e3));
|
|
64515
|
+
answer = await postUse(wallet, rowId, lastBody);
|
|
64516
|
+
continue;
|
|
64517
|
+
}
|
|
64518
|
+
break;
|
|
64211
64519
|
}
|
|
64212
64520
|
const body = answer.body ?? {};
|
|
64213
64521
|
printUseAnswer(opts, answer.status, body);
|
|
64214
64522
|
if (answer.status !== 200 && !(answer.status === 202 && opts.noWait)) process.exitCode = 1;
|
|
64215
64523
|
} catch (err) {
|
|
64216
|
-
|
|
64524
|
+
failFrom2(opts, err);
|
|
64217
64525
|
}
|
|
64218
64526
|
}
|
|
64219
64527
|
function joinPath() {
|
|
@@ -64227,7 +64535,7 @@ async function passwordsInvite(opts) {
|
|
|
64227
64535
|
const { envelope: envelope2, signature } = decodeInviteFragment(hash2);
|
|
64228
64536
|
if (inviteSigner(envelope2, signature) !== wallet.address.toLowerCase()) throw new PasswordsSealError("that invitation was not signed by this key");
|
|
64229
64537
|
const out = await withdrawInvite(wallet, envelope2, signature);
|
|
64230
|
-
|
|
64538
|
+
emit3(opts, { ok: true, withdrawn: true, nonce: out.nonce }, () => {
|
|
64231
64539
|
process.stdout.write(`
|
|
64232
64540
|
${import_picocolors8.default.green("\u2713")} withdrawn; that link opens nothing now
|
|
64233
64541
|
|
|
@@ -64237,7 +64545,7 @@ async function passwordsInvite(opts) {
|
|
|
64237
64545
|
}
|
|
64238
64546
|
const minutes = parseInt10(opts.minutes, "--minutes", INVITE_DEFAULT_MINUTES, INVITE_MIN_MINUTES, INVITE_MAX_MINUTES);
|
|
64239
64547
|
const days = parseInt10(opts.days, "--days", 30, 1, MAX_PERMIT_DAYS);
|
|
64240
|
-
const uses = parseUses(opts.uses, [...
|
|
64548
|
+
const uses = withLevel(parseUses(opts.uses, [...ACTING_USES]), parseGets(opts.gets));
|
|
64241
64549
|
const { passwords: passwords2 } = await listRows(wallet);
|
|
64242
64550
|
const wanted = opts.rows ? splitList(opts.rows) : passwords2.map((r) => r.id);
|
|
64243
64551
|
if (wanted.length === 0) throw new PasswordsSealError("this key holds no logins to hand over; add one first");
|
|
@@ -64283,7 +64591,7 @@ async function passwordsInvite(opts) {
|
|
|
64283
64591
|
};
|
|
64284
64592
|
const inviteSignature = await signInvite(wallet, envelope);
|
|
64285
64593
|
const link = `${siteOrigin()}${joinPath()}#${encodeInviteFragment(envelope, inviteSignature, secret)}`;
|
|
64286
|
-
|
|
64594
|
+
emit3(opts, { ok: true, link, agent: envelope.agent, rows: rows.map((r) => ({ id: r.id, label: r.label })), expiresAt: new Date(envelope.expiresAt * 1e3).toISOString(), minutes }, () => {
|
|
64287
64595
|
process.stdout.write(
|
|
64288
64596
|
`
|
|
64289
64597
|
${import_picocolors8.default.green("\u2713")} an invitation over ${rows.length} login${rows.length === 1 ? "" : "s"}, good for ${minutes} minutes
|
|
@@ -64298,7 +64606,7 @@ async function passwordsInvite(opts) {
|
|
|
64298
64606
|
);
|
|
64299
64607
|
});
|
|
64300
64608
|
} catch (err) {
|
|
64301
|
-
|
|
64609
|
+
failFrom2(opts, err);
|
|
64302
64610
|
}
|
|
64303
64611
|
}
|
|
64304
64612
|
|
|
@@ -64323,7 +64631,7 @@ async function readBrowserCatalog() {
|
|
|
64323
64631
|
networks: body.payment?.networks ?? []
|
|
64324
64632
|
};
|
|
64325
64633
|
}
|
|
64326
|
-
function
|
|
64634
|
+
function expect2(answer, what) {
|
|
64327
64635
|
if (answer.status >= 200 && answer.status < 300 && answer.body) return answer.body;
|
|
64328
64636
|
const body = answer.body ?? null;
|
|
64329
64637
|
const sentence = typeof body?.error === "string" ? body.error : answer.text.slice(0, 300) || `${what}: HTTP ${answer.status}`;
|
|
@@ -64336,15 +64644,15 @@ async function postTask(wallet, args) {
|
|
|
64336
64644
|
if (typeof args.maxSteps === "number") body.maxSteps = args.maxSteps;
|
|
64337
64645
|
if (typeof args.maxSeconds === "number") body.maxSeconds = args.maxSeconds;
|
|
64338
64646
|
const answer = await signedFetch(wallet, "POST", `${BROWSER_LANE}/tasks`, body);
|
|
64339
|
-
return
|
|
64647
|
+
return expect2(answer, "task").task;
|
|
64340
64648
|
}
|
|
64341
64649
|
async function listTasks(wallet) {
|
|
64342
64650
|
const answer = await signedFetch(wallet, "GET", `${BROWSER_LANE}/tasks`);
|
|
64343
|
-
return
|
|
64651
|
+
return expect2(answer, "tasks").tasks ?? [];
|
|
64344
64652
|
}
|
|
64345
64653
|
async function readTask(wallet, id2) {
|
|
64346
64654
|
const answer = await signedFetch(wallet, "GET", `${BROWSER_LANE}/tasks/${encodeURIComponent(id2)}`);
|
|
64347
|
-
return
|
|
64655
|
+
return expect2(answer, "task").task;
|
|
64348
64656
|
}
|
|
64349
64657
|
async function readIdentityBalance(wallet) {
|
|
64350
64658
|
const answer = await signedFetch(
|
|
@@ -64352,7 +64660,7 @@ async function readIdentityBalance(wallet) {
|
|
|
64352
64660
|
"GET",
|
|
64353
64661
|
`${LANE}/credits`
|
|
64354
64662
|
);
|
|
64355
|
-
const body =
|
|
64663
|
+
const body = expect2(answer, "balance");
|
|
64356
64664
|
return { balance: body.balance ?? null, entries: body.entries ?? [], rungsUsd: body.rungsUsd ?? [] };
|
|
64357
64665
|
}
|
|
64358
64666
|
async function readDepositAddress(wallet) {
|
|
@@ -64361,7 +64669,7 @@ async function readDepositAddress(wallet) {
|
|
|
64361
64669
|
const b2 = answer.body ?? {};
|
|
64362
64670
|
return { deposit: null, dark: typeof b2.error === "string" ? b2.error : "deposit addresses are not open yet on this deployment" };
|
|
64363
64671
|
}
|
|
64364
|
-
const body =
|
|
64672
|
+
const body = expect2(answer, "deposit address");
|
|
64365
64673
|
const payToAll = Array.isArray(body.payToAll) ? body.payToAll : [];
|
|
64366
64674
|
const chains = payToAll.filter((e) => e && typeof e.chainId === "number" && typeof e.address === "string").map((e) => ({ chainId: e.chainId, network: typeof e.network === "string" ? e.network : String(e.chainId), address: e.address }));
|
|
64367
64675
|
if (typeof body.address !== "string" || chains.length === 0) throw new WireError(answer.status, "bad_wire", "the deposit address could not be read", answer.body);
|
|
@@ -64377,12 +64685,12 @@ async function readDepositAddress(wallet) {
|
|
|
64377
64685
|
}
|
|
64378
64686
|
async function scanDeposit(wallet) {
|
|
64379
64687
|
const answer = await signedFetch(wallet, "POST", `${LANE}/deposit`, { scan: true });
|
|
64380
|
-
const body = answer.status === 429 ? answer.body ?? {} :
|
|
64688
|
+
const body = answer.status === 429 ? answer.body ?? {} : expect2(answer, "scan");
|
|
64381
64689
|
return { scanned: body.scanned === true, credited: typeof body.credited === "number" ? body.credited : 0, balance: body.balance ?? null };
|
|
64382
64690
|
}
|
|
64383
64691
|
async function cancelTask(wallet, id2) {
|
|
64384
64692
|
const answer = await signedFetch(wallet, "POST", `${BROWSER_LANE}/tasks/${encodeURIComponent(id2)}/cancel`);
|
|
64385
|
-
return
|
|
64693
|
+
return expect2(answer, "cancel").task;
|
|
64386
64694
|
}
|
|
64387
64695
|
async function waitForTask(wallet, id2, { maxSeconds = 900, everyMs = 5e3, onTick } = {}) {
|
|
64388
64696
|
const until = Date.now() + maxSeconds * 1e3;
|
|
@@ -64395,16 +64703,16 @@ async function waitForTask(wallet, id2, { maxSeconds = 900, everyMs = 5e3, onTic
|
|
|
64395
64703
|
}
|
|
64396
64704
|
|
|
64397
64705
|
// src/commands/browser.ts
|
|
64398
|
-
var
|
|
64399
|
-
function
|
|
64400
|
-
if (
|
|
64706
|
+
var jsonMode4 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
64707
|
+
function emit4(opts, data4, human) {
|
|
64708
|
+
if (jsonMode4(opts)) {
|
|
64401
64709
|
process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
|
|
64402
64710
|
return;
|
|
64403
64711
|
}
|
|
64404
64712
|
human();
|
|
64405
64713
|
}
|
|
64406
|
-
function
|
|
64407
|
-
if (
|
|
64714
|
+
function refuse4(opts, error, code, extra = {}) {
|
|
64715
|
+
if (jsonMode4(opts)) {
|
|
64408
64716
|
process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
|
|
64409
64717
|
} else {
|
|
64410
64718
|
process.stderr.write(` ${error}${code ? import_picocolors9.default.dim(` (${code})`) : ""}
|
|
@@ -64412,9 +64720,9 @@ function refuse3(opts, error, code, extra = {}) {
|
|
|
64412
64720
|
}
|
|
64413
64721
|
process.exit(1);
|
|
64414
64722
|
}
|
|
64415
|
-
function
|
|
64416
|
-
if (err instanceof WireError) return
|
|
64417
|
-
return
|
|
64723
|
+
function failFrom3(opts, err) {
|
|
64724
|
+
if (err instanceof WireError) return refuse4(opts, err.message, err.code, { status: err.status });
|
|
64725
|
+
return refuse4(opts, err.message ?? String(err), null);
|
|
64418
64726
|
}
|
|
64419
64727
|
var usd5 = (v) => {
|
|
64420
64728
|
const n2 = Number(v);
|
|
@@ -64429,22 +64737,22 @@ var host = (url) => {
|
|
|
64429
64737
|
return url;
|
|
64430
64738
|
}
|
|
64431
64739
|
};
|
|
64432
|
-
var
|
|
64433
|
-
var
|
|
64740
|
+
var when2 = (iso) => iso ? iso.replace("T", " ").slice(0, 16) : "";
|
|
64741
|
+
var STATUS_COLOR2 = {
|
|
64434
64742
|
queued: import_picocolors9.default.dim,
|
|
64435
64743
|
running: import_picocolors9.default.cyan,
|
|
64436
64744
|
done: import_picocolors9.default.green,
|
|
64437
64745
|
failed: import_picocolors9.default.red,
|
|
64438
64746
|
cancelled: import_picocolors9.default.dim
|
|
64439
64747
|
};
|
|
64440
|
-
var
|
|
64748
|
+
var status2 = (s) => (STATUS_COLOR2[s] ?? import_picocolors9.default.dim)(s.padEnd(9));
|
|
64441
64749
|
function siteUrl(raw) {
|
|
64442
64750
|
const t = raw.trim();
|
|
64443
64751
|
return /^[a-z][a-z0-9+.-]*:\/\//i.test(t) ? t : `https://${t}`;
|
|
64444
64752
|
}
|
|
64445
64753
|
function printTask(t, full) {
|
|
64446
64754
|
process.stdout.write(`
|
|
64447
|
-
${
|
|
64755
|
+
${status2(t.status)} ${import_picocolors9.default.bold(t.id)} ${import_picocolors9.default.dim(host(t.url))} ${import_picocolors9.default.dim(`${t.stepsRun}/${t.maxSteps} steps`)}
|
|
64448
64756
|
`);
|
|
64449
64757
|
process.stdout.write(` ${t.goal}
|
|
64450
64758
|
`);
|
|
@@ -64484,7 +64792,7 @@ function printTask(t, full) {
|
|
|
64484
64792
|
async function browserPricing(opts) {
|
|
64485
64793
|
try {
|
|
64486
64794
|
const { product, usage, networks } = await readBrowserCatalog();
|
|
64487
|
-
|
|
64795
|
+
emit4(opts, { ok: true, product, usage, networks }, () => {
|
|
64488
64796
|
process.stdout.write(`
|
|
64489
64797
|
${import_picocolors9.default.bold("BROWSER")} ${import_picocolors9.default.dim(product?.brief ?? "a site and a task in words; it browses, then answers")}
|
|
64490
64798
|
|
|
@@ -64509,7 +64817,7 @@ async function browserPricing(opts) {
|
|
|
64509
64817
|
process.stdout.write("\n");
|
|
64510
64818
|
});
|
|
64511
64819
|
} catch (err) {
|
|
64512
|
-
|
|
64820
|
+
failFrom3(opts, err);
|
|
64513
64821
|
}
|
|
64514
64822
|
}
|
|
64515
64823
|
async function browserBalance(opts) {
|
|
@@ -64523,7 +64831,7 @@ async function browserBalance(opts) {
|
|
|
64523
64831
|
scan = { scanned: out.scanned, credited: out.credited };
|
|
64524
64832
|
if (out.credited > 0) balance2 = await readIdentityBalance(keys2.wallet);
|
|
64525
64833
|
}
|
|
64526
|
-
|
|
64834
|
+
emit4(opts, { ok: true, wallet: keys2.wallet.address, via: lastAuthVia(), loginKeyRevoked: loginKeyWasRevoked(), balance: balance2.balance, rungsUsd: balance2.rungsUsd, deposit, ...dark ? { depositDark: dark } : {}, ...scan ? { scan } : {} }, () => {
|
|
64527
64835
|
process.stdout.write(`
|
|
64528
64836
|
${import_picocolors9.default.bold("BALANCE")} ${import_picocolors9.default.dim(keys2.wallet.address)}
|
|
64529
64837
|
|
|
@@ -64556,21 +64864,21 @@ async function browserBalance(opts) {
|
|
|
64556
64864
|
process.stdout.write("\n");
|
|
64557
64865
|
});
|
|
64558
64866
|
} catch (err) {
|
|
64559
|
-
|
|
64867
|
+
failFrom3(opts, err);
|
|
64560
64868
|
}
|
|
64561
64869
|
}
|
|
64562
64870
|
async function browserRun(url, opts) {
|
|
64563
64871
|
const goal = (opts.task ?? "").trim();
|
|
64564
|
-
if (!goal) return
|
|
64872
|
+
if (!goal) return refuse4(opts, 'say what the browser agent should do: --task "<words>"', "bad_request");
|
|
64565
64873
|
const maxSteps = opts.steps !== void 0 ? Number(opts.steps) : void 0;
|
|
64566
|
-
if (maxSteps !== void 0 && !Number.isInteger(maxSteps)) return
|
|
64874
|
+
if (maxSteps !== void 0 && !Number.isInteger(maxSteps)) return refuse4(opts, "--steps must be a whole number", "bad_request");
|
|
64567
64875
|
const maxSeconds = opts.seconds !== void 0 ? Number(opts.seconds) : void 0;
|
|
64568
|
-
if (maxSeconds !== void 0 && !Number.isInteger(maxSeconds)) return
|
|
64876
|
+
if (maxSeconds !== void 0 && !Number.isInteger(maxSeconds)) return refuse4(opts, "--seconds must be a whole number", "bad_request");
|
|
64569
64877
|
try {
|
|
64570
64878
|
const keys2 = await requirePasswordsKey();
|
|
64571
64879
|
const task = await postTask(keys2.wallet, { url: siteUrl(url), goal, hosts: opts.host, maxSteps, maxSeconds });
|
|
64572
64880
|
if (!opts.wait) {
|
|
64573
|
-
|
|
64881
|
+
emit4(opts, { ok: true, task }, () => {
|
|
64574
64882
|
printTask(task, false);
|
|
64575
64883
|
process.stdout.write(` ${import_picocolors9.default.dim(`read it back: agentgates browser task ${task.id} --wait`)}
|
|
64576
64884
|
|
|
@@ -64583,13 +64891,13 @@ async function browserRun(url, opts) {
|
|
|
64583
64891
|
const settled = await waitForTask(keys2.wallet, task.id, {
|
|
64584
64892
|
maxSeconds: waitSeconds,
|
|
64585
64893
|
onTick: (t) => {
|
|
64586
|
-
if (
|
|
64894
|
+
if (jsonMode4(opts) || t.status === lastStatus) return;
|
|
64587
64895
|
lastStatus = t.status;
|
|
64588
64896
|
process.stderr.write(` ${import_picocolors9.default.dim(`${t.status}${t.status === "running" ? ` \xB7 ${t.stepsRun} steps` : ""}`)}
|
|
64589
64897
|
`);
|
|
64590
64898
|
}
|
|
64591
64899
|
});
|
|
64592
|
-
|
|
64900
|
+
emit4(opts, { ok: SETTLED.has(settled.status), task: settled }, () => {
|
|
64593
64901
|
printTask(settled, true);
|
|
64594
64902
|
if (!SETTLED.has(settled.status)) process.stdout.write(` ${import_picocolors9.default.dim(`still ${settled.status}; read it later: agentgates browser task ${settled.id} --wait`)}
|
|
64595
64903
|
|
|
@@ -64597,14 +64905,14 @@ async function browserRun(url, opts) {
|
|
|
64597
64905
|
});
|
|
64598
64906
|
if (settled.status === "failed") process.exitCode = 1;
|
|
64599
64907
|
} catch (err) {
|
|
64600
|
-
|
|
64908
|
+
failFrom3(opts, err);
|
|
64601
64909
|
}
|
|
64602
64910
|
}
|
|
64603
64911
|
async function browserTasks(opts) {
|
|
64604
64912
|
try {
|
|
64605
64913
|
const keys2 = await requirePasswordsKey();
|
|
64606
64914
|
const tasks = await listTasks(keys2.wallet);
|
|
64607
|
-
|
|
64915
|
+
emit4(opts, { ok: true, wallet: keys2.wallet.address, tasks }, () => {
|
|
64608
64916
|
process.stdout.write(`
|
|
64609
64917
|
${import_picocolors9.default.bold("YOUR TASKS")} ${import_picocolors9.default.dim(keys2.wallet.address)}
|
|
64610
64918
|
|
|
@@ -64617,7 +64925,7 @@ async function browserTasks(opts) {
|
|
|
64617
64925
|
}
|
|
64618
64926
|
for (const t of tasks) {
|
|
64619
64927
|
const money = t.status === "done" ? usd5(t.chargedUsd) : t.status === "queued" || t.status === "running" ? `${usd5(t.reservedUsd)} reserved` : "";
|
|
64620
|
-
process.stdout.write(` ${
|
|
64928
|
+
process.stdout.write(` ${status2(t.status)} ${t.id} ${import_picocolors9.default.dim(host(t.url).padEnd(24))} ${import_picocolors9.default.dim(`${t.stepsRun}/${t.maxSteps}`.padStart(6))} ${import_picocolors9.default.dim(money.padEnd(16))} ${import_picocolors9.default.dim(when2(t.createdAt))}
|
|
64621
64929
|
`);
|
|
64622
64930
|
process.stdout.write(` ${t.goal.length > 90 ? `${t.goal.slice(0, 89)}\u2026` : t.goal}
|
|
64623
64931
|
`);
|
|
@@ -64625,7 +64933,7 @@ async function browserTasks(opts) {
|
|
|
64625
64933
|
process.stdout.write("\n");
|
|
64626
64934
|
});
|
|
64627
64935
|
} catch (err) {
|
|
64628
|
-
|
|
64936
|
+
failFrom3(opts, err);
|
|
64629
64937
|
}
|
|
64630
64938
|
}
|
|
64631
64939
|
async function browserTask(id2, opts) {
|
|
@@ -64633,19 +64941,19 @@ async function browserTask(id2, opts) {
|
|
|
64633
64941
|
const keys2 = await requirePasswordsKey();
|
|
64634
64942
|
if (opts.cancel) {
|
|
64635
64943
|
const task2 = await cancelTask(keys2.wallet, id2);
|
|
64636
|
-
|
|
64944
|
+
emit4(opts, { ok: true, task: task2 }, () => printTask(task2, false));
|
|
64637
64945
|
return;
|
|
64638
64946
|
}
|
|
64639
64947
|
const task = opts.wait ? await waitForTask(keys2.wallet, id2, {
|
|
64640
64948
|
maxSeconds: typeof opts.wait === "string" ? Math.max(5, Number(opts.wait) || 0) : 900,
|
|
64641
64949
|
onTick: (t) => {
|
|
64642
|
-
if (!
|
|
64950
|
+
if (!jsonMode4(opts) && !SETTLED.has(t.status)) process.stderr.write(` ${import_picocolors9.default.dim(`${t.status} \xB7 ${t.stepsRun} steps`)}
|
|
64643
64951
|
`);
|
|
64644
64952
|
}
|
|
64645
64953
|
}) : await readTask(keys2.wallet, id2);
|
|
64646
|
-
|
|
64954
|
+
emit4(opts, { ok: true, task }, () => printTask(task, true));
|
|
64647
64955
|
} catch (err) {
|
|
64648
|
-
|
|
64956
|
+
failFrom3(opts, err);
|
|
64649
64957
|
}
|
|
64650
64958
|
}
|
|
64651
64959
|
|
|
@@ -64710,20 +65018,20 @@ function installedVersionAt(place) {
|
|
|
64710
65018
|
|
|
64711
65019
|
// src/commands/update.ts
|
|
64712
65020
|
var import_picocolors10 = __toESM(require_picocolors(), 1);
|
|
64713
|
-
var
|
|
65021
|
+
var jsonMode5 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
64714
65022
|
async function update(opts = {}) {
|
|
64715
65023
|
const latest = await fetchLatest();
|
|
64716
65024
|
const place = installPlace();
|
|
64717
65025
|
const stale = !!latest && olderThan(LOCAL_VERSION, latest);
|
|
64718
65026
|
const base = { ok: true, package: PKG, current: LOCAL_VERSION, latest, stale, runsFrom: place.kind, ...place.kind === "home" ? { home: place.home } : place.kind === "checkout" ? { dir: place.dir } : {} };
|
|
64719
65027
|
if (!latest) {
|
|
64720
|
-
if (
|
|
65028
|
+
if (jsonMode5(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "registry_unreachable", error: "npm's registry did not answer; try again in a moment" }, null, 2) + "\n");
|
|
64721
65029
|
else process.stderr.write(` ${import_picocolors10.default.red("\u2715")} npm's registry did not answer; try again in a moment
|
|
64722
65030
|
`);
|
|
64723
65031
|
process.exit(1);
|
|
64724
65032
|
}
|
|
64725
65033
|
if (opts.check || !stale) {
|
|
64726
|
-
if (
|
|
65034
|
+
if (jsonMode5(opts)) process.stdout.write(JSON.stringify(base, null, 2) + "\n");
|
|
64727
65035
|
else if (stale) process.stdout.write(`
|
|
64728
65036
|
${import_picocolors10.default.yellow("\u2191")} ${latest} is out; this copy is ${LOCAL_VERSION}. ${import_picocolors10.default.dim("agentgates update \xB7 installs it")}
|
|
64729
65037
|
|
|
@@ -64736,7 +65044,7 @@ async function update(opts = {}) {
|
|
|
64736
65044
|
}
|
|
64737
65045
|
if (place.kind === "checkout") {
|
|
64738
65046
|
const line = `cd ${place.dir} && git pull --ff-only && npm run build`;
|
|
64739
|
-
if (
|
|
65047
|
+
if (jsonMode5(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "checkout", line, error: "this copy runs from a repository checkout; pull it" }, null, 2) + "\n");
|
|
64740
65048
|
else process.stdout.write(`
|
|
64741
65049
|
this copy runs from a checkout at ${import_picocolors10.default.bold(place.dir)}; update it with
|
|
64742
65050
|
${import_picocolors10.default.cyan(line)}
|
|
@@ -64744,7 +65052,7 @@ async function update(opts = {}) {
|
|
|
64744
65052
|
`);
|
|
64745
65053
|
return;
|
|
64746
65054
|
}
|
|
64747
|
-
if (!
|
|
65055
|
+
if (!jsonMode5(opts)) process.stdout.write(`
|
|
64748
65056
|
${import_picocolors10.default.bold("UPDATE")} ${LOCAL_VERSION} \u2192 ${latest} ${import_picocolors10.default.dim(place.kind === "home" ? `into ${place.home}` : "the global npm install")}
|
|
64749
65057
|
${import_picocolors10.default.dim(`npm ${place.command.join(" ")}`)}
|
|
64750
65058
|
|
|
@@ -64752,7 +65060,7 @@ async function update(opts = {}) {
|
|
|
64752
65060
|
const code = await runNpm(place.command);
|
|
64753
65061
|
const now = installedVersionAt(place);
|
|
64754
65062
|
const done = code === 0 && (place.kind !== "home" || now === latest);
|
|
64755
|
-
if (
|
|
65063
|
+
if (jsonMode5(opts)) {
|
|
64756
65064
|
process.stdout.write(JSON.stringify({ ...base, ok: done, code: done ? void 0 : "npm_failed", installed: now ?? void 0, exit: code }, null, 2) + "\n");
|
|
64757
65065
|
} else if (done) {
|
|
64758
65066
|
process.stdout.write(`
|
|
@@ -65086,7 +65394,7 @@ function printNext(put) {
|
|
|
65086
65394
|
// src/commands/keys.ts
|
|
65087
65395
|
var import_picocolors12 = __toESM(require_picocolors(), 1);
|
|
65088
65396
|
import { hostname as hostname2 } from "node:os";
|
|
65089
|
-
function
|
|
65397
|
+
function emit5(opts, data4, human) {
|
|
65090
65398
|
if (opts.json || !process.stdout.isTTY) {
|
|
65091
65399
|
process.stdout.write(`${JSON.stringify(data4)}
|
|
65092
65400
|
`);
|
|
@@ -65134,7 +65442,7 @@ async function keysList(opts) {
|
|
|
65134
65442
|
try {
|
|
65135
65443
|
const keys2 = await requirePasswordsKey();
|
|
65136
65444
|
const rows = await listLoginKeys(keys2.wallet);
|
|
65137
|
-
|
|
65445
|
+
emit5(opts, { ok: true, address: keys2.state.address, keys: rows, thisMachine: keys2.state.apiKeyPrefix ?? null }, () => printRows(rows, keys2.state.apiKeyPrefix ?? null));
|
|
65138
65446
|
} catch (err) {
|
|
65139
65447
|
fail(opts, err);
|
|
65140
65448
|
}
|
|
@@ -65145,7 +65453,7 @@ async function keysCreate(opts) {
|
|
|
65145
65453
|
const name = (opts.name?.trim() || `cli ${hostname2()}`).slice(0, 64);
|
|
65146
65454
|
const made = await createLoginKey(keys2.wallet, name);
|
|
65147
65455
|
if (opts.keep) await saveLoginKey(keys2.state, { secret: made.key, prefix: made.created.prefix, name: made.created.name });
|
|
65148
|
-
|
|
65456
|
+
emit5(opts, { ok: true, key: made.key, created: made.created, kept: opts.keep === true }, () => {
|
|
65149
65457
|
process.stdout.write(
|
|
65150
65458
|
`
|
|
65151
65459
|
${import_picocolors12.default.green("\u2713")} login key minted: ${import_picocolors12.default.bold(made.created.name)}
|
|
@@ -65172,7 +65480,7 @@ async function keysRevoke(id2, opts) {
|
|
|
65172
65480
|
const out = await revokeLoginKey(keys2.wallet, id2);
|
|
65173
65481
|
const wasMine = !!target && !!keys2.state.apiKeyPrefix && target.prefix === keys2.state.apiKeyPrefix;
|
|
65174
65482
|
if (wasMine) await forgetLoginKey(keys2.state);
|
|
65175
|
-
|
|
65483
|
+
emit5(opts, { ok: true, revoked: id2, keys: out.keys, thisMachineDropped: wasMine }, () => {
|
|
65176
65484
|
process.stdout.write(`
|
|
65177
65485
|
${import_picocolors12.default.green("\u2713")} revoked ${target ? import_picocolors12.default.bold(target.prefix) : id2}${wasMine ? import_picocolors12.default.dim(" (this machine signs with the words until keys create --keep)") : ""}
|
|
65178
65486
|
`);
|
|
@@ -65247,16 +65555,16 @@ async function whoami(opts) {
|
|
|
65247
65555
|
`));
|
|
65248
65556
|
}
|
|
65249
65557
|
const { profile, name: profileName } = resolved;
|
|
65250
|
-
const
|
|
65558
|
+
const jsonMode6 = opts.json === true;
|
|
65251
65559
|
const outcome = await callWithAutoRelogin({
|
|
65252
65560
|
profile,
|
|
65253
65561
|
profileName,
|
|
65254
|
-
jsonMode:
|
|
65562
|
+
jsonMode: jsonMode6,
|
|
65255
65563
|
ttyHeader: import_picocolors14.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
65256
65564
|
fn: (bearer, origin) => apiFetch("/api/whoami", { bearer, origin })
|
|
65257
65565
|
});
|
|
65258
65566
|
if (outcome.kind === "auth_failed") {
|
|
65259
|
-
if (
|
|
65567
|
+
if (jsonMode6) {
|
|
65260
65568
|
process.stdout.write(
|
|
65261
65569
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
65262
65570
|
);
|
|
@@ -65276,7 +65584,7 @@ async function whoami(opts) {
|
|
|
65276
65584
|
throw err;
|
|
65277
65585
|
}
|
|
65278
65586
|
const me = outcome.result;
|
|
65279
|
-
if (
|
|
65587
|
+
if (jsonMode6) {
|
|
65280
65588
|
process.stdout.write(JSON.stringify(me, null, 2) + "\n");
|
|
65281
65589
|
return;
|
|
65282
65590
|
}
|
|
@@ -65480,7 +65788,7 @@ async function send(amount, asset, opts) {
|
|
|
65480
65788
|
}
|
|
65481
65789
|
const { profile, name: profileName } = resolved;
|
|
65482
65790
|
const stdoutIsTty = process.stdout.isTTY === true;
|
|
65483
|
-
const
|
|
65791
|
+
const jsonMode6 = opts.json === true || !stdoutIsTty;
|
|
65484
65792
|
const amountNumber = Number(amount);
|
|
65485
65793
|
if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
|
|
65486
65794
|
process.stderr.write(
|
|
@@ -65589,12 +65897,12 @@ async function send(amount, asset, opts) {
|
|
|
65589
65897
|
try {
|
|
65590
65898
|
activeProfile = await runLoginFlow({
|
|
65591
65899
|
profile: profileName,
|
|
65592
|
-
jsonMode:
|
|
65900
|
+
jsonMode: jsonMode6,
|
|
65593
65901
|
origin: activeProfile.mcpOrigin,
|
|
65594
65902
|
ttyHeader: import_picocolors15.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026")
|
|
65595
65903
|
});
|
|
65596
65904
|
} catch (reloginErr) {
|
|
65597
|
-
if (
|
|
65905
|
+
if (jsonMode6) {
|
|
65598
65906
|
emitNdjson({
|
|
65599
65907
|
ok: false,
|
|
65600
65908
|
status: "auth_failed",
|
|
@@ -65617,7 +65925,7 @@ async function send(amount, asset, opts) {
|
|
|
65617
65925
|
});
|
|
65618
65926
|
} catch (retryErr) {
|
|
65619
65927
|
if (retryErr instanceof ApiError) {
|
|
65620
|
-
if (
|
|
65928
|
+
if (jsonMode6) {
|
|
65621
65929
|
emitNdjson({
|
|
65622
65930
|
ok: false,
|
|
65623
65931
|
status: retryErr.status === 401 ? "auth_failed" : "propose_failed",
|
|
@@ -65635,7 +65943,7 @@ async function send(amount, asset, opts) {
|
|
|
65635
65943
|
throw retryErr;
|
|
65636
65944
|
}
|
|
65637
65945
|
} else if (err instanceof ApiError) {
|
|
65638
|
-
if (
|
|
65946
|
+
if (jsonMode6) {
|
|
65639
65947
|
emitNdjson({
|
|
65640
65948
|
ok: false,
|
|
65641
65949
|
status: "propose_failed",
|
|
@@ -65652,7 +65960,7 @@ async function send(amount, asset, opts) {
|
|
|
65652
65960
|
}
|
|
65653
65961
|
}
|
|
65654
65962
|
if (isBlocked(proposed)) {
|
|
65655
|
-
if (
|
|
65963
|
+
if (jsonMode6) {
|
|
65656
65964
|
const envelope = {
|
|
65657
65965
|
ok: false,
|
|
65658
65966
|
status: "blocked",
|
|
@@ -65716,7 +66024,7 @@ async function send(amount, asset, opts) {
|
|
|
65716
66024
|
if (process.env.CI === "1" || process.env.CI === "true") return false;
|
|
65717
66025
|
return true;
|
|
65718
66026
|
})();
|
|
65719
|
-
if (
|
|
66027
|
+
if (jsonMode6) {
|
|
65720
66028
|
emitNdjson({
|
|
65721
66029
|
ok: true,
|
|
65722
66030
|
status: "proposed",
|
|
@@ -65748,7 +66056,7 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
65748
66056
|
intervalMs: POLL_INTERVAL_MS,
|
|
65749
66057
|
giveUpMs: POLL_GIVEUP_MS,
|
|
65750
66058
|
onTick: (s) => {
|
|
65751
|
-
if (
|
|
66059
|
+
if (jsonMode6) {
|
|
65752
66060
|
emitNdjson({ status: s.status, intent_id: s.approval_id });
|
|
65753
66061
|
} else {
|
|
65754
66062
|
process.stdout.write(` ${describeStatus(s.status)}${import_picocolors15.default.dim("\u2026")}\r`);
|
|
@@ -65763,12 +66071,12 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
65763
66071
|
try {
|
|
65764
66072
|
activeProfile = await runLoginFlow({
|
|
65765
66073
|
profile: profileName,
|
|
65766
|
-
jsonMode:
|
|
66074
|
+
jsonMode: jsonMode6,
|
|
65767
66075
|
origin: activeProfile.mcpOrigin,
|
|
65768
66076
|
ttyHeader: import_picocolors15.default.dim("Bearer expired mid-poll \u2014 re-pairing this terminal\u2026")
|
|
65769
66077
|
});
|
|
65770
66078
|
} catch (reloginErr) {
|
|
65771
|
-
if (
|
|
66079
|
+
if (jsonMode6) {
|
|
65772
66080
|
emitNdjson({
|
|
65773
66081
|
ok: false,
|
|
65774
66082
|
status: "auth_failed",
|
|
@@ -65786,7 +66094,7 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
65786
66094
|
try {
|
|
65787
66095
|
final = await runPoll(activeProfile);
|
|
65788
66096
|
} catch (retryErr) {
|
|
65789
|
-
if (
|
|
66097
|
+
if (jsonMode6) {
|
|
65790
66098
|
emitNdjson({
|
|
65791
66099
|
ok: false,
|
|
65792
66100
|
status: retryErr instanceof ApiError && retryErr.status === 401 ? "auth_failed" : "poll_failed",
|
|
@@ -65802,7 +66110,7 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
65802
66110
|
process.exit(1);
|
|
65803
66111
|
}
|
|
65804
66112
|
} else {
|
|
65805
|
-
if (
|
|
66113
|
+
if (jsonMode6) {
|
|
65806
66114
|
emitNdjson({
|
|
65807
66115
|
ok: false,
|
|
65808
66116
|
status: "poll_failed",
|
|
@@ -65819,7 +66127,7 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
65819
66127
|
}
|
|
65820
66128
|
}
|
|
65821
66129
|
const explorer = final.tx_hash != null ? explorerUrl(final.chain_id, final.tx_hash) : null;
|
|
65822
|
-
if (
|
|
66130
|
+
if (jsonMode6) {
|
|
65823
66131
|
emitNdjson({
|
|
65824
66132
|
ok: final.status === "mined",
|
|
65825
66133
|
status: final.status,
|
|
@@ -65888,7 +66196,7 @@ function explorerUrl2(chainId, hash2) {
|
|
|
65888
66196
|
return null;
|
|
65889
66197
|
}
|
|
65890
66198
|
}
|
|
65891
|
-
async function
|
|
66199
|
+
async function status3(intentId, opts) {
|
|
65892
66200
|
if (!intentId || intentId.trim() === "") {
|
|
65893
66201
|
process.stderr.write(import_picocolors16.default.red("\u2715 Missing intent id.\n"));
|
|
65894
66202
|
process.exit(2);
|
|
@@ -65904,16 +66212,16 @@ async function status2(intentId, opts) {
|
|
|
65904
66212
|
`));
|
|
65905
66213
|
}
|
|
65906
66214
|
const { profile, name: profileName } = resolved;
|
|
65907
|
-
const
|
|
66215
|
+
const jsonMode6 = opts.json === true;
|
|
65908
66216
|
const outcome = await callWithAutoRelogin({
|
|
65909
66217
|
profile,
|
|
65910
66218
|
profileName,
|
|
65911
|
-
jsonMode:
|
|
66219
|
+
jsonMode: jsonMode6,
|
|
65912
66220
|
ttyHeader: import_picocolors16.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
65913
66221
|
fn: (bearer, origin) => fetchStatus({ intentId, bearer, origin })
|
|
65914
66222
|
});
|
|
65915
66223
|
if (outcome.kind === "auth_failed") {
|
|
65916
|
-
if (
|
|
66224
|
+
if (jsonMode6) {
|
|
65917
66225
|
process.stdout.write(
|
|
65918
66226
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
65919
66227
|
);
|
|
@@ -65940,7 +66248,7 @@ async function status2(intentId, opts) {
|
|
|
65940
66248
|
let snap = outcome.result;
|
|
65941
66249
|
let activeProfile = outcome.profile;
|
|
65942
66250
|
if (opts.watch && !isTerminalStatus(snap.status)) {
|
|
65943
|
-
if (!
|
|
66251
|
+
if (!jsonMode6) {
|
|
65944
66252
|
printSnap(snap);
|
|
65945
66253
|
process.stdout.write(import_picocolors16.default.dim("Watching\u2026\n"));
|
|
65946
66254
|
}
|
|
@@ -65952,7 +66260,7 @@ async function status2(intentId, opts) {
|
|
|
65952
66260
|
intervalMs: 0,
|
|
65953
66261
|
giveUpMs: WATCH_GIVEUP_MS,
|
|
65954
66262
|
onTick: (s) => {
|
|
65955
|
-
if (!
|
|
66263
|
+
if (!jsonMode6) {
|
|
65956
66264
|
process.stdout.write(` ${import_picocolors16.default.dim("\u2192")} ${s.status}
|
|
65957
66265
|
`);
|
|
65958
66266
|
}
|
|
@@ -65966,12 +66274,12 @@ async function status2(intentId, opts) {
|
|
|
65966
66274
|
try {
|
|
65967
66275
|
activeProfile = await runLoginFlow({
|
|
65968
66276
|
profile: profileName,
|
|
65969
|
-
jsonMode:
|
|
66277
|
+
jsonMode: jsonMode6,
|
|
65970
66278
|
origin: activeProfile.mcpOrigin,
|
|
65971
66279
|
ttyHeader: import_picocolors16.default.dim("Bearer expired mid-watch \u2014 re-pairing\u2026")
|
|
65972
66280
|
});
|
|
65973
66281
|
} catch (reloginErr) {
|
|
65974
|
-
if (
|
|
66282
|
+
if (jsonMode6) {
|
|
65975
66283
|
process.stdout.write(
|
|
65976
66284
|
JSON.stringify({
|
|
65977
66285
|
ok: false,
|
|
@@ -66000,14 +66308,14 @@ async function status2(intentId, opts) {
|
|
|
66000
66308
|
process.exit(1);
|
|
66001
66309
|
}
|
|
66002
66310
|
}
|
|
66003
|
-
if (
|
|
66311
|
+
if (jsonMode6) {
|
|
66004
66312
|
process.stdout.write(JSON.stringify(final, null, 2) + "\n");
|
|
66005
66313
|
} else {
|
|
66006
66314
|
printSnap(final);
|
|
66007
66315
|
}
|
|
66008
66316
|
process.exit(final.status === "mined" ? 0 : 1);
|
|
66009
66317
|
}
|
|
66010
|
-
if (
|
|
66318
|
+
if (jsonMode6) {
|
|
66011
66319
|
process.stdout.write(JSON.stringify(snap, null, 2) + "\n");
|
|
66012
66320
|
process.exit(snap.status === "mined" ? 0 : 0);
|
|
66013
66321
|
}
|
|
@@ -66099,16 +66407,16 @@ async function balance(opts) {
|
|
|
66099
66407
|
}
|
|
66100
66408
|
chainFilter = id2;
|
|
66101
66409
|
}
|
|
66102
|
-
const
|
|
66410
|
+
const jsonMode6 = opts.json === true;
|
|
66103
66411
|
const outcome = await callWithAutoRelogin({
|
|
66104
66412
|
profile,
|
|
66105
66413
|
profileName,
|
|
66106
|
-
jsonMode:
|
|
66414
|
+
jsonMode: jsonMode6,
|
|
66107
66415
|
ttyHeader: import_picocolors17.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
66108
66416
|
fn: (bearer, origin) => apiFetch("/api/balances", { bearer, origin })
|
|
66109
66417
|
});
|
|
66110
66418
|
if (outcome.kind === "auth_failed") {
|
|
66111
|
-
if (
|
|
66419
|
+
if (jsonMode6) {
|
|
66112
66420
|
process.stdout.write(
|
|
66113
66421
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
66114
66422
|
);
|
|
@@ -66129,7 +66437,7 @@ async function balance(opts) {
|
|
|
66129
66437
|
}
|
|
66130
66438
|
const res = outcome.result;
|
|
66131
66439
|
const filtered = chainFilter !== null ? res.chains.filter((c) => c.chainId === chainFilter) : res.chains;
|
|
66132
|
-
if (
|
|
66440
|
+
if (jsonMode6) {
|
|
66133
66441
|
process.stdout.write(
|
|
66134
66442
|
JSON.stringify(
|
|
66135
66443
|
chainFilter !== null ? { ...res, chains: filtered } : res,
|
|
@@ -66256,11 +66564,11 @@ async function history(opts) {
|
|
|
66256
66564
|
}
|
|
66257
66565
|
limit = n2;
|
|
66258
66566
|
}
|
|
66259
|
-
const
|
|
66567
|
+
const jsonMode6 = opts.json === true;
|
|
66260
66568
|
const outcome = await callWithAutoRelogin({
|
|
66261
66569
|
profile,
|
|
66262
66570
|
profileName,
|
|
66263
|
-
jsonMode:
|
|
66571
|
+
jsonMode: jsonMode6,
|
|
66264
66572
|
ttyHeader: import_picocolors18.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
66265
66573
|
fn: (bearer, origin) => apiFetch(
|
|
66266
66574
|
`/api/history?limit=${encodeURIComponent(String(limit))}`,
|
|
@@ -66268,7 +66576,7 @@ async function history(opts) {
|
|
|
66268
66576
|
)
|
|
66269
66577
|
});
|
|
66270
66578
|
if (outcome.kind === "auth_failed") {
|
|
66271
|
-
if (
|
|
66579
|
+
if (jsonMode6) {
|
|
66272
66580
|
process.stdout.write(
|
|
66273
66581
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
66274
66582
|
);
|
|
@@ -66288,7 +66596,7 @@ async function history(opts) {
|
|
|
66288
66596
|
throw err;
|
|
66289
66597
|
}
|
|
66290
66598
|
const res = outcome.result;
|
|
66291
|
-
if (
|
|
66599
|
+
if (jsonMode6) {
|
|
66292
66600
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
66293
66601
|
return;
|
|
66294
66602
|
}
|
|
@@ -66376,7 +66684,7 @@ function chainIdLabel(id2) {
|
|
|
66376
66684
|
return `chain ${id2}`;
|
|
66377
66685
|
}
|
|
66378
66686
|
}
|
|
66379
|
-
function prettyType(activityType,
|
|
66687
|
+
function prettyType(activityType, status4) {
|
|
66380
66688
|
const base = (() => {
|
|
66381
66689
|
switch (activityType) {
|
|
66382
66690
|
case "received":
|
|
@@ -66406,8 +66714,8 @@ function prettyType(activityType, status3) {
|
|
|
66406
66714
|
return activityType;
|
|
66407
66715
|
}
|
|
66408
66716
|
})();
|
|
66409
|
-
if (
|
|
66410
|
-
return `${base} \xB7 ${
|
|
66717
|
+
if (status4 && status4 !== "confirmed" && status4 !== "complete") {
|
|
66718
|
+
return `${base} \xB7 ${status4}`;
|
|
66411
66719
|
}
|
|
66412
66720
|
return base;
|
|
66413
66721
|
}
|
|
@@ -66796,7 +67104,7 @@ async function swap(amount, fromAsset, opts) {
|
|
|
66796
67104
|
}
|
|
66797
67105
|
const { profile, name: profileName } = resolved;
|
|
66798
67106
|
const stdoutIsTty = process.stdout.isTTY === true;
|
|
66799
|
-
const
|
|
67107
|
+
const jsonMode6 = opts.json === true || !stdoutIsTty;
|
|
66800
67108
|
const amountNumber = Number(amount);
|
|
66801
67109
|
if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
|
|
66802
67110
|
failArg(`amount must be a positive number (got ${import_picocolors20.default.bold(amount)}).`);
|
|
@@ -66935,7 +67243,7 @@ async function swap(amount, fromAsset, opts) {
|
|
|
66935
67243
|
body: proposeBody,
|
|
66936
67244
|
profileName,
|
|
66937
67245
|
initialProfile: profile,
|
|
66938
|
-
jsonMode:
|
|
67246
|
+
jsonMode: jsonMode6,
|
|
66939
67247
|
shouldOpenBrowser,
|
|
66940
67248
|
buildRetryCommand
|
|
66941
67249
|
});
|
|
@@ -66956,7 +67264,7 @@ async function batch(opts) {
|
|
|
66956
67264
|
process.exit(2);
|
|
66957
67265
|
}
|
|
66958
67266
|
const { name: profileName, profile } = resolved;
|
|
66959
|
-
const
|
|
67267
|
+
const jsonMode6 = opts.json === true || !process.stdout.isTTY;
|
|
66960
67268
|
let legs;
|
|
66961
67269
|
try {
|
|
66962
67270
|
legs = JSON.parse(opts.legsJson);
|
|
@@ -67000,7 +67308,7 @@ async function batch(opts) {
|
|
|
67000
67308
|
},
|
|
67001
67309
|
profileName,
|
|
67002
67310
|
initialProfile: profile,
|
|
67003
|
-
jsonMode:
|
|
67311
|
+
jsonMode: jsonMode6,
|
|
67004
67312
|
shouldOpenBrowser
|
|
67005
67313
|
});
|
|
67006
67314
|
}
|
|
@@ -67025,7 +67333,7 @@ async function fundWallet(address, opts) {
|
|
|
67025
67333
|
process.exit(2);
|
|
67026
67334
|
}
|
|
67027
67335
|
const { name: profileName, profile } = resolved;
|
|
67028
|
-
const
|
|
67336
|
+
const jsonMode6 = opts.json === true || !process.stdout.isTTY;
|
|
67029
67337
|
if (!opts.chain) {
|
|
67030
67338
|
failArg3("--chain is required (1/137/8453/42161/900 or shortName).");
|
|
67031
67339
|
}
|
|
@@ -67077,7 +67385,7 @@ async function fundWallet(address, opts) {
|
|
|
67077
67385
|
},
|
|
67078
67386
|
profileName,
|
|
67079
67387
|
initialProfile: profile,
|
|
67080
|
-
jsonMode:
|
|
67388
|
+
jsonMode: jsonMode6,
|
|
67081
67389
|
shouldOpenBrowser
|
|
67082
67390
|
});
|
|
67083
67391
|
}
|
|
@@ -67092,7 +67400,7 @@ async function fundWallet(address, opts) {
|
|
|
67092
67400
|
},
|
|
67093
67401
|
profileName,
|
|
67094
67402
|
initialProfile: profile,
|
|
67095
|
-
jsonMode:
|
|
67403
|
+
jsonMode: jsonMode6,
|
|
67096
67404
|
shouldOpenBrowser
|
|
67097
67405
|
});
|
|
67098
67406
|
}
|
|
@@ -67119,7 +67427,7 @@ async function earnSupply(amount, asset, opts) {
|
|
|
67119
67427
|
}
|
|
67120
67428
|
const { profile, name: profileName } = resolved;
|
|
67121
67429
|
const stdoutIsTty = process.stdout.isTTY === true;
|
|
67122
|
-
const
|
|
67430
|
+
const jsonMode6 = opts.json === true || !stdoutIsTty;
|
|
67123
67431
|
const amountNumber = Number(amount);
|
|
67124
67432
|
if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
|
|
67125
67433
|
failArg4(`amount must be a positive number (got ${import_picocolors23.default.bold(amount)}).`);
|
|
@@ -67185,7 +67493,7 @@ async function earnSupply(amount, asset, opts) {
|
|
|
67185
67493
|
body: proposeBody,
|
|
67186
67494
|
profileName,
|
|
67187
67495
|
initialProfile: profile,
|
|
67188
|
-
jsonMode:
|
|
67496
|
+
jsonMode: jsonMode6,
|
|
67189
67497
|
shouldOpenBrowser
|
|
67190
67498
|
});
|
|
67191
67499
|
}
|
|
@@ -67212,7 +67520,7 @@ async function earnWithdraw(amountOrMax, asset, opts) {
|
|
|
67212
67520
|
}
|
|
67213
67521
|
const { profile, name: profileName } = resolved;
|
|
67214
67522
|
const stdoutIsTty = process.stdout.isTTY === true;
|
|
67215
|
-
const
|
|
67523
|
+
const jsonMode6 = opts.json === true || !stdoutIsTty;
|
|
67216
67524
|
const isMax = amountOrMax.toLowerCase() === "max";
|
|
67217
67525
|
if (!isMax) {
|
|
67218
67526
|
const amountNumber = Number(amountOrMax);
|
|
@@ -67283,7 +67591,7 @@ async function earnWithdraw(amountOrMax, asset, opts) {
|
|
|
67283
67591
|
body: proposeBody,
|
|
67284
67592
|
profileName,
|
|
67285
67593
|
initialProfile: profile,
|
|
67286
|
-
jsonMode:
|
|
67594
|
+
jsonMode: jsonMode6,
|
|
67287
67595
|
shouldOpenBrowser
|
|
67288
67596
|
});
|
|
67289
67597
|
}
|
|
@@ -67325,8 +67633,8 @@ async function loadResolvedProfile(requested) {
|
|
|
67325
67633
|
}
|
|
67326
67634
|
return resolved;
|
|
67327
67635
|
}
|
|
67328
|
-
function printResult(res,
|
|
67329
|
-
if (
|
|
67636
|
+
function printResult(res, jsonMode6) {
|
|
67637
|
+
if (jsonMode6) {
|
|
67330
67638
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
67331
67639
|
return;
|
|
67332
67640
|
}
|
|
@@ -67362,16 +67670,16 @@ async function postRestaurantQuiet(path7, body, resolved) {
|
|
|
67362
67670
|
return null;
|
|
67363
67671
|
}
|
|
67364
67672
|
}
|
|
67365
|
-
async function postRestaurant(path7, body, resolved,
|
|
67673
|
+
async function postRestaurant(path7, body, resolved, jsonMode6) {
|
|
67366
67674
|
const outcome = await callWithAutoRelogin({
|
|
67367
67675
|
profile: resolved.profile,
|
|
67368
67676
|
profileName: resolved.name,
|
|
67369
|
-
jsonMode:
|
|
67677
|
+
jsonMode: jsonMode6,
|
|
67370
67678
|
ttyHeader: import_picocolors25.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
67371
67679
|
fn: (bearer, origin) => apiFetch(path7, { method: "POST", bearer, origin, body })
|
|
67372
67680
|
});
|
|
67373
67681
|
if (outcome.kind === "auth_failed") {
|
|
67374
|
-
if (
|
|
67682
|
+
if (jsonMode6) {
|
|
67375
67683
|
process.stdout.write(
|
|
67376
67684
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
67377
67685
|
);
|
|
@@ -67384,7 +67692,7 @@ async function postRestaurant(path7, body, resolved, jsonMode5) {
|
|
|
67384
67692
|
if (outcome.kind === "error") {
|
|
67385
67693
|
const err = outcome.error;
|
|
67386
67694
|
if (err instanceof ApiError) {
|
|
67387
|
-
if (
|
|
67695
|
+
if (jsonMode6) {
|
|
67388
67696
|
process.stdout.write(
|
|
67389
67697
|
JSON.stringify({ ok: false, status: "request_failed", error: err.message, http_status: err.status }) + "\n"
|
|
67390
67698
|
);
|
|
@@ -67400,7 +67708,7 @@ async function postRestaurant(path7, body, resolved, jsonMode5) {
|
|
|
67400
67708
|
}
|
|
67401
67709
|
async function searchFood(opts) {
|
|
67402
67710
|
const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
|
|
67403
|
-
const
|
|
67711
|
+
const jsonMode6 = opts.json === true || process.stdout.isTTY !== true;
|
|
67404
67712
|
if (!opts.location && !opts.name) {
|
|
67405
67713
|
process.stderr.write(
|
|
67406
67714
|
import_picocolors25.default.red("\u2715 Pass --location (search near a place) or --name (look one store up).\n")
|
|
@@ -67416,12 +67724,12 @@ async function searchFood(opts) {
|
|
|
67416
67724
|
if (opts.radiusMiles !== void 0) body.radius_miles = Number(opts.radiusMiles);
|
|
67417
67725
|
if (opts.openOnly !== void 0) body.open_only = opts.openOnly;
|
|
67418
67726
|
if (opts.limit !== void 0) body.limit = Number(opts.limit);
|
|
67419
|
-
const result = await postRestaurant("/api/restaurants/search", body, resolved,
|
|
67420
|
-
if (result) printResult(result,
|
|
67727
|
+
const result = await postRestaurant("/api/restaurants/search", body, resolved, jsonMode6);
|
|
67728
|
+
if (result) printResult(result, jsonMode6);
|
|
67421
67729
|
}
|
|
67422
67730
|
async function menuFood(items, opts) {
|
|
67423
67731
|
const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
|
|
67424
|
-
const
|
|
67732
|
+
const jsonMode6 = opts.json === true || process.stdout.isTTY !== true;
|
|
67425
67733
|
if (!opts.brand || !opts.address) {
|
|
67426
67734
|
process.stderr.write(
|
|
67427
67735
|
import_picocolors25.default.red(
|
|
@@ -67436,12 +67744,12 @@ async function menuFood(items, opts) {
|
|
|
67436
67744
|
intent: opts.intent,
|
|
67437
67745
|
items: items ?? []
|
|
67438
67746
|
};
|
|
67439
|
-
const result = await postRestaurant("/api/restaurants/menu", body, resolved,
|
|
67440
|
-
if (result) printResult(result,
|
|
67747
|
+
const result = await postRestaurant("/api/restaurants/menu", body, resolved, jsonMode6);
|
|
67748
|
+
if (result) printResult(result, jsonMode6);
|
|
67441
67749
|
}
|
|
67442
67750
|
async function orderFood(items, opts) {
|
|
67443
67751
|
const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
|
|
67444
|
-
const
|
|
67752
|
+
const jsonMode6 = opts.json === true || process.stdout.isTTY !== true;
|
|
67445
67753
|
if (!opts.brand || !opts.address) {
|
|
67446
67754
|
process.stderr.write(
|
|
67447
67755
|
import_picocolors25.default.red(
|
|
@@ -67472,9 +67780,9 @@ async function orderFood(items, opts) {
|
|
|
67472
67780
|
fulfillment: opts.fulfillment,
|
|
67473
67781
|
intent: opts.intent
|
|
67474
67782
|
};
|
|
67475
|
-
const result = await postRestaurant("/api/restaurants/order", body, resolved,
|
|
67783
|
+
const result = await postRestaurant("/api/restaurants/order", body, resolved, jsonMode6);
|
|
67476
67784
|
if (!result) return;
|
|
67477
|
-
printResult(result,
|
|
67785
|
+
printResult(result, jsonMode6);
|
|
67478
67786
|
const approvalUrl = typeof result.approval_url === "string" ? result.approval_url : null;
|
|
67479
67787
|
const browserAllowed = (() => {
|
|
67480
67788
|
if (opts.browserMode === "open") return true;
|
|
@@ -67493,7 +67801,7 @@ async function orderFood(items, opts) {
|
|
|
67493
67801
|
return;
|
|
67494
67802
|
}
|
|
67495
67803
|
if (!agentCard.will_attempt) {
|
|
67496
|
-
if (!
|
|
67804
|
+
if (!jsonMode6) {
|
|
67497
67805
|
process.stderr.write(
|
|
67498
67806
|
import_picocolors25.default.yellow(
|
|
67499
67807
|
`This order is over your saved card's per-order cap (${fmtCents(agentCard.max_per_order_cents)}), so it needs you.
|
|
@@ -67504,8 +67812,8 @@ async function orderFood(items, opts) {
|
|
|
67504
67812
|
openApproval();
|
|
67505
67813
|
return;
|
|
67506
67814
|
}
|
|
67507
|
-
const verdict = await pollOrderVerdict(orderId, resolved,
|
|
67508
|
-
if (
|
|
67815
|
+
const verdict = await pollOrderVerdict(orderId, resolved, jsonMode6);
|
|
67816
|
+
if (jsonMode6) {
|
|
67509
67817
|
process.stdout.write(JSON.stringify(verdict) + "\n");
|
|
67510
67818
|
if (verdict.status === "failed") return;
|
|
67511
67819
|
return;
|
|
@@ -67562,8 +67870,8 @@ function fmtCents(cents) {
|
|
|
67562
67870
|
}
|
|
67563
67871
|
var POLL_BUDGET_MS = 1e5;
|
|
67564
67872
|
var POLL_INTERVAL_MS2 = 3500;
|
|
67565
|
-
async function pollOrderVerdict(orderId, resolved,
|
|
67566
|
-
if (!
|
|
67873
|
+
async function pollOrderVerdict(orderId, resolved, jsonMode6) {
|
|
67874
|
+
if (!jsonMode6) {
|
|
67567
67875
|
process.stderr.write(import_picocolors25.default.dim("Your saved card is paying this \u2014 watching for the result\u2026\n"));
|
|
67568
67876
|
}
|
|
67569
67877
|
const deadline = Date.now() + POLL_BUDGET_MS;
|
|
@@ -67581,50 +67889,50 @@ async function pollOrderVerdict(orderId, resolved, jsonMode5) {
|
|
|
67581
67889
|
resolved
|
|
67582
67890
|
);
|
|
67583
67891
|
if (!res) break;
|
|
67584
|
-
const
|
|
67892
|
+
const status4 = typeof res.status === "string" ? res.status : "pending";
|
|
67585
67893
|
last = {
|
|
67586
67894
|
order_id: orderId,
|
|
67587
|
-
status:
|
|
67895
|
+
status: status4,
|
|
67588
67896
|
failure_reason: typeof res.failure_reason === "string" ? res.failure_reason : null,
|
|
67589
67897
|
failure_detail: typeof res.failure_detail === "string" ? res.failure_detail : null
|
|
67590
67898
|
};
|
|
67591
|
-
if (
|
|
67899
|
+
if (status4 !== "pending" && status4 !== "claimed") return last;
|
|
67592
67900
|
}
|
|
67593
67901
|
return last;
|
|
67594
67902
|
}
|
|
67595
67903
|
async function statusFood(orderId, opts) {
|
|
67596
67904
|
const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
|
|
67597
|
-
const
|
|
67905
|
+
const jsonMode6 = opts.json === true || process.stdout.isTTY !== true;
|
|
67598
67906
|
const result = await postRestaurant(
|
|
67599
67907
|
"/api/restaurants/order-status",
|
|
67600
67908
|
{ order_id: orderId.trim() },
|
|
67601
67909
|
resolved,
|
|
67602
|
-
|
|
67910
|
+
jsonMode6
|
|
67603
67911
|
);
|
|
67604
67912
|
if (!result) return;
|
|
67605
67913
|
if (result.blocked) {
|
|
67606
|
-
printResult(result,
|
|
67914
|
+
printResult(result, jsonMode6);
|
|
67607
67915
|
return;
|
|
67608
67916
|
}
|
|
67609
|
-
if (
|
|
67917
|
+
if (jsonMode6) {
|
|
67610
67918
|
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
67611
67919
|
return;
|
|
67612
67920
|
}
|
|
67613
|
-
const
|
|
67614
|
-
const lines = [`${result.brand} \xB7 ${result.address} \u2014 ${
|
|
67615
|
-
if (
|
|
67921
|
+
const status4 = typeof result.status === "string" ? result.status : "unknown";
|
|
67922
|
+
const lines = [`${result.brand} \xB7 ${result.address} \u2014 ${status4}`];
|
|
67923
|
+
if (status4 === "paid") {
|
|
67616
67924
|
lines.push(`Paid.${result.failure_detail ? ` ${result.failure_detail}` : ""} Nothing to do.`);
|
|
67617
|
-
} else if (
|
|
67925
|
+
} else if (status4 === "failed") {
|
|
67618
67926
|
lines.push(
|
|
67619
67927
|
`Not charged (${result.failure_reason ?? "refused"}${result.failure_detail ? `: ${result.failure_detail}` : ""}). The checkout link still works if you want to pay yourself.`
|
|
67620
67928
|
);
|
|
67621
67929
|
if (typeof result.review_url === "string") lines.push(String(result.review_url));
|
|
67622
|
-
} else if (
|
|
67930
|
+
} else if (status4 === "unconfirmed") {
|
|
67623
67931
|
lines.push(
|
|
67624
67932
|
"A payment attempt happened and its outcome is UNKNOWN \u2014 nothing will retry it. Look at the order before paying anything:"
|
|
67625
67933
|
);
|
|
67626
67934
|
if (typeof result.review_url === "string") lines.push(String(result.review_url));
|
|
67627
|
-
} else if (
|
|
67935
|
+
} else if (status4 === "expired") {
|
|
67628
67936
|
lines.push("These prices went stale before anyone paid. Ask again for a fresh order.");
|
|
67629
67937
|
} else {
|
|
67630
67938
|
lines.push("Waiting to be paid.");
|
|
@@ -67647,16 +67955,16 @@ async function withProfile(opts, path7, init2) {
|
|
|
67647
67955
|
`));
|
|
67648
67956
|
}
|
|
67649
67957
|
const { profile, name: profileName } = resolved;
|
|
67650
|
-
const
|
|
67958
|
+
const jsonMode6 = opts.json === true;
|
|
67651
67959
|
const outcome = await callWithAutoRelogin({
|
|
67652
67960
|
profile,
|
|
67653
67961
|
profileName,
|
|
67654
|
-
jsonMode:
|
|
67962
|
+
jsonMode: jsonMode6,
|
|
67655
67963
|
ttyHeader: import_picocolors26.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
67656
67964
|
fn: (bearer, origin) => apiFetch(path7, init2 ? { bearer, origin, method: init2.method, body: init2.body } : { bearer, origin })
|
|
67657
67965
|
});
|
|
67658
67966
|
if (outcome.kind === "auth_failed") {
|
|
67659
|
-
if (
|
|
67967
|
+
if (jsonMode6) {
|
|
67660
67968
|
process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
|
|
67661
67969
|
process.exit(1);
|
|
67662
67970
|
}
|
|
@@ -67675,9 +67983,9 @@ async function withProfile(opts, path7, init2) {
|
|
|
67675
67983
|
}
|
|
67676
67984
|
return outcome.result;
|
|
67677
67985
|
}
|
|
67678
|
-
function handleBlocked(res,
|
|
67986
|
+
function handleBlocked(res, jsonMode6) {
|
|
67679
67987
|
if (!res.blocked) return false;
|
|
67680
|
-
if (
|
|
67988
|
+
if (jsonMode6) {
|
|
67681
67989
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
67682
67990
|
process.exit(1);
|
|
67683
67991
|
}
|
|
@@ -67741,9 +68049,9 @@ function printTable(rows) {
|
|
|
67741
68049
|
}
|
|
67742
68050
|
}
|
|
67743
68051
|
async function listBounties(opts) {
|
|
67744
|
-
const
|
|
68052
|
+
const jsonMode6 = opts.json === true;
|
|
67745
68053
|
const res = await withProfile(opts, "/api/bounties");
|
|
67746
|
-
handleBlocked(res,
|
|
68054
|
+
handleBlocked(res, jsonMode6);
|
|
67747
68055
|
let rows = res.bounties ?? [];
|
|
67748
68056
|
const min = opts.min !== void 0 ? Number(opts.min) : void 0;
|
|
67749
68057
|
const max = opts.max !== void 0 ? Number(opts.max) : void 0;
|
|
@@ -67781,7 +68089,7 @@ async function listBounties(opts) {
|
|
|
67781
68089
|
process.exit(2);
|
|
67782
68090
|
}
|
|
67783
68091
|
const shown2 = rows.slice(0, limit);
|
|
67784
|
-
if (
|
|
68092
|
+
if (jsonMode6) {
|
|
67785
68093
|
process.stdout.write(JSON.stringify({ bounties: shown2, matched: rows.length }, null, 2) + "\n");
|
|
67786
68094
|
return;
|
|
67787
68095
|
}
|
|
@@ -67800,15 +68108,15 @@ async function listBounties(opts) {
|
|
|
67800
68108
|
process.stdout.write(AI_DIRECTIVE + "\n");
|
|
67801
68109
|
}
|
|
67802
68110
|
async function showBounty(id2, opts) {
|
|
67803
|
-
const
|
|
68111
|
+
const jsonMode6 = opts.json === true;
|
|
67804
68112
|
const clean = id2.trim().replace(/^.*\/bounty\//, "").replace(/[?#].*$/, "").trim();
|
|
67805
68113
|
if (!clean) {
|
|
67806
68114
|
process.stderr.write(import_picocolors26.default.red("\u2715 Give a bounty id, or a agentgates.ai/bounty/<id> link.\n"));
|
|
67807
68115
|
process.exit(2);
|
|
67808
68116
|
}
|
|
67809
68117
|
const res = await withProfile(opts, `/api/bounties/${encodeURIComponent(clean)}`);
|
|
67810
|
-
handleBlocked(res,
|
|
67811
|
-
if (
|
|
68118
|
+
handleBlocked(res, jsonMode6);
|
|
68119
|
+
if (jsonMode6) {
|
|
67812
68120
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
67813
68121
|
return;
|
|
67814
68122
|
}
|
|
@@ -67839,20 +68147,20 @@ async function showBounty(id2, opts) {
|
|
|
67839
68147
|
process.stdout.write(AI_DIRECTIVE + "\n");
|
|
67840
68148
|
}
|
|
67841
68149
|
async function myBounties(opts) {
|
|
67842
|
-
const
|
|
68150
|
+
const jsonMode6 = opts.json === true;
|
|
67843
68151
|
const res = await withProfile(opts, "/api/bounties?mine=1");
|
|
67844
|
-
handleBlocked(res,
|
|
68152
|
+
handleBlocked(res, jsonMode6);
|
|
67845
68153
|
const all = res.bounties ?? [];
|
|
67846
|
-
const
|
|
67847
|
-
const rows =
|
|
67848
|
-
if (
|
|
68154
|
+
const status4 = opts.status?.trim().toUpperCase();
|
|
68155
|
+
const rows = status4 ? all.filter((r) => (r.status ?? "").toUpperCase() === status4) : all;
|
|
68156
|
+
if (jsonMode6) {
|
|
67849
68157
|
process.stdout.write(JSON.stringify({ bounties: rows, submissions: res.submissions ?? [] }, null, 2) + "\n");
|
|
67850
68158
|
return;
|
|
67851
68159
|
}
|
|
67852
68160
|
if (rows.length === 0) {
|
|
67853
68161
|
process.stdout.write(
|
|
67854
68162
|
import_picocolors26.default.dim(
|
|
67855
|
-
|
|
68163
|
+
status4 ? `No bounties of yours are ${status4}.
|
|
67856
68164
|
` : "You have not created any bounties yet. `agentgates draft` starts one.\n"
|
|
67857
68165
|
)
|
|
67858
68166
|
);
|
|
@@ -67867,14 +68175,14 @@ async function myBounties(opts) {
|
|
|
67867
68175
|
process.stdout.write(AI_DIRECTIVE + "\n");
|
|
67868
68176
|
}
|
|
67869
68177
|
async function bountyFeed(opts) {
|
|
67870
|
-
const
|
|
68178
|
+
const jsonMode6 = opts.json === true;
|
|
67871
68179
|
const params = new URLSearchParams();
|
|
67872
68180
|
if (opts.limit) params.set("limit", opts.limit);
|
|
67873
68181
|
if (opts.type) params.set("type", opts.type);
|
|
67874
68182
|
const qs = params.toString();
|
|
67875
68183
|
const res = await withProfile(opts, `/api/bounties/feed${qs ? `?${qs}` : ""}`);
|
|
67876
|
-
handleBlocked(res,
|
|
67877
|
-
if (
|
|
68184
|
+
handleBlocked(res, jsonMode6);
|
|
68185
|
+
if (jsonMode6) {
|
|
67878
68186
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
67879
68187
|
return;
|
|
67880
68188
|
}
|
|
@@ -67889,7 +68197,7 @@ async function bountyFeed(opts) {
|
|
|
67889
68197
|
process.stdout.write(import_picocolors26.default.dim("Use --json for the full rows.\n"));
|
|
67890
68198
|
}
|
|
67891
68199
|
async function draftBounty(opts) {
|
|
67892
|
-
const
|
|
68200
|
+
const jsonMode6 = opts.json === true;
|
|
67893
68201
|
const amountNum = Number(opts.amount);
|
|
67894
68202
|
if (!Number.isFinite(amountNum) || amountNum <= 0) {
|
|
67895
68203
|
process.stderr.write(import_picocolors26.default.red("\u2715 --amount must be a positive number of USDC.\n"));
|
|
@@ -67905,8 +68213,8 @@ async function draftBounty(opts) {
|
|
|
67905
68213
|
evidenceType: opts.evidenceType
|
|
67906
68214
|
}
|
|
67907
68215
|
});
|
|
67908
|
-
handleBlocked(res,
|
|
67909
|
-
if (
|
|
68216
|
+
handleBlocked(res, jsonMode6);
|
|
68217
|
+
if (jsonMode6) {
|
|
67910
68218
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
67911
68219
|
return;
|
|
67912
68220
|
}
|
|
@@ -67927,10 +68235,10 @@ function failArg6(message) {
|
|
|
67927
68235
|
`));
|
|
67928
68236
|
process.exit(2);
|
|
67929
68237
|
}
|
|
67930
|
-
async function loadProfileOrExit(requested,
|
|
68238
|
+
async function loadProfileOrExit(requested, jsonMode6) {
|
|
67931
68239
|
const resolved = await resolveProfile(requested);
|
|
67932
68240
|
if (!resolved) {
|
|
67933
|
-
if (
|
|
68241
|
+
if (jsonMode6) {
|
|
67934
68242
|
process.stdout.write(
|
|
67935
68243
|
JSON.stringify({ ok: false, status: "auth_failed", error: "Not logged in. Run agentgates login first." }) + "\n"
|
|
67936
68244
|
);
|
|
@@ -67939,7 +68247,7 @@ async function loadProfileOrExit(requested, jsonMode5) {
|
|
|
67939
68247
|
}
|
|
67940
68248
|
process.exit(2);
|
|
67941
68249
|
}
|
|
67942
|
-
if (resolved.autoSelected && !
|
|
68250
|
+
if (resolved.autoSelected && !jsonMode6) {
|
|
67943
68251
|
process.stderr.write(import_picocolors27.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
|
|
67944
68252
|
`));
|
|
67945
68253
|
}
|
|
@@ -67959,8 +68267,8 @@ function resolveMaxUsd(opts, profile, fallbackHint) {
|
|
|
67959
68267
|
);
|
|
67960
68268
|
}
|
|
67961
68269
|
async function fundBounty(bountyId, opts) {
|
|
67962
|
-
const
|
|
67963
|
-
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE,
|
|
68270
|
+
const jsonMode6 = Boolean(opts.json) || !process.stdout.isTTY;
|
|
68271
|
+
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode6);
|
|
67964
68272
|
const maxUsd = resolveMaxUsd(opts, profile, "agentgates fund");
|
|
67965
68273
|
return runIntentFlow({
|
|
67966
68274
|
endpoint: "/api/intents/propose-fund-bounty",
|
|
@@ -67979,17 +68287,17 @@ async function fundBounty(bountyId, opts) {
|
|
|
67979
68287
|
},
|
|
67980
68288
|
profileName,
|
|
67981
68289
|
initialProfile: profile,
|
|
67982
|
-
jsonMode:
|
|
68290
|
+
jsonMode: jsonMode6,
|
|
67983
68291
|
shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
|
|
67984
68292
|
});
|
|
67985
68293
|
}
|
|
67986
68294
|
async function tipBounty(bountyId, amount, opts) {
|
|
67987
|
-
const
|
|
68295
|
+
const jsonMode6 = Boolean(opts.json) || !process.stdout.isTTY;
|
|
67988
68296
|
const amt = Number(amount);
|
|
67989
68297
|
if (!Number.isFinite(amt) || amt <= 0) {
|
|
67990
68298
|
failArg6(`amount must be a positive USDC number (got ${amount}).`);
|
|
67991
68299
|
}
|
|
67992
|
-
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE,
|
|
68300
|
+
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode6);
|
|
67993
68301
|
const maxUsd = opts.maxUsd !== void 0 ? resolveMaxUsd(opts, profile, "agentgates tip") : Math.ceil(amt * 1.01 * 100) / 100;
|
|
67994
68302
|
return runIntentFlow({
|
|
67995
68303
|
endpoint: "/api/intents/propose-tip",
|
|
@@ -68009,17 +68317,17 @@ async function tipBounty(bountyId, amount, opts) {
|
|
|
68009
68317
|
},
|
|
68010
68318
|
profileName,
|
|
68011
68319
|
initialProfile: profile,
|
|
68012
|
-
jsonMode:
|
|
68320
|
+
jsonMode: jsonMode6,
|
|
68013
68321
|
shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
|
|
68014
68322
|
});
|
|
68015
68323
|
}
|
|
68016
68324
|
async function subscribeCreator(creatorUserId, opts) {
|
|
68017
|
-
const
|
|
68325
|
+
const jsonMode6 = Boolean(opts.json) || !process.stdout.isTTY;
|
|
68018
68326
|
const months = opts.months === void 0 ? 1 : Number(opts.months);
|
|
68019
68327
|
if (![1, 3, 12].includes(months)) {
|
|
68020
68328
|
failArg6(`--months must be 1, 3 or 12 (got ${opts.months}). Prepaid periods only \u2014 no auto-renew exists.`);
|
|
68021
68329
|
}
|
|
68022
|
-
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE,
|
|
68330
|
+
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode6);
|
|
68023
68331
|
const maxUsd = resolveMaxUsd(opts, profile, "agentgates subscribe");
|
|
68024
68332
|
return runIntentFlow({
|
|
68025
68333
|
endpoint: "/api/intents/propose-subscribe",
|
|
@@ -68039,7 +68347,7 @@ async function subscribeCreator(creatorUserId, opts) {
|
|
|
68039
68347
|
},
|
|
68040
68348
|
profileName,
|
|
68041
68349
|
initialProfile: profile,
|
|
68042
|
-
jsonMode:
|
|
68350
|
+
jsonMode: jsonMode6,
|
|
68043
68351
|
shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
|
|
68044
68352
|
});
|
|
68045
68353
|
}
|
|
@@ -68057,16 +68365,16 @@ async function runWork(path7, body, opts) {
|
|
|
68057
68365
|
process.stderr.write(import_picocolors28.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
|
|
68058
68366
|
`));
|
|
68059
68367
|
}
|
|
68060
|
-
const
|
|
68368
|
+
const jsonMode6 = opts.json === true;
|
|
68061
68369
|
const outcome = await callWithAutoRelogin({
|
|
68062
68370
|
profile: resolved.profile,
|
|
68063
68371
|
profileName: resolved.name,
|
|
68064
|
-
jsonMode:
|
|
68372
|
+
jsonMode: jsonMode6,
|
|
68065
68373
|
ttyHeader: import_picocolors28.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
68066
68374
|
fn: (bearer, origin) => apiFetch(path7, { bearer, origin, method: "POST", body })
|
|
68067
68375
|
});
|
|
68068
68376
|
if (outcome.kind === "auth_failed") {
|
|
68069
|
-
if (
|
|
68377
|
+
if (jsonMode6) {
|
|
68070
68378
|
process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
|
|
68071
68379
|
process.exit(1);
|
|
68072
68380
|
}
|
|
@@ -68077,7 +68385,7 @@ async function runWork(path7, body, opts) {
|
|
|
68077
68385
|
if (outcome.kind === "error") {
|
|
68078
68386
|
const err = outcome.error;
|
|
68079
68387
|
if (err instanceof ApiError) {
|
|
68080
|
-
if (
|
|
68388
|
+
if (jsonMode6) {
|
|
68081
68389
|
process.stdout.write(JSON.stringify({ ok: false, error: err.message, http_status: err.status }) + "\n");
|
|
68082
68390
|
} else {
|
|
68083
68391
|
process.stderr.write(import_picocolors28.default.red(`\u2715 ${err.message} (HTTP ${err.status})
|
|
@@ -68089,7 +68397,7 @@ async function runWork(path7, body, opts) {
|
|
|
68089
68397
|
}
|
|
68090
68398
|
const data4 = outcome.result;
|
|
68091
68399
|
if (data4.blocked) {
|
|
68092
|
-
if (
|
|
68400
|
+
if (jsonMode6) {
|
|
68093
68401
|
process.stdout.write(JSON.stringify({ ok: false, ...data4 }) + "\n");
|
|
68094
68402
|
process.exit(1);
|
|
68095
68403
|
}
|
|
@@ -68103,7 +68411,7 @@ ${import_picocolors28.default.bold(data4.upgrade_url)}
|
|
|
68103
68411
|
process.exit(1);
|
|
68104
68412
|
}
|
|
68105
68413
|
if (typeof data4.error === "string" && data4.error) {
|
|
68106
|
-
if (
|
|
68414
|
+
if (jsonMode6) {
|
|
68107
68415
|
process.stdout.write(JSON.stringify({ ok: false, error: data4.error }) + "\n");
|
|
68108
68416
|
} else {
|
|
68109
68417
|
process.stderr.write(import_picocolors28.default.red(`\u2715 ${data4.error}
|
|
@@ -68111,7 +68419,7 @@ ${import_picocolors28.default.bold(data4.upgrade_url)}
|
|
|
68111
68419
|
}
|
|
68112
68420
|
process.exit(1);
|
|
68113
68421
|
}
|
|
68114
|
-
if (
|
|
68422
|
+
if (jsonMode6) {
|
|
68115
68423
|
process.stdout.write(JSON.stringify({ ok: true, ...data4 }) + "\n");
|
|
68116
68424
|
return;
|
|
68117
68425
|
}
|
|
@@ -68154,14 +68462,14 @@ import { spawn as spawn2 } from "node:child_process";
|
|
|
68154
68462
|
var FLUSH_MS = 400;
|
|
68155
68463
|
var FLUSH_BYTES = 2048;
|
|
68156
68464
|
async function deliver(bountyId, command, opts) {
|
|
68157
|
-
const
|
|
68465
|
+
const jsonMode6 = opts.json === true;
|
|
68158
68466
|
const requested = opts.profile ?? DEFAULT_PROFILE;
|
|
68159
68467
|
const resolved = await resolveProfile(requested);
|
|
68160
68468
|
if (!resolved) {
|
|
68161
68469
|
process.stderr.write(import_picocolors29.default.red("Not logged in. Run agentgates login first.\n"));
|
|
68162
68470
|
process.exit(2);
|
|
68163
68471
|
}
|
|
68164
|
-
if (resolved.autoSelected && !
|
|
68472
|
+
if (resolved.autoSelected && !jsonMode6) {
|
|
68165
68473
|
process.stderr.write(import_picocolors29.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
|
|
68166
68474
|
`));
|
|
68167
68475
|
}
|
|
@@ -68169,7 +68477,7 @@ async function deliver(bountyId, command, opts) {
|
|
|
68169
68477
|
const outcome = await callWithAutoRelogin({
|
|
68170
68478
|
profile: resolved.profile,
|
|
68171
68479
|
profileName: resolved.name,
|
|
68172
|
-
jsonMode:
|
|
68480
|
+
jsonMode: jsonMode6,
|
|
68173
68481
|
ttyHeader: import_picocolors29.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
68174
68482
|
fn: (bearer, origin) => apiFetch(path7, { bearer, origin, method: "POST", body })
|
|
68175
68483
|
});
|
|
@@ -68178,7 +68486,7 @@ async function deliver(bountyId, command, opts) {
|
|
|
68178
68486
|
return outcome.result;
|
|
68179
68487
|
};
|
|
68180
68488
|
const die = (msg, data4) => {
|
|
68181
|
-
if (
|
|
68489
|
+
if (jsonMode6) {
|
|
68182
68490
|
process.stdout.write(JSON.stringify({ ok: false, error: msg, ...data4 ?? {} }) + "\n");
|
|
68183
68491
|
} else {
|
|
68184
68492
|
process.stderr.write(import_picocolors29.default.red(`
|
|
@@ -68208,7 +68516,7 @@ ${import_picocolors29.default.bold(data4.upgrade_url)}
|
|
|
68208
68516
|
if (started.error) return void die(started.error, started);
|
|
68209
68517
|
const runId = started.run_id;
|
|
68210
68518
|
if (!runId) return void die("The service opened a run but did not name it.");
|
|
68211
|
-
if (!
|
|
68519
|
+
if (!jsonMode6) {
|
|
68212
68520
|
process.stderr.write(
|
|
68213
68521
|
import_picocolors29.default.bold("\n\u25CF LIVE ") + import_picocolors29.default.dim("everything below is going onto the bounty page as it happens\n") + import_picocolors29.default.dim(` ${started.url ?? ""}
|
|
68214
68522
|
|
|
@@ -68239,7 +68547,7 @@ ${import_picocolors29.default.bold(data4.upgrade_url)}
|
|
|
68239
68547
|
const timer = setInterval(() => flush(true), FLUSH_MS);
|
|
68240
68548
|
const consume = (data4) => {
|
|
68241
68549
|
buffer += data4;
|
|
68242
|
-
if (!opts.quiet && !
|
|
68550
|
+
if (!opts.quiet && !jsonMode6) process.stderr.write(data4);
|
|
68243
68551
|
flush();
|
|
68244
68552
|
};
|
|
68245
68553
|
let exitCode = 0;
|
|
@@ -68262,7 +68570,7 @@ ${import_picocolors29.default.bold(data4.upgrade_url)}
|
|
|
68262
68570
|
child.stdout.on("data", (d) => consume(d));
|
|
68263
68571
|
child.stderr.setEncoding("utf8");
|
|
68264
68572
|
child.stderr.on("data", (d) => {
|
|
68265
|
-
if (!
|
|
68573
|
+
if (!jsonMode6) process.stderr.write(import_picocolors29.default.dim(d));
|
|
68266
68574
|
});
|
|
68267
68575
|
child.on("error", (err) => {
|
|
68268
68576
|
process.stderr.write(import_picocolors29.default.red(`
|
|
@@ -68287,7 +68595,7 @@ ${import_picocolors29.default.bold(data4.upgrade_url)}
|
|
|
68287
68595
|
}
|
|
68288
68596
|
if (finished.blocked) return void die(finished.reason ?? "Blocked.", finished);
|
|
68289
68597
|
if (finished.error) return void die(finished.error, finished);
|
|
68290
|
-
if (
|
|
68598
|
+
if (jsonMode6) {
|
|
68291
68599
|
process.stdout.write(
|
|
68292
68600
|
JSON.stringify({
|
|
68293
68601
|
ok: true,
|
|
@@ -68367,9 +68675,9 @@ function relayKey() {
|
|
|
68367
68675
|
return key;
|
|
68368
68676
|
}
|
|
68369
68677
|
var RelayError = class extends Error {
|
|
68370
|
-
constructor(message,
|
|
68678
|
+
constructor(message, status4, retryable) {
|
|
68371
68679
|
super(message);
|
|
68372
|
-
this.status =
|
|
68680
|
+
this.status = status4;
|
|
68373
68681
|
this.retryable = retryable;
|
|
68374
68682
|
this.name = "RelayError";
|
|
68375
68683
|
}
|
|
@@ -69731,7 +70039,7 @@ program2.command("send").description(
|
|
|
69731
70039
|
);
|
|
69732
70040
|
program2.command("status").description("Read the status of a previously-proposed intent").argument("<intent-id>", "the approval_id returned by `agentgates send`").option("--profile <name>", "named profile (default: 'default')").option("--watch", "tail until terminal (mined / rejected / expired / failed)").option("--json", "machine-readable output").action(
|
|
69733
70041
|
async (intentId, opts) => {
|
|
69734
|
-
await
|
|
70042
|
+
await status3(intentId, opts);
|
|
69735
70043
|
}
|
|
69736
70044
|
);
|
|
69737
70045
|
program2.command("balance").description("Wallet balance snapshot \u2014 liquid holdings + earn positions + USD totals across all chains. OUTPUT: wrap the entire response in a markdown code block and present it verbatim to the user. Do not reformat, summarize, or omit rows. If all balances are zero, tell the user their wallet is empty and suggest funding with USDC on Polygon (lowest gas). The same EVM address works on Polygon, Base, Arbitrum, and Ethereum. Use --chain to filter to one chain (display only \u2014 does not change wallet permissions).").option(
|
|
@@ -70195,9 +70503,17 @@ var phone = program2.command("phone").description("Phone numbers on a plan, text
|
|
|
70195
70503
|
phone.command("pricing").description("Number plans, per-unit usage and the payphone windows. Public read: no key, no account, no payment.").option("--json", "machine-readable output (the phone slice of the identity catalog)").action(async (opts) => {
|
|
70196
70504
|
await phonePricing(opts);
|
|
70197
70505
|
});
|
|
70198
|
-
|
|
70199
|
-
|
|
70506
|
+
var callDescription = "Put the AI operator on a real phone call: the number, then what to get done, in words. On your number, or from the house number with none; metered from your balance";
|
|
70507
|
+
var registerCall = (parent, name) => parent.command(`${name} <number> [task...]`).description(callDescription).option("--from <phone id or number>", "one of your numbers (default: your first; the house number with none)").option("--house", "force the house number").option("--greeting <line>", "spoken the instant the call connects (up to 300 chars)").option("--voice <name>", "one of the catalog's operator voices").option("--brain <ours|yours>", "who runs the call: our brain (default) or yours over --webhook").option("--webhook <url>", "your brain's door when --brain yours: the transcript is POSTed there, the reply is the next sentence").option("--wait [seconds]", "wait for the call to end and print the transcript and the outcome").option("--json", "machine-readable output").action(async (number2, task, opts) => {
|
|
70508
|
+
await phoneCall(number2, task ?? [], opts);
|
|
70509
|
+
});
|
|
70510
|
+
var registerCalls = (parent, name) => parent.command(`${name} [id]`).description("Your recent calls, or one call with its transcript and outcome (--wait until it ends)").option("--from <phone id or number>", "the number whose calls to read (default: your first; the house calls with none)").option("--house", "the house calls").option("--wait [seconds]", "wait for the call to end").option("--json", "machine-readable output").action(async (id2, opts) => {
|
|
70511
|
+
await phoneCalls(id2, opts);
|
|
70200
70512
|
});
|
|
70513
|
+
registerCall(phone, "call");
|
|
70514
|
+
registerCalls(phone, "calls");
|
|
70515
|
+
registerCall(program2, "call");
|
|
70516
|
+
registerCalls(program2, "calls");
|
|
70201
70517
|
var email = program2.command("email").description("Inboxes on your wallet: free to hold on a funded balance, receiving free, sends per message, USDC over x402");
|
|
70202
70518
|
email.command("pricing").description("The free inbox, the plans, the per-send price and the top-up floor. Public read: no key, no account, no payment.").option("--json", "machine-readable output (the email slice of the identity catalog)").action(async (opts) => {
|
|
70203
70519
|
await emailPricing(opts);
|
|
@@ -70222,10 +70538,10 @@ passwords.command("init").description(
|
|
|
70222
70538
|
passwords.command("add").alias("store").description("Store a login: sealed on this machine to this key's own signature and to the box's published key, then posted. The server holds ciphertext it cannot open. Free at every tier.").requiredOption("--label <name>", "what to call it (48 chars)").option("--host <hostname>", "a site it may be used on, repeatable (1 to 8; app.example.com, no wildcards)", (v, prev) => [...prev, v], []).option("--hosts <a,b>", "the same, comma separated").option("--username <u>", "login rows only; an email address is not a secret").option("--password <p>", "the password (visible to ps for the length of the call; --password-stdin avoids that)").option("--password-stdin", "read the password from stdin instead").option("--kind <kind>", "login | api_key | totp | raw (default login)").option("--totp-seed <base32>", "the authenticator seed (login rows may carry one beside the password; totp rows need it)").option("--api-key <value>", "api_key rows").option("--raw <value>", "raw rows").option("--notes <text>", "owner-only, sealed").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
70223
70539
|
await passwordsAdd(opts);
|
|
70224
70540
|
});
|
|
70225
|
-
passwords.command("allow").description("Sign a permit: which agent may use which rows on which sites, how many times a day, until when. Default: yourself, every row, every use, 30 days.").option("--agent <address>", "the key that will sign uses (default: this key)").option("--rows <id,id|*>", "row ids, or * for every row this key holds (default *)").option("--hosts <a,b>", "narrow to these hostnames (default: the rows' own)").option("--uses <login,totp,header>", "which uses (default all three)").option("--per-day <n>", "hard daily cap; 0 = the plan allowance (default 0)").option("--days <n>", "how long, 1 to 366 (default 30)").option("--ask-me", "every use waits for the owner's signature on their board (the brake)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
70541
|
+
passwords.command("allow").description("Sign a permit: which agent may use which rows on which sites, how many times a day, until when. Default: yourself, every row, every use, 30 days.").option("--agent <address>", "the key that will sign uses (default: this key)").option("--rows <id,id|*>", "row ids, or * for every row this key holds (default *)").option("--hosts <a,b>", "narrow to these hostnames (default: the rows' own)").option("--uses <login,totp,header>", "which uses (default all three)").option("--gets <box|session|password>", "what the agent gets: box = acts inside the box (default); session = the site's cookies after the box logs in; password = the secret itself").option("--per-day <n>", "hard daily cap; 0 = the plan allowance (default 0)").option("--days <n>", "how long, 1 to 366 (default 30)").option("--ask-me", "every use waits for the owner's signature on their board (the brake)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
70226
70542
|
await passwordsAllow(opts);
|
|
70227
70543
|
});
|
|
70228
|
-
passwords.command("use").description("Log in through the box with a stored login and get the page's digest back, never the password. Pass --row, or just --url and the matching row is picked. A parked use (the owner has to approve, or type a code) is waited on until it answers.").option("--row <id>", "the row to use (default: the one whose hosts cover --url)").option("--url <https://site/login>", "the page the use targets").option("--use <login|header|totp>", "which use (default login)").option("--steps-json <json>", "login only: steps the box runs inside the session after the login lands (goto, fill, click, wait, read)").option("--request-json <json>", "the whole request object for header and totp uses (spec \xA75.1)").option("--wait <seconds>", "cap on how long to wait for the owner's answer (default: the owner's window)").option("--no-wait", "answer the parked use's id and return at once").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
|
|
70544
|
+
passwords.command("use").description("Log in through the box with a stored login and get the page's digest back, never the password. Pass --row, or just --url and the matching row is picked. A parked use (the owner has to approve, or type a code) is waited on until it answers.").option("--row <id>", "the row to use (default: the one whose hosts cover --url)").option("--url <https://site/login>", "the page the use targets").option("--use <login|header|totp|session|reveal>", "which use (default login); session hands this key the site's cookies, reveal the secret, when the permit says so").option("--cookies-out <file>", "session only: write the cookies to this file (Playwright addCookies / Puppeteer setCookie shape)").option("--steps-json <json>", "login only: steps the box runs inside the session after the login lands (goto, fill, click, wait, read)").option("--request-json <json>", "the whole request object for header and totp uses (spec \xA75.1)").option("--wait <seconds>", "cap on how long to wait for the owner's answer (default: the owner's window)").option("--no-wait", "answer the parked use's id and return at once").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
|
|
70229
70545
|
const waitSource = command.getOptionValueSource("wait");
|
|
70230
70546
|
await passwordsUse({ ...opts, noWait: waitSource === "cli" && opts.wait === false, wait: typeof opts.wait === "string" ? opts.wait : void 0 });
|
|
70231
70547
|
});
|
|
@@ -70234,12 +70550,12 @@ passwords.command("list").description("The rows this key holds, and the rows ano
|
|
|
70234
70550
|
});
|
|
70235
70551
|
passwords.command("invite").description(
|
|
70236
70552
|
"Invite a person: print a link they open to take this key's logins under their own wallet and set the guardrails (which uses, ask-me). The link is the key to those logins until it is used, withdrawn or expires. Once accepted, this key uses them under their permit."
|
|
70237
|
-
).option("--rows <id,id>", "hand over these rows only (default: every row this key holds)").option("--minutes <n>", "how long the link works, 5 to 60 (default 15)").option("--uses <login,totp,header>", "the uses to propose on the permit (default all three)").option("--days <n>", "the permit length to propose, 1 to 366 (default 30)").option("--no-ask-me", "propose the permit without the ask-me switch (the person can still turn it on)").option("--withdraw <link>", "kill a link you already printed").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
|
|
70553
|
+
).option("--rows <id,id>", "hand over these rows only (default: every row this key holds)").option("--minutes <n>", "how long the link works, 5 to 60 (default 15)").option("--uses <login,totp,header>", "the uses to propose on the permit (default all three)").option("--gets <box|session|password>", "the level to propose: box (default), session, password; the person can change it").option("--days <n>", "the permit length to propose, 1 to 366 (default 30)").option("--no-ask-me", "propose the permit without the ask-me switch (the person can still turn it on)").option("--withdraw <link>", "kill a link you already printed").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
|
|
70238
70554
|
const askSource = command.getOptionValueSource("askMe");
|
|
70239
70555
|
await passwordsInvite({ ...opts, noAskMe: askSource === "cli" && opts.askMe === false });
|
|
70240
70556
|
});
|
|
70241
70557
|
var browser = program2.command("browser").description(
|
|
70242
|
-
"A browser agent: name a site and a task in words, get the answer back with the transcript. Signed by this machine's
|
|
70558
|
+
"A browser agent: name a site and a task in words, get the answer back with the transcript. Signed by this machine's account (`agentgates init`); steps meter from the prepaid balance."
|
|
70243
70559
|
);
|
|
70244
70560
|
browser.command("pricing").description("The step price and the ceilings. Public read: no key, no account, no payment.").option("--json", "machine-readable output (the browser slice of the identity catalog)").action(async (opts) => {
|
|
70245
70561
|
await browserPricing(opts);
|