@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
package/dist/cli.js
CHANGED
|
@@ -29,10 +29,12 @@
|
|
|
29
29
|
*/
|
|
30
30
|
import { spawn, spawnSync } from "node:child_process";
|
|
31
31
|
import { DatabaseSync } from "node:sqlite";
|
|
32
|
+
import { isIP } from "node:net";
|
|
32
33
|
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync, } from "node:fs";
|
|
33
34
|
import { homedir, userInfo } from "node:os";
|
|
34
35
|
import path from "node:path";
|
|
35
36
|
import { fileURLToPath } from "node:url";
|
|
37
|
+
import { Writable } from "node:stream";
|
|
36
38
|
import { startA2aNode } from "./a2a/node.js";
|
|
37
39
|
import { runChatTui } from "./agent/chat-tui.js";
|
|
38
40
|
import { buildChatKernel, buildClient, defaultChatProfile } from "./agent/kernel-builder.js";
|
|
@@ -55,33 +57,18 @@ import { runMcpServe } from "./mcp/cli.js";
|
|
|
55
57
|
import { runHttpServe } from "./http/cli.js";
|
|
56
58
|
import { runGatewayServe } from "./merchant-gateway/cli.js";
|
|
57
59
|
import { DEFAULT_MERCHANT_MCP_HOST, DEFAULT_MERCHANT_MCP_PATH, DEFAULT_MERCHANT_MCP_PORT, startMerchantMcpServer, } from "./mcp/merchant-server.js";
|
|
58
|
-
import { assertMerchantMcpAuthPolicy, CompositeMerchantMcpVerifier, PairedCredentialVerifier, resolveMerchantMcpVerifier, } from "./mcp/merchant-auth.js";
|
|
59
60
|
import { resolveMerchantMcpDirs } from "./mcp/merchant-dirs.js";
|
|
60
|
-
import {
|
|
61
|
-
import {
|
|
62
|
-
import {
|
|
61
|
+
import { MerchantPolicyRuntime } from "./merchant-core/policy-runtime.js";
|
|
62
|
+
import { writeAdminCredentials } from "./auth/merchant-sessions.js";
|
|
63
|
+
import { createPairingCode, revokePairedCredential } from "./auth/merchant-pairing.js";
|
|
64
|
+
import { assembleMerchantRuntime, } from "./mcp/merchant-runtime-assembly.js";
|
|
63
65
|
import { MerchantRuntimeManager } from "./merchant-runtime/manager.js";
|
|
64
66
|
import { buildRuntimeServiceSpecs } from "./merchant-runtime/services.js";
|
|
65
67
|
import { collectMerchantHealth } from "./merchant-runtime/health.js";
|
|
66
68
|
import { MerchantJobs, standardMerchantJobs } from "./merchant-runtime/jobs.js";
|
|
67
69
|
import { runBackup } from "./merchant-runtime/backup.js";
|
|
68
|
-
import {
|
|
69
|
-
import {
|
|
70
|
-
import { buildMerchantPresentationResources } from "./mcp/merchant-resources.js";
|
|
71
|
-
import { merchantAdminSurface } from "./merchant-admin/pending-page.js";
|
|
72
|
-
import { MerchantAdminSessions, writeAdminCredentials } from "./auth/merchant-sessions.js";
|
|
73
|
-
import { createPairingCode, revokePairedCredential } from "./auth/merchant-pairing.js";
|
|
74
|
-
import { MerchantOperationStore } from "./merchant-core/operations.js";
|
|
75
|
-
/** 读能力探测落盘记录的 listing_pause(F08 接线;记录缺失/损坏 → undefined 不判定)。 */
|
|
76
|
-
function probeCapabilitiesListingPause(dataDir) {
|
|
77
|
-
try {
|
|
78
|
-
const probe = JSON.parse(readFileSync(path.join(dataDir, "capability-probe.json"), "utf8"));
|
|
79
|
-
return probe.capabilities?.listing_pause;
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
70
|
+
import { connectMerchant } from "./cloud/merchant-connect.js";
|
|
71
|
+
import { rotateEnrollmentSigningKey } from "./cloud/binding/enrollment-key-recovery.js";
|
|
85
72
|
function readRegistrationStatus(dataDir) {
|
|
86
73
|
try {
|
|
87
74
|
const value = JSON.parse(readFileSync(path.join(dataDir, "registration.json"), "utf8"));
|
|
@@ -111,15 +98,10 @@ function countPendingMerchantCommands(dataDir) {
|
|
|
111
98
|
return undefined;
|
|
112
99
|
}
|
|
113
100
|
}
|
|
114
|
-
import { agentDirName, DEFAULT_AGENTS_ROOT
|
|
101
|
+
import { agentDirName, DEFAULT_AGENTS_ROOT } from "./agent/agent-db.js";
|
|
115
102
|
import { writeFileAtomic } from "./fs/atomic-write.js";
|
|
116
|
-
import { WriteApprovalCandidateStore } from "./agent/merchant/action-candidate.js";
|
|
117
103
|
import { ProfileCredentialBroker } from "./agent/merchant/credential-broker.js";
|
|
118
|
-
import { FakeMerchantClient, fakeMerchantProduct } from "./agent/merchant/fake-merchant-client.js";
|
|
119
104
|
import { HttpMerchantClient } from "./agent/merchant/merchant-client.js";
|
|
120
|
-
import { DefaultMerchantIntelligenceBackend } from "./agent/merchant/intelligence/default-backend.js";
|
|
121
|
-
import { MemoryStore } from "./agent/memory/store.js";
|
|
122
|
-
import { PrivateVault } from "./agent/memory/vault.js";
|
|
123
105
|
import { runDown, runStatus, runUp, SupervisorError } from "./supervisor/manage.js";
|
|
124
106
|
import { parseLogLines, runLogs } from "./supervisor/logs.js";
|
|
125
107
|
import { StackConfigError } from "./supervisor/stack-config.js";
|
|
@@ -132,7 +114,7 @@ import { supplierList, supplierMetrics, supplierPause, supplierPrefer, supplierR
|
|
|
132
114
|
import { merchantStats } from "./product-merchant.js";
|
|
133
115
|
import { merchantPublish } from "./product-publish.js";
|
|
134
116
|
import { catalogServe } from "./product-catalog.js";
|
|
135
|
-
import { extractPublicDomain, runMerchantSetupPublic, SetupPublicError, validatePublicDomain, } from "./product-setup-public.js";
|
|
117
|
+
import { detectPublicIp, extractPublicDomain, runMerchantSetupPublic, SetupPublicError, validatePublicDomain, } from "./product-setup-public.js";
|
|
136
118
|
const USAGE = `kiwi ${PRODUCT_VERSION} — commerce negotiation agent runtime
|
|
137
119
|
|
|
138
120
|
Usage:
|
|
@@ -205,6 +187,8 @@ export function parseArgs(argv) {
|
|
|
205
187
|
let shoppingCliMerchant;
|
|
206
188
|
let merchantId;
|
|
207
189
|
let merchantName;
|
|
190
|
+
let merchantToken;
|
|
191
|
+
let publicUrl;
|
|
208
192
|
let output;
|
|
209
193
|
let force = false;
|
|
210
194
|
let noInstall = false;
|
|
@@ -266,6 +250,12 @@ export function parseArgs(argv) {
|
|
|
266
250
|
else if (arg === "--merchant-id") {
|
|
267
251
|
merchantId = argv[++i];
|
|
268
252
|
}
|
|
253
|
+
else if (arg === "--merchant-token") {
|
|
254
|
+
merchantToken = argv[++i];
|
|
255
|
+
}
|
|
256
|
+
else if (arg === "--public-url") {
|
|
257
|
+
publicUrl = argv[++i];
|
|
258
|
+
}
|
|
269
259
|
else if (arg === "--name") {
|
|
270
260
|
merchantName = argv[++i];
|
|
271
261
|
}
|
|
@@ -398,6 +388,12 @@ export function parseArgs(argv) {
|
|
|
398
388
|
else if (arg !== undefined && arg.startsWith("--merchant-id=")) {
|
|
399
389
|
merchantId = arg.slice("--merchant-id=".length);
|
|
400
390
|
}
|
|
391
|
+
else if (arg !== undefined && arg.startsWith("--merchant-token=")) {
|
|
392
|
+
merchantToken = arg.slice("--merchant-token=".length);
|
|
393
|
+
}
|
|
394
|
+
else if (arg !== undefined && arg.startsWith("--public-url=")) {
|
|
395
|
+
publicUrl = arg.slice("--public-url=".length);
|
|
396
|
+
}
|
|
401
397
|
else if (arg !== undefined && arg.startsWith("--name=")) {
|
|
402
398
|
merchantName = arg.slice("--name=".length);
|
|
403
399
|
}
|
|
@@ -473,6 +469,10 @@ export function parseArgs(argv) {
|
|
|
473
469
|
out.merchantId = merchantId;
|
|
474
470
|
if (merchantName !== undefined)
|
|
475
471
|
out.merchantName = merchantName;
|
|
472
|
+
if (merchantToken !== undefined)
|
|
473
|
+
out.merchantToken = merchantToken;
|
|
474
|
+
if (publicUrl !== undefined)
|
|
475
|
+
out.publicUrl = publicUrl;
|
|
476
476
|
if (output !== undefined)
|
|
477
477
|
out.output = output;
|
|
478
478
|
if (agentId !== undefined)
|
|
@@ -724,8 +724,19 @@ async function cmdTui(args) {
|
|
|
724
724
|
* policy-overrides / agent-db)同一消毒口径(审查 P2:此前读端用原始
|
|
725
725
|
* agent_id、写端消毒,非 ASCII agent_id 下策略热更新对 A2A 静默不生效);
|
|
726
726
|
* 重启后 Ledger/幂等/终态可恢复;显式 --data-dir 覆盖。绝不回退到临时目录。 */
|
|
727
|
-
export function resolveServeDataDir(dataDir, agentId) {
|
|
728
|
-
return dataDir ?? path.resolve(DEFAULT_AGENTS_ROOT, agentDirName(agentId));
|
|
727
|
+
export function resolveServeDataDir(dataDir, agentId, profileDataDir) {
|
|
728
|
+
return dataDir ?? profileDataDir ?? path.resolve(DEFAULT_AGENTS_ROOT, agentDirName(agentId));
|
|
729
|
+
}
|
|
730
|
+
function configuredDataDir(args, profile) {
|
|
731
|
+
return args.dataDir ?? profile.merchant_runtime?.data_dir;
|
|
732
|
+
}
|
|
733
|
+
/** Accept a domain or bare IP as shorthand for its HTTPS origin. */
|
|
734
|
+
export function normalizeMerchantRuntimeOriginInput(input) {
|
|
735
|
+
const value = input.trim();
|
|
736
|
+
if (value === "" || /^https?:\/\//i.test(value))
|
|
737
|
+
return value;
|
|
738
|
+
const unwrapped = value.startsWith("[") && value.endsWith("]") ? value.slice(1, -1) : value;
|
|
739
|
+
return isIP(unwrapped) === 6 ? `https://[${unwrapped}]` : `https://${value}`;
|
|
729
740
|
}
|
|
730
741
|
async function cmdAgentServe(args) {
|
|
731
742
|
const profile = requireProfileOrDefault(args);
|
|
@@ -740,7 +751,7 @@ async function cmdAgentServe(args) {
|
|
|
740
751
|
// mkdtemp 临时目录且 stop 时删除,重启后 Ledger/幂等/终态全丢:已终态
|
|
741
752
|
// negotiation 可重开、已发 conditional offer 返回 offer_unknown。稳定目录
|
|
742
753
|
// 让重启可恢复状态(resolveServeDataDir 见上)。
|
|
743
|
-
const serveDataDir = resolveServeDataDir(args.dataDir, profile.agent_id);
|
|
754
|
+
const serveDataDir = resolveServeDataDir(args.dataDir, profile.agent_id, profile.merchant_runtime?.data_dir);
|
|
744
755
|
// BUG-07:A2A 进程的策略读端——与 MCP 写端共享 <dataDir>/policy-overrides.json,
|
|
745
756
|
// 每次报价 stat 文件 mtime,变化才重载(策略热更新跨进程立即生效)。
|
|
746
757
|
const policyRuntime = new MerchantPolicyRuntime({
|
|
@@ -931,7 +942,7 @@ async function cmdChat(args, requiredRole) {
|
|
|
931
942
|
preferredPort: args.port,
|
|
932
943
|
// 审查:chat 起的 A2A 节点同样要持久 dataDir——否则 Ledger/幂等/签名密钥
|
|
933
944
|
// 全落临时目录,重启后磋商状态与签名身份丢失(Issue 16 B)。
|
|
934
|
-
dataDir: resolveServeDataDir(args.dataDir, p.agent_id),
|
|
945
|
+
dataDir: resolveServeDataDir(args.dataDir, p.agent_id, p.merchant_runtime?.data_dir),
|
|
935
946
|
...(merchantToken ? { ownerToken: merchantToken } : {}),
|
|
936
947
|
ownerTokenSecret: process.env.KIWI_CATALOG_OWNER_TOKEN_SECRET,
|
|
937
948
|
});
|
|
@@ -1196,6 +1207,8 @@ async function routeMerchant(sub, args) {
|
|
|
1196
1207
|
return await cmdMerchantMcp(args);
|
|
1197
1208
|
if (sub === "runtime")
|
|
1198
1209
|
return await cmdMerchantRuntime(args);
|
|
1210
|
+
if (sub === "connect")
|
|
1211
|
+
return await cmdMerchantConnect(args);
|
|
1199
1212
|
if (sub === "init")
|
|
1200
1213
|
return await cmdMerchantInit(args);
|
|
1201
1214
|
if (sub === "publish")
|
|
@@ -1215,6 +1228,37 @@ async function routeMerchant(sub, args) {
|
|
|
1215
1228
|
process.stderr.write(`unknown merchant command: ${sub}\n`);
|
|
1216
1229
|
return EXIT.CONFIG;
|
|
1217
1230
|
}
|
|
1231
|
+
/** 本机执行设备授权;实际 Runtime 持钥留在本机文件,远端控制器不伪造其身份。 */
|
|
1232
|
+
async function cmdMerchantConnect(args) {
|
|
1233
|
+
try {
|
|
1234
|
+
const profile = requireProfileOrDefault(args);
|
|
1235
|
+
const dataDir = resolveServeDataDir(args.dataDir, profile.agent_id, profile.merchant_runtime?.data_dir);
|
|
1236
|
+
const catalog = args.catalog ?? process.env.KIWI_CATALOG_URL ?? profile.merchant_public?.catalog_url ?? DEFAULT_CATALOG_URL;
|
|
1237
|
+
const publicOrigin = process.env.KIWI_CLOUD_PUBLIC_ORIGIN ?? process.env.KIWI_A2A_PUBLIC_URL ?? profile.merchant_public?.public_url;
|
|
1238
|
+
const result = await connectMerchant({
|
|
1239
|
+
profile,
|
|
1240
|
+
dataDir,
|
|
1241
|
+
catalogUrl: catalog,
|
|
1242
|
+
...(publicOrigin !== undefined ? { publicOrigin } : {}),
|
|
1243
|
+
...(process.platform !== "win32" ? { openBrowser: (url) => {
|
|
1244
|
+
const command = process.platform === "darwin" ? "open" : "xdg-open";
|
|
1245
|
+
const commandArgs = [url];
|
|
1246
|
+
const child = spawn(command, commandArgs, { detached: true, stdio: "ignore" });
|
|
1247
|
+
child.once("error", () => {
|
|
1248
|
+
process.stderr.write("无法自动打开浏览器;请使用上方授权链接在手机或其他设备打开。\n");
|
|
1249
|
+
});
|
|
1250
|
+
child.unref();
|
|
1251
|
+
} } : {}),
|
|
1252
|
+
});
|
|
1253
|
+
process.stdout.write(`已上线:Catalog Agent ${result.agentId},绑定 ${result.bindingId},名片 revision ${result.cardRevision}。\n` +
|
|
1254
|
+
"商品发布使用当前 Runtime 绑定签名,并受 Catalog 商家方案额度限制;可在商家后台查看已用名额。\n");
|
|
1255
|
+
return EXIT.OK;
|
|
1256
|
+
}
|
|
1257
|
+
catch (err) {
|
|
1258
|
+
process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
|
|
1259
|
+
return EXIT.CONFIG;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1218
1262
|
/**
|
|
1219
1263
|
* `kiwi merchant runtime start|stop|status|health`:Merchant 实例运行时管理
|
|
1220
1264
|
* (V2 阶段一 src/merchant-runtime/)。A2A 接待服务与 MCP 管理服务作为受管
|
|
@@ -1227,8 +1271,8 @@ async function routeMerchant(sub, args) {
|
|
|
1227
1271
|
*/
|
|
1228
1272
|
async function cmdMerchantRuntime(args) {
|
|
1229
1273
|
const action = args.command[2];
|
|
1230
|
-
if (action === undefined || !["start", "stop", "status", "health"].includes(action)) {
|
|
1231
|
-
process.stderr.write("usage: kiwi merchant runtime <start|stop|status|health> [--profile <file>] [--data-dir <dir>]\n");
|
|
1274
|
+
if (action === undefined || !["start", "stop", "status", "health", "rotate-key"].includes(action)) {
|
|
1275
|
+
process.stderr.write("usage: kiwi merchant runtime <start|stop|status|health|rotate-key> [--profile <file>] [--data-dir <dir>]\n");
|
|
1232
1276
|
return EXIT.CONFIG;
|
|
1233
1277
|
}
|
|
1234
1278
|
const profile = requireProfileOrDefault(args);
|
|
@@ -1237,9 +1281,37 @@ async function cmdMerchantRuntime(args) {
|
|
|
1237
1281
|
return EXIT.CONFIG;
|
|
1238
1282
|
}
|
|
1239
1283
|
const dirs = resolveMerchantMcpDirs({
|
|
1240
|
-
...(args
|
|
1284
|
+
...(configuredDataDir(args, profile) !== undefined ? { dataDir: configuredDataDir(args, profile) } : {}),
|
|
1241
1285
|
agentId: profile.agent_id,
|
|
1242
1286
|
});
|
|
1287
|
+
if (action === "rotate-key") {
|
|
1288
|
+
const publicOrigin = process.env.KIWI_A2A_PUBLIC_URL ?? profile.merchant_public?.public_url;
|
|
1289
|
+
let keyId = `merchant:${profile.agent_id}`;
|
|
1290
|
+
if (publicOrigin !== undefined && publicOrigin.trim() !== "") {
|
|
1291
|
+
try {
|
|
1292
|
+
const parsed = new URL(publicOrigin);
|
|
1293
|
+
if (parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "" ||
|
|
1294
|
+
parsed.pathname !== "/" && parsed.pathname !== "" || parsed.search !== "" || parsed.hash !== "") {
|
|
1295
|
+
throw new Error("public origin must be a bare HTTPS origin");
|
|
1296
|
+
}
|
|
1297
|
+
keyId = parsed.origin;
|
|
1298
|
+
}
|
|
1299
|
+
catch (err) {
|
|
1300
|
+
process.stderr.write(`Runtime key rotation refused: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
1301
|
+
return EXIT.CONFIG;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
try {
|
|
1305
|
+
rotateEnrollmentSigningKey(dirs.merchantDataDir, keyId);
|
|
1306
|
+
}
|
|
1307
|
+
catch (err) {
|
|
1308
|
+
process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
|
|
1309
|
+
return EXIT.CONFIG;
|
|
1310
|
+
}
|
|
1311
|
+
process.stdout.write("Runtime持久签名密钥已轮换。旧Catalog绑定可能仍有效,直到新Runtime使用新密钥完成Catalog登录确认、绑定和名片发布;本地不会假报撤销。若旧密钥确认泄漏,请先在Catalog暂停/撤回旧服务。\n" +
|
|
1312
|
+
"下一步:启动Runtime,然后运行 kiwi merchant connect 重新登录并批准新的公开预览。地址或公开卡片发生变化时,Catalog会展示新预览并要求确认。\n");
|
|
1313
|
+
return EXIT.OK;
|
|
1314
|
+
}
|
|
1243
1315
|
const cliEntry = fileURLToPath(import.meta.url);
|
|
1244
1316
|
const profileArgs = args.profile !== undefined ? ["--profile", args.profile] : [];
|
|
1245
1317
|
const manager = new MerchantRuntimeManager({
|
|
@@ -1358,7 +1430,7 @@ async function cmdMerchantMcp(args) {
|
|
|
1358
1430
|
return EXIT.CONFIG;
|
|
1359
1431
|
}
|
|
1360
1432
|
const dirs = resolveMerchantMcpDirs({
|
|
1361
|
-
...(args
|
|
1433
|
+
...(configuredDataDir(args, profile) !== undefined ? { dataDir: configuredDataDir(args, profile) } : {}),
|
|
1362
1434
|
agentId: profile.agent_id,
|
|
1363
1435
|
});
|
|
1364
1436
|
try {
|
|
@@ -1385,7 +1457,7 @@ async function cmdMerchantMcp(args) {
|
|
|
1385
1457
|
return EXIT.CONFIG;
|
|
1386
1458
|
}
|
|
1387
1459
|
const dirs = resolveMerchantMcpDirs({
|
|
1388
|
-
...(args
|
|
1460
|
+
...(configuredDataDir(args, profile) !== undefined ? { dataDir: configuredDataDir(args, profile) } : {}),
|
|
1389
1461
|
agentId: profile.agent_id,
|
|
1390
1462
|
});
|
|
1391
1463
|
const { code, expiresAt } = createPairingCode(dirs.merchantDataDir);
|
|
@@ -1416,7 +1488,7 @@ async function cmdMerchantMcp(args) {
|
|
|
1416
1488
|
return EXIT.CONFIG;
|
|
1417
1489
|
}
|
|
1418
1490
|
const dirs = resolveMerchantMcpDirs({
|
|
1419
|
-
...(args
|
|
1491
|
+
...(configuredDataDir(args, profile) !== undefined ? { dataDir: configuredDataDir(args, profile) } : {}),
|
|
1420
1492
|
agentId: profile.agent_id,
|
|
1421
1493
|
});
|
|
1422
1494
|
const revoked = revokePairedCredential(dirs.merchantDataDir);
|
|
@@ -1457,233 +1529,34 @@ async function cmdMerchantMcp(args) {
|
|
|
1457
1529
|
// 数据目录接线(V2 §5.1):merchant/principal/transportSessionId 显式注入,
|
|
1458
1530
|
// 路径是 (dataDir, agentId) 的纯函数——重启稳定,传输会话不影响目录。
|
|
1459
1531
|
const dirs = resolveMerchantMcpDirs({
|
|
1460
|
-
...(args
|
|
1532
|
+
...(configuredDataDir(args, profile) !== undefined ? { dataDir: configuredDataDir(args, profile) } : {}),
|
|
1461
1533
|
agentId: profile.agent_id,
|
|
1462
1534
|
});
|
|
1463
|
-
|
|
1464
|
-
// token = V1 静态 Bearer(过渡)。fail-closed 判定见下。
|
|
1465
|
-
let oauth;
|
|
1466
|
-
let oauthDb;
|
|
1467
|
-
let oauthStore;
|
|
1468
|
-
let verifier;
|
|
1469
|
-
// 会话与一次性确认凭证的存储**与认证模式无关**:写操作确认页(/admin/*)
|
|
1470
|
-
// 在两种模式下都挂载——网关路由形态要求实例接受静态内部令牌(token 模式),
|
|
1471
|
-
// 而商家仍必须能批准写候选,否则 prepare_* 只能等到期。
|
|
1472
|
-
{
|
|
1473
|
-
// 数据目录可能尚未创建(例如从未跑过 admin-passwd):先建 0700,再预建库文件。
|
|
1474
|
-
mkdirSync(dirs.merchantDataDir, { recursive: true, mode: 0o700 });
|
|
1475
|
-
const oauthDbPath = path.join(dirs.merchantDataDir, "oauth.sqlite");
|
|
1476
|
-
// 审查 P2:先以 0600 预建空文件再打开,消除「库已建、chmod 未执行」的
|
|
1477
|
-
// 短暂默认权限窗口。
|
|
1478
|
-
if (!existsSync(oauthDbPath)) {
|
|
1479
|
-
writeFileSync(oauthDbPath, "", { mode: 0o600 });
|
|
1480
|
-
}
|
|
1481
|
-
oauthDb = new DatabaseSync(oauthDbPath);
|
|
1482
|
-
chmodSync(oauthDbPath, 0o600);
|
|
1483
|
-
oauthStore = new MerchantOAuthStore({ db: oauthDb });
|
|
1484
|
-
}
|
|
1485
|
-
if (authMode === "oauth") {
|
|
1486
|
-
// issuer:public_url(生产 https)优先;loopback 开发推导为 http://127.0.0.1:<port>。
|
|
1487
|
-
const issuer = mcpConfig?.public_url ?? (isLoopbackHost(host) ? `http://127.0.0.1:${port}` : undefined);
|
|
1488
|
-
if (issuer === undefined) {
|
|
1489
|
-
process.stderr.write("merchant_mcp.auth_mode=oauth 且监听非 loopback 地址时必须配置 merchant_mcp.public_url(https)作为 OAuth issuer\n");
|
|
1490
|
-
return EXIT.CONFIG;
|
|
1491
|
-
}
|
|
1492
|
-
// 授权码/token/客户端注册同样落 oauth.sqlite(上面已按 0600 打开)。
|
|
1493
|
-
oauth = new MerchantOAuthServer({
|
|
1494
|
-
store: oauthStore,
|
|
1495
|
-
issuer,
|
|
1496
|
-
resource: `${issuer}${mcpPath}`,
|
|
1497
|
-
connectorSource: "kiwi-merchant",
|
|
1498
|
-
merchantName: profile.name ?? profile.owner_id,
|
|
1499
|
-
merchantId: profile.owner_id,
|
|
1500
|
-
});
|
|
1501
|
-
verifier = new MerchantOAuthVerifier({
|
|
1502
|
-
store: oauthStore,
|
|
1503
|
-
expectedMerchantId: profile.owner_id,
|
|
1504
|
-
});
|
|
1505
|
-
}
|
|
1506
|
-
else {
|
|
1507
|
-
verifier = resolveMerchantMcpVerifier(mcpConfig?.token_env);
|
|
1508
|
-
// token 模式(含网关路由形态:实例只接受网关的静态内部令牌)下,写操作
|
|
1509
|
-
// 确认页同样挂载,商家在 /admin/pending 批准候选。
|
|
1510
|
-
process.stderr.write("ℹ️ [kiwi] merchant_mcp.auth_mode=token:/mcp 使用静态内部令牌认证" +
|
|
1511
|
-
"(网关路由形态的推荐配置);写操作确认页仍挂载在 /admin/*,\n" +
|
|
1512
|
-
" 需先 `kiwi merchant mcp admin-passwd` 设置管理员口令。\n");
|
|
1513
|
-
}
|
|
1514
|
-
let authWarning;
|
|
1535
|
+
let assembly;
|
|
1515
1536
|
try {
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1537
|
+
assembly = await assembleMerchantRuntime({
|
|
1538
|
+
profile,
|
|
1539
|
+
dataDir: dirs.merchantDataDir,
|
|
1540
|
+
host,
|
|
1541
|
+
port,
|
|
1542
|
+
mcpPath,
|
|
1543
|
+
authMode,
|
|
1544
|
+
...(mcpConfig?.public_url !== undefined ? { issuer: mcpConfig.public_url } : {}),
|
|
1545
|
+
...(mcpConfig?.token_env !== undefined ? { tokenEnv: mcpConfig.token_env } : {}),
|
|
1546
|
+
});
|
|
1519
1547
|
}
|
|
1520
1548
|
catch (err) {
|
|
1549
|
+
// 装配失败(认证策略/上游协议/issuer 等)→ 拒绝启动,不回退弱配置。
|
|
1521
1550
|
process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
|
|
1522
1551
|
return EXIT.CONFIG;
|
|
1523
1552
|
}
|
|
1524
|
-
|
|
1525
|
-
process.stderr.write(`${authWarning}\n`);
|
|
1526
|
-
// 配对凭据(§8.4 第二期,最小授权):由本实例签发、网关持有;与静态令牌
|
|
1527
|
-
// 并存,任一通过即放行。商家重配对即轮换,`unpair` 即吊销。
|
|
1528
|
-
verifier = new CompositeMerchantMcpVerifier([
|
|
1529
|
-
...(verifier !== undefined ? [verifier] : []),
|
|
1530
|
-
new PairedCredentialVerifier(dirs.merchantDataDir),
|
|
1531
|
-
]);
|
|
1532
|
-
// 依赖装配与 chat kernel 同一套:agent data dir + state.sqlite + 审批候选 store。
|
|
1533
|
-
// 审批候选与对话内核共享同一 DB——MCP 生成的 draft 候选在内核侧 /pending 可见。
|
|
1534
|
-
const paths = ensurePathsForDir(dirs.merchantDataDir);
|
|
1535
|
-
const db = openAgentDatabase(paths.db);
|
|
1536
|
-
const now = () => new Date().toISOString();
|
|
1537
|
-
const store = new MemoryStore({ db, vault: new PrivateVault(), now });
|
|
1538
|
-
const principal = store.ensurePrincipal({
|
|
1539
|
-
principal_id: profile.agent_id,
|
|
1540
|
-
owner_id: profile.owner_id,
|
|
1541
|
-
role: profile.role,
|
|
1542
|
-
});
|
|
1543
|
-
store.bindPrincipal(principal.principal_id);
|
|
1544
|
-
const approvals = new WriteApprovalCandidateStore({
|
|
1545
|
-
db,
|
|
1546
|
-
principalId: principal.principal_id,
|
|
1547
|
-
now,
|
|
1548
|
-
});
|
|
1549
|
-
// 执行钩子是进程级的:重启后遗留的 pending 候选无法被本进程执行。按
|
|
1550
|
-
// expireForRecovery 语义把非本服务可恢复的候选先失效(防虚报死候选);
|
|
1551
|
-
// draft_product_change 候选的参数在库内、钩子可确定性重建,留给
|
|
1552
|
-
// service.recoverPendingDrafts() 恢复(阶段四审批闭环)。
|
|
1553
|
-
for (const candidate of approvals.listPending()) {
|
|
1554
|
-
if (candidate.tool !== "draft_product_change")
|
|
1555
|
-
approvals.expireCandidate(candidate.candidate_id);
|
|
1556
|
-
}
|
|
1557
|
-
// merchantClient:fake provider 走离线 Fake,否则真实网关(同 kernel-builder)。
|
|
1558
|
-
let merchantClient;
|
|
1559
|
-
if (isFakeProvider(profile)) {
|
|
1560
|
-
merchantClient = new FakeMerchantClient({ products: [fakeMerchantProduct()] });
|
|
1561
|
-
}
|
|
1562
|
-
else {
|
|
1563
|
-
const broker = new ProfileCredentialBroker(profile);
|
|
1564
|
-
const httpClient = new HttpMerchantClient(profile.commerce.base_url, broker);
|
|
1565
|
-
merchantClient = httpClient;
|
|
1566
|
-
// 能力探测(V2 阶段一/P0-5;协议协商升级):结果落盘供版本组合锁定。
|
|
1567
|
-
// verdict=incompatible(网关通告不含 Kiwi 需要的协议版本)→ 硬拒绝启动;
|
|
1568
|
-
// indeterminate/unhealthy(不可达/协商不可用且不可判定/健康未过)→ 警示
|
|
1569
|
-
// 但不阻塞(网关可能仍在启动,报价路径本身 fail-closed,不产生报价)。
|
|
1570
|
-
const probe = await httpClient.probeCapabilities({
|
|
1571
|
-
persistPath: path.join(dirs.merchantDataDir, "capability-probe.json"),
|
|
1572
|
-
});
|
|
1573
|
-
if (probe.verdict === "incompatible") {
|
|
1574
|
-
process.stderr.write(`[kiwi] shopping-cli 协议不兼容,拒绝启动:${probe.error ?? "未知原因"}。\n` +
|
|
1575
|
-
"升级或更换 shopping-cli 网关(需支持 shopping.negotiation/0.1)后重试。\n");
|
|
1576
|
-
return EXIT.CONFIG;
|
|
1577
|
-
}
|
|
1578
|
-
if (!probe.ok) {
|
|
1579
|
-
process.stderr.write(`⚠️ [kiwi] shopping-cli 能力探测未通过:${probe.error ?? "未知原因"};` +
|
|
1580
|
-
"相关读取/报价在上游恢复前 fail-closed。\n");
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
const intelligence = profile.merchant_experience?.enabled === true &&
|
|
1584
|
-
profile.merchant_experience.intelligence !== false
|
|
1585
|
-
? new DefaultMerchantIntelligenceBackend({
|
|
1586
|
-
merchant_id: profile.owner_id,
|
|
1587
|
-
data_dir: paths.dir,
|
|
1588
|
-
// presentation context 的 principalId 用 owner_id(商家读取口径)——
|
|
1589
|
-
// backend 的 principal 校验键与之对齐(MCP 服务侧统一 owner 口径)。
|
|
1590
|
-
principal_id: profile.owner_id,
|
|
1591
|
-
merchant_client: merchantClient,
|
|
1592
|
-
approvals,
|
|
1593
|
-
now,
|
|
1594
|
-
})
|
|
1595
|
-
: undefined;
|
|
1596
|
-
// BUG-07:运行中策略提供器(覆盖层 <merchantDataDir>/policy-overrides.json)。
|
|
1597
|
-
// 本进程(MCP)为写端:校验 patch + 原子写完整生效策略;A2A 子进程为读端:
|
|
1598
|
-
// 按文件 mtime 读取——策略变更跨进程立即生效,不再只落盘不生效。
|
|
1599
|
-
const policyRuntime = new MerchantPolicyRuntime({
|
|
1600
|
-
basePolicy: profile.merchant_policy,
|
|
1601
|
-
file: path.join(dirs.merchantDataDir, "policy-overrides.json"),
|
|
1602
|
-
now,
|
|
1603
|
-
});
|
|
1604
|
-
// 共享业务入口(V2 阶段二):merchant-core 包装 V1 facade(facade 语义不变),
|
|
1605
|
-
// MCP 工具层经 core 调用;私密读取审计目录落 merchantDataDir/private-audit。
|
|
1606
|
-
const service = new MerchantCoreService({
|
|
1607
|
-
profile,
|
|
1608
|
-
merchantClient,
|
|
1609
|
-
approvals,
|
|
1610
|
-
// MCP 写工具一律 force_pending 只产候选,mode 不影响执行安全;固定 supervised。
|
|
1611
|
-
mode: () => "supervised",
|
|
1612
|
-
now,
|
|
1613
|
-
// 商家 A2A 节点 ledger 基础目录(LedgerStore 会再拼 /ledger)。
|
|
1614
|
-
a2aLedgerDir: path.join(paths.dir, "a2a"),
|
|
1615
|
-
...(intelligence !== undefined ? { intelligence } : {}),
|
|
1616
|
-
auditDir: path.join(dirs.merchantDataDir, "private-audit"),
|
|
1617
|
-
// 命令记录授权主体 = 审批 store principal(批准/拒绝主体一致性校验)。
|
|
1618
|
-
commandPrincipalId: principal.principal_id,
|
|
1619
|
-
// BUG-02:一次性确认凭证存储(OAuth 模式;execute/reject 必须携带有效凭证)。
|
|
1620
|
-
...(oauthStore !== undefined ? { confirmations: oauthStore } : {}),
|
|
1621
|
-
// 长任务 operation store(与命令记录同一 state.sqlite,单 owner 写)。
|
|
1622
|
-
operations: new MerchantOperationStore({ db, now }),
|
|
1623
|
-
// F08 能力接线:能力探测落盘记录中 listing_pause=false 时 fail-closed「不可得」。
|
|
1624
|
-
...(probeCapabilitiesListingPause(dirs.merchantDataDir) !== undefined
|
|
1625
|
-
? { capabilities: { listing_pause: probeCapabilitiesListingPause(dirs.merchantDataDir) } }
|
|
1626
|
-
: {}),
|
|
1627
|
-
// F17/BUG-07 策略热更新:经 MerchantPolicyRuntime 校验 + 原子写完整生效
|
|
1628
|
-
// 策略(版本/digest 回执进命令记录);A2A 进程按同一文件 mtime 读取生效。
|
|
1629
|
-
applyPolicyOverride: (patch) => policyRuntime.apply(patch),
|
|
1630
|
-
// 运行中策略读取:执行器硬策略(底价兜底)按当前生效策略校验。
|
|
1631
|
-
currentPolicy: () => policyRuntime.current().policy,
|
|
1632
|
-
});
|
|
1633
|
-
// 审批闭环(阶段三推广版):恢复全部已注册写工具的 pending 命令(覆盖 V1
|
|
1634
|
-
// recoverPendingDrafts 语义);未注册工具的死候选标 expired。
|
|
1635
|
-
const recovered = service.recoverPendingCommands();
|
|
1636
|
-
// 七类 presentation → MCP 资源(V2 阶段二;私密类不进资源)。
|
|
1637
|
-
const presentations = buildMerchantPresentationResources({
|
|
1638
|
-
context: {
|
|
1639
|
-
profile,
|
|
1640
|
-
// presentation 的 enrich 以 principalId 作为商家读取口径(目录/intelligence
|
|
1641
|
-
// 都按 merchant_id 校验)——用 owner_id,不用进程 principal(agent_id)。
|
|
1642
|
-
principalId: profile.owner_id,
|
|
1643
|
-
merchantClient,
|
|
1644
|
-
approvals,
|
|
1645
|
-
...(intelligence !== undefined ? { intelligence } : {}),
|
|
1646
|
-
},
|
|
1647
|
-
});
|
|
1648
|
-
// 配对兑换:两种认证模式都挂载——凭据由本实例在兑换时新签,不依赖环境变量。
|
|
1649
|
-
const handle = await startMerchantMcpServer({
|
|
1650
|
-
service,
|
|
1651
|
-
host,
|
|
1652
|
-
port,
|
|
1653
|
-
path: mcpPath,
|
|
1654
|
-
pairing: {
|
|
1655
|
-
dir: dirs.merchantDataDir,
|
|
1656
|
-
instance: () => ({
|
|
1657
|
-
ownerId: profile.owner_id,
|
|
1658
|
-
principalId: profile.agent_id,
|
|
1659
|
-
}),
|
|
1660
|
-
},
|
|
1661
|
-
...(verifier !== undefined ? { auth: verifier } : {}),
|
|
1662
|
-
...(oauth !== undefined ? { oauth } : {}),
|
|
1663
|
-
presentations,
|
|
1664
|
-
// 配套商家确认页面(BUG-01/03):cookie 会话 + 一次性确认凭证,两种认证
|
|
1665
|
-
// 模式下都挂载(会话/凭证存 oauth.sqlite,与 OAuth 授权服务器同库不同表)。
|
|
1666
|
-
...(oauthDb !== undefined && oauthStore !== undefined
|
|
1667
|
-
? {
|
|
1668
|
-
admin: {
|
|
1669
|
-
merchantName: profile.name ?? profile.owner_id,
|
|
1670
|
-
surface: merchantAdminSurface(service),
|
|
1671
|
-
sessions: new MerchantAdminSessions({ db: oauthDb }),
|
|
1672
|
-
store: oauthStore,
|
|
1673
|
-
adminDir: dirs.merchantDataDir,
|
|
1674
|
-
secureCookies: (mcpConfig?.public_url ?? "").startsWith("https://"),
|
|
1675
|
-
},
|
|
1676
|
-
}
|
|
1677
|
-
: {}),
|
|
1678
|
-
serverInfo: { name: "kiwi-merchant", version: PRODUCT_VERSION },
|
|
1679
|
-
});
|
|
1553
|
+
const handle = await startMerchantMcpServer(assembly.serverOptions);
|
|
1680
1554
|
console.log(`[merchant mcp] merchant ${profile.agent_id} MCP server: ${handle.url}` +
|
|
1681
|
-
`(auth: ${
|
|
1682
|
-
(recovered.recovered > 0 ? `;恢复 ${recovered.recovered} 个待批准写命令` : ""));
|
|
1555
|
+
`(auth: ${assembly.authLabel}${assembly.authMode === "oauth" ? ",OAuth 端点已挂载" : ""};kiwi_merchant_* 工具 + 展示资源)` +
|
|
1556
|
+
(assembly.recovered.recovered > 0 ? `;恢复 ${assembly.recovered.recovered} 个待批准写命令` : ""));
|
|
1683
1557
|
const shutdown = async () => {
|
|
1684
1558
|
await handle.close().catch(() => undefined);
|
|
1685
|
-
|
|
1686
|
-
db.close();
|
|
1559
|
+
await assembly.close().catch(() => undefined);
|
|
1687
1560
|
process.exit(0);
|
|
1688
1561
|
};
|
|
1689
1562
|
process.on("SIGINT", shutdown);
|
|
@@ -1714,7 +1587,7 @@ async function cmdMerchantStats(args) {
|
|
|
1714
1587
|
try {
|
|
1715
1588
|
const report = merchantStats({
|
|
1716
1589
|
agentId: profile.agent_id,
|
|
1717
|
-
dataDir: resolveServeDataDir(args.dataDir, profile.agent_id),
|
|
1590
|
+
dataDir: resolveServeDataDir(args.dataDir, profile.agent_id, profile.merchant_runtime?.data_dir),
|
|
1718
1591
|
...(days !== undefined ? { days } : {}),
|
|
1719
1592
|
});
|
|
1720
1593
|
printJson(report);
|
|
@@ -1743,19 +1616,72 @@ function promptLine(text, fallback) {
|
|
|
1743
1616
|
});
|
|
1744
1617
|
});
|
|
1745
1618
|
}
|
|
1619
|
+
/** Read a secret in a TTY without echoing it. */
|
|
1620
|
+
function promptSecret(text) {
|
|
1621
|
+
if (!process.stdin.isTTY)
|
|
1622
|
+
return Promise.resolve("");
|
|
1623
|
+
process.stdout.write(text);
|
|
1624
|
+
const hiddenOutput = new Writable({ write(_chunk, _encoding, callback) { callback(); } });
|
|
1625
|
+
return new Promise((resolve) => {
|
|
1626
|
+
const rl = readline.createInterface({ input: process.stdin, output: hiddenOutput, terminal: true });
|
|
1627
|
+
rl.question("", (answer) => {
|
|
1628
|
+
rl.close();
|
|
1629
|
+
process.stdout.write("\n");
|
|
1630
|
+
resolve(answer.trim());
|
|
1631
|
+
});
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1746
1634
|
async function cmdMerchantInit(args) {
|
|
1747
|
-
//
|
|
1635
|
+
// 无参数时续用默认 profile;首次运行仅询问商家名称,其余使用默认值。
|
|
1748
1636
|
let merchantId = args.merchantId ?? process.env.KIWI_MERCHANT_ID ?? "";
|
|
1749
1637
|
let name = args.merchantName ?? process.env.KIWI_MERCHANT_NAME ?? "";
|
|
1750
|
-
|
|
1751
|
-
|
|
1638
|
+
const outputPath = args.output ?? args.profile ?? process.env.KIWI_DEFAULT_PROFILE ?? DEFAULT_PROFILE_PATH;
|
|
1639
|
+
if (existsSync(outputPath) && !args.force && merchantId === "" && name === "") {
|
|
1640
|
+
try {
|
|
1641
|
+
const existing = loadProfile(outputPath);
|
|
1642
|
+
if (existing.role === "merchant") {
|
|
1643
|
+
merchantId = existing.agent_id;
|
|
1644
|
+
name = existing.name ?? existing.owner_id;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
catch {
|
|
1648
|
+
// merchantInit reports safely and preserves unknown/corrupt files.
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
let publicUrl = args.publicUrl ?? process.env.KIWI_A2A_PUBLIC_URL ?? "";
|
|
1652
|
+
if (publicUrl === "" && existsSync(outputPath)) {
|
|
1653
|
+
try {
|
|
1654
|
+
publicUrl = loadProfile(outputPath).merchant_public?.public_url ?? "";
|
|
1655
|
+
}
|
|
1656
|
+
catch { /* validated by init */ }
|
|
1657
|
+
}
|
|
1658
|
+
// 商品服务令牌仅连接 shopping-cli;TTY 隐藏输入并写入本机 credentials 文件。
|
|
1659
|
+
let merchantToken = args.merchantToken ?? "";
|
|
1752
1660
|
if (process.stdin.isTTY) {
|
|
1753
1661
|
merchantId = await promptLine(`merchant_id(回车自动生成${name !== "" ? `,建议 ${slugifyMerchantId(name)}` : ""}): `, merchantId);
|
|
1754
1662
|
name = await promptLine(`商家名称(回车用缺省): `, name);
|
|
1755
|
-
|
|
1756
|
-
if (publicUrl
|
|
1757
|
-
|
|
1758
|
-
|
|
1663
|
+
let addressPrompt = "公网 Runtime 地址(域名或 HTTPS 地址;回车稍后配置): ";
|
|
1664
|
+
if (publicUrl === "") {
|
|
1665
|
+
const detectedIp = await detectPublicIp();
|
|
1666
|
+
if (detectedIp !== null) {
|
|
1667
|
+
process.stdout.write(`检测到服务器出口公网 IPv4:${detectedIp}\n` +
|
|
1668
|
+
"它只是候选地址;是否可用还要验证公网 HTTPS 证书、端口和 Agent Card。已有域名建议优先使用。\n");
|
|
1669
|
+
addressPrompt = `公网 Runtime 地址(域名或 https://${detectedIp};回车稍后配置): `;
|
|
1670
|
+
}
|
|
1671
|
+
else {
|
|
1672
|
+
process.stdout.write("暂时无法自动检测服务器公网 IP;你仍可输入公网域名或 HTTPS 地址。\n");
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
publicUrl = await promptLine(addressPrompt, publicUrl);
|
|
1676
|
+
if (publicUrl !== "") {
|
|
1677
|
+
publicUrl = normalizeMerchantRuntimeOriginInput(publicUrl);
|
|
1678
|
+
}
|
|
1679
|
+
if (merchantToken === "") {
|
|
1680
|
+
loadMerchantCredentials();
|
|
1681
|
+
merchantToken = process.env.KIWI_MERCHANT_TOKEN ?? "";
|
|
1682
|
+
if (merchantToken === "")
|
|
1683
|
+
merchantToken = await promptSecret("shopping-cli 商品服务令牌(回车稍后配置;输入不回显): ");
|
|
1684
|
+
}
|
|
1759
1685
|
// TTY 下可全回车:merchant_id 自动生成(避免固定名碰撞)。
|
|
1760
1686
|
if (merchantId === "")
|
|
1761
1687
|
merchantId = `merchant-${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -1763,9 +1689,8 @@ async function cmdMerchantInit(args) {
|
|
|
1763
1689
|
name = merchantId;
|
|
1764
1690
|
}
|
|
1765
1691
|
else if (merchantId === "" && name === "") {
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
return EXIT.CONFIG;
|
|
1692
|
+
merchantId = `merchant-${Math.random().toString(36).slice(2, 8)}`;
|
|
1693
|
+
name = merchantId;
|
|
1769
1694
|
}
|
|
1770
1695
|
else {
|
|
1771
1696
|
// 系统补全:merchant_id 缺省从名称派生;名称缺省用 merchant_id。
|
|
@@ -1780,18 +1705,76 @@ async function cmdMerchantInit(args) {
|
|
|
1780
1705
|
...(publicUrl !== "" ? { publicUrl } : {}),
|
|
1781
1706
|
...(merchantToken !== "" ? { merchantToken } : {}),
|
|
1782
1707
|
shoppingCliUrl: process.env.SHOPPING_CLI_URL ?? "http://127.0.0.1:8765",
|
|
1783
|
-
shoppingCliDb: process.env.SHOPPING_DB_PATH,
|
|
1708
|
+
shoppingCliDb: args.shoppingCliDb ?? process.env.SHOPPING_DB_PATH,
|
|
1784
1709
|
catalogUrl: args.catalog ?? process.env.KIWI_CATALOG_URL ?? DEFAULT_CATALOG_URL,
|
|
1710
|
+
...(args.dataDir !== undefined ? { dataDir: args.dataDir } : {}),
|
|
1785
1711
|
floorPriceMinor: 0,
|
|
1786
|
-
|
|
1712
|
+
outputPath,
|
|
1787
1713
|
...(args.force ? { force: true } : {}),
|
|
1788
1714
|
// 数据引擎默认自动安装(合一体验);--no-install 显式禁用(受限/CI)
|
|
1789
1715
|
autoInstallShoppingCli: !args.noInstall,
|
|
1790
1716
|
});
|
|
1791
|
-
|
|
1717
|
+
if (merchantToken !== "")
|
|
1718
|
+
process.env.KIWI_MERCHANT_TOKEN = merchantToken;
|
|
1719
|
+
else
|
|
1720
|
+
loadMerchantCredentials();
|
|
1721
|
+
let sourceCapabilities = report.steps.product_source_capabilities;
|
|
1722
|
+
if (report.steps.shopping_cli_reachable.ok) {
|
|
1723
|
+
try {
|
|
1724
|
+
const profile = loadProfile(report.profile_path);
|
|
1725
|
+
const probe = await new HttpMerchantClient(profile.commerce.base_url, new ProfileCredentialBroker(profile)).probeCapabilities();
|
|
1726
|
+
sourceCapabilities = {
|
|
1727
|
+
ok: probe.ok,
|
|
1728
|
+
detail: [probe.verdict, probe.version ? `shopping-cli ${probe.version}` : undefined,
|
|
1729
|
+
probe.protocol_versions ? `protocols ${probe.protocol_versions.join(", ")}` : undefined,
|
|
1730
|
+
probe.error].filter(Boolean).join(";"),
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
catch (err) {
|
|
1734
|
+
sourceCapabilities = { ok: false, detail: err instanceof Error ? err.message : String(err) };
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
let enrollment;
|
|
1738
|
+
const configuredOrigin = args.publicUrl ?? publicUrl;
|
|
1739
|
+
if (configuredOrigin !== "") {
|
|
1740
|
+
try {
|
|
1741
|
+
const profile = loadProfile(report.profile_path);
|
|
1742
|
+
const result = await connectMerchant({
|
|
1743
|
+
profile,
|
|
1744
|
+
dataDir: resolveServeDataDir(args.dataDir, profile.agent_id, profile.merchant_runtime?.data_dir),
|
|
1745
|
+
catalogUrl: args.catalog ?? process.env.KIWI_CATALOG_URL ?? profile.merchant_public?.catalog_url ?? DEFAULT_CATALOG_URL,
|
|
1746
|
+
publicOrigin: configuredOrigin,
|
|
1747
|
+
output: (line) => process.stdout.write(`${line}\n`),
|
|
1748
|
+
...(process.platform !== "win32" ? { openBrowser: (url) => {
|
|
1749
|
+
const command = process.platform === "darwin" ? "open" : "xdg-open";
|
|
1750
|
+
const child = spawn(command, [url], { detached: true, stdio: "ignore" });
|
|
1751
|
+
child.once("error", () => process.stderr.write("无法自动打开浏览器;请使用上方授权链接打开。\n"));
|
|
1752
|
+
child.unref();
|
|
1753
|
+
} } : {}),
|
|
1754
|
+
});
|
|
1755
|
+
enrollment = { ok: true, detail: `绑定 ${result.bindingId},Agent ${result.agentId},名片 revision ${result.cardRevision}` };
|
|
1756
|
+
}
|
|
1757
|
+
catch (err) {
|
|
1758
|
+
enrollment = { ok: false, detail: err instanceof Error ? err.message : String(err) };
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
printJson({ ...report, steps: { ...report.steps, product_source_capabilities: sourceCapabilities,
|
|
1762
|
+
...(enrollment !== undefined ? { runtime_enrollment: enrollment } : {}) } });
|
|
1792
1763
|
for (const warning of report.warnings) {
|
|
1793
1764
|
process.stderr.write(`warning: ${warning}\n`);
|
|
1794
1765
|
}
|
|
1766
|
+
if (!sourceCapabilities.ok)
|
|
1767
|
+
process.stderr.write(`商品源能力尚未通过:${sourceCapabilities.detail ?? "未验证"}\n`);
|
|
1768
|
+
if (enrollment !== undefined && !enrollment.ok) {
|
|
1769
|
+
process.stderr.write(`Runtime enrollment 未完成:${enrollment.detail}\n`);
|
|
1770
|
+
return EXIT.TRANSIENT;
|
|
1771
|
+
}
|
|
1772
|
+
if (configuredOrigin === "") {
|
|
1773
|
+
process.stderr.write("尚未提供公网 Runtime 地址;Catalog 账号授权和绑定未完成。先让 Agent Card 可经 HTTPS 公网访问,再设置 --public-url 重跑 init 继续。\n");
|
|
1774
|
+
}
|
|
1775
|
+
if (args.merchantToken !== undefined && report.ok) {
|
|
1776
|
+
process.stderr.write("shopping-cli 商品服务令牌已写入 ~/.kiwi/credentials.env(0600);它不用于 Kiwi Catalog Runtime 绑定。\n");
|
|
1777
|
+
}
|
|
1795
1778
|
return report.ok ? EXIT.OK : EXIT.CONFIG;
|
|
1796
1779
|
}
|
|
1797
1780
|
/**
|
|
@@ -1806,7 +1789,10 @@ async function cmdMerchantPublish(args) {
|
|
|
1806
1789
|
}
|
|
1807
1790
|
loadMerchantCredentials(); // 加载 init 写入的 credentials.env(KIWI_MERCHANT_TOKEN)
|
|
1808
1791
|
// 缺省路径与 shopping-cli 的 DEFAULT_DB_PATH 一致——商家无需设置 SHOPPING_DB_PATH。
|
|
1809
|
-
const shoppingCliDb = args.shoppingCliDb ??
|
|
1792
|
+
const shoppingCliDb = args.shoppingCliDb ??
|
|
1793
|
+
profile.merchant_public?.shopping_db_path ??
|
|
1794
|
+
process.env.SHOPPING_DB_PATH ??
|
|
1795
|
+
DEFAULT_SHOPPING_DB_PATH;
|
|
1810
1796
|
// `--file <csv>`:先导入商品(shopping-cli import-csv-excel)再发布。
|
|
1811
1797
|
if (args.file !== undefined && args.file !== "") {
|
|
1812
1798
|
const imp = spawnSync("shopping-cli", ["import-csv-excel", "--file", args.file, "--merchant", profile.agent_id, "--format", "json"], { env: { ...process.env, SHOPPING_DB_PATH: shoppingCliDb }, stdio: "inherit" });
|
|
@@ -1825,10 +1811,6 @@ async function cmdMerchantPublish(args) {
|
|
|
1825
1811
|
const merchantToken = (merchantTokenEnv ? process.env[merchantTokenEnv] : undefined) ||
|
|
1826
1812
|
process.env.KIWI_MERCHANT_TOKEN ||
|
|
1827
1813
|
"";
|
|
1828
|
-
if (!merchantToken && !ownerTokenSecret) {
|
|
1829
|
-
process.stderr.write("需要 KIWI_MERCHANT_TOKEN(随机 token,推荐)或 KIWI_CATALOG_OWNER_TOKEN_SECRET(legacy HMAC)\n");
|
|
1830
|
-
return EXIT.CONFIG;
|
|
1831
|
-
}
|
|
1832
1814
|
const catalog = args.catalog ??
|
|
1833
1815
|
profile.merchant_public?.catalog_url ??
|
|
1834
1816
|
process.env.KIWI_CATALOG_URL ??
|
|
@@ -1839,6 +1821,10 @@ async function cmdMerchantPublish(args) {
|
|
|
1839
1821
|
...(merchantToken ? { ownerToken: merchantToken } : {}),
|
|
1840
1822
|
...(ownerTokenSecret ? { ownerTokenSecret } : {}),
|
|
1841
1823
|
shoppingCliDb,
|
|
1824
|
+
dataDir: resolveServeDataDir(args.dataDir, profile.agent_id, profile.merchant_runtime?.data_dir),
|
|
1825
|
+
...(process.env.KIWI_A2A_PUBLIC_URL ?? profile.merchant_public?.public_url
|
|
1826
|
+
? { runtimeOrigin: process.env.KIWI_A2A_PUBLIC_URL ?? profile.merchant_public?.public_url }
|
|
1827
|
+
: {}),
|
|
1842
1828
|
...(args.shoppingCliPath !== undefined ? { shoppingCliPath: args.shoppingCliPath } : {}),
|
|
1843
1829
|
...(args.shoppingCliMerchant !== undefined
|
|
1844
1830
|
? { shoppingCliMerchant: args.shoppingCliMerchant }
|
|
@@ -1995,7 +1981,7 @@ async function cmdMerchantUp(args) {
|
|
|
1995
1981
|
process.env.KIWI_CATALOG_URL ??
|
|
1996
1982
|
DEFAULT_CATALOG_URL;
|
|
1997
1983
|
const merchantToken = process.env.KIWI_MERCHANT_TOKEN || "";
|
|
1998
|
-
const serveDataDir = resolveServeDataDir(args.dataDir, profile.agent_id);
|
|
1984
|
+
const serveDataDir = resolveServeDataDir(args.dataDir, profile.agent_id, profile.merchant_runtime?.data_dir);
|
|
1999
1985
|
let node = await startA2aNode({
|
|
2000
1986
|
profile,
|
|
2001
1987
|
catalog,
|