@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
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
* 每个出站回复落 merchant 侧 Ledger(append-only,§22)。这是 `kiwi agent serve`
|
|
25
25
|
* 的确定性 merchant 行为;未来可替换为 LLM 驱动的 Negotiation Engine(同一 handler 接缝)。
|
|
26
26
|
*/
|
|
27
|
+
import { merchantProcurementTerms, readProcurementProjection } from "./merchant-procurement.js";
|
|
28
|
+
import { statSync as statReceiptLedger } from "node:fs";
|
|
29
|
+
import { StreamGateError } from "../../merchant-core/customer-delivery/stream-gate.js";
|
|
27
30
|
import { BoundedMap, BoundedSet } from "../../runtime/bounded-memory.js";
|
|
28
31
|
import { checkedProductStock, checkedSourceEvidence, quoteFactsStillValid, recoverQuoteSourceSnapshot } from "./merchant-product-facts.js";
|
|
29
32
|
import { LedgerStore } from "../../negotiation/ledger/index.js";
|
|
@@ -35,6 +38,11 @@ import { toMinorUnits as losslessToMinorUnits } from "../../protocol/legacy-shop
|
|
|
35
38
|
import { WORKBENCH_CURRENCY_TABLE_VERSION } from "../../merchant/application/money.js";
|
|
36
39
|
import { ADVISOR_BUYER_MESSAGE_MAX_CHARS, safeAdvisorMessage, } from "./negotiation-advisor.js";
|
|
37
40
|
import { calculateWorkbenchQuote } from "../../merchant/quote-calculator.js";
|
|
41
|
+
import { isOpenInquiryIdentity } from "../open-inquiry-identity.js";
|
|
42
|
+
import { assertSafeTargetUrl } from "../client/url-policy.js";
|
|
43
|
+
import { parseAlipayCollectionLink, parseAlipayCollectionTerms } from "../../handoff/alipay-collection.js";
|
|
44
|
+
import { QuoteHistoryStore, delegationFromMetadata, parseHistoryQueryExtension, isQuoteHistoryRecall, quoteHistoryNote, validateDelegationShape, } from "../../merchant-core/customer-memory/quote-history.js";
|
|
45
|
+
import { thumbprintFromOpenInquiryIdentity, } from "../../commerce/receipt/receipts.js";
|
|
38
46
|
import { createNegotiationPhase, isTerminalPhase, transitionPhase, } from "../../negotiation/state/phase.js";
|
|
39
47
|
import { NegotiationValidationError } from "../../negotiation/domain/common.js";
|
|
40
48
|
import { resolveUnitConversion, unitConversionPolicy, } from "../unit-alias.js";
|
|
@@ -113,12 +121,17 @@ export function requestedDeliveryBeforeOf(payload) {
|
|
|
113
121
|
* 时限与商家已配置的权威交期对齐;解析不出就不猜。
|
|
114
122
|
*/
|
|
115
123
|
export function requestedDeliveryDaysOf(text) {
|
|
116
|
-
|
|
124
|
+
// 日历日期与相对期限混在一起时无法确认买家的真实截止时间,不作推断。
|
|
125
|
+
// 单独“18日”也可能是日期;只有“18日内”等明确时长才按相对日数处理。
|
|
126
|
+
if (/(?:[\d一二两三四五六七八九十]+\s*月\s*[\d一二两三四五六七八九十]+\s*[日号]?|\d{4}[-/.]\d{1,2}[-/.]\d{1,2}|(?<!工作)[\d一二两三四五六七八九十]+\s*日(?!\s*(?:以)?内))/.test(text)) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const numeric = /(?<!\d)(\d{1,3})\s*(?:个)?\s*(?:工作日|天|日(?=\s*(?:以)?内))\s*(?:内|以内|到|到达|送到|送达|发到|发货|到货)?/.exec(text);
|
|
117
130
|
if (numeric !== null) {
|
|
118
131
|
const days = Number(numeric[1]);
|
|
119
132
|
return Number.isSafeInteger(days) && days > 0 ? days : undefined;
|
|
120
133
|
}
|
|
121
|
-
const chinese = /([一二两三四五六七八九十]+)\s*(?:个)?\s*(?:工作日|天|日)\s*(?:内|以内|到|到达|送到|送达|发到|发货|到货)?/.exec(text);
|
|
134
|
+
const chinese = /([一二两三四五六七八九十]+)\s*(?:个)?\s*(?:工作日|天|日(?=\s*(?:以)?内))\s*(?:内|以内|到|到达|送到|送达|发到|发货|到货)?/.exec(text);
|
|
122
135
|
if (chinese === null)
|
|
123
136
|
return undefined;
|
|
124
137
|
const digits = {
|
|
@@ -267,13 +280,41 @@ function offerTerms(opts, now) {
|
|
|
267
280
|
valid_until: new Date(validUntil).toISOString(),
|
|
268
281
|
};
|
|
269
282
|
}
|
|
283
|
+
function alipayBuyerIdentity(identity) {
|
|
284
|
+
return identity.trim() !== "" && !isOpenInquiryIdentity(identity);
|
|
285
|
+
}
|
|
286
|
+
function positiveMinorAmount(value) {
|
|
287
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
288
|
+
}
|
|
289
|
+
function alipayRoute(origin, negotiationId, offerId, version) {
|
|
290
|
+
try {
|
|
291
|
+
const base = assertSafeTargetUrl(origin, { allowLoopback: false });
|
|
292
|
+
if (base.protocol !== "https:" || base.href !== `${base.origin}/`)
|
|
293
|
+
return undefined;
|
|
294
|
+
const ids = [negotiationId, offerId, version];
|
|
295
|
+
if (ids.some((id) => id.trim() === "" || id === "." || id === ".."))
|
|
296
|
+
return undefined;
|
|
297
|
+
const url = `${base.origin}/collect/alipay/${ids.map((id) => encodeURIComponent(id)).join("/")}`;
|
|
298
|
+
return parseAlipayCollectionLink(url) !== null ? url : undefined;
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function recipientSummary(recipient) {
|
|
305
|
+
const chars = Array.from(recipient.trim());
|
|
306
|
+
const first = chars[0];
|
|
307
|
+
return first !== undefined && chars.length > 1 && /^\p{L}$/u.test(first) ? `${first}***` : "***";
|
|
308
|
+
}
|
|
270
309
|
function buildAgreement(input) {
|
|
310
|
+
const agreedTerms = input.agreed_terms;
|
|
271
311
|
return {
|
|
272
312
|
type: "accepted_nonbinding_agreement",
|
|
273
313
|
agreement_id: newAgreementId(),
|
|
274
314
|
negotiation_id: input.negotiation_id,
|
|
275
315
|
accepted_offer_id: input.accepted_offer_id,
|
|
276
316
|
agreed_terms: input.agreed_terms,
|
|
317
|
+
...(agreedTerms.kiwi_alipay_collection !== undefined ? { handoff_destination: agreedTerms.handoff_destination } : {}),
|
|
277
318
|
terms_digest: contentDigest(input.agreed_terms),
|
|
278
319
|
accepted_by: ["buyer", "merchant"],
|
|
279
320
|
created_at: input.created_at,
|
|
@@ -318,7 +359,7 @@ class ProductSourceUnavailableError extends Error {
|
|
|
318
359
|
*/
|
|
319
360
|
/**
|
|
320
361
|
* 单位校验:商品**没有单位就拒绝**(fail-closed,不知道按什么计量就不报价);
|
|
321
|
-
*
|
|
362
|
+
* 有单位时接受商家显式别名及内建的 box/盒、piece/个/件 1:1 写法。
|
|
322
363
|
* 不做“个/件 = 盒”的自动换算,也不改变数量/单价/金额。
|
|
323
364
|
*/
|
|
324
365
|
function unitMismatch(productUnit, requestedUnit, policy) {
|
|
@@ -333,6 +374,11 @@ const declineReply = (reasonCode = "state_conflict", message) => ({
|
|
|
333
374
|
...(message !== undefined ? { message } : {}),
|
|
334
375
|
taskState: "completed",
|
|
335
376
|
});
|
|
377
|
+
function unitDecline(productUnit) {
|
|
378
|
+
return declineReply("field_unsupported", productUnit?.trim()
|
|
379
|
+
? "询价数量单位与商品销售单位不匹配,请核对单位及包装数量后重新询价。"
|
|
380
|
+
: "商品尚未提供销售单位,请联系商家确认后重新询价。");
|
|
381
|
+
}
|
|
336
382
|
/** AC09/D03:统计入站商务动作的商品行数(rfq/offer/counter_offer)。 */
|
|
337
383
|
function multiItemCountOf(envelope) {
|
|
338
384
|
const payload = typeof envelope.payload === "object" && envelope.payload !== null
|
|
@@ -360,6 +406,31 @@ const envelopeReply = (reply) => ({
|
|
|
360
406
|
export function createMerchantHandler(options) {
|
|
361
407
|
const { ledger, now, sender, counterparty } = options;
|
|
362
408
|
const offerPriceMinor = options.offerPriceMinor ?? MERCHANT_OFFER_PRICE_MINOR;
|
|
409
|
+
const currentAlipay = () => {
|
|
410
|
+
try {
|
|
411
|
+
const config = options.alipayCollection;
|
|
412
|
+
const current = config?.current();
|
|
413
|
+
if (config !== undefined && current?.enabled === true && current.recipient.trim() !== "") {
|
|
414
|
+
return { origin: config.origin, version: current.version, summary: recipientSummary(current.recipient) };
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
catch {
|
|
418
|
+
// A private settings read failure must not surface details or enable collection.
|
|
419
|
+
}
|
|
420
|
+
return undefined;
|
|
421
|
+
};
|
|
422
|
+
const collectionForTerms = (terms, negotiationId, offerId) => {
|
|
423
|
+
const collection = parseAlipayCollectionTerms(terms);
|
|
424
|
+
const current = currentAlipay();
|
|
425
|
+
if (collection === null || current === undefined || collection.version !== current.version ||
|
|
426
|
+
collection.recipient_summary !== current.summary || collection.expires_at !== terms.valid_until ||
|
|
427
|
+
!(Date.parse(collection.expires_at) > Date.parse(now())))
|
|
428
|
+
return undefined;
|
|
429
|
+
const destination = alipayRoute(current.origin, negotiationId, offerId, current.version);
|
|
430
|
+
if (destination === undefined || destination !== terms.handoff_destination)
|
|
431
|
+
return undefined;
|
|
432
|
+
return { version: collection.version, totalMinor: collection.total_minor, currency: collection.currency, expiresAt: collection.expires_at };
|
|
433
|
+
};
|
|
363
434
|
const allowDemoPriceFallback = options.allowDemoPriceFallback ?? false;
|
|
364
435
|
const unitPolicy = unitConversionPolicy({
|
|
365
436
|
aliases: options.unitAliases,
|
|
@@ -411,6 +482,190 @@ export function createMerchantHandler(options) {
|
|
|
411
482
|
"decline",
|
|
412
483
|
"cancel",
|
|
413
484
|
]);
|
|
485
|
+
/**
|
|
486
|
+
* K1:验签开放询价身份的本店自动建档。仅在业务边界(正式受理 RFQ /
|
|
487
|
+
* 判定为有效询价)调用;写者不可用时静默继续(询价不被阻断、不承诺
|
|
488
|
+
* 已建档),spooled writer 会可靠重试。匿名/静态凭据/未验签不进入。
|
|
489
|
+
* 返回本店客户 subject(建档不可用时 undefined)。
|
|
490
|
+
*/
|
|
491
|
+
const registerVerifiedCustomerIdentity = async (ctx, source) => {
|
|
492
|
+
const identity = options.customerIdentity;
|
|
493
|
+
if (identity === undefined)
|
|
494
|
+
return undefined;
|
|
495
|
+
if (ctx.identityVerified !== true)
|
|
496
|
+
return undefined;
|
|
497
|
+
if (!isOpenInquiryIdentity(ctx.senderIdentity))
|
|
498
|
+
return undefined;
|
|
499
|
+
try {
|
|
500
|
+
const outcome = await identity.writer.ensure({
|
|
501
|
+
merchant_id: identity.merchantId,
|
|
502
|
+
verified_actor: ctx.senderIdentity,
|
|
503
|
+
source,
|
|
504
|
+
negotiation_id: ctx.envelope.negotiation_id,
|
|
505
|
+
message_id: ctx.envelope.message_id,
|
|
506
|
+
});
|
|
507
|
+
if (outcome.status === "registered")
|
|
508
|
+
return { subject_id: outcome.subject_id };
|
|
509
|
+
return undefined;
|
|
510
|
+
}
|
|
511
|
+
catch {
|
|
512
|
+
// Writer 实现不应抛出(失败收敛为 unavailable);防御性兜底不阻断询价。
|
|
513
|
+
return undefined;
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
/**
|
|
517
|
+
* K2:校验并登记 message metadata 携带的委托声明。失败一律静默降级为
|
|
518
|
+
* 未委托(旧客户端/未授权/过期均正常询价,不带出历史)。委托生效以
|
|
519
|
+
* 验签身份对应的本店客户主体为授权主体。
|
|
520
|
+
*/
|
|
521
|
+
const applyDelegationFromMetadata = async (ctx, subjectId) => {
|
|
522
|
+
const history = options.quoteHistory;
|
|
523
|
+
if (history === undefined)
|
|
524
|
+
return;
|
|
525
|
+
if (ctx.identityVerified !== true || !isOpenInquiryIdentity(ctx.senderIdentity))
|
|
526
|
+
return;
|
|
527
|
+
if (subjectId === undefined)
|
|
528
|
+
return;
|
|
529
|
+
const raw = delegationFromMetadata(ctx.message.metadata);
|
|
530
|
+
if (raw === undefined)
|
|
531
|
+
return;
|
|
532
|
+
const merchantId = options.customerIdentity?.merchantId;
|
|
533
|
+
if (merchantId === undefined)
|
|
534
|
+
return;
|
|
535
|
+
const validated = validateDelegationShape(raw, merchantId, now());
|
|
536
|
+
if (!validated.ok)
|
|
537
|
+
return;
|
|
538
|
+
try {
|
|
539
|
+
await history.store.applyDelegation({
|
|
540
|
+
merchant_id: merchantId,
|
|
541
|
+
buyer_actor: ctx.senderIdentity,
|
|
542
|
+
subject_id: subjectId,
|
|
543
|
+
delegation: validated.delegation,
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
catch {
|
|
547
|
+
// 委托存储失败按未委托处理(静默;下一轮带新 message ID 的 RFQ 可重试)。
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
const indexHistoryOffer = async (ctx, reply, product) => {
|
|
551
|
+
const store = options.quoteHistory?.store;
|
|
552
|
+
const merchantId = options.customerIdentity?.merchantId;
|
|
553
|
+
if (store === undefined || merchantId === undefined ||
|
|
554
|
+
ctx.identityVerified !== true || !isOpenInquiryIdentity(ctx.senderIdentity))
|
|
555
|
+
return;
|
|
556
|
+
const grant = store.checkActive({ merchant_id: merchantId, buyer_actor: ctx.senderIdentity });
|
|
557
|
+
if (grant === undefined)
|
|
558
|
+
return;
|
|
559
|
+
const payload = reply.payload;
|
|
560
|
+
const terms = payload.terms ?? payload.proposed_terms ?? payload.base_terms;
|
|
561
|
+
const item = terms?.items?.[0];
|
|
562
|
+
if (payload.offer_id === undefined || terms === undefined || item?.unit_price === undefined)
|
|
563
|
+
return;
|
|
564
|
+
try {
|
|
565
|
+
await store.indexOffer({
|
|
566
|
+
merchant_id: merchantId, subject_id: grant.subject_id,
|
|
567
|
+
negotiation_id: reply.negotiation_id, offer_id: payload.offer_id, message_id: reply.message_id,
|
|
568
|
+
sku: item.sku, quantity: item.quantity.value, unit: item.quantity.unit,
|
|
569
|
+
currency: item.unit_price.currency, unit_price_minor: item.unit_price.amount_minor,
|
|
570
|
+
terms_digest: contentDigest(terms),
|
|
571
|
+
spec: {
|
|
572
|
+
...(product.source_evidence !== undefined ? {
|
|
573
|
+
source_evidence: product.source_evidence,
|
|
574
|
+
...(product.title !== undefined ? { title: product.title } : {}),
|
|
575
|
+
...(product.unit !== undefined ? { product_unit: product.unit } : {}),
|
|
576
|
+
...(product.valid_until !== undefined ? { product_valid_until: product.valid_until } : {}),
|
|
577
|
+
} : {}),
|
|
578
|
+
},
|
|
579
|
+
...(terms.valid_until !== undefined ? { valid_until: terms.valid_until } : {}),
|
|
580
|
+
quoted_at: reply.created_at,
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
catch {
|
|
584
|
+
// History is optional when the merchant writer is temporarily unavailable.
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
/**
|
|
588
|
+
* K2:历史查询扩展入口(KNP inquiry subject.kiwi_history_query)。
|
|
589
|
+
* 未验签 / 未委托 / 扩展不支持时返回 undefined(走原接待路径,无泄漏)。
|
|
590
|
+
* 唯一入口返回结构化候选及来源;本次价格仍走正式 RFQ。
|
|
591
|
+
*/
|
|
592
|
+
const resolveQuoteHistoryReply = async (ctx) => {
|
|
593
|
+
const history = options.quoteHistory;
|
|
594
|
+
const merchantId = options.customerIdentity?.merchantId;
|
|
595
|
+
if (history === undefined || merchantId === undefined)
|
|
596
|
+
return undefined;
|
|
597
|
+
if (ctx.identityVerified !== true || !isOpenInquiryIdentity(ctx.senderIdentity))
|
|
598
|
+
return undefined;
|
|
599
|
+
const inquiry = ctx.envelope.payload;
|
|
600
|
+
const extension = parseHistoryQueryExtension(inquiry?.subject);
|
|
601
|
+
if (extension === undefined)
|
|
602
|
+
return undefined;
|
|
603
|
+
const authorization = history.store.checkActive({
|
|
604
|
+
merchant_id: merchantId,
|
|
605
|
+
buyer_actor: ctx.senderIdentity,
|
|
606
|
+
});
|
|
607
|
+
if (authorization === undefined)
|
|
608
|
+
return undefined;
|
|
609
|
+
const hits = history.store.queryHistory({
|
|
610
|
+
merchant_id: merchantId,
|
|
611
|
+
subject_id: authorization.subject_id,
|
|
612
|
+
...(extension.skus !== undefined ? { skus: extension.skus } : {}),
|
|
613
|
+
...(extension.limit !== undefined ? { limit: extension.limit } : {}),
|
|
614
|
+
});
|
|
615
|
+
if (history.store.checkActive({
|
|
616
|
+
merchant_id: merchantId, buyer_actor: ctx.senderIdentity,
|
|
617
|
+
})?.subject_id !== authorization.subject_id)
|
|
618
|
+
return undefined;
|
|
619
|
+
const historyData = {
|
|
620
|
+
type: "kiwi_quote_history",
|
|
621
|
+
version: 1,
|
|
622
|
+
hits: hits.map((hit) => ({
|
|
623
|
+
negotiation_id: hit.negotiation_id,
|
|
624
|
+
offer_id: hit.offer_id,
|
|
625
|
+
offer_version: hit.offer_version,
|
|
626
|
+
sku: hit.sku,
|
|
627
|
+
quantity: hit.quantity,
|
|
628
|
+
unit: hit.unit,
|
|
629
|
+
price: {
|
|
630
|
+
currency: hit.currency,
|
|
631
|
+
amount_minor: hit.unit_price_minor,
|
|
632
|
+
},
|
|
633
|
+
terms_digest: hit.terms_digest,
|
|
634
|
+
spec: hit.spec,
|
|
635
|
+
quoted_at: hit.quoted_at,
|
|
636
|
+
...(hit.valid_until !== undefined ? { valid_until: hit.valid_until } : {}),
|
|
637
|
+
})),
|
|
638
|
+
};
|
|
639
|
+
const summary = hits.length === 0
|
|
640
|
+
? "本店没有可引用的已发报价历史;请直接发送正式询价(SKU、数量、单位)。"
|
|
641
|
+
: `找到 ${hits.length} 条上次报价记录(含时间与有效期);本次价格请以正式 RFQ 返回为准。`;
|
|
642
|
+
const reply = seedEnvelope({
|
|
643
|
+
negotiation_id: ctx.envelope.negotiation_id,
|
|
644
|
+
in_reply_to: ctx.envelope.message_id,
|
|
645
|
+
actor: "merchant",
|
|
646
|
+
action: "clarification_response",
|
|
647
|
+
created_at: now(),
|
|
648
|
+
payload: {
|
|
649
|
+
type: "clarification_response",
|
|
650
|
+
answers: [
|
|
651
|
+
{ code: "quote_history", value: hits.length > 0 ? "available" : "empty", note: summary },
|
|
652
|
+
],
|
|
653
|
+
},
|
|
654
|
+
public_message: summary,
|
|
655
|
+
});
|
|
656
|
+
return {
|
|
657
|
+
kind: "accepted",
|
|
658
|
+
taskState: "completed",
|
|
659
|
+
message: {
|
|
660
|
+
role: "agent",
|
|
661
|
+
parts: [
|
|
662
|
+
{ kind: "data", data: { knp_envelope: reply } },
|
|
663
|
+
{ kind: "data", data: historyData },
|
|
664
|
+
],
|
|
665
|
+
messageId: reply.message_id,
|
|
666
|
+
},
|
|
667
|
+
};
|
|
668
|
+
};
|
|
414
669
|
/** 审查 BUG-10:把入站 action 映射到相位机事件并推进;非法转换(不在
|
|
415
670
|
* 转换表内的组合)fail-closed 返回 false(调用方 decline state_conflict)。
|
|
416
671
|
* clarification 由商家的结构化 clarification_response 应答同轮恢复,
|
|
@@ -522,6 +777,139 @@ export function createMerchantHandler(options) {
|
|
|
522
777
|
occurred_at: now(),
|
|
523
778
|
});
|
|
524
779
|
};
|
|
780
|
+
// 买家识别与交易回执 · K4:商家协议持久化。
|
|
781
|
+
// 有效 accept 在相位推进前预写 `agreement_issued` 证据事件(商家协议号、
|
|
782
|
+
// 被接受报价、条款摘要、已验签买方绑定与完整协议结果)。相位与协议无法在
|
|
783
|
+
// 两次 append 间原子提交,因此按“预写证据补齐”:任一中断点重试都复用
|
|
784
|
+
// 同一商家协议号与摘要;终态但无证据的历史窗口保持拒绝(不生成替代协议)。
|
|
785
|
+
/** 查找本磋商已落账的协议证据(offer_id 与 terms_digest 强匹配)。 */
|
|
786
|
+
const findAgreementEvidence = (negotiationId, acceptedOfferId, termsDigest, persistedEvents) => {
|
|
787
|
+
if (acceptedOfferId === "" || termsDigest === "")
|
|
788
|
+
return undefined;
|
|
789
|
+
try {
|
|
790
|
+
for (const event of persistedEvents ?? ledger.events(negotiationId)) {
|
|
791
|
+
if (event.event_kind !== "system")
|
|
792
|
+
continue;
|
|
793
|
+
const result = event.outcome.kind === "ok" ? event.outcome.result : undefined;
|
|
794
|
+
if (result === undefined || result["kind"] !== "agreement_issued")
|
|
795
|
+
continue;
|
|
796
|
+
const agreement = result["agreement"];
|
|
797
|
+
if (agreement === null || typeof agreement !== "object")
|
|
798
|
+
continue;
|
|
799
|
+
const artifact = agreement;
|
|
800
|
+
const evidenceOffer = String(result["accepted_offer_id"] ?? artifact["accepted_offer_id"] ?? "");
|
|
801
|
+
if (evidenceOffer !== acceptedOfferId)
|
|
802
|
+
continue;
|
|
803
|
+
if (String(artifact["terms_digest"] ?? "") !== termsDigest)
|
|
804
|
+
continue;
|
|
805
|
+
return {
|
|
806
|
+
agreement: artifact,
|
|
807
|
+
buyer_binding: String(result["buyer_binding"] ?? ""),
|
|
808
|
+
accept_message_id: result["accept_message_id"],
|
|
809
|
+
accept_wire_digest: result["accept_wire_digest"],
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
catch {
|
|
814
|
+
// 账本不可读:按无证据处理(后续路径各自 fail-closed)。
|
|
815
|
+
}
|
|
816
|
+
return undefined;
|
|
817
|
+
};
|
|
818
|
+
/** 预写协议证据(system 事件,append 原子)。 */
|
|
819
|
+
const appendAgreementEvidence = async (input) => {
|
|
820
|
+
await ledger.append({
|
|
821
|
+
event_kind: "system",
|
|
822
|
+
negotiation_id: input.negotiationId,
|
|
823
|
+
agreement_id: String(input.agreement["agreement_id"] ?? ""),
|
|
824
|
+
terms_digest: String(input.agreement["terms_digest"] ?? ""),
|
|
825
|
+
identity: {
|
|
826
|
+
sender_identity: sender,
|
|
827
|
+
counterparty_identity: boundPeers.get(input.negotiationId) ?? counterparty,
|
|
828
|
+
actor: "merchant",
|
|
829
|
+
},
|
|
830
|
+
capability: { capability: MERCHANT_CAPABILITY, protocol_version: "1.0" },
|
|
831
|
+
outcome: {
|
|
832
|
+
kind: "ok",
|
|
833
|
+
result: {
|
|
834
|
+
kind: "agreement_issued",
|
|
835
|
+
agreement: input.agreement,
|
|
836
|
+
accepted_offer_id: input.acceptedOfferId,
|
|
837
|
+
buyer_binding: input.buyerBinding,
|
|
838
|
+
accept_message_id: input.acceptMessageId,
|
|
839
|
+
accept_wire_digest: input.acceptWireDigest,
|
|
840
|
+
},
|
|
841
|
+
},
|
|
842
|
+
occurred_at: now(),
|
|
843
|
+
});
|
|
844
|
+
};
|
|
845
|
+
const recordAgreementReceipt = (negotiationId, agreement, identity, recovering = false) => {
|
|
846
|
+
const receipts = options.commerceReceipts;
|
|
847
|
+
const binding = thumbprintFromOpenInquiryIdentity(identity);
|
|
848
|
+
if (receipts === undefined || binding === undefined)
|
|
849
|
+
return;
|
|
850
|
+
const agreementId = String(agreement.agreement_id);
|
|
851
|
+
const receipt = {
|
|
852
|
+
event_id: `merchant-agreement:${agreementId}`,
|
|
853
|
+
event_type: "merchant_agreement_issued",
|
|
854
|
+
merchant_id: receipts.merchantId,
|
|
855
|
+
negotiation_id: negotiationId,
|
|
856
|
+
merchant_agreement_id: agreementId,
|
|
857
|
+
accepted_offer_id: String(agreement.accepted_offer_id),
|
|
858
|
+
terms_digest: String(agreement.terms_digest),
|
|
859
|
+
buyer_binding: binding,
|
|
860
|
+
occurred_at: String(agreement.created_at),
|
|
861
|
+
};
|
|
862
|
+
if (recovering)
|
|
863
|
+
receipts.dispatcher.record(receipt);
|
|
864
|
+
else
|
|
865
|
+
void receipts.dispatcher.enqueueAndDeliver(receipt).catch(() => { });
|
|
866
|
+
};
|
|
867
|
+
let scannedVersion;
|
|
868
|
+
const recoverReceipts = () => {
|
|
869
|
+
const dispatcher = options.commerceReceipts?.dispatcher;
|
|
870
|
+
if (!dispatcher)
|
|
871
|
+
return;
|
|
872
|
+
const version = ledger.receiptDirectoryVersion();
|
|
873
|
+
if (version === scannedVersion)
|
|
874
|
+
return;
|
|
875
|
+
let complete = true;
|
|
876
|
+
for (const file of ledger.receiptLedgerFiles()) {
|
|
877
|
+
try {
|
|
878
|
+
const stat = statReceiptLedger(file, { bigint: true });
|
|
879
|
+
dispatcher.replayLedger(file, `${stat.ino}:${stat.size}:${stat.mtimeNs}`, () => {
|
|
880
|
+
const events = ledger.readReceiptLedger(file);
|
|
881
|
+
const terminal = [...events].reverse().find((event) => event.state_transition !== undefined);
|
|
882
|
+
for (const event of events) {
|
|
883
|
+
if (event.event_kind === "message_sent" && event.wire_payload !== undefined) {
|
|
884
|
+
recordEntryReceipt(event.wire_payload, true);
|
|
885
|
+
}
|
|
886
|
+
if (terminal?.state_transition?.to_phase !== "AGREEMENT_REACHED" || event.event_kind !== "system")
|
|
887
|
+
continue;
|
|
888
|
+
const result = event.outcome.kind === "ok" ? event.outcome.result : undefined;
|
|
889
|
+
if (result?.kind === "agreement_issued" && result.agreement !== null && typeof result.agreement === "object") {
|
|
890
|
+
recordAgreementReceipt(event.negotiation_id, result.agreement, String(result.buyer_binding ?? ""), true);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
catch {
|
|
896
|
+
complete = false;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
if (complete)
|
|
900
|
+
scannedVersion = version;
|
|
901
|
+
};
|
|
902
|
+
/** 终态重放:证据命中时按原协议幂等返回(B6)。 */
|
|
903
|
+
const replayedAgreementResult = (agreement) => ({
|
|
904
|
+
kind: "accepted",
|
|
905
|
+
taskState: "completed",
|
|
906
|
+
artifactParts: [{ kind: "data", data: { agreement } }],
|
|
907
|
+
message: {
|
|
908
|
+
role: "agent",
|
|
909
|
+
parts: [{ kind: "text", text: "Agreement reached (nonbinding)." }],
|
|
910
|
+
messageId: newMessageId(),
|
|
911
|
+
},
|
|
912
|
+
});
|
|
525
913
|
// 每 negotiation 已解析的真实商品价(sku → {priceMinor, currency}),带
|
|
526
914
|
// TTL(评审项 L3:此前永久累积、价格永不刷新——长驻 merchant 节点内存
|
|
527
915
|
// 单调增长且价目陈旧)。
|
|
@@ -657,6 +1045,33 @@ export function createMerchantHandler(options) {
|
|
|
657
1045
|
endsAt: value.endsAt,
|
|
658
1046
|
};
|
|
659
1047
|
};
|
|
1048
|
+
const recordEntryReceipt = (reply, recovering = false) => {
|
|
1049
|
+
// K6:带成交入口的报价正式发出(message_sent 已落账)→ 上报“商家已
|
|
1050
|
+
// 提供入口”(可早于协议,按报价引用关联)。预置公开链接与被拒绝审批
|
|
1051
|
+
// 不触发——本函数只在正式报价发布路径上调用。上报失败不影响报价。
|
|
1052
|
+
if (options.commerceReceipts !== undefined && ["offer", "counter_offer", "conditional_offer"].includes(reply.action)) {
|
|
1053
|
+
const payload = reply.payload;
|
|
1054
|
+
const termsPayload = payload.terms ?? payload.proposed_terms ?? payload.base_terms;
|
|
1055
|
+
if (termsPayload !== undefined && termsPayload.handoff_destination !== undefined) {
|
|
1056
|
+
const entry = {
|
|
1057
|
+
event_id: `merchant-entry:${reply.message_id}`,
|
|
1058
|
+
event_type: "merchant_entry_offered",
|
|
1059
|
+
merchant_id: options.commerceReceipts.merchantId,
|
|
1060
|
+
entry_type: "quote_handoff",
|
|
1061
|
+
quote_ref: {
|
|
1062
|
+
negotiation_id: reply.negotiation_id,
|
|
1063
|
+
offer_id: String(reply.payload.offer_id ?? ""),
|
|
1064
|
+
terms_digest: contentDigest(termsPayload),
|
|
1065
|
+
},
|
|
1066
|
+
occurred_at: reply.created_at,
|
|
1067
|
+
};
|
|
1068
|
+
if (recovering)
|
|
1069
|
+
options.commerceReceipts.dispatcher.record(entry);
|
|
1070
|
+
else
|
|
1071
|
+
void options.commerceReceipts.dispatcher.enqueueAndDeliver(entry).catch(() => { });
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
660
1075
|
const appendSent = async (reply, snapshot) => {
|
|
661
1076
|
await ledger.append({
|
|
662
1077
|
event_kind: "message_sent",
|
|
@@ -680,6 +1095,7 @@ export function createMerchantHandler(options) {
|
|
|
680
1095
|
});
|
|
681
1096
|
if (snapshot !== undefined)
|
|
682
1097
|
quoteSources.set(reply.negotiation_id, { offer_id: String(reply.payload.offer_id), snapshot });
|
|
1098
|
+
recordEntryReceipt(reply);
|
|
683
1099
|
if (["offer", "counter_offer", "conditional_offer"].includes(reply.action)) {
|
|
684
1100
|
activeObjectByNegotiation.set(reply.negotiation_id, {
|
|
685
1101
|
offerId: String(reply.payload.offer_id),
|
|
@@ -784,6 +1200,67 @@ export function createMerchantHandler(options) {
|
|
|
784
1200
|
}
|
|
785
1201
|
return {
|
|
786
1202
|
name: "kiwi-agent-serve-merchant",
|
|
1203
|
+
resolveAlipayCollection(input) {
|
|
1204
|
+
if (options.alipayCollection === undefined || !alipayBuyerIdentity(input.buyerPrincipalId) || input.agreementId === "")
|
|
1205
|
+
return undefined;
|
|
1206
|
+
try {
|
|
1207
|
+
// Disk is authoritative: the in-memory phase may already be advanced if
|
|
1208
|
+
// the transition append failed after agreement_issued was persisted.
|
|
1209
|
+
const events = ledger.events(input.negotiationId);
|
|
1210
|
+
if (!ledger.verifyChain(input.negotiationId).valid)
|
|
1211
|
+
return undefined;
|
|
1212
|
+
const phaseEvent = [...events].reverse().find((event) => event.state_transition !== undefined);
|
|
1213
|
+
const samePrincipals = (event) => event.identity.actor === "merchant" &&
|
|
1214
|
+
event.identity.sender_identity === sender && event.identity.counterparty_identity === input.buyerPrincipalId;
|
|
1215
|
+
if (phaseEvent?.state_transition?.to_phase !== "AGREEMENT_REACHED" ||
|
|
1216
|
+
phaseEvent.state_transition.from_phase !== "OFFER_OPEN" || !samePrincipals(phaseEvent))
|
|
1217
|
+
return undefined;
|
|
1218
|
+
const evidence = findAgreementEvidence(input.negotiationId, input.offerId, input.termsDigest, events.slice(0, events.indexOf(phaseEvent)).filter((event) => samePrincipals(event) &&
|
|
1219
|
+
event.agreement_id === input.agreementId && event.terms_digest === input.termsDigest));
|
|
1220
|
+
const artifact = evidence?.agreement;
|
|
1221
|
+
if (evidence?.buyer_binding !== input.buyerPrincipalId || artifact === undefined ||
|
|
1222
|
+
artifact.agreement_id !== input.agreementId || artifact.negotiation_id !== input.negotiationId ||
|
|
1223
|
+
artifact.accepted_offer_id !== input.offerId)
|
|
1224
|
+
return undefined;
|
|
1225
|
+
const terms = artifact.agreed_terms;
|
|
1226
|
+
if (terms === null || typeof terms !== "object" || Array.isArray(terms) ||
|
|
1227
|
+
contentDigest(terms) !== input.termsDigest ||
|
|
1228
|
+
artifact.handoff_destination !== terms.handoff_destination)
|
|
1229
|
+
return undefined;
|
|
1230
|
+
const collection = collectionForTerms(terms, input.negotiationId, input.offerId);
|
|
1231
|
+
return collection?.version === input.version ? collection : undefined;
|
|
1232
|
+
}
|
|
1233
|
+
catch {
|
|
1234
|
+
return undefined;
|
|
1235
|
+
}
|
|
1236
|
+
},
|
|
1237
|
+
async recoverAccept(ctx) {
|
|
1238
|
+
if (ctx.envelope.action !== "accept_nonbinding" || ctx.identityVerified !== true)
|
|
1239
|
+
return undefined;
|
|
1240
|
+
const { negotiation_id, message_id, digest } = ctx.envelope;
|
|
1241
|
+
const payload = ctx.envelope.payload;
|
|
1242
|
+
const evidence = findAgreementEvidence(negotiation_id, payload.offer_id, payload.terms_digest);
|
|
1243
|
+
if (evidence === undefined || evidence.buyer_binding !== ctx.senderIdentity ||
|
|
1244
|
+
evidence.accept_message_id !== message_id || evidence.accept_wire_digest !== digest)
|
|
1245
|
+
return undefined;
|
|
1246
|
+
syncPhaseFromLedger(negotiation_id);
|
|
1247
|
+
const phase = phaseStateByNegotiation.get(negotiation_id)?.phase;
|
|
1248
|
+
if (phase === "OFFER_OPEN") {
|
|
1249
|
+
const terms = evidence.agreement.agreed_terms;
|
|
1250
|
+
if (terms?.kiwi_alipay_collection !== undefined &&
|
|
1251
|
+
(!alipayBuyerIdentity(ctx.senderIdentity) || collectionForTerms(terms, negotiation_id, payload.offer_id) === undefined)) {
|
|
1252
|
+
return undefined;
|
|
1253
|
+
}
|
|
1254
|
+
boundPeers.set(negotiation_id, ctx.senderIdentity);
|
|
1255
|
+
await appendPhaseTransition(negotiation_id, "AGREEMENT_REACHED", phase);
|
|
1256
|
+
}
|
|
1257
|
+
else if (phase !== "AGREEMENT_REACHED") {
|
|
1258
|
+
return undefined;
|
|
1259
|
+
}
|
|
1260
|
+
recordAgreementReceipt(negotiation_id, evidence.agreement, evidence.buyer_binding);
|
|
1261
|
+
return replayedAgreementResult(evidence.agreement);
|
|
1262
|
+
},
|
|
1263
|
+
recoverReceipts,
|
|
787
1264
|
async handle(ctx) {
|
|
788
1265
|
return serialize(ctx.envelope.negotiation_id, async () => {
|
|
789
1266
|
const envelope = ctx.envelope;
|
|
@@ -809,6 +1286,17 @@ export function createMerchantHandler(options) {
|
|
|
809
1286
|
if (COMMERCIAL_ACTIONS.has(envelope.action) &&
|
|
810
1287
|
(closedNegotiations.has(negotiationId) ||
|
|
811
1288
|
(syncedPhase !== undefined && isTerminalPhase(syncedPhase)))) {
|
|
1289
|
+
// K4:accept 重放是幂等恢复不是重开——预写证据命中(同 offer、同摘要)
|
|
1290
|
+
// 时按原商家协议号与摘要返回原协议;无证据(历史窗口/伪造重放)仍拒绝。
|
|
1291
|
+
if (envelope.action === "accept_nonbinding" && syncedPhase === "AGREEMENT_REACHED") {
|
|
1292
|
+
const payload = envelope.payload;
|
|
1293
|
+
const evidence = findAgreementEvidence(negotiationId, typeof payload.offer_id === "string" ? payload.offer_id : "", typeof payload.terms_digest === "string" ? payload.terms_digest : "");
|
|
1294
|
+
if (evidence !== undefined && (evidence.buyer_binding === "" ||
|
|
1295
|
+
(ctx.identityVerified === true && evidence.buyer_binding === ctx.senderIdentity))) {
|
|
1296
|
+
recordAgreementReceipt(negotiationId, evidence.agreement, evidence.buyer_binding);
|
|
1297
|
+
return replayedAgreementResult(evidence.agreement);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
812
1300
|
return declineReply("state_conflict");
|
|
813
1301
|
}
|
|
814
1302
|
if ((envelope.action === "withdraw" || envelope.action === "decline") &&
|
|
@@ -990,6 +1478,14 @@ export function createMerchantHandler(options) {
|
|
|
990
1478
|
}
|
|
991
1479
|
// P0a:inquiry 与普通 A2A 文本统一走接待引擎——结构化 SKU 是协议
|
|
992
1480
|
// 数据(权威),自由文本只是补充;引擎故障回退既有确定性路径。
|
|
1481
|
+
// K2:带历史查询扩展的 inquiry 先走授权历史查询(未委托/未验签/
|
|
1482
|
+
// 扩展不支持时返回 undefined → 走原接待路径)。
|
|
1483
|
+
const historyReply = await resolveQuoteHistoryReply(ctx);
|
|
1484
|
+
if (historyReply !== undefined)
|
|
1485
|
+
return historyReply;
|
|
1486
|
+
if (parseHistoryQueryExtension(ctx.envelope.payload.subject) !== undefined) {
|
|
1487
|
+
return textReply("历史报价不可用,请提供商品规格后继续询价。");
|
|
1488
|
+
}
|
|
993
1489
|
if (options.reception !== undefined) {
|
|
994
1490
|
try {
|
|
995
1491
|
const received = await options.reception.engine.respond({
|
|
@@ -1011,9 +1507,25 @@ export function createMerchantHandler(options) {
|
|
|
1011
1507
|
}
|
|
1012
1508
|
: {}),
|
|
1013
1509
|
});
|
|
1014
|
-
|
|
1510
|
+
// K1:接待引擎判定为有效询价后才建档(空文本/无关消息的澄清
|
|
1511
|
+
// 不建档)。结构化 inquiry(带 sku)由引擎判 recognizedInquiry。
|
|
1512
|
+
if (received.recognizedInquiry) {
|
|
1513
|
+
const registered = await registerVerifiedCustomerIdentity(ctx, "inquiry");
|
|
1514
|
+
await applyDelegationFromMetadata(ctx, registered?.subject_id);
|
|
1515
|
+
}
|
|
1516
|
+
const history = options.quoteHistory?.store;
|
|
1517
|
+
const merchantId = options.customerIdentity?.merchantId;
|
|
1518
|
+
const historyNote = history !== undefined && merchantId !== undefined &&
|
|
1519
|
+
ctx.identityVerified === true && isOpenInquiryIdentity(ctx.senderIdentity) &&
|
|
1520
|
+
isQuoteHistoryRecall(buyerMessage ?? "")
|
|
1521
|
+
? quoteHistoryNote(history, { merchantId, actor: ctx.senderIdentity, sku: structuredSku })
|
|
1522
|
+
: "";
|
|
1523
|
+
return textReply(received.text + historyNote);
|
|
1015
1524
|
}
|
|
1016
|
-
catch {
|
|
1525
|
+
catch (error) {
|
|
1526
|
+
if (error instanceof StreamGateError) {
|
|
1527
|
+
return { kind: "error", protocolCode: "temporarily_unavailable", message: "reception stream busy" };
|
|
1528
|
+
}
|
|
1017
1529
|
// 接待引擎不可用:回退确定性组装(下述既有路径)。
|
|
1018
1530
|
}
|
|
1019
1531
|
}
|
|
@@ -1126,7 +1638,7 @@ export function createMerchantHandler(options) {
|
|
|
1126
1638
|
const product = resolved.product;
|
|
1127
1639
|
const { priceMinor, currency } = product;
|
|
1128
1640
|
if (unitMismatch(product.unit, requestedUnit, unitPolicy))
|
|
1129
|
-
return
|
|
1641
|
+
return unitDecline(product.unit);
|
|
1130
1642
|
const handoff_destination = product.stock === undefined || product.source_evidence === undefined ? undefined : product.handoff_destination;
|
|
1131
1643
|
if (factsUnusable(product, quantity))
|
|
1132
1644
|
return declineReply("temporarily_unavailable");
|
|
@@ -1154,9 +1666,15 @@ export function createMerchantHandler(options) {
|
|
|
1154
1666
|
})
|
|
1155
1667
|
: undefined;
|
|
1156
1668
|
const quoteNote = quoteMessage(product);
|
|
1669
|
+
const projection = readProcurementProjection(payload.requested_terms);
|
|
1670
|
+
const companyFacts = projection ? options.procurementFacts?.(sku) : undefined;
|
|
1671
|
+
const arrival = deliveryBefore();
|
|
1672
|
+
const companyTerms = merchantProcurementTerms(companyFacts, projection, { price: effectivePriceMinor, currency,
|
|
1673
|
+
quantity, unit: requestedUnit, arrival, stock: sourceConfirmed ? product.stock : undefined });
|
|
1674
|
+
const procurement = projection ? { projection, facts_digest: contentDigest(companyFacts ?? null), arrival } : undefined;
|
|
1157
1675
|
// 买家在 RFQ 里声明了到货时限时必须逐条回应,不能只回价格。
|
|
1158
1676
|
const language = replyLanguageOf(envelope.public_message, buyerMessage);
|
|
1159
|
-
const deliveryNote = deliveryCommitmentNote(requestedDeliveryBeforeOf(envelope.payload),
|
|
1677
|
+
const deliveryNote = deliveryCommitmentNote(requestedDeliveryBeforeOf(envelope.payload), arrival, language);
|
|
1160
1678
|
const publicMessage = [advisedMessage, quoteNote.public_message, deliveryNote]
|
|
1161
1679
|
.filter((part) => part !== undefined && part.trim() !== "")
|
|
1162
1680
|
.join(" ") || undefined;
|
|
@@ -1169,16 +1687,16 @@ export function createMerchantHandler(options) {
|
|
|
1169
1687
|
payload: {
|
|
1170
1688
|
type: "offer",
|
|
1171
1689
|
offer_id: newOfferId(),
|
|
1172
|
-
terms: offerTerms({
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1690
|
+
terms: { ...offerTerms({
|
|
1691
|
+
sku,
|
|
1692
|
+
unit: requestedUnit,
|
|
1693
|
+
priceMinor: effectivePriceMinor,
|
|
1694
|
+
quantity,
|
|
1695
|
+
currency,
|
|
1696
|
+
handoff_destination,
|
|
1697
|
+
deliveryBefore: arrival,
|
|
1698
|
+
...quoteValidity(product, promotion.kind === "applied" ? promotion.endsAt : undefined),
|
|
1699
|
+
}, now()), ...companyTerms },
|
|
1182
1700
|
},
|
|
1183
1701
|
...(publicMessage !== undefined ? { public_message: publicMessage } : {}),
|
|
1184
1702
|
});
|
|
@@ -1199,7 +1717,10 @@ export function createMerchantHandler(options) {
|
|
|
1199
1717
|
// stored.conditional.offer_id 与 accept 的 offer_id 强匹配(A314
|
|
1200
1718
|
// 源码核:原返修缺 offer_id,直报价接受仍 offer_unknown)。
|
|
1201
1719
|
conditionalByNegotiation.set(negotiationId, normalizeDirectOfferAsConditional(String(reply.payload.offer_id ?? ""), reply.payload.terms ?? {}, quantity));
|
|
1202
|
-
await appendSent(reply, snapshotFor(sku, quantity, product, promotion));
|
|
1720
|
+
await appendSent(reply, { ...snapshotFor(sku, quantity, product, promotion), ...(procurement ? { procurement } : {}) });
|
|
1721
|
+
const registeredSubject = await registerVerifiedCustomerIdentity(ctx, "rfq");
|
|
1722
|
+
await applyDelegationFromMetadata(ctx, registeredSubject?.subject_id);
|
|
1723
|
+
await indexHistoryOffer(ctx, reply, product);
|
|
1203
1724
|
return envelopeReply(reply);
|
|
1204
1725
|
}
|
|
1205
1726
|
case "offer": {
|
|
@@ -1220,7 +1741,7 @@ export function createMerchantHandler(options) {
|
|
|
1220
1741
|
const product = resolved.product;
|
|
1221
1742
|
const { priceMinor, currency } = product;
|
|
1222
1743
|
if (unitMismatch(product.unit, requestedUnit, unitPolicy))
|
|
1223
|
-
return
|
|
1744
|
+
return unitDecline(product.unit);
|
|
1224
1745
|
const handoff_destination = product.stock === undefined || product.source_evidence === undefined ? undefined : product.handoff_destination;
|
|
1225
1746
|
if (factsUnusable(product, quantity))
|
|
1226
1747
|
return declineReply("temporarily_unavailable");
|
|
@@ -1280,6 +1801,7 @@ export function createMerchantHandler(options) {
|
|
|
1280
1801
|
// review 2-3:还价(counter_offer)同样登记——买家接受直还价走通主路径。
|
|
1281
1802
|
conditionalByNegotiation.set(negotiationId, normalizeDirectOfferAsConditional(String(reply.payload.offer_id ?? ""), reply.payload.proposed_terms ?? {}, quantity));
|
|
1282
1803
|
await appendSent(reply, snapshotFor(sku, quantity, product, promotion));
|
|
1804
|
+
await indexHistoryOffer(ctx, reply, product);
|
|
1283
1805
|
return envelopeReply(reply);
|
|
1284
1806
|
}
|
|
1285
1807
|
case "counter_offer": {
|
|
@@ -1291,6 +1813,11 @@ export function createMerchantHandler(options) {
|
|
|
1291
1813
|
return declineReply("schema_invalid");
|
|
1292
1814
|
const quantity = quantityRaw;
|
|
1293
1815
|
const buyerCounterMinor = counter.proposed_terms?.items?.[0]?.unit_price?.amount_minor;
|
|
1816
|
+
const companyPriceBasis = counter.proposed_terms?.items?.[0]?.unit_price?.basis;
|
|
1817
|
+
if (companyPriceBasis !== undefined && (typeof sku !== "string" ||
|
|
1818
|
+
!quoteSources.get(negotiationId)?.snapshot.procurement ||
|
|
1819
|
+
options.procurementFacts?.(sku)?.native_basis !== companyPriceBasis))
|
|
1820
|
+
return declineReply("schema_invalid");
|
|
1294
1821
|
const floorMinor = floorMinorForSku(sku);
|
|
1295
1822
|
if (floorMinor === null)
|
|
1296
1823
|
return declineReply("temporarily_unavailable");
|
|
@@ -1300,7 +1827,7 @@ export function createMerchantHandler(options) {
|
|
|
1300
1827
|
const product = resolved.product;
|
|
1301
1828
|
const { priceMinor, currency } = product;
|
|
1302
1829
|
if (unitMismatch(product.unit, requestedUnit, unitPolicy))
|
|
1303
|
-
return
|
|
1830
|
+
return unitDecline(product.unit);
|
|
1304
1831
|
const handoff_destination = product.stock === undefined || product.source_evidence === undefined ? undefined : product.handoff_destination;
|
|
1305
1832
|
if (factsUnusable(product, quantity))
|
|
1306
1833
|
return declineReply("temporarily_unavailable");
|
|
@@ -1332,17 +1859,38 @@ export function createMerchantHandler(options) {
|
|
|
1332
1859
|
typeof buyerCounterMinor === "number" &&
|
|
1333
1860
|
Number.isFinite(buyerCounterMinor) &&
|
|
1334
1861
|
buyerCounterMinor < publicBoundMinor;
|
|
1335
|
-
// B2
|
|
1336
|
-
//
|
|
1337
|
-
|
|
1338
|
-
|
|
1862
|
+
// B2:只在需要人工审核的区间尝试消费授权。已签名买家重试同一还价时,
|
|
1863
|
+
// 在队列锁内处理等待/终态/消费,避免重排队或覆盖刚批准的授权。
|
|
1864
|
+
let approved;
|
|
1865
|
+
if (belowPublicBound || policyResponsiveMinorFinal < floorMinor) {
|
|
1866
|
+
const approvals = options.negotiationApprovals;
|
|
1867
|
+
const input = {
|
|
1339
1868
|
negotiation_id: negotiationId,
|
|
1340
|
-
sku,
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1869
|
+
sku, currency, quantity, unit: requestedUnit,
|
|
1870
|
+
buyer_offer_minor: buyerCounterMinor ?? priceMinor,
|
|
1871
|
+
public_bound_minor: publicBoundMinor,
|
|
1872
|
+
floor_minor: floorMinor,
|
|
1873
|
+
buyer_message_id: envelope.message_id,
|
|
1874
|
+
};
|
|
1875
|
+
const pendingMessage = "offer is below the merchant's automatic discount boundary; a merchant approval request has been recorded — retry after approval";
|
|
1876
|
+
if (approvals !== undefined && ctx.identityVerified === true && alipayBuyerIdentity(ctx.senderIdentity)) {
|
|
1877
|
+
const review = approvals.reviewSignedCounter(input);
|
|
1878
|
+
if (review.status !== "approved") {
|
|
1879
|
+
return {
|
|
1880
|
+
kind: "declined", taskState: "completed", reasonCode: "approval_required", approvalStatus: review.status,
|
|
1881
|
+
message: review.status === "pending" ? pendingMessage : `merchant approval is ${review.status}; start a new negotiation if needed`,
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
approved = review.record;
|
|
1885
|
+
}
|
|
1886
|
+
else {
|
|
1887
|
+
approved = approvals?.consume(input);
|
|
1888
|
+
if (approved?.approved_minor === undefined) {
|
|
1889
|
+
approvals?.recordPending(input);
|
|
1890
|
+
return declineReply("approval_required", approvals === undefined ? undefined : pendingMessage);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1346
1894
|
const authorizedMinor = approved?.approved_minor;
|
|
1347
1895
|
// 批准价是商家可接受的下限,但不能低于买家本轮已经愿意出的价。
|
|
1348
1896
|
// 注意 buyerCounter 已被 clamp 到公开边界,不能拿它做 max——否则
|
|
@@ -1355,27 +1903,6 @@ export function createMerchantHandler(options) {
|
|
|
1355
1903
|
? Math.min(priceMinor, Math.max(authorizedMinor, buyerOfferMinor))
|
|
1356
1904
|
: authorizedMinor
|
|
1357
1905
|
: policyResponsiveMinorFinal;
|
|
1358
|
-
if (authorizedMinor === undefined &&
|
|
1359
|
-
(belowPublicBound || responsiveMinor < floorMinor)) {
|
|
1360
|
-
// 公开边界低于私有底价:该区间不能自动报价。登记到商家审批队列,
|
|
1361
|
-
// 人工批准后买家下一轮还价可命中一次性授权价;本轮不返回价格。
|
|
1362
|
-
options.negotiationApprovals?.recordPending({
|
|
1363
|
-
negotiation_id: negotiationId,
|
|
1364
|
-
sku,
|
|
1365
|
-
currency,
|
|
1366
|
-
quantity,
|
|
1367
|
-
unit: requestedUnit,
|
|
1368
|
-
buyer_offer_minor: typeof buyerCounterMinor === "number" && Number.isFinite(buyerCounterMinor)
|
|
1369
|
-
? buyerCounterMinor
|
|
1370
|
-
: priceMinor,
|
|
1371
|
-
public_bound_minor: publicBoundMinor,
|
|
1372
|
-
floor_minor: floorMinor,
|
|
1373
|
-
...(typeof envelope.message_id === "string"
|
|
1374
|
-
? { buyer_message_id: envelope.message_id }
|
|
1375
|
-
: {}),
|
|
1376
|
-
});
|
|
1377
|
-
return declineReply("approval_required", "offer is below the merchant's automatic discount boundary; a merchant approval request has been recorded — retry after approval");
|
|
1378
|
-
}
|
|
1379
1906
|
// 可配置促销(merchant_policy.promos[sku]):买满 bulk_threshold 台,
|
|
1380
1907
|
// 批量价 = min(还价响应, list×(1-d%/100)),同样 clamp 到公开边界;
|
|
1381
1908
|
// 若该价低于私有底价则**不挂这条条件**(不广告无法兑现的价)。
|
|
@@ -1430,30 +1957,65 @@ export function createMerchantHandler(options) {
|
|
|
1430
1957
|
]
|
|
1431
1958
|
.filter((part) => part !== undefined && part.trim() !== "")
|
|
1432
1959
|
.join(" ") || undefined;
|
|
1960
|
+
const procurementProjection = quoteSources.get(negotiationId)?.snapshot.procurement?.projection;
|
|
1961
|
+
const companyFacts = procurementProjection ? options.procurementFacts?.(sku) : undefined;
|
|
1962
|
+
const arrival = deliveryBefore();
|
|
1963
|
+
const procurement = procurementProjection ? { projection: procurementProjection, facts_digest: contentDigest(companyFacts ?? null), arrival } : undefined;
|
|
1964
|
+
const companyTerms = (quotePrice) => merchantProcurementTerms(companyFacts, procurementProjection, {
|
|
1965
|
+
price: quotePrice, currency, quantity, unit: requestedUnit, arrival,
|
|
1966
|
+
stock: product.source_evidence !== undefined ? product.stock : undefined,
|
|
1967
|
+
});
|
|
1968
|
+
const offerId = newOfferId();
|
|
1969
|
+
const quoteTime = now();
|
|
1970
|
+
const baseTerms = { ...offerTerms({
|
|
1971
|
+
sku,
|
|
1972
|
+
unit: requestedUnit,
|
|
1973
|
+
priceMinor: responsiveMinor,
|
|
1974
|
+
quantity,
|
|
1975
|
+
currency,
|
|
1976
|
+
handoff_destination,
|
|
1977
|
+
deliveryBefore: arrival,
|
|
1978
|
+
...quoteValidity(product, authorityPromotion.kind === "applied" ? authorityPromotion.endsAt : undefined),
|
|
1979
|
+
}, quoteTime), ...companyTerms(responsiveMinor) };
|
|
1980
|
+
const explicitTotal = approved?.alipay_total_minor;
|
|
1981
|
+
const alipay = ctx.identityVerified === true && alipayBuyerIdentity(ctx.senderIdentity) &&
|
|
1982
|
+
product.handoff_destination === undefined && product.stock !== undefined && product.source_evidence !== undefined &&
|
|
1983
|
+
currency === "CNY" && approved?.buyer_offer_minor === buyerOfferMinor &&
|
|
1984
|
+
authorizedMinor === responsiveMinor && positiveMinorAmount(explicitTotal) &&
|
|
1985
|
+
// This is a consistency check, not a source of the payable total.
|
|
1986
|
+
BigInt(explicitTotal) >= BigInt(responsiveMinor) * BigInt(quantity)
|
|
1987
|
+
? currentAlipay()
|
|
1988
|
+
: undefined;
|
|
1989
|
+
const destination = alipay === undefined ? undefined : alipayRoute(alipay.origin, negotiationId, offerId, alipay.version);
|
|
1990
|
+
const collectionExpiry = Math.min(Date.parse(baseTerms.valid_until), Date.parse(approved?.expires_at ?? ""));
|
|
1991
|
+
const bindCollection = alipay !== undefined && destination !== undefined && explicitTotal !== undefined &&
|
|
1992
|
+
collectionExpiry > Date.parse(quoteTime);
|
|
1993
|
+
const finalTerms = bindCollection ? {
|
|
1994
|
+
...baseTerms,
|
|
1995
|
+
handoff_destination: destination,
|
|
1996
|
+
valid_until: new Date(collectionExpiry).toISOString(),
|
|
1997
|
+
kiwi_alipay_collection: {
|
|
1998
|
+
version: alipay.version,
|
|
1999
|
+
recipient_summary: alipay.summary,
|
|
2000
|
+
total_minor: explicitTotal,
|
|
2001
|
+
currency: "CNY",
|
|
2002
|
+
expires_at: new Date(collectionExpiry).toISOString(),
|
|
2003
|
+
},
|
|
2004
|
+
} : baseTerms;
|
|
1433
2005
|
const reply = seedEnvelope({
|
|
1434
2006
|
negotiation_id: negotiationId,
|
|
1435
2007
|
in_reply_to: inReplyTo,
|
|
1436
2008
|
actor: "merchant",
|
|
1437
2009
|
action: "conditional_offer",
|
|
1438
|
-
created_at:
|
|
2010
|
+
created_at: quoteTime,
|
|
1439
2011
|
payload: {
|
|
1440
2012
|
type: "conditional_offer",
|
|
1441
|
-
offer_id:
|
|
2013
|
+
offer_id: offerId,
|
|
1442
2014
|
responding_to_offer_id: counter.offer_id,
|
|
1443
2015
|
// 许可绑定(T047):本次报价依据的规则摘要与商品事实指纹;accept 时重验。
|
|
1444
2016
|
policy_digest: policyDigest(),
|
|
1445
2017
|
product_fingerprint: productFingerprint({ sku, priceMinor, currency }),
|
|
1446
|
-
|
|
1447
|
-
base_terms: offerTerms({
|
|
1448
|
-
sku,
|
|
1449
|
-
unit: requestedUnit,
|
|
1450
|
-
priceMinor: responsiveMinor,
|
|
1451
|
-
quantity,
|
|
1452
|
-
currency,
|
|
1453
|
-
handoff_destination,
|
|
1454
|
-
deliveryBefore: deliveryBefore(),
|
|
1455
|
-
...quoteValidity(product, authorityPromotion.kind === "applied" ? authorityPromotion.endsAt : undefined),
|
|
1456
|
-
}, now()),
|
|
2018
|
+
base_terms: finalTerms,
|
|
1457
2019
|
// conditions 可空(§13:空 conditions 等价 base_terms)。促销价低于
|
|
1458
2020
|
// 私有底价时不挂条件——不广告无法兑现的价,也不借 then_terms 泄露底价。
|
|
1459
2021
|
conditions: promotionalMinor !== undefined
|
|
@@ -1464,16 +2026,16 @@ export function createMerchantHandler(options) {
|
|
|
1464
2026
|
{ field: "aggregate.total_quantity", op: "gte", value: bulkThreshold },
|
|
1465
2027
|
],
|
|
1466
2028
|
},
|
|
1467
|
-
then_terms: offerTerms({
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
2029
|
+
then_terms: { ...offerTerms({
|
|
2030
|
+
sku,
|
|
2031
|
+
unit: requestedUnit,
|
|
2032
|
+
priceMinor: promotionalMinor,
|
|
2033
|
+
quantity,
|
|
2034
|
+
currency,
|
|
2035
|
+
handoff_destination,
|
|
2036
|
+
deliveryBefore: arrival,
|
|
2037
|
+
...quoteValidity(product, authorityPromotion.kind === "applied" ? authorityPromotion.endsAt : undefined),
|
|
2038
|
+
}, now()), ...companyTerms(promotionalMinor) },
|
|
1477
2039
|
},
|
|
1478
2040
|
]
|
|
1479
2041
|
: [],
|
|
@@ -1493,7 +2055,8 @@ export function createMerchantHandler(options) {
|
|
|
1493
2055
|
});
|
|
1494
2056
|
if (!advanced)
|
|
1495
2057
|
return declineReply("state_conflict");
|
|
1496
|
-
await appendSent(reply, snapshotFor(sku, quantity, product, authorityPromotion));
|
|
2058
|
+
await appendSent(reply, { ...snapshotFor(sku, quantity, product, authorityPromotion), ...(procurement ? { procurement } : {}) });
|
|
2059
|
+
await indexHistoryOffer(ctx, reply, product);
|
|
1497
2060
|
return envelopeReply(reply);
|
|
1498
2061
|
}
|
|
1499
2062
|
case "clarification": {
|
|
@@ -1671,6 +2234,11 @@ export function createMerchantHandler(options) {
|
|
|
1671
2234
|
return declineReply("approval_required");
|
|
1672
2235
|
if (!quoteFactsStillValid(saved.snapshot, refreshedFacts.product, Date.parse(now())))
|
|
1673
2236
|
return declineReply("approval_required");
|
|
2237
|
+
if (saved.snapshot.procurement) {
|
|
2238
|
+
const currentFacts = options.procurementFacts?.(saved.snapshot.sku);
|
|
2239
|
+
if (saved.snapshot.procurement.facts_digest !== contentDigest(currentFacts ?? null))
|
|
2240
|
+
return declineReply("approval_required");
|
|
2241
|
+
}
|
|
1674
2242
|
if (saved.snapshot.policy_digest !== policyDigest())
|
|
1675
2243
|
return declineReply("approval_required");
|
|
1676
2244
|
const currentFloor = floorMinorForSku(saved.snapshot.sku);
|
|
@@ -1700,24 +2268,46 @@ export function createMerchantHandler(options) {
|
|
|
1700
2268
|
}
|
|
1701
2269
|
// 审查 P1-C:相位机是权威守卫——§15 校验通过后、构建协议之前先
|
|
1702
2270
|
// 推进相位并检查返回值(BUG-10 语义不变:被拒的 accept 不得进入
|
|
1703
|
-
// AGREEMENT_REACHED
|
|
1704
|
-
//
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
2271
|
+
// AGREEMENT_REACHED)。accept 的唯一合法来源相位是 OFFER_OPEN,
|
|
2272
|
+
// 先判相位:拒绝路径不产生任何协议证据(无终态副作用)。
|
|
2273
|
+
const phaseBeforeAccept = phaseStateByNegotiation.get(negotiationId)?.phase ?? "OPEN";
|
|
2274
|
+
if (phaseBeforeAccept !== "OFFER_OPEN") {
|
|
2275
|
+
return declineReply("state_conflict");
|
|
2276
|
+
}
|
|
2277
|
+
// K4:预写证据补齐——先复用/生成协议,落账证据,再推进相位。
|
|
2278
|
+
// 任一中断点重试都复用同一商家协议号与摘要(B6)。
|
|
2279
|
+
if (agreedTerms.kiwi_alipay_collection !== undefined &&
|
|
2280
|
+
(ctx.identityVerified !== true || !alipayBuyerIdentity(ctx.senderIdentity) ||
|
|
2281
|
+
collectionForTerms(agreedTerms, negotiationId, acceptedOfferId) === undefined)) {
|
|
2282
|
+
return declineReply("approval_required");
|
|
2283
|
+
}
|
|
2284
|
+
const priorEvidence = findAgreementEvidence(negotiationId, acceptedOfferId, presentedDigest);
|
|
2285
|
+
const agreement = priorEvidence?.agreement ??
|
|
2286
|
+
buildAgreement({
|
|
2287
|
+
negotiation_id: negotiationId,
|
|
2288
|
+
accepted_offer_id: acceptedOfferId,
|
|
2289
|
+
agreed_terms: agreedTerms,
|
|
2290
|
+
created_at: now(),
|
|
2291
|
+
});
|
|
2292
|
+
if (priorEvidence === undefined) {
|
|
2293
|
+
await appendAgreementEvidence({
|
|
2294
|
+
negotiationId,
|
|
2295
|
+
agreement,
|
|
2296
|
+
acceptedOfferId,
|
|
2297
|
+
buyerBinding: ctx.identityVerified === true ? ctx.senderIdentity : "",
|
|
2298
|
+
acceptMessageId: envelope.message_id,
|
|
2299
|
+
acceptWireDigest: envelope.digest,
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
1708
2302
|
const advanced = await advancePhase(negotiationId, {
|
|
1709
2303
|
type: "accept_nonbinding",
|
|
1710
2304
|
offer_id: acceptedOfferId,
|
|
1711
2305
|
});
|
|
1712
2306
|
if (!advanced) {
|
|
2307
|
+
// OFFER_OPEN 前置判定后推进不会失败;防御性兜底保持 fail-closed。
|
|
1713
2308
|
return declineReply("state_conflict");
|
|
1714
2309
|
}
|
|
1715
|
-
|
|
1716
|
-
negotiation_id: negotiationId,
|
|
1717
|
-
accepted_offer_id: acceptedOfferId,
|
|
1718
|
-
agreed_terms: agreedTerms,
|
|
1719
|
-
created_at: now(),
|
|
1720
|
-
});
|
|
2310
|
+
recordAgreementReceipt(negotiationId, agreement, ctx.identityVerified === true ? ctx.senderIdentity : "");
|
|
1721
2311
|
const artifactPart = { kind: "data", data: { agreement } };
|
|
1722
2312
|
const message = {
|
|
1723
2313
|
role: "agent",
|