effect-agent 0.1.0-beta.85 → 0.1.0-beta.87

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 (751) 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-BLyETCPo.mjs +4562 -0
  7. package/dist/AgentRuntime-BLyETCPo.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-uggeJpv3.mjs +6368 -0
  13. package/dist/DurableAgentRuntime-uggeJpv3.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-Cy_hU1tv.mjs +1469 -0
  45. package/dist/Subagent-Cy_hU1tv.mjs.map +1 -0
  46. package/dist/Subagent-DyfzHNdv.d.mts +826 -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 +6 -5
  61. package/dist/ToolExposure.mjs +17 -9
  62. package/dist/ToolExposure.mjs.map +1 -1
  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 +435 -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 +88 -54
  368. package/dist/index.mjs +97 -54
  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 +252 -0
  388. package/dist/sandbox/ProtectedBrowser.mjs +270 -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 -1
  398. package/src/Ephemeral.ts +17 -0
  399. package/src/ToolExposure.ts +2 -2
  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 +774 -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 +10117 -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 +96 -53
  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 +413 -0
  538. package/src/sandbox/Sandbox.ts +241 -0
  539. package/dist/Agent.d.mts +0 -5
  540. package/dist/Agent.mjs +0 -10
  541. package/dist/Agent.mjs.map +0 -1
  542. package/dist/AgentError.d.mts +0 -5
  543. package/dist/AgentError.mjs +0 -10
  544. package/dist/AgentError.mjs.map +0 -1
  545. package/dist/AgentPolicy.d.mts +0 -5
  546. package/dist/AgentPolicy.mjs +0 -10
  547. package/dist/AgentPolicy.mjs.map +0 -1
  548. package/dist/AgentRuntime.d.mts +0 -5
  549. package/dist/AgentRuntime.mjs +0 -10
  550. package/dist/AgentRuntime.mjs.map +0 -1
  551. package/dist/AgentUpdates.d.mts +0 -5
  552. package/dist/AgentUpdates.mjs +0 -10
  553. package/dist/AgentUpdates.mjs.map +0 -1
  554. package/dist/Approval.d.mts +0 -5
  555. package/dist/Approval.mjs +0 -10
  556. package/dist/Approval.mjs.map +0 -1
  557. package/dist/Budget.d.mts +0 -5
  558. package/dist/Budget.mjs +0 -10
  559. package/dist/Budget.mjs.map +0 -1
  560. package/dist/CodeMode.d.mts +0 -5
  561. package/dist/CodeMode.mjs +0 -10
  562. package/dist/CodeMode.mjs.map +0 -1
  563. package/dist/Commands.d.mts +0 -5
  564. package/dist/Commands.mjs +0 -10
  565. package/dist/Commands.mjs.map +0 -1
  566. package/dist/Compaction.d.mts +0 -5
  567. package/dist/Compaction.mjs +0 -10
  568. package/dist/Compaction.mjs.map +0 -1
  569. package/dist/ContextCompactor.d.mts +0 -5
  570. package/dist/ContextCompactor.mjs +0 -10
  571. package/dist/ContextCompactor.mjs.map +0 -1
  572. package/dist/ContextHistory.d.mts +0 -5
  573. package/dist/ContextHistory.mjs +0 -10
  574. package/dist/ContextHistory.mjs.map +0 -1
  575. package/dist/ContextTools.d.mts +0 -5
  576. package/dist/ContextTools.mjs +0 -10
  577. package/dist/ContextTools.mjs.map +0 -1
  578. package/dist/ContextWindow.d.mts +0 -5
  579. package/dist/ContextWindow.mjs +0 -10
  580. package/dist/ContextWindow.mjs.map +0 -1
  581. package/dist/DurableStep.d.mts +0 -5
  582. package/dist/DurableStep.mjs +0 -10
  583. package/dist/DurableStep.mjs.map +0 -1
  584. package/dist/EphemeralThreads.d.mts +0 -5
  585. package/dist/EphemeralThreads.mjs +0 -10
  586. package/dist/EphemeralThreads.mjs.map +0 -1
  587. package/dist/IdGenerator.d.mts +0 -5
  588. package/dist/IdGenerator.mjs +0 -10
  589. package/dist/IdGenerator.mjs.map +0 -1
  590. package/dist/Identifiers.d.mts +0 -5
  591. package/dist/Identifiers.mjs +0 -10
  592. package/dist/Identifiers.mjs.map +0 -1
  593. package/dist/Mcp.d.mts +0 -5
  594. package/dist/Mcp.mjs +0 -10
  595. package/dist/Mcp.mjs.map +0 -1
  596. package/dist/McpClient.d.mts +0 -5
  597. package/dist/McpClient.mjs +0 -10
  598. package/dist/McpClient.mjs.map +0 -1
  599. package/dist/Memory.d.mts +0 -5
  600. package/dist/Memory.mjs +0 -10
  601. package/dist/Memory.mjs.map +0 -1
  602. package/dist/MemoryNamespace.d.mts +0 -5
  603. package/dist/MemoryNamespace.mjs +0 -10
  604. package/dist/MemoryNamespace.mjs.map +0 -1
  605. package/dist/MemoryNotes.d.mts +0 -5
  606. package/dist/MemoryNotes.mjs +0 -10
  607. package/dist/MemoryNotes.mjs.map +0 -1
  608. package/dist/MemoryReference.d.mts +0 -5
  609. package/dist/MemoryReference.mjs +0 -10
  610. package/dist/MemoryReference.mjs.map +0 -1
  611. package/dist/MemoryRevalidation.d.mts +0 -5
  612. package/dist/MemoryRevalidation.mjs +0 -10
  613. package/dist/MemoryRevalidation.mjs.map +0 -1
  614. package/dist/MemoryStore.d.mts +0 -5
  615. package/dist/MemoryStore.mjs +0 -10
  616. package/dist/MemoryStore.mjs.map +0 -1
  617. package/dist/Messaging.d.mts +0 -5
  618. package/dist/Messaging.mjs +0 -10
  619. package/dist/Messaging.mjs.map +0 -1
  620. package/dist/MessagingHost.d.mts +0 -5
  621. package/dist/MessagingHost.mjs +0 -10
  622. package/dist/MessagingHost.mjs.map +0 -1
  623. package/dist/ModelContext.d.mts +0 -5
  624. package/dist/ModelContext.mjs +0 -10
  625. package/dist/ModelContext.mjs.map +0 -1
  626. package/dist/Receipt.d.mts +0 -5
  627. package/dist/Receipt.mjs +0 -10
  628. package/dist/Receipt.mjs.map +0 -1
  629. package/dist/Redaction.d.mts +0 -5
  630. package/dist/Redaction.mjs +0 -10
  631. package/dist/Redaction.mjs.map +0 -1
  632. package/dist/Remembering.d.mts +0 -5
  633. package/dist/Remembering.mjs +0 -10
  634. package/dist/Remembering.mjs.map +0 -1
  635. package/dist/RememberingStore.d.mts +0 -5
  636. package/dist/RememberingStore.mjs +0 -10
  637. package/dist/RememberingStore.mjs.map +0 -1
  638. package/dist/RunEvent.d.mts +0 -5
  639. package/dist/RunEvent.mjs +0 -10
  640. package/dist/RunEvent.mjs.map +0 -1
  641. package/dist/RunEventSink.d.mts +0 -5
  642. package/dist/RunEventSink.mjs +0 -10
  643. package/dist/RunEventSink.mjs.map +0 -1
  644. package/dist/RunHooks.d.mts +0 -5
  645. package/dist/RunHooks.mjs +0 -10
  646. package/dist/RunHooks.mjs.map +0 -1
  647. package/dist/RunOptions.d.mts +0 -5
  648. package/dist/RunOptions.mjs +0 -10
  649. package/dist/RunOptions.mjs.map +0 -1
  650. package/dist/RunPolicyUsage.d.mts +0 -5
  651. package/dist/RunPolicyUsage.mjs +0 -10
  652. package/dist/RunPolicyUsage.mjs.map +0 -1
  653. package/dist/SemanticMemory.d.mts +0 -5
  654. package/dist/SemanticMemory.mjs +0 -10
  655. package/dist/SemanticMemory.mjs.map +0 -1
  656. package/dist/SemanticMemoryIndex.d.mts +0 -5
  657. package/dist/SemanticMemoryIndex.mjs +0 -10
  658. package/dist/SemanticMemoryIndex.mjs.map +0 -1
  659. package/dist/SemanticMemoryRevalidation.d.mts +0 -5
  660. package/dist/SemanticMemoryRevalidation.mjs +0 -10
  661. package/dist/SemanticMemoryRevalidation.mjs.map +0 -1
  662. package/dist/Subagent.d.mts +0 -5
  663. package/dist/Subagent.mjs +0 -10
  664. package/dist/Subagent.mjs.map +0 -1
  665. package/dist/SubagentContract.d.mts +0 -5
  666. package/dist/SubagentContract.mjs +0 -10
  667. package/dist/SubagentContract.mjs.map +0 -1
  668. package/dist/SubagentHost.d.mts +0 -5
  669. package/dist/SubagentHost.mjs +0 -10
  670. package/dist/SubagentHost.mjs.map +0 -1
  671. package/dist/SubagentReservations.d.mts +0 -5
  672. package/dist/SubagentReservations.mjs +0 -10
  673. package/dist/SubagentReservations.mjs.map +0 -1
  674. package/dist/ThreadHistory.d.mts +0 -5
  675. package/dist/ThreadHistory.mjs +0 -10
  676. package/dist/ThreadHistory.mjs.map +0 -1
  677. package/dist/ToolBroker.d.mts +0 -5
  678. package/dist/ToolBroker.mjs +0 -10
  679. package/dist/ToolBroker.mjs.map +0 -1
  680. package/dist/ToolDiscovery.d.mts +0 -5
  681. package/dist/ToolDiscovery.mjs +0 -10
  682. package/dist/ToolDiscovery.mjs.map +0 -1
  683. package/dist/ToolResult.d.mts +0 -5
  684. package/dist/ToolResult.mjs +0 -10
  685. package/dist/ToolResult.mjs.map +0 -1
  686. package/dist/Usage.d.mts +0 -5
  687. package/dist/Usage.mjs +0 -10
  688. package/dist/Usage.mjs.map +0 -1
  689. package/dist/WebCapture.d.mts +0 -5
  690. package/dist/WebCapture.mjs +0 -10
  691. package/dist/WebCapture.mjs.map +0 -1
  692. package/dist/WebSearch.d.mts +0 -5
  693. package/dist/WebSearch.mjs +0 -10
  694. package/dist/WebSearch.mjs.map +0 -1
  695. package/dist/Worker.d.mts +0 -5
  696. package/dist/Worker.mjs +0 -10
  697. package/dist/Worker.mjs.map +0 -1
  698. package/dist/rolldown-runtime-BBjsoOtd.mjs +0 -27
  699. package/src/Agent.ts +0 -1
  700. package/src/AgentError.ts +0 -1
  701. package/src/AgentPolicy.ts +0 -1
  702. package/src/AgentRuntime.ts +0 -1
  703. package/src/AgentUpdates.ts +0 -1
  704. package/src/Approval.ts +0 -1
  705. package/src/Budget.ts +0 -1
  706. package/src/CodeMode.ts +0 -1
  707. package/src/Commands.ts +0 -1
  708. package/src/Compaction.ts +0 -1
  709. package/src/ContextCompactor.ts +0 -1
  710. package/src/ContextHistory.ts +0 -1
  711. package/src/ContextTools.ts +0 -1
  712. package/src/ContextWindow.ts +0 -1
  713. package/src/DurableStep.ts +0 -1
  714. package/src/EphemeralThreads.ts +0 -1
  715. package/src/IdGenerator.ts +0 -1
  716. package/src/Identifiers.ts +0 -1
  717. package/src/Mcp.ts +0 -1
  718. package/src/McpClient.ts +0 -1
  719. package/src/Memory.ts +0 -1
  720. package/src/MemoryNamespace.ts +0 -1
  721. package/src/MemoryNotes.ts +0 -1
  722. package/src/MemoryReference.ts +0 -1
  723. package/src/MemoryRevalidation.ts +0 -1
  724. package/src/MemoryStore.ts +0 -1
  725. package/src/Messaging.ts +0 -1
  726. package/src/MessagingHost.ts +0 -1
  727. package/src/ModelContext.ts +0 -1
  728. package/src/Receipt.ts +0 -1
  729. package/src/Redaction.ts +0 -1
  730. package/src/Remembering.ts +0 -1
  731. package/src/RememberingStore.ts +0 -1
  732. package/src/RunEvent.ts +0 -1
  733. package/src/RunEventSink.ts +0 -1
  734. package/src/RunHooks.ts +0 -1
  735. package/src/RunOptions.ts +0 -1
  736. package/src/RunPolicyUsage.ts +0 -1
  737. package/src/SemanticMemory.ts +0 -1
  738. package/src/SemanticMemoryIndex.ts +0 -1
  739. package/src/SemanticMemoryRevalidation.ts +0 -1
  740. package/src/Subagent.ts +0 -1
  741. package/src/SubagentContract.ts +0 -1
  742. package/src/SubagentHost.ts +0 -1
  743. package/src/SubagentReservations.ts +0 -1
  744. package/src/ThreadHistory.ts +0 -1
  745. package/src/ToolBroker.ts +0 -1
  746. package/src/ToolDiscovery.ts +0 -1
  747. package/src/ToolResult.ts +0 -1
  748. package/src/Usage.ts +0 -1
  749. package/src/WebCapture.ts +0 -1
  750. package/src/WebSearch.ts +0 -1
  751. package/src/Worker.ts +0 -1
@@ -0,0 +1,751 @@
1
+ import { Digest } from "./Records.mjs";
2
+ import { AcceptedEvent, DeliveryChange, SubscriptionChange, SubscriptionDelivery, SubscriptionDeliveryKey, SubscriptionError, SubscriptionFailpoint, SubscriptionKey, SubscriptionLimits, SubscriptionName, SubscriptionRecord, SubscriptionRetentionPolicy, SubscriptionScanCursors, SubscriptionStore, subscriptionDeliveryKeyString } from "./Subscription.mjs";
3
+ import { applySubscriptionChange, applySubscriptionDeliveryChange, sameAcceptedEventIdentity, sameSourcePartition, subscriptionCanSelect, subscriptionDeliveryCanSelect, validateEventRetention } from "./SubscriptionTransition.mjs";
4
+ import { Clock, Context, Effect, Result, Schema } from "effect";
5
+ import * as SqlClientService from "effect/unstable/sql/SqlClient";
6
+ //#region src/durable/SqlSubscriptionStore.ts
7
+ const CountRow = Schema.Struct({ count: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)) });
8
+ const SequenceRow = Schema.Struct({ sequence: Schema.Natural });
9
+ const ScanRow = Schema.Struct({
10
+ event_scan_cursor: Schema.String,
11
+ delivery_scan_cursor: Schema.String,
12
+ recovery_scan_cursor: Schema.Natural
13
+ });
14
+ const error = (reason, code) => SubscriptionError.make({
15
+ reason,
16
+ code
17
+ });
18
+ const unavailable = (operation) => error("storage", operation);
19
+ const corrupt = (operation) => error("corrupt", operation);
20
+ const bytes = (value) => new TextEncoder().encode(JSON.stringify(value)).byteLength;
21
+ const validate = (schema, value, code) => Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(() => error("validation", code)));
22
+ const encode = (schema, value, code) => Schema.encodeEffect(Schema.fromJsonString(schema))(value).pipe(Effect.mapError(() => corrupt(code)));
23
+ const decode = (schema, value, code) => Schema.decodeEffect(Schema.fromJsonString(schema))(value).pipe(Effect.mapError(() => corrupt(code)));
24
+ const decodeRows = (schema, rows, code) => Schema.decodeUnknownEffect(Schema.Array(schema))(rows).pipe(Effect.mapError(() => corrupt(code)));
25
+ const sameDeliveryIdentity = (left, right) => subscriptionDeliveryKeyString(left.key) === subscriptionDeliveryKeyString(right.key) && left.deliveryId === right.deliveryId && left.source.name === right.source.name && left.source.version === right.source.version && left.threadId === right.threadId && left.admissionKey === right.admissionKey && left.subscriptionFingerprint === right.subscriptionFingerprint && left.eventDigest === right.eventDigest;
26
+ /**
27
+ * Adapter-owned atomic transaction on the store's SqlClient, including any native alarm update.
28
+ * Return only after commit; a failed body must leave its writes uncommitted. Before-mutation
29
+ * failpoints run inside the body, and after-mutation failpoints run after this operation returns.
30
+ */
31
+ var SqlSubscriptionTransaction = class extends Context.Service()("@effect-agent/thread/SqlSubscriptionTransaction") {};
32
+ /**
33
+ * Shared SQLite subscription operations over an existing SqlClient. The adapter validates the
34
+ * partition, initializes its tables, and provides SqlSubscriptionTransaction at construction.
35
+ * The returned methods capture the SQL client, transaction service, and failpoint handler.
36
+ * Cloudflare's transaction also updates its native alarm before committing.
37
+ */
38
+ const makeSqlSubscriptionStore = Effect.fn("SqlSubscriptionStore.make")(function* (partition, options) {
39
+ const sql = yield* SqlClientService.SqlClient;
40
+ const failpoint = yield* SubscriptionFailpoint;
41
+ const transactions = yield* SqlSubscriptionTransaction;
42
+ const StoredJson = Schema.String.check(Schema.isMaxLength(options.maxStoredJsonLength));
43
+ const JsonRow = Schema.Struct({ record_json: StoredJson });
44
+ const RegistrationRow = Schema.Struct({
45
+ owner_id: Schema.String,
46
+ subscription_id: Schema.String,
47
+ ordinal: Schema.Natural,
48
+ source_name: Schema.String,
49
+ source_version: Schema.String,
50
+ matching_key: Schema.String,
51
+ state: SubscriptionRecord.fields.state,
52
+ expires_at_millis: Schema.NullOr(Schema.Number),
53
+ recovery_at_millis: Schema.NullOr(Schema.Number),
54
+ recovery_present: Schema.Literals([0, 1]),
55
+ record_json: StoredJson
56
+ });
57
+ const EventRow = Schema.Struct({
58
+ event_id: Schema.String,
59
+ source_name: Schema.String,
60
+ source_version: Schema.String,
61
+ matching_key: Schema.String,
62
+ payload_digest: Digest,
63
+ cutoff: Schema.Natural,
64
+ cursor: Schema.Natural,
65
+ routing_complete: Schema.Number,
66
+ tombstone: Schema.Literals([0, 1]),
67
+ next_attempt_at_millis: Schema.Number,
68
+ record_json: StoredJson
69
+ });
70
+ const DeliveryRow = Schema.Struct({
71
+ owner_id: Schema.String,
72
+ subscription_id: Schema.String,
73
+ event_id: Schema.String,
74
+ delivery_key: Schema.String,
75
+ state: SubscriptionDelivery.fields.state,
76
+ next_attempt_at_millis: Schema.Number,
77
+ record_json: StoredJson
78
+ });
79
+ yield* sql`CREATE TABLE IF NOT EXISTS effect_agent_event_retention (
80
+ tenant_id TEXT NOT NULL, source_address TEXT NOT NULL, replay_horizon_millis INTEGER NOT NULL,
81
+ next_maintenance_at_millis INTEGER, tombstone_count INTEGER NOT NULL DEFAULT 0, event_cursor TEXT NOT NULL DEFAULT '', delivery_cursor TEXT NOT NULL DEFAULT '', PRIMARY KEY (tenant_id, source_address)
82
+ )`.pipe(Effect.mapError(() => unavailable("initialize event retention")));
83
+ yield* sql`
84
+ INSERT INTO effect_agent_subscription_sequences (
85
+ tenant_id, source_address, sequence, event_scan_cursor, delivery_scan_cursor, recovery_scan_cursor
86
+ ) VALUES (${partition.tenantId}, ${partition.address}, 0, '', '', 0) ON CONFLICT DO NOTHING
87
+ `.pipe(Effect.mapError(() => unavailable("initialize subscription partition")));
88
+ yield* sql`CREATE INDEX IF NOT EXISTS effect_agent_events_retention_order ON effect_agent_subscription_events
89
+ (tenant_id, source_address, tombstone, event_id)
90
+ `.pipe(Effect.mapError(() => unavailable("index event retention")));
91
+ yield* sql`CREATE INDEX IF NOT EXISTS effect_agent_subscriptions_recovery_reference ON effect_agent_subscriptions
92
+ (tenant_id, source_address, source_name, source_version, matching_key, recovery_present)
93
+ WHERE recovery_present=1
94
+ `.pipe(Effect.mapError(() => unavailable("index recovery retention")));
95
+ yield* sql`CREATE INDEX IF NOT EXISTS effect_agent_deliveries_event ON effect_agent_subscription_deliveries
96
+ (tenant_id, source_address, event_id, state)
97
+ `.pipe(Effect.mapError(() => unavailable("index delivery retention")));
98
+ const query = (effect, code) => effect.pipe(Effect.mapError(() => unavailable(code)));
99
+ const requirePartition = (candidate, code) => sameSourcePartition(candidate, partition) ? Effect.void : Effect.fail(error("validation", code));
100
+ const requireKey = Effect.fn("SqlSubscriptionStore.requireKey")(function* (input, code) {
101
+ const key = yield* validate(SubscriptionKey, input, code);
102
+ yield* requirePartition(key.partition, code);
103
+ return key;
104
+ });
105
+ const readRegistration = Effect.fn("SqlSubscriptionStore.readRegistration")(function* (key, code) {
106
+ const rows = yield* query(sql`
107
+ SELECT owner_id, subscription_id, ordinal, source_name, source_version, matching_key, state,
108
+ expires_at_millis, recovery_at_millis, recovery_present, record_json FROM effect_agent_subscriptions
109
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
110
+ AND owner_id=${key.ownerId} AND subscription_id=${key.subscriptionId}
111
+ `, code);
112
+ const decodedRows = yield* decodeRows(RegistrationRow, rows, code);
113
+ if (decodedRows.length > 1) return yield* corrupt(code);
114
+ const row = decodedRows[0];
115
+ if (row === void 0) return null;
116
+ const record = yield* decode(SubscriptionRecord, row.record_json, code);
117
+ if (!sameSourcePartition(record.key.partition, partition) || record.key.ownerId !== row.owner_id || record.key.subscriptionId !== row.subscription_id || record.ordinal !== row.ordinal || record.configuration.source.name !== row.source_name || record.configuration.source.version !== row.source_version || record.configuration.matchingKey !== row.matching_key || record.state !== row.state || record.configuration.expiresAtMillis !== row.expires_at_millis || (record.recovery?.nextAttemptAtMillis ?? null) !== row.recovery_at_millis || (record.recovery === null ? 0 : 1) !== row.recovery_present) return yield* corrupt(`${code}-projection`);
118
+ return record;
119
+ });
120
+ const readEvent = Effect.fn("SqlSubscriptionStore.readEvent")(function* (eventId, code) {
121
+ const rows = yield* query(sql`
122
+ SELECT event_id, source_name, source_version, matching_key, payload_digest, cutoff, cursor,
123
+ routing_complete, tombstone, next_attempt_at_millis, record_json FROM effect_agent_subscription_events
124
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND event_id=${eventId}
125
+ `, code);
126
+ const decodedRows = yield* decodeRows(EventRow, rows, code);
127
+ if (decodedRows.length > 1) return yield* corrupt(code);
128
+ const row = decodedRows[0];
129
+ if (row === void 0) return null;
130
+ const event = yield* decode(AcceptedEvent, row.record_json, code);
131
+ if (!sameSourcePartition(event.partition, partition) || event.eventId !== row.event_id || event.source.name !== row.source_name || event.source.version !== row.source_version || event.matchingKey !== row.matching_key || event.payloadDigest !== row.payload_digest || event.cutoff !== row.cutoff || event.cursor !== row.cursor || (event.routingComplete ? 1 : 0) !== row.routing_complete || (event.tombstone === true ? 1 : 0) !== row.tombstone || event.nextAttemptAtMillis !== row.next_attempt_at_millis) return yield* corrupt(`${code}-projection`);
132
+ return event;
133
+ });
134
+ const readDelivery = Effect.fn("SqlSubscriptionStore.readDelivery")(function* (key, code) {
135
+ const rows = yield* query(sql`
136
+ SELECT owner_id, subscription_id, event_id, delivery_key, state, next_attempt_at_millis, record_json
137
+ FROM effect_agent_subscription_deliveries
138
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
139
+ AND owner_id=${key.subscription.ownerId} AND subscription_id=${key.subscription.subscriptionId}
140
+ AND event_id=${key.eventId}
141
+ `, code);
142
+ const decodedRows = yield* decodeRows(DeliveryRow, rows, code);
143
+ if (decodedRows.length > 1) return yield* corrupt(code);
144
+ const row = decodedRows[0];
145
+ if (row === void 0) return null;
146
+ const delivery = yield* decode(SubscriptionDelivery, row.record_json, code);
147
+ if (!sameSourcePartition(delivery.key.subscription.partition, partition) || delivery.key.subscription.ownerId !== row.owner_id || delivery.key.subscription.subscriptionId !== row.subscription_id || delivery.key.eventId !== row.event_id || subscriptionDeliveryKeyString(delivery.key) !== row.delivery_key || delivery.state !== row.state || delivery.retry.nextAttemptAtMillis !== row.next_attempt_at_millis) return yield* corrupt(`${code}-projection`);
148
+ return delivery;
149
+ });
150
+ const count = Effect.fn("SqlSubscriptionStore.count")(function* (statement, code) {
151
+ const rows = yield* query(statement, code);
152
+ const decoded = yield* decodeRows(CountRow, rows, code);
153
+ if (decoded.length !== 1) return yield* corrupt(code);
154
+ return decoded[0].count;
155
+ });
156
+ const nextSequence = Effect.fn("SqlSubscriptionStore.nextSequence")(function* () {
157
+ const rows = yield* query(sql`
158
+ UPDATE effect_agent_subscription_sequences SET sequence=sequence+1
159
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
160
+ RETURNING sequence
161
+ `, "advance subscription sequence");
162
+ const decoded = yield* decodeRows(SequenceRow, rows, "advance subscription sequence");
163
+ if (decoded.length !== 1) return yield* corrupt("subscription sequence");
164
+ return decoded[0].sequence;
165
+ });
166
+ const writeRegistration = Effect.fn("SqlSubscriptionStore.writeRegistration")(function* (record) {
167
+ const json = yield* encode(SubscriptionRecord, record, "encode subscription");
168
+ yield* query(sql`
169
+ UPDATE effect_agent_subscriptions SET ordinal=${record.ordinal}, source_name=${record.configuration.source.name},
170
+ source_version=${record.configuration.source.version}, matching_key=${record.configuration.matchingKey}, state=${record.state}, expires_at_millis=${record.configuration.expiresAtMillis},
171
+ recovery_at_millis=${record.recovery?.nextAttemptAtMillis ?? null}, recovery_present=${record.recovery === null ? 0 : 1}, record_json=${json}
172
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
173
+ AND owner_id=${record.key.ownerId} AND subscription_id=${record.key.subscriptionId}
174
+ `, "write subscription");
175
+ });
176
+ const writeEvent = Effect.fn("SqlSubscriptionStore.writeEvent")(function* (event) {
177
+ const json = yield* encode(AcceptedEvent, event, "encode event");
178
+ yield* query(sql`
179
+ UPDATE effect_agent_subscription_events SET cursor=${event.cursor}, routing_complete=${event.routingComplete ? 1 : 0}, tombstone=${event.tombstone === true ? 1 : 0},
180
+ next_attempt_at_millis=${event.nextAttemptAtMillis}, record_json=${json}
181
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND event_id=${event.eventId}
182
+ `, "write event");
183
+ });
184
+ const writeDelivery = Effect.fn("SqlSubscriptionStore.writeDelivery")(function* (delivery) {
185
+ const json = yield* encode(SubscriptionDelivery, delivery, "encode delivery");
186
+ yield* query(sql`
187
+ UPDATE effect_agent_subscription_deliveries SET state=${delivery.state},
188
+ next_attempt_at_millis=${delivery.retry.nextAttemptAtMillis}, record_json=${json}
189
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
190
+ AND owner_id=${delivery.key.subscription.ownerId} AND subscription_id=${delivery.key.subscription.subscriptionId}
191
+ AND event_id=${delivery.key.eventId}
192
+ `, "write delivery");
193
+ });
194
+ const register = Effect.fn("SqlSubscriptionStore.register")(function* (input, inputLimits) {
195
+ const record = yield* validate(SubscriptionRecord, input, "register-record");
196
+ const limits = yield* validate(SubscriptionLimits, inputLimits, "register-limits");
197
+ yield* requirePartition(record.key.partition, "register-partition");
198
+ const result = yield* transactions.run(Effect.gen(function* () {
199
+ const existing = yield* readRegistration(record.key, "register-existing");
200
+ if (existing !== null) {
201
+ if (existing.creationFingerprint !== record.creationFingerprint) return yield* error("conflict", "registration-identity");
202
+ return {
203
+ value: existing,
204
+ changed: false
205
+ };
206
+ }
207
+ if (bytes(record.configuration.context) > limits.maxContextBytes) return yield* error("capacity", "context-bytes");
208
+ if (bytes(record.configuration.parameters) > limits.maxPayloadBytes) return yield* error("capacity", "parameters-bytes");
209
+ if (record.configuration.expiresAtMillis !== null && record.configuration.expiresAtMillis - record.createdAtMillis > limits.maxLifetimeMillis) return yield* error("capacity", "lifetime");
210
+ if ((yield* count(sql`SELECT COUNT(*) AS count FROM effect_agent_subscriptions WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}`, "count registrations")) >= limits.maxRegistrations) return yield* error("capacity", "registrations");
211
+ if ((yield* count(sql`SELECT COUNT(*) AS count FROM effect_agent_subscriptions WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND owner_id=${record.key.ownerId}`, "count owner registrations")) >= limits.maxRegistrationsPerOwner) return yield* error("capacity", "owner-registrations");
212
+ const assigned = {
213
+ ...record,
214
+ ordinal: yield* nextSequence()
215
+ };
216
+ const json = yield* encode(SubscriptionRecord, assigned, "encode registration");
217
+ yield* failpoint.hit("subscription:register:before");
218
+ yield* query(sql`
219
+ INSERT INTO effect_agent_subscriptions (tenant_id, source_address, owner_id, subscription_id, ordinal,
220
+ source_name, source_version, matching_key, state, expires_at_millis, recovery_at_millis, recovery_present, record_json)
221
+ VALUES (${partition.tenantId}, ${partition.address}, ${assigned.key.ownerId}, ${assigned.key.subscriptionId}, ${assigned.ordinal},
222
+ ${assigned.configuration.source.name}, ${assigned.configuration.source.version}, ${assigned.configuration.matchingKey}, ${assigned.state},
223
+ ${assigned.configuration.expiresAtMillis}, ${assigned.recovery?.nextAttemptAtMillis ?? null}, ${assigned.recovery === null ? 0 : 1}, ${json})
224
+ `, "insert registration");
225
+ return {
226
+ value: assigned,
227
+ changed: true
228
+ };
229
+ }));
230
+ if (result.changed) yield* failpoint.hit("subscription:register:after");
231
+ return result.value;
232
+ });
233
+ const get = Effect.fn("SqlSubscriptionStore.get")(function* (input) {
234
+ return yield* readRegistration(yield* requireKey(input, "get-key"), "get subscription");
235
+ });
236
+ const list = Effect.fn("SqlSubscriptionStore.list")(function* (ownerId, after, limit) {
237
+ const rows = yield* query(sql`
238
+ SELECT owner_id, subscription_id, ordinal FROM effect_agent_subscriptions WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
239
+ AND owner_id=${ownerId} AND ordinal>${after} ORDER BY ordinal LIMIT ${limit}
240
+ `, "list subscriptions");
241
+ const decoded = yield* decodeRows(Schema.Struct({
242
+ owner_id: Schema.String,
243
+ subscription_id: Schema.String,
244
+ ordinal: Schema.Natural
245
+ }), rows, "list subscriptions");
246
+ return yield* Effect.forEach(decoded, Effect.fn("SqlSubscriptionStore.listRecord")(function* (row) {
247
+ const record = yield* readRegistration({
248
+ partition,
249
+ ownerId: row.owner_id,
250
+ subscriptionId: row.subscription_id
251
+ }, "list subscription");
252
+ if (record === null || record.ordinal !== row.ordinal) return yield* corrupt("list subscription projection");
253
+ return record;
254
+ }));
255
+ });
256
+ const change = Effect.fn("SubscriptionStore.change")(function* (input, expectedRevision, inputChange) {
257
+ const key = yield* requireKey(input, "change-key");
258
+ const change = yield* validate(SubscriptionChange, inputChange, "change");
259
+ yield* validate(Schema.Int.check(Schema.isGreaterThan(0)), expectedRevision, "revision");
260
+ const updated = yield* transactions.run(Effect.gen(function* () {
261
+ const existing = yield* readRegistration(key, "change-registration");
262
+ if (existing === null) return yield* error("not-found", "subscription");
263
+ yield* failpoint.hit("subscription:change:before");
264
+ const updated = {
265
+ ...yield* Effect.fromResult(applySubscriptionChange(existing, expectedRevision, change)),
266
+ ordinal: yield* nextSequence()
267
+ };
268
+ yield* writeRegistration(updated);
269
+ return updated;
270
+ }));
271
+ yield* failpoint.hit("subscription:change:after");
272
+ return updated;
273
+ });
274
+ const cancel = Effect.fn("SqlSubscriptionStore.cancel")(function* (input, expectedRevision) {
275
+ const key = yield* requireKey(input, "cancel-key");
276
+ const result = yield* transactions.run(Effect.gen(function* () {
277
+ const current = yield* readRegistration(key, "cancel subscription");
278
+ if (current === null) return yield* error("not-found", "subscription");
279
+ if (expectedRevision !== void 0 && expectedRevision !== current.configurationRevision && !(current.state === "cancelled" && expectedRevision + 1 === current.configurationRevision)) return yield* SubscriptionError.make({
280
+ reason: "conflict",
281
+ code: "configuration-revision",
282
+ currentRevision: current.configurationRevision,
283
+ currentState: current.state
284
+ });
285
+ if (current.state === "cancelled") return {
286
+ value: current,
287
+ changed: false
288
+ };
289
+ const updated = {
290
+ ...current,
291
+ configurationRevision: current.configurationRevision + 1,
292
+ state: "cancelled",
293
+ recovery: null
294
+ };
295
+ yield* failpoint.hit("subscription:cancel:before");
296
+ yield* writeRegistration(updated);
297
+ return {
298
+ value: updated,
299
+ changed: true
300
+ };
301
+ }));
302
+ if (result.changed) yield* failpoint.hit("subscription:cancel:after");
303
+ return result.value;
304
+ });
305
+ const accept = Effect.fn("SqlSubscriptionStore.accept")(function* (input, inputLimits) {
306
+ const event = yield* validate(AcceptedEvent, input, "accept-event");
307
+ const limits = yield* validate(SubscriptionLimits, inputLimits, "accept-limits");
308
+ yield* requirePartition(event.partition, "accept-partition");
309
+ const result = yield* transactions.run(Effect.gen(function* () {
310
+ const existing = yield* readEvent(event.eventId, "accept event");
311
+ if (existing !== null) {
312
+ if (!sameAcceptedEventIdentity(existing, event)) return yield* error("conflict", "event-identity");
313
+ return {
314
+ value: existing,
315
+ changed: false
316
+ };
317
+ }
318
+ yield* Effect.fromResult(validateEventRetention(event, limits, yield* Clock.currentTimeMillis));
319
+ const retainedPolicies = yield* query(sql`SELECT replay_horizon_millis FROM effect_agent_event_retention WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}`, "retained horizon");
320
+ if (retainedPolicies.length > 0 && retainedPolicies[0]?.replay_horizon_millis !== limits.retention?.replayHorizonMillis) return yield* error("conflict", "retention-horizon");
321
+ if (limits.retention !== void 0) {
322
+ yield* query(sql`INSERT INTO effect_agent_event_retention (tenant_id,source_address,replay_horizon_millis,next_maintenance_at_millis)
323
+ VALUES (${partition.tenantId},${partition.address},${limits.retention.replayHorizonMillis},${event.acceptedAtMillis}) ON CONFLICT DO NOTHING`, "retain event horizon");
324
+ if ((yield* query(sql`SELECT replay_horizon_millis FROM effect_agent_event_retention WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}`, "retained event horizon"))[0]?.replay_horizon_millis !== limits.retention.replayHorizonMillis) return yield* error("conflict", "retention-horizon");
325
+ }
326
+ if (bytes(event.payload) > limits.maxPayloadBytes) return yield* error("capacity", "payload-bytes");
327
+ if ((yield* count(sql`SELECT COUNT(*) AS count FROM effect_agent_subscription_events WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND tombstone=0`, "count events")) >= limits.maxEvents) return yield* error("capacity", "events");
328
+ const accepted = {
329
+ ...event,
330
+ cutoff: yield* nextSequence(),
331
+ cursor: 0,
332
+ routingComplete: false,
333
+ routingFailure: null
334
+ };
335
+ const json = yield* encode(AcceptedEvent, accepted, "encode accepted event");
336
+ yield* failpoint.hit("subscription:accept:before");
337
+ yield* query(sql`
338
+ INSERT INTO effect_agent_subscription_events (tenant_id, source_address, event_id, source_name, source_version,
339
+ matching_key, payload_digest, cutoff, cursor, routing_complete, next_attempt_at_millis, record_json)
340
+ VALUES (${partition.tenantId}, ${partition.address}, ${accepted.eventId}, ${accepted.source.name}, ${accepted.source.version},
341
+ ${accepted.matchingKey}, ${accepted.payloadDigest}, ${accepted.cutoff}, ${accepted.cursor}, 0, ${accepted.nextAttemptAtMillis}, ${json})
342
+ `, "insert event");
343
+ return {
344
+ value: accepted,
345
+ changed: true
346
+ };
347
+ }));
348
+ if (result.changed) yield* failpoint.hit("subscription:accept:after");
349
+ return result.value;
350
+ });
351
+ const event = Effect.fn("SqlSubscriptionStore.event")((eventId) => readEvent(eventId, "get event"));
352
+ const pendingEvents = Effect.fn("SqlSubscriptionStore.pendingEvents")(function* (nowMillis, after, limit) {
353
+ const rows = yield* query(sql`
354
+ SELECT event_id FROM effect_agent_subscription_events WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
355
+ AND routing_complete=0 AND next_attempt_at_millis<=${nowMillis} AND event_id>${after} ORDER BY event_id LIMIT ${limit}
356
+ `, "pending events");
357
+ return yield* decodeRows(Schema.Struct({ event_id: Schema.String }), rows, "pending event keys").pipe(Effect.map((items) => items.map((item) => item.event_id)));
358
+ });
359
+ const candidates = Effect.fn("SqlSubscriptionStore.candidates")(function* (input, limit) {
360
+ const supplied = yield* validate(AcceptedEvent, input, "candidates-event");
361
+ yield* requirePartition(supplied.partition, "candidates-partition");
362
+ const stored = yield* readEvent(supplied.eventId, "candidates event");
363
+ if (stored === null) return yield* error("not-found", "event");
364
+ if (!sameAcceptedEventIdentity(stored, supplied)) return yield* error("conflict", "event");
365
+ const rows = yield* query(sql`
366
+ SELECT owner_id, subscription_id, ordinal FROM effect_agent_subscriptions WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
367
+ AND source_name=${stored.source.name} AND source_version=${stored.source.version} AND matching_key=${stored.matchingKey}
368
+ AND ordinal>${stored.cursor} AND ordinal<=${stored.cutoff} ORDER BY ordinal LIMIT ${limit}
369
+ `, "subscription candidates");
370
+ const decoded = yield* decodeRows(Schema.Struct({
371
+ owner_id: Schema.String,
372
+ subscription_id: Schema.String,
373
+ ordinal: Schema.Natural
374
+ }), rows, "subscription candidates");
375
+ return yield* Effect.forEach(decoded, Effect.fn("SqlSubscriptionStore.candidateRecord")(function* (row) {
376
+ const record = yield* readRegistration({
377
+ partition,
378
+ ownerId: row.owner_id,
379
+ subscriptionId: row.subscription_id
380
+ }, "subscription candidate");
381
+ if (record === null || record.ordinal !== row.ordinal) return yield* corrupt("subscription candidate projection");
382
+ return record;
383
+ }));
384
+ });
385
+ const insertDelivery = Effect.fn("SqlSubscriptionStore.insertDelivery")(function* (delivery) {
386
+ const json = yield* encode(SubscriptionDelivery, delivery, "encode selected delivery");
387
+ yield* query(sql`
388
+ INSERT INTO effect_agent_subscription_deliveries (tenant_id, source_address, owner_id, subscription_id, event_id,
389
+ delivery_key, state, next_attempt_at_millis, record_json)
390
+ VALUES (${partition.tenantId}, ${partition.address}, ${delivery.key.subscription.ownerId}, ${delivery.key.subscription.subscriptionId},
391
+ ${delivery.key.eventId}, ${subscriptionDeliveryKeyString(delivery.key)}, ${delivery.state}, ${delivery.retry.nextAttemptAtMillis}, ${json})
392
+ `, "insert delivery");
393
+ });
394
+ const select = Effect.fn("SqlSubscriptionStore.select")(function* (inputEvent, inputDeliveries, cursor, complete, nowMillis, inputLimits) {
395
+ const supplied = yield* validate(AcceptedEvent, inputEvent, "select-event");
396
+ const deliveries = yield* validate(Schema.Array(SubscriptionDelivery), inputDeliveries, "select-deliveries");
397
+ const limits = yield* validate(SubscriptionLimits, inputLimits, "select-limits");
398
+ yield* requirePartition(supplied.partition, "select-partition");
399
+ for (const candidate of deliveries) yield* requirePartition(candidate.key.subscription.partition, "select-delivery-partition");
400
+ if (yield* transactions.run(Effect.gen(function* () {
401
+ const accepted = yield* readEvent(supplied.eventId, "select event");
402
+ if (accepted === null) return yield* error("not-found", "event");
403
+ if (!sameAcceptedEventIdentity(accepted, supplied) || accepted.cursor !== supplied.cursor) return yield* error("conflict", "event-cursor");
404
+ if (accepted.routingComplete) return false;
405
+ if (!Number.isSafeInteger(cursor) || cursor < accepted.cursor || cursor > accepted.cutoff) return yield* error("validation", "cursor");
406
+ yield* failpoint.hit("subscription:select:before");
407
+ const effectiveNowMillis = Math.max(nowMillis, yield* Clock.currentTimeMillis);
408
+ const additions = [];
409
+ for (const delivery of deliveries) {
410
+ const record = yield* readRegistration(delivery.key.subscription, "select registration");
411
+ if (record === null) return yield* error("not-found", "subscription");
412
+ if (!subscriptionDeliveryCanSelect(delivery, record, accepted) || delivery.key.eventId !== accepted.eventId || delivery.source.name !== accepted.source.name || delivery.source.version !== accepted.source.version || record.ordinal <= accepted.cursor || record.ordinal > cursor) return yield* error("conflict", "selection");
413
+ const existing = yield* readDelivery(delivery.key, "select existing delivery");
414
+ if (existing !== null) {
415
+ if (!sameDeliveryIdentity(existing, delivery)) return yield* error("conflict", "delivery-identity");
416
+ continue;
417
+ }
418
+ if (!subscriptionCanSelect(record, accepted, effectiveNowMillis, false)) continue;
419
+ additions.push({
420
+ delivery,
421
+ record
422
+ });
423
+ }
424
+ if ((yield* count(sql`SELECT COUNT(*) AS count FROM effect_agent_subscription_deliveries WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}`, "count deliveries")) + additions.length > limits.maxDeliveries) return yield* error("capacity", "deliveries");
425
+ for (const ownerId of new Set(additions.map(({ record }) => record.key.ownerId))) if ((yield* count(sql`SELECT COUNT(*) AS count FROM effect_agent_subscription_deliveries WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND owner_id=${ownerId}`, "count owner deliveries")) + additions.filter(({ record }) => record.key.ownerId === ownerId).length > limits.maxDeliveriesPerOwner) return yield* error("capacity", "owner-deliveries");
426
+ for (const addition of additions) {
427
+ yield* insertDelivery(addition.delivery);
428
+ if (addition.record.configuration.mode === "once") yield* writeRegistration({
429
+ ...addition.record,
430
+ state: "consumed",
431
+ recovery: null
432
+ });
433
+ }
434
+ yield* writeEvent({
435
+ ...accepted,
436
+ cursor,
437
+ routingComplete: complete,
438
+ routingFailure: null
439
+ });
440
+ return true;
441
+ }))) yield* failpoint.hit("subscription:select:after");
442
+ });
443
+ const catchUp = Effect.fn("SqlSubscriptionStore.catchUp")(function* (inputEvent, inputDelivery, nowMillis, inputLimits) {
444
+ const supplied = yield* validate(AcceptedEvent, inputEvent, "catch-up-event");
445
+ const delivery = yield* validate(SubscriptionDelivery, inputDelivery, "catch-up-delivery");
446
+ const limits = yield* validate(SubscriptionLimits, inputLimits, "catch-up-limits");
447
+ yield* requirePartition(supplied.partition, "catch-up-partition");
448
+ yield* requirePartition(delivery.key.subscription.partition, "catch-up-delivery-partition");
449
+ if (yield* transactions.run(Effect.gen(function* () {
450
+ const accepted = yield* readEvent(supplied.eventId, "catch-up event");
451
+ const record = yield* readRegistration(delivery.key.subscription, "catch-up subscription");
452
+ if (accepted === null || record === null) return yield* error("not-found", accepted === null ? "event" : "subscription");
453
+ if (!sameAcceptedEventIdentity(accepted, supplied) || !subscriptionDeliveryCanSelect(delivery, record, accepted) || delivery.key.eventId !== accepted.eventId || delivery.source.name !== accepted.source.name || delivery.source.version !== accepted.source.version || record.configuration.mode !== "once") return yield* error("conflict", "catch-up-identity");
454
+ const existing = yield* readDelivery(delivery.key, "catch-up existing delivery");
455
+ if (existing !== null) {
456
+ if (!sameDeliveryIdentity(existing, delivery)) return yield* error("conflict", "delivery-identity");
457
+ return false;
458
+ }
459
+ yield* failpoint.hit("subscription:catch-up:before");
460
+ const effectiveNowMillis = Math.max(nowMillis, yield* Clock.currentTimeMillis);
461
+ if (!subscriptionCanSelect(record, accepted, effectiveNowMillis, true)) return yield* error("conflict", "catch-up-eligibility");
462
+ if ((yield* count(sql`SELECT COUNT(*) AS count FROM effect_agent_subscription_deliveries WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}`, "count deliveries")) >= limits.maxDeliveries) return yield* error("capacity", "deliveries");
463
+ if ((yield* count(sql`SELECT COUNT(*) AS count FROM effect_agent_subscription_deliveries WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND owner_id=${record.key.ownerId}`, "count owner deliveries")) >= limits.maxDeliveriesPerOwner) return yield* error("capacity", "owner-deliveries");
464
+ yield* insertDelivery(delivery);
465
+ yield* writeRegistration({
466
+ ...record,
467
+ state: "consumed",
468
+ recovery: null
469
+ });
470
+ return true;
471
+ }))) yield* failpoint.hit("subscription:catch-up:after");
472
+ });
473
+ const deferEvent = Effect.fn("SqlSubscriptionStore.deferEvent")(function* (eventId, nextAttemptAtMillis, code) {
474
+ const routingFailure = code === void 0 ? "routing-failed" : yield* validate(SubscriptionName, code, "routing-failure");
475
+ yield* transactions.run(Effect.gen(function* () {
476
+ const accepted = yield* readEvent(eventId, "defer event");
477
+ if (accepted === null) return yield* error("not-found", "event");
478
+ yield* failpoint.hit("subscription:defer-event:before");
479
+ yield* writeEvent({
480
+ ...accepted,
481
+ nextAttemptAtMillis,
482
+ routingFailure
483
+ });
484
+ }));
485
+ yield* failpoint.hit("subscription:defer-event:after");
486
+ });
487
+ const delivery = Effect.fn("SqlSubscriptionStore.delivery")(function* (input) {
488
+ const key = yield* validate(SubscriptionDeliveryKey, input, "delivery-key");
489
+ yield* requirePartition(key.subscription.partition, "delivery-partition");
490
+ return yield* readDelivery(key, "get delivery");
491
+ });
492
+ const pendingDeliveries = Effect.fn("SqlSubscriptionStore.pendingDeliveries")(function* (nowMillis, after, limit) {
493
+ const rows = yield* query(sql`
494
+ SELECT owner_id, subscription_id, event_id FROM effect_agent_subscription_deliveries
495
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND CASE WHEN json_valid(record_json) THEN
496
+ ((state NOT IN ('delivered','refused') AND COALESCE(json_extract(record_json, '$.retry.parked'), 0)=0) OR (state='delivered' AND json_extract(record_json, '$.observeSettlement')=1))
497
+ ELSE state<>'refused' END
498
+ AND next_attempt_at_millis<=${nowMillis} AND delivery_key>${after} ORDER BY delivery_key LIMIT ${limit}
499
+ `, "pending deliveries");
500
+ const rowSchema = Schema.Struct({
501
+ owner_id: Schema.String,
502
+ subscription_id: Schema.String,
503
+ event_id: Schema.String
504
+ });
505
+ return yield* decodeRows(rowSchema, rows, "pending delivery keys").pipe(Effect.map((items) => items.map((item) => ({
506
+ subscription: {
507
+ partition,
508
+ ownerId: item.owner_id,
509
+ subscriptionId: item.subscription_id
510
+ },
511
+ eventId: item.event_id
512
+ }))));
513
+ });
514
+ const listDeliveries = Effect.fn("SqlSubscriptionStore.listDeliveries")(function* (input, after, limit) {
515
+ const key = yield* requireKey(input, "list-deliveries-key");
516
+ const rows = yield* query(sql`
517
+ SELECT record_json FROM effect_agent_subscription_deliveries WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
518
+ AND owner_id=${key.ownerId} AND subscription_id=${key.subscriptionId} AND delivery_key>${after} ORDER BY delivery_key LIMIT ${limit}
519
+ `, "list deliveries");
520
+ const decoded = yield* decodeRows(JsonRow, rows, "list deliveries");
521
+ return yield* Effect.forEach(decoded, (row) => decode(SubscriptionDelivery, row.record_json, "list delivery"));
522
+ });
523
+ const changeDelivery = Effect.fn("SqlSubscriptionStore.changeDelivery")(function* (inputKey, inputDeliveryId, inputChange) {
524
+ const key = yield* validate(SubscriptionDeliveryKey, inputKey, "change-delivery-key");
525
+ const deliveryId = yield* validate(Digest, inputDeliveryId, "change-delivery-id");
526
+ const change = yield* validate(DeliveryChange, inputChange, "change-delivery-change");
527
+ yield* requirePartition(key.subscription.partition, "change-delivery-partition");
528
+ const result = yield* transactions.run(Effect.gen(function* () {
529
+ const existing = yield* readDelivery(key, "change delivery");
530
+ const record = yield* readRegistration(key.subscription, "change delivery subscription");
531
+ if (existing === null || record === null) return yield* error("not-found", existing === null ? "delivery" : "subscription");
532
+ yield* failpoint.hit(`subscription:delivery-${change._tag.toLowerCase()}:before`);
533
+ const effectiveChange = change._tag === "Prepare" ? {
534
+ ...change,
535
+ nowMillis: Math.max(change.nowMillis, yield* Clock.currentTimeMillis)
536
+ } : change;
537
+ const transition = applySubscriptionDeliveryChange(existing, record, deliveryId, effectiveChange);
538
+ if (Result.isFailure(transition)) return yield* transition.failure;
539
+ if (transition.success === existing) return {
540
+ value: existing,
541
+ changed: false
542
+ };
543
+ yield* writeDelivery(transition.success);
544
+ return {
545
+ value: transition.success,
546
+ changed: true
547
+ };
548
+ }));
549
+ if (result.changed) yield* failpoint.hit(`subscription:delivery-${change._tag.toLowerCase()}:after`);
550
+ return result.value;
551
+ });
552
+ const recovering = Effect.fn("SqlSubscriptionStore.recovering")(function* (nowMillis, after, limit) {
553
+ const rows = yield* query(sql`
554
+ SELECT owner_id, subscription_id, ordinal FROM effect_agent_subscriptions
555
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND state='active'
556
+ AND recovery_at_millis IS NOT NULL AND recovery_at_millis<=${nowMillis} AND ordinal>${after}
557
+ ORDER BY ordinal LIMIT ${limit}
558
+ `, "recovering subscriptions");
559
+ const rowSchema = Schema.Struct({
560
+ owner_id: Schema.String,
561
+ subscription_id: Schema.String,
562
+ ordinal: Schema.Natural
563
+ });
564
+ return yield* decodeRows(rowSchema, rows, "recovering subscription keys").pipe(Effect.map((items) => items.map((item) => ({
565
+ key: {
566
+ partition,
567
+ ownerId: item.owner_id,
568
+ subscriptionId: item.subscription_id
569
+ },
570
+ ordinal: item.ordinal
571
+ }))));
572
+ });
573
+ const deferRecovery = Effect.fn("SqlSubscriptionStore.deferRecovery")(function* (input, expectedRevision, recovery) {
574
+ const key = yield* requireKey(input, "defer-recovery-key");
575
+ yield* transactions.run(Effect.gen(function* () {
576
+ const record = yield* readRegistration(key, "defer recovery");
577
+ if (record === null) return yield* error("not-found", "subscription");
578
+ if (record.configurationRevision !== expectedRevision) return;
579
+ yield* failpoint.hit("subscription:defer-recovery:before");
580
+ yield* writeRegistration({
581
+ ...record,
582
+ recovery: record.state === "active" || record.state === "paused" ? recovery : null
583
+ });
584
+ }));
585
+ yield* failpoint.hit("subscription:defer-recovery:after");
586
+ });
587
+ const readScanCursors = Effect.gen(function* () {
588
+ const rows = yield* query(sql`
589
+ SELECT event_scan_cursor, delivery_scan_cursor, recovery_scan_cursor
590
+ FROM effect_agent_subscription_sequences
591
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
592
+ `, "read subscription scan cursors");
593
+ const decoded = yield* decodeRows(ScanRow, rows, "read subscription scan cursors");
594
+ if (decoded.length !== 1) return yield* corrupt("subscription scan cursors");
595
+ return {
596
+ events: decoded[0].event_scan_cursor,
597
+ deliveries: decoded[0].delivery_scan_cursor,
598
+ recovery: decoded[0].recovery_scan_cursor
599
+ };
600
+ });
601
+ const advanceScanCursors = Effect.fn("SqlSubscriptionStore.advanceScanCursors")(function* (input) {
602
+ const cursors = yield* validate(SubscriptionScanCursors, input, "scan-cursors");
603
+ yield* transactions.run(Effect.gen(function* () {
604
+ yield* failpoint.hit("subscription:advance-scan-cursors:before");
605
+ yield* query(sql`
606
+ UPDATE effect_agent_subscription_sequences
607
+ SET event_scan_cursor=${cursors.events}, delivery_scan_cursor=${cursors.deliveries}, recovery_scan_cursor=${cursors.recovery}
608
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
609
+ `, "advance subscription scan cursors");
610
+ }));
611
+ yield* failpoint.hit("subscription:advance-scan-cursors:after");
612
+ });
613
+ const indexedDeadline = query(sql`
614
+ SELECT MIN(deadline) AS deadline FROM (
615
+ SELECT next_attempt_at_millis AS deadline FROM effect_agent_subscription_events
616
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND routing_complete=0
617
+ UNION ALL SELECT next_attempt_at_millis FROM effect_agent_subscription_deliveries
618
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND CASE WHEN json_valid(record_json) THEN
619
+ ((state NOT IN ('delivered','refused') AND COALESCE(json_extract(record_json, '$.retry.parked'), 0)=0) OR (state='delivered' AND json_extract(record_json, '$.observeSettlement')=1))
620
+ ELSE state<>'refused' END
621
+ UNION ALL SELECT next_maintenance_at_millis FROM effect_agent_event_retention
622
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}
623
+ UNION ALL SELECT recovery_at_millis FROM effect_agent_subscriptions
624
+ WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND state='active' AND recovery_at_millis IS NOT NULL
625
+ )
626
+ `, "next subscription deadline").pipe(Effect.flatMap((rows) => decodeRows(Schema.Struct({ deadline: Schema.NullOr(Schema.Number) }), rows, "next subscription deadline")), Effect.flatMap((rows) => rows.length === 1 ? Effect.succeed(rows[0].deadline) : Effect.fail(corrupt("next subscription deadline"))));
627
+ const nextDeadline = Effect.gen(function* () {
628
+ const cursors = yield* readScanCursors;
629
+ if (cursors.events !== "" || cursors.deliveries !== "" || cursors.recovery !== 0) return 0;
630
+ return yield* indexedDeadline;
631
+ });
632
+ const compact = Effect.fn("SqlSubscriptionStore.compact")(function* (nowMillis, inputPolicy, requestedLimit) {
633
+ nowMillis = Math.min(nowMillis, yield* Clock.currentTimeMillis);
634
+ const policy = yield* validate(SubscriptionRetentionPolicy, inputPolicy, "retention-policy");
635
+ const limit = yield* validate(Schema.Int.check(Schema.isBetween({
636
+ minimum: 1,
637
+ maximum: 100
638
+ })), requestedLimit, "maintenance-limit");
639
+ const removed = yield* transactions.run(Effect.gen(function* () {
640
+ yield* failpoint.hit("subscription:compact:before");
641
+ yield* query(sql`INSERT INTO effect_agent_event_retention (tenant_id, source_address, replay_horizon_millis) VALUES (${partition.tenantId}, ${partition.address}, ${policy.replayHorizonMillis}) ON CONFLICT DO NOTHING`, "initialize maintenance");
642
+ const progress = yield* query(sql`SELECT replay_horizon_millis, tombstone_count, event_cursor, delivery_cursor FROM effect_agent_event_retention WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}`, "maintenance progress").pipe(Effect.flatMap((rows) => decodeRows(Schema.Struct({
643
+ replay_horizon_millis: Schema.Number,
644
+ tombstone_count: Schema.Natural,
645
+ event_cursor: Schema.String,
646
+ delivery_cursor: Schema.String
647
+ }), rows, "maintenance progress")));
648
+ const cursor = progress[0];
649
+ if (progress.length !== 1 || cursor === void 0) return yield* corrupt("maintenance progress");
650
+ if (cursor.replay_horizon_millis !== policy.replayHorizonMillis) return yield* error("conflict", "retention-horizon");
651
+ const deliveryRows = yield* query(sql`SELECT delivery_key, record_json FROM effect_agent_subscription_deliveries WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND delivery_key>${cursor.delivery_cursor} ORDER BY delivery_key LIMIT ${limit}`, "maintenance deliveries").pipe(Effect.flatMap((rows) => decodeRows(Schema.Struct({
652
+ delivery_key: Schema.String,
653
+ record_json: Schema.String
654
+ }), rows, "maintenance deliveries")));
655
+ const eventRows = yield* query(sql`SELECT event_id, record_json FROM effect_agent_subscription_events WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND event_id>${cursor.event_cursor} ORDER BY event_id LIMIT ${limit}`, "maintenance events").pipe(Effect.flatMap((rows) => decodeRows(Schema.Struct({
656
+ event_id: Schema.String,
657
+ record_json: Schema.String
658
+ }), rows, "maintenance events")));
659
+ const protectedByRecovery = (event) => query(sql`SELECT 1 FROM effect_agent_subscriptions WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND source_name=${event.source.name} AND source_version=${event.source.version} AND matching_key=${event.matchingKey} AND recovery_present=1 LIMIT 1`, "maintenance recovery reference").pipe(Effect.map((rows) => rows.length > 0));
660
+ const cutoff = nowMillis - policy.completedRetentionMillis;
661
+ for (const row of deliveryRows) {
662
+ const decoded = yield* decode(SubscriptionDelivery, row.record_json, "maintenance delivery").pipe(Effect.result);
663
+ if (Result.isFailure(decoded)) {
664
+ yield* Effect.logWarning("Subscription retention preserved corrupt delivery");
665
+ continue;
666
+ }
667
+ const delivery = decoded.success;
668
+ if (subscriptionDeliveryKeyString(delivery.key) !== row.delivery_key || !sameSourcePartition(delivery.key.subscription.partition, partition)) {
669
+ yield* Effect.logWarning("Subscription retention preserved mismatched delivery identity");
670
+ continue;
671
+ }
672
+ if (delivery.state !== "refused" && (delivery.state !== "delivered" || delivery.settledAtMillis === void 0)) continue;
673
+ if ((delivery.settledAtMillis ?? delivery.completedAtMillis ?? delivery.selectedAtMillis) > cutoff) continue;
674
+ const accepted = yield* readEvent(delivery.key.eventId, "maintenance delivery event").pipe(Effect.result);
675
+ if (Result.isFailure(accepted)) {
676
+ if (accepted.failure.reason !== "corrupt") return yield* accepted.failure;
677
+ yield* Effect.logWarning("Subscription retention preserved corrupt event");
678
+ continue;
679
+ }
680
+ const event = accepted.success;
681
+ if (event === null || !event.routingComplete || event.occurredAtMillis === void 0 || event.acceptedAtMillis > cutoff || (yield* protectedByRecovery(event))) continue;
682
+ yield* query(sql`DELETE FROM effect_agent_subscription_deliveries WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND delivery_key=${row.delivery_key}`, "reclaim delivery");
683
+ }
684
+ let removed = 0;
685
+ let tombstones = cursor.tombstone_count;
686
+ for (const row of eventRows) {
687
+ const decoded = yield* decode(AcceptedEvent, row.record_json, "maintenance event").pipe(Effect.result);
688
+ if (Result.isFailure(decoded)) {
689
+ yield* Effect.logWarning("Subscription retention preserved corrupt event");
690
+ continue;
691
+ }
692
+ const event = decoded.success;
693
+ if (event.eventId !== row.event_id || !sameSourcePartition(event.partition, partition)) {
694
+ yield* Effect.logWarning("Subscription retention preserved mismatched event identity");
695
+ continue;
696
+ }
697
+ if (!event.routingComplete || event.occurredAtMillis === void 0 || event.acceptedAtMillis > cutoff) continue;
698
+ const expired = event.occurredAtMillis <= nowMillis - policy.replayHorizonMillis;
699
+ if (event.tombstone === true && !expired) continue;
700
+ if ((yield* query(sql`SELECT 1 FROM effect_agent_subscription_deliveries WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND event_id=${event.eventId} LIMIT 1`, "maintenance delivery reference")).length > 0 || (yield* protectedByRecovery(event))) continue;
701
+ if (expired) {
702
+ yield* query(sql`DELETE FROM effect_agent_subscription_events WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} AND event_id=${event.eventId}`, "expire event identity");
703
+ if (event.tombstone === true) tombstones--;
704
+ } else {
705
+ if (tombstones >= policy.maxTombstones) continue;
706
+ yield* writeEvent({
707
+ ...event,
708
+ payload: null,
709
+ tombstone: true
710
+ });
711
+ tombstones++;
712
+ }
713
+ removed++;
714
+ }
715
+ const remaining = (yield* query(sql`SELECT 1 FROM effect_agent_subscription_events WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address} LIMIT 1`, "remaining maintenance")).length > 0;
716
+ yield* query(sql`UPDATE effect_agent_event_retention SET tombstone_count=${tombstones}, event_cursor=${eventRows.length < limit ? "" : eventRows.at(-1)?.event_id ?? ""}, delivery_cursor=${deliveryRows.length < limit ? "" : deliveryRows.at(-1)?.delivery_key ?? ""}, next_maintenance_at_millis=${remaining ? nowMillis + 6e4 : null} WHERE tenant_id=${partition.tenantId} AND source_address=${partition.address}`, "advance maintenance");
717
+ return removed;
718
+ }));
719
+ yield* failpoint.hit("subscription:compact:after");
720
+ return removed;
721
+ });
722
+ return SubscriptionStore.of({
723
+ partition,
724
+ compact,
725
+ register,
726
+ get,
727
+ list,
728
+ cancel,
729
+ change,
730
+ accept,
731
+ event,
732
+ pendingEvents,
733
+ candidates,
734
+ select,
735
+ catchUp,
736
+ deferEvent,
737
+ delivery,
738
+ pendingDeliveries,
739
+ listDeliveries,
740
+ changeDelivery,
741
+ recovering,
742
+ deferRecovery,
743
+ readScanCursors,
744
+ advanceScanCursors,
745
+ nextDeadline
746
+ });
747
+ });
748
+ //#endregion
749
+ export { SqlSubscriptionTransaction, makeSqlSubscriptionStore };
750
+
751
+ //# sourceMappingURL=SqlSubscriptionStore.mjs.map