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