@agirails/sdk 3.2.0 → 3.4.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 (278) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +12 -14
  3. package/dist/ACTPClient.d.ts +8 -11
  4. package/dist/ACTPClient.d.ts.map +1 -1
  5. package/dist/ACTPClient.js +79 -20
  6. package/dist/ACTPClient.js.map +1 -1
  7. package/dist/__tests__/helpers/mockX402Server.d.ts +67 -0
  8. package/dist/__tests__/helpers/mockX402Server.d.ts.map +1 -0
  9. package/dist/__tests__/helpers/mockX402Server.js +121 -0
  10. package/dist/__tests__/helpers/mockX402Server.js.map +1 -0
  11. package/dist/adapters/BaseAdapter.d.ts +7 -1
  12. package/dist/adapters/BaseAdapter.d.ts.map +1 -1
  13. package/dist/adapters/BaseAdapter.js +11 -6
  14. package/dist/adapters/BaseAdapter.js.map +1 -1
  15. package/dist/adapters/BasicAdapter.d.ts.map +1 -1
  16. package/dist/adapters/BasicAdapter.js +12 -2
  17. package/dist/adapters/BasicAdapter.js.map +1 -1
  18. package/dist/adapters/StandardAdapter.d.ts.map +1 -1
  19. package/dist/adapters/StandardAdapter.js +12 -2
  20. package/dist/adapters/StandardAdapter.js.map +1 -1
  21. package/dist/adapters/X402Adapter.d.ts +161 -199
  22. package/dist/adapters/X402Adapter.d.ts.map +1 -1
  23. package/dist/adapters/X402Adapter.js +603 -414
  24. package/dist/adapters/X402Adapter.js.map +1 -1
  25. package/dist/adapters/index.d.ts +1 -1
  26. package/dist/adapters/index.d.ts.map +1 -1
  27. package/dist/adapters/index.js.map +1 -1
  28. package/dist/api/agirailsApp.d.ts +21 -1
  29. package/dist/api/agirailsApp.d.ts.map +1 -1
  30. package/dist/api/agirailsApp.js.map +1 -1
  31. package/dist/builders/CounterAcceptBuilder.d.ts +96 -0
  32. package/dist/builders/CounterAcceptBuilder.d.ts.map +1 -0
  33. package/dist/builders/CounterAcceptBuilder.js +226 -0
  34. package/dist/builders/CounterAcceptBuilder.js.map +1 -0
  35. package/dist/builders/CounterOfferBuilder.d.ts +143 -0
  36. package/dist/builders/CounterOfferBuilder.d.ts.map +1 -0
  37. package/dist/builders/CounterOfferBuilder.js +329 -0
  38. package/dist/builders/CounterOfferBuilder.js.map +1 -0
  39. package/dist/builders/DeliveryProofBuilder.d.ts.map +1 -1
  40. package/dist/builders/DeliveryProofBuilder.js +3 -2
  41. package/dist/builders/DeliveryProofBuilder.js.map +1 -1
  42. package/dist/builders/QuoteBuilder.d.ts.map +1 -1
  43. package/dist/builders/QuoteBuilder.js +8 -3
  44. package/dist/builders/QuoteBuilder.js.map +1 -1
  45. package/dist/builders/index.d.ts +2 -0
  46. package/dist/builders/index.d.ts.map +1 -1
  47. package/dist/builders/index.js +7 -1
  48. package/dist/builders/index.js.map +1 -1
  49. package/dist/cli/agirails.js +34 -6
  50. package/dist/cli/agirails.js.map +1 -1
  51. package/dist/cli/commands/autopublish.js +9 -1
  52. package/dist/cli/commands/autopublish.js.map +1 -1
  53. package/dist/cli/commands/config.js +1 -12
  54. package/dist/cli/commands/config.js.map +1 -1
  55. package/dist/cli/commands/deploy-env.js +1 -1
  56. package/dist/cli/commands/deploy-env.js.map +1 -1
  57. package/dist/cli/commands/diff.js +38 -4
  58. package/dist/cli/commands/diff.js.map +1 -1
  59. package/dist/cli/commands/health.js +24 -6
  60. package/dist/cli/commands/health.js.map +1 -1
  61. package/dist/cli/commands/init.d.ts +2 -0
  62. package/dist/cli/commands/init.d.ts.map +1 -1
  63. package/dist/cli/commands/init.js +100 -7
  64. package/dist/cli/commands/init.js.map +1 -1
  65. package/dist/cli/commands/pay.d.ts.map +1 -1
  66. package/dist/cli/commands/pay.js +23 -0
  67. package/dist/cli/commands/pay.js.map +1 -1
  68. package/dist/cli/commands/publish.d.ts +34 -0
  69. package/dist/cli/commands/publish.d.ts.map +1 -1
  70. package/dist/cli/commands/publish.js +266 -83
  71. package/dist/cli/commands/publish.js.map +1 -1
  72. package/dist/cli/commands/pull.js +3 -1
  73. package/dist/cli/commands/pull.js.map +1 -1
  74. package/dist/cli/commands/receipt.d.ts +17 -3
  75. package/dist/cli/commands/receipt.d.ts.map +1 -1
  76. package/dist/cli/commands/receipt.js +95 -33
  77. package/dist/cli/commands/receipt.js.map +1 -1
  78. package/dist/cli/commands/repair.d.ts +23 -0
  79. package/dist/cli/commands/repair.d.ts.map +1 -0
  80. package/dist/cli/commands/repair.js +210 -0
  81. package/dist/cli/commands/repair.js.map +1 -0
  82. package/dist/cli/commands/serve.d.ts +38 -0
  83. package/dist/cli/commands/serve.d.ts.map +1 -0
  84. package/dist/cli/commands/serve.js +308 -0
  85. package/dist/cli/commands/serve.js.map +1 -0
  86. package/dist/cli/commands/test.d.ts.map +1 -1
  87. package/dist/cli/commands/test.js +222 -60
  88. package/dist/cli/commands/test.js.map +1 -1
  89. package/dist/cli/commands/tx.js +13 -0
  90. package/dist/cli/commands/tx.js.map +1 -1
  91. package/dist/cli/index.js +9 -1
  92. package/dist/cli/index.js.map +1 -1
  93. package/dist/cli/receiptUpload.d.ts +52 -0
  94. package/dist/cli/receiptUpload.d.ts.map +1 -0
  95. package/dist/cli/receiptUpload.js +134 -0
  96. package/dist/cli/receiptUpload.js.map +1 -0
  97. package/dist/cli/utils/banner.d.ts +31 -0
  98. package/dist/cli/utils/banner.d.ts.map +1 -0
  99. package/dist/cli/utils/banner.js +92 -0
  100. package/dist/cli/utils/banner.js.map +1 -0
  101. package/dist/cli/utils/config.d.ts +0 -2
  102. package/dist/cli/utils/config.d.ts.map +1 -1
  103. package/dist/cli/utils/config.js +40 -25
  104. package/dist/cli/utils/config.js.map +1 -1
  105. package/dist/cli/utils/output.d.ts +2 -0
  106. package/dist/cli/utils/output.d.ts.map +1 -1
  107. package/dist/cli/utils/output.js +7 -1
  108. package/dist/cli/utils/output.js.map +1 -1
  109. package/dist/cli/utils/share.d.ts +51 -0
  110. package/dist/cli/utils/share.d.ts.map +1 -0
  111. package/dist/cli/utils/share.js +133 -0
  112. package/dist/cli/utils/share.js.map +1 -0
  113. package/dist/config/agirailsmd.d.ts.map +1 -1
  114. package/dist/config/agirailsmd.js +2 -1
  115. package/dist/config/agirailsmd.js.map +1 -1
  116. package/dist/config/agirailsmdV4.d.ts +46 -1
  117. package/dist/config/agirailsmdV4.d.ts.map +1 -1
  118. package/dist/config/agirailsmdV4.js +65 -8
  119. package/dist/config/agirailsmdV4.js.map +1 -1
  120. package/dist/config/defaults.d.ts +12 -2
  121. package/dist/config/defaults.d.ts.map +1 -1
  122. package/dist/config/defaults.js +19 -3
  123. package/dist/config/defaults.js.map +1 -1
  124. package/dist/config/networks.d.ts +7 -0
  125. package/dist/config/networks.d.ts.map +1 -1
  126. package/dist/config/networks.js +20 -11
  127. package/dist/config/networks.js.map +1 -1
  128. package/dist/config/pendingPublish.d.ts.map +1 -1
  129. package/dist/config/pendingPublish.js +10 -3
  130. package/dist/config/pendingPublish.js.map +1 -1
  131. package/dist/config/publishPipeline.d.ts +23 -1
  132. package/dist/config/publishPipeline.d.ts.map +1 -1
  133. package/dist/config/publishPipeline.js +70 -15
  134. package/dist/config/publishPipeline.js.map +1 -1
  135. package/dist/config/syncOperations.d.ts.map +1 -1
  136. package/dist/config/syncOperations.js +4 -2
  137. package/dist/config/syncOperations.js.map +1 -1
  138. package/dist/erc8004/ERC8004Bridge.d.ts.map +1 -1
  139. package/dist/erc8004/ERC8004Bridge.js +0 -1
  140. package/dist/erc8004/ERC8004Bridge.js.map +1 -1
  141. package/dist/errors/ACTPError.d.ts +24 -0
  142. package/dist/errors/ACTPError.d.ts.map +1 -0
  143. package/dist/errors/ACTPError.js +35 -0
  144. package/dist/errors/ACTPError.js.map +1 -0
  145. package/dist/errors/X402Errors.d.ts +106 -0
  146. package/dist/errors/X402Errors.d.ts.map +1 -0
  147. package/dist/errors/X402Errors.js +160 -0
  148. package/dist/errors/X402Errors.js.map +1 -0
  149. package/dist/errors/index.d.ts +3 -9
  150. package/dist/errors/index.d.ts.map +1 -1
  151. package/dist/errors/index.js +38 -33
  152. package/dist/errors/index.js.map +1 -1
  153. package/dist/index.d.ts +22 -1
  154. package/dist/index.d.ts.map +1 -1
  155. package/dist/index.js +41 -3
  156. package/dist/index.js.map +1 -1
  157. package/dist/level0/Provider.d.ts +5 -0
  158. package/dist/level0/Provider.d.ts.map +1 -1
  159. package/dist/level0/ServiceDirectory.d.ts.map +1 -1
  160. package/dist/level0/ServiceDirectory.js +3 -2
  161. package/dist/level0/ServiceDirectory.js.map +1 -1
  162. package/dist/level0/provide.d.ts.map +1 -1
  163. package/dist/level0/provide.js +11 -8
  164. package/dist/level0/provide.js.map +1 -1
  165. package/dist/level0/request.d.ts.map +1 -1
  166. package/dist/level0/request.js +14 -6
  167. package/dist/level0/request.js.map +1 -1
  168. package/dist/level1/Agent.d.ts +28 -1
  169. package/dist/level1/Agent.d.ts.map +1 -1
  170. package/dist/level1/Agent.js +89 -12
  171. package/dist/level1/Agent.js.map +1 -1
  172. package/dist/level1/pricing/PriceCalculator.d.ts.map +1 -1
  173. package/dist/level1/pricing/PriceCalculator.js +4 -12
  174. package/dist/level1/pricing/PriceCalculator.js.map +1 -1
  175. package/dist/negotiation/BuyerOrchestrator.d.ts +103 -1
  176. package/dist/negotiation/BuyerOrchestrator.d.ts.map +1 -1
  177. package/dist/negotiation/BuyerOrchestrator.js +499 -4
  178. package/dist/negotiation/BuyerOrchestrator.js.map +1 -1
  179. package/dist/negotiation/DecisionEngine.d.ts +69 -1
  180. package/dist/negotiation/DecisionEngine.d.ts.map +1 -1
  181. package/dist/negotiation/DecisionEngine.js +140 -1
  182. package/dist/negotiation/DecisionEngine.js.map +1 -1
  183. package/dist/negotiation/PolicyEngine.d.ts +32 -0
  184. package/dist/negotiation/PolicyEngine.d.ts.map +1 -1
  185. package/dist/negotiation/PolicyEngine.js.map +1 -1
  186. package/dist/negotiation/ProviderOrchestrator.d.ts +108 -0
  187. package/dist/negotiation/ProviderOrchestrator.d.ts.map +1 -0
  188. package/dist/negotiation/ProviderOrchestrator.js +136 -0
  189. package/dist/negotiation/ProviderOrchestrator.js.map +1 -0
  190. package/dist/negotiation/ProviderPolicy.d.ts +143 -0
  191. package/dist/negotiation/ProviderPolicy.d.ts.map +1 -0
  192. package/dist/negotiation/ProviderPolicy.js +207 -0
  193. package/dist/negotiation/ProviderPolicy.js.map +1 -0
  194. package/dist/negotiation/index.d.ts +8 -1
  195. package/dist/negotiation/index.d.ts.map +1 -1
  196. package/dist/negotiation/index.js +8 -1
  197. package/dist/negotiation/index.js.map +1 -1
  198. package/dist/negotiation/verifyQuoteOnChain.d.ts +58 -0
  199. package/dist/negotiation/verifyQuoteOnChain.d.ts.map +1 -0
  200. package/dist/negotiation/verifyQuoteOnChain.js +83 -0
  201. package/dist/negotiation/verifyQuoteOnChain.js.map +1 -0
  202. package/dist/protocol/ACTPKernel.d.ts +4 -1
  203. package/dist/protocol/ACTPKernel.d.ts.map +1 -1
  204. package/dist/protocol/ACTPKernel.js +2 -1
  205. package/dist/protocol/ACTPKernel.js.map +1 -1
  206. package/dist/protocol/EventMonitor.d.ts +27 -1
  207. package/dist/protocol/EventMonitor.d.ts.map +1 -1
  208. package/dist/protocol/EventMonitor.js +11 -9
  209. package/dist/protocol/EventMonitor.js.map +1 -1
  210. package/dist/protocol/ProofGenerator.d.ts.map +1 -1
  211. package/dist/protocol/ProofGenerator.js +3 -2
  212. package/dist/protocol/ProofGenerator.js.map +1 -1
  213. package/dist/runtime/BlockchainRuntime.d.ts +15 -0
  214. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  215. package/dist/runtime/BlockchainRuntime.js +42 -6
  216. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  217. package/dist/runtime/IACTPRuntime.d.ts +35 -0
  218. package/dist/runtime/IACTPRuntime.d.ts.map +1 -1
  219. package/dist/runtime/MockRuntime.d.ts +14 -2
  220. package/dist/runtime/MockRuntime.d.ts.map +1 -1
  221. package/dist/runtime/MockRuntime.js +55 -22
  222. package/dist/runtime/MockRuntime.js.map +1 -1
  223. package/dist/runtime/types/MockState.d.ts +14 -0
  224. package/dist/runtime/types/MockState.d.ts.map +1 -1
  225. package/dist/runtime/types/MockState.js.map +1 -1
  226. package/dist/server/buildX402Server.d.ts +131 -0
  227. package/dist/server/buildX402Server.d.ts.map +1 -0
  228. package/dist/server/buildX402Server.js +151 -0
  229. package/dist/server/buildX402Server.js.map +1 -0
  230. package/dist/server/index.d.ts +33 -0
  231. package/dist/server/index.d.ts.map +1 -0
  232. package/dist/server/index.js +36 -0
  233. package/dist/server/index.js.map +1 -0
  234. package/dist/transport/QuoteChannel.d.ts +201 -0
  235. package/dist/transport/QuoteChannel.d.ts.map +1 -0
  236. package/dist/transport/QuoteChannel.js +358 -0
  237. package/dist/transport/QuoteChannel.js.map +1 -0
  238. package/dist/types/adapter.d.ts +64 -34
  239. package/dist/types/adapter.d.ts.map +1 -1
  240. package/dist/types/adapter.js +6 -1
  241. package/dist/types/adapter.js.map +1 -1
  242. package/dist/types/eip712.d.ts +20 -0
  243. package/dist/types/eip712.d.ts.map +1 -1
  244. package/dist/types/x402.d.ts +8 -8
  245. package/dist/utils/security.d.ts.map +1 -1
  246. package/dist/utils/security.js +4 -6
  247. package/dist/utils/security.js.map +1 -1
  248. package/dist/wallet/AutoWalletProvider.d.ts +45 -1
  249. package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
  250. package/dist/wallet/AutoWalletProvider.js +154 -1
  251. package/dist/wallet/AutoWalletProvider.js.map +1 -1
  252. package/dist/wallet/EOAWalletProvider.d.ts +13 -1
  253. package/dist/wallet/EOAWalletProvider.d.ts.map +1 -1
  254. package/dist/wallet/EOAWalletProvider.js +24 -0
  255. package/dist/wallet/EOAWalletProvider.js.map +1 -1
  256. package/dist/wallet/IWalletProvider.d.ts +34 -0
  257. package/dist/wallet/IWalletProvider.d.ts.map +1 -1
  258. package/dist/wallet/SmartWalletRouter.d.ts.map +1 -1
  259. package/dist/wallet/SmartWalletRouter.js +3 -1
  260. package/dist/wallet/SmartWalletRouter.js.map +1 -1
  261. package/dist/wallet/aa/BundlerClient.js +8 -4
  262. package/dist/wallet/aa/BundlerClient.js.map +1 -1
  263. package/dist/wallet/aa/DualNonceManager.d.ts +4 -1
  264. package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
  265. package/dist/wallet/aa/DualNonceManager.js +3 -0
  266. package/dist/wallet/aa/DualNonceManager.js.map +1 -1
  267. package/dist/wallet/keystore.d.ts.map +1 -1
  268. package/dist/wallet/keystore.js +6 -4
  269. package/dist/wallet/keystore.js.map +1 -1
  270. package/package.json +31 -3
  271. package/dist/adapters/BeginnerAdapter.d.ts +0 -152
  272. package/dist/adapters/BeginnerAdapter.d.ts.map +0 -1
  273. package/dist/adapters/BeginnerAdapter.js +0 -168
  274. package/dist/adapters/BeginnerAdapter.js.map +0 -1
  275. package/dist/adapters/IntermediateAdapter.d.ts +0 -211
  276. package/dist/adapters/IntermediateAdapter.d.ts.map +0 -1
  277. package/dist/adapters/IntermediateAdapter.js +0 -260
  278. package/dist/adapters/IntermediateAdapter.js.map +0 -1
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ /**
3
+ * ProviderOrchestrator — autonomous provider-side quote flow.
4
+ *
5
+ * Symmetric to BuyerOrchestrator but smaller: one decision per incoming
6
+ * request (quote-or-skip, at what price), one submitQuote tx on-chain,
7
+ * one off-chain POST to the buyer's quote channel. Counter-offer
8
+ * evaluation is delegated to the policy engine; counter-counter
9
+ * strategies are Phase 3 territory and out of scope here.
10
+ *
11
+ * This module does NOT listen to the chain. Callers (Agent.ts in
12
+ * Phase 3) surface an IncomingRequest + consumer endpoint; the
13
+ * orchestrator decides + acts + returns the outcome.
14
+ *
15
+ * @module negotiation/ProviderOrchestrator
16
+ * @see Protocol/aips/AIP-2.1-DRAFT.md §5.2
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.ProviderOrchestrator = void 0;
20
+ const QuoteBuilder_1 = require("../builders/QuoteBuilder");
21
+ const CounterOfferBuilder_1 = require("../builders/CounterOfferBuilder");
22
+ const NonceManager_1 = require("../utils/NonceManager");
23
+ const QuoteChannel_1 = require("../transport/QuoteChannel");
24
+ const ProviderPolicy_1 = require("./ProviderPolicy");
25
+ // ============================================================================
26
+ // Orchestrator
27
+ // ============================================================================
28
+ class ProviderOrchestrator {
29
+ constructor(cfg) {
30
+ this.policy = cfg.policy;
31
+ this.policyEngine = new ProviderPolicy_1.ProviderPolicyEngine(cfg.policy);
32
+ this.runtime = cfg.runtime;
33
+ this.signer = cfg.signer;
34
+ this.kernelAddress = cfg.kernelAddress;
35
+ this.chainId = cfg.chainId;
36
+ this.nonceManager = cfg.nonceManager ?? new NonceManager_1.InMemoryNonceManager();
37
+ this.channel = cfg.channel ?? new QuoteChannel_1.QuoteChannelClient();
38
+ this.quoteBuilder = new QuoteBuilder_1.QuoteBuilder(this.signer, this.nonceManager);
39
+ // Verifier side — builder instance is signer-independent for verify().
40
+ // We hand it the same signer to keep the construction trivial.
41
+ this.counterVerifier = new CounterOfferBuilder_1.CounterOfferBuilder(this.signer, this.nonceManager);
42
+ }
43
+ /**
44
+ * Decide whether to quote. Does NOT touch the chain — pure policy.
45
+ * Use `quote()` below to act on the decision.
46
+ */
47
+ evaluateRequest(req) {
48
+ const result = this.policyEngine.evaluate(req);
49
+ if (!result.allowed) {
50
+ return {
51
+ action: 'skip',
52
+ reason: result.violations.map((v) => `${v.rule}: ${v.detail}`).join('; '),
53
+ violations: result.violations,
54
+ };
55
+ }
56
+ return {
57
+ action: 'quote',
58
+ amountBaseUnits: result.recommended_quote_amount_base_units,
59
+ reason: `Policy passed; recommended quote ${result.recommended_quote_amount_base_units} base units`,
60
+ };
61
+ }
62
+ /**
63
+ * Full quote flow: evaluate → build signed QuoteMessage → submit
64
+ * on-chain → POST to buyer's endpoint.
65
+ *
66
+ * On-chain failure → throws (caller decides retry / cancel).
67
+ * Off-chain POST failure → returns successfully with `channelError`
68
+ * set so caller knows to retry only the delivery step. Preserves the
69
+ * invariant "on-chain tx is what buyer observes regardless of our
70
+ * off-chain delivery".
71
+ */
72
+ async quote(req, providerDID, consumerEndpoint) {
73
+ const decision = this.evaluateRequest(req);
74
+ if (decision.action === 'skip') {
75
+ return { decision };
76
+ }
77
+ // Build + sign QuoteMessage. Amount stays in base units throughout
78
+ // (no float round-trip). Currency / decimals come from policy —
79
+ // hardcoding would silently mask a config drift if we ever support
80
+ // non-USDC tokens. QuoteBuilder validates USDC/6 today; other
81
+ // currencies will throw there until the builder grows support.
82
+ const now = Math.floor(Date.now() / 1000);
83
+ const currency = this.policyEngine.policyCurrency;
84
+ const decimals = currency.toUpperCase() === 'USDC' ? 6 : 6; // placeholder for future currencies
85
+ const quote = await this.quoteBuilder.build({
86
+ txId: req.txId,
87
+ provider: providerDID,
88
+ consumer: req.consumer,
89
+ quotedAmount: decision.amountBaseUnits,
90
+ originalAmount: req.offeredAmount,
91
+ maxPrice: req.maxPrice,
92
+ currency,
93
+ decimals,
94
+ expiresAt: now + this.policyEngine.quoteTtlSeconds,
95
+ chainId: this.chainId,
96
+ kernelAddress: this.kernelAddress,
97
+ });
98
+ // On-chain: INITIATED → QUOTED, hash stored in tx.metadata.
99
+ await this.runtime.submitQuote(req.txId, quote);
100
+ // Off-chain: deliver the signed message so buyer can verify.
101
+ // Caller may omit consumerEndpoint when the transport is handled
102
+ // outside this orchestrator (e.g. Telegram, IPFS pubsub adapter).
103
+ if (consumerEndpoint) {
104
+ try {
105
+ await this.channel.sendQuote(consumerEndpoint, quote);
106
+ }
107
+ catch (err) {
108
+ return {
109
+ decision,
110
+ quote,
111
+ channelError: err instanceof Error ? err.message : String(err),
112
+ };
113
+ }
114
+ }
115
+ return { decision, quote };
116
+ }
117
+ /**
118
+ * Verify + evaluate a buyer counter-offer. Returns the decision;
119
+ * does NOT send any response — Phase 3 wires the response path.
120
+ *
121
+ * @throws if the counter signature / band / expiry fails verify.
122
+ */
123
+ async evaluateCounter(counter) {
124
+ await this.counterVerifier.verify(counter, this.kernelAddress);
125
+ const verdict = this.policyEngine.evaluateCounter(counter.counterAmount);
126
+ // Engine returns `{decision, reason}`; orchestrator API uses
127
+ // `{action, reason}` — reshape at the boundary.
128
+ return { action: verdict.decision, reason: verdict.reason };
129
+ }
130
+ /** Read-only policy accessor for UIs and tests. */
131
+ getPolicy() {
132
+ return this.policy;
133
+ }
134
+ }
135
+ exports.ProviderOrchestrator = ProviderOrchestrator;
136
+ //# sourceMappingURL=ProviderOrchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderOrchestrator.js","sourceRoot":"","sources":["../../src/negotiation/ProviderOrchestrator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAIH,2DAAsE;AACtE,yEAGyC;AACzC,wDAA2E;AAC3E,4DAA+D;AAC/D,qDAI0B;AA+C1B,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E,MAAa,oBAAoB;IAY/B,YAAY,GAA+B;QACzC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,IAAI,qCAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,IAAI,IAAI,mCAAoB,EAAE,CAAC;QACnE,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,IAAI,iCAAkB,EAAE,CAAC;QACvD,IAAI,CAAC,YAAY,GAAG,IAAI,2BAAY,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACrE,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,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC/D,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACzE,6DAA6D;QAC7D,gDAAgD;QAChD,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;IAC9D,CAAC;IAED,mDAAmD;IACnD,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAhID,oDAgIC"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * ProviderPolicy — hard guardrails for autonomous provider quoting.
3
+ *
4
+ * Symmetric to BuyerPolicy. Provider configures what they'll deliver,
5
+ * their price floor, and their lifecycle preferences; ProviderPolicyEngine
6
+ * enforces those invariants on every incoming request so the provider
7
+ * never quotes below floor, outside their service menu, or for a
8
+ * transaction they can't realistically complete before the deadline.
9
+ *
10
+ * @module negotiation/ProviderPolicy
11
+ * @see Protocol/aips/AIP-2.1-DRAFT.md §5.2 (ProviderPolicy.ts creation)
12
+ */
13
+ /**
14
+ * What this agent provides + at what terms.
15
+ *
16
+ * Pricing invariant (enforced at construction):
17
+ * ideal_price.amount ≥ min_acceptable.amount ≥ PLATFORM_MIN_USDC
18
+ *
19
+ * `currency`/`unit` must be identical across min_acceptable and
20
+ * ideal_price — we compare amounts directly, there's no FX in v1.
21
+ */
22
+ export interface ProviderPolicy {
23
+ /**
24
+ * Services this provider offers. Incoming requests for service types
25
+ * NOT in this list get a 'skip' decision (let the tx timeout to
26
+ * CANCELLED; we don't quote for work we don't do).
27
+ */
28
+ services: string[];
29
+ pricing: {
30
+ /** Absolute floor. Any buyer maxPrice below this → skip. */
31
+ min_acceptable: {
32
+ amount: number;
33
+ currency: string;
34
+ unit: string;
35
+ };
36
+ /** Preferred quote amount when buyer's maxPrice ≥ ideal. */
37
+ ideal_price: {
38
+ amount: number;
39
+ currency: string;
40
+ unit: string;
41
+ };
42
+ };
43
+ /** Quote validity window (e.g. "15m"). Governs our QuoteMessage expiresAt. */
44
+ quote_ttl: string;
45
+ /**
46
+ * Minimum time (seconds) we need between now and tx.deadline to
47
+ * realistically deliver. Requests with a tighter deadline get 'skip'.
48
+ * Defaults to 60s if omitted.
49
+ */
50
+ min_deadline_seconds?: number;
51
+ }
52
+ export type ProviderPolicyViolation = {
53
+ rule: 'service_not_offered';
54
+ detail: string;
55
+ } | {
56
+ rule: 'max_price_below_floor';
57
+ detail: string;
58
+ } | {
59
+ rule: 'deadline_too_tight';
60
+ detail: string;
61
+ } | {
62
+ rule: 'currency_mismatch';
63
+ detail: string;
64
+ } | {
65
+ rule: 'unit_mismatch';
66
+ detail: string;
67
+ };
68
+ export interface ProviderPolicyResult {
69
+ allowed: boolean;
70
+ violations: ProviderPolicyViolation[];
71
+ /**
72
+ * When `allowed`, the amount we SHOULD quote per this policy,
73
+ * expressed in USDC base units (1e6 per $1) as a decimal string.
74
+ * Using string-of-base-units throughout avoids Number/float drift
75
+ * on very large amounts and matches what the QuoteMessage carries.
76
+ *
77
+ * Rule: quote our ideal if buyer maxPrice ≥ ideal; otherwise quote
78
+ * at buyer maxPrice (still ≥ floor, validated above). Never below
79
+ * min_acceptable.
80
+ */
81
+ recommended_quote_amount_base_units?: string;
82
+ }
83
+ /**
84
+ * Incoming request surface — the minimum the orchestrator needs to
85
+ * decide whether + at what price to quote. Extracted from the
86
+ * on-chain transaction plus any off-chain context the caller has
87
+ * (service type, consumer DID).
88
+ */
89
+ export interface IncomingRequest {
90
+ txId: string;
91
+ consumer: string;
92
+ /** Buyer's offered amount in USDC base units (smallest unit, string). */
93
+ offeredAmount: string;
94
+ /** Buyer's ceiling in USDC base units. */
95
+ maxPrice: string;
96
+ /** Unix seconds — tx.deadline from on-chain. */
97
+ deadline: number;
98
+ /** Service identifier (e.g. "code-review"). */
99
+ serviceType: string;
100
+ currency: string;
101
+ unit: string;
102
+ }
103
+ export declare class ProviderPolicyEngine {
104
+ private readonly policy;
105
+ private readonly floorBaseUnits;
106
+ private readonly idealBaseUnits;
107
+ private readonly currency;
108
+ constructor(policy: ProviderPolicy);
109
+ /**
110
+ * Evaluate an incoming request against policy. Returns `allowed: true`
111
+ * with `recommended_quote_amount_base_units` (bigint-as-string) when
112
+ * we should quote, or `allowed: false` with the specific rule(s)
113
+ * violated.
114
+ *
115
+ * All numeric comparisons use BigInt on base units — no float drift,
116
+ * no precision loss for large amounts.
117
+ */
118
+ evaluate(req: IncomingRequest): ProviderPolicyResult;
119
+ /**
120
+ * Decide whether to accept a buyer's counter-offer.
121
+ *
122
+ * Simple rule: accept if counter ≥ min_acceptable; reject otherwise.
123
+ * All arithmetic is BigInt on base units — no float drift.
124
+ * Phase 3 will extend this with `counter-counter` strategies.
125
+ */
126
+ evaluateCounter(counterAmountBaseUnits: string): {
127
+ decision: 'accept' | 'reject';
128
+ reason: string;
129
+ };
130
+ /** Expose ttl as seconds for callers building QuoteMessage.expiresAt. */
131
+ get quoteTtlSeconds(): number;
132
+ /** Expose the policy's currency for orchestrator wiring. */
133
+ get policyCurrency(): string;
134
+ /** Expose the policy's unit for orchestrator wiring + UI. */
135
+ get policyUnit(): string;
136
+ }
137
+ /**
138
+ * Parse a short duration string like "15m", "1h", "30s" into seconds.
139
+ * Mirror of PolicyEngine.parseTtl (buyer side) so both sides use the
140
+ * same format in their JSON policies.
141
+ */
142
+ export declare function parseTtl(ttl: string): number;
143
+ //# sourceMappingURL=ProviderPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderPolicy.d.ts","sourceRoot":"","sources":["../../src/negotiation/ProviderPolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IAEnB,OAAO,EAAE;QACP,4DAA4D;QAC5D,cAAc,E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,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAqCD,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,MAAM,EAAE,cAAc;IAmClC;;;;;;;;OAQG;IACH,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,oBAAoB;IAsEpD;;;;;;OAMG;IACH,eAAe,CAAC,sBAAsB,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAmBlG,yEAAyE;IACzE,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED,4DAA4D;IAC5D,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED,6DAA6D;IAC7D,IAAI,UAAU,IAAI,MAAM,CAEvB;CACF;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU5C"}
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ /**
3
+ * ProviderPolicy — hard guardrails for autonomous provider quoting.
4
+ *
5
+ * Symmetric to BuyerPolicy. Provider configures what they'll deliver,
6
+ * their price floor, and their lifecycle preferences; ProviderPolicyEngine
7
+ * enforces those invariants on every incoming request so the provider
8
+ * never quotes below floor, outside their service menu, or for a
9
+ * transaction they can't realistically complete before the deadline.
10
+ *
11
+ * @module negotiation/ProviderPolicy
12
+ * @see Protocol/aips/AIP-2.1-DRAFT.md §5.2 (ProviderPolicy.ts creation)
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.parseTtl = exports.ProviderPolicyEngine = void 0;
16
+ // ============================================================================
17
+ // Engine
18
+ // ============================================================================
19
+ /** Base units per $1 for supported currencies. USDC = 1e6 (6 decimals). */
20
+ const BASE_UNITS_PER_USD = {
21
+ USDC: 1000000n,
22
+ };
23
+ /** Platform minimum in base units — $0.05 × 1e6 for USDC. */
24
+ const PLATFORM_MIN_BASE_UNITS = {
25
+ USDC: 50000n,
26
+ };
27
+ const DEFAULT_MIN_DEADLINE_SECONDS = 60;
28
+ /** Convert a human amount (e.g. 5, 10.5) to base units (bigint). */
29
+ function toBaseUnits(amount, currency) {
30
+ const perUsd = BASE_UNITS_PER_USD[currency.toUpperCase()];
31
+ if (!perUsd)
32
+ throw new Error(`Unsupported currency: ${currency}`);
33
+ // Do the scaling as string→BigInt to avoid float drift on amounts
34
+ // that don't fit cleanly in double precision (e.g. 0.1).
35
+ const [whole, frac = ''] = String(amount).split('.');
36
+ const fracPadded = (frac + '000000').slice(0, String(perUsd).length - 1);
37
+ return BigInt(whole) * perUsd + BigInt(fracPadded || '0');
38
+ }
39
+ /** Format base units back to a human string for error messages. */
40
+ function formatFromBaseUnits(baseUnits, currency) {
41
+ const perUsd = BASE_UNITS_PER_USD[currency.toUpperCase()];
42
+ if (!perUsd)
43
+ return `${baseUnits} base units`;
44
+ const whole = baseUnits / perUsd;
45
+ const frac = baseUnits % perUsd;
46
+ const fracStr = frac.toString().padStart(String(perUsd).length - 1, '0').replace(/0+$/, '');
47
+ return fracStr ? `$${whole}.${fracStr}` : `$${whole}`;
48
+ }
49
+ class ProviderPolicyEngine {
50
+ constructor(policy) {
51
+ const currency = policy.pricing.min_acceptable.currency;
52
+ const platformMin = PLATFORM_MIN_BASE_UNITS[currency.toUpperCase()];
53
+ if (!platformMin) {
54
+ throw new Error(`Unsupported currency in policy: ${currency}`);
55
+ }
56
+ // Enforce pricing invariants at construction — fail fast so mis-
57
+ // configured providers don't quote garbage.
58
+ const floorBu = toBaseUnits(policy.pricing.min_acceptable.amount, currency);
59
+ const idealBu = toBaseUnits(policy.pricing.ideal_price.amount, currency);
60
+ if (floorBu < platformMin) {
61
+ throw new Error(`min_acceptable.amount (${formatFromBaseUnits(floorBu, currency)}) below platform minimum (${formatFromBaseUnits(platformMin, currency)})`);
62
+ }
63
+ if (idealBu < floorBu) {
64
+ throw new Error(`ideal_price.amount (${formatFromBaseUnits(idealBu, currency)}) must be ≥ min_acceptable.amount (${formatFromBaseUnits(floorBu, currency)})`);
65
+ }
66
+ if (policy.pricing.min_acceptable.currency !== policy.pricing.ideal_price.currency) {
67
+ throw new Error('min_acceptable.currency must equal ideal_price.currency');
68
+ }
69
+ if (policy.pricing.min_acceptable.unit !== policy.pricing.ideal_price.unit) {
70
+ throw new Error('min_acceptable.unit must equal ideal_price.unit');
71
+ }
72
+ this.policy = policy;
73
+ this.floorBaseUnits = floorBu;
74
+ this.idealBaseUnits = idealBu;
75
+ this.currency = currency;
76
+ }
77
+ /**
78
+ * Evaluate an incoming request against policy. Returns `allowed: true`
79
+ * with `recommended_quote_amount_base_units` (bigint-as-string) when
80
+ * we should quote, or `allowed: false` with the specific rule(s)
81
+ * violated.
82
+ *
83
+ * All numeric comparisons use BigInt on base units — no float drift,
84
+ * no precision loss for large amounts.
85
+ */
86
+ evaluate(req) {
87
+ const violations = [];
88
+ if (!this.policy.services.includes(req.serviceType)) {
89
+ violations.push({
90
+ rule: 'service_not_offered',
91
+ detail: `We don't offer service "${req.serviceType}". Configured: ${this.policy.services.join(', ')}`,
92
+ });
93
+ }
94
+ if (req.currency.toUpperCase() !== this.currency.toUpperCase()) {
95
+ violations.push({
96
+ rule: 'currency_mismatch',
97
+ detail: `Request in ${req.currency}, we quote in ${this.currency}`,
98
+ });
99
+ }
100
+ // `unit` is the pricing unit (job, hour, page, request, …).
101
+ // Buyer quoting $5/hour vs provider priced-per-job is a genuine
102
+ // mismatch and must not silently be quoted.
103
+ if (req.unit !== this.policy.pricing.min_acceptable.unit) {
104
+ violations.push({
105
+ rule: 'unit_mismatch',
106
+ detail: `Request unit "${req.unit}" does not match policy unit "${this.policy.pricing.min_acceptable.unit}"`,
107
+ });
108
+ }
109
+ let maxPriceBu;
110
+ try {
111
+ maxPriceBu = BigInt(req.maxPrice);
112
+ }
113
+ catch {
114
+ violations.push({
115
+ rule: 'max_price_below_floor',
116
+ detail: `Invalid maxPrice: ${req.maxPrice}`,
117
+ });
118
+ maxPriceBu = 0n;
119
+ }
120
+ if (maxPriceBu < this.floorBaseUnits) {
121
+ violations.push({
122
+ rule: 'max_price_below_floor',
123
+ detail: `Buyer maxPrice ${formatFromBaseUnits(maxPriceBu, this.currency)} below our floor ${formatFromBaseUnits(this.floorBaseUnits, this.currency)}`,
124
+ });
125
+ }
126
+ const now = Math.floor(Date.now() / 1000);
127
+ const minDeadlineSeconds = this.policy.min_deadline_seconds ?? DEFAULT_MIN_DEADLINE_SECONDS;
128
+ if (req.deadline - now < minDeadlineSeconds) {
129
+ violations.push({
130
+ rule: 'deadline_too_tight',
131
+ detail: `tx.deadline - now = ${req.deadline - now}s, need ≥ ${minDeadlineSeconds}s`,
132
+ });
133
+ }
134
+ if (violations.length > 0) {
135
+ return { allowed: false, violations };
136
+ }
137
+ // Recommended quote: ideal unless buyer can't afford it, in which
138
+ // case we quote at maxPrice (still above floor — validated above).
139
+ // BigInt min/max via ternary since there's no Math.min for BigInt.
140
+ const ceilingBu = maxPriceBu < this.idealBaseUnits ? maxPriceBu : this.idealBaseUnits;
141
+ const recommendedBu = ceilingBu > this.floorBaseUnits ? ceilingBu : this.floorBaseUnits;
142
+ return {
143
+ allowed: true,
144
+ violations: [],
145
+ recommended_quote_amount_base_units: recommendedBu.toString(),
146
+ };
147
+ }
148
+ /**
149
+ * Decide whether to accept a buyer's counter-offer.
150
+ *
151
+ * Simple rule: accept if counter ≥ min_acceptable; reject otherwise.
152
+ * All arithmetic is BigInt on base units — no float drift.
153
+ * Phase 3 will extend this with `counter-counter` strategies.
154
+ */
155
+ evaluateCounter(counterAmountBaseUnits) {
156
+ let counter;
157
+ try {
158
+ counter = BigInt(counterAmountBaseUnits);
159
+ }
160
+ catch {
161
+ return { decision: 'reject', reason: `Invalid counter amount: ${counterAmountBaseUnits}` };
162
+ }
163
+ if (counter < this.floorBaseUnits) {
164
+ return {
165
+ decision: 'reject',
166
+ reason: `Counter ${formatFromBaseUnits(counter, this.currency)} below our floor ${formatFromBaseUnits(this.floorBaseUnits, this.currency)}`,
167
+ };
168
+ }
169
+ return {
170
+ decision: 'accept',
171
+ reason: `Counter ${formatFromBaseUnits(counter, this.currency)} meets our floor`,
172
+ };
173
+ }
174
+ /** Expose ttl as seconds for callers building QuoteMessage.expiresAt. */
175
+ get quoteTtlSeconds() {
176
+ return parseTtl(this.policy.quote_ttl);
177
+ }
178
+ /** Expose the policy's currency for orchestrator wiring. */
179
+ get policyCurrency() {
180
+ return this.currency;
181
+ }
182
+ /** Expose the policy's unit for orchestrator wiring + UI. */
183
+ get policyUnit() {
184
+ return this.policy.pricing.min_acceptable.unit;
185
+ }
186
+ }
187
+ exports.ProviderPolicyEngine = ProviderPolicyEngine;
188
+ /**
189
+ * Parse a short duration string like "15m", "1h", "30s" into seconds.
190
+ * Mirror of PolicyEngine.parseTtl (buyer side) so both sides use the
191
+ * same format in their JSON policies.
192
+ */
193
+ function parseTtl(ttl) {
194
+ const match = ttl.trim().match(/^(\d+)\s*([smh])$/i);
195
+ if (!match) {
196
+ throw new Error(`Invalid TTL format: "${ttl}" (expected e.g. "15m", "1h", "30s")`);
197
+ }
198
+ const n = Number(match[1]);
199
+ const unit = match[2].toLowerCase();
200
+ if (unit === 's')
201
+ return n;
202
+ if (unit === 'm')
203
+ return n * 60;
204
+ return n * 3600;
205
+ }
206
+ exports.parseTtl = parseTtl;
207
+ //# sourceMappingURL=ProviderPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderPolicy.js","sourceRoot":"","sources":["../../src/negotiation/ProviderPolicy.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAqFH,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,2EAA2E;AAC3E,MAAM,kBAAkB,GAA2B;IACjD,IAAI,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MAAM,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED,4DAA4D;IAC5D,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,6DAA6D;IAC7D,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC;IACjD,CAAC;CACF;AAhKD,oDAgKC;AAED;;;;GAIG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACrD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,sCAAsC,CAAC,CAAC;IACrF,CAAC;IACD,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACpC,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,CAAC,CAAC;IAC3B,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,CAAC,GAAG,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,IAAI,CAAC;AAClB,CAAC;AAVD,4BAUC"}
@@ -5,5 +5,12 @@ export type { ScoringWeights, CandidateStats, ScoredCandidate } from './Decision
5
5
  export { SessionStore } from './SessionStore';
6
6
  export type { SessionMapping } from './SessionStore';
7
7
  export { BuyerOrchestrator } from './BuyerOrchestrator';
8
- export type { NegotiationResult, RoundResult, OrchestratorConfig, ProgressEvent } from './BuyerOrchestrator';
8
+ export type { NegotiationResult, RoundResult, OrchestratorConfig, ProgressEvent, BuyerNegotiationContext, } from './BuyerOrchestrator';
9
+ export { verifyQuoteHashOnChain } from './verifyQuoteOnChain';
10
+ export type { VerifySource, VerifyOnChainResult } from './verifyQuoteOnChain';
11
+ export type { QuoteForEvaluation, QuoteEvaluation } from './DecisionEngine';
12
+ export { ProviderPolicyEngine, parseTtl as parseProviderTtl } from './ProviderPolicy';
13
+ export type { ProviderPolicy, ProviderPolicyViolation, ProviderPolicyResult, IncomingRequest } from './ProviderPolicy';
14
+ export { ProviderOrchestrator } from './ProviderOrchestrator';
15
+ export type { ProviderOrchestratorConfig, QuoteDecision, QuoteResult, CounterDecision } from './ProviderOrchestrator';
9
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/negotiation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE1G,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/negotiation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE1G,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE9E,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACtF,YAAY,EAAE,cAAc,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEvH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,0BAA0B,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BuyerOrchestrator = exports.SessionStore = exports.DecisionEngine = exports.PolicyEngine = void 0;
3
+ exports.ProviderOrchestrator = exports.parseProviderTtl = exports.ProviderPolicyEngine = exports.verifyQuoteHashOnChain = exports.BuyerOrchestrator = exports.SessionStore = exports.DecisionEngine = exports.PolicyEngine = void 0;
4
4
  var PolicyEngine_1 = require("./PolicyEngine");
5
5
  Object.defineProperty(exports, "PolicyEngine", { enumerable: true, get: function () { return PolicyEngine_1.PolicyEngine; } });
6
6
  var DecisionEngine_1 = require("./DecisionEngine");
@@ -9,4 +9,11 @@ var SessionStore_1 = require("./SessionStore");
9
9
  Object.defineProperty(exports, "SessionStore", { enumerable: true, get: function () { return SessionStore_1.SessionStore; } });
10
10
  var BuyerOrchestrator_1 = require("./BuyerOrchestrator");
11
11
  Object.defineProperty(exports, "BuyerOrchestrator", { enumerable: true, get: function () { return BuyerOrchestrator_1.BuyerOrchestrator; } });
12
+ var verifyQuoteOnChain_1 = require("./verifyQuoteOnChain");
13
+ Object.defineProperty(exports, "verifyQuoteHashOnChain", { enumerable: true, get: function () { return verifyQuoteOnChain_1.verifyQuoteHashOnChain; } });
14
+ var ProviderPolicy_1 = require("./ProviderPolicy");
15
+ Object.defineProperty(exports, "ProviderPolicyEngine", { enumerable: true, get: function () { return ProviderPolicy_1.ProviderPolicyEngine; } });
16
+ Object.defineProperty(exports, "parseProviderTtl", { enumerable: true, get: function () { return ProviderPolicy_1.parseTtl; } });
17
+ var ProviderOrchestrator_1 = require("./ProviderOrchestrator");
18
+ Object.defineProperty(exports, "ProviderOrchestrator", { enumerable: true, get: function () { return ProviderOrchestrator_1.ProviderOrchestrator; } });
12
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/negotiation/index.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAGrB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAGvB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAGrB,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/negotiation/index.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAGrB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAGvB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AAGrB,yDAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAS1B,2DAA8D;AAArD,4HAAA,sBAAsB,OAAA;AAK/B,mDAAsF;AAA7E,sHAAA,oBAAoB,OAAA;AAAE,kHAAA,QAAQ,OAAoB;AAG3D,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * verifyQuoteOnChain — cross-reference a received QuoteMessage against
3
+ * the hash a provider committed on-chain via `transitionState(QUOTED, …)`.
4
+ *
5
+ * AIP-2.1 §3.6 (legacy compatibility). Two matchers, tried in order:
6
+ *
7
+ * 1. `'aip2'` — canonical EIP-712 hash: keccak256(canonicalJson(
8
+ * QuoteMessage minus signature)). This is what
9
+ * AIP-2.1-compliant providers emit.
10
+ * 2. `'legacy'` — ad-hoc hash from Agent.ts:1035-1038 (the
11
+ * counter-offer pricing path that shipped before the
12
+ * formal AIP-2.1 submitQuote runtime method). Hash is:
13
+ * keccak256(JSON.stringify({
14
+ * txId, providerIdealPrice, actualEscrow, provider
15
+ * }))
16
+ * where `providerIdealPrice` is the provider's intended
17
+ * sell price in USDC base units (string), `actualEscrow`
18
+ * is tx.amount (the buyer-offered amount), and `provider`
19
+ * is the provider's EOA address. This path is used
20
+ * only when the SDK-authored hash can't be reconstructed
21
+ * (e.g. pre-AIP-2.1 agents still running).
22
+ *
23
+ * Both paths return a `{ source, match: true }` tagged result so the
24
+ * orchestrator + telemetry can see how many transactions are still
25
+ * coming through the legacy path. The legacy matcher is
26
+ * observability-tagged technical debt — planned removal in 2 SDK
27
+ * minor releases per the AIP-2.1 migration schedule.
28
+ *
29
+ * @module negotiation/verifyQuoteOnChain
30
+ */
31
+ import { QuoteMessage } from '../builders/QuoteBuilder';
32
+ export type VerifySource = 'aip2' | 'legacy';
33
+ export interface VerifyOnChainResult {
34
+ match: boolean;
35
+ /** Which matcher accepted the hash. Only set when `match === true`. */
36
+ source?: VerifySource;
37
+ /** Expected hash per the canonical matcher, for debugging mismatches. */
38
+ canonicalHash?: string;
39
+ /** Expected legacy hash (same purpose). */
40
+ legacyHash?: string;
41
+ }
42
+ /**
43
+ * Cross-reference an off-chain QuoteMessage against the hash stored on
44
+ * chain in `tx.metadata` (or equivalent — MockTransaction.quoteHash).
45
+ *
46
+ * Passing `providerAddress` and `actualEscrow` enables the legacy
47
+ * fallback. Omit them on fresh deployments where legacy is impossible.
48
+ *
49
+ * @param quote - signed QuoteMessage received off-chain
50
+ * @param onChainHash - hash committed on-chain at QUOTED
51
+ * @param providerAddress - provider's EOA address (needed for legacy)
52
+ * @param actualEscrow - tx.amount at QUOTED time (needed for legacy)
53
+ */
54
+ export declare function verifyQuoteHashOnChain(quote: QuoteMessage, onChainHash: string, opts?: {
55
+ providerAddress?: string;
56
+ actualEscrow?: string;
57
+ }): VerifyOnChainResult;
58
+ //# sourceMappingURL=verifyQuoteOnChain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyQuoteOnChain.d.ts","sourceRoot":"","sources":["../../src/negotiation/verifyQuoteOnChain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAgB,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAItE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE7C,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,OAAO,CAAC;IACf,uEAAuE;IACvE,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,yEAAyE;IACzE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,YAAY,EACnB,WAAW,EAAE,MAAM,EACnB,IAAI,GAAE;IACJ,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CAClB,GACL,mBAAmB,CAiCrB"}