@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
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
const DEFAULT_INTERVAL_MS = 30_000;
|
|
17
|
+
const DEFAULT_LEASE_MS = 120_000;
|
|
18
|
+
const DEFAULT_EXECUTION_TIMEOUT_MS = 60_000;
|
|
19
|
+
function isNotOwner(err) {
|
|
20
|
+
const code = err?.code;
|
|
21
|
+
return code === "not_acquired" || code === "feature_disabled" || code === "not_owner";
|
|
22
|
+
}
|
|
23
|
+
/** 建议中的证据引用必须是任务快照里出现过的引用(防止模型编造来源)。 */
|
|
24
|
+
export function collectSnapshotRefs(value, output = new Set()) {
|
|
25
|
+
if (typeof value === "string")
|
|
26
|
+
return output;
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
for (const item of value)
|
|
29
|
+
collectSnapshotRefs(item, output);
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
if (value !== null && typeof value === "object") {
|
|
33
|
+
for (const [key, item] of Object.entries(value)) {
|
|
34
|
+
if (typeof item === "string" && /ref|evidence/i.test(key))
|
|
35
|
+
output.add(item);
|
|
36
|
+
else if (Array.isArray(item) && /ref|evidence/i.test(key)) {
|
|
37
|
+
for (const entry of item)
|
|
38
|
+
if (typeof entry === "string")
|
|
39
|
+
output.add(entry);
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
collectSnapshotRefs(item, output);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return output;
|
|
46
|
+
}
|
|
47
|
+
export function invalidEvidenceRefs(adviceRefs, payload) {
|
|
48
|
+
const allowed = collectSnapshotRefs(payload);
|
|
49
|
+
return adviceRefs.filter((ref) => !allowed.has(ref));
|
|
50
|
+
}
|
|
51
|
+
export class OperationsScheduler {
|
|
52
|
+
options;
|
|
53
|
+
timer;
|
|
54
|
+
stopped = false;
|
|
55
|
+
constructor(options) {
|
|
56
|
+
this.options = options;
|
|
57
|
+
}
|
|
58
|
+
withWrite(work) {
|
|
59
|
+
return this.options.write !== undefined ? this.options.write(work) : work();
|
|
60
|
+
}
|
|
61
|
+
get isRunning() {
|
|
62
|
+
return this.timer !== undefined && !this.stopped;
|
|
63
|
+
}
|
|
64
|
+
start() {
|
|
65
|
+
if (this.timer !== undefined)
|
|
66
|
+
return;
|
|
67
|
+
this.stopped = false;
|
|
68
|
+
this.timer = setInterval(() => {
|
|
69
|
+
void this.tick().catch((err) => {
|
|
70
|
+
this.options.log?.(`[operations scheduler] tick failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
71
|
+
});
|
|
72
|
+
}, this.options.interval_ms ?? DEFAULT_INTERVAL_MS);
|
|
73
|
+
this.timer.unref?.();
|
|
74
|
+
}
|
|
75
|
+
stop() {
|
|
76
|
+
this.stopped = true;
|
|
77
|
+
if (this.timer !== undefined) {
|
|
78
|
+
clearInterval(this.timer);
|
|
79
|
+
this.timer = undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async tick() {
|
|
83
|
+
const result = { evaluations: 0, claimed: 0, committed: 0, failed: 0, stopped: false };
|
|
84
|
+
if (this.stopped)
|
|
85
|
+
return { ...result, stopped: true };
|
|
86
|
+
try {
|
|
87
|
+
this.options.assertOwner();
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
this.stop();
|
|
91
|
+
return { ...result, stopped: true };
|
|
92
|
+
}
|
|
93
|
+
const merchantId = this.options.merchant_id;
|
|
94
|
+
const workerId = this.options.worker_id ?? `ops-scheduler:${process.pid}`;
|
|
95
|
+
const prefilter = this.options.prefilter ??
|
|
96
|
+
(() => ({
|
|
97
|
+
result: "data_incomplete",
|
|
98
|
+
reason_code: "projection_unavailable",
|
|
99
|
+
detail: { missing: "projection" },
|
|
100
|
+
}));
|
|
101
|
+
const evaluations = this.withWrite(() => this.options.service.evaluateDue({ merchant_id: merchantId, prefilter }));
|
|
102
|
+
result.evaluations = evaluations.length;
|
|
103
|
+
const maxTasks = this.options.max_tasks_per_tick ?? 5;
|
|
104
|
+
for (let index = 0; index < maxTasks; index += 1) {
|
|
105
|
+
try {
|
|
106
|
+
this.options.assertOwner();
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
this.stop();
|
|
110
|
+
result.stopped = true;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
const claimed = this.withWrite(() => this.options.service.claimDue({
|
|
114
|
+
merchant_id: merchantId,
|
|
115
|
+
worker_id: workerId,
|
|
116
|
+
lease_ms: this.options.lease_ms ?? DEFAULT_LEASE_MS,
|
|
117
|
+
}));
|
|
118
|
+
if (claimed === undefined)
|
|
119
|
+
break;
|
|
120
|
+
result.claimed += 1;
|
|
121
|
+
const rule = claimed.rule_id === null ? undefined : this.options.service.getRule(merchantId, claimed.rule_id);
|
|
122
|
+
if (rule === undefined) {
|
|
123
|
+
this.options.service.failClaimedTask({
|
|
124
|
+
merchant_id: merchantId,
|
|
125
|
+
task_id: claimed.task_id,
|
|
126
|
+
worker_id: workerId,
|
|
127
|
+
fencing: claimed.fencing_token,
|
|
128
|
+
error_code: "rule_missing",
|
|
129
|
+
});
|
|
130
|
+
result.failed += 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const remaining = claimed.deadline_at === null
|
|
134
|
+
? Number.POSITIVE_INFINITY
|
|
135
|
+
: Date.parse(claimed.deadline_at) - Date.parse(this.options.now());
|
|
136
|
+
if (remaining <= 0) {
|
|
137
|
+
// 截止后不再发起模型调用;记失败并让退避/截止守卫处理。
|
|
138
|
+
this.options.service.failClaimedTask({
|
|
139
|
+
merchant_id: merchantId,
|
|
140
|
+
task_id: claimed.task_id,
|
|
141
|
+
worker_id: workerId,
|
|
142
|
+
fencing: claimed.fencing_token,
|
|
143
|
+
error_code: "deadline_exceeded",
|
|
144
|
+
});
|
|
145
|
+
result.failed += 1;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const timeoutMs = Math.min(this.options.execution_timeout_ms ?? DEFAULT_EXECUTION_TIMEOUT_MS, remaining);
|
|
149
|
+
let timeoutHandle;
|
|
150
|
+
try {
|
|
151
|
+
const adviceRun = await Promise.race([
|
|
152
|
+
this.options.runner({ rule, task: { task_id: claimed.task_id, payload: claimed.payload } }),
|
|
153
|
+
new Promise((_resolve, reject) => {
|
|
154
|
+
timeoutHandle = setTimeout(() => reject(new Error("executor_timeout")), timeoutMs);
|
|
155
|
+
timeoutHandle.unref?.();
|
|
156
|
+
}),
|
|
157
|
+
]);
|
|
158
|
+
const invalid = invalidEvidenceRefs(adviceRun.advice.evidence_refs, claimed.payload);
|
|
159
|
+
const commitInput = invalid.length > 0
|
|
160
|
+
? {
|
|
161
|
+
result_kind: "data_issue",
|
|
162
|
+
payload: {
|
|
163
|
+
reason_code: "invalid_evidence_refs",
|
|
164
|
+
invalid_refs: invalid,
|
|
165
|
+
summary: "模型建议引用了任务快照中不存在的证据,已转为数据缺证待办。",
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
: {
|
|
169
|
+
result_kind: adviceRun.advice.kind,
|
|
170
|
+
payload: { advice: adviceRun.advice },
|
|
171
|
+
};
|
|
172
|
+
this.options.assertOwner();
|
|
173
|
+
this.withWrite(() => this.options.service.commitInternalResult({
|
|
174
|
+
merchant_id: merchantId,
|
|
175
|
+
task_id: claimed.task_id,
|
|
176
|
+
worker_id: workerId,
|
|
177
|
+
fencing: claimed.fencing_token,
|
|
178
|
+
expected_revision: claimed.revision,
|
|
179
|
+
expected_cancel_epoch: claimed.cancel_epoch,
|
|
180
|
+
result_kind: commitInput.result_kind,
|
|
181
|
+
payload: commitInput.payload,
|
|
182
|
+
...(invalid.length === 0
|
|
183
|
+
? { usage: { input: adviceRun.usage.input, output: adviceRun.usage.output } }
|
|
184
|
+
: {}),
|
|
185
|
+
}));
|
|
186
|
+
result.committed += 1;
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
if (isNotOwner(err)) {
|
|
190
|
+
this.stop();
|
|
191
|
+
result.stopped = true;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
result.failed += 1;
|
|
195
|
+
// P2-1:模型/SDK 错误消息可能含换行等控制字符,直接作为 error_code
|
|
196
|
+
// 会让 failClaimedTask 在写库前校验失败;先清洗再落库。
|
|
197
|
+
const rawMessage = err instanceof Error ? err.message : "";
|
|
198
|
+
// eslint-disable-next-line no-control-regex
|
|
199
|
+
const errorCode = rawMessage.replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, 100) || "executor_error";
|
|
200
|
+
try {
|
|
201
|
+
this.options.service.failClaimedTask({
|
|
202
|
+
merchant_id: merchantId,
|
|
203
|
+
task_id: claimed.task_id,
|
|
204
|
+
worker_id: workerId,
|
|
205
|
+
fencing: claimed.fencing_token,
|
|
206
|
+
error_code: errorCode,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
// 任务已被取消/租约失效:保留现状,交 sweep 处理。
|
|
211
|
+
}
|
|
212
|
+
// retryTask 独立 try:fail 成功但 retry 超限时保留 FAILED 即可,
|
|
213
|
+
// 不能因为重试失败而跳过失败落库。
|
|
214
|
+
try {
|
|
215
|
+
this.options.service.retryTask({
|
|
216
|
+
merchant_id: merchantId,
|
|
217
|
+
task_id: claimed.task_id,
|
|
218
|
+
backoff_ms: 15_000,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
// 已达重试上限/任务已被取消:保留 FAILED,交人工核对。
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
finally {
|
|
226
|
+
if (timeoutHandle !== undefined)
|
|
227
|
+
clearTimeout(timeoutHandle);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../../src/merchant-core/operations-jobs/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA0CH,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AACjC,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAE5C,SAAS,UAAU,CAAC,GAAY;IAC9B,MAAM,IAAI,GAAI,GAAiC,EAAE,IAAI,CAAC;IACtD,OAAO,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,kBAAkB,IAAI,IAAI,KAAK,WAAW,CAAC;AACxF,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,mBAAmB,CAAC,KAAc,EAAE,SAAS,IAAI,GAAG,EAAU;IAC5E,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC7C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC5D,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;YAC3E,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC;gB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O,EAAE,OAAO,CAAC,aAAa;wBAC9B,UAAU,EAAE,SAAS;qBACtB,CAAC,CAAC;gBACL,CAAC;gBAAC,MAAM,CAAC;oBACP,+BAA+B;gBACjC,CAAC;gBACD,mDAAmD;gBACnD,mBAAmB;gBACnB,IAAI,CAAC;oBACH,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;wBAC7B,WAAW,EAAE,UAAU;wBACvB,OAAO,EAAE,OAAO,CAAC,OAAO;wBACxB,UAAU,EAAE,MAAM;qBACnB,CAAC,CAAC;gBACL,CAAC;gBAAC,MAAM,CAAC;oBACP,iCAAiC;gBACnC,CAAC;YACH,CAAC;oBAAS,CAAC;gBACT,IAAI,aAAa,KAAK,SAAS;oBAAE,YAAY,CAAC,aAAa,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
17
|
+
import { BackgroundBudgetStore } from "../budget/background-budget.js";
|
|
18
|
+
export type OperationsJobsErrorCode = "validation" | "not_found" | "conflict" | "version_conflict" | "invalid_transition" | "budget_exhausted" | "idempotency_conflict";
|
|
19
|
+
export declare class OperationsJobsError extends Error {
|
|
20
|
+
readonly code: OperationsJobsErrorCode;
|
|
21
|
+
readonly reason: string;
|
|
22
|
+
constructor(code: OperationsJobsErrorCode, reason: string, message: string);
|
|
23
|
+
}
|
|
24
|
+
export declare const RULE_TEMPLATES: readonly ["unfinished_inquiry_digest", "missing_info_draft", "quote_expiry_review", "data_availability_check"];
|
|
25
|
+
export type RuleTemplate = (typeof RULE_TEMPLATES)[number];
|
|
26
|
+
export declare const RULE_ACTION_TYPES: readonly ["internal_summary", "internal_draft", "merchant_todo"];
|
|
27
|
+
export type RuleActionType = (typeof RULE_ACTION_TYPES)[number];
|
|
28
|
+
/** 来源版本只接受纯数字或 vN;其他形式按“无权威版本”处理(不回滚事实)。 */
|
|
29
|
+
export declare function parseSourceVersionRank(value: string | undefined): number | undefined;
|
|
30
|
+
export type RuleState = "ACTIVE" | "PAUSED";
|
|
31
|
+
export interface RuleTriggerSpec {
|
|
32
|
+
readonly kind: "daily_local";
|
|
33
|
+
readonly local_time: string;
|
|
34
|
+
readonly timezone: string;
|
|
35
|
+
}
|
|
36
|
+
export interface RuleScopeSpec {
|
|
37
|
+
readonly sku?: string;
|
|
38
|
+
readonly status?: string;
|
|
39
|
+
readonly window: "previous_local_day" | "last_7_days";
|
|
40
|
+
}
|
|
41
|
+
export interface RulePredicateSpec {
|
|
42
|
+
readonly kind: "fixed_template";
|
|
43
|
+
readonly template: RuleTemplate;
|
|
44
|
+
readonly threshold?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface RuleBudgetSpec {
|
|
47
|
+
readonly max_runs_per_day: number;
|
|
48
|
+
}
|
|
49
|
+
export interface AutomationRule {
|
|
50
|
+
readonly rule_id: string;
|
|
51
|
+
readonly merchant_id: string;
|
|
52
|
+
readonly version: number;
|
|
53
|
+
readonly template: RuleTemplate;
|
|
54
|
+
readonly trigger_spec: RuleTriggerSpec;
|
|
55
|
+
readonly timezone: string;
|
|
56
|
+
readonly scope: RuleScopeSpec;
|
|
57
|
+
readonly predicate_spec: RulePredicateSpec;
|
|
58
|
+
readonly action_type: RuleActionType;
|
|
59
|
+
readonly budget: RuleBudgetSpec;
|
|
60
|
+
readonly authorization_ref: string | null;
|
|
61
|
+
readonly effective_at: string;
|
|
62
|
+
readonly expires_at: string;
|
|
63
|
+
readonly content_hash: string;
|
|
64
|
+
readonly state: RuleState;
|
|
65
|
+
readonly enable_epoch: number;
|
|
66
|
+
readonly next_due_at: string | null;
|
|
67
|
+
readonly missed_count: number;
|
|
68
|
+
readonly created_at: string;
|
|
69
|
+
readonly updated_at: string;
|
|
70
|
+
}
|
|
71
|
+
export interface RuleCandidate {
|
|
72
|
+
readonly candidate_ref: string;
|
|
73
|
+
readonly merchant_id: string;
|
|
74
|
+
readonly mode: "template" | "goal";
|
|
75
|
+
readonly template: RuleTemplate;
|
|
76
|
+
readonly trigger_spec: RuleTriggerSpec;
|
|
77
|
+
readonly timezone: string;
|
|
78
|
+
readonly scope: RuleScopeSpec;
|
|
79
|
+
readonly predicate_spec: RulePredicateSpec;
|
|
80
|
+
readonly action_type: RuleActionType;
|
|
81
|
+
readonly budget: RuleBudgetSpec;
|
|
82
|
+
readonly goal_text: string | null;
|
|
83
|
+
readonly content_hash: string;
|
|
84
|
+
readonly requires_confirmation: true;
|
|
85
|
+
readonly created_at: string;
|
|
86
|
+
}
|
|
87
|
+
export type EvaluationOutcome = "no_change" | "blocked" | "eligible" | "superseded" | "data_incomplete";
|
|
88
|
+
export interface PrefilterResult {
|
|
89
|
+
readonly result: EvaluationOutcome;
|
|
90
|
+
readonly reason_code?: string;
|
|
91
|
+
readonly window_start?: string;
|
|
92
|
+
readonly window_end?: string;
|
|
93
|
+
readonly detail?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
export interface RuleEvaluation {
|
|
96
|
+
readonly evaluation_id: string;
|
|
97
|
+
readonly merchant_id: string;
|
|
98
|
+
readonly rule_id: string;
|
|
99
|
+
readonly rule_version: number;
|
|
100
|
+
readonly trigger_key: string;
|
|
101
|
+
readonly result: EvaluationOutcome;
|
|
102
|
+
readonly reason_code: string | null;
|
|
103
|
+
readonly window_start: string | null;
|
|
104
|
+
readonly window_end: string | null;
|
|
105
|
+
readonly detail: Record<string, unknown>;
|
|
106
|
+
readonly evaluated_at: string;
|
|
107
|
+
}
|
|
108
|
+
export interface ClaimedTask {
|
|
109
|
+
readonly task_id: string;
|
|
110
|
+
readonly merchant_id: string;
|
|
111
|
+
readonly rule_id: string | null;
|
|
112
|
+
readonly rule_version: number | null;
|
|
113
|
+
readonly status: string;
|
|
114
|
+
readonly due_at: string | null;
|
|
115
|
+
readonly attempts: number;
|
|
116
|
+
readonly max_attempts: number;
|
|
117
|
+
readonly fencing_token: number;
|
|
118
|
+
readonly revision: number;
|
|
119
|
+
readonly cancel_epoch: number;
|
|
120
|
+
readonly deadline_at: string | null;
|
|
121
|
+
readonly snapshot_digest: string | null;
|
|
122
|
+
readonly payload: Record<string, unknown>;
|
|
123
|
+
}
|
|
124
|
+
export interface InternalResultCommit {
|
|
125
|
+
readonly receipt_ref: string;
|
|
126
|
+
readonly artifact_id: string;
|
|
127
|
+
readonly task_id: string;
|
|
128
|
+
readonly result_kind: string;
|
|
129
|
+
readonly content_digest: string;
|
|
130
|
+
}
|
|
131
|
+
/** 下一次本地 daily 时间(60 秒粒度);夏令时/时区变更靠重算 offset 收敛。 */
|
|
132
|
+
export declare function nextDailyDueAt(input: {
|
|
133
|
+
now: string;
|
|
134
|
+
local_time: string;
|
|
135
|
+
timezone: string;
|
|
136
|
+
}): string;
|
|
137
|
+
export interface OperationsJobsServiceOptions {
|
|
138
|
+
db: DatabaseSync;
|
|
139
|
+
now: () => string;
|
|
140
|
+
budgetStore?: BackgroundBudgetStore;
|
|
141
|
+
}
|
|
142
|
+
export declare class OperationsJobsService {
|
|
143
|
+
private readonly db;
|
|
144
|
+
private readonly now;
|
|
145
|
+
private readonly budgetStore?;
|
|
146
|
+
constructor(options: OperationsJobsServiceOptions);
|
|
147
|
+
ingestTrustedEvent(input: {
|
|
148
|
+
merchant_id: string;
|
|
149
|
+
source_scope: string;
|
|
150
|
+
external_event_id: string;
|
|
151
|
+
payload_digest: string;
|
|
152
|
+
entity_ref: string;
|
|
153
|
+
source_version?: string;
|
|
154
|
+
occurred_at: string;
|
|
155
|
+
received_at?: string;
|
|
156
|
+
evidence_ref?: string;
|
|
157
|
+
}): {
|
|
158
|
+
status: "accepted" | "duplicate" | "superseded";
|
|
159
|
+
inbox_id: string;
|
|
160
|
+
};
|
|
161
|
+
prepareRule(input: {
|
|
162
|
+
merchant_id: string;
|
|
163
|
+
mode: "template" | "goal";
|
|
164
|
+
template: RuleTemplate;
|
|
165
|
+
trigger_spec: RuleTriggerSpec;
|
|
166
|
+
scope: RuleScopeSpec;
|
|
167
|
+
predicate_spec: RulePredicateSpec;
|
|
168
|
+
action_type: RuleActionType;
|
|
169
|
+
budget: RuleBudgetSpec;
|
|
170
|
+
goal_text?: string;
|
|
171
|
+
}): RuleCandidate;
|
|
172
|
+
activateRule(input: {
|
|
173
|
+
merchant_id: string;
|
|
174
|
+
candidate_ref: string;
|
|
175
|
+
expected_generation?: number;
|
|
176
|
+
}): AutomationRule;
|
|
177
|
+
pauseRule(input: {
|
|
178
|
+
merchant_id: string;
|
|
179
|
+
rule_id: string;
|
|
180
|
+
expected_version: number;
|
|
181
|
+
reason: string;
|
|
182
|
+
}): AutomationRule;
|
|
183
|
+
listRules(merchantId: string): AutomationRule[];
|
|
184
|
+
getRule(merchantId: string, ruleId: string): AutomationRule | undefined;
|
|
185
|
+
/**
|
|
186
|
+
* 评估到期规则。prefilter 缺失时记为 data_incomplete(不伪造 no_change)。
|
|
187
|
+
* eligible 在同事务写评估 + 创建 READY 任务;预算不足只记 blocked。
|
|
188
|
+
*/
|
|
189
|
+
evaluateDue(input: {
|
|
190
|
+
merchant_id: string;
|
|
191
|
+
prefilter?: (rule: AutomationRule) => PrefilterResult;
|
|
192
|
+
now?: string;
|
|
193
|
+
}): RuleEvaluation[];
|
|
194
|
+
/** CAS 领取一个到期 READY 任务;创建 RUNNING attempt 并记录 worker/fencing。 */
|
|
195
|
+
claimDue(input: {
|
|
196
|
+
merchant_id: string;
|
|
197
|
+
worker_id: string;
|
|
198
|
+
lease_ms?: number;
|
|
199
|
+
now?: string;
|
|
200
|
+
}): ClaimedTask | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* 原子提交内部结果:校验 owner/fencing/revision/cancel_epoch/租约/截止/规则;
|
|
203
|
+
* 唯一产物 + attempt 回执 + 任务 SUCCEEDED 同事务;重复提交返回原回执。
|
|
204
|
+
*/
|
|
205
|
+
commitInternalResult(input: {
|
|
206
|
+
merchant_id: string;
|
|
207
|
+
task_id: string;
|
|
208
|
+
worker_id: string;
|
|
209
|
+
fencing: number;
|
|
210
|
+
expected_revision: number;
|
|
211
|
+
expected_cancel_epoch: number;
|
|
212
|
+
result_kind: string;
|
|
213
|
+
payload: Record<string, unknown>;
|
|
214
|
+
usage?: {
|
|
215
|
+
input: number;
|
|
216
|
+
output: number;
|
|
217
|
+
};
|
|
218
|
+
now?: string;
|
|
219
|
+
}): InternalResultCommit;
|
|
220
|
+
/** FAILED 且仍可重试:持久化退避后的 due_at,回到 PENDING。 */
|
|
221
|
+
retryTask(input: {
|
|
222
|
+
merchant_id: string;
|
|
223
|
+
task_id: string;
|
|
224
|
+
backoff_ms?: number;
|
|
225
|
+
/** 429/Retry-After:取与本地退避的较大值并持久化(C08)。 */
|
|
226
|
+
retry_after_ms?: number;
|
|
227
|
+
now?: string;
|
|
228
|
+
}): void;
|
|
229
|
+
listArtifacts(merchantId: string, taskId?: string): Array<{
|
|
230
|
+
artifact_id: string;
|
|
231
|
+
task_id: string;
|
|
232
|
+
result_kind: string;
|
|
233
|
+
content_digest: string;
|
|
234
|
+
receipt_ref: string;
|
|
235
|
+
created_at: string;
|
|
236
|
+
payload: Record<string, unknown>;
|
|
237
|
+
}>;
|
|
238
|
+
/** 未启动才归还;已经领取或结果不明则按预留额保守结算。 */
|
|
239
|
+
private closeReservation;
|
|
240
|
+
/**
|
|
241
|
+
* 执行器明确失败(模型错误/超时/证据无效):只允许当前 worker/fencing 在
|
|
242
|
+
* 租约内把 RUNNING 任务置为 FAILED;之后由 retryTask 持久化退避。外部调用
|
|
243
|
+
* 结果不明时不得调用本方法(应保留 UNKNOWN 供核对)。
|
|
244
|
+
*/
|
|
245
|
+
failClaimedTask(input: {
|
|
246
|
+
merchant_id: string;
|
|
247
|
+
task_id: string;
|
|
248
|
+
worker_id: string;
|
|
249
|
+
fencing: number;
|
|
250
|
+
error_code: string;
|
|
251
|
+
now?: string;
|
|
252
|
+
}): void;
|
|
253
|
+
/** 仅处理规则任务;过期 worker 不可继续提交,未知消耗不重试。 */
|
|
254
|
+
private sweepRuleTasks;
|
|
255
|
+
private requireRule;
|
|
256
|
+
/** C16:额度不足时保留 PENDING 任务(不占配额),等待下一次准入。 */
|
|
257
|
+
private enqueueBudgetWaitingTask;
|
|
258
|
+
private enqueueEligibleTask;
|
|
259
|
+
private advanceRule;
|
|
260
|
+
}
|