@harrylabsj/kiwi 0.10.0 → 0.12.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 +4 -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 +163 -0
- package/contracts/vectors/binding-thumbprint.json +15 -0
- package/dist/a2a/node.d.ts +98 -2
- package/dist/a2a/node.js +252 -100
- 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 +294 -47
- 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 +49 -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 +24 -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.d.ts +2 -2
- package/dist/agent/buyer/buyer-tools.js +1 -1
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/chat-tools.d.ts +2 -11
- package/dist/agent/chat-tools.js.map +1 -1
- package/dist/agent/fake-chat-model.d.ts +3 -3
- package/dist/agent/fake-chat-model.js +3 -5
- package/dist/agent/fake-chat-model.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-builder.js +4 -4
- package/dist/agent/kernel-builder.js.map +1 -1
- package/dist/agent/kernel.d.ts +15 -5
- package/dist/agent/kernel.js +149 -73
- package/dist/agent/kernel.js.map +1 -1
- package/dist/agent/kiwi-tool.d.ts +33 -0
- package/dist/agent/kiwi-tool.js +17 -0
- package/dist/agent/kiwi-tool.js.map +1 -0
- 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/merchant-tools.d.ts +2 -17
- package/dist/agent/merchant/merchant-tools.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/agent/negotiation-chat.d.ts +3 -2
- package/dist/agent/negotiation-chat.js.map +1 -1
- package/dist/agent/session.d.ts +15 -3
- package/dist/agent/session.js +114 -122
- package/dist/agent/session.js.map +1 -1
- package/dist/agent/skills/tools.d.ts +2 -2
- package/dist/agent/skills/tools.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.d.ts +5 -1
- package/dist/cli.js +260 -274
- 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/enrollment-challenge.d.ts +37 -0
- package/dist/cloud/binding/enrollment-challenge.js +153 -0
- package/dist/cloud/binding/enrollment-challenge.js.map +1 -0
- package/dist/cloud/binding/enrollment-heartbeat.d.ts +26 -0
- package/dist/cloud/binding/enrollment-heartbeat.js +146 -0
- package/dist/cloud/binding/enrollment-heartbeat.js.map +1 -0
- package/dist/cloud/binding/enrollment-key-recovery.d.ts +27 -0
- package/dist/cloud/binding/enrollment-key-recovery.js +127 -0
- package/dist/cloud/binding/enrollment-key-recovery.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 +185 -0
- package/dist/cloud/binding/runtime-challenge.js.map +1 -0
- package/dist/cloud/bootstrap.d.ts +63 -0
- package/dist/cloud/bootstrap.js +1161 -0
- package/dist/cloud/bootstrap.js.map +1 -0
- package/dist/cloud/catalog-client.d.ts +305 -0
- package/dist/cloud/catalog-client.js +962 -0
- package/dist/cloud/catalog-client.js.map +1 -0
- package/dist/cloud/config.d.ts +103 -0
- package/dist/cloud/config.js +274 -0
- package/dist/cloud/config.js.map +1 -0
- package/dist/cloud/http-router.d.ts +63 -0
- package/dist/cloud/http-router.js +135 -0
- package/dist/cloud/http-router.js.map +1 -0
- package/dist/cloud/listing-publisher.d.ts +45 -0
- package/dist/cloud/listing-publisher.js +244 -0
- package/dist/cloud/listing-publisher.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/merchant-connect.d.ts +47 -0
- package/dist/cloud/merchant-connect.js +331 -0
- package/dist/cloud/merchant-connect.js.map +1 -0
- package/dist/cloud/merchant-identity.d.ts +14 -0
- package/dist/cloud/merchant-identity.js +76 -0
- package/dist/cloud/merchant-identity.js.map +1 -0
- package/dist/cloud/onboarding/catalog-pipeline.d.ts +135 -0
- package/dist/cloud/onboarding/catalog-pipeline.js +454 -0
- package/dist/cloud/onboarding/catalog-pipeline.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-import-tabular.d.ts +100 -0
- package/dist/cloud/product-import-tabular.js +1073 -0
- package/dist/cloud/product-import-tabular.js.map +1 -0
- package/dist/cloud/product-source.d.ts +104 -0
- package/dist/cloud/product-source.js +276 -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/profile.d.ts +4 -0
- package/dist/config/profile.js +14 -0
- package/dist/config/profile.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 +385 -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 +258 -0
- package/dist/http/merchant-management/api.js +3022 -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 +641 -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 +476 -0
- package/dist/mcp/merchant-runtime-assembly.js.map +1 -0
- package/dist/mcp/merchant-server.d.ts +66 -1
- package/dist/mcp/merchant-server.js +260 -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/negotiation-observer.d.ts +92 -0
- package/dist/merchant/negotiation-observer.js +278 -0
- package/dist/merchant/negotiation-observer.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/operations-report.d.ts +85 -0
- package/dist/merchant/operations-report.js +227 -0
- package/dist/merchant/operations-report.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/stats-store.d.ts +5 -0
- package/dist/merchant/stats-store.js +18 -0
- package/dist/merchant/stats-store.js.map +1 -1
- 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/catalog-publications.d.ts +28 -0
- package/dist/merchant-gateway/catalog-publications.js +69 -0
- package/dist/merchant-gateway/catalog-publications.js.map +1 -1
- package/dist/merchant-gateway/catalog-tools.js +20 -0
- package/dist/merchant-gateway/catalog-tools.js.map +1 -1
- 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 +152 -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/product-cli.d.ts +2 -2
- package/dist/product-cli.js +24 -9
- package/dist/product-cli.js.map +1 -1
- package/dist/product-init.d.ts +4 -1
- package/dist/product-init.js +39 -11
- package/dist/product-init.js.map +1 -1
- package/dist/product-publish.d.ts +8 -2
- package/dist/product-publish.js +222 -142
- package/dist/product-publish.js.map +1 -1
- package/dist/runtime/fake-model.js +9 -3
- package/dist/runtime/fake-model.js.map +1 -1
- 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 +17 -6
- package/skills/kiwi-buyer/SKILL.md +33 -2
|
@@ -19,6 +19,8 @@ import { finalizeEnvelope } from "../../negotiation/domain/envelope.js";
|
|
|
19
19
|
import { contentDigest } from "../../negotiation/jcs.js";
|
|
20
20
|
import { evaluateConditionalOffer } from "../../negotiation/condition/evaluator.js";
|
|
21
21
|
import { toMinorUnits as losslessToMinorUnits } from "../../protocol/legacy-shopping-negotiation/money.js";
|
|
22
|
+
import { WORKBENCH_CURRENCY_TABLE_VERSION } from "../../merchant/application/money.js";
|
|
23
|
+
import { calculateWorkbenchQuote } from "../../merchant/quote-calculator.js";
|
|
22
24
|
import { createNegotiationPhase, isTerminalPhase, transitionPhase, } from "../../negotiation/state/phase.js";
|
|
23
25
|
export const MERCHANT_CAPABILITY = "com.harrylabsj.kiwi.shopping.negotiation";
|
|
24
26
|
export const MERCHANT_SKU = "SKU-001";
|
|
@@ -91,6 +93,11 @@ function seedEnvelope(seed) {
|
|
|
91
93
|
* 报价可被无限期接受)。24h 窗口,accept 时校验(offer_expired 拒绝)。 */
|
|
92
94
|
export const OFFER_VALIDITY_MS = 24 * 60 * 60 * 1000;
|
|
93
95
|
function offerTerms(opts, now) {
|
|
96
|
+
const defaultValidUntil = Date.parse(now) + OFFER_VALIDITY_MS;
|
|
97
|
+
const cap = opts.validUntilCap === undefined ? undefined : Date.parse(opts.validUntilCap);
|
|
98
|
+
const validUntil = cap !== undefined && Number.isFinite(cap)
|
|
99
|
+
? Math.min(defaultValidUntil, cap)
|
|
100
|
+
: defaultValidUntil;
|
|
94
101
|
return {
|
|
95
102
|
items: [
|
|
96
103
|
{
|
|
@@ -108,7 +115,7 @@ function offerTerms(opts, now) {
|
|
|
108
115
|
...(opts.handoff_destination !== undefined
|
|
109
116
|
? { handoff_destination: opts.handoff_destination }
|
|
110
117
|
: {}),
|
|
111
|
-
valid_until: new Date(
|
|
118
|
+
valid_until: new Date(validUntil).toISOString(),
|
|
112
119
|
};
|
|
113
120
|
}
|
|
114
121
|
function buildAgreement(input) {
|
|
@@ -141,16 +148,21 @@ const textReply = (text, taskState = "working") => ({
|
|
|
141
148
|
/** 商品源不可用(源宕机/未知 SKU/价格 lossy)且未开 demo 回退时抛出。
|
|
142
149
|
* handle 层捕获后 decline(temporarily_unavailable),而非报演示价。 */
|
|
143
150
|
class ProductSourceUnavailableError extends Error {
|
|
151
|
+
sourceCode;
|
|
144
152
|
constructor(sku, cause) {
|
|
145
153
|
super(`商品源不可用(${sku}):${cause instanceof Error ? cause.message : String(cause ?? "")}`.trim());
|
|
146
154
|
this.name = "ProductSourceUnavailableError";
|
|
155
|
+
this.sourceCode = cause !== null && typeof cause === "object" && typeof cause.code === "string"
|
|
156
|
+
? cause.code
|
|
157
|
+
: undefined;
|
|
147
158
|
}
|
|
148
159
|
}
|
|
149
160
|
/** 商业拒绝(offer 未知/已关闭/terms_digest 不匹配/终态重开)。
|
|
150
161
|
* decline 消息由 pipeline 按 reason_code 自动构造。 */
|
|
151
|
-
const declineReply = (reasonCode = "state_conflict") => ({
|
|
162
|
+
const declineReply = (reasonCode = "state_conflict", message) => ({
|
|
152
163
|
kind: "declined",
|
|
153
164
|
reasonCode,
|
|
165
|
+
...(message !== undefined ? { message } : {}),
|
|
154
166
|
taskState: "completed",
|
|
155
167
|
});
|
|
156
168
|
const envelopeReply = (reply) => ({
|
|
@@ -168,7 +180,9 @@ export function createMerchantHandler(options) {
|
|
|
168
180
|
const offerPriceMinor = options.offerPriceMinor ?? MERCHANT_OFFER_PRICE_MINOR;
|
|
169
181
|
const allowDemoPriceFallback = options.allowDemoPriceFallback ?? false;
|
|
170
182
|
// BUG-07:merchantPolicy 支持静态值或 provider——每请求解析运行中策略。
|
|
171
|
-
const policyOf = () => typeof options.merchantPolicy === "function"
|
|
183
|
+
const policyOf = () => typeof options.merchantPolicy === "function"
|
|
184
|
+
? options.merchantPolicy()
|
|
185
|
+
: options.merchantPolicy;
|
|
172
186
|
const conditionalByNegotiation = new Map();
|
|
173
187
|
// 审查 P2-D:终态(AGREEMENT_REACHED / WITHDRAWN / DECLINED / CANCELLED)
|
|
174
188
|
// 不得以同一 negotiation_id 重开(§17.4/§21.2)——运行时此前无任何终态
|
|
@@ -226,9 +240,19 @@ export function createMerchantHandler(options) {
|
|
|
226
240
|
case "accept_nonbinding":
|
|
227
241
|
return { type: "accept_nonbinding", offer_id: offerId };
|
|
228
242
|
case "withdraw":
|
|
229
|
-
return {
|
|
243
|
+
return {
|
|
244
|
+
type: "withdraw",
|
|
245
|
+
scope: envelope.payload?.scope === "negotiation"
|
|
246
|
+
? "negotiation"
|
|
247
|
+
: "offer",
|
|
248
|
+
};
|
|
230
249
|
case "decline":
|
|
231
|
-
return {
|
|
250
|
+
return {
|
|
251
|
+
type: "decline",
|
|
252
|
+
scope: envelope.payload?.scope === "negotiation"
|
|
253
|
+
? "negotiation"
|
|
254
|
+
: "offer",
|
|
255
|
+
};
|
|
232
256
|
case "cancel":
|
|
233
257
|
return { type: "cancel" };
|
|
234
258
|
default:
|
|
@@ -241,7 +265,10 @@ export function createMerchantHandler(options) {
|
|
|
241
265
|
const appendPhaseTransition = async (negotiationId, toPhase, fromPhase) => {
|
|
242
266
|
const current = phaseStateByNegotiation.get(negotiationId);
|
|
243
267
|
const effectiveFrom = fromPhase ?? current?.phase ?? "OPEN";
|
|
244
|
-
phaseStateByNegotiation.set(negotiationId, {
|
|
268
|
+
phaseStateByNegotiation.set(negotiationId, {
|
|
269
|
+
...(current ?? createNegotiationPhase(negotiationId)),
|
|
270
|
+
phase: toPhase,
|
|
271
|
+
});
|
|
245
272
|
await ledger.append({
|
|
246
273
|
event_kind: "state_transition",
|
|
247
274
|
negotiation_id: negotiationId,
|
|
@@ -262,9 +289,11 @@ export function createMerchantHandler(options) {
|
|
|
262
289
|
const PRICE_CACHE_TTL_MS = 10 * 60 * 1000;
|
|
263
290
|
const priceBySku = new Map();
|
|
264
291
|
/** 从真实商品源解析 SKU 价目;源不可用/查不到时回退演示价并返回注记。 */
|
|
265
|
-
const resolveProduct = async (sku) => {
|
|
292
|
+
const resolveProduct = async (sku, resolveOptions = {}) => {
|
|
266
293
|
const cached = priceBySku.get(sku);
|
|
267
|
-
|
|
294
|
+
// force=true(成交前重验,T047)绕过缓存:许可有效性必须按**当前**商品事实
|
|
295
|
+
// 判定,而不是十分钟内的历史快照。
|
|
296
|
+
if (cached !== undefined && resolveOptions.force !== true) {
|
|
268
297
|
if (Date.parse(now()) - cached.at <= PRICE_CACHE_TTL_MS)
|
|
269
298
|
return cached;
|
|
270
299
|
priceBySku.delete(sku); // TTL 过期:重新解析(价格会变)
|
|
@@ -289,6 +318,7 @@ export function createMerchantHandler(options) {
|
|
|
289
318
|
: {}),
|
|
290
319
|
...(product.stock !== undefined ? { stock: product.stock } : {}),
|
|
291
320
|
...(product.title !== undefined ? { title: product.title } : {}),
|
|
321
|
+
...(product.valid_until !== undefined ? { valid_until: product.valid_until } : {}),
|
|
292
322
|
};
|
|
293
323
|
priceBySku.set(sku, resolved);
|
|
294
324
|
return resolved;
|
|
@@ -313,16 +343,67 @@ export function createMerchantHandler(options) {
|
|
|
313
343
|
};
|
|
314
344
|
/** resolveProduct 的 fail-closed 包装:商品源不可用且未开 demo 回退时返回
|
|
315
345
|
* null(调用方 decline temporarily_unavailable),否则返回解析结果。 */
|
|
316
|
-
const resolveProductOrDecline = async (sku) => {
|
|
346
|
+
const resolveProductOrDecline = async (sku, options = {}) => {
|
|
317
347
|
try {
|
|
318
|
-
return await resolveProduct(sku);
|
|
348
|
+
return { product: await resolveProduct(sku, options) };
|
|
319
349
|
}
|
|
320
350
|
catch (err) {
|
|
321
|
-
if (err instanceof ProductSourceUnavailableError)
|
|
322
|
-
return
|
|
351
|
+
if (err instanceof ProductSourceUnavailableError) {
|
|
352
|
+
return { declined: declineReply("temporarily_unavailable", err.sourceCode === "PRODUCTS_NOT_CONFIGURED"
|
|
353
|
+
? "暂无可报价商品,请先导入商品;导入后系统会继续服务检查。"
|
|
354
|
+
: undefined) };
|
|
355
|
+
}
|
|
323
356
|
throw err;
|
|
324
357
|
}
|
|
325
358
|
};
|
|
359
|
+
const resolvePromotionQuote = (sku, quantity, basePriceMinor, currency, floorMinor) => {
|
|
360
|
+
if (options.promotionPrice === undefined)
|
|
361
|
+
return { kind: "none" };
|
|
362
|
+
let value;
|
|
363
|
+
try {
|
|
364
|
+
value = options.promotionPrice({ sku, quantity });
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
return { kind: "unavailable" };
|
|
368
|
+
}
|
|
369
|
+
if (value === undefined)
|
|
370
|
+
return { kind: "none" };
|
|
371
|
+
const calculated = calculateWorkbenchQuote({
|
|
372
|
+
base: {
|
|
373
|
+
currency,
|
|
374
|
+
amount_minor: String(basePriceMinor),
|
|
375
|
+
currency_table_version: WORKBENCH_CURRENCY_TABLE_VERSION,
|
|
376
|
+
},
|
|
377
|
+
quantity,
|
|
378
|
+
privateFloorMinor: String(floorMinor),
|
|
379
|
+
promotions: [
|
|
380
|
+
{
|
|
381
|
+
promotion_id: value.promotionId,
|
|
382
|
+
revision: value.revision,
|
|
383
|
+
unit_price: {
|
|
384
|
+
currency: value.currency,
|
|
385
|
+
amount_minor: value.amountMinor,
|
|
386
|
+
currency_table_version: WORKBENCH_CURRENCY_TABLE_VERSION,
|
|
387
|
+
},
|
|
388
|
+
ends_at: value.endsAt,
|
|
389
|
+
priority: 0,
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
});
|
|
393
|
+
if (calculated.status !== "quoted" || calculated.source.kind !== "promotion") {
|
|
394
|
+
return { kind: "invalid" };
|
|
395
|
+
}
|
|
396
|
+
if (Date.parse(value.endsAt) <= Date.parse(now()))
|
|
397
|
+
return { kind: "invalid" };
|
|
398
|
+
const priceMinor = Number(calculated.unit_price.amount_minor);
|
|
399
|
+
return {
|
|
400
|
+
kind: "applied",
|
|
401
|
+
priceMinor,
|
|
402
|
+
promotionId: value.promotionId,
|
|
403
|
+
revision: value.revision,
|
|
404
|
+
endsAt: value.endsAt,
|
|
405
|
+
};
|
|
406
|
+
};
|
|
326
407
|
const appendSent = async (reply) => {
|
|
327
408
|
await ledger.append({
|
|
328
409
|
event_kind: "message_sent",
|
|
@@ -354,7 +435,7 @@ export function createMerchantHandler(options) {
|
|
|
354
435
|
// active_offer_id / last conditional_offer 一次算出。此前按 phase 与
|
|
355
436
|
// conditional 分两趟遍历每条链,长驻 merchant 启动时间随磋商数线性放大
|
|
356
437
|
// (O(total events) 的全量恢复是正确性必需,这里只减掉冗余遍历)。
|
|
357
|
-
const events = ledger.events(negotiationId);
|
|
438
|
+
const events = ledger.events(negotiationId).map((event) => ledger.resolvePayload(event));
|
|
358
439
|
let phase = "OPEN";
|
|
359
440
|
// 审查 K-M15:恢复完整相位状态——AWAITING_CLARIFICATION 的 resume_phase
|
|
360
441
|
// 由「进入它的转换的 from_phase」推导(进入只能是 OPEN/OFFER_OPEN);
|
|
@@ -372,7 +453,9 @@ export function createMerchantHandler(options) {
|
|
|
372
453
|
if (event.event_kind !== "message_sent")
|
|
373
454
|
continue;
|
|
374
455
|
const envelope = event.wire_payload;
|
|
375
|
-
if (envelope?.action === "offer" ||
|
|
456
|
+
if (envelope?.action === "offer" ||
|
|
457
|
+
envelope?.action === "counter_offer" ||
|
|
458
|
+
envelope?.action === "conditional_offer") {
|
|
376
459
|
const offerId = envelope.payload?.offer_id;
|
|
377
460
|
if (typeof offerId === "string" && offerId !== "")
|
|
378
461
|
activeOfferId = offerId;
|
|
@@ -441,8 +524,7 @@ export function createMerchantHandler(options) {
|
|
|
441
524
|
/** 数量校验(审查 P2):数量存在时必须是正整数——0/负数/小数按结构化
|
|
442
525
|
* 无效拒绝,不进 offer terms(否则批量价/条件成交按无意义数量求值);
|
|
443
526
|
* 未报数量沿用 MERCHANT_QUANTITY 缺省口径(不变)。 */
|
|
444
|
-
const invalidQuantity = (raw) => raw !== undefined &&
|
|
445
|
-
(typeof raw !== "number" || !Number.isInteger(raw) || raw <= 0);
|
|
527
|
+
const invalidQuantity = (raw) => raw !== undefined && (typeof raw !== "number" || !Number.isInteger(raw) || raw <= 0);
|
|
446
528
|
const floorMinorForSku = (sku) => {
|
|
447
529
|
const mp = policyOf();
|
|
448
530
|
const floorValue = mp?.price_floors?.[sku] ?? mp?.min_unit_price_private;
|
|
@@ -457,12 +539,60 @@ export function createMerchantHandler(options) {
|
|
|
457
539
|
const deliveryBefore = () => resolveDeliveryBefore(policyOf(), now());
|
|
458
540
|
/** 买家还价(major→minor;KNP 里 buyer counter 的 unit_price)。 */
|
|
459
541
|
const clampToBounds = (minor, floor, list) => Math.min(list, Math.max(minor, floor));
|
|
542
|
+
/**
|
|
543
|
+
* 对买家可见的**自动折扣边界**(公开策略值:max_auto_discount_percent)。
|
|
544
|
+
*
|
|
545
|
+
* 安全要点(T045「不泄露底价」):商家对买家的任何报价都必须 clamp 到
|
|
546
|
+
* **公开边界**而不是 clamp 到私有底价——把还价 clamp 到底价再回给买家,
|
|
547
|
+
* 等于一次极低还价即可探出私有底价(一次探测即泄露精确值)。
|
|
548
|
+
* 私有底价只用来判断「这个价能不能自动报」,绝不出现在返回的条款里。
|
|
549
|
+
*/
|
|
550
|
+
/**
|
|
551
|
+
* 运行中规则的摘要(T047):接受成交前必须重验——商家改了规则/促销/底价后,
|
|
552
|
+
* 旧 conditional 的许可即失效,不能按旧价成交(设计 §10.2「审批时商品/规则
|
|
553
|
+
* 已变化 → 使旧候选失效或重新确认,不能执行过期许可」)。
|
|
554
|
+
*/
|
|
555
|
+
const policyDigest = () => contentDigest((policyOf() ?? {}));
|
|
556
|
+
/** 商品事实指纹(T047):价格/币种变化同样使旧许可失效。 */
|
|
557
|
+
const productFingerprint = (facts) => contentDigest({
|
|
558
|
+
sku: facts.sku,
|
|
559
|
+
priceMinor: facts.priceMinor,
|
|
560
|
+
currency: facts.currency,
|
|
561
|
+
});
|
|
562
|
+
const publicDiscountBoundMinor = (listMinor, sku) => {
|
|
563
|
+
const policy = policyOf();
|
|
564
|
+
const autoRaw = policy?.max_auto_discount_percent;
|
|
565
|
+
const auto = typeof autoRaw === "number" && Number.isFinite(autoRaw) && autoRaw > 0 ? autoRaw : 0;
|
|
566
|
+
// 促销本身是**公开条款**(promos[sku].bulk_discount_percent),因此公开边界
|
|
567
|
+
// 取其与自动折扣的较大者;未公布任何折扣时边界 = list(不自动折扣)。
|
|
568
|
+
const promoPct = policy?.promos?.[sku]?.bulk_discount_percent ?? 0;
|
|
569
|
+
const pct = Math.max(auto, Number.isFinite(promoPct) && promoPct > 0 ? promoPct : 0);
|
|
570
|
+
return applyDiscountPercentMinor(listMinor, pct);
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* 商品事实闸门(T046):数据过期或数量超过可得库存 → 明确不可报价。
|
|
574
|
+
* 设计 §10.1:「数据到期后停止相关自动报价或注明需人工确认,不把库存未知
|
|
575
|
+
* 说成有货」。**不在这里做任何兜底定价**(演示价已在配置层被云端拒绝)。
|
|
576
|
+
*/
|
|
577
|
+
const factsUnusable = (facts, quantity) => {
|
|
578
|
+
if (facts.valid_until !== undefined) {
|
|
579
|
+
const until = Date.parse(facts.valid_until);
|
|
580
|
+
if (!Number.isFinite(until) || until < Date.parse(now()))
|
|
581
|
+
return true;
|
|
582
|
+
}
|
|
583
|
+
if (facts.stock !== undefined && quantity > facts.stock)
|
|
584
|
+
return true;
|
|
585
|
+
return false;
|
|
586
|
+
};
|
|
460
587
|
switch (envelope.action) {
|
|
461
588
|
case "inquiry": {
|
|
462
589
|
// 入站消息由 A2A pipeline 统一落 message_received(§22);这里不再
|
|
463
590
|
// 重复落账——此前 appendSent(envelope) 把买家的 inquiry 记为 merchant
|
|
464
591
|
// 自己"发送"(sender=merchant),审计语义错位且重复。
|
|
465
|
-
|
|
592
|
+
const resolved = await resolveProductOrDecline(MERCHANT_SKU);
|
|
593
|
+
if ("declined" in resolved)
|
|
594
|
+
return resolved.declined;
|
|
595
|
+
return textReply(`We carry ${resolved.product.title ?? MERCHANT_SKU} at ${(resolved.product.priceMinor / 100).toFixed(2)} ${resolved.product.currency}/piece; ask for delivery details.`);
|
|
466
596
|
}
|
|
467
597
|
case "rfq": {
|
|
468
598
|
const payload = envelope.payload;
|
|
@@ -474,12 +604,23 @@ export function createMerchantHandler(options) {
|
|
|
474
604
|
const floorMinor = floorMinorForSku(sku);
|
|
475
605
|
if (floorMinor === null)
|
|
476
606
|
return declineReply("temporarily_unavailable");
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
479
|
-
return
|
|
607
|
+
const resolved = await resolveProductOrDecline(sku);
|
|
608
|
+
if ("declined" in resolved)
|
|
609
|
+
return resolved.declined;
|
|
610
|
+
const product = resolved.product;
|
|
480
611
|
const { priceMinor, currency, note, handoff_destination } = product;
|
|
481
|
-
|
|
482
|
-
|
|
612
|
+
if (factsUnusable(product, quantity))
|
|
613
|
+
return declineReply("temporarily_unavailable");
|
|
614
|
+
const promotion = resolvePromotionQuote(sku, quantity, priceMinor, currency, floorMinor);
|
|
615
|
+
if (promotion.kind === "unavailable")
|
|
616
|
+
return declineReply("temporarily_unavailable");
|
|
617
|
+
if (promotion.kind === "invalid")
|
|
618
|
+
return declineReply("approval_required");
|
|
619
|
+
// 确定性:offer = list 价(公开价)。list < floor 是配置矛盾——此时
|
|
620
|
+
// 用 floor 兜底会把私有底价直接报给买家(T045 泄露面),因此拒绝自动报价。
|
|
621
|
+
const effectivePriceMinor = promotion.kind === "applied" ? promotion.priceMinor : priceMinor;
|
|
622
|
+
if (effectivePriceMinor < floorMinor)
|
|
623
|
+
return declineReply("approval_required");
|
|
483
624
|
const reply = seedEnvelope({
|
|
484
625
|
negotiation_id: negotiationId,
|
|
485
626
|
in_reply_to: inReplyTo,
|
|
@@ -489,7 +630,15 @@ export function createMerchantHandler(options) {
|
|
|
489
630
|
payload: {
|
|
490
631
|
type: "offer",
|
|
491
632
|
offer_id: newOfferId(),
|
|
492
|
-
terms: offerTerms({
|
|
633
|
+
terms: offerTerms({
|
|
634
|
+
sku,
|
|
635
|
+
priceMinor: effectivePriceMinor,
|
|
636
|
+
quantity,
|
|
637
|
+
currency,
|
|
638
|
+
handoff_destination,
|
|
639
|
+
deliveryBefore: deliveryBefore(),
|
|
640
|
+
...(promotion.kind === "applied" ? { validUntilCap: promotion.endsAt } : {}),
|
|
641
|
+
}, now()),
|
|
493
642
|
},
|
|
494
643
|
...(note !== undefined ? { public_message: note } : {}),
|
|
495
644
|
});
|
|
@@ -516,12 +665,23 @@ export function createMerchantHandler(options) {
|
|
|
516
665
|
const floorMinor = floorMinorForSku(sku);
|
|
517
666
|
if (floorMinor === null)
|
|
518
667
|
return declineReply("temporarily_unavailable");
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
521
|
-
return
|
|
668
|
+
const resolved = await resolveProductOrDecline(sku);
|
|
669
|
+
if ("declined" in resolved)
|
|
670
|
+
return resolved.declined;
|
|
671
|
+
const product = resolved.product;
|
|
522
672
|
const { priceMinor, currency, note, handoff_destination } = product;
|
|
523
|
-
|
|
524
|
-
|
|
673
|
+
if (factsUnusable(product, quantity))
|
|
674
|
+
return declineReply("temporarily_unavailable");
|
|
675
|
+
const promotion = resolvePromotionQuote(sku, quantity, priceMinor, currency, floorMinor);
|
|
676
|
+
if (promotion.kind === "unavailable")
|
|
677
|
+
return declineReply("temporarily_unavailable");
|
|
678
|
+
if (promotion.kind === "invalid")
|
|
679
|
+
return declineReply("approval_required");
|
|
680
|
+
// 确定性:counter = list 价(公开价);list < floor 时拒绝自动报价
|
|
681
|
+
// (用 floor 兜底=把底价报给买家)。
|
|
682
|
+
const effectivePriceMinor = promotion.kind === "applied" ? promotion.priceMinor : priceMinor;
|
|
683
|
+
if (effectivePriceMinor < floorMinor)
|
|
684
|
+
return declineReply("approval_required");
|
|
525
685
|
const reply = seedEnvelope({
|
|
526
686
|
negotiation_id: negotiationId,
|
|
527
687
|
in_reply_to: inReplyTo,
|
|
@@ -532,7 +692,15 @@ export function createMerchantHandler(options) {
|
|
|
532
692
|
type: "counter_offer",
|
|
533
693
|
offer_id: newOfferId(),
|
|
534
694
|
responding_to_offer_id: buyerOffer.offer_id ?? "",
|
|
535
|
-
proposed_terms: offerTerms({
|
|
695
|
+
proposed_terms: offerTerms({
|
|
696
|
+
sku,
|
|
697
|
+
priceMinor: effectivePriceMinor,
|
|
698
|
+
quantity,
|
|
699
|
+
currency,
|
|
700
|
+
handoff_destination,
|
|
701
|
+
deliveryBefore: deliveryBefore(),
|
|
702
|
+
...(promotion.kind === "applied" ? { validUntilCap: promotion.endsAt } : {}),
|
|
703
|
+
}, now()),
|
|
536
704
|
},
|
|
537
705
|
...(note !== undefined ? { public_message: note } : {}),
|
|
538
706
|
});
|
|
@@ -557,22 +725,46 @@ export function createMerchantHandler(options) {
|
|
|
557
725
|
const floorMinor = floorMinorForSku(sku);
|
|
558
726
|
if (floorMinor === null)
|
|
559
727
|
return declineReply("temporarily_unavailable");
|
|
560
|
-
const
|
|
561
|
-
if (
|
|
562
|
-
return
|
|
728
|
+
const resolved = await resolveProductOrDecline(sku);
|
|
729
|
+
if ("declined" in resolved)
|
|
730
|
+
return resolved.declined;
|
|
731
|
+
const product = resolved.product;
|
|
563
732
|
const { priceMinor, currency, note, handoff_destination } = product;
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
|
|
733
|
+
if (factsUnusable(product, quantity))
|
|
734
|
+
return declineReply("temporarily_unavailable");
|
|
735
|
+
const authorityPromotion = resolvePromotionQuote(sku, quantity, priceMinor, currency, floorMinor);
|
|
736
|
+
if (authorityPromotion.kind === "unavailable") {
|
|
737
|
+
return declineReply("temporarily_unavailable");
|
|
738
|
+
}
|
|
739
|
+
if (authorityPromotion.kind === "invalid")
|
|
740
|
+
return declineReply("approval_required");
|
|
741
|
+
// 确定性(无 LLM):买家还价只在**公开折扣边界**内响应——
|
|
742
|
+
// 边界 = list×(1-max_auto_discount_percent),是公开策略值;
|
|
743
|
+
// 高于 list 压到 list,低于公开边界抬到公开边界。
|
|
744
|
+
// 关键:绝不把还价 clamp 到私有底价再回给买家(那样一次极低还价
|
|
745
|
+
// 即可探出底价精确值,T045)。
|
|
746
|
+
const publicBoundMinor = publicDiscountBoundMinor(priceMinor, sku);
|
|
747
|
+
const policyResponsiveMinor = typeof buyerCounterMinor === "number" && Number.isFinite(buyerCounterMinor)
|
|
748
|
+
? clampToBounds(buyerCounterMinor, publicBoundMinor, priceMinor)
|
|
568
749
|
: priceMinor;
|
|
750
|
+
const responsiveMinor = authorityPromotion.kind === "applied"
|
|
751
|
+
? Math.min(policyResponsiveMinor, authorityPromotion.priceMinor)
|
|
752
|
+
: policyResponsiveMinor;
|
|
753
|
+
if (responsiveMinor < floorMinor) {
|
|
754
|
+
// 公开边界低于私有底价:该区间不能自动报价,交人工/审批处理,且不返回价格。
|
|
755
|
+
return declineReply("approval_required");
|
|
756
|
+
}
|
|
569
757
|
// 可配置促销(merchant_policy.promos[sku]):买满 bulk_threshold 台,
|
|
570
|
-
// 批量价 =
|
|
758
|
+
// 批量价 = min(还价响应, list×(1-d%/100)),同样 clamp 到公开边界;
|
|
759
|
+
// 若该价低于私有底价则**不挂这条条件**(不广告无法兑现的价)。
|
|
571
760
|
const promo = policyOf()?.promos?.[sku];
|
|
572
761
|
const bulkThreshold = promo?.bulk_threshold ?? DEFAULT_BULK_THRESHOLD;
|
|
573
762
|
const bulkMinor = promo !== undefined
|
|
574
|
-
? clampToBounds(Math.min(responsiveMinor, applyDiscountPercentMinor(priceMinor, promo.bulk_discount_percent ?? 0)),
|
|
575
|
-
:
|
|
763
|
+
? clampToBounds(Math.min(responsiveMinor, applyDiscountPercentMinor(priceMinor, promo.bulk_discount_percent ?? 0)), publicBoundMinor, priceMinor)
|
|
764
|
+
: undefined;
|
|
765
|
+
const promotionalMinor = bulkMinor !== undefined && bulkMinor < responsiveMinor && bulkMinor >= floorMinor
|
|
766
|
+
? bulkMinor
|
|
767
|
+
: undefined;
|
|
576
768
|
const reply = seedEnvelope({
|
|
577
769
|
negotiation_id: negotiationId,
|
|
578
770
|
in_reply_to: inReplyTo,
|
|
@@ -583,14 +775,42 @@ export function createMerchantHandler(options) {
|
|
|
583
775
|
type: "conditional_offer",
|
|
584
776
|
offer_id: newOfferId(),
|
|
585
777
|
responding_to_offer_id: counter.offer_id,
|
|
778
|
+
// 许可绑定(T047):本次报价依据的规则摘要与商品事实指纹;accept 时重验。
|
|
779
|
+
policy_digest: policyDigest(),
|
|
780
|
+
product_fingerprint: productFingerprint({ sku, priceMinor, currency }),
|
|
586
781
|
// base = 还价响应(已 clamp 到 [floor, list])——单台即得到该价。
|
|
587
|
-
base_terms: offerTerms({
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
782
|
+
base_terms: offerTerms({
|
|
783
|
+
sku,
|
|
784
|
+
priceMinor: responsiveMinor,
|
|
785
|
+
quantity,
|
|
786
|
+
currency,
|
|
787
|
+
handoff_destination,
|
|
788
|
+
deliveryBefore: deliveryBefore(),
|
|
789
|
+
...(authorityPromotion.kind === "applied"
|
|
790
|
+
? { validUntilCap: authorityPromotion.endsAt }
|
|
791
|
+
: {}),
|
|
792
|
+
}, now()),
|
|
793
|
+
// conditions 可空(§13:空 conditions 等价 base_terms)。促销价低于
|
|
794
|
+
// 私有底价时不挂条件——不广告无法兑现的价,也不借 then_terms 泄露底价。
|
|
795
|
+
conditions: promotionalMinor !== undefined
|
|
796
|
+
? [
|
|
797
|
+
{
|
|
798
|
+
when: {
|
|
799
|
+
all: [
|
|
800
|
+
{ field: "aggregate.total_quantity", op: "gte", value: bulkThreshold },
|
|
801
|
+
],
|
|
802
|
+
},
|
|
803
|
+
then_terms: offerTerms({
|
|
804
|
+
sku,
|
|
805
|
+
priceMinor: promotionalMinor,
|
|
806
|
+
quantity,
|
|
807
|
+
currency,
|
|
808
|
+
handoff_destination,
|
|
809
|
+
deliveryBefore: deliveryBefore(),
|
|
810
|
+
}, now()),
|
|
811
|
+
},
|
|
812
|
+
]
|
|
813
|
+
: [],
|
|
594
814
|
},
|
|
595
815
|
...(note !== undefined ? { public_message: note } : {}),
|
|
596
816
|
});
|
|
@@ -681,6 +901,28 @@ export function createMerchantHandler(options) {
|
|
|
681
901
|
if (presentedDigest === "" || presentedDigest !== contentDigest(agreedTerms)) {
|
|
682
902
|
return declineReply("terms_digest_mismatch");
|
|
683
903
|
}
|
|
904
|
+
// T047:许可有效性重验——规则或商品事实在报价之后发生变化,旧许可即失效。
|
|
905
|
+
// 必须在相位推进/产出协议之前判定(拒绝不得留下任何终态副作用)。
|
|
906
|
+
const acceptedConditionalPayload = acceptedConditional.conditional;
|
|
907
|
+
const currentPolicyDigest = policyDigest();
|
|
908
|
+
if (acceptedConditionalPayload.policy_digest !== undefined &&
|
|
909
|
+
acceptedConditionalPayload.policy_digest !== currentPolicyDigest) {
|
|
910
|
+
return declineReply("approval_required");
|
|
911
|
+
}
|
|
912
|
+
const acceptedSku = acceptedConditionalPayload.base_terms?.items?.[0]?.sku;
|
|
913
|
+
if (acceptedConditionalPayload.product_fingerprint !== undefined &&
|
|
914
|
+
acceptedSku !== undefined) {
|
|
915
|
+
const refreshed = await resolveProductOrDecline(acceptedSku, { force: true });
|
|
916
|
+
if ("declined" in refreshed ||
|
|
917
|
+
productFingerprint({
|
|
918
|
+
sku: acceptedSku,
|
|
919
|
+
priceMinor: refreshed.product.priceMinor,
|
|
920
|
+
currency: refreshed.product.currency,
|
|
921
|
+
}) !== acceptedConditionalPayload.product_fingerprint) {
|
|
922
|
+
// 商品价/币种变化或商品源已不可用 → 旧许可失效,需重新确认。
|
|
923
|
+
return declineReply("approval_required");
|
|
924
|
+
}
|
|
925
|
+
}
|
|
684
926
|
// 审查 P1-C:相位机是权威守卫——§15 校验通过后、构建协议之前先
|
|
685
927
|
// 推进相位并检查返回值(BUG-10 语义不变:被拒的 accept 不得进入
|
|
686
928
|
// AGREEMENT_REACHED)。推进失败(如 AWAITING_CLARIFICATION 下直接
|
|
@@ -710,7 +952,12 @@ export function createMerchantHandler(options) {
|
|
|
710
952
|
// 协商终态:conditional 不再需要(评审项 L3:此前永久累积)。
|
|
711
953
|
conditionalByNegotiation.delete(negotiationId);
|
|
712
954
|
closedNegotiations.add(negotiationId);
|
|
713
|
-
return {
|
|
955
|
+
return {
|
|
956
|
+
kind: "accepted",
|
|
957
|
+
taskState: "completed",
|
|
958
|
+
artifactParts: [artifactPart],
|
|
959
|
+
message,
|
|
960
|
+
};
|
|
714
961
|
}
|
|
715
962
|
case "withdraw": {
|
|
716
963
|
const scope = envelope.payload.scope ?? "offer";
|