effect-agent 0.1.0-beta.9 → 0.1.0-beta.91

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 (538) hide show
  1. package/dist/Agent-CN0EWRsR.d.mts +226 -0
  2. package/dist/Agent-RklVROrm.mjs +83 -0
  3. package/dist/Agent-RklVROrm.mjs.map +1 -0
  4. package/dist/AgentError-CggcAQ7V.d.mts +101 -0
  5. package/dist/AgentPolicy-CetmQrf3.d.mts +96 -0
  6. package/dist/AgentRuntime-CHipL2jG.mjs +4598 -0
  7. package/dist/AgentRuntime-CHipL2jG.mjs.map +1 -0
  8. package/dist/AgentRuntime-uxR_a4VM.d.mts +346 -0
  9. package/dist/AgentUpdates-DMJ-_xow.d.mts +53 -0
  10. package/dist/ContextCompactor-Dxu5zhOL.d.mts +161 -0
  11. package/dist/ContextWindow-DRQ5Mbm2.d.mts +58 -0
  12. package/dist/DurableAgentRuntime-D7gDKGjH.mjs +6368 -0
  13. package/dist/DurableAgentRuntime-D7gDKGjH.mjs.map +1 -0
  14. package/dist/DurableFailpoint-Oinuuedm.d.mts +41 -0
  15. package/dist/DurableStep-Cry_iol4.d.mts +103 -0
  16. package/dist/Ephemeral.d.mts +22 -0
  17. package/dist/Ephemeral.mjs +22 -0
  18. package/dist/Ephemeral.mjs.map +1 -0
  19. package/dist/EventSource-OqS_P9ug.d.mts +51 -0
  20. package/dist/Identifiers-CN2s30fF.d.mts +40 -0
  21. package/dist/MemoryNamespace-BbRW5p71.d.mts +36 -0
  22. package/dist/MemoryReference-B8Q3UJoJ.d.mts +79 -0
  23. package/dist/Messaging-CkcIdt4I.d.mts +490 -0
  24. package/dist/MessagingHost-CRk0kXzT.d.mts +246 -0
  25. package/dist/MessagingHost-CWi_PP3g.mjs +137 -0
  26. package/dist/MessagingHost-CWi_PP3g.mjs.map +1 -0
  27. package/dist/OperationAuthorizer-TzcQtpX5.d.mts +61 -0
  28. package/dist/Output-D6SkedVx.d.mts +25 -0
  29. package/dist/PageCapture-Df8Xwskw.d.mts +583 -0
  30. package/dist/PageScreenshot-BpgZKAxl.d.mts +48 -0
  31. package/dist/PreparedInputAdmission-C4HbjHgl.d.mts +38 -0
  32. package/dist/Receipt-BAHyigAF.d.mts +33 -0
  33. package/dist/Records-BAGkekt8.d.mts +3570 -0
  34. package/dist/RunEvent-DIrzkjLr.d.mts +460 -0
  35. package/dist/RunEventSink-D5aVhISG.d.mts +108 -0
  36. package/dist/RunJournal-Cgg1kNvc.mjs +825 -0
  37. package/dist/RunJournal-Cgg1kNvc.mjs.map +1 -0
  38. package/dist/RunOptions-g1aigcKI.d.mts +915 -0
  39. package/dist/RunPolicyUsage-ClZxyR46.d.mts +21 -0
  40. package/dist/Sandbox-CEsDWBLq.d.mts +173 -0
  41. package/dist/Schedule-H3SEYX9g.d.mts +842 -0
  42. package/dist/Scheduling-C9aIP8zT.mjs +691 -0
  43. package/dist/Scheduling-C9aIP8zT.mjs.map +1 -0
  44. package/dist/Subagent-DyfzHNdv.d.mts +826 -0
  45. package/dist/Subagent-U5qXOFE8.mjs +1469 -0
  46. package/dist/Subagent-U5qXOFE8.mjs.map +1 -0
  47. package/dist/SubagentContract-DdT7Cqe6.d.mts +116 -0
  48. package/dist/SubagentHost-CJUBQlcc.d.mts +140 -0
  49. package/dist/Subscription-BEP8oQO5.d.mts +921 -0
  50. package/dist/SubscriptionInput-vAAOBrK7.d.mts +41 -0
  51. package/dist/Thread-DOBQ0QUY.d.mts +96 -0
  52. package/dist/ThreadHistory-tS1KwxHR.d.mts +60 -0
  53. package/dist/ToolBroker-DWs4tZra.d.mts +133 -0
  54. package/dist/ToolExposure-9uF_Yo0T.mjs +10 -0
  55. package/dist/ToolExposure-9uF_Yo0T.mjs.map +1 -0
  56. package/dist/ToolExposure-C93U1sPu.mjs +30 -0
  57. package/dist/ToolExposure-C93U1sPu.mjs.map +1 -0
  58. package/dist/ToolExposure-UCN12eCd.d.mts +39 -0
  59. package/dist/ToolExposure-r2eOWk4F.d.mts +46 -0
  60. package/dist/ToolExposure.d.mts +8 -0
  61. package/dist/ToolExposure.mjs +21 -0
  62. package/dist/ToolExposure.mjs.map +1 -0
  63. package/dist/ToolReconciler-DQVaJfpE.d.mts +76 -0
  64. package/dist/ToolResult-DmmgoChv.d.mts +61 -0
  65. package/dist/Usage-Dx0aknfk.d.mts +121 -0
  66. package/dist/WakeScheduler-EjUF-GhC.d.mts +56 -0
  67. package/dist/Worker-CaPYykpe.d.mts +228 -0
  68. package/dist/agent-registration-CWDMOAZA.mjs +172 -0
  69. package/dist/agent-registration-CWDMOAZA.mjs.map +1 -0
  70. package/dist/capabilities/Approval.d.mts +114 -0
  71. package/dist/capabilities/Approval.mjs +226 -0
  72. package/dist/capabilities/Approval.mjs.map +1 -0
  73. package/dist/capabilities/Budget.d.mts +112 -0
  74. package/dist/capabilities/Budget.mjs +346 -0
  75. package/dist/capabilities/Budget.mjs.map +1 -0
  76. package/dist/capabilities/CodeMode.d.mts +157 -0
  77. package/dist/capabilities/CodeMode.mjs +522 -0
  78. package/dist/capabilities/CodeMode.mjs.map +1 -0
  79. package/dist/capabilities/Commands.d.mts +55 -0
  80. package/dist/capabilities/Commands.mjs +57 -0
  81. package/dist/capabilities/Commands.mjs.map +1 -0
  82. package/dist/capabilities/ContextTools.d.mts +321 -0
  83. package/dist/capabilities/ContextTools.mjs +126 -0
  84. package/dist/capabilities/ContextTools.mjs.map +1 -0
  85. package/dist/capabilities/Mcp.d.mts +108 -0
  86. package/dist/capabilities/Mcp.mjs +260 -0
  87. package/dist/capabilities/Mcp.mjs.map +1 -0
  88. package/dist/capabilities/McpClient.d.mts +115 -0
  89. package/dist/capabilities/McpClient.mjs +506 -0
  90. package/dist/capabilities/McpClient.mjs.map +1 -0
  91. package/dist/capabilities/MemoryNotes.d.mts +424 -0
  92. package/dist/capabilities/MemoryNotes.mjs +128 -0
  93. package/dist/capabilities/MemoryNotes.mjs.map +1 -0
  94. package/dist/capabilities/Messaging.d.mts +3 -0
  95. package/dist/capabilities/Messaging.mjs +151 -0
  96. package/dist/capabilities/Messaging.mjs.map +1 -0
  97. package/dist/capabilities/ModelContext.d.mts +89 -0
  98. package/dist/capabilities/ModelContext.mjs +168 -0
  99. package/dist/capabilities/ModelContext.mjs.map +1 -0
  100. package/dist/capabilities/Redaction.d.mts +37 -0
  101. package/dist/capabilities/Redaction.mjs +104 -0
  102. package/dist/capabilities/Redaction.mjs.map +1 -0
  103. package/dist/capabilities/Remembering.d.mts +434 -0
  104. package/dist/capabilities/Remembering.mjs +290 -0
  105. package/dist/capabilities/Remembering.mjs.map +1 -0
  106. package/dist/capabilities/RunHooks.d.mts +82 -0
  107. package/dist/capabilities/RunHooks.mjs +144 -0
  108. package/dist/capabilities/RunHooks.mjs.map +1 -0
  109. package/dist/capabilities/SemanticMemory.d.mts +431 -0
  110. package/dist/capabilities/SemanticMemory.mjs +315 -0
  111. package/dist/capabilities/SemanticMemory.mjs.map +1 -0
  112. package/dist/capabilities/Subagent.d.mts +4 -0
  113. package/dist/capabilities/Subagent.mjs +5 -0
  114. package/dist/capabilities/SubagentReservations.d.mts +186 -0
  115. package/dist/capabilities/SubagentReservations.mjs +479 -0
  116. package/dist/capabilities/SubagentReservations.mjs.map +1 -0
  117. package/dist/capabilities/ToolDiscovery.d.mts +109 -0
  118. package/dist/capabilities/ToolDiscovery.mjs +211 -0
  119. package/dist/capabilities/ToolDiscovery.mjs.map +1 -0
  120. package/dist/capabilities/WebCapture.d.mts +163 -0
  121. package/dist/capabilities/WebCapture.mjs +335 -0
  122. package/dist/capabilities/WebCapture.mjs.map +1 -0
  123. package/dist/capabilities/WebSearch.d.mts +71 -0
  124. package/dist/capabilities/WebSearch.mjs +112 -0
  125. package/dist/capabilities/WebSearch.mjs.map +1 -0
  126. package/dist/compaction-C2OTceKw.mjs +505 -0
  127. package/dist/compaction-C2OTceKw.mjs.map +1 -0
  128. package/dist/core/Agent.d.mts +2 -0
  129. package/dist/core/Agent.mjs +2 -0
  130. package/dist/core/AgentError.d.mts +2 -0
  131. package/dist/core/AgentError.mjs +117 -0
  132. package/dist/core/AgentError.mjs.map +1 -0
  133. package/dist/core/AgentPolicy.d.mts +2 -0
  134. package/dist/core/AgentPolicy.mjs +94 -0
  135. package/dist/core/AgentPolicy.mjs.map +1 -0
  136. package/dist/core/AgentUpdates.d.mts +2 -0
  137. package/dist/core/AgentUpdates.mjs +63 -0
  138. package/dist/core/AgentUpdates.mjs.map +1 -0
  139. package/dist/core/IdGenerator.d.mts +26 -0
  140. package/dist/core/IdGenerator.mjs +27 -0
  141. package/dist/core/IdGenerator.mjs.map +1 -0
  142. package/dist/core/Identifiers.d.mts +2 -0
  143. package/dist/core/Identifiers.mjs +43 -0
  144. package/dist/core/Identifiers.mjs.map +1 -0
  145. package/dist/core/Memory.d.mts +57 -0
  146. package/dist/core/Memory.mjs +203 -0
  147. package/dist/core/Memory.mjs.map +1 -0
  148. package/dist/core/MemoryNamespace.d.mts +2 -0
  149. package/dist/core/MemoryNamespace.mjs +116 -0
  150. package/dist/core/MemoryNamespace.mjs.map +1 -0
  151. package/dist/core/MemoryReference.d.mts +2 -0
  152. package/dist/core/MemoryReference.mjs +109 -0
  153. package/dist/core/MemoryReference.mjs.map +1 -0
  154. package/dist/core/MemoryRevalidation.d.mts +65 -0
  155. package/dist/core/MemoryRevalidation.mjs +126 -0
  156. package/dist/core/MemoryRevalidation.mjs.map +1 -0
  157. package/dist/core/MemoryStore.d.mts +186 -0
  158. package/dist/core/MemoryStore.mjs +243 -0
  159. package/dist/core/MemoryStore.mjs.map +1 -0
  160. package/dist/core/Receipt.d.mts +2 -0
  161. package/dist/core/Receipt.mjs +36 -0
  162. package/dist/core/Receipt.mjs.map +1 -0
  163. package/dist/core/RememberingStore.d.mts +1562 -0
  164. package/dist/core/RememberingStore.mjs +190 -0
  165. package/dist/core/RememberingStore.mjs.map +1 -0
  166. package/dist/core/RunEvent.d.mts +2 -0
  167. package/dist/core/RunEvent.mjs +337 -0
  168. package/dist/core/RunEvent.mjs.map +1 -0
  169. package/dist/core/RunPolicyUsage.d.mts +2 -0
  170. package/dist/core/RunPolicyUsage.mjs +21 -0
  171. package/dist/core/RunPolicyUsage.mjs.map +1 -0
  172. package/dist/core/SemanticMemoryIndex.d.mts +826 -0
  173. package/dist/core/SemanticMemoryIndex.mjs +185 -0
  174. package/dist/core/SemanticMemoryIndex.mjs.map +1 -0
  175. package/dist/core/SemanticMemoryRevalidation.d.mts +45 -0
  176. package/dist/core/SemanticMemoryRevalidation.mjs +191 -0
  177. package/dist/core/SemanticMemoryRevalidation.mjs.map +1 -0
  178. package/dist/core/SubagentContract.d.mts +2 -0
  179. package/dist/core/SubagentContract.mjs +148 -0
  180. package/dist/core/SubagentContract.mjs.map +1 -0
  181. package/dist/core/Thread.d.mts +2 -0
  182. package/dist/core/Thread.mjs +250 -0
  183. package/dist/core/Thread.mjs.map +1 -0
  184. package/dist/core/ToolResult.d.mts +2 -0
  185. package/dist/core/ToolResult.mjs +140 -0
  186. package/dist/core/ToolResult.mjs.map +1 -0
  187. package/dist/core/Usage.d.mts +2 -0
  188. package/dist/core/Usage.mjs +319 -0
  189. package/dist/core/Usage.mjs.map +1 -0
  190. package/dist/core/Worker.d.mts +3 -0
  191. package/dist/core/Worker.mjs +147 -0
  192. package/dist/core/Worker.mjs.map +1 -0
  193. package/dist/durable/ActivityStore.d.mts +116 -0
  194. package/dist/durable/ActivityStore.mjs +131 -0
  195. package/dist/durable/ActivityStore.mjs.map +1 -0
  196. package/dist/durable/Admin.d.mts +2 -0
  197. package/dist/durable/Admin.mjs +328 -0
  198. package/dist/durable/Admin.mjs.map +1 -0
  199. package/dist/durable/AgentRegistration.d.mts +2 -0
  200. package/dist/durable/AgentRegistration.mjs +14 -0
  201. package/dist/durable/AgentRegistration.mjs.map +1 -0
  202. package/dist/durable/Certification.d.mts +111 -0
  203. package/dist/durable/Certification.mjs +159 -0
  204. package/dist/durable/Certification.mjs.map +1 -0
  205. package/dist/durable/CommittedActivity.d.mts +62 -0
  206. package/dist/durable/CommittedActivity.mjs +159 -0
  207. package/dist/durable/CommittedActivity.mjs.map +1 -0
  208. package/dist/durable/Digest.d.mts +2 -0
  209. package/dist/durable/Digest.mjs +50 -0
  210. package/dist/durable/Digest.mjs.map +1 -0
  211. package/dist/durable/DurableAgentRuntime.d.mts +3 -0
  212. package/dist/durable/DurableAgentRuntime.mjs +3 -0
  213. package/dist/durable/DurableFailpoint.d.mts +2 -0
  214. package/dist/durable/DurableFailpoint.mjs +94 -0
  215. package/dist/durable/DurableFailpoint.mjs.map +1 -0
  216. package/dist/durable/DurableFailpointTestControl.d.mts +15 -0
  217. package/dist/durable/DurableFailpointTestControl.mjs +19 -0
  218. package/dist/durable/DurableFailpointTestControl.mjs.map +1 -0
  219. package/dist/durable/EventSource.d.mts +2 -0
  220. package/dist/durable/EventSource.mjs +65 -0
  221. package/dist/durable/EventSource.mjs.map +1 -0
  222. package/dist/durable/GitHubWorkflowSource.d.mts +144 -0
  223. package/dist/durable/GitHubWorkflowSource.mjs +209 -0
  224. package/dist/durable/GitHubWorkflowSource.mjs.map +1 -0
  225. package/dist/durable/MessageDelivery.d.mts +492 -0
  226. package/dist/durable/MessageDelivery.mjs +495 -0
  227. package/dist/durable/MessageDelivery.mjs.map +1 -0
  228. package/dist/durable/MessageDeliveryStoreConformance.d.mts +358 -0
  229. package/dist/durable/MessageDeliveryStoreConformance.mjs +243 -0
  230. package/dist/durable/MessageDeliveryStoreConformance.mjs.map +1 -0
  231. package/dist/durable/OperationAuthorizer.d.mts +2 -0
  232. package/dist/durable/OperationAuthorizer.mjs +70 -0
  233. package/dist/durable/OperationAuthorizer.mjs.map +1 -0
  234. package/dist/durable/PersistentHistory.d.mts +16 -0
  235. package/dist/durable/PersistentHistory.mjs +125 -0
  236. package/dist/durable/PersistentHistory.mjs.map +1 -0
  237. package/dist/durable/PreparedInputAdmission.d.mts +2 -0
  238. package/dist/durable/PreparedInputAdmission.mjs +34 -0
  239. package/dist/durable/PreparedInputAdmission.mjs.map +1 -0
  240. package/dist/durable/Records.d.mts +2 -0
  241. package/dist/durable/Records.mjs +795 -0
  242. package/dist/durable/Records.mjs.map +1 -0
  243. package/dist/durable/Recovery.d.mts +2 -0
  244. package/dist/durable/Recovery.mjs +739 -0
  245. package/dist/durable/Recovery.mjs.map +1 -0
  246. package/dist/durable/RunJournal.d.mts +2 -0
  247. package/dist/durable/RunJournal.mjs +2 -0
  248. package/dist/durable/Schedule.d.mts +2 -0
  249. package/dist/durable/Schedule.mjs +382 -0
  250. package/dist/durable/Schedule.mjs.map +1 -0
  251. package/dist/durable/ScheduleStoreConformance.d.mts +18 -0
  252. package/dist/durable/ScheduleStoreConformance.mjs +420 -0
  253. package/dist/durable/ScheduleStoreConformance.mjs.map +1 -0
  254. package/dist/durable/ScheduleTransition.d.mts +24 -0
  255. package/dist/durable/ScheduleTransition.mjs +180 -0
  256. package/dist/durable/ScheduleTransition.mjs.map +1 -0
  257. package/dist/durable/Scheduling.d.mts +54 -0
  258. package/dist/durable/Scheduling.mjs +2 -0
  259. package/dist/durable/SqlMemoryStore.d.mts +30 -0
  260. package/dist/durable/SqlMemoryStore.mjs +436 -0
  261. package/dist/durable/SqlMemoryStore.mjs.map +1 -0
  262. package/dist/durable/SqlMessageDeliveryStore.d.mts +40 -0
  263. package/dist/durable/SqlMessageDeliveryStore.mjs +167 -0
  264. package/dist/durable/SqlMessageDeliveryStore.mjs.map +1 -0
  265. package/dist/durable/SqlStorageV2Upgrade.d.mts +22 -0
  266. package/dist/durable/SqlStorageV2Upgrade.mjs +459 -0
  267. package/dist/durable/SqlStorageV2Upgrade.mjs.map +1 -0
  268. package/dist/durable/SqlSubscriptionStore.d.mts +63 -0
  269. package/dist/durable/SqlSubscriptionStore.mjs +751 -0
  270. package/dist/durable/SqlSubscriptionStore.mjs.map +1 -0
  271. package/dist/durable/SubmissionLedger.d.mts +3 -0
  272. package/dist/durable/SubmissionLedger.mjs +914 -0
  273. package/dist/durable/SubmissionLedger.mjs.map +1 -0
  274. package/dist/durable/SubmissionLedgerConformance.d.mts +30 -0
  275. package/dist/durable/SubmissionLedgerConformance.mjs +1986 -0
  276. package/dist/durable/SubmissionLedgerConformance.mjs.map +1 -0
  277. package/dist/durable/SubmissionStatus.d.mts +2 -0
  278. package/dist/durable/SubmissionStatus.mjs +18 -0
  279. package/dist/durable/SubmissionStatus.mjs.map +1 -0
  280. package/dist/durable/Subscription.d.mts +2 -0
  281. package/dist/durable/Subscription.mjs +360 -0
  282. package/dist/durable/Subscription.mjs.map +1 -0
  283. package/dist/durable/SubscriptionInput.d.mts +2 -0
  284. package/dist/durable/SubscriptionInput.mjs +52 -0
  285. package/dist/durable/SubscriptionInput.mjs.map +1 -0
  286. package/dist/durable/SubscriptionStoreConformance.d.mts +17 -0
  287. package/dist/durable/SubscriptionStoreConformance.mjs +625 -0
  288. package/dist/durable/SubscriptionStoreConformance.mjs.map +1 -0
  289. package/dist/durable/SubscriptionTools.d.mts +273 -0
  290. package/dist/durable/SubscriptionTools.mjs +190 -0
  291. package/dist/durable/SubscriptionTools.mjs.map +1 -0
  292. package/dist/durable/SubscriptionTransition.d.mts +21 -0
  293. package/dist/durable/SubscriptionTransition.mjs +148 -0
  294. package/dist/durable/SubscriptionTransition.mjs.map +1 -0
  295. package/dist/durable/Subscriptions.d.mts +73 -0
  296. package/dist/durable/Subscriptions.mjs +627 -0
  297. package/dist/durable/Subscriptions.mjs.map +1 -0
  298. package/dist/durable/ThreadContextHistory.d.mts +32 -0
  299. package/dist/durable/ThreadContextHistory.mjs +152 -0
  300. package/dist/durable/ThreadContextHistory.mjs.map +1 -0
  301. package/dist/durable/ThreadContextHistoryProjection.d.mts +60 -0
  302. package/dist/durable/ThreadContextHistoryProjection.mjs +149 -0
  303. package/dist/durable/ThreadContextHistoryProjection.mjs.map +1 -0
  304. package/dist/durable/ThreadInvariants.d.mts +74 -0
  305. package/dist/durable/ThreadInvariants.mjs +200 -0
  306. package/dist/durable/ThreadInvariants.mjs.map +1 -0
  307. package/dist/durable/ThreadProjection.d.mts +78 -0
  308. package/dist/durable/ThreadProjection.mjs +158 -0
  309. package/dist/durable/ThreadProjection.mjs.map +1 -0
  310. package/dist/durable/ThreadProjectionMaintenance.d.mts +49 -0
  311. package/dist/durable/ThreadProjectionMaintenance.mjs +33 -0
  312. package/dist/durable/ThreadProjectionMaintenance.mjs.map +1 -0
  313. package/dist/durable/ThreadStore.d.mts +2 -0
  314. package/dist/durable/ThreadStore.mjs +147 -0
  315. package/dist/durable/ThreadStore.mjs.map +1 -0
  316. package/dist/durable/ThreadStoreConformance.d.mts +29 -0
  317. package/dist/durable/ThreadStoreConformance.mjs +248 -0
  318. package/dist/durable/ThreadStoreConformance.mjs.map +1 -0
  319. package/dist/durable/ToolReconciler.d.mts +2 -0
  320. package/dist/durable/ToolReconciler.mjs +81 -0
  321. package/dist/durable/ToolReconciler.mjs.map +1 -0
  322. package/dist/durable/WakeScheduler.d.mts +2 -0
  323. package/dist/durable/WakeScheduler.mjs +85 -0
  324. package/dist/durable/WakeScheduler.mjs.map +1 -0
  325. package/dist/durable/WorkerHost.d.mts +129 -0
  326. package/dist/durable/WorkerHost.mjs +77 -0
  327. package/dist/durable/WorkerHost.mjs.map +1 -0
  328. package/dist/engine/AgentRuntime.d.mts +2 -0
  329. package/dist/engine/AgentRuntime.mjs +2 -0
  330. package/dist/engine/Compaction.d.mts +7 -0
  331. package/dist/engine/Compaction.mjs +16 -0
  332. package/dist/engine/Compaction.mjs.map +1 -0
  333. package/dist/engine/ContextCompactor.d.mts +2 -0
  334. package/dist/engine/ContextCompactor.mjs +119 -0
  335. package/dist/engine/ContextCompactor.mjs.map +1 -0
  336. package/dist/engine/ContextHistory.d.mts +65 -0
  337. package/dist/engine/ContextHistory.mjs +76 -0
  338. package/dist/engine/ContextHistory.mjs.map +1 -0
  339. package/dist/engine/ContextWindow.d.mts +2 -0
  340. package/dist/engine/ContextWindow.mjs +59 -0
  341. package/dist/engine/ContextWindow.mjs.map +1 -0
  342. package/dist/engine/DurableStep.d.mts +2 -0
  343. package/dist/engine/DurableStep.mjs +62 -0
  344. package/dist/engine/DurableStep.mjs.map +1 -0
  345. package/dist/engine/MessagingHost.d.mts +2 -0
  346. package/dist/engine/MessagingHost.mjs +2 -0
  347. package/dist/engine/Output.d.mts +2 -0
  348. package/dist/engine/Output.mjs +8 -0
  349. package/dist/engine/Output.mjs.map +1 -0
  350. package/dist/engine/RunEventSink.d.mts +2 -0
  351. package/dist/engine/RunEventSink.mjs +22 -0
  352. package/dist/engine/RunEventSink.mjs.map +1 -0
  353. package/dist/engine/RunOptions.d.mts +2 -0
  354. package/dist/engine/RunOptions.mjs +122 -0
  355. package/dist/engine/RunOptions.mjs.map +1 -0
  356. package/dist/engine/SubagentHost.d.mts +2 -0
  357. package/dist/engine/SubagentHost.mjs +72 -0
  358. package/dist/engine/SubagentHost.mjs.map +1 -0
  359. package/dist/engine/ThreadHistory.d.mts +2 -0
  360. package/dist/engine/ThreadHistory.mjs +67 -0
  361. package/dist/engine/ThreadHistory.mjs.map +1 -0
  362. package/dist/engine/ToolBroker.d.mts +2 -0
  363. package/dist/engine/ToolBroker.mjs +42 -0
  364. package/dist/engine/ToolBroker.mjs.map +1 -0
  365. package/dist/foreign-diagnostic-DBQ1XHKh.mjs +37 -0
  366. package/dist/foreign-diagnostic-DBQ1XHKh.mjs.map +1 -0
  367. package/dist/index.d.mts +89 -6
  368. package/dist/index.mjs +98 -6
  369. package/dist/output-contract-BC7tjlGw.mjs +84 -0
  370. package/dist/output-contract-BC7tjlGw.mjs.map +1 -0
  371. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  372. package/dist/sandbox/CodeExecutor.d.mts +194 -0
  373. package/dist/sandbox/CodeExecutor.mjs +278 -0
  374. package/dist/sandbox/CodeExecutor.mjs.map +1 -0
  375. package/dist/sandbox/InteractiveBrowser.d.mts +142 -0
  376. package/dist/sandbox/InteractiveBrowser.mjs +165 -0
  377. package/dist/sandbox/InteractiveBrowser.mjs.map +1 -0
  378. package/dist/sandbox/PageCapture.d.mts +2 -0
  379. package/dist/sandbox/PageCapture.mjs +450 -0
  380. package/dist/sandbox/PageCapture.mjs.map +1 -0
  381. package/dist/sandbox/PageCrawl.d.mts +88 -0
  382. package/dist/sandbox/PageCrawl.mjs +124 -0
  383. package/dist/sandbox/PageCrawl.mjs.map +1 -0
  384. package/dist/sandbox/PageScreenshot.d.mts +2 -0
  385. package/dist/sandbox/PageScreenshot.mjs +53 -0
  386. package/dist/sandbox/PageScreenshot.mjs.map +1 -0
  387. package/dist/sandbox/ProtectedBrowser.d.mts +273 -0
  388. package/dist/sandbox/ProtectedBrowser.mjs +287 -0
  389. package/dist/sandbox/ProtectedBrowser.mjs.map +1 -0
  390. package/dist/sandbox/Sandbox.d.mts +2 -0
  391. package/dist/sandbox/Sandbox.mjs +208 -0
  392. package/dist/sandbox/Sandbox.mjs.map +1 -0
  393. package/dist/utf8-BYfhEkcj.mjs +11 -0
  394. package/dist/utf8-BYfhEkcj.mjs.map +1 -0
  395. package/dist/utf8-DchGZRBd.mjs +23 -0
  396. package/dist/utf8-DchGZRBd.mjs.map +1 -0
  397. package/package.json +1 -40
  398. package/src/Ephemeral.ts +17 -0
  399. package/src/ToolExposure.ts +2 -0
  400. package/src/capabilities/Approval.ts +352 -0
  401. package/src/capabilities/Budget.ts +536 -0
  402. package/src/capabilities/CodeMode.ts +1090 -0
  403. package/src/capabilities/Commands.ts +86 -0
  404. package/src/capabilities/ContextTools.ts +184 -0
  405. package/src/capabilities/Mcp.ts +427 -0
  406. package/src/capabilities/McpClient.ts +967 -0
  407. package/src/capabilities/MemoryNotes.ts +174 -0
  408. package/src/capabilities/Messaging.ts +261 -0
  409. package/src/capabilities/ModelContext.ts +354 -0
  410. package/src/capabilities/Redaction.ts +157 -0
  411. package/src/capabilities/Remembering.ts +550 -0
  412. package/src/capabilities/RunHooks.ts +280 -0
  413. package/src/capabilities/SemanticMemory.ts +447 -0
  414. package/src/capabilities/Subagent.ts +2277 -0
  415. package/src/capabilities/SubagentReservations.ts +850 -0
  416. package/src/capabilities/ToolDiscovery.ts +339 -0
  417. package/src/capabilities/WebCapture.ts +722 -0
  418. package/src/capabilities/WebSearch.ts +184 -0
  419. package/src/capabilities/internal/subagent-background.ts +1106 -0
  420. package/src/capabilities/internal/subagent-contract.ts +142 -0
  421. package/src/capabilities/internal/subagent-policy.ts +235 -0
  422. package/src/capabilities/internal/subagent-reporting.ts +261 -0
  423. package/src/capabilities/internal/utf8.ts +10 -0
  424. package/src/core/Agent.ts +575 -0
  425. package/src/core/AgentError.ts +152 -0
  426. package/src/core/AgentPolicy.ts +153 -0
  427. package/src/core/AgentUpdates.ts +100 -0
  428. package/src/core/IdGenerator.ts +39 -0
  429. package/src/core/Identifiers.ts +48 -0
  430. package/src/core/Memory.ts +290 -0
  431. package/src/core/MemoryNamespace.ts +196 -0
  432. package/src/core/MemoryReference.ts +121 -0
  433. package/src/core/MemoryRevalidation.ts +185 -0
  434. package/src/core/MemoryStore.ts +368 -0
  435. package/src/core/Messaging.ts +90 -0
  436. package/src/core/Receipt.ts +42 -0
  437. package/src/core/RememberingStore.ts +300 -0
  438. package/src/core/RunEvent.ts +366 -0
  439. package/src/core/RunPolicyUsage.ts +17 -0
  440. package/src/core/SemanticMemoryIndex.ts +250 -0
  441. package/src/core/SemanticMemoryRevalidation.ts +254 -0
  442. package/src/core/SubagentContract.ts +196 -0
  443. package/src/core/Thread.ts +371 -0
  444. package/src/core/ToolExposure.ts +74 -0
  445. package/src/core/ToolResult.ts +170 -0
  446. package/src/core/Usage.ts +529 -0
  447. package/src/core/Worker.ts +173 -0
  448. package/src/core/internal/agent-updates.ts +32 -0
  449. package/src/core/internal/utf8.ts +23 -0
  450. package/src/durable/ActivityStore.ts +160 -0
  451. package/src/durable/Admin.ts +496 -0
  452. package/src/durable/AgentRegistration.ts +13 -0
  453. package/src/durable/Certification.ts +210 -0
  454. package/src/durable/CommittedActivity.ts +296 -0
  455. package/src/durable/Digest.ts +93 -0
  456. package/src/durable/DurableAgentRuntime.ts +10340 -0
  457. package/src/durable/DurableFailpoint.ts +103 -0
  458. package/src/durable/DurableFailpointTestControl.ts +39 -0
  459. package/src/durable/EventSource.ts +172 -0
  460. package/src/durable/GitHubWorkflowSource.ts +453 -0
  461. package/src/durable/MessageDelivery.ts +708 -0
  462. package/src/durable/MessageDeliveryStoreConformance.ts +363 -0
  463. package/src/durable/OperationAuthorizer.ts +85 -0
  464. package/src/durable/PersistentHistory.ts +260 -0
  465. package/src/durable/PreparedInputAdmission.ts +44 -0
  466. package/src/durable/Records.ts +1010 -0
  467. package/src/durable/Recovery.ts +1018 -0
  468. package/src/durable/RunJournal.ts +1479 -0
  469. package/src/durable/Schedule.ts +504 -0
  470. package/src/durable/ScheduleStoreConformance.ts +638 -0
  471. package/src/durable/ScheduleTransition.ts +265 -0
  472. package/src/durable/Scheduling.ts +1077 -0
  473. package/src/durable/SqlMemoryStore.ts +778 -0
  474. package/src/durable/SqlMessageDeliveryStore.ts +302 -0
  475. package/src/durable/SqlStorageV2Upgrade.ts +500 -0
  476. package/src/durable/SqlSubscriptionStore.ts +1440 -0
  477. package/src/durable/SubmissionLedger.ts +1201 -0
  478. package/src/durable/SubmissionLedgerConformance.ts +4579 -0
  479. package/src/durable/SubmissionStatus.ts +14 -0
  480. package/src/durable/Subscription.ts +544 -0
  481. package/src/durable/SubscriptionInput.ts +144 -0
  482. package/src/durable/SubscriptionStoreConformance.ts +945 -0
  483. package/src/durable/SubscriptionTools.ts +327 -0
  484. package/src/durable/SubscriptionTransition.ts +302 -0
  485. package/src/durable/Subscriptions.ts +1210 -0
  486. package/src/durable/ThreadContextHistory.ts +227 -0
  487. package/src/durable/ThreadContextHistoryProjection.ts +216 -0
  488. package/src/durable/ThreadInvariants.ts +442 -0
  489. package/src/durable/ThreadProjection.ts +269 -0
  490. package/src/durable/ThreadProjectionMaintenance.ts +67 -0
  491. package/src/durable/ThreadStore.ts +242 -0
  492. package/src/durable/ThreadStoreConformance.ts +710 -0
  493. package/src/durable/ToolReconciler.ts +105 -0
  494. package/src/durable/WakeScheduler.ts +134 -0
  495. package/src/durable/WorkerHost.ts +171 -0
  496. package/src/durable/internal/agent-registration.ts +525 -0
  497. package/src/durable/internal/agent-updates.ts +302 -0
  498. package/src/durable/internal/foreign-diagnostic.ts +47 -0
  499. package/src/durable/internal/journal-checkpoint.ts +104 -0
  500. package/src/durable/internal/journal-metadata.ts +107 -0
  501. package/src/durable/internal/messaging-host.ts +608 -0
  502. package/src/durable/internal/schedule-time.ts +303 -0
  503. package/src/durable/internal/storage-v2-layout.ts +163 -0
  504. package/src/durable/internal/storage-v2.ts +73 -0
  505. package/src/durable/internal/worker-host.ts +2467 -0
  506. package/src/durable/internal/worker-runtime.ts +9 -0
  507. package/src/engine/AgentRuntime.ts +37 -0
  508. package/src/engine/Compaction.ts +11 -0
  509. package/src/engine/ContextCompactor.ts +277 -0
  510. package/src/engine/ContextHistory.ts +73 -0
  511. package/src/engine/ContextWindow.ts +72 -0
  512. package/src/engine/DurableStep.ts +132 -0
  513. package/src/engine/MessagingHost.ts +110 -0
  514. package/src/engine/Output.ts +2 -0
  515. package/src/engine/RunEventSink.ts +132 -0
  516. package/src/engine/RunOptions.ts +1077 -0
  517. package/src/engine/SubagentHost.ts +181 -0
  518. package/src/engine/ThreadHistory.ts +120 -0
  519. package/src/engine/ToolBroker.ts +157 -0
  520. package/src/engine/ToolExposure.ts +48 -0
  521. package/src/engine/internal/agent-runtime.ts +10162 -0
  522. package/src/engine/internal/bounded-value.ts +315 -0
  523. package/src/engine/internal/compaction.ts +678 -0
  524. package/src/engine/internal/error-diagnostic.ts +39 -0
  525. package/src/engine/internal/output-contract.ts +173 -0
  526. package/src/engine/internal/primitive-delta.ts +80 -0
  527. package/src/engine/internal/provider-result-staging.ts +211 -0
  528. package/src/engine/internal/tool-derivative.ts +106 -0
  529. package/src/engine/internal/tool-exposure.ts +224 -0
  530. package/src/engine/internal/tool-telemetry.ts +484 -0
  531. package/src/index.ts +97 -22
  532. package/src/sandbox/CodeExecutor.ts +352 -0
  533. package/src/sandbox/InteractiveBrowser.ts +257 -0
  534. package/src/sandbox/PageCapture.ts +692 -0
  535. package/src/sandbox/PageCrawl.ts +148 -0
  536. package/src/sandbox/PageScreenshot.ts +81 -0
  537. package/src/sandbox/ProtectedBrowser.ts +436 -0
  538. package/src/sandbox/Sandbox.ts +241 -0
@@ -0,0 +1,1010 @@
1
+ import { Schema } from "effect";
2
+ import { Prompt } from "effect/unstable/ai";
3
+
4
+ import { InputMessage } from "../capabilities/Messaging.ts";
5
+ import { PolicyLimit } from "../core/AgentError.ts";
6
+ import { AgentPolicy } from "../core/AgentPolicy.ts";
7
+ import { Update } from "../core/AgentUpdates.ts";
8
+ import {
9
+ AgentId,
10
+ AttemptId,
11
+ ThreadId,
12
+ DelegationId,
13
+ ReceiptId,
14
+ RunId,
15
+ SettlementId,
16
+ SubmissionId,
17
+ ToolCallId,
18
+ TurnId,
19
+ } from "../core/Identifiers.ts";
20
+ import { utf8ByteLength } from "../core/internal/utf8.ts";
21
+ import { IdempotencyKey, Principal } from "../core/Receipt.ts";
22
+ import { ExhaustedLimit } from "../core/RunEvent.ts";
23
+ import { RunPolicyUsage } from "../core/RunPolicyUsage.ts";
24
+ import {
25
+ DelegationDepth,
26
+ SubagentBudgetReservation,
27
+ SubagentGrant,
28
+ SubagentParentLink,
29
+ ToolExecutionKind,
30
+ } from "../core/SubagentContract.ts";
31
+ import { Selection, Snapshot } from "../core/ToolExposure.ts";
32
+ import { ModelCallUsage, RunUsageSummary, RunTotals } from "../core/Usage.ts";
33
+ import { WorkerBudgetScope, WorkerRef, WorkerSource } from "../core/Worker.ts";
34
+ import { ContextHandoff } from "../engine/ContextWindow.ts";
35
+
36
+ const identifier = <const Name extends string>(name: Name) =>
37
+ Schema.NonEmptyString.pipe(Schema.brand(`@effect-agent/thread/${name}`));
38
+
39
+ /** Stable identity of one canonical record. */
40
+ export const RecordId = identifier("RecordId");
41
+ export type RecordId = typeof RecordId.Type;
42
+
43
+ /** Stable idempotency identity of one atomic append. */
44
+ export const BatchId = identifier("BatchId");
45
+ export type BatchId = typeof BatchId.Type;
46
+
47
+ /** Identity of the deployment that produced a record. */
48
+ export const DeploymentId = identifier("DeploymentId");
49
+ export type DeploymentId = typeof DeploymentId.Type;
50
+
51
+ /** Identity of a fenced canonical-log producer. */
52
+ export const ProducerId = identifier("ProducerId");
53
+ export type ProducerId = typeof ProducerId.Type;
54
+
55
+ /** SHA-256 digest encoded as lowercase hexadecimal text. */
56
+ export const Digest = Schema.String.check(Schema.isPattern(/^[a-f0-9]{64}$/)).pipe(
57
+ Schema.brand("@effect-agent/thread/Digest"),
58
+ );
59
+
60
+ export type Digest = typeof Digest.Type;
61
+
62
+ /** Adapter-owned resume cursor. Callers must not parse or synthesize it. */
63
+ export const ObservationOffset = identifier("ObservationOffset");
64
+ export type ObservationOffset = typeof ObservationOffset.Type;
65
+
66
+ /** Gap-free position in one Thread's canonical sequence. */
67
+ export const CanonicalSequence = Schema.Natural.pipe(
68
+ Schema.brand("@effect-agent/thread/CanonicalSequence"),
69
+ );
70
+
71
+ export type CanonicalSequence = typeof CanonicalSequence.Type;
72
+
73
+ /** Monotonic fencing epoch for a Thread producer. */
74
+ export const ProducerEpoch = Schema.Natural.pipe(
75
+ Schema.brand("@effect-agent/thread/ProducerEpoch"),
76
+ );
77
+
78
+ export type ProducerEpoch = typeof ProducerEpoch.Type;
79
+
80
+ const BoundedText = Schema.String.check(Schema.isMaxLength(64 * 1024));
81
+ const BoundedName = Schema.NonEmptyString.check(Schema.isMaxLength(256));
82
+
83
+ /** Stable, non-empty failure classification carried by a failed durable Settlement. */
84
+ const SettlementFailureTag = Schema.NonEmptyString.check(Schema.isMaxLength(256));
85
+
86
+ /** Diagnostic text is bounded independently from the broader persisted JSON envelope. */
87
+ const SettlementFailureMessage = Schema.String.check(Schema.isMaxLength(16 * 1024));
88
+
89
+ /**
90
+ * The complete generic diagnostic allowed on a failed durable Settlement. It deliberately has
91
+ * no raw Cause, stack, provider payload, or application-specific fields; those values can carry
92
+ * secrets and do not form a stable cross-process contract.
93
+ */
94
+ export const SettlementFailureDiagnostic = Schema.Struct({
95
+ errorTag: SettlementFailureTag,
96
+ message: SettlementFailureMessage,
97
+ }).pipe(
98
+ Schema.annotate({
99
+ identifier: "@effect-agent/thread/SettlementFailureDiagnostic",
100
+ parseOptions: { onExcessProperty: "error" },
101
+ }),
102
+ );
103
+
104
+ export type SettlementFailureDiagnostic = typeof SettlementFailureDiagnostic.Type;
105
+
106
+ /** Positive canonical (Run-relative, Attempt-independent) Turn number. */
107
+ const TurnNumber = Schema.Int.check(Schema.isGreaterThan(0));
108
+
109
+ export const MAX_PERSISTED_JSON_DEPTH = 64;
110
+ export const MAX_PERSISTED_JSON_COLLECTION_LENGTH = 4_096;
111
+ export const MAX_PERSISTED_JSON_NODES = 65_536;
112
+ export const MAX_PERSISTED_JSON_BYTES = 1024 * 1024;
113
+
114
+ /**
115
+ * Iteratively preflights an unknown value before Schema's recursive JSON validation. This is the
116
+ * one narrow `Schema.declare` exception in the persistence model: Effect v4's `Unknown.decodeTo`
117
+ * preserves `unknown` as the encoded type, which would leak through every nested record codec.
118
+ * Schema.Json still owns the accepted value shape after this resource preflight succeeds.
119
+ */
120
+ const isJson = Schema.is(Schema.Json);
121
+
122
+ const isPersistedJson = (input: unknown): input is Schema.Json => {
123
+ const pending: Array<
124
+ | { readonly _tag: "visit"; readonly value: unknown; readonly depth: number }
125
+ | { readonly _tag: "leave"; readonly value: object }
126
+ > = [{ _tag: "visit", value: input, depth: 0 }];
127
+
128
+ // Only ancestors indicate a cycle. Shared acyclic values serialize once per occurrence,
129
+ // so revisit them and charge every occurrence against the same resource limits.
130
+ const ancestors = new WeakSet<object>();
131
+ let nodes = 0;
132
+ let textUnits = 0;
133
+
134
+ try {
135
+ while (pending.length > 0) {
136
+ const current = pending.pop();
137
+
138
+ if (current === undefined) return false;
139
+ if (current._tag === "leave") {
140
+ ancestors.delete(current.value);
141
+ continue;
142
+ }
143
+ if (current.depth > MAX_PERSISTED_JSON_DEPTH || ++nodes > MAX_PERSISTED_JSON_NODES) {
144
+ return false;
145
+ }
146
+
147
+ const value = current.value;
148
+
149
+ if (value === null || typeof value === "boolean") continue;
150
+ if (typeof value === "number") {
151
+ if (!Number.isFinite(value)) return false;
152
+ continue;
153
+ }
154
+ if (typeof value === "string") {
155
+ textUnits += value.length;
156
+ if (textUnits > MAX_PERSISTED_JSON_BYTES) return false;
157
+ continue;
158
+ }
159
+ if (typeof value !== "object" || ancestors.has(value)) return false;
160
+ ancestors.add(value);
161
+ pending.push({ _tag: "leave", value });
162
+
163
+ const entries = Array.isArray(value)
164
+ ? Array.from(value, (entry, index) => [index, entry] as const)
165
+ : Object.entries(value);
166
+
167
+ if (entries.length > MAX_PERSISTED_JSON_COLLECTION_LENGTH) return false;
168
+ for (const [key, entry] of entries) {
169
+ textUnits += typeof key === "string" ? key.length : 0;
170
+ if (textUnits > MAX_PERSISTED_JSON_BYTES) return false;
171
+ pending.push({ _tag: "visit", value: entry, depth: current.depth + 1 });
172
+ }
173
+ }
174
+
175
+ if (!isJson(input)) return false;
176
+ const encoded = JSON.stringify(input);
177
+
178
+ return encoded !== undefined && utf8ByteLength(encoded) <= MAX_PERSISTED_JSON_BYTES;
179
+ } catch {
180
+ return false;
181
+ }
182
+ };
183
+
184
+ /** Canonical JSON admitted to persisted records and checkpoints under explicit resource limits. */
185
+ export const PersistedJson = Schema.declare(isPersistedJson, {
186
+ identifier: "@effect-agent/thread/PersistedJson",
187
+ description: "JSON bounded by canonical persistence depth, collection, node, and byte limits",
188
+ });
189
+
190
+ export type PersistedJson = typeof PersistedJson.Type;
191
+
192
+ /** Schema-owned replay inputs whose individual definitions are incorporated into digests. */
193
+ export class DefinitionDigestInput extends Schema.Class<DefinitionDigestInput>(
194
+ "@effect-agent/thread/DefinitionDigestInput",
195
+ )({
196
+ agent: PersistedJson,
197
+ model: PersistedJson,
198
+ tools: PersistedJson,
199
+ }) {}
200
+
201
+ /** Digests make a replay-visible definition/configuration change explicit. */
202
+ export class DefinitionDigests extends Schema.Class<DefinitionDigests>(
203
+ "@effect-agent/thread/DefinitionDigests",
204
+ )({
205
+ agent: Digest,
206
+ model: Digest,
207
+ tools: Digest,
208
+ }) {}
209
+
210
+ export class ThreadCreated extends Schema.TaggedClass<ThreadCreated>(
211
+ "@effect-agent/thread/ThreadCreated",
212
+ )("ThreadCreated", {
213
+ agentId: AgentId,
214
+ definitions: DefinitionDigests,
215
+ }) {}
216
+
217
+ /**
218
+ * One recorded Thread input. `submissionId` is present only for durably accepted work;
219
+ * retained history has no admission or settlement obligation. `kind` identifies the input seam.
220
+ */
221
+ export class UserInputRecorded extends Schema.TaggedClass<UserInputRecorded>(
222
+ "@effect-agent/thread/UserInputRecorded",
223
+ )("UserInputRecorded", {
224
+ submissionId: Schema.optionalKey(SubmissionId),
225
+ kind: Schema.Literals(["user", "steering", "follow-up"]),
226
+ runId: Schema.optionalKey(RunId),
227
+ input: PersistedJson,
228
+ messageAdmission: Schema.optionalKey(InputMessage),
229
+ }) {}
230
+
231
+ /** Immutable clock and duration allowance for one logical Run, before any agent execution. */
232
+ export class RunStartedRecord extends Schema.TaggedClass<RunStartedRecord>(
233
+ "@effect-agent/thread/RunStartedRecord",
234
+ )("RunStarted", {
235
+ runId: RunId,
236
+ /** Older private histories cannot prove programmatic accounting and must be reset. */
237
+ policyAccountingVersion: Schema.Literal(1),
238
+ maxDurationMillis: Schema.Finite.check(Schema.isGreaterThan(0)),
239
+ }) {}
240
+
241
+ const PersistedPromptMessages = Schema.toEncoded(Prompt.Prompt);
242
+ const isPersistedPromptMessages = Schema.is(PersistedPromptMessages);
243
+
244
+ /**
245
+ * Final model output. Immediate history may include the exact encoded Prompt suffix of the
246
+ * successful Run; durable execution instead journals individual ModelResponseRecorded Turns.
247
+ */
248
+ export class ModelCompleted extends Schema.TaggedClass<ModelCompleted>(
249
+ "@effect-agent/thread/ModelCompleted",
250
+ )(
251
+ "ModelCompleted",
252
+ Schema.Struct({
253
+ runId: RunId,
254
+ output: PersistedJson,
255
+ messages: Schema.optionalKey(PersistedJson),
256
+ }).check(
257
+ Schema.makeFilter(
258
+ (record) => record.messages === undefined || isPersistedPromptMessages(record.messages),
259
+ { title: "Retained Run messages are Schema-encoded Effect AI Prompt messages" },
260
+ ),
261
+ ),
262
+ ) {}
263
+
264
+ export class ToolCallSettled extends Schema.TaggedClass<ToolCallSettled>(
265
+ "@effect-agent/thread/ToolCallSettled",
266
+ )("ToolCallSettled", {
267
+ toolSelection: Schema.optionalKey(Selection),
268
+ runId: RunId,
269
+ toolCallId: ToolCallId,
270
+ toolName: BoundedName,
271
+ result: PersistedJson,
272
+ isFailure: Schema.Boolean,
273
+ /** Explicit engine evidence, never inferred from Tool result data. */
274
+ budgetRejected: Schema.optionalKey(Schema.Literal(true)),
275
+ }) {}
276
+
277
+ /**
278
+ * One committed model Turn. `messages` carries the Schema-encoded Effect AI Prompt messages this
279
+ * Turn appended (assistant response plus any tool-call declarations), committed atomically at the
280
+ * Turn boundary so a recovering Attempt can rebuild the next Prompt from canonical records alone.
281
+ * `messagesDigest` pins the exact encoded content.
282
+ */
283
+ const ModelResponseRecordedFields = Schema.Struct({
284
+ toolExposure: Schema.optionalKey(Snapshot),
285
+ runId: RunId,
286
+ turnId: TurnId,
287
+ turn: TurnNumber,
288
+ messages: PersistedJson,
289
+ messagesDigest: Digest,
290
+ /**
291
+ * Number of leading messages that belong only to this Run's evaluated instructions and wake
292
+ * input. They remain canonical and are visible while recovering this Run, but later Runs omit
293
+ * them from their model-facing history. Records without this field retain their full history.
294
+ */
295
+ runScopedPrefixLength: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
296
+ /**
297
+ * Exact normalized usage for every model call staged into this Turn. A
298
+ * summarizer and the Turn response are distinct entries. Absent on legacy
299
+ * records, whose aggregate totals below retain the old resume behavior.
300
+ */
301
+ modelUsage: Schema.optionalKey(Schema.Array(ModelCallUsage)),
302
+ /** Observed invocations without retained accounting before this Turn committed. */
303
+ unobservedModelCalls: Schema.optionalKey(Schema.Natural),
304
+ /** Aggregate compatibility fields used by older projections. */
305
+ inputTokens: Schema.optionalKey(Schema.Natural),
306
+ outputTokens: Schema.optionalKey(Schema.Natural),
307
+ /** Estimated spend staged with the usage; recovery re-seeds the cost budget (RUN-023). */
308
+ costMicrousd: Schema.optionalKey(Schema.Natural),
309
+ }).check(
310
+ Schema.makeFilter(
311
+ (response) =>
312
+ response.runScopedPrefixLength === undefined ||
313
+ (isPersistedPromptMessages(response.messages) &&
314
+ response.runScopedPrefixLength < response.messages.content.length &&
315
+ response.messages.content
316
+ .slice(0, response.runScopedPrefixLength)
317
+ .every((message) => message.role === "system" || message.role === "user")),
318
+ {
319
+ title:
320
+ "Run-scoped Prompt prefix contains only instruction/wake messages and leaves one response",
321
+ },
322
+ ),
323
+ );
324
+
325
+ export class ModelResponseRecorded extends Schema.TaggedClass<ModelResponseRecorded>(
326
+ "@effect-agent/thread/ModelResponseRecorded",
327
+ )("ModelResponseRecorded", ModelResponseRecordedFields) {}
328
+
329
+ /**
330
+ * One approved uncertain/idempotent ordinary Tool Call made durable BEFORE any handler starts
331
+ * (durability §10). `parameters` is the Schema-encoded wire form of the declared call and
332
+ * `parametersDigest` pins it; recovery that sees this record without a matching `ToolCallSettled`
333
+ * (or `ToolCallUnknown` → `ToolCallResolved`) must reconcile or mark unknown, never silently
334
+ * replay (DUR-009). Ordinary `readonly`-class Tools never produce this record. Delegation
335
+ * classification is always prepared, including for a Tool annotated `readonly`.
336
+ */
337
+ export class ToolCallPrepared extends Schema.TaggedClass<ToolCallPrepared>(
338
+ "@effect-agent/thread/ToolCallPrepared",
339
+ )("ToolCallPrepared", {
340
+ runId: RunId,
341
+ turnId: TurnId,
342
+ turn: TurnNumber,
343
+ toolCallId: ToolCallId,
344
+ toolName: BoundedName,
345
+ parameters: PersistedJson,
346
+ parametersDigest: Digest,
347
+ /** Absent legacy evidence grants no delegation replay authority. */
348
+ executionKind: Schema.optionalKey(ToolExecutionKind),
349
+ }) {}
350
+
351
+ /** Monotonic reservations charged before programmatic execution or grace finalization. */
352
+ export class RunPolicyUsageReserved extends Schema.TaggedClass<RunPolicyUsageReserved>()(
353
+ "RunPolicyUsageReserved",
354
+ {
355
+ runId: RunId,
356
+ programmaticToolCalls: RunPolicyUsage.fields.programmaticToolCalls,
357
+ finalizationUsed: RunPolicyUsage.fields.finalizationUsed,
358
+ },
359
+ ) {}
360
+
361
+ /**
362
+ * A durable Unknown Outcome: the external effect of one prepared ordinary Tool Call may have
363
+ * happened but was not confirmed canonically (DUR-009/DUR-017). It is neither success nor
364
+ * ordinary failure; automatic continuation stops until an authorized resolution arrives.
365
+ */
366
+ export class ToolCallUnknown extends Schema.TaggedClass<ToolCallUnknown>(
367
+ "@effect-agent/thread/ToolCallUnknown",
368
+ )("ToolCallUnknown", {
369
+ runId: RunId,
370
+ turn: TurnNumber,
371
+ toolCallId: ToolCallId,
372
+ toolName: BoundedName,
373
+ reason: BoundedText,
374
+ }) {}
375
+
376
+ /** How one open/unknown Tool Call was authoritatively closed (DUR-017 resolution audit). */
377
+ export const ToolCallResolution = Schema.Literals([
378
+ "completed-with-result",
379
+ "failed-with-error",
380
+ "never-started",
381
+ "safe-retry",
382
+ ]);
383
+
384
+ export type ToolCallResolution = typeof ToolCallResolution.Type;
385
+
386
+ /**
387
+ * The canonical audit record closing one open or unknown Tool Call: reconciler-recovered supplier
388
+ * truth or an authorized `resolveUnknown` command. `author`/`reason` make every resolution an
389
+ * attributable decision (DUR-017); a `completed-with-result` resolution is accompanied by the
390
+ * per-call `ToolCallSettled` record carrying the recovered result.
391
+ */
392
+ export class ToolCallResolved extends Schema.TaggedClass<ToolCallResolved>(
393
+ "@effect-agent/thread/ToolCallResolved",
394
+ )("ToolCallResolved", {
395
+ runId: RunId,
396
+ toolCallId: ToolCallId,
397
+ resolution: ToolCallResolution,
398
+ author: BoundedName,
399
+ reason: BoundedText,
400
+ }) {}
401
+
402
+ /**
403
+ * One accepted Durable Step result (durability §11): exactly-once-recorded while the Step's
404
+ * external side effect stays honestly at-least-once-executed. Only success is recorded — a failing
405
+ * Step body fails into the handler's error channel and re-executes on re-entry. `output` is the
406
+ * Schema-encoded Step output; `outputDigest` pins it for replay-divergence detection.
407
+ */
408
+ export class ToolStepSettled extends Schema.TaggedClass<ToolStepSettled>(
409
+ "@effect-agent/thread/ToolStepSettled",
410
+ )("ToolStepSettled", {
411
+ runId: RunId,
412
+ toolCallId: ToolCallId,
413
+ stepName: BoundedName,
414
+ output: PersistedJson,
415
+ outputDigest: Digest,
416
+ }) {}
417
+
418
+ /**
419
+ * A canonical approval request for one declared Tool Call (CAP-006, durability §8): with this
420
+ * record durable, "waiting for explicit approval" is a safe suspension boundary — the resumed
421
+ * Attempt replays the declared batch instead of re-invoking the model.
422
+ */
423
+ export class ToolApprovalRequested extends Schema.TaggedClass<ToolApprovalRequested>(
424
+ "@effect-agent/thread/ToolApprovalRequested",
425
+ )("ToolApprovalRequested", {
426
+ runId: RunId,
427
+ turnId: TurnId,
428
+ turn: TurnNumber,
429
+ toolCallId: ToolCallId,
430
+ toolName: BoundedName,
431
+ parametersDigest: Digest,
432
+ }) {}
433
+
434
+ /** The two-valued approval decision family shared by canonical records and ledger intents. */
435
+ export const ApprovalDecision = Schema.Literals(["approved", "denied"]);
436
+ export type ApprovalDecision = typeof ApprovalDecision.Type;
437
+
438
+ /**
439
+ * The canonical decision for one requested approval. Appended by the deciding Attempt (policy
440
+ * auto-decisions) or by the resuming Attempt after a durable `resolveApproval` intent; it is the
441
+ * deterministic decision authority for every later Attempt of the same Run.
442
+ */
443
+ export class ToolApprovalDecided extends Schema.TaggedClass<ToolApprovalDecided>(
444
+ "@effect-agent/thread/ToolApprovalDecided",
445
+ )("ToolApprovalDecided", {
446
+ runId: RunId,
447
+ turn: TurnNumber,
448
+ toolCallId: ToolCallId,
449
+ decision: ApprovalDecision,
450
+ resolver: BoundedName,
451
+ reason: BoundedText,
452
+ }) {}
453
+
454
+ /**
455
+ * First-class interruption audit (durability §9): appended by a superseding Attempt before it
456
+ * re-invokes the model for a Turn whose prior owner died without a complete canonical response.
457
+ * Duplicate provider cost is thereby possible AND observable in canonical history.
458
+ */
459
+ export class ModelResponseInterrupted extends Schema.TaggedClass<ModelResponseInterrupted>(
460
+ "@effect-agent/thread/ModelResponseInterrupted",
461
+ )("ModelResponseInterrupted", {
462
+ runId: RunId,
463
+ supersededEpoch: ProducerEpoch,
464
+ attemptId: AttemptId,
465
+ reason: BoundedText,
466
+ }) {}
467
+
468
+ /**
469
+ * One engine-native compaction committed before the pre-Turn view changes (RUN-026).
470
+ * `coversThrough` is a Thread record sequence: the projection
471
+ * renders records at or below it as a summary (`summarize`), a fresh window (`rollover`), or with
472
+ * cleared tool results (kind `clear-tool-results`), never erasing source
473
+ * history. The record carries no digest by decision: it is appended by the
474
+ * fenced owner into the very log it covers, and re-verifying a digest would
475
+ * re-read the covered range on every wake — the O(history) work compaction
476
+ * exists to remove. Host-supplied ContextCompactor decisions use this same commit path.
477
+ * Summaries exceeding BoundedText are rejected before append, never truncated.
478
+ * `summary` is present exactly for `summarize` records; the projection
479
+ * treats a summarize record without one as invalid and ignores it fail-safe.
480
+ */
481
+ export class CompactionCreated extends Schema.TaggedClass<CompactionCreated>(
482
+ "@effect-agent/thread/CompactionCreated",
483
+ )("CompactionCreated", {
484
+ runId: RunId,
485
+ turn: TurnNumber,
486
+ kind: Schema.Literals(["clear-tool-results", "summarize", "rollover"]),
487
+ coversThrough: CanonicalSequence,
488
+ summary: Schema.optionalKey(BoundedText),
489
+ handoff: Schema.optionalKey(ContextHandoff),
490
+ }) {}
491
+
492
+ export class RunFailed extends Schema.TaggedClass<RunFailed>("@effect-agent/thread/RunFailed")(
493
+ "RunFailed",
494
+ {
495
+ runId: RunId,
496
+ failure: PersistedJson,
497
+ },
498
+ ) {}
499
+
500
+ const RunCompletedFields = Schema.Struct({
501
+ runId: RunId,
502
+ output: PersistedJson,
503
+ /** Application disposition captured with an ordinary completion. */
504
+ runDisposition: Schema.optionalKey(PersistedJson),
505
+ /** Honest soft-landing marker, present exactly when `exhausted` is present. */
506
+ finishReason: Schema.optionalKey(Schema.Literal("budget-exhausted")),
507
+ /** Budget dimension paired with `finishReason` on a soft landing. */
508
+ exhausted: Schema.optionalKey(ExhaustedLimit),
509
+ }).check(
510
+ Schema.makeFilter(
511
+ (completed) =>
512
+ (completed.finishReason === undefined) === (completed.exhausted === undefined) &&
513
+ (completed.runDisposition === undefined || completed.finishReason === undefined),
514
+ { title: "Run completion metadata matches its terminal family" },
515
+ ),
516
+ );
517
+
518
+ export class RunCompleted extends Schema.TaggedClass<RunCompleted>(
519
+ "@effect-agent/thread/RunCompleted",
520
+ )("RunCompleted", RunCompletedFields) {}
521
+
522
+ export class RepairAnnotated extends Schema.TaggedClass<RepairAnnotated>(
523
+ "@effect-agent/thread/RepairAnnotated",
524
+ )("RepairAnnotated", {
525
+ reason: BoundedText,
526
+ details: PersistedJson,
527
+ }) {}
528
+
529
+ /** Terminal outcome family for one accepted Submission (DUR-002). */
530
+ export const SettlementOutcome = Schema.Literals(["completed", "failed", "aborted"]);
531
+ export type SettlementOutcome = typeof SettlementOutcome.Type;
532
+
533
+ /**
534
+ * A durable abort command made canonical before the active worker is interrupted (DUR-012).
535
+ * Repeating the same abort command is idempotent; abort never rewrites a prior terminal outcome.
536
+ */
537
+ export class AbortRequested extends Schema.TaggedClass<AbortRequested>(
538
+ "@effect-agent/thread/AbortRequested",
539
+ )("AbortRequested", {
540
+ submissionId: SubmissionId,
541
+ author: BoundedName,
542
+ reason: BoundedText,
543
+ }) {}
544
+
545
+ /**
546
+ * The single canonical settlement record owed to one accepted Submission (DUR-002, DUR-011).
547
+ * Canonical history is the outcome authority: the ledger row is finalized from this record and
548
+ * never the other way around (DUR-015).
549
+ */
550
+ const RawSubmissionSettled = Schema.Struct({
551
+ submissionId: SubmissionId,
552
+ settlementId: SettlementId,
553
+ receiptId: ReceiptId,
554
+ outcome: SettlementOutcome,
555
+ runId: Schema.optionalKey(RunId),
556
+ result: Schema.optionalKey(PersistedJson),
557
+ /**
558
+ * Application-defined, Schema-encoded disposition for an ordinary completed
559
+ * Run. Absent for budget exhaustion and every non-completed or run-less
560
+ * settlement; consumers decode it with the application definition's Schema.
561
+ */
562
+ runDisposition: Schema.optionalKey(PersistedJson),
563
+ /**
564
+ * Present only when a `completed` Run settled through the final-answer
565
+ * exhaustion resolution (RUN-011, RUN-018): the durable log must be able to
566
+ * distinguish honest-exhaustion completion from ordinary completion without
567
+ * the live event stream. Absent for every ordinary settlement, keeping
568
+ * existing histories and goldens byte-stable (additive, schemaVersion 1).
569
+ */
570
+ finishReason: Schema.optionalKey(Schema.Literal("budget-exhausted")),
571
+ /**
572
+ * The dimension that bound a budget-exhausted completion (RUN-011,
573
+ * RUN-025), carried verbatim from the live `RunCompleted` event so
574
+ * consumers never reconstruct it from message text. Valid only alongside
575
+ * `finishReason: "budget-exhausted"`; absent on histories persisted before
576
+ * the dimension became durable (additive, schemaVersion 1).
577
+ */
578
+ exhausted: Schema.optionalKey(ExhaustedLimit),
579
+ /**
580
+ * The typed `AgentPolicyError.limit` of a `failed` hard-rail settlement
581
+ * (RUN-011): which finite policy dimension failed the Run, preserved
582
+ * alongside the bounded `{errorTag, message}` failure projection in
583
+ * `result`. Absent for every non-policy failure and on histories persisted
584
+ * before the limit became durable (additive, schemaVersion 1).
585
+ */
586
+ policyLimit: Schema.optionalKey(PolicyLimit),
587
+ /** Canonical aggregate of all priced model calls made by this Run. */
588
+ usageSummary: Schema.optionalKey(RunUsageSummary),
589
+ /** Calls included in usageSummary but not in any ModelResponseRecorded, retained on failure. */
590
+ uncommittedModelUsage: Schema.optionalKey(Schema.Array(ModelCallUsage)),
591
+ });
592
+
593
+ const isPolicyFailureProjection = Schema.is(
594
+ Schema.Struct({ errorTag: Schema.Literal("AgentPolicyError") }),
595
+ );
596
+
597
+ const isSettlementFailureDiagnostic = Schema.is(SettlementFailureDiagnostic);
598
+
599
+ const hasValidSettlementFamily = (settled: typeof RawSubmissionSettled.Type): boolean =>
600
+ (settled.finishReason === undefined || settled.outcome === "completed") &&
601
+ (settled.finishReason === undefined) === (settled.exhausted === undefined) &&
602
+ (settled.usageSummary === undefined || settled.runId !== undefined) &&
603
+ (settled.uncommittedModelUsage === undefined ||
604
+ (settled.runId !== undefined && settled.usageSummary !== undefined)) &&
605
+ (settled.runDisposition === undefined ||
606
+ (settled.outcome === "completed" &&
607
+ settled.finishReason === undefined &&
608
+ settled.runId !== undefined &&
609
+ settled.result !== undefined)) &&
610
+ (settled.outcome !== "failed" || isSettlementFailureDiagnostic(settled.result)) &&
611
+ (settled.outcome !== "aborted" || settled.result === undefined) &&
612
+ (settled.policyLimit === undefined ||
613
+ (settled.outcome === "failed" && isPolicyFailureProjection(settled.result)));
614
+
615
+ const SubmissionSettledFields = RawSubmissionSettled.check(
616
+ Schema.makeFilter(hasValidSettlementFamily, {
617
+ title:
618
+ "failed settlements require a bounded diagnostic; aborted settlements carry no result; budget metadata must match its settlement family",
619
+ }),
620
+ );
621
+
622
+ export class SubmissionSettled extends Schema.TaggedClass<SubmissionSettled>(
623
+ "@effect-agent/thread/SubmissionSettled",
624
+ )("SubmissionSettled", SubmissionSettledFields) {}
625
+
626
+ /** Canonical completed settlement; joined completion may legitimately carry no independent result. */
627
+ export type CompletedSubmissionSettled = SubmissionSettled & {
628
+ readonly outcome: "completed";
629
+ };
630
+
631
+ /** Canonical failed settlement; its bounded diagnostic is required and typed. */
632
+ export type FailedSubmissionSettled = SubmissionSettled & {
633
+ readonly outcome: "failed";
634
+ readonly result: SettlementFailureDiagnostic;
635
+ };
636
+
637
+ /** Canonical aborted settlement; abort records intent rather than fabricating a terminal result. */
638
+ export type AbortedSubmissionSettled = SubmissionSettled & {
639
+ readonly outcome: "aborted";
640
+ readonly result?: never;
641
+ };
642
+
643
+ export type SubmissionSettledRecord =
644
+ | CompletedSubmissionSettled
645
+ | FailedSubmissionSettled
646
+ | AbortedSubmissionSettled;
647
+
648
+ /**
649
+ * Canonical-boundary view of `SubmissionSettled`: `finishReason` is valid
650
+ * only on a `completed` outcome, `exhausted` only alongside
651
+ * `finishReason: "budget-exhausted"`, every `failed` outcome requires the exact bounded
652
+ * `SettlementFailureDiagnostic`, aborted outcomes carry no result, and `policyLimit` only occurs
653
+ * on a `failed` outcome whose diagnostic carries the `AgentPolicyError` tag. `runDisposition`
654
+ * occurs only on an ordinary completed settlement with a Run —
655
+ * so a malformed persisted combination such as
656
+ * `{ outcome: "failed", finishReason: "budget-exhausted" }` or a
657
+ * `policyLimit` contradicting `result.errorTag` fails closed at decode
658
+ * instead of becoming trusted audit history (STORE-006, RUN-011).
659
+ */
660
+ export const SubmissionSettledRecord = SubmissionSettled.pipe(
661
+ Schema.refine(
662
+ (settled): settled is SubmissionSettledRecord => hasValidSettlementFamily(settled),
663
+ {
664
+ expected:
665
+ "failed settlements require a bounded diagnostic, aborted settlements carry no result, finishReason only occurs on completed settlements, exhausted only occurs with finishReason budget-exhausted, runDisposition only occurs on an ordinary completed settlement with a Run result, and policyLimit only occurs on a failed AgentPolicyError settlement",
666
+ },
667
+ ),
668
+ );
669
+
670
+ /**
671
+ * PARENT-log record of one durable child establishment request:
672
+ * the exact parent Tool Call, delegation and target identity, the digests that pin the child's
673
+ * Binding/input/grant, the fenced budget reservation, and the INTENDED child identity derived
674
+ * deterministically from the parent Run and Tool Call pair (D4). `childInput` carries the
675
+ * prepared child input in encoded form (D3) so recovery can complete child admission from this
676
+ * record alone — no live delegation handler is required. `childPrincipal`/`childIdempotencyKey`
677
+ * carry the ledger admission scope with the ledger's exact bounds; the layering keeps their
678
+ * branded Schemas in the ledger port.
679
+ */
680
+ export class SubagentRequested extends Schema.TaggedClass<SubagentRequested>(
681
+ "@effect-agent/thread/SubagentRequested",
682
+ )("SubagentRequested", {
683
+ runId: RunId,
684
+ turnId: TurnId,
685
+ turn: TurnNumber,
686
+ toolCallId: ToolCallId,
687
+ delegationId: DelegationId,
688
+ targetAgentId: AgentId,
689
+ targetDigests: DefinitionDigests,
690
+ childInput: PersistedJson,
691
+ childInputDigest: Digest,
692
+ grantDigest: Digest,
693
+ reservationId: BoundedName,
694
+ reservationDigest: Digest,
695
+ childThreadId: ThreadId,
696
+ childPrincipal: BoundedName,
697
+ childIdempotencyKey: BoundedName,
698
+ /** Effective invocation bound, already clamped to the delegation and child Definition. */
699
+ toolCallAllowance: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
700
+ policy: Schema.optionalKey(Schema.toCodecJson(AgentPolicy)),
701
+ budget: Schema.optionalKey(SubagentBudgetReservation),
702
+ grant: Schema.optionalKey(SubagentGrant),
703
+ depth: Schema.optionalKey(DelegationDepth),
704
+ }) {}
705
+
706
+ /**
707
+ * PARENT-log record that the intended child exists as accepted work:
708
+ * the full established child identity. It is appended only after the child Receipt
709
+ * exists — SUB-017 holds by construction because `childReceiptId` is a required field.
710
+ */
711
+ export class SubagentStarted extends Schema.TaggedClass<SubagentStarted>(
712
+ "@effect-agent/thread/SubagentStarted",
713
+ )("SubagentStarted", {
714
+ runId: RunId,
715
+ toolCallId: ToolCallId,
716
+ childThreadId: ThreadId,
717
+ childSubmissionId: SubmissionId,
718
+ childReceiptId: ReceiptId,
719
+ childRunId: RunId,
720
+ }) {}
721
+
722
+ /**
723
+ * PARENT-log record of one verified child settlement join:
724
+ * the child's canonical Settlement identity and outcome, the digests pinning the verified child
725
+ * result and the bounded projected parent result, the child usage summary, and the FINAL
726
+ * consumed/released accounting decision for the reservation. It commits in ONE atomic batch with
727
+ * the parent `ToolCallSettled` record (SUB-019); `beginChildBudgetRelease` replays
728
+ * `finalAccounting` from this record, so canonical history authorizes the release (DUR-015).
729
+ */
730
+ export class SubagentJoined extends Schema.TaggedClass<SubagentJoined>(
731
+ "@effect-agent/thread/SubagentJoined",
732
+ )("SubagentJoined", {
733
+ runId: RunId,
734
+ toolCallId: ToolCallId,
735
+ childSubmissionId: SubmissionId,
736
+ childSettlementId: SettlementId,
737
+ childOutcome: SettlementOutcome,
738
+ childResultDigest: Digest,
739
+ projectedResultDigest: Digest,
740
+ usageSummary: PersistedJson,
741
+ usage: Schema.optionalKey(RunTotals),
742
+ delegatedUsage: Schema.optionalKey(RunTotals),
743
+ reservationId: BoundedName,
744
+ finalAccounting: PersistedJson,
745
+ }) {}
746
+
747
+ /**
748
+ * CHILD-log immutable lineage: the Parent Link plus the digests that pin
749
+ * the child's definition, input, and authority grant. It is the first record after the child's
750
+ * `ThreadCreated` (its own single-record batch, so the generic `thread-created:{cid}`
751
+ * batch identity is never contradicted) and the join path verifies it fail-closed — a fabricated
752
+ * child or parent identity fails Parent Link verification (SUB-004, D10).
753
+ */
754
+ export class SubagentLineageRecorded extends Schema.TaggedClass<SubagentLineageRecorded>(
755
+ "@effect-agent/thread/SubagentLineageRecorded",
756
+ )("SubagentLineageRecorded", {
757
+ parentLink: SubagentParentLink,
758
+ parentSubmissionId: SubmissionId,
759
+ childDefinitionDigests: DefinitionDigests,
760
+ childInputDigest: Digest,
761
+ grantDigest: Digest,
762
+ /** Copied from the canonical request before readiness; restored for every child Attempt. */
763
+ toolCallAllowance: SubagentRequested.fields.toolCallAllowance,
764
+ policy: SubagentRequested.fields.policy,
765
+ budget: SubagentRequested.fields.budget,
766
+ grant: SubagentRequested.fields.grant,
767
+ }) {}
768
+
769
+ export const WorkerReportingIntent = Schema.Struct({
770
+ /** Omitted preserves existing application-mapped reports. */
771
+ mode: Schema.optionalKey(Schema.Literal("standard")),
772
+ sourceDigests: DefinitionDigests,
773
+ destinationDelegationId: Schema.optionalKey(DelegationId),
774
+ });
775
+
776
+ /** Immutable worker Thread origin. Each input has its own digest and parameters separately. */
777
+ export const WorkerOrigin = Schema.Struct({
778
+ worker: WorkerRef,
779
+ source: WorkerSource,
780
+ /** Omitted retains source-subtree funding; worker-run renews only for a new native Run. */
781
+ budgetScope: Schema.optionalKey(WorkerBudgetScope),
782
+ targetDigests: DefinitionDigests,
783
+ policy: Schema.toCodecJson(AgentPolicy),
784
+ budget: SubagentBudgetReservation,
785
+ grant: SubagentGrant,
786
+ depth: DelegationDepth,
787
+ toolCallAllowance: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
788
+ firstMessageId: IdempotencyKey,
789
+ createdAtMillis: Schema.Natural,
790
+ expiresAtMillis: Schema.Natural,
791
+ /** Exact source registration owns projection; absence means reporting was not declared. */
792
+ reporting: Schema.optionalKey(WorkerReportingIntent),
793
+ }).check(Schema.makeFilter((value) => value.expiresAtMillis > value.createdAtMillis));
794
+
795
+ export type WorkerOrigin = typeof WorkerOrigin.Type;
796
+
797
+ /** Frozen per-input metadata; it grants no attached-child or parent-abort semantics. */
798
+ export const WorkerAdmission = Schema.Struct({
799
+ origin: WorkerOrigin,
800
+ messageId: IdempotencyKey,
801
+ parameters: PersistedJson,
802
+ createdAtMillis: Schema.Natural,
803
+ /** Host-bound source input whose subtree funds this input; never chosen by a model. */
804
+ sourceSubmissionId: Schema.optionalKey(SubmissionId),
805
+ /** Enables routed receipt lookup when the delivery is owned by a reporting child. */
806
+ deliveryPrincipal: Schema.optionalKey(Principal),
807
+ /** Proven framework updates use a separate bounded input-capacity partition. */
808
+ reportKind: Schema.optionalKey(Schema.Literal("update")),
809
+ });
810
+
811
+ export type WorkerAdmission = typeof WorkerAdmission.Type;
812
+
813
+ /** Source-log capacity reservation, retained independently of the source Run's settlement. */
814
+ export class WorkerInputRequested extends Schema.TaggedClass<WorkerInputRequested>()(
815
+ "WorkerInputRequested",
816
+ { admission: WorkerAdmission, inputDigest: Digest },
817
+ ) {}
818
+
819
+ /** Child-log origin, reconstructed from a retained delivery before the child becomes ready. */
820
+ export class WorkerOriginRecorded extends Schema.TaggedClass<WorkerOriginRecorded>()(
821
+ "WorkerOriginRecorded",
822
+ { origin: WorkerOrigin },
823
+ ) {}
824
+
825
+ /** Canonical child completion acknowledgement releases only this input's active capacity. */
826
+ export class WorkerInputCompleted extends Schema.TaggedClass<WorkerInputCompleted>()(
827
+ "WorkerInputCompleted",
828
+ {
829
+ messageId: IdempotencyKey,
830
+ workerThreadId: ThreadId,
831
+ submissionId: SubmissionId,
832
+ receiptId: ReceiptId,
833
+ settlementId: SettlementId,
834
+ completedAtMillis: Schema.Natural,
835
+ },
836
+ ) {}
837
+
838
+ /**
839
+ * Frozen report decision for one actual Run, shared by every joined Receipt. The envelope is
840
+ * a Schema-encoded PreparedInput, validated before append and decoded again on recovery.
841
+ * Keeping the encoded value here avoids a Records/PreparedInput schema dependency cycle.
842
+ */
843
+ export class WorkerReportPrepared extends Schema.TaggedClass<WorkerReportPrepared>()(
844
+ "WorkerReportPrepared",
845
+ {
846
+ runId: RunId,
847
+ messageId: IdempotencyKey,
848
+ envelope: PersistedJson,
849
+ createdAtMillis: Schema.Natural,
850
+ deadlineAtMillis: Schema.Natural,
851
+ predecessor: Schema.optionalKey(IdempotencyKey),
852
+ },
853
+ ) {}
854
+
855
+ /** Accepted update and its optional frozen parent delivery are one atomic canonical fact. */
856
+ export class AgentUpdateEmitted extends Schema.TaggedClass<AgentUpdateEmitted>()(
857
+ "AgentUpdateEmitted",
858
+ {
859
+ update: Update,
860
+ definitions: DefinitionDigests,
861
+ delivery: Schema.optionalKey(
862
+ Schema.Struct({
863
+ messageId: IdempotencyKey,
864
+ envelope: PersistedJson,
865
+ createdAtMillis: Schema.Natural,
866
+ deadlineAtMillis: Schema.Natural,
867
+ predecessor: Schema.optionalKey(IdempotencyKey),
868
+ }),
869
+ ),
870
+ },
871
+ ) {}
872
+
873
+ /** Permanent bounded report refusal. Application errors and raw Run dispositions stay private. */
874
+ export class WorkerReportRefused extends Schema.TaggedClass<WorkerReportRefused>()(
875
+ "WorkerReportRefused",
876
+ {
877
+ runId: RunId,
878
+ messageId: IdempotencyKey,
879
+ reason: Schema.Literals([
880
+ "declaration-unavailable",
881
+ "destination",
882
+ "projection",
883
+ "input",
884
+ "preparation",
885
+ "timeout",
886
+ "defect",
887
+ "expired",
888
+ "denied",
889
+ "capacity",
890
+ ]),
891
+ },
892
+ ) {}
893
+
894
+ /** Frozen source proof of peer provenance, readable through routed canonical storage. */
895
+ export class PeerMessagePrepared extends Schema.TaggedClass<PeerMessagePrepared>()(
896
+ "PeerMessagePrepared",
897
+ {
898
+ messageId: IdempotencyKey,
899
+ sourcePrincipal: Principal,
900
+ operation: Schema.Literals(["send", "reply"]),
901
+ deadlineAtMillis: Schema.Int.check(Schema.isGreaterThan(0)),
902
+ encodedEnvelope: PersistedJson,
903
+ },
904
+ ) {}
905
+
906
+ /**
907
+ * One disjoint subtree slice shared by attached and background children of a source input.
908
+ * The source keeps its own execution ceiling; descendants spend only the remaining allocation.
909
+ * Reservations include future descendant slots and never refund, including after interruption.
910
+ * resultBytes reserves the terminal/projection result, not cumulative Tool output bytes.
911
+ */
912
+ export class SubtreeBudgetReserved extends Schema.TaggedClass<SubtreeBudgetReserved>()(
913
+ "SubtreeBudgetReserved",
914
+ {
915
+ reservationId: BoundedName,
916
+ sourceSubmissionId: Schema.optionalKey(SubmissionId),
917
+ childThreadId: ThreadId,
918
+ lifetime: Schema.Literals(["attached", "background"]),
919
+ depth: DelegationDepth,
920
+ policy: Schema.toCodecJson(AgentPolicy),
921
+ grant: SubagentGrant,
922
+ budget: SubagentBudgetReservation,
923
+ },
924
+ ) {}
925
+
926
+ /**
927
+ * Current private-development canonical payload family. Phase 5 adds the seven durable-Tool tags
928
+ * (prepared/unknown/resolved/step/approval-request/approval-decision/interrupted) additively; S2
929
+ * adds the four durable-Subagent tags (requested/started/joined/lineage) additively, so the
930
+ * envelope keeps `schemaVersion: 1` (P4 precedent for additive payload tags).
931
+ */
932
+ export const CanonicalRecordPayload = Schema.Union([
933
+ ThreadCreated,
934
+ UserInputRecorded,
935
+ RunStartedRecord,
936
+ RunPolicyUsageReserved,
937
+ ModelCompleted,
938
+ ModelResponseRecorded,
939
+ ToolCallPrepared,
940
+ ToolCallSettled,
941
+ ToolCallUnknown,
942
+ ToolCallResolved,
943
+ ToolStepSettled,
944
+ ToolApprovalRequested,
945
+ ToolApprovalDecided,
946
+ ModelResponseInterrupted,
947
+ CompactionCreated,
948
+ RunFailed,
949
+ RunCompleted,
950
+ AbortRequested,
951
+ SubmissionSettledRecord,
952
+ SubagentRequested,
953
+ SubagentStarted,
954
+ SubagentJoined,
955
+ SubagentLineageRecorded,
956
+ WorkerInputRequested,
957
+ WorkerOriginRecorded,
958
+ WorkerInputCompleted,
959
+ WorkerReportPrepared,
960
+ AgentUpdateEmitted,
961
+ WorkerReportRefused,
962
+ PeerMessagePrepared,
963
+ SubtreeBudgetReserved,
964
+ RepairAnnotated,
965
+ ]);
966
+
967
+ export type CanonicalRecordPayload = typeof CanonicalRecordPayload.Type;
968
+
969
+ /**
970
+ * Versioned record envelope stored in an atomic batch. Thread ordering is assigned only
971
+ * when the batch is committed.
972
+ */
973
+ export class RecordEnvelope extends Schema.Class<RecordEnvelope>(
974
+ "@effect-agent/thread/RecordEnvelope",
975
+ )({
976
+ recordId: RecordId,
977
+ family: Schema.Literal("thread"),
978
+ schemaVersion: Schema.Literal(1),
979
+ createdAt: Schema.DateTimeUtcFromString,
980
+ deploymentId: DeploymentId,
981
+ payload: CanonicalRecordPayload,
982
+ }) {}
983
+
984
+ /** Backward-compatible domain name for a canonical record. */
985
+ export const CanonicalRecord = RecordEnvelope;
986
+ export type CanonicalRecord = RecordEnvelope;
987
+
988
+ /** One non-empty, bounded, idempotent atomic append unit. */
989
+ export class CanonicalBatch extends Schema.Class<CanonicalBatch>(
990
+ "@effect-agent/thread/CanonicalBatch",
991
+ )({
992
+ batchId: BatchId,
993
+ producerId: ProducerId,
994
+ records: Schema.NonEmptyArray(RecordEnvelope).check(Schema.isMaxLength(256)),
995
+ }) {}
996
+
997
+ /**
998
+ * A committed record with its Thread ordering and opaque resumable observation cursor.
999
+ */
1000
+ export class CanonicalRecordEnvelope extends Schema.Class<CanonicalRecordEnvelope>(
1001
+ "@effect-agent/thread/CanonicalRecordEnvelope",
1002
+ )({
1003
+ threadId: ThreadId,
1004
+ batchId: BatchId,
1005
+ sequence: CanonicalSequence,
1006
+ offset: ObservationOffset,
1007
+ record: RecordEnvelope,
1008
+ }) {}
1009
+
1010
+ export const CURRENT_CANONICAL_SCHEMA_VERSION = 1 as const;