@harrylabsj/kiwi 0.10.0 → 0.12.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 (531) hide show
  1. package/README.md +4 -1
  2. package/contracts/card-publication/0.1.2/request.schema.json +78 -0
  3. package/contracts/kiwi-contracts.lock.json +2 -2
  4. package/contracts/manifest.json +127 -1
  5. package/contracts/merchant-management/1.0/README.md +109 -0
  6. package/contracts/merchant-management/1.0/approval-decision.schema.json +16 -0
  7. package/contracts/merchant-management/1.0/approval-preview.schema.json +26 -0
  8. package/contracts/merchant-management/1.0/connector-delivery-manifest.schema.json +78 -0
  9. package/contracts/merchant-management/1.0/management-error.schema.json +30 -0
  10. package/contracts/merchant-management/1.0/operation-receipt.schema.json +28 -0
  11. package/contracts/merchant-management/1.0/runtime-management-descriptor.schema.json +33 -0
  12. package/contracts/merchant-management/1.0/runtime-status.schema.json +42 -0
  13. package/contracts/merchant-rfq/0.1.0/delivery-record.schema.json +206 -0
  14. package/contracts/merchant-rfq/0.1.0/fact-snapshot.schema.json +118 -0
  15. package/contracts/merchant-rfq/0.1.0/handoff-record.schema.json +251 -0
  16. package/contracts/merchant-rfq/0.1.0/pricing-input.schema.json +139 -0
  17. package/contracts/merchant-rfq/0.1.0/quote-revision.schema.json +153 -0
  18. package/contracts/merchant-rfq/0.1.0/release-request.schema.json +121 -0
  19. package/contracts/merchant-rfq/0.1.0/rfq-case.schema.json +357 -0
  20. package/contracts/merchant-rfq/0.1.0/source-record.schema.json +162 -0
  21. package/contracts/merchant-workbench/1.0/README.md +6 -0
  22. package/contracts/merchant-workbench/1.0/money.schema.json +19 -0
  23. package/contracts/merchant-workbench/1.0/problem.schema.json +73 -0
  24. package/contracts/runtime-binding/0.1.2/binding-request.schema.json +73 -0
  25. package/contracts/runtime-binding/0.1.2/claims.schema.json +100 -0
  26. package/contracts/runtime-binding/0.1.2/document.schema.json +163 -0
  27. package/contracts/vectors/binding-thumbprint.json +15 -0
  28. package/dist/a2a/node.d.ts +98 -2
  29. package/dist/a2a/node.js +252 -100
  30. package/dist/a2a/node.js.map +1 -1
  31. package/dist/a2a/server/errors.d.ts +8 -0
  32. package/dist/a2a/server/errors.js +8 -0
  33. package/dist/a2a/server/errors.js.map +1 -1
  34. package/dist/a2a/server/merchant-handler.d.ts +13 -0
  35. package/dist/a2a/server/merchant-handler.js +294 -47
  36. package/dist/a2a/server/merchant-handler.js.map +1 -1
  37. package/dist/a2a/server/pipeline.d.ts +15 -10
  38. package/dist/a2a/server/pipeline.js +49 -18
  39. package/dist/a2a/server/pipeline.js.map +1 -1
  40. package/dist/a2a/server/server.d.ts +20 -1
  41. package/dist/a2a/server/server.js +87 -13
  42. package/dist/a2a/server/server.js.map +1 -1
  43. package/dist/a2a/server/task-registry.d.ts +31 -11
  44. package/dist/a2a/server/task-registry.js +65 -20
  45. package/dist/a2a/server/task-registry.js.map +1 -1
  46. package/dist/a2a/server/types.d.ts +24 -0
  47. package/dist/a2a/signing-key.d.ts +6 -0
  48. package/dist/a2a/signing-key.js +12 -0
  49. package/dist/a2a/signing-key.js.map +1 -1
  50. package/dist/agent/buyer/buyer-tools.d.ts +2 -2
  51. package/dist/agent/buyer/buyer-tools.js +1 -1
  52. package/dist/agent/buyer/buyer-tools.js.map +1 -1
  53. package/dist/agent/chat-tools.d.ts +2 -11
  54. package/dist/agent/chat-tools.js.map +1 -1
  55. package/dist/agent/fake-chat-model.d.ts +3 -3
  56. package/dist/agent/fake-chat-model.js +3 -5
  57. package/dist/agent/fake-chat-model.js.map +1 -1
  58. package/dist/agent/host/web-renderer.d.ts +5 -0
  59. package/dist/agent/host/web-renderer.js +25 -6
  60. package/dist/agent/host/web-renderer.js.map +1 -1
  61. package/dist/agent/kernel-builder.js +4 -4
  62. package/dist/agent/kernel-builder.js.map +1 -1
  63. package/dist/agent/kernel.d.ts +15 -5
  64. package/dist/agent/kernel.js +149 -73
  65. package/dist/agent/kernel.js.map +1 -1
  66. package/dist/agent/kiwi-tool.d.ts +33 -0
  67. package/dist/agent/kiwi-tool.js +17 -0
  68. package/dist/agent/kiwi-tool.js.map +1 -0
  69. package/dist/agent/memory/schema.d.ts +1 -1
  70. package/dist/agent/memory/schema.js +190 -1
  71. package/dist/agent/memory/schema.js.map +1 -1
  72. package/dist/agent/memory/store.js +3 -1
  73. package/dist/agent/memory/store.js.map +1 -1
  74. package/dist/agent/merchant/action-candidate.d.ts +1 -0
  75. package/dist/agent/merchant/action-candidate.js +42 -24
  76. package/dist/agent/merchant/action-candidate.js.map +1 -1
  77. package/dist/agent/merchant/fake-merchant-client.d.ts +30 -1
  78. package/dist/agent/merchant/fake-merchant-client.js +151 -2
  79. package/dist/agent/merchant/fake-merchant-client.js.map +1 -1
  80. package/dist/agent/merchant/intelligence/default-backend.js +2 -2
  81. package/dist/agent/merchant/intelligence/default-backend.js.map +1 -1
  82. package/dist/agent/merchant/merchant-client.d.ts +38 -5
  83. package/dist/agent/merchant/merchant-client.js +103 -8
  84. package/dist/agent/merchant/merchant-client.js.map +1 -1
  85. package/dist/agent/merchant/merchant-tools.d.ts +2 -17
  86. package/dist/agent/merchant/merchant-tools.js.map +1 -1
  87. package/dist/agent/merchant/types.d.ts +107 -0
  88. package/dist/agent/merchant/types.js +69 -0
  89. package/dist/agent/merchant/types.js.map +1 -1
  90. package/dist/agent/negotiation-chat.d.ts +3 -2
  91. package/dist/agent/negotiation-chat.js.map +1 -1
  92. package/dist/agent/session.d.ts +15 -3
  93. package/dist/agent/session.js +114 -122
  94. package/dist/agent/session.js.map +1 -1
  95. package/dist/agent/skills/tools.d.ts +2 -2
  96. package/dist/agent/skills/tools.js.map +1 -1
  97. package/dist/alerts/external-delivery.d.ts +78 -0
  98. package/dist/alerts/external-delivery.js +256 -0
  99. package/dist/alerts/external-delivery.js.map +1 -0
  100. package/dist/auth/app-oauth-callback.d.ts +38 -0
  101. package/dist/auth/app-oauth-callback.js +119 -0
  102. package/dist/auth/app-oauth-callback.js.map +1 -0
  103. package/dist/auth/merchant-oauth.js +15 -41
  104. package/dist/auth/merchant-oauth.js.map +1 -1
  105. package/dist/auth/merchant-pairing.d.ts +51 -0
  106. package/dist/auth/merchant-pairing.js +66 -16
  107. package/dist/auth/merchant-pairing.js.map +1 -1
  108. package/dist/auth/merchant-sessions.d.ts +7 -1
  109. package/dist/auth/merchant-sessions.js +25 -3
  110. package/dist/auth/merchant-sessions.js.map +1 -1
  111. package/dist/buyer-core/build-service.d.ts +3 -1
  112. package/dist/buyer-core/build-service.js +4 -1
  113. package/dist/buyer-core/build-service.js.map +1 -1
  114. package/dist/buyer-core/merchant-index.d.ts +20 -0
  115. package/dist/buyer-core/merchant-index.js +83 -12
  116. package/dist/buyer-core/merchant-index.js.map +1 -1
  117. package/dist/buyer-core/network-search.d.ts +92 -0
  118. package/dist/buyer-core/network-search.js +144 -0
  119. package/dist/buyer-core/network-search.js.map +1 -0
  120. package/dist/buyer-core/product-summary.d.ts +71 -0
  121. package/dist/buyer-core/product-summary.js +63 -0
  122. package/dist/buyer-core/product-summary.js.map +1 -0
  123. package/dist/buyer-core/service.d.ts +26 -0
  124. package/dist/buyer-core/service.js +38 -8
  125. package/dist/buyer-core/service.js.map +1 -1
  126. package/dist/cli.d.ts +5 -1
  127. package/dist/cli.js +260 -274
  128. package/dist/cli.js.map +1 -1
  129. package/dist/cloud/binding/audit.d.ts +72 -0
  130. package/dist/cloud/binding/audit.js +137 -0
  131. package/dist/cloud/binding/audit.js.map +1 -0
  132. package/dist/cloud/binding/enrollment-challenge.d.ts +37 -0
  133. package/dist/cloud/binding/enrollment-challenge.js +153 -0
  134. package/dist/cloud/binding/enrollment-challenge.js.map +1 -0
  135. package/dist/cloud/binding/enrollment-heartbeat.d.ts +26 -0
  136. package/dist/cloud/binding/enrollment-heartbeat.js +146 -0
  137. package/dist/cloud/binding/enrollment-heartbeat.js.map +1 -0
  138. package/dist/cloud/binding/enrollment-key-recovery.d.ts +27 -0
  139. package/dist/cloud/binding/enrollment-key-recovery.js +127 -0
  140. package/dist/cloud/binding/enrollment-key-recovery.js.map +1 -0
  141. package/dist/cloud/binding/issuance.d.ts +76 -0
  142. package/dist/cloud/binding/issuance.js +121 -0
  143. package/dist/cloud/binding/issuance.js.map +1 -0
  144. package/dist/cloud/binding/proofs.d.ts +110 -0
  145. package/dist/cloud/binding/proofs.js +200 -0
  146. package/dist/cloud/binding/proofs.js.map +1 -0
  147. package/dist/cloud/binding/runtime-challenge.d.ts +48 -0
  148. package/dist/cloud/binding/runtime-challenge.js +185 -0
  149. package/dist/cloud/binding/runtime-challenge.js.map +1 -0
  150. package/dist/cloud/bootstrap.d.ts +63 -0
  151. package/dist/cloud/bootstrap.js +1161 -0
  152. package/dist/cloud/bootstrap.js.map +1 -0
  153. package/dist/cloud/catalog-client.d.ts +305 -0
  154. package/dist/cloud/catalog-client.js +962 -0
  155. package/dist/cloud/catalog-client.js.map +1 -0
  156. package/dist/cloud/config.d.ts +103 -0
  157. package/dist/cloud/config.js +274 -0
  158. package/dist/cloud/config.js.map +1 -0
  159. package/dist/cloud/http-router.d.ts +63 -0
  160. package/dist/cloud/http-router.js +135 -0
  161. package/dist/cloud/http-router.js.map +1 -0
  162. package/dist/cloud/listing-publisher.d.ts +45 -0
  163. package/dist/cloud/listing-publisher.js +244 -0
  164. package/dist/cloud/listing-publisher.js.map +1 -0
  165. package/dist/cloud/main.d.ts +16 -0
  166. package/dist/cloud/main.js +64 -0
  167. package/dist/cloud/main.js.map +1 -0
  168. package/dist/cloud/merchant-connect.d.ts +47 -0
  169. package/dist/cloud/merchant-connect.js +331 -0
  170. package/dist/cloud/merchant-connect.js.map +1 -0
  171. package/dist/cloud/merchant-identity.d.ts +14 -0
  172. package/dist/cloud/merchant-identity.js +76 -0
  173. package/dist/cloud/merchant-identity.js.map +1 -0
  174. package/dist/cloud/onboarding/catalog-pipeline.d.ts +135 -0
  175. package/dist/cloud/onboarding/catalog-pipeline.js +454 -0
  176. package/dist/cloud/onboarding/catalog-pipeline.js.map +1 -0
  177. package/dist/cloud/onboarding/local-fallback.d.ts +86 -0
  178. package/dist/cloud/onboarding/local-fallback.js +98 -0
  179. package/dist/cloud/onboarding/local-fallback.js.map +1 -0
  180. package/dist/cloud/onboarding/steps.d.ts +95 -0
  181. package/dist/cloud/onboarding/steps.js +175 -0
  182. package/dist/cloud/onboarding/steps.js.map +1 -0
  183. package/dist/cloud/onboarding/store.d.ts +136 -0
  184. package/dist/cloud/onboarding/store.js +472 -0
  185. package/dist/cloud/onboarding/store.js.map +1 -0
  186. package/dist/cloud/onboarding/types.d.ts +132 -0
  187. package/dist/cloud/onboarding/types.js +152 -0
  188. package/dist/cloud/onboarding/types.js.map +1 -0
  189. package/dist/cloud/product-import-tabular.d.ts +100 -0
  190. package/dist/cloud/product-import-tabular.js +1073 -0
  191. package/dist/cloud/product-import-tabular.js.map +1 -0
  192. package/dist/cloud/product-source.d.ts +104 -0
  193. package/dist/cloud/product-source.js +276 -0
  194. package/dist/cloud/product-source.js.map +1 -0
  195. package/dist/cloud/readiness.d.ts +49 -0
  196. package/dist/cloud/readiness.js +54 -0
  197. package/dist/cloud/readiness.js.map +1 -0
  198. package/dist/commerce/data-source.d.ts +5 -0
  199. package/dist/commerce/data-source.js.map +1 -1
  200. package/dist/config/profile.d.ts +4 -0
  201. package/dist/config/profile.js +14 -0
  202. package/dist/config/profile.js.map +1 -1
  203. package/dist/config/provider-kind.d.ts +26 -0
  204. package/dist/config/provider-kind.js +19 -0
  205. package/dist/config/provider-kind.js.map +1 -0
  206. package/dist/contracts/cloud-contracts.d.ts +23 -0
  207. package/dist/contracts/cloud-contracts.js +90 -0
  208. package/dist/contracts/cloud-contracts.js.map +1 -0
  209. package/dist/counterparty/a2a-direct/index.d.ts +3 -0
  210. package/dist/counterparty/a2a-direct/index.js +22 -6
  211. package/dist/counterparty/a2a-direct/index.js.map +1 -1
  212. package/dist/counterparty/registry.d.ts +2 -0
  213. package/dist/counterparty/registry.js +2 -0
  214. package/dist/counterparty/registry.js.map +1 -1
  215. package/dist/counterparty/shopping-cli-hosted/index.d.ts +3 -0
  216. package/dist/counterparty/shopping-cli-hosted/index.js +9 -2
  217. package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -1
  218. package/dist/discovery/catalog-source/buyer-follows.js +2 -2
  219. package/dist/discovery/catalog-source/buyer-follows.js.map +1 -1
  220. package/dist/discovery/catalog-source/cloud-card.d.ts +184 -0
  221. package/dist/discovery/catalog-source/cloud-card.js +385 -0
  222. package/dist/discovery/catalog-source/cloud-card.js.map +1 -0
  223. package/dist/discovery/catalog-source/cloud-hosting.d.ts +71 -0
  224. package/dist/discovery/catalog-source/cloud-hosting.js +70 -0
  225. package/dist/discovery/catalog-source/cloud-hosting.js.map +1 -0
  226. package/dist/discovery/catalog-source/errors.d.ts +12 -2
  227. package/dist/discovery/catalog-source/errors.js +14 -1
  228. package/dist/discovery/catalog-source/errors.js.map +1 -1
  229. package/dist/discovery/catalog-source/index.d.ts +2 -0
  230. package/dist/discovery/catalog-source/index.js +2 -0
  231. package/dist/discovery/catalog-source/index.js.map +1 -1
  232. package/dist/discovery/catalog-source/kiwi-source.js +2 -2
  233. package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
  234. package/dist/discovery/catalog-source/merchant-publications.d.ts +2 -2
  235. package/dist/discovery/catalog-source/merchant-publications.js +10 -5
  236. package/dist/discovery/catalog-source/merchant-publications.js.map +1 -1
  237. package/dist/discovery/catalog-source/source.js +2 -2
  238. package/dist/discovery/catalog-source/source.js.map +1 -1
  239. package/dist/discovery/merchant-subscriptions.d.ts +45 -0
  240. package/dist/discovery/merchant-subscriptions.js +319 -0
  241. package/dist/discovery/merchant-subscriptions.js.map +1 -0
  242. package/dist/discovery/resolve.d.ts +38 -0
  243. package/dist/discovery/resolve.js +100 -7
  244. package/dist/discovery/resolve.js.map +1 -1
  245. package/dist/fanout/orchestrator.d.ts +2 -0
  246. package/dist/fanout/orchestrator.js +4 -1
  247. package/dist/fanout/orchestrator.js.map +1 -1
  248. package/dist/handoff/ledger.d.ts +1 -0
  249. package/dist/handoff/ledger.js +3 -0
  250. package/dist/handoff/ledger.js.map +1 -1
  251. package/dist/handoff/transaction.js +1 -1
  252. package/dist/handoff/transaction.js.map +1 -1
  253. package/dist/http/merchant-engagement-api.d.ts +10 -0
  254. package/dist/http/merchant-engagement-api.js +138 -0
  255. package/dist/http/merchant-engagement-api.js.map +1 -0
  256. package/dist/http/merchant-feed-api.d.ts +7 -0
  257. package/dist/http/merchant-feed-api.js +129 -0
  258. package/dist/http/merchant-feed-api.js.map +1 -0
  259. package/dist/http/merchant-follow-api.d.ts +15 -0
  260. package/dist/http/merchant-follow-api.js +192 -0
  261. package/dist/http/merchant-follow-api.js.map +1 -0
  262. package/dist/http/merchant-management/api.d.ts +258 -0
  263. package/dist/http/merchant-management/api.js +3022 -0
  264. package/dist/http/merchant-management/api.js.map +1 -0
  265. package/dist/http/merchant-management/draft-store.d.ts +51 -0
  266. package/dist/http/merchant-management/draft-store.js +95 -0
  267. package/dist/http/merchant-management/draft-store.js.map +1 -0
  268. package/dist/http/merchant-management/event-projection.d.ts +41 -0
  269. package/dist/http/merchant-management/event-projection.js +190 -0
  270. package/dist/http/merchant-management/event-projection.js.map +1 -0
  271. package/dist/http/merchant-management/operation-store.d.ts +97 -0
  272. package/dist/http/merchant-management/operation-store.js +252 -0
  273. package/dist/http/merchant-management/operation-store.js.map +1 -0
  274. package/dist/http/merchant-management/page.d.ts +29 -0
  275. package/dist/http/merchant-management/page.js +641 -0
  276. package/dist/http/merchant-management/page.js.map +1 -0
  277. package/dist/http/merchant-management/problem-client.d.ts +19 -0
  278. package/dist/http/merchant-management/problem-client.js +55 -0
  279. package/dist/http/merchant-management/problem-client.js.map +1 -0
  280. package/dist/http/merchant-management/problem.d.ts +74 -0
  281. package/dist/http/merchant-management/problem.js +112 -0
  282. package/dist/http/merchant-management/problem.js.map +1 -0
  283. package/dist/http/merchant-management/reconciliation-worker.d.ts +95 -0
  284. package/dist/http/merchant-management/reconciliation-worker.js +397 -0
  285. package/dist/http/merchant-management/reconciliation-worker.js.map +1 -0
  286. package/dist/http/merchant-management/service-state.d.ts +86 -0
  287. package/dist/http/merchant-management/service-state.js +217 -0
  288. package/dist/http/merchant-management/service-state.js.map +1 -0
  289. package/dist/http/merchant-management/trusted-page.d.ts +3 -0
  290. package/dist/http/merchant-management/trusted-page.js +73 -0
  291. package/dist/http/merchant-management/trusted-page.js.map +1 -0
  292. package/dist/http/merchant-management/webauthn-confirmation.d.ts +148 -0
  293. package/dist/http/merchant-management/webauthn-confirmation.js +517 -0
  294. package/dist/http/merchant-management/webauthn-confirmation.js.map +1 -0
  295. package/dist/http/merchant-privacy-api.d.ts +9 -0
  296. package/dist/http/merchant-privacy-api.js +96 -0
  297. package/dist/http/merchant-privacy-api.js.map +1 -0
  298. package/dist/mcp/merchant-rfq-resources.d.ts +37 -0
  299. package/dist/mcp/merchant-rfq-resources.js +132 -0
  300. package/dist/mcp/merchant-rfq-resources.js.map +1 -0
  301. package/dist/mcp/merchant-rfq-tools.d.ts +61 -0
  302. package/dist/mcp/merchant-rfq-tools.js +584 -0
  303. package/dist/mcp/merchant-rfq-tools.js.map +1 -0
  304. package/dist/mcp/merchant-runtime-assembly.d.ts +74 -0
  305. package/dist/mcp/merchant-runtime-assembly.js +476 -0
  306. package/dist/mcp/merchant-runtime-assembly.js.map +1 -0
  307. package/dist/mcp/merchant-server.d.ts +66 -1
  308. package/dist/mcp/merchant-server.js +260 -23
  309. package/dist/mcp/merchant-server.js.map +1 -1
  310. package/dist/mcp/tools.js +8 -2
  311. package/dist/mcp/tools.js.map +1 -1
  312. package/dist/merchant/application/actor.d.ts +85 -0
  313. package/dist/merchant/application/actor.js +162 -0
  314. package/dist/merchant/application/actor.js.map +1 -0
  315. package/dist/merchant/application/money.d.ts +35 -0
  316. package/dist/merchant/application/money.js +124 -0
  317. package/dist/merchant/application/money.js.map +1 -0
  318. package/dist/merchant/application/service.d.ts +228 -0
  319. package/dist/merchant/application/service.js +262 -0
  320. package/dist/merchant/application/service.js.map +1 -0
  321. package/dist/merchant/clock-safety.d.ts +50 -0
  322. package/dist/merchant/clock-safety.js +153 -0
  323. package/dist/merchant/clock-safety.js.map +1 -0
  324. package/dist/merchant/engagement-store.d.ts +32 -0
  325. package/dist/merchant/engagement-store.js +119 -0
  326. package/dist/merchant/engagement-store.js.map +1 -0
  327. package/dist/merchant/exact-product-executors.d.ts +11 -0
  328. package/dist/merchant/exact-product-executors.js +132 -0
  329. package/dist/merchant/exact-product-executors.js.map +1 -0
  330. package/dist/merchant/feed-executors.d.ts +17 -0
  331. package/dist/merchant/feed-executors.js +151 -0
  332. package/dist/merchant/feed-executors.js.map +1 -0
  333. package/dist/merchant/feed-store.d.ts +141 -0
  334. package/dist/merchant/feed-store.js +496 -0
  335. package/dist/merchant/feed-store.js.map +1 -0
  336. package/dist/merchant/follow-store.d.ts +66 -0
  337. package/dist/merchant/follow-store.js +295 -0
  338. package/dist/merchant/follow-store.js.map +1 -0
  339. package/dist/merchant/grant-executors.d.ts +11 -0
  340. package/dist/merchant/grant-executors.js +136 -0
  341. package/dist/merchant/grant-executors.js.map +1 -0
  342. package/dist/merchant/grant-store.d.ts +125 -0
  343. package/dist/merchant/grant-store.js +313 -0
  344. package/dist/merchant/grant-store.js.map +1 -0
  345. package/dist/merchant/inventory-executors.d.ts +47 -0
  346. package/dist/merchant/inventory-executors.js +91 -0
  347. package/dist/merchant/inventory-executors.js.map +1 -0
  348. package/dist/merchant/listing-executors.d.ts +51 -0
  349. package/dist/merchant/listing-executors.js +100 -0
  350. package/dist/merchant/listing-executors.js.map +1 -0
  351. package/dist/merchant/negotiation-observer.d.ts +92 -0
  352. package/dist/merchant/negotiation-observer.js +278 -0
  353. package/dist/merchant/negotiation-observer.js.map +1 -0
  354. package/dist/merchant/operation-receipts.d.ts +57 -0
  355. package/dist/merchant/operation-receipts.js +138 -0
  356. package/dist/merchant/operation-receipts.js.map +1 -0
  357. package/dist/merchant/operations-report.d.ts +85 -0
  358. package/dist/merchant/operations-report.js +227 -0
  359. package/dist/merchant/operations-report.js.map +1 -0
  360. package/dist/merchant/promotion-broadcast-recovery.d.ts +22 -0
  361. package/dist/merchant/promotion-broadcast-recovery.js +74 -0
  362. package/dist/merchant/promotion-broadcast-recovery.js.map +1 -0
  363. package/dist/merchant/promotion-broadcast-workflow.d.ts +42 -0
  364. package/dist/merchant/promotion-broadcast-workflow.js +171 -0
  365. package/dist/merchant/promotion-broadcast-workflow.js.map +1 -0
  366. package/dist/merchant/promotion-executors.d.ts +18 -0
  367. package/dist/merchant/promotion-executors.js +133 -0
  368. package/dist/merchant/promotion-executors.js.map +1 -0
  369. package/dist/merchant/promotion-store.d.ts +114 -0
  370. package/dist/merchant/promotion-store.js +325 -0
  371. package/dist/merchant/promotion-store.js.map +1 -0
  372. package/dist/merchant/promotion-time.d.ts +19 -0
  373. package/dist/merchant/promotion-time.js +162 -0
  374. package/dist/merchant/promotion-time.js.map +1 -0
  375. package/dist/merchant/quote-calculator.d.ts +32 -0
  376. package/dist/merchant/quote-calculator.js +70 -0
  377. package/dist/merchant/quote-calculator.js.map +1 -0
  378. package/dist/merchant/service-control-executors.d.ts +15 -0
  379. package/dist/merchant/service-control-executors.js +52 -0
  380. package/dist/merchant/service-control-executors.js.map +1 -0
  381. package/dist/merchant/stats-store.d.ts +5 -0
  382. package/dist/merchant/stats-store.js +18 -0
  383. package/dist/merchant/stats-store.js.map +1 -1
  384. package/dist/merchant/workbench-service.d.ts +1 -0
  385. package/dist/merchant/workbench-service.js +11 -1
  386. package/dist/merchant/workbench-service.js.map +1 -1
  387. package/dist/merchant-admin/pending-page.d.ts +104 -0
  388. package/dist/merchant-admin/pending-page.js +20 -0
  389. package/dist/merchant-admin/pending-page.js.map +1 -1
  390. package/dist/merchant-admin/rfq-page.d.ts +105 -0
  391. package/dist/merchant-admin/rfq-page.js +176 -0
  392. package/dist/merchant-admin/rfq-page.js.map +1 -0
  393. package/dist/merchant-core/commands.d.ts +27 -0
  394. package/dist/merchant-core/commands.js +90 -1
  395. package/dist/merchant-core/commands.js.map +1 -1
  396. package/dist/merchant-core/executor.d.ts +27 -3
  397. package/dist/merchant-core/executor.js +13 -4
  398. package/dist/merchant-core/executor.js.map +1 -1
  399. package/dist/merchant-core/rfq/artifacts.d.ts +78 -0
  400. package/dist/merchant-core/rfq/artifacts.js +219 -0
  401. package/dist/merchant-core/rfq/artifacts.js.map +1 -0
  402. package/dist/merchant-core/rfq/data-source-adapter.d.ts +49 -0
  403. package/dist/merchant-core/rfq/data-source-adapter.js +128 -0
  404. package/dist/merchant-core/rfq/data-source-adapter.js.map +1 -0
  405. package/dist/merchant-core/rfq/delivery.d.ts +43 -0
  406. package/dist/merchant-core/rfq/delivery.js +57 -0
  407. package/dist/merchant-core/rfq/delivery.js.map +1 -0
  408. package/dist/merchant-core/rfq/fact-resolver.d.ts +76 -0
  409. package/dist/merchant-core/rfq/fact-resolver.js +220 -0
  410. package/dist/merchant-core/rfq/fact-resolver.js.map +1 -0
  411. package/dist/merchant-core/rfq/handoff.d.ts +54 -0
  412. package/dist/merchant-core/rfq/handoff.js +71 -0
  413. package/dist/merchant-core/rfq/handoff.js.map +1 -0
  414. package/dist/merchant-core/rfq/policy.d.ts +77 -0
  415. package/dist/merchant-core/rfq/policy.js +104 -0
  416. package/dist/merchant-core/rfq/policy.js.map +1 -0
  417. package/dist/merchant-core/rfq/pricing.d.ts +48 -0
  418. package/dist/merchant-core/rfq/pricing.js +150 -0
  419. package/dist/merchant-core/rfq/pricing.js.map +1 -0
  420. package/dist/merchant-core/rfq/quote-revisions.d.ts +52 -0
  421. package/dist/merchant-core/rfq/quote-revisions.js +126 -0
  422. package/dist/merchant-core/rfq/quote-revisions.js.map +1 -0
  423. package/dist/merchant-core/rfq/release-coordinator.d.ts +99 -0
  424. package/dist/merchant-core/rfq/release-coordinator.js +355 -0
  425. package/dist/merchant-core/rfq/release-coordinator.js.map +1 -0
  426. package/dist/merchant-core/rfq/repository.d.ts +398 -0
  427. package/dist/merchant-core/rfq/repository.js +855 -0
  428. package/dist/merchant-core/rfq/repository.js.map +1 -0
  429. package/dist/merchant-core/rfq/service.d.ts +398 -0
  430. package/dist/merchant-core/rfq/service.js +1036 -0
  431. package/dist/merchant-core/rfq/service.js.map +1 -0
  432. package/dist/merchant-core/rfq/source-records.d.ts +97 -0
  433. package/dist/merchant-core/rfq/source-records.js +349 -0
  434. package/dist/merchant-core/rfq/source-records.js.map +1 -0
  435. package/dist/merchant-core/rfq/types.d.ts +197 -0
  436. package/dist/merchant-core/rfq/types.js +110 -0
  437. package/dist/merchant-core/rfq/types.js.map +1 -0
  438. package/dist/merchant-core/service.d.ts +118 -1
  439. package/dist/merchant-core/service.js +202 -7
  440. package/dist/merchant-core/service.js.map +1 -1
  441. package/dist/merchant-core/storage/clock-skew-alerts.d.ts +21 -0
  442. package/dist/merchant-core/storage/clock-skew-alerts.js +67 -0
  443. package/dist/merchant-core/storage/clock-skew-alerts.js.map +1 -0
  444. package/dist/merchant-core/storage/leased-job.d.ts +42 -0
  445. package/dist/merchant-core/storage/leased-job.js +38 -0
  446. package/dist/merchant-core/storage/leased-job.js.map +1 -0
  447. package/dist/merchant-core/storage/operation-lifecycle.d.ts +78 -0
  448. package/dist/merchant-core/storage/operation-lifecycle.js +111 -0
  449. package/dist/merchant-core/storage/operation-lifecycle.js.map +1 -0
  450. package/dist/merchant-core/storage/redact.d.ts +29 -0
  451. package/dist/merchant-core/storage/redact.js +34 -0
  452. package/dist/merchant-core/storage/redact.js.map +1 -0
  453. package/dist/merchant-core/storage/schema.d.ts +24 -0
  454. package/dist/merchant-core/storage/schema.js +22 -0
  455. package/dist/merchant-core/storage/schema.js.map +1 -0
  456. package/dist/merchant-core/storage/transaction.d.ts +47 -0
  457. package/dist/merchant-core/storage/transaction.js +28 -0
  458. package/dist/merchant-core/storage/transaction.js.map +1 -0
  459. package/dist/merchant-gateway/catalog-publications.d.ts +28 -0
  460. package/dist/merchant-gateway/catalog-publications.js +69 -0
  461. package/dist/merchant-gateway/catalog-publications.js.map +1 -1
  462. package/dist/merchant-gateway/catalog-tools.js +20 -0
  463. package/dist/merchant-gateway/catalog-tools.js.map +1 -1
  464. package/dist/merchant-gateway/entry-server.js +10 -0
  465. package/dist/merchant-gateway/entry-server.js.map +1 -1
  466. package/dist/negotiation/domain/objects.d.ts +7 -0
  467. package/dist/negotiation/domain/objects.js +8 -0
  468. package/dist/negotiation/domain/objects.js.map +1 -1
  469. package/dist/negotiation/idempotency/store.d.ts +23 -0
  470. package/dist/negotiation/idempotency/store.js +72 -1
  471. package/dist/negotiation/idempotency/store.js.map +1 -1
  472. package/dist/negotiation/idempotency/types.d.ts +16 -0
  473. package/dist/negotiation/idempotency/types.js +2 -0
  474. package/dist/negotiation/idempotency/types.js.map +1 -1
  475. package/dist/negotiation/lease/store.d.ts +18 -22
  476. package/dist/negotiation/lease/store.js +152 -88
  477. package/dist/negotiation/lease/store.js.map +1 -1
  478. package/dist/negotiation/ledger/event.d.ts +6 -0
  479. package/dist/negotiation/ledger/event.js +1 -0
  480. package/dist/negotiation/ledger/event.js.map +1 -1
  481. package/dist/negotiation/ledger/index.d.ts +4 -2
  482. package/dist/negotiation/ledger/index.js +1 -0
  483. package/dist/negotiation/ledger/index.js.map +1 -1
  484. package/dist/negotiation/ledger/payload-segments.d.ts +51 -0
  485. package/dist/negotiation/ledger/payload-segments.js +247 -0
  486. package/dist/negotiation/ledger/payload-segments.js.map +1 -0
  487. package/dist/negotiation/ledger/store.d.ts +34 -0
  488. package/dist/negotiation/ledger/store.js +162 -0
  489. package/dist/negotiation/ledger/store.js.map +1 -1
  490. package/dist/negotiation/recovery/recover.js +1 -1
  491. package/dist/negotiation/recovery/recover.js.map +1 -1
  492. package/dist/privacy/ledger-payload-deletion.d.ts +10 -0
  493. package/dist/privacy/ledger-payload-deletion.js +31 -0
  494. package/dist/privacy/ledger-payload-deletion.js.map +1 -0
  495. package/dist/privacy/local-backup-deletion.d.ts +13 -0
  496. package/dist/privacy/local-backup-deletion.js +115 -0
  497. package/dist/privacy/local-backup-deletion.js.map +1 -0
  498. package/dist/privacy/workbench-retention.d.ts +105 -0
  499. package/dist/privacy/workbench-retention.js +501 -0
  500. package/dist/privacy/workbench-retention.js.map +1 -0
  501. package/dist/product-cli.d.ts +2 -2
  502. package/dist/product-cli.js +24 -9
  503. package/dist/product-cli.js.map +1 -1
  504. package/dist/product-init.d.ts +4 -1
  505. package/dist/product-init.js +39 -11
  506. package/dist/product-init.js.map +1 -1
  507. package/dist/product-publish.d.ts +8 -2
  508. package/dist/product-publish.js +222 -142
  509. package/dist/product-publish.js.map +1 -1
  510. package/dist/runtime/fake-model.js +9 -3
  511. package/dist/runtime/fake-model.js.map +1 -1
  512. package/dist/runtime/model.d.ts +1 -1
  513. package/dist/runtime/model.js +3 -3
  514. package/dist/runtime/model.js.map +1 -1
  515. package/dist/trust/binding/claims.d.ts +92 -0
  516. package/dist/trust/binding/claims.js +175 -0
  517. package/dist/trust/binding/claims.js.map +1 -0
  518. package/dist/trust/binding/thumbprint.d.ts +35 -0
  519. package/dist/trust/binding/thumbprint.js +88 -0
  520. package/dist/trust/binding/thumbprint.js.map +1 -0
  521. package/dist/trust/binding/verify.d.ts +84 -0
  522. package/dist/trust/binding/verify.js +121 -0
  523. package/dist/trust/binding/verify.js.map +1 -0
  524. package/dist/trust/identity/auth-verifier.d.ts +9 -0
  525. package/dist/trust/identity/auth-verifier.js +10 -2
  526. package/dist/trust/identity/auth-verifier.js.map +1 -1
  527. package/dist/trust/identity/jws.d.ts +22 -1
  528. package/dist/trust/identity/jws.js +31 -2
  529. package/dist/trust/identity/jws.js.map +1 -1
  530. package/package.json +17 -6
  531. package/skills/kiwi-buyer/SKILL.md +33 -2
@@ -19,6 +19,8 @@ import { finalizeEnvelope } from "../../negotiation/domain/envelope.js";
19
19
  import { contentDigest } from "../../negotiation/jcs.js";
20
20
  import { evaluateConditionalOffer } from "../../negotiation/condition/evaluator.js";
21
21
  import { toMinorUnits as losslessToMinorUnits } from "../../protocol/legacy-shopping-negotiation/money.js";
22
+ import { WORKBENCH_CURRENCY_TABLE_VERSION } from "../../merchant/application/money.js";
23
+ import { calculateWorkbenchQuote } from "../../merchant/quote-calculator.js";
22
24
  import { createNegotiationPhase, isTerminalPhase, transitionPhase, } from "../../negotiation/state/phase.js";
23
25
  export const MERCHANT_CAPABILITY = "com.harrylabsj.kiwi.shopping.negotiation";
24
26
  export const MERCHANT_SKU = "SKU-001";
@@ -91,6 +93,11 @@ function seedEnvelope(seed) {
91
93
  * 报价可被无限期接受)。24h 窗口,accept 时校验(offer_expired 拒绝)。 */
92
94
  export const OFFER_VALIDITY_MS = 24 * 60 * 60 * 1000;
93
95
  function offerTerms(opts, now) {
96
+ const defaultValidUntil = Date.parse(now) + OFFER_VALIDITY_MS;
97
+ const cap = opts.validUntilCap === undefined ? undefined : Date.parse(opts.validUntilCap);
98
+ const validUntil = cap !== undefined && Number.isFinite(cap)
99
+ ? Math.min(defaultValidUntil, cap)
100
+ : defaultValidUntil;
94
101
  return {
95
102
  items: [
96
103
  {
@@ -108,7 +115,7 @@ function offerTerms(opts, now) {
108
115
  ...(opts.handoff_destination !== undefined
109
116
  ? { handoff_destination: opts.handoff_destination }
110
117
  : {}),
111
- valid_until: new Date(Date.parse(now) + OFFER_VALIDITY_MS).toISOString(),
118
+ valid_until: new Date(validUntil).toISOString(),
112
119
  };
113
120
  }
114
121
  function buildAgreement(input) {
@@ -141,16 +148,21 @@ const textReply = (text, taskState = "working") => ({
141
148
  /** 商品源不可用(源宕机/未知 SKU/价格 lossy)且未开 demo 回退时抛出。
142
149
  * handle 层捕获后 decline(temporarily_unavailable),而非报演示价。 */
143
150
  class ProductSourceUnavailableError extends Error {
151
+ sourceCode;
144
152
  constructor(sku, cause) {
145
153
  super(`商品源不可用(${sku}):${cause instanceof Error ? cause.message : String(cause ?? "")}`.trim());
146
154
  this.name = "ProductSourceUnavailableError";
155
+ this.sourceCode = cause !== null && typeof cause === "object" && typeof cause.code === "string"
156
+ ? cause.code
157
+ : undefined;
147
158
  }
148
159
  }
149
160
  /** 商业拒绝(offer 未知/已关闭/terms_digest 不匹配/终态重开)。
150
161
  * decline 消息由 pipeline 按 reason_code 自动构造。 */
151
- const declineReply = (reasonCode = "state_conflict") => ({
162
+ const declineReply = (reasonCode = "state_conflict", message) => ({
152
163
  kind: "declined",
153
164
  reasonCode,
165
+ ...(message !== undefined ? { message } : {}),
154
166
  taskState: "completed",
155
167
  });
156
168
  const envelopeReply = (reply) => ({
@@ -168,7 +180,9 @@ export function createMerchantHandler(options) {
168
180
  const offerPriceMinor = options.offerPriceMinor ?? MERCHANT_OFFER_PRICE_MINOR;
169
181
  const allowDemoPriceFallback = options.allowDemoPriceFallback ?? false;
170
182
  // BUG-07:merchantPolicy 支持静态值或 provider——每请求解析运行中策略。
171
- const policyOf = () => typeof options.merchantPolicy === "function" ? options.merchantPolicy() : options.merchantPolicy;
183
+ const policyOf = () => typeof options.merchantPolicy === "function"
184
+ ? options.merchantPolicy()
185
+ : options.merchantPolicy;
172
186
  const conditionalByNegotiation = new Map();
173
187
  // 审查 P2-D:终态(AGREEMENT_REACHED / WITHDRAWN / DECLINED / CANCELLED)
174
188
  // 不得以同一 negotiation_id 重开(§17.4/§21.2)——运行时此前无任何终态
@@ -226,9 +240,19 @@ export function createMerchantHandler(options) {
226
240
  case "accept_nonbinding":
227
241
  return { type: "accept_nonbinding", offer_id: offerId };
228
242
  case "withdraw":
229
- return { type: "withdraw", scope: envelope.payload?.scope === "negotiation" ? "negotiation" : "offer" };
243
+ return {
244
+ type: "withdraw",
245
+ scope: envelope.payload?.scope === "negotiation"
246
+ ? "negotiation"
247
+ : "offer",
248
+ };
230
249
  case "decline":
231
- return { type: "decline", scope: envelope.payload?.scope === "negotiation" ? "negotiation" : "offer" };
250
+ return {
251
+ type: "decline",
252
+ scope: envelope.payload?.scope === "negotiation"
253
+ ? "negotiation"
254
+ : "offer",
255
+ };
232
256
  case "cancel":
233
257
  return { type: "cancel" };
234
258
  default:
@@ -241,7 +265,10 @@ export function createMerchantHandler(options) {
241
265
  const appendPhaseTransition = async (negotiationId, toPhase, fromPhase) => {
242
266
  const current = phaseStateByNegotiation.get(negotiationId);
243
267
  const effectiveFrom = fromPhase ?? current?.phase ?? "OPEN";
244
- phaseStateByNegotiation.set(negotiationId, { ...(current ?? createNegotiationPhase(negotiationId)), phase: toPhase });
268
+ phaseStateByNegotiation.set(negotiationId, {
269
+ ...(current ?? createNegotiationPhase(negotiationId)),
270
+ phase: toPhase,
271
+ });
245
272
  await ledger.append({
246
273
  event_kind: "state_transition",
247
274
  negotiation_id: negotiationId,
@@ -262,9 +289,11 @@ export function createMerchantHandler(options) {
262
289
  const PRICE_CACHE_TTL_MS = 10 * 60 * 1000;
263
290
  const priceBySku = new Map();
264
291
  /** 从真实商品源解析 SKU 价目;源不可用/查不到时回退演示价并返回注记。 */
265
- const resolveProduct = async (sku) => {
292
+ const resolveProduct = async (sku, resolveOptions = {}) => {
266
293
  const cached = priceBySku.get(sku);
267
- if (cached !== undefined) {
294
+ // force=true(成交前重验,T047)绕过缓存:许可有效性必须按**当前**商品事实
295
+ // 判定,而不是十分钟内的历史快照。
296
+ if (cached !== undefined && resolveOptions.force !== true) {
268
297
  if (Date.parse(now()) - cached.at <= PRICE_CACHE_TTL_MS)
269
298
  return cached;
270
299
  priceBySku.delete(sku); // TTL 过期:重新解析(价格会变)
@@ -289,6 +318,7 @@ export function createMerchantHandler(options) {
289
318
  : {}),
290
319
  ...(product.stock !== undefined ? { stock: product.stock } : {}),
291
320
  ...(product.title !== undefined ? { title: product.title } : {}),
321
+ ...(product.valid_until !== undefined ? { valid_until: product.valid_until } : {}),
292
322
  };
293
323
  priceBySku.set(sku, resolved);
294
324
  return resolved;
@@ -313,16 +343,67 @@ export function createMerchantHandler(options) {
313
343
  };
314
344
  /** resolveProduct 的 fail-closed 包装:商品源不可用且未开 demo 回退时返回
315
345
  * null(调用方 decline temporarily_unavailable),否则返回解析结果。 */
316
- const resolveProductOrDecline = async (sku) => {
346
+ const resolveProductOrDecline = async (sku, options = {}) => {
317
347
  try {
318
- return await resolveProduct(sku);
348
+ return { product: await resolveProduct(sku, options) };
319
349
  }
320
350
  catch (err) {
321
- if (err instanceof ProductSourceUnavailableError)
322
- return null;
351
+ if (err instanceof ProductSourceUnavailableError) {
352
+ return { declined: declineReply("temporarily_unavailable", err.sourceCode === "PRODUCTS_NOT_CONFIGURED"
353
+ ? "暂无可报价商品,请先导入商品;导入后系统会继续服务检查。"
354
+ : undefined) };
355
+ }
323
356
  throw err;
324
357
  }
325
358
  };
359
+ const resolvePromotionQuote = (sku, quantity, basePriceMinor, currency, floorMinor) => {
360
+ if (options.promotionPrice === undefined)
361
+ return { kind: "none" };
362
+ let value;
363
+ try {
364
+ value = options.promotionPrice({ sku, quantity });
365
+ }
366
+ catch {
367
+ return { kind: "unavailable" };
368
+ }
369
+ if (value === undefined)
370
+ return { kind: "none" };
371
+ const calculated = calculateWorkbenchQuote({
372
+ base: {
373
+ currency,
374
+ amount_minor: String(basePriceMinor),
375
+ currency_table_version: WORKBENCH_CURRENCY_TABLE_VERSION,
376
+ },
377
+ quantity,
378
+ privateFloorMinor: String(floorMinor),
379
+ promotions: [
380
+ {
381
+ promotion_id: value.promotionId,
382
+ revision: value.revision,
383
+ unit_price: {
384
+ currency: value.currency,
385
+ amount_minor: value.amountMinor,
386
+ currency_table_version: WORKBENCH_CURRENCY_TABLE_VERSION,
387
+ },
388
+ ends_at: value.endsAt,
389
+ priority: 0,
390
+ },
391
+ ],
392
+ });
393
+ if (calculated.status !== "quoted" || calculated.source.kind !== "promotion") {
394
+ return { kind: "invalid" };
395
+ }
396
+ if (Date.parse(value.endsAt) <= Date.parse(now()))
397
+ return { kind: "invalid" };
398
+ const priceMinor = Number(calculated.unit_price.amount_minor);
399
+ return {
400
+ kind: "applied",
401
+ priceMinor,
402
+ promotionId: value.promotionId,
403
+ revision: value.revision,
404
+ endsAt: value.endsAt,
405
+ };
406
+ };
326
407
  const appendSent = async (reply) => {
327
408
  await ledger.append({
328
409
  event_kind: "message_sent",
@@ -354,7 +435,7 @@ export function createMerchantHandler(options) {
354
435
  // active_offer_id / last conditional_offer 一次算出。此前按 phase 与
355
436
  // conditional 分两趟遍历每条链,长驻 merchant 启动时间随磋商数线性放大
356
437
  // (O(total events) 的全量恢复是正确性必需,这里只减掉冗余遍历)。
357
- const events = ledger.events(negotiationId);
438
+ const events = ledger.events(negotiationId).map((event) => ledger.resolvePayload(event));
358
439
  let phase = "OPEN";
359
440
  // 审查 K-M15:恢复完整相位状态——AWAITING_CLARIFICATION 的 resume_phase
360
441
  // 由「进入它的转换的 from_phase」推导(进入只能是 OPEN/OFFER_OPEN);
@@ -372,7 +453,9 @@ export function createMerchantHandler(options) {
372
453
  if (event.event_kind !== "message_sent")
373
454
  continue;
374
455
  const envelope = event.wire_payload;
375
- if (envelope?.action === "offer" || envelope?.action === "counter_offer" || envelope?.action === "conditional_offer") {
456
+ if (envelope?.action === "offer" ||
457
+ envelope?.action === "counter_offer" ||
458
+ envelope?.action === "conditional_offer") {
376
459
  const offerId = envelope.payload?.offer_id;
377
460
  if (typeof offerId === "string" && offerId !== "")
378
461
  activeOfferId = offerId;
@@ -441,8 +524,7 @@ export function createMerchantHandler(options) {
441
524
  /** 数量校验(审查 P2):数量存在时必须是正整数——0/负数/小数按结构化
442
525
  * 无效拒绝,不进 offer terms(否则批量价/条件成交按无意义数量求值);
443
526
  * 未报数量沿用 MERCHANT_QUANTITY 缺省口径(不变)。 */
444
- const invalidQuantity = (raw) => raw !== undefined &&
445
- (typeof raw !== "number" || !Number.isInteger(raw) || raw <= 0);
527
+ const invalidQuantity = (raw) => raw !== undefined && (typeof raw !== "number" || !Number.isInteger(raw) || raw <= 0);
446
528
  const floorMinorForSku = (sku) => {
447
529
  const mp = policyOf();
448
530
  const floorValue = mp?.price_floors?.[sku] ?? mp?.min_unit_price_private;
@@ -457,12 +539,60 @@ export function createMerchantHandler(options) {
457
539
  const deliveryBefore = () => resolveDeliveryBefore(policyOf(), now());
458
540
  /** 买家还价(major→minor;KNP 里 buyer counter 的 unit_price)。 */
459
541
  const clampToBounds = (minor, floor, list) => Math.min(list, Math.max(minor, floor));
542
+ /**
543
+ * 对买家可见的**自动折扣边界**(公开策略值:max_auto_discount_percent)。
544
+ *
545
+ * 安全要点(T045「不泄露底价」):商家对买家的任何报价都必须 clamp 到
546
+ * **公开边界**而不是 clamp 到私有底价——把还价 clamp 到底价再回给买家,
547
+ * 等于一次极低还价即可探出私有底价(一次探测即泄露精确值)。
548
+ * 私有底价只用来判断「这个价能不能自动报」,绝不出现在返回的条款里。
549
+ */
550
+ /**
551
+ * 运行中规则的摘要(T047):接受成交前必须重验——商家改了规则/促销/底价后,
552
+ * 旧 conditional 的许可即失效,不能按旧价成交(设计 §10.2「审批时商品/规则
553
+ * 已变化 → 使旧候选失效或重新确认,不能执行过期许可」)。
554
+ */
555
+ const policyDigest = () => contentDigest((policyOf() ?? {}));
556
+ /** 商品事实指纹(T047):价格/币种变化同样使旧许可失效。 */
557
+ const productFingerprint = (facts) => contentDigest({
558
+ sku: facts.sku,
559
+ priceMinor: facts.priceMinor,
560
+ currency: facts.currency,
561
+ });
562
+ const publicDiscountBoundMinor = (listMinor, sku) => {
563
+ const policy = policyOf();
564
+ const autoRaw = policy?.max_auto_discount_percent;
565
+ const auto = typeof autoRaw === "number" && Number.isFinite(autoRaw) && autoRaw > 0 ? autoRaw : 0;
566
+ // 促销本身是**公开条款**(promos[sku].bulk_discount_percent),因此公开边界
567
+ // 取其与自动折扣的较大者;未公布任何折扣时边界 = list(不自动折扣)。
568
+ const promoPct = policy?.promos?.[sku]?.bulk_discount_percent ?? 0;
569
+ const pct = Math.max(auto, Number.isFinite(promoPct) && promoPct > 0 ? promoPct : 0);
570
+ return applyDiscountPercentMinor(listMinor, pct);
571
+ };
572
+ /**
573
+ * 商品事实闸门(T046):数据过期或数量超过可得库存 → 明确不可报价。
574
+ * 设计 §10.1:「数据到期后停止相关自动报价或注明需人工确认,不把库存未知
575
+ * 说成有货」。**不在这里做任何兜底定价**(演示价已在配置层被云端拒绝)。
576
+ */
577
+ const factsUnusable = (facts, quantity) => {
578
+ if (facts.valid_until !== undefined) {
579
+ const until = Date.parse(facts.valid_until);
580
+ if (!Number.isFinite(until) || until < Date.parse(now()))
581
+ return true;
582
+ }
583
+ if (facts.stock !== undefined && quantity > facts.stock)
584
+ return true;
585
+ return false;
586
+ };
460
587
  switch (envelope.action) {
461
588
  case "inquiry": {
462
589
  // 入站消息由 A2A pipeline 统一落 message_received(§22);这里不再
463
590
  // 重复落账——此前 appendSent(envelope) 把买家的 inquiry 记为 merchant
464
591
  // 自己"发送"(sender=merchant),审计语义错位且重复。
465
- return textReply(`We carry ${MERCHANT_SKU} at ${(offerPriceMinor / 100).toFixed(2)} ${MERCHANT_CURRENCY}/piece; ask for delivery details.`);
592
+ const resolved = await resolveProductOrDecline(MERCHANT_SKU);
593
+ if ("declined" in resolved)
594
+ return resolved.declined;
595
+ return textReply(`We carry ${resolved.product.title ?? MERCHANT_SKU} at ${(resolved.product.priceMinor / 100).toFixed(2)} ${resolved.product.currency}/piece; ask for delivery details.`);
466
596
  }
467
597
  case "rfq": {
468
598
  const payload = envelope.payload;
@@ -474,12 +604,23 @@ export function createMerchantHandler(options) {
474
604
  const floorMinor = floorMinorForSku(sku);
475
605
  if (floorMinor === null)
476
606
  return declineReply("temporarily_unavailable");
477
- const product = await resolveProductOrDecline(sku);
478
- if (product === null)
479
- return declineReply("temporarily_unavailable");
607
+ const resolved = await resolveProductOrDecline(sku);
608
+ if ("declined" in resolved)
609
+ return resolved.declined;
610
+ const product = resolved.product;
480
611
  const { priceMinor, currency, note, handoff_destination } = product;
481
- // 确定性:offer = list 价,clamp 到 ≥ floor(永不低于私有底价;无 LLM)。
482
- const effectivePriceMinor = Math.max(priceMinor, floorMinor);
612
+ if (factsUnusable(product, quantity))
613
+ return declineReply("temporarily_unavailable");
614
+ const promotion = resolvePromotionQuote(sku, quantity, priceMinor, currency, floorMinor);
615
+ if (promotion.kind === "unavailable")
616
+ return declineReply("temporarily_unavailable");
617
+ if (promotion.kind === "invalid")
618
+ return declineReply("approval_required");
619
+ // 确定性:offer = list 价(公开价)。list < floor 是配置矛盾——此时
620
+ // 用 floor 兜底会把私有底价直接报给买家(T045 泄露面),因此拒绝自动报价。
621
+ const effectivePriceMinor = promotion.kind === "applied" ? promotion.priceMinor : priceMinor;
622
+ if (effectivePriceMinor < floorMinor)
623
+ return declineReply("approval_required");
483
624
  const reply = seedEnvelope({
484
625
  negotiation_id: negotiationId,
485
626
  in_reply_to: inReplyTo,
@@ -489,7 +630,15 @@ export function createMerchantHandler(options) {
489
630
  payload: {
490
631
  type: "offer",
491
632
  offer_id: newOfferId(),
492
- terms: offerTerms({ sku, priceMinor: effectivePriceMinor, quantity, currency, handoff_destination, deliveryBefore: deliveryBefore() }, now()),
633
+ terms: offerTerms({
634
+ sku,
635
+ priceMinor: effectivePriceMinor,
636
+ quantity,
637
+ currency,
638
+ handoff_destination,
639
+ deliveryBefore: deliveryBefore(),
640
+ ...(promotion.kind === "applied" ? { validUntilCap: promotion.endsAt } : {}),
641
+ }, now()),
493
642
  },
494
643
  ...(note !== undefined ? { public_message: note } : {}),
495
644
  });
@@ -516,12 +665,23 @@ export function createMerchantHandler(options) {
516
665
  const floorMinor = floorMinorForSku(sku);
517
666
  if (floorMinor === null)
518
667
  return declineReply("temporarily_unavailable");
519
- const product = await resolveProductOrDecline(sku);
520
- if (product === null)
521
- return declineReply("temporarily_unavailable");
668
+ const resolved = await resolveProductOrDecline(sku);
669
+ if ("declined" in resolved)
670
+ return resolved.declined;
671
+ const product = resolved.product;
522
672
  const { priceMinor, currency, note, handoff_destination } = product;
523
- // 确定性:counter = list 价,clamp 到 ≥ floor。
524
- const effectivePriceMinor = Math.max(priceMinor, floorMinor);
673
+ if (factsUnusable(product, quantity))
674
+ return declineReply("temporarily_unavailable");
675
+ const promotion = resolvePromotionQuote(sku, quantity, priceMinor, currency, floorMinor);
676
+ if (promotion.kind === "unavailable")
677
+ return declineReply("temporarily_unavailable");
678
+ if (promotion.kind === "invalid")
679
+ return declineReply("approval_required");
680
+ // 确定性:counter = list 价(公开价);list < floor 时拒绝自动报价
681
+ // (用 floor 兜底=把底价报给买家)。
682
+ const effectivePriceMinor = promotion.kind === "applied" ? promotion.priceMinor : priceMinor;
683
+ if (effectivePriceMinor < floorMinor)
684
+ return declineReply("approval_required");
525
685
  const reply = seedEnvelope({
526
686
  negotiation_id: negotiationId,
527
687
  in_reply_to: inReplyTo,
@@ -532,7 +692,15 @@ export function createMerchantHandler(options) {
532
692
  type: "counter_offer",
533
693
  offer_id: newOfferId(),
534
694
  responding_to_offer_id: buyerOffer.offer_id ?? "",
535
- proposed_terms: offerTerms({ sku, priceMinor: effectivePriceMinor, quantity, currency, handoff_destination, deliveryBefore: deliveryBefore() }, now()),
695
+ proposed_terms: offerTerms({
696
+ sku,
697
+ priceMinor: effectivePriceMinor,
698
+ quantity,
699
+ currency,
700
+ handoff_destination,
701
+ deliveryBefore: deliveryBefore(),
702
+ ...(promotion.kind === "applied" ? { validUntilCap: promotion.endsAt } : {}),
703
+ }, now()),
536
704
  },
537
705
  ...(note !== undefined ? { public_message: note } : {}),
538
706
  });
@@ -557,22 +725,46 @@ export function createMerchantHandler(options) {
557
725
  const floorMinor = floorMinorForSku(sku);
558
726
  if (floorMinor === null)
559
727
  return declineReply("temporarily_unavailable");
560
- const product = await resolveProductOrDecline(sku);
561
- if (product === null)
562
- return declineReply("temporarily_unavailable");
728
+ const resolved = await resolveProductOrDecline(sku);
729
+ if ("declined" in resolved)
730
+ return resolved.declined;
731
+ const product = resolved.product;
563
732
  const { priceMinor, currency, note, handoff_destination } = product;
564
- // 确定性(无 LLM):买家还价在 [floor, list] 内响应——高于 floor 就接受,
565
- // 低于 floor 抬到 floor,高于 list 压到 list。
566
- const responsiveMinor = typeof buyerCounterMinor === "number" && Number.isFinite(buyerCounterMinor)
567
- ? clampToBounds(buyerCounterMinor, floorMinor, priceMinor)
733
+ if (factsUnusable(product, quantity))
734
+ return declineReply("temporarily_unavailable");
735
+ const authorityPromotion = resolvePromotionQuote(sku, quantity, priceMinor, currency, floorMinor);
736
+ if (authorityPromotion.kind === "unavailable") {
737
+ return declineReply("temporarily_unavailable");
738
+ }
739
+ if (authorityPromotion.kind === "invalid")
740
+ return declineReply("approval_required");
741
+ // 确定性(无 LLM):买家还价只在**公开折扣边界**内响应——
742
+ // 边界 = list×(1-max_auto_discount_percent),是公开策略值;
743
+ // 高于 list 压到 list,低于公开边界抬到公开边界。
744
+ // 关键:绝不把还价 clamp 到私有底价再回给买家(那样一次极低还价
745
+ // 即可探出底价精确值,T045)。
746
+ const publicBoundMinor = publicDiscountBoundMinor(priceMinor, sku);
747
+ const policyResponsiveMinor = typeof buyerCounterMinor === "number" && Number.isFinite(buyerCounterMinor)
748
+ ? clampToBounds(buyerCounterMinor, publicBoundMinor, priceMinor)
568
749
  : priceMinor;
750
+ const responsiveMinor = authorityPromotion.kind === "applied"
751
+ ? Math.min(policyResponsiveMinor, authorityPromotion.priceMinor)
752
+ : policyResponsiveMinor;
753
+ if (responsiveMinor < floorMinor) {
754
+ // 公开边界低于私有底价:该区间不能自动报价,交人工/审批处理,且不返回价格。
755
+ return declineReply("approval_required");
756
+ }
569
757
  // 可配置促销(merchant_policy.promos[sku]):买满 bulk_threshold 台,
570
- // 批量价 = max(floor, min(还价, list×(1-d%/100))),比单台更便宜。
758
+ // 批量价 = min(还价响应, list×(1-d%/100)),同样 clamp 到公开边界;
759
+ // 若该价低于私有底价则**不挂这条条件**(不广告无法兑现的价)。
571
760
  const promo = policyOf()?.promos?.[sku];
572
761
  const bulkThreshold = promo?.bulk_threshold ?? DEFAULT_BULK_THRESHOLD;
573
762
  const bulkMinor = promo !== undefined
574
- ? clampToBounds(Math.min(responsiveMinor, applyDiscountPercentMinor(priceMinor, promo.bulk_discount_percent ?? 0)), floorMinor, priceMinor)
575
- : responsiveMinor;
763
+ ? clampToBounds(Math.min(responsiveMinor, applyDiscountPercentMinor(priceMinor, promo.bulk_discount_percent ?? 0)), publicBoundMinor, priceMinor)
764
+ : undefined;
765
+ const promotionalMinor = bulkMinor !== undefined && bulkMinor < responsiveMinor && bulkMinor >= floorMinor
766
+ ? bulkMinor
767
+ : undefined;
576
768
  const reply = seedEnvelope({
577
769
  negotiation_id: negotiationId,
578
770
  in_reply_to: inReplyTo,
@@ -583,14 +775,42 @@ export function createMerchantHandler(options) {
583
775
  type: "conditional_offer",
584
776
  offer_id: newOfferId(),
585
777
  responding_to_offer_id: counter.offer_id,
778
+ // 许可绑定(T047):本次报价依据的规则摘要与商品事实指纹;accept 时重验。
779
+ policy_digest: policyDigest(),
780
+ product_fingerprint: productFingerprint({ sku, priceMinor, currency }),
586
781
  // base = 还价响应(已 clamp 到 [floor, list])——单台即得到该价。
587
- base_terms: offerTerms({ sku, priceMinor: responsiveMinor, quantity, currency, handoff_destination, deliveryBefore: deliveryBefore() }, now()),
588
- conditions: [
589
- {
590
- when: { all: [{ field: "aggregate.total_quantity", op: "gte", value: bulkThreshold }] },
591
- then_terms: offerTerms({ sku, priceMinor: bulkMinor, quantity, currency, handoff_destination, deliveryBefore: deliveryBefore() }, now()),
592
- },
593
- ],
782
+ base_terms: offerTerms({
783
+ sku,
784
+ priceMinor: responsiveMinor,
785
+ quantity,
786
+ currency,
787
+ handoff_destination,
788
+ deliveryBefore: deliveryBefore(),
789
+ ...(authorityPromotion.kind === "applied"
790
+ ? { validUntilCap: authorityPromotion.endsAt }
791
+ : {}),
792
+ }, now()),
793
+ // conditions 可空(§13:空 conditions 等价 base_terms)。促销价低于
794
+ // 私有底价时不挂条件——不广告无法兑现的价,也不借 then_terms 泄露底价。
795
+ conditions: promotionalMinor !== undefined
796
+ ? [
797
+ {
798
+ when: {
799
+ all: [
800
+ { field: "aggregate.total_quantity", op: "gte", value: bulkThreshold },
801
+ ],
802
+ },
803
+ then_terms: offerTerms({
804
+ sku,
805
+ priceMinor: promotionalMinor,
806
+ quantity,
807
+ currency,
808
+ handoff_destination,
809
+ deliveryBefore: deliveryBefore(),
810
+ }, now()),
811
+ },
812
+ ]
813
+ : [],
594
814
  },
595
815
  ...(note !== undefined ? { public_message: note } : {}),
596
816
  });
@@ -681,6 +901,28 @@ export function createMerchantHandler(options) {
681
901
  if (presentedDigest === "" || presentedDigest !== contentDigest(agreedTerms)) {
682
902
  return declineReply("terms_digest_mismatch");
683
903
  }
904
+ // T047:许可有效性重验——规则或商品事实在报价之后发生变化,旧许可即失效。
905
+ // 必须在相位推进/产出协议之前判定(拒绝不得留下任何终态副作用)。
906
+ const acceptedConditionalPayload = acceptedConditional.conditional;
907
+ const currentPolicyDigest = policyDigest();
908
+ if (acceptedConditionalPayload.policy_digest !== undefined &&
909
+ acceptedConditionalPayload.policy_digest !== currentPolicyDigest) {
910
+ return declineReply("approval_required");
911
+ }
912
+ const acceptedSku = acceptedConditionalPayload.base_terms?.items?.[0]?.sku;
913
+ if (acceptedConditionalPayload.product_fingerprint !== undefined &&
914
+ acceptedSku !== undefined) {
915
+ const refreshed = await resolveProductOrDecline(acceptedSku, { force: true });
916
+ if ("declined" in refreshed ||
917
+ productFingerprint({
918
+ sku: acceptedSku,
919
+ priceMinor: refreshed.product.priceMinor,
920
+ currency: refreshed.product.currency,
921
+ }) !== acceptedConditionalPayload.product_fingerprint) {
922
+ // 商品价/币种变化或商品源已不可用 → 旧许可失效,需重新确认。
923
+ return declineReply("approval_required");
924
+ }
925
+ }
684
926
  // 审查 P1-C:相位机是权威守卫——§15 校验通过后、构建协议之前先
685
927
  // 推进相位并检查返回值(BUG-10 语义不变:被拒的 accept 不得进入
686
928
  // AGREEMENT_REACHED)。推进失败(如 AWAITING_CLARIFICATION 下直接
@@ -710,7 +952,12 @@ export function createMerchantHandler(options) {
710
952
  // 协商终态:conditional 不再需要(评审项 L3:此前永久累积)。
711
953
  conditionalByNegotiation.delete(negotiationId);
712
954
  closedNegotiations.add(negotiationId);
713
- return { kind: "accepted", taskState: "completed", artifactParts: [artifactPart], message };
955
+ return {
956
+ kind: "accepted",
957
+ taskState: "completed",
958
+ artifactParts: [artifactPart],
959
+ message,
960
+ };
714
961
  }
715
962
  case "withdraw": {
716
963
  const scope = envelope.payload.scope ?? "offer";