@agenticprimitives/fabric 0.0.0-alpha.39 → 0.0.0-alpha.40
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/CLAUDE.md +14 -22
- package/dist/cloudflare/exchange-store.d.ts +20 -1
- package/dist/cloudflare/exchange-store.d.ts.map +1 -1
- package/dist/cloudflare/exchange-store.js +26 -4
- package/dist/cloudflare/exchange-store.js.map +1 -1
- package/dist/cloudflare/index.d.ts +4 -4
- package/dist/cloudflare/index.d.ts.map +1 -1
- package/dist/cloudflare/index.js +2 -2
- package/dist/cloudflare/index.js.map +1 -1
- package/dist/cloudflare/interaction-store.d.ts +26 -0
- package/dist/cloudflare/interaction-store.d.ts.map +1 -1
- package/dist/cloudflare/interaction-store.js +52 -1
- package/dist/cloudflare/interaction-store.js.map +1 -1
- package/dist/cloudflare/orchestration-runtime.d.ts +19 -5
- package/dist/cloudflare/orchestration-runtime.d.ts.map +1 -1
- package/dist/cloudflare/orchestration-runtime.js +11 -6
- package/dist/cloudflare/orchestration-runtime.js.map +1 -1
- package/dist/cloudflare/principal-gateway-do.d.ts +227 -31
- package/dist/cloudflare/principal-gateway-do.d.ts.map +1 -1
- package/dist/cloudflare/principal-gateway-do.js +398 -58
- package/dist/cloudflare/principal-gateway-do.js.map +1 -1
- package/dist/cloudflare/receipt-signer.d.ts.map +1 -1
- package/dist/cloudflare/receipt-signer.js +6 -3
- package/dist/cloudflare/receipt-signer.js.map +1 -1
- package/dist/cloudflare/vault-exchange-store.d.ts.map +1 -1
- package/dist/cloudflare/vault-exchange-store.js +17 -0
- package/dist/cloudflare/vault-exchange-store.js.map +1 -1
- package/dist/cloudflare/vault-interaction-store.d.ts +1 -1
- package/dist/cloudflare/vault-interaction-store.d.ts.map +1 -1
- package/dist/cloudflare/vault-interaction-store.js +14 -0
- package/dist/cloudflare/vault-interaction-store.js.map +1 -1
- package/dist/email/index.d.ts +4 -0
- package/dist/email/index.d.ts.map +1 -1
- package/dist/email/index.js +19 -5
- package/dist/email/index.js.map +1 -1
- package/dist/messaging/board.d.ts +1 -1
- package/dist/messaging/consult-routing.d.ts +92 -19
- package/dist/messaging/consult-routing.d.ts.map +1 -1
- package/dist/messaging/consult-routing.js +136 -35
- package/dist/messaging/consult-routing.js.map +1 -1
- package/dist/messaging/index.d.ts +1 -1
- package/dist/messaging/index.d.ts.map +1 -1
- package/dist/messaging/index.js +1 -1
- package/dist/messaging/index.js.map +1 -1
- package/dist/messaging/vault-store.d.ts.map +1 -1
- package/dist/messaging/vault-store.js +8 -0
- package/dist/messaging/vault-store.js.map +1 -1
- package/package.json +9 -9
package/CLAUDE.md
CHANGED
|
@@ -7,10 +7,8 @@ re-verified against the principal SA. Transport-agnostic core; the Cloudflare `P
|
|
|
7
7
|
adapter ships from `./cloudflare`.
|
|
8
8
|
|
|
9
9
|
## Status
|
|
10
|
-
**W1–W10b DONE
|
|
11
|
-
|
|
12
|
-
re-signing cutover rather than a cleanup (it is inside the signed wire hash, spec 340 §R.1/§R.3);
|
|
13
|
-
interaction-aware ingress; on-chain `atl:gatewayRoot`; `A2aTaskDO`/`SessionStoreDO` absorption.
|
|
10
|
+
**W1–W10b DONE** — history: [`docs/architecture.md` §7a](docs/architecture.md). Next: `MessageEnvelopeV1.kind`
|
|
11
|
+
(a re-signing cutover, spec 340 §R.1/§R.3); on-chain `atl:gatewayRoot`; `A2aTaskDO`/`SessionStoreDO` absorption.
|
|
14
12
|
|
|
15
13
|
## What this package owns
|
|
16
14
|
- `ExchangeRecordV1` — the ONE canonical object (spine id `xch_`); two-level FSM: `ExecState`
|
|
@@ -32,17 +30,19 @@ interaction-aware ingress; on-chain `atl:gatewayRoot`; `A2aTaskDO`/`SessionStore
|
|
|
32
30
|
- **Two serving planes; the transition is a LADDER** ([ADR-0060](../../docs/architecture/decisions/0060-incremental-gateway-adoption.md)).
|
|
33
31
|
`InteractionsDO` serves; this is the target. Ops climb `off → shadow → serving` one at a time. A clean
|
|
34
32
|
shadow proves the planes AGREE, never that either is right.
|
|
33
|
+
- **The gateway authenticates its own ingress** (spec 445 §3.4): `principal`/`tier`/`actor` come only from the
|
|
34
|
+
injected `GatewayDeps.authenticate` via `admitCaller` → `AuthenticatedCaller`; no authenticator ⇒ refused.
|
|
35
|
+
`orchestrate` = verdict + per-step caveat pass + request id. Only an `active` interaction takes exchanges;
|
|
36
|
+
`openInteraction` never overwrites. Consult eligibility = current member ∩ live grant (two inputs).
|
|
35
37
|
- **Authority is never satisfied by the exchange.** A request carries an `authorityRef`; approving a
|
|
36
38
|
case advances the lifecycle, it NEVER unlocks a resource (spec 316 §2, ADR-0041).
|
|
37
39
|
- **`ExecState` is `fulfillment`'s `TaskState`, unmodified** — `fulfillment` stays a pure leaf.
|
|
38
40
|
- **Fail-closed coupling.** An `(exec, case)` pair with no mapping is a typed rejection.
|
|
39
41
|
- **Transport-agnostic core.** No Cloudflare/MCP/A2A-SDK imports in `src/` — `./cloudflare` is the
|
|
40
42
|
only adapter and the only `@cloudflare/workers-types` consumer.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
`compareServed` / `classifyDivergence` (a race is not a divergence), `shouldShadow` sampling, the bounded
|
|
45
|
-
in-memory `recordDivergence`. The ledger VALUES — which op is on which rung, and why — stay with the product.
|
|
43
|
+
- **The adoption ladder's mechanics are here** (`src/adoption.ts`, spec 399 §4): `adoptionStage(ledger, op, env)`
|
|
44
|
+
(`GATEWAY_SHADOW` gates a shadow; `""` is unset), `compareServed` / `classifyDivergence`, `shouldShadow`,
|
|
45
|
+
`recordDivergence`. The ledger VALUES — which op is on which rung, and why — stay with the product.
|
|
46
46
|
|
|
47
47
|
## Boundary
|
|
48
48
|
`types`, `fulfillment`, `vault`, `audit`, `delegation`, `chain-state`, `tool-policy`, `agent-naming`
|
|
@@ -50,19 +50,11 @@ interaction-aware ingress; on-chain `atl:gatewayRoot`; `A2aTaskDO`/`SessionStore
|
|
|
50
50
|
provenance` (the PROV-O projector). No back-edges; nothing imports `fabric` except `./cloudflare` + apps.
|
|
51
51
|
|
|
52
52
|
## Validate
|
|
53
|
-
|
|
54
|
-
pnpm --filter @agenticprimitives/fabric typecheck
|
|
55
|
-
pnpm --filter @agenticprimitives/fabric test
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
## Capabilities
|
|
59
|
-
- **Messaging + Interactions** ([spec 309](../../specs/309-messaging-and-interactions.md)) — fabric IS the
|
|
60
|
-
substrate both were absorbed into · [guide](../../apps/demo-sso-next/docs/messaging-interactions/guide.md).
|
|
61
|
-
- **Home control plane + inbox** ([spec 310](../../specs/310-agentic-trust-home-control-plane-and-inbox.md))
|
|
62
|
-
· [guide](../../apps/demo-sso-next/docs/home-inbox/guide.md).
|
|
63
|
-
- Index: [cross-cutting-capabilities.md](../../docs/architecture/cross-cutting-capabilities.md).
|
|
53
|
+
`pnpm --filter @agenticprimitives/fabric typecheck && pnpm --filter @agenticprimitives/fabric test`
|
|
64
54
|
|
|
65
|
-
##
|
|
66
|
-
[spec
|
|
55
|
+
## Capabilities, spec + guides
|
|
56
|
+
Messaging + Interactions ([spec 309](../../specs/309-messaging-and-interactions.md)) · Home control plane +
|
|
57
|
+
inbox ([spec 310](../../specs/310-agentic-trust-home-control-plane-and-inbox.md)) ·
|
|
58
|
+
[index](../../docs/architecture/cross-cutting-capabilities.md) · [spec 316](../../specs/316-agentic-interaction-fabric.md) (architect-of-record) ·
|
|
67
59
|
[target](../../docs/architecture/agentic-interaction-fabric-target.md) · ADR-0047 ·
|
|
68
60
|
[fabric architecture](docs/architecture.md) (live wiring + build history).
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import type { ExchangeRecordV1, ExchangeEventV1, ExchangeId } from '../exchange-record.js';
|
|
2
2
|
import { type ExchangeApplyResult } from '../exchange-reducer.js';
|
|
3
|
+
/** The outcome of an insert-only write: stored, or refused with the record that was already there. */
|
|
4
|
+
export type ExchangeInsertResult = {
|
|
5
|
+
inserted: true;
|
|
6
|
+
} | {
|
|
7
|
+
inserted: false;
|
|
8
|
+
existing: ExchangeRecordV1;
|
|
9
|
+
};
|
|
3
10
|
/** Durable, single-writer store of `ExchangeRecordV1` snapshots for one principal's gateway DO. */
|
|
4
11
|
export interface ExchangeStore {
|
|
5
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* OVERWRITE by exchange id. Reserved for the single writer's OWN path — a reducer result, a rebuild, a
|
|
14
|
+
* migration — where the caller already holds the record it is replacing. It MUST NOT be reachable from
|
|
15
|
+
* anything a counterparty supplies: an exchange id is shared with every party to the exchange and is not
|
|
16
|
+
* a secret, so an overwrite keyed by one lets any peer replace the owner's history (spec 445 §3.4,
|
|
17
|
+
* audit H-10 / DATA-1). A delivery uses `insert`.
|
|
18
|
+
*/
|
|
6
19
|
put(record: ExchangeRecordV1): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* INSERT-ONLY (spec 445 §3.4). Stores `record` iff nothing is held under its exchange id; otherwise
|
|
22
|
+
* writes NOTHING and returns what is already there, so the caller can tell an idempotent redelivery
|
|
23
|
+
* from an attempt to replace. This is the only write a delivery may make.
|
|
24
|
+
*/
|
|
25
|
+
insert(record: ExchangeRecordV1): Promise<ExchangeInsertResult>;
|
|
7
26
|
/** The current record, or `null`. */
|
|
8
27
|
get(exchangeId: ExchangeId | string): Promise<ExchangeRecordV1 | null>;
|
|
9
28
|
/** Append one event: load → `applyExchangeEvent` → persist on success; the reducer's result is returned
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange-store.d.ts","sourceRoot":"","sources":["../../src/cloudflare/exchange-store.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAiBtF,mGAAmG;AACnG,MAAM,WAAW,aAAa;IAC5B
|
|
1
|
+
{"version":3,"file":"exchange-store.d.ts","sourceRoot":"","sources":["../../src/cloudflare/exchange-store.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAiBtF,sGAAsG;AACtG,MAAM,MAAM,oBAAoB,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAExG,mGAAmG;AACnG,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,GAAG,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAChE,qCAAqC;IACrC,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IACvE;kGAC8F;IAC9F,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;IACrG,0EAA0E;IAC1E,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;CACrC;AAED,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,UAAU,GAAG,aAAa,CAoE/E"}
|
|
@@ -15,15 +15,37 @@ export function createDurableObjectExchangeStore(sql) {
|
|
|
15
15
|
ON CONFLICT(exchange_id) DO UPDATE SET
|
|
16
16
|
record_json = excluded.record_json, rev = excluded.rev, updated_at = excluded.updated_at`, record.exchangeId, JSON.stringify(record), record.rev, record.updatedAt);
|
|
17
17
|
};
|
|
18
|
+
const read = (exchangeId) => {
|
|
19
|
+
const rows = sql
|
|
20
|
+
.exec('SELECT record_json FROM exchange_records WHERE exchange_id = ?', String(exchangeId))
|
|
21
|
+
.toArray();
|
|
22
|
+
return rows[0] ? JSON.parse(rows[0].record_json) : null;
|
|
23
|
+
};
|
|
18
24
|
return {
|
|
19
25
|
async put(record) {
|
|
20
26
|
save(record);
|
|
21
27
|
},
|
|
22
|
-
async
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
async insert(record) {
|
|
29
|
+
// ONE statement decides: `ON CONFLICT DO NOTHING` cannot replace a row, and `RETURNING` reports
|
|
30
|
+
// whether this call was the one that wrote it. No read-then-write window, so the answer does not
|
|
31
|
+
// depend on the DO's single-writer execution to be right (spec 445 §3.4).
|
|
32
|
+
const wrote = sql
|
|
33
|
+
.exec(`INSERT INTO exchange_records (exchange_id, record_json, rev, updated_at)
|
|
34
|
+
VALUES (?, ?, ?, ?)
|
|
35
|
+
ON CONFLICT(exchange_id) DO NOTHING
|
|
36
|
+
RETURNING exchange_id`, record.exchangeId, JSON.stringify(record), record.rev, record.updatedAt)
|
|
25
37
|
.toArray();
|
|
26
|
-
|
|
38
|
+
if (wrote.length > 0)
|
|
39
|
+
return { inserted: true };
|
|
40
|
+
const existing = read(record.exchangeId);
|
|
41
|
+
// A conflict with no row behind it cannot happen in one isolate; throwing says so rather than
|
|
42
|
+
// reporting an insert that did not occur.
|
|
43
|
+
if (!existing)
|
|
44
|
+
throw new Error(`exchange-store: insert conflicted but ${record.exchangeId} is not readable`);
|
|
45
|
+
return { inserted: false, existing };
|
|
46
|
+
},
|
|
47
|
+
async get(exchangeId) {
|
|
48
|
+
return read(exchangeId);
|
|
27
49
|
},
|
|
28
50
|
async append(exchangeId, event) {
|
|
29
51
|
const current = await this.get(exchangeId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange-store.js","sourceRoot":"","sources":["../../src/cloudflare/exchange-store.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,kBAAkB,EAA4B,MAAM,wBAA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AAC;AACJ,CAAC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export { createDurableObjectSqlVault } from './sql-vault.js';
|
|
2
|
-
export { createDurableObjectExchangeStore, type ExchangeStore } from './exchange-store.js';
|
|
3
|
-
export { createDurableObjectInteractionStore, type InteractionStore, type SnapshotPutResult, } from './interaction-store.js';
|
|
2
|
+
export { createDurableObjectExchangeStore, type ExchangeStore, type ExchangeInsertResult } from './exchange-store.js';
|
|
3
|
+
export { createDurableObjectInteractionStore, TerminalRecordError, type InteractionStore, type SnapshotPutResult, } from './interaction-store.js';
|
|
4
4
|
export { createDurableObjectOutboxStore, type OutboxStore, type OutboxEntry } from './outbox-store.js';
|
|
5
5
|
export { createDurableObjectProvenanceStore, type ProvenanceStore } from './provenance-store.js';
|
|
6
6
|
export { createDurableObjectChannelStore, projectionAuthorizes, type ChannelStore, type ChannelV1, type ConversationRoleProjection, type ConversationRoleAction, } from './channel-store.js';
|
|
7
7
|
export { createDurableObjectAuthorityVerdictCache, VERDICT_TTL_MS, type VerdictCacheOptions, type AuthorityVerdictCache, type AuthorityVerdict, type AuthorityVerdictKey, } from './authority-verdict-cache.js';
|
|
8
8
|
export { createDurableObjectRequestIdLedger, type RequestIdLedger, type RequestIdReservation } from './request-id-ledger.js';
|
|
9
9
|
export { createDurableObjectReceiptSigner, verifyDeliveryReceipt, type DeliveryReceiptSigner, type DeliveryReceiptInput, type SignedDeliveryReceiptV1, } from './receipt-signer.js';
|
|
10
|
-
export { PrincipalGatewayDO, type PrincipalGatewayEnv, type GatewayDeps } from './principal-gateway-do.js';
|
|
10
|
+
export { PrincipalGatewayDO, GatewayAuthError, InteractionExistsError, type PrincipalGatewayEnv, type GatewayDeps, type GatewayAuthenticator, type GatewayCallerIdentity, type AuthenticatedCaller, type GatewayOrchestrationResult, type DeliveryOutcome, type DeliveryNote, } from './principal-gateway-do.js';
|
|
11
11
|
export { buildVaultTools, createToolRegistry, type GatewayTool, type GatewayToolContext, type GatewayToolRegistry, } from './gateway-tools.js';
|
|
12
|
-
export { runGatewayOrchestration, gatewayToolSpecs, bindGatewayToolInvoker } from './orchestration-runtime.js';
|
|
12
|
+
export { runGatewayOrchestration, gatewayToolSpecs, bindGatewayToolInvoker, type GatewayStepGate } from './orchestration-runtime.js';
|
|
13
13
|
export { createVaultExchangeStore, exchangeResource, EXCHANGE_INDEX_RESOURCE, type VaultExchangeStore, type ExchangeIndexV1, } from './vault-exchange-store.js';
|
|
14
14
|
export { createVaultInteractionStore, interactionResource, decisionResource, commitmentResource, snapshotResource, inboxEntryResource, INTERACTION_INDEX_RESOURCE, type VaultInteractionStore, type InteractionIndexV1, } from './vault-interaction-store.js';
|
|
15
15
|
export declare const FABRIC_CLOUDFLARE_ADAPTER_STATUS: "w2-coresident-mcp";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cloudflare/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,gCAAgC,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cloudflare/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,gCAAgC,EAAE,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAItH,OAAO,EACL,mCAAmC,EACnC,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,8BAA8B,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,kCAAkC,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EACL,+BAA+B,E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AAM,8BAA8B,CAAC;AAEtC,eAAO,MAAM,gCAAgC,EAAG,mBAA4B,CAAC"}
|
package/dist/cloudflare/index.js
CHANGED
|
@@ -10,14 +10,14 @@ export { createDurableObjectExchangeStore } from './exchange-store.js';
|
|
|
10
10
|
// The interaction spine's durable home (spec 340 W6) — interactions, context snapshots, decisions,
|
|
11
11
|
// commitments and per-viewer inbox state. Five tables, because the six machines answer to different
|
|
12
12
|
// parties at different times and one row would make them one write.
|
|
13
|
-
export { createDurableObjectInteractionStore, } from './interaction-store.js';
|
|
13
|
+
export { createDurableObjectInteractionStore, TerminalRecordError, } from './interaction-store.js';
|
|
14
14
|
export { createDurableObjectOutboxStore } from './outbox-store.js';
|
|
15
15
|
export { createDurableObjectProvenanceStore } from './provenance-store.js';
|
|
16
16
|
export { createDurableObjectChannelStore, projectionAuthorizes, } from './channel-store.js';
|
|
17
17
|
export { createDurableObjectAuthorityVerdictCache, VERDICT_TTL_MS, } from './authority-verdict-cache.js';
|
|
18
18
|
export { createDurableObjectRequestIdLedger } from './request-id-ledger.js';
|
|
19
19
|
export { createDurableObjectReceiptSigner, verifyDeliveryReceipt, } from './receipt-signer.js';
|
|
20
|
-
export { PrincipalGatewayDO } from './principal-gateway-do.js';
|
|
20
|
+
export { PrincipalGatewayDO, GatewayAuthError, InteractionExistsError, } from './principal-gateway-do.js';
|
|
21
21
|
export { buildVaultTools, createToolRegistry, } from './gateway-tools.js';
|
|
22
22
|
export { runGatewayOrchestration, gatewayToolSpecs, bindGatewayToolInvoker } from './orchestration-runtime.js';
|
|
23
23
|
export { createVaultExchangeStore, exchangeResource, EXCHANGE_INDEX_RESOURCE, } from './vault-exchange-store.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cloudflare/index.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,EAAE;AACF,wGAAwG;AACxG,wGAAwG;AACxG,yGAAyG;AACzG,yGAAyG;AACzG,4CAA4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AAgB,EAChB,kBAAkB,EAClB,0BAA0B,GAG3B,MAAM,8BAA8B,CAAC;AAEtC,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAA4B,CAAC"}
|
|
@@ -9,7 +9,33 @@ export type SnapshotPutResult = {
|
|
|
9
9
|
ok: false;
|
|
10
10
|
reason: 'digest-mismatch';
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* A `put*` was offered over a record that has already ENDED (spec 445 §3.4, audit DATB-6).
|
|
14
|
+
*
|
|
15
|
+
* THE RULE: a put creates a record or replaces one that is still live; it never replaces one in a
|
|
16
|
+
* terminal state. A concluded interaction, a refused decision and a discharged commitment are facts
|
|
17
|
+
* about how something ended, and the machines refuse every transition out of them — a put that could
|
|
18
|
+
* write `active` over `discharged` would make that refusal a convention rather than a property.
|
|
19
|
+
*
|
|
20
|
+
* Thrown, not returned: the port's `put*` return `void`, and a refusal a caller can ignore by not
|
|
21
|
+
* looking is the silent overwrite again. Re-putting the IDENTICAL record is a no-op, not an error —
|
|
22
|
+
* a replayed import says nothing new. The reducers are unaffected: a transition is only ever applied
|
|
23
|
+
* to a non-terminal record, so their own writes never meet this guard.
|
|
24
|
+
*/
|
|
25
|
+
export declare class TerminalRecordError extends Error {
|
|
26
|
+
readonly family: 'interaction' | 'decision' | 'commitment';
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly state: string;
|
|
29
|
+
readonly reason: "terminal-state";
|
|
30
|
+
constructor(family: 'interaction' | 'decision' | 'commitment', id: string, state: string);
|
|
31
|
+
}
|
|
32
|
+
/** The guard both stores share, so "terminal" cannot mean one thing over DO-SQL and another over the
|
|
33
|
+
* vault. Returns `'skip'` when the offered record is identical to the stored terminal one. */
|
|
34
|
+
export declare function guardPutOverTerminal<T>(family: 'interaction' | 'decision' | 'commitment', id: string, existing: T | null, incoming: T, stateOf: (r: T) => string): 'write' | 'skip';
|
|
12
35
|
export interface InteractionStore {
|
|
36
|
+
/** Create, or replace while still live. Throws {@link TerminalRecordError} over an ended record —
|
|
37
|
+
* the same holds for `putDecision` and `putCommitment` (spec 445 §3.4). Inbox entries have no
|
|
38
|
+
* terminal state (`deleted` is restorable), so `putInboxEntry` is not guarded. */
|
|
13
39
|
putInteraction(record: InteractionRecordV1): Promise<void>;
|
|
14
40
|
getInteraction(id: InteractionId | string): Promise<InteractionRecordV1 | null>;
|
|
15
41
|
listInteractions(): Promise<InteractionRecordV1[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interaction-store.d.ts","sourceRoot":"","sources":["../../src/cloudflare/interaction-store.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAEtG,OAAO,
|
|
1
|
+
{"version":3,"file":"interaction-store.d.ts","sourceRoot":"","sources":["../../src/cloudflare/interaction-store.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAEtG,OAAO,EAQL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AA+CjE,MAAM,MAAM,iBAAiB,GACzB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,KAAK,GAAG,WAAW,CAAA;CAAE,GACzC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAA;CAAE,CAAC;AAE7C;;;;;;;;;;;;GAYG;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YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,aAAa,CAAC,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC1F,eAAe,CACb,MAAM,EAAE,gBAAgB,EACxB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE;QAAE,UAAU,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,gBAAgB,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAC1E,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;CAChD;AAKD,wBAAgB,mCAAmC,CAAC,GAAG,EAAE,UAAU,GAAG,gBAAgB,CAkMrF"}
|
|
@@ -26,8 +26,9 @@
|
|
|
26
26
|
// authorize anything. Authority is `delegation` + `entitlements` + `tool-policy` at the moment of
|
|
27
27
|
// acting (ADR-0041, ADR-0043).
|
|
28
28
|
import { verifyContextSnapshot } from '../interaction-record.js';
|
|
29
|
-
import { applyInteractionTransition, applyDecisionTransition, applyCommitmentTransition, applyInboxTransition, } from '../interaction-machines.js';
|
|
29
|
+
import { applyInteractionTransition, applyDecisionTransition, applyCommitmentTransition, applyInboxTransition, TERMINAL_INTERACTION_STATES, TERMINAL_DECISION_STATES, TERMINAL_COMMITMENT_STATES, } from '../interaction-machines.js';
|
|
30
30
|
import { bindingKey, resolveInteractionByBinding, } from '../protocol-binding.js';
|
|
31
|
+
import { canonicalizeJson } from '@agenticprimitives/types';
|
|
31
32
|
const CREATE_TABLES = [
|
|
32
33
|
`CREATE TABLE IF NOT EXISTS interaction_records (
|
|
33
34
|
interaction_id TEXT PRIMARY KEY,
|
|
@@ -67,6 +68,47 @@ const CREATE_TABLES = [
|
|
|
67
68
|
PRIMARY KEY (viewer, exchange_id)
|
|
68
69
|
)`,
|
|
69
70
|
];
|
|
71
|
+
/**
|
|
72
|
+
* A `put*` was offered over a record that has already ENDED (spec 445 §3.4, audit DATB-6).
|
|
73
|
+
*
|
|
74
|
+
* THE RULE: a put creates a record or replaces one that is still live; it never replaces one in a
|
|
75
|
+
* terminal state. A concluded interaction, a refused decision and a discharged commitment are facts
|
|
76
|
+
* about how something ended, and the machines refuse every transition out of them — a put that could
|
|
77
|
+
* write `active` over `discharged` would make that refusal a convention rather than a property.
|
|
78
|
+
*
|
|
79
|
+
* Thrown, not returned: the port's `put*` return `void`, and a refusal a caller can ignore by not
|
|
80
|
+
* looking is the silent overwrite again. Re-putting the IDENTICAL record is a no-op, not an error —
|
|
81
|
+
* a replayed import says nothing new. The reducers are unaffected: a transition is only ever applied
|
|
82
|
+
* to a non-terminal record, so their own writes never meet this guard.
|
|
83
|
+
*/
|
|
84
|
+
export class TerminalRecordError extends Error {
|
|
85
|
+
family;
|
|
86
|
+
id;
|
|
87
|
+
state;
|
|
88
|
+
reason = 'terminal-state';
|
|
89
|
+
constructor(family, id, state) {
|
|
90
|
+
super(`interaction-store: ${family} ${id} is ${state} (terminal); a put may not replace it`);
|
|
91
|
+
this.family = family;
|
|
92
|
+
this.id = id;
|
|
93
|
+
this.state = state;
|
|
94
|
+
this.name = 'TerminalRecordError';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** The guard both stores share, so "terminal" cannot mean one thing over DO-SQL and another over the
|
|
98
|
+
* vault. Returns `'skip'` when the offered record is identical to the stored terminal one. */
|
|
99
|
+
export function guardPutOverTerminal(family, id, existing, incoming, stateOf) {
|
|
100
|
+
if (!existing)
|
|
101
|
+
return 'write';
|
|
102
|
+
const terminal = family === 'interaction' ? TERMINAL_INTERACTION_STATES
|
|
103
|
+
: family === 'decision' ? TERMINAL_DECISION_STATES
|
|
104
|
+
: TERMINAL_COMMITMENT_STATES;
|
|
105
|
+
const state = stateOf(existing);
|
|
106
|
+
if (!terminal.includes(state))
|
|
107
|
+
return 'write';
|
|
108
|
+
if (canonicalizeJson(existing) === canonicalizeJson(incoming))
|
|
109
|
+
return 'skip';
|
|
110
|
+
throw new TerminalRecordError(family, id, state);
|
|
111
|
+
}
|
|
70
112
|
/** States an obligation is still live in. `discharged`/`breached`/`void` are ended, differently. */
|
|
71
113
|
const OPEN_COMMITMENT_STATES = ['proposed', 'active', 'fulfilment-claimed'];
|
|
72
114
|
export function createDurableObjectInteractionStore(sql) {
|
|
@@ -91,6 +133,9 @@ export function createDurableObjectInteractionStore(sql) {
|
|
|
91
133
|
};
|
|
92
134
|
const store = {
|
|
93
135
|
async putInteraction(record) {
|
|
136
|
+
const existing = await this.getInteraction(record.interactionId);
|
|
137
|
+
if (guardPutOverTerminal('interaction', String(record.interactionId), existing, record, lifecycleStateOf) === 'skip')
|
|
138
|
+
return;
|
|
94
139
|
saveInteraction(record);
|
|
95
140
|
for (const b of record.protocolBindings ?? []) {
|
|
96
141
|
sql.exec(`INSERT INTO interaction_bindings (binding_key, interaction_id, binding_json) VALUES (?, ?, ?)
|
|
@@ -159,6 +204,9 @@ export function createDurableObjectInteractionStore(sql) {
|
|
|
159
204
|
return rows[0] ? JSON.parse(rows[0].snapshot_json) : null;
|
|
160
205
|
},
|
|
161
206
|
async putDecision(record) {
|
|
207
|
+
const existing = await this.getDecision(record.decisionId);
|
|
208
|
+
if (guardPutOverTerminal('decision', record.decisionId, existing, record, (r) => r.state) === 'skip')
|
|
209
|
+
return;
|
|
162
210
|
sql.exec(`INSERT INTO decision_records (decision_id, record_json, updated_at) VALUES (?, ?, ?)
|
|
163
211
|
ON CONFLICT(decision_id) DO UPDATE SET record_json = excluded.record_json, updated_at = excluded.updated_at`, record.decisionId, JSON.stringify(record), record.updatedAt);
|
|
164
212
|
},
|
|
@@ -175,6 +223,9 @@ export function createDurableObjectInteractionStore(sql) {
|
|
|
175
223
|
return result;
|
|
176
224
|
},
|
|
177
225
|
async putCommitment(record) {
|
|
226
|
+
const existing = await this.getCommitment(record.commitmentId);
|
|
227
|
+
if (guardPutOverTerminal('commitment', record.commitmentId, existing, record, (r) => r.state) === 'skip')
|
|
228
|
+
return;
|
|
178
229
|
saveCommitment(record);
|
|
179
230
|
},
|
|
180
231
|
async getCommitment(id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interaction-store.js","sourceRoot":"","sources":["../../src/cloudflare/interaction-store.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,oGAAoG;AACpG,oGAAoG;AACpG,EAAE;AACF,uGAAuG;AACvG,gGAAgG;AAChG,2FAA2F;AAC3F,EAAE;AACF,iFAAiF;AACjF,EAAE;AACF,mGAAmG;AACnG,oGAAoG;AACpG,gGAAgG;AAChG,4DAA4D;AAC5D,EAAE;AACF,oGAAoG;AACpG,kGAAkG;AAClG,oGAAoG;AACpG,mGAAmG;AACnG,6FAA6F;AAC7F,4DAA4D;AAC5D,iGAAiG;AACjG,mFAAmF;AACnF,EAAE;AACF,oGAAoG;AACpG,kGAAkG;AAClG,+BAA+B;AAG/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,yBAAyB,EACzB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"interaction-store.js","sourceRoot":"","sources":["../../src/cloudflare/interaction-store.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,oGAAoG;AACpG,oGAAoG;AACpG,EAAE;AACF,uGAAuG;AACvG,gGAAgG;AAChG,2FAA2F;AAC3F,EAAE;AACF,iFAAiF;AACjF,EAAE;AACF,mGAAmG;AACnG,oGAAoG;AACpG,gGAAgG;AAChG,4DAA4D;AAC5D,EAAE;AACF,oGAAoG;AACpG,kGAAkG;AAClG,oGAAoG;AACpG,mGAAmG;AACnG,6FAA6F;AAC7F,4DAA4D;AAC5D,iGAAiG;AACjG,mFAAmF;AACnF,EAAE;AACF,oGAAoG;AACpG,kGAAkG;AAClG,+BAA+B;AAG/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,0BAA0B,EAC1B,uB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AC;QAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,MAA2B;IACnD,OAAO,MAAM,CAAC,cAAc,CAAC;AAC/B,CAAC"}
|
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
import type { Vault } from '@agenticprimitives/vault';
|
|
2
2
|
import { type Intent, type Planner, type RunResult, type ToolInvoker, type ToolSpec } from '@agenticprimitives/orchestration';
|
|
3
|
-
import type { GatewayToolRegistry } from './gateway-tools.js';
|
|
3
|
+
import type { GatewayTool, GatewayToolRegistry } from './gateway-tools.js';
|
|
4
4
|
/** The co-resident tools as the planner's tool catalog (id + description; the plan may only reference these). */
|
|
5
5
|
export declare function gatewayToolSpecs(registry: GatewayToolRegistry): ToolSpec[];
|
|
6
|
+
/**
|
|
7
|
+
* The per-step gate (spec 445 §3.4, audit DATA-4). Called for EVERY planned step, with the concrete tool
|
|
8
|
+
* and the resolved arguments, BEFORE the tool runs; it throws to refuse. REQUIRED — the planner's input
|
|
9
|
+
* is by design a peer's text, so a step is authorized where it is used, never by having been planned.
|
|
10
|
+
* `PrincipalGatewayDO.orchestrate` supplies the §3a gate here (caveat pass B per step, request id for a
|
|
11
|
+
* write); a caller with no gate to offer has no business binding vault tools to a planner.
|
|
12
|
+
*/
|
|
13
|
+
export type GatewayStepGate = (tool: GatewayTool, args: Record<string, unknown>) => Promise<void>;
|
|
6
14
|
/** Bind the co-resident tool registry as an orchestration `ToolInvoker`: each planned step dispatches to a
|
|
7
|
-
* DO tool, run over `vault` under `principal
|
|
8
|
-
* the tool catalog too, but this is the last line). */
|
|
15
|
+
* DO tool, run over `vault` under `principal` — after `authorizeStep` has passed it. Fail-closed on an
|
|
16
|
+
* unknown tool (the plan is validated against the tool catalog too, but this is the last line). */
|
|
9
17
|
export declare function bindGatewayToolInvoker(opts: {
|
|
10
18
|
registry: GatewayToolRegistry;
|
|
11
19
|
vault: Vault;
|
|
12
20
|
principal: string;
|
|
21
|
+
authorizeStep: GatewayStepGate;
|
|
13
22
|
}): ToolInvoker;
|
|
14
23
|
/**
|
|
15
24
|
* Run a T2 intent to completion over the co-resident tools. `planner` is injected (LLM adapter in prod, the
|
|
16
|
-
* deterministic rule-based planner in tests). The loop is bounded (`maxSteps`)
|
|
17
|
-
*
|
|
25
|
+
* deterministic rule-based planner in tests). The loop is bounded (`maxSteps`). The loop itself decides no
|
|
26
|
+
* authority — `principal` is the VERIFIED verdict's principal and every step passes `authorizeStep`
|
|
27
|
+
* (ADR-0041; spec 445 §3.4). `tools` narrows the catalog the planner is shown (e.g. read tools only when
|
|
28
|
+
* the run carries no request id); the invoker's gate still stands behind it. Returns the orchestration
|
|
18
29
|
* `RunResult` (outcome + observations + composed result) the DO records onto the exchange stream.
|
|
19
30
|
*/
|
|
20
31
|
export declare function runGatewayOrchestration(intent: Intent, opts: {
|
|
@@ -22,6 +33,9 @@ export declare function runGatewayOrchestration(intent: Intent, opts: {
|
|
|
22
33
|
registry: GatewayToolRegistry;
|
|
23
34
|
vault: Vault;
|
|
24
35
|
principal: string;
|
|
36
|
+
authorizeStep: GatewayStepGate;
|
|
37
|
+
/** The subset of the registry offered to the planner. Default: all of it. */
|
|
38
|
+
tools?: ToolSpec[];
|
|
25
39
|
maxSteps?: number;
|
|
26
40
|
maxReplans?: number;
|
|
27
41
|
}): Promise<RunResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestration-runtime.d.ts","sourceRoot":"","sources":["../../src/cloudflare/orchestration-runtime.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAa,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC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,CAAC;CACrB,GACA,OAAO,CAAC,SAAS,CAAC,CAQpB"}
|
|
@@ -7,27 +7,32 @@ export function gatewayToolSpecs(registry) {
|
|
|
7
7
|
}));
|
|
8
8
|
}
|
|
9
9
|
/** Bind the co-resident tool registry as an orchestration `ToolInvoker`: each planned step dispatches to a
|
|
10
|
-
* DO tool, run over `vault` under `principal
|
|
11
|
-
* the tool catalog too, but this is the last line). */
|
|
10
|
+
* DO tool, run over `vault` under `principal` — after `authorizeStep` has passed it. Fail-closed on an
|
|
11
|
+
* unknown tool (the plan is validated against the tool catalog too, but this is the last line). */
|
|
12
12
|
export function bindGatewayToolInvoker(opts) {
|
|
13
|
+
if (typeof opts.authorizeStep !== 'function')
|
|
14
|
+
throw new Error('orchestration: authorizeStep is required (no gate ⇒ no tools)');
|
|
13
15
|
return async (toolId, args) => {
|
|
14
16
|
const tool = opts.registry.get(toolId);
|
|
15
17
|
if (!tool)
|
|
16
18
|
throw new Error(`orchestration: unknown tool ${toolId}`);
|
|
19
|
+
await opts.authorizeStep(tool, args);
|
|
17
20
|
return tool.run({ principal: opts.principal, vault: opts.vault, args });
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Run a T2 intent to completion over the co-resident tools. `planner` is injected (LLM adapter in prod, the
|
|
22
|
-
* deterministic rule-based planner in tests). The loop is bounded (`maxSteps`)
|
|
23
|
-
*
|
|
25
|
+
* deterministic rule-based planner in tests). The loop is bounded (`maxSteps`). The loop itself decides no
|
|
26
|
+
* authority — `principal` is the VERIFIED verdict's principal and every step passes `authorizeStep`
|
|
27
|
+
* (ADR-0041; spec 445 §3.4). `tools` narrows the catalog the planner is shown (e.g. read tools only when
|
|
28
|
+
* the run carries no request id); the invoker's gate still stands behind it. Returns the orchestration
|
|
24
29
|
* `RunResult` (outcome + observations + composed result) the DO records onto the exchange stream.
|
|
25
30
|
*/
|
|
26
31
|
export function runGatewayOrchestration(intent, opts) {
|
|
27
32
|
return runIntent(intent, {
|
|
28
33
|
planner: opts.planner,
|
|
29
|
-
tools: gatewayToolSpecs(opts.registry),
|
|
30
|
-
invoke: bindGatewayToolInvoker({ registry: opts.registry, vault: opts.vault, principal: opts.principal }),
|
|
34
|
+
tools: opts.tools ?? gatewayToolSpecs(opts.registry),
|
|
35
|
+
invoke: bindGatewayToolInvoker({ registry: opts.registry, vault: opts.vault, principal: opts.principal, authorizeStep: opts.authorizeStep }),
|
|
31
36
|
maxSteps: opts.maxSteps,
|
|
32
37
|
maxReplans: opts.maxReplans,
|
|
33
38
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestration-runtime.js","sourceRoot":"","sources":["../../src/cloudflare/orchestration-runtime.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAA8E,MAAM,kCAAkC,CAAC;AAGzI,iHAAiH;AACjH,MAAM,UAAU,gBAAgB,CAAC,QAA6B;IAC5D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACjC,EAAE,EAAE,CAAC,CAAC,IAAI;QACV,WAAW,EAAE,GAAG,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,2BAA2B,CAAC,CAAC,IAAI,GAAG;KAC3F,CAAC,CAAC,CAAC;AACN,CAAC;
|
|
1
|
+
{"version":3,"file":"orchestration-runtime.js","sourceRoot":"","sources":["../../src/cloudflare/orchestration-runtime.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAA8E,MAAM,kCAAkC,CAAC;AAGzI,iHAAiH;AACjH,MAAM,UAAU,gBAAgB,CAAC,QAA6B;IAC5D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACjC,EAAE,EAAE,CAAC,CAAC,IAAI;QACV,WAAW,EAAE,GAAG,CAAC,CAAC,MAA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