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/cli.js CHANGED
@@ -45330,8 +45330,8 @@ var DEFAULT_DISCOVERY_URL = `${DEFAULT_REGISTRY_URL}/api/call/services`;
45330
45330
  var DEFAULT_MARKETPLACE_DISCOVERY_URL = `${DEFAULT_REGISTRY_URL}/api/call/discovery`;
45331
45331
  var DEFAULT_REGISTRY_FALLBACKS = [
45332
45332
  {
45333
- discoveryUrl: "https://console.vapinetwork.ai/api/call/services",
45334
- marketplaceDiscoveryUrl: "https://console.vapinetwork.ai/api/call/discovery"
45333
+ discoveryUrl: DEFAULT_DISCOVERY_URL,
45334
+ marketplaceDiscoveryUrl: DEFAULT_MARKETPLACE_DISCOVERY_URL
45335
45335
  }
45336
45336
  ];
45337
45337
  var DEFAULT_SPEND_CAPS = {
@@ -45436,6 +45436,83 @@ async function migrateLegacyVapiHome(options = {}) {
45436
45436
  }
45437
45437
  return copied;
45438
45438
  }
45439
+ var LEGACY_REGISTRY_HOSTS = /* @__PURE__ */ new Map([
45440
+ ["console.vapinetwork.ai", "api.vapinetwork.ai"],
45441
+ ["console-staging.vapinetwork.ai", "api-staging.vapinetwork.ai"]
45442
+ ]);
45443
+ var LEGACY_REGISTRY_PATHS = /* @__PURE__ */ new Map([
45444
+ ["/api/network/services", "/api/call/services"],
45445
+ ["/api/marketplace/discovery", "/api/call/discovery"]
45446
+ ]);
45447
+ var REGISTRY_DOMAIN = "vapinetwork.ai";
45448
+ function rewriteLegacyRegistryUrl(value) {
45449
+ let url2;
45450
+ try {
45451
+ url2 = new URL(value);
45452
+ } catch {
45453
+ return value;
45454
+ }
45455
+ let rewritten = false;
45456
+ const host = LEGACY_REGISTRY_HOSTS.get(url2.hostname.toLowerCase());
45457
+ if (host) {
45458
+ url2.hostname = host;
45459
+ rewritten = true;
45460
+ }
45461
+ const hostname3 = url2.hostname.toLowerCase();
45462
+ if (hostname3 === REGISTRY_DOMAIN || hostname3.endsWith(`.${REGISTRY_DOMAIN}`)) {
45463
+ const path = LEGACY_REGISTRY_PATHS.get(url2.pathname.replace(/\/+$/, ""));
45464
+ if (path) {
45465
+ url2.pathname = path;
45466
+ rewritten = true;
45467
+ }
45468
+ }
45469
+ return rewritten ? url2.href : value;
45470
+ }
45471
+ function rewriteLegacyRegistryUrls(config2) {
45472
+ const changes = [];
45473
+ const rewrite = (field, from16) => {
45474
+ const to = rewriteLegacyRegistryUrl(from16);
45475
+ if (to !== from16) changes.push({ field, from: from16, to });
45476
+ return to;
45477
+ };
45478
+ const next = {
45479
+ ...config2,
45480
+ discoveryUrl: rewrite("discoveryUrl", config2.discoveryUrl),
45481
+ marketplaceDiscoveryUrl: rewrite("marketplaceDiscoveryUrl", config2.marketplaceDiscoveryUrl),
45482
+ ...config2.registryFallbacks ? {
45483
+ registryFallbacks: config2.registryFallbacks.map((fallback, index2) => ({
45484
+ discoveryUrl: rewrite(
45485
+ `registryFallbacks[${index2}].discoveryUrl`,
45486
+ fallback.discoveryUrl
45487
+ ),
45488
+ marketplaceDiscoveryUrl: rewrite(
45489
+ `registryFallbacks[${index2}].marketplaceDiscoveryUrl`,
45490
+ fallback.marketplaceDiscoveryUrl
45491
+ )
45492
+ }))
45493
+ } : {}
45494
+ };
45495
+ return changes.length === 0 ? { config: config2, changes } : { config: next, changes };
45496
+ }
45497
+ function formatLegacyRegistryRewrites(changes) {
45498
+ return [
45499
+ "Rewrote retired vAPI registry URLs in the local config:",
45500
+ ...changes.map((change) => ` ${change.field}: ${change.from} -> ${change.to}`)
45501
+ ].join("\n");
45502
+ }
45503
+ async function migrateLegacyRegistryConfig(path = getVapiPaths().config) {
45504
+ let raw;
45505
+ try {
45506
+ raw = await readFile(path, "utf8");
45507
+ } catch (error61) {
45508
+ if (isMissingFile(error61)) return [];
45509
+ throw error61;
45510
+ }
45511
+ const { config: config2, changes } = rewriteLegacyRegistryUrls(configSchema.parse(JSON.parse(raw)));
45512
+ if (changes.length === 0) return [];
45513
+ await writeConfigFile(path, config2);
45514
+ return changes;
45515
+ }
45439
45516
  function getDefaultConfig(source = process.env, options = {}) {
45440
45517
  const registry2 = registryEndpoints(source.VAPI_REGISTRY_URL?.trim() || DEFAULT_REGISTRY_URL);
45441
45518
  const requested = new Set(options.networks ?? ["base"]);
@@ -45474,7 +45551,7 @@ function getDefaultConfig(source = process.env, options = {}) {
45474
45551
  spendCaps: { ...DEFAULT_SPEND_CAPS }
45475
45552
  };
45476
45553
  }
45477
- async function loadConfig(path = getVapiPaths().config, source = process.env) {
45554
+ async function loadConfig(path = getVapiPaths().config, source = process.env, options = {}) {
45478
45555
  if (!process.env.VAPI_HOME?.trim() && path === getVapiPaths(join(homedir(), ".vapi")).config) {
45479
45556
  await migrateLegacyVapiHome({ targetDirectory: join(homedir(), ".vapi") });
45480
45557
  }
@@ -45485,8 +45562,16 @@ async function loadConfig(path = getVapiPaths().config, source = process.env) {
45485
45562
  if (isMissingFile(error61)) return getDefaultConfig(source);
45486
45563
  throw error61;
45487
45564
  }
45488
- const config2 = configSchema.parse(JSON.parse(raw));
45489
- config2.registryFallbacks ??= DEFAULT_REGISTRY_FALLBACKS.map((fallback) => ({ ...fallback }));
45565
+ const parsed = configSchema.parse(JSON.parse(raw));
45566
+ parsed.registryFallbacks ??= DEFAULT_REGISTRY_FALLBACKS.map((fallback) => ({ ...fallback }));
45567
+ const migrated = rewriteLegacyRegistryUrls(parsed);
45568
+ const config2 = migrated.config;
45569
+ if (migrated.changes.length > 0 && options.notice) {
45570
+ options.notice(
45571
+ `${formatLegacyRegistryRewrites(migrated.changes)}
45572
+ Run vapi init to write the new URLs to ${path}.`
45573
+ );
45574
+ }
45490
45575
  const baseRpcUrl = source.BASE_RPC_URL?.trim();
45491
45576
  const arcRpcUrl = source.ARC_TESTNET_RPC_URL?.trim();
45492
45577
  const solanaRpcUrl = source.SOLANA_RPC_URL?.trim();
@@ -45542,15 +45627,7 @@ async function writeDefaultConfig(path = getVapiPaths().config, source = process
45542
45627
  if (copied.includes(path)) return await loadConfig(path, source);
45543
45628
  }
45544
45629
  const config2 = getDefaultConfig(source, options);
45545
- await mkdir(dirname(path), { recursive: true, mode: 448 });
45546
- const temporaryPath = `${path}.${process.pid}.tmp`;
45547
- await writeFile(temporaryPath, `${JSON.stringify(config2, null, 2)}
45548
- `, {
45549
- encoding: "utf8",
45550
- mode: 384,
45551
- flag: "wx"
45552
- });
45553
- await rename(temporaryPath, path);
45630
+ await writeConfigFile(path, config2);
45554
45631
  return config2;
45555
45632
  }
45556
45633
  async function enableDefaultNetwork(network, path = getVapiPaths().config, source = process.env) {
@@ -45561,6 +45638,10 @@ async function enableDefaultNetwork(network, path = getVapiPaths().config, sourc
45561
45638
  usdc: NETWORKS[SOLANA_MAINNET_CAIP2].usdc
45562
45639
  };
45563
45640
  }
45641
+ await writeConfigFile(path, config2);
45642
+ return config2;
45643
+ }
45644
+ async function writeConfigFile(path, config2) {
45564
45645
  await mkdir(dirname(path), { recursive: true, mode: 448 });
45565
45646
  const temporaryPath = `${path}.${process.pid}.tmp`;
45566
45647
  await writeFile(temporaryPath, `${JSON.stringify(config2, null, 2)}
@@ -45570,7 +45651,6 @@ async function enableDefaultNetwork(network, path = getVapiPaths().config, sourc
45570
45651
  flag: "wx"
45571
45652
  });
45572
45653
  await rename(temporaryPath, path);
45573
- return config2;
45574
45654
  }
45575
45655
  async function pathExists(path) {
45576
45656
  try {
@@ -45991,6 +46071,49 @@ async function unlockKeystore(passphrase, path = getVapiPaths().keystore) {
45991
46071
  }
45992
46072
  return await paymentAccountFromKeys(keys);
45993
46073
  }
46074
+ async function readKeystoreAddress(path = getVapiPaths().keystore) {
46075
+ let raw;
46076
+ try {
46077
+ raw = await readFile3(path, "utf8");
46078
+ } catch {
46079
+ return void 0;
46080
+ }
46081
+ let parsed;
46082
+ try {
46083
+ parsed = JSON.parse(raw);
46084
+ } catch {
46085
+ return void 0;
46086
+ }
46087
+ const address2 = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "address") : void 0;
46088
+ return typeof address2 === "string" ? address2 : void 0;
46089
+ }
46090
+ async function exportKeystoreKeys(passphrase, path = getVapiPaths().keystore) {
46091
+ let raw;
46092
+ try {
46093
+ raw = await readFile3(path, "utf8");
46094
+ } catch (error61) {
46095
+ if (isMissingFile(error61)) {
46096
+ throw new KeystoreError(`No vAPI keystore found at ${path}. Run vapi init.`);
46097
+ }
46098
+ throw error61;
46099
+ }
46100
+ const keys = await decryptKeys(parseAnyKeystore(JSON.parse(raw)), passphrase);
46101
+ const evmPrivateKey = keys.evm;
46102
+ const exported = {
46103
+ evm: { address: privateKeyToAccount(evmPrivateKey).address, privateKey: evmPrivateKey }
46104
+ };
46105
+ if (!keys.solana) return exported;
46106
+ const seed = Uint8Array.from(Buffer.from(keys.solana, "base64"));
46107
+ const signer = await createSolanaSigner(Uint8Array.from(seed));
46108
+ const publicKey = Uint8Array.from(getBase58Encoder().encode(signer.address));
46109
+ const secretKey = new Uint8Array(seed.length + publicKey.length);
46110
+ secretKey.set(seed);
46111
+ secretKey.set(publicKey, seed.length);
46112
+ const encoded = getBase58Decoder().decode(secretKey);
46113
+ seed.fill(0);
46114
+ secretKey.fill(0);
46115
+ return { ...exported, solana: { address: signer.address, secretKey: encoded } };
46116
+ }
45994
46117
  async function enableSolanaKey(passphrase, path = getVapiPaths().keystore) {
45995
46118
  let raw;
45996
46119
  try {
@@ -46670,7 +46793,7 @@ function csvCell(value) {
46670
46793
  import { mkdir as mkdir6, writeFile as writeFile4 } from "node:fs/promises";
46671
46794
  import { arch, platform, release } from "node:os";
46672
46795
  import { join as join2 } from "node:path";
46673
- var VAPI_CLIENT_VERSION = "0.2.1";
46796
+ var VAPI_CLIENT_VERSION = "0.2.3";
46674
46797
  async function createSupportReport(options) {
46675
46798
  const message = options.message.trim();
46676
46799
  if (!message) throw new Error("Support report message must not be empty.");
@@ -48804,132 +48927,122 @@ function asRecord(value) {
48804
48927
  var MARK_SOURCE_WIDTH = 743;
48805
48928
  var MARK_SOURCE_HEIGHT = 659;
48806
48929
  var MARK_SOURCE_ROW_HEIGHT = 217;
48807
- var MARK_COLUMNS = 28;
48808
- var MARK_ROWS = 12;
48809
- var PLAIN_BLOCK = "\u2588";
48810
- var MARK_STEP_MS = 70;
48930
+ var MARK_COLUMNS = 21;
48931
+ var MARK_ROWS = 9;
48932
+ var BLOCK = "\u2588";
48811
48933
  var WORDMARK = "vAPI Network";
48812
48934
  var WELCOME = "Welcome to the vAPI Network";
48813
48935
  var TAGLINE = [
48814
- "The trusted network where agents and humans do business.",
48815
- "Search APIs, pay per call, keep receipts. More coming soon."
48936
+ "The trusted network where agents",
48937
+ "and humans do business.",
48938
+ "",
48939
+ "Search APIs, pay per call, keep",
48940
+ "receipts. More coming soon."
48816
48941
  ];
48817
- var ESC = "\x1B";
48942
+ var ESC = String.fromCharCode(27);
48818
48943
  var RESET = `${ESC}[0m`;
48819
- var REVERSE = `${ESC}[7m`;
48820
48944
  var BOLD = `${ESC}[1m`;
48821
48945
  var DIM = `${ESC}[2m`;
48822
- var HIDE_CURSOR = `${ESC}[?25l`;
48823
- var SHOW_CURSOR = `${ESC}[?25h`;
48946
+ var DEFAULT_FOREGROUND = `${ESC}[39m`;
48824
48947
  var MARK_PALETTE = {
48825
- orange: "#ff7300",
48826
- pink: "#ff337c",
48827
- lime: "#c3ff3d",
48828
- cyan: "#97efff",
48829
- blue: "#0041eb",
48830
- purple: "#8a37fb",
48948
+ orange: { hex: "#ff7300", ansi16: 33 },
48949
+ pink: { hex: "#ff337c", ansi16: 95 },
48950
+ lime: { hex: "#c3ff3d", ansi16: 92 },
48951
+ cyan: { hex: "#97efff", ansi16: 96 },
48952
+ blue: { hex: "#0041eb", ansi16: 34 },
48953
+ purple: { hex: "#8a37fb", ansi16: 35 },
48831
48954
  ink: null
48832
48955
  };
48833
48956
  var MARK_BLOCKS = [
48834
- { row: 0, x: 2, width: 90, color: "orange", delay: 0 },
48835
- { row: 0, x: 94, width: 35, color: "pink", delay: 1 },
48836
- { row: 0, x: 131, width: 16, color: "lime", delay: 2 },
48837
- { row: 0, x: 522, width: 219, color: "ink", delay: 1 },
48838
- { row: 1, x: 124, width: 50, color: "cyan", delay: 3 },
48839
- { row: 1, x: 176, width: 24, color: "blue", delay: 4 },
48840
- { row: 1, x: 202, width: 17, color: "purple", delay: 5 },
48841
- { row: 1, x: 402, width: 219, color: "blue", delay: 4 },
48842
- { row: 2, x: 282, width: 219, color: "ink", delay: 7 }
48957
+ { row: 0, x: 2, width: 90, color: "orange" },
48958
+ { row: 0, x: 94, width: 35, color: "pink" },
48959
+ { row: 0, x: 131, width: 16, color: "lime" },
48960
+ { row: 0, x: 522, width: 219, color: "ink" },
48961
+ { row: 1, x: 124, width: 50, color: "cyan" },
48962
+ { row: 1, x: 176, width: 24, color: "blue" },
48963
+ { row: 1, x: 202, width: 17, color: "purple" },
48964
+ { row: 1, x: 402, width: 219, color: "blue" },
48965
+ { row: 2, x: 282, width: 219, color: "ink" }
48843
48966
  ];
48844
- function markColorEnabled(environment = {}) {
48967
+ function detectColorLevel(environment = {}) {
48845
48968
  const env = environment.env ?? process.env;
48846
48969
  const isTty = environment.isTty ?? Boolean(process.stdout.isTTY);
48847
- return isTty && !env.NO_COLOR;
48848
- }
48849
- function shouldAnimateMark(environment = {}) {
48850
- const env = environment.env ?? process.env;
48851
- if (environment.json) return false;
48852
- if (env.NO_COLOR || env.CI) return false;
48853
- return markColorEnabled(environment);
48854
- }
48855
- function renderMarkFrames(options = {}) {
48856
- const steps = [...new Set(MARK_BLOCKS.map((block) => block.delay))].sort(
48857
- (left, right) => left - right
48858
- );
48859
- return steps.map(
48860
- (step) => renderFrame(
48861
- MARK_BLOCKS.filter((block) => block.delay <= step),
48862
- options.color === true
48863
- )
48864
- );
48865
- }
48866
- function renderBanner(options) {
48867
- const frames = renderMarkFrames(options);
48868
- return renderBox(frames[frames.length - 1], options).join("\n");
48869
- }
48870
- async function animateBanner(options) {
48871
- const frames = renderMarkFrames({ color: options.color !== false });
48872
- const sleep = options.sleep ?? defaultSleep;
48873
- const stepMs = options.stepMs ?? MARK_STEP_MS;
48874
- const boxes = frames.map((frame) => renderBox(frame, options));
48875
- const height = boxes[0].length;
48876
- options.write(HIDE_CURSOR);
48877
- try {
48878
- for (const [index2, box] of boxes.entries()) {
48879
- if (index2 > 0) options.write(`${ESC}[${height}A`);
48880
- options.write(box.map((line) => `\r${ESC}[2K${line}
48881
- `).join(""));
48882
- if (index2 < boxes.length - 1) await sleep(stepMs);
48883
- }
48884
- } finally {
48885
- options.write(SHOW_CURSOR);
48886
- }
48887
- }
48888
- function renderBox(frame, options) {
48889
- const color = options.color === true;
48890
- const text = [
48891
- { value: WELCOME, style: BOLD },
48892
- { value: "", style: "" },
48893
- ...TAGLINE.map((line) => ({ value: line, style: "" })),
48894
- { value: "", style: "" },
48895
- { value: `${WORDMARK} v${options.version}`, style: DIM }
48896
- ];
48897
- const textWidth = Math.max(...text.map((line) => line.value.length));
48898
- const gap = 3;
48899
- const inner = 2 + MARK_COLUMNS + gap + textWidth + 2;
48900
- const markLines = frame.split("\n");
48901
- const textTop = Math.floor((MARK_ROWS - text.length) / 2);
48902
- const lines = [];
48903
- lines.push(`\u256D${"\u2500".repeat(inner)}\u256E`);
48904
- lines.push(`\u2502${" ".repeat(inner)}\u2502`);
48905
- for (let row = 0; row < MARK_ROWS; row += 1) {
48906
- const mark = markLines[row] ?? "";
48907
- const markPad = " ".repeat(Math.max(0, MARK_COLUMNS - visibleLength(mark)));
48908
- const entry = text[row - textTop];
48909
- const raw = entry?.value ?? "";
48910
- const styled = color && entry && entry.style && raw ? `${entry.style}${raw}${RESET}` : raw;
48911
- const textPad = " ".repeat(textWidth - raw.length);
48912
- lines.push(`\u2502 ${mark}${markPad}${" ".repeat(gap)}${styled}${textPad} \u2502`);
48970
+ if (env.NO_COLOR) return 0;
48971
+ const forced = env.FORCE_COLOR;
48972
+ if (forced !== void 0) {
48973
+ if (forced === "0" || forced === "false") return 0;
48974
+ if (forced === "2") return 2;
48975
+ if (forced === "3") return 3;
48976
+ return 1;
48913
48977
  }
48914
- lines.push(`\u2502${" ".repeat(inner)}\u2502`);
48915
- lines.push(`\u2570${"\u2500".repeat(inner)}\u256F`);
48916
- return lines;
48917
- }
48918
- function renderFrame(blocks, color) {
48978
+ if (!isTty) return 0;
48979
+ const term = env.TERM ?? "";
48980
+ const program = env.TERM_PROGRAM ?? "";
48981
+ if (term === "dumb") return 0;
48982
+ if (/^(truecolor|24bit)$/i.test(env.COLORTERM ?? "")) return 3;
48983
+ if (/kitty|wezterm|ghostty|alacritty/i.test(term)) return 3;
48984
+ if (/^(iTerm\.app|vscode|Hyper|WezTerm|ghostty)$/i.test(program)) return 3;
48985
+ if (/-256(?:color)?$/i.test(term) || program === "Apple_Terminal") return 2;
48986
+ return 1;
48987
+ }
48988
+ function renderMark(colorLevel = 0) {
48919
48989
  const rows = [];
48920
48990
  for (let row = 0; row < MARK_ROWS; row += 1) {
48921
48991
  const sourceY = row * MARK_SOURCE_HEIGHT / MARK_ROWS;
48922
48992
  const band = Math.min(2, Math.floor(sourceY / MARK_SOURCE_ROW_HEIGHT));
48923
48993
  rows.push(
48924
48994
  renderRow(
48925
- blocks.filter((block) => block.row === band),
48926
- color
48995
+ MARK_BLOCKS.filter((block) => block.row === band),
48996
+ colorLevel
48927
48997
  )
48928
48998
  );
48929
48999
  }
48930
49000
  return rows.join("\n");
48931
49001
  }
48932
- function renderRow(blocks, color) {
49002
+ function bannerWidth() {
49003
+ return frameInnerWidth() + 2;
49004
+ }
49005
+ function renderBanner(options) {
49006
+ const colorLevel = options.colorLevel ?? 0;
49007
+ const columns = options.columns ?? Number.POSITIVE_INFINITY;
49008
+ const text = bannerText(options.version, colorLevel);
49009
+ if (columns < bannerWidth()) {
49010
+ return text.map((line) => line.styled).join("\n");
49011
+ }
49012
+ const inner = frameInnerWidth();
49013
+ const markLines = renderMark(colorLevel).split("\n");
49014
+ const lines = [];
49015
+ lines.push(`\u256D${"\u2500".repeat(inner)}\u256E`);
49016
+ lines.push(`\u2502${" ".repeat(inner)}\u2502`);
49017
+ for (let row = 0; row < MARK_ROWS; row += 1) {
49018
+ const entry = text[row];
49019
+ const value = entry?.value ?? "";
49020
+ const styled = entry?.styled ?? "";
49021
+ const pad4 = " ".repeat(TEXT_WIDTH - value.length);
49022
+ lines.push(`\u2502 ${markLines[row]}${" ".repeat(GAP)}${styled}${pad4} \u2502`);
49023
+ }
49024
+ lines.push(`\u2502${" ".repeat(inner)}\u2502`);
49025
+ lines.push(`\u2570${"\u2500".repeat(inner)}\u256F`);
49026
+ return lines.join("\n");
49027
+ }
49028
+ var GAP = 3;
49029
+ var TEXT_WIDTH = Math.max(WELCOME.length, ...TAGLINE.map((line) => line.length));
49030
+ function frameInnerWidth() {
49031
+ return 2 + MARK_COLUMNS + GAP + TEXT_WIDTH + 2;
49032
+ }
49033
+ function bannerText(version5, colorLevel) {
49034
+ const style = (value, code) => colorLevel > 0 && value ? `${code}${value}${RESET}` : value;
49035
+ const rows = [
49036
+ { value: WELCOME, styled: style(WELCOME, BOLD) },
49037
+ { value: "", styled: "" },
49038
+ ...TAGLINE.map((line) => ({ value: line, styled: line })),
49039
+ { value: "", styled: "" },
49040
+ { value: `${WORDMARK} v${version5}`, styled: style(`${WORDMARK} v${version5}`, DIM) }
49041
+ ];
49042
+ if (rows.length > MARK_ROWS) throw new Error("banner text is taller than the mark");
49043
+ return rows;
49044
+ }
49045
+ function renderRow(blocks, colorLevel) {
48933
49046
  const ordered = [...blocks].sort((left, right) => left.x - right.x);
48934
49047
  let column = 0;
48935
49048
  let line = "";
@@ -48940,7 +49053,8 @@ function renderRow(blocks, color) {
48940
49053
  column = start;
48941
49054
  }
48942
49055
  const width = scaleWidth(block.width);
48943
- line += color ? `${cellPrefix(block.color)}${" ".repeat(width)}${RESET}` : PLAIN_BLOCK.repeat(width);
49056
+ const cells = BLOCK.repeat(width);
49057
+ line += colorLevel > 0 ? `${foreground(block.color, colorLevel)}${cells}${RESET}` : cells;
48944
49058
  column += width;
48945
49059
  }
48946
49060
  return line + " ".repeat(Math.max(0, MARK_COLUMNS - column));
@@ -48951,23 +49065,28 @@ function scaleColumn(x) {
48951
49065
  function scaleWidth(width) {
48952
49066
  return Math.max(1, Math.round(width * MARK_COLUMNS / MARK_SOURCE_WIDTH));
48953
49067
  }
48954
- function cellPrefix(color) {
48955
- const hex3 = MARK_PALETTE[color];
48956
- if (hex3 === null) return REVERSE;
48957
- const value = Number.parseInt(hex3.slice(1), 16);
48958
- return `${ESC}[48;2;${value >> 16 & 255};${value >> 8 & 255};${value & 255}m`;
48959
- }
48960
- function visibleLength(line) {
48961
- return line.replace(new RegExp(`${ESC}\\[[0-9;?]*[A-Za-z]`, "g"), "").length;
49068
+ function foreground(color, colorLevel) {
49069
+ const entry = MARK_PALETTE[color];
49070
+ if (entry === null) return DEFAULT_FOREGROUND;
49071
+ const value = Number.parseInt(entry.hex.slice(1), 16);
49072
+ const red = value >> 16 & 255;
49073
+ const green = value >> 8 & 255;
49074
+ const blue = value & 255;
49075
+ if (colorLevel === 3) return `${ESC}[38;2;${red};${green};${blue}m`;
49076
+ if (colorLevel === 2) return `${ESC}[38;5;${rgbToAnsi256(red, green, blue)}m`;
49077
+ return `${ESC}[${entry.ansi16}m`;
48962
49078
  }
48963
- function defaultSleep(milliseconds) {
48964
- return new Promise((resolve) => {
48965
- setTimeout(resolve, milliseconds);
48966
- });
49079
+ function rgbToAnsi256(red, green, blue) {
49080
+ if (red === green && green === blue) {
49081
+ if (red < 8) return 16;
49082
+ if (red > 248) return 231;
49083
+ return Math.round((red - 8) / 247 * 24) + 232;
49084
+ }
49085
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
48967
49086
  }
48968
49087
 
48969
49088
  // ../cli/src/version.ts
48970
- var CLI_VERSION = "0.2.1";
49089
+ var CLI_VERSION = "0.2.3";
48971
49090
 
48972
49091
  // ../cli/src/cli.ts
48973
49092
  var HELP_HEADING = "vAPI Network";
@@ -48985,6 +49104,7 @@ Usage:
48985
49104
  vapi receipts export --format <json|csv> [--range <24h|7d|30d>]
48986
49105
  vapi stats [--range <24h|7d|30d>] [--json]
48987
49106
  vapi sweep <address> [--network <caip2>] [--json]
49107
+ vapi export-key [--network <caip2>] [--json]
48988
49108
  vapi report "<what happened>" [--include-addresses] [--send] [--json]
48989
49109
  vapi mcp [--json]
48990
49110
  vapi serve [--json]
@@ -48996,8 +49116,7 @@ var processIo = {
48996
49116
  stdout: (message) => process.stdout.write(`${message}
48997
49117
  `),
48998
49118
  stderr: (message) => process.stderr.write(`${message}
48999
- `),
49000
- write: (chunk) => process.stdout.write(chunk)
49119
+ `)
49001
49120
  };
49002
49121
  var UsageError = class extends Error {
49003
49122
  };
@@ -49016,7 +49135,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
49016
49135
  if (command === void 0 || command === "help" || command === "--help" || command === "-h") {
49017
49136
  requireNoArguments(args.slice(command === void 0 ? 0 : 1), command ?? "help");
49018
49137
  if (command === void 0 && !json2) {
49019
- io.stdout(staticBanner());
49138
+ showBanner(io);
49020
49139
  io.stdout(HELP.slice(HELP_HEADING.length + 2));
49021
49140
  return 0;
49022
49141
  }
@@ -49054,6 +49173,9 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
49054
49173
  case "sweep":
49055
49174
  await sweepCommand(args.slice(1), json2, io);
49056
49175
  return 0;
49176
+ case "export-key":
49177
+ await exportKeyCommand(args.slice(1), json2, io);
49178
+ return 0;
49057
49179
  case "report":
49058
49180
  await reportCommand(args.slice(1), json2, io, dependencies);
49059
49181
  return 0;
@@ -49087,14 +49209,24 @@ async function initCommand(argv, json2, io, dependencies) {
49087
49209
  });
49088
49210
  const networks = parseInitNetworks(parsed.one("--networks") ?? "base");
49089
49211
  const enableSolana = networks.includes("solana");
49090
- if (!json2) await showBanner(io);
49212
+ if (!json2) showBanner(io);
49091
49213
  const paths = getVapiPaths();
49092
49214
  let migrated = [];
49093
49215
  if (!process.env.VAPI_HOME?.trim()) {
49094
49216
  migrated = await migrateLegacyVapiHome({ targetDirectory: paths.directory, notice: io.stderr });
49095
49217
  }
49218
+ const adopted = migrated.includes(paths.keystore);
49219
+ if (!adopted && await fileExists(paths.keystore)) {
49220
+ const address2 = await readKeystoreAddress(paths.keystore);
49221
+ throw new Error(
49222
+ [
49223
+ `Keystore already exists at ${paths.keystore}. Refusing to replace the local payment key.`,
49224
+ ...address2 ? [`Address: ${address2}`] : []
49225
+ ].join("\n")
49226
+ );
49227
+ }
49096
49228
  const passphrase = await getKeystorePassphrase({ confirm: true });
49097
- let account = migrated.includes(paths.keystore) ? await unlockKeystore(passphrase, paths.keystore) : await createKeystore(passphrase, paths.keystore, { enableSolana });
49229
+ let account = adopted ? await unlockKeystore(passphrase, paths.keystore) : await createKeystore(passphrase, paths.keystore, { enableSolana });
49098
49230
  if (enableSolana && !account.solana) {
49099
49231
  account = await enableSolanaKey(passphrase, paths.keystore);
49100
49232
  }
@@ -49103,7 +49235,8 @@ async function initCommand(argv, json2, io, dependencies) {
49103
49235
  } else if (enableSolana) {
49104
49236
  await enableDefaultNetwork("solana", paths.config);
49105
49237
  }
49106
- const config2 = await loadConfig(paths.config);
49238
+ const configRewrites = await migrateLegacyRegistryConfig(paths.config);
49239
+ const config2 = await readConfig(paths.config, io);
49107
49240
  const accounts = await listAccounts({
49108
49241
  address: account.address,
49109
49242
  ...account.solana ? { solanaAddress: account.solana.address } : {},
@@ -49115,6 +49248,7 @@ async function initCommand(argv, json2, io, dependencies) {
49115
49248
  accounts,
49116
49249
  config: paths.config,
49117
49250
  keystore: paths.keystore,
49251
+ ...configRewrites.length > 0 ? { configRewrites } : {},
49118
49252
  message: "vAPI wallet created. Its encrypted key stays on this machine.",
49119
49253
  nextSteps: buildNextSteps(account.address)
49120
49254
  };
@@ -49122,6 +49256,7 @@ async function initCommand(argv, json2, io, dependencies) {
49122
49256
  io.stdout(JSON.stringify(result));
49123
49257
  return;
49124
49258
  }
49259
+ if (configRewrites.length > 0) io.stdout(formatLegacyRegistryRewrites(configRewrites));
49125
49260
  io.stdout(result.message);
49126
49261
  io.stdout(`Address: ${result.address}`);
49127
49262
  io.stdout(
@@ -49146,7 +49281,7 @@ async function fundCommand(argv, json2, io, dependencies) {
49146
49281
  });
49147
49282
  const fiatAmount = optionalUsdAmount(parsed.one("--amount"), "--amount");
49148
49283
  const paths = getVapiPaths();
49149
- const config2 = await loadConfig(paths.config);
49284
+ const config2 = await readConfig(paths.config, io);
49150
49285
  const account = await unlockKeystore(await getKeystorePassphrase(), paths.keystore);
49151
49286
  const session = await createOnrampSession({
49152
49287
  address: account.address,
@@ -49166,7 +49301,7 @@ async function searchCommand(argv, json2, io, dependencies) {
49166
49301
  maximumPositionals: 1
49167
49302
  });
49168
49303
  const limit = optionalPositiveInteger(parsed.one("--limit"), "--limit");
49169
- const config2 = await loadConfig(getVapiPaths().config);
49304
+ const config2 = await readConfig(getVapiPaths().config, io);
49170
49305
  const page = await searchMarketplace(
49171
49306
  {
49172
49307
  ...parsed.positionals[0] ? { query: parsed.positionals[0] } : {},
@@ -49190,7 +49325,7 @@ async function inspectCommand(argv, json2, io, dependencies) {
49190
49325
  parsed.positionals[0],
49191
49326
  "Usage: vapi inspect <id> [--endpoint <name>]"
49192
49327
  );
49193
- const config2 = await loadConfig(getVapiPaths().config);
49328
+ const config2 = await readConfig(getVapiPaths().config, io);
49194
49329
  const result = await inspectService(
49195
49330
  { id, ...parsed.one("--endpoint") ? { endpoint: parsed.one("--endpoint") } : {} },
49196
49331
  config2,
@@ -49214,7 +49349,7 @@ async function payCommand(argv, json2, io) {
49214
49349
  });
49215
49350
  const target = requiredPositional(parsed.positionals[0], "Usage: vapi pay <id-or-url> [options]");
49216
49351
  const paths = getVapiPaths();
49217
- const config2 = await loadConfig(paths.config);
49352
+ const config2 = await readConfig(paths.config, io);
49218
49353
  const account = await unlockKeystore(await getKeystorePassphrase(), paths.keystore);
49219
49354
  const bodyText = parsed.one("--body");
49220
49355
  const maxPriceUsd = aliasedOption(parsed, "--max", "--max-price-usd");
@@ -49240,7 +49375,7 @@ async function payCommand(argv, json2, io) {
49240
49375
  async function balanceCommand(argv, json2, io, dependencies) {
49241
49376
  requireNoArguments(argv, "balance");
49242
49377
  const paths = getVapiPaths();
49243
- const config2 = await loadConfig(paths.config);
49378
+ const config2 = await readConfig(paths.config, io);
49244
49379
  const account = await unlockKeystore(await getKeystorePassphrase(), paths.keystore);
49245
49380
  const wallet = await getWallet(account, config2, dependencies);
49246
49381
  output2(io, json2, wallet, formatWallet(wallet));
@@ -49258,7 +49393,7 @@ async function accountsCommand(argv, json2, io, dependencies) {
49258
49393
  const passphrase = await getKeystorePassphrase();
49259
49394
  const account = enable ? await enableSolanaKey(passphrase, paths.keystore) : await unlockKeystore(passphrase, paths.keystore);
49260
49395
  if (enable) await enableDefaultNetwork("solana", paths.config);
49261
- const config2 = await loadConfig(paths.config);
49396
+ const config2 = await readConfig(paths.config, io);
49262
49397
  const accounts = await listAccounts({
49263
49398
  address: account.address,
49264
49399
  ...account.solana ? { solanaAddress: account.solana.address } : {},
@@ -49327,7 +49462,7 @@ async function sweepCommand(argv, json2, io) {
49327
49462
  );
49328
49463
  const requestedNetwork = parsed.one("--network");
49329
49464
  const paths = getVapiPaths();
49330
- const config2 = await loadConfig(paths.config);
49465
+ const config2 = await readConfig(paths.config, io);
49331
49466
  const account = await unlockKeystore(await getKeystorePassphrase(), paths.keystore);
49332
49467
  if (requestedNetwork && !isNetworkConfigured(config2.networks, requestedNetwork)) {
49333
49468
  throw new Error(`Network ${requestedNetwork} is not configured.`);
@@ -49371,6 +49506,33 @@ async function reportCommand(argv, json2, io, dependencies) {
49371
49506
  });
49372
49507
  output2(io, json2, result, formatSupportReport(result));
49373
49508
  }
49509
+ var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
49510
+ async function exportKeyCommand(argv, json2, io) {
49511
+ const parsed = parseArguments(argv, {
49512
+ valueOptions: /* @__PURE__ */ new Set(["--network"]),
49513
+ maximumPositionals: 0
49514
+ });
49515
+ const network = parsed.one("--network") ?? BASE_MAINNET_CAIP2;
49516
+ const solana = isSolanaNetwork(network);
49517
+ if (!solana && !network.startsWith("eip155:")) {
49518
+ throw new UsageError("--network must be an eip155:<chainId> or Solana network identifier.");
49519
+ }
49520
+ const paths = getVapiPaths();
49521
+ const keys = await exportKeystoreKeys(await getKeystorePassphrase(), paths.keystore);
49522
+ if (solana && !keys.solana) {
49523
+ throw new Error(
49524
+ `No Solana key is enabled in ${paths.keystore}. Run vapi accounts --enable solana first.`
49525
+ );
49526
+ }
49527
+ const selected = solana && keys.solana ? keys.solana : keys.evm;
49528
+ const result = {
49529
+ network,
49530
+ address: selected.address,
49531
+ privateKey: "secretKey" in selected ? selected.secretKey : selected.privateKey
49532
+ };
49533
+ io.stderr(EXPORT_KEY_WARNING);
49534
+ io.stdout(json2 ? JSON.stringify(result) : result.privateKey);
49535
+ }
49374
49536
  async function mcpCommand(argv) {
49375
49537
  requireNoArguments(argv, "mcp");
49376
49538
  const paths = getVapiPaths();
@@ -49384,6 +49546,9 @@ async function mcpCommand(argv) {
49384
49546
  searchesPath: paths.searches
49385
49547
  });
49386
49548
  }
49549
+ async function readConfig(path, io) {
49550
+ return await loadConfig(path, process.env, { notice: io.stderr });
49551
+ }
49387
49552
  function output2(io, json2, value, human) {
49388
49553
  io.stdout(json2 ? JSON.stringify(value) : human);
49389
49554
  }
@@ -49449,16 +49614,14 @@ function formatNextStep(label, value, note) {
49449
49614
  const step = `${label.padEnd(10)}${value}`;
49450
49615
  return note === void 0 ? step : `${step.padEnd(52)} ${note}`;
49451
49616
  }
49452
- async function showBanner(io) {
49453
- const write = io.write;
49454
- if (write === void 0 || !shouldAnimateMark()) {
49455
- io.stdout(staticBanner());
49456
- return;
49457
- }
49458
- await animateBanner({ version: CLI_VERSION, write });
49459
- }
49460
- function staticBanner() {
49461
- return renderBanner({ version: CLI_VERSION, color: markColorEnabled() });
49617
+ function showBanner(io) {
49618
+ io.stdout(
49619
+ renderBanner({
49620
+ version: CLI_VERSION,
49621
+ colorLevel: detectColorLevel(),
49622
+ columns: process.stdout.columns
49623
+ })
49624
+ );
49462
49625
  }
49463
49626
  function formatAccounts(accounts) {
49464
49627
  if (accounts.length === 0) return "No configured network accounts.";