vapi-network 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.
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.1. `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.1
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
@@ -48404,7 +48404,7 @@ async function withCredentialLockFile(lockPath, operation) {
48404
48404
  try {
48405
48405
  return await operation();
48406
48406
  } finally {
48407
- await handle.close();
48407
+ await handle.close().catch(() => void 0);
48408
48408
  await unlink2(lockPath).catch(() => void 0);
48409
48409
  }
48410
48410
  }
@@ -71175,7 +71175,7 @@ async function withVaultLock(path, operation) {
71175
71175
  try {
71176
71176
  return await operation();
71177
71177
  } finally {
71178
- await handle.close();
71178
+ await handle.close().catch(() => void 0);
71179
71179
  await unlink4(lockPath).catch(() => void 0);
71180
71180
  }
71181
71181
  }
@@ -74069,7 +74069,7 @@ async function withRegistryLock(path, operation) {
74069
74069
  try {
74070
74070
  return await operation();
74071
74071
  } finally {
74072
- await handle.close();
74072
+ await handle.close().catch(() => void 0);
74073
74073
  await unlink7(lockPath).catch(() => void 0);
74074
74074
  }
74075
74075
  }
@@ -74960,7 +74960,7 @@ async function withLedgerLock(path, operation) {
74960
74960
  try {
74961
74961
  return await operation();
74962
74962
  } finally {
74963
- await handle.close();
74963
+ await handle.close().catch(() => void 0);
74964
74964
  await unlink9(lockPath).catch(() => void 0);
74965
74965
  }
74966
74966
  }
@@ -75260,13 +75260,32 @@ async function transferBetweenAccounts(args) {
75260
75260
  if (existing !== void 0 && existing.transfer?.status !== "failed") {
75261
75261
  throw transferError("authorization_invalid");
75262
75262
  }
75263
- await appendTransferReceipt(context, request, {
75264
- receiptId,
75265
- status: "unknown",
75266
- txHash: null,
75267
- replayed: false,
75268
- reservedOn
75269
- });
75263
+ try {
75264
+ await appendTransferReceipt(context, request, {
75265
+ receiptId,
75266
+ status: "unknown",
75267
+ txHash: null,
75268
+ replayed: false,
75269
+ reservedOn
75270
+ });
75271
+ } catch (error61) {
75272
+ let persisted;
75273
+ try {
75274
+ persisted = await findTransferReceipt(context, nonce);
75275
+ } catch {
75276
+ authorizationPersisted = true;
75277
+ }
75278
+ if (persisted !== void 0 && persisted.transfer?.status !== "failed") {
75279
+ authorizationPersisted = true;
75280
+ }
75281
+ if (!authorizationPersisted) throw error61;
75282
+ return transferResult(context, {
75283
+ status: "unknown",
75284
+ txHash: null,
75285
+ nonce: request.authorization.nonce,
75286
+ replayed: false
75287
+ });
75288
+ }
75270
75289
  try {
75271
75290
  await syncReceipts(context.receiptsPath);
75272
75291
  } catch (error61) {
@@ -78571,7 +78590,7 @@ function createRunBudget(args) {
78571
78590
  import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
78572
78591
  import { arch, platform, release } from "node:os";
78573
78592
  import { join as join14 } from "node:path";
78574
- var VAPI_CLIENT_VERSION = "0.15.0";
78593
+ var VAPI_CLIENT_VERSION = "0.15.1";
78575
78594
  async function createSupportReport(options) {
78576
78595
  const message = options.message.trim();
78577
78596
  if (!message) throw new Error("Support report message must not be empty.");
@@ -80374,26 +80393,28 @@ async function ensureBalanceRouterKey(deps, paidLink) {
80374
80393
  if (!parsed.success) {
80375
80394
  throw new RouterClientError("http", "The Router balance key response was invalid.");
80376
80395
  }
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
- }
80396
+ await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
80397
+ const currentLink = await linkedWallet(deps);
80398
+ if (!sameAgentLink(currentLink, paidLink)) {
80399
+ throw new RouterClientError(
80400
+ "http",
80401
+ "The agent link changed while fetching the Router balance key."
80402
+ );
80403
+ }
80404
+ const returnedBase = validRouterBaseUrl(parsed.data.router_base_url);
80405
+ const expectedBase = validRouterBaseUrl(link3.routerBaseUrl ?? DEFAULT_ROUTER_BASE_URL);
80406
+ if (returnedBase !== expectedBase) {
80407
+ throw new RouterClientError(
80408
+ "http",
80409
+ "The Router balance key response named an unexpected Router base URL."
80410
+ );
80411
+ }
80412
+ try {
80413
+ await deps.secrets.set(account, parsed.data.router_key);
80414
+ } catch {
80415
+ throw new RouterClientError("http", "The Router balance key could not be stored safely.");
80416
+ }
80417
+ });
80397
80418
  }
80398
80419
  );
80399
80420
  }
@@ -80434,12 +80455,14 @@ async function routerBalanceCredentialSnapshot(deps) {
80434
80455
  async function removeRejectedBalanceKey(deps, rejected) {
80435
80456
  if (!deps.secrets.available) return;
80436
80457
  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
- }
80458
+ await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
80459
+ const link3 = await linkedWallet(deps);
80460
+ if (link3.clientId !== rejected.clientId) return;
80461
+ const account = agentSecretAccounts(deps.wallet).routerBalance;
80462
+ if (await deps.secrets.get(account) === rejected.routerKey) {
80463
+ await deps.secrets.remove(account);
80464
+ }
80465
+ });
80443
80466
  });
80444
80467
  }
80445
80468
  async function routerAccessToken(deps) {
@@ -80527,32 +80550,34 @@ async function rotateRouterKey(deps) {
80527
80550
  validRouterBaseUrl(parsed.data.router_base_url);
80528
80551
  try {
80529
80552
  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 {
80553
+ await withCredentialPublishLock(deps.wallets, deps.wallet, async () => {
80554
+ const currentLink = await linkedWallet(deps);
80555
+ if (!sameAgentLink(currentLink, link3)) {
80556
+ throw new RouterClientError("http", "The agent link changed during Router key rotation.");
80557
+ }
80558
+ const account = agentSecretAccounts(deps.wallet).routerStake;
80559
+ let previousKey;
80548
80560
  try {
80549
- if (previousKey === void 0) await deps.secrets.remove(account);
80550
- else await deps.secrets.set(account, previousKey);
80561
+ previousKey = await deps.secrets.get(account);
80562
+ await deps.secrets.set(account, parsed.data.router_key);
80551
80563
  } catch {
80552
- await deps.wallets.clearLink(deps.wallet).catch(() => void 0);
80564
+ throw new RouterClientError("http", "The Router key could not be stored safely.");
80553
80565
  }
80554
- throw new RouterClientError("http", "The Router key could not be stored safely.");
80555
- }
80566
+ try {
80567
+ await deps.wallets.setLink(deps.wallet, {
80568
+ ...currentLink,
80569
+ routerBaseUrl: parsed.data.router_base_url
80570
+ });
80571
+ } catch {
80572
+ try {
80573
+ if (previousKey === void 0) await deps.secrets.remove(account);
80574
+ else await deps.secrets.set(account, previousKey);
80575
+ } catch {
80576
+ await deps.wallets.clearLink(deps.wallet).catch(() => void 0);
80577
+ }
80578
+ throw new RouterClientError("http", "The Router key could not be stored safely.");
80579
+ }
80580
+ });
80556
80581
  });
80557
80582
  } catch (error61) {
80558
80583
  if (error61 instanceof RouterClientError) throw error61;
@@ -85965,34 +85990,48 @@ async function searchDocs(query, options = {}) {
85965
85990
  throw new DocsError("invalid_input", "Search limit must be a positive integer.");
85966
85991
  }
85967
85992
  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
- })
85993
+ const requestOptions2 = {
85994
+ operation: "search",
85995
+ origin,
85996
+ timeoutMs: options.timeoutMs ?? SEARCH_TIMEOUT_MS,
85997
+ fetchImpl: options.fetchImpl
85998
+ };
85999
+ const searchRequest = (name, args) => ({
86000
+ method: "POST",
86001
+ headers: {
86002
+ "content-type": "application/json",
86003
+ accept: "application/json, text/event-stream"
85982
86004
  },
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];
86005
+ body: JSON.stringify({
86006
+ jsonrpc: "2.0",
86007
+ id: 1,
86008
+ method: "tools/call",
86009
+ params: { name, arguments: args }
86010
+ })
85995
86011
  });
86012
+ let results;
86013
+ try {
86014
+ const { text: body } = await requestText(
86015
+ new URL("/mcp", origin),
86016
+ searchRequest("search_docs", {
86017
+ query: normalized,
86018
+ ...options.limit === void 0 ? {} : { limit: Math.min(options.limit, 10) }
86019
+ }),
86020
+ { ...requestOptions2, notFoundOn404: true, notFoundOn405: true }
86021
+ );
86022
+ results = parseSiteSearch(searchTextBlocks(parseSearchEnvelope(body)), origin);
86023
+ } catch (error61) {
86024
+ if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
86025
+ const { text: body } = await requestText(
86026
+ new URL("/~gitbook/mcp", origin),
86027
+ searchRequest("searchDocumentation", { query: normalized }),
86028
+ requestOptions2
86029
+ );
86030
+ results = searchTextBlocks(parseSearchEnvelope(body)).flatMap((block) => {
86031
+ const parsed = parseSearchBlock(block);
86032
+ return parsed === void 0 ? [] : [parsed];
86033
+ });
86034
+ }
85996
86035
  return { results: options.limit === void 0 ? results : results.slice(0, options.limit) };
85997
86036
  }
85998
86037
  async function readDocs(pageUrlOrPath, options = {}) {
@@ -86020,7 +86059,7 @@ async function readDocs(pageUrlOrPath, options = {}) {
86020
86059
  }
86021
86060
  async function readFirstMarkdown(page, options) {
86022
86061
  const path = page.pathname.replace(/\/+$/u, "");
86023
- const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/readme.md"];
86062
+ const candidates = path ? [`${path}.md`, `${path}/readme.md`] : ["/index.md", "/readme.md"];
86024
86063
  for (const pathname of candidates) {
86025
86064
  const candidate = new URL(page);
86026
86065
  candidate.pathname = pathname;
@@ -86044,17 +86083,32 @@ async function askDocs(question, options = {}) {
86044
86083
  const origin = resolveDocsOrigin(options.env);
86045
86084
  const url2 = new URL("/readme.md", origin);
86046
86085
  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);
86086
+ try {
86087
+ const { text: markdown } = await requestText(
86088
+ url2,
86089
+ { method: "GET", headers: { accept: "text/markdown" } },
86090
+ {
86091
+ operation: "ask",
86092
+ origin,
86093
+ timeoutMs: options.timeoutMs ?? ASK_TIMEOUT_MS,
86094
+ fetchImpl: options.fetchImpl,
86095
+ notFoundOn404: true
86096
+ }
86097
+ );
86098
+ return parseAnswer(markdown);
86099
+ } catch (error61) {
86100
+ if (!(error61 instanceof DocsError && error61.code === "not_found")) throw error61;
86101
+ }
86102
+ const { results } = await searchDocs(normalized, { ...options, limit: 3 });
86103
+ if (results.length === 0) return { answer: "No matching documentation found.", sources: [] };
86104
+ return {
86105
+ answer: [
86106
+ "These are the closest sections of the docs; the new docs site has no assistant.",
86107
+ "",
86108
+ ...results.map(({ title, url: url3, excerpt }) => `- [${title}](${url3}): ${excerpt}`)
86109
+ ].join("\n"),
86110
+ sources: results.map(({ title, url: url3 }) => ({ title, url: url3 }))
86111
+ };
86058
86112
  }
86059
86113
  function nonEmpty(value, label) {
86060
86114
  const normalized = value.trim();
@@ -86126,7 +86180,7 @@ async function requestText(requestUrl2, init, options) {
86126
86180
  assertAllowedUrl(next, options.origin);
86127
86181
  url2 = next;
86128
86182
  }
86129
- if (options.notFoundOn404 && response.status === 404) {
86183
+ if (options.notFoundOn404 && response.status === 404 || options.notFoundOn405 && response.status === 405) {
86130
86184
  throw new DocsError("not_found", `Documentation page not found: ${url2.href}`);
86131
86185
  }
86132
86186
  if (!response.ok) {
@@ -86231,12 +86285,40 @@ function searchTextBlocks(payload) {
86231
86285
  throw new DocsError("bad_response", `The documentation search returned an error${message}`);
86232
86286
  }
86233
86287
  const result = asRecord(envelope?.result);
86288
+ if (result?.isError === true) {
86289
+ throw new DocsError("bad_response", "The documentation search tool returned an error.");
86290
+ }
86234
86291
  if (!Array.isArray(result?.content)) throw invalidSearchResponse();
86235
86292
  return result.content.flatMap((item) => {
86236
86293
  const block = asRecord(item);
86237
86294
  return block?.type === "text" && typeof block.text === "string" ? [block.text] : [];
86238
86295
  });
86239
86296
  }
86297
+ function parseSiteSearch(blocks, origin) {
86298
+ if (blocks.length === 0) throw invalidSearchResponse();
86299
+ return blocks.flatMap((block) => {
86300
+ const items = parseJson2(block);
86301
+ if (!Array.isArray(items)) throw invalidSearchResponse();
86302
+ return items.map((item) => {
86303
+ const entry = asRecord(item);
86304
+ if (typeof entry?.title !== "string" || typeof entry.url !== "string" || typeof entry.heading !== "string" || typeof entry.snippet !== "string") {
86305
+ throw invalidSearchResponse();
86306
+ }
86307
+ let url2;
86308
+ try {
86309
+ url2 = new URL(entry.url, origin);
86310
+ } catch {
86311
+ throw invalidSearchResponse();
86312
+ }
86313
+ assertAllowedUrl(url2, origin);
86314
+ return {
86315
+ title: entry.heading ? `${entry.title} \u203A ${entry.heading}` : entry.title,
86316
+ url: url2.href,
86317
+ excerpt: entry.snippet
86318
+ };
86319
+ });
86320
+ });
86321
+ }
86240
86322
  function parseSearchBlock(block) {
86241
86323
  const match = /^Title:\s*([^\r\n]+)\r?\nLink:\s*([^\r\n]+)\r?\nContent:\s*([\s\S]*)$/u.exec(
86242
86324
  block.trim()
@@ -102500,7 +102582,7 @@ async function readProcessStdin() {
102500
102582
  }
102501
102583
 
102502
102584
  // ../cli/src/version.ts
102503
- var CLI_VERSION = "0.15.0";
102585
+ var CLI_VERSION = "0.15.1";
102504
102586
 
102505
102587
  // ../cli/src/status.ts
102506
102588
  async function statusCommand(argv, json2, io, dependencies) {