@harrylabsj/kiwi 0.6.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/LICENSE +201 -0
- package/README.md +150 -0
- package/contracts/candidate-agent-dto-1.0.README.md +39 -0
- package/contracts/candidate-agent-dto-1.0.schema.json +172 -0
- package/contracts/interop/kiwi-buyer-message-send.json +43 -0
- package/contracts/interop/knp-data-part-examples.json +243 -0
- package/contracts/kiwi-catalog/1.0/agent-record.schema.json +78 -0
- package/contracts/kiwi-catalog/1.0/listing-record.schema.json +88 -0
- package/contracts/kiwi-catalog/1.0/listing-search-result.schema.json +60 -0
- package/contracts/negotiation/1.0/schema.json +501 -0
- package/contracts/shopping.negotiation/0.1/capabilities.schema.json +47 -0
- package/contracts/shopping.negotiation/0.1/decision.schema.json +120 -0
- package/contracts/shopping.negotiation/0.1/policy-result.schema.json +52 -0
- package/contracts/shopping.negotiation/0.1/snapshot.schema.json +172 -0
- package/dist/a2a/client/client.d.ts +33 -0
- package/dist/a2a/client/client.js +161 -0
- package/dist/a2a/client/client.js.map +1 -0
- package/dist/a2a/client/error.d.ts +35 -0
- package/dist/a2a/client/error.js +34 -0
- package/dist/a2a/client/error.js.map +1 -0
- package/dist/a2a/client/index.d.ts +29 -0
- package/dist/a2a/client/index.js +26 -0
- package/dist/a2a/client/index.js.map +1 -0
- package/dist/a2a/client/jsonrpc.d.ts +49 -0
- package/dist/a2a/client/jsonrpc.js +85 -0
- package/dist/a2a/client/jsonrpc.js.map +1 -0
- package/dist/a2a/client/parse.d.ts +18 -0
- package/dist/a2a/client/parse.js +134 -0
- package/dist/a2a/client/parse.js.map +1 -0
- package/dist/a2a/client/types.d.ts +102 -0
- package/dist/a2a/client/types.js +26 -0
- package/dist/a2a/client/types.js.map +1 -0
- package/dist/a2a/client/url-policy.d.ts +44 -0
- package/dist/a2a/client/url-policy.js +242 -0
- package/dist/a2a/client/url-policy.js.map +1 -0
- package/dist/a2a/negotiate.d.ts +68 -0
- package/dist/a2a/negotiate.js +288 -0
- package/dist/a2a/negotiate.js.map +1 -0
- package/dist/a2a/node.d.ts +37 -0
- package/dist/a2a/node.js +155 -0
- package/dist/a2a/node.js.map +1 -0
- package/dist/a2a/server/auth.d.ts +38 -0
- package/dist/a2a/server/auth.js +112 -0
- package/dist/a2a/server/auth.js.map +1 -0
- package/dist/a2a/server/card.d.ts +19 -0
- package/dist/a2a/server/card.js +81 -0
- package/dist/a2a/server/card.js.map +1 -0
- package/dist/a2a/server/errors.d.ts +109 -0
- package/dist/a2a/server/errors.js +178 -0
- package/dist/a2a/server/errors.js.map +1 -0
- package/dist/a2a/server/handler.d.ts +22 -0
- package/dist/a2a/server/handler.js +57 -0
- package/dist/a2a/server/handler.js.map +1 -0
- package/dist/a2a/server/inbound-message.d.ts +37 -0
- package/dist/a2a/server/inbound-message.js +104 -0
- package/dist/a2a/server/inbound-message.js.map +1 -0
- package/dist/a2a/server/index.d.ts +43 -0
- package/dist/a2a/server/index.js +42 -0
- package/dist/a2a/server/index.js.map +1 -0
- package/dist/a2a/server/merchant-handler.d.ts +69 -0
- package/dist/a2a/server/merchant-handler.js +316 -0
- package/dist/a2a/server/merchant-handler.js.map +1 -0
- package/dist/a2a/server/pipeline.d.ts +69 -0
- package/dist/a2a/server/pipeline.js +329 -0
- package/dist/a2a/server/pipeline.js.map +1 -0
- package/dist/a2a/server/server.d.ts +64 -0
- package/dist/a2a/server/server.js +420 -0
- package/dist/a2a/server/server.js.map +1 -0
- package/dist/a2a/server/task-registry.d.ts +31 -0
- package/dist/a2a/server/task-registry.js +67 -0
- package/dist/a2a/server/task-registry.js.map +1 -0
- package/dist/a2a/server/throttle.d.ts +154 -0
- package/dist/a2a/server/throttle.js +289 -0
- package/dist/a2a/server/throttle.js.map +1 -0
- package/dist/a2a/server/types.d.ts +191 -0
- package/dist/a2a/server/types.js +17 -0
- package/dist/a2a/server/types.js.map +1 -0
- package/dist/a2a/server/ucp.d.ts +49 -0
- package/dist/a2a/server/ucp.js +85 -0
- package/dist/a2a/server/ucp.js.map +1 -0
- package/dist/a2a/task/index.d.ts +24 -0
- package/dist/a2a/task/index.js +22 -0
- package/dist/a2a/task/index.js.map +1 -0
- package/dist/a2a/task/ledger.d.ts +48 -0
- package/dist/a2a/task/ledger.js +65 -0
- package/dist/a2a/task/ledger.js.map +1 -0
- package/dist/a2a/task/poller.d.ts +93 -0
- package/dist/a2a/task/poller.js +184 -0
- package/dist/a2a/task/poller.js.map +1 -0
- package/dist/a2a/task/state.d.ts +72 -0
- package/dist/a2a/task/state.js +119 -0
- package/dist/a2a/task/state.js.map +1 -0
- package/dist/a2a/ucp-agent.d.ts +49 -0
- package/dist/a2a/ucp-agent.js +78 -0
- package/dist/a2a/ucp-agent.js.map +1 -0
- package/dist/agent/agent-db.d.ts +31 -0
- package/dist/agent/agent-db.js +91 -0
- package/dist/agent/agent-db.js.map +1 -0
- package/dist/agent/buyer/buyer-tools.d.ts +70 -0
- package/dist/agent/buyer/buyer-tools.js +1353 -0
- package/dist/agent/buyer/buyer-tools.js.map +1 -0
- package/dist/agent/buyer/ranker.d.ts +53 -0
- package/dist/agent/buyer/ranker.js +153 -0
- package/dist/agent/buyer/ranker.js.map +1 -0
- package/dist/agent/buyer/scheduler.d.ts +58 -0
- package/dist/agent/buyer/scheduler.js +317 -0
- package/dist/agent/buyer/scheduler.js.map +1 -0
- package/dist/agent/buyer/search-loop.d.ts +42 -0
- package/dist/agent/buyer/search-loop.js +280 -0
- package/dist/agent/buyer/search-loop.js.map +1 -0
- package/dist/agent/buyer/task-store.d.ts +178 -0
- package/dist/agent/buyer/task-store.js +637 -0
- package/dist/agent/buyer/task-store.js.map +1 -0
- package/dist/agent/buyer/types.d.ts +222 -0
- package/dist/agent/buyer/types.js +124 -0
- package/dist/agent/buyer/types.js.map +1 -0
- package/dist/agent/chat-tools.d.ts +41 -0
- package/dist/agent/chat-tools.js +193 -0
- package/dist/agent/chat-tools.js.map +1 -0
- package/dist/agent/chat-tui.d.ts +49 -0
- package/dist/agent/chat-tui.js +314 -0
- package/dist/agent/chat-tui.js.map +1 -0
- package/dist/agent/connector/fake-connector.d.ts +50 -0
- package/dist/agent/connector/fake-connector.js +138 -0
- package/dist/agent/connector/fake-connector.js.map +1 -0
- package/dist/agent/connector/http-connector.d.ts +49 -0
- package/dist/agent/connector/http-connector.js +208 -0
- package/dist/agent/connector/http-connector.js.map +1 -0
- package/dist/agent/connector/types.d.ts +103 -0
- package/dist/agent/connector/types.js +97 -0
- package/dist/agent/connector/types.js.map +1 -0
- package/dist/agent/fake-chat-model.d.ts +22 -0
- package/dist/agent/fake-chat-model.js +134 -0
- package/dist/agent/fake-chat-model.js.map +1 -0
- package/dist/agent/kernel.d.ts +258 -0
- package/dist/agent/kernel.js +1099 -0
- package/dist/agent/kernel.js.map +1 -0
- package/dist/agent/memory/schema.d.ts +32 -0
- package/dist/agent/memory/schema.js +291 -0
- package/dist/agent/memory/schema.js.map +1 -0
- package/dist/agent/memory/store.d.ts +193 -0
- package/dist/agent/memory/store.js +881 -0
- package/dist/agent/memory/store.js.map +1 -0
- package/dist/agent/memory/types.d.ts +139 -0
- package/dist/agent/memory/types.js +119 -0
- package/dist/agent/memory/types.js.map +1 -0
- package/dist/agent/memory/vault.d.ts +49 -0
- package/dist/agent/memory/vault.js +125 -0
- package/dist/agent/memory/vault.js.map +1 -0
- package/dist/agent/merchant/action-candidate.d.ts +106 -0
- package/dist/agent/merchant/action-candidate.js +241 -0
- package/dist/agent/merchant/action-candidate.js.map +1 -0
- package/dist/agent/merchant/credential-broker.d.ts +67 -0
- package/dist/agent/merchant/credential-broker.js +76 -0
- package/dist/agent/merchant/credential-broker.js.map +1 -0
- package/dist/agent/merchant/fake-merchant-client.d.ts +47 -0
- package/dist/agent/merchant/fake-merchant-client.js +143 -0
- package/dist/agent/merchant/fake-merchant-client.js.map +1 -0
- package/dist/agent/merchant/merchant-client.d.ts +49 -0
- package/dist/agent/merchant/merchant-client.js +186 -0
- package/dist/agent/merchant/merchant-client.js.map +1 -0
- package/dist/agent/merchant/merchant-tools.d.ts +74 -0
- package/dist/agent/merchant/merchant-tools.js +582 -0
- package/dist/agent/merchant/merchant-tools.js.map +1 -0
- package/dist/agent/merchant/types.d.ts +119 -0
- package/dist/agent/merchant/types.js +133 -0
- package/dist/agent/merchant/types.js.map +1 -0
- package/dist/agent/mode.d.ts +32 -0
- package/dist/agent/mode.js +34 -0
- package/dist/agent/mode.js.map +1 -0
- package/dist/agent/negotiation-chat.d.ts +81 -0
- package/dist/agent/negotiation-chat.js +330 -0
- package/dist/agent/negotiation-chat.js.map +1 -0
- package/dist/agent/session.d.ts +22 -0
- package/dist/agent/session.js +164 -0
- package/dist/agent/session.js.map +1 -0
- package/dist/agent/system-prompt.d.ts +26 -0
- package/dist/agent/system-prompt.js +77 -0
- package/dist/agent/system-prompt.js.map +1 -0
- package/dist/agent/write-gate.d.ts +98 -0
- package/dist/agent/write-gate.js +76 -0
- package/dist/agent/write-gate.js.map +1 -0
- package/dist/cli.d.ts +18 -0
- package/dist/cli.js +1139 -0
- package/dist/cli.js.map +1 -0
- package/dist/commerce/data-source.d.ts +88 -0
- package/dist/commerce/data-source.js +25 -0
- package/dist/commerce/data-source.js.map +1 -0
- package/dist/commerce/erp-source.d.ts +51 -0
- package/dist/commerce/erp-source.js +184 -0
- package/dist/commerce/erp-source.js.map +1 -0
- package/dist/commerce/fake-client.d.ts +167 -0
- package/dist/commerce/fake-client.js +549 -0
- package/dist/commerce/fake-client.js.map +1 -0
- package/dist/commerce/http-client.d.ts +73 -0
- package/dist/commerce/http-client.js +284 -0
- package/dist/commerce/http-client.js.map +1 -0
- package/dist/commerce/local-db-source.d.ts +50 -0
- package/dist/commerce/local-db-source.js +162 -0
- package/dist/commerce/local-db-source.js.map +1 -0
- package/dist/commerce/shopping-cli-source.d.ts +57 -0
- package/dist/commerce/shopping-cli-source.js +206 -0
- package/dist/commerce/shopping-cli-source.js.map +1 -0
- package/dist/commerce/types.d.ts +146 -0
- package/dist/commerce/types.js +31 -0
- package/dist/commerce/types.js.map +1 -0
- package/dist/config/profile.d.ts +122 -0
- package/dist/config/profile.js +386 -0
- package/dist/config/profile.js.map +1 -0
- package/dist/contracts/negotiation-schema.d.ts +28 -0
- package/dist/contracts/negotiation-schema.js +101 -0
- package/dist/contracts/negotiation-schema.js.map +1 -0
- package/dist/contracts/schemas.d.ts +31 -0
- package/dist/contracts/schemas.js +122 -0
- package/dist/contracts/schemas.js.map +1 -0
- package/dist/counterparty/a2a-direct/index.d.ts +41 -0
- package/dist/counterparty/a2a-direct/index.js +330 -0
- package/dist/counterparty/a2a-direct/index.js.map +1 -0
- package/dist/counterparty/channel.d.ts +200 -0
- package/dist/counterparty/channel.js +61 -0
- package/dist/counterparty/channel.js.map +1 -0
- package/dist/counterparty/index.d.ts +28 -0
- package/dist/counterparty/index.js +24 -0
- package/dist/counterparty/index.js.map +1 -0
- package/dist/counterparty/platform-api/index.d.ts +41 -0
- package/dist/counterparty/platform-api/index.js +65 -0
- package/dist/counterparty/platform-api/index.js.map +1 -0
- package/dist/counterparty/registry.d.ts +51 -0
- package/dist/counterparty/registry.js +71 -0
- package/dist/counterparty/registry.js.map +1 -0
- package/dist/counterparty/shopping-cli-hosted/index.d.ts +36 -0
- package/dist/counterparty/shopping-cli-hosted/index.js +337 -0
- package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -0
- package/dist/discovery/agent-card/error.d.ts +28 -0
- package/dist/discovery/agent-card/error.js +31 -0
- package/dist/discovery/agent-card/error.js.map +1 -0
- package/dist/discovery/agent-card/extensions.d.ts +20 -0
- package/dist/discovery/agent-card/extensions.js +59 -0
- package/dist/discovery/agent-card/extensions.js.map +1 -0
- package/dist/discovery/agent-card/index.d.ts +29 -0
- package/dist/discovery/agent-card/index.js +38 -0
- package/dist/discovery/agent-card/index.js.map +1 -0
- package/dist/discovery/agent-card/secrets.d.ts +30 -0
- package/dist/discovery/agent-card/secrets.js +240 -0
- package/dist/discovery/agent-card/secrets.js.map +1 -0
- package/dist/discovery/agent-card/types.d.ts +110 -0
- package/dist/discovery/agent-card/types.js +37 -0
- package/dist/discovery/agent-card/types.js.map +1 -0
- package/dist/discovery/agent-card/validate.d.ts +31 -0
- package/dist/discovery/agent-card/validate.js +210 -0
- package/dist/discovery/agent-card/validate.js.map +1 -0
- package/dist/discovery/capability/error.d.ts +23 -0
- package/dist/discovery/capability/error.js +28 -0
- package/dist/discovery/capability/error.js.map +1 -0
- package/dist/discovery/capability/index.d.ts +21 -0
- package/dist/discovery/capability/index.js +21 -0
- package/dist/discovery/capability/index.js.map +1 -0
- package/dist/discovery/capability/intersect.d.ts +56 -0
- package/dist/discovery/capability/intersect.js +137 -0
- package/dist/discovery/capability/intersect.js.map +1 -0
- package/dist/discovery/catalog-source/errors.d.ts +32 -0
- package/dist/discovery/catalog-source/errors.js +41 -0
- package/dist/discovery/catalog-source/errors.js.map +1 -0
- package/dist/discovery/catalog-source/index.d.ts +30 -0
- package/dist/discovery/catalog-source/index.js +29 -0
- package/dist/discovery/catalog-source/index.js.map +1 -0
- package/dist/discovery/catalog-source/kiwi-record.d.ts +183 -0
- package/dist/discovery/catalog-source/kiwi-record.js +72 -0
- package/dist/discovery/catalog-source/kiwi-record.js.map +1 -0
- package/dist/discovery/catalog-source/kiwi-schema.d.ts +33 -0
- package/dist/discovery/catalog-source/kiwi-schema.js +106 -0
- package/dist/discovery/catalog-source/kiwi-schema.js.map +1 -0
- package/dist/discovery/catalog-source/kiwi-source.d.ts +38 -0
- package/dist/discovery/catalog-source/kiwi-source.js +318 -0
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -0
- package/dist/discovery/catalog-source/register.d.ts +48 -0
- package/dist/discovery/catalog-source/register.js +83 -0
- package/dist/discovery/catalog-source/register.js.map +1 -0
- package/dist/discovery/catalog-source/schema.d.ts +21 -0
- package/dist/discovery/catalog-source/schema.js +63 -0
- package/dist/discovery/catalog-source/schema.js.map +1 -0
- package/dist/discovery/catalog-source/source.d.ts +45 -0
- package/dist/discovery/catalog-source/source.js +197 -0
- package/dist/discovery/catalog-source/source.js.map +1 -0
- package/dist/discovery/catalog-source/types.d.ts +122 -0
- package/dist/discovery/catalog-source/types.js +30 -0
- package/dist/discovery/catalog-source/types.js.map +1 -0
- package/dist/discovery/index.d.ts +25 -0
- package/dist/discovery/index.js +25 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/resolve.d.ts +175 -0
- package/dist/discovery/resolve.js +367 -0
- package/dist/discovery/resolve.js.map +1 -0
- package/dist/discovery/ucp/error.d.ts +25 -0
- package/dist/discovery/ucp/error.js +27 -0
- package/dist/discovery/ucp/error.js.map +1 -0
- package/dist/discovery/ucp/index.d.ts +33 -0
- package/dist/discovery/ucp/index.js +28 -0
- package/dist/discovery/ucp/index.js.map +1 -0
- package/dist/discovery/ucp/intersect.d.ts +148 -0
- package/dist/discovery/ucp/intersect.js +312 -0
- package/dist/discovery/ucp/intersect.js.map +1 -0
- package/dist/discovery/ucp/resolver.d.ts +62 -0
- package/dist/discovery/ucp/resolver.js +214 -0
- package/dist/discovery/ucp/resolver.js.map +1 -0
- package/dist/discovery/ucp/types.d.ts +97 -0
- package/dist/discovery/ucp/types.js +103 -0
- package/dist/discovery/ucp/types.js.map +1 -0
- package/dist/discovery/ucp/validate.d.ts +38 -0
- package/dist/discovery/ucp/validate.js +232 -0
- package/dist/discovery/ucp/validate.js.map +1 -0
- package/dist/discovery/ucp/vendor.d.ts +60 -0
- package/dist/discovery/ucp/vendor.js +61 -0
- package/dist/discovery/ucp/vendor.js.map +1 -0
- package/dist/doctor.d.ts +26 -0
- package/dist/doctor.js +113 -0
- package/dist/doctor.js.map +1 -0
- package/dist/exit-codes.d.ts +26 -0
- package/dist/exit-codes.js +27 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/fanout/disclosure.d.ts +138 -0
- package/dist/fanout/disclosure.js +188 -0
- package/dist/fanout/disclosure.js.map +1 -0
- package/dist/fanout/index.d.ts +32 -0
- package/dist/fanout/index.js +30 -0
- package/dist/fanout/index.js.map +1 -0
- package/dist/fanout/orchestrator.d.ts +153 -0
- package/dist/fanout/orchestrator.js +439 -0
- package/dist/fanout/orchestrator.js.map +1 -0
- package/dist/fanout/policy.d.ts +128 -0
- package/dist/fanout/policy.js +130 -0
- package/dist/fanout/policy.js.map +1 -0
- package/dist/handoff/acp-commerce.d.ts +58 -0
- package/dist/handoff/acp-commerce.js +69 -0
- package/dist/handoff/acp-commerce.js.map +1 -0
- package/dist/handoff/authorization.d.ts +127 -0
- package/dist/handoff/authorization.js +107 -0
- package/dist/handoff/authorization.js.map +1 -0
- package/dist/handoff/candidate.d.ts +94 -0
- package/dist/handoff/candidate.js +172 -0
- package/dist/handoff/candidate.js.map +1 -0
- package/dist/handoff/channel.d.ts +88 -0
- package/dist/handoff/channel.js +189 -0
- package/dist/handoff/channel.js.map +1 -0
- package/dist/handoff/completion.d.ts +44 -0
- package/dist/handoff/completion.js +136 -0
- package/dist/handoff/completion.js.map +1 -0
- package/dist/handoff/delivery.d.ts +59 -0
- package/dist/handoff/delivery.js +185 -0
- package/dist/handoff/delivery.js.map +1 -0
- package/dist/handoff/destination.d.ts +39 -0
- package/dist/handoff/destination.js +99 -0
- package/dist/handoff/destination.js.map +1 -0
- package/dist/handoff/errors.d.ts +34 -0
- package/dist/handoff/errors.js +47 -0
- package/dist/handoff/errors.js.map +1 -0
- package/dist/handoff/idempotency.d.ts +51 -0
- package/dist/handoff/idempotency.js +168 -0
- package/dist/handoff/idempotency.js.map +1 -0
- package/dist/handoff/index.d.ts +46 -0
- package/dist/handoff/index.js +48 -0
- package/dist/handoff/index.js.map +1 -0
- package/dist/handoff/ledger.d.ts +94 -0
- package/dist/handoff/ledger.js +195 -0
- package/dist/handoff/ledger.js.map +1 -0
- package/dist/handoff/lifecycle.d.ts +29 -0
- package/dist/handoff/lifecycle.js +102 -0
- package/dist/handoff/lifecycle.js.map +1 -0
- package/dist/handoff/metrics.d.ts +56 -0
- package/dist/handoff/metrics.js +78 -0
- package/dist/handoff/metrics.js.map +1 -0
- package/dist/handoff/operator-approval.d.ts +143 -0
- package/dist/handoff/operator-approval.js +287 -0
- package/dist/handoff/operator-approval.js.map +1 -0
- package/dist/handoff/order-record.d.ts +104 -0
- package/dist/handoff/order-record.js +235 -0
- package/dist/handoff/order-record.js.map +1 -0
- package/dist/handoff/package.d.ts +102 -0
- package/dist/handoff/package.js +132 -0
- package/dist/handoff/package.js.map +1 -0
- package/dist/handoff/transaction.d.ts +96 -0
- package/dist/handoff/transaction.js +263 -0
- package/dist/handoff/transaction.js.map +1 -0
- package/dist/handoff/ucp-checkout/cart-channel.d.ts +111 -0
- package/dist/handoff/ucp-checkout/cart-channel.js +370 -0
- package/dist/handoff/ucp-checkout/cart-channel.js.map +1 -0
- package/dist/handoff/ucp-checkout/cart-parse.d.ts +22 -0
- package/dist/handoff/ucp-checkout/cart-parse.js +102 -0
- package/dist/handoff/ucp-checkout/cart-parse.js.map +1 -0
- package/dist/handoff/ucp-checkout/cart-types.d.ts +93 -0
- package/dist/handoff/ucp-checkout/cart-types.js +38 -0
- package/dist/handoff/ucp-checkout/cart-types.js.map +1 -0
- package/dist/handoff/ucp-checkout/channel.d.ts +159 -0
- package/dist/handoff/ucp-checkout/channel.js +636 -0
- package/dist/handoff/ucp-checkout/channel.js.map +1 -0
- package/dist/handoff/ucp-checkout/client.d.ts +88 -0
- package/dist/handoff/ucp-checkout/client.js +228 -0
- package/dist/handoff/ucp-checkout/client.js.map +1 -0
- package/dist/handoff/ucp-checkout/endpoint.d.ts +36 -0
- package/dist/handoff/ucp-checkout/endpoint.js +145 -0
- package/dist/handoff/ucp-checkout/endpoint.js.map +1 -0
- package/dist/handoff/ucp-checkout/index.d.ts +35 -0
- package/dist/handoff/ucp-checkout/index.js +36 -0
- package/dist/handoff/ucp-checkout/index.js.map +1 -0
- package/dist/handoff/ucp-checkout/parse.d.ts +71 -0
- package/dist/handoff/ucp-checkout/parse.js +349 -0
- package/dist/handoff/ucp-checkout/parse.js.map +1 -0
- package/dist/handoff/ucp-checkout/totals.d.ts +41 -0
- package/dist/handoff/ucp-checkout/totals.js +36 -0
- package/dist/handoff/ucp-checkout/totals.js.map +1 -0
- package/dist/handoff/ucp-checkout/types.d.ts +149 -0
- package/dist/handoff/ucp-checkout/types.js +58 -0
- package/dist/handoff/ucp-checkout/types.js.map +1 -0
- package/dist/handoff/url-safety.d.ts +44 -0
- package/dist/handoff/url-safety.js +121 -0
- package/dist/handoff/url-safety.js.map +1 -0
- package/dist/i18n.d.ts +24 -0
- package/dist/i18n.js +27 -0
- package/dist/i18n.js.map +1 -0
- package/dist/negotiation/action-candidate.d.ts +97 -0
- package/dist/negotiation/action-candidate.js +160 -0
- package/dist/negotiation/action-candidate.js.map +1 -0
- package/dist/negotiation/condition/evaluator.d.ts +36 -0
- package/dist/negotiation/condition/evaluator.js +123 -0
- package/dist/negotiation/condition/evaluator.js.map +1 -0
- package/dist/negotiation/context-map/index.d.ts +23 -0
- package/dist/negotiation/context-map/index.js +22 -0
- package/dist/negotiation/context-map/index.js.map +1 -0
- package/dist/negotiation/context-map/store.d.ts +51 -0
- package/dist/negotiation/context-map/store.js +186 -0
- package/dist/negotiation/context-map/store.js.map +1 -0
- package/dist/negotiation/context-map/types.d.ts +29 -0
- package/dist/negotiation/context-map/types.js +57 -0
- package/dist/negotiation/context-map/types.js.map +1 -0
- package/dist/negotiation/domain/common.d.ts +95 -0
- package/dist/negotiation/domain/common.js +216 -0
- package/dist/negotiation/domain/common.js.map +1 -0
- package/dist/negotiation/domain/envelope.d.ts +55 -0
- package/dist/negotiation/domain/envelope.js +110 -0
- package/dist/negotiation/domain/envelope.js.map +1 -0
- package/dist/negotiation/domain/identifiers.d.ts +65 -0
- package/dist/negotiation/domain/identifiers.js +130 -0
- package/dist/negotiation/domain/identifiers.js.map +1 -0
- package/dist/negotiation/domain/objects.d.ts +149 -0
- package/dist/negotiation/domain/objects.js +335 -0
- package/dist/negotiation/domain/objects.js.map +1 -0
- package/dist/negotiation/idempotency/index.d.ts +26 -0
- package/dist/negotiation/idempotency/index.js +25 -0
- package/dist/negotiation/idempotency/index.js.map +1 -0
- package/dist/negotiation/idempotency/store.d.ts +52 -0
- package/dist/negotiation/idempotency/store.js +189 -0
- package/dist/negotiation/idempotency/store.js.map +1 -0
- package/dist/negotiation/idempotency/types.d.ts +102 -0
- package/dist/negotiation/idempotency/types.js +47 -0
- package/dist/negotiation/idempotency/types.js.map +1 -0
- package/dist/negotiation/jcs.d.ts +21 -0
- package/dist/negotiation/jcs.js +114 -0
- package/dist/negotiation/jcs.js.map +1 -0
- package/dist/negotiation/ledger/event.d.ts +142 -0
- package/dist/negotiation/ledger/event.js +206 -0
- package/dist/negotiation/ledger/event.js.map +1 -0
- package/dist/negotiation/ledger/index.d.ts +26 -0
- package/dist/negotiation/ledger/index.js +25 -0
- package/dist/negotiation/ledger/index.js.map +1 -0
- package/dist/negotiation/ledger/store.d.ts +97 -0
- package/dist/negotiation/ledger/store.js +338 -0
- package/dist/negotiation/ledger/store.js.map +1 -0
- package/dist/negotiation/prompt.d.ts +34 -0
- package/dist/negotiation/prompt.js +113 -0
- package/dist/negotiation/prompt.js.map +1 -0
- package/dist/negotiation/recovery/index.d.ts +26 -0
- package/dist/negotiation/recovery/index.js +24 -0
- package/dist/negotiation/recovery/index.js.map +1 -0
- package/dist/negotiation/recovery/outbound.d.ts +49 -0
- package/dist/negotiation/recovery/outbound.js +34 -0
- package/dist/negotiation/recovery/outbound.js.map +1 -0
- package/dist/negotiation/recovery/recover.d.ts +59 -0
- package/dist/negotiation/recovery/recover.js +486 -0
- package/dist/negotiation/recovery/recover.js.map +1 -0
- package/dist/negotiation/recovery/types.d.ts +85 -0
- package/dist/negotiation/recovery/types.js +17 -0
- package/dist/negotiation/recovery/types.js.map +1 -0
- package/dist/negotiation/state/phase.d.ts +70 -0
- package/dist/negotiation/state/phase.js +200 -0
- package/dist/negotiation/state/phase.js.map +1 -0
- package/dist/negotiation/types.d.ts +139 -0
- package/dist/negotiation/types.js +24 -0
- package/dist/negotiation/types.js.map +1 -0
- package/dist/net/safe-http.d.ts +54 -0
- package/dist/net/safe-http.js +116 -0
- package/dist/net/safe-http.js.map +1 -0
- package/dist/operator/controller.d.ts +181 -0
- package/dist/operator/controller.js +784 -0
- package/dist/operator/controller.js.map +1 -0
- package/dist/operator/runner.d.ts +128 -0
- package/dist/operator/runner.js +248 -0
- package/dist/operator/runner.js.map +1 -0
- package/dist/operator/store.d.ts +39 -0
- package/dist/operator/store.js +169 -0
- package/dist/operator/store.js.map +1 -0
- package/dist/operator/strategy.d.ts +54 -0
- package/dist/operator/strategy.js +249 -0
- package/dist/operator/strategy.js.map +1 -0
- package/dist/operator/tui.d.ts +27 -0
- package/dist/operator/tui.js +395 -0
- package/dist/operator/tui.js.map +1 -0
- package/dist/operator/types.d.ts +224 -0
- package/dist/operator/types.js +17 -0
- package/dist/operator/types.js.map +1 -0
- package/dist/product-buyer.d.ts +74 -0
- package/dist/product-buyer.js +161 -0
- package/dist/product-buyer.js.map +1 -0
- package/dist/product-cli.d.ts +56 -0
- package/dist/product-cli.js +175 -0
- package/dist/product-cli.js.map +1 -0
- package/dist/product-compat.d.ts +50 -0
- package/dist/product-compat.js +63 -0
- package/dist/product-compat.js.map +1 -0
- package/dist/product-init.d.ts +73 -0
- package/dist/product-init.js +203 -0
- package/dist/product-init.js.map +1 -0
- package/dist/product-publish.d.ts +85 -0
- package/dist/product-publish.js +216 -0
- package/dist/product-publish.js.map +1 -0
- package/dist/protocol/legacy-shopping-negotiation/adapter.d.ts +42 -0
- package/dist/protocol/legacy-shopping-negotiation/adapter.js +561 -0
- package/dist/protocol/legacy-shopping-negotiation/adapter.js.map +1 -0
- package/dist/protocol/legacy-shopping-negotiation/mapping.d.ts +78 -0
- package/dist/protocol/legacy-shopping-negotiation/mapping.js +321 -0
- package/dist/protocol/legacy-shopping-negotiation/mapping.js.map +1 -0
- package/dist/protocol/legacy-shopping-negotiation/money.d.ts +49 -0
- package/dist/protocol/legacy-shopping-negotiation/money.js +70 -0
- package/dist/protocol/legacy-shopping-negotiation/money.js.map +1 -0
- package/dist/protocol/legacy-shopping-negotiation/types.d.ts +107 -0
- package/dist/protocol/legacy-shopping-negotiation/types.js +34 -0
- package/dist/protocol/legacy-shopping-negotiation/types.js.map +1 -0
- package/dist/runtime/buyer-policy.d.ts +58 -0
- package/dist/runtime/buyer-policy.js +89 -0
- package/dist/runtime/buyer-policy.js.map +1 -0
- package/dist/runtime/fake-model.d.ts +77 -0
- package/dist/runtime/fake-model.js +307 -0
- package/dist/runtime/fake-model.js.map +1 -0
- package/dist/runtime/foreground.d.ts +56 -0
- package/dist/runtime/foreground.js +97 -0
- package/dist/runtime/foreground.js.map +1 -0
- package/dist/runtime/heartbeat.d.ts +36 -0
- package/dist/runtime/heartbeat.js +49 -0
- package/dist/runtime/heartbeat.js.map +1 -0
- package/dist/runtime/merchant-turn.d.ts +35 -0
- package/dist/runtime/merchant-turn.js +20 -0
- package/dist/runtime/merchant-turn.js.map +1 -0
- package/dist/runtime/model.d.ts +40 -0
- package/dist/runtime/model.js +86 -0
- package/dist/runtime/model.js.map +1 -0
- package/dist/runtime/negotiation-turn.d.ts +101 -0
- package/dist/runtime/negotiation-turn.js +317 -0
- package/dist/runtime/negotiation-turn.js.map +1 -0
- package/dist/runtime/tools.d.ts +64 -0
- package/dist/runtime/tools.js +236 -0
- package/dist/runtime/tools.js.map +1 -0
- package/dist/supervisor/init.d.ts +31 -0
- package/dist/supervisor/init.js +222 -0
- package/dist/supervisor/init.js.map +1 -0
- package/dist/supervisor/logs.d.ts +28 -0
- package/dist/supervisor/logs.js +101 -0
- package/dist/supervisor/logs.js.map +1 -0
- package/dist/supervisor/manage.d.ts +72 -0
- package/dist/supervisor/manage.js +419 -0
- package/dist/supervisor/manage.js.map +1 -0
- package/dist/supervisor/manifest.d.ts +69 -0
- package/dist/supervisor/manifest.js +209 -0
- package/dist/supervisor/manifest.js.map +1 -0
- package/dist/supervisor/stack-config.d.ts +79 -0
- package/dist/supervisor/stack-config.js +262 -0
- package/dist/supervisor/stack-config.js.map +1 -0
- package/dist/supervisor/wrapper.d.ts +17 -0
- package/dist/supervisor/wrapper.js +138 -0
- package/dist/supervisor/wrapper.js.map +1 -0
- package/dist/trust/identity/auth-verifier.d.ts +96 -0
- package/dist/trust/identity/auth-verifier.js +166 -0
- package/dist/trust/identity/auth-verifier.js.map +1 -0
- package/dist/trust/identity/identity-binding.d.ts +63 -0
- package/dist/trust/identity/identity-binding.js +59 -0
- package/dist/trust/identity/identity-binding.js.map +1 -0
- package/dist/trust/identity/index.d.ts +38 -0
- package/dist/trust/identity/index.js +31 -0
- package/dist/trust/identity/index.js.map +1 -0
- package/dist/trust/identity/jws.d.ts +64 -0
- package/dist/trust/identity/jws.js +178 -0
- package/dist/trust/identity/jws.js.map +1 -0
- package/dist/trust/identity/keys.d.ts +71 -0
- package/dist/trust/identity/keys.js +118 -0
- package/dist/trust/identity/keys.js.map +1 -0
- package/dist/trust/identity/message-signature.d.ts +105 -0
- package/dist/trust/identity/message-signature.js +297 -0
- package/dist/trust/identity/message-signature.js.map +1 -0
- package/dist/trust/identity/nonce.d.ts +45 -0
- package/dist/trust/identity/nonce.js +50 -0
- package/dist/trust/identity/nonce.js.map +1 -0
- package/dist/trust/identity/signature-base.d.ts +84 -0
- package/dist/trust/identity/signature-base.js +261 -0
- package/dist/trust/identity/signature-base.js.map +1 -0
- package/dist/trust/identity/trust-policy.d.ts +92 -0
- package/dist/trust/identity/trust-policy.js +95 -0
- package/dist/trust/identity/trust-policy.js.map +1 -0
- package/dist/trust/index.d.ts +21 -0
- package/dist/trust/index.js +22 -0
- package/dist/trust/index.js.map +1 -0
- package/dist/trust/records/evaluator.d.ts +76 -0
- package/dist/trust/records/evaluator.js +122 -0
- package/dist/trust/records/evaluator.js.map +1 -0
- package/dist/trust/records/index.d.ts +28 -0
- package/dist/trust/records/index.js +26 -0
- package/dist/trust/records/index.js.map +1 -0
- package/dist/trust/records/store.d.ts +75 -0
- package/dist/trust/records/store.js +339 -0
- package/dist/trust/records/store.js.map +1 -0
- package/dist/trust/records/types.d.ts +159 -0
- package/dist/trust/records/types.js +40 -0
- package/dist/trust/records/types.js.map +1 -0
- package/dist/tui/banner.d.ts +46 -0
- package/dist/tui/banner.js +99 -0
- package/dist/tui/banner.js.map +1 -0
- package/dist/tui/styles.d.ts +70 -0
- package/dist/tui/styles.js +197 -0
- package/dist/tui/styles.js.map +1 -0
- package/dist/tui/theme.d.ts +63 -0
- package/dist/tui/theme.js +136 -0
- package/dist/tui/theme.js.map +1 -0
- package/examples/profiles/buyer.deepseek.yaml +34 -0
- package/examples/profiles/buyer.fake.yaml +36 -0
- package/examples/profiles/buyer.local.yaml +40 -0
- package/examples/profiles/merchant.deepseek.yaml +32 -0
- package/examples/profiles/merchant.fake.yaml +31 -0
- package/examples/profiles/merchant.local.yaml +34 -0
- package/package.json +55 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* shopping-cli HTTP Commerce Connector (design §15): read-side search
|
|
18
|
+
* endpoints only (GET /search/products, /search/merchants, /products/{sku}
|
|
19
|
+
* are public on the gateway — no token is sent for reads).
|
|
20
|
+
*/
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
22
|
+
import { ConnectorError, parseConnectorMerchant, parseConnectorProduct, } from "./types.js";
|
|
23
|
+
import { isRedirectResponse, readJsonBody, SafeHttpError } from "../../net/safe-http.js";
|
|
24
|
+
const REQUEST_TIMEOUT_MS = 10_000;
|
|
25
|
+
export class ShoppingCliConnector {
|
|
26
|
+
connector_id = "shopping-cli";
|
|
27
|
+
platform = "shopping-cli";
|
|
28
|
+
baseUrl;
|
|
29
|
+
buyerBootstrapToken;
|
|
30
|
+
constructor(baseUrl, options = {}) {
|
|
31
|
+
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
32
|
+
this.buyerBootstrapToken = options.buyerBootstrapToken;
|
|
33
|
+
}
|
|
34
|
+
async get(pathname, params) {
|
|
35
|
+
const url = `${this.baseUrl}${pathname}?${new URLSearchParams(params).toString()}`;
|
|
36
|
+
const controller = new AbortController();
|
|
37
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
38
|
+
let response;
|
|
39
|
+
try {
|
|
40
|
+
response = await fetch(url, {
|
|
41
|
+
method: "GET",
|
|
42
|
+
// 出站纪律(与 P0 七处客户端一致):不跟随重定向 + 响应体读取在
|
|
43
|
+
// 超时覆盖内 + 大小上限。
|
|
44
|
+
redirect: "manual",
|
|
45
|
+
signal: controller.signal,
|
|
46
|
+
headers: { accept: "application/json" },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
throw new ConnectorError("transient", `connector request failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
51
|
+
}
|
|
52
|
+
if (isRedirectResponse(response)) {
|
|
53
|
+
throw new ConnectorError("transient", `connector must not follow redirects (HTTP ${response.status})`);
|
|
54
|
+
}
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
const kind = response.status === 404
|
|
57
|
+
? "not_found"
|
|
58
|
+
: response.status === 401 || response.status === 403
|
|
59
|
+
? "auth"
|
|
60
|
+
: response.status >= 400 && response.status < 500
|
|
61
|
+
? "validation"
|
|
62
|
+
: "transient";
|
|
63
|
+
throw new ConnectorError(kind, `connector HTTP ${response.status} for ${pathname}`);
|
|
64
|
+
}
|
|
65
|
+
let payload;
|
|
66
|
+
try {
|
|
67
|
+
payload = await readJsonBody(response, { signal: controller.signal });
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
if (controller.signal.aborted) {
|
|
71
|
+
throw new ConnectorError("transient", `connector request timed out after ${REQUEST_TIMEOUT_MS}ms`);
|
|
72
|
+
}
|
|
73
|
+
throw new ConnectorError("transient", err instanceof SafeHttpError && err.code === "response_too_large"
|
|
74
|
+
? `connector response too large: ${err.message}`
|
|
75
|
+
: `connector returned non-JSON (HTTP ${response.status})`);
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
}
|
|
80
|
+
return payload;
|
|
81
|
+
}
|
|
82
|
+
async searchProducts(query) {
|
|
83
|
+
const payload = (await this.get("/search/products", {
|
|
84
|
+
query: query.query ?? "",
|
|
85
|
+
city: query.city ?? "",
|
|
86
|
+
area: query.area ?? "",
|
|
87
|
+
...(query.max_price !== undefined ? { max_price: String(query.max_price) } : {}),
|
|
88
|
+
include_out_of_stock: query.include_out_of_stock === true ? "true" : "",
|
|
89
|
+
...(query.limit !== undefined ? { limit: String(query.limit) } : {}),
|
|
90
|
+
...(query.offset !== undefined ? { offset: String(query.offset) } : {}),
|
|
91
|
+
}));
|
|
92
|
+
if (payload === null || typeof payload !== "object" || !Array.isArray(payload.results)) {
|
|
93
|
+
throw new ConnectorError("validation", "search/products response lacks a results array");
|
|
94
|
+
}
|
|
95
|
+
return payload.results.map((p) => parseConnectorProduct(p));
|
|
96
|
+
}
|
|
97
|
+
async getProduct(sku) {
|
|
98
|
+
const payload = (await this.get(`/products/${encodeURIComponent(sku)}`, {}));
|
|
99
|
+
if (payload === null || typeof payload !== "object" || payload.product === undefined) {
|
|
100
|
+
throw new ConnectorError("validation", "get product response lacks a product object");
|
|
101
|
+
}
|
|
102
|
+
return parseConnectorProduct(payload.product);
|
|
103
|
+
}
|
|
104
|
+
async searchMerchants(query) {
|
|
105
|
+
const payload = (await this.get("/search/merchants", {
|
|
106
|
+
query: query.query ?? "",
|
|
107
|
+
city: query.city ?? "",
|
|
108
|
+
...(query.limit !== undefined ? { limit: String(query.limit) } : {}),
|
|
109
|
+
...(query.offset !== undefined ? { offset: String(query.offset) } : {}),
|
|
110
|
+
}));
|
|
111
|
+
if (payload === null || typeof payload !== "object" || !Array.isArray(payload.results)) {
|
|
112
|
+
throw new ConnectorError("validation", "search/merchants response lacks a results array");
|
|
113
|
+
}
|
|
114
|
+
return payload.results.map((m) => parseConnectorMerchant(m));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Start a consultation via `POST /buyer/ask`. Requires the buyer bootstrap
|
|
118
|
+
* token in the Authorization header. The buyer task is only linked to the
|
|
119
|
+
* returned conversation — authoritative state stays in the marketplace.
|
|
120
|
+
*/
|
|
121
|
+
async startConsultation(input) {
|
|
122
|
+
void input.merchant_id;
|
|
123
|
+
void input.sku;
|
|
124
|
+
if (this.buyerBootstrapToken === undefined) {
|
|
125
|
+
throw new ConnectorError("auth", "未配置 buyer bootstrap token(gateway 的 SHOPPING_BUYER_BOOTSTRAP_TOKEN);无法发起咨询");
|
|
126
|
+
}
|
|
127
|
+
// Content-addressed idempotency key: a retried start after a lost response
|
|
128
|
+
// dedups on the gateway instead of creating a second conversation.
|
|
129
|
+
const idempotencyKey = createHash("sha256")
|
|
130
|
+
.update(`${input.buyer_id}:${input.sku}:${input.opening_message}`)
|
|
131
|
+
.digest("hex")
|
|
132
|
+
.slice(0, 16);
|
|
133
|
+
const payload = (await this.post("/buyer/ask", {
|
|
134
|
+
buyer_id: input.buyer_id,
|
|
135
|
+
text: input.opening_message,
|
|
136
|
+
}, {
|
|
137
|
+
authorization: `Bearer ${this.buyerBootstrapToken}`,
|
|
138
|
+
"idempotency-key": idempotencyKey,
|
|
139
|
+
}));
|
|
140
|
+
const conversationId = typeof payload.conversation_id === "string"
|
|
141
|
+
? payload.conversation_id
|
|
142
|
+
: typeof payload.conversation?.id === "string"
|
|
143
|
+
? (payload.conversation.id)
|
|
144
|
+
: undefined;
|
|
145
|
+
if (conversationId === undefined) {
|
|
146
|
+
throw new ConnectorError("validation", "buyer/ask response lacks a conversation id");
|
|
147
|
+
}
|
|
148
|
+
const status = typeof payload.status === "string"
|
|
149
|
+
? payload.status
|
|
150
|
+
: typeof payload.conversation?.status === "string"
|
|
151
|
+
? (payload.conversation.status)
|
|
152
|
+
: "waiting_merchant";
|
|
153
|
+
return { conversation_id: conversationId, status };
|
|
154
|
+
}
|
|
155
|
+
async post(pathname, body, headers) {
|
|
156
|
+
const url = `${this.baseUrl}${pathname}`;
|
|
157
|
+
const controller = new AbortController();
|
|
158
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
159
|
+
let response;
|
|
160
|
+
try {
|
|
161
|
+
response = await fetch(url, {
|
|
162
|
+
method: "POST",
|
|
163
|
+
// 出站纪律(同 get):POST 携带 Bearer token——重定向会泄露给第三方。
|
|
164
|
+
redirect: "manual",
|
|
165
|
+
headers: {
|
|
166
|
+
accept: "application/json",
|
|
167
|
+
"content-type": "application/json",
|
|
168
|
+
...headers,
|
|
169
|
+
},
|
|
170
|
+
body: JSON.stringify(body),
|
|
171
|
+
signal: controller.signal,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
throw new ConnectorError("transient", `connector request failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
176
|
+
}
|
|
177
|
+
if (isRedirectResponse(response)) {
|
|
178
|
+
throw new ConnectorError("transient", `connector must not follow redirects (HTTP ${response.status})`);
|
|
179
|
+
}
|
|
180
|
+
if (!response.ok) {
|
|
181
|
+
const kind = response.status === 404
|
|
182
|
+
? "not_found"
|
|
183
|
+
: response.status === 401 || response.status === 403
|
|
184
|
+
? "auth"
|
|
185
|
+
: response.status >= 400 && response.status < 500
|
|
186
|
+
? "validation"
|
|
187
|
+
: "transient";
|
|
188
|
+
throw new ConnectorError(kind, `connector HTTP ${response.status} for ${pathname}`);
|
|
189
|
+
}
|
|
190
|
+
let payload;
|
|
191
|
+
try {
|
|
192
|
+
payload = await readJsonBody(response, { signal: controller.signal });
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
if (controller.signal.aborted) {
|
|
196
|
+
throw new ConnectorError("transient", `connector request timed out after ${REQUEST_TIMEOUT_MS}ms`);
|
|
197
|
+
}
|
|
198
|
+
throw new ConnectorError("transient", err instanceof SafeHttpError && err.code === "response_too_large"
|
|
199
|
+
? `connector response too large: ${err.message}`
|
|
200
|
+
: `connector returned non-JSON (HTTP ${response.status})`);
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
clearTimeout(timer);
|
|
204
|
+
}
|
|
205
|
+
return payload;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=http-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-connector.js","sourceRoot":"","sources":["../../../src/agent/connector/http-connector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,qBAAqB,GAMtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEzF,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAUlC,MAAM,OAAO,oBAAoB;IACtB,YAAY,GAAG,cAAc,CAAC;IAC9B,QAAQ,GAAG,cAAc,CAAC;IAClB,OAAO,CAAS;IAChB,mBAAmB,CAAqB;IAEzD,YAAY,OAAe,EAAE,UAAuC,EAAE;QACpE,IAAI,CAAC,OAAO,GAAG,OAAO,CA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CAAC,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;oBAClD,CAAC,CAAC,MAAM;oBACR,CAAC,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG;wBAC/C,CAAC,CAAC,YAAY;wBACd,CAAC,CAAC,WAAW,CAAC;YACtB,MAAM,IAAI,cAAc,CAAC,IAAI,EAAE,kBAAkB,QAAQ,CAAC,MAAM,QAAQ,QAAQ,EAAE,CAAC,CAAC;QACtF,CAAC;QACD,IAAI,OAAgB,CAAC;QACrB,IAAI,CAAC;YACH,OAAO,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;QACxE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBAC9B,MAAM,IAAI,cAAc,CACtB,WAAW,EACX,qCAAqC,kBAAkB,IAAI,CAC5D,CAAC;YACJ,CAAC;YACD,MAAM,IAAI,cAAc,CACtB,WAAW,EACX,GAAG,YAAY,aAAa,IAAI,GAAG,CAAC,IAAI,KAAK,oBAAoB;gBAC/D,CAAC,CAAC,iCAAiC,GAAG,CAAC,OAAO,EAAE;gBAChD,CAAC,CAAC,qCAAqC,QAAQ,CAAC,MAAM,GAAG,CAC5D,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Commerce Connector boundary (design §2.1.7, §15): the read-side search
|
|
18
|
+
* surface used by Buyer tasks. shopping-cli is the first connector; future
|
|
19
|
+
* external platforms implement the same interface.
|
|
20
|
+
*
|
|
21
|
+
* Connector payloads are untrusted external data (§17): every response is
|
|
22
|
+
* strictly parsed into these DTOs — known fields type-checked, unknown
|
|
23
|
+
* fields isolated (never passed through to the model or the database).
|
|
24
|
+
*/
|
|
25
|
+
/** Public merchant delivery rule (shopping-cli shape). */
|
|
26
|
+
export interface ConnectorDelivery {
|
|
27
|
+
service_area: string;
|
|
28
|
+
fee: number;
|
|
29
|
+
currency: string;
|
|
30
|
+
eta_minutes: number;
|
|
31
|
+
radius_km: number;
|
|
32
|
+
notes: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ConnectorMerchant {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
city: string;
|
|
38
|
+
service_area: string;
|
|
39
|
+
hours: string;
|
|
40
|
+
tags: string[];
|
|
41
|
+
delivery: ConnectorDelivery;
|
|
42
|
+
product_count: number;
|
|
43
|
+
}
|
|
44
|
+
export interface ConnectorProduct {
|
|
45
|
+
sku: string;
|
|
46
|
+
merchant_id: string;
|
|
47
|
+
title: string;
|
|
48
|
+
description: string;
|
|
49
|
+
category: string;
|
|
50
|
+
tags: string[];
|
|
51
|
+
price: number;
|
|
52
|
+
currency: string;
|
|
53
|
+
stock: number;
|
|
54
|
+
delivery_attributes: string[];
|
|
55
|
+
delivery: ConnectorDelivery;
|
|
56
|
+
merchant: ConnectorMerchant;
|
|
57
|
+
warnings: string[];
|
|
58
|
+
}
|
|
59
|
+
export interface SearchProductsQuery {
|
|
60
|
+
query?: string;
|
|
61
|
+
city?: string;
|
|
62
|
+
area?: string;
|
|
63
|
+
max_price?: number;
|
|
64
|
+
include_out_of_stock?: boolean;
|
|
65
|
+
limit?: number;
|
|
66
|
+
offset?: number;
|
|
67
|
+
}
|
|
68
|
+
export interface SearchMerchantsQuery {
|
|
69
|
+
query?: string;
|
|
70
|
+
city?: string;
|
|
71
|
+
limit?: number;
|
|
72
|
+
offset?: number;
|
|
73
|
+
}
|
|
74
|
+
export type ConnectorErrorKind = "transient" | "validation" | "not_found" | "auth";
|
|
75
|
+
export declare class ConnectorError extends Error {
|
|
76
|
+
readonly kind: ConnectorErrorKind;
|
|
77
|
+
constructor(kind: ConnectorErrorKind, message: string);
|
|
78
|
+
}
|
|
79
|
+
export interface CommerceConnector {
|
|
80
|
+
readonly connector_id: string;
|
|
81
|
+
readonly platform: string;
|
|
82
|
+
searchProducts(query: SearchProductsQuery): Promise<ConnectorProduct[]>;
|
|
83
|
+
getProduct(sku: string): Promise<ConnectorProduct>;
|
|
84
|
+
searchMerchants(query: SearchMerchantsQuery): Promise<ConnectorMerchant[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Start a consultation (design §11.8/§20-C): create an authoritative
|
|
87
|
+
* Marketplace Conversation about a product and return its id. The buyer task
|
|
88
|
+
* is only *linked* to this conversation — the conversation itself stays
|
|
89
|
+
* authoritative in the marketplace. Reuses the existing negotiation runtime;
|
|
90
|
+
* this never copies or duplicates authoritative state.
|
|
91
|
+
*/
|
|
92
|
+
startConsultation(input: {
|
|
93
|
+
buyer_id: string;
|
|
94
|
+
sku: string;
|
|
95
|
+
merchant_id: string;
|
|
96
|
+
opening_message: string;
|
|
97
|
+
}): Promise<{
|
|
98
|
+
conversation_id: string;
|
|
99
|
+
status: string;
|
|
100
|
+
}>;
|
|
101
|
+
}
|
|
102
|
+
export declare function parseConnectorMerchant(value: unknown): ConnectorMerchant;
|
|
103
|
+
export declare function parseConnectorProduct(value: unknown): ConnectorProduct;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export class ConnectorError extends Error {
|
|
17
|
+
kind;
|
|
18
|
+
constructor(kind, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "ConnectorError";
|
|
21
|
+
this.kind = kind;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// ---- strict parsing (isolate unknown fields) ------------------------------
|
|
25
|
+
function fail(message) {
|
|
26
|
+
throw new ConnectorError("validation", `connector payload rejected: ${message}`);
|
|
27
|
+
}
|
|
28
|
+
function reqString(value, at) {
|
|
29
|
+
if (typeof value !== "string")
|
|
30
|
+
fail(`${at} must be a string`);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function reqNumber(value, at) {
|
|
34
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
35
|
+
fail(`${at} must be a finite number`);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function stringArray(value, at) {
|
|
39
|
+
if (!Array.isArray(value) || value.some((v) => typeof v !== "string")) {
|
|
40
|
+
fail(`${at} must be a string array`);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function parseDelivery(value, at) {
|
|
45
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
46
|
+
fail(`${at} must be an object`);
|
|
47
|
+
}
|
|
48
|
+
const v = value;
|
|
49
|
+
return {
|
|
50
|
+
service_area: typeof v.service_area === "string" ? v.service_area : "",
|
|
51
|
+
fee: reqNumber(v.fee ?? 0, `${at}.fee`),
|
|
52
|
+
currency: typeof v.currency === "string" ? v.currency : "CNY",
|
|
53
|
+
eta_minutes: reqNumber(v.eta_minutes ?? 0, `${at}.eta_minutes`),
|
|
54
|
+
radius_km: reqNumber(v.radius_km ?? 0, `${at}.radius_km`),
|
|
55
|
+
notes: typeof v.notes === "string" ? v.notes : "",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function parseConnectorMerchant(value) {
|
|
59
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
60
|
+
fail("merchant must be an object");
|
|
61
|
+
}
|
|
62
|
+
const v = value;
|
|
63
|
+
return {
|
|
64
|
+
id: reqString(v.id, "merchant.id"),
|
|
65
|
+
name: typeof v.name === "string" ? v.name : "",
|
|
66
|
+
city: typeof v.city === "string" ? v.city : "",
|
|
67
|
+
service_area: typeof v.service_area === "string" ? v.service_area : "",
|
|
68
|
+
hours: typeof v.hours === "string" ? v.hours : "",
|
|
69
|
+
tags: Array.isArray(v.tags) ? stringArray(v.tags, "merchant.tags") : [],
|
|
70
|
+
delivery: parseDelivery(v.delivery ?? {}, "merchant.delivery"),
|
|
71
|
+
product_count: typeof v.product_count === "number" ? v.product_count : 0,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function parseConnectorProduct(value) {
|
|
75
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
76
|
+
fail("product must be an object");
|
|
77
|
+
}
|
|
78
|
+
const v = value;
|
|
79
|
+
return {
|
|
80
|
+
sku: reqString(v.sku, "product.sku"),
|
|
81
|
+
merchant_id: reqString(v.merchant_id, "product.merchant_id"),
|
|
82
|
+
title: reqString(v.title, "product.title"),
|
|
83
|
+
description: typeof v.description === "string" ? v.description : "",
|
|
84
|
+
category: typeof v.category === "string" ? v.category : "",
|
|
85
|
+
tags: Array.isArray(v.tags) ? stringArray(v.tags, "product.tags") : [],
|
|
86
|
+
price: reqNumber(v.price, "product.price"),
|
|
87
|
+
currency: reqString(v.currency, "product.currency"),
|
|
88
|
+
stock: reqNumber(v.stock, "product.stock"),
|
|
89
|
+
delivery_attributes: Array.isArray(v.delivery_attributes)
|
|
90
|
+
? stringArray(v.delivery_attributes, "product.delivery_attributes")
|
|
91
|
+
: [],
|
|
92
|
+
delivery: parseDelivery(v.delivery ?? {}, "product.delivery"),
|
|
93
|
+
merchant: parseConnectorMerchant(v.merchant ?? {}),
|
|
94
|
+
warnings: Array.isArray(v.warnings) ? stringArray(v.warnings, "product.warnings") : [],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/agent/connector/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAoEH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAqB;IAClC,YAAY,IAAwB,EAAE,OAAe;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAuBD,8EAA8E;AAE9E,SAAS,IAAI,CAAC,OAAe;IAC3B,MAAM,IAAI,cAAc,CAAC,YAAY,EAAE,+BAA+B,OAAO,EAAE,CAAC,CAAC;AACnF,CAAC;AAED,SAAS,SAAS,CAAC,KAAc,EAAE,EAAU;IAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;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AAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC;YACvD,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,mBAAmB,EAAE,6BAA6B,CAAC;YACnE,CAAC,CAAC,EAAE;QACN,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,EAAE,kBAAkB,CAAC;QAC7D,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC;QAClD,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAAE;KACvF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { Model, MutableModels } from "@earendil-works/pi-ai";
|
|
17
|
+
export declare const FAKE_CHAT_MODEL_ID = "fake-chat-model";
|
|
18
|
+
/** A Models collection whose only model is the deterministic chat fake. */
|
|
19
|
+
export declare function createFakeChatModels(): {
|
|
20
|
+
models: MutableModels;
|
|
21
|
+
model: Model<string>;
|
|
22
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Deterministic fake chat model for `model.provider: fake` (offline smoke
|
|
18
|
+
* runs and tests — no network, no keys). Rule-based, NOT a real model:
|
|
19
|
+
*
|
|
20
|
+
* - "记住 X" -> remember tool call (explicit statement), then confirms;
|
|
21
|
+
* - "忘掉/忘记 X" -> forget_memory tool call when an id is mentioned;
|
|
22
|
+
* - anything else -> a canned acknowledgment (real models answer freely).
|
|
23
|
+
*
|
|
24
|
+
* Returns a Models collection with the faux provider registered, ready for
|
|
25
|
+
* the AgentHarness.
|
|
26
|
+
*/
|
|
27
|
+
import { createModels, fauxAssistantMessage, fauxProvider, fauxToolCall } from "@earendil-works/pi-ai";
|
|
28
|
+
import { TOOL_CORRECT_MEMORY, TOOL_FORGET_MEMORY, TOOL_REMEMBER, } from "./chat-tools.js";
|
|
29
|
+
export const FAKE_CHAT_MODEL_ID = "fake-chat-model";
|
|
30
|
+
function lastUserText(context) {
|
|
31
|
+
for (let i = context.messages.length - 1; i >= 0; i--) {
|
|
32
|
+
const m = context.messages[i];
|
|
33
|
+
if (m && m.role === "user") {
|
|
34
|
+
const content = m.content;
|
|
35
|
+
if (typeof content === "string")
|
|
36
|
+
return content;
|
|
37
|
+
if (Array.isArray(content)) {
|
|
38
|
+
const text = content
|
|
39
|
+
.filter((b) => b.type === "text")
|
|
40
|
+
.map((b) => b.text)
|
|
41
|
+
.join(" ");
|
|
42
|
+
if (text !== "")
|
|
43
|
+
return text;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
function hasToolResult(context, toolName) {
|
|
50
|
+
return context.messages.some((m) => m && m.role === "toolResult" && m.toolName === toolName);
|
|
51
|
+
}
|
|
52
|
+
function toolResultText(context, toolName) {
|
|
53
|
+
for (let i = context.messages.length - 1; i >= 0; i--) {
|
|
54
|
+
const m = context.messages[i];
|
|
55
|
+
if (m && m.role === "toolResult" && m.toolName === toolName) {
|
|
56
|
+
const first = m.content[0];
|
|
57
|
+
if (first && first.type === "text")
|
|
58
|
+
return first.text;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
/** Precise personal data the offline demo must route to the Vault, not plaintext. */
|
|
64
|
+
const SENSITIVE_KIND = [
|
|
65
|
+
{ kind: "address", pattern: /(住址|地址|住在|家住|收货|寄到).{0,20}\d/ },
|
|
66
|
+
{ kind: "contact", pattern: /(电话|手机|微信号|联系方式|邮箱|e-?mail).{0,10}\d{5,}/i },
|
|
67
|
+
{ kind: "private_budget", pattern: /(预算|心理价).{0,6}\d/ },
|
|
68
|
+
{ kind: "merchant_cost", pattern: /(成本|进价).{0,6}\d/ },
|
|
69
|
+
{ kind: "merchant_floor", pattern: /(底价|最低价).{0,6}\d/ },
|
|
70
|
+
{ kind: "other", pattern: /(身份证|银行卡|卡号|账号)/ },
|
|
71
|
+
];
|
|
72
|
+
function classifyNote(note) {
|
|
73
|
+
for (const { kind, pattern } of SENSITIVE_KIND) {
|
|
74
|
+
if (pattern.test(note))
|
|
75
|
+
return { kind };
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
/** One canned behavior step; repeats as a safety net for retries. */
|
|
80
|
+
function respond(context) {
|
|
81
|
+
if (hasToolResult(context, TOOL_REMEMBER)) {
|
|
82
|
+
return fauxAssistantMessage(`好的,${toolResultText(context, TOOL_REMEMBER)}`);
|
|
83
|
+
}
|
|
84
|
+
if (hasToolResult(context, TOOL_FORGET_MEMORY)) {
|
|
85
|
+
return fauxAssistantMessage(`好的,${toolResultText(context, TOOL_FORGET_MEMORY)}`);
|
|
86
|
+
}
|
|
87
|
+
if (hasToolResult(context, TOOL_CORRECT_MEMORY)) {
|
|
88
|
+
return fauxAssistantMessage(`好的,${toolResultText(context, TOOL_CORRECT_MEMORY)}`);
|
|
89
|
+
}
|
|
90
|
+
const text = lastUserText(context);
|
|
91
|
+
const rememberMatch = /^记住[::]?\s*(.+)$/.exec(text.trim());
|
|
92
|
+
if (rememberMatch !== null) {
|
|
93
|
+
const note = (rememberMatch[1] ?? "").trim();
|
|
94
|
+
const sensitive = classifyNote(note);
|
|
95
|
+
return fauxAssistantMessage([
|
|
96
|
+
fauxToolCall(TOOL_REMEMBER, {
|
|
97
|
+
namespace: "preference",
|
|
98
|
+
key: `chat.note.${note.slice(0, 24).replace(/\s+/g, "_")}`,
|
|
99
|
+
source_kind: "explicit",
|
|
100
|
+
explicit_user_statement: true,
|
|
101
|
+
reason_summary: `用户明确要求记住:${note.slice(0, 40)}`,
|
|
102
|
+
// Precise personal data (address/contact/budget/cost/floor) is a
|
|
103
|
+
// Restricted Vault write — never plaintext, and it needs a data key.
|
|
104
|
+
...(sensitive !== undefined
|
|
105
|
+
? {
|
|
106
|
+
restricted_kind: sensitive.kind,
|
|
107
|
+
restricted_value: note,
|
|
108
|
+
sensitivity: "restricted",
|
|
109
|
+
}
|
|
110
|
+
: { value: { note }, sensitivity: "normal" }),
|
|
111
|
+
}),
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
const forgetMatch = /^(?:忘掉|忘记)\s*(mem_[0-9a-z]+)/i.exec(text.trim());
|
|
115
|
+
if (forgetMatch !== null) {
|
|
116
|
+
return fauxAssistantMessage([
|
|
117
|
+
fauxToolCall(TOOL_FORGET_MEMORY, {
|
|
118
|
+
memory_id: (forgetMatch[1] ?? "").toLowerCase(),
|
|
119
|
+
reason: "用户要求遗忘",
|
|
120
|
+
}),
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
return fauxAssistantMessage(`(fake 模型)我听到了:「${text.slice(0, 80)}」。真实模型接入后我会自由回答;` +
|
|
124
|
+
"你可以说「记住 …」,或用 /memory、/forget、/correct、/why。");
|
|
125
|
+
}
|
|
126
|
+
/** A Models collection whose only model is the deterministic chat fake. */
|
|
127
|
+
export function createFakeChatModels() {
|
|
128
|
+
const handle = fauxProvider({ models: [{ id: FAKE_CHAT_MODEL_ID, name: FAKE_CHAT_MODEL_ID }] });
|
|
129
|
+
handle.setResponses([respond, respond, respond, respond]);
|
|
130
|
+
const models = createModels();
|
|
131
|
+
models.setProvider(handle.provider);
|
|
132
|
+
return { models, model: handle.getModel() };
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=fake-chat-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-chat-model.js","sourceRoot":"","sources":["../../src/agent/fake-chat-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEvG,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,GACd,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAEpD,SAAS,YAAY,CAAC,OAAgB;IACpC,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACtD,MAAM,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAA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