@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 CHANGED
@@ -14,7 +14,11 @@ export type AgentCommandDependencies = {
14
14
  export declare function agentCommand(argv: string[], json: boolean, io: CliIo, dependencies: CliDependencies): Promise<number>;
15
15
  /** Redact all strings, then restore only public EVM settlement references. */
16
16
  export declare function redactAgentRunResult(executed: RunAgentResult, environment: NodeJS.ProcessEnv): RunAgentResult;
17
- export declare function printAgentRefills(result: RunAgentResult, io: CliIo): void;
17
+ /**
18
+ * Prints each refill's receipt, transaction and warnings. When `io` redacts its lines, pass the
19
+ * plain output as `settlementHashIo`: a transaction that is a settlement hash is printed there.
20
+ */
21
+ export declare function printAgentRefills(result: RunAgentResult, io: CliIo, settlementHashIo?: CliIo): void;
18
22
  export declare function buildAgentRunDeps(input: {
19
23
  profile: AgentProfile;
20
24
  runId: string;
package/dist/cli.js CHANGED
@@ -43926,7 +43926,7 @@ async function assertPublicUrl(url2, options) {
43926
43926
  options.timeoutMs ?? 5e3
43927
43927
  );
43928
43928
  } catch {
43929
- throw guardError(url2);
43929
+ throw guardError(url2, "unresolved");
43930
43930
  }
43931
43931
  if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
43932
43932
  throw guardError(url2);
@@ -44081,10 +44081,67 @@ function isNonPublicIpv6(hextets) {
44081
44081
  const isDocumentation = first === 8193 && hextets[1] === 3512;
44082
44082
  return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
44083
44083
  }
44084
- function guardError(url2) {
44085
- return new Error(
44086
- `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
44084
+ var NetworkGuardError = class extends Error {
44085
+ constructor(message, reason) {
44086
+ super(message);
44087
+ this.reason = reason;
44088
+ this.name = "NetworkGuardError";
44089
+ }
44090
+ reason;
44091
+ };
44092
+ function guardError(url2, reason = "blocked") {
44093
+ return new NetworkGuardError(
44094
+ `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`,
44095
+ reason
44096
+ );
44097
+ }
44098
+ var PROXY_VARIABLES = {
44099
+ "https:": ["HTTPS_PROXY", "https_proxy"],
44100
+ "http:": ["HTTP_PROXY", "http_proxy"]
44101
+ };
44102
+ var SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/u;
44103
+ function describeNetworkFailure(error61, url2, env = process.env) {
44104
+ const host = url2.host;
44105
+ let reason;
44106
+ const guard = guardReason(error61);
44107
+ if (guard !== void 0) {
44108
+ reason = guard === "unresolved" ? `the DNS lookup for ${host} failed` : `${host} is not a public address`;
44109
+ } else if (isTimeout(error61)) {
44110
+ reason = `the connection to ${host} timed out`;
44111
+ } else {
44112
+ const code = systemErrorCode(error61);
44113
+ reason = `could not connect to ${host}${code === void 0 ? "" : ` (${code})`}`;
44114
+ }
44115
+ const proxy = (PROXY_VARIABLES[url2.protocol] ?? []).find(
44116
+ (name) => (env[name] ?? "").trim() !== ""
44087
44117
  );
44118
+ let hint = "";
44119
+ if (proxy !== void 0) {
44120
+ if (env.NODE_USE_ENV_PROXY !== "1") {
44121
+ 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.`;
44122
+ } else if (guard === "unresolved") {
44123
+ hint = ` vapi looks ${host} up on this machine before it uses the proxy in ${proxy}, so the name must resolve here too.`;
44124
+ } else if (guard === void 0) {
44125
+ hint = ` NODE_USE_ENV_PROXY=1 and ${proxy} are set, so the proxy may have refused the connection.`;
44126
+ }
44127
+ }
44128
+ return `${reason}.${hint}`;
44129
+ }
44130
+ function guardReason(error61) {
44131
+ if (!(error61 instanceof Error) || error61.name !== "NetworkGuardError") return void 0;
44132
+ const reason = error61.reason;
44133
+ return reason === "blocked" || reason === "unresolved" ? reason : void 0;
44134
+ }
44135
+ function isTimeout(error61) {
44136
+ return error61 instanceof Error && (error61.name === "TimeoutError" || error61.name === "AbortError");
44137
+ }
44138
+ function systemErrorCode(error61) {
44139
+ for (let current = error61, depth = 0; current instanceof Error && depth < 3; depth += 1) {
44140
+ const code = current.code;
44141
+ if (typeof code === "string" && SYSTEM_ERROR_CODE.test(code)) return code;
44142
+ current = current.cause;
44143
+ }
44144
+ return void 0;
44088
44145
  }
44089
44146
 
44090
44147
  // ../core/src/networks.ts
@@ -47203,12 +47260,12 @@ async function removeStaleLock(path) {
47203
47260
  const pid = lockOwnerPid(owner);
47204
47261
  if (pid !== void 0 && processIsAlive(pid)) return;
47205
47262
  await atomicFileTestHooks?.beforeStaleLockBreak?.(path);
47206
- await removeOwnedLock(path, [owner]);
47263
+ await removeOwnedLock(path, [owner], true);
47207
47264
  } catch (error61) {
47208
47265
  if (!hasCode(error61, "ENOENT")) throw error61;
47209
47266
  }
47210
47267
  }
47211
- async function removeOwnedLock(path, owners) {
47268
+ async function removeOwnedLock(path, owners, staleDeadOwner = false) {
47212
47269
  const tombPath = `${path}.stale.${randomBytes2(16).toString("hex")}`;
47213
47270
  try {
47214
47271
  await rename(path, tombPath);
@@ -47217,7 +47274,7 @@ async function removeOwnedLock(path, owners) {
47217
47274
  await removeOwnedTombs(path, owners);
47218
47275
  const currentOwner = await readFile(path, "utf8").catch(() => void 0);
47219
47276
  if (currentOwner !== void 0 && owners.includes(currentOwner)) {
47220
- await removeOwnedLock(path, owners);
47277
+ await removeOwnedLock(path, owners, staleDeadOwner);
47221
47278
  }
47222
47279
  return;
47223
47280
  }
@@ -47226,6 +47283,7 @@ async function removeOwnedLock(path, owners) {
47226
47283
  let pendingError;
47227
47284
  let renamedOwner;
47228
47285
  try {
47286
+ await atomicFileTestHooks?.afterLockRename?.(tombPath);
47229
47287
  renamedOwner = await readFile(tombPath, "utf8");
47230
47288
  if (!owners.includes(renamedOwner) && !lockOwnerReleased(renamedOwner)) {
47231
47289
  await atomicFileTestHooks?.afterMismatchedLockRename?.(path);
@@ -47234,6 +47292,7 @@ async function removeOwnedLock(path, owners) {
47234
47292
  await atomicFileTestHooks?.afterMismatchedLockRestore?.(path);
47235
47293
  }
47236
47294
  } catch (error61) {
47295
+ if (hasCode(error61, "ENOENT")) return;
47237
47296
  pendingError = error61;
47238
47297
  }
47239
47298
  try {
@@ -47242,7 +47301,7 @@ async function removeOwnedLock(path, owners) {
47242
47301
  } catch (error61) {
47243
47302
  if (!tombUnlinkTolerated(
47244
47303
  error61,
47245
- renamedOwner !== void 0 && lockOwnerReleased(renamedOwner) && owners.includes(renamedOwner)
47304
+ renamedOwner !== void 0 && (lockOwnerReleased(renamedOwner) || staleDeadOwner) && owners.includes(renamedOwner)
47246
47305
  ) && pendingError === void 0) {
47247
47306
  pendingError = error61;
47248
47307
  }
@@ -48405,7 +48464,7 @@ async function withCredentialLockFile(lockPath, operation) {
48405
48464
  try {
48406
48465
  return await operation();
48407
48466
  } finally {
48408
- await handle.close();
48467
+ await handle.close().catch(() => void 0);
48409
48468
  await unlink2(lockPath).catch(() => void 0);
48410
48469
  }
48411
48470
  }
@@ -48469,16 +48528,25 @@ function withBearer(init, accessToken) {
48469
48528
  async function safeFetch(fetchImpl, input2, init) {
48470
48529
  try {
48471
48530
  return await fetchImpl(input2, init);
48472
- } catch {
48473
- throw httpError("The vAPI agent link request failed.");
48531
+ } catch (error61) {
48532
+ throw httpError(`The vAPI agent link request failed: ${networkFailure(error61, input2)}`);
48474
48533
  }
48475
48534
  }
48476
48535
  async function safeAgentFetch(fetchImpl, input2, init) {
48477
48536
  try {
48478
48537
  return await fetchImpl(input2, init);
48538
+ } catch (error61) {
48539
+ throw httpError(`The vAPI agent request failed: ${networkFailure(error61, input2)}`);
48540
+ }
48541
+ }
48542
+ function networkFailure(error61, input2) {
48543
+ let url2;
48544
+ try {
48545
+ url2 = new URL(input2 instanceof Request ? input2.url : input2);
48479
48546
  } catch {
48480
- throw httpError("The vAPI agent request failed.");
48547
+ return "the request did not reach vAPI.";
48481
48548
  }
48549
+ return describeNetworkFailure(error61, url2);
48482
48550
  }
48483
48551
  function deviceAuthorizationError(status, payload) {
48484
48552
  const error61 = stringField(payload, "error");
@@ -71176,7 +71244,7 @@ async function withVaultLock(path, operation) {
71176
71244
  try {
71177
71245
  return await operation();
71178
71246
  } finally {
71179
- await handle.close();
71247
+ await handle.close().catch(() => void 0);
71180
71248
  await unlink4(lockPath).catch(() => void 0);
71181
71249
  }
71182
71250
  }
@@ -74070,7 +74138,7 @@ async function withRegistryLock(path, operation) {
74070
74138
  try {
74071
74139
  return await operation();
74072
74140
  } finally {
74073
- await handle.close();
74141
+ await handle.close().catch(() => void 0);
74074
74142
  await unlink7(lockPath).catch(() => void 0);
74075
74143
  }
74076
74144
  }
@@ -74961,7 +75029,7 @@ async function withLedgerLock(path, operation) {
74961
75029
  try {
74962
75030
  return await operation();
74963
75031
  } finally {
74964
- await handle.close();
75032
+ await handle.close().catch(() => void 0);
74965
75033
  await unlink9(lockPath).catch(() => void 0);
74966
75034
  }
74967
75035
  }
@@ -75261,13 +75329,32 @@ async function transferBetweenAccounts(args) {
75261
75329
  if (existing !== void 0 && existing.transfer?.status !== "failed") {
75262
75330
  throw transferError("authorization_invalid");
75263
75331
  }
75264
- await appendTransferReceipt(context, request, {
75265
- receiptId,
75266
- status: "unknown",
75267
- txHash: null,
75268
- replayed: false,
75269
- reservedOn
75270
- });
75332
+ try {
75333
+ await appendTransferReceipt(context, request, {
75334
+ receiptId,
75335
+ status: "unknown",
75336
+ txHash: null,
75337
+ replayed: false,
75338
+ reservedOn
75339
+ });
75340
+ } catch (error61) {
75341
+ let persisted;
75342
+ try {
75343
+ persisted = await findTransferReceipt(context, nonce);
75344
+ } catch {
75345
+ authorizationPersisted = true;
75346
+ }
75347
+ if (persisted !== void 0 && persisted.transfer?.status !== "failed") {
75348
+ authorizationPersisted = true;
75349
+ }
75350
+ if (!authorizationPersisted) throw error61;
75351
+ return transferResult(context, {
75352
+ status: "unknown",
75353
+ txHash: null,
75354
+ nonce: request.authorization.nonce,
75355
+ replayed: false
75356
+ });
75357
+ }
75271
75358
  try {
75272
75359
  await syncReceipts(context.receiptsPath);
75273
75360
  } catch (error61) {
@@ -78572,7 +78659,7 @@ function createRunBudget(args) {
78572
78659
  import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
78573
78660
  import { arch, platform, release } from "node:os";
78574
78661
  import { join as join14 } from "node:path";
78575
- var VAPI_CLIENT_VERSION = "0.15.0";
78662
+ var VAPI_CLIENT_VERSION = "0.15.2";
78576
78663
  async function createSupportReport(options) {
78577
78664
  const message = options.message.trim();
78578
78665
  if (!message) throw new Error("Support report message must not be empty.");
@@ -80375,26 +80462,28 @@ async function ensureBalanceRouterKey(deps, paidLink) {
80375
80462
  if (!parsed.success) {
80376
80463
  throw new RouterClientError("http", "The Router balance key response was invalid.");
80377
80464
  }
80378
- const currentLink = await linkedWallet(deps);
80379
- if (!sameAgentLink(currentLink, paidLink)) {
80380
- throw new RouterClientError(
80381
- "http",
80382
- "The agent link changed while fetching the Router balance key."
80383
- );
80384
- }
80385
- const returnedBase = validRouterBaseUrl(parsed.data.router_base_url);
80386
- const expectedBase = validRouterBaseUrl(link3.routerBaseUrl ?? DEFAULT_ROUTER_BASE_URL);
80387
- if (returnedBase !== expectedBase) {
80388
- throw new RouterClientError(
80389
- "http",
80390
- "The Router balance key response named an unexpected Router base URL."
80391
- );
80392
- }
80393
- try {
80394
- await deps.secrets.set(account, parsed.data.router_key);
80395
- } catch {
80396
- throw new RouterClientError("http", "The Router balance key could not be stored safely.");
80397
- }
80465
+ await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
80466
+ const currentLink = await linkedWallet(deps);
80467
+ if (!sameAgentLink(currentLink, paidLink)) {
80468
+ throw new RouterClientError(
80469
+ "http",
80470
+ "The agent link changed while fetching the Router balance key."
80471
+ );
80472
+ }
80473
+ const returnedBase = validRouterBaseUrl(parsed.data.router_base_url);
80474
+ const expectedBase = validRouterBaseUrl(link3.routerBaseUrl ?? DEFAULT_ROUTER_BASE_URL);
80475
+ if (returnedBase !== expectedBase) {
80476
+ throw new RouterClientError(
80477
+ "http",
80478
+ "The Router balance key response named an unexpected Router base URL."
80479
+ );
80480
+ }
80481
+ try {
80482
+ await deps.secrets.set(account, parsed.data.router_key);
80483
+ } catch {
80484
+ throw new RouterClientError("http", "The Router balance key could not be stored safely.");
80485
+ }
80486
+ });
80398
80487
  }
80399
80488
  );
80400
80489
  }
@@ -80435,12 +80524,14 @@ async function routerBalanceCredentialSnapshot(deps) {
80435
80524
  async function removeRejectedBalanceKey(deps, rejected) {
80436
80525
  if (!deps.secrets.available) return;
80437
80526
  await withAgentCredentialLock(deps.wallets, rejected.clientId, async () => {
80438
- const link3 = await linkedWallet(deps);
80439
- if (link3.clientId !== rejected.clientId) return;
80440
- const account = agentSecretAccounts(deps.wallet).routerBalance;
80441
- if (await deps.secrets.get(account) === rejected.routerKey) {
80442
- await deps.secrets.remove(account);
80443
- }
80527
+ await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
80528
+ const link3 = await linkedWallet(deps);
80529
+ if (link3.clientId !== rejected.clientId) return;
80530
+ const account = agentSecretAccounts(deps.wallet).routerBalance;
80531
+ if (await deps.secrets.get(account) === rejected.routerKey) {
80532
+ await deps.secrets.remove(account);
80533
+ }
80534
+ });
80444
80535
  });
80445
80536
  }
80446
80537
  async function routerAccessToken(deps) {
@@ -80528,32 +80619,34 @@ async function rotateRouterKey(deps) {
80528
80619
  validRouterBaseUrl(parsed.data.router_base_url);
80529
80620
  try {
80530
80621
  await withAgentCredentialLock(deps.wallets, link3.clientId, async () => {
80531
- const currentLink = await linkedWallet(deps);
80532
- if (!sameAgentLink(currentLink, link3)) {
80533
- throw new RouterClientError("http", "The agent link changed during Router key rotation.");
80534
- }
80535
- const account = agentSecretAccounts(deps.wallet).routerStake;
80536
- let previousKey;
80537
- try {
80538
- previousKey = await deps.secrets.get(account);
80539
- await deps.secrets.set(account, parsed.data.router_key);
80540
- } catch {
80541
- throw new RouterClientError("http", "The Router key could not be stored safely.");
80542
- }
80543
- try {
80544
- await deps.wallets.setLink(deps.wallet, {
80545
- ...currentLink,
80546
- routerBaseUrl: parsed.data.router_base_url
80547
- });
80548
- } catch {
80622
+ await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
80623
+ const currentLink = await linkedWallet(deps);
80624
+ if (!sameAgentLink(currentLink, link3)) {
80625
+ throw new RouterClientError("http", "The agent link changed during Router key rotation.");
80626
+ }
80627
+ const account = agentSecretAccounts(deps.wallet).routerStake;
80628
+ let previousKey;
80549
80629
  try {
80550
- if (previousKey === void 0) await deps.secrets.remove(account);
80551
- else await deps.secrets.set(account, previousKey);
80630
+ previousKey = await deps.secrets.get(account);
80631
+ await deps.secrets.set(account, parsed.data.router_key);
80552
80632
  } catch {
80553
- await deps.wallets.clearLink(deps.wallet).catch(() => void 0);
80633
+ throw new RouterClientError("http", "The Router key could not be stored safely.");
80554
80634
  }
80555
- throw new RouterClientError("http", "The Router key could not be stored safely.");
80556
- }
80635
+ try {
80636
+ await deps.wallets.setLink(deps.wallet, {
80637
+ ...currentLink,
80638
+ routerBaseUrl: parsed.data.router_base_url
80639
+ });
80640
+ } catch {
80641
+ try {
80642
+ if (previousKey === void 0) await deps.secrets.remove(account);
80643
+ else await deps.secrets.set(account, previousKey);
80644
+ } catch {
80645
+ await deps.wallets.clearLink(deps.wallet).catch(() => void 0);
80646
+ }
80647
+ throw new RouterClientError("http", "The Router key could not be stored safely.");
80648
+ }
80649
+ });
80557
80650
  });
80558
80651
  } catch (error61) {
80559
80652
  if (error61 instanceof RouterClientError) throw error61;
@@ -85966,34 +86059,48 @@ async function searchDocs(query, options = {}) {
85966
86059
  throw new DocsError("invalid_input", "Search limit must be a positive integer.");
85967
86060
  }
85968
86061
  const origin = resolveDocsOrigin(options.env);
85969
- const { text: body } = await requestText(
85970
- new URL("/~gitbook/mcp", origin),
85971
- {
85972
- method: "POST",
85973
- headers: {
85974
- "content-type": "application/json",
85975
- accept: "application/json, text/event-stream"
85976
- },
85977
- body: JSON.stringify({
85978
- jsonrpc: "2.0",
85979
- id: 1,
85980
- method: "tools/call",
85981
- params: { name: "searchDocumentation", arguments: { query: normalized } }
85982
- })
86062
+ const requestOptions2 = {
86063
+ operation: "search",
86064
+ origin,
86065
+ timeoutMs: options.timeoutMs ?? SEARCH_TIMEOUT_MS,
86066
+ fetchImpl: options.fetchImpl
86067
+ };
86068
+ const searchRequest = (name, args) => ({
86069
+ method: "POST",
86070
+ headers: {
86071
+ "content-type": "application/json",
86072
+ accept: "application/json, text/event-stream"
85983
86073
  },
85984
- {
85985
- operation: "search",
85986
- origin,
85987
- timeoutMs: options.timeoutMs ?? SEARCH_TIMEOUT_MS,
85988
- fetchImpl: options.fetchImpl
85989
- }
85990
- );
85991
- const payload = parseSearchEnvelope(body);
85992
- const blocks = searchTextBlocks(payload);
85993
- const results = blocks.flatMap((block) => {
85994
- const parsed = parseSearchBlock(block);
85995
- return parsed === void 0 ? [] : [parsed];
86074
+ body: JSON.stringify({
86075
+ jsonrpc: "2.0",
86076
+ id: 1,
86077
+ method: "tools/call",
86078
+ params: { name, arguments: args }
86079
+ })
85996
86080
  });
86081
+ let results;
86082
+ try {
86083
+ const { text: body } = await requestText(
86084
+ new URL("/mcp", origin),
86085
+ searchRequest("search_docs", {
86086
+ query: normalized,
86087
+ ...options.limit === void 0 ? {} : { limit: Math.min(options.limit, 10) }
86088
+ }),
86089
+ { ...requestOptions2, notFoundOn404: true, notFoundOn405: true }
86090
+ );
86091
+ results = parseSiteSearch(searchTextBlocks(parseSearchEnvelope(body)), origin);
86092
+ } catch (error61) {
86093
+ if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
86094
+ const { text: body } = await requestText(
86095
+ new URL("/~gitbook/mcp", origin),
86096
+ searchRequest("searchDocumentation", { query: normalized }),
86097
+ requestOptions2
86098
+ );
86099
+ results = searchTextBlocks(parseSearchEnvelope(body)).flatMap((block) => {
86100
+ const parsed = parseSearchBlock(block);
86101
+ return parsed === void 0 ? [] : [parsed];
86102
+ });
86103
+ }
85997
86104
  return { results: options.limit === void 0 ? results : results.slice(0, options.limit) };
85998
86105
  }
85999
86106
  async function readDocs(pageUrlOrPath, options = {}) {
@@ -86021,7 +86128,7 @@ async function readDocs(pageUrlOrPath, options = {}) {
86021
86128
  }
86022
86129
  async function readFirstMarkdown(page, options) {
86023
86130
  const path = page.pathname.replace(/\/+$/u, "");
86024
- const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/readme.md"];
86131
+ const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/index.md", "/readme.md"];
86025
86132
  for (const pathname of candidates) {
86026
86133
  const candidate = new URL(page);
86027
86134
  candidate.pathname = pathname;
@@ -86045,17 +86152,32 @@ async function askDocs(question, options = {}) {
86045
86152
  const origin = resolveDocsOrigin(options.env);
86046
86153
  const url2 = new URL("/readme.md", origin);
86047
86154
  url2.searchParams.set("ask", normalized);
86048
- const { text: markdown } = await requestText(
86049
- url2,
86050
- { method: "GET", headers: { accept: "text/markdown" } },
86051
- {
86052
- operation: "ask",
86053
- origin,
86054
- timeoutMs: options.timeoutMs ?? ASK_TIMEOUT_MS,
86055
- fetchImpl: options.fetchImpl
86056
- }
86057
- );
86058
- return parseAnswer(markdown);
86155
+ try {
86156
+ const { text: markdown } = await requestText(
86157
+ url2,
86158
+ { method: "GET", headers: { accept: "text/markdown" } },
86159
+ {
86160
+ operation: "ask",
86161
+ origin,
86162
+ timeoutMs: options.timeoutMs ?? ASK_TIMEOUT_MS,
86163
+ fetchImpl: options.fetchImpl,
86164
+ notFoundOn404: true
86165
+ }
86166
+ );
86167
+ return parseAnswer(markdown);
86168
+ } catch (error61) {
86169
+ if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
86170
+ }
86171
+ const { results } = await searchDocs(normalized, { ...options, limit: 3 });
86172
+ if (results.length === 0) return { answer: "No matching documentation found.", sources: [] };
86173
+ return {
86174
+ answer: [
86175
+ "These are the closest sections of the docs; the new docs site has no assistant.",
86176
+ "",
86177
+ ...results.map(({ title, url: url3, excerpt }) => `- [${title}](${url3}): ${excerpt}`)
86178
+ ].join("\n"),
86179
+ sources: results.map(({ title, url: url3 }) => ({ title, url: url3 }))
86180
+ };
86059
86181
  }
86060
86182
  function nonEmpty(value, label) {
86061
86183
  const normalized = value.trim();
@@ -86127,7 +86249,7 @@ async function requestText(requestUrl2, init, options) {
86127
86249
  assertAllowedUrl(next, options.origin);
86128
86250
  url2 = next;
86129
86251
  }
86130
- if (options.notFoundOn404 && response.status === 404) {
86252
+ if (options.notFoundOn404 && response.status === 404 || options.notFoundOn405 && response.status === 405) {
86131
86253
  throw new DocsError("not_found", `Documentation page not found: ${url2.href}`);
86132
86254
  }
86133
86255
  if (!response.ok) {
@@ -86232,12 +86354,40 @@ function searchTextBlocks(payload) {
86232
86354
  throw new DocsError("bad_response", `The documentation search returned an error${message}`);
86233
86355
  }
86234
86356
  const result = asRecord(envelope?.result);
86357
+ if (result?.isError === true) {
86358
+ throw new DocsError("bad_response", "The documentation search tool returned an error.");
86359
+ }
86235
86360
  if (!Array.isArray(result?.content)) throw invalidSearchResponse();
86236
86361
  return result.content.flatMap((item) => {
86237
86362
  const block = asRecord(item);
86238
86363
  return block?.type === "text" && typeof block.text === "string" ? [block.text] : [];
86239
86364
  });
86240
86365
  }
86366
+ function parseSiteSearch(blocks, origin) {
86367
+ if (blocks.length === 0) throw invalidSearchResponse();
86368
+ return blocks.flatMap((block) => {
86369
+ const items = parseJson2(block);
86370
+ if (!Array.isArray(items)) throw invalidSearchResponse();
86371
+ return items.map((item) => {
86372
+ const entry = asRecord(item);
86373
+ if (typeof entry?.title !== "string" || typeof entry.url !== "string" || typeof entry.heading !== "string" || typeof entry.snippet !== "string") {
86374
+ throw invalidSearchResponse();
86375
+ }
86376
+ let url2;
86377
+ try {
86378
+ url2 = new URL(entry.url, origin);
86379
+ } catch {
86380
+ throw invalidSearchResponse();
86381
+ }
86382
+ assertAllowedUrl(url2, origin);
86383
+ return {
86384
+ title: entry.heading ? `${entry.title} \u203A ${entry.heading}` : entry.title,
86385
+ url: url2.href,
86386
+ excerpt: entry.snippet
86387
+ };
86388
+ });
86389
+ });
86390
+ }
86241
86391
  function parseSearchBlock(block) {
86242
86392
  const match = /^Title:\s*([^\r\n]+)\r?\nLink:\s*([^\r\n]+)\r?\nContent:\s*([\s\S]*)$/u.exec(
86243
86393
  block.trim()
@@ -102504,7 +102654,7 @@ async function readProcessStdin() {
102504
102654
  }
102505
102655
 
102506
102656
  // src/version.ts
102507
- var CLI_VERSION = "0.15.0";
102657
+ var CLI_VERSION = "0.15.2";
102508
102658
 
102509
102659
  // src/status.ts
102510
102660
  async function statusCommand(argv, json2, io, dependencies) {
@@ -106292,6 +106442,10 @@ ${RUN_USAGE}`
106292
106442
  ${RUN_USAGE}`);
106293
106443
  }
106294
106444
  const environment = getEnvironment(dependencies);
106445
+ const runIo = resultFile === void 0 ? io : {
106446
+ stdout: (message) => io.stdout(redactDetachedRunText(message, environment)),
106447
+ stderr: (message) => io.stderr(redactDetachedRunText(message, environment))
106448
+ };
106295
106449
  const configuredRunId = environmentRunId(environment, "VAPI_RUN_ID");
106296
106450
  const parentRunId = environmentRunId(environment, "VAPI_PARENT_RUN_ID");
106297
106451
  const paths = getVapiPaths();
@@ -106303,8 +106457,8 @@ ${RUN_USAGE}`);
106303
106457
  if (resultFile !== void 0) {
106304
106458
  await writeJsonAtomic(resultFile, { v: 1, exitCode: 1, result: result2 }, { mode: 384 });
106305
106459
  }
106306
- if (json2) io.stdout(JSON.stringify(result2));
106307
- else io.stderr(message);
106460
+ if (json2) runIo.stdout(JSON.stringify(result2));
106461
+ else runIo.stderr(message);
106308
106462
  return 1;
106309
106463
  }
106310
106464
  const runId = configuredRunId ?? createRunId();
@@ -106368,42 +106522,48 @@ ${RUN_USAGE}`);
106368
106522
  ...runMeta === void 0 ? {} : { runMeta },
106369
106523
  approvals: "tty",
106370
106524
  json: json2,
106371
- io,
106525
+ io: runIo,
106372
106526
  dependencies
106373
106527
  });
106374
106528
  const execute = dependencies.agent?.runAgent ?? runAgent;
106375
106529
  const executed = await execute(task, runDependencies);
106376
106530
  const result = resultFile === void 0 ? executed : redactAgentRunResult(executed, environment);
106377
- if (!json2) printAgentRefills(result, io);
106531
+ if (!json2) printAgentRefills(result, runIo, io);
106378
106532
  const exitCode = result.stoppedBecause.reason === "finished" ? 0 : 1;
106379
106533
  if (resultFile !== void 0) {
106380
106534
  await writeJsonAtomic(resultFile, { v: 1, exitCode, result }, { mode: 384 });
106381
106535
  }
106382
106536
  if (json2) {
106383
- io.stdout(JSON.stringify(result));
106537
+ io.stdout(
106538
+ JSON.stringify(resultFile === void 0 ? result : redactAgentRunResult(result, environment))
106539
+ );
106384
106540
  } else if (result.stoppedBecause.reason === "finished") {
106385
- io.stdout(result.answer ?? "");
106541
+ runIo.stdout(result.answer ?? "");
106386
106542
  } else {
106387
- io.stderr(result.stoppedBecause.detail ?? result.stoppedBecause.reason);
106543
+ runIo.stderr(result.stoppedBecause.detail ?? result.stoppedBecause.reason);
106388
106544
  }
106389
106545
  return exitCode;
106390
106546
  }
106547
+ var SETTLEMENT_HASH = /^0x[0-9a-fA-F]{64}$/u;
106391
106548
  function redactAgentRunResult(executed, environment) {
106392
106549
  const result = redactDetachedRunValue(executed, environment);
106393
106550
  for (const [index2, refill] of (executed.refills ?? []).entries()) {
106394
106551
  const transaction2 = refill.receipt.transaction;
106395
106552
  const redacted = result.refills?.[index2];
106396
- if (redacted !== void 0 && transaction2 !== void 0 && /^0x[0-9a-fA-F]{64}$/u.test(transaction2)) {
106553
+ if (redacted !== void 0 && transaction2 !== void 0 && SETTLEMENT_HASH.test(transaction2)) {
106397
106554
  redacted.receipt.transaction = transaction2;
106398
106555
  }
106399
106556
  }
106400
106557
  return result;
106401
106558
  }
106402
- function printAgentRefills(result, io) {
106559
+ function printAgentRefills(result, io, settlementHashIo = io) {
106403
106560
  for (const refill of result.refills ?? []) {
106404
106561
  io.stderr(`Receipt: ${refill.receipt.id}`);
106405
- if (refill.receipt.transaction !== void 0)
106406
- io.stderr(`Transaction: ${refill.receipt.transaction}`);
106562
+ const transaction2 = refill.receipt.transaction;
106563
+ if (transaction2 !== void 0) {
106564
+ const output4 = SETTLEMENT_HASH.test(transaction2) ? settlementHashIo : io;
106565
+ output4.stderr(`Transaction: ${transaction2}`);
106566
+ }
106407
106567
  for (const warning of refill.warnings ?? []) io.stderr(warning.message);
106408
106568
  }
106409
106569
  }
@@ -111004,12 +111164,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
111004
111164
  exitCode = 0;
111005
111165
  break;
111006
111166
  case "agent":
111007
- exitCode = await agentCommand(
111008
- args.slice(1),
111009
- json2,
111010
- args[1] === "run" && args.includes("--bundle-env") ? io : runIo,
111011
- dependencies
111012
- );
111167
+ exitCode = await agentCommand(args.slice(1), json2, io, dependencies);
111013
111168
  break;
111014
111169
  case "dashboard":
111015
111170
  await dashboardCommand(args.slice(1), json2, io, dependencies);