@harrylabsj/kiwi 0.12.31 → 0.12.33

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 (467) hide show
  1. package/README.md +8 -0
  2. package/dist/a2a/inquiry-nonce-store.d.ts +12 -1
  3. package/dist/a2a/inquiry-nonce-store.js +49 -17
  4. package/dist/a2a/inquiry-nonce-store.js.map +1 -1
  5. package/dist/a2a/negotiate.d.ts +30 -1
  6. package/dist/a2a/negotiate.js +121 -32
  7. package/dist/a2a/negotiate.js.map +1 -1
  8. package/dist/a2a/node.d.ts +4 -0
  9. package/dist/a2a/node.js +182 -4
  10. package/dist/a2a/node.js.map +1 -1
  11. package/dist/a2a/open-inquiry-session.d.ts +1 -0
  12. package/dist/a2a/open-inquiry-session.js +3 -1
  13. package/dist/a2a/open-inquiry-session.js.map +1 -1
  14. package/dist/a2a/open-inquiry-verifier.js +2 -2
  15. package/dist/a2a/open-inquiry-verifier.js.map +1 -1
  16. package/dist/a2a/reception/agent-runtime.d.ts +32 -1
  17. package/dist/a2a/reception/agent-runtime.js +420 -11
  18. package/dist/a2a/reception/agent-runtime.js.map +1 -1
  19. package/dist/a2a/reception/customer-memory-tools.d.ts +73 -0
  20. package/dist/a2a/reception/customer-memory-tools.js +17 -0
  21. package/dist/a2a/reception/customer-memory-tools.js.map +1 -0
  22. package/dist/a2a/reception/engine.d.ts +12 -0
  23. package/dist/a2a/reception/engine.js +42 -1
  24. package/dist/a2a/reception/engine.js.map +1 -1
  25. package/dist/a2a/reception/publish.d.ts +14 -1
  26. package/dist/a2a/reception/publish.js +62 -1
  27. package/dist/a2a/reception/publish.js.map +1 -1
  28. package/dist/a2a/reception/question-spec.d.ts +91 -0
  29. package/dist/a2a/reception/question-spec.js +260 -0
  30. package/dist/a2a/reception/question-spec.js.map +1 -0
  31. package/dist/a2a/reception/reply-outbox.d.ts +6 -0
  32. package/dist/a2a/reception/reply-outbox.js +44 -0
  33. package/dist/a2a/reception/reply-outbox.js.map +1 -1
  34. package/dist/a2a/reception/responder.d.ts +13 -1
  35. package/dist/a2a/reception/responder.js +26 -3
  36. package/dist/a2a/reception/responder.js.map +1 -1
  37. package/dist/a2a/reception/skill-catalog.d.ts +72 -0
  38. package/dist/a2a/reception/skill-catalog.js +85 -0
  39. package/dist/a2a/reception/skill-catalog.js.map +1 -0
  40. package/dist/a2a/reception/skill-contract.d.ts +70 -0
  41. package/dist/a2a/reception/skill-contract.js +183 -0
  42. package/dist/a2a/reception/skill-contract.js.map +1 -0
  43. package/dist/a2a/reception/types.d.ts +12 -0
  44. package/dist/a2a/server/customer-identity-gateway.d.ts +111 -0
  45. package/dist/a2a/server/customer-identity-gateway.js +441 -0
  46. package/dist/a2a/server/customer-identity-gateway.js.map +1 -0
  47. package/dist/a2a/server/errors.d.ts +4 -3
  48. package/dist/a2a/server/errors.js +10 -2
  49. package/dist/a2a/server/errors.js.map +1 -1
  50. package/dist/a2a/server/merchant-handler.d.ts +75 -1
  51. package/dist/a2a/server/merchant-handler.js +676 -86
  52. package/dist/a2a/server/merchant-handler.js.map +1 -1
  53. package/dist/a2a/server/merchant-procurement.d.ts +90 -0
  54. package/dist/a2a/server/merchant-procurement.js +75 -0
  55. package/dist/a2a/server/merchant-procurement.js.map +1 -0
  56. package/dist/a2a/server/merchant-product-facts.d.ts +2 -0
  57. package/dist/a2a/server/merchant-product-facts.js.map +1 -1
  58. package/dist/a2a/server/negotiation-approvals.d.ts +11 -0
  59. package/dist/a2a/server/negotiation-approvals.js +43 -0
  60. package/dist/a2a/server/negotiation-approvals.js.map +1 -1
  61. package/dist/a2a/server/pipeline.js +78 -30
  62. package/dist/a2a/server/pipeline.js.map +1 -1
  63. package/dist/a2a/server/server.js +4 -3
  64. package/dist/a2a/server/server.js.map +1 -1
  65. package/dist/a2a/server/types.d.ts +4 -1
  66. package/dist/a2a/unit-alias.d.ts +3 -3
  67. package/dist/a2a/unit-alias.js +9 -5
  68. package/dist/a2a/unit-alias.js.map +1 -1
  69. package/dist/agent/alipay-native-view.d.ts +27 -0
  70. package/dist/agent/alipay-native-view.js +113 -0
  71. package/dist/agent/alipay-native-view.js.map +1 -0
  72. package/dist/agent/buyer/buyer-tools.d.ts +20 -0
  73. package/dist/agent/buyer/buyer-tools.js +241 -48
  74. package/dist/agent/buyer/buyer-tools.js.map +1 -1
  75. package/dist/agent/buyer/types.d.ts +1 -1
  76. package/dist/agent/buyer/types.js.map +1 -1
  77. package/dist/agent/chat-tui.js +16 -1
  78. package/dist/agent/chat-tui.js.map +1 -1
  79. package/dist/agent/kernel-builder.d.ts +2 -0
  80. package/dist/agent/kernel-builder.js +14 -0
  81. package/dist/agent/kernel-builder.js.map +1 -1
  82. package/dist/agent/kernel.d.ts +8 -0
  83. package/dist/agent/kernel.js +67 -1
  84. package/dist/agent/kernel.js.map +1 -1
  85. package/dist/auth/merchant-sessions.d.ts +3 -0
  86. package/dist/auth/merchant-sessions.js +21 -5
  87. package/dist/auth/merchant-sessions.js.map +1 -1
  88. package/dist/buyer-core/a2a-accept-terms.d.ts +11 -0
  89. package/dist/buyer-core/a2a-accept-terms.js +28 -0
  90. package/dist/buyer-core/a2a-accept-terms.js.map +1 -0
  91. package/dist/buyer-core/a2a-knp.d.ts +7 -2
  92. package/dist/buyer-core/a2a-knp.js +8 -5
  93. package/dist/buyer-core/a2a-knp.js.map +1 -1
  94. package/dist/buyer-core/a2a-negotiator.d.ts +17 -0
  95. package/dist/buyer-core/a2a-negotiator.js +70 -26
  96. package/dist/buyer-core/a2a-negotiator.js.map +1 -1
  97. package/dist/buyer-core/a2a-quote-fetcher.d.ts +25 -15
  98. package/dist/buyer-core/a2a-quote-fetcher.js +92 -19
  99. package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
  100. package/dist/buyer-core/a2a-quote-history.d.ts +94 -0
  101. package/dist/buyer-core/a2a-quote-history.js +149 -0
  102. package/dist/buyer-core/a2a-quote-history.js.map +1 -0
  103. package/dist/buyer-core/build-service.d.ts +19 -0
  104. package/dist/buyer-core/build-service.js +30 -1
  105. package/dist/buyer-core/build-service.js.map +1 -1
  106. package/dist/buyer-core/errors.d.ts +1 -1
  107. package/dist/buyer-core/errors.js +1 -0
  108. package/dist/buyer-core/errors.js.map +1 -1
  109. package/dist/buyer-core/merchant-index.d.ts +2 -2
  110. package/dist/buyer-core/merchant-index.js +23 -5
  111. package/dist/buyer-core/merchant-index.js.map +1 -1
  112. package/dist/buyer-core/open-inquiry-signer.d.ts +1 -0
  113. package/dist/buyer-core/open-inquiry-signer.js +5 -2
  114. package/dist/buyer-core/open-inquiry-signer.js.map +1 -1
  115. package/dist/buyer-core/procurement/cases.d.ts +441 -0
  116. package/dist/buyer-core/procurement/cases.js +457 -0
  117. package/dist/buyer-core/procurement/cases.js.map +1 -0
  118. package/dist/buyer-core/procurement/quote-comparison.d.ts +137 -0
  119. package/dist/buyer-core/procurement/quote-comparison.js +106 -0
  120. package/dist/buyer-core/procurement/quote-comparison.js.map +1 -0
  121. package/dist/buyer-core/procurement/quote-normalizer.d.ts +45 -0
  122. package/dist/buyer-core/procurement/quote-normalizer.js +153 -0
  123. package/dist/buyer-core/procurement/quote-normalizer.js.map +1 -0
  124. package/dist/buyer-core/procurement/requirements.d.ts +50 -0
  125. package/dist/buyer-core/procurement/requirements.js +43 -0
  126. package/dist/buyer-core/procurement/requirements.js.map +1 -0
  127. package/dist/buyer-core/procurement/source-observation.d.ts +57 -0
  128. package/dist/buyer-core/procurement/source-observation.js +54 -0
  129. package/dist/buyer-core/procurement/source-observation.js.map +1 -0
  130. package/dist/buyer-core/procurement/store.d.ts +21 -0
  131. package/dist/buyer-core/procurement/store.js +68 -0
  132. package/dist/buyer-core/procurement/store.js.map +1 -0
  133. package/dist/buyer-core/protocol-recovery.d.ts +10 -1
  134. package/dist/buyer-core/protocol-recovery.js +31 -6
  135. package/dist/buyer-core/protocol-recovery.js.map +1 -1
  136. package/dist/buyer-core/quote-quantity.d.ts +5 -0
  137. package/dist/buyer-core/quote-quantity.js +15 -0
  138. package/dist/buyer-core/quote-quantity.js.map +1 -0
  139. package/dist/buyer-core/service.d.ts +128 -8
  140. package/dist/buyer-core/service.js +543 -75
  141. package/dist/buyer-core/service.js.map +1 -1
  142. package/dist/buyer-core/store.d.ts +21 -0
  143. package/dist/buyer-core/store.js +62 -10
  144. package/dist/buyer-core/store.js.map +1 -1
  145. package/dist/cli.js +26 -19
  146. package/dist/cli.js.map +1 -1
  147. package/dist/cloud/alipay-collection-http.d.ts +44 -0
  148. package/dist/cloud/alipay-collection-http.js +111 -0
  149. package/dist/cloud/alipay-collection-http.js.map +1 -0
  150. package/dist/cloud/bootstrap.js +218 -19
  151. package/dist/cloud/bootstrap.js.map +1 -1
  152. package/dist/cloud/http-router.d.ts +2 -0
  153. package/dist/cloud/http-router.js +5 -0
  154. package/dist/cloud/http-router.js.map +1 -1
  155. package/dist/commerce/receipt/dispatcher.d.ts +43 -0
  156. package/dist/commerce/receipt/dispatcher.js +86 -0
  157. package/dist/commerce/receipt/dispatcher.js.map +1 -0
  158. package/dist/commerce/receipt/receipts.d.ts +147 -0
  159. package/dist/commerce/receipt/receipts.js +285 -0
  160. package/dist/commerce/receipt/receipts.js.map +1 -0
  161. package/dist/config/profile.d.ts +2 -2
  162. package/dist/discovery/catalog-source/buyer-follows.d.ts +3 -3
  163. package/dist/discovery/catalog-source/buyer-follows.js +6 -3
  164. package/dist/discovery/catalog-source/buyer-follows.js.map +1 -1
  165. package/dist/discovery/catalog-source/kiwi-record.d.ts +2 -0
  166. package/dist/discovery/catalog-source/kiwi-record.js.map +1 -1
  167. package/dist/discovery/catalog-source/kiwi-source.js +4 -0
  168. package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
  169. package/dist/handoff/alipay-collection.d.ts +23 -0
  170. package/dist/handoff/alipay-collection.js +70 -0
  171. package/dist/handoff/alipay-collection.js.map +1 -0
  172. package/dist/handoff/order-receipts.d.ts +62 -0
  173. package/dist/handoff/order-receipts.js +72 -0
  174. package/dist/handoff/order-receipts.js.map +1 -0
  175. package/dist/handoff/ucp-checkout/cart-channel.d.ts +2 -1
  176. package/dist/handoff/ucp-checkout/cart-channel.js +1 -0
  177. package/dist/handoff/ucp-checkout/cart-channel.js.map +1 -1
  178. package/dist/handoff/ucp-checkout/channel.d.ts +7 -0
  179. package/dist/handoff/ucp-checkout/channel.js +79 -10
  180. package/dist/handoff/ucp-checkout/channel.js.map +1 -1
  181. package/dist/http/cli.js +6 -0
  182. package/dist/http/cli.js.map +1 -1
  183. package/dist/http/merchant-management/api.d.ts +18 -0
  184. package/dist/http/merchant-management/api.js +752 -3
  185. package/dist/http/merchant-management/api.js.map +1 -1
  186. package/dist/http/merchant-management/draft-store.js +8 -6
  187. package/dist/http/merchant-management/draft-store.js.map +1 -1
  188. package/dist/http/merchant-management/page.d.ts +1 -0
  189. package/dist/http/merchant-management/page.js +335 -5
  190. package/dist/http/merchant-management/page.js.map +1 -1
  191. package/dist/http/server.js +9 -2
  192. package/dist/http/server.js.map +1 -1
  193. package/dist/mcp/cli.d.ts +3 -1
  194. package/dist/mcp/cli.js +18 -2
  195. package/dist/mcp/cli.js.map +1 -1
  196. package/dist/mcp/merchant-runtime-assembly.d.ts +20 -0
  197. package/dist/mcp/merchant-runtime-assembly.js +94 -11
  198. package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
  199. package/dist/mcp/merchant-server.d.ts +5 -0
  200. package/dist/mcp/merchant-server.js +12 -0
  201. package/dist/mcp/merchant-server.js.map +1 -1
  202. package/dist/mcp/procurement-tools.d.ts +10 -0
  203. package/dist/mcp/procurement-tools.js +173 -0
  204. package/dist/mcp/procurement-tools.js.map +1 -0
  205. package/dist/mcp/server.d.ts +4 -0
  206. package/dist/mcp/server.js +63 -9
  207. package/dist/mcp/server.js.map +1 -1
  208. package/dist/mcp/tools.d.ts +4 -1
  209. package/dist/mcp/tools.js +83 -28
  210. package/dist/mcp/tools.js.map +1 -1
  211. package/dist/mcp/types.d.ts +1 -0
  212. package/dist/mcp/types.js.map +1 -1
  213. package/dist/merchant/application/actor.d.ts +3 -1
  214. package/dist/merchant/application/actor.js +21 -0
  215. package/dist/merchant/application/actor.js.map +1 -1
  216. package/dist/merchant/negotiation-ops.d.ts +2 -0
  217. package/dist/merchant/negotiation-ops.js +4 -0
  218. package/dist/merchant/negotiation-ops.js.map +1 -1
  219. package/dist/merchant/weixin-channel.d.ts +68 -0
  220. package/dist/merchant/weixin-channel.js +313 -0
  221. package/dist/merchant/weixin-channel.js.map +1 -0
  222. package/dist/merchant/workbench-server.d.ts +1 -0
  223. package/dist/merchant/workbench-server.js +189 -2
  224. package/dist/merchant/workbench-server.js.map +1 -1
  225. package/dist/merchant-core/budget/background-budget.d.ts +132 -0
  226. package/dist/merchant-core/budget/background-budget.js +308 -0
  227. package/dist/merchant-core/budget/background-budget.js.map +1 -0
  228. package/dist/merchant-core/collection/alipay-store.d.ts +22 -0
  229. package/dist/merchant-core/collection/alipay-store.js +125 -0
  230. package/dist/merchant-core/collection/alipay-store.js.map +1 -0
  231. package/dist/merchant-core/commercial/calculate.js +6 -6
  232. package/dist/merchant-core/commercial/calculate.js.map +1 -1
  233. package/dist/merchant-core/context-governance/actor-context.d.ts +56 -0
  234. package/dist/merchant-core/context-governance/actor-context.js +76 -0
  235. package/dist/merchant-core/context-governance/actor-context.js.map +1 -0
  236. package/dist/merchant-core/context-governance/authority.d.ts +39 -0
  237. package/dist/merchant-core/context-governance/authority.js +28 -0
  238. package/dist/merchant-core/context-governance/authority.js.map +1 -0
  239. package/dist/merchant-core/context-governance/context-guard.d.ts +104 -0
  240. package/dist/merchant-core/context-governance/context-guard.js +194 -0
  241. package/dist/merchant-core/context-governance/context-guard.js.map +1 -0
  242. package/dist/merchant-core/context-governance/data-use-grant.d.ts +91 -0
  243. package/dist/merchant-core/context-governance/data-use-grant.js +211 -0
  244. package/dist/merchant-core/context-governance/data-use-grant.js.map +1 -0
  245. package/dist/merchant-core/context-governance/feature-flags.d.ts +32 -0
  246. package/dist/merchant-core/context-governance/feature-flags.js +83 -0
  247. package/dist/merchant-core/context-governance/feature-flags.js.map +1 -0
  248. package/dist/merchant-core/context-governance/pilot-readiness.d.ts +39 -0
  249. package/dist/merchant-core/context-governance/pilot-readiness.js +141 -0
  250. package/dist/merchant-core/context-governance/pilot-readiness.js.map +1 -0
  251. package/dist/merchant-core/context-governance/source-governance.d.ts +157 -0
  252. package/dist/merchant-core/context-governance/source-governance.js +492 -0
  253. package/dist/merchant-core/context-governance/source-governance.js.map +1 -0
  254. package/dist/merchant-core/context-governance/types.d.ts +62 -0
  255. package/dist/merchant-core/context-governance/types.js +92 -0
  256. package/dist/merchant-core/context-governance/types.js.map +1 -0
  257. package/dist/merchant-core/customer-delivery/binding.d.ts +55 -0
  258. package/dist/merchant-core/customer-delivery/binding.js +121 -0
  259. package/dist/merchant-core/customer-delivery/binding.js.map +1 -0
  260. package/dist/merchant-core/customer-delivery/channel.d.ts +75 -0
  261. package/dist/merchant-core/customer-delivery/channel.js +157 -0
  262. package/dist/merchant-core/customer-delivery/channel.js.map +1 -0
  263. package/dist/merchant-core/customer-delivery/consent-repository.d.ts +50 -0
  264. package/dist/merchant-core/customer-delivery/consent-repository.js +160 -0
  265. package/dist/merchant-core/customer-delivery/consent-repository.js.map +1 -0
  266. package/dist/merchant-core/customer-delivery/dispatcher-loop.d.ts +68 -0
  267. package/dist/merchant-core/customer-delivery/dispatcher-loop.js +132 -0
  268. package/dist/merchant-core/customer-delivery/dispatcher-loop.js.map +1 -0
  269. package/dist/merchant-core/customer-delivery/dispatcher.d.ts +118 -0
  270. package/dist/merchant-core/customer-delivery/dispatcher.js +166 -0
  271. package/dist/merchant-core/customer-delivery/dispatcher.js.map +1 -0
  272. package/dist/merchant-core/customer-delivery/email-adapter.d.ts +31 -0
  273. package/dist/merchant-core/customer-delivery/email-adapter.js +90 -0
  274. package/dist/merchant-core/customer-delivery/email-adapter.js.map +1 -0
  275. package/dist/merchant-core/customer-delivery/gate.d.ts +37 -0
  276. package/dist/merchant-core/customer-delivery/gate.js +196 -0
  277. package/dist/merchant-core/customer-delivery/gate.js.map +1 -0
  278. package/dist/merchant-core/customer-delivery/reconciliation.d.ts +13 -0
  279. package/dist/merchant-core/customer-delivery/reconciliation.js +70 -0
  280. package/dist/merchant-core/customer-delivery/reconciliation.js.map +1 -0
  281. package/dist/merchant-core/customer-delivery/repository.d.ts +55 -0
  282. package/dist/merchant-core/customer-delivery/repository.js +235 -0
  283. package/dist/merchant-core/customer-delivery/repository.js.map +1 -0
  284. package/dist/merchant-core/customer-delivery/smtp-adapter.d.ts +30 -0
  285. package/dist/merchant-core/customer-delivery/smtp-adapter.js +183 -0
  286. package/dist/merchant-core/customer-delivery/smtp-adapter.js.map +1 -0
  287. package/dist/merchant-core/customer-delivery/stream-gate.d.ts +45 -0
  288. package/dist/merchant-core/customer-delivery/stream-gate.js +123 -0
  289. package/dist/merchant-core/customer-delivery/stream-gate.js.map +1 -0
  290. package/dist/merchant-core/customer-delivery/types.d.ts +103 -0
  291. package/dist/merchant-core/customer-delivery/types.js +32 -0
  292. package/dist/merchant-core/customer-delivery/types.js.map +1 -0
  293. package/dist/merchant-core/customer-delivery/weixin-adapter.d.ts +35 -0
  294. package/dist/merchant-core/customer-delivery/weixin-adapter.js +56 -0
  295. package/dist/merchant-core/customer-delivery/weixin-adapter.js.map +1 -0
  296. package/dist/merchant-core/customer-memory/auto-identity.d.ts +43 -0
  297. package/dist/merchant-core/customer-memory/auto-identity.js +163 -0
  298. package/dist/merchant-core/customer-memory/auto-identity.js.map +1 -0
  299. package/dist/merchant-core/customer-memory/grants.d.ts +72 -0
  300. package/dist/merchant-core/customer-memory/grants.js +224 -0
  301. package/dist/merchant-core/customer-memory/grants.js.map +1 -0
  302. package/dist/merchant-core/customer-memory/history.d.ts +51 -0
  303. package/dist/merchant-core/customer-memory/history.js +252 -0
  304. package/dist/merchant-core/customer-memory/history.js.map +1 -0
  305. package/dist/merchant-core/customer-memory/identity.d.ts +66 -0
  306. package/dist/merchant-core/customer-memory/identity.js +249 -0
  307. package/dist/merchant-core/customer-memory/identity.js.map +1 -0
  308. package/dist/merchant-core/customer-memory/maintenance.d.ts +51 -0
  309. package/dist/merchant-core/customer-memory/maintenance.js +67 -0
  310. package/dist/merchant-core/customer-memory/maintenance.js.map +1 -0
  311. package/dist/merchant-core/customer-memory/memory.d.ts +119 -0
  312. package/dist/merchant-core/customer-memory/memory.js +502 -0
  313. package/dist/merchant-core/customer-memory/memory.js.map +1 -0
  314. package/dist/merchant-core/customer-memory/private-transport.d.ts +10 -0
  315. package/dist/merchant-core/customer-memory/private-transport.js +108 -0
  316. package/dist/merchant-core/customer-memory/private-transport.js.map +1 -0
  317. package/dist/merchant-core/customer-memory/quote-history.d.ts +160 -0
  318. package/dist/merchant-core/customer-memory/quote-history.js +392 -0
  319. package/dist/merchant-core/customer-memory/quote-history.js.map +1 -0
  320. package/dist/merchant-core/customer-memory/reception-provider.d.ts +69 -0
  321. package/dist/merchant-core/customer-memory/reception-provider.js +250 -0
  322. package/dist/merchant-core/customer-memory/reception-provider.js.map +1 -0
  323. package/dist/merchant-core/customer-memory/reception-writer.d.ts +19 -0
  324. package/dist/merchant-core/customer-memory/reception-writer.js +32 -0
  325. package/dist/merchant-core/customer-memory/reception-writer.js.map +1 -0
  326. package/dist/merchant-core/customer-memory/types.d.ts +111 -0
  327. package/dist/merchant-core/customer-memory/types.js +58 -0
  328. package/dist/merchant-core/customer-memory/types.js.map +1 -0
  329. package/dist/merchant-core/followup/repository.d.ts +2 -1
  330. package/dist/merchant-core/followup/repository.js +29 -23
  331. package/dist/merchant-core/followup/repository.js.map +1 -1
  332. package/dist/merchant-core/learning/evaluation-fixtures.d.ts +38 -0
  333. package/dist/merchant-core/learning/evaluation-fixtures.js +83 -0
  334. package/dist/merchant-core/learning/evaluation-fixtures.js.map +1 -0
  335. package/dist/merchant-core/learning/evaluation-suite-v1.d.ts +56 -0
  336. package/dist/merchant-core/learning/evaluation-suite-v1.js +129 -0
  337. package/dist/merchant-core/learning/evaluation-suite-v1.js.map +1 -0
  338. package/dist/merchant-core/learning/evaluation.d.ts +84 -0
  339. package/dist/merchant-core/learning/evaluation.js +581 -0
  340. package/dist/merchant-core/learning/evaluation.js.map +1 -0
  341. package/dist/merchant-core/learning/initial-skills.d.ts +36 -0
  342. package/dist/merchant-core/learning/initial-skills.js +67 -0
  343. package/dist/merchant-core/learning/initial-skills.js.map +1 -0
  344. package/dist/merchant-core/learning/precheck.d.ts +33 -0
  345. package/dist/merchant-core/learning/precheck.js +56 -0
  346. package/dist/merchant-core/learning/precheck.js.map +1 -0
  347. package/dist/merchant-core/learning/real-evaluation-runner.d.ts +52 -0
  348. package/dist/merchant-core/learning/real-evaluation-runner.js +167 -0
  349. package/dist/merchant-core/learning/real-evaluation-runner.js.map +1 -0
  350. package/dist/merchant-core/learning/reception-skill-catalog.d.ts +39 -0
  351. package/dist/merchant-core/learning/reception-skill-catalog.js +145 -0
  352. package/dist/merchant-core/learning/reception-skill-catalog.js.map +1 -0
  353. package/dist/merchant-core/learning/recovery-gateway.d.ts +27 -0
  354. package/dist/merchant-core/learning/recovery-gateway.js +106 -0
  355. package/dist/merchant-core/learning/recovery-gateway.js.map +1 -0
  356. package/dist/merchant-core/learning/repository.d.ts +130 -0
  357. package/dist/merchant-core/learning/repository.js +588 -0
  358. package/dist/merchant-core/learning/repository.js.map +1 -0
  359. package/dist/merchant-core/learning/service.d.ts +262 -0
  360. package/dist/merchant-core/learning/service.js +1498 -0
  361. package/dist/merchant-core/learning/service.js.map +1 -0
  362. package/dist/merchant-core/learning/test-dispatch-gateway.d.ts +43 -0
  363. package/dist/merchant-core/learning/test-dispatch-gateway.js +145 -0
  364. package/dist/merchant-core/learning/test-dispatch-gateway.js.map +1 -0
  365. package/dist/merchant-core/learning/types.d.ts +217 -0
  366. package/dist/merchant-core/learning/types.js +52 -0
  367. package/dist/merchant-core/learning/types.js.map +1 -0
  368. package/dist/merchant-core/migrations/ledgers.d.ts +40 -0
  369. package/dist/merchant-core/migrations/ledgers.js +824 -0
  370. package/dist/merchant-core/migrations/ledgers.js.map +1 -0
  371. package/dist/merchant-core/migrations/runner.d.ts +55 -0
  372. package/dist/merchant-core/migrations/runner.js +114 -0
  373. package/dist/merchant-core/migrations/runner.js.map +1 -0
  374. package/dist/merchant-core/operating/repository.d.ts +0 -1
  375. package/dist/merchant-core/operating/repository.js +2 -17
  376. package/dist/merchant-core/operating/repository.js.map +1 -1
  377. package/dist/merchant-core/operations-jobs/advice-runner.d.ts +63 -0
  378. package/dist/merchant-core/operations-jobs/advice-runner.js +199 -0
  379. package/dist/merchant-core/operations-jobs/advice-runner.js.map +1 -0
  380. package/dist/merchant-core/operations-jobs/pilot-evidence.d.ts +64 -0
  381. package/dist/merchant-core/operations-jobs/pilot-evidence.js +109 -0
  382. package/dist/merchant-core/operations-jobs/pilot-evidence.js.map +1 -0
  383. package/dist/merchant-core/operations-jobs/pilot-metrics.d.ts +70 -0
  384. package/dist/merchant-core/operations-jobs/pilot-metrics.js +98 -0
  385. package/dist/merchant-core/operations-jobs/pilot-metrics.js.map +1 -0
  386. package/dist/merchant-core/operations-jobs/projection.d.ts +41 -0
  387. package/dist/merchant-core/operations-jobs/projection.js +158 -0
  388. package/dist/merchant-core/operations-jobs/projection.js.map +1 -0
  389. package/dist/merchant-core/operations-jobs/scheduler.d.ts +68 -0
  390. package/dist/merchant-core/operations-jobs/scheduler.js +233 -0
  391. package/dist/merchant-core/operations-jobs/scheduler.js.map +1 -0
  392. package/dist/merchant-core/operations-jobs/service.d.ts +260 -0
  393. package/dist/merchant-core/operations-jobs/service.js +922 -0
  394. package/dist/merchant-core/operations-jobs/service.js.map +1 -0
  395. package/dist/merchant-core/opportunity/repository.d.ts +0 -1
  396. package/dist/merchant-core/opportunity/repository.js +2 -17
  397. package/dist/merchant-core/opportunity/repository.js.map +1 -1
  398. package/dist/merchant-core/ops/facade.d.ts +10 -0
  399. package/dist/merchant-core/ops/facade.js +52 -0
  400. package/dist/merchant-core/ops/facade.js.map +1 -1
  401. package/dist/merchant-core/ops/schema.d.ts +1 -1
  402. package/dist/merchant-core/ops/schema.js +119 -2
  403. package/dist/merchant-core/ops/schema.js.map +1 -1
  404. package/dist/merchant-core/ops/surface.d.ts +37 -0
  405. package/dist/merchant-core/ops/surface.js +240 -0
  406. package/dist/merchant-core/ops/surface.js.map +1 -1
  407. package/dist/merchant-core/orders/model.d.ts +1 -8
  408. package/dist/merchant-core/orders/model.js +10 -2
  409. package/dist/merchant-core/orders/model.js.map +1 -1
  410. package/dist/merchant-core/orders/repository.d.ts +0 -1
  411. package/dist/merchant-core/orders/repository.js +3 -18
  412. package/dist/merchant-core/orders/repository.js.map +1 -1
  413. package/dist/merchant-core/orders/service.js +34 -8
  414. package/dist/merchant-core/orders/service.js.map +1 -1
  415. package/dist/merchant-core/ownership/instance-ownership.d.ts +122 -0
  416. package/dist/merchant-core/ownership/instance-ownership.js +236 -0
  417. package/dist/merchant-core/ownership/instance-ownership.js.map +1 -0
  418. package/dist/merchant-core/ownership/runtime.d.ts +175 -0
  419. package/dist/merchant-core/ownership/runtime.js +422 -0
  420. package/dist/merchant-core/ownership/runtime.js.map +1 -0
  421. package/dist/merchant-core/proposal/engine.js +2 -0
  422. package/dist/merchant-core/proposal/engine.js.map +1 -1
  423. package/dist/merchant-core/proposal/publish.d.ts +0 -6
  424. package/dist/merchant-core/proposal/publish.js +37 -3
  425. package/dist/merchant-core/proposal/publish.js.map +1 -1
  426. package/dist/merchant-core/proposal/repository.d.ts +0 -7
  427. package/dist/merchant-core/proposal/repository.js +8 -17
  428. package/dist/merchant-core/proposal/repository.js.map +1 -1
  429. package/dist/merchant-core/proposal/types.d.ts +1 -0
  430. package/dist/merchant-core/proposal/types.js.map +1 -1
  431. package/dist/merchant-core/rfq/policy.d.ts +1 -0
  432. package/dist/merchant-core/rfq/policy.js +6 -7
  433. package/dist/merchant-core/rfq/policy.js.map +1 -1
  434. package/dist/merchant-core/rfq/repository.d.ts +0 -1
  435. package/dist/merchant-core/rfq/repository.js +2 -17
  436. package/dist/merchant-core/rfq/repository.js.map +1 -1
  437. package/dist/merchant-core/rfq/service.d.ts +2 -1
  438. package/dist/merchant-core/rfq/service.js +2 -4
  439. package/dist/merchant-core/rfq/service.js.map +1 -1
  440. package/dist/merchant-core/storage/transaction.d.ts +95 -7
  441. package/dist/merchant-core/storage/transaction.js +251 -2
  442. package/dist/merchant-core/storage/transaction.js.map +1 -1
  443. package/dist/merchant-credential-rotation.d.ts +4 -1
  444. package/dist/merchant-credential-rotation.js +12 -8
  445. package/dist/merchant-credential-rotation.js.map +1 -1
  446. package/dist/merchant-runtime/manager.d.ts +2 -0
  447. package/dist/merchant-runtime/manager.js +5 -0
  448. package/dist/merchant-runtime/manager.js.map +1 -1
  449. package/dist/negotiation/domain/objects.d.ts +2 -0
  450. package/dist/negotiation/domain/objects.js +3 -0
  451. package/dist/negotiation/domain/objects.js.map +1 -1
  452. package/dist/negotiation/ledger/store.d.ts +4 -0
  453. package/dist/negotiation/ledger/store.js +20 -0
  454. package/dist/negotiation/ledger/store.js.map +1 -1
  455. package/dist/product-init.d.ts +1 -0
  456. package/dist/product-init.js +4 -1
  457. package/dist/product-init.js.map +1 -1
  458. package/dist/trust/identity/message-signature.d.ts +1 -1
  459. package/dist/trust/identity/message-signature.js +6 -1
  460. package/dist/trust/identity/message-signature.js.map +1 -1
  461. package/dist/trust/identity/nonce.d.ts +5 -0
  462. package/dist/trust/identity/nonce.js +2 -0
  463. package/dist/trust/identity/nonce.js.map +1 -1
  464. package/dist/weixin/ilink-client.d.ts +3 -2
  465. package/dist/weixin/ilink-client.js +9 -2
  466. package/dist/weixin/ilink-client.js.map +1 -1
  467. package/package.json +2 -2
@@ -17,11 +17,21 @@ import { toMinorUnits } from "../../protocol/legacy-shopping-negotiation/money.j
17
17
  import { Agent, } from "@earendil-works/pi-agent-core";
18
18
  import { canonicalUnitToken, multiplyQuantitySafe, resolveUnitConversion, unitConversionPolicy, } from "../unit-alias.js";
19
19
  import { factRevision } from "./publish.js";
20
+ import { DEFAULT_QUESTION_SPEC_REGISTRY, } from "./question-spec.js";
21
+ import { receptionToolContractDigest } from "./skill-contract.js";
22
+ import { MAX_LOADED_SKILL_CHARS, MAX_LOADED_SKILLS, skillSummaryPrompt, } from "./skill-catalog.js";
23
+ import { ContextGuard, } from "../../merchant-core/context-governance/context-guard.js";
24
+ import { createActorContext } from "../../merchant-core/context-governance/actor-context.js";
25
+ import { MEMORY_NAMESPACES, MEMORY_SOURCE_KINDS, } from "../../merchant-core/customer-memory/types.js";
20
26
  export const TOOL_SEARCH_PRODUCTS = "search_products";
21
27
  export const TOOL_COMPARE_PRODUCTS = "compare_products";
22
28
  export const TOOL_GET_COMMERCIAL_FACTS = "get_commercial_facts";
23
29
  export const TOOL_PROPOSE_NEED_PATCH = "propose_need_patch";
24
30
  export const TOOL_PROPOSE_REPLY = "propose_reply";
31
+ export const TOOL_LOAD_RECEPTION_SKILL = "load_reception_skill";
32
+ export const TOOL_RECALL_CUSTOMER_CONTEXT = "recall_customer_context";
33
+ export const TOOL_SEARCH_CUSTOMER_HISTORY = "search_customer_history";
34
+ export const TOOL_PROPOSE_CUSTOMER_MEMORY = "propose_customer_memory";
25
35
  const RECEPTION_TOOL_ALLOWLIST = [
26
36
  TOOL_SEARCH_PRODUCTS,
27
37
  TOOL_COMPARE_PRODUCTS,
@@ -32,6 +42,7 @@ const RECEPTION_TOOL_ALLOWLIST = [
32
42
  const BLOCK_KINDS = new Set([
33
43
  "acknowledge_need",
34
44
  "ask_clarification",
45
+ "ask_registered_question",
35
46
  "show_commercial_terms",
36
47
  "recommend_option",
37
48
  "request_human_help",
@@ -45,11 +56,25 @@ const DEFAULT_SYSTEM_PROMPT = [
45
56
  "stock count, delivery date or any commercial fact; only the facts tool is authoritative.",
46
57
  "When the request is ambiguous or a required field is missing, ask one short",
47
58
  "clarification question. When ready, call propose_reply with typed blocks:",
48
- "acknowledge_need, ask_clarification, show_commercial_terms (using the fact ref),",
59
+ "acknowledge_need, ask_clarification, ask_registered_question (using a registered",
60
+ "question_id from the catalog), show_commercial_terms (using the fact ref),",
49
61
  "request_human_help or next_step. You may use recommend_option with a fact ref and",
50
62
  "compared refs from compare_products; reasonCode must be lowest_public_price or in_stock.",
51
63
  "Never write free-form commercial text.",
64
+ "Every reply block uses the field \"kind\" (never \"type\"). Required shapes:",
65
+ "{\"kind\":\"acknowledge_need\",\"sku\":\"SKU\",\"quantity\":2,\"unit\":\"件\"},",
66
+ "{\"kind\":\"show_commercial_terms\",\"ref\":{\"sku\":\"SKU\",\"revision\":\"sha256:...\"}},",
67
+ "{\"kind\":\"ask_clarification\",\"missing\":[\"quantity\"],\"reason\":\"missing_quantity\"},",
68
+ "{\"kind\":\"ask_registered_question\",\"question_id\":\"q_missing_quantity_v1\"},",
69
+ "{\"kind\":\"next_step\",\"action\":\"send_rfq\"}.",
70
+ "Do not add free-text fields to next_step; the publisher renders all text.",
71
+ "History search hits mean the buyer only asked before: say 曾询价, never 购买 or 已购买;",
72
+ "history is not a current quote. Re-read commercial facts before any price/stock claim.",
52
73
  ].join(" ");
74
+ function buildReceptionSystemPrompt(registry) {
75
+ const catalog = registry.catalogText();
76
+ return catalog === "" ? DEFAULT_SYSTEM_PROMPT : `${DEFAULT_SYSTEM_PROMPT} ${catalog}`;
77
+ }
53
78
  function toolResult(text, details = {}) {
54
79
  return { content: [{ type: "text", text }], details };
55
80
  }
@@ -134,17 +159,32 @@ function buyerUnitMatchesPolicy(policy, buyerUnit, requestedUnit) {
134
159
  function isObject(value) {
135
160
  return typeof value === "object" && value !== null && !Array.isArray(value);
136
161
  }
162
+ /** 严格 schema:模型块只允许固定字段,未知字段直接拒绝(X02)。 */
163
+ function hasOnlyKeys(item, allowed) {
164
+ return Object.keys(item).every((key) => allowed.includes(key));
165
+ }
137
166
  /** 把模型提交的 blocks 限缩到白名单结构;引用仍由发布器校验。 */
138
- export function sanitizeReceptionBlocks(value) {
167
+ export function sanitizeReceptionBlocks(value, questionRegistry = DEFAULT_QUESTION_SPEC_REGISTRY) {
139
168
  if (!Array.isArray(value) || value.length === 0 || value.length > 6)
140
169
  return undefined;
141
170
  const blocks = [];
142
171
  for (const item of value) {
143
- if (!isObject(item) || typeof item.kind !== "string" || !BLOCK_KINDS.has(item.kind)) {
172
+ if (!isObject(item))
144
173
  return undefined;
145
- }
146
- switch (item.kind) {
174
+ // 兼容别名:部分模型把块类型写成 `type`;规范化后仍按 `kind` 严格校验
175
+ // 字段(不扩大允许的块种类)。
176
+ const kind = typeof item.kind === "string"
177
+ ? item.kind
178
+ : typeof item.type === "string"
179
+ ? item.type
180
+ : undefined;
181
+ if (kind === undefined || !BLOCK_KINDS.has(kind))
182
+ return undefined;
183
+ switch (kind) {
147
184
  case "acknowledge_need": {
185
+ if (!hasOnlyKeys(item, ["kind", "type", "sku", "quantity", "unit", "convertedFrom"])) {
186
+ return undefined;
187
+ }
148
188
  const sku = typeof item.sku === "string" && item.sku.trim() !== "" ? item.sku.trim() : undefined;
149
189
  const quantity = typeof item.quantity === "number" && Number.isSafeInteger(item.quantity) && item.quantity > 0
150
190
  ? item.quantity
@@ -159,6 +199,9 @@ export function sanitizeReceptionBlocks(value) {
159
199
  break;
160
200
  }
161
201
  case "ask_clarification": {
202
+ if (!hasOnlyKeys(item, ["kind", "type", "reason", "candidates", "missing"])) {
203
+ return undefined;
204
+ }
162
205
  const reason = item.reason;
163
206
  if (reason !== "missing_sku" &&
164
207
  reason !== "unknown_sku" &&
@@ -180,7 +223,65 @@ export function sanitizeReceptionBlocks(value) {
180
223
  });
181
224
  break;
182
225
  }
226
+ case "ask_registered_question": {
227
+ if (!hasOnlyKeys(item, [
228
+ "kind",
229
+ "type",
230
+ "question_id",
231
+ "schema_version",
232
+ "slot",
233
+ "reason_code",
234
+ "candidate_refs",
235
+ ])) {
236
+ return undefined;
237
+ }
238
+ const questionId = typeof item.question_id === "string" ? item.question_id.trim() : "";
239
+ if (questionId.length === 0 || questionId.length > 64)
240
+ return undefined;
241
+ // 服务端按注册表补齐契约字段:模型只需选择 question_id。若显式提供了
242
+ // schema/slot/reason,必须与注册表一致(不允许模型改写契约)。
243
+ const spec = questionRegistry.resolve(questionId);
244
+ if (spec === undefined)
245
+ return undefined;
246
+ const schemaVersion = item.schema_version === undefined ? spec.schema_version : item.schema_version;
247
+ const slot = item.slot === undefined ? spec.slot : item.slot;
248
+ const reasonCode = item.reason_code === undefined ? spec.reason_code : item.reason_code;
249
+ if (slot !== "sku" && slot !== "quantity" && slot !== "unit")
250
+ return undefined;
251
+ if (typeof schemaVersion !== "number" ||
252
+ !Number.isSafeInteger(schemaVersion) ||
253
+ schemaVersion !== spec.schema_version ||
254
+ slot !== spec.slot ||
255
+ typeof reasonCode !== "string" ||
256
+ reasonCode !== spec.reason_code) {
257
+ return undefined;
258
+ }
259
+ // P2-8:候选引用会原样渲染进买家可见文本;模型输出是不可信数据,
260
+ // 只允许短、无控制字符的引用,并去重(不能借模板注入任意文案)。
261
+ const candidateRefs = Array.isArray(item.candidate_refs)
262
+ ? [
263
+ ...new Set(item.candidate_refs
264
+ .filter((candidate) => typeof candidate === "string")
265
+ .map((candidate) => candidate.trim())
266
+ // eslint-disable-next-line no-control-regex
267
+ .filter((candidate) => candidate.length > 0 && candidate.length <= 64 && !/[\u0000-\u001f\u007f]/.test(candidate))),
268
+ ].slice(0, 8)
269
+ : undefined;
270
+ blocks.push({
271
+ kind: "ask_registered_question",
272
+ question_id: questionId,
273
+ schema_version: schemaVersion,
274
+ slot,
275
+ reason_code: reasonCode,
276
+ ...(candidateRefs !== undefined && candidateRefs.length > 0
277
+ ? { candidate_refs: candidateRefs }
278
+ : {}),
279
+ });
280
+ break;
281
+ }
183
282
  case "show_commercial_terms": {
283
+ if (!hasOnlyKeys(item, ["kind", "type", "ref", "topics"]))
284
+ return undefined;
184
285
  const ref = item.ref;
185
286
  if (!isObject(ref) ||
186
287
  typeof ref.sku !== "string" ||
@@ -198,6 +299,9 @@ export function sanitizeReceptionBlocks(value) {
198
299
  break;
199
300
  }
200
301
  case "recommend_option": {
302
+ if (!hasOnlyKeys(item, ["kind", "type", "ref", "comparedRefs", "reasonCode"])) {
303
+ return undefined;
304
+ }
201
305
  const ref = item.ref;
202
306
  if (!isObject(ref) || typeof ref.sku !== "string" || typeof ref.revision !== "string") {
203
307
  return undefined;
@@ -222,8 +326,10 @@ export function sanitizeReceptionBlocks(value) {
222
326
  break;
223
327
  }
224
328
  case "request_human_help": {
225
- if (item.topic !== "price_below_public_bound")
329
+ if (!hasOnlyKeys(item, ["kind", "type", "topic", "buyerTargetPrice", "currency"]) ||
330
+ item.topic !== "price_below_public_bound") {
226
331
  return undefined;
332
+ }
227
333
  const buyerTargetPrice = typeof item.buyerTargetPrice === "number" && Number.isFinite(item.buyerTargetPrice)
228
334
  ? item.buyerTargetPrice
229
335
  : undefined;
@@ -237,8 +343,9 @@ export function sanitizeReceptionBlocks(value) {
237
343
  break;
238
344
  }
239
345
  case "next_step": {
240
- if (item.action !== "send_rfq")
346
+ if (!hasOnlyKeys(item, ["kind", "type", "action"]) || item.action !== "send_rfq") {
241
347
  return undefined;
348
+ }
242
349
  blocks.push({ kind: "next_step", action: "send_rfq" });
243
350
  break;
244
351
  }
@@ -277,18 +384,113 @@ export function createPiReceptionRuntime(options) {
277
384
  const rejectedFactUnits = new Map();
278
385
  const buyerQuantity = parseBuyerQuantity(input.text);
279
386
  const boundSku = input.structuredSku?.trim() || undefined;
387
+ // M2-6/M3-6:技能目录 + 客户绑定/运行快照/四检查点守卫。
388
+ const skillCatalog = options.skillCatalog;
389
+ const skillBindings = skillCatalog?.activeBindings(input.merchantId) ?? [];
390
+ const skillSummaries = skillCatalog?.summaries(input.merchantId);
391
+ const skillSummaryText = skillSummaries !== undefined ? skillSummaryPrompt(skillSummaries) : "";
392
+ const customerContext = options.customerProvider?.contextFor(input.merchantId, input.identity);
393
+ const guardEnabled = skillCatalog !== undefined || customerContext !== undefined;
394
+ let receptionGuard;
395
+ let receptionSnapshot;
396
+ const receptionActor = !guardEnabled
397
+ ? undefined
398
+ : createActorContext({
399
+ merchant_id: input.merchantId,
400
+ actor_id: `reception:${input.identity}`.slice(0, 128),
401
+ auth_strength: "session",
402
+ subject_binding: customerContext !== undefined ? "organization" : "none",
403
+ capabilities: customerContext !== undefined
404
+ ? ["reception:serve", "customer:self", "memory:read"]
405
+ : ["reception:serve"],
406
+ });
407
+ if (guardEnabled && receptionActor !== undefined) {
408
+ const configVersion = receptionToolContractDigest();
409
+ receptionSnapshot = {
410
+ snapshot_id: `run_${input.contextId}`.slice(0, 128),
411
+ issued_at: input.now,
412
+ binding_epoch: customerContext?.binding_epoch ?? 0,
413
+ grant_versions: customerContext?.grant_versions ?? {},
414
+ data_scope_epochs: customerContext?.data_scope_epochs ?? {},
415
+ memory_set_version: customerContext?.memory_set_version ?? 0,
416
+ conversation_revision: 0,
417
+ config_version: configVersion,
418
+ skill_bindings: skillBindings.map((binding) => ({
419
+ skill_key: binding.skill_key,
420
+ release_id: binding.release_id,
421
+ compiled_artifact_hash: binding.compiled_artifact_hash,
422
+ generation: binding.generation,
423
+ revocation_epoch: binding.revocation_epoch,
424
+ })),
425
+ };
426
+ const authority = {
427
+ currentGrantEpoch: (merchantId, grantId) => options.customerProvider?.currentGrantEpoch(merchantId, grantId),
428
+ currentBindingEpoch: (merchantId) => options.customerProvider?.currentBindingEpoch(merchantId, input.identity),
429
+ currentDataScopeEpoch: (merchantId, scopeKey) => options.customerProvider?.currentDataScopeEpoch(merchantId, scopeKey),
430
+ currentSkillBinding: (merchantId, skillKey) => skillCatalog?.currentBinding(merchantId, skillKey),
431
+ currentMemorySetVersion: (merchantId) => customerContext === undefined
432
+ ? undefined
433
+ : options.customerProvider?.currentMemorySetVersion(merchantId, customerContext.subject_id),
434
+ currentConversationRevision: () => undefined,
435
+ currentConfigVersion: () => configVersion,
436
+ sourceAvailable: () => false,
437
+ };
438
+ receptionGuard = new ContextGuard({ authority, now: () => input.now });
439
+ }
440
+ const checkGuard = (checkpoint, tool) => {
441
+ if (receptionGuard === undefined ||
442
+ receptionActor === undefined ||
443
+ receptionSnapshot === undefined) {
444
+ return;
445
+ }
446
+ const base = {
447
+ actor: receptionActor,
448
+ snapshot: receptionSnapshot,
449
+ capability: "reception:serve",
450
+ };
451
+ if (checkpoint === "tool_call") {
452
+ receptionGuard.checkToolCall({ ...base, ...(tool !== undefined ? { tool } : {}) });
453
+ }
454
+ else if (checkpoint === "provider_attempt") {
455
+ receptionGuard.checkProviderAttempt(base);
456
+ }
457
+ else {
458
+ receptionGuard.checkPublish(base);
459
+ }
460
+ };
461
+ const canProposeMemory = customerContext !== undefined && options.customerProvider !== undefined && (options.customerProvider.canPropose?.(customerContext) ?? true);
462
+ const allowedTools = [
463
+ ...RECEPTION_TOOL_ALLOWLIST,
464
+ ...(skillCatalog !== undefined && skillBindings.length > 0
465
+ ? [TOOL_LOAD_RECEPTION_SKILL]
466
+ : []),
467
+ ...(customerContext !== undefined
468
+ ? [
469
+ TOOL_RECALL_CUSTOMER_CONTEXT,
470
+ TOOL_SEARCH_CUSTOMER_HISTORY,
471
+ ...(canProposeMemory ? [TOOL_PROPOSE_CUSTOMER_MEMORY] : []),
472
+ ]
473
+ : []),
474
+ ];
475
+ let loadedSkillCount = 0;
476
+ let loadedSkillChars = 0;
477
+ const loadedSkills = [];
280
478
  let steps = 0;
281
479
  let toolAttempts = 0;
282
480
  let timedOut = false;
481
+ let toolBudgetExhausted = false;
283
482
  const guard = async (context) => {
284
- if (!RECEPTION_TOOL_ALLOWLIST.includes(context.toolCall.name)) {
483
+ if (!allowedTools.includes(context.toolCall.name)) {
285
484
  return { block: true, reason: "tool_not_allowed" };
286
485
  }
486
+ // 每次工具调用前检查权限/技能绑定/版本;异常向引擎抛出 → 回退确定性。
487
+ checkGuard("tool_call", context.toolCall.name);
287
488
  if (plan !== undefined) {
288
489
  return { block: true, reason: "reply_already_proposed" };
289
490
  }
290
491
  toolAttempts += 1;
291
492
  if (toolAttempts > (options.maxToolAttempts ?? 12)) {
493
+ toolBudgetExhausted = true;
292
494
  return { block: true, reason: "tool_budget_exhausted" };
293
495
  }
294
496
  const serialized = JSON.stringify(context.toolCall.arguments ?? {});
@@ -679,6 +881,184 @@ export function createPiReceptionRuntime(options) {
679
881
  return toolResult(JSON.stringify({ accepted: true }));
680
882
  },
681
883
  },
884
+ ...(skillCatalog !== undefined && skillBindings.length > 0
885
+ ? [
886
+ {
887
+ name: TOOL_LOAD_RECEPTION_SKILL,
888
+ label: "Load reception skill",
889
+ description: "Load one published reception skill by skill_key from this run's summaries.",
890
+ parameters: {
891
+ type: "object",
892
+ additionalProperties: false,
893
+ properties: { skill_key: { type: "string" } },
894
+ required: ["skill_key"],
895
+ },
896
+ execute: async (_id, params) => {
897
+ const args = params;
898
+ const skillKey = isObject(args) && typeof args.skill_key === "string"
899
+ ? args.skill_key.trim()
900
+ : "";
901
+ const binding = skillBindings.find((item) => item.skill_key === skillKey);
902
+ if (binding === undefined) {
903
+ loadedSkills.push({
904
+ skill_key: skillKey,
905
+ release_id: "",
906
+ accepted: false,
907
+ reason: "skill_not_bound",
908
+ });
909
+ return toolResult(JSON.stringify({ accepted: false, error: "skill_not_bound" }));
910
+ }
911
+ if (loadedSkillCount >= MAX_LOADED_SKILLS) {
912
+ loadedSkills.push({
913
+ skill_key: skillKey,
914
+ release_id: binding.release_id,
915
+ accepted: false,
916
+ reason: "max_skills",
917
+ });
918
+ return toolResult(JSON.stringify({
919
+ accepted: false,
920
+ error: "skill_limit_exceeded",
921
+ reason: "max_skills",
922
+ }));
923
+ }
924
+ const artifact = skillCatalog.loadArtifact(input.merchantId, skillKey, binding.release_id);
925
+ if (artifact === undefined) {
926
+ loadedSkills.push({
927
+ skill_key: skillKey,
928
+ release_id: binding.release_id,
929
+ accepted: false,
930
+ reason: "skill_unavailable",
931
+ });
932
+ return toolResult(JSON.stringify({ accepted: false, error: "skill_unavailable" }));
933
+ }
934
+ if (loadedSkillChars + artifact.body_text.length >
935
+ MAX_LOADED_SKILL_CHARS) {
936
+ loadedSkills.push({
937
+ skill_key: skillKey,
938
+ release_id: binding.release_id,
939
+ accepted: false,
940
+ reason: "body_budget",
941
+ });
942
+ return toolResult(JSON.stringify({
943
+ accepted: false,
944
+ error: "skill_limit_exceeded",
945
+ reason: "body_budget",
946
+ }));
947
+ }
948
+ loadedSkillCount += 1;
949
+ loadedSkillChars += artifact.body_text.length;
950
+ loadedSkills.push({
951
+ skill_key: artifact.skill_key,
952
+ release_id: artifact.release_id,
953
+ accepted: true,
954
+ });
955
+ return toolResult(JSON.stringify({
956
+ accepted: true,
957
+ skill_key: artifact.skill_key,
958
+ release_id: artifact.release_id,
959
+ compiled_artifact_hash: artifact.compiled_artifact_hash,
960
+ question_schema_version: artifact.question_schema_version,
961
+ required_tools: artifact.required_tools,
962
+ steps: artifact.steps,
963
+ body_text: artifact.body_text,
964
+ }));
965
+ },
966
+ },
967
+ ]
968
+ : []),
969
+ ...(customerContext !== undefined && options.customerProvider !== undefined
970
+ ? [
971
+ {
972
+ name: TOOL_RECALL_CUSTOMER_CONTEXT,
973
+ label: "Recall customer context",
974
+ description: "Read this bound subject's active memory items (minimum fields only).",
975
+ parameters: { type: "object", additionalProperties: false, properties: {} },
976
+ execute: async () => {
977
+ const items = options.customerProvider.recall(customerContext);
978
+ return toolResult(JSON.stringify({ status: "ok", items }));
979
+ },
980
+ },
981
+ {
982
+ name: TOOL_SEARCH_CUSTOMER_HISTORY,
983
+ label: "Search customer history",
984
+ description: "Search this bound subject's authorized history; at most 5 snippets.",
985
+ parameters: {
986
+ type: "object",
987
+ additionalProperties: false,
988
+ properties: {
989
+ query: { type: "string" },
990
+ cursor: { type: "string" },
991
+ },
992
+ required: ["query"],
993
+ },
994
+ execute: async (_id, params) => {
995
+ const args = params;
996
+ if (!isObject(args) || typeof args.query !== "string") {
997
+ return toolResult(JSON.stringify({ status: "unavailable", reason: "invalid_query" }));
998
+ }
999
+ const cursor = typeof args.cursor === "string" && args.cursor.trim() !== ""
1000
+ ? args.cursor.trim()
1001
+ : undefined;
1002
+ const result = options.customerProvider.search(customerContext, {
1003
+ query: args.query,
1004
+ ...(cursor !== undefined ? { cursor } : {}),
1005
+ });
1006
+ return toolResult(JSON.stringify(result));
1007
+ },
1008
+ },
1009
+ ]
1010
+ : []),
1011
+ ...(canProposeMemory && customerContext !== undefined && options.customerProvider !== undefined
1012
+ ? [
1013
+ {
1014
+ name: TOOL_PROPOSE_CUSTOMER_MEMORY,
1015
+ label: "Propose customer memory",
1016
+ description: "Propose a customer memory candidate. It stays candidate until the customer confirms.",
1017
+ parameters: {
1018
+ type: "object",
1019
+ additionalProperties: false,
1020
+ properties: {
1021
+ namespace: { type: "string" },
1022
+ key: { type: "string" },
1023
+ value_ref: { type: "string" },
1024
+ value_type: { type: "string" },
1025
+ source_kind: { type: "string" },
1026
+ confidence: { type: "number" },
1027
+ },
1028
+ required: ["namespace", "key", "value_ref", "value_type", "source_kind"],
1029
+ },
1030
+ execute: async (_id, params) => {
1031
+ const args = params;
1032
+ if (!isObject(args) ||
1033
+ typeof args.namespace !== "string" ||
1034
+ !MEMORY_NAMESPACES.includes(args.namespace) ||
1035
+ typeof args.key !== "string" ||
1036
+ typeof args.value_ref !== "string" ||
1037
+ typeof args.value_type !== "string" ||
1038
+ typeof args.source_kind !== "string" ||
1039
+ !MEMORY_SOURCE_KINDS.includes(args.source_kind)) {
1040
+ return toolResult(JSON.stringify({ accepted: false, error: "invalid_memory" }));
1041
+ }
1042
+ try {
1043
+ const proposal = await options.customerProvider.propose(customerContext, {
1044
+ namespace: args.namespace,
1045
+ key: args.key,
1046
+ value_ref: args.value_ref,
1047
+ value_type: args.value_type,
1048
+ source_kind: args.source_kind,
1049
+ ...(typeof args.confidence === "number"
1050
+ ? { confidence: args.confidence }
1051
+ : {}),
1052
+ });
1053
+ return toolResult(JSON.stringify({ accepted: true, ...proposal }));
1054
+ }
1055
+ catch {
1056
+ return toolResult(JSON.stringify({ accepted: false, error: "proposal_rejected" }));
1057
+ }
1058
+ },
1059
+ },
1060
+ ]
1061
+ : []),
682
1062
  {
683
1063
  name: TOOL_PROPOSE_REPLY,
684
1064
  label: "Propose reply",
@@ -695,8 +1075,13 @@ export function createPiReceptionRuntime(options) {
695
1075
  const args = params;
696
1076
  if (!isObject(args))
697
1077
  return toolResult(JSON.stringify({ accepted: false, error: "invalid_plan" }));
698
- const blocks = sanitizeReceptionBlocks(args.blocks);
1078
+ const blocks = sanitizeReceptionBlocks(args.blocks, options.questionRegistry ?? DEFAULT_QUESTION_SPEC_REGISTRY);
699
1079
  if (blocks === undefined) {
1080
+ // 诊断开关:记录模型原始 blocks(不含买家原文/密钥),便于定位
1081
+ // 输出契约漂移;默认关闭,不改变生产日志。
1082
+ if (process.env.KIWI_RECEPTION_DEBUG_PROPOSE === "1") {
1083
+ process.stderr.write(`[reception] invalid_blocks ${JSON.stringify(args.blocks).slice(0, 3000)}\n`);
1084
+ }
700
1085
  return toolResult(JSON.stringify({ accepted: false, error: "invalid_blocks" }));
701
1086
  }
702
1087
  if (boundSku !== undefined) {
@@ -746,10 +1131,24 @@ export function createPiReceptionRuntime(options) {
746
1131
  },
747
1132
  },
748
1133
  ];
1134
+ const baseSystemPrompt = options.systemPrompt ??
1135
+ buildReceptionSystemPrompt(options.questionRegistry ?? DEFAULT_QUESTION_SPEC_REGISTRY);
1136
+ const customerPrompt = customerContext !== undefined
1137
+ ? "Customer memory/history tools are bound to the current subject; never expose other subjects or infer identity."
1138
+ : "";
1139
+ const systemPrompt = [baseSystemPrompt, skillSummaryText, customerPrompt]
1140
+ .filter((part) => part.trim() !== "")
1141
+ .join("\n\n");
1142
+ const guardedStreamFn = skillCatalog === undefined
1143
+ ? options.streamFn
1144
+ : ((...args) => {
1145
+ checkGuard("provider_attempt");
1146
+ return options.streamFn(...args);
1147
+ });
749
1148
  const agent = new Agent({
750
- streamFn: options.streamFn,
1149
+ streamFn: guardedStreamFn,
751
1150
  initialState: {
752
- systemPrompt: options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT,
1151
+ systemPrompt,
753
1152
  model: options.model,
754
1153
  tools,
755
1154
  },
@@ -763,10 +1162,12 @@ export function createPiReceptionRuntime(options) {
763
1162
  steps: 0,
764
1163
  toolCalls: {},
765
1164
  usage: { input: 0, output: 0, total: 0 },
1165
+ loadedSkills,
766
1166
  };
767
1167
  let activeLease;
768
1168
  let lastSettledOutput = 0;
769
1169
  let quotaRejected = false;
1170
+ let modelFailed = false;
770
1171
  agent.subscribe((event) => {
771
1172
  if (event.type === "turn_start") {
772
1173
  if (options.budget !== undefined) {
@@ -782,6 +1183,8 @@ export function createPiReceptionRuntime(options) {
782
1183
  return undefined;
783
1184
  }
784
1185
  if (event.type === "message_end" && event.message.role === "assistant") {
1186
+ if (event.message.stopReason === "error" || event.message.stopReason === "aborted")
1187
+ modelFailed = true;
785
1188
  const usage = event.message.usage;
786
1189
  metrics.usage.input += usage.input;
787
1190
  metrics.usage.output += usage.output;
@@ -821,6 +1224,7 @@ export function createPiReceptionRuntime(options) {
821
1224
  await agent.waitForIdle();
822
1225
  }
823
1226
  catch {
1227
+ modelFailed = true;
824
1228
  // 回退确定性路径;未结算的预算 lease 在 finally 按未知用量保留。
825
1229
  }
826
1230
  finally {
@@ -833,8 +1237,13 @@ export function createPiReceptionRuntime(options) {
833
1237
  if (quotaRejected)
834
1238
  metrics.quotaRejected = true;
835
1239
  options.onMetrics?.(metrics);
1240
+ if (options.requireCompleteModelRun === true && (timedOut || quotaRejected || modelFailed || toolBudgetExhausted)) {
1241
+ throw new Error("evaluation_runtime_outcome_unknown");
1242
+ }
836
1243
  if (plan === undefined || timedOut || quotaRejected)
837
1244
  return undefined;
1245
+ // 发布前最后一次版本/撤回检查;失败抛出 → 引擎丢弃模型计划并回退确定性。
1246
+ checkGuard("publish");
838
1247
  return {
839
1248
  plan,
840
1249
  ...(Object.keys(needPatch).length > 0 ? { need: needPatch } : {}),