@harrylabsj/kiwi-merchant-cloud 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.
- package/app/a2a/inquiry-nonce-store.d.ts +12 -1
- package/app/a2a/inquiry-nonce-store.js +49 -17
- package/app/a2a/inquiry-nonce-store.js.map +1 -1
- package/app/a2a/negotiate.d.ts +30 -1
- package/app/a2a/negotiate.js +121 -32
- package/app/a2a/negotiate.js.map +1 -1
- package/app/a2a/node.d.ts +4 -0
- package/app/a2a/node.js +182 -4
- package/app/a2a/node.js.map +1 -1
- package/app/a2a/open-inquiry-session.d.ts +1 -0
- package/app/a2a/open-inquiry-session.js +3 -1
- package/app/a2a/open-inquiry-session.js.map +1 -1
- package/app/a2a/open-inquiry-verifier.js +2 -2
- package/app/a2a/open-inquiry-verifier.js.map +1 -1
- package/app/a2a/reception/agent-runtime.d.ts +32 -1
- package/app/a2a/reception/agent-runtime.js +420 -11
- package/app/a2a/reception/agent-runtime.js.map +1 -1
- package/app/a2a/reception/customer-memory-tools.d.ts +73 -0
- package/app/a2a/reception/customer-memory-tools.js +17 -0
- package/app/a2a/reception/customer-memory-tools.js.map +1 -0
- package/app/a2a/reception/engine.d.ts +12 -0
- package/app/a2a/reception/engine.js +42 -1
- package/app/a2a/reception/engine.js.map +1 -1
- package/app/a2a/reception/publish.d.ts +14 -1
- package/app/a2a/reception/publish.js +62 -1
- package/app/a2a/reception/publish.js.map +1 -1
- package/app/a2a/reception/question-spec.d.ts +91 -0
- package/app/a2a/reception/question-spec.js +260 -0
- package/app/a2a/reception/question-spec.js.map +1 -0
- package/app/a2a/reception/reply-outbox.d.ts +6 -0
- package/app/a2a/reception/reply-outbox.js +44 -0
- package/app/a2a/reception/reply-outbox.js.map +1 -1
- package/app/a2a/reception/responder.d.ts +13 -1
- package/app/a2a/reception/responder.js +26 -3
- package/app/a2a/reception/responder.js.map +1 -1
- package/app/a2a/reception/skill-catalog.d.ts +72 -0
- package/app/a2a/reception/skill-catalog.js +85 -0
- package/app/a2a/reception/skill-catalog.js.map +1 -0
- package/app/a2a/reception/skill-contract.d.ts +70 -0
- package/app/a2a/reception/skill-contract.js +183 -0
- package/app/a2a/reception/skill-contract.js.map +1 -0
- package/app/a2a/reception/types.d.ts +12 -0
- package/app/a2a/server/customer-identity-gateway.d.ts +111 -0
- package/app/a2a/server/customer-identity-gateway.js +441 -0
- package/app/a2a/server/customer-identity-gateway.js.map +1 -0
- package/app/a2a/server/errors.d.ts +4 -3
- package/app/a2a/server/errors.js +10 -2
- package/app/a2a/server/errors.js.map +1 -1
- package/app/a2a/server/merchant-handler.d.ts +75 -1
- package/app/a2a/server/merchant-handler.js +676 -86
- package/app/a2a/server/merchant-handler.js.map +1 -1
- package/app/a2a/server/merchant-procurement.d.ts +90 -0
- package/app/a2a/server/merchant-procurement.js +75 -0
- package/app/a2a/server/merchant-procurement.js.map +1 -0
- package/app/a2a/server/merchant-product-facts.d.ts +2 -0
- package/app/a2a/server/merchant-product-facts.js.map +1 -1
- package/app/a2a/server/negotiation-approvals.d.ts +11 -0
- package/app/a2a/server/negotiation-approvals.js +43 -0
- package/app/a2a/server/negotiation-approvals.js.map +1 -1
- package/app/a2a/server/pipeline.js +78 -30
- package/app/a2a/server/pipeline.js.map +1 -1
- package/app/a2a/server/server.js +4 -3
- package/app/a2a/server/server.js.map +1 -1
- package/app/a2a/server/types.d.ts +4 -1
- package/app/a2a/unit-alias.d.ts +3 -3
- package/app/a2a/unit-alias.js +9 -5
- package/app/a2a/unit-alias.js.map +1 -1
- package/app/agent/alipay-native-view.d.ts +27 -0
- package/app/agent/alipay-native-view.js +113 -0
- package/app/agent/alipay-native-view.js.map +1 -0
- package/app/agent/buyer/buyer-tools.d.ts +20 -0
- package/app/agent/buyer/buyer-tools.js +241 -48
- package/app/agent/buyer/buyer-tools.js.map +1 -1
- package/app/agent/buyer/types.d.ts +1 -1
- package/app/agent/buyer/types.js.map +1 -1
- package/app/agent/chat-tui.js +16 -1
- package/app/agent/chat-tui.js.map +1 -1
- package/app/agent/kernel-builder.d.ts +2 -0
- package/app/agent/kernel-builder.js +14 -0
- package/app/agent/kernel-builder.js.map +1 -1
- package/app/agent/kernel.d.ts +8 -0
- package/app/agent/kernel.js +67 -1
- package/app/agent/kernel.js.map +1 -1
- package/app/auth/merchant-sessions.d.ts +3 -0
- package/app/auth/merchant-sessions.js +21 -5
- package/app/auth/merchant-sessions.js.map +1 -1
- package/app/buyer-core/a2a-accept-terms.d.ts +11 -0
- package/app/buyer-core/a2a-accept-terms.js +28 -0
- package/app/buyer-core/a2a-accept-terms.js.map +1 -0
- package/app/buyer-core/a2a-knp.d.ts +7 -2
- package/app/buyer-core/a2a-knp.js +8 -5
- package/app/buyer-core/a2a-knp.js.map +1 -1
- package/app/buyer-core/a2a-negotiator.d.ts +17 -0
- package/app/buyer-core/a2a-negotiator.js +70 -26
- package/app/buyer-core/a2a-negotiator.js.map +1 -1
- package/app/buyer-core/a2a-quote-fetcher.d.ts +25 -15
- package/app/buyer-core/a2a-quote-fetcher.js +92 -19
- package/app/buyer-core/a2a-quote-fetcher.js.map +1 -1
- package/app/buyer-core/a2a-quote-history.d.ts +94 -0
- package/app/buyer-core/a2a-quote-history.js +149 -0
- package/app/buyer-core/a2a-quote-history.js.map +1 -0
- package/app/buyer-core/build-service.d.ts +19 -0
- package/app/buyer-core/build-service.js +30 -1
- package/app/buyer-core/build-service.js.map +1 -1
- package/app/buyer-core/errors.d.ts +1 -1
- package/app/buyer-core/errors.js +1 -0
- package/app/buyer-core/errors.js.map +1 -1
- package/app/buyer-core/merchant-index.d.ts +2 -2
- package/app/buyer-core/merchant-index.js +23 -5
- package/app/buyer-core/merchant-index.js.map +1 -1
- package/app/buyer-core/open-inquiry-signer.d.ts +1 -0
- package/app/buyer-core/open-inquiry-signer.js +5 -2
- package/app/buyer-core/open-inquiry-signer.js.map +1 -1
- package/app/buyer-core/procurement/cases.d.ts +441 -0
- package/app/buyer-core/procurement/cases.js +457 -0
- package/app/buyer-core/procurement/cases.js.map +1 -0
- package/app/buyer-core/procurement/quote-comparison.d.ts +137 -0
- package/app/buyer-core/procurement/quote-comparison.js +106 -0
- package/app/buyer-core/procurement/quote-comparison.js.map +1 -0
- package/app/buyer-core/procurement/quote-normalizer.d.ts +45 -0
- package/app/buyer-core/procurement/quote-normalizer.js +153 -0
- package/app/buyer-core/procurement/quote-normalizer.js.map +1 -0
- package/app/buyer-core/procurement/requirements.d.ts +50 -0
- package/app/buyer-core/procurement/requirements.js +43 -0
- package/app/buyer-core/procurement/requirements.js.map +1 -0
- package/app/buyer-core/procurement/source-observation.d.ts +57 -0
- package/app/buyer-core/procurement/source-observation.js +54 -0
- package/app/buyer-core/procurement/source-observation.js.map +1 -0
- package/app/buyer-core/procurement/store.d.ts +21 -0
- package/app/buyer-core/procurement/store.js +68 -0
- package/app/buyer-core/procurement/store.js.map +1 -0
- package/app/buyer-core/protocol-recovery.d.ts +10 -1
- package/app/buyer-core/protocol-recovery.js +31 -6
- package/app/buyer-core/protocol-recovery.js.map +1 -1
- package/app/buyer-core/quote-quantity.d.ts +5 -0
- package/app/buyer-core/quote-quantity.js +15 -0
- package/app/buyer-core/quote-quantity.js.map +1 -0
- package/app/buyer-core/service.d.ts +128 -8
- package/app/buyer-core/service.js +543 -75
- package/app/buyer-core/service.js.map +1 -1
- package/app/buyer-core/store.d.ts +21 -0
- package/app/buyer-core/store.js +62 -10
- package/app/buyer-core/store.js.map +1 -1
- package/app/cli.js +26 -19
- package/app/cli.js.map +1 -1
- package/app/cloud/alipay-collection-http.d.ts +44 -0
- package/app/cloud/alipay-collection-http.js +111 -0
- package/app/cloud/alipay-collection-http.js.map +1 -0
- package/app/cloud/bootstrap.js +218 -19
- package/app/cloud/bootstrap.js.map +1 -1
- package/app/cloud/http-router.d.ts +2 -0
- package/app/cloud/http-router.js +5 -0
- package/app/cloud/http-router.js.map +1 -1
- package/app/cloud-sample/products.json +3 -3
- package/app/commerce/receipt/dispatcher.d.ts +43 -0
- package/app/commerce/receipt/dispatcher.js +86 -0
- package/app/commerce/receipt/dispatcher.js.map +1 -0
- package/app/commerce/receipt/receipts.d.ts +147 -0
- package/app/commerce/receipt/receipts.js +285 -0
- package/app/commerce/receipt/receipts.js.map +1 -0
- package/app/config/profile.d.ts +2 -2
- package/app/discovery/catalog-source/buyer-follows.d.ts +3 -3
- package/app/discovery/catalog-source/buyer-follows.js +6 -3
- package/app/discovery/catalog-source/buyer-follows.js.map +1 -1
- package/app/discovery/catalog-source/kiwi-record.d.ts +2 -0
- package/app/discovery/catalog-source/kiwi-record.js.map +1 -1
- package/app/discovery/catalog-source/kiwi-source.js +4 -0
- package/app/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/app/handoff/alipay-collection.d.ts +23 -0
- package/app/handoff/alipay-collection.js +70 -0
- package/app/handoff/alipay-collection.js.map +1 -0
- package/app/handoff/order-receipts.d.ts +62 -0
- package/app/handoff/order-receipts.js +72 -0
- package/app/handoff/order-receipts.js.map +1 -0
- package/app/handoff/ucp-checkout/cart-channel.d.ts +2 -1
- package/app/handoff/ucp-checkout/cart-channel.js +1 -0
- package/app/handoff/ucp-checkout/cart-channel.js.map +1 -1
- package/app/handoff/ucp-checkout/channel.d.ts +7 -0
- package/app/handoff/ucp-checkout/channel.js +79 -10
- package/app/handoff/ucp-checkout/channel.js.map +1 -1
- package/app/http/cli.js +6 -0
- package/app/http/cli.js.map +1 -1
- package/app/http/merchant-management/api.d.ts +18 -0
- package/app/http/merchant-management/api.js +752 -3
- package/app/http/merchant-management/api.js.map +1 -1
- package/app/http/merchant-management/draft-store.js +8 -6
- package/app/http/merchant-management/draft-store.js.map +1 -1
- package/app/http/merchant-management/page.d.ts +1 -0
- package/app/http/merchant-management/page.js +335 -5
- package/app/http/merchant-management/page.js.map +1 -1
- package/app/http/server.js +9 -2
- package/app/http/server.js.map +1 -1
- package/app/mcp/cli.d.ts +3 -1
- package/app/mcp/cli.js +18 -2
- package/app/mcp/cli.js.map +1 -1
- package/app/mcp/merchant-runtime-assembly.d.ts +20 -0
- package/app/mcp/merchant-runtime-assembly.js +94 -11
- package/app/mcp/merchant-runtime-assembly.js.map +1 -1
- package/app/mcp/merchant-server.d.ts +5 -0
- package/app/mcp/merchant-server.js +12 -0
- package/app/mcp/merchant-server.js.map +1 -1
- package/app/mcp/procurement-tools.d.ts +10 -0
- package/app/mcp/procurement-tools.js +173 -0
- package/app/mcp/procurement-tools.js.map +1 -0
- package/app/mcp/server.d.ts +4 -0
- package/app/mcp/server.js +63 -9
- package/app/mcp/server.js.map +1 -1
- package/app/mcp/tools.d.ts +4 -1
- package/app/mcp/tools.js +83 -28
- package/app/mcp/tools.js.map +1 -1
- package/app/mcp/types.d.ts +1 -0
- package/app/mcp/types.js.map +1 -1
- package/app/merchant/application/actor.d.ts +3 -1
- package/app/merchant/application/actor.js +21 -0
- package/app/merchant/application/actor.js.map +1 -1
- package/app/merchant/negotiation-ops.d.ts +2 -0
- package/app/merchant/negotiation-ops.js +4 -0
- package/app/merchant/negotiation-ops.js.map +1 -1
- package/app/merchant/weixin-channel.d.ts +68 -0
- package/app/merchant/weixin-channel.js +313 -0
- package/app/merchant/weixin-channel.js.map +1 -0
- package/app/merchant/workbench-server.d.ts +1 -0
- package/app/merchant/workbench-server.js +189 -2
- package/app/merchant/workbench-server.js.map +1 -1
- package/app/merchant-core/budget/background-budget.d.ts +132 -0
- package/app/merchant-core/budget/background-budget.js +308 -0
- package/app/merchant-core/budget/background-budget.js.map +1 -0
- package/app/merchant-core/collection/alipay-store.d.ts +22 -0
- package/app/merchant-core/collection/alipay-store.js +125 -0
- package/app/merchant-core/collection/alipay-store.js.map +1 -0
- package/app/merchant-core/commercial/calculate.js +6 -6
- package/app/merchant-core/commercial/calculate.js.map +1 -1
- package/app/merchant-core/context-governance/actor-context.d.ts +56 -0
- package/app/merchant-core/context-governance/actor-context.js +76 -0
- package/app/merchant-core/context-governance/actor-context.js.map +1 -0
- package/app/merchant-core/context-governance/authority.d.ts +39 -0
- package/app/merchant-core/context-governance/authority.js +28 -0
- package/app/merchant-core/context-governance/authority.js.map +1 -0
- package/app/merchant-core/context-governance/context-guard.d.ts +104 -0
- package/app/merchant-core/context-governance/context-guard.js +194 -0
- package/app/merchant-core/context-governance/context-guard.js.map +1 -0
- package/app/merchant-core/context-governance/data-use-grant.d.ts +91 -0
- package/app/merchant-core/context-governance/data-use-grant.js +211 -0
- package/app/merchant-core/context-governance/data-use-grant.js.map +1 -0
- package/app/merchant-core/context-governance/feature-flags.d.ts +32 -0
- package/app/merchant-core/context-governance/feature-flags.js +83 -0
- package/app/merchant-core/context-governance/feature-flags.js.map +1 -0
- package/app/merchant-core/context-governance/pilot-readiness.d.ts +39 -0
- package/app/merchant-core/context-governance/pilot-readiness.js +141 -0
- package/app/merchant-core/context-governance/pilot-readiness.js.map +1 -0
- package/app/merchant-core/context-governance/source-governance.d.ts +157 -0
- package/app/merchant-core/context-governance/source-governance.js +492 -0
- package/app/merchant-core/context-governance/source-governance.js.map +1 -0
- package/app/merchant-core/context-governance/types.d.ts +62 -0
- package/app/merchant-core/context-governance/types.js +92 -0
- package/app/merchant-core/context-governance/types.js.map +1 -0
- package/app/merchant-core/customer-delivery/binding.d.ts +55 -0
- package/app/merchant-core/customer-delivery/binding.js +121 -0
- package/app/merchant-core/customer-delivery/binding.js.map +1 -0
- package/app/merchant-core/customer-delivery/channel.d.ts +75 -0
- package/app/merchant-core/customer-delivery/channel.js +157 -0
- package/app/merchant-core/customer-delivery/channel.js.map +1 -0
- package/app/merchant-core/customer-delivery/consent-repository.d.ts +50 -0
- package/app/merchant-core/customer-delivery/consent-repository.js +160 -0
- package/app/merchant-core/customer-delivery/consent-repository.js.map +1 -0
- package/app/merchant-core/customer-delivery/dispatcher-loop.d.ts +68 -0
- package/app/merchant-core/customer-delivery/dispatcher-loop.js +132 -0
- package/app/merchant-core/customer-delivery/dispatcher-loop.js.map +1 -0
- package/app/merchant-core/customer-delivery/dispatcher.d.ts +118 -0
- package/app/merchant-core/customer-delivery/dispatcher.js +166 -0
- package/app/merchant-core/customer-delivery/dispatcher.js.map +1 -0
- package/app/merchant-core/customer-delivery/email-adapter.d.ts +31 -0
- package/app/merchant-core/customer-delivery/email-adapter.js +90 -0
- package/app/merchant-core/customer-delivery/email-adapter.js.map +1 -0
- package/app/merchant-core/customer-delivery/gate.d.ts +37 -0
- package/app/merchant-core/customer-delivery/gate.js +196 -0
- package/app/merchant-core/customer-delivery/gate.js.map +1 -0
- package/app/merchant-core/customer-delivery/reconciliation.d.ts +13 -0
- package/app/merchant-core/customer-delivery/reconciliation.js +70 -0
- package/app/merchant-core/customer-delivery/reconciliation.js.map +1 -0
- package/app/merchant-core/customer-delivery/repository.d.ts +55 -0
- package/app/merchant-core/customer-delivery/repository.js +235 -0
- package/app/merchant-core/customer-delivery/repository.js.map +1 -0
- package/app/merchant-core/customer-delivery/smtp-adapter.d.ts +30 -0
- package/app/merchant-core/customer-delivery/smtp-adapter.js +183 -0
- package/app/merchant-core/customer-delivery/smtp-adapter.js.map +1 -0
- package/app/merchant-core/customer-delivery/stream-gate.d.ts +45 -0
- package/app/merchant-core/customer-delivery/stream-gate.js +123 -0
- package/app/merchant-core/customer-delivery/stream-gate.js.map +1 -0
- package/app/merchant-core/customer-delivery/types.d.ts +103 -0
- package/app/merchant-core/customer-delivery/types.js +32 -0
- package/app/merchant-core/customer-delivery/types.js.map +1 -0
- package/app/merchant-core/customer-delivery/weixin-adapter.d.ts +35 -0
- package/app/merchant-core/customer-delivery/weixin-adapter.js +56 -0
- package/app/merchant-core/customer-delivery/weixin-adapter.js.map +1 -0
- package/app/merchant-core/customer-memory/auto-identity.d.ts +43 -0
- package/app/merchant-core/customer-memory/auto-identity.js +163 -0
- package/app/merchant-core/customer-memory/auto-identity.js.map +1 -0
- package/app/merchant-core/customer-memory/grants.d.ts +72 -0
- package/app/merchant-core/customer-memory/grants.js +224 -0
- package/app/merchant-core/customer-memory/grants.js.map +1 -0
- package/app/merchant-core/customer-memory/history.d.ts +51 -0
- package/app/merchant-core/customer-memory/history.js +252 -0
- package/app/merchant-core/customer-memory/history.js.map +1 -0
- package/app/merchant-core/customer-memory/identity.d.ts +66 -0
- package/app/merchant-core/customer-memory/identity.js +249 -0
- package/app/merchant-core/customer-memory/identity.js.map +1 -0
- package/app/merchant-core/customer-memory/maintenance.d.ts +51 -0
- package/app/merchant-core/customer-memory/maintenance.js +67 -0
- package/app/merchant-core/customer-memory/maintenance.js.map +1 -0
- package/app/merchant-core/customer-memory/memory.d.ts +119 -0
- package/app/merchant-core/customer-memory/memory.js +502 -0
- package/app/merchant-core/customer-memory/memory.js.map +1 -0
- package/app/merchant-core/customer-memory/private-transport.d.ts +10 -0
- package/app/merchant-core/customer-memory/private-transport.js +108 -0
- package/app/merchant-core/customer-memory/private-transport.js.map +1 -0
- package/app/merchant-core/customer-memory/quote-history.d.ts +160 -0
- package/app/merchant-core/customer-memory/quote-history.js +392 -0
- package/app/merchant-core/customer-memory/quote-history.js.map +1 -0
- package/app/merchant-core/customer-memory/reception-provider.d.ts +69 -0
- package/app/merchant-core/customer-memory/reception-provider.js +250 -0
- package/app/merchant-core/customer-memory/reception-provider.js.map +1 -0
- package/app/merchant-core/customer-memory/reception-writer.d.ts +19 -0
- package/app/merchant-core/customer-memory/reception-writer.js +32 -0
- package/app/merchant-core/customer-memory/reception-writer.js.map +1 -0
- package/app/merchant-core/customer-memory/types.d.ts +111 -0
- package/app/merchant-core/customer-memory/types.js +58 -0
- package/app/merchant-core/customer-memory/types.js.map +1 -0
- package/app/merchant-core/followup/repository.d.ts +2 -1
- package/app/merchant-core/followup/repository.js +29 -23
- package/app/merchant-core/followup/repository.js.map +1 -1
- package/app/merchant-core/learning/evaluation-fixtures.d.ts +38 -0
- package/app/merchant-core/learning/evaluation-fixtures.js +83 -0
- package/app/merchant-core/learning/evaluation-fixtures.js.map +1 -0
- package/app/merchant-core/learning/evaluation-suite-v1.d.ts +56 -0
- package/app/merchant-core/learning/evaluation-suite-v1.js +129 -0
- package/app/merchant-core/learning/evaluation-suite-v1.js.map +1 -0
- package/app/merchant-core/learning/evaluation.d.ts +84 -0
- package/app/merchant-core/learning/evaluation.js +581 -0
- package/app/merchant-core/learning/evaluation.js.map +1 -0
- package/app/merchant-core/learning/initial-skills.d.ts +36 -0
- package/app/merchant-core/learning/initial-skills.js +67 -0
- package/app/merchant-core/learning/initial-skills.js.map +1 -0
- package/app/merchant-core/learning/precheck.d.ts +33 -0
- package/app/merchant-core/learning/precheck.js +56 -0
- package/app/merchant-core/learning/precheck.js.map +1 -0
- package/app/merchant-core/learning/real-evaluation-runner.d.ts +52 -0
- package/app/merchant-core/learning/real-evaluation-runner.js +167 -0
- package/app/merchant-core/learning/real-evaluation-runner.js.map +1 -0
- package/app/merchant-core/learning/reception-skill-catalog.d.ts +39 -0
- package/app/merchant-core/learning/reception-skill-catalog.js +145 -0
- package/app/merchant-core/learning/reception-skill-catalog.js.map +1 -0
- package/app/merchant-core/learning/recovery-gateway.d.ts +27 -0
- package/app/merchant-core/learning/recovery-gateway.js +106 -0
- package/app/merchant-core/learning/recovery-gateway.js.map +1 -0
- package/app/merchant-core/learning/repository.d.ts +130 -0
- package/app/merchant-core/learning/repository.js +588 -0
- package/app/merchant-core/learning/repository.js.map +1 -0
- package/app/merchant-core/learning/service.d.ts +262 -0
- package/app/merchant-core/learning/service.js +1498 -0
- package/app/merchant-core/learning/service.js.map +1 -0
- package/app/merchant-core/learning/test-dispatch-gateway.d.ts +43 -0
- package/app/merchant-core/learning/test-dispatch-gateway.js +145 -0
- package/app/merchant-core/learning/test-dispatch-gateway.js.map +1 -0
- package/app/merchant-core/learning/types.d.ts +217 -0
- package/app/merchant-core/learning/types.js +52 -0
- package/app/merchant-core/learning/types.js.map +1 -0
- package/app/merchant-core/migrations/ledgers.d.ts +40 -0
- package/app/merchant-core/migrations/ledgers.js +824 -0
- package/app/merchant-core/migrations/ledgers.js.map +1 -0
- package/app/merchant-core/migrations/runner.d.ts +55 -0
- package/app/merchant-core/migrations/runner.js +114 -0
- package/app/merchant-core/migrations/runner.js.map +1 -0
- package/app/merchant-core/operating/repository.d.ts +0 -1
- package/app/merchant-core/operating/repository.js +2 -17
- package/app/merchant-core/operating/repository.js.map +1 -1
- package/app/merchant-core/operations-jobs/advice-runner.d.ts +63 -0
- package/app/merchant-core/operations-jobs/advice-runner.js +199 -0
- package/app/merchant-core/operations-jobs/advice-runner.js.map +1 -0
- package/app/merchant-core/operations-jobs/pilot-evidence.d.ts +64 -0
- package/app/merchant-core/operations-jobs/pilot-evidence.js +109 -0
- package/app/merchant-core/operations-jobs/pilot-evidence.js.map +1 -0
- package/app/merchant-core/operations-jobs/pilot-metrics.d.ts +70 -0
- package/app/merchant-core/operations-jobs/pilot-metrics.js +98 -0
- package/app/merchant-core/operations-jobs/pilot-metrics.js.map +1 -0
- package/app/merchant-core/operations-jobs/projection.d.ts +41 -0
- package/app/merchant-core/operations-jobs/projection.js +158 -0
- package/app/merchant-core/operations-jobs/projection.js.map +1 -0
- package/app/merchant-core/operations-jobs/scheduler.d.ts +68 -0
- package/app/merchant-core/operations-jobs/scheduler.js +233 -0
- package/app/merchant-core/operations-jobs/scheduler.js.map +1 -0
- package/app/merchant-core/operations-jobs/service.d.ts +260 -0
- package/app/merchant-core/operations-jobs/service.js +922 -0
- package/app/merchant-core/operations-jobs/service.js.map +1 -0
- package/app/merchant-core/opportunity/repository.d.ts +0 -1
- package/app/merchant-core/opportunity/repository.js +2 -17
- package/app/merchant-core/opportunity/repository.js.map +1 -1
- package/app/merchant-core/ops/facade.d.ts +10 -0
- package/app/merchant-core/ops/facade.js +52 -0
- package/app/merchant-core/ops/facade.js.map +1 -1
- package/app/merchant-core/ops/schema.d.ts +1 -1
- package/app/merchant-core/ops/schema.js +119 -2
- package/app/merchant-core/ops/schema.js.map +1 -1
- package/app/merchant-core/ops/surface.d.ts +37 -0
- package/app/merchant-core/ops/surface.js +240 -0
- package/app/merchant-core/ops/surface.js.map +1 -1
- package/app/merchant-core/orders/model.d.ts +1 -8
- package/app/merchant-core/orders/model.js +10 -2
- package/app/merchant-core/orders/model.js.map +1 -1
- package/app/merchant-core/orders/repository.d.ts +0 -1
- package/app/merchant-core/orders/repository.js +3 -18
- package/app/merchant-core/orders/repository.js.map +1 -1
- package/app/merchant-core/orders/service.js +34 -8
- package/app/merchant-core/orders/service.js.map +1 -1
- package/app/merchant-core/ownership/instance-ownership.d.ts +122 -0
- package/app/merchant-core/ownership/instance-ownership.js +236 -0
- package/app/merchant-core/ownership/instance-ownership.js.map +1 -0
- package/app/merchant-core/ownership/runtime.d.ts +175 -0
- package/app/merchant-core/ownership/runtime.js +422 -0
- package/app/merchant-core/ownership/runtime.js.map +1 -0
- package/app/merchant-core/proposal/engine.js +2 -0
- package/app/merchant-core/proposal/engine.js.map +1 -1
- package/app/merchant-core/proposal/publish.d.ts +0 -6
- package/app/merchant-core/proposal/publish.js +37 -3
- package/app/merchant-core/proposal/publish.js.map +1 -1
- package/app/merchant-core/proposal/repository.d.ts +0 -7
- package/app/merchant-core/proposal/repository.js +8 -17
- package/app/merchant-core/proposal/repository.js.map +1 -1
- package/app/merchant-core/proposal/types.d.ts +1 -0
- package/app/merchant-core/proposal/types.js.map +1 -1
- package/app/merchant-core/rfq/policy.d.ts +1 -0
- package/app/merchant-core/rfq/policy.js +6 -7
- package/app/merchant-core/rfq/policy.js.map +1 -1
- package/app/merchant-core/rfq/repository.d.ts +0 -1
- package/app/merchant-core/rfq/repository.js +2 -17
- package/app/merchant-core/rfq/repository.js.map +1 -1
- package/app/merchant-core/rfq/service.d.ts +2 -1
- package/app/merchant-core/rfq/service.js +2 -4
- package/app/merchant-core/rfq/service.js.map +1 -1
- package/app/merchant-core/storage/transaction.d.ts +95 -7
- package/app/merchant-core/storage/transaction.js +251 -2
- package/app/merchant-core/storage/transaction.js.map +1 -1
- package/app/merchant-credential-rotation.d.ts +4 -1
- package/app/merchant-credential-rotation.js +12 -8
- package/app/merchant-credential-rotation.js.map +1 -1
- package/app/merchant-runtime/manager.d.ts +2 -0
- package/app/merchant-runtime/manager.js +5 -0
- package/app/merchant-runtime/manager.js.map +1 -1
- package/app/negotiation/domain/objects.d.ts +2 -0
- package/app/negotiation/domain/objects.js +3 -0
- package/app/negotiation/domain/objects.js.map +1 -1
- package/app/negotiation/ledger/store.d.ts +4 -0
- package/app/negotiation/ledger/store.js +20 -0
- package/app/negotiation/ledger/store.js.map +1 -1
- package/app/product-init.d.ts +1 -0
- package/app/product-init.js +4 -1
- package/app/product-init.js.map +1 -1
- package/app/trust/identity/message-signature.d.ts +1 -1
- package/app/trust/identity/message-signature.js +6 -1
- package/app/trust/identity/message-signature.js.map +1 -1
- package/app/trust/identity/nonce.d.ts +5 -0
- package/app/trust/identity/nonce.js +2 -0
- package/app/trust/identity/nonce.js.map +1 -1
- package/app/weixin/ilink-client.d.ts +3 -2
- package/app/weixin/ilink-client.js +9 -2
- package/app/weixin/ilink-client.js.map +1 -1
- package/build-manifest.json +1672 -487
- package/deployment-lock.json +2 -2
- package/package.json +1 -1
- package/prepare.mjs +5 -1
- package/runtime-package.json +1 -1
- package/shipping-sbom.cdx.json +6 -6
- 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,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,WAAW,EAAE,CAAC;QACd,OAAO;IAC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AAI,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"}
|
|
@@ -102,11 +102,12 @@ export declare function internalServerError(): ServerProtocolError;
|
|
|
102
102
|
/**
|
|
103
103
|
* 认证失败(HTTP 层使用,帧 id 未知故返回 null)。
|
|
104
104
|
* protocol_code ∈ {authentication_required, authorization_failed, identity_rejected,
|
|
105
|
-
* replay_detected}。identity_rejected 与 replay_detected 是 §32 词表里认证相关的
|
|
106
|
-
* 额外结果:身份绑定冲突(403
|
|
105
|
+
* replay_detected, temporarily_unavailable}。identity_rejected 与 replay_detected 是 §32 词表里认证相关的
|
|
106
|
+
* 额外结果:身份绑定冲突(403)与重放(401);nonce 存储故障单独返回 503。
|
|
107
107
|
*/
|
|
108
|
-
export declare function authError(protocolCode: "authentication_required" | "authorization_failed" | "identity_rejected" | "replay_detected"): {
|
|
108
|
+
export declare function authError(protocolCode: "authentication_required" | "authorization_failed" | "identity_rejected" | "replay_detected" | "temporarily_unavailable"): {
|
|
109
109
|
httpStatus: number;
|
|
110
|
+
retryAfter?: number;
|
|
110
111
|
body: JsonRpcErrorBody;
|
|
111
112
|
};
|
|
112
113
|
/**
|
package/app/a2a/server/errors.js
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
* | body 超过 maxPayloadBytes | 413 | -32052 | payload_too_large |
|
|
46
46
|
*/
|
|
47
47
|
import { NegotiationValidationError } from "../../negotiation/domain/common.js";
|
|
48
|
+
import { NONCE_RETRY_AFTER_SECONDS } from "../../trust/identity/nonce.js";
|
|
48
49
|
/** JSON-RPC 2.0 标准 code + A2A/KNP 应用 code。 */
|
|
49
50
|
export const JSONRPC_CODES = {
|
|
50
51
|
PARSE_ERROR: -32700,
|
|
@@ -115,10 +116,17 @@ export function internalServerError() {
|
|
|
115
116
|
/**
|
|
116
117
|
* 认证失败(HTTP 层使用,帧 id 未知故返回 null)。
|
|
117
118
|
* protocol_code ∈ {authentication_required, authorization_failed, identity_rejected,
|
|
118
|
-
* replay_detected}。identity_rejected 与 replay_detected 是 §32 词表里认证相关的
|
|
119
|
-
* 额外结果:身份绑定冲突(403
|
|
119
|
+
* replay_detected, temporarily_unavailable}。identity_rejected 与 replay_detected 是 §32 词表里认证相关的
|
|
120
|
+
* 额外结果:身份绑定冲突(403)与重放(401);nonce 存储故障单独返回 503。
|
|
120
121
|
*/
|
|
121
122
|
export function authError(protocolCode) {
|
|
123
|
+
if (protocolCode === "temporarily_unavailable") {
|
|
124
|
+
return { httpStatus: 503, retryAfter: NONCE_RETRY_AFTER_SECONDS, body: {
|
|
125
|
+
code: JSONRPC_CODES.AUTH_ERROR,
|
|
126
|
+
message: "authentication temporarily unavailable",
|
|
127
|
+
data: { protocol_code: protocolCode, retry_after: NONCE_RETRY_AFTER_SECONDS },
|
|
128
|
+
} };
|
|
129
|
+
}
|
|
122
130
|
let httpStatus;
|
|
123
131
|
let message;
|
|
124
132
|
switch (protocolCode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/a2a/server/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/a2a/server/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAA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;AACzB,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO;QACL,IAAI,EAAE,aAAa,CAAC,cAAc;QAClC,OAAO,EAAE,QAAQ,MAAM,YAAY;QACnC,IAAI,EAAE,EAAE,MAAM,EAAE;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -13,6 +13,18 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
/**
|
|
17
|
+
* 生产 merchant A2A handler(`kiwi agent serve` 用)——脚本化 KNP 磋商:
|
|
18
|
+
*
|
|
19
|
+
* rfq/inquiry → offer;offer → counter_offer(还价到 DEAL 价);
|
|
20
|
+
* counter_offer → conditional_offer;clarification → 文字澄清应答;
|
|
21
|
+
* accept_nonbinding → agreement artifact(三副作用 flag 恒 false);
|
|
22
|
+
* withdraw/decline/cancel → 文字确认。
|
|
23
|
+
*
|
|
24
|
+
* 每个出站回复落 merchant 侧 Ledger(append-only,§22)。这是 `kiwi agent serve`
|
|
25
|
+
* 的确定性 merchant 行为;未来可替换为 LLM 驱动的 Negotiation Engine(同一 handler 接缝)。
|
|
26
|
+
*/
|
|
27
|
+
import { type MerchantProcurementProvider } from "./merchant-procurement.js";
|
|
16
28
|
import { type ProductSourceEvidence } from "./merchant-product-facts.js";
|
|
17
29
|
import type { CommerceDataSource } from "../../commerce/data-source.js";
|
|
18
30
|
import { LedgerStore } from "../../negotiation/ledger/index.js";
|
|
@@ -21,6 +33,9 @@ import type { NegotiationApprovalStore } from "./negotiation-approvals.js";
|
|
|
21
33
|
import { type NegotiationAdvisor } from "./negotiation-advisor.js";
|
|
22
34
|
import type { InquiryInterpreter, InquiryTopic } from "./inquiry-interpreter.js";
|
|
23
35
|
import type { ReceptionEngine } from "../reception/engine.js";
|
|
36
|
+
import type { CustomerIdentityWriter } from "./customer-identity-gateway.js";
|
|
37
|
+
import { QuoteHistoryStore } from "../../merchant-core/customer-memory/quote-history.js";
|
|
38
|
+
import type { ReceiptDispatcher } from "../../commerce/receipt/dispatcher.js";
|
|
24
39
|
import type { A2AMessage } from "../client/types.js";
|
|
25
40
|
import type { NegotiationHandler } from "./types.js";
|
|
26
41
|
export declare const MERCHANT_CAPABILITY = "com.harrylabsj.kiwi.shopping.negotiation";
|
|
@@ -65,6 +80,10 @@ export declare function buyerMessageForAdvisor(message: Pick<A2AMessage, "parts"
|
|
|
65
80
|
* 一致(half-up);要求整数百分比(dealDiscountPercent 缺省 5)。
|
|
66
81
|
*/
|
|
67
82
|
export declare function applyDiscountPercentMinor(priceMinor: number, discountPercent: number): number;
|
|
83
|
+
export type QuoteHistoryAccess = Pick<QuoteHistoryStore, "checkActive" | "queryHistory"> & {
|
|
84
|
+
applyDelegation(input: Parameters<QuoteHistoryStore["applyDelegation"]>[0]): unknown;
|
|
85
|
+
indexOffer(input: Parameters<QuoteHistoryStore["indexOffer"]>[0]): unknown;
|
|
86
|
+
};
|
|
68
87
|
export interface MerchantHandlerOptions {
|
|
69
88
|
ledger: LedgerStore;
|
|
70
89
|
now: () => string;
|
|
@@ -74,6 +93,7 @@ export interface MerchantHandlerOptions {
|
|
|
74
93
|
offerPriceMinor?: number;
|
|
75
94
|
/** 真实商品源(接 shopping-cli /products/{sku} 等开放商品层);缺省用内置演示价。 */
|
|
76
95
|
productSource?: MerchantProductSource;
|
|
96
|
+
procurementFacts?: MerchantProcurementProvider;
|
|
77
97
|
/** 商品源故障时是否回退内置演示价(fail-open);缺省 false = fail-closed
|
|
78
98
|
* (decline temporarily_unavailable)。仅本地 demo/测试形态显式开启。 */
|
|
79
99
|
allowDemoPriceFallback?: boolean;
|
|
@@ -98,6 +118,15 @@ export interface MerchantHandlerOptions {
|
|
|
98
118
|
/** 议价审批队列(B2):低于自动折扣边界的还价转人工,批准后买家重试
|
|
99
119
|
* 命中一次性授权价。缺省时保持原有 approval_required 硬拒行为。 */
|
|
100
120
|
negotiationApprovals?: NegotiationApprovalStore;
|
|
121
|
+
/** Tenant-private settings; the recipient is never emitted unmasked. */
|
|
122
|
+
alipayCollection?: {
|
|
123
|
+
origin: string;
|
|
124
|
+
current: () => {
|
|
125
|
+
version: string;
|
|
126
|
+
enabled: boolean;
|
|
127
|
+
recipient: string;
|
|
128
|
+
} | undefined;
|
|
129
|
+
};
|
|
101
130
|
/** 协商顾问(C):只生成面向买家的措辞,价格仍由确定性引擎计算。
|
|
102
131
|
* 缺省关闭;输出经 safeAdvisorMessage 校验,越界即回退固定文案。 */
|
|
103
132
|
negotiationAdvisor?: NegotiationAdvisor;
|
|
@@ -122,6 +151,33 @@ export interface MerchantHandlerOptions {
|
|
|
122
151
|
amountMinor: string;
|
|
123
152
|
endsAt: string;
|
|
124
153
|
} | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* 买家识别与交易回执 · K1:验签买家的本店身份自动建档。
|
|
156
|
+
* 在正式 RFQ 受理(入参校验后)与判定为有效询价的 inquiry 后调用;
|
|
157
|
+
* 搜索、查任务、无关消息和被拒请求不建档。写者不可用时询价照常继续。
|
|
158
|
+
*/
|
|
159
|
+
customerIdentity?: {
|
|
160
|
+
merchantId: string;
|
|
161
|
+
writer: CustomerIdentityWriter;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* 买家识别与交易回执 · K2:委托与已发报价历史。委托随请求体签名覆盖的
|
|
165
|
+
* message metadata 到达;已发报价在 appendSent 后索引;历史查询扩展
|
|
166
|
+
* (KNP inquiry subject.kiwi_history_query)读前复核授权。任何委托/查询
|
|
167
|
+
* 失败都降级为“未委托/无历史”,绝不阻塞询价。
|
|
168
|
+
*/
|
|
169
|
+
quoteHistory?: {
|
|
170
|
+
store: QuoteHistoryAccess;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* 买家识别与交易回执 · K5/K6:向 Catalog 上报商家侧事实的投递通道。
|
|
174
|
+
* 协议持久化后上报“协议已签发”;带入口的报价正式发出后上报“已提供
|
|
175
|
+
* 入口”。上报失败不阻塞业务(outbox 退避重试)。
|
|
176
|
+
*/
|
|
177
|
+
commerceReceipts?: {
|
|
178
|
+
merchantId: string;
|
|
179
|
+
dispatcher: ReceiptDispatcher;
|
|
180
|
+
};
|
|
125
181
|
}
|
|
126
182
|
/**
|
|
127
183
|
* 真实商品源:给定 SKU 返回价目(shopping-cli 开放层/ERP/商品表均可接入)。
|
|
@@ -162,5 +218,23 @@ export declare function dataSourceProductSource(dataSource: CommerceDataSource):
|
|
|
162
218
|
* valid_until MUST NOT be accepted after that timestamp" 永不生效,陈旧
|
|
163
219
|
* 报价可被无限期接受)。24h 窗口,accept 时校验(offer_expired 拒绝)。 */
|
|
164
220
|
export declare const OFFER_VALIDITY_MS: number;
|
|
221
|
+
export interface AlipayCollectionLookup {
|
|
222
|
+
negotiationId: string;
|
|
223
|
+
offerId: string;
|
|
224
|
+
version: string;
|
|
225
|
+
buyerPrincipalId: string;
|
|
226
|
+
agreementId: string;
|
|
227
|
+
termsDigest: string;
|
|
228
|
+
}
|
|
229
|
+
export interface AlipayCollectionBinding {
|
|
230
|
+
version: string;
|
|
231
|
+
totalMinor: number;
|
|
232
|
+
currency: "CNY";
|
|
233
|
+
expiresAt: string;
|
|
234
|
+
}
|
|
235
|
+
export interface MerchantHandler extends NegotiationHandler {
|
|
236
|
+
/** Only call with a verified buyer principal, never a client-supplied identity. */
|
|
237
|
+
resolveAlipayCollection(input: AlipayCollectionLookup): AlipayCollectionBinding | undefined;
|
|
238
|
+
}
|
|
165
239
|
/** 构造生产 merchant KNP handler。 */
|
|
166
|
-
export declare function createMerchantHandler(options: MerchantHandlerOptions):
|
|
240
|
+
export declare function createMerchantHandler(options: MerchantHandlerOptions): MerchantHandler;
|