@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,142 @@
|
|
|
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 { NegotiationActor } from "../domain/objects.js";
|
|
17
|
+
import type { NegotiationPhase } from "../state/phase.js";
|
|
18
|
+
export declare const LEDGER_EVENT_KINDS: readonly ["message_received", "message_sent", "state_transition", "system", "reconciliation", "error", "handoff_candidate_created", "handoff_candidate_ready", "handoff_candidate_rejected", "handoff_candidate_stale", "handoff_candidate_expired", "handoff_candidate_consumed", "handoff_delivered", "handoff_launched", "handoff_opened_confirmed", "handoff_expired", "handoff_revoked", "handoff_delivery_failed"];
|
|
19
|
+
export type LedgerEventKind = (typeof LEDGER_EVENT_KINDS)[number];
|
|
20
|
+
/** 身份快照(基线 §22 identity snapshot / 子规范 §28)。 */
|
|
21
|
+
export interface LedgerIdentitySnapshot {
|
|
22
|
+
/** 协议级幂等主键的一半:(sender_identity, message_id)。 */
|
|
23
|
+
sender_identity: string;
|
|
24
|
+
/** 对手方身份。 */
|
|
25
|
+
counterparty_identity: string;
|
|
26
|
+
/** KNP envelope actor(buyer|merchant),便于审计快速过滤。 */
|
|
27
|
+
actor?: NegotiationActor;
|
|
28
|
+
}
|
|
29
|
+
/** 能力/版本快照(基线 §22 capability snapshot)。 */
|
|
30
|
+
export interface LedgerCapabilitySnapshot {
|
|
31
|
+
capability: string;
|
|
32
|
+
protocol_version: string;
|
|
33
|
+
agent_version?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Phase 状态转换(对齐 state/phase.ts 的 NegotiationPhase)。 */
|
|
36
|
+
export interface LedgerStateTransition {
|
|
37
|
+
from_phase?: NegotiationPhase;
|
|
38
|
+
to_phase: NegotiationPhase;
|
|
39
|
+
}
|
|
40
|
+
/** 处理结果:成功(可带结构化 result)或协议错误(code 对齐子规范 §18 词表)。 */
|
|
41
|
+
export type LedgerOutcome = {
|
|
42
|
+
kind: "ok";
|
|
43
|
+
result?: Record<string, unknown>;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "error";
|
|
46
|
+
code: string;
|
|
47
|
+
message: string;
|
|
48
|
+
};
|
|
49
|
+
/** 调用方提供的稳定内容字段(digest / 链指针 / 落账元数据由 store 填充)。 */
|
|
50
|
+
export interface LedgerEventContent {
|
|
51
|
+
event_kind: LedgerEventKind;
|
|
52
|
+
negotiation_id: string;
|
|
53
|
+
/** message/exchange refs(基线 §22)。 */
|
|
54
|
+
exchange_id?: string;
|
|
55
|
+
message_id?: string;
|
|
56
|
+
in_reply_to?: string;
|
|
57
|
+
/** remote A2A contextId/taskId(基线 §22 / 子规范 §24.4/§24.5)。 */
|
|
58
|
+
remote_context_id?: string;
|
|
59
|
+
remote_task_id?: string;
|
|
60
|
+
identity: LedgerIdentitySnapshot;
|
|
61
|
+
capability: LedgerCapabilitySnapshot;
|
|
62
|
+
/** wire digest = KNP envelope digest(§19.2)。 */
|
|
63
|
+
wire_digest?: string;
|
|
64
|
+
/** wire payload = 收发时的 envelope 内容(不含 transport signature 字段)。 */
|
|
65
|
+
wire_payload?: Record<string, unknown>;
|
|
66
|
+
/** Phase 状态转换(如该事件驱动了状态机推进)。 */
|
|
67
|
+
state_transition?: LedgerStateTransition;
|
|
68
|
+
/** handoff candidate id(candidate 生命周期事件必填)。 */
|
|
69
|
+
handoff_candidate_id?: string;
|
|
70
|
+
/** handoff id(交付观察事件必填)。 */
|
|
71
|
+
handoff_id?: string;
|
|
72
|
+
/** 溯源:产生该 handoff 的 agreement。 */
|
|
73
|
+
agreement_id?: string;
|
|
74
|
+
/** 溯源:agreement 的 terms_digest。 */
|
|
75
|
+
terms_digest?: string;
|
|
76
|
+
/** 目的地快照(最小化、非秘密;payload 最小化约束见 KTH §11.3)。 */
|
|
77
|
+
destination?: Record<string, unknown>;
|
|
78
|
+
/** 证据快照(OPENED_CONFIRMED 的可归属证据,KTH rev0.3 §9)。 */
|
|
79
|
+
evidence?: Record<string, unknown>;
|
|
80
|
+
outcome: LedgerOutcome;
|
|
81
|
+
/** 业务发生时间(如 envelope.created_at),RFC 3339。 */
|
|
82
|
+
occurred_at: string;
|
|
83
|
+
}
|
|
84
|
+
/** 完整 Ledger 事件。 */
|
|
85
|
+
export interface LedgerEvent extends LedgerEventContent {
|
|
86
|
+
event_id: string;
|
|
87
|
+
/** 链上一条的 event_digest;创世事件为 null。 */
|
|
88
|
+
previous_event_digest: string | null;
|
|
89
|
+
event_digest: string;
|
|
90
|
+
/** 落账时间(可注入时钟),RFC 3339。 */
|
|
91
|
+
recorded_at: string;
|
|
92
|
+
}
|
|
93
|
+
export type LedgerVerifyError = {
|
|
94
|
+
code: "chain_break";
|
|
95
|
+
index: number;
|
|
96
|
+
detail: string;
|
|
97
|
+
} | {
|
|
98
|
+
code: "tampered";
|
|
99
|
+
index: number;
|
|
100
|
+
detail: string;
|
|
101
|
+
} | {
|
|
102
|
+
code: "duplicate";
|
|
103
|
+
index: number;
|
|
104
|
+
detail: string;
|
|
105
|
+
} | {
|
|
106
|
+
code: "corrupt";
|
|
107
|
+
index: number;
|
|
108
|
+
detail: string;
|
|
109
|
+
};
|
|
110
|
+
export interface LedgerVerifyResult {
|
|
111
|
+
valid: boolean;
|
|
112
|
+
count: number;
|
|
113
|
+
error?: LedgerVerifyError;
|
|
114
|
+
}
|
|
115
|
+
export declare const LEDGER_ERROR_CODES: readonly ["ledger_unknown_negotiation", "ledger_chain_corrupt", "ledger_append_only_violation", "ledger_duplicate_content", "ledger_forbidden_content", "ledger_invalid_identity", "ledger_invalid_capability", "ledger_append_locked"];
|
|
116
|
+
export type LedgerErrorCode = (typeof LEDGER_ERROR_CODES)[number];
|
|
117
|
+
/** Ledger 存储/校验失败。与协议错误词表(§18)分开:Ledger 是内部审计域。 */
|
|
118
|
+
export declare class LedgerError extends Error {
|
|
119
|
+
readonly code: LedgerErrorCode;
|
|
120
|
+
/** 出错的行索引(verifyChain 解析坏行时携带)。 */
|
|
121
|
+
readonly index?: number;
|
|
122
|
+
constructor(code: LedgerErrorCode, message: string, index?: number);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 递归扫描内容中的每个 key,命中 CoT / Vault plaintext 禁词即抛
|
|
126
|
+
* ledger_forbidden_content。用于 wire_payload、outcome.result 等自由对象。
|
|
127
|
+
* 幂等键本身(sender_identity 等)是结构化字段,不在递归范围内。
|
|
128
|
+
*/
|
|
129
|
+
export declare function assertNoForbiddenContent(value: unknown, path?: string): void;
|
|
130
|
+
/** 新事件 id:`evt_<uuidv7>`,跨重启稳定且可排序(同 identifiers 的 §6 约定)。 */
|
|
131
|
+
export declare function newLedgerEventId(): string;
|
|
132
|
+
/**
|
|
133
|
+
* 事件「稳定内容」视图:digest 的输入。排除 event_id / event_digest /
|
|
134
|
+
* previous_event_digest / recorded_at(落账元数据),因此同一逻辑事件在任意
|
|
135
|
+
* 链位置、任意落账时间的地址都一致 —— 内容寻址。JCS 跳过 undefined 字段,
|
|
136
|
+
* 可选字段缺省不影响摘要。
|
|
137
|
+
*/
|
|
138
|
+
export declare function eventContentAddressable(content: LedgerEventContent | LedgerEvent): Record<string, unknown>;
|
|
139
|
+
/** 由稳定内容计算 event_digest(contentDigest = JCS + SHA-256,`sha256:` 前缀)。 */
|
|
140
|
+
export declare function computeEventDigest(content: LedgerEventContent | LedgerEvent): string;
|
|
141
|
+
/** 基础结构守卫:保证从磁盘解析的事件具有链校验所需的最小形状。 */
|
|
142
|
+
export declare function isLedgerEvent(value: unknown): value is LedgerEvent;
|
|
@@ -0,0 +1,206 @@
|
|
|
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
|
+
* KNP/1.0 Negotiation Ledger 事件模型(基线 §22 / 子规范 §28)。
|
|
18
|
+
*
|
|
19
|
+
* 每条 Ledger 事件是 append-only、content-addressed、hash-linked 的记录:
|
|
20
|
+
*
|
|
21
|
+
* - `event_digest`:对事件「稳定内容」的 SHA-256 content digest(`sha256:` 前缀,
|
|
22
|
+
* 与 jcs.ts 的 contentDigest 同源)。稳定内容 = 除 event_id / event_digest /
|
|
23
|
+
* previous_event_digest / recorded_at 之外的全部业务字段。这样同一逻辑事件
|
|
24
|
+
* 无论何时、以何种链位置落账都产生同一地址 —— 内容寻址。
|
|
25
|
+
* - `previous_event_digest`:同 negotiation_id 链上前一条的 event_digest。
|
|
26
|
+
* 创世事件(链首)为 null。该字段由 store 按当前链尾计算,调用方不可伪造。
|
|
27
|
+
* - 链完整性由 verifyChain 单独校验:断链(前一 digest 不匹配)与篡改
|
|
28
|
+
* (重算 digest 不匹配)是两种可区分的错误。
|
|
29
|
+
*
|
|
30
|
+
* 不保存(§22 / §28 / §36 不变量 5):raw chain-of-thought 与 Vault plaintext。
|
|
31
|
+
* 该约束不止是文档 —— append 前会递归扫描内容字段,命中禁词即 fail-closed。
|
|
32
|
+
*/
|
|
33
|
+
import { contentDigest } from "../jcs.js";
|
|
34
|
+
import { uuidv7 } from "../domain/identifiers.js";
|
|
35
|
+
export const LEDGER_EVENT_KINDS = [
|
|
36
|
+
"message_received",
|
|
37
|
+
"message_sent",
|
|
38
|
+
"state_transition",
|
|
39
|
+
"system",
|
|
40
|
+
"reconciliation",
|
|
41
|
+
"error",
|
|
42
|
+
// v0.7.0 KTH:candidate 生命周期(KTH rev0.3 §5.1,event-sourced 投影)
|
|
43
|
+
"handoff_candidate_created",
|
|
44
|
+
"handoff_candidate_ready",
|
|
45
|
+
"handoff_candidate_rejected",
|
|
46
|
+
"handoff_candidate_stale",
|
|
47
|
+
"handoff_candidate_expired",
|
|
48
|
+
"handoff_candidate_consumed",
|
|
49
|
+
// v0.7.0 KTH:交付观察(KTH rev0.3 §9,evidence-gated)
|
|
50
|
+
"handoff_delivered",
|
|
51
|
+
"handoff_launched",
|
|
52
|
+
"handoff_opened_confirmed",
|
|
53
|
+
"handoff_expired",
|
|
54
|
+
"handoff_revoked",
|
|
55
|
+
"handoff_delivery_failed",
|
|
56
|
+
];
|
|
57
|
+
export const LEDGER_ERROR_CODES = [
|
|
58
|
+
"ledger_unknown_negotiation",
|
|
59
|
+
"ledger_chain_corrupt",
|
|
60
|
+
"ledger_append_only_violation",
|
|
61
|
+
"ledger_duplicate_content",
|
|
62
|
+
"ledger_forbidden_content",
|
|
63
|
+
"ledger_invalid_identity",
|
|
64
|
+
"ledger_invalid_capability",
|
|
65
|
+
"ledger_append_locked",
|
|
66
|
+
];
|
|
67
|
+
/** Ledger 存储/校验失败。与协议错误词表(§18)分开:Ledger 是内部审计域。 */
|
|
68
|
+
export class LedgerError extends Error {
|
|
69
|
+
code;
|
|
70
|
+
/** 出错的行索引(verifyChain 解析坏行时携带)。 */
|
|
71
|
+
index;
|
|
72
|
+
constructor(code, message, index) {
|
|
73
|
+
super(message);
|
|
74
|
+
this.name = "LedgerError";
|
|
75
|
+
this.code = code;
|
|
76
|
+
this.index = index;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// 禁词检查:不保存 raw chain-of-thought / Vault plaintext(§22 / §28 / §36-5)
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
/** 归一化 key:小写 + 去非字母数字。`chain_of_thought` → `chainofthought`。 */
|
|
83
|
+
function normalizeKey(key) {
|
|
84
|
+
return key.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
85
|
+
}
|
|
86
|
+
/** CoT 相关禁词(精确匹配归一化 key)。 */
|
|
87
|
+
const FORBIDDEN_COT_KEYS = new Set([
|
|
88
|
+
"chainofthought",
|
|
89
|
+
"cot",
|
|
90
|
+
"thought",
|
|
91
|
+
"thoughts",
|
|
92
|
+
"reasoning",
|
|
93
|
+
"rationale",
|
|
94
|
+
"thinking",
|
|
95
|
+
"internalmonologue",
|
|
96
|
+
"scratchpad",
|
|
97
|
+
]);
|
|
98
|
+
/** Vault plaintext / 秘密相关禁词(精确匹配归一化 key)。 */
|
|
99
|
+
const FORBIDDEN_VAULT_KEYS = new Set([
|
|
100
|
+
"vault",
|
|
101
|
+
"vaultplaintext",
|
|
102
|
+
"privatevault",
|
|
103
|
+
"plaintext",
|
|
104
|
+
"secret",
|
|
105
|
+
"secrets",
|
|
106
|
+
"secretkey",
|
|
107
|
+
"privatekey",
|
|
108
|
+
"apikey",
|
|
109
|
+
"password",
|
|
110
|
+
"credential",
|
|
111
|
+
"credentials",
|
|
112
|
+
]);
|
|
113
|
+
/** 子串级兜底:任何 key 中出现即拒绝(双保险,防变形拼写)。 */
|
|
114
|
+
const FORBIDDEN_SUBSTRINGS = ["chainofthought", "vaultplaintext", "privatevault"];
|
|
115
|
+
function isForbiddenKey(key) {
|
|
116
|
+
const normalized = normalizeKey(key);
|
|
117
|
+
if (FORBIDDEN_COT_KEYS.has(normalized) || FORBIDDEN_VAULT_KEYS.has(normalized))
|
|
118
|
+
return true;
|
|
119
|
+
return FORBIDDEN_SUBSTRINGS.some((sub) => normalized.includes(sub));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 递归扫描内容中的每个 key,命中 CoT / Vault plaintext 禁词即抛
|
|
123
|
+
* ledger_forbidden_content。用于 wire_payload、outcome.result 等自由对象。
|
|
124
|
+
* 幂等键本身(sender_identity 等)是结构化字段,不在递归范围内。
|
|
125
|
+
*/
|
|
126
|
+
export function assertNoForbiddenContent(value, path = "$") {
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
for (let i = 0; i < value.length; i++) {
|
|
129
|
+
assertNoForbiddenContent(value[i], `${path}[${i}]`);
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (value !== null && typeof value === "object") {
|
|
134
|
+
for (const key of Object.keys(value)) {
|
|
135
|
+
const childPath = `${path}.${key}`;
|
|
136
|
+
if (isForbiddenKey(key)) {
|
|
137
|
+
throw new LedgerError("ledger_forbidden_content", `ledger MUST NOT record ${childPath}: key is reserved for chain-of-thought / vault plaintext`);
|
|
138
|
+
}
|
|
139
|
+
assertNoForbiddenContent(value[key], childPath);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// 内容寻址与事件构造
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
/** 新事件 id:`evt_<uuidv7>`,跨重启稳定且可排序(同 identifiers 的 §6 约定)。 */
|
|
147
|
+
export function newLedgerEventId() {
|
|
148
|
+
return `evt_${uuidv7()}`;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 事件「稳定内容」视图:digest 的输入。排除 event_id / event_digest /
|
|
152
|
+
* previous_event_digest / recorded_at(落账元数据),因此同一逻辑事件在任意
|
|
153
|
+
* 链位置、任意落账时间的地址都一致 —— 内容寻址。JCS 跳过 undefined 字段,
|
|
154
|
+
* 可选字段缺省不影响摘要。
|
|
155
|
+
*/
|
|
156
|
+
export function eventContentAddressable(content) {
|
|
157
|
+
return {
|
|
158
|
+
event_kind: content.event_kind,
|
|
159
|
+
negotiation_id: content.negotiation_id,
|
|
160
|
+
exchange_id: content.exchange_id,
|
|
161
|
+
message_id: content.message_id,
|
|
162
|
+
in_reply_to: content.in_reply_to,
|
|
163
|
+
remote_context_id: content.remote_context_id,
|
|
164
|
+
remote_task_id: content.remote_task_id,
|
|
165
|
+
identity: content.identity,
|
|
166
|
+
capability: content.capability,
|
|
167
|
+
wire_digest: content.wire_digest,
|
|
168
|
+
wire_payload: content.wire_payload,
|
|
169
|
+
state_transition: content.state_transition,
|
|
170
|
+
// v0.7.0 KTH 字段(JCS 跳过 undefined,KNP 事件向后兼容;KTH 事件的
|
|
171
|
+
// 溯源/证据字段必须纳入 digest——否则篡改 terms_digest/evidence 无法
|
|
172
|
+
// 被 verifyChain 检出,审计链形同虚设,§22/#18)。
|
|
173
|
+
handoff_candidate_id: content.handoff_candidate_id,
|
|
174
|
+
handoff_id: content.handoff_id,
|
|
175
|
+
agreement_id: content.agreement_id,
|
|
176
|
+
terms_digest: content.terms_digest,
|
|
177
|
+
destination: content.destination,
|
|
178
|
+
evidence: content.evidence,
|
|
179
|
+
outcome: content.outcome,
|
|
180
|
+
occurred_at: content.occurred_at,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** 由稳定内容计算 event_digest(contentDigest = JCS + SHA-256,`sha256:` 前缀)。 */
|
|
184
|
+
export function computeEventDigest(content) {
|
|
185
|
+
return contentDigest(eventContentAddressable(content));
|
|
186
|
+
}
|
|
187
|
+
/** 基础结构守卫:保证从磁盘解析的事件具有链校验所需的最小形状。 */
|
|
188
|
+
export function isLedgerEvent(value) {
|
|
189
|
+
if (value === null || typeof value !== "object")
|
|
190
|
+
return false;
|
|
191
|
+
const obj = value;
|
|
192
|
+
return (typeof obj.event_id === "string" &&
|
|
193
|
+
typeof obj.event_digest === "string" &&
|
|
194
|
+
(obj.previous_event_digest === null || typeof obj.previous_event_digest === "string") &&
|
|
195
|
+
typeof obj.negotiation_id === "string" &&
|
|
196
|
+
typeof obj.event_kind === "string" &&
|
|
197
|
+
typeof obj.recorded_at === "string" &&
|
|
198
|
+
typeof obj.occurred_at === "string" &&
|
|
199
|
+
obj.identity !== null &&
|
|
200
|
+
typeof obj.identity === "object" &&
|
|
201
|
+
obj.capability !== null &&
|
|
202
|
+
typeof obj.capability === "object" &&
|
|
203
|
+
obj.outcome !== null &&
|
|
204
|
+
typeof obj.outcome === "object");
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../src/negotiation/ledger/event.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
* KNP/1.0 Negotiation Ledger(基线 §22 / §23 / 子规范 §28)。
|
|
18
|
+
*
|
|
19
|
+
* append-only、content-addressed、hash-linked 的协商审计日志。每条事件含
|
|
20
|
+
* event_digest / previous_event_digest,verifyChain 可区分断链与篡改。
|
|
21
|
+
* 不保存 raw chain-of-thought 与 Vault plaintext(§22 / §28 / §36-5)。
|
|
22
|
+
*/
|
|
23
|
+
export { LedgerError, LEDGER_ERROR_CODES, assertNoForbiddenContent, computeEventDigest, eventContentAddressable, newLedgerEventId, } from "./event.js";
|
|
24
|
+
export type { LedgerCapabilitySnapshot, LedgerEvent, LedgerEventContent, LedgerEventKind, LedgerIdentitySnapshot, LedgerOutcome, LedgerStateTransition, LedgerVerifyError, LedgerVerifyResult, } from "./event.js";
|
|
25
|
+
export { LedgerStore, ledgerFileName } from "./store.js";
|
|
26
|
+
export type { LedgerHighWaterMark, LedgerStoreOptions } from "./store.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
* KNP/1.0 Negotiation Ledger(基线 §22 / §23 / 子规范 §28)。
|
|
18
|
+
*
|
|
19
|
+
* append-only、content-addressed、hash-linked 的协商审计日志。每条事件含
|
|
20
|
+
* event_digest / previous_event_digest,verifyChain 可区分断链与篡改。
|
|
21
|
+
* 不保存 raw chain-of-thought 与 Vault plaintext(§22 / §28 / §36-5)。
|
|
22
|
+
*/
|
|
23
|
+
export { LedgerError, LEDGER_ERROR_CODES, assertNoForbiddenContent, computeEventDigest, eventContentAddressable, newLedgerEventId, } from "./event.js";
|
|
24
|
+
export { LedgerStore, ledgerFileName } from "./store.js";
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/negotiation/ledger/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;GAMG;AACH,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAYpB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -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
|
+
import type { LedgerEvent, LedgerEventContent, LedgerVerifyResult } from "./event.js";
|
|
17
|
+
export interface LedgerHighWaterMark {
|
|
18
|
+
negotiation_id: string;
|
|
19
|
+
count: number;
|
|
20
|
+
last_event_id: string | null;
|
|
21
|
+
last_event_digest: string | null;
|
|
22
|
+
last_recorded_at: string | null;
|
|
23
|
+
last_message_id?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface LedgerStoreOptions {
|
|
26
|
+
/** 基础数据目录;Ledger 文件落在 `<dir>/ledger/`。 */
|
|
27
|
+
dir: string;
|
|
28
|
+
/** 可注入时钟(RFC 3339);缺省用 new Date().toISOString()。 */
|
|
29
|
+
now?: () => string;
|
|
30
|
+
/** 跨进程 append 锁等待上限(ms,缺省 5000);超时 fail-closed。 */
|
|
31
|
+
lockTimeoutMs?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 将 opaque negotiation_id 映射为安全文件名:合法字符保留,其余归一为 `_`,
|
|
35
|
+
* 再附加 id 的 sha256 前缀防止不同 id 归一化碰撞。id 含 `/` 也无法逃逸目录。
|
|
36
|
+
*/
|
|
37
|
+
export declare function ledgerFileName(negotiationId: string): string;
|
|
38
|
+
export declare class LedgerStore {
|
|
39
|
+
private readonly baseDir;
|
|
40
|
+
private readonly ledgerDir;
|
|
41
|
+
private readonly now;
|
|
42
|
+
private readonly lockTimeoutMs;
|
|
43
|
+
constructor(options: LedgerStoreOptions);
|
|
44
|
+
/**
|
|
45
|
+
* 跨进程 append 互斥(评审项 B1):append = load → verify → 整文件重写,
|
|
46
|
+
* 单进程内同步无交错,但**跨进程共享 dir**(handoff 幂等锁文档声称支持
|
|
47
|
+
* 的场景)两个进程同时 append 会各自读到同一链尾、互相覆盖——一条事件
|
|
48
|
+
* 静默丢失(无报错)。锁文件用 `openSync("wx")` 原子创建;持锁崩溃残留
|
|
49
|
+
* 由 mtime 陈旧检测自愈(append 是亚秒级操作,30s 阈值安全);等待超时
|
|
50
|
+
* fail-closed(ledger_append_locked)——绝不静默丢事件。
|
|
51
|
+
*/
|
|
52
|
+
private withChainLock;
|
|
53
|
+
/** ledger 目录(0700),不存在则创建。 */
|
|
54
|
+
private ensureLedgerDir;
|
|
55
|
+
/** negotiation_id → 绝对文件路径(含路径包含检查)。 */
|
|
56
|
+
private filePathFor;
|
|
57
|
+
/** 原子写(对齐 supervisor/manifest.ts:同目录临时文件 + fsync + rename,0600)。 */
|
|
58
|
+
private writeFileAtomic;
|
|
59
|
+
/** 解析一个 JSONL 行;非对象/非事件形状抛 ledger_chain_corrupt。 */
|
|
60
|
+
private parseLine;
|
|
61
|
+
/** 从磁盘读取某 negotiation 的完整事件序列;文件缺失返回 []。 */
|
|
62
|
+
private load;
|
|
63
|
+
/** 某 negotiation 是否已有记录。 */
|
|
64
|
+
hasNegotiation(negotiationId: string): boolean;
|
|
65
|
+
/** 取某 negotiation 的完整事件序列(磁盘直读,不缓存)。 */
|
|
66
|
+
events(negotiationId: string): LedgerEvent[];
|
|
67
|
+
/** 高水位(§23 恢复第 2 步):count / 链尾 digest / 末条 message_id。 */
|
|
68
|
+
highWaterMark(negotiationId: string): LedgerHighWaterMark;
|
|
69
|
+
/**
|
|
70
|
+
* Append 一条事件。链接由当前链尾计算;重复内容(同 event_digest)拒绝。
|
|
71
|
+
* 返回完整事件(含 event_id / digests / recorded_at)。
|
|
72
|
+
*/
|
|
73
|
+
append(content: LedgerEventContent): LedgerEvent;
|
|
74
|
+
private appendUnlocked;
|
|
75
|
+
/**
|
|
76
|
+
* 链完整性校验(§22 verifyChain)。返回结构化结果而非抛错:
|
|
77
|
+
* corrupt 某行不是合法 JSON / 事件形状(撕裂或手工破坏)
|
|
78
|
+
* tampered 重算 event_digest 与存储值不一致(内容被改)
|
|
79
|
+
* chain_break 前一条 digest 不匹配 / 首条非创世(中间删除或链接被改)
|
|
80
|
+
* duplicate event_digest 在链内重复
|
|
81
|
+
* 空链(无事件)视为 valid。
|
|
82
|
+
*/
|
|
83
|
+
verifyChain(negotiationId: string): LedgerVerifyResult;
|
|
84
|
+
/** 对一组事件做链校验(append 与 verifyChain 共用)。 */
|
|
85
|
+
private verifyEvents;
|
|
86
|
+
/** 所有已落账的 negotiation_id(按文件名扫描)。 */
|
|
87
|
+
listNegotiations(): string[];
|
|
88
|
+
/** 按 message_id 查重(§23 第 5 步:compare acknowledged messages)。 */
|
|
89
|
+
findByMessageId(messageId: string): {
|
|
90
|
+
negotiation_id: string;
|
|
91
|
+
event: LedgerEvent;
|
|
92
|
+
} | null;
|
|
93
|
+
/** 内容寻址查询:按 event_digest 取事件(供幂等/审计交叉引用)。 */
|
|
94
|
+
findEventByDigest(negotiationId: string, eventDigest: string): LedgerEvent | null;
|
|
95
|
+
/** 按已落账文件名读取(listNegotiations / findByMessageId 内部复用)。 */
|
|
96
|
+
private loadFromFile;
|
|
97
|
+
}
|