@vapi-network/core 0.15.1 → 0.16.0

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.
Files changed (77) hide show
  1. package/README.md +6 -2
  2. package/dist/agent-link.js +73 -7
  3. package/dist/agent-link.js.map +1 -1
  4. package/dist/atomic-file.d.ts +1 -0
  5. package/dist/atomic-file.d.ts.map +1 -1
  6. package/dist/backup.js +6 -4
  7. package/dist/backup.js.map +1 -1
  8. package/dist/cloud-backup.js +79 -11
  9. package/dist/cloud-backup.js.map +2 -2
  10. package/dist/index.js +126 -16
  11. package/dist/index.js.map +2 -2
  12. package/dist/net-guard.d.ts +17 -0
  13. package/dist/net-guard.d.ts.map +1 -1
  14. package/dist/router-client.js +110 -16
  15. package/dist/router-client.js.map +2 -2
  16. package/dist/secrets.js +19 -8
  17. package/dist/secrets.js.map +1 -1
  18. package/dist/support-report.d.ts +1 -1
  19. package/dist/tasks/actions.d.ts +1 -0
  20. package/dist/tasks/actions.d.ts.map +1 -1
  21. package/dist/tasks/ballots.d.ts +43 -0
  22. package/dist/tasks/ballots.d.ts.map +1 -0
  23. package/dist/tasks/chain-port.d.ts +26 -0
  24. package/dist/tasks/chain-port.d.ts.map +1 -1
  25. package/dist/tasks/chain.d.ts +5 -0
  26. package/dist/tasks/chain.d.ts.map +1 -1
  27. package/dist/tasks/client.d.ts +33 -3
  28. package/dist/tasks/client.d.ts.map +1 -1
  29. package/dist/tasks/funding-attempts.d.ts +58 -0
  30. package/dist/tasks/funding-attempts.d.ts.map +1 -0
  31. package/dist/tasks/funding-intent.d.ts +11 -0
  32. package/dist/tasks/funding-intent.d.ts.map +1 -0
  33. package/dist/tasks/index.d.ts +13 -2
  34. package/dist/tasks/index.d.ts.map +1 -1
  35. package/dist/tasks/money.d.ts +2 -0
  36. package/dist/tasks/money.d.ts.map +1 -1
  37. package/dist/tasks/operation-support.d.ts +10 -2
  38. package/dist/tasks/operation-support.d.ts.map +1 -1
  39. package/dist/tasks/operations.d.ts +651 -13
  40. package/dist/tasks/operations.d.ts.map +1 -1
  41. package/dist/tasks/pending-transactions.d.ts +11 -0
  42. package/dist/tasks/pending-transactions.d.ts.map +1 -1
  43. package/dist/tasks/post-options.d.ts +144 -0
  44. package/dist/tasks/post-options.d.ts.map +1 -0
  45. package/dist/tasks/types.d.ts +5505 -74
  46. package/dist/tasks/types.d.ts.map +1 -1
  47. package/dist/tasks/v2-abi.d.ts +12 -0
  48. package/dist/tasks/v2-abi.d.ts.map +1 -0
  49. package/dist/tasks/v2-abi.generated.d.ts +5966 -0
  50. package/dist/tasks/v2-abi.generated.d.ts.map +1 -0
  51. package/dist/tasks/v2-events.d.ts +6460 -0
  52. package/dist/tasks/v2-events.d.ts.map +1 -0
  53. package/dist/tasks/v2-execution.d.ts +1070 -0
  54. package/dist/tasks/v2-execution.d.ts.map +1 -0
  55. package/dist/tasks/v2-jury.d.ts +863 -0
  56. package/dist/tasks/v2-jury.d.ts.map +1 -0
  57. package/dist/tasks/v2-plan-guard.d.ts +100 -0
  58. package/dist/tasks/v2-plan-guard.d.ts.map +1 -0
  59. package/dist/tasks/v2-public.d.ts +154 -0
  60. package/dist/tasks/v2-public.d.ts.map +1 -0
  61. package/dist/tasks/v2-trust.d.ts +27 -0
  62. package/dist/tasks/v2-trust.d.ts.map +1 -0
  63. package/dist/tasks/v2-write.d.ts +886 -0
  64. package/dist/tasks/v2-write.d.ts.map +1 -0
  65. package/dist/tasks/v2.d.ts +847 -0
  66. package/dist/tasks/v2.d.ts.map +1 -0
  67. package/dist/tasks/verbs.d.ts +1 -1
  68. package/dist/tasks/verbs.d.ts.map +1 -1
  69. package/dist/tasks/x402-funding.d.ts +49 -0
  70. package/dist/tasks/x402-funding.d.ts.map +1 -0
  71. package/dist/tasks.js +17541 -4184
  72. package/dist/tasks.js.map +3 -3
  73. package/dist/x402-pay.d.ts +11 -1
  74. package/dist/x402-pay.d.ts.map +1 -1
  75. package/dist/x402.d.ts +6 -0
  76. package/dist/x402.d.ts.map +1 -1
  77. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -43375,7 +43375,7 @@ async function assertPublicUrl(url2, options) {
43375
43375
  options.timeoutMs ?? 5e3
43376
43376
  );
43377
43377
  } catch {
43378
- throw guardError(url2);
43378
+ throw guardError(url2, "unresolved");
43379
43379
  }
43380
43380
  if (addresses.length === 0 || addresses.some(isNonPublicAddress)) {
43381
43381
  throw guardError(url2);
@@ -43530,10 +43530,67 @@ function isNonPublicIpv6(hextets) {
43530
43530
  const isDocumentation = first === 8193 && hextets[1] === 3512;
43531
43531
  return isUnspecified || isLoopback || isUniqueLocal || isLinkLocal || isSiteLocal || isMulticast || isDocumentation;
43532
43532
  }
43533
- function guardError(url2) {
43534
- return new Error(
43535
- `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`
43533
+ var NetworkGuardError = class extends Error {
43534
+ constructor(message, reason) {
43535
+ super(message);
43536
+ this.reason = reason;
43537
+ this.name = "NetworkGuardError";
43538
+ }
43539
+ reason;
43540
+ };
43541
+ function guardError(url2, reason = "blocked") {
43542
+ return new NetworkGuardError(
43543
+ `URL hostname ${JSON.stringify(url2.hostname)} is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.`,
43544
+ reason
43545
+ );
43546
+ }
43547
+ var PROXY_VARIABLES = {
43548
+ "https:": ["HTTPS_PROXY", "https_proxy"],
43549
+ "http:": ["HTTP_PROXY", "http_proxy"]
43550
+ };
43551
+ var SYSTEM_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,39}$/u;
43552
+ function describeNetworkFailure(error61, url2, env = process.env) {
43553
+ const host = url2.host;
43554
+ let reason;
43555
+ const guard = guardReason(error61);
43556
+ if (guard !== void 0) {
43557
+ reason = guard === "unresolved" ? `the DNS lookup for ${host} failed` : `${host} is not a public address`;
43558
+ } else if (isTimeout(error61)) {
43559
+ reason = `the connection to ${host} timed out`;
43560
+ } else {
43561
+ const code = systemErrorCode(error61);
43562
+ reason = `could not connect to ${host}${code === void 0 ? "" : ` (${code})`}`;
43563
+ }
43564
+ const proxy = (PROXY_VARIABLES[url2.protocol] ?? []).find(
43565
+ (name) => (env[name] ?? "").trim() !== ""
43536
43566
  );
43567
+ let hint = "";
43568
+ if (proxy !== void 0) {
43569
+ if (env.NODE_USE_ENV_PROXY !== "1") {
43570
+ hint = ` ${proxy} is set, but Node.js uses it only with NODE_USE_ENV_PROXY=1 (Node.js 22.21 or later): run the command again with NODE_USE_ENV_PROXY=1.`;
43571
+ } else if (guard === "unresolved") {
43572
+ hint = ` vapi looks ${host} up on this machine before it uses the proxy in ${proxy}, so the name must resolve here too.`;
43573
+ } else if (guard === void 0) {
43574
+ hint = ` NODE_USE_ENV_PROXY=1 and ${proxy} are set, so the proxy may have refused the connection.`;
43575
+ }
43576
+ }
43577
+ return `${reason}.${hint}`;
43578
+ }
43579
+ function guardReason(error61) {
43580
+ if (!(error61 instanceof Error) || error61.name !== "NetworkGuardError") return void 0;
43581
+ const reason = error61.reason;
43582
+ return reason === "blocked" || reason === "unresolved" ? reason : void 0;
43583
+ }
43584
+ function isTimeout(error61) {
43585
+ return error61 instanceof Error && (error61.name === "TimeoutError" || error61.name === "AbortError");
43586
+ }
43587
+ function systemErrorCode(error61) {
43588
+ for (let current = error61, depth = 0; current instanceof Error && depth < 3; depth += 1) {
43589
+ const code = current.code;
43590
+ if (typeof code === "string" && SYSTEM_ERROR_CODE.test(code)) return code;
43591
+ current = current.cause;
43592
+ }
43593
+ return void 0;
43537
43594
  }
43538
43595
 
43539
43596
  // src/networks.ts
@@ -45637,6 +45694,7 @@ async function buildX402Payment(args) {
45637
45694
  nowSeconds: args.nowSeconds ?? Math.floor(Date.now() / 1e3),
45638
45695
  ...args.maximumValidBeforeSeconds === void 0 ? {} : { maximumValidBeforeSeconds: args.maximumValidBeforeSeconds }
45639
45696
  });
45697
+ await args.beforeSignTypedData?.(typedData);
45640
45698
  await args.beforeSign?.({
45641
45699
  network: args.quote.accepted.network,
45642
45700
  token: args.quote.accepted.asset,
@@ -45644,6 +45702,7 @@ async function buildX402Payment(args) {
45644
45702
  authorization
45645
45703
  });
45646
45704
  const signature = await args.signer.signTypedData(typedData);
45705
+ args.onSigned?.();
45647
45706
  const payload = {
45648
45707
  x402Version: 2,
45649
45708
  resource: args.quote.resource,
@@ -45663,6 +45722,8 @@ async function buildCompatibleX402Payment(args) {
45663
45722
  const payment = await buildX402Payment({
45664
45723
  signer: args.account,
45665
45724
  quote: args.quote,
45725
+ ...args.beforeSignTypedData ? { beforeSignTypedData: args.beforeSignTypedData } : {},
45726
+ ...args.onSigned ? { onSigned: args.onSigned } : {},
45666
45727
  ...args.nowSeconds === void 0 ? {} : { nowSeconds: args.nowSeconds },
45667
45728
  ...args.maximumValidBeforeSeconds === void 0 ? {} : { maximumValidBeforeSeconds: args.maximumValidBeforeSeconds },
45668
45729
  ...args.nonce === void 0 ? {} : { nonce: args.nonce },
@@ -46668,12 +46729,12 @@ async function removeStaleLock(path) {
46668
46729
  const pid = lockOwnerPid(owner);
46669
46730
  if (pid !== void 0 && processIsAlive(pid)) return;
46670
46731
  await atomicFileTestHooks?.beforeStaleLockBreak?.(path);
46671
- await removeOwnedLock(path, [owner]);
46732
+ await removeOwnedLock(path, [owner], true);
46672
46733
  } catch (error61) {
46673
46734
  if (!hasCode(error61, "ENOENT")) throw error61;
46674
46735
  }
46675
46736
  }
46676
- async function removeOwnedLock(path, owners) {
46737
+ async function removeOwnedLock(path, owners, staleDeadOwner = false) {
46677
46738
  const tombPath = `${path}.stale.${randomBytes2(16).toString("hex")}`;
46678
46739
  try {
46679
46740
  await rename(path, tombPath);
@@ -46682,7 +46743,7 @@ async function removeOwnedLock(path, owners) {
46682
46743
  await removeOwnedTombs(path, owners);
46683
46744
  const currentOwner = await readFile(path, "utf8").catch(() => void 0);
46684
46745
  if (currentOwner !== void 0 && owners.includes(currentOwner)) {
46685
- await removeOwnedLock(path, owners);
46746
+ await removeOwnedLock(path, owners, staleDeadOwner);
46686
46747
  }
46687
46748
  return;
46688
46749
  }
@@ -46691,6 +46752,7 @@ async function removeOwnedLock(path, owners) {
46691
46752
  let pendingError;
46692
46753
  let renamedOwner;
46693
46754
  try {
46755
+ await atomicFileTestHooks?.afterLockRename?.(tombPath);
46694
46756
  renamedOwner = await readFile(tombPath, "utf8");
46695
46757
  if (!owners.includes(renamedOwner) && !lockOwnerReleased(renamedOwner)) {
46696
46758
  await atomicFileTestHooks?.afterMismatchedLockRename?.(path);
@@ -46699,6 +46761,7 @@ async function removeOwnedLock(path, owners) {
46699
46761
  await atomicFileTestHooks?.afterMismatchedLockRestore?.(path);
46700
46762
  }
46701
46763
  } catch (error61) {
46764
+ if (hasCode(error61, "ENOENT")) return;
46702
46765
  pendingError = error61;
46703
46766
  }
46704
46767
  try {
@@ -46707,7 +46770,7 @@ async function removeOwnedLock(path, owners) {
46707
46770
  } catch (error61) {
46708
46771
  if (!tombUnlinkTolerated(
46709
46772
  error61,
46710
- renamedOwner !== void 0 && lockOwnerReleased(renamedOwner) && owners.includes(renamedOwner)
46773
+ renamedOwner !== void 0 && (lockOwnerReleased(renamedOwner) || staleDeadOwner) && owners.includes(renamedOwner)
46711
46774
  ) && pendingError === void 0) {
46712
46775
  pendingError = error61;
46713
46776
  }
@@ -47939,16 +48002,25 @@ function withBearer(init, accessToken) {
47939
48002
  async function safeFetch(fetchImpl, input2, init) {
47940
48003
  try {
47941
48004
  return await fetchImpl(input2, init);
47942
- } catch {
47943
- throw httpError("The vAPI agent link request failed.");
48005
+ } catch (error61) {
48006
+ throw httpError(`The vAPI agent link request failed: ${networkFailure(error61, input2)}`);
47944
48007
  }
47945
48008
  }
47946
48009
  async function safeAgentFetch(fetchImpl, input2, init) {
47947
48010
  try {
47948
48011
  return await fetchImpl(input2, init);
48012
+ } catch (error61) {
48013
+ throw httpError(`The vAPI agent request failed: ${networkFailure(error61, input2)}`);
48014
+ }
48015
+ }
48016
+ function networkFailure(error61, input2) {
48017
+ let url2;
48018
+ try {
48019
+ url2 = new URL(input2 instanceof Request ? input2.url : input2);
47949
48020
  } catch {
47950
- throw httpError("The vAPI agent request failed.");
48021
+ return "the request did not reach vAPI.";
47951
48022
  }
48023
+ return describeNetworkFailure(error61, url2);
47952
48024
  }
47953
48025
  function deviceAuthorizationError(status, payload) {
47954
48026
  const error61 = stringField(payload, "error");
@@ -77990,7 +78062,7 @@ function createRunBudget(args) {
77990
78062
  import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
77991
78063
  import { arch, platform, release } from "node:os";
77992
78064
  import { join as join14 } from "node:path";
77993
- var VAPI_CLIENT_VERSION = "0.15.1";
78065
+ var VAPI_CLIENT_VERSION = "0.16.0";
77994
78066
  async function createSupportReport(options) {
77995
78067
  const message = options.message.trim();
77996
78068
  if (!message) throw new Error("Support report message must not be empty.");
@@ -78258,13 +78330,23 @@ async function completeX402Payment(args) {
78258
78330
  const spendReservation = {
78259
78331
  ledgerPath: args.ledgerPath ?? getVapiPaths().ledger,
78260
78332
  now: args.now,
78261
- ...args.wallet === void 0 ? {} : { wallet: args.wallet }
78333
+ ...args.wallet === void 0 ? {} : { wallet: args.wallet },
78334
+ ...args.taskFunding === void 0 ? {} : {
78335
+ kind: "escrow-funding",
78336
+ taskKey: args.taskFunding.taskKey,
78337
+ maxPerTaskAtomic: args.taskFunding.maxPerTaskAtomic
78338
+ }
78262
78339
  };
78263
78340
  let reservationId;
78264
78341
  let reservedOn;
78265
78342
  if (args.runBudget === void 0) {
78266
78343
  try {
78267
- await reserveSpend(quote.amountAtomic, args.caps, spendReservation);
78344
+ if (args.taskFunding) reservationId = args.paymentId ?? randomUUID2();
78345
+ const reservation = await reserveSpend(quote.amountAtomic, args.caps, {
78346
+ ...spendReservation,
78347
+ ...reservationId ? { reservationId } : {}
78348
+ });
78349
+ reservedOn = reservation.date;
78268
78350
  } catch (error61) {
78269
78351
  throw walletCapError(error61, quote.amountAtomic, args);
78270
78352
  }
@@ -78304,10 +78386,19 @@ async function completeX402Payment(args) {
78304
78386
  }
78305
78387
  const signStarted = nowMs();
78306
78388
  let payment;
78389
+ let authorizationProduced = false;
78307
78390
  try {
78308
78391
  payment = await buildCompatibleX402Payment({
78309
78392
  account: args.account,
78310
78393
  quote,
78394
+ ...args.taskFunding ? {
78395
+ beforeSignTypedData: async (data) => {
78396
+ await args.taskFunding?.beforeSign?.(data, { id: reservationId, date: reservedOn });
78397
+ },
78398
+ onSigned: () => {
78399
+ authorizationProduced = true;
78400
+ }
78401
+ } : {},
78311
78402
  ...args.beforeSign === void 0 ? {} : { beforeSign: args.beforeSign },
78312
78403
  fetchImpl: args.fetchImpl ?? createPublicFetch({
78313
78404
  allowPrivateNetwork: args.config.allowPrivateNetwork ?? false
@@ -78326,14 +78417,17 @@ async function completeX402Payment(args) {
78326
78417
  }
78327
78418
  }
78328
78419
  } catch (error61) {
78329
- if (args.runBudget !== void 0 && reservationId !== void 0 && reservedOn !== void 0) {
78420
+ if ((args.runBudget !== void 0 || args.taskFunding !== void 0) && !authorizationProduced && reservationId !== void 0 && reservedOn !== void 0) {
78330
78421
  const released = await releaseUnsentReservation(
78331
78422
  args,
78332
78423
  quote.amountAtomic,
78333
78424
  reservationId,
78334
78425
  reservedOn
78335
78426
  );
78336
- if (released) args.runBudget.release(reservationId);
78427
+ if (released) {
78428
+ args.runBudget?.release(reservationId);
78429
+ await args.taskFunding?.onUnsent?.();
78430
+ }
78337
78431
  }
78338
78432
  throw error61;
78339
78433
  } finally {
@@ -79785,9 +79879,14 @@ async function prepareDeliveryManifest(files, note) {
79785
79879
  var TASKS_CLIENT_VERBS = [
79786
79880
  "search",
79787
79881
  "show",
79882
+ "pending",
79883
+ "checkin",
79788
79884
  "post",
79789
79885
  "propose",
79790
79886
  "submit",
79887
+ "milestone",
79888
+ "cancel",
79889
+ "claim",
79791
79890
  "award",
79792
79891
  "sign",
79793
79892
  "fund",
@@ -79797,6 +79896,15 @@ var TASKS_CLIENT_VERBS = [
79797
79896
  "dispute",
79798
79897
  "counter-evidence",
79799
79898
  "resolve-unmatched",
79899
+ "close-rejected",
79900
+ "bump-consent-nonce",
79901
+ "prune-reviewer",
79902
+ "prune-reviewers",
79903
+ "jury",
79904
+ "vote",
79905
+ "approve-bond",
79906
+ "claim-owed",
79907
+ "reviewer-status",
79800
79908
  "message",
79801
79909
  "thread",
79802
79910
  "watch",
@@ -83400,6 +83508,7 @@ export {
83400
83508
  NATIVE_ETH_FEE_MARGIN_PERCENT,
83401
83509
  NATIVE_ETH_L1_FEE_FALLBACK_WEI,
83402
83510
  NETWORKS,
83511
+ NetworkGuardError,
83403
83512
  ONRAMP_FALLBACK_INSTRUCTIONS,
83404
83513
  ONRAMP_NETWORK,
83405
83514
  PASSPHRASE_ENVIRONMENT_VARIABLE,
@@ -83506,6 +83615,7 @@ export {
83506
83615
  deleteSwarmFile,
83507
83616
  deriveEvmPrivateKey,
83508
83617
  deriveSolanaPrivateKey,
83618
+ describeNetworkFailure,
83509
83619
  deviceName,
83510
83620
  discardBody,
83511
83621
  discover,