effect-agent 0.1.0-beta.164 → 0.1.0-beta.165

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 (285) hide show
  1. package/dist/{Admin-Vhz6NdaH.d.mts → Admin-CbwoQEm8.d.mts} +24 -24
  2. package/dist/{Agent-BMATXYsI.mjs → Agent-B0WrUcHy.mjs} +9 -9
  3. package/dist/Agent-B0WrUcHy.mjs.map +1 -0
  4. package/dist/{Agent-ZfnNCQXs.d.mts → Agent-D0fbFT2d.d.mts} +27 -24
  5. package/dist/{AgentError-Bn1ytXRD.d.mts → AgentError-BMqPzIVt.d.mts} +3 -3
  6. package/dist/{AgentPolicy-B4oH8TbG.d.mts → AgentPolicy-CclAEpHn.d.mts} +2 -2
  7. package/dist/{AgentRuntime-D1MmB_0z.d.mts → AgentRuntime-BM36roNi.d.mts} +44 -30
  8. package/dist/{AgentRuntime-Q50HloUc.mjs → AgentRuntime-BTfPyMXN.mjs} +91 -30
  9. package/dist/AgentRuntime-BTfPyMXN.mjs.map +1 -0
  10. package/dist/{AgentUpdates-DMJ-_xow.d.mts → AgentUpdates-DksV4D0A.d.mts} +6 -3
  11. package/dist/{ContextCompactor-BoKQOjr5.d.mts → ContextCompactor-DLpX-HUG.d.mts} +18 -12
  12. package/dist/{ContextWindow-DRQ5Mbm2.d.mts → ContextWindow-aGZOPIPq.d.mts} +24 -22
  13. package/dist/{Digest-COAt3Orl.d.mts → Digest-3l_02jaM.d.mts} +2 -2
  14. package/dist/{DurableAgentRuntime-BTMOgDl_.mjs → DurableAgentRuntime-CWmWREPj.mjs} +11 -11
  15. package/dist/{DurableAgentRuntime-BTMOgDl_.mjs.map → DurableAgentRuntime-CWmWREPj.mjs.map} +1 -1
  16. package/dist/{DurableStep-Cry_iol4.d.mts → DurableStep-CTqx6DOV.d.mts} +13 -11
  17. package/dist/{EventSource-CtS0RBM7.d.mts → EventSource-D29Jsj5U.d.mts} +3 -3
  18. package/dist/{FailureDiagnostic-BElLOoED.mjs → FailureDiagnostic-D9oW23Cn.mjs} +16 -10
  19. package/dist/FailureDiagnostic-D9oW23Cn.mjs.map +1 -0
  20. package/dist/{FailureDiagnostic-CaAkzGHL.d.mts → FailureDiagnostic-DvHruCSJ.d.mts} +10 -9
  21. package/dist/InMemory.d.mts +28 -5
  22. package/dist/InMemory.mjs +37 -4
  23. package/dist/InMemory.mjs.map +1 -1
  24. package/dist/{Messaging-CICd_CSi.d.mts → Messaging-BbuaphiQ.d.mts} +6 -6
  25. package/dist/{Messaging-7VXQnWI3.d.mts → Messaging-DF_IWnxV.d.mts} +5 -5
  26. package/dist/{MessagingHost-DXwWnrMh.d.mts → MessagingHost-Bfbfkx6f.d.mts} +13 -12
  27. package/dist/{MessagingHost-DfsbMPvq.mjs → MessagingHost-DJZJZILu.mjs} +4 -3
  28. package/dist/MessagingHost-DJZJZILu.mjs.map +1 -0
  29. package/dist/{Output-CY7NZByV.d.mts → Output-UsQKiPhz.d.mts} +4 -4
  30. package/dist/{PreparedInputAdmission-CS_zlCvD.d.mts → PreparedInputAdmission-DXvjTe4U.d.mts} +6 -6
  31. package/dist/{Receipt-BAHyigAF.d.mts → Receipt-BkM21Qiu.d.mts} +2 -2
  32. package/dist/{Records-Bm4Qt70a.d.mts → Records-CAQktL0z.d.mts} +8 -8
  33. package/dist/{RunEvent-D0aepYwN.d.mts → RunEvent-B3CRIqIC.d.mts} +5 -5
  34. package/dist/{RunEventSink-9CUdI9Ar.d.mts → RunEventSink-sDXDkrAl.d.mts} +9 -7
  35. package/dist/{RunJournal-D8Vvf_io.mjs → RunJournal-NRgq1PNe.mjs} +3 -3
  36. package/dist/{RunJournal-D8Vvf_io.mjs.map → RunJournal-NRgq1PNe.mjs.map} +1 -1
  37. package/dist/{RunOptions-BHmBa05n.d.mts → RunOptions-CkSZSuIh.d.mts} +87 -83
  38. package/dist/{RunPolicyUsage-CUudVtg_.d.mts → RunPolicyUsage-QmYVw9z8.d.mts} +2 -2
  39. package/dist/{Schedule-Bi_XVKLF.d.mts → Schedule-rEIiYnRq.d.mts} +4 -4
  40. package/dist/{Subagent-Cxvuaius.mjs → Subagent-C-fyHbcp.mjs} +5 -5
  41. package/dist/{Subagent-Cxvuaius.mjs.map → Subagent-C-fyHbcp.mjs.map} +1 -1
  42. package/dist/{Subagent-D59om8SR.d.mts → Subagent-t3pJDZMN.d.mts} +15 -15
  43. package/dist/{SubagentContract-tyN9v-Jv.d.mts → SubagentContract-DdPzxYQj.d.mts} +3 -2
  44. package/dist/{SubagentHost-VTyf_wEF.d.mts → SubagentHost-CXFlEpj0.d.mts} +19 -16
  45. package/dist/{Subscription-nbSNY6Hs.d.mts → Subscription-BJj-R-6V.d.mts} +8 -8
  46. package/dist/{SubscriptionInput-DbXnOMS2.d.mts → SubscriptionInput-DyQtODg2.d.mts} +3 -3
  47. package/dist/Thread-DT8RTLIQ.d.mts +117 -0
  48. package/dist/{ThreadHistory-FD-o4TsR.d.mts → ThreadHistory-DQ-IC1hU.d.mts} +12 -9
  49. package/dist/{ToolBroker-DWs4tZra.d.mts → ToolBroker-DXwv2aUT.d.mts} +14 -12
  50. package/dist/{ToolExposure-UCN12eCd.d.mts → ToolExposure-BsaSH15e.d.mts} +5 -4
  51. package/dist/{ToolExposure-r2eOWk4F.d.mts → ToolExposure-Ckg3-sTf.d.mts} +3 -2
  52. package/dist/{ToolExposure-9uF_Yo0T.mjs → ToolExposure-DBATXxmL.mjs} +2 -2
  53. package/dist/ToolExposure-DBATXxmL.mjs.map +1 -0
  54. package/dist/{ToolExposure-C93U1sPu.mjs → ToolExposure-hTJT2ekj.mjs} +3 -2
  55. package/dist/ToolExposure-hTJT2ekj.mjs.map +1 -0
  56. package/dist/ToolExposure.d.mts +2 -2
  57. package/dist/ToolExposure.mjs +2 -2
  58. package/dist/{ToolResult-BKdqWRff.d.mts → ToolResult-DqyEhJLF.d.mts} +2 -2
  59. package/dist/{Usage-BNjPR7Zr.d.mts → Usage-CzZJ6A2n.d.mts} +3 -2
  60. package/dist/{Worker-XEBYxRQv.d.mts → Worker-DH5SAVIK.d.mts} +7 -7
  61. package/dist/{Worker-CfwzMZEK.mjs → Worker-DZjdMjZn.mjs} +3 -3
  62. package/dist/Worker-DZjdMjZn.mjs.map +1 -0
  63. package/dist/{WorkerAdmission-BVbSB8_A.mjs → WorkerAdmission-DJ76C2b-.mjs} +4 -4
  64. package/dist/{WorkerAdmission-BVbSB8_A.mjs.map → WorkerAdmission-DJ76C2b-.mjs.map} +1 -1
  65. package/dist/{agent-registration-BIOzAej4.mjs → agent-registration-D1dWV7KK.mjs} +3 -3
  66. package/dist/{agent-registration-BIOzAej4.mjs.map → agent-registration-D1dWV7KK.mjs.map} +1 -1
  67. package/dist/capabilities/BrowserUse.d.mts +1 -1
  68. package/dist/capabilities/BrowserUse.mjs +1 -1
  69. package/dist/capabilities/CodeMode.d.mts +2 -2
  70. package/dist/capabilities/CodeMode.mjs +3 -3
  71. package/dist/capabilities/Commands.d.mts +1 -1
  72. package/dist/capabilities/ContextTools.d.mts +2 -2
  73. package/dist/capabilities/ContextTools.mjs +1 -1
  74. package/dist/capabilities/Mcp.d.mts +1 -1
  75. package/dist/capabilities/Mcp.mjs +1 -1
  76. package/dist/capabilities/McpClient.d.mts +1 -1
  77. package/dist/capabilities/McpClient.mjs +1 -1
  78. package/dist/capabilities/MemoryNotes.d.mts +2 -2
  79. package/dist/capabilities/MemoryNotes.mjs +1 -1
  80. package/dist/capabilities/Messaging.d.mts +2 -2
  81. package/dist/capabilities/Messaging.mjs +3 -3
  82. package/dist/capabilities/ModelContext.d.mts +1 -1
  83. package/dist/capabilities/Redaction.d.mts +1 -1
  84. package/dist/capabilities/RunHooks.d.mts +7 -6
  85. package/dist/capabilities/RunHooks.mjs +2 -1
  86. package/dist/capabilities/RunHooks.mjs.map +1 -1
  87. package/dist/capabilities/SemanticMemory.d.mts +1 -1
  88. package/dist/capabilities/SemanticMemory.mjs +1 -1
  89. package/dist/capabilities/Subagent.d.mts +3 -3
  90. package/dist/capabilities/Subagent.mjs +2 -2
  91. package/dist/capabilities/SubagentReservations.d.mts +64 -60
  92. package/dist/capabilities/SubagentReservations.mjs +6 -1
  93. package/dist/capabilities/SubagentReservations.mjs.map +1 -1
  94. package/dist/capabilities/ToolDiscovery.d.mts +2 -2
  95. package/dist/capabilities/ToolDiscovery.mjs +3 -3
  96. package/dist/capabilities/WebCapture.d.mts +1 -1
  97. package/dist/capabilities/WebCapture.mjs +1 -1
  98. package/dist/capabilities/WebSearch.d.mts +1 -1
  99. package/dist/capabilities/WebSearch.mjs +1 -1
  100. package/dist/{compaction-BQK4MUg3.mjs → compaction-FDJhjbzH.mjs} +4 -3
  101. package/dist/compaction-FDJhjbzH.mjs.map +1 -0
  102. package/dist/core/Agent.d.mts +1 -1
  103. package/dist/core/Agent.mjs +1 -1
  104. package/dist/core/AgentError.d.mts +1 -1
  105. package/dist/core/AgentError.mjs +4 -4
  106. package/dist/core/AgentError.mjs.map +1 -1
  107. package/dist/core/AgentPolicy.d.mts +1 -1
  108. package/dist/core/AgentUpdates.d.mts +1 -1
  109. package/dist/core/AgentUpdates.mjs +5 -1
  110. package/dist/core/AgentUpdates.mjs.map +1 -1
  111. package/dist/core/FailureDiagnostic.d.mts +1 -1
  112. package/dist/core/FailureDiagnostic.mjs +1 -1
  113. package/dist/core/IdGenerator.d.mts +3 -1
  114. package/dist/core/IdGenerator.mjs +8 -5
  115. package/dist/core/IdGenerator.mjs.map +1 -1
  116. package/dist/core/Receipt.d.mts +1 -1
  117. package/dist/core/Receipt.mjs +1 -1
  118. package/dist/core/Receipt.mjs.map +1 -1
  119. package/dist/core/RunEvent.d.mts +1 -1
  120. package/dist/core/RunEvent.mjs +2 -2
  121. package/dist/core/RunEvent.mjs.map +1 -1
  122. package/dist/core/RunPolicyUsage.d.mts +1 -1
  123. package/dist/core/RunPolicyUsage.mjs +1 -1
  124. package/dist/core/RunPolicyUsage.mjs.map +1 -1
  125. package/dist/core/SubagentContract.d.mts +1 -1
  126. package/dist/core/SubagentContract.mjs +2 -1
  127. package/dist/core/SubagentContract.mjs.map +1 -1
  128. package/dist/core/Thread.d.mts +2 -2
  129. package/dist/core/Thread.mjs +82 -33
  130. package/dist/core/Thread.mjs.map +1 -1
  131. package/dist/core/ToolResult.d.mts +1 -1
  132. package/dist/core/ToolResult.mjs +1 -1
  133. package/dist/core/ToolResult.mjs.map +1 -1
  134. package/dist/core/Usage.d.mts +1 -1
  135. package/dist/core/Usage.mjs +2 -1
  136. package/dist/core/Usage.mjs.map +1 -1
  137. package/dist/core/Worker.d.mts +2 -2
  138. package/dist/core/Worker.mjs +1 -1
  139. package/dist/durable/ActivityStore.d.mts +1 -1
  140. package/dist/durable/Admin.d.mts +1 -1
  141. package/dist/durable/AgentRegistration.d.mts +1 -1
  142. package/dist/durable/AgentRegistration.mjs +1 -1
  143. package/dist/durable/Certification.d.mts +1 -1
  144. package/dist/durable/CommittedActivity.d.mts +3 -3
  145. package/dist/durable/Digest.d.mts +1 -1
  146. package/dist/durable/DurableAgentRuntime.d.mts +2 -2
  147. package/dist/durable/DurableAgentRuntime.mjs +2 -2
  148. package/dist/durable/EventSource.d.mts +1 -1
  149. package/dist/durable/GitHubWorkflowSource.d.mts +4 -4
  150. package/dist/durable/GitHubWorkflowSource.mjs +1 -1
  151. package/dist/durable/LifecyclePublication.d.mts +1 -1
  152. package/dist/durable/LifecyclePublication.mjs +1 -1
  153. package/dist/durable/MessageDelivery.d.mts +9 -9
  154. package/dist/durable/MessageDelivery.mjs +2 -2
  155. package/dist/durable/MessageDeliveryStoreConformance.d.mts +28 -28
  156. package/dist/durable/MessageDeliveryStoreConformance.mjs +1 -1
  157. package/dist/durable/PersistentHistory.d.mts +2 -2
  158. package/dist/durable/PersistentHistory.mjs +2 -2
  159. package/dist/durable/PreparedInputAdmission.d.mts +1 -1
  160. package/dist/durable/PreparedInputAdmission.mjs +1 -1
  161. package/dist/durable/Records.d.mts +1 -1
  162. package/dist/durable/Records.mjs +5 -5
  163. package/dist/durable/Recovery.d.mts +1 -1
  164. package/dist/durable/RunJournal.d.mts +1 -1
  165. package/dist/durable/RunJournal.mjs +1 -1
  166. package/dist/durable/Schedule.d.mts +1 -1
  167. package/dist/durable/Schedule.mjs +1 -1
  168. package/dist/durable/ScheduleStoreConformance.d.mts +1 -1
  169. package/dist/durable/ScheduleTransition.d.mts +1 -1
  170. package/dist/durable/Scheduling.d.mts +4 -4
  171. package/dist/durable/SubmissionLedger.d.mts +2 -2
  172. package/dist/durable/SubmissionLedger.mjs +3 -3
  173. package/dist/durable/SubmissionLedgerConformance.d.mts +2 -2
  174. package/dist/durable/SubmissionLedgerConformance.mjs +3 -3
  175. package/dist/durable/SubmissionStatus.d.mts +1 -1
  176. package/dist/durable/Subscription.d.mts +1 -1
  177. package/dist/durable/Subscription.mjs +1 -1
  178. package/dist/durable/SubscriptionInput.d.mts +1 -1
  179. package/dist/durable/SubscriptionInput.mjs +1 -1
  180. package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
  181. package/dist/durable/SubscriptionTools.d.mts +7 -7
  182. package/dist/durable/SubscriptionTools.mjs +1 -1
  183. package/dist/durable/SubscriptionTransition.d.mts +1 -1
  184. package/dist/durable/Subscriptions.d.mts +7 -7
  185. package/dist/durable/ThreadContextHistory.d.mts +1 -1
  186. package/dist/durable/ThreadContextHistoryProjection.d.mts +1 -1
  187. package/dist/durable/ThreadContextHistoryProjection.mjs +2 -2
  188. package/dist/durable/ThreadInvariants.d.mts +2 -2
  189. package/dist/durable/ThreadInvariants.mjs +1 -1
  190. package/dist/durable/ThreadProjection.d.mts +1 -1
  191. package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
  192. package/dist/durable/ThreadStore.d.mts +1 -1
  193. package/dist/durable/ThreadStore.mjs +1 -1
  194. package/dist/durable/ThreadStoreConformance.d.mts +1 -1
  195. package/dist/durable/ThreadStoreConformance.mjs +1 -1
  196. package/dist/durable/WorkerAdmission.d.mts +6 -6
  197. package/dist/durable/WorkerAdmission.mjs +1 -1
  198. package/dist/durable/WorkerHost.d.mts +7 -7
  199. package/dist/durable/WorkerHost.mjs +1 -1
  200. package/dist/engine/AgentRuntime.d.mts +1 -1
  201. package/dist/engine/AgentRuntime.mjs +1 -1
  202. package/dist/engine/Compaction.d.mts +1 -1
  203. package/dist/engine/Compaction.mjs +1 -1
  204. package/dist/engine/ContextCompactor.d.mts +1 -1
  205. package/dist/engine/ContextCompactor.mjs +8 -3
  206. package/dist/engine/ContextCompactor.mjs.map +1 -1
  207. package/dist/engine/ContextWindow.d.mts +1 -1
  208. package/dist/engine/ContextWindow.mjs +3 -1
  209. package/dist/engine/ContextWindow.mjs.map +1 -1
  210. package/dist/engine/DurableStep.d.mts +1 -1
  211. package/dist/engine/DurableStep.mjs +2 -1
  212. package/dist/engine/DurableStep.mjs.map +1 -1
  213. package/dist/engine/MessagingHost.d.mts +1 -1
  214. package/dist/engine/MessagingHost.mjs +1 -1
  215. package/dist/engine/Output.d.mts +1 -1
  216. package/dist/engine/Output.mjs +1 -1
  217. package/dist/engine/RunEventSink.d.mts +1 -1
  218. package/dist/engine/RunEventSink.mjs +2 -1
  219. package/dist/engine/RunEventSink.mjs.map +1 -1
  220. package/dist/engine/RunOptions.d.mts +1 -1
  221. package/dist/engine/RunOptions.mjs +5 -2
  222. package/dist/engine/RunOptions.mjs.map +1 -1
  223. package/dist/engine/SubagentHost.d.mts +1 -1
  224. package/dist/engine/SubagentHost.mjs +4 -2
  225. package/dist/engine/SubagentHost.mjs.map +1 -1
  226. package/dist/engine/ThreadHistory.d.mts +1 -1
  227. package/dist/engine/ThreadHistory.mjs +12 -10
  228. package/dist/engine/ThreadHistory.mjs.map +1 -1
  229. package/dist/engine/ToolBroker.d.mts +1 -1
  230. package/dist/engine/ToolBroker.mjs +2 -1
  231. package/dist/engine/ToolBroker.mjs.map +1 -1
  232. package/dist/index.d.mts +34 -34
  233. package/dist/index.mjs +9 -9
  234. package/dist/{output-contract-DS-S8mTv.mjs → output-contract-DUNIO6as.mjs} +4 -3
  235. package/dist/output-contract-DUNIO6as.mjs.map +1 -0
  236. package/package.json +1 -1
  237. package/src/InMemory.ts +61 -2
  238. package/src/capabilities/RunHooks.ts +6 -3
  239. package/src/capabilities/SubagentReservations.ts +7 -1
  240. package/src/core/Agent.ts +3 -8
  241. package/src/core/AgentError.ts +1 -1
  242. package/src/core/AgentUpdates.ts +5 -1
  243. package/src/core/FailureDiagnostic.ts +6 -8
  244. package/src/core/IdGenerator.ts +5 -2
  245. package/src/core/Messaging.ts +1 -1
  246. package/src/core/Receipt.ts +1 -1
  247. package/src/core/RunEvent.ts +1 -1
  248. package/src/core/RunPolicyUsage.ts +1 -1
  249. package/src/core/SubagentContract.ts +2 -1
  250. package/src/core/Thread.ts +163 -61
  251. package/src/core/ToolExposure.ts +2 -1
  252. package/src/core/ToolResult.ts +1 -1
  253. package/src/core/Usage.ts +2 -1
  254. package/src/core/Worker.ts +1 -1
  255. package/src/core/internal/agent-updates.ts +3 -2
  256. package/src/core/internal/message-status.ts +1 -1
  257. package/src/core/internal/strict-schema.ts +3 -1
  258. package/src/engine/ContextCompactor.ts +8 -2
  259. package/src/engine/ContextWindow.ts +4 -1
  260. package/src/engine/DurableStep.ts +2 -1
  261. package/src/engine/MessagingHost.ts +2 -1
  262. package/src/engine/RunEventSink.ts +2 -1
  263. package/src/engine/RunOptions.ts +5 -1
  264. package/src/engine/SubagentHost.ts +3 -1
  265. package/src/engine/ThreadHistory.ts +20 -10
  266. package/src/engine/ToolBroker.ts +2 -1
  267. package/src/engine/ToolExposure.ts +2 -1
  268. package/src/engine/internal/agent-runtime.ts +41 -49
  269. package/src/engine/internal/bounded-value.ts +2 -1
  270. package/src/engine/internal/compaction.ts +3 -2
  271. package/src/engine/internal/output-contract.ts +3 -2
  272. package/src/engine/internal/primitive-delta.ts +51 -10
  273. package/src/engine/internal/tool-derivative.ts +5 -1
  274. package/src/engine/internal/tool-exposure.ts +5 -2
  275. package/src/engine/internal/tool-telemetry.ts +12 -13
  276. package/dist/Agent-BMATXYsI.mjs.map +0 -1
  277. package/dist/AgentRuntime-Q50HloUc.mjs.map +0 -1
  278. package/dist/FailureDiagnostic-BElLOoED.mjs.map +0 -1
  279. package/dist/MessagingHost-DfsbMPvq.mjs.map +0 -1
  280. package/dist/Thread-DOBQ0QUY.d.mts +0 -96
  281. package/dist/ToolExposure-9uF_Yo0T.mjs.map +0 -1
  282. package/dist/ToolExposure-C93U1sPu.mjs.map +0 -1
  283. package/dist/Worker-CfwzMZEK.mjs.map +0 -1
  284. package/dist/compaction-BQK4MUg3.mjs.map +0 -1
  285. package/dist/output-contract-DS-S8mTv.mjs.map +0 -1
@@ -1,11 +1,9 @@
1
- import {
2
- Cause as EffectCause,
3
- Exit,
4
- Predicate,
5
- Redacted,
6
- Schema,
7
- SchemaTransformation,
8
- } from "effect";
1
+ import * as EffectCause from "effect/Cause";
2
+ import * as Exit from "effect/Exit";
3
+ import * as Predicate from "effect/Predicate";
4
+ import * as Redacted from "effect/Redacted";
5
+ import * as Schema from "effect/Schema";
6
+ import * as SchemaTransformation from "effect/SchemaTransformation";
9
7
 
10
8
  import { strictSchema } from "./internal/strict-schema.ts";
11
9
 
@@ -1,5 +1,8 @@
1
- import { Context, Effect, Layer, Schema } from "effect";
2
- import { IdGenerator as EffectAiIdGenerator } from "effect/unstable/ai";
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Schema from "effect/Schema";
5
+ import * as EffectAiIdGenerator from "effect/unstable/ai/IdGenerator";
3
6
 
4
7
  import { ThreadId, RunId, TurnId } from "./Identifiers.ts";
5
8
 
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import * as Schema from "effect/Schema";
2
2
 
3
3
  import { AgentId, ThreadId } from "./Identifiers.ts";
4
4
  import { MessageRef } from "./internal/message-status.ts";
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import * as Schema from "effect/Schema";
2
2
 
3
3
  import { ReceiptId, SubmissionId, ThreadId } from "./Identifiers.ts";
4
4
 
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import * as Schema from "effect/Schema";
2
2
 
3
3
  import { Update } from "./AgentUpdates.ts";
4
4
  import { AgentId, ThreadId, DelegationId, RunId, ToolCallId, TurnId } from "./Identifiers.ts";
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import * as Schema from "effect/Schema";
2
2
 
3
3
  /**
4
4
  * Cumulative policy accounting for one logical Run across replacement Attempts.
@@ -1,4 +1,5 @@
1
- import { Context, Schema } from "effect";
1
+ import * as Context from "effect/Context";
2
+ import * as Schema from "effect/Schema";
2
3
 
3
4
  import { AgentId, ThreadId, DelegationId, RunId, ToolCallId, SubmissionId } from "./Identifiers.ts";
4
5
 
@@ -1,5 +1,12 @@
1
- import { Clock, Context, DateTime, Effect, Layer, Schema, SynchronizedRef } from "effect";
2
- import { Prompt } from "effect/unstable/ai";
1
+ import type { Scope } from "effect";
2
+ import * as Clock from "effect/Clock";
3
+ import * as Context from "effect/Context";
4
+ import * as DateTime from "effect/DateTime";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Layer from "effect/Layer";
7
+ import * as Schema from "effect/Schema";
8
+ import * as SynchronizedRef from "effect/SynchronizedRef";
9
+ import * as Prompt from "effect/unstable/ai/Prompt";
3
10
 
4
11
  import { ThreadId, RunId } from "./Identifiers.ts";
5
12
  import { utf8ByteLength } from "./internal/utf8.ts";
@@ -77,11 +84,18 @@ export class ThreadEncodingError extends Schema.TaggedError<ThreadEncodingError>
77
84
  { threadId: ThreadId, message: Schema.String },
78
85
  ) {}
79
86
 
87
+ /** A scoped view cannot access another owner's history or be used after closure. */
88
+ export class ThreadOwnershipError extends Schema.TaggedError<ThreadOwnershipError>()(
89
+ "ThreadOwnershipError",
90
+ { threadId: ThreadId, reason: Schema.Literals(["closed", "foreign"]), message: Schema.String },
91
+ ) {}
92
+
80
93
  export type ThreadError =
81
94
  | ThreadNotFound
82
95
  | ThreadLimitExceeded
83
96
  | ThreadHistoryDiverged
84
- | ThreadEncodingError;
97
+ | ThreadEncodingError
98
+ | ThreadOwnershipError;
85
99
 
86
100
  /** Reconstruct exact Effect AI Prompt history, including tools, reasoning, files, and options. */
87
101
  export const toPrompt = (snapshot: Thread): Prompt.Prompt =>
@@ -93,32 +107,51 @@ export const toPrompt = (snapshot: Thread): Prompt.Prompt =>
93
107
  * ThreadHistory.layer uses this store for ordinary Runs and interactive history.
94
108
  * Scope closure releases all in-memory state.
95
109
  */
96
- export class Store extends Context.Service<
97
- Store,
98
- {
99
- readonly create: (threadId: ThreadId) => Effect.Effect<Thread, ThreadLimitExceeded>;
100
- readonly append: (
101
- threadId: ThreadId,
102
- message: ThreadAppend,
103
- ) => Effect.Effect<Thread, ThreadNotFound | ThreadLimitExceeded | ThreadEncodingError>;
104
- /**
105
- * Record an engine-emitted full history only when it is an append-only
106
- * extension of the exact official Prompt already stored. The entire
107
- * suffix commits in one transaction or not at all: concurrent writers are
108
- * serialized, a writer whose history no longer extends the committed
109
- * official history fails with ThreadHistoryDiverged, and a limit
110
- * failure inside the suffix records nothing. Earlier updates remain committed if the Run
111
- * later fails or is interrupted; this transaction covers one update, not the whole Run.
112
- */
113
- readonly recordHistory: (
114
- threadId: ThreadId,
115
- runId: RunId,
116
- history: Prompt.Prompt,
117
- ) => Effect.Effect<Thread, ThreadError>;
118
- readonly snapshot: (threadId: ThreadId) => Effect.Effect<Thread, ThreadNotFound>;
119
- readonly export: (threadId: ThreadId) => Effect.Effect<ThreadExport, ThreadNotFound>;
120
- }
121
- >()("@effect-agent/capabilities/EphemeralThreads") {}
110
+ interface StoreService {
111
+ /**
112
+ * Acquire an isolated ownership view over this same bounded store. Newly created Threads
113
+ * belong to the supplied Scope; closing it releases only that view's Threads and bytes.
114
+ * Supplied by layerMemory; custom stores may omit this capability.
115
+ * The view rejects foreign IDs and all access after closure. Keep its Scope open through
116
+ * all users, including streams, child Runs, snapshots and history hooks.
117
+ */
118
+ readonly scoped?: Effect.Effect<StoreService, never, Scope.Scope>;
119
+ readonly create: (
120
+ threadId: ThreadId,
121
+ ) => Effect.Effect<Thread, ThreadLimitExceeded | ThreadOwnershipError>;
122
+ readonly append: (
123
+ threadId: ThreadId,
124
+ message: ThreadAppend,
125
+ ) => Effect.Effect<
126
+ Thread,
127
+ ThreadNotFound | ThreadLimitExceeded | ThreadEncodingError | ThreadOwnershipError
128
+ >;
129
+ /**
130
+ * Record an engine-emitted full history only when it is an append-only
131
+ * extension of the exact official Prompt already stored. The entire
132
+ * suffix commits in one transaction or not at all: concurrent writers are
133
+ * serialized, a writer whose history no longer extends the committed
134
+ * official history fails with ThreadHistoryDiverged, and a limit
135
+ * failure inside the suffix records nothing. Earlier updates remain committed if the Run
136
+ * later fails or is interrupted; this transaction covers one update, not the whole Run.
137
+ */
138
+ readonly recordHistory: (
139
+ threadId: ThreadId,
140
+ runId: RunId,
141
+ history: Prompt.Prompt,
142
+ ) => Effect.Effect<Thread, ThreadError>;
143
+ readonly snapshot: (
144
+ threadId: ThreadId,
145
+ ) => Effect.Effect<Thread, ThreadNotFound | ThreadOwnershipError>;
146
+ readonly export: (
147
+ threadId: ThreadId,
148
+ ) => Effect.Effect<ThreadExport, ThreadNotFound | ThreadOwnershipError>;
149
+ }
150
+
151
+ /** Process-local conversation store supplied by layerMemory. */
152
+ export class Store extends Context.Service<Store, StoreService>()(
153
+ "@effect-agent/capabilities/EphemeralThreads",
154
+ ) {}
122
155
 
123
156
  const encodeMessage = (
124
157
  threadId: ThreadId,
@@ -134,27 +167,71 @@ const encodeMessage = (
134
167
  ),
135
168
  );
136
169
 
137
- const findSnapshot = (
138
- state: ReadonlyMap<ThreadId, Thread>,
139
- threadId: ThreadId,
140
- ): Effect.Effect<Thread, ThreadNotFound> => {
141
- const snapshot = state.get(threadId);
170
+ interface Owner {
171
+ closed: boolean;
172
+ readonly parent?: Owner;
173
+ }
142
174
 
143
- return snapshot === undefined
144
- ? Effect.fail(ThreadNotFound.make({ threadId }))
145
- : Effect.succeed(snapshot);
146
- };
175
+ interface Entry {
176
+ readonly snapshot: Thread;
177
+ readonly owner: Owner;
178
+ }
147
179
 
148
- const totalStoreBytes = (threads: ReadonlyMap<ThreadId, Thread>): number => {
149
- let total = 0;
180
+ interface State {
181
+ readonly threads: ReadonlyMap<ThreadId, Entry>;
182
+ readonly contentBytes: number;
183
+ }
150
184
 
151
- for (const snapshot of threads.values()) total += snapshot.contentBytes;
185
+ const belongsTo = (owner: Owner, ancestor: Owner): boolean => {
186
+ for (let current: Owner | undefined = owner; current !== undefined; current = current.parent) {
187
+ if (current === ancestor) return true;
188
+ }
152
189
 
153
- return total;
190
+ return false;
154
191
  };
155
192
 
193
+ const access = (state: State, owner: Owner, threadId: ThreadId) => {
194
+ for (let current: Owner | undefined = owner; current !== undefined; current = current.parent) {
195
+ if (current.closed) {
196
+ return Effect.fail(
197
+ ThreadOwnershipError.make({
198
+ threadId,
199
+ reason: "closed",
200
+ message: "The in-memory conversation owner is closed",
201
+ }),
202
+ );
203
+ }
204
+ }
205
+ const entry = state.threads.get(threadId);
206
+
207
+ return entry !== undefined && entry.owner !== owner
208
+ ? Effect.fail(
209
+ ThreadOwnershipError.make({
210
+ threadId,
211
+ reason: "foreign",
212
+ message: "The Thread belongs to another in-memory conversation owner",
213
+ }),
214
+ )
215
+ : Effect.succeed(entry?.snapshot);
216
+ };
217
+
218
+ const findSnapshot = Effect.fnUntraced(function* (state: State, owner: Owner, threadId: ThreadId) {
219
+ const snapshot = yield* access(state, owner, threadId);
220
+
221
+ return snapshot === undefined ? yield* ThreadNotFound.make({ threadId }) : snapshot;
222
+ });
223
+
224
+ const put = (state: State, owner: Owner, snapshot: Thread): State => ({
225
+ threads: new Map(state.threads).set(snapshot.threadId, { snapshot, owner }),
226
+ contentBytes:
227
+ state.contentBytes +
228
+ snapshot.contentBytes -
229
+ (state.threads.get(snapshot.threadId)?.snapshot.contentBytes ?? 0),
230
+ });
231
+
156
232
  const appendEncoded = Effect.fn("Thread.Store.appendEncoded")(function* (
157
- threads: ReadonlyMap<ThreadId, Thread>,
233
+ state: State,
234
+ owner: Owner,
158
235
  current: Thread,
159
236
  append: ThreadAppend,
160
237
  encoded: string,
@@ -181,7 +258,7 @@ const appendEncoded = Effect.fn("Thread.Store.appendEncoded")(function* (
181
258
  observedValue: contentBytes,
182
259
  });
183
260
  }
184
- const storeBytes = totalStoreBytes(threads) + messageBytes;
261
+ const storeBytes = state.contentBytes + messageBytes;
185
262
 
186
263
  if (storeBytes > MAX_STORE_CONTENT_BYTES) {
187
264
  return yield* ThreadLimitExceeded.make({
@@ -209,31 +286,52 @@ const appendEncoded = Effect.fn("Thread.Store.appendEncoded")(function* (
209
286
  messages: [...current.messages, message],
210
287
  });
211
288
 
212
- return [next, new Map(threads).set(threadId, next)] as const;
289
+ return [next, put(state, owner, next)] as const;
213
290
  });
214
291
 
215
292
  /** In-memory storage shared for the consumer's Scope; it does not survive process loss. */
216
293
  export const layerMemory = Layer.effect(
217
294
  Store,
218
295
  Effect.gen(function* () {
219
- const state = yield* SynchronizedRef.make<ReadonlyMap<ThreadId, Thread>>(new Map());
220
-
221
- yield* Effect.addFinalizer(() => SynchronizedRef.set(state, new Map()));
222
-
223
- return Store.of({
296
+ const state = yield* SynchronizedRef.make<State>({ threads: new Map(), contentBytes: 0 });
297
+ const root: Owner = { closed: false };
298
+
299
+ const release = (owner: Owner) =>
300
+ SynchronizedRef.update(state, (current) => {
301
+ owner.closed = true;
302
+ const threads = new Map(current.threads);
303
+ let contentBytes = current.contentBytes;
304
+
305
+ for (const [id, entry] of threads) {
306
+ if (belongsTo(entry.owner, owner)) {
307
+ threads.delete(id);
308
+ contentBytes -= entry.snapshot.contentBytes;
309
+ }
310
+ }
311
+
312
+ return { threads, contentBytes };
313
+ });
314
+
315
+ yield* Effect.addFinalizer(() => release(root));
316
+
317
+ const view = (owner: Owner): StoreService => ({
318
+ scoped: Effect.acquireRelease(
319
+ Effect.sync((): Owner => ({ closed: false, parent: owner })),
320
+ release,
321
+ ).pipe(Effect.map(view)),
224
322
  create: (threadId) =>
225
323
  SynchronizedRef.modifyEffect(
226
324
  state,
227
325
  Effect.fn(function* (threads) {
228
- const existing = threads.get(threadId);
326
+ const existing = yield* access(threads, owner, threadId);
229
327
 
230
328
  if (existing !== undefined) return [existing, threads] as const;
231
- if (threads.size >= MAX_THREADS) {
329
+ if (threads.threads.size >= MAX_THREADS) {
232
330
  return yield* ThreadLimitExceeded.make({
233
331
  threadId,
234
332
  limit: "threads",
235
333
  limitValue: MAX_THREADS,
236
- observedValue: threads.size + 1,
334
+ observedValue: threads.threads.size + 1,
237
335
  });
238
336
  }
239
337
 
@@ -245,7 +343,7 @@ export const layerMemory = Layer.effect(
245
343
  messages: [],
246
344
  });
247
345
 
248
- return [created, new Map(threads).set(threadId, created)] as const;
346
+ return [created, put(threads, owner, created)] as const;
249
347
  }),
250
348
  ),
251
349
  append: Effect.fn("Thread.Store.append")(function* (threadId, message) {
@@ -255,9 +353,9 @@ export const layerMemory = Layer.effect(
255
353
  return yield* SynchronizedRef.modifyEffect(
256
354
  state,
257
355
  Effect.fn(function* (threads) {
258
- const current = yield* findSnapshot(threads, threadId);
356
+ const current = yield* findSnapshot(threads, owner, threadId);
259
357
 
260
- return yield* appendEncoded(threads, current, message, encoded, timestamp);
358
+ return yield* appendEncoded(threads, owner, current, message, encoded, timestamp);
261
359
  }),
262
360
  );
263
361
  }),
@@ -271,7 +369,7 @@ export const layerMemory = Layer.effect(
271
369
  return yield* SynchronizedRef.modifyEffect(
272
370
  state,
273
371
  Effect.fn(function* (threads) {
274
- const current = yield* findSnapshot(threads, threadId);
372
+ const current = yield* findSnapshot(threads, owner, threadId);
275
373
 
276
374
  const currentEncoded = yield* Effect.forEach(current.messages, (entry) =>
277
375
  encodeMessage(threadId, entry.message),
@@ -292,7 +390,7 @@ export const layerMemory = Layer.effect(
292
390
 
293
391
  const messages = [...current.messages];
294
392
  let contentBytes = current.contentBytes;
295
- let storeBytes = totalStoreBytes(threads);
393
+ let storeBytes = threads.contentBytes;
296
394
  let nextSequence = current.nextSequence;
297
395
 
298
396
  for (const entry of incoming.slice(currentEncoded.length)) {
@@ -349,16 +447,18 @@ export const layerMemory = Layer.effect(
349
447
  messages,
350
448
  });
351
449
 
352
- return [snapshot, new Map(threads).set(threadId, snapshot)] as const;
450
+ return [snapshot, put(threads, owner, snapshot)] as const;
353
451
  }),
354
452
  );
355
453
  },
356
454
  ),
357
455
  snapshot: (threadId) =>
358
- SynchronizedRef.get(state).pipe(Effect.flatMap((all) => findSnapshot(all, threadId))),
456
+ SynchronizedRef.get(state).pipe(
457
+ Effect.flatMap((all) => findSnapshot(all, owner, threadId)),
458
+ ),
359
459
  export: (threadId) =>
360
460
  Effect.gen(function* () {
361
- const snapshot = yield* findSnapshot(yield* SynchronizedRef.get(state), threadId);
461
+ const snapshot = yield* findSnapshot(yield* SynchronizedRef.get(state), owner, threadId);
362
462
 
363
463
  return ThreadExport.make({
364
464
  format: "effect-agent/ephemeral-thread@1",
@@ -367,5 +467,7 @@ export const layerMemory = Layer.effect(
367
467
  });
368
468
  }),
369
469
  });
470
+
471
+ return view(root);
370
472
  }),
371
473
  );
@@ -1,4 +1,5 @@
1
- import { Context, Schema } from "effect";
1
+ import * as Context from "effect/Context";
2
+ import * as Schema from "effect/Schema";
2
3
  import type { Tool } from "effect/unstable/ai";
3
4
 
4
5
  /** Registered native names only. Empty selection deliberately clears non-pinned Tools. */
@@ -1,5 +1,5 @@
1
1
  import * as Schema from "effect/Schema";
2
- import { AiError } from "effect/unstable/ai";
2
+ import * as AiError from "effect/unstable/ai/AiError";
3
3
 
4
4
  import { ToolCallId } from "./Identifiers.ts";
5
5
  import { codePointUtf8Length, utf8ByteLength } from "./internal/utf8.ts";
package/src/core/Usage.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Effect, Schema } from "effect";
1
+ import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
2
3
 
3
4
  import { RunId } from "./Identifiers.ts";
4
5
 
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import * as Schema from "effect/Schema";
2
2
 
3
3
  import { AgentPolicy } from "./AgentPolicy.ts";
4
4
  import { Update } from "./AgentUpdates.ts";
@@ -1,5 +1,6 @@
1
- import { Schema } from "effect";
2
- import { Tool, Toolkit } from "effect/unstable/ai";
1
+ import * as Schema from "effect/Schema";
2
+ import * as Tool from "effect/unstable/ai/Tool";
3
+ import * as Toolkit from "effect/unstable/ai/Toolkit";
3
4
 
4
5
  import { Emitter, UpdateError } from "../AgentUpdates.ts";
5
6
 
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import * as Schema from "effect/Schema";
2
2
 
3
3
  import { SettlementId, ThreadId } from "../Identifiers.ts";
4
4
  import { IdempotencyKey, Receipt } from "../Receipt.ts";
@@ -1,4 +1,6 @@
1
- import { Schema, SchemaParser, SchemaTransformation } from "effect";
1
+ import * as Schema from "effect/Schema";
2
+ import * as SchemaParser from "effect/SchemaParser";
3
+ import * as SchemaTransformation from "effect/SchemaTransformation";
2
4
 
3
5
  /** Keep strict parsing on nested values even when an outer parser uses its defaults. */
4
6
  export const strictSchema = <S extends Schema.Top>(schema: S) =>
@@ -1,5 +1,11 @@
1
- import { Context, Effect, Layer, Option, Schema, Stream } from "effect";
2
- import { type LanguageModel, type Model, Prompt } from "effect/unstable/ai";
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Option from "effect/Option";
5
+ import * as Schema from "effect/Schema";
6
+ import * as Stream from "effect/Stream";
7
+ import type { LanguageModel, Model } from "effect/unstable/ai";
8
+ import * as Prompt from "effect/unstable/ai/Prompt";
3
9
 
4
10
  import { type CompactionPolicy } from "../core/AgentPolicy.ts";
5
11
  import { type RunId, type ThreadId } from "../core/Identifiers.ts";
@@ -1,4 +1,7 @@
1
- import { Context, type Effect, Encoding, Schema } from "effect";
1
+ import type { Effect } from "effect";
2
+ import * as Context from "effect/Context";
3
+ import * as Encoding from "effect/Encoding";
4
+ import * as Schema from "effect/Schema";
2
5
 
3
6
  import { RunId, ThreadId } from "../core/Identifiers.ts";
4
7
 
@@ -1,5 +1,6 @@
1
- import { Context, Schema } from "effect";
2
1
  import type { Effect, Option } from "effect";
2
+ import * as Context from "effect/Context";
3
+ import * as Schema from "effect/Schema";
3
4
  import type { Tool } from "effect/unstable/ai";
4
5
 
5
6
  import { ToolCallId } from "../core/Identifiers.ts";
@@ -1,4 +1,5 @@
1
- import { Context, type Effect } from "effect";
1
+ import type { Effect } from "effect";
2
+ import * as Context from "effect/Context";
2
3
 
3
4
  import type { AnyDefinition } from "../core/Agent.ts";
4
5
  import type { ThreadId } from "../core/Identifiers.ts";
@@ -1,5 +1,6 @@
1
- import { Context, Schema } from "effect";
2
1
  import type { Effect } from "effect";
2
+ import * as Context from "effect/Context";
3
+ import * as Schema from "effect/Schema";
3
4
 
4
5
  import {
5
6
  type AgentId,
@@ -1,4 +1,8 @@
1
- import { type Cause, Effect, Context, type DateTime, Layer, Schema } from "effect";
1
+ import type { Cause, DateTime } from "effect";
2
+ import * as Context from "effect/Context";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Schema from "effect/Schema";
2
6
  import type { LanguageModel, Model, Prompt, Response } from "effect/unstable/ai";
3
7
 
4
8
  import { type AnyDefinition } from "../core/Agent.ts";
@@ -1,5 +1,7 @@
1
1
  import type { Effect, Option } from "effect";
2
- import { Context, Schema, Stream } from "effect";
2
+ import * as Context from "effect/Context";
3
+ import * as Schema from "effect/Schema";
4
+ import * as Stream from "effect/Stream";
3
5
 
4
6
  import type * as Agent from "../core/Agent.ts";
5
7
  import type { AgentPolicy } from "../core/AgentPolicy.ts";
@@ -1,4 +1,7 @@
1
- import { Context, Effect, Layer, Schema } from "effect";
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Schema from "effect/Schema";
2
5
  import type { Prompt } from "effect/unstable/ai";
3
6
 
4
7
  import { ThreadId, type RunId } from "../core/Identifiers.ts";
@@ -57,6 +60,8 @@ export class ThreadHistory extends Context.Service<
57
60
  ThreadHistory,
58
61
  {
59
62
  readonly retention: "incremental" | "on-success";
63
+ /** Present only for the in-memory adapter; identifies its exact Store ownership view. */
64
+ readonly memoryStore?: ConversationStore["Service"];
60
65
  readonly open: (request: {
61
66
  readonly threadId: ThreadId;
62
67
  readonly runId: RunId;
@@ -64,12 +69,8 @@ export class ThreadHistory extends Context.Service<
64
69
  readonly load: (threadId: ThreadId) => Effect.Effect<Prompt.Prompt, ThreadHistoryError>;
65
70
  }
66
71
  >()("@effect-agent/engine/ThreadHistory") {
67
- /**
68
- * Retain bounded in-memory history across Runs. Provide once around the application so
69
- * all Runs share the same store. The underlying Thread.Store service is exposed for
70
- * snapshots and interactive hooks; separate Layer builds own separate stores.
71
- */
72
- static readonly layer = Layer.effect(
72
+ /** Bind incremental history to the supplied Thread.Store, including scoped ownership views. */
73
+ static readonly layerFromStore = Layer.effect(
73
74
  ThreadHistory,
74
75
  Effect.gen(function* () {
75
76
  const threads = yield* ConversationStore;
@@ -84,7 +85,11 @@ export class ThreadHistory extends Context.Service<
84
85
  ? "limit"
85
86
  : cause._tag === "ThreadHistoryDiverged"
86
87
  ? "conflict"
87
- : "encoding",
88
+ : cause._tag === "ThreadOwnershipError"
89
+ ? cause.reason === "closed"
90
+ ? "fenced"
91
+ : "conflict"
92
+ : "encoding",
88
93
  message:
89
94
  cause._tag === "ThreadNotFound"
90
95
  ? "Thread history is not present in this application Scope"
@@ -96,6 +101,7 @@ export class ThreadHistory extends Context.Service<
96
101
 
97
102
  return ThreadHistory.of({
98
103
  retention: "incremental",
104
+ memoryStore: threads,
99
105
  load: (threadId) =>
100
106
  threads.snapshot(threadId).pipe(Effect.map(toPrompt), Effect.mapError(historyError)),
101
107
  open: Effect.fn("ThreadHistory.open")(function* ({ threadId, runId }) {
@@ -108,12 +114,16 @@ export class ThreadHistory extends Context.Service<
108
114
  threads
109
115
  .recordHistory(threadId, runId, history)
110
116
  .pipe(Effect.asVoid, Effect.mapError(historyError)),
111
- commit: () => Effect.void,
117
+ commit: () =>
118
+ threads.snapshot(threadId).pipe(Effect.asVoid, Effect.mapError(historyError)),
112
119
  };
113
120
  }),
114
121
  });
115
122
  }),
116
- ).pipe(Layer.provideMerge(layerMemory));
123
+ );
124
+
125
+ /** Retain bounded history for the application Scope. Separate Layer builds own separate stores. */
126
+ static readonly layer = ThreadHistory.layerFromStore.pipe(Layer.provideMerge(layerMemory));
117
127
  }
118
128
 
119
129
  /** Retain in-memory conversation history for the application Scope. */
@@ -1,5 +1,6 @@
1
1
  import type { Effect } from "effect";
2
- import { Context, Schema } from "effect";
2
+ import * as Context from "effect/Context";
3
+ import * as Schema from "effect/Schema";
3
4
  import type { Tool, Toolkit } from "effect/unstable/ai";
4
5
 
5
6
  /**
@@ -1,4 +1,5 @@
1
- import { Context, type Effect } from "effect";
1
+ import type { Effect } from "effect";
2
+ import * as Context from "effect/Context";
2
3
  import type { Tool } from "effect/unstable/ai";
3
4
 
4
5
  import type { RunId, ThreadId } from "../core/Identifiers.ts";