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,224 @@
1
+ import { Context, Effect, Schema } from "effect";
2
+ import { Tool, type LanguageModel } from "effect/unstable/ai";
3
+
4
+ import type { AnyDefinition } from "../../core/Agent.ts";
5
+ import { ModelProtocolError } from "../../core/AgentError.ts";
6
+ import { utf8ByteLength } from "../../core/internal/utf8.ts";
7
+ import {
8
+ getToolExecutionKind,
9
+ isSubagentToolAllowed,
10
+ type SubagentGrant,
11
+ } from "../../core/SubagentContract.ts";
12
+ import {
13
+ AdditionalToolCatalog,
14
+ IncludesCatalogDocumentation,
15
+ DiscoveryTool,
16
+ Limits,
17
+ PinnedTool,
18
+ Selection,
19
+ Snapshot,
20
+ ToolNames,
21
+ ToolNamespace,
22
+ } from "../../core/ToolExposure.ts";
23
+ import { ContextRolloverTool } from "../ContextWindow.ts";
24
+ import { getToolExecutionClass } from "../DurableStep.ts";
25
+ import { RunToolVisibility, type CatalogEntry, type VisibilityRequest } from "../ToolExposure.ts";
26
+
27
+ const invalid = (message: string) => ModelProtocolError.make({ message });
28
+
29
+ export const decodeSelection = (value: unknown) =>
30
+ Schema.decodeUnknownEffect(Selection)(value).pipe(
31
+ Effect.mapError(() => invalid("Invalid Tool exposure selection")),
32
+ );
33
+
34
+ export const decodeSnapshot = (value: unknown) =>
35
+ Schema.decodeUnknownEffect(Snapshot)(value).pipe(
36
+ Effect.mapError(() => invalid("Invalid recorded Tool exposure snapshot")),
37
+ Effect.map((snapshot) =>
38
+ Object.freeze(
39
+ Snapshot.make({
40
+ exposedToolNames: Object.freeze([...snapshot.exposedToolNames]),
41
+ ...(snapshot.selection === undefined
42
+ ? {}
43
+ : {
44
+ selection: Object.freeze(
45
+ Selection.make({ toolNames: Object.freeze([...snapshot.selection.toolNames]) }),
46
+ ),
47
+ }),
48
+ }),
49
+ ),
50
+ ),
51
+ );
52
+
53
+ export const eligibleCatalog = Effect.fn("ToolExposure.eligibleCatalog")(function* (
54
+ definition: AnyDefinition,
55
+ request: Omit<VisibilityRequest, "toolNames">,
56
+ grant: SubagentGrant | undefined,
57
+ depth: number,
58
+ ) {
59
+ const visibility = yield* RunToolVisibility;
60
+ const entries: Array<CatalogEntry> = [];
61
+
62
+ for (const tool of Object.values(definition.toolkit.tools)) {
63
+ if (
64
+ Context.get(tool.annotations, DiscoveryTool) &&
65
+ (getToolExecutionKind(tool.annotations) !== "ordinary" ||
66
+ getToolExecutionClass(tool) !== "readonly")
67
+ )
68
+ return yield* invalid("Discovery requires ordinary readonly Tools");
69
+ const namespace = Context.get(tool.annotations, ToolNamespace);
70
+
71
+ entries.push({
72
+ kind: "native",
73
+ tool,
74
+ nativeToolName: tool.name,
75
+ ...(namespace === undefined ? {} : { namespace }),
76
+ });
77
+ for (const extra of Context.get(tool.annotations, AdditionalToolCatalog)) {
78
+ entries.push({ kind: "code-mode", ...extra, nativeToolName: tool.name });
79
+ }
80
+ }
81
+ const names = [...new Set(entries.map((entry) => entry.tool.name))];
82
+
83
+ const visible =
84
+ visibility === undefined ? names : yield* visibility.visible({ ...request, toolNames: names });
85
+
86
+ const checked =
87
+ visibility === undefined
88
+ ? visible
89
+ : yield* Schema.decodeEffect(ToolNames)(visible).pipe(
90
+ Effect.mapError(() => invalid("Host Tool visibility returned invalid names")),
91
+ );
92
+
93
+ if (checked.some((name) => !names.includes(name)))
94
+ return yield* invalid("Host Tool visibility returned an unregistered name");
95
+ const allowed = new Set(checked);
96
+
97
+ const permits = (tool: Tool.Any) =>
98
+ allowed.has(tool.name) && isSubagentToolAllowed(grant, depth, tool.name, tool.annotations);
99
+
100
+ for (const outer of Object.values(definition.toolkit.tools)) {
101
+ if (
102
+ permits(outer) &&
103
+ Context.get(outer.annotations, IncludesCatalogDocumentation) &&
104
+ Context.get(outer.annotations, AdditionalToolCatalog).some((entry) => !permits(entry.tool))
105
+ ) {
106
+ return yield* invalid(
107
+ "A Tool description includes hidden catalogue declarations; configure includeDeclarations: false",
108
+ );
109
+ }
110
+ }
111
+
112
+ return Object.freeze(
113
+ entries
114
+ .filter((entry) => {
115
+ const outer = definition.toolkit.tools[entry.nativeToolName];
116
+
117
+ return outer !== undefined && permits(outer) && permits(entry.tool);
118
+ })
119
+ .map((entry) => Object.freeze(entry)),
120
+ );
121
+ });
122
+
123
+ export const validateSelection = Effect.fn("ToolExposure.validateSelection")(function* (
124
+ value: unknown,
125
+ definition: AnyDefinition,
126
+ entries: ReadonlyArray<CatalogEntry>,
127
+ requireEligible = true,
128
+ ) {
129
+ const selection = yield* decodeSelection(value);
130
+
131
+ const eligible = new Set(
132
+ entries.filter((entry) => entry.kind === "native").map((entry) => entry.nativeToolName),
133
+ );
134
+
135
+ if (
136
+ selection.toolNames.some(
137
+ (name) =>
138
+ !Object.hasOwn(definition.toolkit.tools, name) || (requireEligible && !eligible.has(name)),
139
+ )
140
+ ) {
141
+ return yield* invalid("Tool selection names a Tool outside the eligible registered toolkit");
142
+ }
143
+
144
+ return Selection.make({ toolNames: Object.freeze([...selection.toolNames]) });
145
+ });
146
+
147
+ export const exposureSnapshot = Effect.fn("ToolExposure.exposureSnapshot")(function* (
148
+ definition: AnyDefinition,
149
+ selection: Selection | undefined,
150
+ entries: ReadonlyArray<CatalogEntry>,
151
+ transformer?: LanguageModel.CodecTransformer,
152
+ only?: ReadonlyArray<string>,
153
+ ) {
154
+ const native = entries.filter((entry) => entry.kind === "native").map((entry) => entry.tool);
155
+ const progressive = definition.toolExposure !== undefined || selection !== undefined;
156
+
157
+ const mandatory = Object.values(definition.toolkit.tools).filter(
158
+ (tool) =>
159
+ Context.get(tool.annotations, DiscoveryTool) ||
160
+ Context.get(tool.annotations, ContextRolloverTool) ||
161
+ (definition.completion?.required === true && definition.completion.tool === tool.name),
162
+ );
163
+
164
+ if (
165
+ progressive &&
166
+ mandatory.some((tool) => !native.some((candidate) => candidate.name === tool.name))
167
+ ) {
168
+ return yield* invalid("A mandatory Tool is excluded by host visibility or the inherited grant");
169
+ }
170
+
171
+ // Explicit pins affect selection, never eligibility. Hosts may disable a common action
172
+ // without disabling the Run; protocol-required Tools still fail closed above.
173
+ const pinned = native.filter(
174
+ (tool) => Context.get(tool.annotations, PinnedTool) || mandatory.includes(tool),
175
+ );
176
+
177
+ if (selection !== undefined) yield* validateSelection(selection, definition, entries, false);
178
+ const selected = selection === undefined ? undefined : new Set(selection.toolNames);
179
+
180
+ const names = native
181
+ .filter((tool) => selected === undefined || selected.has(tool.name) || pinned.includes(tool))
182
+ .map((tool) => tool.name)
183
+ .filter((name) => only === undefined || only.includes(name));
184
+
185
+ if (progressive) {
186
+ const limits = yield* Schema.decodeEffect(Limits)({
187
+ maxTools: definition.toolExposure?.maxTools ?? 64,
188
+ maxSchemaBytes: definition.toolExposure?.maxSchemaBytes ?? 262_144,
189
+ }).pipe(Effect.mapError(() => invalid("Invalid Tool exposure bounds")));
190
+
191
+ if (names.length > limits.maxTools)
192
+ return yield* invalid("Tool exposure exceeds the configured Tool count bound");
193
+
194
+ const bytes = yield* Effect.try({
195
+ try: () =>
196
+ utf8ByteLength(
197
+ JSON.stringify(
198
+ names.map((name) => {
199
+ const tool = definition.toolkit.tools[name];
200
+
201
+ if (tool === undefined) throw new Error("Selected Tool is unavailable");
202
+
203
+ return Tool.isProviderDefined(tool)
204
+ ? { type: tool.providerName, args: tool.args }
205
+ : {
206
+ name,
207
+ description: Tool.getDescription(tool),
208
+ parameters: Tool.getJsonSchema(tool, { transformer }),
209
+ };
210
+ }),
211
+ ),
212
+ ),
213
+ catch: () => invalid("A selected Tool schema cannot be rendered"),
214
+ });
215
+
216
+ if (bytes > limits.maxSchemaBytes)
217
+ return yield* invalid("Tool exposure exceeds the configured schema byte bound");
218
+ }
219
+
220
+ return yield* decodeSnapshot({
221
+ exposedToolNames: names,
222
+ ...(selection === undefined ? {} : { selection }),
223
+ });
224
+ });
@@ -0,0 +1,484 @@
1
+ import {
2
+ Cause,
3
+ Context,
4
+ Effect,
5
+ ErrorReporter,
6
+ Exit,
7
+ type Fiber,
8
+ Layer,
9
+ Option,
10
+ Stream,
11
+ Tracer,
12
+ } from "effect";
13
+ import { AiError, type Tool } from "effect/unstable/ai";
14
+
15
+ import type { ToolFailureHandling } from "../../core/RunEvent.ts";
16
+ import { isolateToolDerivative } from "./tool-derivative.ts";
17
+
18
+ /**
19
+ * @internal Payload-free control signal used only to close the canonical Tool span with a failed
20
+ * Exit. It is removed immediately outside that span and never enters the public error channel.
21
+ */
22
+ export class ToolSpanFailure extends AiError.AiError.extend<ToolSpanFailure>(
23
+ "@effect-agent/engine/ToolSpanFailure",
24
+ )({}) {
25
+ override readonly name = "ToolCallFailed";
26
+
27
+ /** Schema-safe factory retaining the generated constructor required by Effect Schema. */
28
+ static marker(): ToolSpanFailure {
29
+ return ToolSpanFailure.make({
30
+ module: "effect-agent",
31
+ method: "execute_tool",
32
+ reason: AiError.UnknownError.make({
33
+ description: "Tool execution reached a failed terminal state",
34
+ }),
35
+ });
36
+ }
37
+ }
38
+
39
+ const TOOL_SPAN_FAILURE_MARKER_ATTRIBUTE = "@effect-agent/engine/ToolSpanFailureMarker";
40
+
41
+ const terminalOutcomeTokens = new WeakMap<
42
+ object,
43
+ {
44
+ readonly outcome: "success" | "failure";
45
+ readonly failureMarker: ToolSpanFailure | undefined;
46
+ readonly failureHandling: ToolFailureHandling | undefined;
47
+ readonly failureMode: Tool.FailureMode | undefined;
48
+ }
49
+ >();
50
+
51
+ /** @internal Annotate one completed attempt and hand its existing marker to the isolated span. */
52
+ export const annotateToolSpanTerminalOutcome = (
53
+ outcome: "success" | "failure",
54
+ failureMarker?: ToolSpanFailure,
55
+ failureHandling?: ToolFailureHandling,
56
+ failureMode?: Tool.FailureMode,
57
+ ): Effect.Effect<void> => {
58
+ const token = {};
59
+
60
+ terminalOutcomeTokens.set(token, { outcome, failureMarker, failureHandling, failureMode });
61
+
62
+ return Effect.annotateCurrentSpan({
63
+ "effect_agent.tool.outcome": outcome,
64
+ [TOOL_SPAN_FAILURE_MARKER_ATTRIBUTE]: token,
65
+ });
66
+ };
67
+
68
+ export const stripToolSpanFailures = <E>(
69
+ cause: Cause.Cause<E | ToolSpanFailure>,
70
+ marker: ToolSpanFailure,
71
+ ): { readonly found: boolean; readonly residual: Cause.Cause<E | ToolSpanFailure> } => {
72
+ const found = cause.reasons.some(
73
+ (reason) => Cause.isFailReason(reason) && reason.error === marker,
74
+ );
75
+
76
+ if (!found) {
77
+ // Effect v4 Cause is a flat collection of Reasons. Object-identity absence proves only that
78
+ // this invocation's marker is absent: another ToolSpanFailure may still be a genuine handler
79
+ // failure, so retain both the exact Cause object and its complete error union.
80
+ return { found: false, residual: cause };
81
+ }
82
+
83
+ const reasons = cause.reasons.filter((reason) => {
84
+ if (Cause.isFailReason(reason) && reason.error === marker) {
85
+ return false;
86
+ }
87
+
88
+ return true;
89
+ });
90
+
91
+ return { found: true, residual: Cause.fromReasons(reasons) };
92
+ };
93
+
94
+ /** @internal Remove only the private marker and restore the saved Cause plus every residual. */
95
+ export const restoreToolSpanFailureCause = <E, Original>(
96
+ cause: Cause.Cause<E | ToolSpanFailure>,
97
+ marker: ToolSpanFailure,
98
+ original: Cause.Cause<Original> | undefined,
99
+ ): {
100
+ readonly found: boolean;
101
+ readonly restored: Cause.Cause<E | Original | ToolSpanFailure>;
102
+ } => {
103
+ const { found, residual } = stripToolSpanFailures(cause, marker);
104
+
105
+ return {
106
+ found,
107
+ restored: original === undefined ? residual : Cause.combine(original, residual),
108
+ };
109
+ };
110
+
111
+ const MAX_REPORTED_SPAN_LIFECYCLE_DEFECTS = 16;
112
+
113
+ /** Content-free marker used only to close a delegate that cannot be wrapped safely. */
114
+ class ToolSpanLifecycleFailure extends Error {
115
+ override readonly name = "ToolSpanLifecycleFailure";
116
+
117
+ constructor() {
118
+ super("Tool span lifecycle failed");
119
+ }
120
+ }
121
+
122
+ /**
123
+ * @internal Guard one host span so synchronous exporter defects cannot alter Tool execution.
124
+ * The wrapper retains the span contract for Effect while forwarding every measurement to the host.
125
+ */
126
+ class IsolatedToolSpan implements Tracer.Span {
127
+ readonly _tag = "Span";
128
+ readonly name: string;
129
+ readonly spanId: string;
130
+ readonly traceId: string;
131
+ readonly parent: Tracer.Span["parent"];
132
+ readonly annotations: Tracer.Span["annotations"];
133
+ readonly attributes = new Map<string, unknown>();
134
+ readonly links: Array<Tracer.SpanLink>;
135
+ readonly sampled: boolean;
136
+ readonly kind: Tracer.SpanKind;
137
+ status: Tracer.SpanStatus;
138
+
139
+ readonly #delegate: Tracer.Span;
140
+ readonly #recordDefect: (defect: unknown) => void;
141
+ #terminalOutcome: "success" | "failure" | undefined;
142
+ #terminalFailure: ToolSpanFailure | undefined;
143
+ #terminalFailureHandling: ToolFailureHandling | undefined;
144
+ #terminalFailureMode: Tool.FailureMode | undefined;
145
+
146
+ constructor(
147
+ delegate: Tracer.Span,
148
+ options: Parameters<Tracer.Tracer["span"]>[0],
149
+ recordDefect: (defect: unknown) => void,
150
+ ) {
151
+ this.#delegate = delegate;
152
+ this.#recordDefect = recordDefect;
153
+ this.name = options.name;
154
+ this.spanId = delegate.spanId;
155
+ this.traceId = delegate.traceId;
156
+ this.parent = options.parent;
157
+ this.annotations = options.annotations;
158
+ this.links = [...options.links];
159
+ // The host tracer owns the final sampling decision. Reading it here keeps that access inside
160
+ // the caller's existing creation try/fallback together with span allocation and identifiers.
161
+ this.sampled = delegate.sampled;
162
+ this.kind = options.kind;
163
+ this.status = { _tag: "Started", startTime: options.startTime };
164
+ }
165
+
166
+ end(endTime: bigint, exit: Exit.Exit<unknown, unknown>): void {
167
+ if (this.status._tag === "Ended") return;
168
+
169
+ // Early downstream closure can own terminal telemetry from a no-fail stream finalizer, where
170
+ // the private typed marker is intentionally captured because there is no consumer left to
171
+ // observe it. Once present, the bounded outcome annotation is authoritative for this completed
172
+ // attempt even if downstream cancellation or telemetry interruption determines the channel Exit.
173
+ const exportedExit =
174
+ this.#terminalOutcome === "failure"
175
+ ? Exit.fail(this.#terminalFailure ?? new ToolSpanLifecycleFailure())
176
+ : this.#terminalOutcome === "success"
177
+ ? Exit.succeed(undefined)
178
+ : exit;
179
+
180
+ this.status = {
181
+ _tag: "Ended",
182
+ startTime: this.status.startTime,
183
+ endTime,
184
+ exit: exportedExit,
185
+ };
186
+ if (this.#terminalOutcome !== undefined) {
187
+ // The public attribute map is intentionally mutable for ordinary instrumentation. Restore
188
+ // this framework-owned value from the authenticated private token at the export boundary so
189
+ // handler or telemetry code cannot forge the canonical terminal classification.
190
+ this.attributes.set("effect_agent.tool.outcome", this.#terminalOutcome);
191
+ try {
192
+ this.#delegate.attribute("effect_agent.tool.outcome", this.#terminalOutcome);
193
+ } catch (defect) {
194
+ this.#recordDefect(defect);
195
+ }
196
+ }
197
+ for (const [key, value] of [
198
+ ["effect_agent.tool.failure_mode", this.#terminalFailureMode],
199
+ ["effect_agent.tool.failure_handling", this.#terminalFailureHandling],
200
+ ] as const) {
201
+ if (value !== undefined) {
202
+ this.attributes.set(key, value);
203
+ try {
204
+ this.#delegate.attribute(key, value);
205
+ } catch (defect) {
206
+ this.#recordDefect(defect);
207
+ }
208
+ } else if (key === "effect_agent.tool.failure_handling") {
209
+ this.attributes.delete(key);
210
+ }
211
+ }
212
+ try {
213
+ this.#delegate.end(endTime, exportedExit);
214
+ } catch (defect) {
215
+ this.#recordDefect(defect);
216
+ }
217
+ }
218
+
219
+ attribute(key: string, value: unknown): void {
220
+ if (key === TOOL_SPAN_FAILURE_MARKER_ATTRIBUTE) {
221
+ if (typeof value === "object" && value !== null) {
222
+ const terminal = terminalOutcomeTokens.get(value);
223
+
224
+ if (terminal !== undefined) {
225
+ this.#terminalOutcome = terminal.outcome;
226
+ this.#terminalFailure = terminal.failureMarker;
227
+ this.#terminalFailureHandling = terminal.failureHandling;
228
+ this.#terminalFailureMode = terminal.failureMode;
229
+ }
230
+ }
231
+
232
+ return;
233
+ }
234
+ // Only the authenticated terminal token may classify a failure's route.
235
+ if (key === "effect_agent.tool.failure_handling") return;
236
+ this.attributes.set(key, value);
237
+ try {
238
+ this.#delegate.attribute(key, value);
239
+ } catch (defect) {
240
+ this.#recordDefect(defect);
241
+ }
242
+ }
243
+
244
+ event(name: string, startTime: bigint, attributes?: Record<string, unknown>): void {
245
+ try {
246
+ this.#delegate.event(name, startTime, attributes);
247
+ } catch (defect) {
248
+ this.#recordDefect(defect);
249
+ }
250
+ }
251
+
252
+ addLinks(links: ReadonlyArray<Tracer.SpanLink>): void {
253
+ this.links.push(...links);
254
+ try {
255
+ this.#delegate.addLinks(links);
256
+ } catch (defect) {
257
+ this.#recordDefect(defect);
258
+ }
259
+ }
260
+ }
261
+
262
+ interface IsolatedToolTracer {
263
+ readonly tracer: Tracer.Tracer;
264
+ readonly reportLifecycleDefects: Effect.Effect<void>;
265
+ }
266
+
267
+ /**
268
+ * @internal Isolate the complete canonical span lifecycle. A creation defect receives a local,
269
+ * non-exported span so the handler still runs; delegate method/finalization defects are retained
270
+ * as bounded reporter diagnostics and never enter the handler stream Cause.
271
+ */
272
+ export const makeIsolatedToolTracer = (delegate: Tracer.Tracer): IsolatedToolTracer => {
273
+ const defects: Array<unknown> = [];
274
+
275
+ const recordDefect = (defect: unknown): void => {
276
+ if (defects.length < MAX_REPORTED_SPAN_LIFECYCLE_DEFECTS) defects.push(defect);
277
+ };
278
+
279
+ let delegateContext: Tracer.Tracer["context"];
280
+
281
+ try {
282
+ delegateContext = delegate.context?.bind(delegate);
283
+ } catch (defect) {
284
+ recordDefect(defect);
285
+ delegateContext = undefined;
286
+ }
287
+
288
+ const context: Tracer.Tracer["context"] =
289
+ delegateContext === undefined
290
+ ? undefined
291
+ : <X>(primitive: Tracer.EffectPrimitive<X>, fiber: Fiber.Fiber<unknown, unknown>): X => {
292
+ type Evaluation =
293
+ | { readonly _tag: "Pending" }
294
+ | { readonly _tag: "Succeeded"; readonly value: X }
295
+ | { readonly _tag: "Failed"; readonly error: unknown };
296
+ let evaluation: Evaluation = { _tag: "Pending" };
297
+ const currentEvaluation = (): Evaluation => evaluation;
298
+
299
+ const evaluate = (currentFiber: Fiber.Fiber<unknown, unknown>): X => {
300
+ switch (evaluation._tag) {
301
+ case "Succeeded":
302
+ return evaluation.value;
303
+ case "Failed":
304
+ throw evaluation.error;
305
+ case "Pending": {
306
+ try {
307
+ const value = primitive["~effect/Effect/evaluate"](currentFiber);
308
+
309
+ evaluation = { _tag: "Succeeded", value };
310
+
311
+ return value;
312
+ } catch (error) {
313
+ evaluation = { _tag: "Failed", error };
314
+ throw error;
315
+ }
316
+ }
317
+ }
318
+ };
319
+
320
+ const guardedPrimitive: Tracer.EffectPrimitive<X> = {
321
+ ["~effect/Effect/evaluate"]: evaluate,
322
+ };
323
+
324
+ try {
325
+ delegateContext(guardedPrimitive, fiber);
326
+ } catch (defect) {
327
+ const observed = currentEvaluation();
328
+
329
+ switch (observed._tag) {
330
+ case "Failed":
331
+ throw observed.error;
332
+ case "Succeeded":
333
+ recordDefect(defect);
334
+
335
+ return observed.value;
336
+ case "Pending":
337
+ recordDefect(defect);
338
+
339
+ return evaluate(fiber);
340
+ }
341
+ }
342
+ const observed = currentEvaluation();
343
+
344
+ switch (observed._tag) {
345
+ case "Failed":
346
+ throw observed.error;
347
+ case "Succeeded":
348
+ return observed.value;
349
+ case "Pending":
350
+ return evaluate(fiber);
351
+ }
352
+ };
353
+
354
+ const tracer = Tracer.make({
355
+ context,
356
+ span(options) {
357
+ let delegateSpan: Tracer.Span;
358
+
359
+ try {
360
+ delegateSpan = delegate.span(options);
361
+ } catch (defect) {
362
+ recordDefect(defect);
363
+
364
+ // This native span is deliberately not handed to the host exporter. It only preserves
365
+ // Effect's current-span contract so Tool behavior continues without observable tracing.
366
+ return new Tracer.NativeSpan(options);
367
+ }
368
+ try {
369
+ return new IsolatedToolSpan(delegateSpan, options, recordDefect);
370
+ } catch (defect) {
371
+ recordDefect(defect);
372
+ try {
373
+ // Allocation succeeded, so best-effort close the host span without attaching the raw
374
+ // wrapper defect. The start time gives this abandoned measurement a bounded duration.
375
+ delegateSpan.end(options.startTime, Exit.fail(new ToolSpanLifecycleFailure()));
376
+ } catch (closeDefect) {
377
+ recordDefect(closeDefect);
378
+ }
379
+
380
+ return new Tracer.NativeSpan(options);
381
+ }
382
+ },
383
+ });
384
+
385
+ const reportLifecycleDefects = Effect.suspend(() => {
386
+ const pending = defects.splice(0);
387
+
388
+ return Effect.forEach(
389
+ pending,
390
+ (defect) => isolateToolDerivative(ErrorReporter.report(Cause.die(defect))),
391
+ { discard: true },
392
+ );
393
+ });
394
+
395
+ return { tracer, reportLifecycleDefects };
396
+ };
397
+
398
+ export interface ToolSpanTelemetryService {
399
+ /** Measure one Tool handler attempt while isolating every host span-lifecycle defect. */
400
+ readonly isolateSpanLifecycle: <A, E, R>(
401
+ stream: Stream.Stream<A, E, R>,
402
+ ) => Stream.Stream<A, E, R>;
403
+ /** Effect counterpart used by programmatic Tool handlers nested inside an outer Tool stream. */
404
+ readonly isolateEffectSpanLifecycle: <A, E, R>(
405
+ effect: Effect.Effect<A, E, R>,
406
+ ) => Effect.Effect<A, E, R>;
407
+ /** Keep Effect AI implementation annotations local while preserving host-owned handler spans. */
408
+ readonly isolateToolkitHandle: <A, E, R>(
409
+ effect: Effect.Effect<A, E, R>,
410
+ ) => Effect.Effect<A, E, R>;
411
+ }
412
+
413
+ /**
414
+ * @internal Engine-owned span-lifecycle policy. The AgentRuntime composition boundary builds this
415
+ * capability from the host's ambient Tracer; Tool execution consumes it without selecting,
416
+ * decorating, or locally providing a Tracer implementation.
417
+ */
418
+ export class ToolSpanTelemetry extends Context.Service<
419
+ ToolSpanTelemetry,
420
+ ToolSpanTelemetryService
421
+ >()("@effect-agent/engine/ToolSpanTelemetry") {
422
+ static readonly layer: Layer.Layer<ToolSpanTelemetry> = Layer.effect(
423
+ ToolSpanTelemetry,
424
+ Effect.map(Tracer.Tracer, (delegate) =>
425
+ ToolSpanTelemetry.of({
426
+ isolateEffectSpanLifecycle: (effect) =>
427
+ Effect.suspend(() => {
428
+ const isolated = makeIsolatedToolTracer(delegate);
429
+
430
+ return effect.pipe(
431
+ Effect.provideService(Tracer.Tracer, isolated.tracer),
432
+ // `Effect.ensuring` runs after the measured span's finalizer, matching the Stream
433
+ // boundary below while keeping the broker's value and error channels unchanged.
434
+ Effect.ensuring(isolated.reportLifecycleDefects),
435
+ );
436
+ }),
437
+ isolateToolkitHandle: (effect) =>
438
+ Effect.currentSpan.pipe(
439
+ Effect.option,
440
+ Effect.flatMap((parentOption) => {
441
+ if (Option.isNone(parentOption)) return effect;
442
+ const parent = parentOption.value;
443
+
444
+ // Effect AI annotates its current span with decoded Tool parameters before forking
445
+ // the handler. Keep those annotations on a local span that is never handed to the
446
+ // host tracer. DisablePropagation makes explicit handler spans filter past this
447
+ // implementation parent and attach to the canonical execute_tool span instead.
448
+ const local = new Tracer.NativeSpan({
449
+ name: "AgentRuntime.toolkit.handle",
450
+ parent: Option.some(parent),
451
+ annotations: Context.add(Context.empty(), Tracer.DisablePropagation, true),
452
+ links: [],
453
+ startTime: 0n,
454
+ kind: "internal",
455
+ sampled: parent.sampled,
456
+ });
457
+
458
+ return effect.pipe(
459
+ Effect.withParentSpan(local),
460
+ Effect.onExit((exit) =>
461
+ Effect.sync(() => {
462
+ local.end(0n, exit);
463
+ }),
464
+ ),
465
+ );
466
+ }),
467
+ ),
468
+ isolateSpanLifecycle: (stream) =>
469
+ Stream.unwrap(
470
+ Effect.sync(() => {
471
+ const isolated = makeIsolatedToolTracer(delegate);
472
+
473
+ return stream.pipe(
474
+ Stream.provideService(Tracer.Tracer, isolated.tracer),
475
+ // `Stream.ensuring` runs after the canonical span's own finalizer, so creation,
476
+ // annotation, and close defects are reported outside this execution's measurement.
477
+ Stream.ensuring(isolated.reportLifecycleDefects),
478
+ );
479
+ }),
480
+ ),
481
+ }),
482
+ ),
483
+ );
484
+ }