@harrylabsj/kiwi 0.10.0 → 0.11.0
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 +1 -1
- package/contracts/card-publication/0.1.2/request.schema.json +78 -0
- package/contracts/kiwi-contracts.lock.json +2 -2
- package/contracts/manifest.json +127 -1
- package/contracts/merchant-management/1.0/README.md +109 -0
- package/contracts/merchant-management/1.0/approval-decision.schema.json +16 -0
- package/contracts/merchant-management/1.0/approval-preview.schema.json +26 -0
- package/contracts/merchant-management/1.0/connector-delivery-manifest.schema.json +78 -0
- package/contracts/merchant-management/1.0/management-error.schema.json +30 -0
- package/contracts/merchant-management/1.0/operation-receipt.schema.json +28 -0
- package/contracts/merchant-management/1.0/runtime-management-descriptor.schema.json +33 -0
- package/contracts/merchant-management/1.0/runtime-status.schema.json +42 -0
- package/contracts/merchant-rfq/0.1.0/delivery-record.schema.json +206 -0
- package/contracts/merchant-rfq/0.1.0/fact-snapshot.schema.json +118 -0
- package/contracts/merchant-rfq/0.1.0/handoff-record.schema.json +251 -0
- package/contracts/merchant-rfq/0.1.0/pricing-input.schema.json +139 -0
- package/contracts/merchant-rfq/0.1.0/quote-revision.schema.json +153 -0
- package/contracts/merchant-rfq/0.1.0/release-request.schema.json +121 -0
- package/contracts/merchant-rfq/0.1.0/rfq-case.schema.json +357 -0
- package/contracts/merchant-rfq/0.1.0/source-record.schema.json +162 -0
- package/contracts/merchant-workbench/1.0/README.md +6 -0
- package/contracts/merchant-workbench/1.0/money.schema.json +19 -0
- package/contracts/merchant-workbench/1.0/problem.schema.json +73 -0
- package/contracts/runtime-binding/0.1.2/binding-request.schema.json +73 -0
- package/contracts/runtime-binding/0.1.2/claims.schema.json +100 -0
- package/contracts/runtime-binding/0.1.2/document.schema.json +161 -0
- package/contracts/vectors/binding-thumbprint.json +15 -0
- package/dist/a2a/node.d.ts +96 -2
- package/dist/a2a/node.js +164 -91
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/server/errors.d.ts +8 -0
- package/dist/a2a/server/errors.js +8 -0
- package/dist/a2a/server/errors.js.map +1 -1
- package/dist/a2a/server/merchant-handler.d.ts +13 -0
- package/dist/a2a/server/merchant-handler.js +267 -34
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/pipeline.d.ts +15 -10
- package/dist/a2a/server/pipeline.js +48 -18
- package/dist/a2a/server/pipeline.js.map +1 -1
- package/dist/a2a/server/server.d.ts +20 -1
- package/dist/a2a/server/server.js +87 -13
- package/dist/a2a/server/server.js.map +1 -1
- package/dist/a2a/server/task-registry.d.ts +31 -11
- package/dist/a2a/server/task-registry.js +65 -20
- package/dist/a2a/server/task-registry.js.map +1 -1
- package/dist/a2a/server/types.d.ts +23 -0
- package/dist/a2a/signing-key.d.ts +6 -0
- package/dist/a2a/signing-key.js +12 -0
- package/dist/a2a/signing-key.js.map +1 -1
- package/dist/agent/buyer/buyer-tools.js +1 -1
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/host/web-renderer.d.ts +5 -0
- package/dist/agent/host/web-renderer.js +25 -6
- package/dist/agent/host/web-renderer.js.map +1 -1
- package/dist/agent/kernel.js +6 -6
- package/dist/agent/kernel.js.map +1 -1
- package/dist/agent/memory/schema.d.ts +1 -1
- package/dist/agent/memory/schema.js +190 -1
- package/dist/agent/memory/schema.js.map +1 -1
- package/dist/agent/memory/store.js +3 -1
- package/dist/agent/memory/store.js.map +1 -1
- package/dist/agent/merchant/action-candidate.d.ts +1 -0
- package/dist/agent/merchant/action-candidate.js +42 -24
- package/dist/agent/merchant/action-candidate.js.map +1 -1
- package/dist/agent/merchant/fake-merchant-client.d.ts +30 -1
- package/dist/agent/merchant/fake-merchant-client.js +151 -2
- package/dist/agent/merchant/fake-merchant-client.js.map +1 -1
- package/dist/agent/merchant/intelligence/default-backend.js +2 -2
- package/dist/agent/merchant/intelligence/default-backend.js.map +1 -1
- package/dist/agent/merchant/merchant-client.d.ts +38 -5
- package/dist/agent/merchant/merchant-client.js +103 -8
- package/dist/agent/merchant/merchant-client.js.map +1 -1
- package/dist/agent/merchant/types.d.ts +107 -0
- package/dist/agent/merchant/types.js +69 -0
- package/dist/agent/merchant/types.js.map +1 -1
- package/dist/alerts/external-delivery.d.ts +78 -0
- package/dist/alerts/external-delivery.js +256 -0
- package/dist/alerts/external-delivery.js.map +1 -0
- package/dist/auth/app-oauth-callback.d.ts +38 -0
- package/dist/auth/app-oauth-callback.js +119 -0
- package/dist/auth/app-oauth-callback.js.map +1 -0
- package/dist/auth/merchant-oauth.js +15 -41
- package/dist/auth/merchant-oauth.js.map +1 -1
- package/dist/auth/merchant-pairing.d.ts +51 -0
- package/dist/auth/merchant-pairing.js +66 -16
- package/dist/auth/merchant-pairing.js.map +1 -1
- package/dist/auth/merchant-sessions.d.ts +7 -1
- package/dist/auth/merchant-sessions.js +25 -3
- package/dist/auth/merchant-sessions.js.map +1 -1
- package/dist/buyer-core/build-service.d.ts +3 -1
- package/dist/buyer-core/build-service.js +4 -1
- package/dist/buyer-core/build-service.js.map +1 -1
- package/dist/buyer-core/merchant-index.d.ts +20 -0
- package/dist/buyer-core/merchant-index.js +83 -12
- package/dist/buyer-core/merchant-index.js.map +1 -1
- package/dist/buyer-core/network-search.d.ts +92 -0
- package/dist/buyer-core/network-search.js +144 -0
- package/dist/buyer-core/network-search.js.map +1 -0
- package/dist/buyer-core/product-summary.d.ts +71 -0
- package/dist/buyer-core/product-summary.js +63 -0
- package/dist/buyer-core/product-summary.js.map +1 -0
- package/dist/buyer-core/service.d.ts +26 -0
- package/dist/buyer-core/service.js +38 -8
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/cli.js +21 -242
- package/dist/cli.js.map +1 -1
- package/dist/cloud/binding/audit.d.ts +72 -0
- package/dist/cloud/binding/audit.js +137 -0
- package/dist/cloud/binding/audit.js.map +1 -0
- package/dist/cloud/binding/issuance.d.ts +76 -0
- package/dist/cloud/binding/issuance.js +121 -0
- package/dist/cloud/binding/issuance.js.map +1 -0
- package/dist/cloud/binding/proofs.d.ts +110 -0
- package/dist/cloud/binding/proofs.js +200 -0
- package/dist/cloud/binding/proofs.js.map +1 -0
- package/dist/cloud/binding/runtime-challenge.d.ts +48 -0
- package/dist/cloud/binding/runtime-challenge.js +178 -0
- package/dist/cloud/binding/runtime-challenge.js.map +1 -0
- package/dist/cloud/bootstrap.d.ts +63 -0
- package/dist/cloud/bootstrap.js +937 -0
- package/dist/cloud/bootstrap.js.map +1 -0
- package/dist/cloud/config.d.ts +91 -0
- package/dist/cloud/config.js +229 -0
- package/dist/cloud/config.js.map +1 -0
- package/dist/cloud/http-router.d.ts +61 -0
- package/dist/cloud/http-router.js +127 -0
- package/dist/cloud/http-router.js.map +1 -0
- package/dist/cloud/main.d.ts +16 -0
- package/dist/cloud/main.js +64 -0
- package/dist/cloud/main.js.map +1 -0
- package/dist/cloud/onboarding/local-fallback.d.ts +86 -0
- package/dist/cloud/onboarding/local-fallback.js +98 -0
- package/dist/cloud/onboarding/local-fallback.js.map +1 -0
- package/dist/cloud/onboarding/steps.d.ts +95 -0
- package/dist/cloud/onboarding/steps.js +175 -0
- package/dist/cloud/onboarding/steps.js.map +1 -0
- package/dist/cloud/onboarding/store.d.ts +136 -0
- package/dist/cloud/onboarding/store.js +472 -0
- package/dist/cloud/onboarding/store.js.map +1 -0
- package/dist/cloud/onboarding/types.d.ts +132 -0
- package/dist/cloud/onboarding/types.js +152 -0
- package/dist/cloud/onboarding/types.js.map +1 -0
- package/dist/cloud/product-source.d.ts +97 -0
- package/dist/cloud/product-source.js +226 -0
- package/dist/cloud/product-source.js.map +1 -0
- package/dist/cloud/readiness.d.ts +49 -0
- package/dist/cloud/readiness.js +54 -0
- package/dist/cloud/readiness.js.map +1 -0
- package/dist/commerce/data-source.d.ts +5 -0
- package/dist/commerce/data-source.js.map +1 -1
- package/dist/config/provider-kind.d.ts +26 -0
- package/dist/config/provider-kind.js +19 -0
- package/dist/config/provider-kind.js.map +1 -0
- package/dist/contracts/cloud-contracts.d.ts +23 -0
- package/dist/contracts/cloud-contracts.js +90 -0
- package/dist/contracts/cloud-contracts.js.map +1 -0
- package/dist/counterparty/a2a-direct/index.d.ts +3 -0
- package/dist/counterparty/a2a-direct/index.js +22 -6
- package/dist/counterparty/a2a-direct/index.js.map +1 -1
- package/dist/counterparty/registry.d.ts +2 -0
- package/dist/counterparty/registry.js +2 -0
- package/dist/counterparty/registry.js.map +1 -1
- package/dist/counterparty/shopping-cli-hosted/index.d.ts +3 -0
- package/dist/counterparty/shopping-cli-hosted/index.js +9 -2
- package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -1
- package/dist/discovery/catalog-source/buyer-follows.js +2 -2
- package/dist/discovery/catalog-source/buyer-follows.js.map +1 -1
- package/dist/discovery/catalog-source/cloud-card.d.ts +184 -0
- package/dist/discovery/catalog-source/cloud-card.js +379 -0
- package/dist/discovery/catalog-source/cloud-card.js.map +1 -0
- package/dist/discovery/catalog-source/cloud-hosting.d.ts +71 -0
- package/dist/discovery/catalog-source/cloud-hosting.js +70 -0
- package/dist/discovery/catalog-source/cloud-hosting.js.map +1 -0
- package/dist/discovery/catalog-source/errors.d.ts +12 -2
- package/dist/discovery/catalog-source/errors.js +14 -1
- package/dist/discovery/catalog-source/errors.js.map +1 -1
- package/dist/discovery/catalog-source/index.d.ts +2 -0
- package/dist/discovery/catalog-source/index.js +2 -0
- package/dist/discovery/catalog-source/index.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.js +2 -2
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/discovery/catalog-source/merchant-publications.d.ts +2 -2
- package/dist/discovery/catalog-source/merchant-publications.js +10 -5
- package/dist/discovery/catalog-source/merchant-publications.js.map +1 -1
- package/dist/discovery/catalog-source/source.js +2 -2
- package/dist/discovery/catalog-source/source.js.map +1 -1
- package/dist/discovery/merchant-subscriptions.d.ts +45 -0
- package/dist/discovery/merchant-subscriptions.js +319 -0
- package/dist/discovery/merchant-subscriptions.js.map +1 -0
- package/dist/discovery/resolve.d.ts +38 -0
- package/dist/discovery/resolve.js +100 -7
- package/dist/discovery/resolve.js.map +1 -1
- package/dist/fanout/orchestrator.d.ts +2 -0
- package/dist/fanout/orchestrator.js +4 -1
- package/dist/fanout/orchestrator.js.map +1 -1
- package/dist/handoff/ledger.d.ts +1 -0
- package/dist/handoff/ledger.js +3 -0
- package/dist/handoff/ledger.js.map +1 -1
- package/dist/handoff/transaction.js +1 -1
- package/dist/handoff/transaction.js.map +1 -1
- package/dist/http/merchant-engagement-api.d.ts +10 -0
- package/dist/http/merchant-engagement-api.js +138 -0
- package/dist/http/merchant-engagement-api.js.map +1 -0
- package/dist/http/merchant-feed-api.d.ts +7 -0
- package/dist/http/merchant-feed-api.js +129 -0
- package/dist/http/merchant-feed-api.js.map +1 -0
- package/dist/http/merchant-follow-api.d.ts +15 -0
- package/dist/http/merchant-follow-api.js +192 -0
- package/dist/http/merchant-follow-api.js.map +1 -0
- package/dist/http/merchant-management/api.d.ts +241 -0
- package/dist/http/merchant-management/api.js +2785 -0
- package/dist/http/merchant-management/api.js.map +1 -0
- package/dist/http/merchant-management/draft-store.d.ts +51 -0
- package/dist/http/merchant-management/draft-store.js +95 -0
- package/dist/http/merchant-management/draft-store.js.map +1 -0
- package/dist/http/merchant-management/event-projection.d.ts +41 -0
- package/dist/http/merchant-management/event-projection.js +190 -0
- package/dist/http/merchant-management/event-projection.js.map +1 -0
- package/dist/http/merchant-management/operation-store.d.ts +97 -0
- package/dist/http/merchant-management/operation-store.js +252 -0
- package/dist/http/merchant-management/operation-store.js.map +1 -0
- package/dist/http/merchant-management/page.d.ts +29 -0
- package/dist/http/merchant-management/page.js +346 -0
- package/dist/http/merchant-management/page.js.map +1 -0
- package/dist/http/merchant-management/problem-client.d.ts +19 -0
- package/dist/http/merchant-management/problem-client.js +55 -0
- package/dist/http/merchant-management/problem-client.js.map +1 -0
- package/dist/http/merchant-management/problem.d.ts +74 -0
- package/dist/http/merchant-management/problem.js +112 -0
- package/dist/http/merchant-management/problem.js.map +1 -0
- package/dist/http/merchant-management/reconciliation-worker.d.ts +95 -0
- package/dist/http/merchant-management/reconciliation-worker.js +397 -0
- package/dist/http/merchant-management/reconciliation-worker.js.map +1 -0
- package/dist/http/merchant-management/service-state.d.ts +86 -0
- package/dist/http/merchant-management/service-state.js +217 -0
- package/dist/http/merchant-management/service-state.js.map +1 -0
- package/dist/http/merchant-management/trusted-page.d.ts +3 -0
- package/dist/http/merchant-management/trusted-page.js +73 -0
- package/dist/http/merchant-management/trusted-page.js.map +1 -0
- package/dist/http/merchant-management/webauthn-confirmation.d.ts +148 -0
- package/dist/http/merchant-management/webauthn-confirmation.js +517 -0
- package/dist/http/merchant-management/webauthn-confirmation.js.map +1 -0
- package/dist/http/merchant-privacy-api.d.ts +9 -0
- package/dist/http/merchant-privacy-api.js +96 -0
- package/dist/http/merchant-privacy-api.js.map +1 -0
- package/dist/mcp/merchant-rfq-resources.d.ts +37 -0
- package/dist/mcp/merchant-rfq-resources.js +132 -0
- package/dist/mcp/merchant-rfq-resources.js.map +1 -0
- package/dist/mcp/merchant-rfq-tools.d.ts +61 -0
- package/dist/mcp/merchant-rfq-tools.js +584 -0
- package/dist/mcp/merchant-rfq-tools.js.map +1 -0
- package/dist/mcp/merchant-runtime-assembly.d.ts +74 -0
- package/dist/mcp/merchant-runtime-assembly.js +473 -0
- package/dist/mcp/merchant-runtime-assembly.js.map +1 -0
- package/dist/mcp/merchant-server.d.ts +64 -1
- package/dist/mcp/merchant-server.js +245 -23
- package/dist/mcp/merchant-server.js.map +1 -1
- package/dist/mcp/tools.js +8 -2
- package/dist/mcp/tools.js.map +1 -1
- package/dist/merchant/application/actor.d.ts +85 -0
- package/dist/merchant/application/actor.js +162 -0
- package/dist/merchant/application/actor.js.map +1 -0
- package/dist/merchant/application/money.d.ts +35 -0
- package/dist/merchant/application/money.js +124 -0
- package/dist/merchant/application/money.js.map +1 -0
- package/dist/merchant/application/service.d.ts +228 -0
- package/dist/merchant/application/service.js +262 -0
- package/dist/merchant/application/service.js.map +1 -0
- package/dist/merchant/clock-safety.d.ts +50 -0
- package/dist/merchant/clock-safety.js +153 -0
- package/dist/merchant/clock-safety.js.map +1 -0
- package/dist/merchant/engagement-store.d.ts +32 -0
- package/dist/merchant/engagement-store.js +119 -0
- package/dist/merchant/engagement-store.js.map +1 -0
- package/dist/merchant/exact-product-executors.d.ts +11 -0
- package/dist/merchant/exact-product-executors.js +132 -0
- package/dist/merchant/exact-product-executors.js.map +1 -0
- package/dist/merchant/feed-executors.d.ts +17 -0
- package/dist/merchant/feed-executors.js +151 -0
- package/dist/merchant/feed-executors.js.map +1 -0
- package/dist/merchant/feed-store.d.ts +141 -0
- package/dist/merchant/feed-store.js +496 -0
- package/dist/merchant/feed-store.js.map +1 -0
- package/dist/merchant/follow-store.d.ts +66 -0
- package/dist/merchant/follow-store.js +295 -0
- package/dist/merchant/follow-store.js.map +1 -0
- package/dist/merchant/grant-executors.d.ts +11 -0
- package/dist/merchant/grant-executors.js +136 -0
- package/dist/merchant/grant-executors.js.map +1 -0
- package/dist/merchant/grant-store.d.ts +125 -0
- package/dist/merchant/grant-store.js +313 -0
- package/dist/merchant/grant-store.js.map +1 -0
- package/dist/merchant/inventory-executors.d.ts +47 -0
- package/dist/merchant/inventory-executors.js +91 -0
- package/dist/merchant/inventory-executors.js.map +1 -0
- package/dist/merchant/listing-executors.d.ts +51 -0
- package/dist/merchant/listing-executors.js +100 -0
- package/dist/merchant/listing-executors.js.map +1 -0
- package/dist/merchant/operation-receipts.d.ts +57 -0
- package/dist/merchant/operation-receipts.js +138 -0
- package/dist/merchant/operation-receipts.js.map +1 -0
- package/dist/merchant/promotion-broadcast-recovery.d.ts +22 -0
- package/dist/merchant/promotion-broadcast-recovery.js +74 -0
- package/dist/merchant/promotion-broadcast-recovery.js.map +1 -0
- package/dist/merchant/promotion-broadcast-workflow.d.ts +42 -0
- package/dist/merchant/promotion-broadcast-workflow.js +171 -0
- package/dist/merchant/promotion-broadcast-workflow.js.map +1 -0
- package/dist/merchant/promotion-executors.d.ts +18 -0
- package/dist/merchant/promotion-executors.js +133 -0
- package/dist/merchant/promotion-executors.js.map +1 -0
- package/dist/merchant/promotion-store.d.ts +114 -0
- package/dist/merchant/promotion-store.js +325 -0
- package/dist/merchant/promotion-store.js.map +1 -0
- package/dist/merchant/promotion-time.d.ts +19 -0
- package/dist/merchant/promotion-time.js +162 -0
- package/dist/merchant/promotion-time.js.map +1 -0
- package/dist/merchant/quote-calculator.d.ts +32 -0
- package/dist/merchant/quote-calculator.js +70 -0
- package/dist/merchant/quote-calculator.js.map +1 -0
- package/dist/merchant/service-control-executors.d.ts +15 -0
- package/dist/merchant/service-control-executors.js +52 -0
- package/dist/merchant/service-control-executors.js.map +1 -0
- package/dist/merchant/workbench-service.d.ts +1 -0
- package/dist/merchant/workbench-service.js +11 -1
- package/dist/merchant/workbench-service.js.map +1 -1
- package/dist/merchant-admin/pending-page.d.ts +104 -0
- package/dist/merchant-admin/pending-page.js +20 -0
- package/dist/merchant-admin/pending-page.js.map +1 -1
- package/dist/merchant-admin/rfq-page.d.ts +105 -0
- package/dist/merchant-admin/rfq-page.js +176 -0
- package/dist/merchant-admin/rfq-page.js.map +1 -0
- package/dist/merchant-core/commands.d.ts +27 -0
- package/dist/merchant-core/commands.js +90 -1
- package/dist/merchant-core/commands.js.map +1 -1
- package/dist/merchant-core/executor.d.ts +27 -3
- package/dist/merchant-core/executor.js +13 -4
- package/dist/merchant-core/executor.js.map +1 -1
- package/dist/merchant-core/rfq/artifacts.d.ts +78 -0
- package/dist/merchant-core/rfq/artifacts.js +219 -0
- package/dist/merchant-core/rfq/artifacts.js.map +1 -0
- package/dist/merchant-core/rfq/data-source-adapter.d.ts +49 -0
- package/dist/merchant-core/rfq/data-source-adapter.js +128 -0
- package/dist/merchant-core/rfq/data-source-adapter.js.map +1 -0
- package/dist/merchant-core/rfq/delivery.d.ts +43 -0
- package/dist/merchant-core/rfq/delivery.js +57 -0
- package/dist/merchant-core/rfq/delivery.js.map +1 -0
- package/dist/merchant-core/rfq/fact-resolver.d.ts +76 -0
- package/dist/merchant-core/rfq/fact-resolver.js +220 -0
- package/dist/merchant-core/rfq/fact-resolver.js.map +1 -0
- package/dist/merchant-core/rfq/handoff.d.ts +54 -0
- package/dist/merchant-core/rfq/handoff.js +71 -0
- package/dist/merchant-core/rfq/handoff.js.map +1 -0
- package/dist/merchant-core/rfq/policy.d.ts +77 -0
- package/dist/merchant-core/rfq/policy.js +104 -0
- package/dist/merchant-core/rfq/policy.js.map +1 -0
- package/dist/merchant-core/rfq/pricing.d.ts +48 -0
- package/dist/merchant-core/rfq/pricing.js +150 -0
- package/dist/merchant-core/rfq/pricing.js.map +1 -0
- package/dist/merchant-core/rfq/quote-revisions.d.ts +52 -0
- package/dist/merchant-core/rfq/quote-revisions.js +126 -0
- package/dist/merchant-core/rfq/quote-revisions.js.map +1 -0
- package/dist/merchant-core/rfq/release-coordinator.d.ts +99 -0
- package/dist/merchant-core/rfq/release-coordinator.js +355 -0
- package/dist/merchant-core/rfq/release-coordinator.js.map +1 -0
- package/dist/merchant-core/rfq/repository.d.ts +398 -0
- package/dist/merchant-core/rfq/repository.js +855 -0
- package/dist/merchant-core/rfq/repository.js.map +1 -0
- package/dist/merchant-core/rfq/service.d.ts +398 -0
- package/dist/merchant-core/rfq/service.js +1036 -0
- package/dist/merchant-core/rfq/service.js.map +1 -0
- package/dist/merchant-core/rfq/source-records.d.ts +97 -0
- package/dist/merchant-core/rfq/source-records.js +349 -0
- package/dist/merchant-core/rfq/source-records.js.map +1 -0
- package/dist/merchant-core/rfq/types.d.ts +197 -0
- package/dist/merchant-core/rfq/types.js +110 -0
- package/dist/merchant-core/rfq/types.js.map +1 -0
- package/dist/merchant-core/service.d.ts +118 -1
- package/dist/merchant-core/service.js +202 -7
- package/dist/merchant-core/service.js.map +1 -1
- package/dist/merchant-core/storage/clock-skew-alerts.d.ts +21 -0
- package/dist/merchant-core/storage/clock-skew-alerts.js +67 -0
- package/dist/merchant-core/storage/clock-skew-alerts.js.map +1 -0
- package/dist/merchant-core/storage/leased-job.d.ts +42 -0
- package/dist/merchant-core/storage/leased-job.js +38 -0
- package/dist/merchant-core/storage/leased-job.js.map +1 -0
- package/dist/merchant-core/storage/operation-lifecycle.d.ts +78 -0
- package/dist/merchant-core/storage/operation-lifecycle.js +111 -0
- package/dist/merchant-core/storage/operation-lifecycle.js.map +1 -0
- package/dist/merchant-core/storage/redact.d.ts +29 -0
- package/dist/merchant-core/storage/redact.js +34 -0
- package/dist/merchant-core/storage/redact.js.map +1 -0
- package/dist/merchant-core/storage/schema.d.ts +24 -0
- package/dist/merchant-core/storage/schema.js +22 -0
- package/dist/merchant-core/storage/schema.js.map +1 -0
- package/dist/merchant-core/storage/transaction.d.ts +47 -0
- package/dist/merchant-core/storage/transaction.js +28 -0
- package/dist/merchant-core/storage/transaction.js.map +1 -0
- package/dist/merchant-gateway/entry-server.js +10 -0
- package/dist/merchant-gateway/entry-server.js.map +1 -1
- package/dist/negotiation/domain/objects.d.ts +7 -0
- package/dist/negotiation/domain/objects.js +8 -0
- package/dist/negotiation/domain/objects.js.map +1 -1
- package/dist/negotiation/idempotency/store.d.ts +23 -0
- package/dist/negotiation/idempotency/store.js +72 -1
- package/dist/negotiation/idempotency/store.js.map +1 -1
- package/dist/negotiation/idempotency/types.d.ts +16 -0
- package/dist/negotiation/idempotency/types.js +2 -0
- package/dist/negotiation/idempotency/types.js.map +1 -1
- package/dist/negotiation/lease/store.d.ts +18 -22
- package/dist/negotiation/lease/store.js +133 -88
- package/dist/negotiation/lease/store.js.map +1 -1
- package/dist/negotiation/ledger/event.d.ts +6 -0
- package/dist/negotiation/ledger/event.js +1 -0
- package/dist/negotiation/ledger/event.js.map +1 -1
- package/dist/negotiation/ledger/index.d.ts +4 -2
- package/dist/negotiation/ledger/index.js +1 -0
- package/dist/negotiation/ledger/index.js.map +1 -1
- package/dist/negotiation/ledger/payload-segments.d.ts +51 -0
- package/dist/negotiation/ledger/payload-segments.js +247 -0
- package/dist/negotiation/ledger/payload-segments.js.map +1 -0
- package/dist/negotiation/ledger/store.d.ts +34 -0
- package/dist/negotiation/ledger/store.js +162 -0
- package/dist/negotiation/ledger/store.js.map +1 -1
- package/dist/negotiation/recovery/recover.js +1 -1
- package/dist/negotiation/recovery/recover.js.map +1 -1
- package/dist/privacy/ledger-payload-deletion.d.ts +10 -0
- package/dist/privacy/ledger-payload-deletion.js +31 -0
- package/dist/privacy/ledger-payload-deletion.js.map +1 -0
- package/dist/privacy/local-backup-deletion.d.ts +13 -0
- package/dist/privacy/local-backup-deletion.js +115 -0
- package/dist/privacy/local-backup-deletion.js.map +1 -0
- package/dist/privacy/workbench-retention.d.ts +105 -0
- package/dist/privacy/workbench-retention.js +501 -0
- package/dist/privacy/workbench-retention.js.map +1 -0
- package/dist/runtime/model.d.ts +1 -1
- package/dist/runtime/model.js +3 -3
- package/dist/runtime/model.js.map +1 -1
- package/dist/trust/binding/claims.d.ts +92 -0
- package/dist/trust/binding/claims.js +175 -0
- package/dist/trust/binding/claims.js.map +1 -0
- package/dist/trust/binding/thumbprint.d.ts +35 -0
- package/dist/trust/binding/thumbprint.js +88 -0
- package/dist/trust/binding/thumbprint.js.map +1 -0
- package/dist/trust/binding/verify.d.ts +84 -0
- package/dist/trust/binding/verify.js +121 -0
- package/dist/trust/binding/verify.js.map +1 -0
- package/dist/trust/identity/auth-verifier.d.ts +9 -0
- package/dist/trust/identity/auth-verifier.js +10 -2
- package/dist/trust/identity/auth-verifier.js.map +1 -1
- package/dist/trust/identity/jws.d.ts +22 -1
- package/dist/trust/identity/jws.js +31 -2
- package/dist/trust/identity/jws.js.map +1 -1
- package/package.json +12 -4
- package/skills/kiwi-buyer/SKILL.md +33 -2
|
@@ -0,0 +1,1036 @@
|
|
|
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
|
+
* Merchant RFQ 服务面(设计 v0.1.1 §11.1;Merchant Core 内的 RFQ 子服务)。
|
|
18
|
+
*
|
|
19
|
+
* - 一次编排只调用一个确定性业务核心:本服务不启动自由聊天模型重复
|
|
20
|
+
* 理解请求;提取建议由宿主模型提出、本服务做类型/范围/引用校验。
|
|
21
|
+
* - WorkBuddy 是操作入口不是状态权威:失去宿主连接后,本服务的持久
|
|
22
|
+
* 状态(询盘/报价/审批/审计)仍可经管理页/CLI 读取(Merchant
|
|
23
|
+
* Independence Gate 的本次具体化,§4.3)。
|
|
24
|
+
* - 计价、权限与状态转移由确定性代码处理;模型输出不是审批凭证(I03)。
|
|
25
|
+
* - 金额只接受服务端快照/操作者确认来源;模型提交的最终金额一律拒绝。
|
|
26
|
+
*/
|
|
27
|
+
import { randomUUID } from "node:crypto";
|
|
28
|
+
import { RfqError } from "./types.js";
|
|
29
|
+
import { calculatePricing } from "./pricing.js";
|
|
30
|
+
import { RfqRepository } from "./repository.js";
|
|
31
|
+
import { applyExtractionProposal, computeBlockers, parseCsvInquiry, sha256Hex, } from "./source-records.js";
|
|
32
|
+
import { evaluateFreshness, resolveFactSnapshot, } from "./fact-resolver.js";
|
|
33
|
+
import { RfqArtifactStore } from "./artifacts.js";
|
|
34
|
+
import { RfqReleaseCoordinator } from "./release-coordinator.js";
|
|
35
|
+
import { recordReportedDelivery, DELIVERY_CHANNELS } from "./delivery.js";
|
|
36
|
+
import { recordOwnerRecorded } from "./handoff.js";
|
|
37
|
+
import { diffQuotes, invalidReasonOf, buildPublicProjection } from "./quote-revisions.js";
|
|
38
|
+
/** 幂等记录保留天数(§10.3 建议初值;发布/移交类跟随报价保留,不清理)。 */
|
|
39
|
+
export const IDEMPOTENCY_RETENTION_DAYS = 30;
|
|
40
|
+
/**
|
|
41
|
+
* 幂等保留清理的保护名单:发布/移交准备类关键幂等不提前清理(§10.3)。
|
|
42
|
+
* 有界清理任务(RFQ-014)实现时必须查询本名单——名单内 operation 的
|
|
43
|
+
* 幂等记录跟随对应报价保留策略,不适用 30 天保留。
|
|
44
|
+
*/
|
|
45
|
+
export const IDEMPOTENCY_PRESERVE_OPERATIONS = new Set([
|
|
46
|
+
"rfq.prepare_release",
|
|
47
|
+
"rfq.prepare_handoff",
|
|
48
|
+
]);
|
|
49
|
+
export class MerchantRfqService {
|
|
50
|
+
deps;
|
|
51
|
+
constructor(deps) {
|
|
52
|
+
this.deps = deps;
|
|
53
|
+
}
|
|
54
|
+
repo() {
|
|
55
|
+
return this.deps.repo;
|
|
56
|
+
}
|
|
57
|
+
assertActor(ctx) {
|
|
58
|
+
if (ctx.principalId.trim() === "" || ctx.actor.trim() === "") {
|
|
59
|
+
throw new RfqError("auth", "缺少已认证主体(AuthContext 必须由传输层注入)");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
audit(ctx, operation, objectDigest, result) {
|
|
63
|
+
this.repo().appendAudit({
|
|
64
|
+
actor: ctx.actor,
|
|
65
|
+
operation,
|
|
66
|
+
objectDigest,
|
|
67
|
+
result,
|
|
68
|
+
traceId: ctx.traceId,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// ---- 步骤一/二:导入与提取(§5.1) --------------------------------------
|
|
72
|
+
/** 导入询盘:保存原始材料摘要 + 应用提取 proposal(全部保持未确认)。 */
|
|
73
|
+
ingest(ctx, cmd) {
|
|
74
|
+
this.assertActor(ctx);
|
|
75
|
+
if (cmd.kind !== "manual_text" && cmd.kind !== "csv") {
|
|
76
|
+
throw new RfqError("validation", 'ingest 的 kind 必须是 "manual_text" 或 "csv"');
|
|
77
|
+
}
|
|
78
|
+
if (typeof cmd.content !== "string" || cmd.content.trim() === "") {
|
|
79
|
+
throw new RfqError("source_invalid", "询盘内容不能为空");
|
|
80
|
+
}
|
|
81
|
+
// 输入上限(§17.3):粘贴文本 100 KB;CSV 2 MB(行数上限由 parseCsvInquiry
|
|
82
|
+
// 把关)。超限明确拒绝,不截断后继续正式报价。
|
|
83
|
+
const maxBytes = cmd.kind === "csv" ? 2 * 1024 * 1024 : 100 * 1024;
|
|
84
|
+
if (Buffer.byteLength(cmd.content, "utf8") > maxBytes) {
|
|
85
|
+
throw new RfqError("source_invalid", `单个${cmd.kind === "csv" ? "CSV" : "粘贴文本"}上限 ${Math.floor(maxBytes / 1024)} KB(超限拒绝,不截断)`);
|
|
86
|
+
}
|
|
87
|
+
const { result, replayed } = this.repo().withIdempotency({
|
|
88
|
+
principalId: ctx.principalId,
|
|
89
|
+
operation: "rfq.ingest",
|
|
90
|
+
key: cmd.idempotencyKey,
|
|
91
|
+
request: { kind: cmd.kind, content_sha256: sha256Hex(cmd.content), proposal: cmd.proposal ?? null },
|
|
92
|
+
run: () => this.ingestOnce(ctx, cmd),
|
|
93
|
+
serialize: (r) => r,
|
|
94
|
+
deserialize: (stored) => JSON.parse(stored),
|
|
95
|
+
});
|
|
96
|
+
return { ...result, replayed };
|
|
97
|
+
}
|
|
98
|
+
ingestOnce(ctx, cmd) {
|
|
99
|
+
// 客户显示名/外部引用为操作者提供元数据;原始客户文字始终按不可信内容处理。
|
|
100
|
+
void cmd.displayName;
|
|
101
|
+
void cmd.externalRef;
|
|
102
|
+
const kase = this.repo().createCase();
|
|
103
|
+
const { source } = this.repo().createSource({
|
|
104
|
+
caseId: kase.case_id,
|
|
105
|
+
kind: cmd.kind,
|
|
106
|
+
content: cmd.content,
|
|
107
|
+
receivedAt: this.deps.now(),
|
|
108
|
+
submittedBy: ctx.actor,
|
|
109
|
+
synthetic: false,
|
|
110
|
+
});
|
|
111
|
+
let fields;
|
|
112
|
+
let warnings = [];
|
|
113
|
+
if (cmd.kind === "csv") {
|
|
114
|
+
const parsed = parseCsvInquiry(cmd.content);
|
|
115
|
+
fields = {
|
|
116
|
+
client_ref: "rfq",
|
|
117
|
+
recipient_ref: null,
|
|
118
|
+
terms: {
|
|
119
|
+
currency: "CNY",
|
|
120
|
+
tax_basis: "UNKNOWN",
|
|
121
|
+
tax_rate_bps: null,
|
|
122
|
+
shipping_known: false,
|
|
123
|
+
shipping_minor: null,
|
|
124
|
+
delivery_date: null,
|
|
125
|
+
payment_terms: null,
|
|
126
|
+
},
|
|
127
|
+
lines: parsed.lines.map((l) => ({
|
|
128
|
+
...l,
|
|
129
|
+
confirmation: "unconfirmed",
|
|
130
|
+
confirmation_ref: null,
|
|
131
|
+
evidence_source_ids: [source.source_id],
|
|
132
|
+
})),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
fields = {
|
|
137
|
+
client_ref: "rfq",
|
|
138
|
+
recipient_ref: null,
|
|
139
|
+
terms: {
|
|
140
|
+
currency: "CNY",
|
|
141
|
+
tax_basis: "UNKNOWN",
|
|
142
|
+
tax_rate_bps: null,
|
|
143
|
+
shipping_known: false,
|
|
144
|
+
shipping_minor: null,
|
|
145
|
+
delivery_date: null,
|
|
146
|
+
payment_terms: null,
|
|
147
|
+
},
|
|
148
|
+
lines: [
|
|
149
|
+
{
|
|
150
|
+
line_id: "L1",
|
|
151
|
+
query: cmd.content,
|
|
152
|
+
sku: null,
|
|
153
|
+
quantity: null,
|
|
154
|
+
unit: null,
|
|
155
|
+
confirmation: "unconfirmed",
|
|
156
|
+
confirmation_ref: null,
|
|
157
|
+
evidence_source_ids: [source.source_id],
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (cmd.proposal !== undefined && cmd.proposal.entries.length > 0) {
|
|
163
|
+
const outcome = applyExtractionProposal({
|
|
164
|
+
fields,
|
|
165
|
+
entries: cmd.proposal.entries,
|
|
166
|
+
sourceContent: cmd.content,
|
|
167
|
+
sourceId: source.source_id,
|
|
168
|
+
span: cmd.content,
|
|
169
|
+
});
|
|
170
|
+
fields = outcome.fields;
|
|
171
|
+
warnings = outcome.warnings;
|
|
172
|
+
}
|
|
173
|
+
const blockers = computeBlockers(fields);
|
|
174
|
+
const { case: updated, revision } = this.repo().createCaseRevision({
|
|
175
|
+
caseId: kase.case_id,
|
|
176
|
+
expectedVersion: kase.version,
|
|
177
|
+
fields,
|
|
178
|
+
blockers,
|
|
179
|
+
sourceIds: [source.source_id],
|
|
180
|
+
});
|
|
181
|
+
this.audit(ctx, "rfq.ingest", `case:${kase.case_id}`, `revision:${revision.revision}`);
|
|
182
|
+
return {
|
|
183
|
+
case_id: updated.case_id,
|
|
184
|
+
revision: revision.revision,
|
|
185
|
+
stage: updated.stage,
|
|
186
|
+
blockers,
|
|
187
|
+
source_id: source.source_id,
|
|
188
|
+
warnings,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// ---- 需求修订与关闭 -------------------------------------------------------
|
|
192
|
+
/** 客户修改条件/操作者修订:新 revision + 旧报价替代(§5.2、§8.2)。 */
|
|
193
|
+
revise(ctx, cmd) {
|
|
194
|
+
this.assertActor(ctx);
|
|
195
|
+
const { result, replayed } = this.repo().withIdempotency({
|
|
196
|
+
principalId: ctx.principalId,
|
|
197
|
+
operation: "rfq.revise",
|
|
198
|
+
key: cmd.idempotencyKey,
|
|
199
|
+
request: { case_id: cmd.caseId, expected_revision: cmd.expectedRevision, changes: cmd.changes, source: cmd.source ?? null },
|
|
200
|
+
run: () => this.reviseOnce(ctx, cmd),
|
|
201
|
+
serialize: (r) => r,
|
|
202
|
+
deserialize: (stored) => JSON.parse(stored),
|
|
203
|
+
});
|
|
204
|
+
return { ...result, replayed };
|
|
205
|
+
}
|
|
206
|
+
reviseOnce(ctx, cmd) {
|
|
207
|
+
const kase = this.repo().getCase(cmd.caseId);
|
|
208
|
+
if (kase === undefined)
|
|
209
|
+
throw new RfqError("not_found", `未知询盘 ${cmd.caseId}`);
|
|
210
|
+
if (kase.stage === "CLOSED" || kase.stage === "CANCELLED") {
|
|
211
|
+
throw new RfqError("case_closed", `询盘 ${cmd.caseId} 已是终态,不能修订`);
|
|
212
|
+
}
|
|
213
|
+
const current = this.repo().getCaseRevision(cmd.caseId, kase.current_revision);
|
|
214
|
+
if (current === undefined)
|
|
215
|
+
throw new RfqError("not_found", `询盘 ${cmd.caseId} 缺少当前 revision`);
|
|
216
|
+
// 修订材料:优先客户新消息(新建来源记录);否则必须存在单一主来源
|
|
217
|
+
// 供引用核验——不再对「无来源」做自证式校验(fail-closed,§5.2/§6.2)。
|
|
218
|
+
let newSource;
|
|
219
|
+
if (cmd.source !== undefined) {
|
|
220
|
+
if (typeof cmd.source.content !== "string" || cmd.source.content.trim() === "") {
|
|
221
|
+
throw new RfqError("source_invalid", "修订来源内容不能为空");
|
|
222
|
+
}
|
|
223
|
+
if (Buffer.byteLength(cmd.source.content, "utf8") > 100 * 1024) {
|
|
224
|
+
throw new RfqError("source_invalid", "修订来源上限 100 KB(超限拒绝,不截断)");
|
|
225
|
+
}
|
|
226
|
+
newSource = this.repo().createSource({
|
|
227
|
+
caseId: cmd.caseId,
|
|
228
|
+
kind: "customer_feedback",
|
|
229
|
+
content: cmd.source.content,
|
|
230
|
+
receivedAt: this.deps.now(),
|
|
231
|
+
submittedBy: ctx.actor,
|
|
232
|
+
synthetic: false,
|
|
233
|
+
}).source;
|
|
234
|
+
}
|
|
235
|
+
const sources = current.source_ids;
|
|
236
|
+
const primarySource = sources.length === 1 ? sources[0] : undefined;
|
|
237
|
+
const sourceId = newSource?.source_id ?? primarySource;
|
|
238
|
+
if (sourceId === undefined) {
|
|
239
|
+
throw new RfqError("validation", "修订需要客户新消息原文(source.content)或单一主来源材料");
|
|
240
|
+
}
|
|
241
|
+
const material = newSource !== undefined ? cmd.source.content : (this.repo().getSource(sourceId)?.content ?? "");
|
|
242
|
+
const outcome = applyExtractionProposal({
|
|
243
|
+
fields: current.fields,
|
|
244
|
+
entries: cmd.changes,
|
|
245
|
+
sourceContent: material,
|
|
246
|
+
sourceId,
|
|
247
|
+
span: material,
|
|
248
|
+
});
|
|
249
|
+
const sourceIds = newSource !== undefined && !sources.includes(newSource.source_id)
|
|
250
|
+
? [...sources, newSource.source_id]
|
|
251
|
+
: sources;
|
|
252
|
+
const blockers = computeBlockers(outcome.fields);
|
|
253
|
+
// 关键需求更新 → 先建新 revision,再使旧审批失效(§8.2)。
|
|
254
|
+
const { case: updated, revision } = this.repo().createCaseRevision({
|
|
255
|
+
caseId: cmd.caseId,
|
|
256
|
+
expectedVersion: kase.version,
|
|
257
|
+
fields: outcome.fields,
|
|
258
|
+
blockers,
|
|
259
|
+
sourceIds,
|
|
260
|
+
});
|
|
261
|
+
let superseded = null;
|
|
262
|
+
if (kase.current_quote_id !== null) {
|
|
263
|
+
superseded = kase.current_quote_id;
|
|
264
|
+
this.repo().supersedeCurrentQuote({
|
|
265
|
+
caseId: cmd.caseId,
|
|
266
|
+
expectedVersion: updated.version,
|
|
267
|
+
actor: ctx.actor,
|
|
268
|
+
reason: `需求更新至 revision ${revision.revision};旧版本审批失效`,
|
|
269
|
+
stage: updated.stage,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
this.audit(ctx, "rfq.revise", `case:${cmd.caseId}`, `revision:${revision.revision}`);
|
|
273
|
+
return {
|
|
274
|
+
case_id: updated.case_id,
|
|
275
|
+
revision: revision.revision,
|
|
276
|
+
stage: updated.stage,
|
|
277
|
+
blockers,
|
|
278
|
+
superseded_quote: superseded,
|
|
279
|
+
source_id: newSource?.source_id ?? null,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/** 操作者显式取消/关闭(唯一进入 CANCELLED/CLOSED 的通道;§8.1 v0.1.1)。 */
|
|
283
|
+
closeCase(ctx, cmd) {
|
|
284
|
+
this.assertActor(ctx);
|
|
285
|
+
const { result, replayed } = this.repo().withIdempotency({
|
|
286
|
+
principalId: ctx.principalId,
|
|
287
|
+
operation: "rfq.close",
|
|
288
|
+
key: cmd.idempotencyKey,
|
|
289
|
+
request: { case_id: cmd.caseId, expected_revision: cmd.expectedRevision, outcome: cmd.outcome, reason: cmd.reason ?? null },
|
|
290
|
+
run: () => {
|
|
291
|
+
const kase = this.repo().getCase(cmd.caseId);
|
|
292
|
+
if (kase === undefined)
|
|
293
|
+
throw new RfqError("not_found", `未知询盘 ${cmd.caseId}`);
|
|
294
|
+
if (kase.version !== cmd.expectedRevision) {
|
|
295
|
+
throw new RfqError("version_conflict", `询盘版本已变化(${kase.version} ≠ ${cmd.expectedRevision})`);
|
|
296
|
+
}
|
|
297
|
+
const updated = this.repo().closeCase({
|
|
298
|
+
caseId: cmd.caseId,
|
|
299
|
+
expectedVersion: cmd.expectedRevision,
|
|
300
|
+
stage: cmd.outcome,
|
|
301
|
+
});
|
|
302
|
+
// 未决审批一并失效(§8.1):DRAFT/VALIDATED/PENDING_APPROVAL 报价 →
|
|
303
|
+
// SUPERSEDED,其 PENDING_APPROVAL 发布 → SUPERSEDED(后续确认返回
|
|
304
|
+
// APPROVAL_STALE)。APPROVED/EXPORTED 与审计保留,不重写历史。
|
|
305
|
+
for (const quote of this.repo().listQuotesForCase(cmd.caseId)) {
|
|
306
|
+
if (!["DRAFT", "VALIDATED", "PENDING_APPROVAL"].includes(quote.status))
|
|
307
|
+
continue;
|
|
308
|
+
this.repo().transitionQuote({
|
|
309
|
+
quoteId: quote.quote_id,
|
|
310
|
+
revision: quote.revision,
|
|
311
|
+
from: [quote.status],
|
|
312
|
+
to: "SUPERSEDED",
|
|
313
|
+
actor: ctx.actor,
|
|
314
|
+
reason: `询盘${cmd.outcome === "CANCELLED" ? "已取消" : "已关闭"};未决审批失效`,
|
|
315
|
+
});
|
|
316
|
+
for (const release of this.repo().listReleasesForQuote(quote.quote_id, quote.revision)) {
|
|
317
|
+
if (release.status === "PENDING_APPROVAL") {
|
|
318
|
+
this.repo().transitionRelease(release.release_id, ["PENDING_APPROVAL"], "SUPERSEDED");
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// 指针指向的已替代版本清空(指针失效;stage 保持终态)。
|
|
323
|
+
if (kase.current_quote_id !== null) {
|
|
324
|
+
const pointerQuote = kase.current_quote_id !== null && kase.current_quote_revision !== null
|
|
325
|
+
? this.repo().getQuote(kase.current_quote_id, kase.current_quote_revision)
|
|
326
|
+
: undefined;
|
|
327
|
+
if (pointerQuote === undefined || pointerQuote.status === "SUPERSEDED") {
|
|
328
|
+
this.repo().updateCurrentQuote({
|
|
329
|
+
caseId: cmd.caseId,
|
|
330
|
+
expectedVersion: updated.version,
|
|
331
|
+
quoteId: null,
|
|
332
|
+
quoteRevision: null,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
this.audit(ctx, "rfq.close", `case:${cmd.caseId}`, cmd.outcome);
|
|
337
|
+
return { case_id: updated.case_id, stage: updated.stage };
|
|
338
|
+
},
|
|
339
|
+
serialize: (r) => r,
|
|
340
|
+
deserialize: (stored) => JSON.parse(stored),
|
|
341
|
+
});
|
|
342
|
+
return { ...result, replayed };
|
|
343
|
+
}
|
|
344
|
+
// ---- 读取 -----------------------------------------------------------------
|
|
345
|
+
getCase(ctx, caseId) {
|
|
346
|
+
this.assertActor(ctx);
|
|
347
|
+
const kase = this.repo().getCase(caseId);
|
|
348
|
+
if (kase === undefined)
|
|
349
|
+
throw new RfqError("not_found", `未知询盘 ${caseId}`);
|
|
350
|
+
const revision = this.repo().getCaseRevision(caseId, kase.current_revision);
|
|
351
|
+
if (revision === undefined)
|
|
352
|
+
throw new RfqError("not_found", `询盘 ${caseId} 缺少当前 revision`);
|
|
353
|
+
const now = this.deps.now();
|
|
354
|
+
const quotes = this.repo().listQuotesForCase(caseId).map((q) => ({
|
|
355
|
+
quote_id: q.quote_id,
|
|
356
|
+
revision: q.revision,
|
|
357
|
+
status: q.status,
|
|
358
|
+
totals: JSON.parse(q.pricing_output_json),
|
|
359
|
+
valid_until: q.valid_until,
|
|
360
|
+
...(invalidReasonOf(q.status, q.valid_until, now) !== undefined
|
|
361
|
+
? { invalid_reason: invalidReasonOf(q.status, q.valid_until, now) }
|
|
362
|
+
: {}),
|
|
363
|
+
}));
|
|
364
|
+
return {
|
|
365
|
+
case: kase,
|
|
366
|
+
revision: kase.current_revision,
|
|
367
|
+
fields: revision.fields,
|
|
368
|
+
blockers: computeBlockers(revision.fields),
|
|
369
|
+
quotes,
|
|
370
|
+
releases: this.repo().listReleasesForQuote(kase.current_quote_id ?? "", kase.current_quote_revision ?? 0),
|
|
371
|
+
current_quote_id: kase.current_quote_id,
|
|
372
|
+
current_quote_revision: kase.current_quote_revision,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
/** 报价只读视图(MCP 资源/compare 用;只含授权投影与事件投影)。 */
|
|
376
|
+
getQuoteView(ctx, quoteId, revision) {
|
|
377
|
+
this.assertActor(ctx);
|
|
378
|
+
const quote = this.repo().getQuote(quoteId, revision);
|
|
379
|
+
if (quote === undefined)
|
|
380
|
+
throw new RfqError("not_found", `未知报价 ${quoteId}@${revision}`);
|
|
381
|
+
const now = this.deps.now();
|
|
382
|
+
const invalid = invalidReasonOf(quote.status, quote.valid_until, now);
|
|
383
|
+
return {
|
|
384
|
+
quote_id: quote.quote_id,
|
|
385
|
+
revision: quote.revision,
|
|
386
|
+
case_id: quote.case_id,
|
|
387
|
+
case_revision: quote.case_revision,
|
|
388
|
+
status: quote.status,
|
|
389
|
+
valid_until: quote.valid_until,
|
|
390
|
+
projection: { ...JSON.parse(quote.projection_json), status: quote.status },
|
|
391
|
+
...(invalid !== undefined ? { invalid_reason: invalid } : {}),
|
|
392
|
+
events: this.repo()
|
|
393
|
+
.listQuoteEvents(quoteId, revision)
|
|
394
|
+
.map((e) => ({ event: e.event, actor: e.actor, at: e.at, reason: e.reason })),
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
/** 管理页列表(案例级摘要)。 */
|
|
398
|
+
listCases(ctx, limit = 50) {
|
|
399
|
+
this.assertActor(ctx);
|
|
400
|
+
return this.repo()
|
|
401
|
+
.listCases(Math.min(Math.max(limit, 1), 200))
|
|
402
|
+
.map((c) => {
|
|
403
|
+
try {
|
|
404
|
+
return this.getCase(ctx, c.case_id);
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
})
|
|
410
|
+
.filter((v) => v !== null);
|
|
411
|
+
}
|
|
412
|
+
/** 管理页发布详情(含投影与候选状态;批准走命令日志)。 */
|
|
413
|
+
adminReleaseDetail(ctx, releaseId) {
|
|
414
|
+
this.assertActor(ctx);
|
|
415
|
+
const release = this.repo().getRelease(releaseId);
|
|
416
|
+
if (release === undefined)
|
|
417
|
+
throw new RfqError("not_found", `未知发布 ${releaseId}`);
|
|
418
|
+
const quote = this.repo().getQuote(release.quote_id, release.quote_revision);
|
|
419
|
+
return {
|
|
420
|
+
release: {
|
|
421
|
+
release_id: release.release_id,
|
|
422
|
+
status: release.status,
|
|
423
|
+
candidate_id: release.candidate_id,
|
|
424
|
+
quote_id: release.quote_id,
|
|
425
|
+
quote_revision: release.quote_revision,
|
|
426
|
+
recipient_ref: release.recipient_ref,
|
|
427
|
+
artifact_id: release.artifact_id,
|
|
428
|
+
artifact_sha256: release.artifact_sha256,
|
|
429
|
+
},
|
|
430
|
+
quote: quote === undefined
|
|
431
|
+
? null
|
|
432
|
+
: {
|
|
433
|
+
case_id: quote.case_id,
|
|
434
|
+
case_revision: quote.case_revision,
|
|
435
|
+
status: quote.status,
|
|
436
|
+
projection: {
|
|
437
|
+
...JSON.parse(quote.projection_json),
|
|
438
|
+
status: quote.status,
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
/** 商品搜索(§6.4:完整性显式;「当前页无匹配」≠「全库不存在」)。 */
|
|
444
|
+
async searchProducts(ctx, q) {
|
|
445
|
+
this.assertActor(ctx);
|
|
446
|
+
// lineId 是工具面的行定位上下文(§11.2 match 行级候选):必须是当前
|
|
447
|
+
// revision 中真实存在的需求行,防止对不存在的行做「看似有据」的搜索。
|
|
448
|
+
if (q.lineId !== undefined) {
|
|
449
|
+
if (q.caseId === undefined) {
|
|
450
|
+
throw new RfqError("validation", "lineId 必须与 caseId 同时提供");
|
|
451
|
+
}
|
|
452
|
+
const kase = this.repo().getCase(q.caseId);
|
|
453
|
+
if (kase === undefined)
|
|
454
|
+
throw new RfqError("not_found", `未知询盘 ${q.caseId}`);
|
|
455
|
+
const revision = this.repo().getCaseRevision(q.caseId, kase.current_revision);
|
|
456
|
+
if (revision === undefined || !revision.fields.lines.some((l) => l.line_id === q.lineId)) {
|
|
457
|
+
throw new RfqError("validation", `询盘 ${q.caseId} 当前 revision 不存在需求行 ${q.lineId}`);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
const limit = Math.min(Math.max(q.limit ?? 20, 1), 100);
|
|
461
|
+
const items = await this.deps.dataSource.getProducts({ query: q.query, limit });
|
|
462
|
+
// 上游单页 limit 能力不构成完整目录保证(§6.4;cursor 契约与
|
|
463
|
+
// shopping-cli 联合实现——首版单页,complete 按「是否触顶」显式标注)。
|
|
464
|
+
const complete = items.length < limit;
|
|
465
|
+
return {
|
|
466
|
+
items,
|
|
467
|
+
next_cursor: null,
|
|
468
|
+
complete,
|
|
469
|
+
snapshot_at: this.deps.now(),
|
|
470
|
+
source_version: null,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* 具名人工确认(权威写入通道:管理页表单/CLI 具名交互;§11.2)。
|
|
475
|
+
* 模型工具只能读取确认结果,不能自报 human_confirmed。
|
|
476
|
+
*/
|
|
477
|
+
confirmLines(ctx, cmd) {
|
|
478
|
+
this.assertActor(ctx);
|
|
479
|
+
if (this.deps.confirmationMinter === undefined) {
|
|
480
|
+
throw new RfqError("unavailable", "具名确认通道未配置(只能通过可信管理页/CLI 确认)");
|
|
481
|
+
}
|
|
482
|
+
const kase = this.repo().getCase(cmd.caseId);
|
|
483
|
+
if (kase === undefined)
|
|
484
|
+
throw new RfqError("not_found", `未知询盘 ${cmd.caseId}`);
|
|
485
|
+
if (kase.current_revision !== cmd.expectedRevision) {
|
|
486
|
+
throw new RfqError("version_conflict", `询盘 revision 已变化(${kase.current_revision} ≠ ${cmd.expectedRevision})`);
|
|
487
|
+
}
|
|
488
|
+
const current = this.repo().getCaseRevision(cmd.caseId, kase.current_revision);
|
|
489
|
+
if (current === undefined)
|
|
490
|
+
throw new RfqError("not_found", `询盘 ${cmd.caseId} 缺少当前 revision`);
|
|
491
|
+
const fields = structuredClone(current.fields);
|
|
492
|
+
for (const sel of cmd.selections) {
|
|
493
|
+
const line = fields.lines.find((l) => l.line_id === sel.line_id);
|
|
494
|
+
if (line === undefined)
|
|
495
|
+
throw new RfqError("validation", `未知 line_id:${sel.line_id}`);
|
|
496
|
+
// 服务层入参校验(防御纵深;路由层同样把关):空 SKU 不允许进入
|
|
497
|
+
// 「已确认」状态——否则会以空 SKU 通过 READY 门。
|
|
498
|
+
if (typeof sel.sku !== "string" || sel.sku.trim() === "") {
|
|
499
|
+
throw new RfqError("validation", `行 ${sel.line_id} 确认需要非空 SKU`);
|
|
500
|
+
}
|
|
501
|
+
if (sel.quantity !== undefined && (!Number.isSafeInteger(sel.quantity) || sel.quantity < 1 || sel.quantity > 100_000)) {
|
|
502
|
+
throw new RfqError("validation", `行 ${sel.line_id} 数量必须是 1..100000 的整数`);
|
|
503
|
+
}
|
|
504
|
+
if (sel.unit !== undefined && (typeof sel.unit !== "string" || sel.unit.trim() === "")) {
|
|
505
|
+
throw new RfqError("validation", `行 ${sel.line_id} 单位必须是非空字符串`);
|
|
506
|
+
}
|
|
507
|
+
line.sku = sel.sku;
|
|
508
|
+
if (sel.quantity !== undefined)
|
|
509
|
+
line.quantity = sel.quantity;
|
|
510
|
+
if (sel.unit !== undefined)
|
|
511
|
+
line.unit = sel.unit;
|
|
512
|
+
line.confirmation = "confirmed";
|
|
513
|
+
line.confirmation_ref = this.deps.confirmationMinter({
|
|
514
|
+
caseId: cmd.caseId,
|
|
515
|
+
revision: kase.current_revision,
|
|
516
|
+
lineId: sel.line_id,
|
|
517
|
+
sku: sel.sku,
|
|
518
|
+
actor: ctx.actor,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
const blockers = computeBlockers(fields);
|
|
522
|
+
const { case: updated, revision } = this.repo().createCaseRevision({
|
|
523
|
+
caseId: cmd.caseId,
|
|
524
|
+
expectedVersion: kase.version,
|
|
525
|
+
fields,
|
|
526
|
+
blockers,
|
|
527
|
+
sourceIds: current.source_ids,
|
|
528
|
+
});
|
|
529
|
+
if (kase.current_quote_id !== null) {
|
|
530
|
+
this.repo().supersedeCurrentQuote({
|
|
531
|
+
caseId: cmd.caseId,
|
|
532
|
+
expectedVersion: updated.version,
|
|
533
|
+
actor: ctx.actor,
|
|
534
|
+
reason: `确认更新至 revision ${revision.revision}`,
|
|
535
|
+
stage: updated.stage,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
this.audit(ctx, "rfq.confirm_items", `case:${cmd.caseId}`, `revision:${revision.revision}`);
|
|
539
|
+
return { case_id: updated.case_id, revision: revision.revision, stage: updated.stage, blockers };
|
|
540
|
+
}
|
|
541
|
+
/** MCP 侧确认读取:只核对已确认状态与引用存在性(不自报确认,§11.2)。 */
|
|
542
|
+
readConfirmations(ctx, cmd) {
|
|
543
|
+
this.assertActor(ctx);
|
|
544
|
+
const kase = this.repo().getCase(cmd.caseId);
|
|
545
|
+
if (kase === undefined)
|
|
546
|
+
throw new RfqError("not_found", `未知询盘 ${cmd.caseId}`);
|
|
547
|
+
if (kase.current_revision !== cmd.expectedRevision) {
|
|
548
|
+
throw new RfqError("version_conflict", `询盘 revision 已变化`);
|
|
549
|
+
}
|
|
550
|
+
const revision = this.repo().getCaseRevision(cmd.caseId, kase.current_revision);
|
|
551
|
+
if (revision === undefined)
|
|
552
|
+
throw new RfqError("not_found", `缺少当前 revision`);
|
|
553
|
+
const confirmed = [];
|
|
554
|
+
const missing = [];
|
|
555
|
+
for (const sel of cmd.selections) {
|
|
556
|
+
const line = revision.fields.lines.find((l) => l.line_id === sel.line_id);
|
|
557
|
+
const ok = line !== undefined &&
|
|
558
|
+
line.confirmation === "confirmed" &&
|
|
559
|
+
line.confirmation_ref !== null &&
|
|
560
|
+
line.sku === sel.sku &&
|
|
561
|
+
line.confirmation_ref === sel.confirmation_ref;
|
|
562
|
+
if (ok)
|
|
563
|
+
confirmed.push(sel.line_id);
|
|
564
|
+
else
|
|
565
|
+
missing.push(sel.line_id);
|
|
566
|
+
}
|
|
567
|
+
return { confirmed, missing };
|
|
568
|
+
}
|
|
569
|
+
// ---- 事实与计价(§5.1 步骤四/五) -----------------------------------------
|
|
570
|
+
/** 建立新事实快照;指纹变化时旧报价/候选失效(§6.3)。 */
|
|
571
|
+
async refreshFacts(ctx, cmd) {
|
|
572
|
+
this.assertActor(ctx);
|
|
573
|
+
const { result, replayed } = await this.repo().withIdempotencyAsync({
|
|
574
|
+
principalId: ctx.principalId,
|
|
575
|
+
operation: "rfq.refresh_facts",
|
|
576
|
+
key: cmd.idempotencyKey,
|
|
577
|
+
request: { case_id: cmd.caseId, expected_revision: cmd.expectedRevision },
|
|
578
|
+
run: async () => {
|
|
579
|
+
const kase = this.repo().getCase(cmd.caseId);
|
|
580
|
+
if (kase === undefined)
|
|
581
|
+
throw new RfqError("not_found", `未知询盘 ${cmd.caseId}`);
|
|
582
|
+
if (kase.current_revision !== cmd.expectedRevision) {
|
|
583
|
+
throw new RfqError("version_conflict", `询盘 revision 已变化`);
|
|
584
|
+
}
|
|
585
|
+
if (kase.stage === "CLOSED" || kase.stage === "CANCELLED") {
|
|
586
|
+
throw new RfqError("case_closed", "终态询盘不能刷新事实");
|
|
587
|
+
}
|
|
588
|
+
const revision = this.repo().getCaseRevision(cmd.caseId, kase.current_revision);
|
|
589
|
+
if (revision === undefined)
|
|
590
|
+
throw new RfqError("not_found", `缺少当前 revision`);
|
|
591
|
+
const skus = revision.fields.lines.filter((l) => l.sku !== null).map((l) => l.sku);
|
|
592
|
+
const snapshotId = `snap_${randomUUID()}`;
|
|
593
|
+
const snapshot = await resolveFactSnapshot({
|
|
594
|
+
dataSource: this.deps.dataSource,
|
|
595
|
+
merchantId: this.repo().merchantId,
|
|
596
|
+
caseId: cmd.caseId,
|
|
597
|
+
caseRevision: kase.current_revision,
|
|
598
|
+
skus,
|
|
599
|
+
snapshotId,
|
|
600
|
+
nowIso: this.deps.now(),
|
|
601
|
+
...(this.deps.freshnessSeconds !== undefined ? { freshness: this.deps.freshnessSeconds } : {}),
|
|
602
|
+
});
|
|
603
|
+
this.repo().saveSnapshot({
|
|
604
|
+
snapshotId,
|
|
605
|
+
caseId: cmd.caseId,
|
|
606
|
+
caseRevision: kase.current_revision,
|
|
607
|
+
fields: snapshot.fields,
|
|
608
|
+
contentFingerprint: snapshot.content_fingerprint,
|
|
609
|
+
complete: snapshot.complete,
|
|
610
|
+
fetchedAt: snapshot.fetched_at,
|
|
611
|
+
synthetic: snapshot.synthetic,
|
|
612
|
+
});
|
|
613
|
+
// 指纹变化 → 旧报价失效(新 revision 不需要:事实不是需求字段)。
|
|
614
|
+
let superseded = null;
|
|
615
|
+
const previous = this.repo().getLatestSnapshotForCase(cmd.caseId, snapshotId);
|
|
616
|
+
if (previous !== undefined &&
|
|
617
|
+
previous.content_fingerprint !== snapshot.content_fingerprint &&
|
|
618
|
+
kase.current_quote_id !== null) {
|
|
619
|
+
superseded = kase.current_quote_id;
|
|
620
|
+
this.repo().supersedeCurrentQuote({
|
|
621
|
+
caseId: cmd.caseId,
|
|
622
|
+
expectedVersion: kase.version,
|
|
623
|
+
actor: ctx.actor,
|
|
624
|
+
reason: "事实指纹变化;旧报价失效(源值或源版本变化即失效)",
|
|
625
|
+
stage: "READY",
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
const freshness = evaluateFreshness(snapshot.fields, this.deps.now());
|
|
629
|
+
this.audit(ctx, "rfq.refresh_facts", `case:${cmd.caseId}`, snapshotId);
|
|
630
|
+
return {
|
|
631
|
+
snapshot_id: snapshotId,
|
|
632
|
+
fingerprint: snapshot.content_fingerprint,
|
|
633
|
+
fields: snapshot.fields.length,
|
|
634
|
+
stale: freshness.stale,
|
|
635
|
+
missing_verification: freshness.missing_verification,
|
|
636
|
+
superseded_quote: superseded,
|
|
637
|
+
};
|
|
638
|
+
},
|
|
639
|
+
serialize: (r) => r,
|
|
640
|
+
deserialize: (stored) => JSON.parse(stored),
|
|
641
|
+
});
|
|
642
|
+
return { ...result, replayed };
|
|
643
|
+
}
|
|
644
|
+
/** 确定性计价(Core 计算;不接受模型最终金额,§5.1 步骤五)。 */
|
|
645
|
+
price(ctx, cmd) {
|
|
646
|
+
this.assertActor(ctx);
|
|
647
|
+
const { result, replayed } = this.repo().withIdempotency({
|
|
648
|
+
principalId: ctx.principalId,
|
|
649
|
+
operation: "rfq.price",
|
|
650
|
+
key: cmd.idempotencyKey,
|
|
651
|
+
request: { case_id: cmd.caseId, expected_revision: cmd.expectedRevision, snapshot_id: cmd.snapshotId },
|
|
652
|
+
run: () => this.priceOnce(ctx, cmd),
|
|
653
|
+
serialize: (r) => r,
|
|
654
|
+
deserialize: (stored) => JSON.parse(stored),
|
|
655
|
+
});
|
|
656
|
+
return { ...result, replayed };
|
|
657
|
+
}
|
|
658
|
+
priceOnce(ctx, cmd) {
|
|
659
|
+
const kase = this.repo().getCase(cmd.caseId);
|
|
660
|
+
if (kase === undefined)
|
|
661
|
+
throw new RfqError("not_found", `未知询盘 ${cmd.caseId}`);
|
|
662
|
+
if (kase.stage === "CLOSED" || kase.stage === "CANCELLED") {
|
|
663
|
+
throw new RfqError("case_closed", "终态询盘不能计价");
|
|
664
|
+
}
|
|
665
|
+
if (kase.current_revision !== cmd.expectedRevision) {
|
|
666
|
+
throw new RfqError("version_conflict", `询盘 revision 已变化(${kase.current_revision} ≠ ${cmd.expectedRevision})`);
|
|
667
|
+
}
|
|
668
|
+
const revision = this.repo().getCaseRevision(cmd.caseId, kase.current_revision);
|
|
669
|
+
if (revision === undefined)
|
|
670
|
+
throw new RfqError("not_found", `缺少当前 revision`);
|
|
671
|
+
const blockers = computeBlockers(revision.fields);
|
|
672
|
+
if (blockers.length > 0) {
|
|
673
|
+
throw new RfqError("needs_clarification", `关键字段未确认(${blockers.length} 项):先补齐再计价`);
|
|
674
|
+
}
|
|
675
|
+
const snapshot = this.repo().getSnapshot(cmd.snapshotId);
|
|
676
|
+
if (snapshot === undefined || snapshot.case_id !== cmd.caseId) {
|
|
677
|
+
throw new RfqError("not_found", `未知事实快照 ${cmd.snapshotId}`);
|
|
678
|
+
}
|
|
679
|
+
const factFields = JSON.parse(snapshot.fields_json);
|
|
680
|
+
const priceBySku = new Map();
|
|
681
|
+
for (const f of factFields) {
|
|
682
|
+
if (f.field_path.endsWith(".price_minor")) {
|
|
683
|
+
priceBySku.set(f.field_path.slice("products.".length, -".price_minor".length), f.value);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
// 计价输入:单价只来自已授权快照(经授权的价格规则);优惠为操作者
|
|
687
|
+
// 确认字段(首版固定 0 —— 优惠输入开放属于版本化扩展,§7.4)。
|
|
688
|
+
const pricingLines = revision.fields.lines.map((line) => {
|
|
689
|
+
const sku = line.sku;
|
|
690
|
+
const unitPrice = priceBySku.get(sku);
|
|
691
|
+
if (unitPrice === undefined || unitPrice === null) {
|
|
692
|
+
throw new RfqError("source_unavailable", `SKU ${sku} 的授权价格缺失(价格缺失不降级为演示价)`);
|
|
693
|
+
}
|
|
694
|
+
return {
|
|
695
|
+
line_id: line.line_id,
|
|
696
|
+
sku,
|
|
697
|
+
unit: line.unit ?? "",
|
|
698
|
+
quantity: line.quantity,
|
|
699
|
+
unit_price_minor: unitPrice,
|
|
700
|
+
discount_minor: 0,
|
|
701
|
+
tax_basis: revision.fields.terms.tax_basis,
|
|
702
|
+
tax_rate_bps: revision.fields.terms.tax_rate_bps,
|
|
703
|
+
// 字段证据来源(pricing-input.schema.json 必填):行级证据缺省回溯
|
|
704
|
+
// 到需求 revision 的来源清单(不为空,满足 minItems 1)。
|
|
705
|
+
evidence_source_ids: line.evidence_source_ids.length > 0 ? line.evidence_source_ids : [...revision.source_ids],
|
|
706
|
+
};
|
|
707
|
+
});
|
|
708
|
+
const pricingInput = {
|
|
709
|
+
schema_version: "0.1.0",
|
|
710
|
+
currency: "CNY",
|
|
711
|
+
rounding: "HALF_UP_LINE",
|
|
712
|
+
lines: pricingLines,
|
|
713
|
+
shipping: {
|
|
714
|
+
amount_minor: revision.fields.terms.shipping_minor,
|
|
715
|
+
tax_basis: revision.fields.terms.tax_basis,
|
|
716
|
+
tax_rate_bps: revision.fields.terms.tax_rate_bps,
|
|
717
|
+
evidence_source_ids: [...revision.source_ids],
|
|
718
|
+
},
|
|
719
|
+
};
|
|
720
|
+
const output = calculatePricing(pricingInput);
|
|
721
|
+
// 硬策略(含底价兜底;拒绝只返回理由码)。报价有效期缺省 7 天(模型
|
|
722
|
+
// 不可改变有效期——工具面不暴露该参数;调整走部署配置/策略,§13.1)。
|
|
723
|
+
// 有效期与策略的 max_valid_until_days 同源于 quote_ttl_seconds(cli 装配),
|
|
724
|
+
// 两侧同用向下取整到天,避免「策略 TTL < 缺省 7 天 → 计价必拒」的错配。
|
|
725
|
+
const validityDays = this.deps.quoteValidityDays?.() ?? 7;
|
|
726
|
+
const validUntil = new Date(Date.parse(this.deps.now()) + validityDays * 86_400_000).toISOString();
|
|
727
|
+
const policyCtx = {
|
|
728
|
+
merchantId: this.repo().merchantId,
|
|
729
|
+
lines: pricingLines.map((l) => ({ sku: l.sku, quantity: l.quantity, unit: l.unit, unit_price_minor: l.unit_price_minor })),
|
|
730
|
+
validUntil,
|
|
731
|
+
paymentTerms: revision.fields.terms.payment_terms ?? "",
|
|
732
|
+
facts: factFields,
|
|
733
|
+
nowIso: this.deps.now(),
|
|
734
|
+
};
|
|
735
|
+
this.deps.coordinator.validateWithCurrentPolicy(policyCtx);
|
|
736
|
+
const projection = buildPublicProjection({
|
|
737
|
+
quoteId: "",
|
|
738
|
+
revision: 1,
|
|
739
|
+
caseId: cmd.caseId,
|
|
740
|
+
caseRevision: kase.current_revision,
|
|
741
|
+
clientRef: revision.fields.client_ref,
|
|
742
|
+
recipientRef: revision.fields.recipient_ref ?? "",
|
|
743
|
+
pricingInput,
|
|
744
|
+
pricingOutput: output,
|
|
745
|
+
deliveryTerms: revision.fields.terms.delivery_date ?? "",
|
|
746
|
+
paymentTerms: revision.fields.terms.payment_terms ?? "",
|
|
747
|
+
validUntil,
|
|
748
|
+
dataAsOf: snapshot.fetched_at,
|
|
749
|
+
});
|
|
750
|
+
const quoteId = `qt_${randomUUID()}`;
|
|
751
|
+
const projectionFinal = { ...projection, quote_id: quoteId };
|
|
752
|
+
const quote = this.repo().createQuote({
|
|
753
|
+
quoteId,
|
|
754
|
+
revision: 1,
|
|
755
|
+
caseId: cmd.caseId,
|
|
756
|
+
caseRevision: kase.current_revision,
|
|
757
|
+
snapshotId: cmd.snapshotId,
|
|
758
|
+
factFingerprint: snapshot.content_fingerprint,
|
|
759
|
+
pricingInput,
|
|
760
|
+
pricingOutput: output,
|
|
761
|
+
projection: projectionFinal,
|
|
762
|
+
policyVersion: this.deps.policyVersion(),
|
|
763
|
+
validUntil: policyCtx.validUntil,
|
|
764
|
+
actor: ctx.actor,
|
|
765
|
+
});
|
|
766
|
+
// 新版本替代旧指针(一份 RFQ 同时只有一个 current_quote_revision)。
|
|
767
|
+
if (kase.current_quote_id !== null) {
|
|
768
|
+
this.repo().supersedeCurrentQuote({
|
|
769
|
+
caseId: cmd.caseId,
|
|
770
|
+
expectedVersion: kase.version,
|
|
771
|
+
actor: ctx.actor,
|
|
772
|
+
reason: `新报价 ${quoteId} 替代旧版本`,
|
|
773
|
+
stage: "PRICED",
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
this.repo().updateCurrentQuote({
|
|
777
|
+
caseId: cmd.caseId,
|
|
778
|
+
expectedVersion: this.repo().getCase(cmd.caseId)?.version ?? kase.version,
|
|
779
|
+
quoteId,
|
|
780
|
+
quoteRevision: 1,
|
|
781
|
+
stage: "PRICED",
|
|
782
|
+
});
|
|
783
|
+
this.audit(ctx, "rfq.price", `quote:${quoteId}`, `totals:${output.totals.gross_minor}`);
|
|
784
|
+
return {
|
|
785
|
+
quote_id: quote.quote_id,
|
|
786
|
+
revision: quote.revision,
|
|
787
|
+
status: quote.status,
|
|
788
|
+
totals: output.totals,
|
|
789
|
+
valid_until: quote.valid_until,
|
|
790
|
+
blockers: [],
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
/** 版本差异(§11.1 compare;旧版失效原因显式)。 */
|
|
794
|
+
compare(ctx, a, b) {
|
|
795
|
+
this.assertActor(ctx);
|
|
796
|
+
const qa = this.repo().getQuote(a.quote_id, a.revision);
|
|
797
|
+
const qb = this.repo().getQuote(b.quote_id, b.revision);
|
|
798
|
+
if (qa === undefined || qb === undefined) {
|
|
799
|
+
throw new RfqError("not_found", `未知报价 ${qa === undefined ? a.quote_id : b.quote_id}`);
|
|
800
|
+
}
|
|
801
|
+
const va = { ...JSON.parse(qa.projection_json), status: qa.status };
|
|
802
|
+
const vb = { ...JSON.parse(qb.projection_json), status: qb.status };
|
|
803
|
+
const now = this.deps.now();
|
|
804
|
+
return diffQuotes({ view: va, ...(invalidReasonOf(qa.status, qa.valid_until, now) !== undefined ? { invalidReason: invalidReasonOf(qa.status, qa.valid_until, now) } : {}) }, { view: vb, ...(invalidReasonOf(qb.status, qb.valid_until, now) !== undefined ? { invalidReason: invalidReasonOf(qb.status, qb.valid_until, now) } : {}) });
|
|
805
|
+
}
|
|
806
|
+
// ---- 发布(三阶段)与导出 --------------------------------------------------
|
|
807
|
+
async prepareRelease(ctx, cmd) {
|
|
808
|
+
this.assertActor(ctx);
|
|
809
|
+
// async:prepareRelease 含命令日志登记(异步)。
|
|
810
|
+
const { result, replayed } = await this.repo().withIdempotencyAsync({
|
|
811
|
+
principalId: ctx.principalId,
|
|
812
|
+
operation: "rfq.prepare_release",
|
|
813
|
+
key: cmd.idempotencyKey,
|
|
814
|
+
request: { case_id: cmd.caseId, quote_id: cmd.quoteId, revision: cmd.revision, recipient: cmd.recipientRef ?? null },
|
|
815
|
+
run: async () => {
|
|
816
|
+
const prepared = await this.deps.coordinator.prepareRelease({
|
|
817
|
+
caseId: cmd.caseId,
|
|
818
|
+
quoteId: cmd.quoteId,
|
|
819
|
+
revision: cmd.revision,
|
|
820
|
+
...(cmd.recipientRef !== undefined ? { recipientRef: cmd.recipientRef } : {}),
|
|
821
|
+
actor: ctx.actor,
|
|
822
|
+
prepareCandidate: cmd.prepareCandidate,
|
|
823
|
+
});
|
|
824
|
+
return {
|
|
825
|
+
release_id: prepared.release_id,
|
|
826
|
+
candidate_id: prepared.candidate_id,
|
|
827
|
+
artifact_id: prepared.artifact_id,
|
|
828
|
+
artifact_sha256: prepared.artifact_sha256,
|
|
829
|
+
public_projection_digest: prepared.public_projection_digest,
|
|
830
|
+
warnings: prepared.warnings,
|
|
831
|
+
};
|
|
832
|
+
},
|
|
833
|
+
serialize: (r) => r,
|
|
834
|
+
deserialize: (stored) => JSON.parse(stored),
|
|
835
|
+
});
|
|
836
|
+
return { ...result, replayed };
|
|
837
|
+
}
|
|
838
|
+
getRelease(ctx, releaseId) {
|
|
839
|
+
this.assertActor(ctx);
|
|
840
|
+
const release = this.repo().getRelease(releaseId);
|
|
841
|
+
if (release === undefined)
|
|
842
|
+
throw new RfqError("not_found", `未知发布 ${releaseId}`);
|
|
843
|
+
const quote = this.repo().getQuote(release.quote_id, release.quote_revision);
|
|
844
|
+
const downloadable = release.status === "APPROVED" &&
|
|
845
|
+
quote !== undefined &&
|
|
846
|
+
quote.status === "APPROVED";
|
|
847
|
+
return {
|
|
848
|
+
release_id: release.release_id,
|
|
849
|
+
status: release.status,
|
|
850
|
+
quote_id: release.quote_id,
|
|
851
|
+
quote_revision: release.quote_revision,
|
|
852
|
+
candidate_id: release.candidate_id,
|
|
853
|
+
artifact_id: release.artifact_id,
|
|
854
|
+
recipient_ref: release.recipient_ref,
|
|
855
|
+
downloadable,
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* 权限下载(管理页专用;EXPORTED 唯一触发通道,v0.1.1 §8.2/§11.4)。
|
|
860
|
+
* 调用前必须完成管理页会话认证与归属校验;MCP 资源读取不经过本方法。
|
|
861
|
+
*/
|
|
862
|
+
downloadArtifact(ctx, artifactId) {
|
|
863
|
+
this.assertActor(ctx);
|
|
864
|
+
const artifact = this.repo().getArtifact(artifactId);
|
|
865
|
+
if (artifact === undefined)
|
|
866
|
+
throw new RfqError("not_found", `未知产物 ${artifactId}`);
|
|
867
|
+
if (!artifact.activated) {
|
|
868
|
+
throw new RfqError("forbidden", "产物未激活(批准前不提供下载)");
|
|
869
|
+
}
|
|
870
|
+
const quote = this.repo().getQuote(artifact.quote_id, artifact.quote_revision);
|
|
871
|
+
if (quote === undefined || (quote.status !== "APPROVED" && quote.status !== "EXPORTED")) {
|
|
872
|
+
throw new RfqError("forbidden", "产物对应的报价不是已批准状态");
|
|
873
|
+
}
|
|
874
|
+
// 报价过期(§13.1 报价有效期)→ 新正式下载关闭:不假称客户手中的历史
|
|
875
|
+
// 副本消失,审计与已导出记录不受影响;需要重新提供则重新计价发布。
|
|
876
|
+
const projection = JSON.parse(quote.projection_json);
|
|
877
|
+
if (projection.valid_until !== undefined &&
|
|
878
|
+
Date.parse(projection.valid_until) <= Date.parse(this.deps.now())) {
|
|
879
|
+
throw new RfqError("quote_expired", `报价已过有效期(${projection.valid_until});正式下载关闭,请重新计价发布`);
|
|
880
|
+
}
|
|
881
|
+
const content = this.deps.artifacts.read(artifact);
|
|
882
|
+
if (quote.status === "APPROVED") {
|
|
883
|
+
this.repo().markQuoteExported({ quoteId: quote.quote_id, revision: quote.revision, actor: ctx.actor });
|
|
884
|
+
}
|
|
885
|
+
this.audit(ctx, "rfq.download_artifact", `artifact:${artifactId}`, "ok");
|
|
886
|
+
return {
|
|
887
|
+
content,
|
|
888
|
+
content_type: artifact.content_type,
|
|
889
|
+
filename: `quote-${artifact.quote_id}-v${artifact.quote_revision}.${artifact.content_type === "application/pdf" ? "pdf" : "txt"}`,
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
// ---- 发送与移交 -----------------------------------------------------------
|
|
893
|
+
recordDelivery(ctx, cmd) {
|
|
894
|
+
this.assertActor(ctx);
|
|
895
|
+
const { result, replayed } = this.repo().withIdempotency({
|
|
896
|
+
principalId: ctx.principalId,
|
|
897
|
+
operation: "rfq.record_delivery",
|
|
898
|
+
key: cmd.idempotencyKey,
|
|
899
|
+
request: { quote_id: cmd.quoteId, revision: cmd.revision, channel: cmd.channel, evidence: cmd.evidenceRef },
|
|
900
|
+
run: () => {
|
|
901
|
+
const quote = this.repo().getQuote(cmd.quoteId, cmd.revision);
|
|
902
|
+
if (quote === undefined)
|
|
903
|
+
throw new RfqError("not_found", `未知报价 ${cmd.quoteId}`);
|
|
904
|
+
if (quote.status !== "APPROVED" && quote.status !== "EXPORTED") {
|
|
905
|
+
throw new RfqError("approval_stale", "只有已批准/已导出的报价可以记录发送(导出状态不冒充发送状态)");
|
|
906
|
+
}
|
|
907
|
+
if (!DELIVERY_CHANNELS.includes(cmd.channel)) {
|
|
908
|
+
throw new RfqError("validation", "channel 必须是 manual_wechat/manual_email/manual_other/integrated_channel");
|
|
909
|
+
}
|
|
910
|
+
const row = recordReportedDelivery(this.repo(), {
|
|
911
|
+
quoteId: cmd.quoteId,
|
|
912
|
+
quoteRevision: cmd.revision,
|
|
913
|
+
...(cmd.releaseId !== undefined ? { releaseId: cmd.releaseId } : {}),
|
|
914
|
+
channel: cmd.channel,
|
|
915
|
+
evidenceRef: cmd.evidenceRef,
|
|
916
|
+
actor: ctx.actor,
|
|
917
|
+
});
|
|
918
|
+
this.audit(ctx, "rfq.record_delivery", `delivery:${row.delivery_id}`, "REPORTED_SENT");
|
|
919
|
+
return { delivery_id: row.delivery_id, status: "REPORTED_SENT" };
|
|
920
|
+
},
|
|
921
|
+
serialize: (r) => r,
|
|
922
|
+
deserialize: (stored) => JSON.parse(stored),
|
|
923
|
+
});
|
|
924
|
+
return { ...result, replayed };
|
|
925
|
+
}
|
|
926
|
+
async prepareHandoff(ctx, cmd) {
|
|
927
|
+
this.assertActor(ctx);
|
|
928
|
+
const { result, replayed } = await this.repo().withIdempotencyAsync({
|
|
929
|
+
principalId: ctx.principalId,
|
|
930
|
+
operation: "rfq.prepare_handoff",
|
|
931
|
+
key: cmd.idempotencyKey,
|
|
932
|
+
request: { quote_id: cmd.quoteId, revision: cmd.revision, target: cmd.targetRef, intent: cmd.intentEvidenceRef },
|
|
933
|
+
run: async () => {
|
|
934
|
+
const prepared = await this.deps.coordinator.prepareHandoff({
|
|
935
|
+
quoteId: cmd.quoteId,
|
|
936
|
+
revision: cmd.revision,
|
|
937
|
+
targetRef: cmd.targetRef,
|
|
938
|
+
intentEvidenceRef: cmd.intentEvidenceRef,
|
|
939
|
+
actor: ctx.actor,
|
|
940
|
+
prepareCandidate: cmd.prepareCandidate,
|
|
941
|
+
});
|
|
942
|
+
return {
|
|
943
|
+
handoff_id: prepared.handoff_id,
|
|
944
|
+
candidate_id: prepared.candidate_id,
|
|
945
|
+
packet_digest: prepared.packet_digest,
|
|
946
|
+
};
|
|
947
|
+
},
|
|
948
|
+
serialize: (r) => r,
|
|
949
|
+
deserialize: (stored) => JSON.parse(stored),
|
|
950
|
+
});
|
|
951
|
+
return { ...result, replayed };
|
|
952
|
+
}
|
|
953
|
+
getHandoff(ctx, handoffId) {
|
|
954
|
+
this.assertActor(ctx);
|
|
955
|
+
const handoff = this.repo().getHandoff(handoffId);
|
|
956
|
+
if (handoff === undefined)
|
|
957
|
+
throw new RfqError("not_found", `未知移交 ${handoffId}`);
|
|
958
|
+
return {
|
|
959
|
+
handoff_id: handoff.handoff_id,
|
|
960
|
+
status: handoff.status,
|
|
961
|
+
packet_digest: handoff.packet_digest,
|
|
962
|
+
origin_kind: handoff.origin_kind,
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
/** OWNER_RECORDED(操作者自述已提交目标系统;管理页/CLI 通道)。 */
|
|
966
|
+
markHandoffOwnerRecorded(ctx, handoffId) {
|
|
967
|
+
this.assertActor(ctx);
|
|
968
|
+
recordOwnerRecorded(this.repo(), handoffId, ctx.actor);
|
|
969
|
+
this.audit(ctx, "rfq.handoff_owner_recorded", `handoff:${handoffId}`, "OWNER_RECORDED");
|
|
970
|
+
return { handoff_id: handoffId, status: "OWNER_RECORDED" };
|
|
971
|
+
}
|
|
972
|
+
// ---- 恢复(§9.5) -----------------------------------------------------------
|
|
973
|
+
/** 作业查询(§11.2 get_job;首版长任务同步执行,作业机制为恢复/审计留痕)。 */
|
|
974
|
+
getJob(ctx, jobId) {
|
|
975
|
+
this.assertActor(ctx);
|
|
976
|
+
const job = this.repo().getJob(jobId);
|
|
977
|
+
if (job === undefined)
|
|
978
|
+
throw new RfqError("not_found", `未知作业 ${jobId}`);
|
|
979
|
+
return {
|
|
980
|
+
job_id: job.job_id,
|
|
981
|
+
operation: job.operation,
|
|
982
|
+
status: job.status,
|
|
983
|
+
progress: job.progress,
|
|
984
|
+
error_code: job.error_code,
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* 启动恢复同步(§9.5):候选已死 **或报价已不在 PENDING_APPROVAL**(prepare
|
|
989
|
+
* 崩溃窗口:候选存活但 quote 停在 VALIDATED 等)的发布标 SUPERSEDED——
|
|
990
|
+
* 不冒充「外部操作已撤销」,只是让投影与业务状态一致。
|
|
991
|
+
*/
|
|
992
|
+
recoverReleases() {
|
|
993
|
+
if (this.deps.candidateStatus === undefined)
|
|
994
|
+
return 0;
|
|
995
|
+
let recovered = 0;
|
|
996
|
+
for (const release of this.repo().listReleasesByStatus("PENDING_APPROVAL")) {
|
|
997
|
+
const status = this.deps.candidateStatus(release.candidate_id);
|
|
998
|
+
const candidateAlive = status === "pending_approval" || status === "approved";
|
|
999
|
+
if (candidateAlive) {
|
|
1000
|
+
const quote = this.repo().getQuote(release.quote_id, release.quote_revision);
|
|
1001
|
+
if (quote !== undefined && quote.status === "PENDING_APPROVAL")
|
|
1002
|
+
continue;
|
|
1003
|
+
}
|
|
1004
|
+
this.repo().transitionRelease(release.release_id, ["PENDING_APPROVAL"], "SUPERSEDED");
|
|
1005
|
+
recovered += 1;
|
|
1006
|
+
}
|
|
1007
|
+
return recovered;
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* 幂等记录保留清理(§10.3:30 天;prepare/移交准备类关键幂等跟随报价
|
|
1011
|
+
* 保留策略,不清理)。启动维护时调用。
|
|
1012
|
+
*/
|
|
1013
|
+
pruneExpiredIdempotency() {
|
|
1014
|
+
return this.repo().pruneIdempotency({
|
|
1015
|
+
olderThanDays: IDEMPOTENCY_RETENTION_DAYS,
|
|
1016
|
+
preserveOperations: IDEMPOTENCY_PRESERVE_OPERATIONS,
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* 孤儿产物回收(§10.4 临时产物 TTL):文件已渲染但事务回滚的孤儿文件、
|
|
1021
|
+
* 以及无有效发布引用且超 TTL 的未激活产物行。被有效 release(含待批准)
|
|
1022
|
+
* 引用的文件一律保留;不假称外部已获取的副本消失。启动维护时调用。
|
|
1023
|
+
*/
|
|
1024
|
+
cleanupOrphanArtifacts(input) {
|
|
1025
|
+
if (!Number.isFinite(input.ttlSeconds) || input.ttlSeconds < 0) {
|
|
1026
|
+
throw new RfqError("validation", "ttlSeconds 必须是非负数");
|
|
1027
|
+
}
|
|
1028
|
+
const nowMs = Date.parse(this.deps.now());
|
|
1029
|
+
const cutoffMs = nowMs - input.ttlSeconds * 1000;
|
|
1030
|
+
const referenced = new Set(this.repo().listValidReleaseArtifactPaths());
|
|
1031
|
+
const filesRemoved = this.deps.artifacts.cleanupUnreferencedAll(referenced, { olderThanMs: cutoffMs });
|
|
1032
|
+
const rowsRemoved = this.repo().deleteUnreferencedUnactivatedArtifacts(new Date(cutoffMs).toISOString(), referenced);
|
|
1033
|
+
return { files_removed: filesRemoved, rows_removed: rowsRemoved };
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
//# sourceMappingURL=service.js.map
|