@harrylabsj/kiwi 0.12.30 → 0.12.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a2a/node.d.ts +1 -0
- package/dist/a2a/node.js +170 -2
- package/dist/a2a/node.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/merchant-handler.d.ts +56 -1
- package/dist/a2a/server/merchant-handler.js +659 -44
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/pipeline.js +74 -29
- package/dist/a2a/server/pipeline.js.map +1 -1
- package/dist/a2a/server/types.d.ts +2 -0
- 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/buyer/buyer-tools.js +1 -2
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/search-loop.js +0 -1
- package/dist/agent/buyer/search-loop.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-knp.d.ts +4 -2
- package/dist/buyer-core/a2a-knp.js +5 -2
- package/dist/buyer-core/a2a-knp.js.map +1 -1
- package/dist/buyer-core/a2a-negotiator.d.ts +1 -0
- package/dist/buyer-core/a2a-negotiator.js +18 -11
- package/dist/buyer-core/a2a-negotiator.js.map +1 -1
- package/dist/buyer-core/a2a-quote-fetcher.d.ts +25 -0
- package/dist/buyer-core/a2a-quote-fetcher.js +82 -4
- 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.js +0 -1
- 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/protocol-recovery.d.ts +2 -1
- package/dist/buyer-core/protocol-recovery.js +14 -4
- package/dist/buyer-core/protocol-recovery.js.map +1 -1
- package/dist/buyer-core/service.d.ts +58 -5
- package/dist/buyer-core/service.js +279 -53
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/buyer-core/store.d.ts +8 -0
- package/dist/buyer-core/store.js +37 -7
- package/dist/buyer-core/store.js.map +1 -1
- package/dist/cli.js +136 -34
- package/dist/cli.js.map +1 -1
- package/dist/cloud/bootstrap.d.ts +1 -1
- package/dist/cloud/bootstrap.js +162 -35
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/product-import-tabular.js +13 -5
- package/dist/cloud/product-import-tabular.js.map +1 -1
- package/dist/cloud/trade-platforms-client.d.ts +30 -0
- package/dist/cloud/trade-platforms-client.js +34 -1
- package/dist/cloud/trade-platforms-client.js.map +1 -1
- package/dist/commerce/receipt/dispatcher.d.ts +42 -0
- package/dist/commerce/receipt/dispatcher.js +68 -0
- package/dist/commerce/receipt/dispatcher.js.map +1 -0
- package/dist/commerce/receipt/receipts.d.ts +140 -0
- package/dist/commerce/receipt/receipts.js +247 -0
- package/dist/commerce/receipt/receipts.js.map +1 -0
- package/dist/config/profile.d.ts +2 -2
- package/dist/handoff/order-receipts.d.ts +62 -0
- package/dist/handoff/order-receipts.js +71 -0
- package/dist/handoff/order-receipts.js.map +1 -0
- package/dist/handoff/trade-platform-rules.js +5 -2
- package/dist/handoff/trade-platform-rules.js.map +1 -1
- 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 +6 -0
- package/dist/handoff/ucp-checkout/channel.js +44 -0
- 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 +11 -1
- package/dist/http/merchant-management/api.js +471 -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.js +83 -22
- package/dist/http/merchant-management/page.js.map +1 -1
- package/dist/mcp/cli.js +6 -0
- 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 +93 -3
- 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/tools.js +12 -3
- package/dist/mcp/tools.js.map +1 -1
- package/dist/merchant/application/actor.d.ts +1 -1
- package/dist/merchant/application/actor.js +15 -0
- package/dist/merchant/application/actor.js.map +1 -1
- package/dist/merchant/workbench-server.d.ts +38 -0
- package/dist/merchant/workbench-server.js +428 -0
- package/dist/merchant/workbench-server.js.map +1 -0
- 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/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/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/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/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/storage/transaction.d.ts +102 -7
- package/dist/merchant-core/storage/transaction.js +274 -3
- 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-gateway/catalog-tools.js +4 -2
- package/dist/merchant-gateway/catalog-tools.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/product-buyer.d.ts +1 -0
- package/dist/product-buyer.js +0 -1
- package/dist/product-buyer.js.map +1 -1
- package/dist/product-cli.js +11 -1
- package/dist/product-cli.js.map +1 -1
- package/package.json +5 -3
- package/skills/kiwi-buyer/SKILL.md +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* 试点观测口径(设计 v1.1 §20.2 / M5)。
|
|
18
|
+
*
|
|
19
|
+
* 只从持久记录计算可复核计数与比率;不读取客户正文、密钥或底价。
|
|
20
|
+
* 分母为 0 时返回 null(显示为“无数据”),不伪造 0 或 100%。
|
|
21
|
+
*/
|
|
22
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
23
|
+
export interface PilotMetric {
|
|
24
|
+
readonly numerator: number;
|
|
25
|
+
readonly denominator: number;
|
|
26
|
+
/** null = 无数据;不要用 0 冒充。 */
|
|
27
|
+
readonly value: number | null;
|
|
28
|
+
readonly note?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface PilotMetricsReport {
|
|
31
|
+
readonly merchant_id: string;
|
|
32
|
+
readonly window_start: string | null;
|
|
33
|
+
readonly window_end: string;
|
|
34
|
+
readonly corrections: {
|
|
35
|
+
readonly total: number;
|
|
36
|
+
readonly rejected: number;
|
|
37
|
+
};
|
|
38
|
+
readonly repeat_correction_rate: PilotMetric;
|
|
39
|
+
readonly candidates: {
|
|
40
|
+
readonly total: number;
|
|
41
|
+
readonly ready_for_review: number;
|
|
42
|
+
readonly evaluation_failed: number;
|
|
43
|
+
readonly stale: number;
|
|
44
|
+
};
|
|
45
|
+
readonly skills: {
|
|
46
|
+
readonly active_releases: number;
|
|
47
|
+
readonly revoked_releases: number;
|
|
48
|
+
readonly hard_gate_failures: number;
|
|
49
|
+
};
|
|
50
|
+
readonly memory: {
|
|
51
|
+
readonly active: number;
|
|
52
|
+
readonly candidates: number;
|
|
53
|
+
readonly deleted: number;
|
|
54
|
+
};
|
|
55
|
+
readonly tasks: {
|
|
56
|
+
readonly pending: number;
|
|
57
|
+
readonly running: number;
|
|
58
|
+
readonly succeeded: number;
|
|
59
|
+
readonly failed: number;
|
|
60
|
+
readonly unknown: number;
|
|
61
|
+
readonly budget_blocked_evaluations: number;
|
|
62
|
+
};
|
|
63
|
+
readonly accuracy_notes: readonly string[];
|
|
64
|
+
}
|
|
65
|
+
export declare function computePilotMetrics(input: {
|
|
66
|
+
db: DatabaseSync;
|
|
67
|
+
merchantId: string;
|
|
68
|
+
since?: string;
|
|
69
|
+
until?: string;
|
|
70
|
+
}): PilotMetricsReport;
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
function ratio(numerator, denominator) {
|
|
17
|
+
return {
|
|
18
|
+
numerator,
|
|
19
|
+
denominator,
|
|
20
|
+
value: denominator === 0 ? null : numerator / denominator,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function computePilotMetrics(input) {
|
|
24
|
+
const { db, merchantId } = input;
|
|
25
|
+
const until = input.until ?? new Date().toISOString();
|
|
26
|
+
const since = input.since ?? null;
|
|
27
|
+
const timeFilter = (column) => since === null
|
|
28
|
+
? { sql: `${column} <= ?`, params: [until] }
|
|
29
|
+
: { sql: `${column} >= ? AND ${column} <= ?`, params: [since, until] };
|
|
30
|
+
const count = (sql, params) => Number(db.prepare(sql).get(...params)?.n ?? 0);
|
|
31
|
+
const correctionWindow = timeFilter("created_at");
|
|
32
|
+
const correctionsTotal = count(`SELECT COUNT(*) AS n FROM learning_corrections WHERE merchant_id = ? AND ${correctionWindow.sql}`, [merchantId, ...correctionWindow.params]);
|
|
33
|
+
const rejections = count(`SELECT COUNT(*) AS n FROM learning_rejections WHERE merchant_id = ? AND ${correctionWindow.sql}`, [merchantId, ...correctionWindow.params]);
|
|
34
|
+
// 重复纠错:同一 issue tag 在窗口内出现在多个纠正中;分子为“再次出现”
|
|
35
|
+
// 的纠正数。tag 由商家选择,分类口径固定版本;沉默不视为正确。
|
|
36
|
+
const repeatedRows = db
|
|
37
|
+
.prepare(`SELECT COUNT(*) AS n FROM learning_corrections c
|
|
38
|
+
WHERE c.merchant_id = ? AND ${correctionWindow.sql.replaceAll("created_at", "c.created_at")}
|
|
39
|
+
AND EXISTS (
|
|
40
|
+
SELECT 1 FROM learning_corrections prev, json_each(c.issue_tags_json) tag
|
|
41
|
+
WHERE prev.merchant_id = c.merchant_id AND prev.correction_id != c.correction_id
|
|
42
|
+
AND prev.created_at < c.created_at
|
|
43
|
+
AND EXISTS (SELECT 1 FROM json_each(prev.issue_tags_json) ptag WHERE ptag.value = tag.value))`)
|
|
44
|
+
.get(merchantId, ...correctionWindow.params);
|
|
45
|
+
const correctionsWithTags = count(`SELECT COUNT(*) AS n FROM learning_corrections
|
|
46
|
+
WHERE merchant_id = ? AND json_array_length(issue_tags_json) > 0
|
|
47
|
+
AND ${correctionWindow.sql}`, [merchantId, ...correctionWindow.params]);
|
|
48
|
+
const candidates = {
|
|
49
|
+
total: count("SELECT COUNT(*) AS n FROM learning_candidates WHERE merchant_id = ?", [merchantId]),
|
|
50
|
+
ready_for_review: count("SELECT COUNT(*) AS n FROM learning_candidates WHERE merchant_id = ? AND state = 'READY_FOR_REVIEW'", [merchantId]),
|
|
51
|
+
evaluation_failed: count("SELECT COUNT(*) AS n FROM learning_candidates WHERE merchant_id = ? AND state = 'EVALUATION_FAILED'", [merchantId]),
|
|
52
|
+
stale: count("SELECT COUNT(*) AS n FROM learning_candidates WHERE merchant_id = ? AND state = 'STALE'", [merchantId]),
|
|
53
|
+
};
|
|
54
|
+
const hardGateRows = db
|
|
55
|
+
.prepare("SELECT report_json FROM learning_evaluations WHERE merchant_id = ? AND report_json IS NOT NULL")
|
|
56
|
+
.all(merchantId);
|
|
57
|
+
let hardGateFailures = 0;
|
|
58
|
+
for (const row of hardGateRows) {
|
|
59
|
+
const report = JSON.parse(row.report_json);
|
|
60
|
+
hardGateFailures += Number(report.hard_gate_failures ?? 0);
|
|
61
|
+
}
|
|
62
|
+
const memory = {
|
|
63
|
+
active: count(`SELECT COUNT(*) AS n FROM customer_memories WHERE merchant_id = ? AND state = 'active'
|
|
64
|
+
AND expires_at > ?`, [merchantId, until]),
|
|
65
|
+
candidates: count("SELECT COUNT(*) AS n FROM customer_memories WHERE merchant_id = ? AND state = 'candidate'", [merchantId]),
|
|
66
|
+
deleted: count("SELECT COUNT(*) AS n FROM customer_memories WHERE merchant_id = ? AND state = 'deleted'", [merchantId]),
|
|
67
|
+
};
|
|
68
|
+
const tasks = {
|
|
69
|
+
pending: count("SELECT COUNT(*) AS n FROM followup_tasks WHERE merchant_id = ? AND status IN ('PENDING','READY')", [merchantId]),
|
|
70
|
+
running: count("SELECT COUNT(*) AS n FROM followup_tasks WHERE merchant_id = ? AND status = 'RUNNING'", [merchantId]),
|
|
71
|
+
succeeded: count("SELECT COUNT(*) AS n FROM followup_tasks WHERE merchant_id = ? AND status = 'SUCCEEDED'", [merchantId]),
|
|
72
|
+
failed: count("SELECT COUNT(*) AS n FROM followup_tasks WHERE merchant_id = ? AND status = 'FAILED'", [merchantId]),
|
|
73
|
+
unknown: count("SELECT COUNT(*) AS n FROM followup_tasks WHERE merchant_id = ? AND status = 'UNKNOWN'", [merchantId]),
|
|
74
|
+
budget_blocked_evaluations: count("SELECT COUNT(*) AS n FROM rule_evaluations WHERE merchant_id = ? AND reason_code LIKE 'budget:%'", [merchantId]),
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
merchant_id: merchantId,
|
|
78
|
+
window_start: since,
|
|
79
|
+
window_end: until,
|
|
80
|
+
corrections: { total: correctionsTotal, rejected: rejections },
|
|
81
|
+
repeat_correction_rate: ratio(Number(repeatedRows?.n ?? 0), correctionsWithTags),
|
|
82
|
+
candidates,
|
|
83
|
+
skills: {
|
|
84
|
+
active_releases: count("SELECT COUNT(*) AS n FROM skill_releases WHERE merchant_id = ? AND state = 'ACTIVE'", [merchantId]),
|
|
85
|
+
revoked_releases: count("SELECT COUNT(*) AS n FROM skill_releases WHERE merchant_id = ? AND state = 'REVOKED'", [merchantId]),
|
|
86
|
+
hard_gate_failures: hardGateFailures,
|
|
87
|
+
},
|
|
88
|
+
memory,
|
|
89
|
+
tasks,
|
|
90
|
+
accuracy_notes: [
|
|
91
|
+
"重复纠错率按 issue_tags 再次出现近似计算;固定分类版本,沉默不视为正确。",
|
|
92
|
+
"记忆有效续接率/无效追问率需要接待运行 trace 抽样,当前报告只给可用计数。",
|
|
93
|
+
"任务成本按实际 usage 记录;usage_state=unknown 单独保留,不记为免费。",
|
|
94
|
+
"日报按时率需要按 due_at/截至窗口分组,当前给 PENDING/RUNNING/SUCCEEDED 计数。",
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=pilot-metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pilot-metrics.js","sourceRoot":"","sources":["../../../src/merchant-core/operations-jobs/pilot-metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAoDH,SAAS,KAAK,CAAC,SAAiB,EAAE,WAAmB;IACnD,OAAO;QACL,SAAS;QACT,WAAW;QACX,KAAK,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,GAAG,WAAW;KAC1D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAKnC;IACC,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACtD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC;IAClC,MAAM,UAAU,GAAG,CAAC,MAAc,EAAqC,EAAE,CACvE,KAAK,KAAK,IAAI;QACZ,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,MAAM,OAAO,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE;QAC5C,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,MAAM,aAAa,MAAM,OAAO,EAAE,MAAM,EAAE,CAAC,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AK,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,mBAAmB,CAAC;QAChF,UAAU;QACV,MAAM,EAAE;YACN,eAAe,EAAE,KAAK,CACpB,qFAAqF,EACrF,CAAC,UAAU,CAAC,CACb;YACD,gBAAgB,EAAE,KAAK,CACrB,sFAAsF,EACtF,CAAC,UAAU,CAAC,CACb;YACD,kBAAkB,EAAE,gBAAgB;SACrC;QACD,MAAM;QACN,KAAK;QACL,cAAc,EAAE;YACd,4CAA4C;YAC5C,0CAA0C;YAC1C,kDAAkD;YAClD,0DAA0D;SAC3D;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* 经营任务投影(设计 §15.2)。
|
|
18
|
+
*
|
|
19
|
+
* 把固定模板映射到本机持久数据,输出 no_change / eligible / data_incomplete。
|
|
20
|
+
* 只读、无模型调用;查询失败或必需表缺失时 data_incomplete,绝不伪造
|
|
21
|
+
* no_change。evidence_refs 只包含真实存在的机会/选项引用。
|
|
22
|
+
*/
|
|
23
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
24
|
+
import type { AutomationRule, PrefilterResult } from "./service.js";
|
|
25
|
+
export interface OperationsProjectionOptions {
|
|
26
|
+
readonly db: DatabaseSync;
|
|
27
|
+
readonly now: () => string;
|
|
28
|
+
/** 每类最多投影的候选数(超出标记 truncated)。 */
|
|
29
|
+
readonly max_candidates?: number;
|
|
30
|
+
}
|
|
31
|
+
export declare class OperationsProjection {
|
|
32
|
+
private readonly db;
|
|
33
|
+
private readonly now;
|
|
34
|
+
private readonly limit;
|
|
35
|
+
constructor(options: OperationsProjectionOptions);
|
|
36
|
+
private missingTables;
|
|
37
|
+
private window;
|
|
38
|
+
prefilter(rule: AutomationRule): PrefilterResult;
|
|
39
|
+
private byStatuses;
|
|
40
|
+
private expiringQuotes;
|
|
41
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
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 OPEN_STATUSES = [
|
|
17
|
+
"NEW",
|
|
18
|
+
"NEEDS_INFO",
|
|
19
|
+
"READY_FOR_PROPOSAL",
|
|
20
|
+
"PENDING_APPROVAL",
|
|
21
|
+
"WAITING_CUSTOMER",
|
|
22
|
+
"RESULT_UNVERIFIED",
|
|
23
|
+
];
|
|
24
|
+
const REQUIRED_TABLES = [
|
|
25
|
+
"sales_opportunities",
|
|
26
|
+
"opportunity_events",
|
|
27
|
+
"proposal_options",
|
|
28
|
+
"proposal_sets",
|
|
29
|
+
];
|
|
30
|
+
export class OperationsProjection {
|
|
31
|
+
db;
|
|
32
|
+
now;
|
|
33
|
+
limit;
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.db = options.db;
|
|
36
|
+
this.now = options.now;
|
|
37
|
+
this.limit = options.max_candidates ?? 20;
|
|
38
|
+
}
|
|
39
|
+
missingTables() {
|
|
40
|
+
try {
|
|
41
|
+
const rows = this.db
|
|
42
|
+
.prepare("SELECT name FROM sqlite_master WHERE type = 'table'")
|
|
43
|
+
.all();
|
|
44
|
+
const names = new Set(rows.map((row) => row.name));
|
|
45
|
+
return REQUIRED_TABLES.filter((table) => !names.has(table));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return [...REQUIRED_TABLES];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
window(rule) {
|
|
52
|
+
const end = Date.parse(rule.next_due_at ?? this.now());
|
|
53
|
+
const days = rule.scope.window === "last_7_days" ? 7 : 1;
|
|
54
|
+
return {
|
|
55
|
+
start: new Date(end - days * 86_400_000).toISOString(),
|
|
56
|
+
end: new Date(end).toISOString(),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
prefilter(rule) {
|
|
60
|
+
const missing = this.missingTables();
|
|
61
|
+
if (missing.length > 0) {
|
|
62
|
+
return {
|
|
63
|
+
result: "data_incomplete",
|
|
64
|
+
reason_code: "projection_unavailable",
|
|
65
|
+
detail: { missing_tables: missing, template: rule.template },
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const window = this.window(rule);
|
|
69
|
+
try {
|
|
70
|
+
if (rule.template === "data_availability_check") {
|
|
71
|
+
return {
|
|
72
|
+
result: "no_change",
|
|
73
|
+
detail: { template: rule.template, tables_ready: REQUIRED_TABLES.length },
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (rule.template === "missing_info_draft") {
|
|
77
|
+
return this.byStatuses(rule, ["NEEDS_INFO"], window);
|
|
78
|
+
}
|
|
79
|
+
if (rule.template === "quote_expiry_review") {
|
|
80
|
+
return this.expiringQuotes(rule, window);
|
|
81
|
+
}
|
|
82
|
+
return this.byStatuses(rule, [...OPEN_STATUSES], window);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
return {
|
|
86
|
+
result: "data_incomplete",
|
|
87
|
+
reason_code: "projection_read_failed",
|
|
88
|
+
detail: {
|
|
89
|
+
template: rule.template,
|
|
90
|
+
error: err instanceof Error ? err.message.slice(0, 200) : "projection_error",
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
byStatuses(rule, statuses, window) {
|
|
96
|
+
const placeholders = statuses.map(() => "?").join(",");
|
|
97
|
+
const rows = this.db
|
|
98
|
+
.prepare(`SELECT opportunity_id, status, updated_at FROM sales_opportunities
|
|
99
|
+
WHERE merchant_id = ? AND status IN (${placeholders})
|
|
100
|
+
ORDER BY updated_at DESC LIMIT ?`)
|
|
101
|
+
.all(rule.merchant_id, ...statuses, this.limit + 1);
|
|
102
|
+
if (rows.length === 0) {
|
|
103
|
+
return {
|
|
104
|
+
result: "no_change",
|
|
105
|
+
window_start: window.start,
|
|
106
|
+
window_end: window.end,
|
|
107
|
+
detail: { template: rule.template, candidates: 0 },
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const truncated = rows.length > this.limit;
|
|
111
|
+
const visible = rows.slice(0, this.limit);
|
|
112
|
+
return {
|
|
113
|
+
result: "eligible",
|
|
114
|
+
window_start: window.start,
|
|
115
|
+
window_end: window.end,
|
|
116
|
+
detail: {
|
|
117
|
+
template: rule.template,
|
|
118
|
+
candidates: rows.length,
|
|
119
|
+
...(truncated ? { truncated: true } : {}),
|
|
120
|
+
candidate_refs: visible.map((row) => `opportunity:${row.opportunity_id}`),
|
|
121
|
+
evidence_refs: visible.map((row) => `opportunity:${row.opportunity_id}`),
|
|
122
|
+
statuses: visible.map((row) => ({ ref: row.opportunity_id, status: row.status })),
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
expiringQuotes(rule, window) {
|
|
127
|
+
const horizon = new Date(Date.parse(window.end) + 72 * 3_600_000).toISOString();
|
|
128
|
+
const rows = this.db
|
|
129
|
+
.prepare(`SELECT o.set_id, o.option_id, o.valid_until FROM proposal_options o
|
|
130
|
+
JOIN proposal_sets s ON s.set_id = o.set_id AND s.merchant_id = ?
|
|
131
|
+
WHERE o.valid_until IS NOT NULL AND o.valid_until > ? AND o.valid_until <= ?
|
|
132
|
+
ORDER BY o.valid_until ASC LIMIT ?`)
|
|
133
|
+
.all(rule.merchant_id, window.end, horizon, this.limit + 1);
|
|
134
|
+
if (rows.length === 0) {
|
|
135
|
+
return {
|
|
136
|
+
result: "no_change",
|
|
137
|
+
window_start: window.start,
|
|
138
|
+
window_end: window.end,
|
|
139
|
+
detail: { template: rule.template, candidates: 0 },
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const visible = rows.slice(0, this.limit);
|
|
143
|
+
return {
|
|
144
|
+
result: "eligible",
|
|
145
|
+
window_start: window.start,
|
|
146
|
+
window_end: window.end,
|
|
147
|
+
detail: {
|
|
148
|
+
template: rule.template,
|
|
149
|
+
candidates: rows.length,
|
|
150
|
+
...(rows.length > this.limit ? { truncated: true } : {}),
|
|
151
|
+
candidate_refs: visible.map((row) => `proposal:${row.set_id}:${row.option_id}`),
|
|
152
|
+
evidence_refs: visible.map((row) => `proposal:${row.set_id}:${row.option_id}`),
|
|
153
|
+
expiring: visible,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../src/merchant-core/operations-jobs/projection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAaH,MAAM,aAAa,GAAG;IACpB,KAAK;IACL,YAAY;IACZ,oBAAoB;IACpB,kBAAkB;IAClB,kBAAk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AE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,UAAU;YAClB,YAAY,EAAE,MAAM,CAAC,KAAK;YAC1B,UAAU,EAAE,MAAM,CAAC,GAAG;YACtB,MAAM,EAAE;gBACN,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,UAAU,EAAE,IAAI,CAAC,MAAM;gBACvB,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxD,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;gBAC/E,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;gBAC9E,QAAQ,EAAE,OAAO;aAClB;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* 经营任务运行时调度(设计 §15.2 / M6-5 前后)。
|
|
18
|
+
*
|
|
19
|
+
* 只由治理所有权持有者启动:每个 tick 先核验所有权,评估到期规则、领取
|
|
20
|
+
* 规则任务、在事务外运行模型建议,再用 commitInternalResult 原子提交。
|
|
21
|
+
* 失败/超时走 FAILED + 退避;所有权丢失立即停止且不写业务结果。
|
|
22
|
+
*/
|
|
23
|
+
import type { OperationsJobsService, PrefilterResult } from "./service.js";
|
|
24
|
+
import type { OperationAdviceRun } from "./advice-runner.js";
|
|
25
|
+
export interface OperationsSchedulerOptions {
|
|
26
|
+
readonly service: OperationsJobsService;
|
|
27
|
+
readonly merchant_id: string;
|
|
28
|
+
/** 治理所有权预检;抛错即视为失权,停止调度。 */
|
|
29
|
+
readonly assertOwner: () => void;
|
|
30
|
+
/** 所有权栅栏写;提供时领取/提交在该事务内执行(推荐)。 */
|
|
31
|
+
readonly write?: <T>(work: () => T) => T;
|
|
32
|
+
readonly runner: (input: {
|
|
33
|
+
rule: NonNullable<ReturnType<OperationsJobsService["getRule"]>>;
|
|
34
|
+
task: {
|
|
35
|
+
task_id: string;
|
|
36
|
+
payload: Record<string, unknown>;
|
|
37
|
+
};
|
|
38
|
+
}) => Promise<OperationAdviceRun>;
|
|
39
|
+
readonly now: () => string;
|
|
40
|
+
readonly worker_id?: string;
|
|
41
|
+
readonly interval_ms?: number;
|
|
42
|
+
readonly lease_ms?: number;
|
|
43
|
+
readonly execution_timeout_ms?: number;
|
|
44
|
+
readonly max_tasks_per_tick?: number;
|
|
45
|
+
readonly prefilter?: (rule: NonNullable<ReturnType<OperationsJobsService["getRule"]>>) => PrefilterResult;
|
|
46
|
+
readonly log?: (line: string) => void;
|
|
47
|
+
}
|
|
48
|
+
export interface SchedulerTickResult {
|
|
49
|
+
readonly evaluations: number;
|
|
50
|
+
readonly claimed: number;
|
|
51
|
+
readonly committed: number;
|
|
52
|
+
readonly failed: number;
|
|
53
|
+
readonly stopped: boolean;
|
|
54
|
+
}
|
|
55
|
+
/** 建议中的证据引用必须是任务快照里出现过的引用(防止模型编造来源)。 */
|
|
56
|
+
export declare function collectSnapshotRefs(value: unknown, output?: Set<string>): Set<string>;
|
|
57
|
+
export declare function invalidEvidenceRefs(adviceRefs: readonly string[], payload: Record<string, unknown>): string[];
|
|
58
|
+
export declare class OperationsScheduler {
|
|
59
|
+
private readonly options;
|
|
60
|
+
private timer;
|
|
61
|
+
private stopped;
|
|
62
|
+
constructor(options: OperationsSchedulerOptions);
|
|
63
|
+
private withWrite;
|
|
64
|
+
get isRunning(): boolean;
|
|
65
|
+
start(): void;
|
|
66
|
+
stop(): void;
|
|
67
|
+
tick(): Promise<SchedulerTickResult>;
|
|
68
|
+
}
|