@vapi-network/cli 0.15.0 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +5 -1
- package/dist/cli.js +284 -129
- package/dist/cli.js.map +2 -2
- package/dist/index.js +284 -129
- package/dist/index.js.map +2 -2
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -43924,7 +43924,7 @@ async function assertPublicUrl(url2, options) {
|
|
|
43924
43924
|
options.timeoutMs ?? 5e3
|
|
43925
43925
|
);
|
|
43926
43926
|
} catch {
|
|
43927
|
-
throw guardError(url2);
|
|
43927
|
+
throw guardError(url2, "unresolved");
|
|
43928
43928
|
}
|
|
43929
43929
|
if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
|
|
43930
43930
|
throw guardError(url2);
|
|
@@ -44079,10 +44079,67 @@ function isNonPublicIpv6(hextets) {
|
|
|
44079
44079
|
const isDocumentation = first === 8193 && hextets[1] === 3512;
|
|
44080
44080
|
return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
|
|
44081
44081
|
}
|
|
44082
|
-
|
|
44083
|
-
|
|
44084
|
-
|
|
44082
|
+
var NetworkGuardError = class extends Error {
|
|
44083
|
+
constructor(message, reason) {
|
|
44084
|
+
super(message);
|
|
44085
|
+
this.reason = reason;
|
|
44086
|
+
this.name = "NetworkGuardError";
|
|
44087
|
+
}
|
|
44088
|
+
reason;
|
|
44089
|
+
};
|
|
44090
|
+
function guardError(url2, reason = "blocked") {
|
|
44091
|
+
return new NetworkGuardError(
|
|
44092
|
+
`URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`,
|
|
44093
|
+
reason
|
|
44094
|
+
);
|
|
44095
|
+
}
|
|
44096
|
+
var PROXY_VARIABLES = {
|
|
44097
|
+
"https:": ["HTTPS_PROXY", "https_proxy"],
|
|
44098
|
+
"http:": ["HTTP_PROXY", "http_proxy"]
|
|
44099
|
+
};
|
|
44100
|
+
var SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/u;
|
|
44101
|
+
function describeNetworkFailure(error61, url2, env = process.env) {
|
|
44102
|
+
const host = url2.host;
|
|
44103
|
+
let reason;
|
|
44104
|
+
const guard = guardReason(error61);
|
|
44105
|
+
if (guard !== void 0) {
|
|
44106
|
+
reason = guard === "unresolved" ? `the DNS lookup for ${host} failed` : `${host} is not a public address`;
|
|
44107
|
+
} else if (isTimeout(error61)) {
|
|
44108
|
+
reason = `the connection to ${host} timed out`;
|
|
44109
|
+
} else {
|
|
44110
|
+
const code = systemErrorCode(error61);
|
|
44111
|
+
reason = `could not connect to ${host}${code === void 0 ? "" : ` (${code})`}`;
|
|
44112
|
+
}
|
|
44113
|
+
const proxy = (PROXY_VARIABLES[url2.protocol] ?? []).find(
|
|
44114
|
+
(name) => (env[name] ?? "").trim() !== ""
|
|
44085
44115
|
);
|
|
44116
|
+
let hint = "";
|
|
44117
|
+
if (proxy !== void 0) {
|
|
44118
|
+
if (env.NODE_USE_ENV_PROXY !== "1") {
|
|
44119
|
+
hint = ` ${proxy} is set, but Node.js uses it only with NODE_USE_ENV_PROXY=1 (Node.js 22.21 or later): run the command again with NODE_USE_ENV_PROXY=1.`;
|
|
44120
|
+
} else if (guard === "unresolved") {
|
|
44121
|
+
hint = ` vapi looks ${host} up on this machine before it uses the proxy in ${proxy}, so the name must resolve here too.`;
|
|
44122
|
+
} else if (guard === void 0) {
|
|
44123
|
+
hint = ` NODE_USE_ENV_PROXY=1 and ${proxy} are set, so the proxy may have refused the connection.`;
|
|
44124
|
+
}
|
|
44125
|
+
}
|
|
44126
|
+
return `${reason}.${hint}`;
|
|
44127
|
+
}
|
|
44128
|
+
function guardReason(error61) {
|
|
44129
|
+
if (!(error61 instanceof Error) || error61.name !== "NetworkGuardError") return void 0;
|
|
44130
|
+
const reason = error61.reason;
|
|
44131
|
+
return reason === "blocked" || reason === "unresolved" ? reason : void 0;
|
|
44132
|
+
}
|
|
44133
|
+
function isTimeout(error61) {
|
|
44134
|
+
return error61 instanceof Error && (error61.name === "TimeoutError" || error61.name === "AbortError");
|
|
44135
|
+
}
|
|
44136
|
+
function systemErrorCode(error61) {
|
|
44137
|
+
for (let current = error61, depth = 0; current instanceof Error && depth < 3; depth += 1) {
|
|
44138
|
+
const code = current.code;
|
|
44139
|
+
if (typeof code === "string" && SYSTEM_ERROR_CODE.test(code)) return code;
|
|
44140
|
+
current = current.cause;
|
|
44141
|
+
}
|
|
44142
|
+
return void 0;
|
|
44086
44143
|
}
|
|
44087
44144
|
|
|
44088
44145
|
// ../core/src/networks.ts
|
|
@@ -47201,12 +47258,12 @@ async function removeStaleLock(path) {
|
|
|
47201
47258
|
const pid = lockOwnerPid(owner);
|
|
47202
47259
|
if (pid !== void 0 && processIsAlive(pid)) return;
|
|
47203
47260
|
await atomicFileTestHooks?.beforeStaleLockBreak?.(path);
|
|
47204
|
-
await removeOwnedLock(path, [owner]);
|
|
47261
|
+
await removeOwnedLock(path, [owner], true);
|
|
47205
47262
|
} catch (error61) {
|
|
47206
47263
|
if (!hasCode(error61, "ENOENT")) throw error61;
|
|
47207
47264
|
}
|
|
47208
47265
|
}
|
|
47209
|
-
async function removeOwnedLock(path, owners) {
|
|
47266
|
+
async function removeOwnedLock(path, owners, staleDeadOwner = false) {
|
|
47210
47267
|
const tombPath = `${path}.stale.${randomBytes2(16).toString("hex")}`;
|
|
47211
47268
|
try {
|
|
47212
47269
|
await rename(path, tombPath);
|
|
@@ -47215,7 +47272,7 @@ async function removeOwnedLock(path, owners) {
|
|
|
47215
47272
|
await removeOwnedTombs(path, owners);
|
|
47216
47273
|
const currentOwner = await readFile(path, "utf8").catch(() => void 0);
|
|
47217
47274
|
if (currentOwner !== void 0 && owners.includes(currentOwner)) {
|
|
47218
|
-
await removeOwnedLock(path, owners);
|
|
47275
|
+
await removeOwnedLock(path, owners, staleDeadOwner);
|
|
47219
47276
|
}
|
|
47220
47277
|
return;
|
|
47221
47278
|
}
|
|
@@ -47224,6 +47281,7 @@ async function removeOwnedLock(path, owners) {
|
|
|
47224
47281
|
let pendingError;
|
|
47225
47282
|
let renamedOwner;
|
|
47226
47283
|
try {
|
|
47284
|
+
await atomicFileTestHooks?.afterLockRename?.(tombPath);
|
|
47227
47285
|
renamedOwner = await readFile(tombPath, "utf8");
|
|
47228
47286
|
if (!owners.includes(renamedOwner) && !lockOwnerReleased(renamedOwner)) {
|
|
47229
47287
|
await atomicFileTestHooks?.afterMismatchedLockRename?.(path);
|
|
@@ -47232,6 +47290,7 @@ async function removeOwnedLock(path, owners) {
|
|
|
47232
47290
|
await atomicFileTestHooks?.afterMismatchedLockRestore?.(path);
|
|
47233
47291
|
}
|
|
47234
47292
|
} catch (error61) {
|
|
47293
|
+
if (hasCode(error61, "ENOENT")) return;
|
|
47235
47294
|
pendingError = error61;
|
|
47236
47295
|
}
|
|
47237
47296
|
try {
|
|
@@ -47240,7 +47299,7 @@ async function removeOwnedLock(path, owners) {
|
|
|
47240
47299
|
} catch (error61) {
|
|
47241
47300
|
if (!tombUnlinkTolerated(
|
|
47242
47301
|
error61,
|
|
47243
|
-
renamedOwner !== void 0 && lockOwnerReleased(renamedOwner) && owners.includes(renamedOwner)
|
|
47302
|
+
renamedOwner !== void 0 && (lockOwnerReleased(renamedOwner) || staleDeadOwner) && owners.includes(renamedOwner)
|
|
47244
47303
|
) && pendingError === void 0) {
|
|
47245
47304
|
pendingError = error61;
|
|
47246
47305
|
}
|
|
@@ -48403,7 +48462,7 @@ async function withCredentialLockFile(lockPath, operation) {
|
|
|
48403
48462
|
try {
|
|
48404
48463
|
return await operation();
|
|
48405
48464
|
} finally {
|
|
48406
|
-
await handle.close();
|
|
48465
|
+
await handle.close().catch(() => void 0);
|
|
48407
48466
|
await unlink2(lockPath).catch(() => void 0);
|
|
48408
48467
|
}
|
|
48409
48468
|
}
|
|
@@ -48467,16 +48526,25 @@ function withBearer(init, accessToken) {
|
|
|
48467
48526
|
async function safeFetch(fetchImpl, input2, init) {
|
|
48468
48527
|
try {
|
|
48469
48528
|
return await fetchImpl(input2, init);
|
|
48470
|
-
} catch {
|
|
48471
|
-
throw httpError(
|
|
48529
|
+
} catch (error61) {
|
|
48530
|
+
throw httpError(`The vAPI agent link request failed: ${networkFailure(error61, input2)}`);
|
|
48472
48531
|
}
|
|
48473
48532
|
}
|
|
48474
48533
|
async function safeAgentFetch(fetchImpl, input2, init) {
|
|
48475
48534
|
try {
|
|
48476
48535
|
return await fetchImpl(input2, init);
|
|
48536
|
+
} catch (error61) {
|
|
48537
|
+
throw httpError(`The vAPI agent request failed: ${networkFailure(error61, input2)}`);
|
|
48538
|
+
}
|
|
48539
|
+
}
|
|
48540
|
+
function networkFailure(error61, input2) {
|
|
48541
|
+
let url2;
|
|
48542
|
+
try {
|
|
48543
|
+
url2 = new URL(input2 instanceof Request ? input2.url : input2);
|
|
48477
48544
|
} catch {
|
|
48478
|
-
|
|
48545
|
+
return "the request did not reach vAPI.";
|
|
48479
48546
|
}
|
|
48547
|
+
return describeNetworkFailure(error61, url2);
|
|
48480
48548
|
}
|
|
48481
48549
|
function deviceAuthorizationError(status, payload) {
|
|
48482
48550
|
const error61 = stringField(payload, "error");
|
|
@@ -71174,7 +71242,7 @@ async function withVaultLock(path, operation) {
|
|
|
71174
71242
|
try {
|
|
71175
71243
|
return await operation();
|
|
71176
71244
|
} finally {
|
|
71177
|
-
await handle.close();
|
|
71245
|
+
await handle.close().catch(() => void 0);
|
|
71178
71246
|
await unlink4(lockPath).catch(() => void 0);
|
|
71179
71247
|
}
|
|
71180
71248
|
}
|
|
@@ -74068,7 +74136,7 @@ async function withRegistryLock(path, operation) {
|
|
|
74068
74136
|
try {
|
|
74069
74137
|
return await operation();
|
|
74070
74138
|
} finally {
|
|
74071
|
-
await handle.close();
|
|
74139
|
+
await handle.close().catch(() => void 0);
|
|
74072
74140
|
await unlink7(lockPath).catch(() => void 0);
|
|
74073
74141
|
}
|
|
74074
74142
|
}
|
|
@@ -74959,7 +75027,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74959
75027
|
try {
|
|
74960
75028
|
return await operation();
|
|
74961
75029
|
} finally {
|
|
74962
|
-
await handle.close();
|
|
75030
|
+
await handle.close().catch(() => void 0);
|
|
74963
75031
|
await unlink9(lockPath).catch(() => void 0);
|
|
74964
75032
|
}
|
|
74965
75033
|
}
|
|
@@ -75259,13 +75327,32 @@ async function transferBetweenAccounts(args) {
|
|
|
75259
75327
|
if (existing !== void 0 && existing.transfer?.status !== "failed") {
|
|
75260
75328
|
throw transferError("authorization_invalid");
|
|
75261
75329
|
}
|
|
75262
|
-
|
|
75263
|
-
|
|
75264
|
-
|
|
75265
|
-
|
|
75266
|
-
|
|
75267
|
-
|
|
75268
|
-
|
|
75330
|
+
try {
|
|
75331
|
+
await appendTransferReceipt(context, request, {
|
|
75332
|
+
receiptId,
|
|
75333
|
+
status: "unknown",
|
|
75334
|
+
txHash: null,
|
|
75335
|
+
replayed: false,
|
|
75336
|
+
reservedOn
|
|
75337
|
+
});
|
|
75338
|
+
} catch (error61) {
|
|
75339
|
+
let persisted;
|
|
75340
|
+
try {
|
|
75341
|
+
persisted = await findTransferReceipt(context, nonce);
|
|
75342
|
+
} catch {
|
|
75343
|
+
authorizationPersisted = true;
|
|
75344
|
+
}
|
|
75345
|
+
if (persisted !== void 0 && persisted.transfer?.status !== "failed") {
|
|
75346
|
+
authorizationPersisted = true;
|
|
75347
|
+
}
|
|
75348
|
+
if (!authorizationPersisted) throw error61;
|
|
75349
|
+
return transferResult(context, {
|
|
75350
|
+
status: "unknown",
|
|
75351
|
+
txHash: null,
|
|
75352
|
+
nonce: request.authorization.nonce,
|
|
75353
|
+
replayed: false
|
|
75354
|
+
});
|
|
75355
|
+
}
|
|
75269
75356
|
try {
|
|
75270
75357
|
await syncReceipts(context.receiptsPath);
|
|
75271
75358
|
} catch (error61) {
|
|
@@ -78570,7 +78657,7 @@ function createRunBudget(args) {
|
|
|
78570
78657
|
import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
|
|
78571
78658
|
import { arch, platform, release } from "node:os";
|
|
78572
78659
|
import { join as join14 } from "node:path";
|
|
78573
|
-
var VAPI_CLIENT_VERSION = "0.15.
|
|
78660
|
+
var VAPI_CLIENT_VERSION = "0.15.2";
|
|
78574
78661
|
async function createSupportReport(options) {
|
|
78575
78662
|
const message = options.message.trim();
|
|
78576
78663
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
@@ -80373,26 +80460,28 @@ async function ensureBalanceRouterKey(deps, paidLink) {
|
|
|
80373
80460
|
if (!parsed.success) {
|
|
80374
80461
|
throw new RouterClientError("http", "The Router balance key response was invalid.");
|
|
80375
80462
|
}
|
|
80376
|
-
|
|
80377
|
-
|
|
80378
|
-
|
|
80379
|
-
|
|
80380
|
-
|
|
80381
|
-
|
|
80382
|
-
|
|
80383
|
-
|
|
80384
|
-
|
|
80385
|
-
|
|
80386
|
-
|
|
80387
|
-
|
|
80388
|
-
|
|
80389
|
-
|
|
80390
|
-
|
|
80391
|
-
|
|
80392
|
-
|
|
80393
|
-
|
|
80394
|
-
|
|
80395
|
-
|
|
80463
|
+
await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
|
|
80464
|
+
const currentLink = await linkedWallet(deps);
|
|
80465
|
+
if (!sameAgentLink(currentLink, paidLink)) {
|
|
80466
|
+
throw new RouterClientError(
|
|
80467
|
+
"http",
|
|
80468
|
+
"The agent link changed while fetching the Router balance key."
|
|
80469
|
+
);
|
|
80470
|
+
}
|
|
80471
|
+
const returnedBase = validRouterBaseUrl(parsed.data.router_base_url);
|
|
80472
|
+
const expectedBase = validRouterBaseUrl(link3.routerBaseUrl ?? DEFAULT_ROUTER_BASE_URL);
|
|
80473
|
+
if (returnedBase !== expectedBase) {
|
|
80474
|
+
throw new RouterClientError(
|
|
80475
|
+
"http",
|
|
80476
|
+
"The Router balance key response named an unexpected Router base URL."
|
|
80477
|
+
);
|
|
80478
|
+
}
|
|
80479
|
+
try {
|
|
80480
|
+
await deps.secrets.set(account, parsed.data.router_key);
|
|
80481
|
+
} catch {
|
|
80482
|
+
throw new RouterClientError("http", "The Router balance key could not be stored safely.");
|
|
80483
|
+
}
|
|
80484
|
+
});
|
|
80396
80485
|
}
|
|
80397
80486
|
);
|
|
80398
80487
|
}
|
|
@@ -80433,12 +80522,14 @@ async function routerBalanceCredentialSnapshot(deps) {
|
|
|
80433
80522
|
async function removeRejectedBalanceKey(deps, rejected) {
|
|
80434
80523
|
if (!deps.secrets.available) return;
|
|
80435
80524
|
await withAgentCredentialLock(deps.wallets, rejected.clientId, async () => {
|
|
80436
|
-
|
|
80437
|
-
|
|
80438
|
-
|
|
80439
|
-
|
|
80440
|
-
await deps.secrets.
|
|
80441
|
-
|
|
80525
|
+
await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
|
|
80526
|
+
const link3 = await linkedWallet(deps);
|
|
80527
|
+
if (link3.clientId !== rejected.clientId) return;
|
|
80528
|
+
const account = agentSecretAccounts(deps.wallet).routerBalance;
|
|
80529
|
+
if (await deps.secrets.get(account) === rejected.routerKey) {
|
|
80530
|
+
await deps.secrets.remove(account);
|
|
80531
|
+
}
|
|
80532
|
+
});
|
|
80442
80533
|
});
|
|
80443
80534
|
}
|
|
80444
80535
|
async function routerAccessToken(deps) {
|
|
@@ -80526,32 +80617,34 @@ async function rotateRouterKey(deps) {
|
|
|
80526
80617
|
validRouterBaseUrl(parsed.data.router_base_url);
|
|
80527
80618
|
try {
|
|
80528
80619
|
await withAgentCredentialLock(deps.wallets, link3.clientId, async () => {
|
|
80529
|
-
|
|
80530
|
-
|
|
80531
|
-
|
|
80532
|
-
|
|
80533
|
-
|
|
80534
|
-
|
|
80535
|
-
|
|
80536
|
-
previousKey = await deps.secrets.get(account);
|
|
80537
|
-
await deps.secrets.set(account, parsed.data.router_key);
|
|
80538
|
-
} catch {
|
|
80539
|
-
throw new RouterClientError("http", "The Router key could not be stored safely.");
|
|
80540
|
-
}
|
|
80541
|
-
try {
|
|
80542
|
-
await deps.wallets.setLink(deps.wallet, {
|
|
80543
|
-
...currentLink,
|
|
80544
|
-
routerBaseUrl: parsed.data.router_base_url
|
|
80545
|
-
});
|
|
80546
|
-
} catch {
|
|
80620
|
+
await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
|
|
80621
|
+
const currentLink = await linkedWallet(deps);
|
|
80622
|
+
if (!sameAgentLink(currentLink, link3)) {
|
|
80623
|
+
throw new RouterClientError("http", "The agent link changed during Router key rotation.");
|
|
80624
|
+
}
|
|
80625
|
+
const account = agentSecretAccounts(deps.wallet).routerStake;
|
|
80626
|
+
let previousKey;
|
|
80547
80627
|
try {
|
|
80548
|
-
|
|
80549
|
-
|
|
80628
|
+
previousKey = await deps.secrets.get(account);
|
|
80629
|
+
await deps.secrets.set(account, parsed.data.router_key);
|
|
80550
80630
|
} catch {
|
|
80551
|
-
|
|
80631
|
+
throw new RouterClientError("http", "The Router key could not be stored safely.");
|
|
80552
80632
|
}
|
|
80553
|
-
|
|
80554
|
-
|
|
80633
|
+
try {
|
|
80634
|
+
await deps.wallets.setLink(deps.wallet, {
|
|
80635
|
+
...currentLink,
|
|
80636
|
+
routerBaseUrl: parsed.data.router_base_url
|
|
80637
|
+
});
|
|
80638
|
+
} catch {
|
|
80639
|
+
try {
|
|
80640
|
+
if (previousKey === void 0) await deps.secrets.remove(account);
|
|
80641
|
+
else await deps.secrets.set(account, previousKey);
|
|
80642
|
+
} catch {
|
|
80643
|
+
await deps.wallets.clearLink(deps.wallet).catch(() => void 0);
|
|
80644
|
+
}
|
|
80645
|
+
throw new RouterClientError("http", "The Router key could not be stored safely.");
|
|
80646
|
+
}
|
|
80647
|
+
});
|
|
80555
80648
|
});
|
|
80556
80649
|
} catch (error61) {
|
|
80557
80650
|
if (error61 instanceof RouterClientError) throw error61;
|
|
@@ -85964,34 +86057,48 @@ async function searchDocs(query, options = {}) {
|
|
|
85964
86057
|
throw new DocsError("invalid_input", "Search limit must be a positive integer.");
|
|
85965
86058
|
}
|
|
85966
86059
|
const origin = resolveDocsOrigin(options.env);
|
|
85967
|
-
const
|
|
85968
|
-
|
|
85969
|
-
|
|
85970
|
-
|
|
85971
|
-
|
|
85972
|
-
|
|
85973
|
-
|
|
85974
|
-
|
|
85975
|
-
|
|
85976
|
-
|
|
85977
|
-
|
|
85978
|
-
method: "tools/call",
|
|
85979
|
-
params: { name: "searchDocumentation", arguments: { query: normalized } }
|
|
85980
|
-
})
|
|
86060
|
+
const requestOptions2 = {
|
|
86061
|
+
operation: "search",
|
|
86062
|
+
origin,
|
|
86063
|
+
timeoutMs: options.timeoutMs ?? SEARCH_TIMEOUT_MS,
|
|
86064
|
+
fetchImpl: options.fetchImpl
|
|
86065
|
+
};
|
|
86066
|
+
const searchRequest = (name, args) => ({
|
|
86067
|
+
method: "POST",
|
|
86068
|
+
headers: {
|
|
86069
|
+
"content-type": "application/json",
|
|
86070
|
+
accept: "application/json, text/event-stream"
|
|
85981
86071
|
},
|
|
85982
|
-
{
|
|
85983
|
-
|
|
85984
|
-
|
|
85985
|
-
|
|
85986
|
-
|
|
85987
|
-
}
|
|
85988
|
-
);
|
|
85989
|
-
const payload = parseSearchEnvelope(body);
|
|
85990
|
-
const blocks = searchTextBlocks(payload);
|
|
85991
|
-
const results = blocks.flatMap((block) => {
|
|
85992
|
-
const parsed = parseSearchBlock(block);
|
|
85993
|
-
return parsed === void 0 ? [] : [parsed];
|
|
86072
|
+
body: JSON.stringify({
|
|
86073
|
+
jsonrpc: "2.0",
|
|
86074
|
+
id: 1,
|
|
86075
|
+
method: "tools/call",
|
|
86076
|
+
params: { name, arguments: args }
|
|
86077
|
+
})
|
|
85994
86078
|
});
|
|
86079
|
+
let results;
|
|
86080
|
+
try {
|
|
86081
|
+
const { text: body } = await requestText(
|
|
86082
|
+
new URL("/mcp", origin),
|
|
86083
|
+
searchRequest("search_docs", {
|
|
86084
|
+
query: normalized,
|
|
86085
|
+
...options.limit === void 0 ? {} : { limit: Math.min(options.limit, 10) }
|
|
86086
|
+
}),
|
|
86087
|
+
{ ...requestOptions2, notFoundOn404: true, notFoundOn405: true }
|
|
86088
|
+
);
|
|
86089
|
+
results = parseSiteSearch(searchTextBlocks(parseSearchEnvelope(body)), origin);
|
|
86090
|
+
} catch (error61) {
|
|
86091
|
+
if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
|
|
86092
|
+
const { text: body } = await requestText(
|
|
86093
|
+
new URL("/~gitbook/mcp", origin),
|
|
86094
|
+
searchRequest("searchDocumentation", { query: normalized }),
|
|
86095
|
+
requestOptions2
|
|
86096
|
+
);
|
|
86097
|
+
results = searchTextBlocks(parseSearchEnvelope(body)).flatMap((block) => {
|
|
86098
|
+
const parsed = parseSearchBlock(block);
|
|
86099
|
+
return parsed === void 0 ? [] : [parsed];
|
|
86100
|
+
});
|
|
86101
|
+
}
|
|
85995
86102
|
return { results: options.limit === void 0 ? results : results.slice(0, options.limit) };
|
|
85996
86103
|
}
|
|
85997
86104
|
async function readDocs(pageUrlOrPath, options = {}) {
|
|
@@ -86019,7 +86126,7 @@ async function readDocs(pageUrlOrPath, options = {}) {
|
|
|
86019
86126
|
}
|
|
86020
86127
|
async function readFirstMarkdown(page, options) {
|
|
86021
86128
|
const path = page.pathname.replace(/\/+$/u, "");
|
|
86022
|
-
const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/readme.md"];
|
|
86129
|
+
const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/index.md", "/readme.md"];
|
|
86023
86130
|
for (const pathname of candidates) {
|
|
86024
86131
|
const candidate = new URL(page);
|
|
86025
86132
|
candidate.pathname = pathname;
|
|
@@ -86043,17 +86150,32 @@ async function askDocs(question, options = {}) {
|
|
|
86043
86150
|
const origin = resolveDocsOrigin(options.env);
|
|
86044
86151
|
const url2 = new URL("/readme.md", origin);
|
|
86045
86152
|
url2.searchParams.set("ask", normalized);
|
|
86046
|
-
|
|
86047
|
-
|
|
86048
|
-
|
|
86049
|
-
|
|
86050
|
-
|
|
86051
|
-
|
|
86052
|
-
|
|
86053
|
-
|
|
86054
|
-
|
|
86055
|
-
|
|
86056
|
-
|
|
86153
|
+
try {
|
|
86154
|
+
const { text: markdown } = await requestText(
|
|
86155
|
+
url2,
|
|
86156
|
+
{ method: "GET", headers: { accept: "text/markdown" } },
|
|
86157
|
+
{
|
|
86158
|
+
operation: "ask",
|
|
86159
|
+
origin,
|
|
86160
|
+
timeoutMs: options.timeoutMs ?? ASK_TIMEOUT_MS,
|
|
86161
|
+
fetchImpl: options.fetchImpl,
|
|
86162
|
+
notFoundOn404: true
|
|
86163
|
+
}
|
|
86164
|
+
);
|
|
86165
|
+
return parseAnswer(markdown);
|
|
86166
|
+
} catch (error61) {
|
|
86167
|
+
if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
|
|
86168
|
+
}
|
|
86169
|
+
const { results } = await searchDocs(normalized, { ...options, limit: 3 });
|
|
86170
|
+
if (results.length === 0) return { answer: "No matching documentation found.", sources: [] };
|
|
86171
|
+
return {
|
|
86172
|
+
answer: [
|
|
86173
|
+
"These are the closest sections of the docs; the new docs site has no assistant.",
|
|
86174
|
+
"",
|
|
86175
|
+
...results.map(({ title, url: url3, excerpt }) => `- [${title}](${url3}): ${excerpt}`)
|
|
86176
|
+
].join("\n"),
|
|
86177
|
+
sources: results.map(({ title, url: url3 }) => ({ title, url: url3 }))
|
|
86178
|
+
};
|
|
86057
86179
|
}
|
|
86058
86180
|
function nonEmpty(value, label) {
|
|
86059
86181
|
const normalized = value.trim();
|
|
@@ -86125,7 +86247,7 @@ async function requestText(requestUrl2, init, options) {
|
|
|
86125
86247
|
assertAllowedUrl(next, options.origin);
|
|
86126
86248
|
url2 = next;
|
|
86127
86249
|
}
|
|
86128
|
-
if (options.notFoundOn404 && response.status === 404) {
|
|
86250
|
+
if (options.notFoundOn404 && response.status === 404 || options.notFoundOn405 && response.status === 405) {
|
|
86129
86251
|
throw new DocsError("not_found", `Documentation page not found: ${url2.href}`);
|
|
86130
86252
|
}
|
|
86131
86253
|
if (!response.ok) {
|
|
@@ -86230,12 +86352,40 @@ function searchTextBlocks(payload) {
|
|
|
86230
86352
|
throw new DocsError("bad_response", `The documentation search returned an error${message}`);
|
|
86231
86353
|
}
|
|
86232
86354
|
const result = asRecord(envelope?.result);
|
|
86355
|
+
if (result?.isError === true) {
|
|
86356
|
+
throw new DocsError("bad_response", "The documentation search tool returned an error.");
|
|
86357
|
+
}
|
|
86233
86358
|
if (!Array.isArray(result?.content)) throw invalidSearchResponse();
|
|
86234
86359
|
return result.content.flatMap((item) => {
|
|
86235
86360
|
const block = asRecord(item);
|
|
86236
86361
|
return block?.type === "text" && typeof block.text === "string" ? [block.text] : [];
|
|
86237
86362
|
});
|
|
86238
86363
|
}
|
|
86364
|
+
function parseSiteSearch(blocks, origin) {
|
|
86365
|
+
if (blocks.length === 0) throw invalidSearchResponse();
|
|
86366
|
+
return blocks.flatMap((block) => {
|
|
86367
|
+
const items = parseJson2(block);
|
|
86368
|
+
if (!Array.isArray(items)) throw invalidSearchResponse();
|
|
86369
|
+
return items.map((item) => {
|
|
86370
|
+
const entry = asRecord(item);
|
|
86371
|
+
if (typeof entry?.title !== "string" || typeof entry.url !== "string" || typeof entry.heading !== "string" || typeof entry.snippet !== "string") {
|
|
86372
|
+
throw invalidSearchResponse();
|
|
86373
|
+
}
|
|
86374
|
+
let url2;
|
|
86375
|
+
try {
|
|
86376
|
+
url2 = new URL(entry.url, origin);
|
|
86377
|
+
} catch {
|
|
86378
|
+
throw invalidSearchResponse();
|
|
86379
|
+
}
|
|
86380
|
+
assertAllowedUrl(url2, origin);
|
|
86381
|
+
return {
|
|
86382
|
+
title: entry.heading ? `${entry.title} \u203A ${entry.heading}` : entry.title,
|
|
86383
|
+
url: url2.href,
|
|
86384
|
+
excerpt: entry.snippet
|
|
86385
|
+
};
|
|
86386
|
+
});
|
|
86387
|
+
});
|
|
86388
|
+
}
|
|
86239
86389
|
function parseSearchBlock(block) {
|
|
86240
86390
|
const match = /^Title:\s*([^\r\n]+)\r?\nLink:\s*([^\r\n]+)\r?\nContent:\s*([\s\S]*)$/u.exec(
|
|
86241
86391
|
block.trim()
|
|
@@ -102499,7 +102649,7 @@ async function readProcessStdin() {
|
|
|
102499
102649
|
}
|
|
102500
102650
|
|
|
102501
102651
|
// src/version.ts
|
|
102502
|
-
var CLI_VERSION = "0.15.
|
|
102652
|
+
var CLI_VERSION = "0.15.2";
|
|
102503
102653
|
|
|
102504
102654
|
// src/status.ts
|
|
102505
102655
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -106287,6 +106437,10 @@ ${RUN_USAGE}`
|
|
|
106287
106437
|
${RUN_USAGE}`);
|
|
106288
106438
|
}
|
|
106289
106439
|
const environment = getEnvironment(dependencies);
|
|
106440
|
+
const runIo = resultFile === void 0 ? io : {
|
|
106441
|
+
stdout: (message) => io.stdout(redactDetachedRunText(message, environment)),
|
|
106442
|
+
stderr: (message) => io.stderr(redactDetachedRunText(message, environment))
|
|
106443
|
+
};
|
|
106290
106444
|
const configuredRunId = environmentRunId(environment, "VAPI_RUN_ID");
|
|
106291
106445
|
const parentRunId = environmentRunId(environment, "VAPI_PARENT_RUN_ID");
|
|
106292
106446
|
const paths = getVapiPaths();
|
|
@@ -106298,8 +106452,8 @@ ${RUN_USAGE}`);
|
|
|
106298
106452
|
if (resultFile !== void 0) {
|
|
106299
106453
|
await writeJsonAtomic(resultFile, { v: 1, exitCode: 1, result: result2 }, { mode: 384 });
|
|
106300
106454
|
}
|
|
106301
|
-
if (json2)
|
|
106302
|
-
else
|
|
106455
|
+
if (json2) runIo.stdout(JSON.stringify(result2));
|
|
106456
|
+
else runIo.stderr(message);
|
|
106303
106457
|
return 1;
|
|
106304
106458
|
}
|
|
106305
106459
|
const runId = configuredRunId ?? createRunId();
|
|
@@ -106363,42 +106517,48 @@ ${RUN_USAGE}`);
|
|
|
106363
106517
|
...runMeta === void 0 ? {} : { runMeta },
|
|
106364
106518
|
approvals: "tty",
|
|
106365
106519
|
json: json2,
|
|
106366
|
-
io,
|
|
106520
|
+
io: runIo,
|
|
106367
106521
|
dependencies
|
|
106368
106522
|
});
|
|
106369
106523
|
const execute = dependencies.agent?.runAgent ?? runAgent;
|
|
106370
106524
|
const executed = await execute(task, runDependencies);
|
|
106371
106525
|
const result = resultFile === void 0 ? executed : redactAgentRunResult(executed, environment);
|
|
106372
|
-
if (!json2) printAgentRefills(result, io);
|
|
106526
|
+
if (!json2) printAgentRefills(result, runIo, io);
|
|
106373
106527
|
const exitCode = result.stoppedBecause.reason === "finished" ? 0 : 1;
|
|
106374
106528
|
if (resultFile !== void 0) {
|
|
106375
106529
|
await writeJsonAtomic(resultFile, { v: 1, exitCode, result }, { mode: 384 });
|
|
106376
106530
|
}
|
|
106377
106531
|
if (json2) {
|
|
106378
|
-
io.stdout(
|
|
106532
|
+
io.stdout(
|
|
106533
|
+
JSON.stringify(resultFile === void 0 ? result : redactAgentRunResult(result, environment))
|
|
106534
|
+
);
|
|
106379
106535
|
} else if (result.stoppedBecause.reason === "finished") {
|
|
106380
|
-
|
|
106536
|
+
runIo.stdout(result.answer ?? "");
|
|
106381
106537
|
} else {
|
|
106382
|
-
|
|
106538
|
+
runIo.stderr(result.stoppedBecause.detail ?? result.stoppedBecause.reason);
|
|
106383
106539
|
}
|
|
106384
106540
|
return exitCode;
|
|
106385
106541
|
}
|
|
106542
|
+
var SETTLEMENT_HASH = /^0x[0-9a-fA-F]{64}$/u;
|
|
106386
106543
|
function redactAgentRunResult(executed, environment) {
|
|
106387
106544
|
const result = redactDetachedRunValue(executed, environment);
|
|
106388
106545
|
for (const [index2, refill] of (executed.refills ?? []).entries()) {
|
|
106389
106546
|
const transaction2 = refill.receipt.transaction;
|
|
106390
106547
|
const redacted = result.refills?.[index2];
|
|
106391
|
-
if (redacted !== void 0 && transaction2 !== void 0 &&
|
|
106548
|
+
if (redacted !== void 0 && transaction2 !== void 0 && SETTLEMENT_HASH.test(transaction2)) {
|
|
106392
106549
|
redacted.receipt.transaction = transaction2;
|
|
106393
106550
|
}
|
|
106394
106551
|
}
|
|
106395
106552
|
return result;
|
|
106396
106553
|
}
|
|
106397
|
-
function printAgentRefills(result, io) {
|
|
106554
|
+
function printAgentRefills(result, io, settlementHashIo = io) {
|
|
106398
106555
|
for (const refill of result.refills ?? []) {
|
|
106399
106556
|
io.stderr(`Receipt: ${refill.receipt.id}`);
|
|
106400
|
-
|
|
106401
|
-
|
|
106557
|
+
const transaction2 = refill.receipt.transaction;
|
|
106558
|
+
if (transaction2 !== void 0) {
|
|
106559
|
+
const output4 = SETTLEMENT_HASH.test(transaction2) ? settlementHashIo : io;
|
|
106560
|
+
output4.stderr(`Transaction: ${transaction2}`);
|
|
106561
|
+
}
|
|
106402
106562
|
for (const warning of refill.warnings ?? []) io.stderr(warning.message);
|
|
106403
106563
|
}
|
|
106404
106564
|
}
|
|
@@ -110999,12 +111159,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
110999
111159
|
exitCode = 0;
|
|
111000
111160
|
break;
|
|
111001
111161
|
case "agent":
|
|
111002
|
-
exitCode = await agentCommand(
|
|
111003
|
-
args.slice(1),
|
|
111004
|
-
json2,
|
|
111005
|
-
args[1] === "run" && args.includes("--bundle-env") ? io : runIo,
|
|
111006
|
-
dependencies
|
|
111007
|
-
);
|
|
111162
|
+
exitCode = await agentCommand(args.slice(1), json2, io, dependencies);
|
|
111008
111163
|
break;
|
|
111009
111164
|
case "dashboard":
|
|
111010
111165
|
await dashboardCommand(args.slice(1), json2, io, dependencies);
|