@agentgates/cli 0.73.0 → 0.83.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/README.md +31 -0
- package/dist/cli.mjs +1547 -517
- package/package.json +6 -2
package/dist/cli.mjs
CHANGED
|
@@ -982,7 +982,7 @@ var require_command = __commonJS({
|
|
|
982
982
|
var EventEmitter = __require("node:events").EventEmitter;
|
|
983
983
|
var childProcess2 = __require("node:child_process");
|
|
984
984
|
var path8 = __require("node:path");
|
|
985
|
-
var
|
|
985
|
+
var fs11 = __require("node:fs");
|
|
986
986
|
var process8 = __require("node:process");
|
|
987
987
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
988
988
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -1915,10 +1915,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1915
1915
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1916
1916
|
function findFile2(baseDir, baseName2) {
|
|
1917
1917
|
const localBin = path8.resolve(baseDir, baseName2);
|
|
1918
|
-
if (
|
|
1918
|
+
if (fs11.existsSync(localBin)) return localBin;
|
|
1919
1919
|
if (sourceExt.includes(path8.extname(baseName2))) return void 0;
|
|
1920
1920
|
const foundExt = sourceExt.find(
|
|
1921
|
-
(ext) =>
|
|
1921
|
+
(ext) => fs11.existsSync(`${localBin}${ext}`)
|
|
1922
1922
|
);
|
|
1923
1923
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
1924
1924
|
return void 0;
|
|
@@ -1930,7 +1930,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1930
1930
|
if (this._scriptPath) {
|
|
1931
1931
|
let resolvedScriptPath;
|
|
1932
1932
|
try {
|
|
1933
|
-
resolvedScriptPath =
|
|
1933
|
+
resolvedScriptPath = fs11.realpathSync(this._scriptPath);
|
|
1934
1934
|
} catch (err) {
|
|
1935
1935
|
resolvedScriptPath = this._scriptPath;
|
|
1936
1936
|
}
|
|
@@ -3128,7 +3128,7 @@ var init_constants = __esm({
|
|
|
3128
3128
|
trim = (v) => v ? v.replace(/\/$/, "") : "";
|
|
3129
3129
|
CLI_API_ORIGIN = trim(process.env.BOUNTY_API_ORIGIN) || "https://cli.agentgates.ai";
|
|
3130
3130
|
CREATORS_ORIGIN = trim(process.env.BOUNTY_CREATORS_ORIGIN) || "https://agentgates.ai";
|
|
3131
|
-
CLI_VERSION = "0.
|
|
3131
|
+
CLI_VERSION = "0.83.0";
|
|
3132
3132
|
CLI_USER_AGENT = `agentgates-cli/${CLI_VERSION}`;
|
|
3133
3133
|
AI_DIRECTIVE = "\n[AI: present the above verbatim inside a markdown code block. Do not reformat, summarize, or omit rows.]";
|
|
3134
3134
|
}
|
|
@@ -5483,8 +5483,8 @@ var init_units = __esm({
|
|
|
5483
5483
|
});
|
|
5484
5484
|
|
|
5485
5485
|
// node_modules/ethers/lib.esm/utils/uuid.js
|
|
5486
|
-
function uuidV4(
|
|
5487
|
-
const bytes2 = getBytes(
|
|
5486
|
+
function uuidV4(randomBytes10) {
|
|
5487
|
+
const bytes2 = getBytes(randomBytes10, "randomBytes");
|
|
5488
5488
|
bytes2[6] = bytes2[6] & 15 | 64;
|
|
5489
5489
|
bytes2[8] = bytes2[8] & 63 | 128;
|
|
5490
5490
|
const value = hexlify(bytes2);
|
|
@@ -8474,7 +8474,7 @@ function weierstrass(curveDef) {
|
|
|
8474
8474
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
8475
8475
|
if (["recovered", "canonical"].some((k) => k in opts))
|
|
8476
8476
|
throw new Error("sign() legacy options not supported");
|
|
8477
|
-
const { hash: hash2, randomBytes:
|
|
8477
|
+
const { hash: hash2, randomBytes: randomBytes10 } = CURVE;
|
|
8478
8478
|
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
8479
8479
|
if (lowS == null)
|
|
8480
8480
|
lowS = true;
|
|
@@ -8485,7 +8485,7 @@ function weierstrass(curveDef) {
|
|
|
8485
8485
|
const d = normPrivateKeyToScalar(privateKey);
|
|
8486
8486
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
8487
8487
|
if (ent != null) {
|
|
8488
|
-
const e = ent === true ?
|
|
8488
|
+
const e = ent === true ? randomBytes10(Fp3.BYTES) : ent;
|
|
8489
8489
|
seedArgs.push(ensureBytes("extraEntropy", e));
|
|
8490
8490
|
}
|
|
8491
8491
|
const seed = concatBytes2(...seedArgs);
|
|
@@ -23503,7 +23503,7 @@ var require_constants = __commonJS({
|
|
|
23503
23503
|
// node_modules/node-gyp-build/node-gyp-build.js
|
|
23504
23504
|
var require_node_gyp_build = __commonJS({
|
|
23505
23505
|
"node_modules/node-gyp-build/node-gyp-build.js"(exports, module) {
|
|
23506
|
-
var
|
|
23506
|
+
var fs11 = __require("fs");
|
|
23507
23507
|
var path8 = __require("path");
|
|
23508
23508
|
var os5 = __require("os");
|
|
23509
23509
|
var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
@@ -23564,7 +23564,7 @@ var require_node_gyp_build = __commonJS({
|
|
|
23564
23564
|
};
|
|
23565
23565
|
function readdirSync(dir) {
|
|
23566
23566
|
try {
|
|
23567
|
-
return
|
|
23567
|
+
return fs11.readdirSync(dir);
|
|
23568
23568
|
} catch (err) {
|
|
23569
23569
|
return [];
|
|
23570
23570
|
}
|
|
@@ -23658,7 +23658,7 @@ var require_node_gyp_build = __commonJS({
|
|
|
23658
23658
|
return typeof window !== "undefined" && window.process && window.process.type === "renderer";
|
|
23659
23659
|
}
|
|
23660
23660
|
function isAlpine(platform3) {
|
|
23661
|
-
return platform3 === "linux" &&
|
|
23661
|
+
return platform3 === "linux" && fs11.existsSync("/etc/alpine-release");
|
|
23662
23662
|
}
|
|
23663
23663
|
load.parseTags = parseTags;
|
|
23664
23664
|
load.matchTags = matchTags;
|
|
@@ -25860,7 +25860,7 @@ var require_websocket = __commonJS({
|
|
|
25860
25860
|
var http2 = __require("http");
|
|
25861
25861
|
var net = __require("net");
|
|
25862
25862
|
var tls = __require("tls");
|
|
25863
|
-
var { randomBytes:
|
|
25863
|
+
var { randomBytes: randomBytes10, createHash: createHash10 } = __require("crypto");
|
|
25864
25864
|
var { Duplex, Readable } = __require("stream");
|
|
25865
25865
|
var { URL: URL4 } = __require("url");
|
|
25866
25866
|
var PerMessageDeflate = require_permessage_deflate();
|
|
@@ -26386,7 +26386,7 @@ var require_websocket = __commonJS({
|
|
|
26386
26386
|
}
|
|
26387
26387
|
}
|
|
26388
26388
|
const defaultPort = isSecure ? 443 : 80;
|
|
26389
|
-
const key =
|
|
26389
|
+
const key = randomBytes10(16).toString("base64");
|
|
26390
26390
|
const request = isSecure ? https2.request : http2.request;
|
|
26391
26391
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
26392
26392
|
let perMessageDeflate;
|
|
@@ -26516,7 +26516,7 @@ var require_websocket = __commonJS({
|
|
|
26516
26516
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
26517
26517
|
return;
|
|
26518
26518
|
}
|
|
26519
|
-
const digest =
|
|
26519
|
+
const digest = createHash10("sha1").update(key + GUID).digest("base64");
|
|
26520
26520
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
26521
26521
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
26522
26522
|
return;
|
|
@@ -26762,7 +26762,7 @@ var require_websocket_server = __commonJS({
|
|
|
26762
26762
|
var EventEmitter = __require("events");
|
|
26763
26763
|
var http2 = __require("http");
|
|
26764
26764
|
var { Duplex } = __require("stream");
|
|
26765
|
-
var { createHash:
|
|
26765
|
+
var { createHash: createHash10 } = __require("crypto");
|
|
26766
26766
|
var extension = require_extension();
|
|
26767
26767
|
var PerMessageDeflate = require_permessage_deflate();
|
|
26768
26768
|
var subprotocol = require_subprotocol();
|
|
@@ -27057,7 +27057,7 @@ var require_websocket_server = __commonJS({
|
|
|
27057
27057
|
);
|
|
27058
27058
|
}
|
|
27059
27059
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
27060
|
-
const digest =
|
|
27060
|
+
const digest = createHash10("sha1").update(key + GUID).digest("base64");
|
|
27061
27061
|
const headers = [
|
|
27062
27062
|
"HTTP/1.1 101 Switching Protocols",
|
|
27063
27063
|
"Upgrade: websocket",
|
|
@@ -31697,7 +31697,9 @@ function buildSecretPayload(input) {
|
|
|
31697
31697
|
}
|
|
31698
31698
|
secret[field] = value;
|
|
31699
31699
|
}
|
|
31700
|
-
|
|
31700
|
+
const throughLogin = input.signsInThrough === true && kind === "login";
|
|
31701
|
+
if (throughLogin && secret.password) throw new PasswordsSealError("a login that signs in through another row holds no password of its own");
|
|
31702
|
+
if (rules.required && !secret[rules.required] && !throughLogin) {
|
|
31701
31703
|
throw new PasswordsSealError(`a ${kind} row needs its ${rules.required}`);
|
|
31702
31704
|
}
|
|
31703
31705
|
const hosts = validateHosts(input.hosts);
|
|
@@ -32678,82 +32680,12 @@ var init_passwords_wire = __esm({
|
|
|
32678
32680
|
revokedNoticed = false;
|
|
32679
32681
|
keyOnly = false;
|
|
32680
32682
|
loginReading = null;
|
|
32681
|
-
SIGNED_DOORS = /\/keys(\/(?!me\/)|$)|\/passwords\/[A-Za-z0-9_-]{1,64}\/use$|\/seal-key$|\/ag\/(?:agent
|
|
32683
|
+
SIGNED_DOORS = /\/keys(\/(?!me\/)|$)|\/passwords\/[A-Za-z0-9_-]{1,64}\/use$|\/seal-key$|\/ag\/(?:agent(?:\?turnOn=1)?|bindings)$|\/integrations(\/|$)/;
|
|
32682
32684
|
PASSWORDS_BOX_APP_ID = "c8746c93771d337af3588872dcad76ddb1fccdb6";
|
|
32683
32685
|
PASSWORDS_REPORT_DATA_LABEL = "agentgates/passwords/seal-key/v1";
|
|
32684
32686
|
}
|
|
32685
32687
|
});
|
|
32686
32688
|
|
|
32687
|
-
// package.json
|
|
32688
|
-
var require_package = __commonJS({
|
|
32689
|
-
"package.json"(exports, module) {
|
|
32690
|
-
module.exports = {
|
|
32691
|
-
name: "@agentgates/cli",
|
|
32692
|
-
version: "0.73.0",
|
|
32693
|
-
description: "Wallet operations for AI agents and humans",
|
|
32694
|
-
keywords: [
|
|
32695
|
-
"crypto",
|
|
32696
|
-
"wallet",
|
|
32697
|
-
"cli",
|
|
32698
|
-
"ai-agent",
|
|
32699
|
-
"agentgates",
|
|
32700
|
-
"usdc",
|
|
32701
|
-
"solana",
|
|
32702
|
-
"ethereum",
|
|
32703
|
-
"polygon",
|
|
32704
|
-
"defi"
|
|
32705
|
-
],
|
|
32706
|
-
license: "MIT",
|
|
32707
|
-
homepage: "https://agentgates.ai",
|
|
32708
|
-
repository: {
|
|
32709
|
-
type: "git",
|
|
32710
|
-
url: "git+https://github.com/Carlos-Sotop/agentgates-ai-cli.git"
|
|
32711
|
-
},
|
|
32712
|
-
author: "Agentgates",
|
|
32713
|
-
type: "module",
|
|
32714
|
-
bin: {
|
|
32715
|
-
agentgates: "bin/agentgates"
|
|
32716
|
-
},
|
|
32717
|
-
files: [
|
|
32718
|
-
"bin",
|
|
32719
|
-
"dist/cli.mjs",
|
|
32720
|
-
"scripts/postinstall.mjs",
|
|
32721
|
-
"README.md"
|
|
32722
|
-
],
|
|
32723
|
-
scripts: {
|
|
32724
|
-
build: `esbuild src/main.ts --bundle --platform=node --format=esm --outfile=dist/cli.mjs --define:process.env.CLI_VERSION="\\"$npm_package_version\\"" --banner:js="import{createRequire}from'module';const require=createRequire(import.meta.url);"`,
|
|
32725
|
-
"build:tsc": "tsc -p tsconfig.json",
|
|
32726
|
-
postinstall: "node scripts/postinstall.mjs || exit 0",
|
|
32727
|
-
prepare: "[ -x node_modules/.bin/esbuild ] && npm run build || true",
|
|
32728
|
-
dev: "tsc -w -p tsconfig.json",
|
|
32729
|
-
typecheck: "tsc --noEmit",
|
|
32730
|
-
test: "tsc -p tsconfig.json && node --test test/*.test.mjs",
|
|
32731
|
-
bounty: "node bin/bounty",
|
|
32732
|
-
"sync:bounty-shared": "node scripts/sync-bounty-shared.mjs",
|
|
32733
|
-
clean: "rm -rf dist"
|
|
32734
|
-
},
|
|
32735
|
-
engines: {
|
|
32736
|
-
node: ">=20"
|
|
32737
|
-
},
|
|
32738
|
-
devDependencies: {
|
|
32739
|
-
"@solana/web3.js": "^1.98.4",
|
|
32740
|
-
"@types/node": "^22.10.0",
|
|
32741
|
-
commander: "^12.1.0",
|
|
32742
|
-
esbuild: "^0.28.0",
|
|
32743
|
-
ethers: "^6.16.0",
|
|
32744
|
-
open: "^10.1.0",
|
|
32745
|
-
picocolors: "^1.1.1",
|
|
32746
|
-
typescript: "^5.6.3"
|
|
32747
|
-
},
|
|
32748
|
-
dependencies: {
|
|
32749
|
-
"@noble/ciphers": "^1.3.0",
|
|
32750
|
-
"@noble/curves": "^1.9.7",
|
|
32751
|
-
"@noble/hashes": "^1.8.0"
|
|
32752
|
-
}
|
|
32753
|
-
};
|
|
32754
|
-
}
|
|
32755
|
-
});
|
|
32756
|
-
|
|
32757
32689
|
// node_modules/@noble/hashes/cryptoNode.js
|
|
32758
32690
|
var require_cryptoNode = __commonJS({
|
|
32759
32691
|
"node_modules/@noble/hashes/cryptoNode.js"(exports) {
|
|
@@ -32797,7 +32729,7 @@ var require_utils = __commonJS({
|
|
|
32797
32729
|
exports.createHasher = createHasher2;
|
|
32798
32730
|
exports.createOptHasher = createOptHasher;
|
|
32799
32731
|
exports.createXOFer = createXOFer;
|
|
32800
|
-
exports.randomBytes =
|
|
32732
|
+
exports.randomBytes = randomBytes10;
|
|
32801
32733
|
var crypto_1 = require_cryptoNode();
|
|
32802
32734
|
function isBytes3(a) {
|
|
32803
32735
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
@@ -32995,7 +32927,7 @@ var require_utils = __commonJS({
|
|
|
32995
32927
|
exports.wrapConstructor = createHasher2;
|
|
32996
32928
|
exports.wrapConstructorWithOpts = createOptHasher;
|
|
32997
32929
|
exports.wrapXOFConstructorWithOpts = createXOFer;
|
|
32998
|
-
function
|
|
32930
|
+
function randomBytes10(bytesLength = 32) {
|
|
32999
32931
|
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") {
|
|
33000
32932
|
return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
33001
32933
|
}
|
|
@@ -35167,7 +35099,7 @@ var require_edwards = __commonJS({
|
|
|
35167
35099
|
});
|
|
35168
35100
|
const { prehash } = eddsaOpts;
|
|
35169
35101
|
const { BASE, Fp: Fp3, Fn: Fn2 } = Point2;
|
|
35170
|
-
const
|
|
35102
|
+
const randomBytes10 = eddsaOpts.randomBytes || utils_ts_1.randomBytes;
|
|
35171
35103
|
const adjustScalarBytes2 = eddsaOpts.adjustScalarBytes || ((bytes2) => bytes2);
|
|
35172
35104
|
const domain = eddsaOpts.domain || ((data4, ctx2, phflag) => {
|
|
35173
35105
|
(0, utils_ts_1._abool2)(phflag, "phflag");
|
|
@@ -35249,7 +35181,7 @@ var require_edwards = __commonJS({
|
|
|
35249
35181
|
signature: 2 * _size,
|
|
35250
35182
|
seed: _size
|
|
35251
35183
|
};
|
|
35252
|
-
function randomSecretKey(seed =
|
|
35184
|
+
function randomSecretKey(seed = randomBytes10(lengths.seed)) {
|
|
35253
35185
|
return (0, utils_ts_1._abytes2)(seed, lengths.seed, "seed");
|
|
35254
35186
|
}
|
|
35255
35187
|
function keygen(seed) {
|
|
@@ -49757,7 +49689,7 @@ var require_websocket2 = __commonJS({
|
|
|
49757
49689
|
var http2 = __require("http");
|
|
49758
49690
|
var net = __require("net");
|
|
49759
49691
|
var tls = __require("tls");
|
|
49760
|
-
var { randomBytes:
|
|
49692
|
+
var { randomBytes: randomBytes10, createHash: createHash10 } = __require("crypto");
|
|
49761
49693
|
var { Duplex, Readable } = __require("stream");
|
|
49762
49694
|
var { URL: URL4 } = __require("url");
|
|
49763
49695
|
var PerMessageDeflate = require_permessage_deflate2();
|
|
@@ -50295,7 +50227,7 @@ var require_websocket2 = __commonJS({
|
|
|
50295
50227
|
}
|
|
50296
50228
|
}
|
|
50297
50229
|
const defaultPort = isSecure ? 443 : 80;
|
|
50298
|
-
const key =
|
|
50230
|
+
const key = randomBytes10(16).toString("base64");
|
|
50299
50231
|
const request = isSecure ? https2.request : http2.request;
|
|
50300
50232
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
50301
50233
|
let perMessageDeflate;
|
|
@@ -50425,7 +50357,7 @@ var require_websocket2 = __commonJS({
|
|
|
50425
50357
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
50426
50358
|
return;
|
|
50427
50359
|
}
|
|
50428
|
-
const digest =
|
|
50360
|
+
const digest = createHash10("sha1").update(key + GUID).digest("base64");
|
|
50429
50361
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
50430
50362
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
50431
50363
|
return;
|
|
@@ -50794,7 +50726,7 @@ var require_websocket_server2 = __commonJS({
|
|
|
50794
50726
|
var EventEmitter = __require("events");
|
|
50795
50727
|
var http2 = __require("http");
|
|
50796
50728
|
var { Duplex } = __require("stream");
|
|
50797
|
-
var { createHash:
|
|
50729
|
+
var { createHash: createHash10 } = __require("crypto");
|
|
50798
50730
|
var extension = require_extension2();
|
|
50799
50731
|
var PerMessageDeflate = require_permessage_deflate2();
|
|
50800
50732
|
var subprotocol = require_subprotocol2();
|
|
@@ -51101,7 +51033,7 @@ var require_websocket_server2 = __commonJS({
|
|
|
51101
51033
|
);
|
|
51102
51034
|
}
|
|
51103
51035
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
51104
|
-
const digest =
|
|
51036
|
+
const digest = createHash10("sha1").update(key + GUID).digest("base64");
|
|
51105
51037
|
const headers = [
|
|
51106
51038
|
"HTTP/1.1 101 Switching Protocols",
|
|
51107
51039
|
"Upgrade: websocket",
|
|
@@ -51568,14 +51500,14 @@ var init_v1ToV6 = __esm({
|
|
|
51568
51500
|
});
|
|
51569
51501
|
|
|
51570
51502
|
// node_modules/rpc-websockets/node_modules/uuid/dist-node/md5.js
|
|
51571
|
-
import { createHash as
|
|
51503
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
51572
51504
|
function md52(bytes2) {
|
|
51573
51505
|
if (Array.isArray(bytes2)) {
|
|
51574
51506
|
bytes2 = Buffer.from(bytes2);
|
|
51575
51507
|
} else if (typeof bytes2 === "string") {
|
|
51576
51508
|
bytes2 = Buffer.from(bytes2, "utf8");
|
|
51577
51509
|
}
|
|
51578
|
-
return
|
|
51510
|
+
return createHash8("md5").update(bytes2).digest();
|
|
51579
51511
|
}
|
|
51580
51512
|
var md5_default2;
|
|
51581
51513
|
var init_md52 = __esm({
|
|
@@ -51682,14 +51614,14 @@ var init_v42 = __esm({
|
|
|
51682
51614
|
});
|
|
51683
51615
|
|
|
51684
51616
|
// node_modules/rpc-websockets/node_modules/uuid/dist-node/sha1.js
|
|
51685
|
-
import { createHash as
|
|
51617
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
51686
51618
|
function sha12(bytes2) {
|
|
51687
51619
|
if (Array.isArray(bytes2)) {
|
|
51688
51620
|
bytes2 = Buffer.from(bytes2);
|
|
51689
51621
|
} else if (typeof bytes2 === "string") {
|
|
51690
51622
|
bytes2 = Buffer.from(bytes2, "utf8");
|
|
51691
51623
|
}
|
|
51692
|
-
return
|
|
51624
|
+
return createHash9("sha1").update(bytes2).digest();
|
|
51693
51625
|
}
|
|
51694
51626
|
var sha1_default2;
|
|
51695
51627
|
var init_sha12 = __esm({
|
|
@@ -53912,7 +53844,7 @@ var require_weierstrass = __commonJS({
|
|
|
53912
53844
|
bits2int: "function",
|
|
53913
53845
|
bits2int_modN: "function"
|
|
53914
53846
|
});
|
|
53915
|
-
const
|
|
53847
|
+
const randomBytes10 = ecdsaOpts.randomBytes || utils_ts_1.randomBytes;
|
|
53916
53848
|
const hmac3 = ecdsaOpts.hmac || ((key, ...msgs) => (0, hmac_js_1.hmac)(hash2, key, (0, utils_ts_1.concatBytes)(...msgs)));
|
|
53917
53849
|
const { Fp: Fp3, Fn: Fn2 } = Point2;
|
|
53918
53850
|
const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn2;
|
|
@@ -54067,7 +53999,7 @@ var require_weierstrass = __commonJS({
|
|
|
54067
53999
|
const d = _normFnElement(Fn2, privateKey);
|
|
54068
54000
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
54069
54001
|
if (extraEntropy != null && extraEntropy !== false) {
|
|
54070
|
-
const e = extraEntropy === true ?
|
|
54002
|
+
const e = extraEntropy === true ? randomBytes10(lengths.secretKey) : extraEntropy;
|
|
54071
54003
|
seedArgs.push((0, utils_ts_1.ensureBytes)("extraEntropy", e));
|
|
54072
54004
|
}
|
|
54073
54005
|
const seed = (0, utils_ts_1.concatBytes)(...seedArgs);
|
|
@@ -63672,6 +63604,9 @@ Message: ${transactionMessage}.
|
|
|
63672
63604
|
}
|
|
63673
63605
|
});
|
|
63674
63606
|
|
|
63607
|
+
// src/main.ts
|
|
63608
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
63609
|
+
|
|
63675
63610
|
// node_modules/commander/esm.mjs
|
|
63676
63611
|
var import_index = __toESM(require_commander(), 1);
|
|
63677
63612
|
var {
|
|
@@ -64666,7 +64601,7 @@ function shortAddress(addr) {
|
|
|
64666
64601
|
|
|
64667
64602
|
// src/commands/onboard.ts
|
|
64668
64603
|
var import_picocolors12 = __toESM(require_picocolors(), 1);
|
|
64669
|
-
import { createInterface } from "node:readline/promises";
|
|
64604
|
+
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
64670
64605
|
init_constants();
|
|
64671
64606
|
|
|
64672
64607
|
// src/lib/water.ts
|
|
@@ -64803,55 +64738,8 @@ function water() {
|
|
|
64803
64738
|
|
|
64804
64739
|
// src/commands/compute.ts
|
|
64805
64740
|
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
64806
|
-
|
|
64807
|
-
|
|
64808
|
-
async function computePlans(opts) {
|
|
64809
|
-
const res = await fetch(`${SITE}/api/compute/catalog`, { headers: { accept: "application/json" } });
|
|
64810
|
-
if (!res.ok) throw new Error(`compute catalog: HTTP ${res.status}`);
|
|
64811
|
-
const body = await res.json();
|
|
64812
|
-
if (opts.json) {
|
|
64813
|
-
process.stdout.write(JSON.stringify(body, null, 2) + "\n");
|
|
64814
|
-
return;
|
|
64815
|
-
}
|
|
64816
|
-
const plans = body.plans ?? [];
|
|
64817
|
-
if (plans.length === 0) {
|
|
64818
|
-
process.stdout.write(` ${import_picocolors3.default.dim("No plans are on sale right now.")}
|
|
64819
|
-
`);
|
|
64820
|
-
return;
|
|
64821
|
-
}
|
|
64822
|
-
process.stdout.write(`
|
|
64823
|
-
${import_picocolors3.default.bold("CONFIDENTIAL VIRTUAL MACHINES")} ${import_picocolors3.default.dim("memory encrypted in use")}
|
|
64824
|
-
|
|
64825
|
-
`);
|
|
64826
|
-
for (const p of plans) {
|
|
64827
|
-
const spec = `${p.vcpu} vCPU \xB7 ${Math.round(p.memoryMb / 1024)} GB \xB7 ${p.diskGb}GB disk`;
|
|
64828
|
-
process.stdout.write(` ${import_picocolors3.default.bold(p.name.padEnd(10))} ${import_picocolors3.default.cyan(usd(p.priceUsdPerHour))}${import_picocolors3.default.dim("/hour")} ${import_picocolors3.default.dim(spec)}
|
|
64829
|
-
`);
|
|
64830
|
-
process.stdout.write(` ${import_picocolors3.default.dim(p.id.padEnd(10))} ${import_picocolors3.default.dim(`${p.egressQuotaGb} GB traffic`)}
|
|
64831
|
-
`);
|
|
64832
|
-
const ladder = p.pricing.map((r) => `${r.hoursPerPayment}h ${usd(r.totalUsd)}`).join(" ");
|
|
64833
|
-
if (ladder) process.stdout.write(` ${import_picocolors3.default.dim(ladder)}
|
|
64834
|
-
`);
|
|
64835
|
-
process.stdout.write("\n");
|
|
64836
|
-
}
|
|
64837
|
-
const nets = body.payment?.networks ?? [];
|
|
64838
|
-
if (nets.length) process.stdout.write(` ${import_picocolors3.default.dim(`USDC on ${nets.join(", ")}`)}
|
|
64839
|
-
|
|
64840
|
-
`);
|
|
64841
|
-
}
|
|
64842
|
-
async function computeBuy() {
|
|
64843
|
-
process.stdout.write(
|
|
64844
|
-
`
|
|
64845
|
-
Renting signs an x402 payment, and this CLI has no signer yet.
|
|
64846
|
-
Buy from the wallet, one biometric: ${import_picocolors3.default.cyan(`${SITE}/compute`)}
|
|
64847
|
-
Prices from here: ${import_picocolors3.default.dim("agentgates compute plans")}
|
|
64848
|
-
|
|
64849
|
-
`
|
|
64850
|
-
);
|
|
64851
|
-
}
|
|
64852
|
-
|
|
64853
|
-
// src/commands/inference.ts
|
|
64854
|
-
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
64741
|
+
import { promises as fs8 } from "node:fs";
|
|
64742
|
+
import { createInterface } from "node:readline/promises";
|
|
64855
64743
|
|
|
64856
64744
|
// src/lib/passwords-key.ts
|
|
64857
64745
|
init_lib2();
|
|
@@ -65033,9 +64921,6 @@ async function requirePasswordsKey() {
|
|
|
65033
64921
|
return existing;
|
|
65034
64922
|
}
|
|
65035
64923
|
|
|
65036
|
-
// src/commands/inference.ts
|
|
65037
|
-
init_passwords_wire();
|
|
65038
|
-
|
|
65039
64924
|
// src/lib/x402-pay.ts
|
|
65040
64925
|
init_lib2();
|
|
65041
64926
|
var EVM_CHAINS = {
|
|
@@ -65127,7 +65012,7 @@ async function chooseLeg(body, address) {
|
|
|
65127
65012
|
bestHeldMicro: bestHeld
|
|
65128
65013
|
};
|
|
65129
65014
|
}
|
|
65130
|
-
function
|
|
65015
|
+
function usd(micro) {
|
|
65131
65016
|
const neg = micro < 0n;
|
|
65132
65017
|
const v = neg ? -micro : micro;
|
|
65133
65018
|
const whole = v / 1000000n;
|
|
@@ -65172,9 +65057,683 @@ async function signLeg(leg, privateKey) {
|
|
|
65172
65057
|
};
|
|
65173
65058
|
}
|
|
65174
65059
|
|
|
65060
|
+
// src/lib/compute-wire.ts
|
|
65061
|
+
init_constants();
|
|
65062
|
+
init_passwords_wire();
|
|
65063
|
+
var trim3 = (v) => v ? v.trim().replace(/\/+$/, "") : "";
|
|
65064
|
+
function computeOrigin() {
|
|
65065
|
+
return trim3(process.env.AGENTGATES_COMPUTE_ORIGIN) || "https://api.agentgates.ai";
|
|
65066
|
+
}
|
|
65067
|
+
var DEPLOYMENTS_PATH = "/api/compute/deployments";
|
|
65068
|
+
var CATALOG_PATH = "/api/compute/catalog";
|
|
65069
|
+
var ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
65070
|
+
function deploymentPath(id2, action) {
|
|
65071
|
+
const clean3 = String(id2 ?? "").trim();
|
|
65072
|
+
if (!ID_RE.test(clean3)) throw new Error(`"${id2}" is not a machine id (agentgates compute list shows yours)`);
|
|
65073
|
+
return `${DEPLOYMENTS_PATH}/${clean3}${action ? `/${action}` : ""}`;
|
|
65074
|
+
}
|
|
65075
|
+
function positiveInt(value, what) {
|
|
65076
|
+
const n2 = typeof value === "number" ? value : Number(String(value ?? "").trim());
|
|
65077
|
+
if (!Number.isInteger(n2) || n2 <= 0) throw new Error(`${what} must be a whole number above 0`);
|
|
65078
|
+
return n2;
|
|
65079
|
+
}
|
|
65080
|
+
var ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
65081
|
+
function parseEnvPairs(pairs) {
|
|
65082
|
+
const out = {};
|
|
65083
|
+
for (const raw of pairs ?? []) {
|
|
65084
|
+
const at = raw.indexOf("=");
|
|
65085
|
+
const key = at > 0 ? raw.slice(0, at) : "";
|
|
65086
|
+
if (!ENV_KEY_RE.test(key)) {
|
|
65087
|
+
throw new Error(
|
|
65088
|
+
at > 0 ? `--env takes KEY=VALUE, and "${key.slice(0, 64)}" is not a variable name` : "--env takes KEY=VALUE: one --env has no NAME= in front (its text is not shown)"
|
|
65089
|
+
);
|
|
65090
|
+
}
|
|
65091
|
+
out[key] = raw.slice(at + 1);
|
|
65092
|
+
}
|
|
65093
|
+
return out;
|
|
65094
|
+
}
|
|
65095
|
+
function createBody(input) {
|
|
65096
|
+
const plan = (input.plan ?? "").trim();
|
|
65097
|
+
if (!plan) throw new Error("say which plan: --plan <id> (agentgates compute plans lists them)");
|
|
65098
|
+
const hours = positiveInt(input.hours, "--hours");
|
|
65099
|
+
const image = input.image?.trim();
|
|
65100
|
+
const compose = input.compose;
|
|
65101
|
+
if (image && compose !== void 0) throw new Error("send --image or --compose, not both");
|
|
65102
|
+
if (!image && (compose === void 0 || !compose.trim())) {
|
|
65103
|
+
throw new Error("say what runs: --image <image> (one container) or --compose <file> (a docker-compose.yml)");
|
|
65104
|
+
}
|
|
65105
|
+
const body = { plan, hours };
|
|
65106
|
+
if (image) {
|
|
65107
|
+
body.image = image;
|
|
65108
|
+
if (input.port !== void 0) {
|
|
65109
|
+
const port = positiveInt(input.port, "--port");
|
|
65110
|
+
if (port > 65535) throw new Error("--port must be a port number, 1 to 65535");
|
|
65111
|
+
body.port = port;
|
|
65112
|
+
}
|
|
65113
|
+
} else {
|
|
65114
|
+
if (input.port !== void 0) throw new Error("--port goes with --image; a compose publishes its own ports");
|
|
65115
|
+
body.compose = compose;
|
|
65116
|
+
}
|
|
65117
|
+
if (input.env && Object.keys(input.env).length > 0) body.env = input.env;
|
|
65118
|
+
const name = input.name?.trim();
|
|
65119
|
+
if (name) body.name = name;
|
|
65120
|
+
return body;
|
|
65121
|
+
}
|
|
65122
|
+
function legsOn(body, network) {
|
|
65123
|
+
const want = (network ?? "").trim().toLowerCase();
|
|
65124
|
+
if (!want) return body;
|
|
65125
|
+
return { ...body, accepts: (body.accepts ?? []).filter((leg) => (leg.network ?? "").toLowerCase() === want) };
|
|
65126
|
+
}
|
|
65127
|
+
function offeredNetworks(body) {
|
|
65128
|
+
return (body.accepts ?? []).map((leg) => leg.network ?? "?");
|
|
65129
|
+
}
|
|
65130
|
+
async function computeCall(args) {
|
|
65131
|
+
const f2 = args.fetchImpl ?? fetch;
|
|
65132
|
+
const res = await f2(args.url, {
|
|
65133
|
+
method: args.method,
|
|
65134
|
+
headers: {
|
|
65135
|
+
accept: "application/json",
|
|
65136
|
+
"user-agent": CLI_USER_AGENT,
|
|
65137
|
+
...args.body !== void 0 ? { "content-type": "application/json" } : {},
|
|
65138
|
+
...args.headers ?? {}
|
|
65139
|
+
},
|
|
65140
|
+
...args.body !== void 0 ? { body: JSON.stringify(args.body) } : {},
|
|
65141
|
+
signal: AbortSignal.timeout(args.timeoutMs)
|
|
65142
|
+
});
|
|
65143
|
+
const text = await res.text().catch(() => "");
|
|
65144
|
+
let parsed = {};
|
|
65145
|
+
try {
|
|
65146
|
+
parsed = text ? JSON.parse(text) : {};
|
|
65147
|
+
} catch {
|
|
65148
|
+
parsed = { error: text.replace(/\s+/g, " ").trim().slice(0, 300) || `HTTP ${res.status}` };
|
|
65149
|
+
}
|
|
65150
|
+
const json2 = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : { value: parsed };
|
|
65151
|
+
const retryAfter = Number(res.headers.get("retry-after"));
|
|
65152
|
+
return { status: res.status, json: json2, retryAfterSeconds: Number.isFinite(retryAfter) && retryAfter > 0 ? retryAfter : null };
|
|
65153
|
+
}
|
|
65154
|
+
function askPrice(url, body, fetchImpl) {
|
|
65155
|
+
return computeCall({ method: "POST", url, body, timeoutMs: 6e4, fetchImpl });
|
|
65156
|
+
}
|
|
65157
|
+
var BACKOFF_MS = [2e3, 4e3, 8e3, 15e3, 3e4];
|
|
65158
|
+
async function sendPaid(args) {
|
|
65159
|
+
const attempts = Math.max(1, args.attempts ?? 6);
|
|
65160
|
+
const sleep4 = args.sleep ?? ((ms) => new Promise((resolve3) => setTimeout(resolve3, ms)));
|
|
65161
|
+
let last = null;
|
|
65162
|
+
let why = "";
|
|
65163
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
65164
|
+
let answer = null;
|
|
65165
|
+
try {
|
|
65166
|
+
answer = await computeCall({
|
|
65167
|
+
method: "POST",
|
|
65168
|
+
url: args.url,
|
|
65169
|
+
body: args.body,
|
|
65170
|
+
headers: { "x-payment": args.payment },
|
|
65171
|
+
// A create waits for the chain, then the vendor: the API allows
|
|
65172
|
+
// itself 120 seconds.
|
|
65173
|
+
timeoutMs: args.timeoutMs ?? 15e4,
|
|
65174
|
+
fetchImpl: args.fetchImpl
|
|
65175
|
+
});
|
|
65176
|
+
} catch (err) {
|
|
65177
|
+
why = err?.message || String(err);
|
|
65178
|
+
}
|
|
65179
|
+
if (answer) {
|
|
65180
|
+
last = answer;
|
|
65181
|
+
if (answer.status >= 200 && answer.status < 300) return { kind: "served", answer, attempts: attempt };
|
|
65182
|
+
const inProgress = answer.status === 409 && answer.json?.code === "payment_in_progress";
|
|
65183
|
+
if (!(answer.status >= 500 || answer.status === 429 || inProgress)) return { kind: "refused", answer, attempts: attempt };
|
|
65184
|
+
why = typeof answer.json?.error === "string" ? answer.json.error : `HTTP ${answer.status}`;
|
|
65185
|
+
}
|
|
65186
|
+
if (attempt === attempts) break;
|
|
65187
|
+
const waitMs = answer?.retryAfterSeconds ? Math.min(answer.retryAfterSeconds, 60) * 1e3 : BACKOFF_MS[Math.min(attempt - 1, BACKOFF_MS.length - 1)];
|
|
65188
|
+
args.onRetry?.(why, attempt, waitMs);
|
|
65189
|
+
await sleep4(waitMs);
|
|
65190
|
+
}
|
|
65191
|
+
return { kind: "no_answer", error: why, attempts, last };
|
|
65192
|
+
}
|
|
65193
|
+
async function ownerGet(wallet, path8, opts = {}) {
|
|
65194
|
+
const header = await ownerAuthHeader(wallet, "GET", path8);
|
|
65195
|
+
return computeCall({
|
|
65196
|
+
method: "GET",
|
|
65197
|
+
url: `${computeOrigin()}${path8}`,
|
|
65198
|
+
headers: { "x-wallet-auth": header },
|
|
65199
|
+
timeoutMs: opts.timeoutMs ?? 6e4,
|
|
65200
|
+
fetchImpl: opts.fetchImpl
|
|
65201
|
+
});
|
|
65202
|
+
}
|
|
65203
|
+
function stillStarting(machine) {
|
|
65204
|
+
if (machine.status === "provisioning") return true;
|
|
65205
|
+
return machine.status === "stopped" && machine.stop?.starting === true;
|
|
65206
|
+
}
|
|
65207
|
+
async function waitUntilRunning(args) {
|
|
65208
|
+
const now = args.now ?? Date.now;
|
|
65209
|
+
const sleep4 = args.sleep ?? ((ms) => new Promise((resolve3) => setTimeout(resolve3, ms)));
|
|
65210
|
+
const started = now();
|
|
65211
|
+
let machine = null;
|
|
65212
|
+
for (; ; ) {
|
|
65213
|
+
let answer = null;
|
|
65214
|
+
try {
|
|
65215
|
+
answer = await args.read();
|
|
65216
|
+
} catch {
|
|
65217
|
+
answer = null;
|
|
65218
|
+
}
|
|
65219
|
+
if (answer && answer.status >= 400 && answer.status < 500) return { kind: "refused", answer };
|
|
65220
|
+
if (answer && answer.status >= 200 && answer.status < 300) {
|
|
65221
|
+
machine = answer.json;
|
|
65222
|
+
args.onTick?.(machine);
|
|
65223
|
+
if (machine.status === "running") return { kind: "running", machine };
|
|
65224
|
+
if (!stillStarting(machine)) return { kind: "ended", machine };
|
|
65225
|
+
}
|
|
65226
|
+
const elapsed = now() - started;
|
|
65227
|
+
if (elapsed >= args.timeoutMs) return { kind: "timeout", machine };
|
|
65228
|
+
await sleep4(Math.min(elapsed < 6e4 ? 5e3 : 1e4, Math.max(1, args.timeoutMs - elapsed)));
|
|
65229
|
+
}
|
|
65230
|
+
}
|
|
65231
|
+
|
|
65232
|
+
// src/commands/compute.ts
|
|
65233
|
+
var money = (v) => `$${String(v).replace(/(\.\d\d\d?)0+$/, "$1")}`;
|
|
65234
|
+
var jsonMode = (opts) => Boolean(opts.json) || !process.stdout.isTTY;
|
|
65235
|
+
var sink = null;
|
|
65236
|
+
function say(text) {
|
|
65237
|
+
if (sink) sink(text, "out");
|
|
65238
|
+
else process.stdout.write(text);
|
|
65239
|
+
}
|
|
65240
|
+
function sayErr(text) {
|
|
65241
|
+
if (sink) sink(text, "err");
|
|
65242
|
+
else process.stderr.write(text);
|
|
65243
|
+
}
|
|
65244
|
+
function fail(opts, error, code, extra = {}) {
|
|
65245
|
+
if (jsonMode(opts)) {
|
|
65246
|
+
say(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
|
|
65247
|
+
} else {
|
|
65248
|
+
const line2 = `
|
|
65249
|
+
${import_picocolors3.default.red("\u2717")} ${error}${code ? import_picocolors3.default.dim(` (${code})`) : ""}
|
|
65250
|
+
|
|
65251
|
+
`;
|
|
65252
|
+
if (sink) sink(line2, "err");
|
|
65253
|
+
else process.stderr.write(line2);
|
|
65254
|
+
}
|
|
65255
|
+
process.exitCode = 1;
|
|
65256
|
+
}
|
|
65257
|
+
function apiWords(answer) {
|
|
65258
|
+
const e = answer.json?.error;
|
|
65259
|
+
return typeof e === "string" && e ? e : `the compute API answered ${answer.status}`;
|
|
65260
|
+
}
|
|
65261
|
+
function apiCode(answer) {
|
|
65262
|
+
const c = answer.json?.code;
|
|
65263
|
+
return typeof c === "string" && c ? c : `http_${answer.status}`;
|
|
65264
|
+
}
|
|
65265
|
+
async function payingKey(opts) {
|
|
65266
|
+
let keys2;
|
|
65267
|
+
try {
|
|
65268
|
+
keys2 = await requirePasswordsKey();
|
|
65269
|
+
} catch (err) {
|
|
65270
|
+
fail(opts, err.message, "no_account");
|
|
65271
|
+
return null;
|
|
65272
|
+
}
|
|
65273
|
+
if (keys2.state.keyOnly) {
|
|
65274
|
+
fail(
|
|
65275
|
+
opts,
|
|
65276
|
+
"this machine runs on a login key with no words, and a machine is paid for and owned by a key that signs: run `agentgates init` here, or set AGENTGATES_PASSWORDS_SEED",
|
|
65277
|
+
"words_required"
|
|
65278
|
+
);
|
|
65279
|
+
return null;
|
|
65280
|
+
}
|
|
65281
|
+
return keys2.wallet;
|
|
65282
|
+
}
|
|
65283
|
+
async function computePlans(opts) {
|
|
65284
|
+
const res = await fetch(`${computeOrigin()}${CATALOG_PATH}`, { headers: { accept: "application/json" } });
|
|
65285
|
+
if (!res.ok) throw new Error(`compute catalog: HTTP ${res.status}`);
|
|
65286
|
+
const body = await res.json();
|
|
65287
|
+
if (opts.json) {
|
|
65288
|
+
say(JSON.stringify(body, null, 2) + "\n");
|
|
65289
|
+
return;
|
|
65290
|
+
}
|
|
65291
|
+
const plans = body.plans ?? [];
|
|
65292
|
+
if (plans.length === 0) {
|
|
65293
|
+
say(` ${import_picocolors3.default.dim("No plans are on sale right now.")}
|
|
65294
|
+
`);
|
|
65295
|
+
return;
|
|
65296
|
+
}
|
|
65297
|
+
say(`
|
|
65298
|
+
${import_picocolors3.default.bold("CONFIDENTIAL VIRTUAL MACHINES")} ${import_picocolors3.default.dim("memory encrypted in use")}
|
|
65299
|
+
|
|
65300
|
+
`);
|
|
65301
|
+
for (const p of plans) {
|
|
65302
|
+
const spec = `${p.vcpu} vCPU \xB7 ${Math.round(p.memoryMb / 1024)} GB \xB7 ${p.diskGb}GB disk`;
|
|
65303
|
+
say(` ${import_picocolors3.default.bold(p.name.padEnd(10))} ${import_picocolors3.default.cyan(money(p.priceUsdPerHour))}${import_picocolors3.default.dim("/hour")} ${import_picocolors3.default.dim(spec)}
|
|
65304
|
+
`);
|
|
65305
|
+
say(` ${import_picocolors3.default.dim(p.id.padEnd(10))} ${import_picocolors3.default.dim(`${p.egressQuotaGb} GB traffic`)}
|
|
65306
|
+
`);
|
|
65307
|
+
const ladder = p.pricing.map((r) => `${r.hoursPerPayment}h ${money(r.totalUsd)}`).join(" ");
|
|
65308
|
+
if (ladder) say(` ${import_picocolors3.default.dim(ladder)}
|
|
65309
|
+
`);
|
|
65310
|
+
say("\n");
|
|
65311
|
+
}
|
|
65312
|
+
const nets = body.payment?.networks ?? [];
|
|
65313
|
+
if (nets.length) say(` ${import_picocolors3.default.dim(`USDC on ${nets.join(", ")}`)}
|
|
65314
|
+
`);
|
|
65315
|
+
say(` ${import_picocolors3.default.dim("rent one: agentgates compute buy --plan <id> --hours 1 --image <image> (--quote prices it, signs nothing)")}
|
|
65316
|
+
|
|
65317
|
+
`);
|
|
65318
|
+
}
|
|
65319
|
+
async function readCompose(file) {
|
|
65320
|
+
if (file === "-") {
|
|
65321
|
+
const chunks = [];
|
|
65322
|
+
for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
|
|
65323
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
65324
|
+
}
|
|
65325
|
+
try {
|
|
65326
|
+
return await fs8.readFile(file, "utf8");
|
|
65327
|
+
} catch (err) {
|
|
65328
|
+
throw new Error(`could not read the compose file ${file}: ${err.code ?? err.message}`);
|
|
65329
|
+
}
|
|
65330
|
+
}
|
|
65331
|
+
function microOfUsd(raw) {
|
|
65332
|
+
const m = /^\s*\$?(\d+)(?:\.(\d{1,6}))?\s*$/.exec(raw);
|
|
65333
|
+
if (!m) throw new Error(`--max-usd takes dollars, like 1 or 0.5 (got "${raw}")`);
|
|
65334
|
+
return BigInt(m[1]) * 1000000n + BigInt((m[2] ?? "").padEnd(6, "0"));
|
|
65335
|
+
}
|
|
65336
|
+
function legView(leg) {
|
|
65337
|
+
let amount = null;
|
|
65338
|
+
try {
|
|
65339
|
+
amount = leg.maxAmountRequired ? usd(BigInt(leg.maxAmountRequired)) : null;
|
|
65340
|
+
} catch {
|
|
65341
|
+
amount = null;
|
|
65342
|
+
}
|
|
65343
|
+
return {
|
|
65344
|
+
network: leg.network ?? "?",
|
|
65345
|
+
amountUsd: amount,
|
|
65346
|
+
amountAtomic: leg.maxAmountRequired ?? null,
|
|
65347
|
+
payTo: leg.payTo ?? null,
|
|
65348
|
+
asset: leg.asset ?? null,
|
|
65349
|
+
validSeconds: leg.maxTimeoutSeconds ?? null
|
|
65350
|
+
};
|
|
65351
|
+
}
|
|
65352
|
+
async function computeBuy(opts) {
|
|
65353
|
+
let body;
|
|
65354
|
+
try {
|
|
65355
|
+
const compose = opts.compose !== void 0 ? await readCompose(opts.compose) : void 0;
|
|
65356
|
+
body = createBody({
|
|
65357
|
+
plan: opts.plan,
|
|
65358
|
+
hours: opts.hours,
|
|
65359
|
+
image: opts.image,
|
|
65360
|
+
port: opts.port,
|
|
65361
|
+
compose,
|
|
65362
|
+
env: parseEnvPairs(opts.env),
|
|
65363
|
+
name: opts.name
|
|
65364
|
+
});
|
|
65365
|
+
} catch (err) {
|
|
65366
|
+
fail(opts, err.message, "bad_input");
|
|
65367
|
+
return;
|
|
65368
|
+
}
|
|
65369
|
+
const what = `${String(body.plan)}, ${String(body.hours)} h, ${typeof body.image === "string" ? body.image : "your compose"}`;
|
|
65370
|
+
await payFor(opts, { url: `${computeOrigin()}${DEPLOYMENTS_PATH}`, body, what, action: "buy" });
|
|
65371
|
+
}
|
|
65372
|
+
async function computeRenew(id2, opts) {
|
|
65373
|
+
let path8;
|
|
65374
|
+
let hours;
|
|
65375
|
+
try {
|
|
65376
|
+
path8 = deploymentPath(id2, "renew");
|
|
65377
|
+
hours = positiveInt(opts.hours, "--hours");
|
|
65378
|
+
} catch (err) {
|
|
65379
|
+
fail(opts, err.message, "bad_input");
|
|
65380
|
+
return;
|
|
65381
|
+
}
|
|
65382
|
+
await payFor(opts, { url: `${computeOrigin()}${path8}`, body: { hours }, what: `${hours} more h on ${id2}`, action: "renew" });
|
|
65383
|
+
}
|
|
65384
|
+
async function payFor(opts, args) {
|
|
65385
|
+
let quote;
|
|
65386
|
+
try {
|
|
65387
|
+
quote = await askPrice(args.url, args.body);
|
|
65388
|
+
} catch (err) {
|
|
65389
|
+
fail(opts, `the compute API did not answer: ${err.message}`, "unreachable");
|
|
65390
|
+
return;
|
|
65391
|
+
}
|
|
65392
|
+
if (quote.status !== 402) {
|
|
65393
|
+
if (quote.status >= 200 && quote.status < 300) {
|
|
65394
|
+
emitMachine(opts, quote.json, { note: "served without a payment" });
|
|
65395
|
+
return;
|
|
65396
|
+
}
|
|
65397
|
+
fail(opts, apiWords(quote), apiCode(quote), { status: quote.status });
|
|
65398
|
+
return;
|
|
65399
|
+
}
|
|
65400
|
+
const offer = quote.json;
|
|
65401
|
+
const legs = (offer.accepts ?? []).map(legView);
|
|
65402
|
+
const description = offer.accepts?.[0]?.description ?? null;
|
|
65403
|
+
if (opts.quote) {
|
|
65404
|
+
if (jsonMode(opts)) {
|
|
65405
|
+
say(JSON.stringify({ ok: true, quote: { description, resource: offer.accepts?.[0]?.resource ?? null, legs } }, null, 2) + "\n");
|
|
65406
|
+
return;
|
|
65407
|
+
}
|
|
65408
|
+
say(`
|
|
65409
|
+
${import_picocolors3.default.bold(description ?? args.what)} ${import_picocolors3.default.dim("nothing signed")}
|
|
65410
|
+
|
|
65411
|
+
`);
|
|
65412
|
+
for (const [i, l] of legs.entries()) {
|
|
65413
|
+
const evm = evmLegs({ accepts: [offer.accepts[i]] }).length > 0;
|
|
65414
|
+
say(` ${import_picocolors3.default.cyan((l.amountUsd ?? "?").padEnd(10))} ${l.network.padEnd(9)} ${import_picocolors3.default.dim(`to ${l.payTo ?? "?"}`)}${evm ? "" : import_picocolors3.default.dim(" (needs a Solana key; this CLI signs EVM legs)")}
|
|
65415
|
+
`);
|
|
65416
|
+
}
|
|
65417
|
+
say(`
|
|
65418
|
+
${import_picocolors3.default.dim("pay: the same command without --quote")}
|
|
65419
|
+
|
|
65420
|
+
`);
|
|
65421
|
+
return;
|
|
65422
|
+
}
|
|
65423
|
+
const wallet = await payingKey(opts);
|
|
65424
|
+
if (!wallet) return;
|
|
65425
|
+
const narrowed = legsOn(offer, opts.network);
|
|
65426
|
+
if (opts.network && !(narrowed.accepts ?? []).length) {
|
|
65427
|
+
fail(opts, `this price has no leg on ${opts.network} (offered: ${offeredNetworks(offer).join(", ") || "none"})`, "network_not_offered", { legs });
|
|
65428
|
+
return;
|
|
65429
|
+
}
|
|
65430
|
+
const choice = await chooseLeg(narrowed, wallet.address);
|
|
65431
|
+
let leg;
|
|
65432
|
+
let heldMicro;
|
|
65433
|
+
if (choice.ok) {
|
|
65434
|
+
leg = choice.leg;
|
|
65435
|
+
heldMicro = choice.heldMicro;
|
|
65436
|
+
} else if (choice.needMicro !== null && choice.bestHeldMicro === null) {
|
|
65437
|
+
leg = [...evmLegs(narrowed)].sort((a, b2) => a.amountMicro < b2.amountMicro ? -1 : a.amountMicro > b2.amountMicro ? 1 : 0)[0];
|
|
65438
|
+
heldMicro = null;
|
|
65439
|
+
} else {
|
|
65440
|
+
const need2 = choice.needMicro === null ? null : usd(choice.needMicro);
|
|
65441
|
+
const held3 = choice.bestHeldMicro === null ? null : usd(choice.bestHeldMicro);
|
|
65442
|
+
const evmNets = evmLegs(narrowed).map((l) => l.network);
|
|
65443
|
+
const sentence = need2 && held3 ? `${choice.reason}. It costs ${need2} and this key holds ${held3}. Send USDC to ${wallet.address} on ${evmNets.join(" or ") || "an offered network"}, then run this again` : choice.reason;
|
|
65444
|
+
fail(opts, sentence, need2 && held3 ? "insufficient_funds" : "no_signable_leg", { address: wallet.address, legs });
|
|
65445
|
+
return;
|
|
65446
|
+
}
|
|
65447
|
+
const price = usd(leg.amountMicro);
|
|
65448
|
+
if (opts.maxUsd !== void 0) {
|
|
65449
|
+
let ceiling;
|
|
65450
|
+
try {
|
|
65451
|
+
ceiling = microOfUsd(opts.maxUsd);
|
|
65452
|
+
} catch (err) {
|
|
65453
|
+
fail(opts, err.message, "bad_input");
|
|
65454
|
+
return;
|
|
65455
|
+
}
|
|
65456
|
+
if (leg.amountMicro > ceiling) {
|
|
65457
|
+
fail(opts, `the price is ${price} on ${leg.network}, over --max-usd ${usd(ceiling)}: nothing was signed`, "over_max", { legs });
|
|
65458
|
+
return;
|
|
65459
|
+
}
|
|
65460
|
+
}
|
|
65461
|
+
if (!opts.yes) {
|
|
65462
|
+
if (jsonMode(opts) || !process.stdin.isTTY) {
|
|
65463
|
+
fail(opts, `pass --yes to pay ${price} on ${leg.network} without a prompt: nothing was signed`, "confirm_required", { legs });
|
|
65464
|
+
return;
|
|
65465
|
+
}
|
|
65466
|
+
say(`
|
|
65467
|
+
${import_picocolors3.default.bold(description ?? args.what)}
|
|
65468
|
+
`);
|
|
65469
|
+
const holds = heldMicro === null ? "this key's balance could not be read" : `this key holds ${usd(heldMicro)} there`;
|
|
65470
|
+
say(` ${import_picocolors3.default.dim(`pay ${price} USDC on ${leg.network} to ${leg.payTo} \xB7 ${holds} \xB7 no gas`)}
|
|
65471
|
+
`);
|
|
65472
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
65473
|
+
let answer = "";
|
|
65474
|
+
try {
|
|
65475
|
+
answer = (await rl.question(` Pay? [y/N] `)).trim().toLowerCase();
|
|
65476
|
+
} catch {
|
|
65477
|
+
answer = "";
|
|
65478
|
+
} finally {
|
|
65479
|
+
rl.close();
|
|
65480
|
+
}
|
|
65481
|
+
if (answer !== "y" && answer !== "yes") {
|
|
65482
|
+
say(` ${import_picocolors3.default.dim("Nothing paid.")}
|
|
65483
|
+
|
|
65484
|
+
`);
|
|
65485
|
+
return;
|
|
65486
|
+
}
|
|
65487
|
+
}
|
|
65488
|
+
const signed2 = await signLeg(leg, wallet.privateKey);
|
|
65489
|
+
const paid = { network: leg.network, amountUsd: price, amountAtomic: leg.amountMicro.toString(), from: signed2.from, nonce: signed2.nonce };
|
|
65490
|
+
if (!jsonMode(opts)) say(` ${import_picocolors3.default.dim(`paying ${price} on ${leg.network}`)}
|
|
65491
|
+
`);
|
|
65492
|
+
else sayErr(`${JSON.stringify({ event: "paid", ...paid })}
|
|
65493
|
+
`);
|
|
65494
|
+
const outcome = await sendPaid({
|
|
65495
|
+
url: args.url,
|
|
65496
|
+
body: args.body,
|
|
65497
|
+
payment: signed2.header,
|
|
65498
|
+
onRetry: (why, attempt, waitMs) => {
|
|
65499
|
+
if (!jsonMode(opts)) {
|
|
65500
|
+
say(` ${import_picocolors3.default.dim(`no clear answer yet (${why}); sending the same payment again in ${Math.round(waitMs / 1e3)} s (${attempt})`)}
|
|
65501
|
+
`);
|
|
65502
|
+
}
|
|
65503
|
+
}
|
|
65504
|
+
});
|
|
65505
|
+
if (outcome.kind === "no_answer") {
|
|
65506
|
+
fail(
|
|
65507
|
+
opts,
|
|
65508
|
+
`no clear answer after ${outcome.attempts} tries (${outcome.error}). The payment may have settled: do not pay again. \`agentgates compute list\` shows what it bought`,
|
|
65509
|
+
"no_answer",
|
|
65510
|
+
{ paid }
|
|
65511
|
+
);
|
|
65512
|
+
return;
|
|
65513
|
+
}
|
|
65514
|
+
if (outcome.kind === "refused") {
|
|
65515
|
+
const a = outcome.answer;
|
|
65516
|
+
const resent = outcome.attempts > 1;
|
|
65517
|
+
const charged = resent ? "The first send may have settled: do not pay again; `agentgates compute list` shows what it bought" : "Nothing was charged";
|
|
65518
|
+
if (a.status === 402 && a.json?.code === "insufficient_funds") {
|
|
65519
|
+
const need2 = typeof a.json.needUsd === "string" ? `$${a.json.needUsd}` : price;
|
|
65520
|
+
const have = typeof a.json.haveUsd === "string" ? `$${a.json.haveUsd}` : null;
|
|
65521
|
+
fail(
|
|
65522
|
+
opts,
|
|
65523
|
+
`not enough USDC on ${a.json.network ?? leg.network}: it costs ${need2}${have ? ` and ${signed2.from} holds ${have}` : ""}. ${charged}`,
|
|
65524
|
+
"insufficient_funds",
|
|
65525
|
+
{ status: a.status, needUsd: a.json.needUsd ?? null, haveUsd: a.json.haveUsd ?? null, paid }
|
|
65526
|
+
);
|
|
65527
|
+
return;
|
|
65528
|
+
}
|
|
65529
|
+
if (a.status === 402) {
|
|
65530
|
+
fail(
|
|
65531
|
+
opts,
|
|
65532
|
+
resent ? `the payment was refused on a resend: ${apiWords(a)}. ${charged}` : `the payment was refused and nothing was charged: ${apiWords(a)}`,
|
|
65533
|
+
apiCode(a) === "http_402" ? "payment_refused" : apiCode(a),
|
|
65534
|
+
{ status: a.status, paid, resent }
|
|
65535
|
+
);
|
|
65536
|
+
return;
|
|
65537
|
+
}
|
|
65538
|
+
if (a.json?.code === "payment_already_spent") {
|
|
65539
|
+
fail(opts, `${apiWords(a)} (\`agentgates compute list\`)`, "payment_already_spent", { status: a.status, paid });
|
|
65540
|
+
return;
|
|
65541
|
+
}
|
|
65542
|
+
fail(opts, apiWords(a), apiCode(a), { status: a.status, paid });
|
|
65543
|
+
return;
|
|
65544
|
+
}
|
|
65545
|
+
const machine = outcome.answer.json;
|
|
65546
|
+
const note2 = machine.alreadyPaid === true ? "this payment had already bought it; nothing was charged again" : null;
|
|
65547
|
+
if (!(opts.wait && args.action === "buy" && machine.deploymentId)) {
|
|
65548
|
+
emitMachine(opts, machine, { paid, note: note2, next: args.action === "buy" });
|
|
65549
|
+
return;
|
|
65550
|
+
}
|
|
65551
|
+
if (!jsonMode(opts)) emitMachine(opts, machine, { paid, note: note2, next: false });
|
|
65552
|
+
else sayErr(`${JSON.stringify({ event: "machine", deploymentId: machine.deploymentId ?? null, status: machine.status ?? null })}
|
|
65553
|
+
`);
|
|
65554
|
+
await waitAndReport(opts, wallet, machine.deploymentId ?? "", { paid, deploymentId: machine.deploymentId ?? null });
|
|
65555
|
+
}
|
|
65556
|
+
function readRefused(opts, answer, wallet, extra = {}) {
|
|
65557
|
+
const words7 = apiWords(answer);
|
|
65558
|
+
const hint = answer.status === 404 ? ` (this key is ${wallet.address})` : "";
|
|
65559
|
+
fail(opts, `${words7}${hint}`, apiCode(answer), { status: answer.status, signer: wallet.address, ...extra });
|
|
65560
|
+
}
|
|
65561
|
+
async function computeList(opts) {
|
|
65562
|
+
const wallet = await payingKey(opts);
|
|
65563
|
+
if (!wallet) return;
|
|
65564
|
+
let answer;
|
|
65565
|
+
try {
|
|
65566
|
+
answer = await ownerGet(wallet, DEPLOYMENTS_PATH);
|
|
65567
|
+
} catch (err) {
|
|
65568
|
+
fail(opts, `the compute API did not answer: ${err.message}`, "unreachable");
|
|
65569
|
+
return;
|
|
65570
|
+
}
|
|
65571
|
+
if (answer.status !== 200) {
|
|
65572
|
+
readRefused(opts, answer, wallet);
|
|
65573
|
+
return;
|
|
65574
|
+
}
|
|
65575
|
+
const machines = Array.isArray(answer.json.deployments) ? answer.json.deployments : [];
|
|
65576
|
+
if (jsonMode(opts)) {
|
|
65577
|
+
say(JSON.stringify({ ok: true, owner: wallet.address, deployments: machines }, null, 2) + "\n");
|
|
65578
|
+
return;
|
|
65579
|
+
}
|
|
65580
|
+
say(`
|
|
65581
|
+
${import_picocolors3.default.bold("MACHINES")} ${import_picocolors3.default.dim(`owned by ${wallet.address}`)}
|
|
65582
|
+
|
|
65583
|
+
`);
|
|
65584
|
+
if (machines.length === 0) {
|
|
65585
|
+
say(` ${import_picocolors3.default.dim("None yet. Rent one: agentgates compute buy --plan <id> --hours 1 --image <image>")}
|
|
65586
|
+
|
|
65587
|
+
`);
|
|
65588
|
+
return;
|
|
65589
|
+
}
|
|
65590
|
+
for (const m of machines) say(`${machineLines(m)}
|
|
65591
|
+
|
|
65592
|
+
`);
|
|
65593
|
+
}
|
|
65594
|
+
async function computeStatus(id2, opts) {
|
|
65595
|
+
let path8;
|
|
65596
|
+
try {
|
|
65597
|
+
path8 = deploymentPath(id2);
|
|
65598
|
+
} catch (err) {
|
|
65599
|
+
fail(opts, err.message, "bad_input");
|
|
65600
|
+
return;
|
|
65601
|
+
}
|
|
65602
|
+
const wallet = await payingKey(opts);
|
|
65603
|
+
if (!wallet) return;
|
|
65604
|
+
let answer;
|
|
65605
|
+
try {
|
|
65606
|
+
answer = await ownerGet(wallet, path8);
|
|
65607
|
+
} catch (err) {
|
|
65608
|
+
fail(opts, `the compute API did not answer: ${err.message}`, "unreachable");
|
|
65609
|
+
return;
|
|
65610
|
+
}
|
|
65611
|
+
if (answer.status !== 200) {
|
|
65612
|
+
readRefused(opts, answer, wallet);
|
|
65613
|
+
return;
|
|
65614
|
+
}
|
|
65615
|
+
const machine = answer.json;
|
|
65616
|
+
if (jsonMode(opts)) {
|
|
65617
|
+
say(JSON.stringify({ ok: true, deployment: machine }, null, 2) + "\n");
|
|
65618
|
+
return;
|
|
65619
|
+
}
|
|
65620
|
+
say(`
|
|
65621
|
+
${machineLines(machine)}
|
|
65622
|
+
`);
|
|
65623
|
+
const invoices = Array.isArray(machine.invoices) ? machine.invoices.length : 0;
|
|
65624
|
+
if (invoices) say(` ${import_picocolors3.default.dim(`${invoices} payment${invoices === 1 ? "" : "s"} on record`)}
|
|
65625
|
+
`);
|
|
65626
|
+
if (machine.attestation) say(` ${import_picocolors3.default.dim("attestation: live (--json carries the quote)")}
|
|
65627
|
+
`);
|
|
65628
|
+
say("\n");
|
|
65629
|
+
}
|
|
65630
|
+
async function computeWait(id2, opts) {
|
|
65631
|
+
try {
|
|
65632
|
+
deploymentPath(id2);
|
|
65633
|
+
} catch (err) {
|
|
65634
|
+
fail(opts, err.message, "bad_input");
|
|
65635
|
+
return;
|
|
65636
|
+
}
|
|
65637
|
+
const wallet = await payingKey(opts);
|
|
65638
|
+
if (!wallet) return;
|
|
65639
|
+
await waitAndReport(opts, wallet, id2, {});
|
|
65640
|
+
}
|
|
65641
|
+
async function waitAndReport(opts, wallet, id2, extra) {
|
|
65642
|
+
let minutes;
|
|
65643
|
+
try {
|
|
65644
|
+
minutes = opts.timeout === void 0 ? 15 : positiveInt(opts.timeout, "--timeout");
|
|
65645
|
+
} catch (err) {
|
|
65646
|
+
fail(opts, err.message, "bad_input");
|
|
65647
|
+
return;
|
|
65648
|
+
}
|
|
65649
|
+
const path8 = deploymentPath(id2);
|
|
65650
|
+
let lastStatus = "";
|
|
65651
|
+
const started = Date.now();
|
|
65652
|
+
const outcome = await waitUntilRunning({
|
|
65653
|
+
read: () => ownerGet(wallet, path8),
|
|
65654
|
+
timeoutMs: minutes * 6e4,
|
|
65655
|
+
onTick: (m) => {
|
|
65656
|
+
if (jsonMode(opts) || m.status === lastStatus) return;
|
|
65657
|
+
lastStatus = m.status ?? "";
|
|
65658
|
+
say(` ${import_picocolors3.default.dim(`${lastStatus} \xB7 ${Math.round((Date.now() - started) / 1e3)} s`)}
|
|
65659
|
+
`);
|
|
65660
|
+
}
|
|
65661
|
+
});
|
|
65662
|
+
if (outcome.kind === "running") {
|
|
65663
|
+
emitMachine(opts, outcome.machine, { paid: extra.paid, note: "running", next: false });
|
|
65664
|
+
return;
|
|
65665
|
+
}
|
|
65666
|
+
if (outcome.kind === "refused") {
|
|
65667
|
+
readRefused(opts, outcome.answer, wallet, extra);
|
|
65668
|
+
return;
|
|
65669
|
+
}
|
|
65670
|
+
if (outcome.kind === "ended") {
|
|
65671
|
+
const m = outcome.machine;
|
|
65672
|
+
fail(opts, `the machine is ${m.status}${m.killReason ? ` (${m.killReason})` : ""}, and will not run by itself`, "not_running", { deployment: m, ...extra });
|
|
65673
|
+
return;
|
|
65674
|
+
}
|
|
65675
|
+
fail(
|
|
65676
|
+
opts,
|
|
65677
|
+
`still ${outcome.machine?.status ?? "unread"} after ${minutes} min; the clock starts only when it runs. Wait again: agentgates compute wait ${id2}`,
|
|
65678
|
+
"timeout",
|
|
65679
|
+
{ deployment: outcome.machine, ...extra }
|
|
65680
|
+
);
|
|
65681
|
+
}
|
|
65682
|
+
function statusWord(status4) {
|
|
65683
|
+
const s = status4 ?? "?";
|
|
65684
|
+
if (s === "running") return import_picocolors3.default.green(s);
|
|
65685
|
+
if (s === "provisioning" || s === "stopped") return import_picocolors3.default.yellow(s);
|
|
65686
|
+
if (s === "failed" || s === "destroyed" || s === "grace" || s === "suspended") return import_picocolors3.default.red(s);
|
|
65687
|
+
return s;
|
|
65688
|
+
}
|
|
65689
|
+
function inWords(iso) {
|
|
65690
|
+
if (!iso) return "";
|
|
65691
|
+
const ms = Date.parse(iso) - Date.now();
|
|
65692
|
+
if (!Number.isFinite(ms)) return "";
|
|
65693
|
+
const mins = Math.round(Math.abs(ms) / 6e4);
|
|
65694
|
+
const span = mins < 90 ? `${mins} min` : mins < 48 * 60 ? `${Math.round(mins / 60)} h` : `${Math.round(mins / 1440)} days`;
|
|
65695
|
+
return ms >= 0 ? `in ${span}` : `${span} ago`;
|
|
65696
|
+
}
|
|
65697
|
+
function machineLines(m) {
|
|
65698
|
+
const head = ` ${import_picocolors3.default.bold(m.deploymentId ?? "?")} ${statusWord(m.status)} ${import_picocolors3.default.dim(`${m.plan ?? ""}${m.name ? ` \xB7 ${m.name}` : ""}`)}`;
|
|
65699
|
+
const lines = [head];
|
|
65700
|
+
if (m.endpoint) lines.push(` endpoint ${import_picocolors3.default.cyan(m.endpoint)}`);
|
|
65701
|
+
if (m.expiresAt) lines.push(` paid to ${m.expiresAt} ${import_picocolors3.default.dim(inWords(m.expiresAt))}`);
|
|
65702
|
+
else if (m.status === "provisioning") lines.push(` ${import_picocolors3.default.dim("the clock starts when it runs")}`);
|
|
65703
|
+
if (m.killReason) lines.push(` ${import_picocolors3.default.dim(`ended: ${m.killReason}`)}`);
|
|
65704
|
+
if (m.verifyUrl) lines.push(` verify ${import_picocolors3.default.dim(`${computeOrigin()}${m.verifyUrl}`)}`);
|
|
65705
|
+
return lines.join("\n");
|
|
65706
|
+
}
|
|
65707
|
+
function emitMachine(opts, machine, extra) {
|
|
65708
|
+
if (jsonMode(opts)) {
|
|
65709
|
+
say(
|
|
65710
|
+
JSON.stringify(
|
|
65711
|
+
{ ok: true, deployment: machine, ...extra.paid ? { paid: extra.paid } : {}, ...extra.note ? { note: extra.note } : {} },
|
|
65712
|
+
null,
|
|
65713
|
+
2
|
|
65714
|
+
) + "\n"
|
|
65715
|
+
);
|
|
65716
|
+
return;
|
|
65717
|
+
}
|
|
65718
|
+
say(`
|
|
65719
|
+
${import_picocolors3.default.green("\u2713")} ${extra.note ?? (extra.paid ? `paid ${extra.paid.amountUsd} on ${extra.paid.network}` : "ready")}
|
|
65720
|
+
|
|
65721
|
+
`);
|
|
65722
|
+
say(`${machineLines(machine)}
|
|
65723
|
+
|
|
65724
|
+
`);
|
|
65725
|
+
if (extra.next && machine.deploymentId && machine.status !== "running") {
|
|
65726
|
+
say(` ${import_picocolors3.default.dim(`wait for it: agentgates compute wait ${machine.deploymentId}`)}
|
|
65727
|
+
|
|
65728
|
+
`);
|
|
65729
|
+
}
|
|
65730
|
+
}
|
|
65731
|
+
|
|
65175
65732
|
// src/commands/inference.ts
|
|
65733
|
+
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
65734
|
+
init_passwords_wire();
|
|
65176
65735
|
init_constants();
|
|
65177
|
-
var
|
|
65736
|
+
var SITE = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
|
|
65178
65737
|
function applyFilters(models, f2) {
|
|
65179
65738
|
let out = models;
|
|
65180
65739
|
if (f2.tier === "confidential") out = out.filter((m) => m.confidential);
|
|
@@ -65190,7 +65749,7 @@ function applyFilters(models, f2) {
|
|
|
65190
65749
|
var hasFilters = (f2) => Boolean(f2.tier || (f2.tag ?? []).length || f2.org || f2.search);
|
|
65191
65750
|
var ctx = (n2) => n2 >= 1e6 ? `${Math.round(n2 / 1e6)}M` : `${Math.round(n2 / 1e3)}k`;
|
|
65192
65751
|
async function inferenceModels(opts) {
|
|
65193
|
-
const res = await fetch(`${
|
|
65752
|
+
const res = await fetch(`${SITE}/api/inference/catalog`, { headers: { accept: "application/json" } });
|
|
65194
65753
|
if (!res.ok) throw new Error(`inference catalog: HTTP ${res.status}`);
|
|
65195
65754
|
const body = await res.json();
|
|
65196
65755
|
const all = body.models ?? [];
|
|
@@ -65371,8 +65930,8 @@ async function inferenceTopUp(amountUsd, opts = {}) {
|
|
|
65371
65930
|
}
|
|
65372
65931
|
const choice = await chooseLeg(quote.json, wallet.address);
|
|
65373
65932
|
if (!choice.ok) {
|
|
65374
|
-
const need2 = choice.needMicro === null ? null :
|
|
65375
|
-
const held3 = choice.bestHeldMicro === null ? null :
|
|
65933
|
+
const need2 = choice.needMicro === null ? null : usd(choice.needMicro);
|
|
65934
|
+
const held3 = choice.bestHeldMicro === null ? null : usd(choice.bestHeldMicro);
|
|
65376
65935
|
const sentence = need2 && held3 ? `${choice.reason}. The top-up costs ${need2} and this key holds ${held3}. Send USDC to ${wallet.address} on base, polygon or arbitrum` : choice.reason;
|
|
65377
65936
|
process.stdout.write(opts.json ? `${JSON.stringify({ ok: false, error: sentence })}
|
|
65378
65937
|
` : `
|
|
@@ -65382,7 +65941,7 @@ async function inferenceTopUp(amountUsd, opts = {}) {
|
|
|
65382
65941
|
return;
|
|
65383
65942
|
}
|
|
65384
65943
|
if (!opts.json) process.stdout.write(`
|
|
65385
|
-
${import_picocolors4.default.dim(`paying ${
|
|
65944
|
+
${import_picocolors4.default.dim(`paying ${usd(choice.leg.amountMicro)} on ${choice.leg.network}`)}
|
|
65386
65945
|
`);
|
|
65387
65946
|
const signed2 = await signLeg(choice.leg, wallet.privateKey);
|
|
65388
65947
|
const paid = await post3(signed2.header);
|
|
@@ -65432,7 +65991,7 @@ async function inferenceAsk(words7, opts = {}) {
|
|
|
65432
65991
|
};
|
|
65433
65992
|
const quote = await post3(null);
|
|
65434
65993
|
if (quote.status === 200) {
|
|
65435
|
-
|
|
65994
|
+
say2(opts, quote.json);
|
|
65436
65995
|
return;
|
|
65437
65996
|
}
|
|
65438
65997
|
if (quote.status !== 402) {
|
|
@@ -65447,8 +66006,8 @@ async function inferenceAsk(words7, opts = {}) {
|
|
|
65447
66006
|
}
|
|
65448
66007
|
const choice = await chooseLeg(quote.json, wallet.address);
|
|
65449
66008
|
if (!choice.ok) {
|
|
65450
|
-
const need2 = choice.needMicro === null ? null :
|
|
65451
|
-
const held3 = choice.bestHeldMicro === null ? null :
|
|
66009
|
+
const need2 = choice.needMicro === null ? null : usd(choice.needMicro);
|
|
66010
|
+
const held3 = choice.bestHeldMicro === null ? null : usd(choice.bestHeldMicro);
|
|
65452
66011
|
const sentence = need2 && held3 ? `${choice.reason}. The ask costs ${need2} and this key holds ${held3}. Send USDC to ${wallet.address} on base, polygon or arbitrum and it pays for itself` : choice.reason;
|
|
65453
66012
|
process.stdout.write(
|
|
65454
66013
|
opts.json ? `${JSON.stringify({ ok: false, error: sentence })}
|
|
@@ -65460,7 +66019,7 @@ async function inferenceAsk(words7, opts = {}) {
|
|
|
65460
66019
|
return;
|
|
65461
66020
|
}
|
|
65462
66021
|
if (!opts.json) process.stdout.write(`
|
|
65463
|
-
${import_picocolors4.default.dim(`paying ${
|
|
66022
|
+
${import_picocolors4.default.dim(`paying ${usd(choice.leg.amountMicro)} on ${choice.leg.network}`)}
|
|
65464
66023
|
`);
|
|
65465
66024
|
const signed2 = await signLeg(choice.leg, wallet.privateKey);
|
|
65466
66025
|
const paid = await post3(signed2.header);
|
|
@@ -65475,9 +66034,9 @@ async function inferenceAsk(words7, opts = {}) {
|
|
|
65475
66034
|
);
|
|
65476
66035
|
return;
|
|
65477
66036
|
}
|
|
65478
|
-
|
|
66037
|
+
say2(opts, paid.json);
|
|
65479
66038
|
}
|
|
65480
|
-
function
|
|
66039
|
+
function say2(opts, answer) {
|
|
65481
66040
|
if (opts.json || !process.stdout.isTTY) {
|
|
65482
66041
|
process.stdout.write(`${JSON.stringify(answer)}
|
|
65483
66042
|
`);
|
|
@@ -68109,7 +68668,7 @@ function eddsa(Point2, cHash, eddsaOpts = {}) {
|
|
|
68109
68668
|
});
|
|
68110
68669
|
const { prehash } = eddsaOpts;
|
|
68111
68670
|
const { BASE, Fp: Fp3, Fn: Fn2 } = Point2;
|
|
68112
|
-
const
|
|
68671
|
+
const randomBytes10 = eddsaOpts.randomBytes || randomBytes6;
|
|
68113
68672
|
const adjustScalarBytes2 = eddsaOpts.adjustScalarBytes || ((bytes2) => bytes2);
|
|
68114
68673
|
const domain = eddsaOpts.domain || ((data4, ctx2, phflag) => {
|
|
68115
68674
|
_abool2(phflag, "phflag");
|
|
@@ -68191,7 +68750,7 @@ function eddsa(Point2, cHash, eddsaOpts = {}) {
|
|
|
68191
68750
|
signature: 2 * _size,
|
|
68192
68751
|
seed: _size
|
|
68193
68752
|
};
|
|
68194
|
-
function randomSecretKey(seed =
|
|
68753
|
+
function randomSecretKey(seed = randomBytes10(lengths.seed)) {
|
|
68195
68754
|
return _abytes2(seed, lengths.seed, "seed");
|
|
68196
68755
|
}
|
|
68197
68756
|
function keygen(seed) {
|
|
@@ -69034,14 +69593,18 @@ function codeFrom(text, pattern) {
|
|
|
69034
69593
|
return null;
|
|
69035
69594
|
}
|
|
69036
69595
|
}
|
|
69037
|
-
const
|
|
69596
|
+
const words7 = withoutLinks(haystack);
|
|
69597
|
+
const labeled = words7.split(/\r?\n/).filter((line2) => /\b(code|verification|verify|otp|pin|passcode|one[- ]time)\b/i.test(line2));
|
|
69038
69598
|
for (const line2 of labeled) {
|
|
69039
69599
|
const m = line2.match(/\b\d{4,8}\b/);
|
|
69040
69600
|
if (m) return m[0];
|
|
69041
69601
|
}
|
|
69042
|
-
const anywhere =
|
|
69602
|
+
const anywhere = words7.match(/\b\d{4,8}\b/);
|
|
69043
69603
|
return anywhere ? anywhere[0] : null;
|
|
69044
69604
|
}
|
|
69605
|
+
function withoutLinks(text) {
|
|
69606
|
+
return text.replace(/https?:\/\/[^\s"'<>]+/g, " ");
|
|
69607
|
+
}
|
|
69045
69608
|
|
|
69046
69609
|
// src/lib/seal-grants.ts
|
|
69047
69610
|
init_passwords_wire();
|
|
@@ -69236,12 +69799,12 @@ async function payphoneCall(args) {
|
|
|
69236
69799
|
}
|
|
69237
69800
|
const choice = await chooseLeg(quote.json, args.address);
|
|
69238
69801
|
if (!choice.ok) {
|
|
69239
|
-
const need2 = choice.needMicro === null ? null :
|
|
69240
|
-
const held3 = choice.bestHeldMicro === null ? null :
|
|
69802
|
+
const need2 = choice.needMicro === null ? null : usd(choice.needMicro);
|
|
69803
|
+
const held3 = choice.bestHeldMicro === null ? null : usd(choice.bestHeldMicro);
|
|
69241
69804
|
const shortfall = need2 && held3 ? `${choice.reason}. The window costs ${need2} and this key holds ${held3}. Send USDC to ${args.address} on base, polygon or arbitrum and it pays for itself` : need2 ? `${choice.reason}. The window costs ${need2}` : choice.reason;
|
|
69242
69805
|
throw new WireError(402, "payphone_unfunded", shortfall, quote.json);
|
|
69243
69806
|
}
|
|
69244
|
-
args.onQuote?.(`paying ${
|
|
69807
|
+
args.onQuote?.(`paying ${usd(choice.leg.amountMicro)} on ${choice.leg.network}`);
|
|
69245
69808
|
const signed2 = await signLeg(choice.leg, args.privateKey);
|
|
69246
69809
|
let paid = await post(body, signed2.header, 18e4);
|
|
69247
69810
|
if (paid.status >= 400) {
|
|
@@ -69278,17 +69841,17 @@ async function payphoneRead(payment, asked, what) {
|
|
|
69278
69841
|
}
|
|
69279
69842
|
|
|
69280
69843
|
// src/commands/phone.ts
|
|
69281
|
-
var
|
|
69282
|
-
var
|
|
69844
|
+
var SITE2 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
|
|
69845
|
+
var jsonMode2 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
69283
69846
|
function emit2(opts, data4, human) {
|
|
69284
|
-
if (
|
|
69847
|
+
if (jsonMode2(opts)) {
|
|
69285
69848
|
process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
|
|
69286
69849
|
return;
|
|
69287
69850
|
}
|
|
69288
69851
|
human();
|
|
69289
69852
|
}
|
|
69290
69853
|
function refuse(opts, error, code, extra = {}) {
|
|
69291
|
-
if (
|
|
69854
|
+
if (jsonMode2(opts)) {
|
|
69292
69855
|
process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
|
|
69293
69856
|
} else {
|
|
69294
69857
|
process.stderr.write(` ${error}${code ? import_picocolors5.default.dim(` (${code})`) : ""}
|
|
@@ -69300,7 +69863,7 @@ function failFrom(opts, err) {
|
|
|
69300
69863
|
if (err instanceof WireError) return refuse(opts, err.message, err.code, { status: err.status });
|
|
69301
69864
|
return refuse(opts, err.message ?? String(err), null);
|
|
69302
69865
|
}
|
|
69303
|
-
var
|
|
69866
|
+
var usd2 = (v) => {
|
|
69304
69867
|
const n2 = Number(v);
|
|
69305
69868
|
if (Number.isInteger(n2)) return `$${n2}`;
|
|
69306
69869
|
const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
|
|
@@ -69331,7 +69894,7 @@ function phoneSlice(body) {
|
|
|
69331
69894
|
return out;
|
|
69332
69895
|
}
|
|
69333
69896
|
async function phonePricing(opts) {
|
|
69334
|
-
const res = await fetch(`${
|
|
69897
|
+
const res = await fetch(`${SITE2}/api/account/catalog`, { headers: { accept: "application/json" } });
|
|
69335
69898
|
if (!res.ok) throw new Error(`phone catalog: HTTP ${res.status}`);
|
|
69336
69899
|
const body = await res.json();
|
|
69337
69900
|
const slice = phoneSlice(body);
|
|
@@ -69352,7 +69915,7 @@ async function phonePricing(opts) {
|
|
|
69352
69915
|
`);
|
|
69353
69916
|
for (const p of plans) {
|
|
69354
69917
|
const count = p.phones ?? 1;
|
|
69355
|
-
const price =
|
|
69918
|
+
const price = usd2(p.priceUsd).padStart(4);
|
|
69356
69919
|
const term = `/${p.units} days`.padEnd(9);
|
|
69357
69920
|
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"}`)}
|
|
69358
69921
|
`);
|
|
@@ -69362,9 +69925,9 @@ async function phonePricing(opts) {
|
|
|
69362
69925
|
const u = slice.phoneUsage;
|
|
69363
69926
|
if (u) {
|
|
69364
69927
|
const meter = [
|
|
69365
|
-
u.textUsd ? `text ${
|
|
69366
|
-
u.minuteUsd ? `call minute ${
|
|
69367
|
-
u.waitCodeUsd !== void 0 ? `wait-code ${Number(u.waitCodeUsd) === 0 ? "free" :
|
|
69928
|
+
u.textUsd ? `text ${usd2(u.textUsd)}` : "",
|
|
69929
|
+
u.minuteUsd ? `call minute ${usd2(u.minuteUsd)}` : "",
|
|
69930
|
+
u.waitCodeUsd !== void 0 ? `wait-code ${Number(u.waitCodeUsd) === 0 ? "free" : usd2(u.waitCodeUsd)}` : ""
|
|
69368
69931
|
].filter(Boolean).join(" \xB7 ");
|
|
69369
69932
|
process.stdout.write(`
|
|
69370
69933
|
${import_picocolors5.default.dim(`usage, from the prepaid balance: ${meter}`)}
|
|
@@ -69378,7 +69941,7 @@ async function phonePricing(opts) {
|
|
|
69378
69941
|
${import_picocolors5.default.bold("THE OPERATOR")} ${import_picocolors5.default.dim("our brain, voice and ears on the line; the transcript and the outcome back")}
|
|
69379
69942
|
|
|
69380
69943
|
`);
|
|
69381
|
-
process.stdout.write(` ${import_picocolors5.default.cyan(
|
|
69944
|
+
process.stdout.write(` ${import_picocolors5.default.cyan(usd2(op.minuteUsd))} ${import_picocolors5.default.dim(`a minute, all in, ${op.minutes ?? op.maxMinutes ?? "?"} minutes a call by default (--minutes up to ${op.maxMinutes ?? "?"}), from the prepaid balance`)}
|
|
69382
69945
|
`);
|
|
69383
69946
|
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>"')}
|
|
69384
69947
|
`);
|
|
@@ -69396,7 +69959,7 @@ async function phonePricing(opts) {
|
|
|
69396
69959
|
${import_picocolors5.default.bold("PAYPHONE")} ${import_picocolors5.default.dim("no plan, no number, no account: one x402 payment, one call")}
|
|
69397
69960
|
|
|
69398
69961
|
`);
|
|
69399
|
-
const ladder = windows.map((w) => `${w.minutes} min ${
|
|
69962
|
+
const ladder = windows.map((w) => `${w.minutes} min ${usd2(w.priceUsd)}${w.operatorPriceUsd ? import_picocolors5.default.dim(` (${usd2(w.operatorPriceUsd)} with the operator)`) : ""}`).join(" ");
|
|
69400
69963
|
process.stdout.write(` ${ladder}
|
|
69401
69964
|
`);
|
|
69402
69965
|
}
|
|
@@ -69420,9 +69983,9 @@ function printCall(c, from, perMinuteUsd, full, key = null) {
|
|
|
69420
69983
|
const { task, lines, shut } = openedCall(c, key);
|
|
69421
69984
|
if (task) process.stdout.write(` ${task}
|
|
69422
69985
|
`);
|
|
69423
|
-
if (perMinuteUsd) process.stdout.write(` ${import_picocolors5.default.dim(`${
|
|
69986
|
+
if (perMinuteUsd) process.stdout.write(` ${import_picocolors5.default.dim(`${usd2(perMinuteUsd)} a minute, from the balance`)}
|
|
69424
69987
|
`);
|
|
69425
|
-
if (c.billedUsd) process.stdout.write(` ${import_picocolors5.default.dim(`billed ${
|
|
69988
|
+
if (c.billedUsd) process.stdout.write(` ${import_picocolors5.default.dim(`billed ${usd2(c.billedUsd)}`)}
|
|
69426
69989
|
`);
|
|
69427
69990
|
if (shut) process.stdout.write(` ${import_picocolors5.default.dim("sealed: this key does not open it (agentgates email seal-status)")}
|
|
69428
69991
|
`);
|
|
@@ -69480,12 +70043,12 @@ async function walkUpToThePayphone(opts, args) {
|
|
|
69480
70043
|
voice: opts.voice ?? null,
|
|
69481
70044
|
greeting: opts.greeting ?? null,
|
|
69482
70045
|
onQuote: (note2) => {
|
|
69483
|
-
if (!
|
|
70046
|
+
if (!jsonMode2(opts)) process.stderr.write(` ${import_picocolors5.default.dim(note2)}
|
|
69484
70047
|
`);
|
|
69485
70048
|
}
|
|
69486
70049
|
});
|
|
69487
70050
|
const placed = walk.call;
|
|
69488
|
-
const paid =
|
|
70051
|
+
const paid = usd(walk.paidMicro);
|
|
69489
70052
|
const render = (row2, full) => {
|
|
69490
70053
|
printCall(row2, "the payphone", null, full);
|
|
69491
70054
|
process.stdout.write(` ${import_picocolors5.default.dim(`${paid} paid on ${walk.network} for ${window2} ${window2 === 1 ? "minute" : "minutes"}, nothing held`)}
|
|
@@ -69511,7 +70074,7 @@ async function walkUpToThePayphone(opts, args) {
|
|
|
69511
70074
|
} catch {
|
|
69512
70075
|
break;
|
|
69513
70076
|
}
|
|
69514
|
-
if (!
|
|
70077
|
+
if (!jsonMode2(opts) && row?.status && row.status !== last) {
|
|
69515
70078
|
last = row.status;
|
|
69516
70079
|
process.stderr.write(` ${import_picocolors5.default.dim(STATUS_WORD[row.status] ?? row.status)}
|
|
69517
70080
|
`);
|
|
@@ -69566,7 +70129,7 @@ async function phoneCall(toRaw, words7, opts) {
|
|
|
69566
70129
|
} catch (err) {
|
|
69567
70130
|
const empty2 = err instanceof WireError && (err.code === "balance_empty" || err.status === 402);
|
|
69568
70131
|
if (!empty2 || brain === "yours" || opts.webhook) throw err;
|
|
69569
|
-
if (!
|
|
70132
|
+
if (!jsonMode2(opts)) process.stderr.write(` ${import_picocolors5.default.dim("this account holds no balance; walking up to the payphone instead")}
|
|
69570
70133
|
`);
|
|
69571
70134
|
return await walkUpToThePayphone(opts, {
|
|
69572
70135
|
to,
|
|
@@ -69593,7 +70156,7 @@ async function phoneCall(toRaw, words7, opts) {
|
|
|
69593
70156
|
const ended = await waitForCall(keys2.wallet, phoneId, placed.callId, {
|
|
69594
70157
|
maxSeconds,
|
|
69595
70158
|
onTick: (c) => {
|
|
69596
|
-
if (
|
|
70159
|
+
if (jsonMode2(opts) || c.status === last) return;
|
|
69597
70160
|
last = c.status;
|
|
69598
70161
|
process.stderr.write(` ${import_picocolors5.default.dim(STATUS_WORD[c.status] ?? c.status)}
|
|
69599
70162
|
`);
|
|
@@ -69747,6 +70310,50 @@ var import_picocolors6 = __toESM(require_picocolors(), 1);
|
|
|
69747
70310
|
|
|
69748
70311
|
// src/lib/inbox-wire.ts
|
|
69749
70312
|
init_passwords_wire();
|
|
70313
|
+
|
|
70314
|
+
// src/lib/press-mail.ts
|
|
70315
|
+
function pressLinkAllowed(link, site) {
|
|
70316
|
+
if (typeof link !== "string" || link.length > 4096) return false;
|
|
70317
|
+
let url;
|
|
70318
|
+
try {
|
|
70319
|
+
url = new URL(link);
|
|
70320
|
+
} catch {
|
|
70321
|
+
return false;
|
|
70322
|
+
}
|
|
70323
|
+
if (url.protocol !== "https:" || url.username || url.password) return false;
|
|
70324
|
+
const host2 = url.hostname.toLowerCase();
|
|
70325
|
+
const bare = site.toLowerCase().replace(/^www\./, "");
|
|
70326
|
+
return host2 === bare || host2.endsWith(`.${bare}`);
|
|
70327
|
+
}
|
|
70328
|
+
function pressSenderAllowed(fromAddr, site, mailers = []) {
|
|
70329
|
+
const domain = (fromAddr.split("@").pop() ?? "").trim().toLowerCase().replace(/>$/, "");
|
|
70330
|
+
const bare = site.toLowerCase().replace(/^www\./, "");
|
|
70331
|
+
if (domain === bare || domain.endsWith(`.${bare}`)) return true;
|
|
70332
|
+
return mailers.map((m) => m.toLowerCase()).some((m) => domain === m || domain.endsWith(`.${m}`));
|
|
70333
|
+
}
|
|
70334
|
+
var LABELED_LINE_RE = /\b(code|verification|verify|otp|pin|passcode|one[- ]time)\b/i;
|
|
70335
|
+
function pressMailOf(mail, site) {
|
|
70336
|
+
const text = `${mail.subject ?? ""}
|
|
70337
|
+
${mail.text ?? ""}`.slice(0, 8e3).replace(/https?:\/\/[^\s"'<>]+/g, " ");
|
|
70338
|
+
let code = null;
|
|
70339
|
+
for (const line2 of text.split(/\r?\n/)) {
|
|
70340
|
+
if (!LABELED_LINE_RE.test(line2)) continue;
|
|
70341
|
+
const m = line2.match(/\b\d{4,8}\b/);
|
|
70342
|
+
if (m) {
|
|
70343
|
+
code = m[0];
|
|
70344
|
+
break;
|
|
70345
|
+
}
|
|
70346
|
+
}
|
|
70347
|
+
code = code ?? text.match(/\b\d{6}\b/)?.[0] ?? text.match(/\b\d{4,8}\b/)?.[0] ?? null;
|
|
70348
|
+
const blob = `${mail.text ?? ""}
|
|
70349
|
+
${mail.html ?? ""}`.slice(0, 2e5).replace(/&/g, "&");
|
|
70350
|
+
const links = [...blob.matchAll(/https:\/\/[^\s"'<>)\]]+/g)].map((m) => m[0].replace(/[.,;:!?]+$/, "")).filter((l) => pressLinkAllowed(l, site));
|
|
70351
|
+
const withToken = links.find((l) => /[?&](token|verificationToken)=/i.test(l));
|
|
70352
|
+
const pathLike = links.find((l) => /\/(login|signup|sign-up|verify|verification|confirm|otp|auth|magic)/i.test(new URL(l).pathname));
|
|
70353
|
+
return { code, link: withToken ?? pathLike ?? null };
|
|
70354
|
+
}
|
|
70355
|
+
|
|
70356
|
+
// src/lib/inbox-wire.ts
|
|
69750
70357
|
async function leaseInbox(wallet, args = {}) {
|
|
69751
70358
|
const body = {};
|
|
69752
70359
|
if (args.name) body.name = args.name;
|
|
@@ -69814,6 +70421,42 @@ ${opened.text}`, pattern);
|
|
|
69814
70421
|
}
|
|
69815
70422
|
}
|
|
69816
70423
|
}
|
|
70424
|
+
async function waitSiteMail(wallet, inboxId, { site, mailers = [], since, timeoutSeconds = 60 }) {
|
|
70425
|
+
const deadline = Date.now() + timeoutSeconds * 1e3;
|
|
70426
|
+
let after = since;
|
|
70427
|
+
let key = null;
|
|
70428
|
+
for (; ; ) {
|
|
70429
|
+
const remaining = Math.max(1, Math.ceil((deadline - Date.now()) / 1e3));
|
|
70430
|
+
const body = { timeoutSeconds: remaining };
|
|
70431
|
+
if (after) body.since = after;
|
|
70432
|
+
let out;
|
|
70433
|
+
try {
|
|
70434
|
+
out = expectOk(await signedFetch(wallet, "POST", lanePath(`/inboxes/${encodeURIComponent(inboxId)}/wait-code`), body, (remaining + 30) * 1e3), "the site's mail");
|
|
70435
|
+
} catch (err) {
|
|
70436
|
+
if (err instanceof WireError && err.status === 408) return null;
|
|
70437
|
+
throw err;
|
|
70438
|
+
}
|
|
70439
|
+
if (!out.sealed) return null;
|
|
70440
|
+
const rows = Array.isArray(out.messages) ? out.messages : [];
|
|
70441
|
+
key = key ?? await mailKeyFor(wallet);
|
|
70442
|
+
if (!key) throw new Error("this inbox is sealed and this account has no mail key registered");
|
|
70443
|
+
for (const row of rows) {
|
|
70444
|
+
if (row.direction === "out") continue;
|
|
70445
|
+
let opened;
|
|
70446
|
+
try {
|
|
70447
|
+
opened = openMessage(key, inboxId, row);
|
|
70448
|
+
} catch {
|
|
70449
|
+
continue;
|
|
70450
|
+
}
|
|
70451
|
+
if (!pressSenderAllowed(opened.from, site, mailers)) continue;
|
|
70452
|
+
const found = pressMailOf(opened, site);
|
|
70453
|
+
if (found.code || found.link) return { ...found, from: opened.from, receivedAt: opened.receivedAt };
|
|
70454
|
+
}
|
|
70455
|
+
const newest = rows.map((r) => r.receivedAt).filter(Boolean).sort().pop();
|
|
70456
|
+
if (newest) after = new Date(new Date(newest).getTime() + 1).toISOString();
|
|
70457
|
+
if (Date.now() >= deadline) return null;
|
|
70458
|
+
}
|
|
70459
|
+
}
|
|
69817
70460
|
async function inboxDomain() {
|
|
69818
70461
|
let res;
|
|
69819
70462
|
try {
|
|
@@ -69829,8 +70472,8 @@ async function inboxDomain() {
|
|
|
69829
70472
|
|
|
69830
70473
|
// src/commands/email.ts
|
|
69831
70474
|
init_passwords_wire();
|
|
69832
|
-
var
|
|
69833
|
-
var
|
|
70475
|
+
var SITE3 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
|
|
70476
|
+
var usd3 = (v) => {
|
|
69834
70477
|
const n2 = Number(v);
|
|
69835
70478
|
if (Number.isInteger(n2)) return `$${n2}`;
|
|
69836
70479
|
const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
|
|
@@ -69853,7 +70496,7 @@ function emailSlice(body) {
|
|
|
69853
70496
|
return out;
|
|
69854
70497
|
}
|
|
69855
70498
|
async function emailPricing(opts) {
|
|
69856
|
-
const res = await fetch(`${
|
|
70499
|
+
const res = await fetch(`${SITE3}/api/account/catalog`, { headers: { accept: "application/json" } });
|
|
69857
70500
|
if (!res.ok) throw new Error(`email catalog: HTTP ${res.status}`);
|
|
69858
70501
|
const body = await res.json();
|
|
69859
70502
|
const slice = emailSlice(body);
|
|
@@ -69894,7 +70537,7 @@ async function emailPricing(opts) {
|
|
|
69894
70537
|
}
|
|
69895
70538
|
for (const f2 of families) {
|
|
69896
70539
|
const rows = byFamily.get(f2).sort((a, b2) => a.units - b2.units);
|
|
69897
|
-
const cells = rows.map((p) => `${import_picocolors6.default.cyan(
|
|
70540
|
+
const cells = rows.map((p) => `${import_picocolors6.default.cyan(usd3(p.priceUsd).padStart(4))}${import_picocolors6.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
|
|
69898
70541
|
const lead = rows[0];
|
|
69899
70542
|
const cap = [
|
|
69900
70543
|
lead.inboxes ? `${lead.inboxes} inbox${lead.inboxes === 1 ? "" : "es"}` : "",
|
|
@@ -69908,8 +70551,8 @@ async function emailPricing(opts) {
|
|
|
69908
70551
|
const send2 = slice.sendOverflow?.priceUsd;
|
|
69909
70552
|
const wait2 = body.phoneUsage?.waitCodeUsd;
|
|
69910
70553
|
const meter = [
|
|
69911
|
-
send2 ? `send ${
|
|
69912
|
-
wait2 !== void 0 ? `wait-code ${Number(wait2) === 0 ? "free" :
|
|
70554
|
+
send2 ? `send ${usd3(send2)}` : "",
|
|
70555
|
+
wait2 !== void 0 ? `wait-code ${Number(wait2) === 0 ? "free" : usd3(wait2)}` : ""
|
|
69913
70556
|
].filter(Boolean).join(" \xB7 ");
|
|
69914
70557
|
if (meter) process.stdout.write(`
|
|
69915
70558
|
${import_picocolors6.default.dim(`usage, from the prepaid balance: ${meter}`)}
|
|
@@ -69919,7 +70562,7 @@ async function emailPricing(opts) {
|
|
|
69919
70562
|
const bal = slice.balance;
|
|
69920
70563
|
if (bal?.note) process.stdout.write(` ${import_picocolors6.default.dim(bal.note)}
|
|
69921
70564
|
`);
|
|
69922
|
-
else if (bal?.minTopUpUsd) process.stdout.write(` ${import_picocolors6.default.dim(`top up any amount from ${
|
|
70565
|
+
else if (bal?.minTopUpUsd) process.stdout.write(` ${import_picocolors6.default.dim(`top up any amount from ${usd3(bal.minTopUpUsd)}`)}
|
|
69923
70566
|
`);
|
|
69924
70567
|
const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
|
|
69925
70568
|
if (nets.length) process.stdout.write(`
|
|
@@ -69932,7 +70575,7 @@ function emailDoor(first) {
|
|
|
69932
70575
|
process.stdout.write(
|
|
69933
70576
|
`
|
|
69934
70577
|
${first}, and this CLI has no signer yet.
|
|
69935
|
-
Do it from the wallet, one biometric: ${import_picocolors6.default.cyan(`${
|
|
70578
|
+
Do it from the wallet, one biometric: ${import_picocolors6.default.cyan(`${SITE3}/email`)}
|
|
69936
70579
|
Prices from here: ${import_picocolors6.default.dim("agentgates email pricing")}
|
|
69937
70580
|
|
|
69938
70581
|
`
|
|
@@ -70093,7 +70736,7 @@ function emit3(opts, data4, human) {
|
|
|
70093
70736
|
}
|
|
70094
70737
|
human();
|
|
70095
70738
|
}
|
|
70096
|
-
function
|
|
70739
|
+
function fail2(opts, err) {
|
|
70097
70740
|
const message = err instanceof Error ? err.message : String(err);
|
|
70098
70741
|
const code = err?.code;
|
|
70099
70742
|
if (opts.json || !process.stdout.isTTY) {
|
|
@@ -70151,7 +70794,7 @@ async function keysList(opts) {
|
|
|
70151
70794
|
const rows = await listLoginKeys(keys2.wallet);
|
|
70152
70795
|
emit3(opts, { ok: true, address: keys2.state.address, keys: rows, thisMachine: keys2.state.apiKeyPrefix ?? null }, () => printRows(rows, keys2.state.apiKeyPrefix ?? null));
|
|
70153
70796
|
} catch (err) {
|
|
70154
|
-
|
|
70797
|
+
fail2(opts, err);
|
|
70155
70798
|
}
|
|
70156
70799
|
}
|
|
70157
70800
|
async function keysCreate(opts) {
|
|
@@ -70199,7 +70842,7 @@ async function keysCreate(opts) {
|
|
|
70199
70842
|
);
|
|
70200
70843
|
});
|
|
70201
70844
|
} catch (err) {
|
|
70202
|
-
|
|
70845
|
+
fail2(opts, err);
|
|
70203
70846
|
}
|
|
70204
70847
|
}
|
|
70205
70848
|
async function keysFolders(id2, args, opts) {
|
|
@@ -70226,7 +70869,7 @@ async function keysFolders(id2, args, opts) {
|
|
|
70226
70869
|
`);
|
|
70227
70870
|
});
|
|
70228
70871
|
} catch (err) {
|
|
70229
|
-
|
|
70872
|
+
fail2(opts, err);
|
|
70230
70873
|
}
|
|
70231
70874
|
}
|
|
70232
70875
|
async function keysRevoke(id2, opts) {
|
|
@@ -70244,7 +70887,7 @@ async function keysRevoke(id2, opts) {
|
|
|
70244
70887
|
printRows(out.keys, wasMine ? null : keys2.state.apiKeyPrefix ?? null);
|
|
70245
70888
|
});
|
|
70246
70889
|
} catch (err) {
|
|
70247
|
-
|
|
70890
|
+
fail2(opts, err);
|
|
70248
70891
|
}
|
|
70249
70892
|
}
|
|
70250
70893
|
async function adoptKey(secret, name) {
|
|
@@ -70276,7 +70919,7 @@ async function keysUse(secret, opts) {
|
|
|
70276
70919
|
);
|
|
70277
70920
|
});
|
|
70278
70921
|
} catch (err) {
|
|
70279
|
-
|
|
70922
|
+
fail2(opts, err);
|
|
70280
70923
|
}
|
|
70281
70924
|
}
|
|
70282
70925
|
|
|
@@ -70405,11 +71048,11 @@ async function serveWordsOnce(args) {
|
|
|
70405
71048
|
let port = 0;
|
|
70406
71049
|
let done = () => {
|
|
70407
71050
|
};
|
|
70408
|
-
let
|
|
71051
|
+
let fail11 = () => {
|
|
70409
71052
|
};
|
|
70410
71053
|
const settled = new Promise((resolve3, reject) => {
|
|
70411
71054
|
done = resolve3;
|
|
70412
|
-
|
|
71055
|
+
fail11 = reject;
|
|
70413
71056
|
});
|
|
70414
71057
|
const server = createServer((req, res) => {
|
|
70415
71058
|
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
@@ -70435,7 +71078,7 @@ async function serveWordsOnce(args) {
|
|
|
70435
71078
|
const timer = setTimeout(() => {
|
|
70436
71079
|
if (!taken) {
|
|
70437
71080
|
server.close();
|
|
70438
|
-
|
|
71081
|
+
fail11(new Error(`nobody took the session in ${Math.round(args.waitMs / 1e3)}s`));
|
|
70439
71082
|
}
|
|
70440
71083
|
}, args.waitMs);
|
|
70441
71084
|
try {
|
|
@@ -70449,11 +71092,11 @@ async function receiveKeyOnce(args) {
|
|
|
70449
71092
|
let taken = false;
|
|
70450
71093
|
let done = () => {
|
|
70451
71094
|
};
|
|
70452
|
-
let
|
|
71095
|
+
let fail11 = () => {
|
|
70453
71096
|
};
|
|
70454
71097
|
const settled = new Promise((resolve3, reject) => {
|
|
70455
71098
|
done = resolve3;
|
|
70456
|
-
|
|
71099
|
+
fail11 = reject;
|
|
70457
71100
|
});
|
|
70458
71101
|
const server = createServer(async (req, res) => {
|
|
70459
71102
|
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
@@ -70483,7 +71126,7 @@ async function receiveKeyOnce(args) {
|
|
|
70483
71126
|
const timer = setTimeout(() => {
|
|
70484
71127
|
if (!taken) {
|
|
70485
71128
|
server.close();
|
|
70486
|
-
|
|
71129
|
+
fail11(new Error(`nobody handed a session over in ${Math.round(args.waitMs / 1e3)}s`));
|
|
70487
71130
|
}
|
|
70488
71131
|
}, args.waitMs);
|
|
70489
71132
|
try {
|
|
@@ -70498,9 +71141,9 @@ function handoffCode(code, port) {
|
|
|
70498
71141
|
|
|
70499
71142
|
// src/commands/session.ts
|
|
70500
71143
|
init_passwords_wire();
|
|
70501
|
-
var
|
|
71144
|
+
var jsonMode3 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
70502
71145
|
function refuse2(opts, error, code = null) {
|
|
70503
|
-
if (
|
|
71146
|
+
if (jsonMode3(opts)) process.stdout.write(JSON.stringify({ ok: false, code, error }, null, 2) + "\n");
|
|
70504
71147
|
else process.stderr.write(` ${error}${code ? import_picocolors8.default.dim(` (${code})`) : ""}
|
|
70505
71148
|
`);
|
|
70506
71149
|
process.exit(1);
|
|
@@ -70529,7 +71172,7 @@ async function sessionOpen(opts) {
|
|
|
70529
71172
|
address,
|
|
70530
71173
|
waitMs,
|
|
70531
71174
|
onUrl: (url, port) => {
|
|
70532
|
-
if (
|
|
71175
|
+
if (jsonMode3(opts)) {
|
|
70533
71176
|
process.stdout.write(JSON.stringify({ ok: true, status: "waiting", url, port, address, waitSeconds: waitMs / 1e3 }) + "\n");
|
|
70534
71177
|
} else {
|
|
70535
71178
|
process.stdout.write(`
|
|
@@ -70544,7 +71187,7 @@ async function sessionOpen(opts) {
|
|
|
70544
71187
|
});
|
|
70545
71188
|
}
|
|
70546
71189
|
});
|
|
70547
|
-
if (
|
|
71190
|
+
if (jsonMode3(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "handed", address }) + "\n");
|
|
70548
71191
|
else process.stdout.write(` ${import_picocolors8.default.green("\u2713")} handed over; the browser is this account now.
|
|
70549
71192
|
|
|
70550
71193
|
`);
|
|
@@ -70559,7 +71202,7 @@ async function sessionReceive(opts) {
|
|
|
70559
71202
|
waitMs,
|
|
70560
71203
|
onCode: (code, port) => {
|
|
70561
71204
|
const typed = handoffCode(code, port);
|
|
70562
|
-
if (
|
|
71205
|
+
if (jsonMode3(opts)) {
|
|
70563
71206
|
process.stdout.write(JSON.stringify({ ok: true, status: "waiting", code: typed, port, waitSeconds: waitMs / 1e3 }) + "\n");
|
|
70564
71207
|
} else {
|
|
70565
71208
|
process.stdout.write(`
|
|
@@ -70573,7 +71216,7 @@ async function sessionReceive(opts) {
|
|
|
70573
71216
|
}
|
|
70574
71217
|
});
|
|
70575
71218
|
const { address, prefix, sealed, mode } = await adoptKey(key, `computer ${hostname2()}`);
|
|
70576
|
-
if (
|
|
71219
|
+
if (jsonMode3(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "received", address, prefix, sealed, mode, path: passwordsKeyPath() }) + "\n");
|
|
70577
71220
|
else {
|
|
70578
71221
|
process.stdout.write(` ${import_picocolors8.default.green("\u2713")} this CLI runs on ${import_picocolors8.default.bold(prefix)} for ${address}
|
|
70579
71222
|
`);
|
|
@@ -70616,17 +71259,17 @@ function loginKeyLines(login2) {
|
|
|
70616
71259
|
` : ` ${import_picocolors9.default.dim(`login key here: ${login2.prefix}; every call sends it`)}
|
|
70617
71260
|
`;
|
|
70618
71261
|
}
|
|
70619
|
-
var
|
|
70620
|
-
var
|
|
71262
|
+
var SITE4 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
|
|
71263
|
+
var jsonMode4 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
70621
71264
|
function emit4(opts, data4, human) {
|
|
70622
|
-
if (
|
|
71265
|
+
if (jsonMode4(opts)) {
|
|
70623
71266
|
process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
|
|
70624
71267
|
return;
|
|
70625
71268
|
}
|
|
70626
71269
|
human();
|
|
70627
71270
|
}
|
|
70628
71271
|
function refuse3(opts, error, code, extra = {}) {
|
|
70629
|
-
if (
|
|
71272
|
+
if (jsonMode4(opts)) {
|
|
70630
71273
|
process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
|
|
70631
71274
|
} else {
|
|
70632
71275
|
process.stderr.write(` ${error}${code ? import_picocolors9.default.dim(` (${code})`) : ""}
|
|
@@ -70680,7 +71323,7 @@ function parseInt10(raw, name, dflt, min, max) {
|
|
|
70680
71323
|
if (!Number.isInteger(n2) || n2 < min || n2 > max) throw new PasswordsSealError(`${name} is a whole number from ${min} to ${max}`);
|
|
70681
71324
|
return n2;
|
|
70682
71325
|
}
|
|
70683
|
-
var
|
|
71326
|
+
var usd4 = (v) => {
|
|
70684
71327
|
const n2 = Number(v);
|
|
70685
71328
|
if (Number.isInteger(n2)) return `$${n2}`;
|
|
70686
71329
|
const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
|
|
@@ -70703,7 +71346,7 @@ function passwordsSlice(body) {
|
|
|
70703
71346
|
return out;
|
|
70704
71347
|
}
|
|
70705
71348
|
async function passwordsPricing(opts) {
|
|
70706
|
-
const res = await fetch(`${
|
|
71349
|
+
const res = await fetch(`${SITE4}/api/account/catalog`, { headers: { accept: "application/json" } });
|
|
70707
71350
|
if (!res.ok) throw new Error(`passwords catalog: HTTP ${res.status}`);
|
|
70708
71351
|
const body = await res.json();
|
|
70709
71352
|
const slice = passwordsSlice(body);
|
|
@@ -70744,7 +71387,7 @@ async function passwordsPricing(opts) {
|
|
|
70744
71387
|
}
|
|
70745
71388
|
for (const f2 of families) {
|
|
70746
71389
|
const rows = byFamily.get(f2).sort((a, b2) => a.units - b2.units);
|
|
70747
|
-
const cells = rows.map((p) => `${import_picocolors9.default.cyan(
|
|
71390
|
+
const cells = rows.map((p) => `${import_picocolors9.default.cyan(usd4(p.priceUsd).padStart(4))}${import_picocolors9.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
|
|
70748
71391
|
const lead = rows[0];
|
|
70749
71392
|
const cap = [
|
|
70750
71393
|
lead.passwords ? `${lead.passwords.toLocaleString()} passwords` : "",
|
|
@@ -70758,8 +71401,8 @@ async function passwordsPricing(opts) {
|
|
|
70758
71401
|
const use = slice.passwordsUsage?.useUsd;
|
|
70759
71402
|
const login2 = slice.passwordsUsage?.loginUsd;
|
|
70760
71403
|
const meter = [
|
|
70761
|
-
use ? `a code or key ${
|
|
70762
|
-
login2 ? `a login ${
|
|
71404
|
+
use ? `a code or key ${usd4(use)}` : "",
|
|
71405
|
+
login2 ? `a login ${usd4(login2)}` : ""
|
|
70763
71406
|
].filter(Boolean).join(" \xB7 ");
|
|
70764
71407
|
if (meter) process.stdout.write(`
|
|
70765
71408
|
${import_picocolors9.default.dim(`past the daily uses, from the agent's prepaid balance: ${meter}`)}
|
|
@@ -70856,6 +71499,14 @@ async function passwordsAdd(opts) {
|
|
|
70856
71499
|
const kind = opts.kind ?? "login";
|
|
70857
71500
|
let password = opts.password;
|
|
70858
71501
|
if (opts.passwordStdin) password = readFileSync(0, "utf8").replace(/\r?\n$/, "");
|
|
71502
|
+
if (opts.through) {
|
|
71503
|
+
if (kind !== "login") throw new PasswordsSealError("--through makes a login row");
|
|
71504
|
+
if (password !== void 0 || opts.passwordStdin) throw new PasswordsSealError("--through stores no password: the site signs in with the login row it names");
|
|
71505
|
+
const { passwords: passwords2 } = await listRows(wallet);
|
|
71506
|
+
const row2 = passwords2.find((r) => r.id === opts.through);
|
|
71507
|
+
if (!row2) throw new PasswordsSealError(`this key holds no row ${opts.through} (agentgates passwords list)`);
|
|
71508
|
+
if (row2.kind !== "login") throw new PasswordsSealError("--through names a login row: the account the site signs in through");
|
|
71509
|
+
}
|
|
70859
71510
|
const secret = {
|
|
70860
71511
|
password,
|
|
70861
71512
|
totpSeed: opts.totpSeed,
|
|
@@ -70889,7 +71540,7 @@ async function passwordsAdd(opts) {
|
|
|
70889
71540
|
if (!password || password === "-") throw new PasswordsSealError("a mailbox row needs --password, the app password (Gmail: myaccount.google.com/apppasswords, with 2-Step Verification on). An inbox leased here needs none: store the row on its own address instead.");
|
|
70890
71541
|
}
|
|
70891
71542
|
}
|
|
70892
|
-
const payload = buildSecretPayload({ kind, secret, hosts, notes: opts.notes, backupCodes: readArg(opts.backupCodes), device });
|
|
71543
|
+
const payload = buildSecretPayload({ kind, secret, hosts, notes: opts.notes, backupCodes: readArg(opts.backupCodes), device, signsInThrough: Boolean(opts.through) });
|
|
70893
71544
|
let username;
|
|
70894
71545
|
if (opts.username !== void 0 && opts.username !== "") {
|
|
70895
71546
|
if (kind !== "login" && kind !== "mailbox") throw new PasswordsSealError("only a login or a mailbox carries a username");
|
|
@@ -71104,6 +71755,16 @@ function printUseAnswer(opts, status4, body) {
|
|
|
71104
71755
|
if (typeof result.codesLeft === "number") process.stdout.write(` ${import_picocolors9.default.dim(`${result.codesLeft} backup code${result.codesLeft === 1 ? "" : "s"} left`)}
|
|
71105
71756
|
`);
|
|
71106
71757
|
if (result.device && typeof result.device === "object") process.stdout.write(` ${import_picocolors9.default.dim(`the site created a device credential for ${String(result.device.rpId ?? "")}; agentgates passwords device seals it into the row`)}
|
|
71758
|
+
`);
|
|
71759
|
+
if (result.apiKey && typeof result.apiKey === "object" && result.apiKey.kept === true) {
|
|
71760
|
+
process.stdout.write(` ${import_picocolors9.default.green("\u2713")} the key is kept inside the CVM in this row; a header use fills {apiKey} with it
|
|
71761
|
+
`);
|
|
71762
|
+
}
|
|
71763
|
+
for (const field of Array.isArray(result.sealed) ? result.sealed : []) {
|
|
71764
|
+
process.stdout.write(` ${import_picocolors9.default.dim(`${field} is sealed to the owner (agentgates passwords open-sealed opens it with the owner's key)`)}
|
|
71765
|
+
`);
|
|
71766
|
+
}
|
|
71767
|
+
if (result.withheld === true) process.stdout.write(` ${import_picocolors9.default.dim("the answer had no field where the seal looked for it, so none of it was handed back")}
|
|
71107
71768
|
`);
|
|
71108
71769
|
for (const s of Array.isArray(result.solved) ? result.solved : []) {
|
|
71109
71770
|
process.stdout.write(` ${import_picocolors9.default.dim(`passed a ${String(s.kind)} check ${s.how === "service" ? "through the solver service" : "by hand"} in ${Math.max(1, Math.round(Number(s.ms ?? 0) / 1e3))}s`)}
|
|
@@ -71184,6 +71845,10 @@ async function passwordsUse(opts) {
|
|
|
71184
71845
|
if (use !== "login" && use !== "session") throw new PasswordsSealError("--mailbox goes with the login or session use");
|
|
71185
71846
|
request.mailbox = opts.mailbox;
|
|
71186
71847
|
}
|
|
71848
|
+
if (opts.asRow) {
|
|
71849
|
+
if (use !== "login") throw new PasswordsSealError("--as-row goes with the login use");
|
|
71850
|
+
request.credential = opts.asRow;
|
|
71851
|
+
}
|
|
71187
71852
|
let workflowRow = null;
|
|
71188
71853
|
if (opts.workflow) {
|
|
71189
71854
|
if (use !== "login") throw new PasswordsSealError("--workflow goes with the login use");
|
|
@@ -71211,7 +71876,7 @@ function waitOptionsOf(opts) {
|
|
|
71211
71876
|
return {
|
|
71212
71877
|
waitSeconds: opts.wait !== void 0 ? parseInt10(opts.wait, "--wait", 0, 0, 3600) : null,
|
|
71213
71878
|
noWait: opts.noWait,
|
|
71214
|
-
note:
|
|
71879
|
+
note: jsonMode4(opts) ? void 0 : (line2) => process.stderr.write(` ${import_picocolors9.default.dim(line2)}
|
|
71215
71880
|
`)
|
|
71216
71881
|
};
|
|
71217
71882
|
}
|
|
@@ -71220,6 +71885,9 @@ async function postUseAndWait(wallet, rowId, firstBody, opts = {}) {
|
|
|
71220
71885
|
{
|
|
71221
71886
|
let lastBody = firstBody;
|
|
71222
71887
|
let broughtCode = null;
|
|
71888
|
+
let pressNamed = false;
|
|
71889
|
+
let pressBrought = false;
|
|
71890
|
+
let ownerNamed = false;
|
|
71223
71891
|
let answer = await postUse(wallet, rowId, firstBody);
|
|
71224
71892
|
const startedAt = Date.now();
|
|
71225
71893
|
const boxBudgetEnd = waitCap !== null ? startedAt + waitCap * 1e3 : startedAt + 24e4;
|
|
@@ -71227,13 +71895,46 @@ async function postUseAndWait(wallet, rowId, firstBody, opts = {}) {
|
|
|
71227
71895
|
const body = answer.body ?? {};
|
|
71228
71896
|
if (answer.status === 202) {
|
|
71229
71897
|
if (!body.useId) break;
|
|
71230
|
-
|
|
71898
|
+
const heldForOwner = body.code === "attend_pending" && !body.view;
|
|
71899
|
+
if (body.code === "attend_pending" && !heldForOwner) break;
|
|
71231
71900
|
const expiresAt = body.expiresAt ? Date.parse(body.expiresAt) : NaN;
|
|
71232
71901
|
const deadline = Math.min(
|
|
71233
71902
|
Number.isFinite(expiresAt) ? expiresAt : Date.now() + 6e5,
|
|
71234
71903
|
waitCap !== null ? startedAt + waitCap * 1e3 : Number.POSITIVE_INFINITY
|
|
71235
71904
|
);
|
|
71236
71905
|
if (Date.now() >= deadline) break;
|
|
71906
|
+
if (body.code === "press_pending") {
|
|
71907
|
+
const press = body;
|
|
71908
|
+
if (!pressNamed) {
|
|
71909
|
+
opts.note?.(`${press.site ?? "the site"} takes this press only from the owner's own browser: open ${press.open ?? "its sign-up page"} and press Continue`);
|
|
71910
|
+
pressNamed = true;
|
|
71911
|
+
}
|
|
71912
|
+
const asked = firstBody.request ?? {};
|
|
71913
|
+
const site = typeof asked.url === "string" ? siteOfUrl(asked.url) : null;
|
|
71914
|
+
if (!pressBrought && site && press.source?.sealed === true && press.source.kind === "inbox" && typeof press.source.id === "string") {
|
|
71915
|
+
try {
|
|
71916
|
+
const mail = await waitSiteMail(wallet, press.source.id, { site, since: press.askedAt ?? null, timeoutSeconds: Math.max(5, Math.min(60, Math.floor((deadline - Date.now()) / 1e3))) });
|
|
71917
|
+
if (mail?.link) {
|
|
71918
|
+
pressBrought = true;
|
|
71919
|
+
opts.note?.(`the site's mail is in; the CVM finishes the sign-up on its link`);
|
|
71920
|
+
lastBody = { ...firstBody, request: { ...asked, verifyUrl: mail.link, ...mail.code ? { otpCode: mail.code } : {} }, useId: body.useId };
|
|
71921
|
+
answer = await postUse(wallet, rowId, lastBody);
|
|
71922
|
+
continue;
|
|
71923
|
+
}
|
|
71924
|
+
if (mail?.code) {
|
|
71925
|
+
pressBrought = true;
|
|
71926
|
+
opts.note?.(`the site's mail carries no link the CVM may finish on: type ${mail.code} in the browser you pressed in`);
|
|
71927
|
+
lastBody = { ...firstBody, request: { ...asked, otpCode: mail.code }, useId: body.useId };
|
|
71928
|
+
answer = await postUse(wallet, rowId, lastBody);
|
|
71929
|
+
continue;
|
|
71930
|
+
}
|
|
71931
|
+
answer = await postUse(wallet, rowId, { ...firstBody, useId: body.useId });
|
|
71932
|
+
continue;
|
|
71933
|
+
} catch (err) {
|
|
71934
|
+
opts.note?.(`could not read the sealed inbox here (${err instanceof Error ? err.message : String(err)}); waiting on the owner`);
|
|
71935
|
+
}
|
|
71936
|
+
}
|
|
71937
|
+
}
|
|
71237
71938
|
const source = body.source;
|
|
71238
71939
|
if (body.code === "code_pending" && source?.sealed === true && source.kind === "inbox" && typeof source.id === "string" && !broughtCode) {
|
|
71239
71940
|
opts.note?.(`the site sent a code to a sealed inbox; reading it with this key`);
|
|
@@ -71248,7 +71949,15 @@ async function postUseAndWait(wallet, rowId, firstBody, opts = {}) {
|
|
|
71248
71949
|
opts.note?.(`could not read the sealed inbox here (${err instanceof Error ? err.message : String(err)}); waiting for the owner`);
|
|
71249
71950
|
}
|
|
71250
71951
|
}
|
|
71251
|
-
|
|
71952
|
+
if (heldForOwner) {
|
|
71953
|
+
if (!ownerNamed) {
|
|
71954
|
+
const wall = body.wall;
|
|
71955
|
+
opts.note?.(`a step only a person completes${typeof wall === "string" && wall ? ` (${wall})` : ""}: the page is on the owner's board; waiting for their Done`);
|
|
71956
|
+
ownerNamed = true;
|
|
71957
|
+
}
|
|
71958
|
+
} else {
|
|
71959
|
+
opts.note?.(body.error ?? "waiting for the owner");
|
|
71960
|
+
}
|
|
71252
71961
|
lastBody = { ...firstBody, useId: body.useId, wait: 25 };
|
|
71253
71962
|
answer = await postUse(wallet, rowId, lastBody);
|
|
71254
71963
|
continue;
|
|
@@ -71388,6 +72097,80 @@ async function storeSealedRow(wallet, input) {
|
|
|
71388
72097
|
cvmKeyId: att.keyId
|
|
71389
72098
|
});
|
|
71390
72099
|
}
|
|
72100
|
+
var AUTO_OWNER_HOPS = 8;
|
|
72101
|
+
var AUTO_OWNER_PAUSE_SECONDS = 10;
|
|
72102
|
+
var PHONE_FIELD = { x: 640, y: 438 };
|
|
72103
|
+
var DEVICE_FIELD = { x: 640, y: 363 };
|
|
72104
|
+
function nationalDigits(number2) {
|
|
72105
|
+
const digits = number2.replace(/\D/g, "");
|
|
72106
|
+
return digits.length === 11 && digits.startsWith("1") ? digits.slice(1) : digits;
|
|
72107
|
+
}
|
|
72108
|
+
async function heldCardOf(wallet, useId) {
|
|
72109
|
+
const out = expectOk(await signedFetch(wallet, "GET", lanePath("/passwords/pending")), "the waiting cards");
|
|
72110
|
+
const card2 = (out.pending ?? []).find((c) => c.id === useId);
|
|
72111
|
+
if (!card2 || !card2.secretId || !card2.attend?.token) throw new PasswordsSealError("the held page is not on this key's waiting cards");
|
|
72112
|
+
return { row: card2.secretId, useId, token: card2.attend.token };
|
|
72113
|
+
}
|
|
72114
|
+
async function heldInput(card2, input) {
|
|
72115
|
+
const res = await fetch(`${siteOrigin()}/api/passwords/${encodeURIComponent(card2.row)}/attend/${encodeURIComponent(card2.useId)}/input`, {
|
|
72116
|
+
method: "POST",
|
|
72117
|
+
headers: { authorization: `Bearer ${card2.token}`, "content-type": "application/json", accept: "application/json" },
|
|
72118
|
+
body: JSON.stringify({ ...input, view: card2.token })
|
|
72119
|
+
});
|
|
72120
|
+
if (!res.ok) throw new PasswordsSealError(`the held page refused an input (${res.status})`);
|
|
72121
|
+
}
|
|
72122
|
+
var sleepMs = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
72123
|
+
async function answerDeviceCheck(wallet, useId, inboxId, note2) {
|
|
72124
|
+
const card2 = await heldCardOf(wallet, useId);
|
|
72125
|
+
const since = Date.now() - 6e4;
|
|
72126
|
+
const deadline = Date.now() + 9e4;
|
|
72127
|
+
let code = null;
|
|
72128
|
+
while (Date.now() < deadline && !code) {
|
|
72129
|
+
try {
|
|
72130
|
+
const mailed = await waitInboxCode(wallet, inboxId, { timeoutSeconds: 8 });
|
|
72131
|
+
if (mailed.receivedAt && Date.parse(mailed.receivedAt) >= since) code = mailed.code;
|
|
72132
|
+
else await sleepMs(3e3);
|
|
72133
|
+
} catch (err) {
|
|
72134
|
+
if (err instanceof WireError && err.status !== 408) throw err;
|
|
72135
|
+
}
|
|
72136
|
+
}
|
|
72137
|
+
if (!code) throw new PasswordsSealError("no code reached the inbox in ninety seconds");
|
|
72138
|
+
await heldInput(card2, { kind: "click", x: DEVICE_FIELD.x, y: DEVICE_FIELD.y });
|
|
72139
|
+
await sleepMs(400);
|
|
72140
|
+
await heldInput(card2, { kind: "type", text: code });
|
|
72141
|
+
await sleepMs(400);
|
|
72142
|
+
await heldInput(card2, { kind: "key", key: "Enter" });
|
|
72143
|
+
note2?.("the device check's code is typed");
|
|
72144
|
+
}
|
|
72145
|
+
async function answerPhoneCheck(wallet, useId, sms, note2) {
|
|
72146
|
+
const card2 = await heldCardOf(wallet, useId);
|
|
72147
|
+
const digits = nationalDigits(sms.number);
|
|
72148
|
+
if (digits.length < 7) throw new PasswordsSealError("--sms-number is a phone number");
|
|
72149
|
+
await heldInput(card2, { kind: "click", x: PHONE_FIELD.x, y: PHONE_FIELD.y });
|
|
72150
|
+
await sleepMs(400);
|
|
72151
|
+
await heldInput(card2, { kind: "type", text: digits });
|
|
72152
|
+
await sleepMs(400);
|
|
72153
|
+
const typedAt = Date.now();
|
|
72154
|
+
await heldInput(card2, { kind: "key", key: "Enter" });
|
|
72155
|
+
note2?.(`the phone check has the number; waiting for its text at ${sms.id}`);
|
|
72156
|
+
const deadline = typedAt + 12e4;
|
|
72157
|
+
let code = null;
|
|
72158
|
+
while (Date.now() < deadline && !code) {
|
|
72159
|
+
try {
|
|
72160
|
+
const texted = await waitPhoneCode(wallet, sms.id, { timeoutSeconds: 6 });
|
|
72161
|
+
if (texted.receivedAt && Date.parse(texted.receivedAt) >= typedAt - 3e3) code = texted.code;
|
|
72162
|
+
else await sleepMs(3e3);
|
|
72163
|
+
} catch (err) {
|
|
72164
|
+
if (err instanceof WireError && err.status !== 408 && err.status !== 404) throw err;
|
|
72165
|
+
}
|
|
72166
|
+
}
|
|
72167
|
+
if (!code) throw new PasswordsSealError("no text reached the number in two minutes");
|
|
72168
|
+
await sleepMs(500);
|
|
72169
|
+
await heldInput(card2, { kind: "type", text: code });
|
|
72170
|
+
await sleepMs(400);
|
|
72171
|
+
await heldInput(card2, { kind: "key", key: "Enter" });
|
|
72172
|
+
note2?.("the text's code is typed");
|
|
72173
|
+
}
|
|
71391
72174
|
async function passwordsSignupFlow(wallet, args, wait2 = {}) {
|
|
71392
72175
|
let site;
|
|
71393
72176
|
try {
|
|
@@ -71399,21 +72182,55 @@ async function passwordsSignupFlow(wallet, args, wait2 = {}) {
|
|
|
71399
72182
|
const source = sourceOf(args);
|
|
71400
72183
|
if (source?.kind === "phone" && args.email) throw new PasswordsSealError("an account made on a number carries no --email: the number is the identity and the code comes by text");
|
|
71401
72184
|
const mailbox = source ? source.id : await mailboxRowFor(wallet);
|
|
71402
|
-
|
|
72185
|
+
let asRow = null;
|
|
72186
|
+
if (args.asRow) {
|
|
72187
|
+
if (args.password) throw new PasswordsSealError("--as-row brings its own password: leave --password out");
|
|
72188
|
+
if (!args.useId) {
|
|
72189
|
+
const { passwords: passwords2 } = await listRows(wallet);
|
|
72190
|
+
const row = passwords2.find((r) => r.id === args.asRow);
|
|
72191
|
+
if (!row) throw new PasswordsSealError(`this key holds no row ${args.asRow} (agentgates passwords list)`);
|
|
72192
|
+
if (row.kind !== "login") throw new PasswordsSealError("--as-row names a login: the account whose sign-in the site takes");
|
|
72193
|
+
const opened = parseSecretPayload(openDurable(await revealRow(wallet, row.id), await signVaultMessage(wallet)).toString("utf8"));
|
|
72194
|
+
const held3 = opened.secret.password;
|
|
72195
|
+
if (typeof held3 !== "string" || !held3) throw new PasswordsSealError("that login holds no password");
|
|
72196
|
+
asRow = { username: row.username ?? void 0, password: held3 };
|
|
72197
|
+
}
|
|
72198
|
+
}
|
|
72199
|
+
const password = asRow?.password ?? args.password ?? (args.useId ? void 0 : generatePassword());
|
|
71403
72200
|
const request = { url: args.url, ...password !== void 0 ? { password } : {} };
|
|
71404
72201
|
if (source && source.kind !== "mailbox") request.source = { kind: source.kind, id: source.id };
|
|
71405
72202
|
if (args.email) request.email = args.email;
|
|
71406
72203
|
if (args.name) request.name = args.name;
|
|
71407
72204
|
if (args.username) request.username = args.username;
|
|
72205
|
+
else if (asRow?.username) request.username = asRow.username;
|
|
71408
72206
|
if (args.steps !== void 0) request.steps = args.steps;
|
|
71409
72207
|
if (args.drive) request.drive = true;
|
|
71410
72208
|
if (args.birthday) request.birthday = args.birthday;
|
|
71411
72209
|
if (args.attend || args.useId) request.attend = true;
|
|
71412
|
-
|
|
72210
|
+
let answer = await postUseAndWait(wallet, mailbox, { use: "signup", request, ...args.useId ? { useId: args.useId } : {} }, wait2);
|
|
72211
|
+
if (args.autoOwner && (args.attend || args.useId)) {
|
|
72212
|
+
const { password: _sent, ...continued } = request;
|
|
72213
|
+
for (let hop = 0; hop < AUTO_OWNER_HOPS; hop += 1) {
|
|
72214
|
+
const held3 = answer.body ?? {};
|
|
72215
|
+
if (answer.status !== 202 || held3.code !== "attend_pending" || !held3.useId) break;
|
|
72216
|
+
const wall = String(held3.wall ?? "");
|
|
72217
|
+
if (/phone/i.test(wall) && args.smsId && args.smsNumber) {
|
|
72218
|
+
await answerPhoneCheck(wallet, held3.useId, { id: args.smsId, number: args.smsNumber }, args.note);
|
|
72219
|
+
} else if (/device/i.test(wall) && source?.kind === "inbox") {
|
|
72220
|
+
await answerDeviceCheck(wallet, held3.useId, source.id, args.note);
|
|
72221
|
+
} else if (/did not expect/i.test(wall)) {
|
|
72222
|
+
args.note?.(`a page had not drawn; continuing in ${AUTO_OWNER_PAUSE_SECONDS}s`);
|
|
72223
|
+
await sleepMs(AUTO_OWNER_PAUSE_SECONDS * 1e3);
|
|
72224
|
+
} else {
|
|
72225
|
+
break;
|
|
72226
|
+
}
|
|
72227
|
+
answer = await postUseAndWait(wallet, mailbox, { use: "signup", request: continued, useId: held3.useId }, wait2);
|
|
72228
|
+
}
|
|
72229
|
+
}
|
|
71413
72230
|
const body = answer.body ?? {};
|
|
71414
72231
|
const result = body.result ?? {};
|
|
71415
72232
|
const ok = answer.status === 200 && result.ok === true;
|
|
71416
|
-
const storedPassword = password ?? (typeof result.password === "string" ? result.password : void 0);
|
|
72233
|
+
const storedPassword = args.asRow ? void 0 : password ?? (typeof result.password === "string" ? result.password : void 0);
|
|
71417
72234
|
const email2 = typeof result.email === "string" && result.email ? result.email : args.email ?? null;
|
|
71418
72235
|
const phone2 = typeof result.phone === "string" ? result.phone : null;
|
|
71419
72236
|
const signInAs = typeof result.signInAs === "string" ? result.signInAs : null;
|
|
@@ -71459,6 +72276,7 @@ async function passwordsSignupFlow(wallet, args, wait2 = {}) {
|
|
|
71459
72276
|
// it on and the continue call signs in to the account you made there.
|
|
71460
72277
|
then: result.then === "signin" || body.then === "signin" ? "signin" : null,
|
|
71461
72278
|
drove: result.drove ?? body.drove ?? null,
|
|
72279
|
+
...typeof body.open === "string" ? { open: String(body.open) } : {},
|
|
71462
72280
|
passwordSet,
|
|
71463
72281
|
digest: typeof result.digest === "string" ? result.digest : "",
|
|
71464
72282
|
...result.cookies !== void 0 ? { cookies: result.cookies } : {},
|
|
@@ -71469,7 +72287,12 @@ async function passwordsSignupFlow(wallet, args, wait2 = {}) {
|
|
|
71469
72287
|
...body.chargedUsd !== void 0 ? { chargedUsd: body.chargedUsd } : {},
|
|
71470
72288
|
stored,
|
|
71471
72289
|
...storeError ? { storeError } : {},
|
|
71472
|
-
|
|
72290
|
+
// A sign-up that failed AFTER the password went into the form comes back
|
|
72291
|
+
// with it too: the site may still make the account (GitHub made one after
|
|
72292
|
+
// the CVM closed its page on 2026-09-27, and on 2026-09-28 the mailed
|
|
72293
|
+
// confirm link made livefire-agent), and this answer is then the only
|
|
72294
|
+
// place the password is left.
|
|
72295
|
+
...passwordSet && storedPassword !== void 0 && (ok ? !args.store || storeError : true) ? { password: storedPassword } : {}
|
|
71473
72296
|
};
|
|
71474
72297
|
}
|
|
71475
72298
|
function birthdayOf(raw) {
|
|
@@ -71494,10 +72317,23 @@ async function passwordsSignup(opts) {
|
|
|
71494
72317
|
}
|
|
71495
72318
|
const answer = await passwordsSignupFlow(
|
|
71496
72319
|
wallet,
|
|
71497
|
-
{ url: opts.url, email: opts.email, name: opts.name, username: opts.username, password: opts.password, mailbox: opts.mailbox, inbox: opts.inbox, phone: opts.phone, label: opts.label, store: opts.store !== false, steps, drive: opts.drive === true, birthday: birthdayOf(opts.birthday), attend: opts.attend
|
|
72320
|
+
{ url: opts.url, email: opts.email, name: opts.name, username: opts.username, password: opts.password, mailbox: opts.mailbox, inbox: opts.inbox, phone: opts.phone, label: opts.label, store: opts.store !== false, steps, drive: opts.drive === true, birthday: birthdayOf(opts.birthday), attend: opts.attend !== false, useId: opts.useId, asRow: opts.asRow, autoOwner: opts.autoOwner === true, smsId: opts.smsId, smsNumber: opts.smsNumber, note: jsonMode4(opts) ? void 0 : (line2) => process.stdout.write(` ${import_picocolors9.default.dim(line2)}
|
|
72321
|
+
`) },
|
|
71498
72322
|
waitOptionsOf(opts)
|
|
71499
72323
|
);
|
|
71500
72324
|
emit4(opts, answer, () => {
|
|
72325
|
+
if (answer.code === "press_pending" && answer.useId) {
|
|
72326
|
+
process.stdout.write(
|
|
72327
|
+
`
|
|
72328
|
+
${import_picocolors9.default.yellow("!")} ${import_picocolors9.default.bold(answer.site)} takes this press only from your own browser
|
|
72329
|
+
${import_picocolors9.default.dim("open")} ${answer.open ?? answer.url} ${import_picocolors9.default.dim("and press Continue")}
|
|
72330
|
+
${import_picocolors9.default.dim("use")} ${answer.useId}
|
|
72331
|
+
${import_picocolors9.default.dim(`then: agentgates passwords signup --url ${answer.url}${answer.source.kind !== "mailbox" ? ` --${answer.source.kind} ${answer.source.id}` : ""} --use-id ${answer.useId} (reads the site's mail; the CVM finishes the sign-up)`)}
|
|
72332
|
+
|
|
72333
|
+
`
|
|
72334
|
+
);
|
|
72335
|
+
return;
|
|
72336
|
+
}
|
|
71501
72337
|
if (answer.code === "attend_pending" && answer.useId) {
|
|
71502
72338
|
process.stdout.write(
|
|
71503
72339
|
`
|
|
@@ -71545,6 +72381,8 @@ ${answer.digest.split("\n").slice(0, 12).map((l) => ` ${l}`).join("\n")}
|
|
|
71545
72381
|
process.stdout.write(`
|
|
71546
72382
|
${answer.error ?? `HTTP ${answer.status}`}${answer.code ? import_picocolors9.default.dim(` (${answer.code})`) : ""}
|
|
71547
72383
|
${answer.useId ? ` ${import_picocolors9.default.dim("use")} ${answer.useId}
|
|
72384
|
+
` : ""}${answer.password ? ` ${import_picocolors9.default.dim("the form took this password; if the site makes the account anyway, it signs in with it:")}
|
|
72385
|
+
${answer.password}
|
|
71548
72386
|
` : ""}${answer.digest ? `
|
|
71549
72387
|
${answer.digest.split("\n").slice(0, 12).map((l) => ` ${l}`).join("\n")}
|
|
71550
72388
|
` : ""}
|
|
@@ -71703,6 +72541,42 @@ async function passwordsInvite(opts) {
|
|
|
71703
72541
|
failFrom2(opts, err);
|
|
71704
72542
|
}
|
|
71705
72543
|
}
|
|
72544
|
+
function sealedAnswerAad(rowId, field) {
|
|
72545
|
+
return `agentgates-passwords-sealed-answer-v1|${rowId}|${field}`;
|
|
72546
|
+
}
|
|
72547
|
+
async function passwordsOpenSealed(opts) {
|
|
72548
|
+
try {
|
|
72549
|
+
const { wallet } = await requirePasswordsKey();
|
|
72550
|
+
if (!opts.row || !opts.field || !opts.blob) throw new PasswordsSealError("--row, --field and --blob: the row the use ran on, the sealed field's name, and its {sealed} value (or @file)");
|
|
72551
|
+
const blob = (readArg(opts.blob) ?? "").trim();
|
|
72552
|
+
const key = await mailKeyFor(wallet);
|
|
72553
|
+
if (!key) throw new PasswordsSealError("this account has no data key: nothing was sealed to it");
|
|
72554
|
+
let value;
|
|
72555
|
+
try {
|
|
72556
|
+
value = openText(key.dataKey, blob, sealedAnswerAad(opts.row, opts.field));
|
|
72557
|
+
} catch {
|
|
72558
|
+
throw new PasswordsSealError("that blob does not open as this row's field under this account's key");
|
|
72559
|
+
}
|
|
72560
|
+
if (opts.out) {
|
|
72561
|
+
writeFileSync2(opts.out, value, { mode: 384 });
|
|
72562
|
+
emit4(opts, { ok: true, row: opts.row, field: opts.field, out: opts.out, chars: value.length }, () => {
|
|
72563
|
+
process.stdout.write(`
|
|
72564
|
+
${import_picocolors9.default.green("\u2713")} ${opts.field} opened: ${value.length} characters, written to ${opts.out}
|
|
72565
|
+
|
|
72566
|
+
`);
|
|
72567
|
+
});
|
|
72568
|
+
return;
|
|
72569
|
+
}
|
|
72570
|
+
emit4(opts, { ok: true, row: opts.row, field: opts.field, value }, () => {
|
|
72571
|
+
process.stdout.write(`
|
|
72572
|
+
${opts.field} ${value}
|
|
72573
|
+
|
|
72574
|
+
`);
|
|
72575
|
+
});
|
|
72576
|
+
} catch (err) {
|
|
72577
|
+
failFrom2(opts, err);
|
|
72578
|
+
}
|
|
72579
|
+
}
|
|
71706
72580
|
|
|
71707
72581
|
// src/commands/browser.ts
|
|
71708
72582
|
var import_picocolors10 = __toESM(require_picocolors(), 1);
|
|
@@ -71805,16 +72679,16 @@ async function waitForTask(wallet, id2, { maxSeconds = 900, everyMs = 5e3, onTic
|
|
|
71805
72679
|
}
|
|
71806
72680
|
|
|
71807
72681
|
// src/commands/browser.ts
|
|
71808
|
-
var
|
|
72682
|
+
var jsonMode5 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
71809
72683
|
function emit5(opts, data4, human) {
|
|
71810
|
-
if (
|
|
72684
|
+
if (jsonMode5(opts)) {
|
|
71811
72685
|
process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
|
|
71812
72686
|
return;
|
|
71813
72687
|
}
|
|
71814
72688
|
human();
|
|
71815
72689
|
}
|
|
71816
72690
|
function refuse4(opts, error, code, extra = {}) {
|
|
71817
|
-
if (
|
|
72691
|
+
if (jsonMode5(opts)) {
|
|
71818
72692
|
process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
|
|
71819
72693
|
} else {
|
|
71820
72694
|
process.stderr.write(` ${error}${code ? import_picocolors10.default.dim(` (${code})`) : ""}
|
|
@@ -71826,7 +72700,7 @@ function failFrom3(opts, err) {
|
|
|
71826
72700
|
if (err instanceof WireError) return refuse4(opts, err.message, err.code, { status: err.status });
|
|
71827
72701
|
return refuse4(opts, err.message ?? String(err), null);
|
|
71828
72702
|
}
|
|
71829
|
-
var
|
|
72703
|
+
var usd5 = (v) => {
|
|
71830
72704
|
const n2 = Number(v);
|
|
71831
72705
|
if (Number.isInteger(n2)) return `$${n2}`;
|
|
71832
72706
|
const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
|
|
@@ -71859,9 +72733,9 @@ function printTask(t, full) {
|
|
|
71859
72733
|
`);
|
|
71860
72734
|
process.stdout.write(` ${t.goal}
|
|
71861
72735
|
`);
|
|
71862
|
-
if (t.status === "done") process.stdout.write(` ${import_picocolors10.default.dim(`charged ${
|
|
72736
|
+
if (t.status === "done") process.stdout.write(` ${import_picocolors10.default.dim(`charged ${usd5(t.chargedUsd)}`)}
|
|
71863
72737
|
`);
|
|
71864
|
-
else if (t.status === "queued" || t.status === "running") process.stdout.write(` ${import_picocolors10.default.dim(`reserved ${
|
|
72738
|
+
else if (t.status === "queued" || t.status === "running") process.stdout.write(` ${import_picocolors10.default.dim(`reserved ${usd5(t.reservedUsd)}`)}
|
|
71865
72739
|
`);
|
|
71866
72740
|
if (t.answer) process.stdout.write(`
|
|
71867
72741
|
${import_picocolors10.default.bold("Answer")}
|
|
@@ -71906,7 +72780,7 @@ async function browserPricing(opts) {
|
|
|
71906
72780
|
`);
|
|
71907
72781
|
return;
|
|
71908
72782
|
}
|
|
71909
|
-
if (usage?.stepUsd) process.stdout.write(` ${import_picocolors10.default.cyan(
|
|
72783
|
+
if (usage?.stepUsd) process.stdout.write(` ${import_picocolors10.default.cyan(usd5(usage.stepUsd))} ${import_picocolors10.default.dim("a step, from the prepaid balance")}
|
|
71910
72784
|
`);
|
|
71911
72785
|
if (usage) {
|
|
71912
72786
|
process.stdout.write(` ${import_picocolors10.default.dim(`steps 1 to ${usage.maxSteps} (default ${usage.defaultSteps}) \xB7 ${usage.minSeconds} to ${usage.maxSeconds} seconds \xB7 up to ${usage.maxHosts} extra hosts`)}
|
|
@@ -71940,8 +72814,8 @@ async function browserBalance(opts) {
|
|
|
71940
72814
|
|
|
71941
72815
|
`);
|
|
71942
72816
|
if (balance2.balance) {
|
|
71943
|
-
process.stdout.write(` ${import_picocolors10.default.cyan(
|
|
71944
|
-
if (Number(balance2.balance.reservedUsd) > 0) process.stdout.write(import_picocolors10.default.dim(` \xB7 ${
|
|
72817
|
+
process.stdout.write(` ${import_picocolors10.default.cyan(usd5(balance2.balance.availableUsd))} ${import_picocolors10.default.dim("available")}`);
|
|
72818
|
+
if (Number(balance2.balance.reservedUsd) > 0) process.stdout.write(import_picocolors10.default.dim(` \xB7 ${usd5(balance2.balance.reservedUsd)} reserved by tasks in flight`));
|
|
71945
72819
|
process.stdout.write("\n");
|
|
71946
72820
|
} else {
|
|
71947
72821
|
process.stdout.write(` ${import_picocolors10.default.dim("no balance under this key yet; a top-up opens it")}
|
|
@@ -72064,7 +72938,7 @@ async function browserRun(url, opts) {
|
|
|
72064
72938
|
maxSteps,
|
|
72065
72939
|
maxSeconds,
|
|
72066
72940
|
loginRow: opts.login,
|
|
72067
|
-
note:
|
|
72941
|
+
note: jsonMode5(opts) ? void 0 : (line2) => process.stderr.write(` ${import_picocolors10.default.dim(line2)}
|
|
72068
72942
|
`)
|
|
72069
72943
|
});
|
|
72070
72944
|
if (!opts.wait) {
|
|
@@ -72081,7 +72955,7 @@ async function browserRun(url, opts) {
|
|
|
72081
72955
|
const settled = await waitForTask(keys2.wallet, task.id, {
|
|
72082
72956
|
maxSeconds: waitSeconds,
|
|
72083
72957
|
onTick: (t) => {
|
|
72084
|
-
if (
|
|
72958
|
+
if (jsonMode5(opts) || t.status === lastStatus) return;
|
|
72085
72959
|
lastStatus = t.status;
|
|
72086
72960
|
process.stderr.write(` ${import_picocolors10.default.dim(`${t.status}${t.status === "running" ? ` \xB7 ${t.stepsRun} steps` : ""}`)}
|
|
72087
72961
|
`);
|
|
@@ -72114,8 +72988,8 @@ async function browserTasks(opts) {
|
|
|
72114
72988
|
return;
|
|
72115
72989
|
}
|
|
72116
72990
|
for (const t of tasks) {
|
|
72117
|
-
const
|
|
72118
|
-
process.stdout.write(` ${status2(t.status)} ${t.id} ${import_picocolors10.default.dim(host(t.url).padEnd(24))} ${import_picocolors10.default.dim(`${t.stepsRun}/${t.maxSteps}`.padStart(6))} ${import_picocolors10.default.dim(
|
|
72991
|
+
const money2 = t.status === "done" ? usd5(t.chargedUsd) : t.status === "queued" || t.status === "running" ? `${usd5(t.reservedUsd)} reserved` : "";
|
|
72992
|
+
process.stdout.write(` ${status2(t.status)} ${t.id} ${import_picocolors10.default.dim(host(t.url).padEnd(24))} ${import_picocolors10.default.dim(`${t.stepsRun}/${t.maxSteps}`.padStart(6))} ${import_picocolors10.default.dim(money2.padEnd(16))} ${import_picocolors10.default.dim(when2(t.createdAt))}
|
|
72119
72993
|
`);
|
|
72120
72994
|
process.stdout.write(` ${t.goal.length > 90 ? `${t.goal.slice(0, 89)}\u2026` : t.goal}
|
|
72121
72995
|
`);
|
|
@@ -72137,7 +73011,7 @@ async function browserTask(id2, opts) {
|
|
|
72137
73011
|
const task = opts.wait ? await waitForTask(keys2.wallet, id2, {
|
|
72138
73012
|
maxSeconds: typeof opts.wait === "string" ? Math.max(5, Number(opts.wait) || 0) : 900,
|
|
72139
73013
|
onTick: (t) => {
|
|
72140
|
-
if (!
|
|
73014
|
+
if (!jsonMode5(opts) && !SETTLED.has(t.status)) process.stderr.write(` ${import_picocolors10.default.dim(`${t.status} \xB7 ${t.stepsRun} steps`)}
|
|
72141
73015
|
`);
|
|
72142
73016
|
}
|
|
72143
73017
|
}) : await readTask(keys2.wallet, id2);
|
|
@@ -72152,7 +73026,16 @@ import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
|
72152
73026
|
import path4 from "node:path";
|
|
72153
73027
|
import { spawn } from "node:child_process";
|
|
72154
73028
|
var PKG = "@agentgates/cli";
|
|
72155
|
-
var LOCAL_VERSION =
|
|
73029
|
+
var LOCAL_VERSION = (() => {
|
|
73030
|
+
for (const rel of ["../../package.json", "../package.json"]) {
|
|
73031
|
+
try {
|
|
73032
|
+
const v = JSON.parse(readFileSync2(new URL(rel, import.meta.url), "utf8")).version;
|
|
73033
|
+
if (typeof v === "string") return v;
|
|
73034
|
+
} catch {
|
|
73035
|
+
}
|
|
73036
|
+
}
|
|
73037
|
+
return "0.0.0";
|
|
73038
|
+
})();
|
|
72156
73039
|
function olderThan(a, b2) {
|
|
72157
73040
|
const num = (v) => v.replace(/^v/, "").split("-")[0].split(".").map((n2) => parseInt(n2, 10) || 0);
|
|
72158
73041
|
const [x, y] = [num(a), num(b2)];
|
|
@@ -72208,20 +73091,20 @@ function installedVersionAt(place) {
|
|
|
72208
73091
|
|
|
72209
73092
|
// src/commands/update.ts
|
|
72210
73093
|
var import_picocolors11 = __toESM(require_picocolors(), 1);
|
|
72211
|
-
var
|
|
73094
|
+
var jsonMode6 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
72212
73095
|
async function update(opts = {}) {
|
|
72213
73096
|
const latest = await fetchLatest();
|
|
72214
73097
|
const place = installPlace();
|
|
72215
73098
|
const stale = !!latest && olderThan(LOCAL_VERSION, latest);
|
|
72216
73099
|
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 } : {} };
|
|
72217
73100
|
if (!latest) {
|
|
72218
|
-
if (
|
|
73101
|
+
if (jsonMode6(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");
|
|
72219
73102
|
else process.stderr.write(` ${import_picocolors11.default.red("\u2715")} npm's registry did not answer; try again in a moment
|
|
72220
73103
|
`);
|
|
72221
73104
|
process.exit(1);
|
|
72222
73105
|
}
|
|
72223
73106
|
if (opts.check || !stale) {
|
|
72224
|
-
if (
|
|
73107
|
+
if (jsonMode6(opts)) process.stdout.write(JSON.stringify(base, null, 2) + "\n");
|
|
72225
73108
|
else if (stale) process.stdout.write(`
|
|
72226
73109
|
${import_picocolors11.default.yellow("\u2191")} ${latest} is out; this copy is ${LOCAL_VERSION}. ${import_picocolors11.default.dim("agentgates update \xB7 installs it")}
|
|
72227
73110
|
|
|
@@ -72234,7 +73117,7 @@ async function update(opts = {}) {
|
|
|
72234
73117
|
}
|
|
72235
73118
|
if (place.kind === "checkout") {
|
|
72236
73119
|
const line2 = `cd ${place.dir} && git pull --ff-only && npm run build`;
|
|
72237
|
-
if (
|
|
73120
|
+
if (jsonMode6(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "checkout", line: line2, error: "this copy runs from a repository checkout; pull it" }, null, 2) + "\n");
|
|
72238
73121
|
else process.stdout.write(`
|
|
72239
73122
|
this copy runs from a checkout at ${import_picocolors11.default.bold(place.dir)}; update it with
|
|
72240
73123
|
${import_picocolors11.default.cyan(line2)}
|
|
@@ -72242,7 +73125,7 @@ async function update(opts = {}) {
|
|
|
72242
73125
|
`);
|
|
72243
73126
|
return;
|
|
72244
73127
|
}
|
|
72245
|
-
if (!
|
|
73128
|
+
if (!jsonMode6(opts)) process.stdout.write(`
|
|
72246
73129
|
${import_picocolors11.default.bold("UPDATE")} ${LOCAL_VERSION} \u2192 ${latest} ${import_picocolors11.default.dim(place.kind === "home" ? `into ${place.home}` : "the global npm install")}
|
|
72247
73130
|
${import_picocolors11.default.dim(`npm ${place.command.join(" ")}`)}
|
|
72248
73131
|
|
|
@@ -72250,7 +73133,7 @@ async function update(opts = {}) {
|
|
|
72250
73133
|
const code = await runNpm(place.command);
|
|
72251
73134
|
const now = installedVersionAt(place);
|
|
72252
73135
|
const done = code === 0 && (place.kind !== "home" || now === latest);
|
|
72253
|
-
if (
|
|
73136
|
+
if (jsonMode6(opts)) {
|
|
72254
73137
|
process.stdout.write(JSON.stringify({ ...base, ok: done, code: done ? void 0 : "npm_failed", installed: now ?? void 0, exit: code }, null, 2) + "\n");
|
|
72255
73138
|
} else if (done) {
|
|
72256
73139
|
process.stdout.write(`
|
|
@@ -72432,7 +73315,7 @@ async function onboard(opts = {}) {
|
|
|
72432
73315
|
if (stale) put(stale);
|
|
72433
73316
|
const order = menuOrder(opts.lane, !!account, latestSeen !== null).filter((k) => existing ? k !== "wallet" : true);
|
|
72434
73317
|
printMenu(put, order, true);
|
|
72435
|
-
const rl =
|
|
73318
|
+
const rl = createInterface2({ input: process.stdin, output: process.stdout });
|
|
72436
73319
|
const exitDefault = String(order.indexOf("poke") + 1);
|
|
72437
73320
|
let first = true;
|
|
72438
73321
|
let plain = put;
|
|
@@ -72590,7 +73473,7 @@ init_passwords_wire();
|
|
|
72590
73473
|
init_passwords_seal();
|
|
72591
73474
|
|
|
72592
73475
|
// src/lib/mcp-stdio.ts
|
|
72593
|
-
import { createInterface as
|
|
73476
|
+
import { createInterface as createInterface3 } from "node:readline";
|
|
72594
73477
|
var MCP_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
72595
73478
|
var McpToolError = class extends Error {
|
|
72596
73479
|
constructor(message, detail = {}) {
|
|
@@ -72607,7 +73490,7 @@ var INVALID_PARAMS = -32602;
|
|
|
72607
73490
|
function reply(id2, result) {
|
|
72608
73491
|
return { jsonrpc: "2.0", id: id2, result };
|
|
72609
73492
|
}
|
|
72610
|
-
function
|
|
73493
|
+
function fail3(id2, code, message, data4) {
|
|
72611
73494
|
return { jsonrpc: "2.0", id: id2, error: data4 === void 0 ? { code, message } : { code, message, data: data4 } };
|
|
72612
73495
|
}
|
|
72613
73496
|
function parseLine(line2) {
|
|
@@ -72615,10 +73498,10 @@ function parseLine(line2) {
|
|
|
72615
73498
|
if (!trimmed) return null;
|
|
72616
73499
|
try {
|
|
72617
73500
|
const parsed = JSON.parse(trimmed);
|
|
72618
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { response:
|
|
73501
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return { response: fail3(null, INVALID_REQUEST, "a JSON-RPC message is an object") };
|
|
72619
73502
|
return { message: parsed };
|
|
72620
73503
|
} catch {
|
|
72621
|
-
return { response:
|
|
73504
|
+
return { response: fail3(null, PARSE_ERROR, "the line is not JSON") };
|
|
72622
73505
|
}
|
|
72623
73506
|
}
|
|
72624
73507
|
var McpRich = class {
|
|
@@ -72653,7 +73536,7 @@ async function dispatch(message, tools, info) {
|
|
|
72653
73536
|
const id2 = message.id === void 0 ? null : message.id;
|
|
72654
73537
|
const isNotification = message.id === void 0;
|
|
72655
73538
|
if (typeof message.method !== "string") {
|
|
72656
|
-
return isNotification ? null :
|
|
73539
|
+
return isNotification ? null : fail3(id2, INVALID_REQUEST, "a request names a method");
|
|
72657
73540
|
}
|
|
72658
73541
|
const params = message.params && typeof message.params === "object" ? message.params : {};
|
|
72659
73542
|
switch (message.method) {
|
|
@@ -72679,7 +73562,7 @@ async function dispatch(message, tools, info) {
|
|
|
72679
73562
|
case "tools/call": {
|
|
72680
73563
|
const name = typeof params.name === "string" ? params.name : "";
|
|
72681
73564
|
const tool = tools.find((t) => t.name === name);
|
|
72682
|
-
if (!tool) return
|
|
73565
|
+
if (!tool) return fail3(id2, INVALID_PARAMS, `no tool named "${name}"`);
|
|
72683
73566
|
const args = params.arguments && typeof params.arguments === "object" && !Array.isArray(params.arguments) ? params.arguments : {};
|
|
72684
73567
|
try {
|
|
72685
73568
|
return reply(id2, toolResult(await tool.handler(args)));
|
|
@@ -72694,7 +73577,7 @@ async function dispatch(message, tools, info) {
|
|
|
72694
73577
|
case "prompts/list":
|
|
72695
73578
|
return reply(id2, { prompts: [] });
|
|
72696
73579
|
default:
|
|
72697
|
-
return isNotification ? null :
|
|
73580
|
+
return isNotification ? null : fail3(id2, METHOD_NOT_FOUND, `no method "${message.method}"`);
|
|
72698
73581
|
}
|
|
72699
73582
|
}
|
|
72700
73583
|
async function serve(tools, info, { input = process.stdin, output: output2 = process.stdout } = {}) {
|
|
@@ -72703,7 +73586,7 @@ async function serve(tools, info, { input = process.stdin, output: output2 = pro
|
|
|
72703
73586
|
`);
|
|
72704
73587
|
};
|
|
72705
73588
|
const inFlight = /* @__PURE__ */ new Set();
|
|
72706
|
-
const lines =
|
|
73589
|
+
const lines = createInterface3({ input, crlfDelay: Infinity });
|
|
72707
73590
|
for await (const line2 of lines) {
|
|
72708
73591
|
const parsed = parseLine(line2);
|
|
72709
73592
|
if (!parsed) continue;
|
|
@@ -72715,7 +73598,7 @@ async function serve(tools, info, { input = process.stdin, output: output2 = pro
|
|
|
72715
73598
|
if (response) send2(response);
|
|
72716
73599
|
}).catch((err) => {
|
|
72717
73600
|
const id2 = parsed.message.id === void 0 ? null : parsed.message.id;
|
|
72718
|
-
if (id2 !== null) send2(
|
|
73601
|
+
if (id2 !== null) send2(fail3(id2, -32603, err instanceof Error ? err.message : String(err)));
|
|
72719
73602
|
}).finally(() => {
|
|
72720
73603
|
inFlight.delete(job);
|
|
72721
73604
|
});
|
|
@@ -73007,7 +73890,7 @@ function emit6(opts, data4, human) {
|
|
|
73007
73890
|
}
|
|
73008
73891
|
human();
|
|
73009
73892
|
}
|
|
73010
|
-
function
|
|
73893
|
+
function fail4(opts, err) {
|
|
73011
73894
|
const message = err instanceof Error ? err.message : String(err);
|
|
73012
73895
|
const code = err?.code;
|
|
73013
73896
|
if (opts.json || !process.stdout.isTTY) {
|
|
@@ -73108,7 +73991,7 @@ async function memoryOverview(opts) {
|
|
|
73108
73991
|
process.stdout.write("\n");
|
|
73109
73992
|
});
|
|
73110
73993
|
} catch (err) {
|
|
73111
|
-
|
|
73994
|
+
fail4(opts, err);
|
|
73112
73995
|
}
|
|
73113
73996
|
}
|
|
73114
73997
|
async function memoryMkdir(folder, opts) {
|
|
@@ -73121,7 +74004,7 @@ async function memoryMkdir(folder, opts) {
|
|
|
73121
74004
|
|
|
73122
74005
|
`));
|
|
73123
74006
|
} catch (err) {
|
|
73124
|
-
|
|
74007
|
+
fail4(opts, err);
|
|
73125
74008
|
}
|
|
73126
74009
|
}
|
|
73127
74010
|
async function memoryRmdir(folder, opts) {
|
|
@@ -73134,7 +74017,7 @@ async function memoryRmdir(folder, opts) {
|
|
|
73134
74017
|
|
|
73135
74018
|
`));
|
|
73136
74019
|
} catch (err) {
|
|
73137
|
-
|
|
74020
|
+
fail4(opts, err);
|
|
73138
74021
|
}
|
|
73139
74022
|
}
|
|
73140
74023
|
async function memoryLs(target, opts) {
|
|
@@ -73188,7 +74071,7 @@ async function memoryLs(target, opts) {
|
|
|
73188
74071
|
process.stdout.write("\n");
|
|
73189
74072
|
});
|
|
73190
74073
|
} catch (err) {
|
|
73191
|
-
|
|
74074
|
+
fail4(opts, err);
|
|
73192
74075
|
}
|
|
73193
74076
|
}
|
|
73194
74077
|
async function memorySources(opts) {
|
|
@@ -73217,7 +74100,7 @@ async function memorySources(opts) {
|
|
|
73217
74100
|
process.stdout.write("\n");
|
|
73218
74101
|
});
|
|
73219
74102
|
} catch (err) {
|
|
73220
|
-
|
|
74103
|
+
fail4(opts, err);
|
|
73221
74104
|
}
|
|
73222
74105
|
}
|
|
73223
74106
|
async function memoryCat(path8, opts) {
|
|
@@ -73244,7 +74127,7 @@ async function memoryCat(path8, opts) {
|
|
|
73244
74127
|
emit6(opts, { ok: true, folder, name, id: row.id, version: row.version, updatedAt: row.updatedAt, text }, () => process.stdout.write(text.endsWith("\n") ? text : `${text}
|
|
73245
74128
|
`));
|
|
73246
74129
|
} catch (err) {
|
|
73247
|
-
|
|
74130
|
+
fail4(opts, err);
|
|
73248
74131
|
}
|
|
73249
74132
|
}
|
|
73250
74133
|
async function memoryPut(path8, opts) {
|
|
@@ -73267,7 +74150,7 @@ async function memoryPut(path8, opts) {
|
|
|
73267
74150
|
`)
|
|
73268
74151
|
);
|
|
73269
74152
|
} catch (err) {
|
|
73270
|
-
|
|
74153
|
+
fail4(opts, err);
|
|
73271
74154
|
}
|
|
73272
74155
|
}
|
|
73273
74156
|
async function memoryRm(path8, opts) {
|
|
@@ -73284,7 +74167,7 @@ async function memoryRm(path8, opts) {
|
|
|
73284
74167
|
|
|
73285
74168
|
`));
|
|
73286
74169
|
} catch (err) {
|
|
73287
|
-
|
|
74170
|
+
fail4(opts, err);
|
|
73288
74171
|
}
|
|
73289
74172
|
}
|
|
73290
74173
|
async function openAbout(wallet) {
|
|
@@ -73341,7 +74224,7 @@ async function memoryAbout(opts) {
|
|
|
73341
74224
|
process.stdout.write("\n");
|
|
73342
74225
|
});
|
|
73343
74226
|
} catch (err) {
|
|
73344
|
-
|
|
74227
|
+
fail4(opts, err);
|
|
73345
74228
|
}
|
|
73346
74229
|
}
|
|
73347
74230
|
async function grepMemory(wallet, key, pattern, folders) {
|
|
@@ -73390,7 +74273,7 @@ async function memoryGrep(patternRaw, folder, opts) {
|
|
|
73390
74273
|
`);
|
|
73391
74274
|
});
|
|
73392
74275
|
} catch (err) {
|
|
73393
|
-
|
|
74276
|
+
fail4(opts, err);
|
|
73394
74277
|
}
|
|
73395
74278
|
}
|
|
73396
74279
|
async function readStdin() {
|
|
@@ -73633,7 +74516,7 @@ function emit7(opts, data4, human) {
|
|
|
73633
74516
|
}
|
|
73634
74517
|
human();
|
|
73635
74518
|
}
|
|
73636
|
-
function
|
|
74519
|
+
function fail5(opts, err) {
|
|
73637
74520
|
const message = err instanceof Error ? err.message : String(err);
|
|
73638
74521
|
const code = err?.code;
|
|
73639
74522
|
if (opts.json || !process.stdout.isTTY) {
|
|
@@ -73862,7 +74745,7 @@ async function filesList(folderArg, opts) {
|
|
|
73862
74745
|
process.stdout.write("\n");
|
|
73863
74746
|
});
|
|
73864
74747
|
} catch (err) {
|
|
73865
|
-
|
|
74748
|
+
fail5(opts, err);
|
|
73866
74749
|
}
|
|
73867
74750
|
}
|
|
73868
74751
|
async function filesPut(path8, opts) {
|
|
@@ -73882,7 +74765,7 @@ async function filesPut(path8, opts) {
|
|
|
73882
74765
|
`)
|
|
73883
74766
|
);
|
|
73884
74767
|
} catch (err) {
|
|
73885
|
-
|
|
74768
|
+
fail5(opts, err);
|
|
73886
74769
|
}
|
|
73887
74770
|
}
|
|
73888
74771
|
async function filesGet(target, opts) {
|
|
@@ -73903,7 +74786,7 @@ async function filesGet(target, opts) {
|
|
|
73903
74786
|
`)
|
|
73904
74787
|
);
|
|
73905
74788
|
} catch (err) {
|
|
73906
|
-
|
|
74789
|
+
fail5(opts, err);
|
|
73907
74790
|
}
|
|
73908
74791
|
}
|
|
73909
74792
|
async function moveOpened(wallet, key, dataPublicKey, file, folder) {
|
|
@@ -73932,7 +74815,7 @@ async function filesMv(target, folderArg, opts) {
|
|
|
73932
74815
|
`)
|
|
73933
74816
|
);
|
|
73934
74817
|
} catch (err) {
|
|
73935
|
-
|
|
74818
|
+
fail5(opts, err);
|
|
73936
74819
|
}
|
|
73937
74820
|
}
|
|
73938
74821
|
async function filesRm(target, opts) {
|
|
@@ -73951,13 +74834,13 @@ async function filesRm(target, opts) {
|
|
|
73951
74834
|
`)
|
|
73952
74835
|
);
|
|
73953
74836
|
} catch (err) {
|
|
73954
|
-
|
|
74837
|
+
fail5(opts, err);
|
|
73955
74838
|
}
|
|
73956
74839
|
}
|
|
73957
74840
|
|
|
73958
74841
|
// src/commands/card.ts
|
|
73959
74842
|
var import_picocolors15 = __toESM(require_picocolors(), 1);
|
|
73960
|
-
import { createInterface as
|
|
74843
|
+
import { createInterface as createInterface4 } from "node:readline/promises";
|
|
73961
74844
|
|
|
73962
74845
|
// src/lib/memory-address.ts
|
|
73963
74846
|
var ADDRESS_FOLDER = "profile";
|
|
@@ -74435,7 +75318,7 @@ function emit8(opts, data4, human) {
|
|
|
74435
75318
|
}
|
|
74436
75319
|
human();
|
|
74437
75320
|
}
|
|
74438
|
-
function
|
|
75321
|
+
function fail6(opts, err) {
|
|
74439
75322
|
const message = err instanceof Error ? err.message : String(err);
|
|
74440
75323
|
const code = err?.code;
|
|
74441
75324
|
if (opts.json || !process.stdout.isTTY) {
|
|
@@ -74499,7 +75382,7 @@ var QUESTIONS = [
|
|
|
74499
75382
|
{ field: "zip", ask: "ZIP code", abroad: "Postal code" }
|
|
74500
75383
|
];
|
|
74501
75384
|
async function askAddress() {
|
|
74502
|
-
const rl =
|
|
75385
|
+
const rl = createInterface4({ input: process.stdin, output: process.stdout });
|
|
74503
75386
|
const answers = { country: "US", line1: "", line2: "", city: "", region: "", zip: "" };
|
|
74504
75387
|
try {
|
|
74505
75388
|
process.stdout.write(`
|
|
@@ -74581,7 +75464,7 @@ async function cardAddressSet(opts) {
|
|
|
74581
75464
|
`)
|
|
74582
75465
|
);
|
|
74583
75466
|
} catch (err) {
|
|
74584
|
-
|
|
75467
|
+
fail6(opts, err);
|
|
74585
75468
|
}
|
|
74586
75469
|
}
|
|
74587
75470
|
async function cardAddressShow(opts) {
|
|
@@ -74608,7 +75491,7 @@ ${lines.map((l) => ` ${l}`).join("\n")}
|
|
|
74608
75491
|
`)
|
|
74609
75492
|
);
|
|
74610
75493
|
} catch (err) {
|
|
74611
|
-
|
|
75494
|
+
fail6(opts, err);
|
|
74612
75495
|
}
|
|
74613
75496
|
}
|
|
74614
75497
|
async function cardAddressClear(opts) {
|
|
@@ -74624,7 +75507,7 @@ async function cardAddressClear(opts) {
|
|
|
74624
75507
|
`)
|
|
74625
75508
|
);
|
|
74626
75509
|
} catch (err) {
|
|
74627
|
-
|
|
75510
|
+
fail6(opts, err);
|
|
74628
75511
|
}
|
|
74629
75512
|
}
|
|
74630
75513
|
|
|
@@ -75495,9 +76378,9 @@ function usdOf(micro) {
|
|
|
75495
76378
|
const rest = (n2 % 1000000n).toString().padStart(6, "0").replace(/0+$/, "");
|
|
75496
76379
|
return rest ? `${whole}.${rest}` : `${whole}`;
|
|
75497
76380
|
}
|
|
75498
|
-
function microOf(
|
|
75499
|
-
const clean3 =
|
|
75500
|
-
if (!/^\d+(\.\d{1,6})?$/.test(clean3)) throw new Error(`a dollar amount, like 40 or 12.50 (got ${
|
|
76381
|
+
function microOf(usd6) {
|
|
76382
|
+
const clean3 = usd6.trim().replace(/^\$/, "");
|
|
76383
|
+
if (!/^\d+(\.\d{1,6})?$/.test(clean3)) throw new Error(`a dollar amount, like 40 or 12.50 (got ${usd6})`);
|
|
75501
76384
|
const [whole, frac = ""] = clean3.split(".");
|
|
75502
76385
|
return (BigInt(whole) * 1000000n + BigInt((frac + "000000").slice(0, 6))).toString();
|
|
75503
76386
|
}
|
|
@@ -75521,16 +76404,16 @@ function firstSentence(words7) {
|
|
|
75521
76404
|
}
|
|
75522
76405
|
|
|
75523
76406
|
// src/commands/intents.ts
|
|
75524
|
-
var
|
|
76407
|
+
var jsonMode7 = (opts) => opts.json === true || !process.stdout.isTTY;
|
|
75525
76408
|
function emit9(opts, data4, human) {
|
|
75526
|
-
if (
|
|
76409
|
+
if (jsonMode7(opts)) {
|
|
75527
76410
|
process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
|
|
75528
76411
|
return;
|
|
75529
76412
|
}
|
|
75530
76413
|
human();
|
|
75531
76414
|
}
|
|
75532
76415
|
function refuse5(opts, error, code, extra = {}) {
|
|
75533
|
-
if (
|
|
76416
|
+
if (jsonMode7(opts)) {
|
|
75534
76417
|
process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
|
|
75535
76418
|
} else {
|
|
75536
76419
|
process.stderr.write(` ${error}${code ? import_picocolors17.default.dim(` (${code})`) : ""}
|
|
@@ -76174,6 +77057,7 @@ async function intentsNoShow(askId, opts) {
|
|
|
76174
77057
|
|
|
76175
77058
|
// src/commands/integrations.ts
|
|
76176
77059
|
var import_picocolors18 = __toESM(require_picocolors(), 1);
|
|
77060
|
+
import { createHash as createHash6, randomBytes as randomBytes9 } from "node:crypto";
|
|
76177
77061
|
init_passwords_wire();
|
|
76178
77062
|
function emit10(opts, data4, human) {
|
|
76179
77063
|
if (opts.json || !process.stdout.isTTY) {
|
|
@@ -76183,7 +77067,7 @@ function emit10(opts, data4, human) {
|
|
|
76183
77067
|
}
|
|
76184
77068
|
human();
|
|
76185
77069
|
}
|
|
76186
|
-
function
|
|
77070
|
+
function fail7(opts, err) {
|
|
76187
77071
|
const message = err instanceof Error ? err.message : String(err);
|
|
76188
77072
|
const code = err instanceof WireError ? err.code : err?.code;
|
|
76189
77073
|
if (opts.json || !process.stdout.isTTY) {
|
|
@@ -76246,7 +77130,7 @@ async function integrationsList(opts) {
|
|
|
76246
77130
|
}
|
|
76247
77131
|
});
|
|
76248
77132
|
} catch (err) {
|
|
76249
|
-
|
|
77133
|
+
fail7(opts, err);
|
|
76250
77134
|
}
|
|
76251
77135
|
}
|
|
76252
77136
|
var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -76306,7 +77190,7 @@ async function integrationsUse(integrationId, opts) {
|
|
|
76306
77190
|
return;
|
|
76307
77191
|
}
|
|
76308
77192
|
} catch (err) {
|
|
76309
|
-
|
|
77193
|
+
fail7(opts, err);
|
|
76310
77194
|
}
|
|
76311
77195
|
}
|
|
76312
77196
|
async function integrationsSignup(provider, opts) {
|
|
@@ -76325,7 +77209,7 @@ async function integrationsSignup(provider, opts) {
|
|
|
76325
77209
|
`);
|
|
76326
77210
|
});
|
|
76327
77211
|
} catch (err) {
|
|
76328
|
-
|
|
77212
|
+
fail7(opts, err);
|
|
76329
77213
|
}
|
|
76330
77214
|
}
|
|
76331
77215
|
async function integrationsSignupReport(signupId, opts) {
|
|
@@ -76340,7 +77224,7 @@ async function integrationsSignupReport(signupId, opts) {
|
|
|
76340
77224
|
`);
|
|
76341
77225
|
});
|
|
76342
77226
|
} catch (err) {
|
|
76343
|
-
|
|
77227
|
+
fail7(opts, err);
|
|
76344
77228
|
}
|
|
76345
77229
|
}
|
|
76346
77230
|
async function integrationsSignupHandoff(signupId, provider, opts) {
|
|
@@ -76365,7 +77249,7 @@ async function integrationsSignupHandoff(signupId, provider, opts) {
|
|
|
76365
77249
|
`);
|
|
76366
77250
|
});
|
|
76367
77251
|
} catch (err) {
|
|
76368
|
-
|
|
77252
|
+
fail7(opts, err);
|
|
76369
77253
|
}
|
|
76370
77254
|
}
|
|
76371
77255
|
async function sitesList(opts) {
|
|
@@ -76402,7 +77286,7 @@ async function sitesList(opts) {
|
|
|
76402
77286
|
}
|
|
76403
77287
|
});
|
|
76404
77288
|
} catch (err) {
|
|
76405
|
-
|
|
77289
|
+
fail7(opts, err);
|
|
76406
77290
|
}
|
|
76407
77291
|
}
|
|
76408
77292
|
var CHANGE_ID_RE = /^[A-Za-z0-9_-]{22}$/;
|
|
@@ -76436,7 +77320,7 @@ async function sitesChange(changeId, opts) {
|
|
|
76436
77320
|
process.stdout.write("\n");
|
|
76437
77321
|
});
|
|
76438
77322
|
} catch (err) {
|
|
76439
|
-
|
|
77323
|
+
fail7(opts, err);
|
|
76440
77324
|
}
|
|
76441
77325
|
}
|
|
76442
77326
|
async function sitesShip(changeId, opts) {
|
|
@@ -76454,7 +77338,7 @@ async function sitesShip(changeId, opts) {
|
|
|
76454
77338
|
`);
|
|
76455
77339
|
});
|
|
76456
77340
|
} catch (err) {
|
|
76457
|
-
|
|
77341
|
+
fail7(opts, err);
|
|
76458
77342
|
}
|
|
76459
77343
|
}
|
|
76460
77344
|
async function sitesSkip(changeId, opts) {
|
|
@@ -76469,7 +77353,115 @@ async function sitesSkip(changeId, opts) {
|
|
|
76469
77353
|
`);
|
|
76470
77354
|
});
|
|
76471
77355
|
} catch (err) {
|
|
76472
|
-
|
|
77356
|
+
fail7(opts, err);
|
|
77357
|
+
}
|
|
77358
|
+
}
|
|
77359
|
+
async function sitesUndo(changeId, opts) {
|
|
77360
|
+
try {
|
|
77361
|
+
if (!CHANGE_ID_RE.test(changeId)) throw new Error("a change id is 22 characters (the one the card's link ends in)");
|
|
77362
|
+
const { wallet } = await requirePasswordsKey();
|
|
77363
|
+
const out = expectOk(await signedFetch(wallet, "POST", lanePath(`/sites/changes/${changeId}/undo`)), "sites undo");
|
|
77364
|
+
emit10(opts, { ok: true, change: out.change }, () => {
|
|
77365
|
+
process.stdout.write(`
|
|
77366
|
+
${import_picocolors18.default.yellow(out.change.state)} ${import_picocolors18.default.dim(out.change.id)}
|
|
77367
|
+
|
|
77368
|
+
`);
|
|
77369
|
+
});
|
|
77370
|
+
} catch (err) {
|
|
77371
|
+
fail7(opts, err);
|
|
77372
|
+
}
|
|
77373
|
+
}
|
|
77374
|
+
async function sitesFix(changeId, opts) {
|
|
77375
|
+
try {
|
|
77376
|
+
if (!CHANGE_ID_RE.test(changeId)) throw new Error("a change id is 22 characters (the one the card's link ends in)");
|
|
77377
|
+
const { wallet } = await requirePasswordsKey();
|
|
77378
|
+
const read = expectOk(await signedFetch(wallet, "GET", lanePath(`/sites/changes/${changeId}`)), "sites change");
|
|
77379
|
+
if (read.change?.state !== "failed" || read.change.code !== "ship_check_failed") throw new Error(`the change is ${read.change?.state ?? "unread"}: only a change the live check stopped is fixed`);
|
|
77380
|
+
const body = { appId: read.change.appId, id: randomBytes9(16).toString("base64url") };
|
|
77381
|
+
const digest = createHash6("sha256").update(JSON.stringify(body), "utf8").digest("base64url");
|
|
77382
|
+
const out = expectOk(await signedFetch(wallet, "POST", lanePath(`/sites/changes/${changeId}/fix/${digest}`), body), "sites fix");
|
|
77383
|
+
emit10(opts, { ok: true, change: out.change }, () => {
|
|
77384
|
+
process.stdout.write(`
|
|
77385
|
+
${import_picocolors18.default.green(out.change.state)} ${import_picocolors18.default.dim(`the fix is change ${out.change.id}`)}
|
|
77386
|
+
|
|
77387
|
+
`);
|
|
77388
|
+
});
|
|
77389
|
+
} catch (err) {
|
|
77390
|
+
fail7(opts, err);
|
|
77391
|
+
}
|
|
77392
|
+
}
|
|
77393
|
+
function askOf(dataKey, owner, ask) {
|
|
77394
|
+
if (!ask) return null;
|
|
77395
|
+
try {
|
|
77396
|
+
const aad = `AGENTGATES-CONVERSATION-v1|turn|${normalizeOwner2(owner)}|${ask.conversationId}|${ask.seq}|${ask.role}${ask.author ? `|${ask.author}|${ask.channel ?? ""}` : ""}`;
|
|
77397
|
+
const text = openText(dataKey, ask.ciphertext, aad);
|
|
77398
|
+
if (ask.author === "card") {
|
|
77399
|
+
const words7 = JSON.parse(text).words ?? "";
|
|
77400
|
+
return words7 ? `Fix: ${words7.split("\n")[0].trim()}` : null;
|
|
77401
|
+
}
|
|
77402
|
+
const m = /^Asked for a change on site [A-Za-z0-9_-]{22}: ([\s\S]*)$/.exec(text.trim());
|
|
77403
|
+
return (m ? m[1] : text).trim() || null;
|
|
77404
|
+
} catch {
|
|
77405
|
+
return null;
|
|
77406
|
+
}
|
|
77407
|
+
}
|
|
77408
|
+
async function sitesChanges(siteId, opts) {
|
|
77409
|
+
try {
|
|
77410
|
+
if (!CHANGE_ID_RE.test(siteId)) throw new Error("a site id is 22 characters (agentgates sites lists them)");
|
|
77411
|
+
if (opts.before && !CHANGE_ID_RE.test(opts.before)) throw new Error("--before takes the last change id of the page before");
|
|
77412
|
+
const { wallet } = await requirePasswordsKey();
|
|
77413
|
+
const q = opts.before ? `?before=${encodeURIComponent(opts.before)}` : "";
|
|
77414
|
+
const out = expectOk(await signedFetch(wallet, "GET", lanePath(`/sites/${siteId}/changes${q}`)), "sites changes");
|
|
77415
|
+
const key = await mailKeyFor(wallet).catch(() => null);
|
|
77416
|
+
const rows = (out.changes ?? []).map((c) => {
|
|
77417
|
+
let done = null;
|
|
77418
|
+
if (key && c.card) {
|
|
77419
|
+
try {
|
|
77420
|
+
done = (JSON.parse(openText(key.dataKey, c.card.ciphertext, cardAad(wallet.address, c.card))).words ?? "").split("\n")[0].trim() || null;
|
|
77421
|
+
} catch {
|
|
77422
|
+
done = null;
|
|
77423
|
+
}
|
|
77424
|
+
}
|
|
77425
|
+
const asked = key ? askOf(key.dataKey, wallet.address, c.ask) : null;
|
|
77426
|
+
return { id: c.id, state: c.state, code: c.code, round: c.round, costMicro: c.costMicro, updatedAt: c.updatedAt, title: done ?? asked ?? (c.round === 0 ? "Merged on GitHub" : null) };
|
|
77427
|
+
});
|
|
77428
|
+
emit10(opts, { ok: true, changes: rows, next: out.next ?? null }, () => {
|
|
77429
|
+
if (!rows.length) {
|
|
77430
|
+
process.stdout.write(`
|
|
77431
|
+
${import_picocolors18.default.dim("No changes yet.")}
|
|
77432
|
+
|
|
77433
|
+
`);
|
|
77434
|
+
return;
|
|
77435
|
+
}
|
|
77436
|
+
process.stdout.write("\n");
|
|
77437
|
+
for (const r of rows) {
|
|
77438
|
+
const state = r.state === "live" ? import_picocolors18.default.green("live") : r.state === "ready" ? import_picocolors18.default.cyan("ready") : import_picocolors18.default.yellow(r.code ?? r.state);
|
|
77439
|
+
process.stdout.write(` ${state} ${r.title ?? import_picocolors18.default.dim("(no words open here)")}
|
|
77440
|
+
${import_picocolors18.default.dim(`${r.id} ${r.updatedAt}`)}
|
|
77441
|
+
|
|
77442
|
+
`);
|
|
77443
|
+
}
|
|
77444
|
+
if (out.next) process.stdout.write(` ${import_picocolors18.default.dim(`older: agentgates sites changes ${siteId} --before ${out.next}`)}
|
|
77445
|
+
|
|
77446
|
+
`);
|
|
77447
|
+
});
|
|
77448
|
+
} catch (err) {
|
|
77449
|
+
fail7(opts, err);
|
|
77450
|
+
}
|
|
77451
|
+
}
|
|
77452
|
+
async function sitesRemove(siteId, opts) {
|
|
77453
|
+
try {
|
|
77454
|
+
if (!CHANGE_ID_RE.test(siteId)) throw new Error("a site id is 22 characters (agentgates sites lists them)");
|
|
77455
|
+
const { wallet } = await requirePasswordsKey();
|
|
77456
|
+
const out = expectOk(await signedFetch(wallet, "POST", lanePath(`/sites/${siteId}/remove`)), "sites remove");
|
|
77457
|
+
emit10(opts, { ok: true, id: out.id, state: out.state }, () => {
|
|
77458
|
+
process.stdout.write(`
|
|
77459
|
+
${import_picocolors18.default.yellow(out.state)} ${import_picocolors18.default.dim(out.id)}
|
|
77460
|
+
|
|
77461
|
+
`);
|
|
77462
|
+
});
|
|
77463
|
+
} catch (err) {
|
|
77464
|
+
fail7(opts, err);
|
|
76473
77465
|
}
|
|
76474
77466
|
}
|
|
76475
77467
|
|
|
@@ -76480,7 +77472,7 @@ init_passwords_wire();
|
|
|
76480
77472
|
|
|
76481
77473
|
// src/lib/ag-wire.ts
|
|
76482
77474
|
init_constants();
|
|
76483
|
-
import { createHash as
|
|
77475
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
76484
77476
|
|
|
76485
77477
|
// src/lib/conversation-seal.ts
|
|
76486
77478
|
var CONVERSATION_SUITE = "AGENTGATES-CONVERSATION-v1";
|
|
@@ -76531,7 +77523,7 @@ function agMemoryKeyAad(ownerWallet, keyId) {
|
|
|
76531
77523
|
return `${AG_SEAL_SUITE}|memory-key|${normalizeAgOwner(ownerWallet)}|${keyId}`;
|
|
76532
77524
|
}
|
|
76533
77525
|
function fleetBindingReportData(publicKey) {
|
|
76534
|
-
return
|
|
77526
|
+
return createHash7("sha512").update(Buffer.from(AG_REPORT_DATA_LABEL, "utf8")).update(Buffer.from(fromB64u2(publicKey))).digest("hex");
|
|
76535
77527
|
}
|
|
76536
77528
|
function parseAgAttestation(raw) {
|
|
76537
77529
|
const a = raw && typeof raw === "object" ? raw : null;
|
|
@@ -76578,7 +77570,7 @@ function verifyAgFleetAttestation(body, opts) {
|
|
|
76578
77570
|
now: opts.now
|
|
76579
77571
|
});
|
|
76580
77572
|
if (!proof.ok) return proof;
|
|
76581
|
-
if (att.keyId !==
|
|
77573
|
+
if (att.keyId !== createHash7("sha256").update(fromB64u2(att.publicKey)).digest("base64url")) {
|
|
76582
77574
|
return { ok: false, reason: "the served key id is not the hash of the served key" };
|
|
76583
77575
|
}
|
|
76584
77576
|
return { ok: true, value: att };
|
|
@@ -76603,8 +77595,14 @@ async function readAgAttestation() {
|
|
|
76603
77595
|
if (!proven.ok) throw new WireError(0, "box_unproven", `the AG AI box did not prove itself (${proven.reason}), so nothing was sealed`, null);
|
|
76604
77596
|
return proven.value;
|
|
76605
77597
|
}
|
|
76606
|
-
async function readAgent(wallet) {
|
|
76607
|
-
return expectOk(await signedFetch(wallet, "GET", lanePath("/ag/agent")), "agent");
|
|
77598
|
+
async function readAgent(wallet, opts = {}) {
|
|
77599
|
+
return expectOk(await signedFetch(wallet, "GET", lanePath(opts.turnOn ? "/ag/agent?turnOn=1" : "/ag/agent")), "agent");
|
|
77600
|
+
}
|
|
77601
|
+
function agentProofMessage(ownerWallet, agentAddress, nonce) {
|
|
77602
|
+
return `Agentgates: turn on my agent
|
|
77603
|
+
account: ${normalizeAgOwner(ownerWallet)}
|
|
77604
|
+
agent: ${normalizeAgOwner(agentAddress)}
|
|
77605
|
+
nonce: ${nonce}`;
|
|
76608
77606
|
}
|
|
76609
77607
|
async function postAgentOn(wallet, body) {
|
|
76610
77608
|
return expectOk(await signedFetch(wallet, "POST", lanePath("/ag/agent"), body), "agent on");
|
|
@@ -76677,7 +77675,7 @@ function emit11(opts, data4, human) {
|
|
|
76677
77675
|
}
|
|
76678
77676
|
human();
|
|
76679
77677
|
}
|
|
76680
|
-
function
|
|
77678
|
+
function fail8(opts, err) {
|
|
76681
77679
|
const message = err instanceof Error ? err.message : String(err);
|
|
76682
77680
|
const code = err?.code;
|
|
76683
77681
|
if (opts.json || !process.stdout.isTTY) {
|
|
@@ -76733,7 +77731,7 @@ async function agentStatus(opts) {
|
|
|
76733
77731
|
process.stdout.write("\n");
|
|
76734
77732
|
});
|
|
76735
77733
|
} catch (err) {
|
|
76736
|
-
|
|
77734
|
+
fail8(opts, err);
|
|
76737
77735
|
}
|
|
76738
77736
|
}
|
|
76739
77737
|
async function agentOn(opts) {
|
|
@@ -76746,7 +77744,10 @@ async function agentOn(opts) {
|
|
|
76746
77744
|
if (!seal) throw new WireError(409, "seal_missing", "seal this account first (agentgates email seal): the agent's thread is written to your Memory, and Memory seals to your account's key", null);
|
|
76747
77745
|
const account = await mailKeyFor(wallet);
|
|
76748
77746
|
if (!account) throw new WireError(409, "no_key", "this machine holds no copy of the account's data key", null);
|
|
77747
|
+
const { turnOnNonce } = await readAgent(wallet, { turnOn: true });
|
|
77748
|
+
if (!turnOnNonce) throw new WireError(409, "turn_on_nonce", "the agent door gave no turn-on code, so nothing was turned on: try again", null);
|
|
76749
77749
|
const agent2 = ethers_exports.Wallet.createRandom();
|
|
77750
|
+
const proof = { nonce: turnOnNonce, signature: await agent2.signMessage(agentProofMessage(wallet.address, agent2.address, turnOnNonce)) };
|
|
76750
77751
|
const aad = agWalletKeyAad(wallet.address);
|
|
76751
77752
|
const keyOwnerBlob = sealText(seal.sealingPublicKey, agent2.privateKey, aad);
|
|
76752
77753
|
const keyBoxBlob = sealText(fleet.publicKey, agent2.privateKey, aad);
|
|
@@ -76756,7 +77757,7 @@ async function agentOn(opts) {
|
|
|
76756
77757
|
const pair = keySealingKeyFromParts({ wire: made.key, reading });
|
|
76757
77758
|
await putKeyWrap(wallet, made.created.id, { sealingPublicKey: pair.publicKey, wrap: sealTo(pair.publicKey, account.dataKey, keyWrapAad(keys2.state.address, made.created.id)) });
|
|
76758
77759
|
const memoryKeyBoxBlob = sealText(fleet.publicKey, JSON.stringify({ wire: made.key, reading }), agMemoryKeyAad(wallet.address, made.created.id));
|
|
76759
|
-
const out = await postAgentOn(wallet, { agentAddress: agent2.address, keyOwnerBlob, keyBoxBlob, memoryKeyId: made.created.id, memoryKeyBoxBlob });
|
|
77760
|
+
const out = await postAgentOn(wallet, { agentAddress: agent2.address, keyOwnerBlob, keyBoxBlob, memoryKeyId: made.created.id, memoryKeyBoxBlob, proof });
|
|
76760
77761
|
const note2 = opts.fund !== void 0 ? AGENT_PAYS_SENTENCE : null;
|
|
76761
77762
|
emit11(opts, { ok: true, agent: out.agent, memoryKeyId: made.created.id, fleet: { mode: fleet.mode, keyId: fleet.keyId }, ...note2 ? { note: note2 } : {} }, () => {
|
|
76762
77763
|
process.stdout.write(
|
|
@@ -76775,7 +77776,7 @@ async function agentOn(opts) {
|
|
|
76775
77776
|
throw err;
|
|
76776
77777
|
}
|
|
76777
77778
|
} catch (err) {
|
|
76778
|
-
|
|
77779
|
+
fail8(opts, err);
|
|
76779
77780
|
}
|
|
76780
77781
|
}
|
|
76781
77782
|
async function agentOff(opts) {
|
|
@@ -76800,14 +77801,14 @@ async function agentOff(opts) {
|
|
|
76800
77801
|
`);
|
|
76801
77802
|
});
|
|
76802
77803
|
} catch (err) {
|
|
76803
|
-
|
|
77804
|
+
fail8(opts, err);
|
|
76804
77805
|
}
|
|
76805
77806
|
}
|
|
76806
77807
|
async function agentFund(_amountUsd, opts) {
|
|
76807
|
-
|
|
77808
|
+
fail8(opts, agentPaysRefusal());
|
|
76808
77809
|
}
|
|
76809
77810
|
async function agentRefill(_action, opts) {
|
|
76810
|
-
|
|
77811
|
+
fail8(opts, agentPaysRefusal());
|
|
76811
77812
|
}
|
|
76812
77813
|
async function agentSay(text, opts) {
|
|
76813
77814
|
try {
|
|
@@ -76820,7 +77821,7 @@ async function agentSay(text, opts) {
|
|
|
76820
77821
|
`);
|
|
76821
77822
|
});
|
|
76822
77823
|
} catch (err) {
|
|
76823
|
-
|
|
77824
|
+
fail8(opts, err);
|
|
76824
77825
|
}
|
|
76825
77826
|
}
|
|
76826
77827
|
async function agentJournal(opts) {
|
|
@@ -76849,7 +77850,7 @@ async function agentJournal(opts) {
|
|
|
76849
77850
|
process.stdout.write("\n");
|
|
76850
77851
|
});
|
|
76851
77852
|
} catch (err) {
|
|
76852
|
-
|
|
77853
|
+
fail8(opts, err);
|
|
76853
77854
|
}
|
|
76854
77855
|
}
|
|
76855
77856
|
async function agentBind(channel, senderId, opts) {
|
|
@@ -76909,7 +77910,7 @@ async function agentBind(channel, senderId, opts) {
|
|
|
76909
77910
|
`);
|
|
76910
77911
|
});
|
|
76911
77912
|
} catch (err) {
|
|
76912
|
-
|
|
77913
|
+
fail8(opts, err);
|
|
76913
77914
|
}
|
|
76914
77915
|
}
|
|
76915
77916
|
async function agentBindings(opts) {
|
|
@@ -76930,7 +77931,7 @@ async function agentBindings(opts) {
|
|
|
76930
77931
|
process.stdout.write("\n");
|
|
76931
77932
|
});
|
|
76932
77933
|
} catch (err) {
|
|
76933
|
-
|
|
77934
|
+
fail8(opts, err);
|
|
76934
77935
|
}
|
|
76935
77936
|
}
|
|
76936
77937
|
async function agentUnbind(id2, opts) {
|
|
@@ -76945,7 +77946,7 @@ async function agentUnbind(id2, opts) {
|
|
|
76945
77946
|
`);
|
|
76946
77947
|
});
|
|
76947
77948
|
} catch (err) {
|
|
76948
|
-
|
|
77949
|
+
fail8(opts, err);
|
|
76949
77950
|
}
|
|
76950
77951
|
}
|
|
76951
77952
|
|
|
@@ -77014,16 +78015,16 @@ async function whoami(opts) {
|
|
|
77014
78015
|
`));
|
|
77015
78016
|
}
|
|
77016
78017
|
const { profile, name: profileName } = resolved;
|
|
77017
|
-
const
|
|
78018
|
+
const jsonMode8 = opts.json === true;
|
|
77018
78019
|
const outcome = await callWithAutoRelogin({
|
|
77019
78020
|
profile,
|
|
77020
78021
|
profileName,
|
|
77021
|
-
jsonMode:
|
|
78022
|
+
jsonMode: jsonMode8,
|
|
77022
78023
|
ttyHeader: import_picocolors21.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
77023
78024
|
fn: (bearer, origin) => apiFetch("/api/whoami", { bearer, origin })
|
|
77024
78025
|
});
|
|
77025
78026
|
if (outcome.kind === "auth_failed") {
|
|
77026
|
-
if (
|
|
78027
|
+
if (jsonMode8) {
|
|
77027
78028
|
process.stdout.write(
|
|
77028
78029
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
77029
78030
|
);
|
|
@@ -77043,7 +78044,7 @@ async function whoami(opts) {
|
|
|
77043
78044
|
throw err;
|
|
77044
78045
|
}
|
|
77045
78046
|
const me = outcome.result;
|
|
77046
|
-
if (
|
|
78047
|
+
if (jsonMode8) {
|
|
77047
78048
|
process.stdout.write(JSON.stringify(me, null, 2) + "\n");
|
|
77048
78049
|
return;
|
|
77049
78050
|
}
|
|
@@ -77256,7 +78257,7 @@ async function send(amount, asset, opts) {
|
|
|
77256
78257
|
}
|
|
77257
78258
|
const { profile, name: profileName } = resolved;
|
|
77258
78259
|
const stdoutIsTty = process.stdout.isTTY === true;
|
|
77259
|
-
const
|
|
78260
|
+
const jsonMode8 = opts.json === true || !stdoutIsTty;
|
|
77260
78261
|
const amountNumber = Number(amount);
|
|
77261
78262
|
if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
|
|
77262
78263
|
process.stderr.write(
|
|
@@ -77365,12 +78366,12 @@ async function send(amount, asset, opts) {
|
|
|
77365
78366
|
try {
|
|
77366
78367
|
activeProfile = await runLoginFlow({
|
|
77367
78368
|
profile: profileName,
|
|
77368
|
-
jsonMode:
|
|
78369
|
+
jsonMode: jsonMode8,
|
|
77369
78370
|
origin: activeProfile.mcpOrigin,
|
|
77370
78371
|
ttyHeader: import_picocolors22.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026")
|
|
77371
78372
|
});
|
|
77372
78373
|
} catch (reloginErr) {
|
|
77373
|
-
if (
|
|
78374
|
+
if (jsonMode8) {
|
|
77374
78375
|
emitNdjson({
|
|
77375
78376
|
ok: false,
|
|
77376
78377
|
status: "auth_failed",
|
|
@@ -77393,7 +78394,7 @@ async function send(amount, asset, opts) {
|
|
|
77393
78394
|
});
|
|
77394
78395
|
} catch (retryErr) {
|
|
77395
78396
|
if (retryErr instanceof ApiError) {
|
|
77396
|
-
if (
|
|
78397
|
+
if (jsonMode8) {
|
|
77397
78398
|
emitNdjson({
|
|
77398
78399
|
ok: false,
|
|
77399
78400
|
status: retryErr.status === 401 ? "auth_failed" : "propose_failed",
|
|
@@ -77411,7 +78412,7 @@ async function send(amount, asset, opts) {
|
|
|
77411
78412
|
throw retryErr;
|
|
77412
78413
|
}
|
|
77413
78414
|
} else if (err instanceof ApiError) {
|
|
77414
|
-
if (
|
|
78415
|
+
if (jsonMode8) {
|
|
77415
78416
|
emitNdjson({
|
|
77416
78417
|
ok: false,
|
|
77417
78418
|
status: "propose_failed",
|
|
@@ -77428,7 +78429,7 @@ async function send(amount, asset, opts) {
|
|
|
77428
78429
|
}
|
|
77429
78430
|
}
|
|
77430
78431
|
if (isBlocked(proposed)) {
|
|
77431
|
-
if (
|
|
78432
|
+
if (jsonMode8) {
|
|
77432
78433
|
const envelope = {
|
|
77433
78434
|
ok: false,
|
|
77434
78435
|
status: "blocked",
|
|
@@ -77492,7 +78493,7 @@ async function send(amount, asset, opts) {
|
|
|
77492
78493
|
if (process.env.CI === "1" || process.env.CI === "true") return false;
|
|
77493
78494
|
return true;
|
|
77494
78495
|
})();
|
|
77495
|
-
if (
|
|
78496
|
+
if (jsonMode8) {
|
|
77496
78497
|
emitNdjson({
|
|
77497
78498
|
ok: true,
|
|
77498
78499
|
status: "proposed",
|
|
@@ -77524,7 +78525,7 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
77524
78525
|
intervalMs: POLL_INTERVAL_MS,
|
|
77525
78526
|
giveUpMs: POLL_GIVEUP_MS,
|
|
77526
78527
|
onTick: (s) => {
|
|
77527
|
-
if (
|
|
78528
|
+
if (jsonMode8) {
|
|
77528
78529
|
emitNdjson({ status: s.status, intent_id: s.approval_id });
|
|
77529
78530
|
} else {
|
|
77530
78531
|
process.stdout.write(` ${describeStatus(s.status)}${import_picocolors22.default.dim("\u2026")}\r`);
|
|
@@ -77539,12 +78540,12 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
77539
78540
|
try {
|
|
77540
78541
|
activeProfile = await runLoginFlow({
|
|
77541
78542
|
profile: profileName,
|
|
77542
|
-
jsonMode:
|
|
78543
|
+
jsonMode: jsonMode8,
|
|
77543
78544
|
origin: activeProfile.mcpOrigin,
|
|
77544
78545
|
ttyHeader: import_picocolors22.default.dim("Bearer expired mid-poll \u2014 re-pairing this terminal\u2026")
|
|
77545
78546
|
});
|
|
77546
78547
|
} catch (reloginErr) {
|
|
77547
|
-
if (
|
|
78548
|
+
if (jsonMode8) {
|
|
77548
78549
|
emitNdjson({
|
|
77549
78550
|
ok: false,
|
|
77550
78551
|
status: "auth_failed",
|
|
@@ -77562,7 +78563,7 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
77562
78563
|
try {
|
|
77563
78564
|
final = await runPoll(activeProfile);
|
|
77564
78565
|
} catch (retryErr) {
|
|
77565
|
-
if (
|
|
78566
|
+
if (jsonMode8) {
|
|
77566
78567
|
emitNdjson({
|
|
77567
78568
|
ok: false,
|
|
77568
78569
|
status: retryErr instanceof ApiError && retryErr.status === 401 ? "auth_failed" : "poll_failed",
|
|
@@ -77578,7 +78579,7 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
77578
78579
|
process.exit(1);
|
|
77579
78580
|
}
|
|
77580
78581
|
} else {
|
|
77581
|
-
if (
|
|
78582
|
+
if (jsonMode8) {
|
|
77582
78583
|
emitNdjson({
|
|
77583
78584
|
ok: false,
|
|
77584
78585
|
status: "poll_failed",
|
|
@@ -77595,7 +78596,7 @@ ${import_picocolors22.default.bold("Proposed.")} Open this URL to approve with b
|
|
|
77595
78596
|
}
|
|
77596
78597
|
}
|
|
77597
78598
|
const explorer = final.tx_hash != null ? explorerUrl(final.chain_id, final.tx_hash) : null;
|
|
77598
|
-
if (
|
|
78599
|
+
if (jsonMode8) {
|
|
77599
78600
|
emitNdjson({
|
|
77600
78601
|
ok: final.status === "mined",
|
|
77601
78602
|
status: final.status,
|
|
@@ -77681,16 +78682,16 @@ async function status3(intentId, opts) {
|
|
|
77681
78682
|
`));
|
|
77682
78683
|
}
|
|
77683
78684
|
const { profile, name: profileName } = resolved;
|
|
77684
|
-
const
|
|
78685
|
+
const jsonMode8 = opts.json === true;
|
|
77685
78686
|
const outcome = await callWithAutoRelogin({
|
|
77686
78687
|
profile,
|
|
77687
78688
|
profileName,
|
|
77688
|
-
jsonMode:
|
|
78689
|
+
jsonMode: jsonMode8,
|
|
77689
78690
|
ttyHeader: import_picocolors23.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
77690
78691
|
fn: (bearer, origin) => fetchStatus({ intentId, bearer, origin })
|
|
77691
78692
|
});
|
|
77692
78693
|
if (outcome.kind === "auth_failed") {
|
|
77693
|
-
if (
|
|
78694
|
+
if (jsonMode8) {
|
|
77694
78695
|
process.stdout.write(
|
|
77695
78696
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
77696
78697
|
);
|
|
@@ -77717,7 +78718,7 @@ async function status3(intentId, opts) {
|
|
|
77717
78718
|
let snap = outcome.result;
|
|
77718
78719
|
let activeProfile = outcome.profile;
|
|
77719
78720
|
if (opts.watch && !isTerminalStatus(snap.status)) {
|
|
77720
|
-
if (!
|
|
78721
|
+
if (!jsonMode8) {
|
|
77721
78722
|
printSnap(snap);
|
|
77722
78723
|
process.stdout.write(import_picocolors23.default.dim("Watching\u2026\n"));
|
|
77723
78724
|
}
|
|
@@ -77729,7 +78730,7 @@ async function status3(intentId, opts) {
|
|
|
77729
78730
|
intervalMs: 0,
|
|
77730
78731
|
giveUpMs: WATCH_GIVEUP_MS,
|
|
77731
78732
|
onTick: (s) => {
|
|
77732
|
-
if (!
|
|
78733
|
+
if (!jsonMode8) {
|
|
77733
78734
|
process.stdout.write(` ${import_picocolors23.default.dim("\u2192")} ${s.status}
|
|
77734
78735
|
`);
|
|
77735
78736
|
}
|
|
@@ -77743,12 +78744,12 @@ async function status3(intentId, opts) {
|
|
|
77743
78744
|
try {
|
|
77744
78745
|
activeProfile = await runLoginFlow({
|
|
77745
78746
|
profile: profileName,
|
|
77746
|
-
jsonMode:
|
|
78747
|
+
jsonMode: jsonMode8,
|
|
77747
78748
|
origin: activeProfile.mcpOrigin,
|
|
77748
78749
|
ttyHeader: import_picocolors23.default.dim("Bearer expired mid-watch \u2014 re-pairing\u2026")
|
|
77749
78750
|
});
|
|
77750
78751
|
} catch (reloginErr) {
|
|
77751
|
-
if (
|
|
78752
|
+
if (jsonMode8) {
|
|
77752
78753
|
process.stdout.write(
|
|
77753
78754
|
JSON.stringify({
|
|
77754
78755
|
ok: false,
|
|
@@ -77777,14 +78778,14 @@ async function status3(intentId, opts) {
|
|
|
77777
78778
|
process.exit(1);
|
|
77778
78779
|
}
|
|
77779
78780
|
}
|
|
77780
|
-
if (
|
|
78781
|
+
if (jsonMode8) {
|
|
77781
78782
|
process.stdout.write(JSON.stringify(final, null, 2) + "\n");
|
|
77782
78783
|
} else {
|
|
77783
78784
|
printSnap(final);
|
|
77784
78785
|
}
|
|
77785
78786
|
process.exit(final.status === "mined" ? 0 : 1);
|
|
77786
78787
|
}
|
|
77787
|
-
if (
|
|
78788
|
+
if (jsonMode8) {
|
|
77788
78789
|
process.stdout.write(JSON.stringify(snap, null, 2) + "\n");
|
|
77789
78790
|
process.exit(snap.status === "mined" ? 0 : 0);
|
|
77790
78791
|
}
|
|
@@ -77877,16 +78878,16 @@ async function balance(opts) {
|
|
|
77877
78878
|
}
|
|
77878
78879
|
chainFilter = id2;
|
|
77879
78880
|
}
|
|
77880
|
-
const
|
|
78881
|
+
const jsonMode8 = opts.json === true;
|
|
77881
78882
|
const outcome = await callWithAutoRelogin({
|
|
77882
78883
|
profile,
|
|
77883
78884
|
profileName,
|
|
77884
|
-
jsonMode:
|
|
78885
|
+
jsonMode: jsonMode8,
|
|
77885
78886
|
ttyHeader: import_picocolors24.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
77886
78887
|
fn: (bearer, origin) => apiFetch("/api/balances", { bearer, origin })
|
|
77887
78888
|
});
|
|
77888
78889
|
if (outcome.kind === "auth_failed") {
|
|
77889
|
-
if (
|
|
78890
|
+
if (jsonMode8) {
|
|
77890
78891
|
process.stdout.write(
|
|
77891
78892
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
77892
78893
|
);
|
|
@@ -77907,7 +78908,7 @@ async function balance(opts) {
|
|
|
77907
78908
|
}
|
|
77908
78909
|
const res = outcome.result;
|
|
77909
78910
|
const filtered = chainFilter !== null ? res.chains.filter((c) => c.chainId === chainFilter) : res.chains;
|
|
77910
|
-
if (
|
|
78911
|
+
if (jsonMode8) {
|
|
77911
78912
|
process.stdout.write(
|
|
77912
78913
|
JSON.stringify(
|
|
77913
78914
|
chainFilter !== null ? { ...res, chains: filtered } : res,
|
|
@@ -78035,11 +79036,11 @@ async function history(opts) {
|
|
|
78035
79036
|
}
|
|
78036
79037
|
limit = n2;
|
|
78037
79038
|
}
|
|
78038
|
-
const
|
|
79039
|
+
const jsonMode8 = opts.json === true;
|
|
78039
79040
|
const outcome = await callWithAutoRelogin({
|
|
78040
79041
|
profile,
|
|
78041
79042
|
profileName,
|
|
78042
|
-
jsonMode:
|
|
79043
|
+
jsonMode: jsonMode8,
|
|
78043
79044
|
ttyHeader: import_picocolors25.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
78044
79045
|
fn: (bearer, origin) => apiFetch(
|
|
78045
79046
|
`/api/history?limit=${encodeURIComponent(String(limit))}`,
|
|
@@ -78047,7 +79048,7 @@ async function history(opts) {
|
|
|
78047
79048
|
)
|
|
78048
79049
|
});
|
|
78049
79050
|
if (outcome.kind === "auth_failed") {
|
|
78050
|
-
if (
|
|
79051
|
+
if (jsonMode8) {
|
|
78051
79052
|
process.stdout.write(
|
|
78052
79053
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
78053
79054
|
);
|
|
@@ -78067,7 +79068,7 @@ async function history(opts) {
|
|
|
78067
79068
|
throw err;
|
|
78068
79069
|
}
|
|
78069
79070
|
const res = outcome.result;
|
|
78070
|
-
if (
|
|
79071
|
+
if (jsonMode8) {
|
|
78071
79072
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
78072
79073
|
return;
|
|
78073
79074
|
}
|
|
@@ -78585,7 +79586,7 @@ async function swap(amount, fromAsset, opts) {
|
|
|
78585
79586
|
}
|
|
78586
79587
|
const { profile, name: profileName } = resolved;
|
|
78587
79588
|
const stdoutIsTty = process.stdout.isTTY === true;
|
|
78588
|
-
const
|
|
79589
|
+
const jsonMode8 = opts.json === true || !stdoutIsTty;
|
|
78589
79590
|
const amountNumber = Number(amount);
|
|
78590
79591
|
if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
|
|
78591
79592
|
failArg(`amount must be a positive number (got ${import_picocolors27.default.bold(amount)}).`);
|
|
@@ -78724,7 +79725,7 @@ async function swap(amount, fromAsset, opts) {
|
|
|
78724
79725
|
body: proposeBody,
|
|
78725
79726
|
profileName,
|
|
78726
79727
|
initialProfile: profile,
|
|
78727
|
-
jsonMode:
|
|
79728
|
+
jsonMode: jsonMode8,
|
|
78728
79729
|
shouldOpenBrowser,
|
|
78729
79730
|
buildRetryCommand
|
|
78730
79731
|
});
|
|
@@ -78745,7 +79746,7 @@ async function batch(opts) {
|
|
|
78745
79746
|
process.exit(2);
|
|
78746
79747
|
}
|
|
78747
79748
|
const { name: profileName, profile } = resolved;
|
|
78748
|
-
const
|
|
79749
|
+
const jsonMode8 = opts.json === true || !process.stdout.isTTY;
|
|
78749
79750
|
let legs;
|
|
78750
79751
|
try {
|
|
78751
79752
|
legs = JSON.parse(opts.legsJson);
|
|
@@ -78789,7 +79790,7 @@ async function batch(opts) {
|
|
|
78789
79790
|
},
|
|
78790
79791
|
profileName,
|
|
78791
79792
|
initialProfile: profile,
|
|
78792
|
-
jsonMode:
|
|
79793
|
+
jsonMode: jsonMode8,
|
|
78793
79794
|
shouldOpenBrowser
|
|
78794
79795
|
});
|
|
78795
79796
|
}
|
|
@@ -78814,7 +79815,7 @@ async function fundWallet(address, opts) {
|
|
|
78814
79815
|
process.exit(2);
|
|
78815
79816
|
}
|
|
78816
79817
|
const { name: profileName, profile } = resolved;
|
|
78817
|
-
const
|
|
79818
|
+
const jsonMode8 = opts.json === true || !process.stdout.isTTY;
|
|
78818
79819
|
if (!opts.chain) {
|
|
78819
79820
|
failArg3("--chain is required (1/137/8453/42161/900 or shortName).");
|
|
78820
79821
|
}
|
|
@@ -78866,7 +79867,7 @@ async function fundWallet(address, opts) {
|
|
|
78866
79867
|
},
|
|
78867
79868
|
profileName,
|
|
78868
79869
|
initialProfile: profile,
|
|
78869
|
-
jsonMode:
|
|
79870
|
+
jsonMode: jsonMode8,
|
|
78870
79871
|
shouldOpenBrowser
|
|
78871
79872
|
});
|
|
78872
79873
|
}
|
|
@@ -78881,7 +79882,7 @@ async function fundWallet(address, opts) {
|
|
|
78881
79882
|
},
|
|
78882
79883
|
profileName,
|
|
78883
79884
|
initialProfile: profile,
|
|
78884
|
-
jsonMode:
|
|
79885
|
+
jsonMode: jsonMode8,
|
|
78885
79886
|
shouldOpenBrowser
|
|
78886
79887
|
});
|
|
78887
79888
|
}
|
|
@@ -78908,7 +79909,7 @@ async function earnSupply(amount, asset, opts) {
|
|
|
78908
79909
|
}
|
|
78909
79910
|
const { profile, name: profileName } = resolved;
|
|
78910
79911
|
const stdoutIsTty = process.stdout.isTTY === true;
|
|
78911
|
-
const
|
|
79912
|
+
const jsonMode8 = opts.json === true || !stdoutIsTty;
|
|
78912
79913
|
const amountNumber = Number(amount);
|
|
78913
79914
|
if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
|
|
78914
79915
|
failArg4(`amount must be a positive number (got ${import_picocolors30.default.bold(amount)}).`);
|
|
@@ -78974,7 +79975,7 @@ async function earnSupply(amount, asset, opts) {
|
|
|
78974
79975
|
body: proposeBody,
|
|
78975
79976
|
profileName,
|
|
78976
79977
|
initialProfile: profile,
|
|
78977
|
-
jsonMode:
|
|
79978
|
+
jsonMode: jsonMode8,
|
|
78978
79979
|
shouldOpenBrowser
|
|
78979
79980
|
});
|
|
78980
79981
|
}
|
|
@@ -79001,7 +80002,7 @@ async function earnWithdraw(amountOrMax, asset, opts) {
|
|
|
79001
80002
|
}
|
|
79002
80003
|
const { profile, name: profileName } = resolved;
|
|
79003
80004
|
const stdoutIsTty = process.stdout.isTTY === true;
|
|
79004
|
-
const
|
|
80005
|
+
const jsonMode8 = opts.json === true || !stdoutIsTty;
|
|
79005
80006
|
const isMax = amountOrMax.toLowerCase() === "max";
|
|
79006
80007
|
if (!isMax) {
|
|
79007
80008
|
const amountNumber = Number(amountOrMax);
|
|
@@ -79072,7 +80073,7 @@ async function earnWithdraw(amountOrMax, asset, opts) {
|
|
|
79072
80073
|
body: proposeBody,
|
|
79073
80074
|
profileName,
|
|
79074
80075
|
initialProfile: profile,
|
|
79075
|
-
jsonMode:
|
|
80076
|
+
jsonMode: jsonMode8,
|
|
79076
80077
|
shouldOpenBrowser
|
|
79077
80078
|
});
|
|
79078
80079
|
}
|
|
@@ -79114,8 +80115,8 @@ async function loadResolvedProfile(requested) {
|
|
|
79114
80115
|
}
|
|
79115
80116
|
return resolved;
|
|
79116
80117
|
}
|
|
79117
|
-
function printResult(res,
|
|
79118
|
-
if (
|
|
80118
|
+
function printResult(res, jsonMode8) {
|
|
80119
|
+
if (jsonMode8) {
|
|
79119
80120
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
79120
80121
|
return;
|
|
79121
80122
|
}
|
|
@@ -79151,16 +80152,16 @@ async function postRestaurantQuiet(path8, body, resolved) {
|
|
|
79151
80152
|
return null;
|
|
79152
80153
|
}
|
|
79153
80154
|
}
|
|
79154
|
-
async function postRestaurant(path8, body, resolved,
|
|
80155
|
+
async function postRestaurant(path8, body, resolved, jsonMode8) {
|
|
79155
80156
|
const outcome = await callWithAutoRelogin({
|
|
79156
80157
|
profile: resolved.profile,
|
|
79157
80158
|
profileName: resolved.name,
|
|
79158
|
-
jsonMode:
|
|
80159
|
+
jsonMode: jsonMode8,
|
|
79159
80160
|
ttyHeader: import_picocolors32.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
79160
80161
|
fn: (bearer, origin) => apiFetch(path8, { method: "POST", bearer, origin, body })
|
|
79161
80162
|
});
|
|
79162
80163
|
if (outcome.kind === "auth_failed") {
|
|
79163
|
-
if (
|
|
80164
|
+
if (jsonMode8) {
|
|
79164
80165
|
process.stdout.write(
|
|
79165
80166
|
JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
|
|
79166
80167
|
);
|
|
@@ -79173,7 +80174,7 @@ async function postRestaurant(path8, body, resolved, jsonMode7) {
|
|
|
79173
80174
|
if (outcome.kind === "error") {
|
|
79174
80175
|
const err = outcome.error;
|
|
79175
80176
|
if (err instanceof ApiError) {
|
|
79176
|
-
if (
|
|
80177
|
+
if (jsonMode8) {
|
|
79177
80178
|
process.stdout.write(
|
|
79178
80179
|
JSON.stringify({ ok: false, status: "request_failed", error: err.message, http_status: err.status }) + "\n"
|
|
79179
80180
|
);
|
|
@@ -79189,7 +80190,7 @@ async function postRestaurant(path8, body, resolved, jsonMode7) {
|
|
|
79189
80190
|
}
|
|
79190
80191
|
async function searchFood(opts) {
|
|
79191
80192
|
const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
|
|
79192
|
-
const
|
|
80193
|
+
const jsonMode8 = opts.json === true || process.stdout.isTTY !== true;
|
|
79193
80194
|
if (!opts.location && !opts.name) {
|
|
79194
80195
|
process.stderr.write(
|
|
79195
80196
|
import_picocolors32.default.red("\u2715 Pass --location (search near a place) or --name (look one store up).\n")
|
|
@@ -79205,12 +80206,12 @@ async function searchFood(opts) {
|
|
|
79205
80206
|
if (opts.radiusMiles !== void 0) body.radius_miles = Number(opts.radiusMiles);
|
|
79206
80207
|
if (opts.openOnly !== void 0) body.open_only = opts.openOnly;
|
|
79207
80208
|
if (opts.limit !== void 0) body.limit = Number(opts.limit);
|
|
79208
|
-
const result = await postRestaurant("/api/restaurants/search", body, resolved,
|
|
79209
|
-
if (result) printResult(result,
|
|
80209
|
+
const result = await postRestaurant("/api/restaurants/search", body, resolved, jsonMode8);
|
|
80210
|
+
if (result) printResult(result, jsonMode8);
|
|
79210
80211
|
}
|
|
79211
80212
|
async function menuFood(items, opts) {
|
|
79212
80213
|
const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
|
|
79213
|
-
const
|
|
80214
|
+
const jsonMode8 = opts.json === true || process.stdout.isTTY !== true;
|
|
79214
80215
|
if (!opts.brand || !opts.address) {
|
|
79215
80216
|
process.stderr.write(
|
|
79216
80217
|
import_picocolors32.default.red(
|
|
@@ -79225,12 +80226,12 @@ async function menuFood(items, opts) {
|
|
|
79225
80226
|
intent: opts.intent,
|
|
79226
80227
|
items: items ?? []
|
|
79227
80228
|
};
|
|
79228
|
-
const result = await postRestaurant("/api/restaurants/menu", body, resolved,
|
|
79229
|
-
if (result) printResult(result,
|
|
80229
|
+
const result = await postRestaurant("/api/restaurants/menu", body, resolved, jsonMode8);
|
|
80230
|
+
if (result) printResult(result, jsonMode8);
|
|
79230
80231
|
}
|
|
79231
80232
|
async function orderFood(items, opts) {
|
|
79232
80233
|
const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
|
|
79233
|
-
const
|
|
80234
|
+
const jsonMode8 = opts.json === true || process.stdout.isTTY !== true;
|
|
79234
80235
|
if (!opts.brand || !opts.address) {
|
|
79235
80236
|
process.stderr.write(
|
|
79236
80237
|
import_picocolors32.default.red(
|
|
@@ -79261,9 +80262,9 @@ async function orderFood(items, opts) {
|
|
|
79261
80262
|
fulfillment: opts.fulfillment,
|
|
79262
80263
|
intent: opts.intent
|
|
79263
80264
|
};
|
|
79264
|
-
const result = await postRestaurant("/api/restaurants/order", body, resolved,
|
|
80265
|
+
const result = await postRestaurant("/api/restaurants/order", body, resolved, jsonMode8);
|
|
79265
80266
|
if (!result) return;
|
|
79266
|
-
printResult(result,
|
|
80267
|
+
printResult(result, jsonMode8);
|
|
79267
80268
|
const approvalUrl = typeof result.approval_url === "string" ? result.approval_url : null;
|
|
79268
80269
|
const browserAllowed = (() => {
|
|
79269
80270
|
if (opts.browserMode === "open") return true;
|
|
@@ -79282,7 +80283,7 @@ async function orderFood(items, opts) {
|
|
|
79282
80283
|
return;
|
|
79283
80284
|
}
|
|
79284
80285
|
if (!agentCard.will_attempt) {
|
|
79285
|
-
if (!
|
|
80286
|
+
if (!jsonMode8) {
|
|
79286
80287
|
process.stderr.write(
|
|
79287
80288
|
import_picocolors32.default.yellow(
|
|
79288
80289
|
`This order is over your saved card's per-order cap (${fmtCents(agentCard.max_per_order_cents)}), so it needs you.
|
|
@@ -79293,8 +80294,8 @@ async function orderFood(items, opts) {
|
|
|
79293
80294
|
openApproval();
|
|
79294
80295
|
return;
|
|
79295
80296
|
}
|
|
79296
|
-
const verdict = await pollOrderVerdict(orderId, resolved,
|
|
79297
|
-
if (
|
|
80297
|
+
const verdict = await pollOrderVerdict(orderId, resolved, jsonMode8);
|
|
80298
|
+
if (jsonMode8) {
|
|
79298
80299
|
process.stdout.write(JSON.stringify(verdict) + "\n");
|
|
79299
80300
|
if (verdict.status === "failed") return;
|
|
79300
80301
|
return;
|
|
@@ -79351,8 +80352,8 @@ function fmtCents(cents) {
|
|
|
79351
80352
|
}
|
|
79352
80353
|
var POLL_BUDGET_MS = 1e5;
|
|
79353
80354
|
var POLL_INTERVAL_MS2 = 3500;
|
|
79354
|
-
async function pollOrderVerdict(orderId, resolved,
|
|
79355
|
-
if (!
|
|
80355
|
+
async function pollOrderVerdict(orderId, resolved, jsonMode8) {
|
|
80356
|
+
if (!jsonMode8) {
|
|
79356
80357
|
process.stderr.write(import_picocolors32.default.dim("Your saved card is paying this \u2014 watching for the result\u2026\n"));
|
|
79357
80358
|
}
|
|
79358
80359
|
const deadline = Date.now() + POLL_BUDGET_MS;
|
|
@@ -79383,19 +80384,19 @@ async function pollOrderVerdict(orderId, resolved, jsonMode7) {
|
|
|
79383
80384
|
}
|
|
79384
80385
|
async function statusFood(orderId, opts) {
|
|
79385
80386
|
const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
|
|
79386
|
-
const
|
|
80387
|
+
const jsonMode8 = opts.json === true || process.stdout.isTTY !== true;
|
|
79387
80388
|
const result = await postRestaurant(
|
|
79388
80389
|
"/api/restaurants/order-status",
|
|
79389
80390
|
{ order_id: orderId.trim() },
|
|
79390
80391
|
resolved,
|
|
79391
|
-
|
|
80392
|
+
jsonMode8
|
|
79392
80393
|
);
|
|
79393
80394
|
if (!result) return;
|
|
79394
80395
|
if (result.blocked) {
|
|
79395
|
-
printResult(result,
|
|
80396
|
+
printResult(result, jsonMode8);
|
|
79396
80397
|
return;
|
|
79397
80398
|
}
|
|
79398
|
-
if (
|
|
80399
|
+
if (jsonMode8) {
|
|
79399
80400
|
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
79400
80401
|
return;
|
|
79401
80402
|
}
|
|
@@ -79437,16 +80438,16 @@ async function withProfile(opts, path8, init2) {
|
|
|
79437
80438
|
`));
|
|
79438
80439
|
}
|
|
79439
80440
|
const { profile, name: profileName } = resolved;
|
|
79440
|
-
const
|
|
80441
|
+
const jsonMode8 = opts.json === true;
|
|
79441
80442
|
const outcome = await callWithAutoRelogin({
|
|
79442
80443
|
profile,
|
|
79443
80444
|
profileName,
|
|
79444
|
-
jsonMode:
|
|
80445
|
+
jsonMode: jsonMode8,
|
|
79445
80446
|
ttyHeader: import_picocolors33.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
79446
80447
|
fn: (bearer, origin) => apiFetch(path8, init2 ? { bearer, origin, method: init2.method, body: init2.body } : { bearer, origin })
|
|
79447
80448
|
});
|
|
79448
80449
|
if (outcome.kind === "auth_failed") {
|
|
79449
|
-
if (
|
|
80450
|
+
if (jsonMode8) {
|
|
79450
80451
|
process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
|
|
79451
80452
|
process.exit(1);
|
|
79452
80453
|
}
|
|
@@ -79465,9 +80466,9 @@ async function withProfile(opts, path8, init2) {
|
|
|
79465
80466
|
}
|
|
79466
80467
|
return outcome.result;
|
|
79467
80468
|
}
|
|
79468
|
-
function handleBlocked(res,
|
|
80469
|
+
function handleBlocked(res, jsonMode8) {
|
|
79469
80470
|
if (!res.blocked) return false;
|
|
79470
|
-
if (
|
|
80471
|
+
if (jsonMode8) {
|
|
79471
80472
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
79472
80473
|
process.exit(1);
|
|
79473
80474
|
}
|
|
@@ -79531,9 +80532,9 @@ function printTable(rows) {
|
|
|
79531
80532
|
}
|
|
79532
80533
|
}
|
|
79533
80534
|
async function listBounties(opts) {
|
|
79534
|
-
const
|
|
80535
|
+
const jsonMode8 = opts.json === true;
|
|
79535
80536
|
const res = await withProfile(opts, "/api/bounties");
|
|
79536
|
-
handleBlocked(res,
|
|
80537
|
+
handleBlocked(res, jsonMode8);
|
|
79537
80538
|
let rows = res.bounties ?? [];
|
|
79538
80539
|
const min = opts.min !== void 0 ? Number(opts.min) : void 0;
|
|
79539
80540
|
const max = opts.max !== void 0 ? Number(opts.max) : void 0;
|
|
@@ -79571,7 +80572,7 @@ async function listBounties(opts) {
|
|
|
79571
80572
|
process.exit(2);
|
|
79572
80573
|
}
|
|
79573
80574
|
const shown2 = rows.slice(0, limit);
|
|
79574
|
-
if (
|
|
80575
|
+
if (jsonMode8) {
|
|
79575
80576
|
process.stdout.write(JSON.stringify({ bounties: shown2, matched: rows.length }, null, 2) + "\n");
|
|
79576
80577
|
return;
|
|
79577
80578
|
}
|
|
@@ -79590,15 +80591,15 @@ async function listBounties(opts) {
|
|
|
79590
80591
|
process.stdout.write(AI_DIRECTIVE + "\n");
|
|
79591
80592
|
}
|
|
79592
80593
|
async function showBounty(id2, opts) {
|
|
79593
|
-
const
|
|
80594
|
+
const jsonMode8 = opts.json === true;
|
|
79594
80595
|
const clean3 = id2.trim().replace(/^.*\/bounty\//, "").replace(/[?#].*$/, "").trim();
|
|
79595
80596
|
if (!clean3) {
|
|
79596
80597
|
process.stderr.write(import_picocolors33.default.red("\u2715 Give a bounty id, or a agentgates.ai/bounty/<id> link.\n"));
|
|
79597
80598
|
process.exit(2);
|
|
79598
80599
|
}
|
|
79599
80600
|
const res = await withProfile(opts, `/api/bounties/${encodeURIComponent(clean3)}`);
|
|
79600
|
-
handleBlocked(res,
|
|
79601
|
-
if (
|
|
80601
|
+
handleBlocked(res, jsonMode8);
|
|
80602
|
+
if (jsonMode8) {
|
|
79602
80603
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
79603
80604
|
return;
|
|
79604
80605
|
}
|
|
@@ -79629,13 +80630,13 @@ async function showBounty(id2, opts) {
|
|
|
79629
80630
|
process.stdout.write(AI_DIRECTIVE + "\n");
|
|
79630
80631
|
}
|
|
79631
80632
|
async function myBounties(opts) {
|
|
79632
|
-
const
|
|
80633
|
+
const jsonMode8 = opts.json === true;
|
|
79633
80634
|
const res = await withProfile(opts, "/api/bounties?mine=1");
|
|
79634
|
-
handleBlocked(res,
|
|
80635
|
+
handleBlocked(res, jsonMode8);
|
|
79635
80636
|
const all = res.bounties ?? [];
|
|
79636
80637
|
const status4 = opts.status?.trim().toUpperCase();
|
|
79637
80638
|
const rows = status4 ? all.filter((r) => (r.status ?? "").toUpperCase() === status4) : all;
|
|
79638
|
-
if (
|
|
80639
|
+
if (jsonMode8) {
|
|
79639
80640
|
process.stdout.write(JSON.stringify({ bounties: rows, submissions: res.submissions ?? [] }, null, 2) + "\n");
|
|
79640
80641
|
return;
|
|
79641
80642
|
}
|
|
@@ -79657,14 +80658,14 @@ async function myBounties(opts) {
|
|
|
79657
80658
|
process.stdout.write(AI_DIRECTIVE + "\n");
|
|
79658
80659
|
}
|
|
79659
80660
|
async function bountyFeed(opts) {
|
|
79660
|
-
const
|
|
80661
|
+
const jsonMode8 = opts.json === true;
|
|
79661
80662
|
const params = new URLSearchParams();
|
|
79662
80663
|
if (opts.limit) params.set("limit", opts.limit);
|
|
79663
80664
|
if (opts.type) params.set("type", opts.type);
|
|
79664
80665
|
const qs = params.toString();
|
|
79665
80666
|
const res = await withProfile(opts, `/api/bounties/feed${qs ? `?${qs}` : ""}`);
|
|
79666
|
-
handleBlocked(res,
|
|
79667
|
-
if (
|
|
80667
|
+
handleBlocked(res, jsonMode8);
|
|
80668
|
+
if (jsonMode8) {
|
|
79668
80669
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
79669
80670
|
return;
|
|
79670
80671
|
}
|
|
@@ -79679,7 +80680,7 @@ async function bountyFeed(opts) {
|
|
|
79679
80680
|
process.stdout.write(import_picocolors33.default.dim("Use --json for the full rows.\n"));
|
|
79680
80681
|
}
|
|
79681
80682
|
async function draftBounty(opts) {
|
|
79682
|
-
const
|
|
80683
|
+
const jsonMode8 = opts.json === true;
|
|
79683
80684
|
const amountNum = Number(opts.amount);
|
|
79684
80685
|
if (!Number.isFinite(amountNum) || amountNum <= 0) {
|
|
79685
80686
|
process.stderr.write(import_picocolors33.default.red("\u2715 --amount must be a positive number of USDC.\n"));
|
|
@@ -79695,8 +80696,8 @@ async function draftBounty(opts) {
|
|
|
79695
80696
|
evidenceType: opts.evidenceType
|
|
79696
80697
|
}
|
|
79697
80698
|
});
|
|
79698
|
-
handleBlocked(res,
|
|
79699
|
-
if (
|
|
80699
|
+
handleBlocked(res, jsonMode8);
|
|
80700
|
+
if (jsonMode8) {
|
|
79700
80701
|
process.stdout.write(JSON.stringify(res, null, 2) + "\n");
|
|
79701
80702
|
return;
|
|
79702
80703
|
}
|
|
@@ -79717,10 +80718,10 @@ function failArg6(message) {
|
|
|
79717
80718
|
`));
|
|
79718
80719
|
process.exit(2);
|
|
79719
80720
|
}
|
|
79720
|
-
async function loadProfileOrExit(requested,
|
|
80721
|
+
async function loadProfileOrExit(requested, jsonMode8) {
|
|
79721
80722
|
const resolved = await resolveProfile(requested);
|
|
79722
80723
|
if (!resolved) {
|
|
79723
|
-
if (
|
|
80724
|
+
if (jsonMode8) {
|
|
79724
80725
|
process.stdout.write(
|
|
79725
80726
|
JSON.stringify({ ok: false, status: "auth_failed", error: "Not logged in. Run agentgates login first." }) + "\n"
|
|
79726
80727
|
);
|
|
@@ -79729,7 +80730,7 @@ async function loadProfileOrExit(requested, jsonMode7) {
|
|
|
79729
80730
|
}
|
|
79730
80731
|
process.exit(2);
|
|
79731
80732
|
}
|
|
79732
|
-
if (resolved.autoSelected && !
|
|
80733
|
+
if (resolved.autoSelected && !jsonMode8) {
|
|
79733
80734
|
process.stderr.write(import_picocolors34.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
|
|
79734
80735
|
`));
|
|
79735
80736
|
}
|
|
@@ -79749,8 +80750,8 @@ function resolveMaxUsd(opts, profile, fallbackHint) {
|
|
|
79749
80750
|
);
|
|
79750
80751
|
}
|
|
79751
80752
|
async function fundBounty(bountyId, opts) {
|
|
79752
|
-
const
|
|
79753
|
-
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE,
|
|
80753
|
+
const jsonMode8 = Boolean(opts.json) || !process.stdout.isTTY;
|
|
80754
|
+
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode8);
|
|
79754
80755
|
const maxUsd = resolveMaxUsd(opts, profile, "agentgates fund");
|
|
79755
80756
|
return runIntentFlow({
|
|
79756
80757
|
endpoint: "/api/intents/propose-fund-bounty",
|
|
@@ -79769,17 +80770,17 @@ async function fundBounty(bountyId, opts) {
|
|
|
79769
80770
|
},
|
|
79770
80771
|
profileName,
|
|
79771
80772
|
initialProfile: profile,
|
|
79772
|
-
jsonMode:
|
|
80773
|
+
jsonMode: jsonMode8,
|
|
79773
80774
|
shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
|
|
79774
80775
|
});
|
|
79775
80776
|
}
|
|
79776
80777
|
async function tipBounty(bountyId, amount, opts) {
|
|
79777
|
-
const
|
|
80778
|
+
const jsonMode8 = Boolean(opts.json) || !process.stdout.isTTY;
|
|
79778
80779
|
const amt = Number(amount);
|
|
79779
80780
|
if (!Number.isFinite(amt) || amt <= 0) {
|
|
79780
80781
|
failArg6(`amount must be a positive USDC number (got ${amount}).`);
|
|
79781
80782
|
}
|
|
79782
|
-
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE,
|
|
80783
|
+
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode8);
|
|
79783
80784
|
const maxUsd = opts.maxUsd !== void 0 ? resolveMaxUsd(opts, profile, "agentgates tip") : Math.ceil(amt * 1.01 * 100) / 100;
|
|
79784
80785
|
return runIntentFlow({
|
|
79785
80786
|
endpoint: "/api/intents/propose-tip",
|
|
@@ -79799,17 +80800,17 @@ async function tipBounty(bountyId, amount, opts) {
|
|
|
79799
80800
|
},
|
|
79800
80801
|
profileName,
|
|
79801
80802
|
initialProfile: profile,
|
|
79802
|
-
jsonMode:
|
|
80803
|
+
jsonMode: jsonMode8,
|
|
79803
80804
|
shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
|
|
79804
80805
|
});
|
|
79805
80806
|
}
|
|
79806
80807
|
async function subscribeCreator(creatorUserId, opts) {
|
|
79807
|
-
const
|
|
80808
|
+
const jsonMode8 = Boolean(opts.json) || !process.stdout.isTTY;
|
|
79808
80809
|
const months = opts.months === void 0 ? 1 : Number(opts.months);
|
|
79809
80810
|
if (![1, 3, 12].includes(months)) {
|
|
79810
80811
|
failArg6(`--months must be 1, 3 or 12 (got ${opts.months}). Prepaid periods only \u2014 no auto-renew exists.`);
|
|
79811
80812
|
}
|
|
79812
|
-
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE,
|
|
80813
|
+
const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode8);
|
|
79813
80814
|
const maxUsd = resolveMaxUsd(opts, profile, "agentgates subscribe");
|
|
79814
80815
|
return runIntentFlow({
|
|
79815
80816
|
endpoint: "/api/intents/propose-subscribe",
|
|
@@ -79829,7 +80830,7 @@ async function subscribeCreator(creatorUserId, opts) {
|
|
|
79829
80830
|
},
|
|
79830
80831
|
profileName,
|
|
79831
80832
|
initialProfile: profile,
|
|
79832
|
-
jsonMode:
|
|
80833
|
+
jsonMode: jsonMode8,
|
|
79833
80834
|
shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
|
|
79834
80835
|
});
|
|
79835
80836
|
}
|
|
@@ -79848,16 +80849,16 @@ async function runWork(path8, body, opts) {
|
|
|
79848
80849
|
process.stderr.write(import_picocolors35.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
|
|
79849
80850
|
`));
|
|
79850
80851
|
}
|
|
79851
|
-
const
|
|
80852
|
+
const jsonMode8 = opts.json === true;
|
|
79852
80853
|
const outcome = await callWithAutoRelogin({
|
|
79853
80854
|
profile: resolved.profile,
|
|
79854
80855
|
profileName: resolved.name,
|
|
79855
|
-
jsonMode:
|
|
80856
|
+
jsonMode: jsonMode8,
|
|
79856
80857
|
ttyHeader: import_picocolors35.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
79857
80858
|
fn: (bearer, origin) => apiFetch(path8, { bearer, origin, method: "POST", body })
|
|
79858
80859
|
});
|
|
79859
80860
|
if (outcome.kind === "auth_failed") {
|
|
79860
|
-
if (
|
|
80861
|
+
if (jsonMode8) {
|
|
79861
80862
|
process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
|
|
79862
80863
|
process.exit(1);
|
|
79863
80864
|
}
|
|
@@ -79868,7 +80869,7 @@ async function runWork(path8, body, opts) {
|
|
|
79868
80869
|
if (outcome.kind === "error") {
|
|
79869
80870
|
const err = outcome.error;
|
|
79870
80871
|
if (err instanceof ApiError) {
|
|
79871
|
-
if (
|
|
80872
|
+
if (jsonMode8) {
|
|
79872
80873
|
process.stdout.write(JSON.stringify({ ok: false, error: err.message, http_status: err.status }) + "\n");
|
|
79873
80874
|
} else {
|
|
79874
80875
|
process.stderr.write(import_picocolors35.default.red(`\u2715 ${err.message} (HTTP ${err.status})
|
|
@@ -79880,7 +80881,7 @@ async function runWork(path8, body, opts) {
|
|
|
79880
80881
|
}
|
|
79881
80882
|
const data4 = outcome.result;
|
|
79882
80883
|
if (data4.blocked) {
|
|
79883
|
-
if (
|
|
80884
|
+
if (jsonMode8) {
|
|
79884
80885
|
process.stdout.write(JSON.stringify({ ok: false, ...data4 }) + "\n");
|
|
79885
80886
|
process.exit(1);
|
|
79886
80887
|
}
|
|
@@ -79894,7 +80895,7 @@ ${import_picocolors35.default.bold(data4.upgrade_url)}
|
|
|
79894
80895
|
process.exit(1);
|
|
79895
80896
|
}
|
|
79896
80897
|
if (typeof data4.error === "string" && data4.error) {
|
|
79897
|
-
if (
|
|
80898
|
+
if (jsonMode8) {
|
|
79898
80899
|
process.stdout.write(JSON.stringify({ ok: false, error: data4.error }) + "\n");
|
|
79899
80900
|
} else {
|
|
79900
80901
|
process.stderr.write(import_picocolors35.default.red(`\u2715 ${data4.error}
|
|
@@ -79902,7 +80903,7 @@ ${import_picocolors35.default.bold(data4.upgrade_url)}
|
|
|
79902
80903
|
}
|
|
79903
80904
|
process.exit(1);
|
|
79904
80905
|
}
|
|
79905
|
-
if (
|
|
80906
|
+
if (jsonMode8) {
|
|
79906
80907
|
process.stdout.write(JSON.stringify({ ok: true, ...data4 }) + "\n");
|
|
79907
80908
|
return;
|
|
79908
80909
|
}
|
|
@@ -79946,14 +80947,14 @@ init_constants();
|
|
|
79946
80947
|
var FLUSH_MS = 400;
|
|
79947
80948
|
var FLUSH_BYTES = 2048;
|
|
79948
80949
|
async function deliver(bountyId, command, opts) {
|
|
79949
|
-
const
|
|
80950
|
+
const jsonMode8 = opts.json === true;
|
|
79950
80951
|
const requested = opts.profile ?? DEFAULT_PROFILE;
|
|
79951
80952
|
const resolved = await resolveProfile(requested);
|
|
79952
80953
|
if (!resolved) {
|
|
79953
80954
|
process.stderr.write(import_picocolors36.default.red("Not logged in. Run agentgates login first.\n"));
|
|
79954
80955
|
process.exit(2);
|
|
79955
80956
|
}
|
|
79956
|
-
if (resolved.autoSelected && !
|
|
80957
|
+
if (resolved.autoSelected && !jsonMode8) {
|
|
79957
80958
|
process.stderr.write(import_picocolors36.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
|
|
79958
80959
|
`));
|
|
79959
80960
|
}
|
|
@@ -79961,7 +80962,7 @@ async function deliver(bountyId, command, opts) {
|
|
|
79961
80962
|
const outcome = await callWithAutoRelogin({
|
|
79962
80963
|
profile: resolved.profile,
|
|
79963
80964
|
profileName: resolved.name,
|
|
79964
|
-
jsonMode:
|
|
80965
|
+
jsonMode: jsonMode8,
|
|
79965
80966
|
ttyHeader: import_picocolors36.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
|
|
79966
80967
|
fn: (bearer, origin) => apiFetch(path8, { bearer, origin, method: "POST", body })
|
|
79967
80968
|
});
|
|
@@ -79970,7 +80971,7 @@ async function deliver(bountyId, command, opts) {
|
|
|
79970
80971
|
return outcome.result;
|
|
79971
80972
|
};
|
|
79972
80973
|
const die = (msg, data4) => {
|
|
79973
|
-
if (
|
|
80974
|
+
if (jsonMode8) {
|
|
79974
80975
|
process.stdout.write(JSON.stringify({ ok: false, error: msg, ...data4 ?? {} }) + "\n");
|
|
79975
80976
|
} else {
|
|
79976
80977
|
process.stderr.write(import_picocolors36.default.red(`
|
|
@@ -80000,7 +81001,7 @@ ${import_picocolors36.default.bold(data4.upgrade_url)}
|
|
|
80000
81001
|
if (started.error) return void die(started.error, started);
|
|
80001
81002
|
const runId = started.run_id;
|
|
80002
81003
|
if (!runId) return void die("The service opened a run but did not name it.");
|
|
80003
|
-
if (!
|
|
81004
|
+
if (!jsonMode8) {
|
|
80004
81005
|
process.stderr.write(
|
|
80005
81006
|
import_picocolors36.default.bold("\n\u25CF LIVE ") + import_picocolors36.default.dim("everything below is going onto the bounty page as it happens\n") + import_picocolors36.default.dim(` ${started.url ?? ""}
|
|
80006
81007
|
|
|
@@ -80031,7 +81032,7 @@ ${import_picocolors36.default.bold(data4.upgrade_url)}
|
|
|
80031
81032
|
const timer = setInterval(() => flush(true), FLUSH_MS);
|
|
80032
81033
|
const consume = (data4) => {
|
|
80033
81034
|
buffer += data4;
|
|
80034
|
-
if (!opts.quiet && !
|
|
81035
|
+
if (!opts.quiet && !jsonMode8) process.stderr.write(data4);
|
|
80035
81036
|
flush();
|
|
80036
81037
|
};
|
|
80037
81038
|
let exitCode = 0;
|
|
@@ -80054,7 +81055,7 @@ ${import_picocolors36.default.bold(data4.upgrade_url)}
|
|
|
80054
81055
|
child.stdout.on("data", (d) => consume(d));
|
|
80055
81056
|
child.stderr.setEncoding("utf8");
|
|
80056
81057
|
child.stderr.on("data", (d) => {
|
|
80057
|
-
if (!
|
|
81058
|
+
if (!jsonMode8) process.stderr.write(import_picocolors36.default.dim(d));
|
|
80058
81059
|
});
|
|
80059
81060
|
child.on("error", (err) => {
|
|
80060
81061
|
process.stderr.write(import_picocolors36.default.red(`
|
|
@@ -80079,7 +81080,7 @@ ${import_picocolors36.default.bold(data4.upgrade_url)}
|
|
|
80079
81080
|
}
|
|
80080
81081
|
if (finished.blocked) return void die(finished.reason ?? "Blocked.", finished);
|
|
80081
81082
|
if (finished.error) return void die(finished.error, finished);
|
|
80082
|
-
if (
|
|
81083
|
+
if (jsonMode8) {
|
|
80083
81084
|
process.stdout.write(
|
|
80084
81085
|
JSON.stringify({
|
|
80085
81086
|
ok: true,
|
|
@@ -80117,7 +81118,7 @@ init_constants();
|
|
|
80117
81118
|
// src/lib/trade-sol.ts
|
|
80118
81119
|
var import_web3 = __toESM(require_index_cjs(), 1);
|
|
80119
81120
|
init_constants();
|
|
80120
|
-
import { promises as
|
|
81121
|
+
import { promises as fs9 } from "node:fs";
|
|
80121
81122
|
import * as path6 from "node:path";
|
|
80122
81123
|
import * as os3 from "node:os";
|
|
80123
81124
|
var TRADE_CHAIN_ID = 901;
|
|
@@ -80214,7 +81215,7 @@ function tradeSolPath() {
|
|
|
80214
81215
|
async function loadTradeKey() {
|
|
80215
81216
|
let raw;
|
|
80216
81217
|
try {
|
|
80217
|
-
raw = await
|
|
81218
|
+
raw = await fs9.readFile(tradeSolPath(), "utf8");
|
|
80218
81219
|
} catch (err) {
|
|
80219
81220
|
if (err.code === "ENOENT") return null;
|
|
80220
81221
|
throw err;
|
|
@@ -80242,11 +81243,11 @@ async function loadOrCreateTradeKey() {
|
|
|
80242
81243
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
80243
81244
|
};
|
|
80244
81245
|
const dir = path6.dirname(tradeSolPath());
|
|
80245
|
-
await
|
|
80246
|
-
await
|
|
81246
|
+
await fs9.mkdir(dir, { recursive: true, mode: 448 });
|
|
81247
|
+
await fs9.chmod(dir, 448).catch(() => {
|
|
80247
81248
|
});
|
|
80248
|
-
await
|
|
80249
|
-
await
|
|
81249
|
+
await fs9.writeFile(tradeSolPath(), JSON.stringify(state, null, 2), { mode: 384 });
|
|
81250
|
+
await fs9.chmod(tradeSolPath(), 384).catch(() => {
|
|
80250
81251
|
});
|
|
80251
81252
|
return { state, keypair, created: true };
|
|
80252
81253
|
}
|
|
@@ -80475,7 +81476,7 @@ async function runTrade(args) {
|
|
|
80475
81476
|
}
|
|
80476
81477
|
|
|
80477
81478
|
// src/commands/trade.ts
|
|
80478
|
-
function
|
|
81479
|
+
function fail9(message, json2) {
|
|
80479
81480
|
if (json2) {
|
|
80480
81481
|
process.stdout.write(JSON.stringify({ ok: false, error: message }) + "\n");
|
|
80481
81482
|
} else {
|
|
@@ -80489,7 +81490,7 @@ async function withContext(opts, fn) {
|
|
|
80489
81490
|
const ctx2 = await resolveTradeContext();
|
|
80490
81491
|
return await fn(ctx2);
|
|
80491
81492
|
} catch (err) {
|
|
80492
|
-
|
|
81493
|
+
fail9(err.message, opts.json);
|
|
80493
81494
|
}
|
|
80494
81495
|
}
|
|
80495
81496
|
function servedFloorUnits(ctx2) {
|
|
@@ -80515,7 +81516,7 @@ async function tradeKey(opts) {
|
|
|
80515
81516
|
];
|
|
80516
81517
|
process.stdout.write(lines.join("\n") + "\n" + AI_DIRECTIVE + "\n");
|
|
80517
81518
|
} catch (err) {
|
|
80518
|
-
|
|
81519
|
+
fail9(err.message, opts.json);
|
|
80519
81520
|
}
|
|
80520
81521
|
}
|
|
80521
81522
|
async function tradeStatus(opts) {
|
|
@@ -80572,7 +81573,7 @@ async function tradeQuote(coinArg, amount, opts) {
|
|
|
80572
81573
|
const coin = await resolveCoin(coinArg);
|
|
80573
81574
|
const amountNumber = Number(amount);
|
|
80574
81575
|
if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
|
|
80575
|
-
|
|
81576
|
+
fail9(`Amount "${amount}" is not a positive number.`, opts.json);
|
|
80576
81577
|
}
|
|
80577
81578
|
const res = await fetch(`${CREATORS_ORIGIN}/api/launch-quote`, {
|
|
80578
81579
|
method: "POST",
|
|
@@ -80586,7 +81587,7 @@ async function tradeQuote(coinArg, amount, opts) {
|
|
|
80586
81587
|
});
|
|
80587
81588
|
const body = await res.json().catch(() => null);
|
|
80588
81589
|
if (!res.ok || !body) {
|
|
80589
|
-
|
|
81590
|
+
fail9(`Quote failed: ${body?.error ?? `HTTP ${res.status}`}`, opts.json);
|
|
80590
81591
|
}
|
|
80591
81592
|
const floor = servedFloorUnits(ctx2);
|
|
80592
81593
|
const belowFloor = side === "buy" && floor !== null && parseDecimalToUnits(amount, USDC_DECIMALS, "Amount") < floor.units;
|
|
@@ -80661,12 +81662,12 @@ async function tradeBuy(coinArg, amount, opts) {
|
|
|
80661
81662
|
try {
|
|
80662
81663
|
units = parseDecimalToUnits(amount, USDC_DECIMALS, "Buy amount");
|
|
80663
81664
|
} catch (err) {
|
|
80664
|
-
|
|
81665
|
+
fail9(err.message, opts.json);
|
|
80665
81666
|
}
|
|
80666
|
-
if (units <= 0n)
|
|
81667
|
+
if (units <= 0n) fail9("Buy amount must be above zero.", opts.json);
|
|
80667
81668
|
const floor = servedFloorUnits(ctx2);
|
|
80668
81669
|
if (floor && units < floor.units) {
|
|
80669
|
-
|
|
81670
|
+
fail9(`Buys start at $${floor.usdc} (served by launch-config; the relay refuses below it).`, opts.json);
|
|
80670
81671
|
}
|
|
80671
81672
|
const { keypair, state, created } = await loadOrCreateTradeKey();
|
|
80672
81673
|
if (created && !opts.json) {
|
|
@@ -80681,23 +81682,23 @@ async function tradeSell(coinArg, amount, opts) {
|
|
|
80681
81682
|
await withContext(opts, async (ctx2) => {
|
|
80682
81683
|
const coin = await resolveCoin(coinArg);
|
|
80683
81684
|
const key = await loadTradeKey();
|
|
80684
|
-
if (!key)
|
|
81685
|
+
if (!key) fail9("No agent trading key yet (nothing to sell with). Run: agentgates trade key", opts.json);
|
|
80685
81686
|
let sellAmount = amount.trim();
|
|
80686
81687
|
const pct = sellAmount.match(/^(\d+)%$/);
|
|
80687
81688
|
if (sellAmount === "all" || pct) {
|
|
80688
81689
|
const bal = await readTokenBalance(rpcConnection(), key.state.address, coin.mint);
|
|
80689
|
-
if (!bal)
|
|
80690
|
-
if (bal.units <= 0n)
|
|
81690
|
+
if (!bal) fail9("Could not read the coin balance from the RPC; pass an explicit amount.", opts.json);
|
|
81691
|
+
if (bal.units <= 0n) fail9("This key holds none of that coin.", opts.json);
|
|
80691
81692
|
let units = bal.units;
|
|
80692
81693
|
if (pct) {
|
|
80693
81694
|
const p = BigInt(pct[1]);
|
|
80694
|
-
if (p <= 0n || p > 100n)
|
|
81695
|
+
if (p <= 0n || p > 100n) fail9(`Percentage must be 1-100, got "${amount}".`, opts.json);
|
|
80695
81696
|
units = bal.units * p / 100n;
|
|
80696
81697
|
}
|
|
80697
|
-
if (units <= 0n)
|
|
81698
|
+
if (units <= 0n) fail9("Sell amount rounds to zero.", opts.json);
|
|
80698
81699
|
sellAmount = formatUnits2(units, bal.decimals);
|
|
80699
81700
|
} else if (!/^\d+(\.\d+)?$/.test(sellAmount)) {
|
|
80700
|
-
|
|
81701
|
+
fail9(`Sell amount "${amount}" is not a coin amount, a percentage like 50%, or "all".`, opts.json);
|
|
80701
81702
|
}
|
|
80702
81703
|
const result = await runTrade({ ctx: ctx2, keypair: key.keypair, token: coin.mint, side: "sell", amount: sellAmount, minOut: opts.minOut });
|
|
80703
81704
|
await reportTrade(ctx2, opts, { side: "sell", coin, address: key.state.address, amount: sellAmount, result });
|
|
@@ -80712,16 +81713,16 @@ function describeOrder(o) {
|
|
|
80712
81713
|
async function tradeOrderPlace(coinArg, opts) {
|
|
80713
81714
|
await withContext(opts, async (ctx2) => {
|
|
80714
81715
|
if (opts.buy === void 0 === (opts.sell === void 0)) {
|
|
80715
|
-
|
|
81716
|
+
fail9("Pass exactly one of --buy <usdc> or --sell <amount|N%|all>.", opts.json);
|
|
80716
81717
|
}
|
|
80717
81718
|
if (opts.at === void 0 === (opts.onGraduation !== true)) {
|
|
80718
|
-
|
|
81719
|
+
fail9("Pass exactly one trigger: --at <value> (price, or mcap with --mcap) or --on-graduation.", opts.json);
|
|
80719
81720
|
}
|
|
80720
81721
|
const coin = await resolveCoin(coinArg);
|
|
80721
81722
|
const side = opts.buy !== void 0 ? "buy" : "sell";
|
|
80722
81723
|
const kind = opts.onGraduation ? side === "buy" ? "buy_on_graduation" : "sell_on_graduation" : side === "buy" ? "buy_at" : "sell_at";
|
|
80723
|
-
if (opts.stop && kind !== "sell_at")
|
|
80724
|
-
if (opts.mcap && !opts.at)
|
|
81724
|
+
if (opts.stop && kind !== "sell_at") fail9("--stop only applies to a --sell order with --at.", opts.json);
|
|
81725
|
+
if (opts.mcap && !opts.at) fail9("--mcap qualifies --at.", opts.json);
|
|
80725
81726
|
const { keypair, state, created } = await loadOrCreateTradeKey();
|
|
80726
81727
|
if (created && !opts.json) {
|
|
80727
81728
|
process.stderr.write(import_picocolors37.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
|
|
@@ -80733,11 +81734,11 @@ async function tradeOrderPlace(coinArg, opts) {
|
|
|
80733
81734
|
try {
|
|
80734
81735
|
units = parseDecimalToUnits(opts.buy, USDC_DECIMALS, "Buy amount");
|
|
80735
81736
|
} catch (err) {
|
|
80736
|
-
|
|
81737
|
+
fail9(err.message, opts.json);
|
|
80737
81738
|
}
|
|
80738
81739
|
const floor = servedFloorUnits(ctx2);
|
|
80739
81740
|
if (floor && units < floor.units) {
|
|
80740
|
-
|
|
81741
|
+
fail9(`Buys start at $${floor.usdc} (served by launch-config; the relay refuses below it).`, opts.json);
|
|
80741
81742
|
}
|
|
80742
81743
|
amount = opts.buy;
|
|
80743
81744
|
} else {
|
|
@@ -80745,24 +81746,24 @@ async function tradeOrderPlace(coinArg, opts) {
|
|
|
80745
81746
|
const pct = amount.match(/^(\d+)%$/);
|
|
80746
81747
|
if (amount === "all" || pct) {
|
|
80747
81748
|
const bal = await readTokenBalance(rpcConnection(), state.address, coin.mint);
|
|
80748
|
-
if (!bal)
|
|
80749
|
-
if (bal.units <= 0n)
|
|
81749
|
+
if (!bal) fail9("Could not read the coin balance from the RPC; pass an explicit amount.", opts.json);
|
|
81750
|
+
if (bal.units <= 0n) fail9("This key holds none of that coin.", opts.json);
|
|
80750
81751
|
let units = bal.units;
|
|
80751
81752
|
if (pct) {
|
|
80752
81753
|
const p = BigInt(pct[1]);
|
|
80753
|
-
if (p <= 0n || p > 100n)
|
|
81754
|
+
if (p <= 0n || p > 100n) fail9(`Percentage must be 1-100, got "${opts.sell}".`, opts.json);
|
|
80754
81755
|
units = bal.units * p / 100n;
|
|
80755
81756
|
}
|
|
80756
|
-
if (units <= 0n)
|
|
81757
|
+
if (units <= 0n) fail9("Sell amount rounds to zero.", opts.json);
|
|
80757
81758
|
amount = formatUnits2(units, bal.decimals);
|
|
80758
81759
|
} else if (!/^\d+(\.\d+)?$/.test(amount)) {
|
|
80759
|
-
|
|
81760
|
+
fail9(`Sell amount "${opts.sell}" is not a coin amount, a percentage like 50%, or "all".`, opts.json);
|
|
80760
81761
|
}
|
|
80761
81762
|
}
|
|
80762
81763
|
let expiresInDays;
|
|
80763
81764
|
if (opts.expiresDays !== void 0) {
|
|
80764
81765
|
const n2 = Number(opts.expiresDays);
|
|
80765
|
-
if (!Number.isInteger(n2) || n2 < 1)
|
|
81766
|
+
if (!Number.isInteger(n2) || n2 < 1) fail9(`--expires-days must be a positive integer, got "${opts.expiresDays}".`, opts.json);
|
|
80766
81767
|
expiresInDays = n2;
|
|
80767
81768
|
}
|
|
80768
81769
|
const prepared = await prepareOrder({
|
|
@@ -80798,7 +81799,7 @@ async function tradeOrderPlace(coinArg, opts) {
|
|
|
80798
81799
|
async function tradeOrdersList(opts) {
|
|
80799
81800
|
await withContext(opts, async (ctx2) => {
|
|
80800
81801
|
const key = await loadTradeKey();
|
|
80801
|
-
if (!key)
|
|
81802
|
+
if (!key) fail9("No agent trading key yet. Run: agentgates trade key", opts.json);
|
|
80802
81803
|
const token = opts.coin ? (await resolveCoin(opts.coin)).mint : void 0;
|
|
80803
81804
|
const res = await listOrders(key.state.address, token);
|
|
80804
81805
|
if (opts.json) {
|
|
@@ -80818,15 +81819,15 @@ async function tradeOrdersList(opts) {
|
|
|
80818
81819
|
async function tradeOrderCancel(id2, opts) {
|
|
80819
81820
|
await withContext(opts, async (_ctx) => {
|
|
80820
81821
|
const key = await loadTradeKey();
|
|
80821
|
-
if (!key)
|
|
81822
|
+
if (!key) fail9("No agent trading key yet. Run: agentgates trade key", opts.json);
|
|
80822
81823
|
try {
|
|
80823
81824
|
await cancelOrder(id2, key.state.address);
|
|
80824
81825
|
} catch (err) {
|
|
80825
81826
|
if (err instanceof RelayError && err.status === 409) {
|
|
80826
|
-
|
|
81827
|
+
fail9(`Order ${id2} already fired or ended; nothing to cancel.`, opts.json);
|
|
80827
81828
|
}
|
|
80828
81829
|
if (err instanceof RelayError && err.status === 404) {
|
|
80829
|
-
|
|
81830
|
+
fail9(`No order ${id2} for this key (already canceled, or never placed).`, opts.json);
|
|
80830
81831
|
}
|
|
80831
81832
|
throw err;
|
|
80832
81833
|
}
|
|
@@ -80841,12 +81842,12 @@ async function tradeOrderCancel(id2, opts) {
|
|
|
80841
81842
|
async function tradePositions(opts) {
|
|
80842
81843
|
await withContext(opts, async (ctx2) => {
|
|
80843
81844
|
const key = await loadTradeKey();
|
|
80844
|
-
if (!key)
|
|
81845
|
+
if (!key) fail9("No agent trading key yet. Run: agentgates trade key", opts.json);
|
|
80845
81846
|
let body;
|
|
80846
81847
|
try {
|
|
80847
81848
|
body = await relayGet(`/launch-portfolio?address=${encodeURIComponent(key.state.address)}`);
|
|
80848
81849
|
} catch (err) {
|
|
80849
|
-
if (err instanceof RelayError)
|
|
81850
|
+
if (err instanceof RelayError) fail9(`Positions read failed: ${err.message}`, opts.json);
|
|
80850
81851
|
throw err;
|
|
80851
81852
|
}
|
|
80852
81853
|
const rows = body?.tokens ?? [];
|
|
@@ -80894,7 +81895,7 @@ init_constants();
|
|
|
80894
81895
|
|
|
80895
81896
|
// src/lib/desk-sol.ts
|
|
80896
81897
|
var import_web32 = __toESM(require_index_cjs(), 1);
|
|
80897
|
-
import { promises as
|
|
81898
|
+
import { promises as fs10 } from "node:fs";
|
|
80898
81899
|
import * as path7 from "node:path";
|
|
80899
81900
|
import * as os4 from "node:os";
|
|
80900
81901
|
async function resolveDeskContext() {
|
|
@@ -80916,7 +81917,7 @@ function deskSessionKeyPath() {
|
|
|
80916
81917
|
async function loadDeskSessionKey() {
|
|
80917
81918
|
let raw;
|
|
80918
81919
|
try {
|
|
80919
|
-
raw = await
|
|
81920
|
+
raw = await fs10.readFile(deskSessionPath(), "utf8");
|
|
80920
81921
|
} catch (err) {
|
|
80921
81922
|
if (err.code === "ENOENT") return null;
|
|
80922
81923
|
throw err;
|
|
@@ -80945,11 +81946,11 @@ async function loadOrCreateDeskSessionKey() {
|
|
|
80945
81946
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
80946
81947
|
};
|
|
80947
81948
|
const dir = path7.dirname(deskSessionPath());
|
|
80948
|
-
await
|
|
80949
|
-
await
|
|
81949
|
+
await fs10.mkdir(dir, { recursive: true, mode: 448 });
|
|
81950
|
+
await fs10.chmod(dir, 448).catch(() => {
|
|
80950
81951
|
});
|
|
80951
|
-
await
|
|
80952
|
-
await
|
|
81952
|
+
await fs10.writeFile(deskSessionPath(), JSON.stringify(state, null, 2), { mode: 384 });
|
|
81953
|
+
await fs10.chmod(deskSessionPath(), 384).catch(() => {
|
|
80953
81954
|
});
|
|
80954
81955
|
return { state, keypair, created: true };
|
|
80955
81956
|
}
|
|
@@ -81060,7 +82061,7 @@ async function runDeskTrade(args) {
|
|
|
81060
82061
|
}
|
|
81061
82062
|
|
|
81062
82063
|
// src/commands/desk.ts
|
|
81063
|
-
function
|
|
82064
|
+
function fail10(message, json2) {
|
|
81064
82065
|
if (json2) {
|
|
81065
82066
|
process.stdout.write(JSON.stringify({ ok: false, error: message }) + "\n");
|
|
81066
82067
|
} else {
|
|
@@ -81074,7 +82075,7 @@ async function withDesk(opts, fn) {
|
|
|
81074
82075
|
const ctx2 = await resolveDeskContext();
|
|
81075
82076
|
return await fn(ctx2);
|
|
81076
82077
|
} catch (err) {
|
|
81077
|
-
|
|
82078
|
+
fail10(err.message, opts.json);
|
|
81078
82079
|
}
|
|
81079
82080
|
}
|
|
81080
82081
|
function servedFloorUnits2(ctx2) {
|
|
@@ -81085,7 +82086,7 @@ function servedFloorUnits2(ctx2) {
|
|
|
81085
82086
|
async function requireOwner(opts) {
|
|
81086
82087
|
const key = await loadTradeKey();
|
|
81087
82088
|
if (!key) {
|
|
81088
|
-
|
|
82089
|
+
fail10("No agent trading key yet (the desk's owner). Run: agentgates trade key", opts.json);
|
|
81089
82090
|
}
|
|
81090
82091
|
return key;
|
|
81091
82092
|
}
|
|
@@ -81154,7 +82155,7 @@ async function deskStatus(opts) {
|
|
|
81154
82155
|
if (opts.fills !== void 0) {
|
|
81155
82156
|
const n2 = Number(opts.fills);
|
|
81156
82157
|
if (!Number.isInteger(n2) || n2 <= 0) {
|
|
81157
|
-
|
|
82158
|
+
fail10(`--fills must be a positive integer, got "${opts.fills}".`, opts.json);
|
|
81158
82159
|
}
|
|
81159
82160
|
fillsLimit = n2;
|
|
81160
82161
|
}
|
|
@@ -81202,9 +82203,9 @@ async function deskDeposit(amount, opts) {
|
|
|
81202
82203
|
try {
|
|
81203
82204
|
units = parseDecimalToUnits(amount, USDC_DECIMALS, "Deposit amount");
|
|
81204
82205
|
} catch (err) {
|
|
81205
|
-
|
|
82206
|
+
fail10(err.message, opts.json);
|
|
81206
82207
|
}
|
|
81207
|
-
if (units <= 0n)
|
|
82208
|
+
if (units <= 0n) fail10("Deposit amount must be above zero.", opts.json);
|
|
81208
82209
|
const { keypair, state, created } = await loadOrCreateTradeKey();
|
|
81209
82210
|
if (created && !opts.json) {
|
|
81210
82211
|
process.stderr.write(import_picocolors38.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
|
|
@@ -81248,7 +82249,7 @@ async function deskWithdraw(amount, opts) {
|
|
|
81248
82249
|
const trimmed = amount.trim();
|
|
81249
82250
|
if (trimmed !== "all") {
|
|
81250
82251
|
if (!/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
81251
|
-
|
|
82252
|
+
fail10(`Withdraw amount "${amount}" is not a decimal amount or "all".`, opts.json);
|
|
81252
82253
|
}
|
|
81253
82254
|
}
|
|
81254
82255
|
const result = await runDeskCeremony({
|
|
@@ -81287,18 +82288,18 @@ async function deskWithdraw(amount, opts) {
|
|
|
81287
82288
|
}
|
|
81288
82289
|
async function deskSessionRegister(opts) {
|
|
81289
82290
|
await withDesk(opts, async (ctx2) => {
|
|
81290
|
-
if (!opts.cap)
|
|
81291
|
-
if (!opts.minutes)
|
|
82291
|
+
if (!opts.cap) fail10("--cap <usdc> is required: the per-trade cap is your risk statement, never defaulted.", opts.json);
|
|
82292
|
+
if (!opts.minutes) fail10("--minutes <n> is required: the session expiry is your risk statement, never defaulted.", opts.json);
|
|
81292
82293
|
let capUnits;
|
|
81293
82294
|
try {
|
|
81294
82295
|
capUnits = parseDecimalToUnits(opts.cap, USDC_DECIMALS, "Per-trade cap");
|
|
81295
82296
|
} catch (err) {
|
|
81296
|
-
|
|
82297
|
+
fail10(err.message, opts.json);
|
|
81297
82298
|
}
|
|
81298
|
-
if (capUnits <= 0n)
|
|
82299
|
+
if (capUnits <= 0n) fail10("Per-trade cap must be above zero.", opts.json);
|
|
81299
82300
|
const minutes = Number(opts.minutes);
|
|
81300
82301
|
if (!Number.isInteger(minutes) || minutes <= 0) {
|
|
81301
|
-
|
|
82302
|
+
fail10(`--minutes must be a positive integer, got "${opts.minutes}".`, opts.json);
|
|
81302
82303
|
}
|
|
81303
82304
|
const owner = await loadOrCreateTradeKey();
|
|
81304
82305
|
if (owner.created && !opts.json) {
|
|
@@ -81382,7 +82383,7 @@ async function deskSessionRevoke(opts) {
|
|
|
81382
82383
|
async function requireSessionKeypair(opts) {
|
|
81383
82384
|
const session = await loadDeskSessionKey();
|
|
81384
82385
|
if (!session) {
|
|
81385
|
-
|
|
82386
|
+
fail10(
|
|
81386
82387
|
"No desk session key on this terminal. Register one: agentgates desk session register --cap <usdc> --minutes <n>",
|
|
81387
82388
|
opts.json
|
|
81388
82389
|
);
|
|
@@ -81426,12 +82427,12 @@ async function deskBuy(coinArg, amount, opts) {
|
|
|
81426
82427
|
try {
|
|
81427
82428
|
units = parseDecimalToUnits(amount, USDC_DECIMALS, "Buy amount");
|
|
81428
82429
|
} catch (err) {
|
|
81429
|
-
|
|
82430
|
+
fail10(err.message, opts.json);
|
|
81430
82431
|
}
|
|
81431
|
-
if (units <= 0n)
|
|
82432
|
+
if (units <= 0n) fail10("Buy amount must be above zero.", opts.json);
|
|
81432
82433
|
const floor = servedFloorUnits2(ctx2);
|
|
81433
82434
|
if (floor && units < floor.units) {
|
|
81434
|
-
|
|
82435
|
+
fail10(`Buys start at $${floor.usdc} (served by launch-config; the relay refuses below it).`, opts.json);
|
|
81435
82436
|
}
|
|
81436
82437
|
const owner = await requireOwner(opts);
|
|
81437
82438
|
const session = await requireSessionKeypair(opts);
|
|
@@ -81456,16 +82457,16 @@ async function deskSell(coinArg, amount, opts) {
|
|
|
81456
82457
|
const pct = sellAmount.match(/^(\d+)%$/);
|
|
81457
82458
|
if (pct) {
|
|
81458
82459
|
const state = await deskState(owner.state.address, coin.mint);
|
|
81459
|
-
if (!state.coin)
|
|
82460
|
+
if (!state.coin) fail10("The desk holds none of that coin for this owner.", opts.json);
|
|
81460
82461
|
const credit = BigInt(state.coin.creditUnits);
|
|
81461
|
-
if (credit <= 0n)
|
|
82462
|
+
if (credit <= 0n) fail10("The desk holds none of that coin for this owner.", opts.json);
|
|
81462
82463
|
const p = BigInt(pct[1]);
|
|
81463
|
-
if (p <= 0n || p > 100n)
|
|
82464
|
+
if (p <= 0n || p > 100n) fail10(`Percentage must be 1-100, got "${amount}".`, opts.json);
|
|
81464
82465
|
const units = credit * p / 100n;
|
|
81465
|
-
if (units <= 0n)
|
|
82466
|
+
if (units <= 0n) fail10("Sell amount rounds to zero.", opts.json);
|
|
81466
82467
|
sellAmount = formatUnits2(units, state.coin.decimals);
|
|
81467
82468
|
} else if (sellAmount !== "all" && !/^\d+(\.\d+)?$/.test(sellAmount)) {
|
|
81468
|
-
|
|
82469
|
+
fail10(`Sell amount "${amount}" is not a coin amount, a percentage like 50%, or "all".`, opts.json);
|
|
81469
82470
|
}
|
|
81470
82471
|
const result = await runDeskTrade({
|
|
81471
82472
|
ctx: ctx2,
|
|
@@ -81481,7 +82482,7 @@ async function deskSell(coinArg, amount, opts) {
|
|
|
81481
82482
|
}
|
|
81482
82483
|
|
|
81483
82484
|
// src/main.ts
|
|
81484
|
-
var { version: VERSION } =
|
|
82485
|
+
var { version: VERSION } = JSON.parse(readFileSync3(new URL("../package.json", import.meta.url), "utf8"));
|
|
81485
82486
|
var program2 = new Command();
|
|
81486
82487
|
program2.name("agentgates").description(
|
|
81487
82488
|
"Drive your non-custodial Agentgates wallet from the terminal.\nPair once with biometric; every send still requires biometric in your browser."
|
|
@@ -81980,8 +82981,22 @@ var compute = program2.command("compute").description("Confidential virtual mach
|
|
|
81980
82981
|
compute.command("plans").description("Live plans and the price ladder. Public read: no key, no account, no payment.").option("--json", "machine-readable output (the raw catalog)").action(async (opts) => {
|
|
81981
82982
|
await computePlans(opts);
|
|
81982
82983
|
});
|
|
81983
|
-
compute.command("buy").description(
|
|
81984
|
-
|
|
82984
|
+
compute.command("buy").description(
|
|
82985
|
+
"Rent a machine: asks the price (free), signs the 402 with this machine's key (USDC on an EVM network, no gas), resends that same payment until the API answers, and prints the machine. The key that pays owns it."
|
|
82986
|
+
).option("--plan <id>", "a plan id (agentgates compute plans)").option("--hours <n>", "prepaid hours; the clock starts when the machine runs").option("--image <image>", "one container image, served on host port 8080").option("--port <n>", "with --image: the container port behind 8080 (default 80)").option("--compose <file>", "a docker-compose.yml that publishes a port (- reads stdin)").option("--env <KEY=VALUE>", "an env value, sealed to the machine and never stored; repeatable", (v, prev) => prev.concat(v), []).option("--name <name>", "a label for the machine").option("--network <name>", "pay on this network only; default: the cheapest one this key holds the USDC for").option("--max-usd <dollars>", "refuse to sign above this price").option("--quote", "print the price on every network and stop: nothing is signed").option("--yes", "pay without the prompt (needed when stdout is not a TTY)").option("--wait", "after paying, wait until the machine runs and print its endpoint").option("--timeout <minutes>", "with --wait: how long to wait (default 15)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
82987
|
+
await computeBuy(opts);
|
|
82988
|
+
});
|
|
82989
|
+
compute.command("renew <id>").description("Add paid hours to a machine: same price ask, same signature, same resend. Any wallet may pay; the owner stays the owner.").option("--hours <n>", "hours to add to the end of its clock").option("--network <name>", "pay on this network only").option("--max-usd <dollars>", "refuse to sign above this price").option("--quote", "print the price and stop: nothing is signed").option("--yes", "pay without the prompt (needed when stdout is not a TTY)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (id2, opts) => {
|
|
82990
|
+
await computeRenew(id2, opts);
|
|
82991
|
+
});
|
|
82992
|
+
compute.command("list").description("The machines this machine's key paid for (an owner read it signs).").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
82993
|
+
await computeList(opts);
|
|
82994
|
+
});
|
|
82995
|
+
compute.command("status <id>").description("One machine: status, endpoint, paid time, payments, live attestation (an owner read).").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (id2, opts) => {
|
|
82996
|
+
await computeStatus(id2, opts);
|
|
82997
|
+
});
|
|
82998
|
+
compute.command("wait <id>").description("Wait until a machine runs, then print its endpoint. The clock starts when it runs.").option("--timeout <minutes>", "how long to wait (default 15)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (id2, opts) => {
|
|
82999
|
+
await computeWait(id2, opts);
|
|
81985
83000
|
});
|
|
81986
83001
|
var inference = program2.command("inference").description("Attested confidential models, plus an open tier, USDC per request");
|
|
81987
83002
|
inference.command("models").description("Live models and per-token prices. Public read: no key, no account, no payment.").option("--all", "every model, not just the attested tier").option("--tier <tier>", "confidential | open").option("--tag <tag>", "filter by tag, repeatable (the board carries: reasoning, multimodal, frontier)", (v, prev) => prev.concat(v), []).option("--org <org>", "filter by maker org (openai, anthropic, qwen, ...)").option("--search <text>", "match against model id and name").option("--json", "machine-readable output (the catalog, filters applied)").action(async (opts) => {
|
|
@@ -81997,8 +83012,8 @@ inference.command("key").description("Mint a key that buys turns without the wor
|
|
|
81997
83012
|
}
|
|
81998
83013
|
await inferenceKeyCreate(opts);
|
|
81999
83014
|
});
|
|
82000
|
-
inference.command("topup").argument("<usd>", "dollars to add to the account balance", (v) => Number(v)).description("Buy prepaid balance with one x402 payment from this machine's key. A streamed turn can only be served from a balance.").option("--json", "machine-readable output").action(async (
|
|
82001
|
-
await inferenceTopUp(
|
|
83015
|
+
inference.command("topup").argument("<usd>", "dollars to add to the account balance", (v) => Number(v)).description("Buy prepaid balance with one x402 payment from this machine's key. A streamed turn can only be served from a balance.").option("--json", "machine-readable output").action(async (usd6, opts) => {
|
|
83016
|
+
await inferenceTopUp(usd6, opts);
|
|
82002
83017
|
});
|
|
82003
83018
|
inference.command("ask").argument("[words...]", "what to ask, in words").description("One paid ask, signed by this machine's key: the prepaid balance if it covers it, else one x402 payment.").option("--model <id>", "a catalog id (agentgates inference models)").option("--max-tokens <n>", "output ceiling", (v) => parseInt(v, 10)).option("--json", "machine-readable output").action(async (words7, opts) => {
|
|
82004
83019
|
await inferenceAsk(words7, opts);
|
|
@@ -82049,23 +83064,26 @@ passwords.command("init").description(
|
|
|
82049
83064
|
).option("--seed <twelve words>", "bring the phrase (quote it)").option("--reveal-seed", "print this key's words again").option("--import <hex>", "bring a bare 32-byte secp256k1 private key (64 hex chars) instead of words").option("--replace", "with --seed or --import: overwrite what is already here (the old key is the only thing that opens the rows it sealed)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
82050
83065
|
await passwordsInit(opts);
|
|
82051
83066
|
});
|
|
82052
|
-
passwords.command("add").alias("store").description("Store a login: sealed on this machine to this key's own signature and to the CVM'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: the username; mailbox rows: the address the codes arrive at").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 | mailbox (default login); mailbox = your own mailbox, read by the box for the codes sites email (--username the address, --password the app password, --host the mail server; Gmail's is known). An address leased here (agentgates passwords inbox lease) needs no app password: --password -").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("--backup-codes <codes|@file>", "login rows: the account's own backup codes, comma separated or one per line in a file; the CVM spends one when the site asks for a code and a permit lists codes").option("--device-json <json|@file>", "login rows: a device credential your own browser holds for the account (rpId, credentialId, privateKey, userHandle, signCount); agentgates passwords device provisions one through the CVM instead").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
83067
|
+
passwords.command("add").alias("store").description("Store a login: sealed on this machine to this key's own signature and to the CVM'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: the username; mailbox rows: the address the codes arrive at").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 | mailbox (default login); mailbox = your own mailbox, read by the box for the codes sites email (--username the address, --password the app password, --host the mail server; Gmail's is known). An address leased here (agentgates passwords inbox lease) needs no app password: --password -").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("--backup-codes <codes|@file>", "login rows: the account's own backup codes, comma separated or one per line in a file; the CVM spends one when the site asks for a code and a permit lists codes").option("--device-json <json|@file>", "login rows: a device credential your own browser holds for the account (rpId, credentialId, privateKey, userHandle, signCount); agentgates passwords device provisions one through the CVM instead").option("--through <row>", "a site that signs in through another site's account (Resend through GitHub): the new login holds no password of its own; its uses name that login row (passwords use --as-row) and the CVM types it on that row's own sites").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
82053
83068
|
await passwordsAdd(opts);
|
|
82054
83069
|
});
|
|
82055
83070
|
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 <session|password>", "what the agent gets: session = the site's cookies after the CVM logs in (default); password = the secret itself; cvm = the acting uses alone, for an agent that works inside the CVM over the API").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("--factors <device,codes,mail,sms>", "the account's sign-in verification step the agent may complete: device = the stored device credential answers the site's device step; codes = one of the stored backup codes is spent; mail = a code the site emails is read from your mailbox row or an inbox this key holds (allow the mailbox row too); sms = a code the site texts is read from a number this key holds").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
82056
83071
|
await passwordsAllow(opts);
|
|
82057
83072
|
});
|
|
82058
|
-
passwords.command("use").description("Log in through the CVM 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, or --workflow to run a task the owner taught the CVM. 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 CVM runs inside the session after the login lands (goto, fill, click, wait, read, press; a click may name the control's text instead of a selector)").option("--workflow <name>", "login only: run a workflow the owner taught the CVM on the row, by its name (passwords list shows them); --url may be left out").option("--input <name=value>", "a value the workflow takes, by its name; repeat for each (a value you leave out types what the owner typed)", (v, prev = []) => [...prev, v]).option("--code-steps-json <json>", "login only: the clicks that reach a code field the site keeps behind a 'try another way' menu (at most 4, click and wait), run before the code is typed").option("--enroll-device", "login only, your own key: provision a device credential for the account on this sign-in (the steps reach the page where the account adds a device); agentgates passwords device does this and seals it into the row").option("--attend", "login only, your own key: the CVM fills the password and holds the page for you at the controls (finish it on your board's live view); prints the use id and the view token").option("--use-id <id>", "continue a parked use by its id (Done on an attended sign-in, or a use the owner answered)").option("--mailbox <row>", "login and session: the mailbox row the box reads an emailed sign-in code from (default: your one mailbox row, when the permit covers it and lists mail)").option("--solve", "login and session, your own key: the CVM passes a bot check it meets (Cloudflare, Turnstile, reCAPTCHA, hCaptcha) by ticking it, then through its solver service").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) => {
|
|
83073
|
+
passwords.command("use").description("Log in through the CVM 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, or --workflow to run a task the owner taught the CVM. 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 CVM runs inside the session after the login lands (goto, fill, click, wait, read, press; a click may name the control's text instead of a selector; key reads the key a site shows once, {kind: key, label|selector, prefix?}, and keeps it in the row for {apiKey})").option("--workflow <name>", "login only: run a workflow the owner taught the CVM on the row, by its name (passwords list shows them); --url may be left out").option("--input <name=value>", "a value the workflow takes, by its name; repeat for each (a value you leave out types what the owner typed)", (v, prev = []) => [...prev, v]).option("--code-steps-json <json>", "login only: the clicks that reach a code field the site keeps behind a 'try another way' menu (at most 4, click and wait), run before the code is typed").option("--enroll-device", "login only, your own key: provision a device credential for the account on this sign-in (the steps reach the page where the account adds a device); agentgates passwords device does this and seals it into the row").option("--attend", "login only, your own key: the CVM fills the password and holds the page for you at the controls (finish it on your board's live view); prints the use id and the view token").option("--use-id <id>", "continue a parked use by its id (Done on an attended sign-in, or a use the owner answered)").option("--mailbox <row>", "login and session: the mailbox row the box reads an emailed sign-in code from (default: your one mailbox row, when the permit covers it and lists mail)").option("--as-row <row>", "login only: sign in through another site's account (Resend through GitHub): the login row whose username and password the CVM types, on that row's own sites only; the password never leaves the CVM").option("--solve", "login and session, your own key: the CVM passes a bot check it meets (Cloudflare, Turnstile, reCAPTCHA, hCaptcha) by ticking it, then through its solver service").option("--request-json <json>", "the whole request object for header and totp uses (spec \xA75.1); a header request's seal {json: <field>} seals that field of the JSON answer to the owner (a webhook's signing secret)").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) => {
|
|
82059
83074
|
const waitSource = command.getOptionValueSource("wait");
|
|
82060
83075
|
await passwordsUse({ ...opts, noWait: waitSource === "cli" && opts.wait === false, wait: typeof opts.wait === "string" ? opts.wait : void 0 });
|
|
82061
83076
|
});
|
|
82062
83077
|
passwords.command("checks [word]").description("Bot checks (Cloudflare, Turnstile, reCAPTCHA, hCaptcha): ask = an agent's use that meets one waits for your answer on the board (default); solve = the CVM passes every one it can without asking. No word prints the current one.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (word, opts) => {
|
|
82063
83078
|
await passwordsChecks(word, opts);
|
|
82064
83079
|
});
|
|
83080
|
+
passwords.command("open-sealed").description("Open a field the CVM sealed to you in a header use's answer (a webhook's signing secret): only the account owner's key opens it, the same key that opens the account's sealed mail.").option("--row <id>", "the row the header use ran on").option("--field <name>", "the sealed field's name (signing_secret)").option("--blob <value|@file>", "the field's {sealed} value from the answer").option("--out <file>", "write the value to this file (read by you alone) and print its length, not the value").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
83081
|
+
await passwordsOpenSealed(opts);
|
|
83082
|
+
});
|
|
82065
83083
|
passwords.command("code").description("Fetch a verification code one of the account's own contacts received, for an account the owner is registering or signing into elsewhere: the newest message from a site in your mailbox row (an app password, or a Gmail login you connected on your board; the permit lists mail), or the newest code that reached an inbox or a number this key holds, read through its own door (a sealed inbox is opened with your own key). One source: --mailbox, --inbox or --phone.").option("--from <domain>", "the site the code comes from, e.g. etsy.com (a mailbox row reads that sender)").option("--mailbox <row>", "the mailbox row (default: your one mailbox row, or your one Gmail login)").option("--inbox <id>", "an inbox this key holds (agentgates passwords inbox list): the newest code that reached it").option("--phone <id>", "a number this key holds (agentgates phone list): the newest code texted to it").option("--timeout <seconds>", "--inbox and --phone: how long the door waits for a code (default 60)").option("--since <minutes>", "how far back to look (default 10)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
82066
83084
|
await passwordsCode(opts);
|
|
82067
83085
|
});
|
|
82068
|
-
passwords.command("signup").description("Register the account owner on a site through the CVM, under a permit the owner signed: the CVM completes the site's own sign-up form with the owner's chosen identity and a password generated here, the site's verification code is read from a contact the account already holds, and the new login is saved as a row under this key. The source is one of your mailbox row (the CVM reads it), an inbox this key holds (--inbox: the code is read through the inbox's own door; a sealed inbox is opened with your own key) or a number this key holds (--phone: the code is read through the number's own door). The permit lists signup, and mail or sms for the source. Priced as a login; the code read is the wait-code door's own draw, reported in the answer.").requiredOption("--url <url>", "the https address of the site's sign-up page (or its sign-in page with a Sign up link)").option("--email <address>", "the address to sign up with: the source's own by default, or a plus alias of it (you+shop@gmail.com); none with --phone").option("--name <name>", "the name the form asks for").option("--username <name>", "the username when the form asks for one (the CVM derives one otherwise)").option("--password <password>", "the password to use (generated here when absent)").option("--mailbox <row>", "the mailbox row (default: your one mailbox row, or your one Gmail login)").option("--inbox <id>", "an inbox this key holds (agentgates passwords inbox list): the account is made with its address").option("--phone <id>", "a number this key holds (agentgates phone list): the account is made on the number, the code comes by text").option("--label <label>", "the stored row's label (default: the site)").option("--no-store", "do not store the new login as a row; the password prints once instead").option("--steps-json <json>", "steps to run at the site once the account exists (the login use's steps shape)").option("--drive", "let the CVM's own model update a step of the site book's recipe that no longer matches the form; a step only you can complete in person stops the run and names it").option("--birthday <yyyy-mm-dd>", "the date of birth a sign-up form asks for; typed, never kept").option("--attend", "
|
|
83086
|
+
passwords.command("signup").description("Register the account owner on a site through the CVM, under a permit the owner signed: the CVM completes the site's own sign-up form with the owner's chosen identity and a password generated here, the site's verification code is read from a contact the account already holds, and the new login is saved as a row under this key. The source is one of your mailbox row (the CVM reads it), an inbox this key holds (--inbox: the code is read through the inbox's own door; a sealed inbox is opened with your own key) or a number this key holds (--phone: the code is read through the number's own door). The permit lists signup, and mail or sms for the source. Priced as a login; the code read is the wait-code door's own draw, reported in the answer.").requiredOption("--url <url>", "the https address of the site's sign-up page (or its sign-in page with a Sign up link)").option("--email <address>", "the address to sign up with: the source's own by default, or a plus alias of it (you+shop@gmail.com); none with --phone").option("--name <name>", "the name the form asks for").option("--username <name>", "the username when the form asks for one (the CVM derives one otherwise)").option("--password <password>", "the password to use (generated here when absent)").option("--mailbox <row>", "the mailbox row (default: your one mailbox row, or your one Gmail login)").option("--inbox <id>", "an inbox this key holds (agentgates passwords inbox list): the account is made with its address").option("--phone <id>", "a number this key holds (agentgates phone list): the account is made on the number, the code comes by text").option("--label <label>", "the stored row's label (default: the site)").option("--no-store", "do not store the new login as a row; the password prints once instead").option("--steps-json <json>", "steps to run at the site once the account exists (the login use's steps shape)").option("--drive", "let the CVM's own model update a step of the site book's recipe that no longer matches the form; a step only you can complete in person stops the run and names it").option("--birthday <yyyy-mm-dd>", "the date of birth a sign-up form asks for; typed, never kept").option("--attend", "the default: a step only a person completes (a puzzle, a verification the site shows) holds the page for the account owner at the controls of their board's live view. Your own key: finish it there, or continue here with --use-id. An agent's key: this run waits for the owner's Done, then goes on").option("--no-attend", "a step only a person completes ends the run with the step named, and nothing is held").option("--use-id <id>", "continue a sign-up the CVM is holding for you (Done): the steps after the one you completed run on").option("--as-row <row>", "sign up THROUGH another site's account (Vercel's Continue with GitHub): the login row whose account the run signs in as; its username and password are opened here under your key, sent with the request, never printed and never stored again").option("--auto-owner", "your own key plays the owner at the walls it can answer and continues the run: a page that has not drawn gets a moment, and a phone check is answered with --sms-id and --sms-number; any other wall stays held for you").option("--sms-id <phoneId>", "with --auto-owner: the number this key may read a text from (the house's pool number is listed in poolSmsReaders); the phone check's code is read there").option("--sms-number <+15551234567>", "with --auto-owner: the phone number typed into the phone check (the number behind --sms-id)").option("--wait <seconds>", "how long to wait on a parked use or a starting CVM (default: the use's own window)").option("--no-wait", "print the first answer and leave").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
82069
83087
|
await passwordsSignup(opts);
|
|
82070
83088
|
});
|
|
82071
83089
|
passwords.command("device").description("Provision a device credential for an account through the CVM: the CVM logs in with your stored login, the steps reach the page where the account adds a device, the site's own ceremony creates the credential inside the CVM, and it is sealed into the row (both copies). From then on a permit that lists device lets the CVM complete the account's device step with it. Your own key only.").requiredOption("--row <id>", "the login to provision it on (agentgates passwords list)").requiredOption("--url <https://site/login>", "the account's sign-in page").option("--page <https://site/security>", "the page where the account adds a device (a passkey)").option("--click <text>", "the text on that page's add-a-device button").option("--steps-json <json>", "instead of --page and --click: the steps that reach and press it").option("--wait <seconds>", "cap on how long to wait for a parked sign-in (a code the site sent you)").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) => {
|
|
@@ -82240,6 +83258,18 @@ sites.command("ship <changeId>").description("Ship a ready change: the owner's s
|
|
|
82240
83258
|
sites.command("skip <changeId>").description("Close a change that has not shipped.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (changeId, opts) => {
|
|
82241
83259
|
await sitesSkip(changeId, opts);
|
|
82242
83260
|
});
|
|
83261
|
+
sites.command("undo <changeId>").description("Take back the site's latest live change: production goes back to the build before it and a revert is merged.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (changeId, opts) => {
|
|
83262
|
+
await sitesUndo(changeId, opts);
|
|
83263
|
+
});
|
|
83264
|
+
sites.command("fix <changeId>").description("A change Agentgates' live check stopped: the agent builds a new change whose ask is what failed.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (changeId, opts) => {
|
|
83265
|
+
await sitesFix(changeId, opts);
|
|
83266
|
+
});
|
|
83267
|
+
sites.command("changes <siteId>").description("One site's changes, newest first: what each did (its card) or what was asked, where it stands.").option("--before <changeId>", "the page before's last change id (the older page)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (siteId, opts) => {
|
|
83268
|
+
await sitesChanges(siteId, opts);
|
|
83269
|
+
});
|
|
83270
|
+
sites.command("remove <siteId>").description("Take a site off Agentgates. Its GitHub repo, Vercel project and connections stay yours.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (siteId, opts) => {
|
|
83271
|
+
await sitesRemove(siteId, opts);
|
|
83272
|
+
});
|
|
82243
83273
|
var memory = program2.command("memory").description("Sealed folders of markdown your agents read: names and bodies are sealed on this machine to the account's data key; the wire and the server carry ciphertext only.");
|
|
82244
83274
|
memory.command("overview", { isDefault: true }).description("The folders, their counts, and what the plan allows.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
82245
83275
|
await memoryOverview(opts);
|
|
@@ -82311,8 +83341,8 @@ agent.command("on").description("Turn your agent on: a wallet minted here, its k
|
|
|
82311
83341
|
agent.command("off").description("Turn your agent off: the CVM's copies go, its Memory key is revoked. Its thread stays in Memory.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
|
|
82312
83342
|
await agentOff(opts);
|
|
82313
83343
|
});
|
|
82314
|
-
agent.command("fund <usd>").description("Retired: your agent pays from your balance, so there is nothing to fund. Says so and moves nothing.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (
|
|
82315
|
-
await agentFund(
|
|
83344
|
+
agent.command("fund <usd>").description("Retired: your agent pays from your balance, so there is nothing to fund. Says so and moves nothing.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (usd6, opts) => {
|
|
83345
|
+
await agentFund(usd6, opts);
|
|
82316
83346
|
});
|
|
82317
83347
|
agent.command("refill [off]").description("Retired: your agent pays from your balance, so there is no refill rule. Says so and moves nothing.").option("--below <usd>", "retired").option("--add <usd>", "retired").option("--cap <usd>", "retired").option("--days <n>", "retired").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (action, opts) => {
|
|
82318
83348
|
await agentRefill(action, opts);
|