@vapi-network/core 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.
@@ -1 +1 @@
1
- {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../src/docs.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,gCAAgC,CAAC;AAUjE,MAAM,MAAM,aAAa,GACvB,eAAe,GAAG,kBAAkB,GAAG,WAAW,GAAG,SAAS,GAAG,cAAc,CAAC;AAElF,qBAAa,SAAU,SAAQ,KAAK;IAIhC,QAAQ,CAAC,IAAI,EAAE,aAAa;IAH9B,QAAQ,CAAC,IAAI,eAAe;gBAGjB,IAAI,EAAE,aAAa,EAC5B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,YAAY;CAIzB;AAED,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAC/E,MAAM,MAAM,kBAAkB,GAAG;IAAE,OAAO,EAAE,gBAAgB,EAAE,CAAA;CAAE,CAAC;AACjE,MAAM,MAAM,gBAAgB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AACjE,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AACxD,MAAM,MAAM,eAAe,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA4BxE,wBAAsB,UAAU,CAC9B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,kBAAkB,CAAC,CAmC7B;AAED,wBAAsB,QAAQ,CAC5B,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAuB3B;AA4BD,wBAAsB,OAAO,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,eAAe,CAAC,CAiB1B"}
1
+ {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../src/docs.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,gCAAgC,CAAC;AAUjE,MAAM,MAAM,aAAa,GACvB,eAAe,GAAG,kBAAkB,GAAG,WAAW,GAAG,SAAS,GAAG,cAAc,CAAC;AAElF,qBAAa,SAAU,SAAQ,KAAK;IAIhC,QAAQ,CAAC,IAAI,EAAE,aAAa;IAH9B,QAAQ,CAAC,IAAI,eAAe;gBAGjB,IAAI,EAAE,aAAa,EAC5B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,YAAY;CAIzB;AAED,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAC/E,MAAM,MAAM,kBAAkB,GAAG;IAAE,OAAO,EAAE,gBAAgB,EAAE,CAAA;CAAE,CAAC;AACjE,MAAM,MAAM,gBAAgB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AACjE,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AACxD,MAAM,MAAM,eAAe,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA4BxE,wBAAsB,UAAU,CAC9B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,kBAAkB,CAAC,CAiD7B;AAED,wBAAsB,QAAQ,CAC5B,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,gBAAgB,CAAC,CAuB3B;AA4BD,wBAAsB,OAAO,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,eAAe,CAAC,CAgC1B"}
package/dist/index.js CHANGED
@@ -43375,7 +43375,7 @@ async function assertPublicUrl(url2, options) {
43375
43375
  options.timeoutMs ?? 5e3
43376
43376
  );
43377
43377
  } catch {
43378
- throw guardError(url2);
43378
+ throw guardError(url2, "unresolved");
43379
43379
  }
43380
43380
  if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
43381
43381
  throw guardError(url2);
@@ -43530,11 +43530,68 @@ function isNonPublicIpv6(hextets) {
43530
43530
  const isDocumentation = first === 8193 && hextets[1] === 3512;
43531
43531
  return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
43532
43532
  }
43533
- function guardError(url2) {
43534
- return new Error(
43535
- `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
43533
+ var NetworkGuardError = class extends Error {
43534
+ constructor(message, reason) {
43535
+ super(message);
43536
+ this.reason = reason;
43537
+ this.name = "NetworkGuardError";
43538
+ }
43539
+ reason;
43540
+ };
43541
+ function guardError(url2, reason = "blocked") {
43542
+ return new NetworkGuardError(
43543
+ `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`,
43544
+ reason
43536
43545
  );
43537
43546
  }
43547
+ var PROXY_VARIABLES = {
43548
+ "https:": ["HTTPS_PROXY", "https_proxy"],
43549
+ "http:": ["HTTP_PROXY", "http_proxy"]
43550
+ };
43551
+ var SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/u;
43552
+ function describeNetworkFailure(error61, url2, env = process.env) {
43553
+ const host = url2.host;
43554
+ let reason;
43555
+ const guard = guardReason(error61);
43556
+ if (guard !== void 0) {
43557
+ reason = guard === "unresolved" ? `the DNS lookup for ${host} failed` : `${host} is not a public address`;
43558
+ } else if (isTimeout(error61)) {
43559
+ reason = `the connection to ${host} timed out`;
43560
+ } else {
43561
+ const code = systemErrorCode(error61);
43562
+ reason = `could not connect to ${host}${code === void 0 ? "" : ` (${code})`}`;
43563
+ }
43564
+ const proxy = (PROXY_VARIABLES[url2.protocol] ?? []).find(
43565
+ (name) => (env[name] ?? "").trim() !== ""
43566
+ );
43567
+ let hint = "";
43568
+ if (proxy !== void 0) {
43569
+ if (env.NODE_USE_ENV_PROXY !== "1") {
43570
+ 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.`;
43571
+ } else if (guard === "unresolved") {
43572
+ hint = ` vapi looks ${host} up on this machine before it uses the proxy in ${proxy}, so the name must resolve here too.`;
43573
+ } else if (guard === void 0) {
43574
+ hint = ` NODE_USE_ENV_PROXY=1 and ${proxy} are set, so the proxy may have refused the connection.`;
43575
+ }
43576
+ }
43577
+ return `${reason}.${hint}`;
43578
+ }
43579
+ function guardReason(error61) {
43580
+ if (!(error61 instanceof Error) || error61.name !== "NetworkGuardError") return void 0;
43581
+ const reason = error61.reason;
43582
+ return reason === "blocked" || reason === "unresolved" ? reason : void 0;
43583
+ }
43584
+ function isTimeout(error61) {
43585
+ return error61 instanceof Error && (error61.name === "TimeoutError" || error61.name === "AbortError");
43586
+ }
43587
+ function systemErrorCode(error61) {
43588
+ for (let current = error61, depth = 0; current instanceof Error && depth < 3; depth += 1) {
43589
+ const code = current.code;
43590
+ if (typeof code === "string" && SYSTEM_ERROR_CODE.test(code)) return code;
43591
+ current = current.cause;
43592
+ }
43593
+ return void 0;
43594
+ }
43538
43595
 
43539
43596
  // src/networks.ts
43540
43597
  var USDC_DECIMALS = 6;
@@ -46668,12 +46725,12 @@ async function removeStaleLock(path) {
46668
46725
  const pid = lockOwnerPid(owner);
46669
46726
  if (pid !== void 0 && processIsAlive(pid)) return;
46670
46727
  await atomicFileTestHooks?.beforeStaleLockBreak?.(path);
46671
- await removeOwnedLock(path, [owner]);
46728
+ await removeOwnedLock(path, [owner], true);
46672
46729
  } catch (error61) {
46673
46730
  if (!hasCode(error61, "ENOENT")) throw error61;
46674
46731
  }
46675
46732
  }
46676
- async function removeOwnedLock(path, owners) {
46733
+ async function removeOwnedLock(path, owners, staleDeadOwner = false) {
46677
46734
  const tombPath = `${path}.stale.${randomBytes2(16).toString("hex")}`;
46678
46735
  try {
46679
46736
  await rename(path, tombPath);
@@ -46682,7 +46739,7 @@ async function removeOwnedLock(path, owners) {
46682
46739
  await removeOwnedTombs(path, owners);
46683
46740
  const currentOwner = await readFile(path, "utf8").catch(() => void 0);
46684
46741
  if (currentOwner !== void 0 && owners.includes(currentOwner)) {
46685
- await removeOwnedLock(path, owners);
46742
+ await removeOwnedLock(path, owners, staleDeadOwner);
46686
46743
  }
46687
46744
  return;
46688
46745
  }
@@ -46691,6 +46748,7 @@ async function removeOwnedLock(path, owners) {
46691
46748
  let pendingError;
46692
46749
  let renamedOwner;
46693
46750
  try {
46751
+ await atomicFileTestHooks?.afterLockRename?.(tombPath);
46694
46752
  renamedOwner = await readFile(tombPath, "utf8");
46695
46753
  if (!owners.includes(renamedOwner) && !lockOwnerReleased(renamedOwner)) {
46696
46754
  await atomicFileTestHooks?.afterMismatchedLockRename?.(path);
@@ -46699,6 +46757,7 @@ async function removeOwnedLock(path, owners) {
46699
46757
  await atomicFileTestHooks?.afterMismatchedLockRestore?.(path);
46700
46758
  }
46701
46759
  } catch (error61) {
46760
+ if (hasCode(error61, "ENOENT")) return;
46702
46761
  pendingError = error61;
46703
46762
  }
46704
46763
  try {
@@ -46707,7 +46766,7 @@ async function removeOwnedLock(path, owners) {
46707
46766
  } catch (error61) {
46708
46767
  if (!tombUnlinkTolerated(
46709
46768
  error61,
46710
- renamedOwner !== void 0 && lockOwnerReleased(renamedOwner) && owners.includes(renamedOwner)
46769
+ renamedOwner !== void 0 && (lockOwnerReleased(renamedOwner) || staleDeadOwner) && owners.includes(renamedOwner)
46711
46770
  ) && pendingError === void 0) {
46712
46771
  pendingError = error61;
46713
46772
  }
@@ -47875,7 +47934,7 @@ async function withCredentialLockFile(lockPath, operation) {
47875
47934
  try {
47876
47935
  return await operation();
47877
47936
  } finally {
47878
- await handle.close();
47937
+ await handle.close().catch(() => void 0);
47879
47938
  await unlink2(lockPath).catch(() => void 0);
47880
47939
  }
47881
47940
  }
@@ -47939,16 +47998,25 @@ function withBearer(init, accessToken) {
47939
47998
  async function safeFetch(fetchImpl, input2, init) {
47940
47999
  try {
47941
48000
  return await fetchImpl(input2, init);
47942
- } catch {
47943
- throw httpError("The vAPI agent link request failed.");
48001
+ } catch (error61) {
48002
+ throw httpError(`The vAPI agent link request failed: ${networkFailure(error61, input2)}`);
47944
48003
  }
47945
48004
  }
47946
48005
  async function safeAgentFetch(fetchImpl, input2, init) {
47947
48006
  try {
47948
48007
  return await fetchImpl(input2, init);
48008
+ } catch (error61) {
48009
+ throw httpError(`The vAPI agent request failed: ${networkFailure(error61, input2)}`);
48010
+ }
48011
+ }
48012
+ function networkFailure(error61, input2) {
48013
+ let url2;
48014
+ try {
48015
+ url2 = new URL(input2 instanceof Request ? input2.url : input2);
47949
48016
  } catch {
47950
- throw httpError("The vAPI agent request failed.");
48017
+ return "the request did not reach vAPI.";
47951
48018
  }
48019
+ return describeNetworkFailure(error61, url2);
47952
48020
  }
47953
48021
  function deviceAuthorizationError(status, payload) {
47954
48022
  const error61 = stringField(payload, "error");
@@ -70669,7 +70737,7 @@ async function withVaultLock(path, operation) {
70669
70737
  try {
70670
70738
  return await operation();
70671
70739
  } finally {
70672
- await handle.close();
70740
+ await handle.close().catch(() => void 0);
70673
70741
  await unlink4(lockPath).catch(() => void 0);
70674
70742
  }
70675
70743
  }
@@ -73566,7 +73634,7 @@ async function withRegistryLock(path, operation) {
73566
73634
  try {
73567
73635
  return await operation();
73568
73636
  } finally {
73569
- await handle.close();
73637
+ await handle.close().catch(() => void 0);
73570
73638
  await unlink7(lockPath).catch(() => void 0);
73571
73639
  }
73572
73640
  }
@@ -74457,7 +74525,7 @@ async function withLedgerLock(path, operation) {
74457
74525
  try {
74458
74526
  return await operation();
74459
74527
  } finally {
74460
- await handle.close();
74528
+ await handle.close().catch(() => void 0);
74461
74529
  await unlink9(lockPath).catch(() => void 0);
74462
74530
  }
74463
74531
  }
@@ -74757,13 +74825,32 @@ async function transferBetweenAccounts(args) {
74757
74825
  if (existing !== void 0 && existing.transfer?.status !== "failed") {
74758
74826
  throw transferError("authorization_invalid");
74759
74827
  }
74760
- await appendTransferReceipt(context, request, {
74761
- receiptId,
74762
- status: "unknown",
74763
- txHash: null,
74764
- replayed: false,
74765
- reservedOn
74766
- });
74828
+ try {
74829
+ await appendTransferReceipt(context, request, {
74830
+ receiptId,
74831
+ status: "unknown",
74832
+ txHash: null,
74833
+ replayed: false,
74834
+ reservedOn
74835
+ });
74836
+ } catch (error61) {
74837
+ let persisted;
74838
+ try {
74839
+ persisted = await findTransferReceipt(context, nonce);
74840
+ } catch {
74841
+ authorizationPersisted = true;
74842
+ }
74843
+ if (persisted !== void 0 && persisted.transfer?.status !== "failed") {
74844
+ authorizationPersisted = true;
74845
+ }
74846
+ if (!authorizationPersisted) throw error61;
74847
+ return transferResult(context, {
74848
+ status: "unknown",
74849
+ txHash: null,
74850
+ nonce: request.authorization.nonce,
74851
+ replayed: false
74852
+ });
74853
+ }
74767
74854
  try {
74768
74855
  await syncReceipts(context.receiptsPath);
74769
74856
  } catch (error61) {
@@ -77971,7 +78058,7 @@ function createRunBudget(args) {
77971
78058
  import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
77972
78059
  import { arch, platform, release } from "node:os";
77973
78060
  import { join as join14 } from "node:path";
77974
- var VAPI_CLIENT_VERSION = "0.15.0";
78061
+ var VAPI_CLIENT_VERSION = "0.15.2";
77975
78062
  async function createSupportReport(options) {
77976
78063
  const message = options.message.trim();
77977
78064
  if (!message) throw new Error("Support report message must not be empty.");
@@ -79511,26 +79598,28 @@ async function ensureBalanceRouterKey(deps, paidLink) {
79511
79598
  if (!parsed.success) {
79512
79599
  throw new RouterClientError("http", "The Router balance key response was invalid.");
79513
79600
  }
79514
- const currentLink = await linkedWallet(deps);
79515
- if (!sameAgentLink(currentLink, paidLink)) {
79516
- throw new RouterClientError(
79517
- "http",
79518
- "The agent link changed while fetching the Router balance key."
79519
- );
79520
- }
79521
- const returnedBase = validRouterBaseUrl(parsed.data.router_base_url);
79522
- const expectedBase = validRouterBaseUrl(link2.routerBaseUrl ?? DEFAULT_ROUTER_BASE_URL);
79523
- if (returnedBase !== expectedBase) {
79524
- throw new RouterClientError(
79525
- "http",
79526
- "The Router balance key response named an unexpected Router base URL."
79527
- );
79528
- }
79529
- try {
79530
- await deps.secrets.set(account, parsed.data.router_key);
79531
- } catch {
79532
- throw new RouterClientError("http", "The Router balance key could not be stored safely.");
79533
- }
79601
+ await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
79602
+ const currentLink = await linkedWallet(deps);
79603
+ if (!sameAgentLink(currentLink, paidLink)) {
79604
+ throw new RouterClientError(
79605
+ "http",
79606
+ "The agent link changed while fetching the Router balance key."
79607
+ );
79608
+ }
79609
+ const returnedBase = validRouterBaseUrl(parsed.data.router_base_url);
79610
+ const expectedBase = validRouterBaseUrl(link2.routerBaseUrl ?? DEFAULT_ROUTER_BASE_URL);
79611
+ if (returnedBase !== expectedBase) {
79612
+ throw new RouterClientError(
79613
+ "http",
79614
+ "The Router balance key response named an unexpected Router base URL."
79615
+ );
79616
+ }
79617
+ try {
79618
+ await deps.secrets.set(account, parsed.data.router_key);
79619
+ } catch {
79620
+ throw new RouterClientError("http", "The Router balance key could not be stored safely.");
79621
+ }
79622
+ });
79534
79623
  }
79535
79624
  );
79536
79625
  }
@@ -80024,34 +80113,48 @@ async function searchDocs(query, options = {}) {
80024
80113
  throw new DocsError("invalid_input", "Search limit must be a positive integer.");
80025
80114
  }
80026
80115
  const origin = resolveDocsOrigin(options.env);
80027
- const { text: body } = await requestText(
80028
- new URL("/~gitbook/mcp", origin),
80029
- {
80030
- method: "POST",
80031
- headers: {
80032
- "content-type": "application/json",
80033
- accept: "application/json, text/event-stream"
80034
- },
80035
- body: JSON.stringify({
80036
- jsonrpc: "2.0",
80037
- id: 1,
80038
- method: "tools/call",
80039
- params: { name: "searchDocumentation", arguments: { query: normalized } }
80040
- })
80116
+ const requestOptions = {
80117
+ operation: "search",
80118
+ origin,
80119
+ timeoutMs: options.timeoutMs ?? SEARCH_TIMEOUT_MS,
80120
+ fetchImpl: options.fetchImpl
80121
+ };
80122
+ const searchRequest = (name, args) => ({
80123
+ method: "POST",
80124
+ headers: {
80125
+ "content-type": "application/json",
80126
+ accept: "application/json, text/event-stream"
80041
80127
  },
80042
- {
80043
- operation: "search",
80044
- origin,
80045
- timeoutMs: options.timeoutMs ?? SEARCH_TIMEOUT_MS,
80046
- fetchImpl: options.fetchImpl
80047
- }
80048
- );
80049
- const payload = parseSearchEnvelope(body);
80050
- const blocks = searchTextBlocks(payload);
80051
- const results = blocks.flatMap((block) => {
80052
- const parsed = parseSearchBlock(block);
80053
- return parsed === void 0 ? [] : [parsed];
80128
+ body: JSON.stringify({
80129
+ jsonrpc: "2.0",
80130
+ id: 1,
80131
+ method: "tools/call",
80132
+ params: { name, arguments: args }
80133
+ })
80054
80134
  });
80135
+ let results;
80136
+ try {
80137
+ const { text: body } = await requestText(
80138
+ new URL("/mcp", origin),
80139
+ searchRequest("search_docs", {
80140
+ query: normalized,
80141
+ ...options.limit === void 0 ? {} : { limit: Math.min(options.limit, 10) }
80142
+ }),
80143
+ { ...requestOptions, notFoundOn404: true, notFoundOn405: true }
80144
+ );
80145
+ results = parseSiteSearch(searchTextBlocks(parseSearchEnvelope(body)), origin);
80146
+ } catch (error61) {
80147
+ if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
80148
+ const { text: body } = await requestText(
80149
+ new URL("/~gitbook/mcp", origin),
80150
+ searchRequest("searchDocumentation", { query: normalized }),
80151
+ requestOptions
80152
+ );
80153
+ results = searchTextBlocks(parseSearchEnvelope(body)).flatMap((block) => {
80154
+ const parsed = parseSearchBlock(block);
80155
+ return parsed === void 0 ? [] : [parsed];
80156
+ });
80157
+ }
80055
80158
  return { results: options.limit === void 0 ? results : results.slice(0, options.limit) };
80056
80159
  }
80057
80160
  async function readDocs(pageUrlOrPath, options = {}) {
@@ -80079,7 +80182,7 @@ async function readDocs(pageUrlOrPath, options = {}) {
80079
80182
  }
80080
80183
  async function readFirstMarkdown(page, options) {
80081
80184
  const path = page.pathname.replace(/\/+$/u, "");
80082
- const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/readme.md"];
80185
+ const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/index.md", "/readme.md"];
80083
80186
  for (const pathname of candidates) {
80084
80187
  const candidate = new URL(page);
80085
80188
  candidate.pathname = pathname;
@@ -80103,17 +80206,32 @@ async function askDocs(question, options = {}) {
80103
80206
  const origin = resolveDocsOrigin(options.env);
80104
80207
  const url2 = new URL("/readme.md", origin);
80105
80208
  url2.searchParams.set("ask", normalized);
80106
- const { text: markdown } = await requestText(
80107
- url2,
80108
- { method: "GET", headers: { accept: "text/markdown" } },
80109
- {
80110
- operation: "ask",
80111
- origin,
80112
- timeoutMs: options.timeoutMs ?? ASK_TIMEOUT_MS,
80113
- fetchImpl: options.fetchImpl
80114
- }
80115
- );
80116
- return parseAnswer(markdown);
80209
+ try {
80210
+ const { text: markdown } = await requestText(
80211
+ url2,
80212
+ { method: "GET", headers: { accept: "text/markdown" } },
80213
+ {
80214
+ operation: "ask",
80215
+ origin,
80216
+ timeoutMs: options.timeoutMs ?? ASK_TIMEOUT_MS,
80217
+ fetchImpl: options.fetchImpl,
80218
+ notFoundOn404: true
80219
+ }
80220
+ );
80221
+ return parseAnswer(markdown);
80222
+ } catch (error61) {
80223
+ if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
80224
+ }
80225
+ const { results } = await searchDocs(normalized, { ...options, limit: 3 });
80226
+ if (results.length === 0) return { answer: "No matching documentation found.", sources: [] };
80227
+ return {
80228
+ answer: [
80229
+ "These are the closest sections of the docs; the new docs site has no assistant.",
80230
+ "",
80231
+ ...results.map(({ title, url: url3, excerpt }) => `- [${title}](${url3}): ${excerpt}`)
80232
+ ].join("\n"),
80233
+ sources: results.map(({ title, url: url3 }) => ({ title, url: url3 }))
80234
+ };
80117
80235
  }
80118
80236
  function nonEmpty(value, label) {
80119
80237
  const normalized = value.trim();
@@ -80185,7 +80303,7 @@ async function requestText(requestUrl, init, options) {
80185
80303
  assertAllowedUrl(next, options.origin);
80186
80304
  url2 = next;
80187
80305
  }
80188
- if (options.notFoundOn404 && response.status === 404) {
80306
+ if (options.notFoundOn404 && response.status === 404 || options.notFoundOn405 && response.status === 405) {
80189
80307
  throw new DocsError("not_found", `Documentation page not found: ${url2.href}`);
80190
80308
  }
80191
80309
  if (!response.ok) {
@@ -80290,12 +80408,40 @@ function searchTextBlocks(payload) {
80290
80408
  throw new DocsError("bad_response", `The documentation search returned an error${message}`);
80291
80409
  }
80292
80410
  const result = asRecord(envelope?.result);
80411
+ if (result?.isError === true) {
80412
+ throw new DocsError("bad_response", "The documentation search tool returned an error.");
80413
+ }
80293
80414
  if (!Array.isArray(result?.content)) throw invalidSearchResponse();
80294
80415
  return result.content.flatMap((item) => {
80295
80416
  const block = asRecord(item);
80296
80417
  return block?.type === "text" && typeof block.text === "string" ? [block.text] : [];
80297
80418
  });
80298
80419
  }
80420
+ function parseSiteSearch(blocks, origin) {
80421
+ if (blocks.length === 0) throw invalidSearchResponse();
80422
+ return blocks.flatMap((block) => {
80423
+ const items = parseJson2(block);
80424
+ if (!Array.isArray(items)) throw invalidSearchResponse();
80425
+ return items.map((item) => {
80426
+ const entry = asRecord(item);
80427
+ if (typeof entry?.title !== "string" || typeof entry.url !== "string" || typeof entry.heading !== "string" || typeof entry.snippet !== "string") {
80428
+ throw invalidSearchResponse();
80429
+ }
80430
+ let url2;
80431
+ try {
80432
+ url2 = new URL(entry.url, origin);
80433
+ } catch {
80434
+ throw invalidSearchResponse();
80435
+ }
80436
+ assertAllowedUrl(url2, origin);
80437
+ return {
80438
+ title: entry.heading ? `${entry.title} \u203A ${entry.heading}` : entry.title,
80439
+ url: url2.href,
80440
+ excerpt: entry.snippet
80441
+ };
80442
+ });
80443
+ });
80444
+ }
80299
80445
  function parseSearchBlock(block) {
80300
80446
  const match = /^Title:\s*([^\r\n]+)\r?\nLink:\s*([^\r\n]+)\r?\nContent:\s*([\s\S]*)$/u.exec(
80301
80447
  block.trim()
@@ -83322,6 +83468,7 @@ export {
83322
83468
  NATIVE_ETH_FEE_MARGIN_PERCENT,
83323
83469
  NATIVE_ETH_L1_FEE_FALLBACK_WEI,
83324
83470
  NETWORKS,
83471
+ NetworkGuardError,
83325
83472
  ONRAMP_FALLBACK_INSTRUCTIONS,
83326
83473
  ONRAMP_NETWORK,
83327
83474
  PASSPHRASE_ENVIRONMENT_VARIABLE,
@@ -83428,6 +83575,7 @@ export {
83428
83575
  deleteSwarmFile,
83429
83576
  deriveEvmPrivateKey,
83430
83577
  deriveSolanaPrivateKey,
83578
+ describeNetworkFailure,
83431
83579
  deviceName,
83432
83580
  discardBody,
83433
83581
  discover,