@harrylabsj/kiwi 0.12.31 → 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 +34 -0
- package/dist/a2a/server/merchant-handler.js +439 -19
- 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/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/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 +57 -5
- package/dist/buyer-core/service.js +275 -50
- 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 +13 -2
- package/dist/cli.js.map +1 -1
- package/dist/cloud/bootstrap.js +141 -7
- package/dist/cloud/bootstrap.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/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 +10 -0
- package/dist/http/merchant-management/api.js +443 -0
- 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 +2 -2
- 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 +7 -1
- 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 +1 -0
- package/dist/merchant/workbench-server.js +176 -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/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-runtime/manager.d.ts +2 -0
- package/dist/merchant-runtime/manager.js +5 -0
- package/dist/merchant-runtime/manager.js.map +1 -1
- package/package.json +1 -1
|
@@ -17,11 +17,21 @@ import { toMinorUnits } from "../../protocol/legacy-shopping-negotiation/money.j
|
|
|
17
17
|
import { Agent, } from "@earendil-works/pi-agent-core";
|
|
18
18
|
import { canonicalUnitToken, multiplyQuantitySafe, resolveUnitConversion, unitConversionPolicy, } from "../unit-alias.js";
|
|
19
19
|
import { factRevision } from "./publish.js";
|
|
20
|
+
import { DEFAULT_QUESTION_SPEC_REGISTRY, } from "./question-spec.js";
|
|
21
|
+
import { receptionToolContractDigest } from "./skill-contract.js";
|
|
22
|
+
import { MAX_LOADED_SKILL_CHARS, MAX_LOADED_SKILLS, skillSummaryPrompt, } from "./skill-catalog.js";
|
|
23
|
+
import { ContextGuard, } from "../../merchant-core/context-governance/context-guard.js";
|
|
24
|
+
import { createActorContext } from "../../merchant-core/context-governance/actor-context.js";
|
|
25
|
+
import { MEMORY_NAMESPACES, MEMORY_SOURCE_KINDS, } from "../../merchant-core/customer-memory/types.js";
|
|
20
26
|
export const TOOL_SEARCH_PRODUCTS = "search_products";
|
|
21
27
|
export const TOOL_COMPARE_PRODUCTS = "compare_products";
|
|
22
28
|
export const TOOL_GET_COMMERCIAL_FACTS = "get_commercial_facts";
|
|
23
29
|
export const TOOL_PROPOSE_NEED_PATCH = "propose_need_patch";
|
|
24
30
|
export const TOOL_PROPOSE_REPLY = "propose_reply";
|
|
31
|
+
export const TOOL_LOAD_RECEPTION_SKILL = "load_reception_skill";
|
|
32
|
+
export const TOOL_RECALL_CUSTOMER_CONTEXT = "recall_customer_context";
|
|
33
|
+
export const TOOL_SEARCH_CUSTOMER_HISTORY = "search_customer_history";
|
|
34
|
+
export const TOOL_PROPOSE_CUSTOMER_MEMORY = "propose_customer_memory";
|
|
25
35
|
const RECEPTION_TOOL_ALLOWLIST = [
|
|
26
36
|
TOOL_SEARCH_PRODUCTS,
|
|
27
37
|
TOOL_COMPARE_PRODUCTS,
|
|
@@ -32,6 +42,7 @@ const RECEPTION_TOOL_ALLOWLIST = [
|
|
|
32
42
|
const BLOCK_KINDS = new Set([
|
|
33
43
|
"acknowledge_need",
|
|
34
44
|
"ask_clarification",
|
|
45
|
+
"ask_registered_question",
|
|
35
46
|
"show_commercial_terms",
|
|
36
47
|
"recommend_option",
|
|
37
48
|
"request_human_help",
|
|
@@ -45,11 +56,25 @@ const DEFAULT_SYSTEM_PROMPT = [
|
|
|
45
56
|
"stock count, delivery date or any commercial fact; only the facts tool is authoritative.",
|
|
46
57
|
"When the request is ambiguous or a required field is missing, ask one short",
|
|
47
58
|
"clarification question. When ready, call propose_reply with typed blocks:",
|
|
48
|
-
"acknowledge_need, ask_clarification,
|
|
59
|
+
"acknowledge_need, ask_clarification, ask_registered_question (using a registered",
|
|
60
|
+
"question_id from the catalog), show_commercial_terms (using the fact ref),",
|
|
49
61
|
"request_human_help or next_step. You may use recommend_option with a fact ref and",
|
|
50
62
|
"compared refs from compare_products; reasonCode must be lowest_public_price or in_stock.",
|
|
51
63
|
"Never write free-form commercial text.",
|
|
64
|
+
"Every reply block uses the field \"kind\" (never \"type\"). Required shapes:",
|
|
65
|
+
"{\"kind\":\"acknowledge_need\",\"sku\":\"SKU\",\"quantity\":2,\"unit\":\"件\"},",
|
|
66
|
+
"{\"kind\":\"show_commercial_terms\",\"ref\":{\"sku\":\"SKU\",\"revision\":\"sha256:...\"}},",
|
|
67
|
+
"{\"kind\":\"ask_clarification\",\"missing\":[\"quantity\"],\"reason\":\"missing_quantity\"},",
|
|
68
|
+
"{\"kind\":\"ask_registered_question\",\"question_id\":\"q_missing_quantity_v1\"},",
|
|
69
|
+
"{\"kind\":\"next_step\",\"action\":\"send_rfq\"}.",
|
|
70
|
+
"Do not add free-text fields to next_step; the publisher renders all text.",
|
|
71
|
+
"History search hits mean the buyer only asked before: say 曾询价, never 购买 or 已购买;",
|
|
72
|
+
"history is not a current quote. Re-read commercial facts before any price/stock claim.",
|
|
52
73
|
].join(" ");
|
|
74
|
+
function buildReceptionSystemPrompt(registry) {
|
|
75
|
+
const catalog = registry.catalogText();
|
|
76
|
+
return catalog === "" ? DEFAULT_SYSTEM_PROMPT : `${DEFAULT_SYSTEM_PROMPT} ${catalog}`;
|
|
77
|
+
}
|
|
53
78
|
function toolResult(text, details = {}) {
|
|
54
79
|
return { content: [{ type: "text", text }], details };
|
|
55
80
|
}
|
|
@@ -134,17 +159,32 @@ function buyerUnitMatchesPolicy(policy, buyerUnit, requestedUnit) {
|
|
|
134
159
|
function isObject(value) {
|
|
135
160
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
136
161
|
}
|
|
162
|
+
/** 严格 schema:模型块只允许固定字段,未知字段直接拒绝(X02)。 */
|
|
163
|
+
function hasOnlyKeys(item, allowed) {
|
|
164
|
+
return Object.keys(item).every((key) => allowed.includes(key));
|
|
165
|
+
}
|
|
137
166
|
/** 把模型提交的 blocks 限缩到白名单结构;引用仍由发布器校验。 */
|
|
138
|
-
export function sanitizeReceptionBlocks(value) {
|
|
167
|
+
export function sanitizeReceptionBlocks(value, questionRegistry = DEFAULT_QUESTION_SPEC_REGISTRY) {
|
|
139
168
|
if (!Array.isArray(value) || value.length === 0 || value.length > 6)
|
|
140
169
|
return undefined;
|
|
141
170
|
const blocks = [];
|
|
142
171
|
for (const item of value) {
|
|
143
|
-
if (!isObject(item)
|
|
172
|
+
if (!isObject(item))
|
|
144
173
|
return undefined;
|
|
145
|
-
|
|
146
|
-
|
|
174
|
+
// 兼容别名:部分模型把块类型写成 `type`;规范化后仍按 `kind` 严格校验
|
|
175
|
+
// 字段(不扩大允许的块种类)。
|
|
176
|
+
const kind = typeof item.kind === "string"
|
|
177
|
+
? item.kind
|
|
178
|
+
: typeof item.type === "string"
|
|
179
|
+
? item.type
|
|
180
|
+
: undefined;
|
|
181
|
+
if (kind === undefined || !BLOCK_KINDS.has(kind))
|
|
182
|
+
return undefined;
|
|
183
|
+
switch (kind) {
|
|
147
184
|
case "acknowledge_need": {
|
|
185
|
+
if (!hasOnlyKeys(item, ["kind", "type", "sku", "quantity", "unit", "convertedFrom"])) {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
148
188
|
const sku = typeof item.sku === "string" && item.sku.trim() !== "" ? item.sku.trim() : undefined;
|
|
149
189
|
const quantity = typeof item.quantity === "number" && Number.isSafeInteger(item.quantity) && item.quantity > 0
|
|
150
190
|
? item.quantity
|
|
@@ -159,6 +199,9 @@ export function sanitizeReceptionBlocks(value) {
|
|
|
159
199
|
break;
|
|
160
200
|
}
|
|
161
201
|
case "ask_clarification": {
|
|
202
|
+
if (!hasOnlyKeys(item, ["kind", "type", "reason", "candidates", "missing"])) {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
162
205
|
const reason = item.reason;
|
|
163
206
|
if (reason !== "missing_sku" &&
|
|
164
207
|
reason !== "unknown_sku" &&
|
|
@@ -180,7 +223,65 @@ export function sanitizeReceptionBlocks(value) {
|
|
|
180
223
|
});
|
|
181
224
|
break;
|
|
182
225
|
}
|
|
226
|
+
case "ask_registered_question": {
|
|
227
|
+
if (!hasOnlyKeys(item, [
|
|
228
|
+
"kind",
|
|
229
|
+
"type",
|
|
230
|
+
"question_id",
|
|
231
|
+
"schema_version",
|
|
232
|
+
"slot",
|
|
233
|
+
"reason_code",
|
|
234
|
+
"candidate_refs",
|
|
235
|
+
])) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
const questionId = typeof item.question_id === "string" ? item.question_id.trim() : "";
|
|
239
|
+
if (questionId.length === 0 || questionId.length > 64)
|
|
240
|
+
return undefined;
|
|
241
|
+
// 服务端按注册表补齐契约字段:模型只需选择 question_id。若显式提供了
|
|
242
|
+
// schema/slot/reason,必须与注册表一致(不允许模型改写契约)。
|
|
243
|
+
const spec = questionRegistry.resolve(questionId);
|
|
244
|
+
if (spec === undefined)
|
|
245
|
+
return undefined;
|
|
246
|
+
const schemaVersion = item.schema_version === undefined ? spec.schema_version : item.schema_version;
|
|
247
|
+
const slot = item.slot === undefined ? spec.slot : item.slot;
|
|
248
|
+
const reasonCode = item.reason_code === undefined ? spec.reason_code : item.reason_code;
|
|
249
|
+
if (slot !== "sku" && slot !== "quantity" && slot !== "unit")
|
|
250
|
+
return undefined;
|
|
251
|
+
if (typeof schemaVersion !== "number" ||
|
|
252
|
+
!Number.isSafeInteger(schemaVersion) ||
|
|
253
|
+
schemaVersion !== spec.schema_version ||
|
|
254
|
+
slot !== spec.slot ||
|
|
255
|
+
typeof reasonCode !== "string" ||
|
|
256
|
+
reasonCode !== spec.reason_code) {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
// P2-8:候选引用会原样渲染进买家可见文本;模型输出是不可信数据,
|
|
260
|
+
// 只允许短、无控制字符的引用,并去重(不能借模板注入任意文案)。
|
|
261
|
+
const candidateRefs = Array.isArray(item.candidate_refs)
|
|
262
|
+
? [
|
|
263
|
+
...new Set(item.candidate_refs
|
|
264
|
+
.filter((candidate) => typeof candidate === "string")
|
|
265
|
+
.map((candidate) => candidate.trim())
|
|
266
|
+
// eslint-disable-next-line no-control-regex
|
|
267
|
+
.filter((candidate) => candidate.length > 0 && candidate.length <= 64 && !/[\u0000-\u001f\u007f]/.test(candidate))),
|
|
268
|
+
].slice(0, 8)
|
|
269
|
+
: undefined;
|
|
270
|
+
blocks.push({
|
|
271
|
+
kind: "ask_registered_question",
|
|
272
|
+
question_id: questionId,
|
|
273
|
+
schema_version: schemaVersion,
|
|
274
|
+
slot,
|
|
275
|
+
reason_code: reasonCode,
|
|
276
|
+
...(candidateRefs !== undefined && candidateRefs.length > 0
|
|
277
|
+
? { candidate_refs: candidateRefs }
|
|
278
|
+
: {}),
|
|
279
|
+
});
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
183
282
|
case "show_commercial_terms": {
|
|
283
|
+
if (!hasOnlyKeys(item, ["kind", "type", "ref", "topics"]))
|
|
284
|
+
return undefined;
|
|
184
285
|
const ref = item.ref;
|
|
185
286
|
if (!isObject(ref) ||
|
|
186
287
|
typeof ref.sku !== "string" ||
|
|
@@ -198,6 +299,9 @@ export function sanitizeReceptionBlocks(value) {
|
|
|
198
299
|
break;
|
|
199
300
|
}
|
|
200
301
|
case "recommend_option": {
|
|
302
|
+
if (!hasOnlyKeys(item, ["kind", "type", "ref", "comparedRefs", "reasonCode"])) {
|
|
303
|
+
return undefined;
|
|
304
|
+
}
|
|
201
305
|
const ref = item.ref;
|
|
202
306
|
if (!isObject(ref) || typeof ref.sku !== "string" || typeof ref.revision !== "string") {
|
|
203
307
|
return undefined;
|
|
@@ -222,8 +326,10 @@ export function sanitizeReceptionBlocks(value) {
|
|
|
222
326
|
break;
|
|
223
327
|
}
|
|
224
328
|
case "request_human_help": {
|
|
225
|
-
if (item
|
|
329
|
+
if (!hasOnlyKeys(item, ["kind", "type", "topic", "buyerTargetPrice", "currency"]) ||
|
|
330
|
+
item.topic !== "price_below_public_bound") {
|
|
226
331
|
return undefined;
|
|
332
|
+
}
|
|
227
333
|
const buyerTargetPrice = typeof item.buyerTargetPrice === "number" && Number.isFinite(item.buyerTargetPrice)
|
|
228
334
|
? item.buyerTargetPrice
|
|
229
335
|
: undefined;
|
|
@@ -237,8 +343,9 @@ export function sanitizeReceptionBlocks(value) {
|
|
|
237
343
|
break;
|
|
238
344
|
}
|
|
239
345
|
case "next_step": {
|
|
240
|
-
if (item.action !== "send_rfq")
|
|
346
|
+
if (!hasOnlyKeys(item, ["kind", "type", "action"]) || item.action !== "send_rfq") {
|
|
241
347
|
return undefined;
|
|
348
|
+
}
|
|
242
349
|
blocks.push({ kind: "next_step", action: "send_rfq" });
|
|
243
350
|
break;
|
|
244
351
|
}
|
|
@@ -277,18 +384,113 @@ export function createPiReceptionRuntime(options) {
|
|
|
277
384
|
const rejectedFactUnits = new Map();
|
|
278
385
|
const buyerQuantity = parseBuyerQuantity(input.text);
|
|
279
386
|
const boundSku = input.structuredSku?.trim() || undefined;
|
|
387
|
+
// M2-6/M3-6:技能目录 + 客户绑定/运行快照/四检查点守卫。
|
|
388
|
+
const skillCatalog = options.skillCatalog;
|
|
389
|
+
const skillBindings = skillCatalog?.activeBindings(input.merchantId) ?? [];
|
|
390
|
+
const skillSummaries = skillCatalog?.summaries(input.merchantId);
|
|
391
|
+
const skillSummaryText = skillSummaries !== undefined ? skillSummaryPrompt(skillSummaries) : "";
|
|
392
|
+
const customerContext = options.customerProvider?.contextFor(input.merchantId, input.identity);
|
|
393
|
+
const guardEnabled = skillCatalog !== undefined || customerContext !== undefined;
|
|
394
|
+
let receptionGuard;
|
|
395
|
+
let receptionSnapshot;
|
|
396
|
+
const receptionActor = !guardEnabled
|
|
397
|
+
? undefined
|
|
398
|
+
: createActorContext({
|
|
399
|
+
merchant_id: input.merchantId,
|
|
400
|
+
actor_id: `reception:${input.identity}`.slice(0, 128),
|
|
401
|
+
auth_strength: "session",
|
|
402
|
+
subject_binding: customerContext !== undefined ? "organization" : "none",
|
|
403
|
+
capabilities: customerContext !== undefined
|
|
404
|
+
? ["reception:serve", "customer:self", "memory:read"]
|
|
405
|
+
: ["reception:serve"],
|
|
406
|
+
});
|
|
407
|
+
if (guardEnabled && receptionActor !== undefined) {
|
|
408
|
+
const configVersion = receptionToolContractDigest();
|
|
409
|
+
receptionSnapshot = {
|
|
410
|
+
snapshot_id: `run_${input.contextId}`.slice(0, 128),
|
|
411
|
+
issued_at: input.now,
|
|
412
|
+
binding_epoch: customerContext?.binding_epoch ?? 0,
|
|
413
|
+
grant_versions: customerContext?.grant_versions ?? {},
|
|
414
|
+
data_scope_epochs: customerContext?.data_scope_epochs ?? {},
|
|
415
|
+
memory_set_version: customerContext?.memory_set_version ?? 0,
|
|
416
|
+
conversation_revision: 0,
|
|
417
|
+
config_version: configVersion,
|
|
418
|
+
skill_bindings: skillBindings.map((binding) => ({
|
|
419
|
+
skill_key: binding.skill_key,
|
|
420
|
+
release_id: binding.release_id,
|
|
421
|
+
compiled_artifact_hash: binding.compiled_artifact_hash,
|
|
422
|
+
generation: binding.generation,
|
|
423
|
+
revocation_epoch: binding.revocation_epoch,
|
|
424
|
+
})),
|
|
425
|
+
};
|
|
426
|
+
const authority = {
|
|
427
|
+
currentGrantEpoch: (merchantId, grantId) => options.customerProvider?.currentGrantEpoch(merchantId, grantId),
|
|
428
|
+
currentBindingEpoch: (merchantId) => options.customerProvider?.currentBindingEpoch(merchantId, input.identity),
|
|
429
|
+
currentDataScopeEpoch: (merchantId, scopeKey) => options.customerProvider?.currentDataScopeEpoch(merchantId, scopeKey),
|
|
430
|
+
currentSkillBinding: (merchantId, skillKey) => skillCatalog?.currentBinding(merchantId, skillKey),
|
|
431
|
+
currentMemorySetVersion: (merchantId) => customerContext === undefined
|
|
432
|
+
? undefined
|
|
433
|
+
: options.customerProvider?.currentMemorySetVersion(merchantId, customerContext.subject_id),
|
|
434
|
+
currentConversationRevision: () => undefined,
|
|
435
|
+
currentConfigVersion: () => configVersion,
|
|
436
|
+
sourceAvailable: () => false,
|
|
437
|
+
};
|
|
438
|
+
receptionGuard = new ContextGuard({ authority, now: () => input.now });
|
|
439
|
+
}
|
|
440
|
+
const checkGuard = (checkpoint, tool) => {
|
|
441
|
+
if (receptionGuard === undefined ||
|
|
442
|
+
receptionActor === undefined ||
|
|
443
|
+
receptionSnapshot === undefined) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const base = {
|
|
447
|
+
actor: receptionActor,
|
|
448
|
+
snapshot: receptionSnapshot,
|
|
449
|
+
capability: "reception:serve",
|
|
450
|
+
};
|
|
451
|
+
if (checkpoint === "tool_call") {
|
|
452
|
+
receptionGuard.checkToolCall({ ...base, ...(tool !== undefined ? { tool } : {}) });
|
|
453
|
+
}
|
|
454
|
+
else if (checkpoint === "provider_attempt") {
|
|
455
|
+
receptionGuard.checkProviderAttempt(base);
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
receptionGuard.checkPublish(base);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
const canProposeMemory = customerContext !== undefined && options.customerProvider !== undefined && (options.customerProvider.canPropose?.(customerContext) ?? true);
|
|
462
|
+
const allowedTools = [
|
|
463
|
+
...RECEPTION_TOOL_ALLOWLIST,
|
|
464
|
+
...(skillCatalog !== undefined && skillBindings.length > 0
|
|
465
|
+
? [TOOL_LOAD_RECEPTION_SKILL]
|
|
466
|
+
: []),
|
|
467
|
+
...(customerContext !== undefined
|
|
468
|
+
? [
|
|
469
|
+
TOOL_RECALL_CUSTOMER_CONTEXT,
|
|
470
|
+
TOOL_SEARCH_CUSTOMER_HISTORY,
|
|
471
|
+
...(canProposeMemory ? [TOOL_PROPOSE_CUSTOMER_MEMORY] : []),
|
|
472
|
+
]
|
|
473
|
+
: []),
|
|
474
|
+
];
|
|
475
|
+
let loadedSkillCount = 0;
|
|
476
|
+
let loadedSkillChars = 0;
|
|
477
|
+
const loadedSkills = [];
|
|
280
478
|
let steps = 0;
|
|
281
479
|
let toolAttempts = 0;
|
|
282
480
|
let timedOut = false;
|
|
481
|
+
let toolBudgetExhausted = false;
|
|
283
482
|
const guard = async (context) => {
|
|
284
|
-
if (!
|
|
483
|
+
if (!allowedTools.includes(context.toolCall.name)) {
|
|
285
484
|
return { block: true, reason: "tool_not_allowed" };
|
|
286
485
|
}
|
|
486
|
+
// 每次工具调用前检查权限/技能绑定/版本;异常向引擎抛出 → 回退确定性。
|
|
487
|
+
checkGuard("tool_call", context.toolCall.name);
|
|
287
488
|
if (plan !== undefined) {
|
|
288
489
|
return { block: true, reason: "reply_already_proposed" };
|
|
289
490
|
}
|
|
290
491
|
toolAttempts += 1;
|
|
291
492
|
if (toolAttempts > (options.maxToolAttempts ?? 12)) {
|
|
493
|
+
toolBudgetExhausted = true;
|
|
292
494
|
return { block: true, reason: "tool_budget_exhausted" };
|
|
293
495
|
}
|
|
294
496
|
const serialized = JSON.stringify(context.toolCall.arguments ?? {});
|
|
@@ -679,6 +881,184 @@ export function createPiReceptionRuntime(options) {
|
|
|
679
881
|
return toolResult(JSON.stringify({ accepted: true }));
|
|
680
882
|
},
|
|
681
883
|
},
|
|
884
|
+
...(skillCatalog !== undefined && skillBindings.length > 0
|
|
885
|
+
? [
|
|
886
|
+
{
|
|
887
|
+
name: TOOL_LOAD_RECEPTION_SKILL,
|
|
888
|
+
label: "Load reception skill",
|
|
889
|
+
description: "Load one published reception skill by skill_key from this run's summaries.",
|
|
890
|
+
parameters: {
|
|
891
|
+
type: "object",
|
|
892
|
+
additionalProperties: false,
|
|
893
|
+
properties: { skill_key: { type: "string" } },
|
|
894
|
+
required: ["skill_key"],
|
|
895
|
+
},
|
|
896
|
+
execute: async (_id, params) => {
|
|
897
|
+
const args = params;
|
|
898
|
+
const skillKey = isObject(args) && typeof args.skill_key === "string"
|
|
899
|
+
? args.skill_key.trim()
|
|
900
|
+
: "";
|
|
901
|
+
const binding = skillBindings.find((item) => item.skill_key === skillKey);
|
|
902
|
+
if (binding === undefined) {
|
|
903
|
+
loadedSkills.push({
|
|
904
|
+
skill_key: skillKey,
|
|
905
|
+
release_id: "",
|
|
906
|
+
accepted: false,
|
|
907
|
+
reason: "skill_not_bound",
|
|
908
|
+
});
|
|
909
|
+
return toolResult(JSON.stringify({ accepted: false, error: "skill_not_bound" }));
|
|
910
|
+
}
|
|
911
|
+
if (loadedSkillCount >= MAX_LOADED_SKILLS) {
|
|
912
|
+
loadedSkills.push({
|
|
913
|
+
skill_key: skillKey,
|
|
914
|
+
release_id: binding.release_id,
|
|
915
|
+
accepted: false,
|
|
916
|
+
reason: "max_skills",
|
|
917
|
+
});
|
|
918
|
+
return toolResult(JSON.stringify({
|
|
919
|
+
accepted: false,
|
|
920
|
+
error: "skill_limit_exceeded",
|
|
921
|
+
reason: "max_skills",
|
|
922
|
+
}));
|
|
923
|
+
}
|
|
924
|
+
const artifact = skillCatalog.loadArtifact(input.merchantId, skillKey, binding.release_id);
|
|
925
|
+
if (artifact === undefined) {
|
|
926
|
+
loadedSkills.push({
|
|
927
|
+
skill_key: skillKey,
|
|
928
|
+
release_id: binding.release_id,
|
|
929
|
+
accepted: false,
|
|
930
|
+
reason: "skill_unavailable",
|
|
931
|
+
});
|
|
932
|
+
return toolResult(JSON.stringify({ accepted: false, error: "skill_unavailable" }));
|
|
933
|
+
}
|
|
934
|
+
if (loadedSkillChars + artifact.body_text.length >
|
|
935
|
+
MAX_LOADED_SKILL_CHARS) {
|
|
936
|
+
loadedSkills.push({
|
|
937
|
+
skill_key: skillKey,
|
|
938
|
+
release_id: binding.release_id,
|
|
939
|
+
accepted: false,
|
|
940
|
+
reason: "body_budget",
|
|
941
|
+
});
|
|
942
|
+
return toolResult(JSON.stringify({
|
|
943
|
+
accepted: false,
|
|
944
|
+
error: "skill_limit_exceeded",
|
|
945
|
+
reason: "body_budget",
|
|
946
|
+
}));
|
|
947
|
+
}
|
|
948
|
+
loadedSkillCount += 1;
|
|
949
|
+
loadedSkillChars += artifact.body_text.length;
|
|
950
|
+
loadedSkills.push({
|
|
951
|
+
skill_key: artifact.skill_key,
|
|
952
|
+
release_id: artifact.release_id,
|
|
953
|
+
accepted: true,
|
|
954
|
+
});
|
|
955
|
+
return toolResult(JSON.stringify({
|
|
956
|
+
accepted: true,
|
|
957
|
+
skill_key: artifact.skill_key,
|
|
958
|
+
release_id: artifact.release_id,
|
|
959
|
+
compiled_artifact_hash: artifact.compiled_artifact_hash,
|
|
960
|
+
question_schema_version: artifact.question_schema_version,
|
|
961
|
+
required_tools: artifact.required_tools,
|
|
962
|
+
steps: artifact.steps,
|
|
963
|
+
body_text: artifact.body_text,
|
|
964
|
+
}));
|
|
965
|
+
},
|
|
966
|
+
},
|
|
967
|
+
]
|
|
968
|
+
: []),
|
|
969
|
+
...(customerContext !== undefined && options.customerProvider !== undefined
|
|
970
|
+
? [
|
|
971
|
+
{
|
|
972
|
+
name: TOOL_RECALL_CUSTOMER_CONTEXT,
|
|
973
|
+
label: "Recall customer context",
|
|
974
|
+
description: "Read this bound subject's active memory items (minimum fields only).",
|
|
975
|
+
parameters: { type: "object", additionalProperties: false, properties: {} },
|
|
976
|
+
execute: async () => {
|
|
977
|
+
const items = options.customerProvider.recall(customerContext);
|
|
978
|
+
return toolResult(JSON.stringify({ status: "ok", items }));
|
|
979
|
+
},
|
|
980
|
+
},
|
|
981
|
+
{
|
|
982
|
+
name: TOOL_SEARCH_CUSTOMER_HISTORY,
|
|
983
|
+
label: "Search customer history",
|
|
984
|
+
description: "Search this bound subject's authorized history; at most 5 snippets.",
|
|
985
|
+
parameters: {
|
|
986
|
+
type: "object",
|
|
987
|
+
additionalProperties: false,
|
|
988
|
+
properties: {
|
|
989
|
+
query: { type: "string" },
|
|
990
|
+
cursor: { type: "string" },
|
|
991
|
+
},
|
|
992
|
+
required: ["query"],
|
|
993
|
+
},
|
|
994
|
+
execute: async (_id, params) => {
|
|
995
|
+
const args = params;
|
|
996
|
+
if (!isObject(args) || typeof args.query !== "string") {
|
|
997
|
+
return toolResult(JSON.stringify({ status: "unavailable", reason: "invalid_query" }));
|
|
998
|
+
}
|
|
999
|
+
const cursor = typeof args.cursor === "string" && args.cursor.trim() !== ""
|
|
1000
|
+
? args.cursor.trim()
|
|
1001
|
+
: undefined;
|
|
1002
|
+
const result = options.customerProvider.search(customerContext, {
|
|
1003
|
+
query: args.query,
|
|
1004
|
+
...(cursor !== undefined ? { cursor } : {}),
|
|
1005
|
+
});
|
|
1006
|
+
return toolResult(JSON.stringify(result));
|
|
1007
|
+
},
|
|
1008
|
+
},
|
|
1009
|
+
]
|
|
1010
|
+
: []),
|
|
1011
|
+
...(canProposeMemory && customerContext !== undefined && options.customerProvider !== undefined
|
|
1012
|
+
? [
|
|
1013
|
+
{
|
|
1014
|
+
name: TOOL_PROPOSE_CUSTOMER_MEMORY,
|
|
1015
|
+
label: "Propose customer memory",
|
|
1016
|
+
description: "Propose a customer memory candidate. It stays candidate until the customer confirms.",
|
|
1017
|
+
parameters: {
|
|
1018
|
+
type: "object",
|
|
1019
|
+
additionalProperties: false,
|
|
1020
|
+
properties: {
|
|
1021
|
+
namespace: { type: "string" },
|
|
1022
|
+
key: { type: "string" },
|
|
1023
|
+
value_ref: { type: "string" },
|
|
1024
|
+
value_type: { type: "string" },
|
|
1025
|
+
source_kind: { type: "string" },
|
|
1026
|
+
confidence: { type: "number" },
|
|
1027
|
+
},
|
|
1028
|
+
required: ["namespace", "key", "value_ref", "value_type", "source_kind"],
|
|
1029
|
+
},
|
|
1030
|
+
execute: async (_id, params) => {
|
|
1031
|
+
const args = params;
|
|
1032
|
+
if (!isObject(args) ||
|
|
1033
|
+
typeof args.namespace !== "string" ||
|
|
1034
|
+
!MEMORY_NAMESPACES.includes(args.namespace) ||
|
|
1035
|
+
typeof args.key !== "string" ||
|
|
1036
|
+
typeof args.value_ref !== "string" ||
|
|
1037
|
+
typeof args.value_type !== "string" ||
|
|
1038
|
+
typeof args.source_kind !== "string" ||
|
|
1039
|
+
!MEMORY_SOURCE_KINDS.includes(args.source_kind)) {
|
|
1040
|
+
return toolResult(JSON.stringify({ accepted: false, error: "invalid_memory" }));
|
|
1041
|
+
}
|
|
1042
|
+
try {
|
|
1043
|
+
const proposal = await options.customerProvider.propose(customerContext, {
|
|
1044
|
+
namespace: args.namespace,
|
|
1045
|
+
key: args.key,
|
|
1046
|
+
value_ref: args.value_ref,
|
|
1047
|
+
value_type: args.value_type,
|
|
1048
|
+
source_kind: args.source_kind,
|
|
1049
|
+
...(typeof args.confidence === "number"
|
|
1050
|
+
? { confidence: args.confidence }
|
|
1051
|
+
: {}),
|
|
1052
|
+
});
|
|
1053
|
+
return toolResult(JSON.stringify({ accepted: true, ...proposal }));
|
|
1054
|
+
}
|
|
1055
|
+
catch {
|
|
1056
|
+
return toolResult(JSON.stringify({ accepted: false, error: "proposal_rejected" }));
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
},
|
|
1060
|
+
]
|
|
1061
|
+
: []),
|
|
682
1062
|
{
|
|
683
1063
|
name: TOOL_PROPOSE_REPLY,
|
|
684
1064
|
label: "Propose reply",
|
|
@@ -695,8 +1075,13 @@ export function createPiReceptionRuntime(options) {
|
|
|
695
1075
|
const args = params;
|
|
696
1076
|
if (!isObject(args))
|
|
697
1077
|
return toolResult(JSON.stringify({ accepted: false, error: "invalid_plan" }));
|
|
698
|
-
const blocks = sanitizeReceptionBlocks(args.blocks);
|
|
1078
|
+
const blocks = sanitizeReceptionBlocks(args.blocks, options.questionRegistry ?? DEFAULT_QUESTION_SPEC_REGISTRY);
|
|
699
1079
|
if (blocks === undefined) {
|
|
1080
|
+
// 诊断开关:记录模型原始 blocks(不含买家原文/密钥),便于定位
|
|
1081
|
+
// 输出契约漂移;默认关闭,不改变生产日志。
|
|
1082
|
+
if (process.env.KIWI_RECEPTION_DEBUG_PROPOSE === "1") {
|
|
1083
|
+
process.stderr.write(`[reception] invalid_blocks ${JSON.stringify(args.blocks).slice(0, 3000)}\n`);
|
|
1084
|
+
}
|
|
700
1085
|
return toolResult(JSON.stringify({ accepted: false, error: "invalid_blocks" }));
|
|
701
1086
|
}
|
|
702
1087
|
if (boundSku !== undefined) {
|
|
@@ -746,10 +1131,24 @@ export function createPiReceptionRuntime(options) {
|
|
|
746
1131
|
},
|
|
747
1132
|
},
|
|
748
1133
|
];
|
|
1134
|
+
const baseSystemPrompt = options.systemPrompt ??
|
|
1135
|
+
buildReceptionSystemPrompt(options.questionRegistry ?? DEFAULT_QUESTION_SPEC_REGISTRY);
|
|
1136
|
+
const customerPrompt = customerContext !== undefined
|
|
1137
|
+
? "Customer memory/history tools are bound to the current subject; never expose other subjects or infer identity."
|
|
1138
|
+
: "";
|
|
1139
|
+
const systemPrompt = [baseSystemPrompt, skillSummaryText, customerPrompt]
|
|
1140
|
+
.filter((part) => part.trim() !== "")
|
|
1141
|
+
.join("\n\n");
|
|
1142
|
+
const guardedStreamFn = skillCatalog === undefined
|
|
1143
|
+
? options.streamFn
|
|
1144
|
+
: ((...args) => {
|
|
1145
|
+
checkGuard("provider_attempt");
|
|
1146
|
+
return options.streamFn(...args);
|
|
1147
|
+
});
|
|
749
1148
|
const agent = new Agent({
|
|
750
|
-
streamFn:
|
|
1149
|
+
streamFn: guardedStreamFn,
|
|
751
1150
|
initialState: {
|
|
752
|
-
systemPrompt
|
|
1151
|
+
systemPrompt,
|
|
753
1152
|
model: options.model,
|
|
754
1153
|
tools,
|
|
755
1154
|
},
|
|
@@ -763,10 +1162,12 @@ export function createPiReceptionRuntime(options) {
|
|
|
763
1162
|
steps: 0,
|
|
764
1163
|
toolCalls: {},
|
|
765
1164
|
usage: { input: 0, output: 0, total: 0 },
|
|
1165
|
+
loadedSkills,
|
|
766
1166
|
};
|
|
767
1167
|
let activeLease;
|
|
768
1168
|
let lastSettledOutput = 0;
|
|
769
1169
|
let quotaRejected = false;
|
|
1170
|
+
let modelFailed = false;
|
|
770
1171
|
agent.subscribe((event) => {
|
|
771
1172
|
if (event.type === "turn_start") {
|
|
772
1173
|
if (options.budget !== undefined) {
|
|
@@ -782,6 +1183,8 @@ export function createPiReceptionRuntime(options) {
|
|
|
782
1183
|
return undefined;
|
|
783
1184
|
}
|
|
784
1185
|
if (event.type === "message_end" && event.message.role === "assistant") {
|
|
1186
|
+
if (event.message.stopReason === "error" || event.message.stopReason === "aborted")
|
|
1187
|
+
modelFailed = true;
|
|
785
1188
|
const usage = event.message.usage;
|
|
786
1189
|
metrics.usage.input += usage.input;
|
|
787
1190
|
metrics.usage.output += usage.output;
|
|
@@ -821,6 +1224,7 @@ export function createPiReceptionRuntime(options) {
|
|
|
821
1224
|
await agent.waitForIdle();
|
|
822
1225
|
}
|
|
823
1226
|
catch {
|
|
1227
|
+
modelFailed = true;
|
|
824
1228
|
// 回退确定性路径;未结算的预算 lease 在 finally 按未知用量保留。
|
|
825
1229
|
}
|
|
826
1230
|
finally {
|
|
@@ -833,8 +1237,13 @@ export function createPiReceptionRuntime(options) {
|
|
|
833
1237
|
if (quotaRejected)
|
|
834
1238
|
metrics.quotaRejected = true;
|
|
835
1239
|
options.onMetrics?.(metrics);
|
|
1240
|
+
if (options.requireCompleteModelRun === true && (timedOut || quotaRejected || modelFailed || toolBudgetExhausted)) {
|
|
1241
|
+
throw new Error("evaluation_runtime_outcome_unknown");
|
|
1242
|
+
}
|
|
836
1243
|
if (plan === undefined || timedOut || quotaRejected)
|
|
837
1244
|
return undefined;
|
|
1245
|
+
// 发布前最后一次版本/撤回检查;失败抛出 → 引擎丢弃模型计划并回退确定性。
|
|
1246
|
+
checkGuard("publish");
|
|
838
1247
|
return {
|
|
839
1248
|
plan,
|
|
840
1249
|
...(Object.keys(needPatch).length > 0 ? { need: needPatch } : {}),
|