@harrylabsj/kiwi 0.12.31 → 0.12.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/a2a/inquiry-nonce-store.d.ts +12 -1
- package/dist/a2a/inquiry-nonce-store.js +49 -17
- package/dist/a2a/inquiry-nonce-store.js.map +1 -1
- package/dist/a2a/negotiate.d.ts +30 -1
- package/dist/a2a/negotiate.js +121 -32
- package/dist/a2a/negotiate.js.map +1 -1
- package/dist/a2a/node.d.ts +4 -0
- package/dist/a2a/node.js +182 -4
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/open-inquiry-session.d.ts +1 -0
- package/dist/a2a/open-inquiry-session.js +3 -1
- package/dist/a2a/open-inquiry-session.js.map +1 -1
- package/dist/a2a/open-inquiry-verifier.js +2 -2
- package/dist/a2a/open-inquiry-verifier.js.map +1 -1
- package/dist/a2a/reception/agent-runtime.d.ts +32 -1
- package/dist/a2a/reception/agent-runtime.js +420 -11
- package/dist/a2a/reception/agent-runtime.js.map +1 -1
- package/dist/a2a/reception/customer-memory-tools.d.ts +73 -0
- package/dist/a2a/reception/customer-memory-tools.js +17 -0
- package/dist/a2a/reception/customer-memory-tools.js.map +1 -0
- package/dist/a2a/reception/engine.d.ts +12 -0
- package/dist/a2a/reception/engine.js +42 -1
- package/dist/a2a/reception/engine.js.map +1 -1
- package/dist/a2a/reception/publish.d.ts +14 -1
- package/dist/a2a/reception/publish.js +62 -1
- package/dist/a2a/reception/publish.js.map +1 -1
- package/dist/a2a/reception/question-spec.d.ts +91 -0
- package/dist/a2a/reception/question-spec.js +260 -0
- package/dist/a2a/reception/question-spec.js.map +1 -0
- package/dist/a2a/reception/reply-outbox.d.ts +6 -0
- package/dist/a2a/reception/reply-outbox.js +44 -0
- package/dist/a2a/reception/reply-outbox.js.map +1 -1
- package/dist/a2a/reception/responder.d.ts +13 -1
- package/dist/a2a/reception/responder.js +26 -3
- package/dist/a2a/reception/responder.js.map +1 -1
- package/dist/a2a/reception/skill-catalog.d.ts +72 -0
- package/dist/a2a/reception/skill-catalog.js +85 -0
- package/dist/a2a/reception/skill-catalog.js.map +1 -0
- package/dist/a2a/reception/skill-contract.d.ts +70 -0
- package/dist/a2a/reception/skill-contract.js +183 -0
- package/dist/a2a/reception/skill-contract.js.map +1 -0
- package/dist/a2a/reception/types.d.ts +12 -0
- package/dist/a2a/server/customer-identity-gateway.d.ts +111 -0
- package/dist/a2a/server/customer-identity-gateway.js +441 -0
- package/dist/a2a/server/customer-identity-gateway.js.map +1 -0
- package/dist/a2a/server/errors.d.ts +4 -3
- package/dist/a2a/server/errors.js +10 -2
- package/dist/a2a/server/errors.js.map +1 -1
- package/dist/a2a/server/merchant-handler.d.ts +75 -1
- package/dist/a2a/server/merchant-handler.js +676 -86
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/merchant-procurement.d.ts +90 -0
- package/dist/a2a/server/merchant-procurement.js +75 -0
- package/dist/a2a/server/merchant-procurement.js.map +1 -0
- package/dist/a2a/server/merchant-product-facts.d.ts +2 -0
- package/dist/a2a/server/merchant-product-facts.js.map +1 -1
- package/dist/a2a/server/negotiation-approvals.d.ts +11 -0
- package/dist/a2a/server/negotiation-approvals.js +43 -0
- package/dist/a2a/server/negotiation-approvals.js.map +1 -1
- package/dist/a2a/server/pipeline.js +78 -30
- package/dist/a2a/server/pipeline.js.map +1 -1
- package/dist/a2a/server/server.js +4 -3
- package/dist/a2a/server/server.js.map +1 -1
- package/dist/a2a/server/types.d.ts +4 -1
- package/dist/a2a/unit-alias.d.ts +3 -3
- package/dist/a2a/unit-alias.js +9 -5
- package/dist/a2a/unit-alias.js.map +1 -1
- package/dist/agent/alipay-native-view.d.ts +27 -0
- package/dist/agent/alipay-native-view.js +113 -0
- package/dist/agent/alipay-native-view.js.map +1 -0
- package/dist/agent/buyer/buyer-tools.d.ts +20 -0
- package/dist/agent/buyer/buyer-tools.js +241 -48
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/types.d.ts +1 -1
- package/dist/agent/buyer/types.js.map +1 -1
- package/dist/agent/chat-tui.js +16 -1
- package/dist/agent/chat-tui.js.map +1 -1
- package/dist/agent/kernel-builder.d.ts +2 -0
- package/dist/agent/kernel-builder.js +14 -0
- package/dist/agent/kernel-builder.js.map +1 -1
- package/dist/agent/kernel.d.ts +8 -0
- package/dist/agent/kernel.js +67 -1
- package/dist/agent/kernel.js.map +1 -1
- package/dist/auth/merchant-sessions.d.ts +3 -0
- package/dist/auth/merchant-sessions.js +21 -5
- package/dist/auth/merchant-sessions.js.map +1 -1
- package/dist/buyer-core/a2a-accept-terms.d.ts +11 -0
- package/dist/buyer-core/a2a-accept-terms.js +28 -0
- package/dist/buyer-core/a2a-accept-terms.js.map +1 -0
- package/dist/buyer-core/a2a-knp.d.ts +7 -2
- package/dist/buyer-core/a2a-knp.js +8 -5
- package/dist/buyer-core/a2a-knp.js.map +1 -1
- package/dist/buyer-core/a2a-negotiator.d.ts +17 -0
- package/dist/buyer-core/a2a-negotiator.js +70 -26
- package/dist/buyer-core/a2a-negotiator.js.map +1 -1
- package/dist/buyer-core/a2a-quote-fetcher.d.ts +25 -15
- package/dist/buyer-core/a2a-quote-fetcher.js +92 -19
- package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
- package/dist/buyer-core/a2a-quote-history.d.ts +94 -0
- package/dist/buyer-core/a2a-quote-history.js +149 -0
- package/dist/buyer-core/a2a-quote-history.js.map +1 -0
- package/dist/buyer-core/build-service.d.ts +19 -0
- package/dist/buyer-core/build-service.js +30 -1
- package/dist/buyer-core/build-service.js.map +1 -1
- package/dist/buyer-core/errors.d.ts +1 -1
- package/dist/buyer-core/errors.js +1 -0
- package/dist/buyer-core/errors.js.map +1 -1
- package/dist/buyer-core/merchant-index.d.ts +2 -2
- package/dist/buyer-core/merchant-index.js +23 -5
- package/dist/buyer-core/merchant-index.js.map +1 -1
- package/dist/buyer-core/open-inquiry-signer.d.ts +1 -0
- package/dist/buyer-core/open-inquiry-signer.js +5 -2
- package/dist/buyer-core/open-inquiry-signer.js.map +1 -1
- package/dist/buyer-core/procurement/cases.d.ts +441 -0
- package/dist/buyer-core/procurement/cases.js +457 -0
- package/dist/buyer-core/procurement/cases.js.map +1 -0
- package/dist/buyer-core/procurement/quote-comparison.d.ts +137 -0
- package/dist/buyer-core/procurement/quote-comparison.js +106 -0
- package/dist/buyer-core/procurement/quote-comparison.js.map +1 -0
- package/dist/buyer-core/procurement/quote-normalizer.d.ts +45 -0
- package/dist/buyer-core/procurement/quote-normalizer.js +153 -0
- package/dist/buyer-core/procurement/quote-normalizer.js.map +1 -0
- package/dist/buyer-core/procurement/requirements.d.ts +50 -0
- package/dist/buyer-core/procurement/requirements.js +43 -0
- package/dist/buyer-core/procurement/requirements.js.map +1 -0
- package/dist/buyer-core/procurement/source-observation.d.ts +57 -0
- package/dist/buyer-core/procurement/source-observation.js +54 -0
- package/dist/buyer-core/procurement/source-observation.js.map +1 -0
- package/dist/buyer-core/procurement/store.d.ts +21 -0
- package/dist/buyer-core/procurement/store.js +68 -0
- package/dist/buyer-core/procurement/store.js.map +1 -0
- package/dist/buyer-core/protocol-recovery.d.ts +10 -1
- package/dist/buyer-core/protocol-recovery.js +31 -6
- package/dist/buyer-core/protocol-recovery.js.map +1 -1
- package/dist/buyer-core/quote-quantity.d.ts +5 -0
- package/dist/buyer-core/quote-quantity.js +15 -0
- package/dist/buyer-core/quote-quantity.js.map +1 -0
- package/dist/buyer-core/service.d.ts +128 -8
- package/dist/buyer-core/service.js +543 -75
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/buyer-core/store.d.ts +21 -0
- package/dist/buyer-core/store.js +62 -10
- package/dist/buyer-core/store.js.map +1 -1
- package/dist/cli.js +26 -19
- package/dist/cli.js.map +1 -1
- package/dist/cloud/alipay-collection-http.d.ts +44 -0
- package/dist/cloud/alipay-collection-http.js +111 -0
- package/dist/cloud/alipay-collection-http.js.map +1 -0
- package/dist/cloud/bootstrap.js +218 -19
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/http-router.d.ts +2 -0
- package/dist/cloud/http-router.js +5 -0
- package/dist/cloud/http-router.js.map +1 -1
- package/dist/commerce/receipt/dispatcher.d.ts +43 -0
- package/dist/commerce/receipt/dispatcher.js +86 -0
- package/dist/commerce/receipt/dispatcher.js.map +1 -0
- package/dist/commerce/receipt/receipts.d.ts +147 -0
- package/dist/commerce/receipt/receipts.js +285 -0
- package/dist/commerce/receipt/receipts.js.map +1 -0
- package/dist/config/profile.d.ts +2 -2
- package/dist/discovery/catalog-source/buyer-follows.d.ts +3 -3
- package/dist/discovery/catalog-source/buyer-follows.js +6 -3
- package/dist/discovery/catalog-source/buyer-follows.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-record.d.ts +2 -0
- package/dist/discovery/catalog-source/kiwi-record.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.js +4 -0
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/handoff/alipay-collection.d.ts +23 -0
- package/dist/handoff/alipay-collection.js +70 -0
- package/dist/handoff/alipay-collection.js.map +1 -0
- package/dist/handoff/order-receipts.d.ts +62 -0
- package/dist/handoff/order-receipts.js +72 -0
- package/dist/handoff/order-receipts.js.map +1 -0
- package/dist/handoff/ucp-checkout/cart-channel.d.ts +2 -1
- package/dist/handoff/ucp-checkout/cart-channel.js +1 -0
- package/dist/handoff/ucp-checkout/cart-channel.js.map +1 -1
- package/dist/handoff/ucp-checkout/channel.d.ts +7 -0
- package/dist/handoff/ucp-checkout/channel.js +79 -10
- package/dist/handoff/ucp-checkout/channel.js.map +1 -1
- package/dist/http/cli.js +6 -0
- package/dist/http/cli.js.map +1 -1
- package/dist/http/merchant-management/api.d.ts +18 -0
- package/dist/http/merchant-management/api.js +752 -3
- package/dist/http/merchant-management/api.js.map +1 -1
- package/dist/http/merchant-management/draft-store.js +8 -6
- package/dist/http/merchant-management/draft-store.js.map +1 -1
- package/dist/http/merchant-management/page.d.ts +1 -0
- package/dist/http/merchant-management/page.js +335 -5
- package/dist/http/merchant-management/page.js.map +1 -1
- package/dist/http/server.js +9 -2
- package/dist/http/server.js.map +1 -1
- package/dist/mcp/cli.d.ts +3 -1
- package/dist/mcp/cli.js +18 -2
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/merchant-runtime-assembly.d.ts +20 -0
- package/dist/mcp/merchant-runtime-assembly.js +94 -11
- package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
- package/dist/mcp/merchant-server.d.ts +5 -0
- package/dist/mcp/merchant-server.js +12 -0
- package/dist/mcp/merchant-server.js.map +1 -1
- package/dist/mcp/procurement-tools.d.ts +10 -0
- package/dist/mcp/procurement-tools.js +173 -0
- package/dist/mcp/procurement-tools.js.map +1 -0
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.js +63 -9
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.d.ts +4 -1
- package/dist/mcp/tools.js +83 -28
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +1 -0
- package/dist/mcp/types.js.map +1 -1
- package/dist/merchant/application/actor.d.ts +3 -1
- package/dist/merchant/application/actor.js +21 -0
- package/dist/merchant/application/actor.js.map +1 -1
- package/dist/merchant/negotiation-ops.d.ts +2 -0
- package/dist/merchant/negotiation-ops.js +4 -0
- package/dist/merchant/negotiation-ops.js.map +1 -1
- package/dist/merchant/weixin-channel.d.ts +68 -0
- package/dist/merchant/weixin-channel.js +313 -0
- package/dist/merchant/weixin-channel.js.map +1 -0
- package/dist/merchant/workbench-server.d.ts +1 -0
- package/dist/merchant/workbench-server.js +189 -2
- package/dist/merchant/workbench-server.js.map +1 -1
- package/dist/merchant-core/budget/background-budget.d.ts +132 -0
- package/dist/merchant-core/budget/background-budget.js +308 -0
- package/dist/merchant-core/budget/background-budget.js.map +1 -0
- package/dist/merchant-core/collection/alipay-store.d.ts +22 -0
- package/dist/merchant-core/collection/alipay-store.js +125 -0
- package/dist/merchant-core/collection/alipay-store.js.map +1 -0
- package/dist/merchant-core/commercial/calculate.js +6 -6
- package/dist/merchant-core/commercial/calculate.js.map +1 -1
- package/dist/merchant-core/context-governance/actor-context.d.ts +56 -0
- package/dist/merchant-core/context-governance/actor-context.js +76 -0
- package/dist/merchant-core/context-governance/actor-context.js.map +1 -0
- package/dist/merchant-core/context-governance/authority.d.ts +39 -0
- package/dist/merchant-core/context-governance/authority.js +28 -0
- package/dist/merchant-core/context-governance/authority.js.map +1 -0
- package/dist/merchant-core/context-governance/context-guard.d.ts +104 -0
- package/dist/merchant-core/context-governance/context-guard.js +194 -0
- package/dist/merchant-core/context-governance/context-guard.js.map +1 -0
- package/dist/merchant-core/context-governance/data-use-grant.d.ts +91 -0
- package/dist/merchant-core/context-governance/data-use-grant.js +211 -0
- package/dist/merchant-core/context-governance/data-use-grant.js.map +1 -0
- package/dist/merchant-core/context-governance/feature-flags.d.ts +32 -0
- package/dist/merchant-core/context-governance/feature-flags.js +83 -0
- package/dist/merchant-core/context-governance/feature-flags.js.map +1 -0
- package/dist/merchant-core/context-governance/pilot-readiness.d.ts +39 -0
- package/dist/merchant-core/context-governance/pilot-readiness.js +141 -0
- package/dist/merchant-core/context-governance/pilot-readiness.js.map +1 -0
- package/dist/merchant-core/context-governance/source-governance.d.ts +157 -0
- package/dist/merchant-core/context-governance/source-governance.js +492 -0
- package/dist/merchant-core/context-governance/source-governance.js.map +1 -0
- package/dist/merchant-core/context-governance/types.d.ts +62 -0
- package/dist/merchant-core/context-governance/types.js +92 -0
- package/dist/merchant-core/context-governance/types.js.map +1 -0
- package/dist/merchant-core/customer-delivery/binding.d.ts +55 -0
- package/dist/merchant-core/customer-delivery/binding.js +121 -0
- package/dist/merchant-core/customer-delivery/binding.js.map +1 -0
- package/dist/merchant-core/customer-delivery/channel.d.ts +75 -0
- package/dist/merchant-core/customer-delivery/channel.js +157 -0
- package/dist/merchant-core/customer-delivery/channel.js.map +1 -0
- package/dist/merchant-core/customer-delivery/consent-repository.d.ts +50 -0
- package/dist/merchant-core/customer-delivery/consent-repository.js +160 -0
- package/dist/merchant-core/customer-delivery/consent-repository.js.map +1 -0
- package/dist/merchant-core/customer-delivery/dispatcher-loop.d.ts +68 -0
- package/dist/merchant-core/customer-delivery/dispatcher-loop.js +132 -0
- package/dist/merchant-core/customer-delivery/dispatcher-loop.js.map +1 -0
- package/dist/merchant-core/customer-delivery/dispatcher.d.ts +118 -0
- package/dist/merchant-core/customer-delivery/dispatcher.js +166 -0
- package/dist/merchant-core/customer-delivery/dispatcher.js.map +1 -0
- package/dist/merchant-core/customer-delivery/email-adapter.d.ts +31 -0
- package/dist/merchant-core/customer-delivery/email-adapter.js +90 -0
- package/dist/merchant-core/customer-delivery/email-adapter.js.map +1 -0
- package/dist/merchant-core/customer-delivery/gate.d.ts +37 -0
- package/dist/merchant-core/customer-delivery/gate.js +196 -0
- package/dist/merchant-core/customer-delivery/gate.js.map +1 -0
- package/dist/merchant-core/customer-delivery/reconciliation.d.ts +13 -0
- package/dist/merchant-core/customer-delivery/reconciliation.js +70 -0
- package/dist/merchant-core/customer-delivery/reconciliation.js.map +1 -0
- package/dist/merchant-core/customer-delivery/repository.d.ts +55 -0
- package/dist/merchant-core/customer-delivery/repository.js +235 -0
- package/dist/merchant-core/customer-delivery/repository.js.map +1 -0
- package/dist/merchant-core/customer-delivery/smtp-adapter.d.ts +30 -0
- package/dist/merchant-core/customer-delivery/smtp-adapter.js +183 -0
- package/dist/merchant-core/customer-delivery/smtp-adapter.js.map +1 -0
- package/dist/merchant-core/customer-delivery/stream-gate.d.ts +45 -0
- package/dist/merchant-core/customer-delivery/stream-gate.js +123 -0
- package/dist/merchant-core/customer-delivery/stream-gate.js.map +1 -0
- package/dist/merchant-core/customer-delivery/types.d.ts +103 -0
- package/dist/merchant-core/customer-delivery/types.js +32 -0
- package/dist/merchant-core/customer-delivery/types.js.map +1 -0
- package/dist/merchant-core/customer-delivery/weixin-adapter.d.ts +35 -0
- package/dist/merchant-core/customer-delivery/weixin-adapter.js +56 -0
- package/dist/merchant-core/customer-delivery/weixin-adapter.js.map +1 -0
- package/dist/merchant-core/customer-memory/auto-identity.d.ts +43 -0
- package/dist/merchant-core/customer-memory/auto-identity.js +163 -0
- package/dist/merchant-core/customer-memory/auto-identity.js.map +1 -0
- package/dist/merchant-core/customer-memory/grants.d.ts +72 -0
- package/dist/merchant-core/customer-memory/grants.js +224 -0
- package/dist/merchant-core/customer-memory/grants.js.map +1 -0
- package/dist/merchant-core/customer-memory/history.d.ts +51 -0
- package/dist/merchant-core/customer-memory/history.js +252 -0
- package/dist/merchant-core/customer-memory/history.js.map +1 -0
- package/dist/merchant-core/customer-memory/identity.d.ts +66 -0
- package/dist/merchant-core/customer-memory/identity.js +249 -0
- package/dist/merchant-core/customer-memory/identity.js.map +1 -0
- package/dist/merchant-core/customer-memory/maintenance.d.ts +51 -0
- package/dist/merchant-core/customer-memory/maintenance.js +67 -0
- package/dist/merchant-core/customer-memory/maintenance.js.map +1 -0
- package/dist/merchant-core/customer-memory/memory.d.ts +119 -0
- package/dist/merchant-core/customer-memory/memory.js +502 -0
- package/dist/merchant-core/customer-memory/memory.js.map +1 -0
- package/dist/merchant-core/customer-memory/private-transport.d.ts +10 -0
- package/dist/merchant-core/customer-memory/private-transport.js +108 -0
- package/dist/merchant-core/customer-memory/private-transport.js.map +1 -0
- package/dist/merchant-core/customer-memory/quote-history.d.ts +160 -0
- package/dist/merchant-core/customer-memory/quote-history.js +392 -0
- package/dist/merchant-core/customer-memory/quote-history.js.map +1 -0
- package/dist/merchant-core/customer-memory/reception-provider.d.ts +69 -0
- package/dist/merchant-core/customer-memory/reception-provider.js +250 -0
- package/dist/merchant-core/customer-memory/reception-provider.js.map +1 -0
- package/dist/merchant-core/customer-memory/reception-writer.d.ts +19 -0
- package/dist/merchant-core/customer-memory/reception-writer.js +32 -0
- package/dist/merchant-core/customer-memory/reception-writer.js.map +1 -0
- package/dist/merchant-core/customer-memory/types.d.ts +111 -0
- package/dist/merchant-core/customer-memory/types.js +58 -0
- package/dist/merchant-core/customer-memory/types.js.map +1 -0
- package/dist/merchant-core/followup/repository.d.ts +2 -1
- package/dist/merchant-core/followup/repository.js +29 -23
- package/dist/merchant-core/followup/repository.js.map +1 -1
- package/dist/merchant-core/learning/evaluation-fixtures.d.ts +38 -0
- package/dist/merchant-core/learning/evaluation-fixtures.js +83 -0
- package/dist/merchant-core/learning/evaluation-fixtures.js.map +1 -0
- package/dist/merchant-core/learning/evaluation-suite-v1.d.ts +56 -0
- package/dist/merchant-core/learning/evaluation-suite-v1.js +129 -0
- package/dist/merchant-core/learning/evaluation-suite-v1.js.map +1 -0
- package/dist/merchant-core/learning/evaluation.d.ts +84 -0
- package/dist/merchant-core/learning/evaluation.js +581 -0
- package/dist/merchant-core/learning/evaluation.js.map +1 -0
- package/dist/merchant-core/learning/initial-skills.d.ts +36 -0
- package/dist/merchant-core/learning/initial-skills.js +67 -0
- package/dist/merchant-core/learning/initial-skills.js.map +1 -0
- package/dist/merchant-core/learning/precheck.d.ts +33 -0
- package/dist/merchant-core/learning/precheck.js +56 -0
- package/dist/merchant-core/learning/precheck.js.map +1 -0
- package/dist/merchant-core/learning/real-evaluation-runner.d.ts +52 -0
- package/dist/merchant-core/learning/real-evaluation-runner.js +167 -0
- package/dist/merchant-core/learning/real-evaluation-runner.js.map +1 -0
- package/dist/merchant-core/learning/reception-skill-catalog.d.ts +39 -0
- package/dist/merchant-core/learning/reception-skill-catalog.js +145 -0
- package/dist/merchant-core/learning/reception-skill-catalog.js.map +1 -0
- package/dist/merchant-core/learning/recovery-gateway.d.ts +27 -0
- package/dist/merchant-core/learning/recovery-gateway.js +106 -0
- package/dist/merchant-core/learning/recovery-gateway.js.map +1 -0
- package/dist/merchant-core/learning/repository.d.ts +130 -0
- package/dist/merchant-core/learning/repository.js +588 -0
- package/dist/merchant-core/learning/repository.js.map +1 -0
- package/dist/merchant-core/learning/service.d.ts +262 -0
- package/dist/merchant-core/learning/service.js +1498 -0
- package/dist/merchant-core/learning/service.js.map +1 -0
- package/dist/merchant-core/learning/test-dispatch-gateway.d.ts +43 -0
- package/dist/merchant-core/learning/test-dispatch-gateway.js +145 -0
- package/dist/merchant-core/learning/test-dispatch-gateway.js.map +1 -0
- package/dist/merchant-core/learning/types.d.ts +217 -0
- package/dist/merchant-core/learning/types.js +52 -0
- package/dist/merchant-core/learning/types.js.map +1 -0
- package/dist/merchant-core/migrations/ledgers.d.ts +40 -0
- package/dist/merchant-core/migrations/ledgers.js +824 -0
- package/dist/merchant-core/migrations/ledgers.js.map +1 -0
- package/dist/merchant-core/migrations/runner.d.ts +55 -0
- package/dist/merchant-core/migrations/runner.js +114 -0
- package/dist/merchant-core/migrations/runner.js.map +1 -0
- package/dist/merchant-core/operating/repository.d.ts +0 -1
- package/dist/merchant-core/operating/repository.js +2 -17
- package/dist/merchant-core/operating/repository.js.map +1 -1
- package/dist/merchant-core/operations-jobs/advice-runner.d.ts +63 -0
- package/dist/merchant-core/operations-jobs/advice-runner.js +199 -0
- package/dist/merchant-core/operations-jobs/advice-runner.js.map +1 -0
- package/dist/merchant-core/operations-jobs/pilot-evidence.d.ts +64 -0
- package/dist/merchant-core/operations-jobs/pilot-evidence.js +109 -0
- package/dist/merchant-core/operations-jobs/pilot-evidence.js.map +1 -0
- package/dist/merchant-core/operations-jobs/pilot-metrics.d.ts +70 -0
- package/dist/merchant-core/operations-jobs/pilot-metrics.js +98 -0
- package/dist/merchant-core/operations-jobs/pilot-metrics.js.map +1 -0
- package/dist/merchant-core/operations-jobs/projection.d.ts +41 -0
- package/dist/merchant-core/operations-jobs/projection.js +158 -0
- package/dist/merchant-core/operations-jobs/projection.js.map +1 -0
- package/dist/merchant-core/operations-jobs/scheduler.d.ts +68 -0
- package/dist/merchant-core/operations-jobs/scheduler.js +233 -0
- package/dist/merchant-core/operations-jobs/scheduler.js.map +1 -0
- package/dist/merchant-core/operations-jobs/service.d.ts +260 -0
- package/dist/merchant-core/operations-jobs/service.js +922 -0
- package/dist/merchant-core/operations-jobs/service.js.map +1 -0
- package/dist/merchant-core/opportunity/repository.d.ts +0 -1
- package/dist/merchant-core/opportunity/repository.js +2 -17
- package/dist/merchant-core/opportunity/repository.js.map +1 -1
- package/dist/merchant-core/ops/facade.d.ts +10 -0
- package/dist/merchant-core/ops/facade.js +52 -0
- package/dist/merchant-core/ops/facade.js.map +1 -1
- package/dist/merchant-core/ops/schema.d.ts +1 -1
- package/dist/merchant-core/ops/schema.js +119 -2
- package/dist/merchant-core/ops/schema.js.map +1 -1
- package/dist/merchant-core/ops/surface.d.ts +37 -0
- package/dist/merchant-core/ops/surface.js +240 -0
- package/dist/merchant-core/ops/surface.js.map +1 -1
- package/dist/merchant-core/orders/model.d.ts +1 -8
- package/dist/merchant-core/orders/model.js +10 -2
- package/dist/merchant-core/orders/model.js.map +1 -1
- package/dist/merchant-core/orders/repository.d.ts +0 -1
- package/dist/merchant-core/orders/repository.js +3 -18
- package/dist/merchant-core/orders/repository.js.map +1 -1
- package/dist/merchant-core/orders/service.js +34 -8
- package/dist/merchant-core/orders/service.js.map +1 -1
- package/dist/merchant-core/ownership/instance-ownership.d.ts +122 -0
- package/dist/merchant-core/ownership/instance-ownership.js +236 -0
- package/dist/merchant-core/ownership/instance-ownership.js.map +1 -0
- package/dist/merchant-core/ownership/runtime.d.ts +175 -0
- package/dist/merchant-core/ownership/runtime.js +422 -0
- package/dist/merchant-core/ownership/runtime.js.map +1 -0
- package/dist/merchant-core/proposal/engine.js +2 -0
- package/dist/merchant-core/proposal/engine.js.map +1 -1
- package/dist/merchant-core/proposal/publish.d.ts +0 -6
- package/dist/merchant-core/proposal/publish.js +37 -3
- package/dist/merchant-core/proposal/publish.js.map +1 -1
- package/dist/merchant-core/proposal/repository.d.ts +0 -7
- package/dist/merchant-core/proposal/repository.js +8 -17
- package/dist/merchant-core/proposal/repository.js.map +1 -1
- package/dist/merchant-core/proposal/types.d.ts +1 -0
- package/dist/merchant-core/proposal/types.js.map +1 -1
- package/dist/merchant-core/rfq/policy.d.ts +1 -0
- package/dist/merchant-core/rfq/policy.js +6 -7
- package/dist/merchant-core/rfq/policy.js.map +1 -1
- package/dist/merchant-core/rfq/repository.d.ts +0 -1
- package/dist/merchant-core/rfq/repository.js +2 -17
- package/dist/merchant-core/rfq/repository.js.map +1 -1
- package/dist/merchant-core/rfq/service.d.ts +2 -1
- package/dist/merchant-core/rfq/service.js +2 -4
- package/dist/merchant-core/rfq/service.js.map +1 -1
- package/dist/merchant-core/storage/transaction.d.ts +95 -7
- package/dist/merchant-core/storage/transaction.js +251 -2
- package/dist/merchant-core/storage/transaction.js.map +1 -1
- package/dist/merchant-credential-rotation.d.ts +4 -1
- package/dist/merchant-credential-rotation.js +12 -8
- package/dist/merchant-credential-rotation.js.map +1 -1
- package/dist/merchant-runtime/manager.d.ts +2 -0
- package/dist/merchant-runtime/manager.js +5 -0
- package/dist/merchant-runtime/manager.js.map +1 -1
- package/dist/negotiation/domain/objects.d.ts +2 -0
- package/dist/negotiation/domain/objects.js +3 -0
- package/dist/negotiation/domain/objects.js.map +1 -1
- package/dist/negotiation/ledger/store.d.ts +4 -0
- package/dist/negotiation/ledger/store.js +20 -0
- package/dist/negotiation/ledger/store.js.map +1 -1
- package/dist/product-init.d.ts +1 -0
- package/dist/product-init.js +4 -1
- package/dist/product-init.js.map +1 -1
- package/dist/trust/identity/message-signature.d.ts +1 -1
- package/dist/trust/identity/message-signature.js +6 -1
- package/dist/trust/identity/message-signature.js.map +1 -1
- package/dist/trust/identity/nonce.d.ts +5 -0
- package/dist/trust/identity/nonce.js +2 -0
- package/dist/trust/identity/nonce.js.map +1 -1
- package/dist/weixin/ilink-client.d.ts +3 -2
- package/dist/weixin/ilink-client.js +9 -2
- package/dist/weixin/ilink-client.js.map +1 -1
- package/package.json +2 -2
|
@@ -23,20 +23,29 @@ import { fenceModelPayload } from "../context/fencing.js";
|
|
|
23
23
|
import { HandoffIdempotencyStore, HandoffEventStore, createHandoffCandidate, executeHandoff, validateDestination, validateExternalDestinationUrl, } from "../../handoff/index.js";
|
|
24
24
|
import { buildMarketplaceSourceBinding, MarketplaceLaunchPolicyError, parseMarketplaceTradeUrl, sameMarketplaceTarget, } from "../../handoff/launch-marketplace-policy.js";
|
|
25
25
|
import { isUrlDestinationType } from "../../handoff/destination.js";
|
|
26
|
+
import { ALIPAY_COLLECTION_NOTICE, ALIPAY_PRIVATE_DISPLAY_REQUIRED, isAlipayCollectionAgreement, isAlipayCollectionDestination, parseAlipayCollectionLink, parseAlipayCollectionTerms, } from "../../handoff/alipay-collection.js";
|
|
26
27
|
import { CatalogSourceError } from "../../discovery/catalog-source/errors.js";
|
|
27
28
|
import { CommerceError } from "../../commerce/data-source.js";
|
|
28
29
|
import { toMinorUnits as losslessToMinorUnits } from "../../protocol/legacy-shopping-negotiation/money.js";
|
|
29
30
|
import { contentDigest } from "../../negotiation/jcs.js";
|
|
31
|
+
import { VaultKeyError } from "../memory/vault.js";
|
|
30
32
|
import { requireScopeCredential } from "../merchant/credential-broker.js";
|
|
31
|
-
import { NEGOTIATE_DEAL_PRICE_MINOR,
|
|
33
|
+
import { NEGOTIATE_DEAL_PRICE_MINOR, NEGOTIATE_SKU, negotiateWithAgent, summarizeNegotiation, } from "../../a2a/negotiate.js";
|
|
32
34
|
import { buildNegotiationChatTools, writeGateText } from "../negotiation-chat.js";
|
|
33
|
-
import { routeWriteCandidate } from "../write-gate.js";
|
|
35
|
+
import { APPROVAL_TTL_MS, routeWriteCandidate } from "../write-gate.js";
|
|
34
36
|
import { runSearchCycle } from "./search-loop.js";
|
|
35
37
|
import { assertTrackingRuleType } from "./task-store.js";
|
|
36
38
|
import { BuyerTaskError } from "./types.js";
|
|
37
39
|
function textResult(text, details) {
|
|
38
40
|
return { content: [{ type: "text", text }], details };
|
|
39
41
|
}
|
|
42
|
+
function alipayDeliveryResult(status, handoffId, negotiationId) {
|
|
43
|
+
const prefix = status === "delivered" ? "支付宝交接已记录" : "该支付宝协议已交付,未重复交接";
|
|
44
|
+
return {
|
|
45
|
+
ok: true, status, handoff_id: handoffId, negotiation_id: negotiationId,
|
|
46
|
+
text: `${prefix};请在原生终端输入 /alipay ${handoffId} ${negotiationId} 查看。${ALIPAY_COLLECTION_NOTICE}`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
40
49
|
function errorText(err) {
|
|
41
50
|
if (err instanceof BuyerTaskError)
|
|
42
51
|
return `任务操作被拒绝(${err.code}):${err.message}`;
|
|
@@ -220,6 +229,27 @@ const NEGOTIABLE_TASK_STATUSES = new Set([
|
|
|
220
229
|
"shortlist_ready",
|
|
221
230
|
"awaiting_user",
|
|
222
231
|
]);
|
|
232
|
+
function pendingMerchantApproval(store, taskId) {
|
|
233
|
+
// Resume data comes from the merchant channel with an independent buyer signer, never a tool parameter.
|
|
234
|
+
const events = store.taskEvents(taskId);
|
|
235
|
+
const pending = [...events].reverse().find((event) => event.type === "a2a_negotiated" && event.payload.merchant_approval_resume !== undefined);
|
|
236
|
+
const resume = pending?.payload.merchant_approval_resume;
|
|
237
|
+
return resume !== undefined && !events.some((event) => event.type === "merchant_approval_resume_closed" &&
|
|
238
|
+
event.payload.negotiation_id === resume.negotiationId) ? resume : undefined;
|
|
239
|
+
}
|
|
240
|
+
function closeMerchantApprovalResume(store, taskId, negotiationId, reason, origin) {
|
|
241
|
+
return store.appendEvent(taskId, "merchant_approval_resume_closed", {
|
|
242
|
+
negotiation_id: negotiationId, reason,
|
|
243
|
+
}, origin, `a2a-neg:${taskId}:${negotiationId}:merchant-approval-closed`);
|
|
244
|
+
}
|
|
245
|
+
/** Human-only local action: stop resuming without sending anything to the merchant. */
|
|
246
|
+
export function abandonMerchantApprovalResume(store, taskId) {
|
|
247
|
+
const task = store.getTask(taskId);
|
|
248
|
+
if (task === undefined || !NEGOTIABLE_TASK_STATUSES.has(task.status))
|
|
249
|
+
return false;
|
|
250
|
+
const resume = pendingMerchantApproval(store, taskId);
|
|
251
|
+
return resume !== undefined && closeMerchantApprovalResume(store, taskId, resume.negotiationId, "abandoned", "user");
|
|
252
|
+
}
|
|
223
253
|
/** 磋商前置快照(审批候选 + 执行前重读用,§16)。 */
|
|
224
254
|
function negotiationPreconditions(store, catalogConfigured, taskId) {
|
|
225
255
|
const task = store.getTask(taskId);
|
|
@@ -227,6 +257,7 @@ function negotiationPreconditions(store, catalogConfigured, taskId) {
|
|
|
227
257
|
task_status: task?.status ?? null,
|
|
228
258
|
task_version: task?.version ?? null,
|
|
229
259
|
catalog_configured: catalogConfigured,
|
|
260
|
+
merchant_pending_negotiation_id: pendingMerchantApproval(store, taskId)?.negotiationId ?? null,
|
|
230
261
|
};
|
|
231
262
|
}
|
|
232
263
|
/**
|
|
@@ -255,8 +286,24 @@ async function executeNegotiateBuyerTask(deps, args) {
|
|
|
255
286
|
.listCandidates(a.task_id)
|
|
256
287
|
.find((c) => c.candidate_status === "shortlisted" || c.candidate_status === "selected")?.sku;
|
|
257
288
|
const sku = candidateSku ?? intent.category ?? intent.query_text ?? NEGOTIATE_SKU;
|
|
289
|
+
const resume = pendingMerchantApproval(store, a.task_id);
|
|
290
|
+
let maxTotal;
|
|
291
|
+
try {
|
|
292
|
+
maxTotal = store.resolveBudget(task.constraints);
|
|
293
|
+
if (maxTotal === undefined && task.constraints.max_total_price_vault_ref !== undefined) {
|
|
294
|
+
throw new BuyerTaskError("validation", "invalid vaulted budget");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
const code = error instanceof BuyerTaskError ? error.code
|
|
299
|
+
: error instanceof VaultKeyError ? "vault_decryption_failed" : "vault_unavailable";
|
|
300
|
+
throw new BuyerTaskError(code, `无法读取任务的私有总预算(${code});未发送磋商请求`);
|
|
301
|
+
}
|
|
258
302
|
const result = await negotiateWithAgent({
|
|
259
303
|
catalog: deps.catalog,
|
|
304
|
+
allowMerchantApprovalResume: true,
|
|
305
|
+
alipayCollectionAvailable: deps.alipayCollectionAvailable === true,
|
|
306
|
+
...(resume === undefined ? {} : { resume }),
|
|
260
307
|
allowLoopback: deps.allowLoopback === true,
|
|
261
308
|
// CD #27:listing → owner_agent_id → getRecord → fresh verify 全链,
|
|
262
309
|
// 与 search_listings 同一注入源(历史教训:只注入 search 面不注入磋商面)。
|
|
@@ -274,26 +321,47 @@ async function executeNegotiateBuyerTask(deps, args) {
|
|
|
274
321
|
return converted.lossless ? converted.amount_minor : NEGOTIATE_DEAL_PRICE_MINOR;
|
|
275
322
|
})()
|
|
276
323
|
: NEGOTIATE_DEAL_PRICE_MINOR,
|
|
277
|
-
deliveryBefore: intent.needed_by
|
|
324
|
+
...(intent.needed_by !== undefined ? { deliveryBefore: intent.needed_by } : {}),
|
|
278
325
|
senderIdentity: deps.profile.agent_id,
|
|
279
|
-
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
const total = task.constraints.max_total_price;
|
|
288
|
-
const qty = intent.quantity ?? 1;
|
|
289
|
-
if (total !== undefined && Number.isFinite(total) && qty > 0) {
|
|
290
|
-
const c = losslessToMinorUnits(total / qty, 2);
|
|
291
|
-
return c.lossless ? c.amount_minor : undefined;
|
|
292
|
-
}
|
|
293
|
-
return undefined;
|
|
294
|
-
})(),
|
|
326
|
+
...(deps.outboundSigner !== undefined ? { outboundSigner: deps.outboundSigner } : {}),
|
|
327
|
+
// Convert the private limits separately; the negotiator enforces both before AcceptNonbinding.
|
|
328
|
+
// An unrepresentable explicit budget is rejected, not ignored in favor of a default.
|
|
329
|
+
...(task.constraints.max_unit_price === undefined ? {} : {
|
|
330
|
+
maxPriceMinor: losslessToMinorUnits(task.constraints.max_unit_price, 2).amount_minor,
|
|
331
|
+
}),
|
|
332
|
+
...(maxTotal === undefined ? {} : { maxTotalMinor: losslessToMinorUnits(maxTotal, 2).amount_minor }),
|
|
295
333
|
});
|
|
296
334
|
const eventKey = `a2a-neg:${a.task_id}:${result.negotiationId}`;
|
|
335
|
+
if (result.merchantApprovalResume !== undefined) {
|
|
336
|
+
store.appendEvent(a.task_id, "a2a_negotiated", {
|
|
337
|
+
ok: false,
|
|
338
|
+
negotiation_id: result.negotiationId,
|
|
339
|
+
catalog_agent_id: result.catalogAgentId,
|
|
340
|
+
merchant_approval_resume: result.merchantApprovalResume,
|
|
341
|
+
}, "model", `${eventKey}:merchant-approval`);
|
|
342
|
+
return {
|
|
343
|
+
ok: true,
|
|
344
|
+
status: "merchant_approval_pending",
|
|
345
|
+
task_id: a.task_id,
|
|
346
|
+
negotiation_id: result.negotiationId,
|
|
347
|
+
text: `商家需要人工确认本次报价。商家确认后,请使用同一任务继续磋商;请勿自动反复重试。如需改价或换商家,可在终端输入 /abandon-quote ${a.task_id}。`,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
const resolution = result.merchantApprovalResolution;
|
|
351
|
+
if (resume !== undefined && resolution !== undefined) {
|
|
352
|
+
closeMerchantApprovalResume(store, a.task_id, resume.negotiationId, resolution, "model");
|
|
353
|
+
}
|
|
354
|
+
if (resolution !== undefined && resolution !== "quoted") {
|
|
355
|
+
const notice = {
|
|
356
|
+
rejected: "商家已拒绝上一轮报价",
|
|
357
|
+
expired: "上一轮报价的商家审批已过期",
|
|
358
|
+
consumed: "上一轮报价的商家授权已使用,无法再次续接",
|
|
359
|
+
}[resolution];
|
|
360
|
+
return {
|
|
361
|
+
ok: true, status: `merchant_approval_${resolution}`, task_id: a.task_id, negotiation_id: result.negotiationId,
|
|
362
|
+
text: `${notice}。未重新提交,也未达成协议;如需重新报价,请先与用户确认,再用同一任务发起新磋商。`,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
297
365
|
if (!result.ok) {
|
|
298
366
|
store.appendEvent(a.task_id, "a2a_negotiated", {
|
|
299
367
|
ok: false,
|
|
@@ -343,10 +411,14 @@ async function executeNegotiateBuyerTask(deps, args) {
|
|
|
343
411
|
negotiation_id: result.negotiationId,
|
|
344
412
|
agreement_id: result.agreement?.agreement_id ?? null,
|
|
345
413
|
deal_price_minor: facts?.dealPriceMinor ?? null,
|
|
414
|
+
...(facts?.payableTotalMinor === undefined ? {} : { payable_total_minor: facts.payableTotalMinor }),
|
|
346
415
|
// v0.7.0 KTH:agreement 快照落任务记录——handoff_agreement 的
|
|
347
416
|
// agreementReader 以此做 pre-execution revalidation(§10)。
|
|
348
417
|
agreed_terms: result.agreement?.agreed_terms ?? null,
|
|
349
418
|
terms_digest: result.agreement?.terms_digest ?? null,
|
|
419
|
+
accepted_offer_id: result.agreement?.accepted_offer_id ?? null,
|
|
420
|
+
handoff_destination: result.agreement?.handoff_destination ?? null,
|
|
421
|
+
accepted_channel_url: result.acceptedChannelUrl ?? null,
|
|
350
422
|
merchant_identity_ref: `merchant:${result.catalogAgentId}`,
|
|
351
423
|
},
|
|
352
424
|
origin: "model",
|
|
@@ -363,6 +435,7 @@ async function executeNegotiateBuyerTask(deps, args) {
|
|
|
363
435
|
quantity: facts?.quantity ?? intent.quantity ?? 1,
|
|
364
436
|
offer_price_minor: facts?.offerPriceMinor ?? null,
|
|
365
437
|
deal_price_minor: facts?.dealPriceMinor ?? null,
|
|
438
|
+
...(facts?.payableTotalMinor === undefined ? {} : { payable_total_minor: facts.payableTotalMinor }),
|
|
366
439
|
delivery_before: facts?.deliveryBefore ?? null,
|
|
367
440
|
agreement_id: result.agreement?.agreement_id ?? null,
|
|
368
441
|
steps: result.steps,
|
|
@@ -1061,7 +1134,8 @@ export function buildBuyerTools(deps) {
|
|
|
1061
1134
|
"SKU/数量/目标单价/交期取自任务 intent(category 或 query_text 视为 SKU)。" +
|
|
1062
1135
|
"结果是非绑定协议(不创建订单、不锁库存、不授权支付)。写操作:supervised 模式" +
|
|
1063
1136
|
"需 /approve 批准后才真正发送消息;任务须处于 ready/tracking/shortlist_ready/awaiting_user。" +
|
|
1064
|
-
"达成协议后任务进入 selected_nonbinding
|
|
1137
|
+
"达成协议后任务进入 selected_nonbinding。原生签名终端若收到 merchant_approval_pending," +
|
|
1138
|
+
"在商家确认后用同一 task_id 继续;不得换商家或自动轮询。",
|
|
1065
1139
|
parameters: {
|
|
1066
1140
|
type: "object",
|
|
1067
1141
|
properties: {
|
|
@@ -1146,7 +1220,8 @@ export function buildBuyerTools(deps) {
|
|
|
1146
1220
|
"目的地**只取商家在协议里直传的成交入口**(merchant 从 shopping-cli 读的 handoff_destination)," +
|
|
1147
1221
|
"不允许 LLM 自编、也不读 catalog 投影——协议未带成交入口则拒绝交接。" +
|
|
1148
1222
|
"经审批门(supervised 需 /approve)后执行:重验 agreement/terms/destination/expiry," +
|
|
1149
|
-
"安全交付到 external checkout URL。不创建订单、不授权支付、不预留库存。"
|
|
1223
|
+
"安全交付到 external checkout URL。不创建订单、不授权支付、不预留库存。" +
|
|
1224
|
+
"支付宝收款必须由具备私有显示能力的原生终端人工批准,只传 task_id;请勿覆盖收款摘要、有效期或目的地。",
|
|
1150
1225
|
parameters: {
|
|
1151
1226
|
type: "object",
|
|
1152
1227
|
properties: {
|
|
@@ -1184,9 +1259,22 @@ export function buildBuyerTools(deps) {
|
|
|
1184
1259
|
if (agreement === undefined) {
|
|
1185
1260
|
return textResult("任务记录缺少 agreement 快照(磋商未完成或 terms 未持久化)。");
|
|
1186
1261
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1262
|
+
const collection = resolveAlipayCollection(agreement, Date.parse(deps.now()));
|
|
1263
|
+
if (collection.kind !== "ordinary") {
|
|
1264
|
+
if (deps.alipayCollectionAvailable !== true || deps.registerPending === undefined) {
|
|
1265
|
+
return textResult(ALIPAY_PRIVATE_DISPLAY_REQUIRED, { status: "authorization_denied" });
|
|
1266
|
+
}
|
|
1267
|
+
if (Object.keys(p).some((key) => key !== "task_id")) {
|
|
1268
|
+
return textResult("支付宝交接仅接受 task_id;不得覆盖商家声明的目的地、收款摘要或有效期。", { status: "invalid_params" });
|
|
1269
|
+
}
|
|
1270
|
+
if (collection.kind !== "collection") {
|
|
1271
|
+
return textResult(collection.kind === "expired" ? "支付宝收款指引已过期。" : "支付宝收款指引未绑定同源的签名磋商与已接受协议。", { status: collection.kind });
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
// Use the exact merchant declaration; never derive a collection from model input.
|
|
1275
|
+
const agreementDestination = collection.kind === "collection"
|
|
1276
|
+
? { type: "external_checkout_url", ref: collection.link.url }
|
|
1277
|
+
: agreementDestinationFromTerms(agreement.agreed_terms);
|
|
1190
1278
|
if (agreementDestination === undefined) {
|
|
1191
1279
|
return textResult("商家未在协议中声明成交入口(handoff_destination),无法交接。");
|
|
1192
1280
|
}
|
|
@@ -1200,6 +1288,14 @@ export function buildBuyerTools(deps) {
|
|
|
1200
1288
|
e.destination?.ref === destination.ref &&
|
|
1201
1289
|
e.destination?.type === destination.type);
|
|
1202
1290
|
if (priorDelivery !== undefined) {
|
|
1291
|
+
if (collection.kind === "collection") {
|
|
1292
|
+
const handoffId = priorDelivery.handoff_id;
|
|
1293
|
+
if (handoffId === undefined) {
|
|
1294
|
+
return textResult("该支付宝协议已交付过,但缺少交接 ID;请核对本机交接记录。", { status: "already_delivered" });
|
|
1295
|
+
}
|
|
1296
|
+
const result = alipayDeliveryResult("already_delivered", handoffId, collection.link.negotiationId);
|
|
1297
|
+
return textResult(result.text, result);
|
|
1298
|
+
}
|
|
1203
1299
|
return textResult(`该协议已交付过(handoff ${priorDelivery.handoff_id ?? "unknown"},` +
|
|
1204
1300
|
`目的地 ${destination.type} ${destination.ref}),同一目的地不重复交接。`);
|
|
1205
1301
|
}
|
|
@@ -1228,6 +1324,12 @@ export function buildBuyerTools(deps) {
|
|
|
1228
1324
|
const lastStale = [...handoff.ledger.events(agreement.negotiation_id).map((event) => handoff.ledger.resolvePayload(event))]
|
|
1229
1325
|
.reverse()
|
|
1230
1326
|
.find((e) => e.event_kind === "handoff_candidate_stale");
|
|
1327
|
+
const now = deps.now();
|
|
1328
|
+
const nowMs = Date.parse(now);
|
|
1329
|
+
const expiresAtMs = collection.kind === "collection"
|
|
1330
|
+
? Math.min(nowMs + expiresInHours * 3_600_000, Date.parse(collection.metadata.expires_at))
|
|
1331
|
+
: nowMs + expiresInHours * 3_600_000;
|
|
1332
|
+
const collectionSummary = collection.kind === "collection" ? alipayDisplaySummary(collection.metadata) : undefined;
|
|
1231
1333
|
const candidate = createHandoffCandidate({
|
|
1232
1334
|
agreement_id: agreement.agreement_id,
|
|
1233
1335
|
negotiation_id: agreement.negotiation_id,
|
|
@@ -1236,14 +1338,14 @@ export function buildBuyerTools(deps) {
|
|
|
1236
1338
|
merchant_identity_ref: agreement.merchant_identity_ref,
|
|
1237
1339
|
destination: { type: destination.type, ref: destination.ref },
|
|
1238
1340
|
display_summary: {
|
|
1239
|
-
merchant: p.display_summary_merchant ?? agreement.merchant_identity_ref,
|
|
1240
|
-
summary: p.display_summary_text ?? `negotiation ${agreement.negotiation_id}`,
|
|
1341
|
+
merchant: collection.kind === "collection" ? agreement.merchant_identity_ref : (p.display_summary_merchant ?? agreement.merchant_identity_ref),
|
|
1342
|
+
summary: collectionSummary ?? p.display_summary_text ?? `negotiation ${agreement.negotiation_id}`,
|
|
1241
1343
|
},
|
|
1242
1344
|
policy_version: "handoff-policy/1",
|
|
1243
1345
|
// 时钟统一用注入的 deps.now()(此前 created_at 走墙钟、事件走注入时钟,
|
|
1244
1346
|
// time_to_handoff 指标掺入偏差)。
|
|
1245
|
-
created_at:
|
|
1246
|
-
expires_at: new Date(
|
|
1347
|
+
created_at: now,
|
|
1348
|
+
expires_at: new Date(expiresAtMs).toISOString(),
|
|
1247
1349
|
...(lastStale?.handoff_candidate_id !== undefined
|
|
1248
1350
|
? { supersedes_candidate_id: lastStale.handoff_candidate_id }
|
|
1249
1351
|
: {}),
|
|
@@ -1294,6 +1396,10 @@ export function buildBuyerTools(deps) {
|
|
|
1294
1396
|
},
|
|
1295
1397
|
preconditions: { agreement_bound: true },
|
|
1296
1398
|
risk: "handoff_delivery",
|
|
1399
|
+
...(collection.kind === "collection" ? {
|
|
1400
|
+
force_pending: true,
|
|
1401
|
+
ttl_ms: Math.min(APPROVAL_TTL_MS, expiresAtMs - nowMs),
|
|
1402
|
+
} : {}),
|
|
1297
1403
|
execute: (approvedArgs) => executeHandoffForCandidate(deps, approvedArgs),
|
|
1298
1404
|
// §16 stale 检测的真实重读:approval 与执行之间协议被重磋商改写
|
|
1299
1405
|
//(agreement 消失 / 身份变化 / terms_digest 不匹配)→ 候选 supersede。
|
|
@@ -1305,6 +1411,12 @@ export function buildBuyerTools(deps) {
|
|
|
1305
1411
|
current.agreement_id === agreement.agreement_id &&
|
|
1306
1412
|
current.negotiation_id === agreement.negotiation_id &&
|
|
1307
1413
|
contentDigest(current.agreed_terms) === candidate.terms_digest;
|
|
1414
|
+
if (collection.kind === "collection") {
|
|
1415
|
+
const fresh = resolveAlipayCollection(current, Date.parse(deps.now()));
|
|
1416
|
+
return { agreement_bound: stillBound && fresh.kind === "collection" &&
|
|
1417
|
+
fresh.link.url === collection.link.url && deps.alipayCollectionAvailable === true &&
|
|
1418
|
+
deps.store.getTask(p.task_id)?.status === "selected_nonbinding" };
|
|
1419
|
+
}
|
|
1308
1420
|
return { agreement_bound: stillBound };
|
|
1309
1421
|
},
|
|
1310
1422
|
// autopilot 政策闸:handoff 把买家送向真实成交入口(外部结账/PO/联系
|
|
@@ -1316,7 +1428,11 @@ export function buildBuyerTools(deps) {
|
|
|
1316
1428
|
? "buyer 未授权自动交接(auto_negotiate=false),需要人工确认。"
|
|
1317
1429
|
: "handoff 交付默认需要人工确认;如确需自动执行,请在 profile 设置 buyer_policy.auto_handoff: true。",
|
|
1318
1430
|
});
|
|
1319
|
-
|
|
1431
|
+
const rendered = writeGateText(outcome);
|
|
1432
|
+
if (collectionSummary !== undefined && (outcome.kind === "pending_approval" || outcome.kind === "advice_only")) {
|
|
1433
|
+
return textResult(`商家 ${agreement.merchant_identity_ref};${collectionSummary}\n${rendered.content[0]?.type === "text" ? rendered.content[0].text : ""}`, rendered.details);
|
|
1434
|
+
}
|
|
1435
|
+
return rendered;
|
|
1320
1436
|
}
|
|
1321
1437
|
catch (err) {
|
|
1322
1438
|
return textResult(errorText(err));
|
|
@@ -1750,10 +1866,48 @@ function agreementFromTask(events) {
|
|
|
1750
1866
|
? payload.merchant_identity_ref
|
|
1751
1867
|
: "merchant:unknown",
|
|
1752
1868
|
...(merchantDomain !== undefined ? { merchant_domain: merchantDomain } : {}),
|
|
1869
|
+
...(typeof payload.accepted_offer_id === "string" ? { accepted_offer_id: payload.accepted_offer_id } : {}),
|
|
1870
|
+
handoff_destination: payload.handoff_destination,
|
|
1871
|
+
...(typeof payload.accepted_channel_url === "string" ? { accepted_channel_url: payload.accepted_channel_url } : {}),
|
|
1872
|
+
...(typeof payload.terms_digest === "string" ? { terms_digest: payload.terms_digest } : {}),
|
|
1753
1873
|
};
|
|
1754
1874
|
}
|
|
1755
1875
|
return undefined;
|
|
1756
1876
|
}
|
|
1877
|
+
/** Derive the collection only from the accepted KNP snapshot in the owned task. */
|
|
1878
|
+
export function resolveTaskAlipayCollection(events, nowMs) {
|
|
1879
|
+
return resolveAlipayCollection(agreementFromTask(events), nowMs);
|
|
1880
|
+
}
|
|
1881
|
+
function resolveAlipayCollection(agreement, nowMs) {
|
|
1882
|
+
if (agreement === undefined || !isAlipayCollectionAgreement(agreement.agreed_terms, agreement.handoff_destination)) {
|
|
1883
|
+
return { kind: "ordinary" };
|
|
1884
|
+
}
|
|
1885
|
+
const terms = agreement.agreed_terms;
|
|
1886
|
+
const declared = agreement.handoff_destination;
|
|
1887
|
+
const link = typeof declared === "string" ? parseAlipayCollectionLink(declared) : null;
|
|
1888
|
+
const metadata = parseAlipayCollectionTerms(terms);
|
|
1889
|
+
if (link === null || metadata === null || declared !== terms?.handoff_destination ||
|
|
1890
|
+
link.negotiationId !== agreement.negotiation_id || link.offerId !== agreement.accepted_offer_id ||
|
|
1891
|
+
link.version !== metadata.version || agreement.terms_digest !== contentDigest(terms) ||
|
|
1892
|
+
agreement.accepted_channel_url === undefined || !Number.isFinite(nowMs))
|
|
1893
|
+
return { kind: "invalid" };
|
|
1894
|
+
try {
|
|
1895
|
+
const channel = new URL(agreement.accepted_channel_url);
|
|
1896
|
+
if (channel.origin !== link.origin || channel.username !== "" || channel.password !== "")
|
|
1897
|
+
return { kind: "invalid" };
|
|
1898
|
+
}
|
|
1899
|
+
catch {
|
|
1900
|
+
return { kind: "invalid" };
|
|
1901
|
+
}
|
|
1902
|
+
if (Date.parse(metadata.expires_at) <= nowMs)
|
|
1903
|
+
return { kind: "expired" };
|
|
1904
|
+
return { kind: "collection", link, metadata, agreementId: agreement.agreement_id, termsDigest: agreement.terms_digest };
|
|
1905
|
+
}
|
|
1906
|
+
function alipayDisplaySummary(metadata) {
|
|
1907
|
+
const whole = Math.floor(metadata.total_minor / 100);
|
|
1908
|
+
const fraction = String(metadata.total_minor % 100).padStart(2, "0");
|
|
1909
|
+
return `支付宝收款方 ${metadata.recipient_summary};金额 CNY ${whole}.${fraction};有效期 ${metadata.expires_at}。${ALIPAY_COLLECTION_NOTICE}`;
|
|
1910
|
+
}
|
|
1757
1911
|
function handoffResultText(result) {
|
|
1758
1912
|
switch (result.kind) {
|
|
1759
1913
|
case "delivered": {
|
|
@@ -1800,6 +1954,18 @@ async function executeHandoffForCandidate(deps, args) {
|
|
|
1800
1954
|
error: "任务记录缺少 agreement 快照,交接中止(fail-closed)",
|
|
1801
1955
|
};
|
|
1802
1956
|
}
|
|
1957
|
+
const collection = resolveAlipayCollection(agreement, Date.parse(deps.now()));
|
|
1958
|
+
const collectionLink = collection.kind === "collection" ? collection.link : undefined;
|
|
1959
|
+
if (collection.kind !== "ordinary" || isAlipayCollectionDestination(a.candidate.destination_ref)) {
|
|
1960
|
+
if (deps.alipayCollectionAvailable !== true || collectionLink === undefined ||
|
|
1961
|
+
deps.store.getTask(a.task_id)?.status !== "selected_nonbinding" ||
|
|
1962
|
+
a.candidate.agreement_id !== agreement.agreement_id || a.candidate.negotiation_id !== agreement.negotiation_id ||
|
|
1963
|
+
a.candidate.terms_digest !== agreement.terms_digest ||
|
|
1964
|
+
a.candidate.merchant_identity_ref !== agreement.merchant_identity_ref ||
|
|
1965
|
+
a.candidate.destination_type !== "external_checkout_url" || a.candidate.destination_ref !== collectionLink.url) {
|
|
1966
|
+
return { ok: false, status: "stale", error: "支付宝交接不再匹配当前协议、目的地或终端能力。" };
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1803
1969
|
// ── A651 包四:三平台市场形态 URL 目的地的强制交易门输入 ─────────────
|
|
1804
1970
|
// 审批链带回的 sidecar + 执行期 configured CatalogSource 新鲜重读;市场
|
|
1805
1971
|
// 形态目的地无 sidecar(或不配置来源)→ executeHandoff 固定
|
|
@@ -1879,30 +2045,57 @@ async function executeHandoffForCandidate(deps, args) {
|
|
|
1879
2045
|
negotiation_id: agreement.negotiation_id,
|
|
1880
2046
|
agreed_terms: agreement.agreed_terms,
|
|
1881
2047
|
}),
|
|
1882
|
-
urlSafety: (url) =>
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
try {
|
|
1891
|
-
parsed = parseMarketplaceTradeUrl(hopUrl);
|
|
1892
|
-
}
|
|
1893
|
-
catch {
|
|
1894
|
-
throw new CommerceError("invalid_input", "destination hop left the marketplace trade form (same platform, same product id required)");
|
|
1895
|
-
}
|
|
1896
|
-
if (!sameMarketplaceTarget(parsed, launchTarget)) {
|
|
1897
|
-
throw new CommerceError("invalid_input", "destination redirect changed platform product identity");
|
|
1898
|
-
}
|
|
2048
|
+
urlSafety: async (url) => {
|
|
2049
|
+
if (collection.kind === "collection") {
|
|
2050
|
+
const safe = await validateExternalDestinationUrl(url, {
|
|
2051
|
+
expectedHost: new URL(collection.link.origin).hostname,
|
|
2052
|
+
maxRedirects: 0,
|
|
2053
|
+
onHop: (hop) => {
|
|
2054
|
+
if (hop !== collection.link.url)
|
|
2055
|
+
throw new CommerceError("invalid_input", "collection destination changed");
|
|
1899
2056
|
},
|
|
2057
|
+
});
|
|
2058
|
+
const fresh = resolveTaskAlipayCollection(deps.store.taskEvents(a.task_id), Date.parse(deps.now()));
|
|
2059
|
+
if (safe.finalUrl !== collection.link.url || fresh.kind !== "collection" ||
|
|
2060
|
+
fresh.link.url !== collection.link.url || fresh.agreementId !== collection.agreementId ||
|
|
2061
|
+
fresh.termsDigest !== collection.termsDigest || deps.store.getTask(a.task_id)?.status !== "selected_nonbinding") {
|
|
2062
|
+
throw new CommerceError("invalid_input", "collection agreement no longer matches the approved destination");
|
|
1900
2063
|
}
|
|
1901
|
-
|
|
1902
|
-
|
|
2064
|
+
return safe;
|
|
2065
|
+
}
|
|
2066
|
+
return validateExternalDestinationUrl(url, {
|
|
2067
|
+
...(agreement.merchant_domain !== undefined ? { expectedHost: agreement.merchant_domain } : {}),
|
|
2068
|
+
...(declaredHost !== undefined ? { allowlist: [declaredHost] } : {}),
|
|
2069
|
+
allowHttp: false,
|
|
2070
|
+
onHop: (hopUrl) => {
|
|
2071
|
+
if (isAlipayCollectionDestination(hopUrl)) {
|
|
2072
|
+
throw new CommerceError("invalid_input", "ordinary handoff cannot redirect to an Alipay collection destination");
|
|
2073
|
+
}
|
|
2074
|
+
if (launchTarget === undefined)
|
|
2075
|
+
return;
|
|
2076
|
+
let parsed;
|
|
2077
|
+
try {
|
|
2078
|
+
parsed = parseMarketplaceTradeUrl(hopUrl);
|
|
2079
|
+
}
|
|
2080
|
+
catch {
|
|
2081
|
+
throw new CommerceError("invalid_input", "destination hop left the marketplace trade form (same platform, same product id required)");
|
|
2082
|
+
}
|
|
2083
|
+
if (!sameMarketplaceTarget(parsed, launchTarget)) {
|
|
2084
|
+
throw new CommerceError("invalid_input", "destination redirect changed platform product identity");
|
|
2085
|
+
}
|
|
2086
|
+
},
|
|
2087
|
+
});
|
|
2088
|
+
},
|
|
1903
2089
|
...(launchContext !== undefined ? { launchContext } : {}),
|
|
1904
2090
|
now: deps.now,
|
|
1905
2091
|
});
|
|
2092
|
+
if (collection.kind === "collection") {
|
|
2093
|
+
if (result.kind === "delivered" || result.kind === "already_delivered") {
|
|
2094
|
+
const handoffId = result.kind === "delivered" ? result.handoff.handoff_id : result.handoff_id;
|
|
2095
|
+
return alipayDeliveryResult(result.kind, handoffId, collection.link.negotiationId);
|
|
2096
|
+
}
|
|
2097
|
+
return { ok: false, status: result.kind, text: "支付宝收款入口未交付;请重新核对协议及其有效期。" };
|
|
2098
|
+
}
|
|
1906
2099
|
const rendered = handoffResultText(result);
|
|
1907
2100
|
return {
|
|
1908
2101
|
ok: result.kind === "delivered" || result.kind === "already_delivered",
|