@agirails/sdk 2.2.3 → 2.3.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.
Files changed (211) hide show
  1. package/README.md +65 -31
  2. package/dist/ACTPClient.d.ts +42 -1
  3. package/dist/ACTPClient.d.ts.map +1 -1
  4. package/dist/ACTPClient.js +207 -22
  5. package/dist/ACTPClient.js.map +1 -1
  6. package/dist/abi/AgentRegistry.json +133 -0
  7. package/dist/adapters/AdapterRouter.d.ts.map +1 -1
  8. package/dist/adapters/AdapterRouter.js.map +1 -1
  9. package/dist/adapters/BasicAdapter.d.ts +10 -1
  10. package/dist/adapters/BasicAdapter.d.ts.map +1 -1
  11. package/dist/adapters/BasicAdapter.js +36 -1
  12. package/dist/adapters/BasicAdapter.js.map +1 -1
  13. package/dist/adapters/X402Adapter.d.ts +34 -7
  14. package/dist/adapters/X402Adapter.d.ts.map +1 -1
  15. package/dist/adapters/X402Adapter.js +36 -8
  16. package/dist/adapters/X402Adapter.js.map +1 -1
  17. package/dist/adapters/index.d.ts +1 -1
  18. package/dist/adapters/index.d.ts.map +1 -1
  19. package/dist/adapters/index.js.map +1 -1
  20. package/dist/cli/commands/diff.d.ts +11 -0
  21. package/dist/cli/commands/diff.d.ts.map +1 -0
  22. package/dist/cli/commands/diff.js +115 -0
  23. package/dist/cli/commands/diff.js.map +1 -0
  24. package/dist/cli/commands/init.d.ts +1 -0
  25. package/dist/cli/commands/init.d.ts.map +1 -1
  26. package/dist/cli/commands/init.js +260 -19
  27. package/dist/cli/commands/init.js.map +1 -1
  28. package/dist/cli/commands/publish.d.ts +11 -0
  29. package/dist/cli/commands/publish.d.ts.map +1 -0
  30. package/dist/cli/commands/publish.js +170 -0
  31. package/dist/cli/commands/publish.js.map +1 -0
  32. package/dist/cli/commands/pull.d.ts +12 -0
  33. package/dist/cli/commands/pull.d.ts.map +1 -0
  34. package/dist/cli/commands/pull.js +99 -0
  35. package/dist/cli/commands/pull.js.map +1 -0
  36. package/dist/cli/commands/register.d.ts +16 -0
  37. package/dist/cli/commands/register.d.ts.map +1 -0
  38. package/dist/cli/commands/register.js +211 -0
  39. package/dist/cli/commands/register.js.map +1 -0
  40. package/dist/cli/index.js +10 -0
  41. package/dist/cli/index.js.map +1 -1
  42. package/dist/cli/utils/config.d.ts +6 -0
  43. package/dist/cli/utils/config.d.ts.map +1 -1
  44. package/dist/cli/utils/config.js.map +1 -1
  45. package/dist/config/agirailsmd.d.ts +94 -0
  46. package/dist/config/agirailsmd.d.ts.map +1 -0
  47. package/dist/config/agirailsmd.js +209 -0
  48. package/dist/config/agirailsmd.js.map +1 -0
  49. package/dist/config/networks.d.ts +22 -4
  50. package/dist/config/networks.d.ts.map +1 -1
  51. package/dist/config/networks.js +64 -26
  52. package/dist/config/networks.js.map +1 -1
  53. package/dist/config/publishPipeline.d.ts +75 -0
  54. package/dist/config/publishPipeline.d.ts.map +1 -0
  55. package/dist/config/publishPipeline.js +193 -0
  56. package/dist/config/publishPipeline.js.map +1 -0
  57. package/dist/config/syncOperations.d.ts +67 -0
  58. package/dist/config/syncOperations.d.ts.map +1 -0
  59. package/dist/config/syncOperations.js +208 -0
  60. package/dist/config/syncOperations.js.map +1 -0
  61. package/dist/erc8004/ERC8004Bridge.d.ts.map +1 -1
  62. package/dist/erc8004/ERC8004Bridge.js +6 -5
  63. package/dist/erc8004/ERC8004Bridge.js.map +1 -1
  64. package/dist/erc8004/ReputationReporter.d.ts.map +1 -1
  65. package/dist/erc8004/ReputationReporter.js +9 -12
  66. package/dist/erc8004/ReputationReporter.js.map +1 -1
  67. package/dist/index.d.ts +5 -0
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +11 -3
  70. package/dist/index.js.map +1 -1
  71. package/dist/level0/request.d.ts.map +1 -1
  72. package/dist/level0/request.js +23 -86
  73. package/dist/level0/request.js.map +1 -1
  74. package/dist/level1/Agent.d.ts +0 -11
  75. package/dist/level1/Agent.d.ts.map +1 -1
  76. package/dist/level1/Agent.js +19 -36
  77. package/dist/level1/Agent.js.map +1 -1
  78. package/dist/protocol/ACTPKernel.d.ts +7 -1
  79. package/dist/protocol/ACTPKernel.d.ts.map +1 -1
  80. package/dist/protocol/ACTPKernel.js +13 -10
  81. package/dist/protocol/ACTPKernel.js.map +1 -1
  82. package/dist/protocol/EventMonitor.d.ts +14 -0
  83. package/dist/protocol/EventMonitor.d.ts.map +1 -1
  84. package/dist/protocol/EventMonitor.js +14 -0
  85. package/dist/protocol/EventMonitor.js.map +1 -1
  86. package/dist/registry/AgentRegistryClient.d.ts +75 -0
  87. package/dist/registry/AgentRegistryClient.d.ts.map +1 -0
  88. package/dist/registry/AgentRegistryClient.js +160 -0
  89. package/dist/registry/AgentRegistryClient.js.map +1 -0
  90. package/dist/runtime/BlockchainRuntime.d.ts +5 -0
  91. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  92. package/dist/runtime/BlockchainRuntime.js +1 -1
  93. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  94. package/dist/storage/ArchiveBundleBuilder.d.ts.map +1 -1
  95. package/dist/storage/ArchiveBundleBuilder.js.map +1 -1
  96. package/dist/storage/ArweaveClient.d.ts.map +1 -1
  97. package/dist/storage/ArweaveClient.js +2 -0
  98. package/dist/storage/ArweaveClient.js.map +1 -1
  99. package/dist/storage/FilebaseClient.d.ts.map +1 -1
  100. package/dist/storage/FilebaseClient.js +2 -0
  101. package/dist/storage/FilebaseClient.js.map +1 -1
  102. package/dist/types/adapter.d.ts +39 -0
  103. package/dist/types/adapter.d.ts.map +1 -1
  104. package/dist/types/adapter.js +7 -0
  105. package/dist/types/adapter.js.map +1 -1
  106. package/dist/types/x402.d.ts +23 -0
  107. package/dist/types/x402.d.ts.map +1 -1
  108. package/dist/types/x402.js.map +1 -1
  109. package/dist/utils/ErrorRecoveryGuide.d.ts.map +1 -1
  110. package/dist/utils/ErrorRecoveryGuide.js +3 -2
  111. package/dist/utils/ErrorRecoveryGuide.js.map +1 -1
  112. package/dist/utils/IPFSClient.d.ts +3 -2
  113. package/dist/utils/IPFSClient.d.ts.map +1 -1
  114. package/dist/utils/IPFSClient.js +7 -5
  115. package/dist/utils/IPFSClient.js.map +1 -1
  116. package/dist/utils/computeTypeHash.js +1 -3
  117. package/dist/utils/computeTypeHash.js.map +1 -1
  118. package/dist/utils/retry.d.ts.map +1 -1
  119. package/dist/utils/retry.js +0 -1
  120. package/dist/utils/retry.js.map +1 -1
  121. package/dist/utils/validation.d.ts +2 -2
  122. package/dist/utils/validation.d.ts.map +1 -1
  123. package/dist/utils/validation.js +2 -2
  124. package/dist/utils/validation.js.map +1 -1
  125. package/dist/wallet/AutoWalletProvider.d.ts +77 -0
  126. package/dist/wallet/AutoWalletProvider.d.ts.map +1 -0
  127. package/dist/wallet/AutoWalletProvider.js +197 -0
  128. package/dist/wallet/AutoWalletProvider.js.map +1 -0
  129. package/dist/wallet/EOAWalletProvider.d.ts +21 -0
  130. package/dist/wallet/EOAWalletProvider.d.ts.map +1 -0
  131. package/dist/wallet/EOAWalletProvider.js +57 -0
  132. package/dist/wallet/EOAWalletProvider.js.map +1 -0
  133. package/dist/wallet/IWalletProvider.d.ts +115 -0
  134. package/dist/wallet/IWalletProvider.d.ts.map +1 -0
  135. package/dist/wallet/IWalletProvider.js +12 -0
  136. package/dist/wallet/IWalletProvider.js.map +1 -0
  137. package/dist/wallet/aa/BundlerClient.d.ts +70 -0
  138. package/dist/wallet/aa/BundlerClient.d.ts.map +1 -0
  139. package/dist/wallet/aa/BundlerClient.js +183 -0
  140. package/dist/wallet/aa/BundlerClient.js.map +1 -0
  141. package/dist/wallet/aa/DualNonceManager.d.ts +55 -0
  142. package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -0
  143. package/dist/wallet/aa/DualNonceManager.js +131 -0
  144. package/dist/wallet/aa/DualNonceManager.js.map +1 -0
  145. package/dist/wallet/aa/PaymasterClient.d.ts +52 -0
  146. package/dist/wallet/aa/PaymasterClient.d.ts.map +1 -0
  147. package/dist/wallet/aa/PaymasterClient.js +115 -0
  148. package/dist/wallet/aa/PaymasterClient.js.map +1 -0
  149. package/dist/wallet/aa/TransactionBatcher.d.ts +87 -0
  150. package/dist/wallet/aa/TransactionBatcher.d.ts.map +1 -0
  151. package/dist/wallet/aa/TransactionBatcher.js +148 -0
  152. package/dist/wallet/aa/TransactionBatcher.js.map +1 -0
  153. package/dist/wallet/aa/UserOpBuilder.d.ts +71 -0
  154. package/dist/wallet/aa/UserOpBuilder.d.ts.map +1 -0
  155. package/dist/wallet/aa/UserOpBuilder.js +196 -0
  156. package/dist/wallet/aa/UserOpBuilder.js.map +1 -0
  157. package/dist/wallet/aa/constants.d.ts +54 -0
  158. package/dist/wallet/aa/constants.d.ts.map +1 -0
  159. package/dist/wallet/aa/constants.js +18 -0
  160. package/dist/wallet/aa/constants.js.map +1 -0
  161. package/dist/wallet/keystore.d.ts +16 -0
  162. package/dist/wallet/keystore.d.ts.map +1 -0
  163. package/dist/wallet/keystore.js +132 -0
  164. package/dist/wallet/keystore.js.map +1 -0
  165. package/package.json +5 -2
  166. package/src/ACTPClient.ts +275 -27
  167. package/src/abi/AgentRegistry.json +133 -0
  168. package/src/adapters/AdapterRouter.ts +0 -1
  169. package/src/adapters/BasicAdapter.ts +41 -1
  170. package/src/adapters/X402Adapter.ts +94 -16
  171. package/src/adapters/index.ts +9 -1
  172. package/src/cli/commands/diff.ts +141 -0
  173. package/src/cli/commands/init.ts +311 -22
  174. package/src/cli/commands/publish.ts +208 -0
  175. package/src/cli/commands/pull.ts +124 -0
  176. package/src/cli/commands/register.ts +233 -0
  177. package/src/cli/index.ts +12 -0
  178. package/src/cli/utils/config.ts +9 -0
  179. package/src/config/agirailsmd.ts +262 -0
  180. package/src/config/networks.ts +89 -26
  181. package/src/config/publishPipeline.ts +276 -0
  182. package/src/config/syncOperations.ts +279 -0
  183. package/src/erc8004/ERC8004Bridge.ts +6 -5
  184. package/src/erc8004/ReputationReporter.ts +14 -18
  185. package/src/index.ts +15 -0
  186. package/src/level0/request.ts +27 -88
  187. package/src/level1/Agent.ts +21 -37
  188. package/src/protocol/ACTPKernel.ts +20 -10
  189. package/src/protocol/EventMonitor.ts +14 -0
  190. package/src/registry/AgentRegistryClient.ts +202 -0
  191. package/src/runtime/BlockchainRuntime.ts +7 -1
  192. package/src/storage/ArchiveBundleBuilder.ts +0 -2
  193. package/src/storage/ArweaveClient.ts +2 -1
  194. package/src/storage/FilebaseClient.ts +3 -3
  195. package/src/types/adapter.ts +14 -0
  196. package/src/types/x402.ts +32 -0
  197. package/src/utils/ErrorRecoveryGuide.ts +4 -2
  198. package/src/utils/IPFSClient.ts +9 -7
  199. package/src/utils/computeTypeHash.ts +1 -3
  200. package/src/utils/retry.ts +0 -1
  201. package/src/utils/validation.ts +2 -2
  202. package/src/wallet/AutoWalletProvider.ts +294 -0
  203. package/src/wallet/EOAWalletProvider.ts +69 -0
  204. package/src/wallet/IWalletProvider.ts +133 -0
  205. package/src/wallet/aa/BundlerClient.ts +273 -0
  206. package/src/wallet/aa/DualNonceManager.ts +163 -0
  207. package/src/wallet/aa/PaymasterClient.ts +173 -0
  208. package/src/wallet/aa/TransactionBatcher.ts +240 -0
  209. package/src/wallet/aa/UserOpBuilder.ts +246 -0
  210. package/src/wallet/aa/constants.ts +60 -0
  211. package/src/wallet/keystore.ts +119 -0
@@ -22,6 +22,8 @@ import {
22
22
  UnifiedPayParams,
23
23
  UnifiedPayResult,
24
24
  } from '../types/adapter';
25
+ import { IWalletProvider } from '../wallet/IWalletProvider';
26
+ import { ethers } from 'ethers';
25
27
 
26
28
  /**
27
29
  * Parameters for creating a simple payment.
@@ -116,11 +118,15 @@ export class BasicAdapter extends BaseAdapter implements IAdapter {
116
118
  * @param runtime - ACTP runtime implementation (MockRuntime or BlockchainRuntime)
117
119
  * @param requesterAddress - The requester's Ethereum address
118
120
  * @param easHelper - Optional EAS helper for attestation verification (SECURITY FIX C-4)
121
+ * @param walletProvider - Optional wallet provider for AA batched payments
122
+ * @param contractAddresses - Optional contract addresses for batched payment encoding
119
123
  */
120
124
  constructor(
121
125
  private runtime: IACTPRuntime,
122
126
  requesterAddress: string,
123
- private easHelper?: EASHelper
127
+ private easHelper?: EASHelper,
128
+ private walletProvider?: IWalletProvider,
129
+ private contractAddresses?: { usdc: string; actpKernel: string; escrowVault: string }
124
130
  ) {
125
131
  super(requesterAddress);
126
132
  }
@@ -187,6 +193,40 @@ export class BasicAdapter extends BaseAdapter implements IAdapter {
187
193
  );
188
194
  }
189
195
 
196
+ // ====================================================================
197
+ // AIP-12: Batched payment via AA wallet (1 UserOp = 3 on-chain calls)
198
+ // ====================================================================
199
+ if (this.walletProvider?.payACTPBatched && this.contractAddresses) {
200
+ const serviceHash = ethers.ZeroHash;
201
+ const result = await this.walletProvider.payACTPBatched({
202
+ provider,
203
+ requester,
204
+ amount: amount.toString(),
205
+ deadline,
206
+ disputeWindow,
207
+ serviceHash,
208
+ agentId: agentId || '0',
209
+ contracts: this.contractAddresses,
210
+ });
211
+
212
+ if (!result.success) {
213
+ throw new Error(`Batched payment UserOp failed: ${result.hash}`);
214
+ }
215
+
216
+ return {
217
+ txId: result.txId,
218
+ provider,
219
+ requester,
220
+ amount: this.formatAmount(amount),
221
+ deadline: new Date(deadline * 1000).toISOString(),
222
+ state: 'COMMITTED',
223
+ };
224
+ }
225
+
226
+ // ====================================================================
227
+ // Legacy flow: sequential on-chain calls (EOA / mock)
228
+ // ====================================================================
229
+
190
230
  // Create transaction
191
231
  const txId = await this.runtime.createTransaction({
192
232
  provider,
@@ -35,6 +35,7 @@ import {
35
35
  X402Error,
36
36
  X402ErrorCode,
37
37
  X402Network,
38
+ X402FeeBreakdown,
38
39
  isValidX402Network,
39
40
  } from '../types/x402';
40
41
 
@@ -46,14 +47,33 @@ import {
46
47
  export type FetchFunction = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
47
48
 
48
49
  /**
49
- * Transfer function for atomic payments.
50
- *
50
+ * Transfer function for atomic payments (legacy direct transfer).
51
+ *
51
52
  * @param to - Recipient address
52
53
  * @param amount - Amount in USDC wei (string)
53
54
  * @returns Transaction hash as proof
54
55
  */
55
56
  export type TransferFunction = (to: string, amount: string) => Promise<string>;
56
57
 
58
+ /**
59
+ * Approve function for USDC allowance (used with X402Relay).
60
+ *
61
+ * @param spender - Spender address (relay contract)
62
+ * @param amount - Amount in USDC wei (string)
63
+ * @returns Transaction hash
64
+ */
65
+ export type ApproveFunction = (spender: string, amount: string) => Promise<string>;
66
+
67
+ /**
68
+ * Relay pay function — calls X402Relay.payWithFee().
69
+ *
70
+ * @param provider - Provider address
71
+ * @param grossAmount - Gross USDC amount (string)
72
+ * @param serviceId - Service identifier (bytes32 hex)
73
+ * @returns Transaction hash
74
+ */
75
+ export type RelayPayFunction = (provider: string, grossAmount: string, serviceId: string) => Promise<string>;
76
+
57
77
  /** Supported HTTP methods for x402 requests */
58
78
  export type X402HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
59
79
 
@@ -76,12 +96,15 @@ export interface X402PayParams extends UnifiedPayParams {
76
96
 
77
97
  /**
78
98
  * Configuration options for X402Adapter.
99
+ *
100
+ * For fee-enabled payments via X402Relay, provide relayAddress + approveFn + relayPayFn.
101
+ * Without relay config, falls back to legacy direct transfer (no platform fee).
79
102
  */
80
103
  export interface X402AdapterConfig {
81
104
  /** Expected network for validation (must match server's X-Payment-Network) */
82
105
  expectedNetwork: X402Network;
83
106
 
84
- /** Transfer function for atomic payments (required) */
107
+ /** Transfer function for direct atomic payments (legacy fallback) */
85
108
  transferFn: TransferFunction;
86
109
 
87
110
  /** Request timeout in milliseconds (default: 30000) */
@@ -92,6 +115,20 @@ export interface X402AdapterConfig {
92
115
 
93
116
  /** Default headers to include in all requests */
94
117
  defaultHeaders?: Record<string, string>;
118
+
119
+ // --- X402Relay fee-splitting (optional, recommended) ---
120
+
121
+ /** X402Relay contract address for on-chain fee splitting */
122
+ relayAddress?: string;
123
+
124
+ /** USDC approve function — required when relayAddress is set */
125
+ approveFn?: ApproveFunction;
126
+
127
+ /** Relay payWithFee function — required when relayAddress is set */
128
+ relayPayFn?: RelayPayFunction;
129
+
130
+ /** Platform fee in basis points (default: 100 = 1%). Read-only display hint. */
131
+ platformFeeBps?: number;
95
132
  }
96
133
 
97
134
  /**
@@ -104,6 +141,7 @@ interface AtomicPaymentRecord {
104
141
  amount: string;
105
142
  timestamp: number;
106
143
  endpoint: string;
144
+ feeBreakdown?: X402FeeBreakdown;
107
145
  }
108
146
 
109
147
  // ============================================================================
@@ -287,15 +325,15 @@ export class X402Adapter extends BaseAdapter implements IAdapter {
287
325
  );
288
326
  }
289
327
 
290
- // Step 6: ATOMIC PAYMENT - direct transfer, no escrow
291
- const txHash = await this.executeAtomicPayment(paymentHeaders);
328
+ // Step 6: ATOMIC PAYMENT - via relay (with fee) or direct transfer (legacy)
329
+ const { txHash, feeBreakdown } = await this.executeAtomicPayment(paymentHeaders);
292
330
 
293
331
  // Step 7: Retry with proof (same method/headers/body + payment proof)
294
332
  const serviceResponse = await this.retryWithProof(
295
- endpoint,
296
- txHash,
297
- method,
298
- requestHeaders,
333
+ endpoint,
334
+ txHash,
335
+ method,
336
+ requestHeaders,
299
337
  requestBody,
300
338
  contentType
301
339
  );
@@ -308,6 +346,7 @@ export class X402Adapter extends BaseAdapter implements IAdapter {
308
346
  amount: paymentHeaders.amount,
309
347
  timestamp: now,
310
348
  endpoint,
349
+ feeBreakdown,
311
350
  });
312
351
 
313
352
  // Step 9: Return result - DONE! No release needed.
@@ -323,6 +362,7 @@ export class X402Adapter extends BaseAdapter implements IAdapter {
323
362
  provider: paymentHeaders.paymentAddress.toLowerCase(),
324
363
  requester: this.requesterAddress.toLowerCase(),
325
364
  deadline: new Date(paymentHeaders.deadline * 1000).toISOString(),
365
+ feeBreakdown,
326
366
  };
327
367
  }
328
368
 
@@ -562,20 +602,58 @@ export class X402Adapter extends BaseAdapter implements IAdapter {
562
602
  }
563
603
 
564
604
  /**
565
- * Execute atomic payment - direct transfer to provider.
605
+ * Execute atomic payment with fee splitting via X402Relay (if configured),
606
+ * or direct transfer as legacy fallback.
566
607
  *
567
- * This is the key difference from ACTP:
568
- * - No escrow
569
- * - No state machine
570
- * - Just transfer and done
608
+ * Relay flow: approve relay relay.payWithFee(provider, gross, serviceId)
609
+ * Legacy flow: transferFn(provider, amount) — no fee extraction
571
610
  */
572
- private async executeAtomicPayment(headers: X402PaymentHeaders): Promise<string> {
611
+ private async executeAtomicPayment(headers: X402PaymentHeaders): Promise<{
612
+ txHash: string;
613
+ feeBreakdown?: X402FeeBreakdown;
614
+ }> {
573
615
  try {
616
+ // Relay path: on-chain fee splitting
617
+ if (this.config.relayAddress && this.config.approveFn && this.config.relayPayFn) {
618
+ const grossAmount = headers.amount;
619
+ const feeBps = this.config.platformFeeBps ?? 100;
620
+ const MIN_FEE = 50_000n; // $0.05 USDC
621
+
622
+ // Calculate fee: max(gross * bps / 10000, MIN_FEE)
623
+ const grossBig = BigInt(grossAmount);
624
+ const bpsFee = (grossBig * BigInt(feeBps)) / 10_000n;
625
+ const fee = bpsFee > MIN_FEE ? bpsFee : MIN_FEE;
626
+ const providerNet = grossBig - fee;
627
+
628
+ // 1. Approve relay for gross amount
629
+ await this.config.approveFn(this.config.relayAddress, grossAmount);
630
+
631
+ // 2. Call relay.payWithFee
632
+ const serviceId = headers.serviceId ?? '0x' + '0'.repeat(64);
633
+ const txHash = await this.config.relayPayFn(
634
+ headers.paymentAddress,
635
+ grossAmount,
636
+ serviceId
637
+ );
638
+
639
+ return {
640
+ txHash,
641
+ feeBreakdown: {
642
+ grossAmount,
643
+ providerNet: providerNet.toString(),
644
+ platformFee: fee.toString(),
645
+ feeBps,
646
+ estimated: true,
647
+ },
648
+ };
649
+ }
650
+
651
+ // Legacy path: direct transfer, no fee
574
652
  const txHash = await this.transferFn(
575
653
  headers.paymentAddress,
576
654
  headers.amount
577
655
  );
578
- return txHash;
656
+ return { txHash };
579
657
  } catch (error) {
580
658
  throw new X402Error(
581
659
  `Atomic payment failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
@@ -23,7 +23,15 @@ export {
23
23
  } from './BaseAdapter';
24
24
  export { BasicAdapter, BasicPayParams, BasicPayResult } from './BasicAdapter';
25
25
  export { StandardAdapter, StandardTransactionParams } from './StandardAdapter';
26
- export { X402Adapter, X402AdapterConfig, FetchFunction } from './X402Adapter';
26
+ export {
27
+ X402Adapter,
28
+ X402AdapterConfig,
29
+ X402PayParams,
30
+ X402HttpMethod,
31
+ FetchFunction,
32
+ ApproveFunction,
33
+ RelayPayFunction,
34
+ } from './X402Adapter';
27
35
  export { AdapterRegistry } from './AdapterRegistry';
28
36
  export { AdapterRouter, AdapterSelectionResult } from './AdapterRouter';
29
37
  export {
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Diff Command - Compare local AGIRAILS.md with on-chain config
3
+ *
4
+ * Shows sync status between local file and AgentRegistry state.
5
+ * Terraform-style: never auto-overwrites, just shows differences.
6
+ *
7
+ * @module cli/commands/diff
8
+ */
9
+
10
+ import { Command } from 'commander';
11
+ import { Output, ExitCode } from '../utils/output';
12
+ import { mapError } from '../utils/client';
13
+ import { resolve } from 'path';
14
+ import { ethers } from 'ethers';
15
+ import { diff } from '../../config/syncOperations';
16
+ import { getNetwork } from '../../config/networks';
17
+
18
+ // ============================================================================
19
+ // Command Definition
20
+ // ============================================================================
21
+
22
+ export function createDiffCommand(): Command {
23
+ const cmd = new Command('diff')
24
+ .description('Compare local AGIRAILS.md with on-chain config')
25
+ .argument('[path]', 'Path to AGIRAILS.md', './AGIRAILS.md')
26
+ .option('-n, --network <network>', 'Network (base-sepolia | base-mainnet)', 'base-sepolia')
27
+ .option('-a, --address <address>', 'Agent address to compare with')
28
+ .option('--json', 'Output as JSON')
29
+ .option('-q, --quiet', 'Output only sync status')
30
+ .action(async (path, options) => {
31
+ const output = new Output(
32
+ options.json ? 'json' : options.quiet ? 'quiet' : 'human'
33
+ );
34
+
35
+ try {
36
+ await runDiff(path, options, output);
37
+ } catch (error) {
38
+ const structuredError = mapError(error);
39
+ output.errorResult({
40
+ code: structuredError.code,
41
+ message: structuredError.message,
42
+ details: structuredError.details,
43
+ });
44
+ process.exit(ExitCode.ERROR);
45
+ }
46
+ });
47
+
48
+ return cmd;
49
+ }
50
+
51
+ // ============================================================================
52
+ // Implementation
53
+ // ============================================================================
54
+
55
+ interface DiffCommandOptions {
56
+ network: string;
57
+ address?: string;
58
+ }
59
+
60
+ async function runDiff(
61
+ filePath: string,
62
+ options: DiffCommandOptions,
63
+ output: Output
64
+ ): Promise<void> {
65
+ const resolvedPath = resolve(filePath);
66
+
67
+ // Determine agent address
68
+ let agentAddress = options.address;
69
+ if (!agentAddress) {
70
+ const privateKey = process.env.ACTP_PRIVATE_KEY || process.env.PRIVATE_KEY;
71
+ if (!privateKey) {
72
+ output.error('Agent address required. Use --address or set ACTP_PRIVATE_KEY env var.');
73
+ process.exit(ExitCode.INVALID_INPUT);
74
+ }
75
+ agentAddress = new ethers.Wallet(privateKey).address;
76
+ }
77
+
78
+ const networkConfig = getNetwork(options.network);
79
+ if (!networkConfig.contracts.agentRegistry) {
80
+ output.error(`AgentRegistry not deployed on ${options.network}`);
81
+ process.exit(ExitCode.ERROR);
82
+ }
83
+
84
+ const spinner = output.spinner('Comparing local and on-chain config...');
85
+
86
+ try {
87
+ const provider = new ethers.JsonRpcProvider(networkConfig.rpcUrl);
88
+
89
+ const result = await diff({
90
+ path: resolvedPath,
91
+ agentAddress,
92
+ registryAddress: networkConfig.contracts.agentRegistry,
93
+ provider,
94
+ });
95
+
96
+ spinner.stop(true);
97
+
98
+ output.result(
99
+ {
100
+ status: result.status,
101
+ inSync: result.inSync,
102
+ localHash: result.localHash,
103
+ onChainHash: result.onChainHash,
104
+ onChainCID: result.onChainCID || null,
105
+ hasLocalFile: result.hasLocalFile,
106
+ hasOnChainConfig: result.hasOnChainConfig,
107
+ network: options.network,
108
+ agent: agentAddress,
109
+ },
110
+ { quietKey: 'status' }
111
+ );
112
+
113
+ output.blank();
114
+
115
+ // Human-friendly status messages
116
+ switch (result.status) {
117
+ case 'in-sync':
118
+ output.success('Local and on-chain configs are in sync.');
119
+ break;
120
+ case 'local-ahead':
121
+ output.warning('Local changes not yet published. Run: actp publish');
122
+ break;
123
+ case 'remote-ahead':
124
+ output.warning('On-chain config is newer. Run: actp pull');
125
+ break;
126
+ case 'diverged':
127
+ output.warning('Local and on-chain configs have diverged.');
128
+ output.print(' Resolve by running: actp publish (to push local) or actp pull --force (to accept remote)');
129
+ break;
130
+ case 'no-local':
131
+ output.info('No local AGIRAILS.md found. Run: actp pull');
132
+ break;
133
+ case 'no-remote':
134
+ output.info('No config published on-chain. Run: actp publish');
135
+ break;
136
+ }
137
+ } catch (error) {
138
+ spinner.stop(false);
139
+ throw error;
140
+ }
141
+ }