@agenticprimitives/fabric 0.0.0-alpha.4 → 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.
Files changed (198) hide show
  1. package/CLAUDE.md +28 -35
  2. package/README.md +18 -16
  3. package/dist/adoption.d.ts +79 -0
  4. package/dist/adoption.d.ts.map +1 -0
  5. package/dist/adoption.js +95 -0
  6. package/dist/adoption.js.map +1 -0
  7. package/dist/case-emissions.d.ts +95 -0
  8. package/dist/case-emissions.d.ts.map +1 -0
  9. package/dist/case-emissions.js +208 -0
  10. package/dist/case-emissions.js.map +1 -0
  11. package/dist/case-machine.d.ts +28 -2
  12. package/dist/case-machine.d.ts.map +1 -1
  13. package/dist/case-machine.js +34 -7
  14. package/dist/case-machine.js.map +1 -1
  15. package/dist/cloudflare/authority-verdict-cache.d.ts +28 -1
  16. package/dist/cloudflare/authority-verdict-cache.d.ts.map +1 -1
  17. package/dist/cloudflare/authority-verdict-cache.js +32 -1
  18. package/dist/cloudflare/authority-verdict-cache.js.map +1 -1
  19. package/dist/cloudflare/exchange-store.d.ts +20 -1
  20. package/dist/cloudflare/exchange-store.d.ts.map +1 -1
  21. package/dist/cloudflare/exchange-store.js +26 -4
  22. package/dist/cloudflare/exchange-store.js.map +1 -1
  23. package/dist/cloudflare/index.d.ts +7 -4
  24. package/dist/cloudflare/index.d.ts.map +1 -1
  25. package/dist/cloudflare/index.js +8 -2
  26. package/dist/cloudflare/index.js.map +1 -1
  27. package/dist/cloudflare/interaction-store.d.ts +81 -0
  28. package/dist/cloudflare/interaction-store.d.ts.map +1 -0
  29. package/dist/cloudflare/interaction-store.js +281 -0
  30. package/dist/cloudflare/interaction-store.js.map +1 -0
  31. package/dist/cloudflare/orchestration-runtime.d.ts +19 -5
  32. package/dist/cloudflare/orchestration-runtime.d.ts.map +1 -1
  33. package/dist/cloudflare/orchestration-runtime.js +11 -6
  34. package/dist/cloudflare/orchestration-runtime.js.map +1 -1
  35. package/dist/cloudflare/principal-gateway-do.d.ts +360 -30
  36. package/dist/cloudflare/principal-gateway-do.d.ts.map +1 -1
  37. package/dist/cloudflare/principal-gateway-do.js +580 -58
  38. package/dist/cloudflare/principal-gateway-do.js.map +1 -1
  39. package/dist/cloudflare/receipt-signer.d.ts.map +1 -1
  40. package/dist/cloudflare/receipt-signer.js +6 -3
  41. package/dist/cloudflare/receipt-signer.js.map +1 -1
  42. package/dist/cloudflare/sql-vault.d.ts.map +1 -1
  43. package/dist/cloudflare/sql-vault.js +56 -0
  44. package/dist/cloudflare/sql-vault.js.map +1 -1
  45. package/dist/cloudflare/vault-exchange-store.d.ts +47 -0
  46. package/dist/cloudflare/vault-exchange-store.d.ts.map +1 -0
  47. package/dist/cloudflare/vault-exchange-store.js +135 -0
  48. package/dist/cloudflare/vault-exchange-store.js.map +1 -0
  49. package/dist/cloudflare/vault-interaction-store.d.ts +44 -0
  50. package/dist/cloudflare/vault-interaction-store.d.ts.map +1 -0
  51. package/dist/cloudflare/vault-interaction-store.js +259 -0
  52. package/dist/cloudflare/vault-interaction-store.js.map +1 -0
  53. package/dist/communicative-act.d.ts +24 -1
  54. package/dist/communicative-act.d.ts.map +1 -1
  55. package/dist/communicative-act.js +28 -0
  56. package/dist/communicative-act.js.map +1 -1
  57. package/dist/delivery-envelope.d.ts.map +1 -1
  58. package/dist/delivery-envelope.js +0 -1
  59. package/dist/delivery-envelope.js.map +1 -1
  60. package/dist/email/index.d.ts +79 -0
  61. package/dist/email/index.d.ts.map +1 -0
  62. package/dist/email/index.js +91 -0
  63. package/dist/email/index.js.map +1 -0
  64. package/dist/enum-retirement.d.ts +43 -0
  65. package/dist/enum-retirement.d.ts.map +1 -0
  66. package/dist/enum-retirement.js +93 -0
  67. package/dist/enum-retirement.js.map +1 -0
  68. package/dist/exchange-record.d.ts +35 -4
  69. package/dist/exchange-record.d.ts.map +1 -1
  70. package/dist/exchange-record.js.map +1 -1
  71. package/dist/exchange-reducer.d.ts +32 -4
  72. package/dist/exchange-reducer.d.ts.map +1 -1
  73. package/dist/exchange-reducer.js +75 -1
  74. package/dist/exchange-reducer.js.map +1 -1
  75. package/dist/exchange-state.d.ts +30 -8
  76. package/dist/exchange-state.d.ts.map +1 -1
  77. package/dist/exchange-state.js +12 -10
  78. package/dist/exchange-state.js.map +1 -1
  79. package/dist/inbox-doc.d.ts +2 -2
  80. package/dist/inbox-doc.d.ts.map +1 -1
  81. package/dist/inbox-doc.js.map +1 -1
  82. package/dist/inbox-projection.d.ts +2 -2
  83. package/dist/inbox-projection.d.ts.map +1 -1
  84. package/dist/inbox-projection.js.map +1 -1
  85. package/dist/inbox-revision.d.ts +42 -0
  86. package/dist/inbox-revision.d.ts.map +1 -0
  87. package/dist/inbox-revision.js +57 -0
  88. package/dist/inbox-revision.js.map +1 -0
  89. package/dist/index.d.ts +26 -3
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +40 -2
  92. package/dist/index.js.map +1 -1
  93. package/dist/interaction-machines.d.ts +136 -0
  94. package/dist/interaction-machines.d.ts.map +1 -0
  95. package/dist/interaction-machines.js +174 -0
  96. package/dist/interaction-machines.js.map +1 -0
  97. package/dist/interaction-profile.d.ts +136 -0
  98. package/dist/interaction-profile.d.ts.map +1 -0
  99. package/dist/interaction-profile.js +212 -0
  100. package/dist/interaction-profile.js.map +1 -0
  101. package/dist/interaction-record.d.ts +168 -0
  102. package/dist/interaction-record.d.ts.map +1 -0
  103. package/dist/interaction-record.js +108 -0
  104. package/dist/interaction-record.js.map +1 -0
  105. package/dist/interactions/grant-scopes.d.ts +21 -0
  106. package/dist/interactions/grant-scopes.d.ts.map +1 -0
  107. package/dist/interactions/grant-scopes.js +88 -0
  108. package/dist/interactions/grant-scopes.js.map +1 -0
  109. package/dist/interactions/index.d.ts +1 -0
  110. package/dist/interactions/index.d.ts.map +1 -1
  111. package/dist/interactions/index.js +3 -0
  112. package/dist/interactions/index.js.map +1 -1
  113. package/dist/interactions/machine.d.ts +2 -2
  114. package/dist/interactions/machine.d.ts.map +1 -1
  115. package/dist/interactions/machine.js +2 -2
  116. package/dist/interactions/machine.js.map +1 -1
  117. package/dist/interactions/open-case.d.ts +60 -0
  118. package/dist/interactions/open-case.d.ts.map +1 -0
  119. package/dist/interactions/open-case.js +83 -0
  120. package/dist/interactions/open-case.js.map +1 -0
  121. package/dist/interactions/store.d.ts +9 -0
  122. package/dist/interactions/store.d.ts.map +1 -1
  123. package/dist/interactions/store.js +57 -2
  124. package/dist/interactions/store.js.map +1 -1
  125. package/dist/messaging/board.d.ts +4 -4
  126. package/dist/messaging/board.d.ts.map +1 -1
  127. package/dist/messaging/board.js +2 -2
  128. package/dist/messaging/board.js.map +1 -1
  129. package/dist/messaging/consult-routing.d.ts +103 -23
  130. package/dist/messaging/consult-routing.d.ts.map +1 -1
  131. package/dist/messaging/consult-routing.js +157 -47
  132. package/dist/messaging/consult-routing.js.map +1 -1
  133. package/dist/messaging/consult.d.ts +4 -0
  134. package/dist/messaging/consult.d.ts.map +1 -1
  135. package/dist/messaging/consult.js +3 -1
  136. package/dist/messaging/consult.js.map +1 -1
  137. package/dist/messaging/conversation-interaction.d.ts +66 -0
  138. package/dist/messaging/conversation-interaction.d.ts.map +1 -0
  139. package/dist/messaging/conversation-interaction.js +139 -0
  140. package/dist/messaging/conversation-interaction.js.map +1 -0
  141. package/dist/messaging/conversation.d.ts +69 -1
  142. package/dist/messaging/conversation.d.ts.map +1 -1
  143. package/dist/messaging/conversation.js +131 -0
  144. package/dist/messaging/conversation.js.map +1 -1
  145. package/dist/messaging/delivery.d.ts +2 -2
  146. package/dist/messaging/delivery.d.ts.map +1 -1
  147. package/dist/messaging/delivery.js +8 -1
  148. package/dist/messaging/delivery.js.map +1 -1
  149. package/dist/messaging/envelope.d.ts +7 -3
  150. package/dist/messaging/envelope.d.ts.map +1 -1
  151. package/dist/messaging/envelope.js +18 -1
  152. package/dist/messaging/envelope.js.map +1 -1
  153. package/dist/messaging/hash.d.ts +8 -2
  154. package/dist/messaging/hash.d.ts.map +1 -1
  155. package/dist/messaging/hash.js +6 -0
  156. package/dist/messaging/hash.js.map +1 -1
  157. package/dist/messaging/inbox-assistant.d.ts +16 -4
  158. package/dist/messaging/inbox-assistant.d.ts.map +1 -1
  159. package/dist/messaging/inbox-assistant.js +27 -4
  160. package/dist/messaging/inbox-assistant.js.map +1 -1
  161. package/dist/messaging/index.d.ts +7 -3
  162. package/dist/messaging/index.d.ts.map +1 -1
  163. package/dist/messaging/index.js +11 -2
  164. package/dist/messaging/index.js.map +1 -1
  165. package/dist/messaging/outbound-message.d.ts +42 -0
  166. package/dist/messaging/outbound-message.d.ts.map +1 -0
  167. package/dist/messaging/outbound-message.js +64 -0
  168. package/dist/messaging/outbound-message.js.map +1 -0
  169. package/dist/messaging/projector.d.ts +3 -3
  170. package/dist/messaging/projector.d.ts.map +1 -1
  171. package/dist/messaging/projector.js.map +1 -1
  172. package/dist/messaging/receipts.d.ts +3 -3
  173. package/dist/messaging/receipts.d.ts.map +1 -1
  174. package/dist/messaging/receipts.js.map +1 -1
  175. package/dist/messaging/rules.d.ts +10 -3
  176. package/dist/messaging/rules.d.ts.map +1 -1
  177. package/dist/messaging/rules.js +8 -1
  178. package/dist/messaging/rules.js.map +1 -1
  179. package/dist/messaging/store.d.ts +4 -4
  180. package/dist/messaging/store.d.ts.map +1 -1
  181. package/dist/messaging/store.js +5 -3
  182. package/dist/messaging/store.js.map +1 -1
  183. package/dist/messaging/types.d.ts +30 -0
  184. package/dist/messaging/types.d.ts.map +1 -1
  185. package/dist/messaging/types.js +3 -0
  186. package/dist/messaging/types.js.map +1 -1
  187. package/dist/messaging/vault-store.d.ts +2 -2
  188. package/dist/messaging/vault-store.d.ts.map +1 -1
  189. package/dist/messaging/vault-store.js +8 -0
  190. package/dist/messaging/vault-store.js.map +1 -1
  191. package/dist/protocol-binding.d.ts +71 -0
  192. package/dist/protocol-binding.d.ts.map +1 -0
  193. package/dist/protocol-binding.js +0 -0
  194. package/dist/protocol-binding.js.map +1 -0
  195. package/dist/record-catalog.d.ts.map +1 -1
  196. package/dist/record-catalog.js +12 -0
  197. package/dist/record-catalog.js.map +1 -1
  198. package/package.json +28 -15
@@ -52,9 +52,19 @@ export interface CaseTransitionEventV1 {
52
52
  authorityRef?: AuthorityRef;
53
53
  signature?: SignatureProof;
54
54
  }
55
+ /** W10b-3: `denied`/`expired`/`revoked` collapsed into `closed` — same terminality, and the verdict
56
+ * that distinguished them now lives in the decision and commitment records. */
55
57
  export declare const TERMINAL_CASE_STATES: readonly CaseState[];
56
58
  export declare function isTerminalCaseState(state: CaseState): boolean;
57
- export type CaseRejection = 'wrong-case' | 'invalid-transition' | 'unauthorized-actor' | 'case-expired' | 'not-yet-due';
59
+ /** The transitions that cannot land on the case machine alone. Exported so the set is a constant a
60
+ * caller can read rather than a rule buried in a branch. */
61
+ export declare const TRANSITIONS_REQUIRING_GRANTED_DECISION: readonly CaseTransition[];
62
+ export declare function requiresGrantedDecision(transition: CaseTransition): boolean;
63
+ export type CaseRejection = 'wrong-case' | 'invalid-transition' | 'unauthorized-actor' | 'case-expired' | 'not-yet-due'
64
+ /** W10b-3: the transition needs a granted decision and none was supplied. Its own reason rather than
65
+ * `invalid-transition`, because the case IS in a legal state — what is missing is the determination,
66
+ * and a caller that cannot tell those apart will "fix" the wrong one. */
67
+ | 'requires-granted-decision';
58
68
  export type CaseResult = {
59
69
  ok: true;
60
70
  case: FabricCaseV1;
@@ -62,11 +72,27 @@ export type CaseResult = {
62
72
  ok: false;
63
73
  reason: CaseRejection;
64
74
  };
75
+ /**
76
+ * What this machine cannot know on its own (spec 340 W10b-3).
77
+ *
78
+ * Until W10b-3, "you cannot issue before approving" was an FSM edge: `issue-credential` ran only
79
+ * `from: ['approved']`. With the determination moved to the decision machine, `triaged` is reachable by
80
+ * plain triage, so that ordering has to be re-established as a precondition or issuance could skip the
81
+ * determination entirely.
82
+ *
83
+ * Passed IN rather than looked up: this module is pure and has no store. The caller that holds the
84
+ * decision supplies it, and supplying nothing is a refusal, not a pass — a machine that treated
85
+ * "no decision provided" as "no decision required" would be exactly the fail-open this repo forbids.
86
+ */
87
+ export interface CaseTransitionContext {
88
+ /** The state of the decision for this case, or `null`/absent when there is none. */
89
+ decisionState?: 'pending' | 'granted' | 'refused' | 'withdrawn' | 'expired' | 'superseded' | null;
90
+ }
65
91
  /**
66
92
  * Pure, fail-closed (spec 316 §2). Generic over the concrete case type: preserves whatever extra fields
67
93
  * `T` carries beyond `CaseFsmFields`. Returns the next case or a typed rejection — never a silent no-op.
68
94
  */
69
- export declare function applyCaseTransition<T extends CaseFsmFields>(current: T, event: CaseTransitionEventV1): {
95
+ export declare function applyCaseTransition<T extends CaseFsmFields>(current: T, event: CaseTransitionEventV1, ctx?: CaseTransitionContext): {
70
96
  ok: true;
71
97
  case: T;
72
98
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"case-machine.d.ts","sourceRoot":"","sources":["../src/case-machine.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;uEACuE;AACvE,MAAM,WAAW,aAAa;IAC5B;;4DAEwD;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,SAAS,EAAE,gBAAgB,CAAC;IAC5B,aAAa,CAAC,EAAE,gBAAgB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;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,mBAAmB,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAE7D;AA2CD;6DAC6D;AAC7D,eAAO,MAAM,sCAAsC,EAAE,SAAS,cAAc,EAAyB,CAAC;AAEtG,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO,CAE3E;AAED,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,oBAAoB,GACpB,oBAAoB,GACpB,cAAc,GACd,aAAa;AACf;;0EAE0E;GACxE,2BAA2B,CAAC;AAEhC,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC;AAcjG;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,qBAAqB;IACpC,oFAAoF;IACpF,aAAa,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,YAAY,GAAG,IAAI,CAAC;CACnG;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,aAAa,EACzD,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,qBAAqB,EAC5B,GAAG,GAAE,qBAA0B,GAC9B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAgC9D"}
@@ -14,10 +14,24 @@
14
14
  // are inbox read-receipt facts. So `admit`(submitted→delivered)/`view`(delivered→seen) are DROPPED (they
15
15
  // become `ExchangeEventV1` `kind:'message'` events), and the moves that referenced `seen`/`delivered`
16
16
  // re-anchor on `submitted`/`triaged`.
17
- export const TERMINAL_CASE_STATES = ['denied', 'completed', 'expired', 'revoked', 'failed'];
17
+ /** W10b-3: `denied`/`expired`/`revoked` collapsed into `closed` — same terminality, and the verdict
18
+ * that distinguished them now lives in the decision and commitment records. */
19
+ export const TERMINAL_CASE_STATES = ['completed', 'closed', 'failed'];
18
20
  export function isTerminalCaseState(state) {
19
21
  return TERMINAL_CASE_STATES.includes(state);
20
22
  }
23
+ /**
24
+ * spec 340 W10b-3. The VERBS are unchanged — that is deliberate and load-bearing. A stored v1 case-event
25
+ * log names transitions, not states, so keeping every verb is what lets history replay with no
26
+ * migration (W10b-1). What changed is where four of them LAND, because `approved`/`denied`/`expired`/
27
+ * `revoked` were never execution states (§R.2):
28
+ *
29
+ * · `approve` now lands on `triaged` — the responder is working toward issuance. The DETERMINATION
30
+ * goes to the decision machine via `caseTransitionEmissions`. "Approved" was never a description
31
+ * of how far the work got; reading it as one is the "deciding is not doing" collapse.
32
+ * · `deny`/`expire`/`revoke` land on `closed` — taken up, ended without issuance. The verdict is in
33
+ * the decision record; the voided obligation is in the commitment record.
34
+ */
21
35
  const TRANSITIONS = {
22
36
  submit: { from: ['draft'], to: 'submitted', signers: ['requester'] },
23
37
  triage: { from: ['submitted'], to: 'triaged', signers: ['responder'] },
@@ -25,14 +39,24 @@ const TRANSITIONS = {
25
39
  // needs-info → triaged (NOT submitted): the requester supplied info, the responder RESUMES working
26
40
  // (couples to exec `working`), preserving the "responder engaged" phase across the info loop.
27
41
  'submit-info': { from: ['needs-info'], to: 'triaged', signers: ['requester'] },
28
- approve: { from: ['submitted', 'triaged'], to: 'approved', signers: ['responder', 'resource-owner'] },
29
- 'issue-credential': { from: ['approved'], to: 'issued', signers: ['resource-owner', 'responder'] },
42
+ approve: { from: ['submitted', 'triaged'], to: 'triaged', signers: ['responder', 'resource-owner'] },
43
+ // `from: ['triaged']` plus a REQUIRED granted decision — see `requiresGrantedDecision`. The ordering
44
+ // "you cannot issue before approving" used to be an FSM edge (`from: ['approved']`); with the
45
+ // decision out of this enum it becomes a cross-machine precondition instead, because `triaged` is
46
+ // reachable by plain triage and would otherwise let issuance skip the determination entirely.
47
+ 'issue-credential': { from: ['triaged'], to: 'issued', signers: ['resource-owner', 'responder'] },
30
48
  'deliver-credential': { from: ['issued'], to: 'completed', signers: ['resource-owner', 'responder'] },
31
- deny: { from: 'any-non-terminal', to: 'denied', signers: ['responder', 'resource-owner'] },
32
- expire: { from: 'any-non-terminal', to: 'expired', signers: ['any'] },
33
- revoke: { from: 'any-non-terminal', to: 'revoked', signers: ['responder', 'resource-owner'] },
49
+ deny: { from: 'any-non-terminal', to: 'closed', signers: ['responder', 'resource-owner'] },
50
+ expire: { from: 'any-non-terminal', to: 'closed', signers: ['any'] },
51
+ revoke: { from: 'any-non-terminal', to: 'closed', signers: ['responder', 'resource-owner'] },
34
52
  fail: { from: 'any-non-terminal', to: 'failed', signers: ['any'] },
35
53
  };
54
+ /** The transitions that cannot land on the case machine alone. Exported so the set is a constant a
55
+ * caller can read rather than a rule buried in a branch. */
56
+ export const TRANSITIONS_REQUIRING_GRANTED_DECISION = ['issue-credential'];
57
+ export function requiresGrantedDecision(transition) {
58
+ return TRANSITIONS_REQUIRING_GRANTED_DECISION.includes(transition);
59
+ }
36
60
  function actorRoles(c, actor) {
37
61
  const roles = new Set(['any']);
38
62
  if (actor === c.requester)
@@ -50,7 +74,7 @@ function isPastExpiry(c, atIso) {
50
74
  * Pure, fail-closed (spec 316 §2). Generic over the concrete case type: preserves whatever extra fields
51
75
  * `T` carries beyond `CaseFsmFields`. Returns the next case or a typed rejection — never a silent no-op.
52
76
  */
53
- export function applyCaseTransition(current, event) {
77
+ export function applyCaseTransition(current, event, ctx = {}) {
54
78
  if (event.caseId !== current.id)
55
79
  return { ok: false, reason: 'wrong-case' };
56
80
  const spec = TRANSITIONS[event.transition];
@@ -59,6 +83,9 @@ export function applyCaseTransition(current, event) {
59
83
  const fromOk = spec.from === 'any-non-terminal' ? !isTerminalCaseState(current.state) : spec.from.includes(current.state);
60
84
  if (!fromOk)
61
85
  return { ok: false, reason: 'invalid-transition' };
86
+ if (requiresGrantedDecision(event.transition) && ctx.decisionState !== 'granted') {
87
+ return { ok: false, reason: 'requires-granted-decision' };
88
+ }
62
89
  // `expire` only lands once the deadline passed; everything else (except `fail`) rejects on an expired case.
63
90
  if (event.transition === 'expire') {
64
91
  if (current.expiresAt === undefined || !isPastExpiry(current, event.at))
@@ -1 +1 @@
1
- {"version":3,"file":"case-machine.js","sourceRoot":"","sources":["../src/case-machine.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,wGAAwG;AACxG,kCAAkC;AAClC,+GAA+G;AAC/G,4EAA4E;AAC5E,sGAAsG;AACtG,8BAA8B;AAC9B,EAAE;AACF,4GAA4G;AAC5G,6GAA6G;AAC7G,2FAA2F;AAC3F,EAAE;AACF,2GAA2G;AAC3G,yGAAyG;AACzG,sGAAsG;AACtG,sCAAsC;AAwEtC,MAAM,CAAC,MAAM,oBAAoB,GAAyB,CAAC,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAElH,MAAM,UAAU,mBAAmB,CAAC,KAAgB;IAClD,OAAO,oBAAoB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC;AAWD,MAAM,WAAW,GAA2C;IAC1D,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE;IACpE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE;IACtE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE;IACxF,mGAAmG;IACnG,8FAA8F;IAC9F,aAAa,EAAE,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,CA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,IAAI,EAAE,CAAC;AAClC,CAAC"}
@@ -23,5 +23,32 @@ export interface AuthorityVerdictCache {
23
23
  /** Deployment-epoch change (spec 311): drop every verdict NOT on `currentEpoch`. */
24
24
  sweepEpoch(currentEpoch: string): Promise<void>;
25
25
  }
26
- export declare function createDurableObjectAuthorityVerdictCache(sql: SqlStorage): AuthorityVerdictCache;
26
+ /**
27
+ * How long a cached verdict may be reused before the cold path must run again.
28
+ *
29
+ * 60s mirrors `InteractionsDO`'s existing positive-verdict cache (NEW-H4/FAB-A2A-1), which was sized as
30
+ * an RPC-429 mitigation for high-frequency non-sensitive reads. Matching it keeps ONE number in the
31
+ * deployment rather than two that drift.
32
+ */
33
+ export declare const VERDICT_TTL_MS = 60000;
34
+ export interface VerdictCacheOptions {
35
+ /** Bounded reuse window. `0` disables caching entirely (every get misses ⇒ cold path every call). */
36
+ ttlMs?: number;
37
+ now?: () => number;
38
+ }
39
+ /**
40
+ * BOUNDED REUSE IS PART OF THE VERDICT, NOT AN OPTIMISATION KNOB.
41
+ *
42
+ * Verdict (A) asserts "this delegation was valid AND UNREVOKED at `verifiedAt`". Serving it later without
43
+ * regard to age silently upgrades that into "is valid and unrevoked", which is a claim the cold path never
44
+ * made. Before this, `verified_at` was written and never read: a verdict cached once stayed warm forever,
45
+ * and a revoked delegation kept passing (A) until something called `invalidateDelegation` — a revocation
46
+ * NOTICE that has to be delivered by a second mechanism and may simply never arrive. Revocation that only
47
+ * works when someone remembers to push it is not revocation.
48
+ *
49
+ * Expiry is a MISS, not an error: `invokeFast` refuses on a miss and the caller re-runs `verifyAndCache`,
50
+ * which re-checks the signature and `isRevoked` on-chain. So the ceiling on serving a revoked delegation
51
+ * is `ttlMs`, and the mechanism is the same one throughout (ADR-0013) — the cold path, run again.
52
+ */
53
+ export declare function createDurableObjectAuthorityVerdictCache(sql: SqlStorage, opts?: VerdictCacheOptions): AuthorityVerdictCache;
27
54
  //# sourceMappingURL=authority-verdict-cache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authority-verdict-cache.d.ts","sourceRoot":"","sources":["../../src/cloudflare/authority-verdict-cache.ts"],"names":[],"mappings":"AA6BA;4GAC4G;AAC5G,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,kGAAkG;IAClG,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,YAAY,GAAG,gBAAgB,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;AAYhH,MAAM,WAAW,qBAAqB;IACpC,yDAAyD;IACzD,GAAG,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C;mGAC+F;IAC/F,GAAG,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAChE,uFAAuF;IACvF,oBAAoB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,oFAAoF;IACpF,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAKD,wBAAgB,wCAAwC,CAAC,GAAG,EAAE,UAAU,GAAG,qBAAqB,CA6C/F"}
1
+ {"version":3,"file":"authority-verdict-cache.d.ts","sourceRoot":"","sources":["../../src/cloudflare/authority-verdict-cache.ts"],"names":[],"mappings":"AA6BA;4GAC4G;AAC5G,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,kGAAkG;IAClG,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,gBAAgB,EAAE,YAAY,GAAG,gBAAgB,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;AAYhH,MAAM,WAAW,qBAAqB;IACpC,yDAAyD;IACzD,GAAG,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C;mGAC+F;IAC/F,GAAG,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAChE,uFAAuF;IACvF,oBAAoB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,oFAAoF;IACpF,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAKD;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,QAAS,CAAC;AAErC,MAAM,WAAW,mBAAmB;IAClC,qGAAqG;IACrG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wCAAwC,CACtD,GAAG,EAAE,UAAU,EACf,IAAI,CAAC,EAAE,mBAAmB,GACzB,qBAAqB,CAsDvB"}
@@ -26,10 +26,34 @@ const CREATE_TABLE = `CREATE TABLE IF NOT EXISTS authority_verdicts (
26
26
  const CREATE_IDX_DELEG = `CREATE INDEX IF NOT EXISTS idx_authority_verdicts_deleg ON authority_verdicts (delegation_hash)`;
27
27
  const CREATE_IDX_EPOCH = `CREATE INDEX IF NOT EXISTS idx_authority_verdicts_epoch ON authority_verdicts (epoch)`;
28
28
  const keyOf = (k) => `${k.sessionKey.toLowerCase()}|${k.delegationHash.toLowerCase()}|${k.epoch}|${k.manager.toLowerCase()}`;
29
- export function createDurableObjectAuthorityVerdictCache(sql) {
29
+ /**
30
+ * How long a cached verdict may be reused before the cold path must run again.
31
+ *
32
+ * 60s mirrors `InteractionsDO`'s existing positive-verdict cache (NEW-H4/FAB-A2A-1), which was sized as
33
+ * an RPC-429 mitigation for high-frequency non-sensitive reads. Matching it keeps ONE number in the
34
+ * deployment rather than two that drift.
35
+ */
36
+ export const VERDICT_TTL_MS = 60_000;
37
+ /**
38
+ * BOUNDED REUSE IS PART OF THE VERDICT, NOT AN OPTIMISATION KNOB.
39
+ *
40
+ * Verdict (A) asserts "this delegation was valid AND UNREVOKED at `verifiedAt`". Serving it later without
41
+ * regard to age silently upgrades that into "is valid and unrevoked", which is a claim the cold path never
42
+ * made. Before this, `verified_at` was written and never read: a verdict cached once stayed warm forever,
43
+ * and a revoked delegation kept passing (A) until something called `invalidateDelegation` — a revocation
44
+ * NOTICE that has to be delivered by a second mechanism and may simply never arrive. Revocation that only
45
+ * works when someone remembers to push it is not revocation.
46
+ *
47
+ * Expiry is a MISS, not an error: `invokeFast` refuses on a miss and the caller re-runs `verifyAndCache`,
48
+ * which re-checks the signature and `isRevoked` on-chain. So the ceiling on serving a revoked delegation
49
+ * is `ttlMs`, and the mechanism is the same one throughout (ADR-0013) — the cold path, run again.
50
+ */
51
+ export function createDurableObjectAuthorityVerdictCache(sql, opts) {
30
52
  sql.exec(CREATE_TABLE);
31
53
  sql.exec(CREATE_IDX_DELEG);
32
54
  sql.exec(CREATE_IDX_EPOCH);
55
+ const ttlMs = opts?.ttlMs ?? VERDICT_TTL_MS;
56
+ const now = opts?.now ?? (() => Date.now());
33
57
  return {
34
58
  async put(v) {
35
59
  sql.exec(`INSERT INTO authority_verdicts (cache_key, principal, session_key, delegation_hash, epoch, manager, verified_at)
@@ -46,6 +70,13 @@ export function createDurableObjectAuthorityVerdictCache(sql) {
46
70
  const r = rows[0];
47
71
  if (!r)
48
72
  return null;
73
+ // Age it out. An unparseable `verified_at` counts as EXPIRED: a row whose age cannot be established
74
+ // is one whose freshness cannot be established, and the safe reading of "I don't know" is a miss.
75
+ const verifiedAtMs = Date.parse(r.verified_at);
76
+ if (!Number.isFinite(verifiedAtMs) || now() - verifiedAtMs >= ttlMs) {
77
+ sql.exec('DELETE FROM authority_verdicts WHERE cache_key = ?', keyOf(key));
78
+ return null;
79
+ }
49
80
  return {
50
81
  principal: r.principal,
51
82
  sessionKey: r.session_key,
@@ -1 +1 @@
1
- {"version":3,"file":"authority-verdict-cache.js","sourceRoot":"","sources":["../../src/cloudflare/authority-verdict-cache.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,uEAAuE;AACvE,EAAE;AACF,0FAA0F;AAC1F,2GAA2G;AAC3G,oGAAoG;AACpG,iGAAiG;AACjG,4GAA4G;AAC5G,qDAAqD;AACrD,wGAAwG;AACxG,yGAAyG;AACzG,wGAAwG;AACxG,4GAA4G;AAC5G,oGAAoG;AACpG,EAAE;AACF,0GAA0G;AAE1G,MAAM,YAAY,GAAG;;;;;;;;EAQnB,CAAC;AACH,MAAM,gBAAgB,GAAG,iGAAiG,CAAC;AAC3H,MAAM,gBAAgB,GAAG,uFAAuF,CAAC;AAwCjH,MAAM,KAAK,GAAG,CAAC,CAAsB,EAAU,EAAE,CAC/C,GAAG,CAAC,CAAC,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AAE1G,MAAM,UAAU,wCAAwC,CAAC,GAAe;IACtE,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvB,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC3B,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAE3B,OAAO;QACL,KAAK,CAAC,GAAG,CAAC,CAAC;YACT,GAAG,CAAC,IAAI,CACN;;;;;0EAKkE,EAClE,KAAK,CAAC,CAAC,CAAC,EACR,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE,EACzB,CAAC,CAAC,UAAU,CAAC,WAAW,EAAE,EAC1B,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,EAC9B,CAAC,CAAC,KAAK,EACP,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EACvB,CAAC,CAAC,UAAU,CACb,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,GAAG;YACX,MAAM,IAAI,GAAG,GAAG;iBACb,IAAI,CAAa,sDAAsD,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;iBACpF,OAAO,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,IAAI,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAC;YACpB,OAAO;gBACL,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,UAAU,EAAE,CAAC,CAAC,WAAW;gBACzB,cAAc,EAAE,CAAC,CAAC,eAAe;gBACjC,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,UAAU,EAAE,CAAC,CAAC,WAAW;aAC1B,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,oBAAoB,CAAC,cAAc;YACvC,GAAG,CAAC,IAAI,CAAC,0DAA0D,EAAE,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC;QACrG,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,YAAY;YAC3B,GAAG,CAAC,IAAI,CAAC,iDAAiD,EAAE,YAAY,CAAC,CAAC;QAC5E,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"authority-verdict-cache.js","sourceRoot":"","sources":["../../src/cloudflare/authority-verdict-cache.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,uEAAuE;AACvE,EAAE;AACF,0FAA0F;AAC1F,2GAA2G;AAC3G,oGAAoG;AACpG,iG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1, 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
- /** Seed / overwrite an exchange (e.g. T0 delivery persisting a freshly-built record). Single-writer. */
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,wGA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F,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 get(exchangeId) {
23
- const rows = sql
24
- .exec('SELECT record_json FROM exchange_records WHERE exchange_id = ?', String(exchangeId))
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
- return rows[0] ? JSON.parse(rows[0].record_json) : null;
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,wBAAwB,CAAC;AAEtF,MAAM,YAAY,GAAG;;;;;EAKnB,CAAC;AACH,MAAM,YAAY,GAAG,+FAA+F,CAAC;AAsBrH,MAAM,UAAU,gCAAgC,CAAC,GAAe;IAC9D,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvB,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAEvB,MAAM,IAAI,GAAG,CAAC,MAAwB,EAAQ,EAAE;QAC9C,GAAG,CAAC,IAAI,CACN;;;kGAG4F,EAC5F,MAAM,CAAC,UAAU,EACjB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EACtB,MAAM,CAAC,GAAG,EACV,MAAM,CAAC,SAAS,CACjB,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,CAAC,GAAG,CAAC,MAAM;YACd,IAAI,CAAC,MAAM,CAAC,CAAC;QACf,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,UAAU;YAClB,MAAM,IAAI,GAAG,GAAG;iBACb,IAAI,CAAc,gEAAgE,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;iBACvG,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAsB,CAAC,CAAC,CAAC,IAAI,CAAC;QAChF,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK;YAC5B,MA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AC,OAAO;gBAAE,OAAO,IAAI,CAAC;YAC1B,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAClD,IAAI,MAAM,CAAC,EAAE;gBAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACnC,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,KAAK,CAAC,IAAI;YACR,MAAM,IAAI,GAAG,GAAG;iBACb,IAAI,CAAc,mEAAmE,CAAC;iBACtF,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAqB,CAAC,CAAC;QACxE,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,13 +1,16 @@
1
1
  export { createDurableObjectSqlVault } from './sql-vault.js';
2
- export { createDurableObjectExchangeStore, type ExchangeStore } from './exchange-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';
3
4
  export { createDurableObjectOutboxStore, type OutboxStore, type OutboxEntry } from './outbox-store.js';
4
5
  export { createDurableObjectProvenanceStore, type ProvenanceStore } from './provenance-store.js';
5
6
  export { createDurableObjectChannelStore, projectionAuthorizes, type ChannelStore, type ChannelV1, type ConversationRoleProjection, type ConversationRoleAction, } from './channel-store.js';
6
- export { createDurableObjectAuthorityVerdictCache, type AuthorityVerdictCache, type AuthorityVerdict, type AuthorityVerdictKey, } from './authority-verdict-cache.js';
7
+ export { createDurableObjectAuthorityVerdictCache, VERDICT_TTL_MS, type VerdictCacheOptions, type AuthorityVerdictCache, type AuthorityVerdict, type AuthorityVerdictKey, } from './authority-verdict-cache.js';
7
8
  export { createDurableObjectRequestIdLedger, type RequestIdLedger, type RequestIdReservation } from './request-id-ledger.js';
8
9
  export { createDurableObjectReceiptSigner, verifyDeliveryReceipt, type DeliveryReceiptSigner, type DeliveryReceiptInput, type SignedDeliveryReceiptV1, } from './receipt-signer.js';
9
- 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';
10
11
  export { buildVaultTools, createToolRegistry, type GatewayTool, type GatewayToolContext, type GatewayToolRegistry, } from './gateway-tools.js';
11
- export { runGatewayOrchestration, gatewayToolSpecs, bindGatewayToolInvoker } from './orchestration-runtime.js';
12
+ export { runGatewayOrchestration, gatewayToolSpecs, bindGatewayToolInvoker, type GatewayStepGate } from './orchestration-runtime.js';
13
+ export { createVaultExchangeStore, exchangeResource, EXCHANGE_INDEX_RESOURCE, type VaultExchangeStore, type ExchangeIndexV1, } from './vault-exchange-store.js';
14
+ export { createVaultInteractionStore, interactionResource, decisionResource, commitmentResource, snapshotResource, inboxEntryResource, INTERACTION_INDEX_RESOURCE, type VaultInteractionStore, type InteractionIndexV1, } from './vault-interaction-store.js';
12
15
  export declare const FABRIC_CLOUDFLARE_ADAPTER_STATUS: "w2-coresident-mcp";
13
16
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAC3F,OAAO,EAAE,8BAA8B,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,kCAAkC,EAAE,KAAK,eAAe,EAAE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,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,GACxB,MAAM,8BAA8B,CAAC;AAEtC,eAAO,MAAM,gCAAgC,EAAG,mBAA4B,CAAC"}
@@ -7,14 +7,20 @@
7
7
  // absorption follow in subsequent W2 steps.
8
8
  export { createDurableObjectSqlVault } from './sql-vault.js';
9
9
  export { createDurableObjectExchangeStore } from './exchange-store.js';
10
+ // The interaction spine's durable home (spec 340 W6) — interactions, context snapshots, decisions,
11
+ // commitments and per-viewer inbox state. Five tables, because the six machines answer to different
12
+ // parties at different times and one row would make them one write.
13
+ export { createDurableObjectInteractionStore, TerminalRecordError, } from './interaction-store.js';
10
14
  export { createDurableObjectOutboxStore } from './outbox-store.js';
11
15
  export { createDurableObjectProvenanceStore } from './provenance-store.js';
12
16
  export { createDurableObjectChannelStore, projectionAuthorizes, } from './channel-store.js';
13
- export { createDurableObjectAuthorityVerdictCache, } from './authority-verdict-cache.js';
17
+ export { createDurableObjectAuthorityVerdictCache, VERDICT_TTL_MS, } from './authority-verdict-cache.js';
14
18
  export { createDurableObjectRequestIdLedger } from './request-id-ledger.js';
15
19
  export { createDurableObjectReceiptSigner, verifyDeliveryReceipt, } from './receipt-signer.js';
16
- export { PrincipalGatewayDO } from './principal-gateway-do.js';
20
+ export { PrincipalGatewayDO, GatewayAuthError, InteractionExistsError, } from './principal-gateway-do.js';
17
21
  export { buildVaultTools, createToolRegistry, } from './gateway-tools.js';
18
22
  export { runGatewayOrchestration, gatewayToolSpecs, bindGatewayToolInvoker } from './orchestration-runtime.js';
23
+ export { createVaultExchangeStore, exchangeResource, EXCHANGE_INDEX_RESOURCE, } from './vault-exchange-store.js';
24
+ export { createVaultInteractionStore, interactionResource, decisionResource, commitmentResource, snapshotResource, inboxEntryResource, INTERACTION_INDEX_RESOURCE, } from './vault-interaction-store.js';
19
25
  export const FABRIC_CLOUDFLARE_ADAPTER_STATUS = 'w2-coresident-mcp';
20
26
  //# sourceMappingURL=index.js.map
@@ -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,4CAA4C;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,gCAAgC,EAAsB,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,8BAA8B,EAAsC,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,kCAAkC,EAAwB,MAAM,uBAAuB,CAAC;AACjG,OAAO,EACL,+BAA+B,EAAE,oBAAoB,GAEtD,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,wCAAwC,GAIzC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,kCAAkC,EAAmD,MAAM,wBAAwB,CAAC;AAC7H,OAAO,EACL,gCAAgC,EAChC,qBAAqB,GAItB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAA8C,MAAM,2BAA2B,CAAC;AAC3G,OAAO,EACL,eAAe,EACf,kBAAkB,GAInB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAE/G,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAA4B,CAAC"}
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,4CAA4C;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,gCAAgC,EAAiD,MAAM,qBAAqB,CAAC;AACtH,mGAAmG;AACnG,oGAAoG;AACpG,oEAAoE;AACpE,OAAO,EACL,mCAAmC,EACnC,mBAAmB,GAGpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,8BAA8B,EAAsC,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,kCAAkC,EAAwB,MAAM,uBAAuB,CAAC;AACjG,OAAO,EACL,+BAA+B,EAAE,oBAAoB,GAEtD,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,wCAAwC,EACxC,cAAc,GAKf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,kCAAkC,EAAmD,MAAM,wBAAwB,CAAC;AAC7H,OAAO,EACL,gCAAgC,EAChC,qBAAqB,GAItB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,GASvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,eAAe,EACf,kBAAkB,GAInB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,sBAAsB,EAAwB,MAAM,4BAA4B,CAAC;AACrI,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,GAGxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,GAG3B,MAAM,8BAA8B,CAAC;AAEtC,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAA4B,CAAC"}
@@ -0,0 +1,81 @@
1
+ import type { InteractionRecordV1, InteractionId, ContextSnapshotV1 } from '../interaction-record.js';
2
+ import { type InteractionLifecycleV1, type InteractionTransition, type DecisionRecordV1, type DecisionTransition, type CommitmentRecordV1, type CommitmentTransition, type InboxEntryV1, type InboxTransition, type MachineResult } from '../interaction-machines.js';
3
+ import { type ProtocolBindingV1, type BindingResolution } from '../protocol-binding.js';
4
+ import type { CanonicalAgentId } from '@agenticprimitives/types';
5
+ export type SnapshotPutResult = {
6
+ ok: true;
7
+ stored: 'new' | 'identical';
8
+ } | {
9
+ ok: false;
10
+ reason: 'digest-mismatch';
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';
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. */
39
+ putInteraction(record: InteractionRecordV1): Promise<void>;
40
+ getInteraction(id: InteractionId | string): Promise<InteractionRecordV1 | null>;
41
+ listInteractions(): Promise<InteractionRecordV1[]>;
42
+ /** Drive the interaction lifecycle THROUGH its machine. `null` when the interaction is unknown. */
43
+ transitionInteraction(id: InteractionId | string, event: {
44
+ transition: InteractionTransition;
45
+ actor: CanonicalAgentId;
46
+ at: string;
47
+ }): Promise<MachineResult<InteractionLifecycleV1> | null>;
48
+ /** Index a foreign correlator. Duplicates across interactions are KEPT — that is the ambiguity. */
49
+ bindProtocolTo(id: InteractionId, binding: ProtocolBindingV1): Promise<void>;
50
+ resolveByBinding(protocol: string, field: string, value: string): Promise<BindingResolution>;
51
+ /** Content-addressed. Verifies the digest against the bytes before storing — which IS the
52
+ * immutability guarantee: forged content cannot reach a digest it does not hash to. */
53
+ putContextSnapshot(snapshot: ContextSnapshotV1): Promise<SnapshotPutResult>;
54
+ getContextSnapshot(digest: string): Promise<ContextSnapshotV1 | null>;
55
+ putDecision(record: DecisionRecordV1): Promise<void>;
56
+ getDecision(id: string): Promise<DecisionRecordV1 | null>;
57
+ transitionDecision(id: string, event: {
58
+ transition: DecisionTransition;
59
+ actor: CanonicalAgentId;
60
+ at: string;
61
+ subject?: string;
62
+ }): Promise<MachineResult<DecisionRecordV1> | null>;
63
+ putCommitment(record: CommitmentRecordV1): Promise<void>;
64
+ getCommitment(id: string): Promise<CommitmentRecordV1 | null>;
65
+ /** Open obligations — the query "what is still owed" that a single `case` field could not answer. */
66
+ listOpenCommitments(): Promise<CommitmentRecordV1[]>;
67
+ transitionCommitment(id: string, event: {
68
+ transition: CommitmentTransition;
69
+ actor: CanonicalAgentId;
70
+ at: string;
71
+ }): Promise<MachineResult<CommitmentRecordV1> | null>;
72
+ putInboxEntry(entry: InboxEntryV1): Promise<void>;
73
+ getInboxEntry(viewer: CanonicalAgentId, exchangeId: string): Promise<InboxEntryV1 | null>;
74
+ transitionInbox(viewer: CanonicalAgentId, exchangeId: string, event: {
75
+ transition: InboxTransition;
76
+ actor: CanonicalAgentId;
77
+ at: string;
78
+ }): Promise<MachineResult<InboxEntryV1> | null>;
79
+ }
80
+ export declare function createDurableObjectInteractionStore(sql: SqlStorage): InteractionStore;
81
+ //# sourceMappingURL=interaction-store.d.ts.map
@@ -0,0 +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,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;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAEhC,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,GAAG,YAAY;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM;IADnH,QAAQ,CAAC,MAAM,EAAG,gBAAgB,CAAU;gBACvB,MAAM,EAAE,aAAa,GAAG,UAAU,GAAG,YAAY,EAAW,EAAE,EAAE,MAAM,EAAW,KAAK,EAAE,MAAM;CAIpH;AAED;+FAC+F;AAC/F,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,MAAM,EAAE,aAAa,GAAG,UAAU,GAAG,YAAY,EAC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