effect-durable-agent 0.1.0-alpha.3 → 0.1.0-alpha.30

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 (221) hide show
  1. package/README.md +43 -41
  2. package/dist/assert-never-CoyUpoRB.js +18 -0
  3. package/dist/assert-never-CoyUpoRB.js.map +1 -0
  4. package/dist/{commands-Ce1ec6kH.d.ts → commands-3OD-p8dD.d.ts} +16 -9
  5. package/dist/compaction-63iEDHHl.js +523 -0
  6. package/dist/compaction-63iEDHHl.js.map +1 -0
  7. package/dist/context-projection-D_uRtK3r.d.ts +139 -0
  8. package/dist/{core-Hv3cFydL.d.ts → core-BcimKMIv.d.ts} +6 -4
  9. package/dist/delivery-2ZILvoRD.js +507 -0
  10. package/dist/delivery-2ZILvoRD.js.map +1 -0
  11. package/dist/{websocket-wire-D3tLrhe2.d.ts → delivery-RjM1_NAE.d.ts} +1019 -200
  12. package/dist/domain/command-queues.d.ts +81 -2
  13. package/dist/domain/command-queues.js +1 -1
  14. package/dist/domain/command-queues.js.map +1 -1
  15. package/dist/domain/context-projection.d.ts +2 -0
  16. package/dist/domain/context-projection.js +32 -0
  17. package/dist/domain/context-projection.js.map +1 -0
  18. package/dist/domain/message-transcript.d.ts +36 -2
  19. package/dist/domain/message-transcript.js +10 -2
  20. package/dist/domain/message-transcript.js.map +1 -1
  21. package/dist/domain/model-usage.d.ts +2 -0
  22. package/dist/domain/model-usage.js +59 -0
  23. package/dist/domain/model-usage.js.map +1 -0
  24. package/dist/domain/reduced-state-schema.d.ts +3 -996
  25. package/dist/domain/reduced-state-schema.js +121 -12
  26. package/dist/domain/reduced-state-schema.js.map +1 -1
  27. package/dist/domain/reduced-state.d.ts +3 -2
  28. package/dist/domain/reduced-state.js +937 -2
  29. package/dist/domain/reduced-state.js.map +1 -0
  30. package/dist/domain/run-scheduling.d.ts +2 -0
  31. package/dist/domain/run-scheduling.js +127 -0
  32. package/dist/domain/run-scheduling.js.map +1 -0
  33. package/dist/{durable-DlScwmCy.d.ts → durable-Cqv5ZRFA.d.ts} +8505 -2497
  34. package/dist/{durable-C3Rz7kg3.js → durable-D13w1Qr3.js} +253 -91
  35. package/dist/durable-D13w1Qr3.js.map +1 -0
  36. package/dist/envelope-BCzKUq_z.js +91 -0
  37. package/dist/envelope-BCzKUq_z.js.map +1 -0
  38. package/dist/envelope-Che6KatU.d.ts +254 -0
  39. package/dist/{keep-alive-p8dIcSVy.js → event-factory-_vF1bIJ7.js} +8 -10
  40. package/dist/event-factory-_vF1bIJ7.js.map +1 -0
  41. package/dist/{events-Bb9-Cu-7.d.ts → events-Dg0o5wWs.d.ts} +140 -324
  42. package/dist/{id-generator-C2Q15uZM.d.ts → id-generator-BKGoKjt-.d.ts} +3 -3
  43. package/dist/in-memory-CeODnZhE.js +150 -0
  44. package/dist/in-memory-CeODnZhE.js.map +1 -0
  45. package/dist/index.d.ts +8 -7
  46. package/dist/index.js +6 -5
  47. package/dist/interpreter-DKGJ1sSx.js +1452 -0
  48. package/dist/interpreter-DKGJ1sSx.js.map +1 -0
  49. package/dist/keep-alive-_zFCUvt3.d.ts +28 -0
  50. package/dist/model-resolver-D0vcDZsU.d.ts +24 -0
  51. package/dist/model-usage-0GeHwaaU.d.ts +54 -0
  52. package/dist/records--54mZEBx.js +675 -0
  53. package/dist/records--54mZEBx.js.map +1 -0
  54. package/dist/reduced-state-DU2ECOUp.d.ts +47821 -0
  55. package/dist/reduced-state-schema-B2t3cobf.d.ts +2187 -0
  56. package/dist/{reducer-registry-C0svUa63.d.ts → reducer-registry-JLU1yptN.d.ts} +24 -8
  57. package/dist/run-scheduling-wakeup-D_bGdicf.d.ts +24 -0
  58. package/dist/services/compaction.d.ts +2 -2
  59. package/dist/services/compaction.js +2 -426
  60. package/dist/services/id-generator.d.ts +1 -1
  61. package/dist/services/id-generator.js +4 -2
  62. package/dist/services/id-generator.js.map +1 -1
  63. package/dist/services/keep-alive.d.ts +2 -0
  64. package/dist/services/keep-alive.js +13 -0
  65. package/dist/services/keep-alive.js.map +1 -0
  66. package/dist/services/model-call.d.ts +15 -0
  67. package/dist/services/model-call.js +15 -0
  68. package/dist/services/model-call.js.map +1 -0
  69. package/dist/services/model-resolver.d.ts +2 -0
  70. package/dist/services/model-resolver.js +17 -0
  71. package/dist/services/model-resolver.js.map +1 -0
  72. package/dist/services/prompt-projector.d.ts +2 -2
  73. package/dist/services/prompt-projector.js +49 -5
  74. package/dist/services/prompt-projector.js.map +1 -1
  75. package/dist/services/reducer-registry.d.ts +2 -2
  76. package/dist/services/reducer-registry.js +21 -4
  77. package/dist/services/reducer-registry.js.map +1 -1
  78. package/dist/services/run-scheduler.d.ts +2 -0
  79. package/dist/services/run-scheduler.js +25 -0
  80. package/dist/services/run-scheduler.js.map +1 -0
  81. package/dist/services/run-scheduling-wakeup.d.ts +2 -0
  82. package/dist/services/run-scheduling-wakeup.js +13 -0
  83. package/dist/services/run-scheduling-wakeup.js.map +1 -0
  84. package/dist/services/runtime-layer.d.ts +48 -0
  85. package/dist/services/runtime-layer.js +51 -0
  86. package/dist/services/runtime-layer.js.map +1 -0
  87. package/dist/services/runtime.d.ts +1 -1
  88. package/dist/services/runtime.js +34 -20
  89. package/dist/services/runtime.js.map +1 -1
  90. package/dist/services/session-event-observer.d.ts +2 -0
  91. package/dist/services/session-event-observer.js +13 -0
  92. package/dist/services/session-event-observer.js.map +1 -0
  93. package/dist/services/session-query.d.ts +2 -2
  94. package/dist/services/session-query.js +141 -2
  95. package/dist/services/session-query.js.map +1 -0
  96. package/dist/services/session-state.d.ts +2 -0
  97. package/dist/services/session-state.js +2 -0
  98. package/dist/services/session-store.d.ts +2 -2
  99. package/dist/services/session-store.js +272 -2
  100. package/dist/services/session-store.js.map +1 -0
  101. package/dist/services/sink-checkpoint-store.d.ts +2 -0
  102. package/dist/services/sink-checkpoint-store.js +50 -0
  103. package/dist/services/sink-checkpoint-store.js.map +1 -0
  104. package/dist/services/sink-registry.d.ts +2 -2
  105. package/dist/services/sink-registry.js +1 -1
  106. package/dist/services/span-names.d.ts +1 -1
  107. package/dist/services/span-names.js +7 -1
  108. package/dist/services/span-names.js.map +1 -1
  109. package/dist/services/tool-registry.d.ts +2 -2
  110. package/dist/services/tool-registry.js +12 -3
  111. package/dist/services/tool-registry.js.map +1 -1
  112. package/dist/services/tracing.d.ts +3 -3
  113. package/dist/services/tracing.js +25 -4
  114. package/dist/services/tracing.js.map +1 -1
  115. package/dist/session-event-observer-HvrRckbC.d.ts +24 -0
  116. package/dist/{session-query-Cbf-e0rG.js → session-state-BQYsuBqi.js} +693 -251
  117. package/dist/session-state-BQYsuBqi.js.map +1 -0
  118. package/dist/session-store-CQxg9U82.d.ts +3302 -0
  119. package/dist/sink-checkpoint-store-DWGifxp0.d.ts +39 -0
  120. package/dist/sink-registry-DskRcyOS.js +345 -0
  121. package/dist/sink-registry-DskRcyOS.js.map +1 -0
  122. package/dist/subscription-DmO3BcdT.js +505 -0
  123. package/dist/subscription-DmO3BcdT.js.map +1 -0
  124. package/dist/subscription-rC35dAWn.d.ts +958 -0
  125. package/dist/testkit/layers.d.ts +34 -19
  126. package/dist/testkit/layers.js +30 -16
  127. package/dist/testkit/layers.js.map +1 -1
  128. package/dist/testkit/transcript.d.ts +226 -0
  129. package/dist/testkit/transcript.js +1475 -0
  130. package/dist/testkit/transcript.js.map +1 -0
  131. package/dist/{tool-registry-CcnkAAQK.d.ts → tool-registry-BzlMhwzj.d.ts} +44 -8
  132. package/dist/{tracing-BXHAkxkx.d.ts → tracing-BwjbF285.d.ts} +1 -2
  133. package/dist/transcript.d.ts +101 -0
  134. package/dist/transcript.js +107 -0
  135. package/dist/transcript.js.map +1 -0
  136. package/dist/types/commands.d.ts +2 -2
  137. package/dist/types/commands.js +8 -3
  138. package/dist/types/commands.js.map +1 -1
  139. package/dist/types/core.d.ts +2 -2
  140. package/dist/types/core.js +4 -2
  141. package/dist/types/core.js.map +1 -1
  142. package/dist/types/events/durable.d.ts +2 -2
  143. package/dist/types/events/durable.js +2 -2
  144. package/dist/types/events.d.ts +5 -4
  145. package/dist/types/events.js +3 -2
  146. package/dist/types/events.js.map +1 -1
  147. package/dist/types/tracing.d.ts +1 -1
  148. package/dist/types/tracing.js.map +1 -1
  149. package/dist/websocket/events.d.ts +2 -0
  150. package/dist/websocket/events.js +2 -0
  151. package/dist/websocket.d.ts +2201 -0
  152. package/dist/websocket.js +684 -0
  153. package/dist/websocket.js.map +1 -0
  154. package/dist/window-read-CBZEJ84M.d.ts +113 -0
  155. package/dist/window-read-DPFAA1hM.js +264 -0
  156. package/dist/window-read-DPFAA1hM.js.map +1 -0
  157. package/package.json +87 -46
  158. package/testing/offline-trace/README.md +2 -1
  159. package/CHANGELOG.md +0 -25
  160. package/CONTRIBUTING.md +0 -26
  161. package/SECURITY.md +0 -7
  162. package/dist/command-queues-CQ9cwRP7.d.ts +0 -468
  163. package/dist/compaction-1LSZR944.d.ts +0 -144
  164. package/dist/durable-C3Rz7kg3.js.map +0 -1
  165. package/dist/durable-object-runtime-CiMKxGs6.d.ts +0 -257
  166. package/dist/durable-object-runtime-wKiqaAt2.js +0 -1494
  167. package/dist/durable-object-runtime-wKiqaAt2.js.map +0 -1
  168. package/dist/durable-object-storage-Czy7IPrh.d.ts +0 -41
  169. package/dist/host/durable-object-runtime.d.ts +0 -2
  170. package/dist/host/durable-object-runtime.js +0 -2
  171. package/dist/host/durable-object-storage.d.ts +0 -2
  172. package/dist/host/durable-object-storage.js +0 -0
  173. package/dist/host/durable-object.d.ts +0 -83
  174. package/dist/host/durable-object.js +0 -191
  175. package/dist/host/durable-object.js.map +0 -1
  176. package/dist/host/websocket-wire.d.ts +0 -2
  177. package/dist/host/websocket-wire.js +0 -105
  178. package/dist/host/websocket-wire.js.map +0 -1
  179. package/dist/index-BVVgDSdq.d.ts +0 -1
  180. package/dist/keep-alive-DYDsH6qN.d.ts +0 -111
  181. package/dist/keep-alive-p8dIcSVy.js.map +0 -1
  182. package/dist/message-transcript-BCHdHAe2.d.ts +0 -32
  183. package/dist/prompt-projector-DimXJPOJ.d.ts +0 -39
  184. package/dist/reduced-state-C4nVVzz9.js +0 -910
  185. package/dist/reduced-state-C4nVVzz9.js.map +0 -1
  186. package/dist/runtime-DcdPOEuE.d.ts +0 -60
  187. package/dist/services/compaction.js.map +0 -1
  188. package/dist/session-query-Cbf-e0rG.js.map +0 -1
  189. package/dist/session-query-hxfujxUH.d.ts +0 -769
  190. package/dist/session-store-D2Ore1QC.d.ts +0 -295
  191. package/dist/session-store-pYxQW9qh.js +0 -214
  192. package/dist/session-store-pYxQW9qh.js.map +0 -1
  193. package/dist/sink-registry-BziFpxoE.d.ts +0 -158
  194. package/dist/sink-registry-CFC6xjsN.js +0 -312
  195. package/dist/sink-registry-CFC6xjsN.js.map +0 -1
  196. package/docs/assets/architecture.svg +0 -216
  197. package/docs/assets/event-sequence.svg +0 -133
  198. package/docs/assets/gcp-trace.png +0 -0
  199. package/docs/assets/hero.svg +0 -33
  200. package/docs/message-steering.md +0 -831
  201. package/docs/releasing.md +0 -96
  202. package/docs/spec.md +0 -777
  203. package/docs/subagents.md +0 -725
  204. package/docs/testing.md +0 -64
  205. package/docs/ui-projection.md +0 -742
  206. package/docs/websocket-protocol.md +0 -639
  207. package/examples/001-no-tools/README.md +0 -65
  208. package/examples/001-no-tools/worker.ts +0 -79
  209. package/examples/002-slack-bridge/README.md +0 -134
  210. package/examples/002-slack-bridge/events.ts +0 -115
  211. package/examples/002-slack-bridge/reducer.ts +0 -216
  212. package/examples/002-slack-bridge/scenario.test.ts +0 -223
  213. package/examples/002-slack-bridge/sinks.ts +0 -109
  214. package/examples/002-slack-bridge/worker.ts +0 -140
  215. package/examples/003-sandbox-lifecycle/README.md +0 -78
  216. package/examples/003-sandbox-lifecycle/events.ts +0 -203
  217. package/examples/003-sandbox-lifecycle/reducer.ts +0 -305
  218. package/examples/003-sandbox-lifecycle/scenario.test.ts +0 -202
  219. package/examples/_shared/event-id.ts +0 -12
  220. package/examples/_shared/http.ts +0 -27
  221. package/examples/_shared/openai.ts +0 -33
@@ -1,742 +0,0 @@
1
- # effect-durable-agent UI projection proposal
2
-
3
- Status: future
4
- Runtime: EDAGiaAgent
5
- Last reviewed: 2026-07-11
6
-
7
- Audience: EDA/Gia runtime + UI maintainers
8
-
9
- Current runtime exposes small Gia attachment and current-sandbox reducer projections in the EDA snapshot; this document describes the desired future full-transcript projection layer.
10
-
11
- ## 1. Purpose
12
-
13
- Gia is moving from Cloudflare Think's chat-message storage model to `effect-durable-agent` (EDA), whose source of truth is a durable event log plus live-only ephemeral events. The browser UI still needs a simple, paginated, renderable transcript.
14
-
15
- This proposal defines a future server-side UI projection layer for EDA. There is currently no generic `EDAUIItem`, `EDAUISnapshot`, `_eda_ui_items` table, projection API, or `useEDASessionUI` hook in this repository. The current host-facing read APIs are `EDARuntime.snapshot()` and `EDARuntime.messages()`, derived from canonical `ReducedState`; Gia additionally exposes attachment and current-sandbox state from its app reducers in the EDA snapshot.
16
-
17
- The current web product server-renders EDAGiaAgent sessions from
18
- `loadEDAGiaSnapshot(...)`, hydrates that serialized snapshot, then follows
19
- `/api/eda-agent/sessions/:sessionId/events?afterSeq=<snapshot.state.lastSeq>`
20
- with EDA WebSocket ACK flow control. Durable event frames advance the live
21
- cursor and schedule a snapshot refresh; ephemeral text, reasoning, and tool
22
- parameter frames fold into a live overlay. Heartbeats are connection-health
23
- frames only and are not ACKed.
24
-
25
- The proposed layer would:
26
-
27
- - avoid replaying a whole session from `seq = 0` on every UI load;
28
- - support latest-N transcript rendering and older-message pagination;
29
- - prevent cross-page lifecycle tears for turns, tool calls, and custom app events;
30
- - keep app-specific UI projections, such as current E2B sandbox identity, simple and pluggable;
31
- - preserve EDA's durable/ephemeral semantics instead of forcing the browser to understand the raw event model.
32
-
33
- ## 2. EDA primer
34
-
35
- EDA models one session as ordered facts.
36
-
37
- ### 2.1 Durable events
38
-
39
- Durable events are persisted, sequenced, replayable facts. Examples:
40
-
41
- - `CommandAdmitted`
42
- - `CommandStarted`
43
- - `UserMessageCommitted`
44
- - `RunStarted`
45
- - `TurnStarted`
46
- - `InferenceStarted`
47
- - `ToolCallCreated`
48
- - `ToolCallStarted`
49
- - `ToolCallCompleted`
50
- - `AssistantMessageCommitted`
51
- - `TurnCompleted`
52
- - `CommandCompleted`
53
-
54
- Every durable event receives an authoritative `seq`. Durable replay reconstructs `ReducedState`, query state, and recovery decisions.
55
-
56
- ### 2.2 Ephemeral events
57
-
58
- Ephemeral events are live-only, ordered against the current durable head as `(seq, subSeq)`. Examples:
59
-
60
- - `TextDelta`
61
- - `ReasoningDelta`
62
- - `ToolParamsStart`
63
- - `ToolParamsDelta`
64
- - `ToolParamsEnd`
65
- - transient status events
66
-
67
- Ephemeral events are not persisted as a replay log. Current reconnect catches up with durable replay plus the same-process raw active-turn ephemeral replay buffer, then follows future live events. A coalesced UI projection snapshot is proposed by this document but is not implemented.
68
-
69
- ### 2.3 `SessionState` authority
70
-
71
- `SessionState` is the live-process write authority:
72
-
73
- 1. Commit durable events to `EDASessionStore`.
74
- 2. Fold newly committed durable events into authoritative in-memory `ReducedState`.
75
- 3. Publish positioned durable events to `LiveEventBus`.
76
- 4. Allocate positions for ephemerals and publish them to `LiveEventBus`.
77
-
78
- Storage, live bus, subscribers, UI state, and read models are downstream from this authority.
79
-
80
- ### 2.4 Compaction is model-context compaction
81
-
82
- EDA compaction rebases the future model prompt onto a summary plus retained tail. It does not mean the user-visible transcript must disappear. UI pagination must be able to show older conversation history even when model context has compacted.
83
-
84
- ## 3. Current EDA browser transport
85
-
86
- The EDA browser client receives a server-rendered snapshot and follows the
87
- session event stream with explicit durable positions and ACK flow control.
88
-
89
- That model is excellent when the server owns one canonical `UIMessage[]`. EDA is more expressive: it has lifecycle facts, app-specific durable events, live-only deltas, tool lifecycle, E2B sandbox identity, recovery events, and context compaction. A raw `UIMessage[]` should become an output projection, not the source of truth.
90
-
91
- ## 4. Problem statement
92
-
93
- The UI needs to render a long-running EDA session efficiently and correctly.
94
-
95
- A naive UI would:
96
-
97
- ```text
98
- connect -> replay durable events from seq 0 -> reduce in browser
99
- ```
100
-
101
- This is unacceptable for long sessions and compactions.
102
-
103
- A less naive UI would:
104
-
105
- ```text
106
- connect -> get snapshot -> stream later events
107
- ```
108
-
109
- This is better, but still not enough if the browser receives raw events. Raw durable event ranges are not safe pagination units.
110
-
111
- A turn or tool call can span many events:
112
-
113
- ```text
114
- seq 100 ToolCallCreated
115
- seq 101 ToolCallStarted
116
- seq 130 gia-agent/SandboxCreated
117
- seq 200 ToolCallCompleted
118
- ```
119
-
120
- If the UI pages by raw event sequence, it can render orphaned or partial state:
121
-
122
- - an E2B sandbox replacement without the surrounding session state;
123
- - tool started on one page and completed on another;
124
- - a turn terminal without the turn's child cards;
125
- - custom app lifecycle events with no UI parent.
126
-
127
- The UI wants renderable entities, not event fragments.
128
-
129
- ## 5. Goals
130
-
131
- 1. **Server-side projection**: browser consumes UI projection state and patches, not raw EDA event facts.
132
- 2. **Latest-N rendering**: initial page renders the latest N transcript roots.
133
- 3. **Cursor pagination**: older roots load with stable cursors, not offsets.
134
- 4. **All-or-zero entity grouping**: a page contains a complete projected entity group or none of it.
135
- 5. **Live streaming UX**: text/reasoning/tool-params deltas still render smoothly.
136
- 6. **Custom app events**: apps add small projection reducers; they do not add custom pagination engines.
137
- 7. **Bounded payloads**: huge outputs/logs are summarized in transcript items and fetched lazily as details.
138
- 8. **Reconnect safety**: reconnect uses durable sequence checkpoints plus projection snapshots and idempotent patches.
139
-
140
- ## 6. Non-goals
141
-
142
- - Do not make the browser an EDA event reducer.
143
- - Do not guarantee raw event ranges contain complete lifecycles.
144
- - Do not make ephemerals replayable history.
145
- - Do not conflate model context compaction with UI transcript pagination.
146
- - Do not add one-off UI tables or routes for each app-specific feature.
147
-
148
- ## 7. Core recommendation (future)
149
-
150
- Add an EDA UI projection layer:
151
-
152
- ```text
153
- Durable + ephemeral EDA events
154
- ↓
155
- Server-side UI reducers
156
- ↓
157
- Generic UI projection items
158
- ↓
159
- Paginated snapshot + live UI patches
160
- ↓
161
- React transcript rendering
162
- ```
163
-
164
- The browser pages **projection roots**, not events.
165
-
166
- If a page includes an assistant turn root, the server includes all projected children for that root: text block, reasoning block, tool call cards, status notices, etc. If the page does not include the root, it includes none of those children.
167
-
168
- This is the central all-or-zero guarantee.
169
-
170
- ## 8. Projection model
171
-
172
- ### 8.1 UI item
173
-
174
- A UI projection item is a stable renderable unit:
175
-
176
- ```ts
177
- interface EDAUIItem {
178
- readonly itemId: string;
179
- readonly rootItemId: string;
180
- readonly parentItemId?: string;
181
- readonly kind: string;
182
- readonly anchorSeq: number;
183
- readonly updatedSeq: number;
184
- readonly ordinal: string;
185
- readonly payload: unknown;
186
- }
187
- ```
188
-
189
- Field meanings:
190
-
191
- - `itemId`: stable identity, e.g. `eda:tool-call:<toolCallId>`.
192
- - `rootItemId`: transcript page boundary, e.g. `eda:assistant-turn:<turnId>`.
193
- - `parentItemId`: optional nesting parent.
194
- - `kind`: render type, e.g. `user-message`, `assistant-turn`, `tool-call`.
195
- - `anchorSeq`: first durable sequence that made this item visible.
196
- - `updatedSeq`: latest durable sequence folded into this item.
197
- - `ordinal`: deterministic order within a root, including child ordering.
198
- - `payload`: bounded UI payload, versioned by kind.
199
-
200
- ### 8.2 Root items
201
-
202
- Root items are pagination units. Candidate root kinds:
203
-
204
- - `system-notice`
205
- - `user-message`
206
- - `assistant-turn`
207
- - `compaction-notice`
208
- - `recovery-notice`
209
-
210
- A page selects roots by `anchorSeq`, then returns descendants for those roots.
211
-
212
- ### 8.3 Child items
213
-
214
- Child items render inside a root. Candidate child kinds:
215
-
216
- - `assistant-text`
217
- - `assistant-reasoning`
218
- - `tool-call`
219
- - `tool-result`
220
- - `trace-status`
221
-
222
- A child must not be returned without its root in transcript pagination.
223
-
224
- ### 8.4 Detail items
225
-
226
- Some data is too large for transcript cards:
227
-
228
- - stdout/stderr bodies;
229
- - full tool params/results;
230
- - trace logs;
231
- - long reasoning traces.
232
-
233
- Projection items should contain summaries/tails/previews and a `hasMoreDetails` flag. Detail payloads should be fetched separately by `itemId`, with their own pagination if needed.
234
-
235
- ## 9. All-or-zero page guarantee
236
-
237
- We do not guarantee this:
238
-
239
- > All raw durable events for an entity are physically contained in one event page.
240
-
241
- That is impossible for long-running entities.
242
-
243
- We guarantee this instead:
244
-
245
- > For a given `projectionThroughSeq`, all durable event effects up to that sequence have been folded into the projected item group. A transcript page includes all items for selected roots, or zero items for non-selected roots.
246
-
247
- ### 9.1 Invariants
248
-
249
- 1. **Page roots are selected first.**
250
- The query chooses root items using cursor pagination over `anchorSeq`.
251
-
252
- 2. **Descendants are fetched by root.**
253
- After roots are selected, the query fetches `WHERE root_item_id IN (...)`.
254
-
255
- 3. **No orphan child rendering.**
256
- A child item whose root is not selected is not returned in that page.
257
-
258
- 4. **Idempotent updates.**
259
- Items carry `updatedSeq`; clients ignore stale patches where `updatedSeq <= current.updatedSeq`.
260
-
261
- 5. **Complete as of a checkpoint, not necessarily terminal.**
262
- A running tool card is complete as of `projectionThroughSeq` even if it will later complete. The terminal event will arrive as a future patch or appear in a later page fetch.
263
-
264
- 6. **Large details are out-of-band.**
265
- A page may show a complete card summary while full logs remain lazy details.
266
-
267
- ### 9.2 Example
268
-
269
- Raw events:
270
-
271
- ```text
272
- 100 TurnStarted(turn-1)
273
- 101 InferenceStarted(inference-1)
274
- 102 ToolCallCreated(tool-1)
275
- 103 ToolCallStarted(tool-1)
276
- 104 gia-agent/SandboxCreated(gia-session-1, e2b-sandbox-1)
277
- 105 ToolCallCompleted(tool-1)
278
- 106 AssistantMessageCommitted(turn-1)
279
- 107 TurnCompleted(turn-1)
280
- ```
281
-
282
- Projection roots:
283
-
284
- ```text
285
- root: eda:assistant-turn:turn-1
286
- child: eda:tool-call:tool-1
287
- child: eda:assistant-text:message-1
288
- ```
289
-
290
- Pagination returns either:
291
-
292
- ```text
293
- assistant-turn turn-1 + all descendants
294
- ```
295
-
296
- or:
297
-
298
- ```text
299
- none of turn-1's descendants
300
- ```
301
-
302
- It never returns `eda:tool-call:tool-1` alone.
303
-
304
- ## 10. Custom app events without custom pagination
305
-
306
- Custom app events participate by registering UI reducers that emit generic projection operations.
307
-
308
- ### 10.1 Generic reducer interface
309
-
310
- ```ts
311
- interface EDAUIReducer<State = unknown> {
312
- readonly name: string;
313
- readonly interests: ReadonlyArray<string>; // namespace/type keys
314
- readonly initial: State;
315
- reduce(
316
- state: State,
317
- event: PositionedDurableEvent,
318
- ctx: EDAUIReducerContext,
319
- ): EDAUIReducerResult<State>;
320
- }
321
- ```
322
-
323
- Reducers are pure. They do not write SQL directly and do not send WebSocket messages directly.
324
-
325
- ### 10.2 Generic projection operations
326
-
327
- Reducers emit operations such as:
328
-
329
- ```ts
330
- type EDAUIProjectionOp =
331
- | { readonly _tag: "UpsertItem"; readonly item: EDAUIItem }
332
- | { readonly _tag: "PatchItem"; readonly itemId: string; readonly updatedSeq: number; readonly patch: unknown }
333
- | { readonly _tag: "AppendDetail"; readonly itemId: string; readonly detail: unknown };
334
- ```
335
-
336
- The projection engine applies these operations to the generic UI projection store and live patch stream.
337
-
338
- ### 10.3 Framework reducers
339
-
340
- EDA core registers reducers for framework event types:
341
-
342
- - command status notices;
343
- - user messages;
344
- - assistant turn roots;
345
- - assistant committed/partial messages;
346
- - reasoning/text summaries;
347
- - tool-call lifecycle;
348
- - compaction/recovery notices.
349
-
350
- ### 10.4 Gia E2B sandbox reducer
351
-
352
- Gia registers one reducer for the E2B `gia-agent/SandboxCreated` fact. It
353
- records the latest authoritative logical sandbox id, E2B metadata, creation
354
- time, and durable sequence. Command cards remain entirely
355
- owned by the framework `ToolCall*` projection; their completed result already
356
- contains the `runBash` exit, timing, output, retryability, and logical sandbox
357
- metadata.
358
-
359
- No app-specific pagination route is required. The page query still selects roots and descendants from the same generic projection model.
360
-
361
- ### 10.5 Custom event conventions
362
-
363
- To keep custom app events simple, app event schemas should include:
364
-
365
- 1. a stable entity id, e.g. `executionKey`;
366
- 2. a parent correlation id when the event is attached to framework UI, e.g. `toolCallId`;
367
- 3. bounded summary fields for transcript cards;
368
- 4. references or lazy detail IDs for large payloads;
369
- 5. schema versioning under the app namespace.
370
-
371
- If a custom event cannot resolve a parent, the reducer should either:
372
-
373
- - create an app-owned root item, or
374
- - emit a diagnostics-only item not shown in transcript pagination.
375
-
376
- It should not create orphan transcript children.
377
-
378
- ## 11. Ephemeral text deltas
379
-
380
- Ephemeral `TextDelta` events should render as live patches to an active draft, not as pageable history.
381
-
382
- ### 11.1 Live flow
383
-
384
- 1. Provider stream emits text.
385
- 2. EDA publishes `TextDelta` at `(currentDurableHead, subSeq)`.
386
- 3. UI live reducer appends the delta to an active assistant draft item.
387
- 4. Browser receives an idempotent patch such as:
388
-
389
- ```ts
390
- {
391
- type: "patch",
392
- durableThroughSeq: 120,
393
- ops: [
394
- { op: "appendText", itemId: "eda:assistant-draft:<inferenceId>", delta: "hello" }
395
- ]
396
- }
397
- ```
398
-
399
- ### 11.2 Active overlay
400
-
401
- Streaming drafts live in an active overlay, not in older transcript pages:
402
-
403
- ```text
404
- paged roots:
405
- latest committed transcript roots
406
-
407
- active overlay:
408
- current assistant draft
409
- current reasoning draft
410
- current speculative tool params
411
- current running tool cards
412
- ```
413
-
414
- If the user is at the bottom, the overlay renders like the latest assistant turn. If the user is paged far back, the UI can show a “new activity” affordance without mutating old pages.
415
-
416
- ### 11.3 Finalization
417
-
418
- When the inference finishes, EDA commits durable final events such as:
419
-
420
- - `AssistantMessageCommitted`
421
- - `InferenceCompleted`
422
- - `TurnCompleted`
423
-
424
- The UI durable reducer then:
425
-
426
- 1. upserts or finalizes the committed assistant item;
427
- 2. reconciles it with the draft item;
428
- 3. retires the ephemeral draft.
429
-
430
- After finalization, the assistant message is durable, pageable, and reload-safe.
431
-
432
- ### 11.4 Reconnect
433
-
434
- Ephemeral deltas are not replayed one by one. On reconnect:
435
-
436
- 1. client sends durable checkpoint;
437
- 2. server returns durable/projection snapshot;
438
- 3. snapshot includes coalesced active draft text if still available;
439
- 4. live stream resumes with future patches.
440
-
441
- If the Durable Object restarted and live-only text was lost, the server must not fabricate it. Recovery produces durable explanation events such as `AssistantPartialCommitted`, `InferenceFailed`, interruption-coded `TurnFailed` / `RunFailed`, and a replacement `RunStarted` for transparent continuation. Existing durable histories may still contain deprecated `TurnStopped` / `RunInterrupted` events, which the projection accepts during replay.
442
-
443
- ## 12. Public query and stream API
444
-
445
- ### 12.1 `getUiSnapshot`
446
-
447
- Initial page load.
448
-
449
- ```ts
450
- interface GetUiSnapshotInput {
451
- readonly latestRoots?: number; // default 50
452
- }
453
-
454
- interface EDAUISnapshot {
455
- readonly schemaVersion: 1;
456
- readonly sessionId: string;
457
- readonly projectionThroughSeq: number;
458
- readonly durableHeadSeq: number;
459
- readonly page: EDAUIPage;
460
- readonly active: EDAUIActiveOverlay;
461
- }
462
- ```
463
-
464
- The snapshot returns latest roots plus all descendants for those roots.
465
-
466
- ### 12.2 `getUiPage`
467
-
468
- Older pagination.
469
-
470
- ```ts
471
- interface GetUiPageInput {
472
- readonly beforeAnchorSeq?: number;
473
- readonly limit?: number; // default 50
474
- }
475
-
476
- interface EDAUIPage {
477
- readonly projectionThroughSeq: number;
478
- readonly roots: ReadonlyArray<EDAUIItem>;
479
- readonly itemsByRoot: Readonly<Record<string, ReadonlyArray<EDAUIItem>>>;
480
- readonly oldestAnchorSeq?: number;
481
- readonly newestAnchorSeq?: number;
482
- readonly hasMoreBefore: boolean;
483
- }
484
- ```
485
-
486
- `itemsByRoot[rootItemId]` includes the root and every selected descendant, sorted by `ordinal`.
487
-
488
- ### 12.3 `subscribeUi`
489
-
490
- Reconnect-safe live stream.
491
-
492
- ```ts
493
- interface SubscribeUiInput {
494
- readonly afterSeq: number;
495
- readonly knownProjectionSeq?: number;
496
- }
497
-
498
- type EDAUILiveMessage =
499
- | { readonly type: "snapshot"; readonly snapshot: EDAUISnapshot }
500
- | { readonly type: "patch"; readonly patch: EDAUIPatch }
501
- | { readonly type: "status"; readonly status: string; readonly reason?: string };
502
- ```
503
-
504
- Patches are idempotent and ordered by durable/ephemeral position. A client that misses too much reconnects and asks for a new snapshot.
505
-
506
- ### 12.4 `getUiItemDetails`
507
-
508
- Lazy details for large data.
509
-
510
- ```ts
511
- interface GetUiItemDetailsInput {
512
- readonly itemId: string;
513
- readonly cursor?: string;
514
- readonly limit?: number;
515
- }
516
- ```
517
-
518
- Used for full stdout/stderr, full tool params/results, long traces, etc.
519
-
520
- ## 13. Storage shape
521
-
522
- ### 13.1 Generic projection table
523
-
524
- A future durable projection store can be generic:
525
-
526
- ```sql
527
- CREATE TABLE _eda_ui_items (
528
- item_id TEXT PRIMARY KEY,
529
- root_item_id TEXT NOT NULL,
530
- parent_item_id TEXT,
531
- kind TEXT NOT NULL,
532
- anchor_seq INTEGER NOT NULL,
533
- updated_seq INTEGER NOT NULL,
534
- ordinal TEXT NOT NULL,
535
- payload_json TEXT NOT NULL
536
- );
537
-
538
- CREATE INDEX _eda_ui_items_roots_idx
539
- ON _eda_ui_items(parent_item_id, anchor_seq);
540
-
541
- CREATE INDEX _eda_ui_items_root_children_idx
542
- ON _eda_ui_items(root_item_id, ordinal);
543
-
544
- CREATE INDEX _eda_ui_items_updated_seq_idx
545
- ON _eda_ui_items(updated_seq);
546
- ```
547
-
548
- Root items have `parent_item_id IS NULL`.
549
-
550
- ### 13.2 Optional details table
551
-
552
- Large details can be split out later:
553
-
554
- ```sql
555
- CREATE TABLE _eda_ui_item_details (
556
- item_id TEXT NOT NULL,
557
- detail_seq INTEGER NOT NULL,
558
- detail_kind TEXT NOT NULL,
559
- payload_json TEXT NOT NULL,
560
- PRIMARY KEY (item_id, detail_seq)
561
- );
562
- ```
563
-
564
- ### 13.3 Projection cursor
565
-
566
- The materialized projection needs a cursor:
567
-
568
- ```sql
569
- CREATE TABLE _eda_ui_projection_metadata (
570
- id TEXT PRIMARY KEY,
571
- through_seq INTEGER NOT NULL,
572
- projection_version INTEGER NOT NULL,
573
- updated_at_ms INTEGER NOT NULL
574
- );
575
- ```
576
-
577
- Snapshot responses expose `projectionThroughSeq` so clients know exactly what the page represents.
578
-
579
- ## 14. Where projection runs
580
-
581
- There are two related concerns.
582
-
583
- ### 14.1 Live projection
584
-
585
- For active sessions, `SessionState` can maintain small in-memory UI projection state for current/active roots. This supports fast live snapshots and coalesced ephemeral reconnect state.
586
-
587
- ### 14.2 Durable materialized projection
588
-
589
- For pagination and old roots, a cursor-backed projection runner should materialize `_eda_ui_items` by folding durable events through registered pure UI reducers.
590
-
591
- This should follow EDA's sink principle:
592
-
593
- - do not run arbitrary app side effects inline on the append path;
594
- - use durable cursor semantics;
595
- - expose `projectionThroughSeq`;
596
- - use idempotent reducer operations.
597
-
598
- Because UI reducers are pure and local, a later implementation may choose an optimized core path for framework-owned projections. The design should not require app-specific SQL or app-specific pagination logic.
599
-
600
- ## 15. Consistency model
601
-
602
- The projection is a read model, so it has a checkpoint.
603
-
604
- - `durableHeadSeq`: latest committed durable event.
605
- - `projectionThroughSeq`: latest durable event folded into the UI projection page.
606
-
607
- If projection lags durable head, the server has two safe options:
608
-
609
- 1. wait briefly for projection catch-up before answering; or
610
- 2. return the snapshot at `projectionThroughSeq` and start live patching from that sequence.
611
-
612
- Clients must treat patches as idempotent by `itemId` + `updatedSeq`.
613
-
614
- ## 16. React hook shape
615
-
616
- The UI hook should not expose EDA internals directly.
617
-
618
- ```ts
619
- const session = useEDASessionUI({
620
- sessionId,
621
- latestRoots: 50,
622
- });
623
-
624
- session.roots;
625
- session.itemsByRoot;
626
- session.active;
627
- session.loadOlder();
628
- session.connectionStatus;
629
- session.submitMessage(...);
630
- session.stopTurn(...);
631
- ```
632
-
633
- The hook owns:
634
-
635
- - initial snapshot load;
636
- - WebSocket subscription;
637
- - cursor pagination;
638
- - idempotent patch application;
639
- - scroll anchoring for older-page insertion;
640
- - new-activity indicator when user is not at bottom.
641
-
642
- Rendering components consume projection items, not raw events.
643
-
644
- ## 17. Proposed implementation phases
645
-
646
- ### Phase 0: agreement and types
647
-
648
- - Land this design document.
649
- - Define `EDAUIItem`, `EDAUIPage`, `EDAUISnapshot`, `EDAUIPatch` schemas under `effect-durable-agent/`.
650
- - Define pure reducer interfaces and operation types.
651
-
652
- ### Phase 1: minimal latest snapshot
653
-
654
- - Implement `getUiSnapshot({ latestRoots })` for latest committed transcript roots.
655
- - Include active overlay for current assistant draft/reasoning/tool params.
656
- - Keep raw event replay out of the browser.
657
-
658
- ### Phase 2: generic projection reducers
659
-
660
- - Add framework reducers for:
661
- - user message roots;
662
- - assistant turn roots;
663
- - assistant text/reasoning children;
664
- - tool-call children;
665
- - compaction/recovery notices.
666
- - Add Gia reducer for authoritative E2B sandbox identity.
667
- - Add tests proving root-child all-or-zero pages.
668
-
669
- ### Phase 3: older page query
670
-
671
- - Implement `getUiPage({ beforeAnchorSeq, limit })`.
672
- - Select roots first, then descendants.
673
- - Preserve scroll position when prepending older pages.
674
-
675
- ### Phase 4: live patches
676
-
677
- - Implement `subscribeUi({ afterSeq })`.
678
- - Convert durable events and ephemerals into UI patches.
679
- - Coalesce ephemeral text/reasoning/tool-param state for reconnect snapshots.
680
-
681
- ### Phase 5: materialized UI projection table
682
-
683
- - Add `_eda_ui_items` and projection cursor.
684
- - Add projection catch-up runner using the same reducer registry.
685
- - Use table-backed pagination for long sessions.
686
-
687
- ### Phase 6: details and large payloads
688
-
689
- - Add `getUiItemDetails`.
690
- - Move large stdout/stderr/tool-result bodies out of transcript cards.
691
- - Add UI affordances for expanding detail panels.
692
-
693
- ## 18. Test plan
694
-
695
- ### 18.1 Pure reducer tests
696
-
697
- - Tool lifecycle folds into one tool card.
698
- - Completed/failed/cancelled tool terminals update status idempotently.
699
- - Unknown custom event leaves state unchanged.
700
-
701
- ### 18.2 Pagination tests
702
-
703
- - Latest page includes selected roots and all descendants.
704
- - Older page includes selected roots and all descendants.
705
- - No child item is returned when its root is outside the page.
706
- - Cursor pagination is stable when newer live events arrive.
707
-
708
- ### 18.3 Live patch tests
709
-
710
- - Text deltas append to active draft.
711
- - Reconnect snapshot includes coalesced draft when live state exists.
712
- - `AssistantMessageCommitted` retires draft and creates committed item.
713
- - Stale patches are ignored by `updatedSeq`.
714
-
715
- ### 18.4 Custom app event tests
716
-
717
- - Gia `SandboxCreated` updates authoritative E2B sandbox identity idempotently.
718
- - E2B sandbox identity does not create a separate transcript command card.
719
- - Unknown Gia app events leave projected transcript state unchanged.
720
-
721
- ### 18.5 Recovery tests
722
-
723
- - Restart during streaming does not fabricate lost ephemeral text.
724
- - Durable `AssistantPartialCommitted` appears as a committed partial item.
725
- - Open tool work receives durable cancellation/recovery explanation.
726
-
727
- ## 19. Open questions
728
-
729
- 1. Should `_eda_ui_items` be introduced immediately, or should v0 compute latest pages from existing message rows and live state first?
730
- 2. How much projection catch-up lag is acceptable before `getUiSnapshot` waits?
731
- 3. Should assistant turn be the root for all assistant-side process cards, or should final assistant messages be roots with sibling process groups?
732
- 4. What is the first detail API shape for tool-result stdout/stderr?
733
- 5. Should UI reducers live in `effect-durable-agent/services/` or a new `ui/` boundary?
734
- 6. How do projection versions migrate when reducer payload schemas change?
735
-
736
- ## 20. Summary
737
-
738
- EDA's durable event log remains the source of truth. The browser should not page or reduce raw events.
739
-
740
- The UI should page complete server-projected transcript roots. Each page selects roots first and returns all descendants for those roots, which prevents cross-page lifecycle tears. Custom app events participate by registering pure UI reducers that emit generic projection operations. Ephemeral text deltas remain live-only patches to active draft items and become durable/pageable only when EDA commits assistant message events.
741
-
742
- This gives Gia a UI model that is efficient for long sessions, compatible with compaction, safe for custom lifecycle events, and still faithful to EDA's durable/ephemeral architecture.