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