@harrylabsj/kiwi-merchant-cloud 0.12.31 → 0.12.32

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 (314) hide show
  1. package/app/a2a/node.d.ts +1 -0
  2. package/app/a2a/node.js +170 -2
  3. package/app/a2a/node.js.map +1 -1
  4. package/app/a2a/reception/agent-runtime.d.ts +32 -1
  5. package/app/a2a/reception/agent-runtime.js +420 -11
  6. package/app/a2a/reception/agent-runtime.js.map +1 -1
  7. package/app/a2a/reception/customer-memory-tools.d.ts +73 -0
  8. package/app/a2a/reception/customer-memory-tools.js +17 -0
  9. package/app/a2a/reception/customer-memory-tools.js.map +1 -0
  10. package/app/a2a/reception/engine.d.ts +12 -0
  11. package/app/a2a/reception/engine.js +42 -1
  12. package/app/a2a/reception/engine.js.map +1 -1
  13. package/app/a2a/reception/publish.d.ts +14 -1
  14. package/app/a2a/reception/publish.js +62 -1
  15. package/app/a2a/reception/publish.js.map +1 -1
  16. package/app/a2a/reception/question-spec.d.ts +91 -0
  17. package/app/a2a/reception/question-spec.js +260 -0
  18. package/app/a2a/reception/question-spec.js.map +1 -0
  19. package/app/a2a/reception/reply-outbox.d.ts +6 -0
  20. package/app/a2a/reception/reply-outbox.js +44 -0
  21. package/app/a2a/reception/reply-outbox.js.map +1 -1
  22. package/app/a2a/reception/responder.d.ts +13 -1
  23. package/app/a2a/reception/responder.js +26 -3
  24. package/app/a2a/reception/responder.js.map +1 -1
  25. package/app/a2a/reception/skill-catalog.d.ts +72 -0
  26. package/app/a2a/reception/skill-catalog.js +85 -0
  27. package/app/a2a/reception/skill-catalog.js.map +1 -0
  28. package/app/a2a/reception/skill-contract.d.ts +70 -0
  29. package/app/a2a/reception/skill-contract.js +183 -0
  30. package/app/a2a/reception/skill-contract.js.map +1 -0
  31. package/app/a2a/reception/types.d.ts +12 -0
  32. package/app/a2a/server/customer-identity-gateway.d.ts +111 -0
  33. package/app/a2a/server/customer-identity-gateway.js +441 -0
  34. package/app/a2a/server/customer-identity-gateway.js.map +1 -0
  35. package/app/a2a/server/merchant-handler.d.ts +34 -0
  36. package/app/a2a/server/merchant-handler.js +439 -19
  37. package/app/a2a/server/merchant-handler.js.map +1 -1
  38. package/app/a2a/server/pipeline.js +74 -29
  39. package/app/a2a/server/pipeline.js.map +1 -1
  40. package/app/a2a/server/types.d.ts +2 -0
  41. package/app/a2a/unit-alias.d.ts +3 -3
  42. package/app/a2a/unit-alias.js +9 -5
  43. package/app/a2a/unit-alias.js.map +1 -1
  44. package/app/auth/merchant-sessions.d.ts +3 -0
  45. package/app/auth/merchant-sessions.js +21 -5
  46. package/app/auth/merchant-sessions.js.map +1 -1
  47. package/app/buyer-core/a2a-knp.d.ts +4 -2
  48. package/app/buyer-core/a2a-knp.js +5 -2
  49. package/app/buyer-core/a2a-knp.js.map +1 -1
  50. package/app/buyer-core/a2a-negotiator.d.ts +1 -0
  51. package/app/buyer-core/a2a-negotiator.js +18 -11
  52. package/app/buyer-core/a2a-negotiator.js.map +1 -1
  53. package/app/buyer-core/a2a-quote-fetcher.d.ts +25 -0
  54. package/app/buyer-core/a2a-quote-fetcher.js +82 -4
  55. package/app/buyer-core/a2a-quote-fetcher.js.map +1 -1
  56. package/app/buyer-core/a2a-quote-history.d.ts +94 -0
  57. package/app/buyer-core/a2a-quote-history.js +149 -0
  58. package/app/buyer-core/a2a-quote-history.js.map +1 -0
  59. package/app/buyer-core/build-service.d.ts +19 -0
  60. package/app/buyer-core/build-service.js +30 -1
  61. package/app/buyer-core/build-service.js.map +1 -1
  62. package/app/buyer-core/errors.d.ts +1 -1
  63. package/app/buyer-core/errors.js +1 -0
  64. package/app/buyer-core/errors.js.map +1 -1
  65. package/app/buyer-core/open-inquiry-signer.d.ts +1 -0
  66. package/app/buyer-core/open-inquiry-signer.js +5 -2
  67. package/app/buyer-core/open-inquiry-signer.js.map +1 -1
  68. package/app/buyer-core/protocol-recovery.d.ts +2 -1
  69. package/app/buyer-core/protocol-recovery.js +14 -4
  70. package/app/buyer-core/protocol-recovery.js.map +1 -1
  71. package/app/buyer-core/service.d.ts +57 -5
  72. package/app/buyer-core/service.js +275 -50
  73. package/app/buyer-core/service.js.map +1 -1
  74. package/app/buyer-core/store.d.ts +8 -0
  75. package/app/buyer-core/store.js +37 -7
  76. package/app/buyer-core/store.js.map +1 -1
  77. package/app/cli.js +13 -2
  78. package/app/cli.js.map +1 -1
  79. package/app/cloud/bootstrap.js +141 -7
  80. package/app/cloud/bootstrap.js.map +1 -1
  81. package/app/cloud-sample/products.json +3 -3
  82. package/app/commerce/receipt/dispatcher.d.ts +42 -0
  83. package/app/commerce/receipt/dispatcher.js +68 -0
  84. package/app/commerce/receipt/dispatcher.js.map +1 -0
  85. package/app/commerce/receipt/receipts.d.ts +140 -0
  86. package/app/commerce/receipt/receipts.js +247 -0
  87. package/app/commerce/receipt/receipts.js.map +1 -0
  88. package/app/config/profile.d.ts +2 -2
  89. package/app/handoff/order-receipts.d.ts +62 -0
  90. package/app/handoff/order-receipts.js +71 -0
  91. package/app/handoff/order-receipts.js.map +1 -0
  92. package/app/handoff/ucp-checkout/cart-channel.d.ts +2 -1
  93. package/app/handoff/ucp-checkout/cart-channel.js +1 -0
  94. package/app/handoff/ucp-checkout/cart-channel.js.map +1 -1
  95. package/app/handoff/ucp-checkout/channel.d.ts +6 -0
  96. package/app/handoff/ucp-checkout/channel.js +44 -0
  97. package/app/handoff/ucp-checkout/channel.js.map +1 -1
  98. package/app/http/cli.js +6 -0
  99. package/app/http/cli.js.map +1 -1
  100. package/app/http/merchant-management/api.d.ts +10 -0
  101. package/app/http/merchant-management/api.js +443 -0
  102. package/app/http/merchant-management/api.js.map +1 -1
  103. package/app/http/merchant-management/draft-store.js +8 -6
  104. package/app/http/merchant-management/draft-store.js.map +1 -1
  105. package/app/http/merchant-management/page.js +2 -2
  106. package/app/mcp/cli.js +6 -0
  107. package/app/mcp/cli.js.map +1 -1
  108. package/app/mcp/merchant-runtime-assembly.d.ts +20 -0
  109. package/app/mcp/merchant-runtime-assembly.js +93 -3
  110. package/app/mcp/merchant-runtime-assembly.js.map +1 -1
  111. package/app/mcp/merchant-server.d.ts +5 -0
  112. package/app/mcp/merchant-server.js +12 -0
  113. package/app/mcp/merchant-server.js.map +1 -1
  114. package/app/mcp/tools.js +7 -1
  115. package/app/mcp/tools.js.map +1 -1
  116. package/app/merchant/application/actor.d.ts +1 -1
  117. package/app/merchant/application/actor.js +15 -0
  118. package/app/merchant/application/actor.js.map +1 -1
  119. package/app/merchant/workbench-server.d.ts +1 -0
  120. package/app/merchant/workbench-server.js +176 -2
  121. package/app/merchant/workbench-server.js.map +1 -1
  122. package/app/merchant-core/budget/background-budget.d.ts +132 -0
  123. package/app/merchant-core/budget/background-budget.js +308 -0
  124. package/app/merchant-core/budget/background-budget.js.map +1 -0
  125. package/app/merchant-core/context-governance/actor-context.d.ts +56 -0
  126. package/app/merchant-core/context-governance/actor-context.js +76 -0
  127. package/app/merchant-core/context-governance/actor-context.js.map +1 -0
  128. package/app/merchant-core/context-governance/authority.d.ts +39 -0
  129. package/app/merchant-core/context-governance/authority.js +28 -0
  130. package/app/merchant-core/context-governance/authority.js.map +1 -0
  131. package/app/merchant-core/context-governance/context-guard.d.ts +104 -0
  132. package/app/merchant-core/context-governance/context-guard.js +194 -0
  133. package/app/merchant-core/context-governance/context-guard.js.map +1 -0
  134. package/app/merchant-core/context-governance/data-use-grant.d.ts +91 -0
  135. package/app/merchant-core/context-governance/data-use-grant.js +211 -0
  136. package/app/merchant-core/context-governance/data-use-grant.js.map +1 -0
  137. package/app/merchant-core/context-governance/feature-flags.d.ts +32 -0
  138. package/app/merchant-core/context-governance/feature-flags.js +83 -0
  139. package/app/merchant-core/context-governance/feature-flags.js.map +1 -0
  140. package/app/merchant-core/context-governance/pilot-readiness.d.ts +39 -0
  141. package/app/merchant-core/context-governance/pilot-readiness.js +141 -0
  142. package/app/merchant-core/context-governance/pilot-readiness.js.map +1 -0
  143. package/app/merchant-core/context-governance/source-governance.d.ts +157 -0
  144. package/app/merchant-core/context-governance/source-governance.js +492 -0
  145. package/app/merchant-core/context-governance/source-governance.js.map +1 -0
  146. package/app/merchant-core/context-governance/types.d.ts +62 -0
  147. package/app/merchant-core/context-governance/types.js +92 -0
  148. package/app/merchant-core/context-governance/types.js.map +1 -0
  149. package/app/merchant-core/customer-delivery/binding.d.ts +55 -0
  150. package/app/merchant-core/customer-delivery/binding.js +121 -0
  151. package/app/merchant-core/customer-delivery/binding.js.map +1 -0
  152. package/app/merchant-core/customer-delivery/channel.d.ts +75 -0
  153. package/app/merchant-core/customer-delivery/channel.js +157 -0
  154. package/app/merchant-core/customer-delivery/channel.js.map +1 -0
  155. package/app/merchant-core/customer-delivery/consent-repository.d.ts +50 -0
  156. package/app/merchant-core/customer-delivery/consent-repository.js +160 -0
  157. package/app/merchant-core/customer-delivery/consent-repository.js.map +1 -0
  158. package/app/merchant-core/customer-delivery/dispatcher-loop.d.ts +68 -0
  159. package/app/merchant-core/customer-delivery/dispatcher-loop.js +132 -0
  160. package/app/merchant-core/customer-delivery/dispatcher-loop.js.map +1 -0
  161. package/app/merchant-core/customer-delivery/dispatcher.d.ts +118 -0
  162. package/app/merchant-core/customer-delivery/dispatcher.js +166 -0
  163. package/app/merchant-core/customer-delivery/dispatcher.js.map +1 -0
  164. package/app/merchant-core/customer-delivery/email-adapter.d.ts +31 -0
  165. package/app/merchant-core/customer-delivery/email-adapter.js +90 -0
  166. package/app/merchant-core/customer-delivery/email-adapter.js.map +1 -0
  167. package/app/merchant-core/customer-delivery/gate.d.ts +37 -0
  168. package/app/merchant-core/customer-delivery/gate.js +196 -0
  169. package/app/merchant-core/customer-delivery/gate.js.map +1 -0
  170. package/app/merchant-core/customer-delivery/reconciliation.d.ts +13 -0
  171. package/app/merchant-core/customer-delivery/reconciliation.js +70 -0
  172. package/app/merchant-core/customer-delivery/reconciliation.js.map +1 -0
  173. package/app/merchant-core/customer-delivery/repository.d.ts +55 -0
  174. package/app/merchant-core/customer-delivery/repository.js +235 -0
  175. package/app/merchant-core/customer-delivery/repository.js.map +1 -0
  176. package/app/merchant-core/customer-delivery/smtp-adapter.d.ts +30 -0
  177. package/app/merchant-core/customer-delivery/smtp-adapter.js +183 -0
  178. package/app/merchant-core/customer-delivery/smtp-adapter.js.map +1 -0
  179. package/app/merchant-core/customer-delivery/stream-gate.d.ts +45 -0
  180. package/app/merchant-core/customer-delivery/stream-gate.js +123 -0
  181. package/app/merchant-core/customer-delivery/stream-gate.js.map +1 -0
  182. package/app/merchant-core/customer-delivery/types.d.ts +103 -0
  183. package/app/merchant-core/customer-delivery/types.js +32 -0
  184. package/app/merchant-core/customer-delivery/types.js.map +1 -0
  185. package/app/merchant-core/customer-delivery/weixin-adapter.d.ts +35 -0
  186. package/app/merchant-core/customer-delivery/weixin-adapter.js +56 -0
  187. package/app/merchant-core/customer-delivery/weixin-adapter.js.map +1 -0
  188. package/app/merchant-core/customer-memory/auto-identity.d.ts +43 -0
  189. package/app/merchant-core/customer-memory/auto-identity.js +163 -0
  190. package/app/merchant-core/customer-memory/auto-identity.js.map +1 -0
  191. package/app/merchant-core/customer-memory/grants.d.ts +72 -0
  192. package/app/merchant-core/customer-memory/grants.js +224 -0
  193. package/app/merchant-core/customer-memory/grants.js.map +1 -0
  194. package/app/merchant-core/customer-memory/history.d.ts +51 -0
  195. package/app/merchant-core/customer-memory/history.js +252 -0
  196. package/app/merchant-core/customer-memory/history.js.map +1 -0
  197. package/app/merchant-core/customer-memory/identity.d.ts +66 -0
  198. package/app/merchant-core/customer-memory/identity.js +249 -0
  199. package/app/merchant-core/customer-memory/identity.js.map +1 -0
  200. package/app/merchant-core/customer-memory/maintenance.d.ts +51 -0
  201. package/app/merchant-core/customer-memory/maintenance.js +67 -0
  202. package/app/merchant-core/customer-memory/maintenance.js.map +1 -0
  203. package/app/merchant-core/customer-memory/memory.d.ts +119 -0
  204. package/app/merchant-core/customer-memory/memory.js +502 -0
  205. package/app/merchant-core/customer-memory/memory.js.map +1 -0
  206. package/app/merchant-core/customer-memory/private-transport.d.ts +10 -0
  207. package/app/merchant-core/customer-memory/private-transport.js +108 -0
  208. package/app/merchant-core/customer-memory/private-transport.js.map +1 -0
  209. package/app/merchant-core/customer-memory/quote-history.d.ts +160 -0
  210. package/app/merchant-core/customer-memory/quote-history.js +392 -0
  211. package/app/merchant-core/customer-memory/quote-history.js.map +1 -0
  212. package/app/merchant-core/customer-memory/reception-provider.d.ts +69 -0
  213. package/app/merchant-core/customer-memory/reception-provider.js +250 -0
  214. package/app/merchant-core/customer-memory/reception-provider.js.map +1 -0
  215. package/app/merchant-core/customer-memory/reception-writer.d.ts +19 -0
  216. package/app/merchant-core/customer-memory/reception-writer.js +32 -0
  217. package/app/merchant-core/customer-memory/reception-writer.js.map +1 -0
  218. package/app/merchant-core/customer-memory/types.d.ts +111 -0
  219. package/app/merchant-core/customer-memory/types.js +58 -0
  220. package/app/merchant-core/customer-memory/types.js.map +1 -0
  221. package/app/merchant-core/followup/repository.d.ts +2 -1
  222. package/app/merchant-core/followup/repository.js +29 -23
  223. package/app/merchant-core/followup/repository.js.map +1 -1
  224. package/app/merchant-core/learning/evaluation-fixtures.d.ts +38 -0
  225. package/app/merchant-core/learning/evaluation-fixtures.js +83 -0
  226. package/app/merchant-core/learning/evaluation-fixtures.js.map +1 -0
  227. package/app/merchant-core/learning/evaluation-suite-v1.d.ts +56 -0
  228. package/app/merchant-core/learning/evaluation-suite-v1.js +129 -0
  229. package/app/merchant-core/learning/evaluation-suite-v1.js.map +1 -0
  230. package/app/merchant-core/learning/evaluation.d.ts +84 -0
  231. package/app/merchant-core/learning/evaluation.js +581 -0
  232. package/app/merchant-core/learning/evaluation.js.map +1 -0
  233. package/app/merchant-core/learning/initial-skills.d.ts +36 -0
  234. package/app/merchant-core/learning/initial-skills.js +67 -0
  235. package/app/merchant-core/learning/initial-skills.js.map +1 -0
  236. package/app/merchant-core/learning/precheck.d.ts +33 -0
  237. package/app/merchant-core/learning/precheck.js +56 -0
  238. package/app/merchant-core/learning/precheck.js.map +1 -0
  239. package/app/merchant-core/learning/real-evaluation-runner.d.ts +52 -0
  240. package/app/merchant-core/learning/real-evaluation-runner.js +167 -0
  241. package/app/merchant-core/learning/real-evaluation-runner.js.map +1 -0
  242. package/app/merchant-core/learning/reception-skill-catalog.d.ts +39 -0
  243. package/app/merchant-core/learning/reception-skill-catalog.js +145 -0
  244. package/app/merchant-core/learning/reception-skill-catalog.js.map +1 -0
  245. package/app/merchant-core/learning/recovery-gateway.d.ts +27 -0
  246. package/app/merchant-core/learning/recovery-gateway.js +106 -0
  247. package/app/merchant-core/learning/recovery-gateway.js.map +1 -0
  248. package/app/merchant-core/learning/repository.d.ts +130 -0
  249. package/app/merchant-core/learning/repository.js +588 -0
  250. package/app/merchant-core/learning/repository.js.map +1 -0
  251. package/app/merchant-core/learning/service.d.ts +262 -0
  252. package/app/merchant-core/learning/service.js +1498 -0
  253. package/app/merchant-core/learning/service.js.map +1 -0
  254. package/app/merchant-core/learning/test-dispatch-gateway.d.ts +43 -0
  255. package/app/merchant-core/learning/test-dispatch-gateway.js +145 -0
  256. package/app/merchant-core/learning/test-dispatch-gateway.js.map +1 -0
  257. package/app/merchant-core/learning/types.d.ts +217 -0
  258. package/app/merchant-core/learning/types.js +52 -0
  259. package/app/merchant-core/learning/types.js.map +1 -0
  260. package/app/merchant-core/migrations/ledgers.d.ts +40 -0
  261. package/app/merchant-core/migrations/ledgers.js +824 -0
  262. package/app/merchant-core/migrations/ledgers.js.map +1 -0
  263. package/app/merchant-core/migrations/runner.d.ts +55 -0
  264. package/app/merchant-core/migrations/runner.js +114 -0
  265. package/app/merchant-core/migrations/runner.js.map +1 -0
  266. package/app/merchant-core/operations-jobs/advice-runner.d.ts +63 -0
  267. package/app/merchant-core/operations-jobs/advice-runner.js +199 -0
  268. package/app/merchant-core/operations-jobs/advice-runner.js.map +1 -0
  269. package/app/merchant-core/operations-jobs/pilot-evidence.d.ts +64 -0
  270. package/app/merchant-core/operations-jobs/pilot-evidence.js +109 -0
  271. package/app/merchant-core/operations-jobs/pilot-evidence.js.map +1 -0
  272. package/app/merchant-core/operations-jobs/pilot-metrics.d.ts +70 -0
  273. package/app/merchant-core/operations-jobs/pilot-metrics.js +98 -0
  274. package/app/merchant-core/operations-jobs/pilot-metrics.js.map +1 -0
  275. package/app/merchant-core/operations-jobs/projection.d.ts +41 -0
  276. package/app/merchant-core/operations-jobs/projection.js +158 -0
  277. package/app/merchant-core/operations-jobs/projection.js.map +1 -0
  278. package/app/merchant-core/operations-jobs/scheduler.d.ts +68 -0
  279. package/app/merchant-core/operations-jobs/scheduler.js +233 -0
  280. package/app/merchant-core/operations-jobs/scheduler.js.map +1 -0
  281. package/app/merchant-core/operations-jobs/service.d.ts +260 -0
  282. package/app/merchant-core/operations-jobs/service.js +922 -0
  283. package/app/merchant-core/operations-jobs/service.js.map +1 -0
  284. package/app/merchant-core/ops/facade.d.ts +10 -0
  285. package/app/merchant-core/ops/facade.js +52 -0
  286. package/app/merchant-core/ops/facade.js.map +1 -1
  287. package/app/merchant-core/ops/schema.d.ts +1 -1
  288. package/app/merchant-core/ops/schema.js +119 -2
  289. package/app/merchant-core/ops/schema.js.map +1 -1
  290. package/app/merchant-core/ops/surface.d.ts +37 -0
  291. package/app/merchant-core/ops/surface.js +240 -0
  292. package/app/merchant-core/ops/surface.js.map +1 -1
  293. package/app/merchant-core/ownership/instance-ownership.d.ts +122 -0
  294. package/app/merchant-core/ownership/instance-ownership.js +236 -0
  295. package/app/merchant-core/ownership/instance-ownership.js.map +1 -0
  296. package/app/merchant-core/ownership/runtime.d.ts +175 -0
  297. package/app/merchant-core/ownership/runtime.js +422 -0
  298. package/app/merchant-core/ownership/runtime.js.map +1 -0
  299. package/app/merchant-core/storage/transaction.d.ts +102 -7
  300. package/app/merchant-core/storage/transaction.js +274 -3
  301. package/app/merchant-core/storage/transaction.js.map +1 -1
  302. package/app/merchant-credential-rotation.d.ts +4 -1
  303. package/app/merchant-credential-rotation.js +12 -8
  304. package/app/merchant-credential-rotation.js.map +1 -1
  305. package/app/merchant-runtime/manager.d.ts +2 -0
  306. package/app/merchant-runtime/manager.js +5 -0
  307. package/app/merchant-runtime/manager.js.map +1 -1
  308. package/build-manifest.json +1202 -242
  309. package/deployment-lock.json +2 -2
  310. package/package.json +1 -1
  311. package/prepare.mjs +5 -1
  312. package/runtime-package.json +1 -1
  313. package/shipping-sbom.cdx.json +6 -6
  314. package/shipping-source.json +12 -12
@@ -0,0 +1,441 @@
1
+ /**
2
+ * Copyright 2026 harrylabsj
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * 验签买家的本店身份建档通道(买家识别与交易回执 · K1)。
18
+ *
19
+ * 单写者部署下管理写者由 standalone workbench 持有所有权(instance_ownership
20
+ * CAS 租约),A2A 进程对 state.sqlite 只读。本模块把“验签上下文交给持有写权
21
+ * 的进程”的内部命令通道做成可插拔 Writer:
22
+ *
23
+ * - `local`(缺省):A2A 进程自身即写者(单进程部署/测试),直接幂等建档。
24
+ * - `spooled`:建档意图先落本地 spool(a2a dir JSON,进程崩溃不丢),再转发
25
+ * 给写者进程的内部端点;写者短时不可用时**绝不阻塞普通询价**、绝不承诺
26
+ * 已建档,spool 保留并在后续请求与定时 drain 中可靠重试(A6)。
27
+ *
28
+ * 转发端点契约:POST {forwardUrl},头 `x-kiwi-identity-channel-token`,
29
+ * 体 `{merchant_id, verified_actor, source, negotiation_id?, message_id?}`,
30
+ * 成功 `{ok:true, subject_id}`;任何网络/5xx/鉴权失败都视为写者不可用。
31
+ * 建档语义(幂等、唯一映射、REVOKED 不重建)由写者侧
32
+ * `ensureVerifiedCustomerIdentity` 保证——通道重试不会产生重复主体。
33
+ */
34
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
35
+ import { dirname } from "node:path";
36
+ import { DatabaseSync } from "node:sqlite";
37
+ import { createHash, timingSafeEqual } from "node:crypto";
38
+ import { resolveOpenInquirySessionKey } from "../open-inquiry-session.js";
39
+ import { QuoteHistoryStore, validateDelegationShape } from "../../merchant-core/customer-memory/quote-history.js";
40
+ import { ensureVerifiedCustomerIdentity, } from "../../merchant-core/customer-memory/auto-identity.js";
41
+ import { CustomerMemoryError } from "../../merchant-core/customer-memory/types.js";
42
+ import { inImmediateTransaction } from "../../merchant-core/storage/transaction.js";
43
+ import { registerGovernanceLedgers } from "../../merchant-core/migrations/ledgers.js";
44
+ function assertLocalWriter(db, merchantId, now, assertOwner) {
45
+ if (assertOwner !== undefined) {
46
+ assertOwner();
47
+ return;
48
+ }
49
+ const ownershipTable = db.prepare("SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = 'instance_ownership'").get();
50
+ if (ownershipTable === undefined)
51
+ return;
52
+ const holder = db.prepare("SELECT 1 FROM instance_ownership WHERE merchant_id = ? AND state = 'HELD' AND lease_expires_at > ?").get(merchantId, now);
53
+ if (holder !== undefined)
54
+ throw new Error("Workbench holds the customer writer lease");
55
+ }
56
+ // ---------------------------------------------------------------------------
57
+ // 本地 Writer:A2A 进程即写者(直接写 state.sqlite)
58
+ // ---------------------------------------------------------------------------
59
+ export class LocalCustomerIdentityWriter {
60
+ dbPath;
61
+ now;
62
+ handle;
63
+ assertOwner;
64
+ spool;
65
+ constructor(options) {
66
+ this.dbPath = options.dbPath;
67
+ this.assertOwner = options.assertOwner;
68
+ this.now = options.now;
69
+ if (options.spoolFile !== undefined)
70
+ this.spool = new IdentitySpool(options.spoolFile, options.now);
71
+ }
72
+ async ensure(input) {
73
+ const result = this.write(input);
74
+ if (result.status === "registered")
75
+ this.spool?.remove(input.merchant_id, input.verified_actor);
76
+ else
77
+ this.spool?.upsert(input, result.reason);
78
+ return result;
79
+ }
80
+ async drain() {
81
+ for (const entry of this.spool?.due() ?? [])
82
+ await this.ensure(entry);
83
+ }
84
+ write(input) {
85
+ const db = this.open();
86
+ if (db === undefined) {
87
+ return { status: "unavailable", reason: "customer identity store unavailable" };
88
+ }
89
+ try {
90
+ const result = inImmediateTransaction(db, () => {
91
+ const stamp = this.now();
92
+ assertLocalWriter(db, input.merchant_id, stamp, this.assertOwner);
93
+ return ensureVerifiedCustomerIdentity(db, {
94
+ merchant_id: input.merchant_id,
95
+ verified_actor: input.verified_actor,
96
+ now: stamp,
97
+ });
98
+ });
99
+ return { status: "registered", subject_id: result.subject_id, created: result.created };
100
+ }
101
+ catch (err) {
102
+ // 存储损坏/迁移缺口等:建档不可用,但不阻断询价。
103
+ return {
104
+ status: "unavailable",
105
+ reason: err instanceof CustomerMemoryError ? `identity store error: ${err.reason}` : "identity store error",
106
+ };
107
+ }
108
+ }
109
+ close() {
110
+ this.handle?.close();
111
+ this.handle = undefined;
112
+ }
113
+ open() {
114
+ if (this.handle !== undefined)
115
+ return this.handle;
116
+ try {
117
+ // 惰性打开 + 触发模块迁移(幂等;老库补 v4 表)。
118
+ this.assertOwner?.();
119
+ const db = new DatabaseSync(this.dbPath);
120
+ try {
121
+ db.exec("PRAGMA busy_timeout = 3000");
122
+ registerGovernanceLedgers(db);
123
+ }
124
+ catch (error) {
125
+ db.close();
126
+ throw error;
127
+ }
128
+ this.handle = db;
129
+ return db;
130
+ }
131
+ catch {
132
+ return undefined;
133
+ }
134
+ }
135
+ }
136
+ const SPOOL_MAX_ENTRIES = 10_000;
137
+ const SPOOL_RETRY_MIN_INTERVAL_MS = 30_000;
138
+ class IdentitySpool {
139
+ file;
140
+ now;
141
+ state;
142
+ constructor(file, now) {
143
+ this.file = file;
144
+ this.now = now;
145
+ this.state = this.load();
146
+ }
147
+ upsert(input, error) {
148
+ const existing = this.state.pending.find((entry) => entry.merchant_id === input.merchant_id && entry.verified_actor === input.verified_actor);
149
+ if (existing !== undefined) {
150
+ existing.attempts += 1;
151
+ if (error !== undefined)
152
+ existing.last_error = error;
153
+ this.save();
154
+ return;
155
+ }
156
+ if (this.state.pending.length >= SPOOL_MAX_ENTRIES) {
157
+ // 有界保护:溢出时丢弃最老的待发项(最老者最可能已被后续请求覆盖)。
158
+ this.state.pending.shift();
159
+ }
160
+ this.state.pending.push({
161
+ merchant_id: input.merchant_id,
162
+ verified_actor: input.verified_actor,
163
+ source: input.source,
164
+ ...(input.negotiation_id !== undefined ? { negotiation_id: input.negotiation_id } : {}),
165
+ ...(input.message_id !== undefined ? { message_id: input.message_id } : {}),
166
+ first_seen_at: this.now(),
167
+ attempts: 1,
168
+ ...(error !== undefined ? { last_error: error } : {}),
169
+ });
170
+ this.save();
171
+ }
172
+ remove(merchantId, verifiedActor) {
173
+ const before = this.state.pending.length;
174
+ this.state.pending = this.state.pending.filter((entry) => !(entry.merchant_id === merchantId && entry.verified_actor === verifiedActor));
175
+ if (this.state.pending.length !== before)
176
+ this.save();
177
+ }
178
+ /** 到期可重试的待发项(attempts 指数退避由调度方控制,这里只做最小间隔)。 */
179
+ due() {
180
+ return this.state.pending.slice();
181
+ }
182
+ load() {
183
+ try {
184
+ const parsed = JSON.parse(readFileSync(this.file, "utf8"));
185
+ if (parsed.version === 1 && Array.isArray(parsed.pending))
186
+ return parsed;
187
+ }
188
+ catch {
189
+ // 首次启动或坏文件:从空 spool 开始(意图会在下一次有效询价重建)。
190
+ }
191
+ return { version: 1, pending: [] };
192
+ }
193
+ save() {
194
+ mkdirSync(dirname(this.file), { recursive: true, mode: 0o700 });
195
+ const tmp = `${this.file}.tmp`;
196
+ writeFileSync(tmp, `${JSON.stringify(this.state)}\n`, { mode: 0o600 });
197
+ renameSync(tmp, this.file);
198
+ }
199
+ }
200
+ export class SpooledCustomerIdentityWriter {
201
+ spool;
202
+ forwardUrl;
203
+ forwardToken;
204
+ now;
205
+ fetchImpl;
206
+ logError;
207
+ lastAttemptAt = 0;
208
+ constructor(options) {
209
+ this.spool = new IdentitySpool(options.spoolFile, options.now);
210
+ this.forwardUrl = options.forwardUrl;
211
+ this.forwardToken = options.forwardToken;
212
+ this.now = options.now;
213
+ this.fetchImpl = options.fetchImpl ?? fetch;
214
+ this.logError = options.logError ?? (() => { });
215
+ }
216
+ async ensure(input) {
217
+ if (this.forwardUrl === undefined) {
218
+ this.spool.upsert(input, "forward endpoint not configured");
219
+ return { status: "unavailable", reason: "identity writer endpoint not configured" };
220
+ }
221
+ this.spool.upsert(input);
222
+ const outcome = await this.forward(input);
223
+ if (outcome.status === "registered") {
224
+ this.spool.remove(input.merchant_id, input.verified_actor);
225
+ // 顺手清掉同 actor 的历史待发项(remove 已按 merchant+actor 精确匹配)。
226
+ return outcome;
227
+ }
228
+ this.spool.upsert(input, outcome.reason);
229
+ return outcome;
230
+ }
231
+ /** drain:spool 中的历史意图可靠重试(启动时/定时调用)。 */
232
+ async drain() {
233
+ if (this.forwardUrl === undefined)
234
+ return;
235
+ const nowMs = Date.parse(this.now());
236
+ if (Number.isFinite(nowMs) && nowMs - this.lastAttemptAt < SPOOL_RETRY_MIN_INTERVAL_MS)
237
+ return;
238
+ this.lastAttemptAt = nowMs;
239
+ for (const entry of this.spool.due()) {
240
+ const outcome = await this.forward({
241
+ merchant_id: entry.merchant_id,
242
+ verified_actor: entry.verified_actor,
243
+ source: entry.source,
244
+ ...(entry.negotiation_id !== undefined ? { negotiation_id: entry.negotiation_id } : {}),
245
+ ...(entry.message_id !== undefined ? { message_id: entry.message_id } : {}),
246
+ });
247
+ if (outcome.status === "registered") {
248
+ this.spool.remove(entry.merchant_id, entry.verified_actor);
249
+ }
250
+ else {
251
+ this.spool.upsert({
252
+ merchant_id: entry.merchant_id,
253
+ verified_actor: entry.verified_actor,
254
+ source: entry.source,
255
+ }, outcome.reason);
256
+ }
257
+ }
258
+ }
259
+ async forward(input) {
260
+ try {
261
+ const response = await this.fetchImpl(this.forwardUrl, {
262
+ method: "POST",
263
+ redirect: "error",
264
+ headers: {
265
+ "content-type": "application/json",
266
+ ...(this.forwardToken !== undefined
267
+ ? { "x-kiwi-identity-channel-token": this.forwardToken }
268
+ : {}),
269
+ },
270
+ body: JSON.stringify(input),
271
+ signal: AbortSignal.timeout(3000),
272
+ });
273
+ if (!response.ok) {
274
+ return { status: "unavailable", reason: `identity writer http ${response.status}` };
275
+ }
276
+ const body = (await response.json());
277
+ if (body.ok === true && typeof body.subject_id === "string") {
278
+ return {
279
+ status: "registered",
280
+ subject_id: body.subject_id,
281
+ created: body.created === true,
282
+ };
283
+ }
284
+ return { status: "unavailable", reason: "identity writer returned invalid response" };
285
+ }
286
+ catch (err) {
287
+ this.logError("customer identity forward failed", err);
288
+ return { status: "unavailable", reason: "identity writer unreachable" };
289
+ }
290
+ }
291
+ }
292
+ /** 从环境装配 Writer(缺省 local)。 */
293
+ export function resolveCustomerIdentityWriter(options) {
294
+ const mode = process.env.KIWI_CUSTOMER_IDENTITY_WRITER ?? "local";
295
+ if (mode === "spooled") {
296
+ return new SpooledCustomerIdentityWriter({
297
+ spoolFile: `${options.a2aDir}/identity-registration-spool.json`,
298
+ ...(process.env.KIWI_CUSTOMER_IDENTITY_FORWARD_URL !== undefined
299
+ ? { forwardUrl: process.env.KIWI_CUSTOMER_IDENTITY_FORWARD_URL }
300
+ : {}),
301
+ ...(process.env.KIWI_CUSTOMER_IDENTITY_CHANNEL_TOKEN !== undefined
302
+ ? { forwardToken: process.env.KIWI_CUSTOMER_IDENTITY_CHANNEL_TOKEN }
303
+ : {}),
304
+ now: options.now,
305
+ ...(options.logError !== undefined ? { logError: options.logError } : {}),
306
+ });
307
+ }
308
+ return new LocalCustomerIdentityWriter({
309
+ dbPath: `${options.dataDir}/state.sqlite`,
310
+ spoolFile: `${options.a2aDir}/identity-registration-spool.json`,
311
+ now: options.now,
312
+ assertOwner: options.assertOwner,
313
+ });
314
+ }
315
+ export function createQuoteHistoryAccess(options) {
316
+ const remote = process.env.KIWI_CUSTOMER_IDENTITY_WRITER === "spooled";
317
+ let db;
318
+ const open = () => {
319
+ try {
320
+ db ??= new DatabaseSync(options.dbPath, { readOnly: true });
321
+ return new QuoteHistoryStore({ db, now: options.now });
322
+ }
323
+ catch {
324
+ return undefined;
325
+ }
326
+ };
327
+ let writeDb;
328
+ const writable = () => {
329
+ if (writeDb === undefined) {
330
+ writeDb = new DatabaseSync(options.dbPath);
331
+ writeDb.exec("PRAGMA busy_timeout = 3000");
332
+ }
333
+ return writeDb;
334
+ };
335
+ const write = async (command) => {
336
+ if (remote) {
337
+ const url = process.env.KIWI_CUSTOMER_IDENTITY_FORWARD_URL;
338
+ const token = process.env.KIWI_CUSTOMER_IDENTITY_CHANNEL_TOKEN;
339
+ if (url === undefined || token === undefined)
340
+ return;
341
+ const response = await fetch(url, {
342
+ method: "POST", redirect: "error", signal: AbortSignal.timeout(3000),
343
+ headers: { "content-type": "application/json", "x-kiwi-identity-channel-token": token },
344
+ body: JSON.stringify(command),
345
+ });
346
+ if (!response.ok)
347
+ throw new Error("Workbench history write unavailable");
348
+ await response.body?.cancel();
349
+ return;
350
+ }
351
+ const connection = writable();
352
+ inImmediateTransaction(connection, () => {
353
+ assertLocalWriter(connection, command.input.merchant_id, options.now(), options.assertOwner);
354
+ const store = new QuoteHistoryStore({ db: connection, now: options.now });
355
+ if (command.kind === "delegation")
356
+ store.applyDelegation(command.input);
357
+ else
358
+ store.indexOffer(command.input);
359
+ });
360
+ };
361
+ return {
362
+ store: {
363
+ checkActive: (input) => open()?.checkActive(input),
364
+ queryHistory: (input) => open()?.queryHistory(input) ?? [],
365
+ applyDelegation: (input) => write({ kind: "delegation", input }),
366
+ indexOffer: (input) => write({ kind: "offer", input }),
367
+ },
368
+ prune(merchantId) {
369
+ // A separate Workbench writer performs its own maintenance.
370
+ if (remote || !existsSync(options.dbPath))
371
+ return;
372
+ // Maintenance is periodic and must not keep a writer open on an idle node.
373
+ const connection = new DatabaseSync(options.dbPath);
374
+ try {
375
+ connection.exec("PRAGMA busy_timeout = 3000");
376
+ if (connection.prepare("SELECT 1 FROM sqlite_schema WHERE name = 'published_offers'").get() === undefined)
377
+ return;
378
+ inImmediateTransaction(connection, () => {
379
+ assertLocalWriter(connection, merchantId, options.now(), options.assertOwner);
380
+ new QuoteHistoryStore({ db: connection, now: options.now }).pruneForMerchant(merchantId);
381
+ });
382
+ }
383
+ finally {
384
+ connection.close();
385
+ }
386
+ },
387
+ close: () => { db?.close(); writeDb?.close(); },
388
+ };
389
+ }
390
+ /** Only the bound A2A process may ask the Workbench to register its verified actor. */
391
+ export function createCustomerIdentityReceiver(options) {
392
+ const tokenHash = (value) => createHash("sha256").update(value).digest();
393
+ return async (token, readBody) => {
394
+ const expected = process.env.KIWI_CUSTOMER_IDENTITY_CHANNEL_TOKEN;
395
+ if (options.assertOwner === undefined || typeof token !== "string" || expected === undefined ||
396
+ expected.length < 32 || !timingSafeEqual(tokenHash(token), tokenHash(expected))) {
397
+ return { status: 404, body: { ok: false } };
398
+ }
399
+ const body = await readBody();
400
+ if (body === null || typeof body !== "object")
401
+ return { status: 400, body: { ok: false } };
402
+ const command = body;
403
+ try {
404
+ return inImmediateTransaction(options.db, () => {
405
+ options.assertOwner?.();
406
+ const store = new QuoteHistoryStore({ db: options.db, now: options.now });
407
+ if (command.kind === "delegation" || command.kind === "offer") {
408
+ const input = command.input;
409
+ if (input?.merchant_id !== options.merchantId)
410
+ return { status: 400, body: { ok: false } };
411
+ if (command.kind === "delegation") {
412
+ const delegation = command.input;
413
+ if (resolveOpenInquirySessionKey(delegation.buyer_actor) === undefined ||
414
+ !validateDelegationShape(delegation.delegation, options.merchantId, options.now()).ok) {
415
+ return { status: 400, body: { ok: false } };
416
+ }
417
+ store.applyDelegation(delegation);
418
+ }
419
+ else {
420
+ store.indexOffer(command.input);
421
+ }
422
+ return { status: 200, body: { ok: true } };
423
+ }
424
+ const input = body;
425
+ if (input.merchant_id !== options.merchantId || typeof input.verified_actor !== "string" ||
426
+ resolveOpenInquirySessionKey(input.verified_actor) === undefined ||
427
+ !["rfq", "inquiry", "reception-text"].includes(input.source ?? "")) {
428
+ return { status: 400, body: { ok: false } };
429
+ }
430
+ const result = ensureVerifiedCustomerIdentity(options.db, {
431
+ merchant_id: options.merchantId, verified_actor: input.verified_actor, now: options.now(),
432
+ });
433
+ return { status: 200, body: { ok: true, subject_id: result.subject_id, created: result.created } };
434
+ });
435
+ }
436
+ catch {
437
+ return { status: 503, body: { ok: false } };
438
+ }
439
+ };
440
+ }
441
+ //# sourceMappingURL=customer-identity-gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customer-identity-gateway.js","sourceRoot":"","sources":["../../../src/a2a/server/customer-identity-gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAGlH,OAAO,EACL,8BAA8B,GAC/B,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAEtF,SAAS,iBAAiB,CAAC,EAAgB,EAAE,UAAkB,EAAE,GAAW,EAAE,WAAwB;IACpG,IAA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ACH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YACrG,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -21,6 +21,9 @@ import type { NegotiationApprovalStore } from "./negotiation-approvals.js";
21
21
  import { type NegotiationAdvisor } from "./negotiation-advisor.js";
22
22
  import type { InquiryInterpreter, InquiryTopic } from "./inquiry-interpreter.js";
23
23
  import type { ReceptionEngine } from "../reception/engine.js";
24
+ import type { CustomerIdentityWriter } from "./customer-identity-gateway.js";
25
+ import { QuoteHistoryStore } from "../../merchant-core/customer-memory/quote-history.js";
26
+ import type { ReceiptDispatcher } from "../../commerce/receipt/dispatcher.js";
24
27
  import type { A2AMessage } from "../client/types.js";
25
28
  import type { NegotiationHandler } from "./types.js";
26
29
  export declare const MERCHANT_CAPABILITY = "com.harrylabsj.kiwi.shopping.negotiation";
@@ -65,6 +68,10 @@ export declare function buyerMessageForAdvisor(message: Pick<A2AMessage, "parts"
65
68
  * 一致(half-up);要求整数百分比(dealDiscountPercent 缺省 5)。
66
69
  */
67
70
  export declare function applyDiscountPercentMinor(priceMinor: number, discountPercent: number): number;
71
+ export type QuoteHistoryAccess = Pick<QuoteHistoryStore, "checkActive" | "queryHistory"> & {
72
+ applyDelegation(input: Parameters<QuoteHistoryStore["applyDelegation"]>[0]): unknown;
73
+ indexOffer(input: Parameters<QuoteHistoryStore["indexOffer"]>[0]): unknown;
74
+ };
68
75
  export interface MerchantHandlerOptions {
69
76
  ledger: LedgerStore;
70
77
  now: () => string;
@@ -122,6 +129,33 @@ export interface MerchantHandlerOptions {
122
129
  amountMinor: string;
123
130
  endsAt: string;
124
131
  } | undefined;
132
+ /**
133
+ * 买家识别与交易回执 · K1:验签买家的本店身份自动建档。
134
+ * 在正式 RFQ 受理(入参校验后)与判定为有效询价的 inquiry 后调用;
135
+ * 搜索、查任务、无关消息和被拒请求不建档。写者不可用时询价照常继续。
136
+ */
137
+ customerIdentity?: {
138
+ merchantId: string;
139
+ writer: CustomerIdentityWriter;
140
+ };
141
+ /**
142
+ * 买家识别与交易回执 · K2:委托与已发报价历史。委托随请求体签名覆盖的
143
+ * message metadata 到达;已发报价在 appendSent 后索引;历史查询扩展
144
+ * (KNP inquiry subject.kiwi_history_query)读前复核授权。任何委托/查询
145
+ * 失败都降级为“未委托/无历史”,绝不阻塞询价。
146
+ */
147
+ quoteHistory?: {
148
+ store: QuoteHistoryAccess;
149
+ };
150
+ /**
151
+ * 买家识别与交易回执 · K5/K6:向 Catalog 上报商家侧事实的投递通道。
152
+ * 协议持久化后上报“协议已签发”;带入口的报价正式发出后上报“已提供
153
+ * 入口”。上报失败不阻塞业务(outbox 退避重试)。
154
+ */
155
+ commerceReceipts?: {
156
+ merchantId: string;
157
+ dispatcher: ReceiptDispatcher;
158
+ };
125
159
  }
126
160
  /**
127
161
  * 真实商品源:给定 SKU 返回价目(shopping-cli 开放层/ERP/商品表均可接入)。