@harrylabsj/kiwi 0.12.2 → 0.12.4
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/contracts/kiwi-contracts.lock.json +1 -1
- package/dist/a2a/client/client.d.ts +3 -1
- package/dist/a2a/client/client.js +23 -14
- package/dist/a2a/client/client.js.map +1 -1
- package/dist/a2a/client/types.d.ts +1 -1
- package/dist/a2a/client/url-policy.d.ts +2 -1
- package/dist/a2a/client/url-policy.js +5 -2
- package/dist/a2a/client/url-policy.js.map +1 -1
- package/dist/a2a/negotiate.js +68 -27
- package/dist/a2a/negotiate.js.map +1 -1
- package/dist/a2a/server/merchant-handler.d.ts +0 -6
- package/dist/a2a/server/merchant-handler.js +591 -474
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/pipeline.d.ts +1 -0
- package/dist/a2a/server/pipeline.js +48 -10
- package/dist/a2a/server/pipeline.js.map +1 -1
- package/dist/a2a/task/poller.d.ts +3 -0
- package/dist/a2a/task/poller.js +3 -0
- package/dist/a2a/task/poller.js.map +1 -1
- package/dist/agent/buyer/buyer-tools.d.ts +1 -1
- package/dist/agent/buyer/buyer-tools.js +37 -1
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/scheduler.d.ts +3 -0
- package/dist/agent/buyer/scheduler.js +25 -5
- package/dist/agent/buyer/scheduler.js.map +1 -1
- package/dist/agent/buyer/search-loop.js +6 -2
- package/dist/agent/buyer/search-loop.js.map +1 -1
- package/dist/agent/buyer/task-store.d.ts +12 -0
- package/dist/agent/buyer/task-store.js +101 -14
- package/dist/agent/buyer/task-store.js.map +1 -1
- package/dist/agent/kernel.d.ts +11 -0
- package/dist/agent/kernel.js +345 -273
- package/dist/agent/kernel.js.map +1 -1
- package/dist/agent/kiwi-tool.d.ts +11 -12
- package/dist/agent/merchant/action-candidate.d.ts +7 -0
- package/dist/agent/merchant/action-candidate.js +54 -9
- package/dist/agent/merchant/action-candidate.js.map +1 -1
- package/dist/agent/negotiation-chat.js +36 -8
- package/dist/agent/negotiation-chat.js.map +1 -1
- package/dist/agent/session.js +8 -0
- package/dist/agent/session.js.map +1 -1
- package/dist/agent/write-gate.d.ts +4 -0
- package/dist/agent/write-gate.js +22 -20
- package/dist/agent/write-gate.js.map +1 -1
- package/dist/buyer-core/a2a-knp.d.ts +1 -8
- package/dist/buyer-core/a2a-knp.js +15 -2
- package/dist/buyer-core/a2a-knp.js.map +1 -1
- package/dist/buyer-core/a2a-negotiator.d.ts +24 -19
- package/dist/buyer-core/a2a-negotiator.js +90 -24
- package/dist/buyer-core/a2a-negotiator.js.map +1 -1
- package/dist/buyer-core/a2a-quote-fetcher.d.ts +15 -3
- package/dist/buyer-core/a2a-quote-fetcher.js +131 -55
- package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
- package/dist/buyer-core/build-service.d.ts +2 -0
- package/dist/buyer-core/build-service.js +28 -2
- package/dist/buyer-core/build-service.js.map +1 -1
- package/dist/buyer-core/errors.js +1 -1
- package/dist/buyer-core/negotiator.d.ts +0 -15
- package/dist/buyer-core/negotiator.js +3 -0
- package/dist/buyer-core/negotiator.js.map +1 -1
- package/dist/buyer-core/protocol-recovery.d.ts +67 -0
- package/dist/buyer-core/protocol-recovery.js +328 -0
- package/dist/buyer-core/protocol-recovery.js.map +1 -0
- package/dist/buyer-core/service.d.ts +53 -2
- package/dist/buyer-core/service.js +584 -74
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/buyer-core/store.d.ts +27 -2
- package/dist/buyer-core/store.js +131 -26
- package/dist/buyer-core/store.js.map +1 -1
- package/dist/cli.js +208 -21
- package/dist/cli.js.map +1 -1
- package/dist/cloud/binding/enrollment-challenge.d.ts +1 -0
- package/dist/cloud/binding/enrollment-challenge.js +84 -33
- package/dist/cloud/binding/enrollment-challenge.js.map +1 -1
- package/dist/cloud/binding/enrollment-heartbeat.d.ts +2 -0
- package/dist/cloud/binding/enrollment-heartbeat.js +6 -2
- package/dist/cloud/binding/enrollment-heartbeat.js.map +1 -1
- package/dist/cloud/binding/proofs.d.ts +5 -0
- package/dist/cloud/binding/proofs.js +14 -1
- package/dist/cloud/binding/proofs.js.map +1 -1
- package/dist/cloud/binding/runtime-challenge.d.ts +2 -0
- package/dist/cloud/binding/runtime-challenge.js +20 -8
- package/dist/cloud/binding/runtime-challenge.js.map +1 -1
- package/dist/cloud/binding/store-lock.d.ts +13 -0
- package/dist/cloud/binding/store-lock.js +77 -0
- package/dist/cloud/binding/store-lock.js.map +1 -0
- package/dist/cloud/bootstrap.js +5 -2
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/catalog-client.d.ts +4 -0
- package/dist/cloud/catalog-client.js +106 -29
- package/dist/cloud/catalog-client.js.map +1 -1
- package/dist/cloud/connect-service.d.ts +6 -0
- package/dist/cloud/connect-service.js +360 -120
- package/dist/cloud/connect-service.js.map +1 -1
- package/dist/cloud/onboarding/catalog-pipeline.d.ts +32 -1
- package/dist/cloud/onboarding/catalog-pipeline.js +80 -19
- package/dist/cloud/onboarding/catalog-pipeline.js.map +1 -1
- package/dist/cloud/onboarding/store.js +12 -4
- package/dist/cloud/onboarding/store.js.map +1 -1
- package/dist/cloud/product-import-tabular.js +12 -0
- package/dist/cloud/product-import-tabular.js.map +1 -1
- package/dist/commerce/http-client.d.ts +30 -1
- package/dist/commerce/http-client.js +11 -7
- package/dist/commerce/http-client.js.map +1 -1
- package/dist/commerce/types.d.ts +2 -1
- package/dist/commerce/types.js.map +1 -1
- package/dist/counterparty/a2a-direct/index.js +2 -20
- package/dist/counterparty/a2a-direct/index.js.map +1 -1
- package/dist/counterparty/channel.d.ts +2 -1
- package/dist/counterparty/channel.js.map +1 -1
- package/dist/counterparty/shopping-cli-hosted/index.js +2 -24
- package/dist/counterparty/shopping-cli-hosted/index.js.map +1 -1
- package/dist/demo/demo-runner.d.ts +1 -1
- package/dist/demo/demo-runner.js +3 -6
- package/dist/demo/demo-runner.js.map +1 -1
- package/dist/discovery/catalog-source/cloud-card.d.ts +4 -3
- package/dist/discovery/catalog-source/cloud-card.js +28 -25
- package/dist/discovery/catalog-source/cloud-card.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.d.ts +5 -19
- package/dist/discovery/catalog-source/kiwi-source.js +15 -12
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/discovery/catalog-source/register.js +22 -12
- package/dist/discovery/catalog-source/register.js.map +1 -1
- package/dist/discovery/catalog-source/source.d.ts +3 -17
- package/dist/discovery/catalog-source/source.js +11 -8
- package/dist/discovery/catalog-source/source.js.map +1 -1
- package/dist/discovery/catalog-source/types.d.ts +3 -2
- package/dist/discovery/catalog-source/types.js +0 -15
- package/dist/discovery/catalog-source/types.js.map +1 -1
- package/dist/discovery/merchant-subscriptions.d.ts +4 -0
- package/dist/discovery/merchant-subscriptions.js +72 -23
- package/dist/discovery/merchant-subscriptions.js.map +1 -1
- package/dist/discovery/resolve.d.ts +7 -3
- package/dist/discovery/resolve.js +62 -30
- package/dist/discovery/resolve.js.map +1 -1
- package/dist/discovery/ucp/resolver.d.ts +3 -17
- package/dist/discovery/ucp/resolver.js +9 -3
- package/dist/discovery/ucp/resolver.js.map +1 -1
- package/dist/fanout/disclosure.js +27 -10
- package/dist/fanout/disclosure.js.map +1 -1
- package/dist/fanout/orchestrator.js +38 -24
- package/dist/fanout/orchestrator.js.map +1 -1
- package/dist/fs/atomic-write.d.ts +11 -0
- package/dist/fs/atomic-write.js +67 -10
- package/dist/fs/atomic-write.js.map +1 -1
- package/dist/handoff/order-record.js +25 -3
- package/dist/handoff/order-record.js.map +1 -1
- package/dist/handoff/ucp-checkout/channel.js +2 -1
- package/dist/handoff/ucp-checkout/channel.js.map +1 -1
- package/dist/handoff/ucp-checkout/client.d.ts +1 -0
- package/dist/handoff/ucp-checkout/client.js +48 -37
- package/dist/handoff/ucp-checkout/client.js.map +1 -1
- package/dist/handoff/url-safety.js +3 -0
- package/dist/handoff/url-safety.js.map +1 -1
- package/dist/http/bounded-ip-rate-limit.d.ts +10 -0
- package/dist/http/bounded-ip-rate-limit.js +37 -0
- package/dist/http/bounded-ip-rate-limit.js.map +1 -0
- package/dist/http/cli.js +23 -0
- package/dist/http/cli.js.map +1 -1
- package/dist/http/merchant-feed-api.js +8 -1
- package/dist/http/merchant-feed-api.js.map +1 -1
- package/dist/http/merchant-management/api.js +20 -1
- package/dist/http/merchant-management/api.js.map +1 -1
- package/dist/http/merchant-management/reconciliation-worker.js +5 -2
- package/dist/http/merchant-management/reconciliation-worker.js.map +1 -1
- package/dist/http/merchant-management/trusted-page.js +1 -1
- package/dist/http/merchant-management/trusted-page.js.map +1 -1
- package/dist/http/merchant-server.js +2 -1
- package/dist/http/merchant-server.js.map +1 -1
- package/dist/http/server.d.ts +15 -0
- package/dist/http/server.js +107 -9
- package/dist/http/server.js.map +1 -1
- package/dist/mcp/merchant-rfq-tools.d.ts +6 -4
- package/dist/mcp/merchant-rfq-tools.js +2 -0
- package/dist/mcp/merchant-rfq-tools.js.map +1 -1
- package/dist/mcp/merchant-runtime-assembly.js +1 -18
- package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
- package/dist/mcp/merchant-server.d.ts +0 -22
- package/dist/mcp/merchant-server.js +25 -2
- package/dist/mcp/merchant-server.js.map +1 -1
- package/dist/mcp/types.d.ts +1 -1
- package/dist/mcp/types.js +1 -1
- package/dist/merchant/ai-runtime/config.d.ts +99 -0
- package/dist/merchant/ai-runtime/config.js +187 -0
- package/dist/merchant/ai-runtime/config.js.map +1 -0
- package/dist/merchant/ai-runtime/gate.d.ts +142 -0
- package/dist/merchant/ai-runtime/gate.js +343 -0
- package/dist/merchant/ai-runtime/gate.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-authoritative-receipts.d.ts +5 -0
- package/dist/merchant/ai-runtime/owner-authoritative-receipts.js +53 -0
- package/dist/merchant/ai-runtime/owner-authoritative-receipts.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-budget-gate.d.ts +10 -0
- package/dist/merchant/ai-runtime/owner-budget-gate.js +37 -0
- package/dist/merchant/ai-runtime/owner-budget-gate.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-business-config.d.ts +33 -0
- package/dist/merchant/ai-runtime/owner-business-config.js +93 -0
- package/dist/merchant/ai-runtime/owner-business-config.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-business-host.d.ts +24 -0
- package/dist/merchant/ai-runtime/owner-business-host.js +114 -0
- package/dist/merchant/ai-runtime/owner-business-host.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-business-proof-contract.d.ts +26 -0
- package/dist/merchant/ai-runtime/owner-business-proof-contract.js +2 -0
- package/dist/merchant/ai-runtime/owner-business-proof-contract.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-committed-proof.d.ts +55 -0
- package/dist/merchant/ai-runtime/owner-committed-proof.js +141 -0
- package/dist/merchant/ai-runtime/owner-committed-proof.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-factory-config.d.ts +30 -0
- package/dist/merchant/ai-runtime/owner-factory-config.js +99 -0
- package/dist/merchant/ai-runtime/owner-factory-config.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-file-grant.d.ts +71 -0
- package/dist/merchant/ai-runtime/owner-file-grant.js +118 -0
- package/dist/merchant/ai-runtime/owner-file-grant.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-local-readonly-host.d.ts +17 -0
- package/dist/merchant/ai-runtime/owner-local-readonly-host.js +116 -0
- package/dist/merchant/ai-runtime/owner-local-readonly-host.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-operation-reader.d.ts +24 -0
- package/dist/merchant/ai-runtime/owner-operation-reader.js +62 -0
- package/dist/merchant/ai-runtime/owner-operation-reader.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-provider-guard.d.ts +9 -0
- package/dist/merchant/ai-runtime/owner-provider-guard.js +127 -0
- package/dist/merchant/ai-runtime/owner-provider-guard.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-readonly-facts.d.ts +26 -0
- package/dist/merchant/ai-runtime/owner-readonly-facts.js +72 -0
- package/dist/merchant/ai-runtime/owner-readonly-facts.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-sdk-tools.d.ts +43 -0
- package/dist/merchant/ai-runtime/owner-sdk-tools.js +83 -0
- package/dist/merchant/ai-runtime/owner-sdk-tools.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-session.d.ts +341 -0
- package/dist/merchant/ai-runtime/owner-session.js +1280 -0
- package/dist/merchant/ai-runtime/owner-session.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-storage-admission.d.ts +35 -0
- package/dist/merchant/ai-runtime/owner-storage-admission.js +324 -0
- package/dist/merchant/ai-runtime/owner-storage-admission.js.map +1 -0
- package/dist/merchant/ai-runtime/owner-trusted-factory.d.ts +44 -0
- package/dist/merchant/ai-runtime/owner-trusted-factory.js +185 -0
- package/dist/merchant/ai-runtime/owner-trusted-factory.js.map +1 -0
- package/dist/merchant/ai-runtime/sqlite-budget-store.d.ts +68 -0
- package/dist/merchant/ai-runtime/sqlite-budget-store.js +335 -0
- package/dist/merchant/ai-runtime/sqlite-budget-store.js.map +1 -0
- package/dist/merchant/ai-runtime/status.d.ts +64 -0
- package/dist/merchant/ai-runtime/status.js +56 -0
- package/dist/merchant/ai-runtime/status.js.map +1 -0
- package/dist/merchant/application/service.d.ts +1 -1
- package/dist/merchant/application/service.js +7 -8
- package/dist/merchant/application/service.js.map +1 -1
- package/dist/merchant/grant-store.js +9 -4
- package/dist/merchant/grant-store.js.map +1 -1
- package/dist/merchant/negotiation-observer.d.ts +3 -0
- package/dist/merchant/negotiation-observer.js +33 -19
- package/dist/merchant/negotiation-observer.js.map +1 -1
- package/dist/merchant/operations-report.js +7 -3
- package/dist/merchant/operations-report.js.map +1 -1
- package/dist/merchant/promotion-store.js +1 -0
- package/dist/merchant/promotion-store.js.map +1 -1
- package/dist/merchant/stats-store.js +13 -7
- package/dist/merchant/stats-store.js.map +1 -1
- package/dist/merchant/workbench-service.d.ts +1 -0
- package/dist/merchant/workbench-service.js +28 -11
- package/dist/merchant/workbench-service.js.map +1 -1
- package/dist/merchant-core/commands.d.ts +3 -0
- package/dist/merchant-core/commands.js +39 -2
- package/dist/merchant-core/commands.js.map +1 -1
- package/dist/merchant-core/executor.d.ts +2 -0
- package/dist/merchant-core/executor.js +1 -1
- package/dist/merchant-core/executor.js.map +1 -1
- package/dist/merchant-core/operations.d.ts +2 -2
- package/dist/merchant-core/operations.js +11 -9
- package/dist/merchant-core/operations.js.map +1 -1
- package/dist/merchant-core/product-import.js +1 -1
- package/dist/merchant-core/product-import.js.map +1 -1
- package/dist/merchant-core/rfq/pending-candidates.d.ts +14 -0
- package/dist/merchant-core/rfq/pending-candidates.js +11 -0
- package/dist/merchant-core/rfq/pending-candidates.js.map +1 -0
- package/dist/merchant-core/rfq/release-coordinator.d.ts +9 -2
- package/dist/merchant-core/rfq/release-coordinator.js +32 -14
- package/dist/merchant-core/rfq/release-coordinator.js.map +1 -1
- package/dist/merchant-core/rfq/repository.d.ts +4 -7
- package/dist/merchant-core/rfq/repository.js +10 -24
- package/dist/merchant-core/rfq/repository.js.map +1 -1
- package/dist/merchant-core/rfq/service.d.ts +5 -2
- package/dist/merchant-core/rfq/service.js +4 -3
- package/dist/merchant-core/rfq/service.js.map +1 -1
- package/dist/merchant-gateway/entry-server.js +25 -1
- package/dist/merchant-gateway/entry-server.js.map +1 -1
- package/dist/merchant-gateway/pinned-fetch.d.ts +9 -2
- package/dist/merchant-gateway/pinned-fetch.js +63 -27
- package/dist/merchant-gateway/pinned-fetch.js.map +1 -1
- package/dist/merchant-runtime/manager.d.ts +5 -2
- package/dist/merchant-runtime/manager.js +40 -11
- package/dist/merchant-runtime/manager.js.map +1 -1
- package/dist/negotiation/context-map/store.js +4 -13
- package/dist/negotiation/context-map/store.js.map +1 -1
- package/dist/negotiation/domain/common.js +33 -2
- package/dist/negotiation/domain/common.js.map +1 -1
- package/dist/negotiation/domain/envelope.d.ts +2 -5
- package/dist/negotiation/domain/envelope.js +36 -9
- package/dist/negotiation/domain/envelope.js.map +1 -1
- package/dist/negotiation/domain/objects.js +14 -0
- package/dist/negotiation/domain/objects.js.map +1 -1
- package/dist/negotiation/idempotency/store.d.ts +4 -1
- package/dist/negotiation/idempotency/store.js +80 -52
- package/dist/negotiation/idempotency/store.js.map +1 -1
- package/dist/negotiation/idempotency/types.d.ts +7 -1
- package/dist/negotiation/idempotency/types.js +1 -1
- package/dist/negotiation/idempotency/types.js.map +1 -1
- package/dist/negotiation/jcs.js +11 -16
- package/dist/negotiation/jcs.js.map +1 -1
- package/dist/negotiation/ledger/store.d.ts +15 -9
- package/dist/negotiation/ledger/store.js +201 -65
- package/dist/negotiation/ledger/store.js.map +1 -1
- package/dist/negotiation/recovery/recover.js +30 -30
- package/dist/negotiation/recovery/recover.js.map +1 -1
- package/dist/negotiation/recovery/types.d.ts +3 -3
- package/dist/net/request-budget.d.ts +17 -0
- package/dist/net/request-budget.js +63 -0
- package/dist/net/request-budget.js.map +1 -0
- package/dist/operator/controller.d.ts +1 -1
- package/dist/operator/controller.js +23 -12
- package/dist/operator/controller.js.map +1 -1
- package/dist/operator/runner.d.ts +69 -0
- package/dist/operator/runner.js +260 -39
- package/dist/operator/runner.js.map +1 -1
- package/dist/operator/strategy.d.ts +2 -0
- package/dist/operator/strategy.js +11 -0
- package/dist/operator/strategy.js.map +1 -1
- package/dist/privacy/workbench-retention.js +28 -10
- package/dist/privacy/workbench-retention.js.map +1 -1
- package/dist/product-init.js +25 -4
- package/dist/product-init.js.map +1 -1
- package/dist/product-publish.js +3 -102
- package/dist/product-publish.js.map +1 -1
- package/dist/runtime/foreground.d.ts +1 -1
- package/dist/runtime/foreground.js +3 -0
- package/dist/runtime/foreground.js.map +1 -1
- package/dist/runtime/model.js +4 -0
- package/dist/runtime/model.js.map +1 -1
- package/dist/supervisor/manage.js +109 -35
- package/dist/supervisor/manage.js.map +1 -1
- package/dist/trust/identity/jws.js +46 -5
- package/dist/trust/identity/jws.js.map +1 -1
- package/dist/trust/identity/message-signature.js +15 -2
- package/dist/trust/identity/message-signature.js.map +1 -1
- package/dist/trust/records/store.d.ts +8 -1
- package/dist/trust/records/store.js +68 -6
- package/dist/trust/records/store.js.map +1 -1
- package/dist/weixin/channel.d.ts +4 -0
- package/dist/weixin/channel.js +17 -3
- package/dist/weixin/channel.js.map +1 -1
- package/dist/weixin/cli-weixin.js +8 -2
- package/dist/weixin/cli-weixin.js.map +1 -1
- package/package.json +32 -8
- package/scripts/check-install-toolchain.mjs +69 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** A221 exact facts adapter. Only getExactProduct capability; no writer/model/default client. */
|
|
2
|
+
import { parseExactMoney, WORKBENCH_CURRENCY_TABLE_VERSION, } from "../../merchant/application/money.js";
|
|
3
|
+
export class OwnerReadonlyFactsError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
constructor(code) {
|
|
6
|
+
super(code);
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function createOwnerReadonlyFactsAdapter(config, client, options = {}) {
|
|
11
|
+
if (client === null || typeof client?.getExactProduct !== "function")
|
|
12
|
+
throw new OwnerReadonlyFactsError("owner_readonly_transport_required");
|
|
13
|
+
const get = client.getExactProduct.bind(client), runtimeMerchantId = config.runtimeMerchantId, upstreamMerchantId = config.source.merchantId;
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
async readFresh(sku) {
|
|
16
|
+
if (typeof sku !== "string" || !sku || sku.trim().length === 0)
|
|
17
|
+
throw new OwnerReadonlyFactsError("owner_sku_invalid");
|
|
18
|
+
let p;
|
|
19
|
+
try {
|
|
20
|
+
p = await get(upstreamMerchantId, sku);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new OwnerReadonlyFactsError("owner_facts_unavailable");
|
|
24
|
+
}
|
|
25
|
+
if (p === null ||
|
|
26
|
+
typeof p !== "object" ||
|
|
27
|
+
p.merchant_id !== upstreamMerchantId ||
|
|
28
|
+
p.sku !== sku)
|
|
29
|
+
throw new OwnerReadonlyFactsError("owner_facts_binding_mismatch");
|
|
30
|
+
if (typeof p.price_minor !== "string" ||
|
|
31
|
+
!/^(0|[1-9][0-9]*)$/.test(p.price_minor) ||
|
|
32
|
+
typeof p.currency !== "string" ||
|
|
33
|
+
!/^[A-Z]{3}$/.test(p.currency) ||
|
|
34
|
+
typeof p.currency_table_version !== "string" ||
|
|
35
|
+
!p.currency_table_version)
|
|
36
|
+
throw new OwnerReadonlyFactsError("owner_money_unknown");
|
|
37
|
+
if (p.currency_table_version !== WORKBENCH_CURRENCY_TABLE_VERSION)
|
|
38
|
+
throw new OwnerReadonlyFactsError("owner_currency_table_unknown");
|
|
39
|
+
try {
|
|
40
|
+
parseExactMoney({ currency: p.currency, amount_minor: p.price_minor });
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new OwnerReadonlyFactsError("owner_money_unknown");
|
|
44
|
+
}
|
|
45
|
+
if (!Number.isSafeInteger(p.authority_version) || p.authority_version < 1)
|
|
46
|
+
throw new OwnerReadonlyFactsError("owner_money_version_unknown");
|
|
47
|
+
if (!Number.isSafeInteger(p.stock) || p.stock < 0)
|
|
48
|
+
throw new OwnerReadonlyFactsError("owner_inventory_unknown");
|
|
49
|
+
if (p.listing_paused !== undefined && typeof p.listing_paused !== "boolean")
|
|
50
|
+
throw new OwnerReadonlyFactsError("owner_listing_unknown");
|
|
51
|
+
const hostObservedAt = (options.now ?? (() => new Date().toISOString()))();
|
|
52
|
+
if (!Number.isFinite(Date.parse(hostObservedAt)))
|
|
53
|
+
throw new OwnerReadonlyFactsError("owner_observation_time_invalid");
|
|
54
|
+
return Object.freeze({
|
|
55
|
+
kind: "shopping-cli-exact-observation",
|
|
56
|
+
runtimeMerchantId,
|
|
57
|
+
upstreamMerchantId,
|
|
58
|
+
sku,
|
|
59
|
+
currency: p.currency,
|
|
60
|
+
amountMinor: p.price_minor,
|
|
61
|
+
currencyTableVersion: p.currency_table_version,
|
|
62
|
+
moneyAuthorityVersion: p.authority_version,
|
|
63
|
+
stock: p.stock,
|
|
64
|
+
listingPaused: p.listing_paused ?? null,
|
|
65
|
+
hostObservedAt,
|
|
66
|
+
sourceVerifiedAt: null,
|
|
67
|
+
inventorySourceVersion: null,
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=owner-readonly-facts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owner-readonly-facts.js","sourceRoot":"","sources":["../../../src/merchant/ai-runtime/owner-readonly-facts.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EACL,eAAe,EACf,gCAAgC,GACjC,MAAM,qCAAqC,CAAC;AAG7C,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAC3B;IAArB,YAAqB,IAAY;QAC/B,KAAK,CAAC,IAAI,CAAC,CAAC;QADO,SAAI,GAAJ,IAAI,CAAQ;IAEjC,CAAC;CACF;AAgBD,MAAM,UAAU,+BAA+B,CAC7C,MAA2B,EAC3B,MAA+C,EAC/C,UAAkC,EAAE;IAEpC,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,EAAE,eAAe,KAAK,UAAU;QAClE,MAAM,IAAI,uBAAuB,CAAC,mCAAmC,CAAC,CAAC;IACzE,MAAM,GAAG,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,EAC7C,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,EAC5C,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,KAAK,CAAC,SAAS,CAAC,GAAW;YACzB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;gBAC5D,M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guments. This module does not implement commercial
|
|
4
|
+
* approval, budget, grant, recovery or operation state; host must enforce them.
|
|
5
|
+
*/
|
|
6
|
+
import { type Registry, type TaskId, type ConversationId, type ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
7
|
+
import type { TSchema } from "@earendil-works/pi-ai";
|
|
8
|
+
export interface OwnerSdkToolCall {
|
|
9
|
+
readonly taskId: TaskId;
|
|
10
|
+
readonly callId: string;
|
|
11
|
+
readonly conversationId: ConversationId;
|
|
12
|
+
readonly tool: string;
|
|
13
|
+
readonly args: Readonly<Record<string, unknown>>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Both capabilities must be assembled by the authenticated local host:
|
|
17
|
+
* invokeTool enforces approval/fresh facts/grant/budget/operation gates;
|
|
18
|
+
* historyStrong re-reads grant and reads the bound real SDK conversation.
|
|
19
|
+
* Presence checks cannot establish that a caller implemented those contracts.
|
|
20
|
+
*/
|
|
21
|
+
export interface OwnerSdkHost {
|
|
22
|
+
invokeTool(call: OwnerSdkToolCall): Promise<ToolExecutionResult>;
|
|
23
|
+
historyStrong(limit: number): Promise<readonly string[]>;
|
|
24
|
+
}
|
|
25
|
+
export interface OwnerSdkToolSpec {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly description: string;
|
|
28
|
+
readonly parameters: TSchema;
|
|
29
|
+
}
|
|
30
|
+
export interface OwnerSdkRegistry {
|
|
31
|
+
readonly registry: Registry;
|
|
32
|
+
history(limit?: number): Promise<readonly string[]>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* New registry containing only these tools and SDK built-ins. Do not merge with
|
|
36
|
+
* a registry containing ungated effects. Pure converse installs no tools.
|
|
37
|
+
* Always reinstall on Harness reopen; SDK stores names, not closures.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createOwnerSdkRegistry(input: {
|
|
40
|
+
readonly mode: "converse" | "operation";
|
|
41
|
+
readonly host: OwnerSdkHost;
|
|
42
|
+
readonly tools: readonly OwnerSdkToolSpec[];
|
|
43
|
+
}): OwnerSdkRegistry;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A208: official Durable registry adapter. Host capabilities are trusted local
|
|
3
|
+
* assembly, never model arguments. This module does not implement commercial
|
|
4
|
+
* approval, budget, grant, recovery or operation state; host must enforce them.
|
|
5
|
+
*/
|
|
6
|
+
import { createRegistry, defineExtension, defineTool, } from "@earendil-works/pi-durable";
|
|
7
|
+
/**
|
|
8
|
+
* New registry containing only these tools and SDK built-ins. Do not merge with
|
|
9
|
+
* a registry containing ungated effects. Pure converse installs no tools.
|
|
10
|
+
* Always reinstall on Harness reopen; SDK stores names, not closures.
|
|
11
|
+
*/
|
|
12
|
+
export function createOwnerSdkRegistry(input) {
|
|
13
|
+
if (input === null ||
|
|
14
|
+
typeof input !== "object" ||
|
|
15
|
+
(input.mode !== "converse" && input.mode !== "operation") ||
|
|
16
|
+
input.host === null ||
|
|
17
|
+
typeof input.host !== "object" ||
|
|
18
|
+
typeof input.host.invokeTool !== "function" ||
|
|
19
|
+
typeof input.host.historyStrong !== "function" ||
|
|
20
|
+
!Array.isArray(input.tools)) {
|
|
21
|
+
throw new TypeError("owner SDK registry: trusted host capabilities required");
|
|
22
|
+
}
|
|
23
|
+
// Capture methods now: swapping config methods cannot turn a live registry
|
|
24
|
+
// into an ungated executor. Host remains responsible for its own state.
|
|
25
|
+
const invokeTool = input.host.invokeTool.bind(input.host);
|
|
26
|
+
const historyStrong = input.host.historyStrong.bind(input.host);
|
|
27
|
+
const registry = createRegistry();
|
|
28
|
+
if (input.mode === "operation") {
|
|
29
|
+
const tools = input.tools.map((spec) => {
|
|
30
|
+
if (spec === null ||
|
|
31
|
+
typeof spec !== "object" ||
|
|
32
|
+
typeof spec.name !== "string" ||
|
|
33
|
+
spec.name.length === 0 ||
|
|
34
|
+
typeof spec.description !== "string" ||
|
|
35
|
+
spec.parameters === null ||
|
|
36
|
+
typeof spec.parameters !== "object") {
|
|
37
|
+
throw new TypeError("owner SDK registry: invalid tool specification");
|
|
38
|
+
}
|
|
39
|
+
const name = spec.name;
|
|
40
|
+
return defineTool({
|
|
41
|
+
name,
|
|
42
|
+
description: spec.description,
|
|
43
|
+
parameters: spec.parameters,
|
|
44
|
+
replay: "unsafe",
|
|
45
|
+
executionMode: "sequential",
|
|
46
|
+
async execute(args, api) {
|
|
47
|
+
// These identifiers are supplied by the actual SDK task, not model
|
|
48
|
+
// arguments. Host must bind them to its exact local owner session.
|
|
49
|
+
if (!Number.isSafeInteger(api.taskId) ||
|
|
50
|
+
api.taskId <= 0 ||
|
|
51
|
+
typeof api.callId !== "string" ||
|
|
52
|
+
api.callId.length === 0 ||
|
|
53
|
+
!Number.isSafeInteger(api.conversationId) ||
|
|
54
|
+
api.conversationId <= 0 ||
|
|
55
|
+
args === null ||
|
|
56
|
+
typeof args !== "object" ||
|
|
57
|
+
Array.isArray(args)) {
|
|
58
|
+
throw new TypeError("owner SDK registry: invalid SDK call context");
|
|
59
|
+
}
|
|
60
|
+
// No catch/fallback effect runner: host refusal remains refusal.
|
|
61
|
+
return invokeTool(Object.freeze({
|
|
62
|
+
taskId: api.taskId,
|
|
63
|
+
callId: api.callId,
|
|
64
|
+
conversationId: api.conversationId,
|
|
65
|
+
tool: name,
|
|
66
|
+
args: args,
|
|
67
|
+
}));
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
registry.install(defineExtension({ name: "kiwi-owner-host", tools }));
|
|
72
|
+
}
|
|
73
|
+
return Object.freeze({
|
|
74
|
+
registry,
|
|
75
|
+
async history(limit = 50) {
|
|
76
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1000) {
|
|
77
|
+
throw new RangeError("owner SDK registry: history limit must be 1..1000");
|
|
78
|
+
}
|
|
79
|
+
return historyStrong(limit);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=owner-sdk-tools.js.map
|
|
@@ -0,0 +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V,IAAI,EAAE,IAAyC;qBAChD,CAAC,CACH,CAAC;gBACJ,CAAC;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,QAAQ;QACR,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE;YACtB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,IAAI,EAAE,CAAC;gBAC9D,MAAM,IAAI,UAAU,CAAC,mDAAmD,CAAC,CAAC;YAC5E,CAAC;YACD,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,341 @@
|
|
|
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 OwnerStorageAdmission } from "./owner-storage-admission.js";
|
|
17
|
+
import { OwnerBusinessHost } from "./owner-business-host.js";
|
|
18
|
+
import type { OwnerBusinessBinding, OwnerCommittedPermit } from "./owner-committed-proof.js";
|
|
19
|
+
export interface OwnerSessionSwitches {
|
|
20
|
+
ownerEnabled: boolean;
|
|
21
|
+
aiRuntimeEnabled: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function readOwnerSessionSwitches(env: Record<string, string | undefined>): OwnerSessionSwitches;
|
|
24
|
+
export declare function ownerSessionFullyEnabled(s: OwnerSessionSwitches): boolean;
|
|
25
|
+
export declare function assertOpaqueMerchantId(merchantId: unknown): string;
|
|
26
|
+
export declare function merchantDirName(merchantId: string): string;
|
|
27
|
+
export declare function merchantStorageDir(storageRoot: string, merchantId: string): string;
|
|
28
|
+
export interface FileGrant {
|
|
29
|
+
merchantId: string;
|
|
30
|
+
principal: string;
|
|
31
|
+
granted_at?: string;
|
|
32
|
+
}
|
|
33
|
+
export type GrantCheck = {
|
|
34
|
+
ok: true;
|
|
35
|
+
grant: FileGrant;
|
|
36
|
+
} | {
|
|
37
|
+
ok: false;
|
|
38
|
+
code: "grant_missing" | "grant_unknown" | "grant_merchant_mismatch";
|
|
39
|
+
};
|
|
40
|
+
export declare function checkFileGrant(grantFile: string, merchantId: string, principal: string): GrantCheck;
|
|
41
|
+
export type OperationState = "reserved" | "pending" | "settled" | "reconciliation";
|
|
42
|
+
export interface OperationRecord {
|
|
43
|
+
operation_id: string;
|
|
44
|
+
/** Private new-store binding; absent on legacy converse operations. */
|
|
45
|
+
business_binding?: OwnerBusinessBinding;
|
|
46
|
+
merchant_id: string;
|
|
47
|
+
principal_id?: string;
|
|
48
|
+
candidate_id?: string;
|
|
49
|
+
/** 业务 key:kind + argsHash(同业务重复驱动在此阻断)。 */
|
|
50
|
+
business_key: string;
|
|
51
|
+
kind: string;
|
|
52
|
+
args_hash: string;
|
|
53
|
+
state: OperationState;
|
|
54
|
+
created_at: string;
|
|
55
|
+
updated_at: string;
|
|
56
|
+
/** Accounting is independent of the authoritative business state. Pending blocks redrive. */
|
|
57
|
+
budget_accounting_state?: "pending" | "settled";
|
|
58
|
+
budget_lease_id?: string;
|
|
59
|
+
reconciliation?: {
|
|
60
|
+
decided_at: string;
|
|
61
|
+
outcome: "settled_no_new_effect" | "settled_with_evidence" | "requires_manual_review";
|
|
62
|
+
evidence?: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export declare class OwnerSessionError extends Error {
|
|
66
|
+
readonly code: string;
|
|
67
|
+
constructor(code: string, message: string);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A204-D5:受信本地核对器——reconciliation 结算必须经它核对(绑定 source/
|
|
71
|
+
* operation/merchant 的真实核查结果);任意字符串自述不构成权威对账。
|
|
72
|
+
*/
|
|
73
|
+
export interface ReconciliationVerifier {
|
|
74
|
+
/** Legacy boolean attestations are ignored by A210. */
|
|
75
|
+
verify?(input: {
|
|
76
|
+
operationId: string;
|
|
77
|
+
merchantId: string;
|
|
78
|
+
businessKey: string;
|
|
79
|
+
evidence: string;
|
|
80
|
+
}): {
|
|
81
|
+
trusted: true;
|
|
82
|
+
} | {
|
|
83
|
+
trusted: false;
|
|
84
|
+
reason: string;
|
|
85
|
+
};
|
|
86
|
+
source?: string;
|
|
87
|
+
query?(input: {
|
|
88
|
+
operationId: string;
|
|
89
|
+
merchantId: string;
|
|
90
|
+
principal: string;
|
|
91
|
+
businessKey: string;
|
|
92
|
+
}): {
|
|
93
|
+
source: string;
|
|
94
|
+
operationId: string;
|
|
95
|
+
merchantId: string;
|
|
96
|
+
principal: string;
|
|
97
|
+
businessKey: string;
|
|
98
|
+
receiptRef: string;
|
|
99
|
+
outcome: "confirmed_applied" | "confirmed_not_applied" | "unknown";
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 业务 key:kind + argsHash(参数内容绑定,非调用次数)。
|
|
104
|
+
* A202-R3:argsHash 复用冻结的 contentDigest(JCS canonical,嵌套全层级
|
|
105
|
+
* 可见)——不再自造 JSON replacer(旧实现根层键白名单致嵌套同名键变化不可见)。
|
|
106
|
+
*/
|
|
107
|
+
export declare function businessKey(kind: string, args: unknown): string;
|
|
108
|
+
export interface OwnerBudgetGate {
|
|
109
|
+
acquire(input: {
|
|
110
|
+
merchantId: string;
|
|
111
|
+
estimatedTokens: number;
|
|
112
|
+
}): Promise<{
|
|
113
|
+
allowed: true;
|
|
114
|
+
leaseId: string;
|
|
115
|
+
} | {
|
|
116
|
+
allowed: false;
|
|
117
|
+
reason: string;
|
|
118
|
+
}>;
|
|
119
|
+
settle(input: {
|
|
120
|
+
leaseId: string;
|
|
121
|
+
usedTokens: number;
|
|
122
|
+
}): Promise<void>;
|
|
123
|
+
}
|
|
124
|
+
export interface ApprovalStoreLike {
|
|
125
|
+
create(input: {
|
|
126
|
+
tool: string;
|
|
127
|
+
arguments: Record<string, unknown>;
|
|
128
|
+
preconditions: Record<string, unknown>;
|
|
129
|
+
risk: string;
|
|
130
|
+
expires_at: string;
|
|
131
|
+
}): {
|
|
132
|
+
candidate_id: string;
|
|
133
|
+
status: string;
|
|
134
|
+
};
|
|
135
|
+
get(candidateId: string): {
|
|
136
|
+
candidate_id: string;
|
|
137
|
+
status: string;
|
|
138
|
+
tool?: string;
|
|
139
|
+
arguments?: unknown;
|
|
140
|
+
preconditions?: unknown;
|
|
141
|
+
merchant_id?: unknown;
|
|
142
|
+
} | undefined;
|
|
143
|
+
markApproved(candidateId: string): unknown;
|
|
144
|
+
expireCandidate(candidateId: string): unknown;
|
|
145
|
+
listPending(): ReadonlyArray<{
|
|
146
|
+
candidate_id: string;
|
|
147
|
+
status: string;
|
|
148
|
+
tool?: string;
|
|
149
|
+
}>;
|
|
150
|
+
ownerBinding?: Readonly<{
|
|
151
|
+
merchantId: string;
|
|
152
|
+
principal: string;
|
|
153
|
+
}>;
|
|
154
|
+
expireForRecovery?(): number;
|
|
155
|
+
expireDue?(): number;
|
|
156
|
+
claimForExecution?(id: string): unknown;
|
|
157
|
+
markExecuted?(id: string): unknown;
|
|
158
|
+
supersede?(id: string): unknown;
|
|
159
|
+
}
|
|
160
|
+
export interface OwnerBusinessTool extends importToolSpec {
|
|
161
|
+
readFresh(args: Readonly<Record<string, unknown>>): Promise<Record<string, unknown>>;
|
|
162
|
+
execute(args: Record<string, unknown>, operationId: string): Promise<{
|
|
163
|
+
known: boolean;
|
|
164
|
+
result: import("@earendil-works/pi-durable").ToolExecutionResult;
|
|
165
|
+
}>;
|
|
166
|
+
}
|
|
167
|
+
type importToolSpec = import("./owner-sdk-tools.js").OwnerSdkToolSpec;
|
|
168
|
+
export interface OwnerSdkRuntime {
|
|
169
|
+
models: import("@earendil-works/pi-ai/models").Models;
|
|
170
|
+
model: import("@earendil-works/pi-durable").ModelRef;
|
|
171
|
+
reservationTokens: number;
|
|
172
|
+
maxRequests: number;
|
|
173
|
+
timeoutMs: number;
|
|
174
|
+
tools: readonly OwnerBusinessTool[];
|
|
175
|
+
}
|
|
176
|
+
export interface SdkSurface {
|
|
177
|
+
sessionFile: string;
|
|
178
|
+
history(limit?: number): Promise<string[]>;
|
|
179
|
+
/** Legacy compatibility only; never used by the A210 official runtime. */
|
|
180
|
+
hostGate(args: {
|
|
181
|
+
text: string;
|
|
182
|
+
}): void;
|
|
183
|
+
host?: import("./owner-sdk-tools.js").OwnerSdkHost;
|
|
184
|
+
mode?: "converse" | "operation";
|
|
185
|
+
runtime?: OwnerSdkRuntime;
|
|
186
|
+
checkGrant?: () => void;
|
|
187
|
+
storageAdmission?: OwnerStorageAdmission;
|
|
188
|
+
}
|
|
189
|
+
export type EffectRunner = (input: {
|
|
190
|
+
operationId: string;
|
|
191
|
+
businessKey: string;
|
|
192
|
+
text: string;
|
|
193
|
+
sdk: SdkSurface;
|
|
194
|
+
registerOwnerTools?: boolean;
|
|
195
|
+
}) => Promise<EffectOutcome>;
|
|
196
|
+
export interface EffectOutcome {
|
|
197
|
+
known: boolean;
|
|
198
|
+
summary: string;
|
|
199
|
+
usedTokens?: number;
|
|
200
|
+
}
|
|
201
|
+
export interface OwnerSessionInput {
|
|
202
|
+
storageAdmission?: OwnerStorageAdmission;
|
|
203
|
+
/** Explicit trusted in-process enablement; absent uses dual default-off env. */
|
|
204
|
+
switches?: OwnerSessionSwitches;
|
|
205
|
+
storageRoot: string;
|
|
206
|
+
merchantId: string;
|
|
207
|
+
grantFile: string;
|
|
208
|
+
principal: string;
|
|
209
|
+
now?: () => string;
|
|
210
|
+
businessHost?: OwnerBusinessHost;
|
|
211
|
+
reconciliationVerifier?: ReconciliationVerifier;
|
|
212
|
+
budgetGate?: OwnerBudgetGate;
|
|
213
|
+
approvals?: ApprovalStoreLike;
|
|
214
|
+
sdkRuntime?: OwnerSdkRuntime;
|
|
215
|
+
/** Legacy runners are not accepted for gated business execution. */
|
|
216
|
+
effectRunner?: EffectRunner;
|
|
217
|
+
}
|
|
218
|
+
export interface OwnerSubmitResult {
|
|
219
|
+
ok: true;
|
|
220
|
+
operationId: string;
|
|
221
|
+
state: "settled";
|
|
222
|
+
turnSummary: string;
|
|
223
|
+
}
|
|
224
|
+
export interface OwnerSubmitReconciliation {
|
|
225
|
+
ok: false;
|
|
226
|
+
operationId: string;
|
|
227
|
+
state: "reconciliation";
|
|
228
|
+
reason: "unknown_result_no_redrive";
|
|
229
|
+
}
|
|
230
|
+
export type OwnerSubmitOutcome = OwnerSubmitResult | OwnerSubmitReconciliation | {
|
|
231
|
+
ok: false;
|
|
232
|
+
code: string;
|
|
233
|
+
message: string;
|
|
234
|
+
};
|
|
235
|
+
/** Local diagnostic, not a business retry signal. Only retryAccounting may consume it. */
|
|
236
|
+
export declare class OwnerAccountingFailure extends OwnerSessionError {
|
|
237
|
+
readonly operationId: string;
|
|
238
|
+
readonly leaseId: string;
|
|
239
|
+
readonly usedTokens: number;
|
|
240
|
+
readonly budgetError: unknown;
|
|
241
|
+
readonly businessError: unknown;
|
|
242
|
+
readonly journalErrors: readonly unknown[];
|
|
243
|
+
readonly budgetSettled: boolean;
|
|
244
|
+
readonly businessOutcome: OwnerSubmitOutcome;
|
|
245
|
+
readonly cause: AggregateError;
|
|
246
|
+
constructor(operationId: string, leaseId: string, usedTokens: number, businessOutcome: OwnerSubmitOutcome, budgetError: unknown, businessError: unknown, journalErrors: readonly unknown[], budgetSettled: boolean);
|
|
247
|
+
}
|
|
248
|
+
type SubmitInput = {
|
|
249
|
+
text: string;
|
|
250
|
+
mode?: "converse" | "operation";
|
|
251
|
+
kind?: string;
|
|
252
|
+
args?: Record<string, unknown>;
|
|
253
|
+
approval?: {
|
|
254
|
+
candidateId: string;
|
|
255
|
+
approvedBy?: string;
|
|
256
|
+
approvalRef?: string;
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
export declare class LocalMerchantOwnerSession {
|
|
260
|
+
readonly sessionFile: string;
|
|
261
|
+
readonly recoveredApprovalCount: number;
|
|
262
|
+
private readonly operationsFile;
|
|
263
|
+
private readonly dataDir;
|
|
264
|
+
private readonly ownershipToken;
|
|
265
|
+
private readonly nowFn;
|
|
266
|
+
private readonly input;
|
|
267
|
+
private readonly grant;
|
|
268
|
+
private queue;
|
|
269
|
+
private released;
|
|
270
|
+
private activeTurn;
|
|
271
|
+
private journalInitialized;
|
|
272
|
+
private readonly accountingFailures;
|
|
273
|
+
constructor(input: OwnerSessionInput);
|
|
274
|
+
private assertGrant;
|
|
275
|
+
private store;
|
|
276
|
+
get operationsPath(): string;
|
|
277
|
+
private readOperations;
|
|
278
|
+
private writeOperations;
|
|
279
|
+
private recoverOperations;
|
|
280
|
+
expireForRecovery(): number;
|
|
281
|
+
submitTurn(input: SubmitInput): Promise<OwnerSubmitOutcome>;
|
|
282
|
+
/** Deterministic committed dispatch, same queue as SDK turns; no second agent loop. */
|
|
283
|
+
submitCommittedOperation(permit: OwnerCommittedPermit): Promise<OwnerSubmitOutcome>;
|
|
284
|
+
private businessAuthority;
|
|
285
|
+
private businessGrantDigest;
|
|
286
|
+
/** Trusted local recovery only: no business execution, provider call, new lease or JSON permit. */
|
|
287
|
+
retryAccounting(failure: OwnerAccountingFailure): Promise<OwnerSubmitOutcome>;
|
|
288
|
+
private completeAccounting;
|
|
289
|
+
private assertBusinessRecord;
|
|
290
|
+
private applyBusinessReceipt;
|
|
291
|
+
reconcileCommittedOperation(operationId: string): Promise<OperationRecord>;
|
|
292
|
+
private doCommittedOperation;
|
|
293
|
+
private doSubmitTurn;
|
|
294
|
+
checkExecutionValid(operationId: string, expectedState: OperationState): boolean;
|
|
295
|
+
history(limit?: number): Promise<string[]>;
|
|
296
|
+
reconcileOperation(operationId: string, _outcome: {
|
|
297
|
+
evidence?: string;
|
|
298
|
+
decision: "settled_no_new_effect" | "settled_with_evidence" | "requires_manual_review";
|
|
299
|
+
}): OperationRecord;
|
|
300
|
+
hasUnresolvedForBusinessKey(kind: string, args: unknown): boolean;
|
|
301
|
+
storageFiles(): {
|
|
302
|
+
operations: boolean;
|
|
303
|
+
session: boolean;
|
|
304
|
+
admission: boolean;
|
|
305
|
+
lock: boolean;
|
|
306
|
+
};
|
|
307
|
+
release(): void;
|
|
308
|
+
}
|
|
309
|
+
/** Official loop only. No default faux, local counter, custom loop or self-approval. */
|
|
310
|
+
export declare const defaultPiDurableEffectRunner: EffectRunner;
|
|
311
|
+
export interface OwnerToolDefinition<TArgs = Record<string, unknown>> {
|
|
312
|
+
name: string;
|
|
313
|
+
label: string;
|
|
314
|
+
description: string;
|
|
315
|
+
parameters: unknown;
|
|
316
|
+
execute: (args: TArgs) => Promise<{
|
|
317
|
+
content: Array<{
|
|
318
|
+
type: "text";
|
|
319
|
+
text: string;
|
|
320
|
+
}>;
|
|
321
|
+
details?: unknown;
|
|
322
|
+
}>;
|
|
323
|
+
}
|
|
324
|
+
export declare function defineOwnerTool<TArgs>(def: OwnerToolDefinition<TArgs> & {
|
|
325
|
+
grantFile: string;
|
|
326
|
+
merchantId: string;
|
|
327
|
+
principal: string;
|
|
328
|
+
}): {
|
|
329
|
+
name: string;
|
|
330
|
+
label: string;
|
|
331
|
+
description: string;
|
|
332
|
+
parameters: unknown;
|
|
333
|
+
run: (args: TArgs) => Promise<{
|
|
334
|
+
content: Array<{
|
|
335
|
+
type: "text";
|
|
336
|
+
text: string;
|
|
337
|
+
}>;
|
|
338
|
+
details?: unknown;
|
|
339
|
+
}>;
|
|
340
|
+
};
|
|
341
|
+
export {};
|