vapi-network 0.2.1 → 0.2.3

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/index.js CHANGED
@@ -9846,8 +9846,10 @@ __export(src_exports, {
9846
9846
  enableSolanaKey: () => enableSolanaKey,
9847
9847
  encryptPrivateKey: () => encryptPrivateKey,
9848
9848
  executionModeSchema: () => executionModeSchema,
9849
+ exportKeystoreKeys: () => exportKeystoreKeys,
9849
9850
  filterReceiptsByRange: () => filterReceiptsByRange,
9850
9851
  firstPartyProvenanceSchema: () => firstPartyProvenanceSchema,
9852
+ formatLegacyRegistryRewrites: () => formatLegacyRegistryRewrites,
9851
9853
  formatUsdc: () => formatUsdc,
9852
9854
  getAgentCashPaths: () => getAgentCashPaths,
9853
9855
  getArcGasHeadroomAtomic: () => getArcGasHeadroomAtomic,
@@ -9881,6 +9883,7 @@ __export(src_exports, {
9881
9883
  marketplaceKindSchema: () => marketplaceKindSchema,
9882
9884
  marketplacePublicFactSchema: () => marketplacePublicFactSchema,
9883
9885
  mergeListings: () => mergeListings,
9886
+ migrateLegacyRegistryConfig: () => migrateLegacyRegistryConfig,
9884
9887
  migrateLegacyVapiHome: () => migrateLegacyVapiHome,
9885
9888
  normalizeResourceUrl: () => normalizeResourceUrl,
9886
9889
  openRequestMarketplaceHitSchema: () => openRequestMarketplaceHitSchema,
@@ -9896,6 +9899,7 @@ __export(src_exports, {
9896
9899
  parseSettlementResponse: () => parseSettlementResponse,
9897
9900
  pinnedLookup: () => pinnedLookup,
9898
9901
  provenanceSchema: () => provenanceSchema,
9902
+ readKeystoreAddress: () => readKeystoreAddress,
9899
9903
  readReceipts: () => readReceipts,
9900
9904
  readSearchEvents: () => readSearchEvents,
9901
9905
  readSolanaGasBalance: () => readSolanaGasBalance,
@@ -9905,6 +9909,8 @@ __export(src_exports, {
9905
9909
  receiptsToCsv: () => receiptsToCsv,
9906
9910
  requireRpcUrl: () => requireRpcUrl,
9907
9911
  reserveSpend: () => reserveSpend,
9912
+ rewriteLegacyRegistryUrl: () => rewriteLegacyRegistryUrl,
9913
+ rewriteLegacyRegistryUrls: () => rewriteLegacyRegistryUrls,
9908
9914
  searchServicesResponseSchema: () => searchServicesResponseSchema,
9909
9915
  serviceOfferMarketplaceHitSchema: () => serviceOfferMarketplaceHitSchema,
9910
9916
  serviceSummarySchema: () => serviceSummarySchema,
@@ -45526,8 +45532,8 @@ var DEFAULT_DISCOVERY_URL = `${DEFAULT_REGISTRY_URL}/api/call/services`;
45526
45532
  var DEFAULT_MARKETPLACE_DISCOVERY_URL = `${DEFAULT_REGISTRY_URL}/api/call/discovery`;
45527
45533
  var DEFAULT_REGISTRY_FALLBACKS = [
45528
45534
  {
45529
- discoveryUrl: "https://console.vapinetwork.ai/api/call/services",
45530
- marketplaceDiscoveryUrl: "https://console.vapinetwork.ai/api/call/discovery"
45535
+ discoveryUrl: DEFAULT_DISCOVERY_URL,
45536
+ marketplaceDiscoveryUrl: DEFAULT_MARKETPLACE_DISCOVERY_URL
45531
45537
  }
45532
45538
  ];
45533
45539
  var DEFAULT_SPEND_CAPS = {
@@ -45632,6 +45638,83 @@ async function migrateLegacyVapiHome(options = {}) {
45632
45638
  }
45633
45639
  return copied;
45634
45640
  }
45641
+ var LEGACY_REGISTRY_HOSTS = /* @__PURE__ */ new Map([
45642
+ ["console.vapinetwork.ai", "api.vapinetwork.ai"],
45643
+ ["console-staging.vapinetwork.ai", "api-staging.vapinetwork.ai"]
45644
+ ]);
45645
+ var LEGACY_REGISTRY_PATHS = /* @__PURE__ */ new Map([
45646
+ ["/api/network/services", "/api/call/services"],
45647
+ ["/api/marketplace/discovery", "/api/call/discovery"]
45648
+ ]);
45649
+ var REGISTRY_DOMAIN = "vapinetwork.ai";
45650
+ function rewriteLegacyRegistryUrl(value) {
45651
+ let url2;
45652
+ try {
45653
+ url2 = new URL(value);
45654
+ } catch {
45655
+ return value;
45656
+ }
45657
+ let rewritten = false;
45658
+ const host = LEGACY_REGISTRY_HOSTS.get(url2.hostname.toLowerCase());
45659
+ if (host) {
45660
+ url2.hostname = host;
45661
+ rewritten = true;
45662
+ }
45663
+ const hostname4 = url2.hostname.toLowerCase();
45664
+ if (hostname4 === REGISTRY_DOMAIN || hostname4.endsWith(`.${REGISTRY_DOMAIN}`)) {
45665
+ const path = LEGACY_REGISTRY_PATHS.get(url2.pathname.replace(/\/+$/, ""));
45666
+ if (path) {
45667
+ url2.pathname = path;
45668
+ rewritten = true;
45669
+ }
45670
+ }
45671
+ return rewritten ? url2.href : value;
45672
+ }
45673
+ function rewriteLegacyRegistryUrls(config2) {
45674
+ const changes = [];
45675
+ const rewrite = (field, from16) => {
45676
+ const to = rewriteLegacyRegistryUrl(from16);
45677
+ if (to !== from16) changes.push({ field, from: from16, to });
45678
+ return to;
45679
+ };
45680
+ const next = {
45681
+ ...config2,
45682
+ discoveryUrl: rewrite("discoveryUrl", config2.discoveryUrl),
45683
+ marketplaceDiscoveryUrl: rewrite("marketplaceDiscoveryUrl", config2.marketplaceDiscoveryUrl),
45684
+ ...config2.registryFallbacks ? {
45685
+ registryFallbacks: config2.registryFallbacks.map((fallback, index2) => ({
45686
+ discoveryUrl: rewrite(
45687
+ `registryFallbacks[${index2}].discoveryUrl`,
45688
+ fallback.discoveryUrl
45689
+ ),
45690
+ marketplaceDiscoveryUrl: rewrite(
45691
+ `registryFallbacks[${index2}].marketplaceDiscoveryUrl`,
45692
+ fallback.marketplaceDiscoveryUrl
45693
+ )
45694
+ }))
45695
+ } : {}
45696
+ };
45697
+ return changes.length === 0 ? { config: config2, changes } : { config: next, changes };
45698
+ }
45699
+ function formatLegacyRegistryRewrites(changes) {
45700
+ return [
45701
+ "Rewrote retired vAPI registry URLs in the local config:",
45702
+ ...changes.map((change) => ` ${change.field}: ${change.from} -> ${change.to}`)
45703
+ ].join("\n");
45704
+ }
45705
+ async function migrateLegacyRegistryConfig(path = getVapiPaths().config) {
45706
+ let raw;
45707
+ try {
45708
+ raw = await readFile(path, "utf8");
45709
+ } catch (error61) {
45710
+ if (isMissingFile(error61)) return [];
45711
+ throw error61;
45712
+ }
45713
+ const { config: config2, changes } = rewriteLegacyRegistryUrls(configSchema.parse(JSON.parse(raw)));
45714
+ if (changes.length === 0) return [];
45715
+ await writeConfigFile(path, config2);
45716
+ return changes;
45717
+ }
45635
45718
  function getDefaultConfig(source = process.env, options = {}) {
45636
45719
  const registry2 = registryEndpoints(source.VAPI_REGISTRY_URL?.trim() || DEFAULT_REGISTRY_URL);
45637
45720
  const requested = new Set(options.networks ?? ["base"]);
@@ -45670,7 +45753,7 @@ function getDefaultConfig(source = process.env, options = {}) {
45670
45753
  spendCaps: { ...DEFAULT_SPEND_CAPS }
45671
45754
  };
45672
45755
  }
45673
- async function loadConfig(path = getVapiPaths().config, source = process.env) {
45756
+ async function loadConfig(path = getVapiPaths().config, source = process.env, options = {}) {
45674
45757
  if (!process.env.VAPI_HOME?.trim() && path === getVapiPaths(join(homedir(), ".vapi")).config) {
45675
45758
  await migrateLegacyVapiHome({ targetDirectory: join(homedir(), ".vapi") });
45676
45759
  }
@@ -45681,8 +45764,16 @@ async function loadConfig(path = getVapiPaths().config, source = process.env) {
45681
45764
  if (isMissingFile(error61)) return getDefaultConfig(source);
45682
45765
  throw error61;
45683
45766
  }
45684
- const config2 = configSchema.parse(JSON.parse(raw));
45685
- config2.registryFallbacks ??= DEFAULT_REGISTRY_FALLBACKS.map((fallback) => ({ ...fallback }));
45767
+ const parsed = configSchema.parse(JSON.parse(raw));
45768
+ parsed.registryFallbacks ??= DEFAULT_REGISTRY_FALLBACKS.map((fallback) => ({ ...fallback }));
45769
+ const migrated = rewriteLegacyRegistryUrls(parsed);
45770
+ const config2 = migrated.config;
45771
+ if (migrated.changes.length > 0 && options.notice) {
45772
+ options.notice(
45773
+ `${formatLegacyRegistryRewrites(migrated.changes)}
45774
+ Run vapi init to write the new URLs to ${path}.`
45775
+ );
45776
+ }
45686
45777
  const baseRpcUrl = source.BASE_RPC_URL?.trim();
45687
45778
  const arcRpcUrl = source.ARC_TESTNET_RPC_URL?.trim();
45688
45779
  const solanaRpcUrl = source.SOLANA_RPC_URL?.trim();
@@ -45738,15 +45829,7 @@ async function writeDefaultConfig(path = getVapiPaths().config, source = process
45738
45829
  if (copied.includes(path)) return await loadConfig(path, source);
45739
45830
  }
45740
45831
  const config2 = getDefaultConfig(source, options);
45741
- await mkdir(dirname(path), { recursive: true, mode: 448 });
45742
- const temporaryPath = `${path}.${process.pid}.tmp`;
45743
- await writeFile(temporaryPath, `${JSON.stringify(config2, null, 2)}
45744
- `, {
45745
- encoding: "utf8",
45746
- mode: 384,
45747
- flag: "wx"
45748
- });
45749
- await rename(temporaryPath, path);
45832
+ await writeConfigFile(path, config2);
45750
45833
  return config2;
45751
45834
  }
45752
45835
  async function enableDefaultNetwork(network, path = getVapiPaths().config, source = process.env) {
@@ -45757,6 +45840,10 @@ async function enableDefaultNetwork(network, path = getVapiPaths().config, sourc
45757
45840
  usdc: NETWORKS[SOLANA_MAINNET_CAIP2].usdc
45758
45841
  };
45759
45842
  }
45843
+ await writeConfigFile(path, config2);
45844
+ return config2;
45845
+ }
45846
+ async function writeConfigFile(path, config2) {
45760
45847
  await mkdir(dirname(path), { recursive: true, mode: 448 });
45761
45848
  const temporaryPath = `${path}.${process.pid}.tmp`;
45762
45849
  await writeFile(temporaryPath, `${JSON.stringify(config2, null, 2)}
@@ -45766,7 +45853,6 @@ async function enableDefaultNetwork(network, path = getVapiPaths().config, sourc
45766
45853
  flag: "wx"
45767
45854
  });
45768
45855
  await rename(temporaryPath, path);
45769
- return config2;
45770
45856
  }
45771
45857
  async function pathExists(path) {
45772
45858
  try {
@@ -46323,6 +46409,49 @@ async function unlockKeystore(passphrase, path = getVapiPaths().keystore) {
46323
46409
  }
46324
46410
  return await paymentAccountFromKeys(keys);
46325
46411
  }
46412
+ async function readKeystoreAddress(path = getVapiPaths().keystore) {
46413
+ let raw;
46414
+ try {
46415
+ raw = await readFile3(path, "utf8");
46416
+ } catch {
46417
+ return void 0;
46418
+ }
46419
+ let parsed;
46420
+ try {
46421
+ parsed = JSON.parse(raw);
46422
+ } catch {
46423
+ return void 0;
46424
+ }
46425
+ const address2 = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "address") : void 0;
46426
+ return typeof address2 === "string" ? address2 : void 0;
46427
+ }
46428
+ async function exportKeystoreKeys(passphrase, path = getVapiPaths().keystore) {
46429
+ let raw;
46430
+ try {
46431
+ raw = await readFile3(path, "utf8");
46432
+ } catch (error61) {
46433
+ if (isMissingFile(error61)) {
46434
+ throw new KeystoreError(`No vAPI keystore found at ${path}. Run vapi init.`);
46435
+ }
46436
+ throw error61;
46437
+ }
46438
+ const keys = await decryptKeys(parseAnyKeystore(JSON.parse(raw)), passphrase);
46439
+ const evmPrivateKey = keys.evm;
46440
+ const exported = {
46441
+ evm: { address: privateKeyToAccount(evmPrivateKey).address, privateKey: evmPrivateKey }
46442
+ };
46443
+ if (!keys.solana) return exported;
46444
+ const seed = Uint8Array.from(Buffer.from(keys.solana, "base64"));
46445
+ const signer = await createSolanaSigner(Uint8Array.from(seed));
46446
+ const publicKey = Uint8Array.from(getBase58Encoder().encode(signer.address));
46447
+ const secretKey = new Uint8Array(seed.length + publicKey.length);
46448
+ secretKey.set(seed);
46449
+ secretKey.set(publicKey, seed.length);
46450
+ const encoded = getBase58Decoder().decode(secretKey);
46451
+ seed.fill(0);
46452
+ secretKey.fill(0);
46453
+ return { ...exported, solana: { address: signer.address, secretKey: encoded } };
46454
+ }
46326
46455
  async function enableSolanaKey(passphrase, path = getVapiPaths().keystore) {
46327
46456
  let raw;
46328
46457
  try {
@@ -47022,7 +47151,7 @@ function csvCell(value) {
47022
47151
  import { mkdir as mkdir6, writeFile as writeFile4 } from "node:fs/promises";
47023
47152
  import { arch, platform, release } from "node:os";
47024
47153
  import { join as join2 } from "node:path";
47025
- var VAPI_CLIENT_VERSION = "0.2.1";
47154
+ var VAPI_CLIENT_VERSION = "0.2.3";
47026
47155
  async function createSupportReport(options) {
47027
47156
  const message = options.message.trim();
47028
47157
  if (!message) throw new Error("Support report message must not be empty.");
@@ -49631,132 +49760,122 @@ function asRecord2(value) {
49631
49760
  var MARK_SOURCE_WIDTH = 743;
49632
49761
  var MARK_SOURCE_HEIGHT = 659;
49633
49762
  var MARK_SOURCE_ROW_HEIGHT = 217;
49634
- var MARK_COLUMNS = 28;
49635
- var MARK_ROWS = 12;
49636
- var PLAIN_BLOCK = "\u2588";
49637
- var MARK_STEP_MS = 70;
49763
+ var MARK_COLUMNS = 21;
49764
+ var MARK_ROWS = 9;
49765
+ var BLOCK = "\u2588";
49638
49766
  var WORDMARK = "vAPI Network";
49639
49767
  var WELCOME = "Welcome to the vAPI Network";
49640
49768
  var TAGLINE = [
49641
- "The trusted network where agents and humans do business.",
49642
- "Search APIs, pay per call, keep receipts. More coming soon."
49769
+ "The trusted network where agents",
49770
+ "and humans do business.",
49771
+ "",
49772
+ "Search APIs, pay per call, keep",
49773
+ "receipts. More coming soon."
49643
49774
  ];
49644
- var ESC = "\x1B";
49775
+ var ESC = String.fromCharCode(27);
49645
49776
  var RESET = `${ESC}[0m`;
49646
- var REVERSE = `${ESC}[7m`;
49647
49777
  var BOLD = `${ESC}[1m`;
49648
49778
  var DIM = `${ESC}[2m`;
49649
- var HIDE_CURSOR = `${ESC}[?25l`;
49650
- var SHOW_CURSOR = `${ESC}[?25h`;
49779
+ var DEFAULT_FOREGROUND = `${ESC}[39m`;
49651
49780
  var MARK_PALETTE = {
49652
- orange: "#ff7300",
49653
- pink: "#ff337c",
49654
- lime: "#c3ff3d",
49655
- cyan: "#97efff",
49656
- blue: "#0041eb",
49657
- purple: "#8a37fb",
49781
+ orange: { hex: "#ff7300", ansi16: 33 },
49782
+ pink: { hex: "#ff337c", ansi16: 95 },
49783
+ lime: { hex: "#c3ff3d", ansi16: 92 },
49784
+ cyan: { hex: "#97efff", ansi16: 96 },
49785
+ blue: { hex: "#0041eb", ansi16: 34 },
49786
+ purple: { hex: "#8a37fb", ansi16: 35 },
49658
49787
  ink: null
49659
49788
  };
49660
49789
  var MARK_BLOCKS = [
49661
- { row: 0, x: 2, width: 90, color: "orange", delay: 0 },
49662
- { row: 0, x: 94, width: 35, color: "pink", delay: 1 },
49663
- { row: 0, x: 131, width: 16, color: "lime", delay: 2 },
49664
- { row: 0, x: 522, width: 219, color: "ink", delay: 1 },
49665
- { row: 1, x: 124, width: 50, color: "cyan", delay: 3 },
49666
- { row: 1, x: 176, width: 24, color: "blue", delay: 4 },
49667
- { row: 1, x: 202, width: 17, color: "purple", delay: 5 },
49668
- { row: 1, x: 402, width: 219, color: "blue", delay: 4 },
49669
- { row: 2, x: 282, width: 219, color: "ink", delay: 7 }
49790
+ { row: 0, x: 2, width: 90, color: "orange" },
49791
+ { row: 0, x: 94, width: 35, color: "pink" },
49792
+ { row: 0, x: 131, width: 16, color: "lime" },
49793
+ { row: 0, x: 522, width: 219, color: "ink" },
49794
+ { row: 1, x: 124, width: 50, color: "cyan" },
49795
+ { row: 1, x: 176, width: 24, color: "blue" },
49796
+ { row: 1, x: 202, width: 17, color: "purple" },
49797
+ { row: 1, x: 402, width: 219, color: "blue" },
49798
+ { row: 2, x: 282, width: 219, color: "ink" }
49670
49799
  ];
49671
- function markColorEnabled(environment = {}) {
49800
+ function detectColorLevel(environment = {}) {
49672
49801
  const env = environment.env ?? process.env;
49673
49802
  const isTty = environment.isTty ?? Boolean(process.stdout.isTTY);
49674
- return isTty && !env.NO_COLOR;
49675
- }
49676
- function shouldAnimateMark(environment = {}) {
49677
- const env = environment.env ?? process.env;
49678
- if (environment.json) return false;
49679
- if (env.NO_COLOR || env.CI) return false;
49680
- return markColorEnabled(environment);
49681
- }
49682
- function renderMarkFrames(options = {}) {
49683
- const steps = [...new Set(MARK_BLOCKS.map((block) => block.delay))].sort(
49684
- (left, right) => left - right
49685
- );
49686
- return steps.map(
49687
- (step) => renderFrame(
49688
- MARK_BLOCKS.filter((block) => block.delay <= step),
49689
- options.color === true
49690
- )
49691
- );
49692
- }
49693
- function renderBanner(options) {
49694
- const frames = renderMarkFrames(options);
49695
- return renderBox(frames[frames.length - 1], options).join("\n");
49696
- }
49697
- async function animateBanner(options) {
49698
- const frames = renderMarkFrames({ color: options.color !== false });
49699
- const sleep = options.sleep ?? defaultSleep;
49700
- const stepMs = options.stepMs ?? MARK_STEP_MS;
49701
- const boxes = frames.map((frame) => renderBox(frame, options));
49702
- const height = boxes[0].length;
49703
- options.write(HIDE_CURSOR);
49704
- try {
49705
- for (const [index2, box] of boxes.entries()) {
49706
- if (index2 > 0) options.write(`${ESC}[${height}A`);
49707
- options.write(box.map((line) => `\r${ESC}[2K${line}
49708
- `).join(""));
49709
- if (index2 < boxes.length - 1) await sleep(stepMs);
49710
- }
49711
- } finally {
49712
- options.write(SHOW_CURSOR);
49713
- }
49714
- }
49715
- function renderBox(frame, options) {
49716
- const color = options.color === true;
49717
- const text = [
49718
- { value: WELCOME, style: BOLD },
49719
- { value: "", style: "" },
49720
- ...TAGLINE.map((line) => ({ value: line, style: "" })),
49721
- { value: "", style: "" },
49722
- { value: `${WORDMARK} v${options.version}`, style: DIM }
49723
- ];
49724
- const textWidth = Math.max(...text.map((line) => line.value.length));
49725
- const gap = 3;
49726
- const inner = 2 + MARK_COLUMNS + gap + textWidth + 2;
49727
- const markLines = frame.split("\n");
49728
- const textTop = Math.floor((MARK_ROWS - text.length) / 2);
49729
- const lines = [];
49730
- lines.push(`\u256D${"\u2500".repeat(inner)}\u256E`);
49731
- lines.push(`\u2502${" ".repeat(inner)}\u2502`);
49732
- for (let row = 0; row < MARK_ROWS; row += 1) {
49733
- const mark = markLines[row] ?? "";
49734
- const markPad = " ".repeat(Math.max(0, MARK_COLUMNS - visibleLength(mark)));
49735
- const entry = text[row - textTop];
49736
- const raw = entry?.value ?? "";
49737
- const styled = color && entry && entry.style && raw ? `${entry.style}${raw}${RESET}` : raw;
49738
- const textPad = " ".repeat(textWidth - raw.length);
49739
- lines.push(`\u2502 ${mark}${markPad}${" ".repeat(gap)}${styled}${textPad} \u2502`);
49803
+ if (env.NO_COLOR) return 0;
49804
+ const forced = env.FORCE_COLOR;
49805
+ if (forced !== void 0) {
49806
+ if (forced === "0" || forced === "false") return 0;
49807
+ if (forced === "2") return 2;
49808
+ if (forced === "3") return 3;
49809
+ return 1;
49740
49810
  }
49741
- lines.push(`\u2502${" ".repeat(inner)}\u2502`);
49742
- lines.push(`\u2570${"\u2500".repeat(inner)}\u256F`);
49743
- return lines;
49744
- }
49745
- function renderFrame(blocks, color) {
49811
+ if (!isTty) return 0;
49812
+ const term = env.TERM ?? "";
49813
+ const program = env.TERM_PROGRAM ?? "";
49814
+ if (term === "dumb") return 0;
49815
+ if (/^(truecolor|24bit)$/i.test(env.COLORTERM ?? "")) return 3;
49816
+ if (/kitty|wezterm|ghostty|alacritty/i.test(term)) return 3;
49817
+ if (/^(iTerm\.app|vscode|Hyper|WezTerm|ghostty)$/i.test(program)) return 3;
49818
+ if (/-256(?:color)?$/i.test(term) || program === "Apple_Terminal") return 2;
49819
+ return 1;
49820
+ }
49821
+ function renderMark(colorLevel = 0) {
49746
49822
  const rows = [];
49747
49823
  for (let row = 0; row < MARK_ROWS; row += 1) {
49748
49824
  const sourceY = row * MARK_SOURCE_HEIGHT / MARK_ROWS;
49749
49825
  const band = Math.min(2, Math.floor(sourceY / MARK_SOURCE_ROW_HEIGHT));
49750
49826
  rows.push(
49751
49827
  renderRow(
49752
- blocks.filter((block) => block.row === band),
49753
- color
49828
+ MARK_BLOCKS.filter((block) => block.row === band),
49829
+ colorLevel
49754
49830
  )
49755
49831
  );
49756
49832
  }
49757
49833
  return rows.join("\n");
49758
49834
  }
49759
- function renderRow(blocks, color) {
49835
+ function bannerWidth() {
49836
+ return frameInnerWidth() + 2;
49837
+ }
49838
+ function renderBanner(options) {
49839
+ const colorLevel = options.colorLevel ?? 0;
49840
+ const columns = options.columns ?? Number.POSITIVE_INFINITY;
49841
+ const text = bannerText(options.version, colorLevel);
49842
+ if (columns < bannerWidth()) {
49843
+ return text.map((line) => line.styled).join("\n");
49844
+ }
49845
+ const inner = frameInnerWidth();
49846
+ const markLines = renderMark(colorLevel).split("\n");
49847
+ const lines = [];
49848
+ lines.push(`\u256D${"\u2500".repeat(inner)}\u256E`);
49849
+ lines.push(`\u2502${" ".repeat(inner)}\u2502`);
49850
+ for (let row = 0; row < MARK_ROWS; row += 1) {
49851
+ const entry = text[row];
49852
+ const value = entry?.value ?? "";
49853
+ const styled = entry?.styled ?? "";
49854
+ const pad4 = " ".repeat(TEXT_WIDTH - value.length);
49855
+ lines.push(`\u2502 ${markLines[row]}${" ".repeat(GAP)}${styled}${pad4} \u2502`);
49856
+ }
49857
+ lines.push(`\u2502${" ".repeat(inner)}\u2502`);
49858
+ lines.push(`\u2570${"\u2500".repeat(inner)}\u256F`);
49859
+ return lines.join("\n");
49860
+ }
49861
+ var GAP = 3;
49862
+ var TEXT_WIDTH = Math.max(WELCOME.length, ...TAGLINE.map((line) => line.length));
49863
+ function frameInnerWidth() {
49864
+ return 2 + MARK_COLUMNS + GAP + TEXT_WIDTH + 2;
49865
+ }
49866
+ function bannerText(version5, colorLevel) {
49867
+ const style = (value, code) => colorLevel > 0 && value ? `${code}${value}${RESET}` : value;
49868
+ const rows = [
49869
+ { value: WELCOME, styled: style(WELCOME, BOLD) },
49870
+ { value: "", styled: "" },
49871
+ ...TAGLINE.map((line) => ({ value: line, styled: line })),
49872
+ { value: "", styled: "" },
49873
+ { value: `${WORDMARK} v${version5}`, styled: style(`${WORDMARK} v${version5}`, DIM) }
49874
+ ];
49875
+ if (rows.length > MARK_ROWS) throw new Error("banner text is taller than the mark");
49876
+ return rows;
49877
+ }
49878
+ function renderRow(blocks, colorLevel) {
49760
49879
  const ordered = [...blocks].sort((left, right) => left.x - right.x);
49761
49880
  let column = 0;
49762
49881
  let line = "";
@@ -49767,7 +49886,8 @@ function renderRow(blocks, color) {
49767
49886
  column = start;
49768
49887
  }
49769
49888
  const width = scaleWidth(block.width);
49770
- line += color ? `${cellPrefix(block.color)}${" ".repeat(width)}${RESET}` : PLAIN_BLOCK.repeat(width);
49889
+ const cells = BLOCK.repeat(width);
49890
+ line += colorLevel > 0 ? `${foreground(block.color, colorLevel)}${cells}${RESET}` : cells;
49771
49891
  column += width;
49772
49892
  }
49773
49893
  return line + " ".repeat(Math.max(0, MARK_COLUMNS - column));
@@ -49778,23 +49898,28 @@ function scaleColumn(x) {
49778
49898
  function scaleWidth(width) {
49779
49899
  return Math.max(1, Math.round(width * MARK_COLUMNS / MARK_SOURCE_WIDTH));
49780
49900
  }
49781
- function cellPrefix(color) {
49782
- const hex3 = MARK_PALETTE[color];
49783
- if (hex3 === null) return REVERSE;
49784
- const value = Number.parseInt(hex3.slice(1), 16);
49785
- return `${ESC}[48;2;${value >> 16 & 255};${value >> 8 & 255};${value & 255}m`;
49786
- }
49787
- function visibleLength(line) {
49788
- return line.replace(new RegExp(`${ESC}\\[[0-9;?]*[A-Za-z]`, "g"), "").length;
49901
+ function foreground(color, colorLevel) {
49902
+ const entry = MARK_PALETTE[color];
49903
+ if (entry === null) return DEFAULT_FOREGROUND;
49904
+ const value = Number.parseInt(entry.hex.slice(1), 16);
49905
+ const red = value >> 16 & 255;
49906
+ const green = value >> 8 & 255;
49907
+ const blue = value & 255;
49908
+ if (colorLevel === 3) return `${ESC}[38;2;${red};${green};${blue}m`;
49909
+ if (colorLevel === 2) return `${ESC}[38;5;${rgbToAnsi256(red, green, blue)}m`;
49910
+ return `${ESC}[${entry.ansi16}m`;
49789
49911
  }
49790
- function defaultSleep(milliseconds) {
49791
- return new Promise((resolve2) => {
49792
- setTimeout(resolve2, milliseconds);
49793
- });
49912
+ function rgbToAnsi256(red, green, blue) {
49913
+ if (red === green && green === blue) {
49914
+ if (red < 8) return 16;
49915
+ if (red > 248) return 231;
49916
+ return Math.round((red - 8) / 247 * 24) + 232;
49917
+ }
49918
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
49794
49919
  }
49795
49920
 
49796
49921
  // ../cli/src/version.ts
49797
- var CLI_VERSION = "0.2.1";
49922
+ var CLI_VERSION = "0.2.3";
49798
49923
 
49799
49924
  // ../cli/src/cli.ts
49800
49925
  var HELP_HEADING = "vAPI Network";
@@ -49812,6 +49937,7 @@ Usage:
49812
49937
  vapi receipts export --format <json|csv> [--range <24h|7d|30d>]
49813
49938
  vapi stats [--range <24h|7d|30d>] [--json]
49814
49939
  vapi sweep <address> [--network <caip2>] [--json]
49940
+ vapi export-key [--network <caip2>] [--json]
49815
49941
  vapi report "<what happened>" [--include-addresses] [--send] [--json]
49816
49942
  vapi mcp [--json]
49817
49943
  vapi serve [--json]
@@ -49823,8 +49949,7 @@ var processIo = {
49823
49949
  stdout: (message) => process.stdout.write(`${message}
49824
49950
  `),
49825
49951
  stderr: (message) => process.stderr.write(`${message}
49826
- `),
49827
- write: (chunk) => process.stdout.write(chunk)
49952
+ `)
49828
49953
  };
49829
49954
  var UsageError = class extends Error {
49830
49955
  };
@@ -49843,7 +49968,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
49843
49968
  if (command === void 0 || command === "help" || command === "--help" || command === "-h") {
49844
49969
  requireNoArguments(args.slice(command === void 0 ? 0 : 1), command ?? "help");
49845
49970
  if (command === void 0 && !json2) {
49846
- io.stdout(staticBanner());
49971
+ showBanner(io);
49847
49972
  io.stdout(HELP.slice(HELP_HEADING.length + 2));
49848
49973
  return 0;
49849
49974
  }
@@ -49881,6 +50006,9 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
49881
50006
  case "sweep":
49882
50007
  await sweepCommand(args.slice(1), json2, io);
49883
50008
  return 0;
50009
+ case "export-key":
50010
+ await exportKeyCommand(args.slice(1), json2, io);
50011
+ return 0;
49884
50012
  case "report":
49885
50013
  await reportCommand(args.slice(1), json2, io, dependencies);
49886
50014
  return 0;
@@ -49914,14 +50042,24 @@ async function initCommand(argv, json2, io, dependencies) {
49914
50042
  });
49915
50043
  const networks = parseInitNetworks(parsed.one("--networks") ?? "base");
49916
50044
  const enableSolana = networks.includes("solana");
49917
- if (!json2) await showBanner(io);
50045
+ if (!json2) showBanner(io);
49918
50046
  const paths = getVapiPaths();
49919
50047
  let migrated = [];
49920
50048
  if (!process.env.VAPI_HOME?.trim()) {
49921
50049
  migrated = await migrateLegacyVapiHome({ targetDirectory: paths.directory, notice: io.stderr });
49922
50050
  }
50051
+ const adopted = migrated.includes(paths.keystore);
50052
+ if (!adopted && await fileExists(paths.keystore)) {
50053
+ const address2 = await readKeystoreAddress(paths.keystore);
50054
+ throw new Error(
50055
+ [
50056
+ `Keystore already exists at ${paths.keystore}. Refusing to replace the local payment key.`,
50057
+ ...address2 ? [`Address: ${address2}`] : []
50058
+ ].join("\n")
50059
+ );
50060
+ }
49923
50061
  const passphrase = await getKeystorePassphrase({ confirm: true });
49924
- let account = migrated.includes(paths.keystore) ? await unlockKeystore(passphrase, paths.keystore) : await createKeystore(passphrase, paths.keystore, { enableSolana });
50062
+ let account = adopted ? await unlockKeystore(passphrase, paths.keystore) : await createKeystore(passphrase, paths.keystore, { enableSolana });
49925
50063
  if (enableSolana && !account.solana) {
49926
50064
  account = await enableSolanaKey(passphrase, paths.keystore);
49927
50065
  }
@@ -49930,7 +50068,8 @@ async function initCommand(argv, json2, io, dependencies) {
49930
50068
  } else if (enableSolana) {
49931
50069
  await enableDefaultNetwork("solana", paths.config);
49932
50070
  }
49933
- const config2 = await loadConfig(paths.config);
50071
+ const configRewrites = await migrateLegacyRegistryConfig(paths.config);
50072
+ const config2 = await readConfig(paths.config, io);
49934
50073
  const accounts = await listAccounts({
49935
50074
  address: account.address,
49936
50075
  ...account.solana ? { solanaAddress: account.solana.address } : {},
@@ -49942,6 +50081,7 @@ async function initCommand(argv, json2, io, dependencies) {
49942
50081
  accounts,
49943
50082
  config: paths.config,
49944
50083
  keystore: paths.keystore,
50084
+ ...configRewrites.length > 0 ? { configRewrites } : {},
49945
50085
  message: "vAPI wallet created. Its encrypted key stays on this machine.",
49946
50086
  nextSteps: buildNextSteps(account.address)
49947
50087
  };
@@ -49949,6 +50089,7 @@ async function initCommand(argv, json2, io, dependencies) {
49949
50089
  io.stdout(JSON.stringify(result));
49950
50090
  return;
49951
50091
  }
50092
+ if (configRewrites.length > 0) io.stdout(formatLegacyRegistryRewrites(configRewrites));
49952
50093
  io.stdout(result.message);
49953
50094
  io.stdout(`Address: ${result.address}`);
49954
50095
  io.stdout(
@@ -49973,7 +50114,7 @@ async function fundCommand(argv, json2, io, dependencies) {
49973
50114
  });
49974
50115
  const fiatAmount = optionalUsdAmount(parsed.one("--amount"), "--amount");
49975
50116
  const paths = getVapiPaths();
49976
- const config2 = await loadConfig(paths.config);
50117
+ const config2 = await readConfig(paths.config, io);
49977
50118
  const account = await unlockKeystore(await getKeystorePassphrase(), paths.keystore);
49978
50119
  const session = await createOnrampSession({
49979
50120
  address: account.address,
@@ -49993,7 +50134,7 @@ async function searchCommand(argv, json2, io, dependencies) {
49993
50134
  maximumPositionals: 1
49994
50135
  });
49995
50136
  const limit = optionalPositiveInteger(parsed.one("--limit"), "--limit");
49996
- const config2 = await loadConfig(getVapiPaths().config);
50137
+ const config2 = await readConfig(getVapiPaths().config, io);
49997
50138
  const page = await searchMarketplace(
49998
50139
  {
49999
50140
  ...parsed.positionals[0] ? { query: parsed.positionals[0] } : {},
@@ -50017,7 +50158,7 @@ async function inspectCommand(argv, json2, io, dependencies) {
50017
50158
  parsed.positionals[0],
50018
50159
  "Usage: vapi inspect <id> [--endpoint <name>]"
50019
50160
  );
50020
- const config2 = await loadConfig(getVapiPaths().config);
50161
+ const config2 = await readConfig(getVapiPaths().config, io);
50021
50162
  const result = await inspectService(
50022
50163
  { id, ...parsed.one("--endpoint") ? { endpoint: parsed.one("--endpoint") } : {} },
50023
50164
  config2,
@@ -50041,7 +50182,7 @@ async function payCommand(argv, json2, io) {
50041
50182
  });
50042
50183
  const target = requiredPositional(parsed.positionals[0], "Usage: vapi pay <id-or-url> [options]");
50043
50184
  const paths = getVapiPaths();
50044
- const config2 = await loadConfig(paths.config);
50185
+ const config2 = await readConfig(paths.config, io);
50045
50186
  const account = await unlockKeystore(await getKeystorePassphrase(), paths.keystore);
50046
50187
  const bodyText = parsed.one("--body");
50047
50188
  const maxPriceUsd = aliasedOption(parsed, "--max", "--max-price-usd");
@@ -50067,7 +50208,7 @@ async function payCommand(argv, json2, io) {
50067
50208
  async function balanceCommand(argv, json2, io, dependencies) {
50068
50209
  requireNoArguments(argv, "balance");
50069
50210
  const paths = getVapiPaths();
50070
- const config2 = await loadConfig(paths.config);
50211
+ const config2 = await readConfig(paths.config, io);
50071
50212
  const account = await unlockKeystore(await getKeystorePassphrase(), paths.keystore);
50072
50213
  const wallet = await getWallet(account, config2, dependencies);
50073
50214
  output2(io, json2, wallet, formatWallet(wallet));
@@ -50085,7 +50226,7 @@ async function accountsCommand(argv, json2, io, dependencies) {
50085
50226
  const passphrase = await getKeystorePassphrase();
50086
50227
  const account = enable ? await enableSolanaKey(passphrase, paths.keystore) : await unlockKeystore(passphrase, paths.keystore);
50087
50228
  if (enable) await enableDefaultNetwork("solana", paths.config);
50088
- const config2 = await loadConfig(paths.config);
50229
+ const config2 = await readConfig(paths.config, io);
50089
50230
  const accounts = await listAccounts({
50090
50231
  address: account.address,
50091
50232
  ...account.solana ? { solanaAddress: account.solana.address } : {},
@@ -50154,7 +50295,7 @@ async function sweepCommand(argv, json2, io) {
50154
50295
  );
50155
50296
  const requestedNetwork = parsed.one("--network");
50156
50297
  const paths = getVapiPaths();
50157
- const config2 = await loadConfig(paths.config);
50298
+ const config2 = await readConfig(paths.config, io);
50158
50299
  const account = await unlockKeystore(await getKeystorePassphrase(), paths.keystore);
50159
50300
  if (requestedNetwork && !isNetworkConfigured(config2.networks, requestedNetwork)) {
50160
50301
  throw new Error(`Network ${requestedNetwork} is not configured.`);
@@ -50198,6 +50339,33 @@ async function reportCommand(argv, json2, io, dependencies) {
50198
50339
  });
50199
50340
  output2(io, json2, result, formatSupportReport(result));
50200
50341
  }
50342
+ var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
50343
+ async function exportKeyCommand(argv, json2, io) {
50344
+ const parsed = parseArguments(argv, {
50345
+ valueOptions: /* @__PURE__ */ new Set(["--network"]),
50346
+ maximumPositionals: 0
50347
+ });
50348
+ const network = parsed.one("--network") ?? BASE_MAINNET_CAIP2;
50349
+ const solana = isSolanaNetwork(network);
50350
+ if (!solana && !network.startsWith("eip155:")) {
50351
+ throw new UsageError("--network must be an eip155:<chainId> or Solana network identifier.");
50352
+ }
50353
+ const paths = getVapiPaths();
50354
+ const keys = await exportKeystoreKeys(await getKeystorePassphrase(), paths.keystore);
50355
+ if (solana && !keys.solana) {
50356
+ throw new Error(
50357
+ `No Solana key is enabled in ${paths.keystore}. Run vapi accounts --enable solana first.`
50358
+ );
50359
+ }
50360
+ const selected = solana && keys.solana ? keys.solana : keys.evm;
50361
+ const result = {
50362
+ network,
50363
+ address: selected.address,
50364
+ privateKey: "secretKey" in selected ? selected.secretKey : selected.privateKey
50365
+ };
50366
+ io.stderr(EXPORT_KEY_WARNING);
50367
+ io.stdout(json2 ? JSON.stringify(result) : result.privateKey);
50368
+ }
50201
50369
  async function mcpCommand(argv) {
50202
50370
  requireNoArguments(argv, "mcp");
50203
50371
  const paths = getVapiPaths();
@@ -50211,6 +50379,9 @@ async function mcpCommand(argv) {
50211
50379
  searchesPath: paths.searches
50212
50380
  });
50213
50381
  }
50382
+ async function readConfig(path, io) {
50383
+ return await loadConfig(path, process.env, { notice: io.stderr });
50384
+ }
50214
50385
  function output2(io, json2, value, human) {
50215
50386
  io.stdout(json2 ? JSON.stringify(value) : human);
50216
50387
  }
@@ -50276,16 +50447,14 @@ function formatNextStep(label, value, note) {
50276
50447
  const step = `${label.padEnd(10)}${value}`;
50277
50448
  return note === void 0 ? step : `${step.padEnd(52)} ${note}`;
50278
50449
  }
50279
- async function showBanner(io) {
50280
- const write = io.write;
50281
- if (write === void 0 || !shouldAnimateMark()) {
50282
- io.stdout(staticBanner());
50283
- return;
50284
- }
50285
- await animateBanner({ version: CLI_VERSION, write });
50286
- }
50287
- function staticBanner() {
50288
- return renderBanner({ version: CLI_VERSION, color: markColorEnabled() });
50450
+ function showBanner(io) {
50451
+ io.stdout(
50452
+ renderBanner({
50453
+ version: CLI_VERSION,
50454
+ colorLevel: detectColorLevel(),
50455
+ columns: process.stdout.columns
50456
+ })
50457
+ );
50289
50458
  }
50290
50459
  function formatAccounts(accounts) {
50291
50460
  if (accounts.length === 0) return "No configured network accounts.";