@vapi-network/core 0.15.0 → 0.15.1

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,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AAG,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
@@ -47875,7 +47875,7 @@ async function withCredentialLockFile(lockPath, operation) {
47875
47875
  try {
47876
47876
  return await operation();
47877
47877
  } finally {
47878
- await handle.close();
47878
+ await handle.close().catch(() => void 0);
47879
47879
  await unlink2(lockPath).catch(() => void 0);
47880
47880
  }
47881
47881
  }
@@ -70669,7 +70669,7 @@ async function withVaultLock(path, operation) {
70669
70669
  try {
70670
70670
  return await operation();
70671
70671
  } finally {
70672
- await handle.close();
70672
+ await handle.close().catch(() => void 0);
70673
70673
  await unlink4(lockPath).catch(() => void 0);
70674
70674
  }
70675
70675
  }
@@ -73566,7 +73566,7 @@ async function withRegistryLock(path, operation) {
73566
73566
  try {
73567
73567
  return await operation();
73568
73568
  } finally {
73569
- await handle.close();
73569
+ await handle.close().catch(() => void 0);
73570
73570
  await unlink7(lockPath).catch(() => void 0);
73571
73571
  }
73572
73572
  }
@@ -74457,7 +74457,7 @@ async function withLedgerLock(path, operation) {
74457
74457
  try {
74458
74458
  return await operation();
74459
74459
  } finally {
74460
- await handle.close();
74460
+ await handle.close().catch(() => void 0);
74461
74461
  await unlink9(lockPath).catch(() => void 0);
74462
74462
  }
74463
74463
  }
@@ -74757,13 +74757,32 @@ async function transferBetweenAccounts(args) {
74757
74757
  if (existing !== void 0 && existing.transfer?.status !== "failed") {
74758
74758
  throw transferError("authorization_invalid");
74759
74759
  }
74760
- await appendTransferReceipt(context, request, {
74761
- receiptId,
74762
- status: "unknown",
74763
- txHash: null,
74764
- replayed: false,
74765
- reservedOn
74766
- });
74760
+ try {
74761
+ await appendTransferReceipt(context, request, {
74762
+ receiptId,
74763
+ status: "unknown",
74764
+ txHash: null,
74765
+ replayed: false,
74766
+ reservedOn
74767
+ });
74768
+ } catch (error61) {
74769
+ let persisted;
74770
+ try {
74771
+ persisted = await findTransferReceipt(context, nonce);
74772
+ } catch {
74773
+ authorizationPersisted = true;
74774
+ }
74775
+ if (persisted !== void 0 && persisted.transfer?.status !== "failed") {
74776
+ authorizationPersisted = true;
74777
+ }
74778
+ if (!authorizationPersisted) throw error61;
74779
+ return transferResult(context, {
74780
+ status: "unknown",
74781
+ txHash: null,
74782
+ nonce: request.authorization.nonce,
74783
+ replayed: false
74784
+ });
74785
+ }
74767
74786
  try {
74768
74787
  await syncReceipts(context.receiptsPath);
74769
74788
  } catch (error61) {
@@ -77971,7 +77990,7 @@ function createRunBudget(args) {
77971
77990
  import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
77972
77991
  import { arch, platform, release } from "node:os";
77973
77992
  import { join as join14 } from "node:path";
77974
- var VAPI_CLIENT_VERSION = "0.15.0";
77993
+ var VAPI_CLIENT_VERSION = "0.15.1";
77975
77994
  async function createSupportReport(options) {
77976
77995
  const message = options.message.trim();
77977
77996
  if (!message) throw new Error("Support report message must not be empty.");
@@ -79511,26 +79530,28 @@ async function ensureBalanceRouterKey(deps, paidLink) {
79511
79530
  if (!parsed.success) {
79512
79531
  throw new RouterClientError("http", "The Router balance key response was invalid.");
79513
79532
  }
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
- }
79533
+ await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
79534
+ const currentLink = await linkedWallet(deps);
79535
+ if (!sameAgentLink(currentLink, paidLink)) {
79536
+ throw new RouterClientError(
79537
+ "http",
79538
+ "The agent link changed while fetching the Router balance key."
79539
+ );
79540
+ }
79541
+ const returnedBase = validRouterBaseUrl(parsed.data.router_base_url);
79542
+ const expectedBase = validRouterBaseUrl(link2.routerBaseUrl ?? DEFAULT_ROUTER_BASE_URL);
79543
+ if (returnedBase !== expectedBase) {
79544
+ throw new RouterClientError(
79545
+ "http",
79546
+ "The Router balance key response named an unexpected Router base URL."
79547
+ );
79548
+ }
79549
+ try {
79550
+ await deps.secrets.set(account, parsed.data.router_key);
79551
+ } catch {
79552
+ throw new RouterClientError("http", "The Router balance key could not be stored safely.");
79553
+ }
79554
+ });
79534
79555
  }
79535
79556
  );
79536
79557
  }
@@ -80024,34 +80045,48 @@ async function searchDocs(query, options = {}) {
80024
80045
  throw new DocsError("invalid_input", "Search limit must be a positive integer.");
80025
80046
  }
80026
80047
  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
- })
80048
+ const requestOptions = {
80049
+ operation: "search",
80050
+ origin,
80051
+ timeoutMs: options.timeoutMs ?? SEARCH_TIMEOUT_MS,
80052
+ fetchImpl: options.fetchImpl
80053
+ };
80054
+ const searchRequest = (name, args) => ({
80055
+ method: "POST",
80056
+ headers: {
80057
+ "content-type": "application/json",
80058
+ accept: "application/json, text/event-stream"
80041
80059
  },
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];
80060
+ body: JSON.stringify({
80061
+ jsonrpc: "2.0",
80062
+ id: 1,
80063
+ method: "tools/call",
80064
+ params: { name, arguments: args }
80065
+ })
80054
80066
  });
80067
+ let results;
80068
+ try {
80069
+ const { text: body } = await requestText(
80070
+ new URL("/mcp", origin),
80071
+ searchRequest("search_docs", {
80072
+ query: normalized,
80073
+ ...options.limit === void 0 ? {} : { limit: Math.min(options.limit, 10) }
80074
+ }),
80075
+ { ...requestOptions, notFoundOn404: true, notFoundOn405: true }
80076
+ );
80077
+ results = parseSiteSearch(searchTextBlocks(parseSearchEnvelope(body)), origin);
80078
+ } catch (error61) {
80079
+ if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
80080
+ const { text: body } = await requestText(
80081
+ new URL("/~gitbook/mcp", origin),
80082
+ searchRequest("searchDocumentation", { query: normalized }),
80083
+ requestOptions
80084
+ );
80085
+ results = searchTextBlocks(parseSearchEnvelope(body)).flatMap((block) => {
80086
+ const parsed = parseSearchBlock(block);
80087
+ return parsed === void 0 ? [] : [parsed];
80088
+ });
80089
+ }
80055
80090
  return { results: options.limit === void 0 ? results : results.slice(0, options.limit) };
80056
80091
  }
80057
80092
  async function readDocs(pageUrlOrPath, options = {}) {
@@ -80079,7 +80114,7 @@ async function readDocs(pageUrlOrPath, options = {}) {
80079
80114
  }
80080
80115
  async function readFirstMarkdown(page, options) {
80081
80116
  const path = page.pathname.replace(/\/+$/u, "");
80082
- const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/readme.md"];
80117
+ const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/index.md", "/readme.md"];
80083
80118
  for (const pathname of candidates) {
80084
80119
  const candidate = new URL(page);
80085
80120
  candidate.pathname = pathname;
@@ -80103,17 +80138,32 @@ async function askDocs(question, options = {}) {
80103
80138
  const origin = resolveDocsOrigin(options.env);
80104
80139
  const url2 = new URL("/readme.md", origin);
80105
80140
  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);
80141
+ try {
80142
+ const { text: markdown } = await requestText(
80143
+ url2,
80144
+ { method: "GET", headers: { accept: "text/markdown" } },
80145
+ {
80146
+ operation: "ask",
80147
+ origin,
80148
+ timeoutMs: options.timeoutMs ?? ASK_TIMEOUT_MS,
80149
+ fetchImpl: options.fetchImpl,
80150
+ notFoundOn404: true
80151
+ }
80152
+ );
80153
+ return parseAnswer(markdown);
80154
+ } catch (error61) {
80155
+ if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
80156
+ }
80157
+ const { results } = await searchDocs(normalized, { ...options, limit: 3 });
80158
+ if (results.length === 0) return { answer: "No matching documentation found.", sources: [] };
80159
+ return {
80160
+ answer: [
80161
+ "These are the closest sections of the docs; the new docs site has no assistant.",
80162
+ "",
80163
+ ...results.map(({ title, url: url3, excerpt }) => `- [${title}](${url3}): ${excerpt}`)
80164
+ ].join("\n"),
80165
+ sources: results.map(({ title, url: url3 }) => ({ title, url: url3 }))
80166
+ };
80117
80167
  }
80118
80168
  function nonEmpty(value, label) {
80119
80169
  const normalized = value.trim();
@@ -80185,7 +80235,7 @@ async function requestText(requestUrl, init, options) {
80185
80235
  assertAllowedUrl(next, options.origin);
80186
80236
  url2 = next;
80187
80237
  }
80188
- if (options.notFoundOn404 && response.status === 404) {
80238
+ if (options.notFoundOn404 && response.status === 404 || options.notFoundOn405 && response.status === 405) {
80189
80239
  throw new DocsError("not_found", `Documentation page not found: ${url2.href}`);
80190
80240
  }
80191
80241
  if (!response.ok) {
@@ -80290,12 +80340,40 @@ function searchTextBlocks(payload) {
80290
80340
  throw new DocsError("bad_response", `The documentation search returned an error${message}`);
80291
80341
  }
80292
80342
  const result = asRecord(envelope?.result);
80343
+ if (result?.isError === true) {
80344
+ throw new DocsError("bad_response", "The documentation search tool returned an error.");
80345
+ }
80293
80346
  if (!Array.isArray(result?.content)) throw invalidSearchResponse();
80294
80347
  return result.content.flatMap((item) => {
80295
80348
  const block = asRecord(item);
80296
80349
  return block?.type === "text" && typeof block.text === "string" ? [block.text] : [];
80297
80350
  });
80298
80351
  }
80352
+ function parseSiteSearch(blocks, origin) {
80353
+ if (blocks.length === 0) throw invalidSearchResponse();
80354
+ return blocks.flatMap((block) => {
80355
+ const items = parseJson2(block);
80356
+ if (!Array.isArray(items)) throw invalidSearchResponse();
80357
+ return items.map((item) => {
80358
+ const entry = asRecord(item);
80359
+ if (typeof entry?.title !== "string" || typeof entry.url !== "string" || typeof entry.heading !== "string" || typeof entry.snippet !== "string") {
80360
+ throw invalidSearchResponse();
80361
+ }
80362
+ let url2;
80363
+ try {
80364
+ url2 = new URL(entry.url, origin);
80365
+ } catch {
80366
+ throw invalidSearchResponse();
80367
+ }
80368
+ assertAllowedUrl(url2, origin);
80369
+ return {
80370
+ title: entry.heading ? `${entry.title} \u203A ${entry.heading}` : entry.title,
80371
+ url: url2.href,
80372
+ excerpt: entry.snippet
80373
+ };
80374
+ });
80375
+ });
80376
+ }
80299
80377
  function parseSearchBlock(block) {
80300
80378
  const match = /^Title:\s*([^\r\n]+)\r?\nLink:\s*([^\r\n]+)\r?\nContent:\s*([\s\S]*)$/u.exec(
80301
80379
  block.trim()