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,1090 @@
1
+ import {
2
+ type Layer,
3
+ Cause,
4
+ Context,
5
+ Duration,
6
+ Effect,
7
+ Exit,
8
+ Option,
9
+ Schema,
10
+ type Scope,
11
+ } from "effect";
12
+ import { Tool, Toolkit } from "effect/unstable/ai";
13
+
14
+ import { utf8ByteLength } from "../core/internal/utf8.ts";
15
+ import { AdditionalToolCatalog, IncludesCatalogDocumentation } from "../core/ToolExposure.ts";
16
+ import {
17
+ type ToolBrokerConfigurationError,
18
+ type ToolBrokerUnavailableError,
19
+ ToolBroker,
20
+ type ProgrammaticCallOutcome,
21
+ type ToolBrokerPass,
22
+ ProgrammaticCallRecord,
23
+ } from "../engine/ToolBroker.ts";
24
+ import { CurrentToolCatalog } from "../engine/ToolExposure.ts";
25
+ import {
26
+ type CodeExecutionError,
27
+ CodeExecutionHost,
28
+ CodeExecutionLimits,
29
+ CodeExecutionNamespace,
30
+ CodeExecutionRequest,
31
+ CodeExecutor,
32
+ JsIdentifier,
33
+ type CodeExecutionResult,
34
+ type CodeHostCall,
35
+ type CodeHostCallResult,
36
+ } from "../sandbox/CodeExecutor.ts";
37
+ import { NetworkDisabled } from "../sandbox/Sandbox.ts";
38
+
39
+ /**
40
+ * Code Mode (D-035, ADR-0017; capability spec §9.1): one native Effect AI
41
+ * Tool whose input is bounded JavaScript source, executed in one isolated
42
+ * `CodeExecutor` pass that may call an explicit construction-time allowlist
43
+ * of existing Tools through typed sandbox globals and the engine-owned
44
+ * `ToolBroker`. The builder follows the Delegation pattern: an explicit
45
+ * record of selected Tools plus namespace mapping fixed at construction,
46
+ * returning an ordinary Tool and a handler Layer, with no ambient registry
47
+ * (CAP-014). Deployment class `E` only.
48
+ */
49
+
50
+ const maxFailureTextLength = 4 * 1024;
51
+ const BoundedFailureText = Schema.String.check(Schema.isMaxLength(maxFailureTextLength));
52
+ const BoundedErrorTag = Schema.NonEmptyString.check(Schema.isMaxLength(256));
53
+ const BoundedLogLine = Schema.String.check(Schema.isMaxLength(16 * 1024));
54
+ const BoundedLogs = Schema.Array(BoundedLogLine).check(Schema.isMaxLength(4_096));
55
+ const BoundedCode = Schema.NonEmptyString.check(Schema.isMaxLength(512 * 1024));
56
+
57
+ /** A pass-local report, available to the host even when the caller interrupts execution. */
58
+ export const CodeModePassReport = Schema.Struct({
59
+ status: Schema.Literals(["completed", "failed", "interrupted", "defect"]),
60
+ calls: Schema.Array(ProgrammaticCallRecord),
61
+ });
62
+
63
+ export type CodeModePassReport = typeof CodeModePassReport.Type;
64
+
65
+ const encodedJsonByteLength = (value: unknown): number | undefined => {
66
+ try {
67
+ const encoded = JSON.stringify(value);
68
+
69
+ return encoded === undefined ? undefined : utf8ByteLength(encoded);
70
+ } catch {
71
+ return undefined;
72
+ }
73
+ };
74
+
75
+ /** Model-decoded Code Mode parameters: one async function expression. */
76
+ export const CodeModeParameters = Schema.Struct({
77
+ code: BoundedCode,
78
+ });
79
+
80
+ /**
81
+ * The bounded model-visible success: the program's JSON result plus captured
82
+ * logs, both already passed through the aggregate egress budget (CAP-016).
83
+ */
84
+ export class CodeModeSuccess extends Schema.Class<CodeModeSuccess>(
85
+ "@effect-agent/capabilities/CodeModeSuccess",
86
+ )({
87
+ result: Schema.Json,
88
+ logs: BoundedLogs,
89
+ }) {}
90
+
91
+ /**
92
+ * The bounded model-visible failure envelope. `failureMode: "return"` turns
93
+ * it into a failed Tool result, so a model can correct a failing program
94
+ * without a blind retry; it carries the same bounded log capture as success
95
+ * plus the bounded thrown value where one exists, all inside the same
96
+ * aggregate egress budget (CAP-016).
97
+ */
98
+ export class CodeModeFailure extends Schema.TaggedError<CodeModeFailure>()("CodeModeFailure", {
99
+ errorTag: BoundedErrorTag,
100
+ message: BoundedFailureText,
101
+ logs: BoundedLogs,
102
+ thrown: Schema.optionalKey(Schema.Json),
103
+ /** Invocation-ordered evidence that fits the egress budget. This is not a replay plan. */
104
+ calls: Schema.optionalKey(Schema.Array(ProgrammaticCallRecord)),
105
+ omittedCalls: Schema.optionalKey(Schema.Natural),
106
+ }) {}
107
+
108
+ /** A selective documentation request is invalid or cannot fit its declared byte budget. */
109
+ export class CodeModeDescriptionError extends Schema.TaggedError<CodeModeDescriptionError>()(
110
+ "CodeModeDescriptionError",
111
+ {
112
+ reason: Schema.Literals([
113
+ "invalid-selection",
114
+ "unknown-method",
115
+ "invalid-bound",
116
+ "limit-exceeded",
117
+ ]),
118
+ message: BoundedFailureText,
119
+ },
120
+ ) {}
121
+
122
+ const DescriptionMethods = Schema.Array(Schema.NonEmptyString.check(Schema.isMaxLength(257))).check(
123
+ Schema.isMinLength(1),
124
+ Schema.isMaxLength(64),
125
+ Schema.isUnique(),
126
+ );
127
+
128
+ const DescriptionByteLimit = Schema.Int.check(
129
+ Schema.isBetween({ minimum: 1, maximum: 256 * 1024 }),
130
+ );
131
+
132
+ /** The namespace-record shape accepted by `CodeMode.make`. */
133
+ export type CodeModeNamespaces = Record<string, Record<string, Tool.Any>>;
134
+
135
+ /**
136
+ * Union of every Tool selected across all namespaces, computed distributively
137
+ * per namespace: indexing the namespace union with the INTERSECTION of method
138
+ * keys would erase every Tool once two namespaces have disjoint methods.
139
+ */
140
+ export type CodeModeSelectedTool<Namespaces extends CodeModeNamespaces> = {
141
+ [Namespace in keyof Namespaces]: Namespaces[Namespace][keyof Namespaces[Namespace]];
142
+ }[keyof Namespaces];
143
+
144
+ /** The selected Tools re-keyed by their own Tool names. */
145
+ export type CodeModeSelectedRecord<Namespaces extends CodeModeNamespaces> = {
146
+ readonly [T in CodeModeSelectedTool<Namespaces> as T["name"]]: T;
147
+ };
148
+
149
+ /**
150
+ * The native Effect AI Tool created by `CodeMode.make` (CAP-014). Its only
151
+ * per-call dependency is the engine-provided `ToolBroker`; the `CodeExecutor`
152
+ * and every selected handler and redaction service are construction requirements of the handler
153
+ * Layer instead, so they stay visible in the composed `R`.
154
+ */
155
+ export type CodeModeTool<Name extends string> = Tool.Tool<
156
+ Name,
157
+ {
158
+ readonly parameters: typeof CodeModeParameters;
159
+ readonly success: typeof CodeModeSuccess;
160
+ readonly failure: typeof CodeModeFailure;
161
+ readonly failureMode: "return";
162
+ },
163
+ ToolBroker
164
+ >;
165
+
166
+ /** Singleton Tool record provided by one Code Mode handler Layer. */
167
+ export type CodeModeTools<Name extends string> = {
168
+ readonly [Key in Name]: CodeModeTool<Name>;
169
+ };
170
+
171
+ /** Construction requirements of the Code Mode handler Layer. */
172
+ export type CodeModeLayerRequirements<
173
+ Namespaces extends CodeModeNamespaces,
174
+ RedactionRequirements = never,
175
+ > =
176
+ | CodeExecutor
177
+ | Exclude<RedactionRequirements, Scope.Scope>
178
+ | Tool.HandlersFor<CodeModeSelectedRecord<Namespaces>>
179
+ | Tool.HandlerServices<CodeModeSelectedTool<Namespaces>>;
180
+
181
+ export interface CodeModeOptions<
182
+ Namespaces extends CodeModeNamespaces,
183
+ RedactionRequirements = never,
184
+ > {
185
+ /** Model-visible description; the builder appends the sandbox contract. */
186
+ readonly description: string;
187
+ /** Include all sandbox declarations in the model-facing description. Defaults to true. */
188
+ readonly includeDeclarations?: boolean | undefined;
189
+ /**
190
+ * Explicit allowlist: namespace name → method name → native Effect AI
191
+ * Tool. Reads and mutations are allowed; calls requiring additional approval fail closed.
192
+ */
193
+ readonly tools: Namespaces;
194
+ /** Executor limits for one pass; a bounded default applies when omitted. */
195
+ readonly limits?: CodeExecutionLimits | undefined;
196
+ /**
197
+ * Aggregate model-visible egress budget in UTF-8 bytes across the final
198
+ * result, captured logs, and any thrown value (CAP-016). Default 65536.
199
+ */
200
+ readonly maxEgressBytes?: number | undefined;
201
+ /**
202
+ * Host-only ephemeral report after executor resources and invocation fibers close, including
203
+ * failure, defect, and interruption. It contains no arguments/results and is never a checkpoint.
204
+ * Keep this total callback bounded; its services are captured with the handler Layer.
205
+ */
206
+ readonly onPassExit?:
207
+ | ((report: CodeModePassReport) => Effect.Effect<void, never, RedactionRequirements>)
208
+ | undefined;
209
+ /**
210
+ * Optional aggregate redaction pass applied to the model-visible egress
211
+ * before the byte budget. Its services are acquired with the handler Layer;
212
+ * temporary resources close with each redaction invocation.
213
+ * It must be total; a defect stays a defect.
214
+ */
215
+ readonly redactEgress?:
216
+ | ((egress: {
217
+ readonly result: Schema.Json;
218
+ readonly logs: ReadonlyArray<string>;
219
+ }) => Effect.Effect<
220
+ {
221
+ readonly result: Schema.Json;
222
+ readonly logs: ReadonlyArray<string>;
223
+ },
224
+ never,
225
+ RedactionRequirements
226
+ >)
227
+ | undefined;
228
+ }
229
+
230
+ /**
231
+ * An immutable Code Mode definition: one model-facing Tool over an explicit
232
+ * allowlist, plus the handler Layer that runs generated programs through the
233
+ * `CodeExecutor` port and the engine-owned broker. It owns no acquired
234
+ * resources.
235
+ */
236
+ export interface CodeModeDefinition<
237
+ Name extends string,
238
+ Namespaces extends CodeModeNamespaces,
239
+ RedactionRequirements = never,
240
+ > {
241
+ readonly name: Name;
242
+ /** The assembled model-facing description, optionally including all declarations. */
243
+ readonly description: string;
244
+ /** Rendered TypeScript declarations of the sandbox globals (documentation only). */
245
+ readonly declarations: string;
246
+ /**
247
+ * Render complete encoded-schema declarations for 1–64 unique, exact namespace.method names.
248
+ * The UTF-8 byte limit defaults to 16384 and must be an integer from 1 through 262144.
249
+ * Oversized documentation fails rather than truncating a declaration. This host operation
250
+ * does not authorize a model to see the selected methods; filter selections by current
251
+ * visibility and inherited grants before returning its output to a model.
252
+ */
253
+ readonly describe: (
254
+ methods: ReadonlyArray<string>,
255
+ options?: { readonly maxBytes?: number | undefined },
256
+ ) => Effect.Effect<string, CodeModeDescriptionError>;
257
+ /** The executor-facing namespace catalog derived from the allowlist. */
258
+ readonly namespaces: ReadonlyArray<CodeExecutionNamespace>;
259
+ readonly limits: CodeExecutionLimits;
260
+ readonly maxEgressBytes: number;
261
+ /** The ordinary Effect AI Tool to include in the model-facing Toolkit. */
262
+ readonly tool: CodeModeTool<Name>;
263
+ /** Handler Layer; selected handler requirements stay visible in `R`. */
264
+ readonly handlers: Layer.Layer<
265
+ Tool.HandlersFor<CodeModeTools<Name>>,
266
+ never,
267
+ CodeModeLayerRequirements<Namespaces, RedactionRequirements>
268
+ >;
269
+ }
270
+
271
+ const defaultLimits = CodeExecutionLimits.make({
272
+ maxSourceBytes: 256 * 1024,
273
+ maxWallTime: Duration.seconds(30),
274
+ maxLogBytes: 256 * 1024,
275
+ maxResultBytes: 1024 * 1024,
276
+ maxHostCalls: 64,
277
+ maxHostCallArgumentBytes: 256 * 1024,
278
+ maxHostCallResultBytes: 1024 * 1024,
279
+ });
280
+
281
+ const defaultMaxEgressBytes = 64 * 1024;
282
+
283
+ // ---------------------------------------------------------------------------
284
+ // Declaration rendering (capability spec §9.1): the encoded side of each
285
+ // Schema — the JSON that actually crosses the sandbox boundary — rendered as
286
+ // TypeScript documentation via the same JSON-schema derivation Effect AI
287
+ // applies to Tool parameters. A schema the renderer cannot express fails Tool
288
+ // construction closed rather than degrading to `unknown`.
289
+ // ---------------------------------------------------------------------------
290
+
291
+ const MAX_RENDER_DEPTH = 24;
292
+
293
+ const isJsonSchemaRecord = (value: unknown): value is Record<string, unknown> =>
294
+ typeof value === "object" && value !== null && !Array.isArray(value);
295
+
296
+ const renderJsonSchemaType = (
297
+ schema: unknown,
298
+ defs: Record<string, unknown>,
299
+ depth: number,
300
+ indent: string,
301
+ ): string => {
302
+ if (depth > MAX_RENDER_DEPTH) {
303
+ throw new Error("Code Mode declaration rendering exceeded its depth bound");
304
+ }
305
+ if (!isJsonSchemaRecord(schema)) {
306
+ throw new Error(`Code Mode cannot render the JSON schema fragment ${JSON.stringify(schema)}`);
307
+ }
308
+ const reference = schema.$ref;
309
+
310
+ if (typeof reference === "string") {
311
+ const match = /^#\/\$defs\/(.+)$/.exec(reference);
312
+ // JSON-pointer tokens escape `/` as `~1` and `~` as `~0`.
313
+ const key = match === null ? undefined : match[1].replaceAll("~1", "/").replaceAll("~0", "~");
314
+ const resolved = key === undefined ? undefined : defs[key];
315
+
316
+ if (resolved === undefined) {
317
+ throw new Error(`Code Mode cannot resolve the JSON schema reference ${reference}`);
318
+ }
319
+
320
+ return renderJsonSchemaType(resolved, defs, depth + 1, indent);
321
+ }
322
+ if (Array.isArray(schema.enum)) {
323
+ return schema.enum.map((value) => JSON.stringify(value)).join(" | ");
324
+ }
325
+ if ("const" in schema) {
326
+ return JSON.stringify(schema.const);
327
+ }
328
+ const union = schema.anyOf ?? schema.oneOf;
329
+
330
+ if (Array.isArray(union)) {
331
+ return union.map((member) => renderJsonSchemaType(member, defs, depth + 1, indent)).join(" | ");
332
+ }
333
+ const type = schema.type;
334
+
335
+ if (Array.isArray(type)) {
336
+ return type
337
+ .map((member) => renderJsonSchemaType({ ...schema, type: member }, defs, depth + 1, indent))
338
+ .join(" | ");
339
+ }
340
+ switch (type) {
341
+ case "string": {
342
+ return "string";
343
+ }
344
+ case "number":
345
+ case "integer": {
346
+ return "number";
347
+ }
348
+ case "boolean": {
349
+ return "boolean";
350
+ }
351
+ case "null": {
352
+ return "null";
353
+ }
354
+ case "array": {
355
+ if (!("items" in schema)) {
356
+ throw new Error("Code Mode cannot render an array schema without items");
357
+ }
358
+
359
+ return `ReadonlyArray<${renderJsonSchemaType(schema.items, defs, depth + 1, indent)}>`;
360
+ }
361
+ case "object":
362
+ case undefined: {
363
+ if (isJsonSchemaRecord(schema.properties)) {
364
+ const required = Array.isArray(schema.required) ? schema.required : [];
365
+ const inner = `${indent} `;
366
+
367
+ const fields = Object.entries(schema.properties).map(([key, property]) => {
368
+ const optional = required.includes(key) ? "" : "?";
369
+ // A JSON property name need not be a TypeScript identifier.
370
+ const rendered = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
371
+
372
+ return `${inner}readonly ${rendered}${optional}: ${renderJsonSchemaType(property, defs, depth + 1, inner)};`;
373
+ });
374
+
375
+ return fields.length === 0 ? "{}" : `{\n${fields.join("\n")}\n${indent}}`;
376
+ }
377
+ if (isJsonSchemaRecord(schema.additionalProperties)) {
378
+ return `Record<string, ${renderJsonSchemaType(schema.additionalProperties, defs, depth + 1, indent)}>`;
379
+ }
380
+ // A bare `{ "type": "object" }` states "any JSON object" (Schema.Json's
381
+ // object member derives to exactly this); rendering it as an
382
+ // unconstrained record is faithful, not a deriver degradation.
383
+ if (type === "object" && !("properties" in schema) && !("additionalProperties" in schema)) {
384
+ return "Record<string, unknown>";
385
+ }
386
+ break;
387
+ }
388
+ default: {
389
+ break;
390
+ }
391
+ }
392
+ throw new Error(
393
+ `Code Mode cannot render the JSON schema fragment ${JSON.stringify(schema).slice(0, 200)}; fix or simplify the Tool's Schema`,
394
+ );
395
+ };
396
+
397
+ const renderTopLevel = (jsonSchema: unknown, indent: string): string => {
398
+ const defs =
399
+ isJsonSchemaRecord(jsonSchema) && isJsonSchemaRecord(jsonSchema.$defs)
400
+ ? jsonSchema.$defs
401
+ : ({} as Record<string, unknown>);
402
+
403
+ return renderJsonSchemaType(jsonSchema, defs, 0, indent);
404
+ };
405
+
406
+ const decodeIdentifier = Schema.decodeUnknownOption(JsIdentifier);
407
+
408
+ interface ResolvedMethod {
409
+ readonly namespace: string;
410
+ readonly method: string;
411
+ readonly tool: Tool.Any;
412
+ }
413
+
414
+ const renderDeclarations = (methods: ReadonlyArray<ResolvedMethod>): string => {
415
+ const namespaces = new Map<string, Array<ResolvedMethod>>();
416
+
417
+ for (const method of methods) {
418
+ const existing = namespaces.get(method.namespace) ?? [];
419
+
420
+ existing.push(method);
421
+ namespaces.set(method.namespace, existing);
422
+ }
423
+
424
+ const blocks = [...namespaces.entries()].map(([namespace, members]) => {
425
+ const lines = members.map((member) => {
426
+ const parameters = renderTopLevel(Tool.getJsonSchema(member.tool), " ");
427
+ const success = renderTopLevel(Tool.getJsonSchemaFromSchema(member.tool.successSchema), " ");
428
+
429
+ // A description is arbitrary text: newlines and comment terminators
430
+ // must not be able to break out of the documentation comment.
431
+ const safeDescription = member.tool.description
432
+ ?.replaceAll("*/", "*\\/")
433
+ .replaceAll(/\s*\n\s*/g, " ");
434
+
435
+ const description = safeDescription === undefined ? "" : ` /** ${safeDescription} */\n`;
436
+
437
+ return `${description} ${member.method}(input: ${parameters}): Promise<${success}>;`;
438
+ });
439
+
440
+ return `declare const ${namespace}: {\n${lines.join("\n")}\n};`;
441
+ });
442
+
443
+ return blocks.join("\n\n");
444
+ };
445
+
446
+ // ---------------------------------------------------------------------------
447
+ // Aggregate model-visible egress (CAP-016): the final result, captured logs,
448
+ // and any thrown value share one byte budget. Logs are truncated line-by-line
449
+ // with an explicit marker; a result that alone exceeds the budget is a typed
450
+ // failure rather than silent truncation.
451
+ // ---------------------------------------------------------------------------
452
+
453
+ const truncationMarker = "… logs truncated by the egress budget";
454
+ const MAX_EGRESS_LOG_LINE_CHARACTERS = 16_000;
455
+
456
+ /**
457
+ * Budget charge of one log line as it actually crosses to the model: the
458
+ * JSON-encoded string (quotes, escapes) plus one array separator. Charging
459
+ * raw UTF-8 would undercount model-visible bytes for escape-heavy content.
460
+ */
461
+ const encodedLogLineBytes = (line: string): number => {
462
+ try {
463
+ return utf8ByteLength(JSON.stringify(line)) + 1;
464
+ } catch {
465
+ return Number.MAX_SAFE_INTEGER;
466
+ }
467
+ };
468
+
469
+ const budgetedLogs = (
470
+ logs: ReadonlyArray<string>,
471
+ remainingBytes: number,
472
+ ): ReadonlyArray<string> => {
473
+ const kept: Array<string> = [];
474
+ let used = 0;
475
+ let truncated = false;
476
+
477
+ for (const raw of logs) {
478
+ // Per-line cap keeps every kept line inside the BoundedLogLine schema.
479
+ const line =
480
+ raw.length > MAX_EGRESS_LOG_LINE_CHARACTERS
481
+ ? `${raw.slice(0, MAX_EGRESS_LOG_LINE_CHARACTERS - 1)}…`
482
+ : raw;
483
+
484
+ const bytes = encodedLogLineBytes(line);
485
+
486
+ if (kept.length >= 4_096 || used + bytes > remainingBytes) {
487
+ truncated = true;
488
+ break;
489
+ }
490
+ kept.push(line);
491
+ used += bytes;
492
+ }
493
+ if (truncated) {
494
+ // Truncation is never silent: drop kept lines from the end until the
495
+ // marker itself fits inside the budget.
496
+ const markerBytes = encodedLogLineBytes(truncationMarker);
497
+
498
+ while (kept.length > 0 && used + markerBytes > remainingBytes) {
499
+ used -= encodedLogLineBytes(kept.pop() ?? "");
500
+ }
501
+ if (markerBytes <= remainingBytes) {
502
+ kept.push(truncationMarker);
503
+ }
504
+ }
505
+
506
+ return kept;
507
+ };
508
+
509
+ const boundedMessage = (message: string): string => message.slice(0, maxFailureTextLength);
510
+
511
+ const executionFailureMessage = (error: CodeExecutionError): string => {
512
+ switch (error._tag) {
513
+ case "CodeExecutionTimeoutError": {
514
+ return `The program exceeded its ${Duration.format(error.maxWallTime)} ${error.kind} budget`;
515
+ }
516
+ case "CodeOutputLimitError": {
517
+ return `The ${error.surface} limit of ${error.limit} bytes was exceeded (${error.observed} bytes observed)`;
518
+ }
519
+ case "CodeHostCallLimitError": {
520
+ return `The pass exceeded its executor cap of ${error.limit} host calls`;
521
+ }
522
+ default: {
523
+ return error.message;
524
+ }
525
+ }
526
+ };
527
+
528
+ /** UTF-8-aware truncation so a message can never exceed the aggregate budget. */
529
+ const truncateToUtf8Bytes = (value: string, maxBytes: number): string => {
530
+ if (utf8ByteLength(value) <= maxBytes) {
531
+ return value;
532
+ }
533
+ let output = "";
534
+ let used = 0;
535
+
536
+ for (const character of value) {
537
+ const bytes = utf8ByteLength(character);
538
+
539
+ if (used + bytes + 3 > maxBytes) {
540
+ break;
541
+ }
542
+ output += character;
543
+ used += bytes;
544
+ }
545
+
546
+ return `${output}…`;
547
+ };
548
+
549
+ type EgressRedactor<Requirements = never> = NonNullable<
550
+ CodeModeOptions<CodeModeNamespaces, Requirements>["redactEgress"]
551
+ >;
552
+
553
+ // ---------------------------------------------------------------------------
554
+ // Builder
555
+ // ---------------------------------------------------------------------------
556
+
557
+ const make = <
558
+ const Name extends string,
559
+ Namespaces extends CodeModeNamespaces,
560
+ RedactionRequirements = never,
561
+ >(
562
+ name: Name,
563
+ options: CodeModeOptions<Namespaces, RedactionRequirements>,
564
+ ): CodeModeDefinition<Name, Namespaces, RedactionRequirements> => {
565
+ const limits = options.limits ?? defaultLimits;
566
+ const maxEgressBytes = options.maxEgressBytes ?? defaultMaxEgressBytes;
567
+
568
+ // Fail closed on an invalid egress bound: NaN would make every size
569
+ // comparison false and Infinity would remove the bound entirely.
570
+ if (
571
+ !Number.isSafeInteger(maxEgressBytes) ||
572
+ maxEgressBytes < 256 ||
573
+ maxEgressBytes > 4 * 1024 * 1024
574
+ ) {
575
+ throw new Error(
576
+ `Code Mode maxEgressBytes must be an integer between 256 and ${4 * 1024 * 1024}; received ${String(maxEgressBytes)}`,
577
+ );
578
+ }
579
+
580
+ // Construction-time fail-closed validation (CAP-014).
581
+ const methods: Array<ResolvedMethod> = [];
582
+ const toolsByName = new Map<string, Tool.Any>();
583
+ const methodToTool = new Map<string, string>();
584
+
585
+ for (const [namespace, namespaceMethods] of Object.entries(options.tools)) {
586
+ if (Option.isNone(decodeIdentifier(namespace))) {
587
+ throw new Error(`Code Mode namespace ${namespace} is not a valid JavaScript identifier`);
588
+ }
589
+ const entries = Object.entries(namespaceMethods);
590
+
591
+ if (entries.length === 0) {
592
+ throw new Error(`Code Mode namespace ${namespace} declares no methods`);
593
+ }
594
+ for (const [method, tool] of entries) {
595
+ if (Option.isNone(decodeIdentifier(method))) {
596
+ throw new Error(
597
+ `Code Mode method ${namespace}.${method} is not a valid JavaScript identifier`,
598
+ );
599
+ }
600
+ const approval = tool.needsApproval;
601
+
602
+ if (approval !== undefined && approval !== false) {
603
+ throw new Error(
604
+ `Code Mode rejects Tool ${tool.name} (${namespace}.${method}): approval-requiring Tools cannot be invoked programmatically in the ephemeral slice`,
605
+ );
606
+ }
607
+ const existing = toolsByName.get(tool.name);
608
+
609
+ if (existing !== undefined && existing !== tool) {
610
+ throw new Error(
611
+ `Code Mode selected two different Tools named ${tool.name}; Tool names must identify one Tool`,
612
+ );
613
+ }
614
+ toolsByName.set(tool.name, tool);
615
+ methodToTool.set(`${namespace}.${method}`, tool.name);
616
+ methods.push({ namespace, method, tool });
617
+ }
618
+ }
619
+ if (methods.length === 0) {
620
+ throw new Error("Code Mode requires at least one allowlisted Tool");
621
+ }
622
+
623
+ // Declarations derive from the encoded Schemas and fail construction closed
624
+ // on anything the renderer cannot express.
625
+ const declarations = renderDeclarations(methods);
626
+
627
+ const methodsByPath = new Map(
628
+ methods.map((method) => [`${method.namespace}.${method.method}`, method]),
629
+ );
630
+
631
+ const describe = Effect.fn("CodeMode.describe")(function* (
632
+ selected: ReadonlyArray<string>,
633
+ options?: { readonly maxBytes?: number | undefined },
634
+ ) {
635
+ const paths = yield* Schema.decodeEffect(DescriptionMethods)(selected).pipe(
636
+ Effect.mapError(() =>
637
+ CodeModeDescriptionError.make({
638
+ reason: "invalid-selection",
639
+ message:
640
+ "Select between 1 and 64 unique namespace.method names, each at most 257 characters",
641
+ }),
642
+ ),
643
+ );
644
+
645
+ const maxBytes = yield* Schema.decodeEffect(DescriptionByteLimit)(
646
+ options?.maxBytes ?? 16 * 1024,
647
+ ).pipe(
648
+ Effect.mapError(() =>
649
+ CodeModeDescriptionError.make({
650
+ reason: "invalid-bound",
651
+ message: "The documentation byte limit must be an integer between 1 and 262144",
652
+ }),
653
+ ),
654
+ );
655
+
656
+ const selectedMethods: Array<ResolvedMethod> = [];
657
+
658
+ for (const path of paths) {
659
+ const method = methodsByPath.get(path);
660
+
661
+ if (method === undefined) {
662
+ return yield* CodeModeDescriptionError.make({
663
+ reason: "unknown-method",
664
+ message: "The selection contains a method outside this Code Mode allowlist",
665
+ });
666
+ }
667
+ selectedMethods.push(method);
668
+ }
669
+
670
+ const documentation = renderDeclarations(selectedMethods);
671
+
672
+ if (utf8ByteLength(documentation) > maxBytes) {
673
+ return yield* CodeModeDescriptionError.make({
674
+ reason: "limit-exceeded",
675
+ message: `The selected declarations exceed the ${maxBytes}-byte documentation limit; select fewer methods or raise the limit`,
676
+ });
677
+ }
678
+
679
+ return documentation;
680
+ });
681
+
682
+ const namespaces = [...new Set(methods.map((method) => method.namespace))].map((namespace) =>
683
+ CodeExecutionNamespace.make({
684
+ name: namespace,
685
+ methods: methods
686
+ .filter((method) => method.namespace === namespace)
687
+ .map((method) => method.method),
688
+ }),
689
+ );
690
+
691
+ const description = [
692
+ options.description,
693
+ "",
694
+ "The `code` argument must be one JavaScript async function expression; the sandbox invokes it exactly once with no arguments. It runs isolated with no ambient network, filesystem, environment, or secrets. Return one JSON value. `console.log` output is captured within a bounded budget and returned alongside the result.",
695
+ "Namespace methods return Promises. An expected Tool failure rejects with a JSON envelope carrying a stable `_tag`; catch it to branch. Use Promise.all for independent calls; the host bounds concurrency. Await every call you need. Writes may complete before a failure: inspect call outcomes and never blindly retry a program.",
696
+ ...(options.includeDeclarations === false
697
+ ? []
698
+ : ["", "Sandbox globals:", "```ts", declarations, "```"]),
699
+ ].join("\n");
700
+
701
+ const tool = Tool.make(name, {
702
+ description,
703
+ parameters: CodeModeParameters,
704
+ success: CodeModeSuccess,
705
+ failure: CodeModeFailure,
706
+ failureMode: "return",
707
+ })
708
+ .annotate(Tool.Readonly, false)
709
+ .annotate(ToolExecutionClassAnnotation, "uncertain")
710
+ .annotate(IncludesCatalogDocumentation, options.includeDeclarations !== false)
711
+ .annotate(
712
+ AdditionalToolCatalog,
713
+ Object.freeze(methods.map((method) => Object.freeze({ ...method }))),
714
+ )
715
+ .addDependency(ToolBroker) as CodeModeTool<Name>;
716
+
717
+ const outerToolkit = Toolkit.make(tool);
718
+
719
+ /**
720
+ * The nested namespace record collapses into one Toolkit keyed by exact
721
+ * Tool names. The assertion restores the name-keyed record type TypeScript
722
+ * cannot compute from `Map` iteration; construction above guarantees the
723
+ * name uniqueness the type states.
724
+ */
725
+ const selectedToolkit = Toolkit.make(...toolsByName.values()) as unknown as Toolkit.Toolkit<
726
+ CodeModeSelectedRecord<Namespaces>
727
+ >;
728
+
729
+ const executionRequest = (
730
+ code: string,
731
+ visibleNamespaces: ReadonlyArray<CodeExecutionNamespace>,
732
+ ): CodeExecutionRequest =>
733
+ CodeExecutionRequest.make({
734
+ language: "javascript",
735
+ source: code,
736
+ namespaces: visibleNamespaces,
737
+ network: NetworkDisabled.make({}),
738
+ limits,
739
+ });
740
+
741
+ const routeHostCall = (
742
+ pass: ToolBrokerPass,
743
+ hostCall: CodeHostCall,
744
+ visiblePaths: ReadonlySet<string> | undefined,
745
+ ): Effect.Effect<CodeHostCallResult> =>
746
+ Effect.gen(function* () {
747
+ const path = `${hostCall.namespace}.${hostCall.method}`;
748
+
749
+ const toolName =
750
+ visiblePaths === undefined || visiblePaths.has(path) ? methodToTool.get(path) : undefined;
751
+
752
+ if (toolName === undefined) {
753
+ return {
754
+ _tag: "CodeHostCallFailure",
755
+ error: {
756
+ _tag: "UnknownCodeModeMethod",
757
+ message: "The requested method is not available in this pass",
758
+ },
759
+ } as const;
760
+ }
761
+
762
+ const outcome: ProgrammaticCallOutcome = yield* pass.invoke({
763
+ toolName,
764
+ encodedArguments: hostCall.argument,
765
+ });
766
+
767
+ switch (outcome._tag) {
768
+ case "ProgrammaticCallSuccess": {
769
+ const value = decodeBrokerJson(outcome.encodedResult);
770
+
771
+ return Option.isSome(value)
772
+ ? ({ _tag: "CodeHostCallSuccess", value: value.value } as const)
773
+ : ({ _tag: "CodeHostCallFailure", error: brokerProtocolEnvelope } as const);
774
+ }
775
+ case "ProgrammaticCallFailure": {
776
+ const value = decodeBrokerJson(outcome.encodedResult);
777
+
778
+ return {
779
+ _tag: "CodeHostCallFailure",
780
+ error: Option.isSome(value) ? value.value : brokerProtocolEnvelope,
781
+ } as const;
782
+ }
783
+ case "ProgrammaticCallError": {
784
+ return {
785
+ _tag: "CodeHostCallFailure",
786
+ error: { _tag: outcome.errorTag, message: outcome.message },
787
+ } as const;
788
+ }
789
+ }
790
+ });
791
+
792
+ const build = Effect.gen(function* () {
793
+ const captured = yield* Effect.context<never>();
794
+ const redactionServices = yield* Effect.context<Exclude<RedactionRequirements, Scope.Scope>>();
795
+ const configuredRedactor = options.redactEgress;
796
+
797
+ const redact: EgressRedactor | undefined =
798
+ configuredRedactor === undefined
799
+ ? undefined
800
+ : (egress) =>
801
+ Effect.scoped(configuredRedactor(egress)).pipe(
802
+ // Merge invocation-local services before opening the redaction Scope.
803
+ // The inner Scope shadows any Scope retained in the construction context.
804
+ Effect.updateContext((current: Context.Context<never>) =>
805
+ Context.merge(current, redactionServices),
806
+ ),
807
+ );
808
+
809
+ const withHandler = yield* selectedToolkit;
810
+ const executor = yield* CodeExecutor;
811
+
812
+ const successEgress = (
813
+ execution: CodeExecutionResult,
814
+ ): Effect.Effect<CodeModeSuccess, CodeModeFailure> =>
815
+ Effect.gen(function* () {
816
+ let egress: { readonly result: Schema.Json; readonly logs: ReadonlyArray<string> } = {
817
+ result: execution.value,
818
+ logs: execution.logs,
819
+ };
820
+
821
+ if (redact !== undefined) {
822
+ egress = yield* redact(egress);
823
+ }
824
+ const resultBytes = encodedJsonByteLength(egress.result);
825
+
826
+ if (resultBytes === undefined || resultBytes > maxEgressBytes) {
827
+ return yield* CodeModeFailure.make({
828
+ errorTag: "CodeModeEgressExceeded",
829
+ message: `The program result of ${resultBytes ?? "unencodable"} bytes exceeds the ${maxEgressBytes}-byte model-visible egress budget; return a smaller value`,
830
+ logs: budgetedLogs(egress.logs, Math.max(0, maxEgressBytes - 256)),
831
+ });
832
+ }
833
+
834
+ return CodeModeSuccess.make({
835
+ result: egress.result,
836
+ logs: budgetedLogs(egress.logs, maxEgressBytes - resultBytes),
837
+ });
838
+ });
839
+
840
+ /**
841
+ * The failure half of the aggregate egress policy (CAP-016): the configured
842
+ * redaction pass covers failure logs and thrown values exactly like success
843
+ * egress — a program cannot leak by logging and then throwing — and the
844
+ * message itself is bounded by the budget, not only by its own schema cap.
845
+ */
846
+ const failureEgress = (
847
+ error: CodeExecutionError | ToolBrokerUnavailableError | ToolBrokerConfigurationError,
848
+ ): Effect.Effect<CodeModeFailure> =>
849
+ Effect.gen(function* () {
850
+ if (
851
+ error._tag === "ToolBrokerUnavailableError" ||
852
+ error._tag === "ToolBrokerConfigurationError"
853
+ ) {
854
+ return CodeModeFailure.make({
855
+ errorTag: error._tag,
856
+ message: truncateToUtf8Bytes(boundedMessage(error.message), maxEgressBytes),
857
+ logs: [],
858
+ });
859
+ }
860
+ let logs: ReadonlyArray<string> = "logs" in error ? error.logs : [];
861
+ let candidateThrown = error._tag === "CodeProgramFailedError" ? error.thrown : undefined;
862
+
863
+ if (redact !== undefined) {
864
+ const redacted = yield* redact({ result: candidateThrown ?? null, logs });
865
+
866
+ logs = redacted.logs;
867
+ candidateThrown = candidateThrown === undefined ? undefined : redacted.result;
868
+ }
869
+
870
+ const message = truncateToUtf8Bytes(
871
+ boundedMessage(executionFailureMessage(error)),
872
+ maxEgressBytes,
873
+ );
874
+
875
+ const messageBytes = utf8ByteLength(message);
876
+
877
+ // `thrown` is included only when it fits TOGETHER with the message inside
878
+ // the aggregate budget, and it reduces the log allowance only when it is
879
+ // actually included.
880
+ const candidateBytes =
881
+ candidateThrown === undefined ? undefined : encodedJsonByteLength(candidateThrown);
882
+
883
+ const includeThrown =
884
+ candidateThrown !== undefined &&
885
+ candidateBytes !== undefined &&
886
+ messageBytes + candidateBytes <= maxEgressBytes;
887
+
888
+ const remaining = Math.max(
889
+ 0,
890
+ maxEgressBytes - messageBytes - (includeThrown ? (candidateBytes ?? 0) : 0),
891
+ );
892
+
893
+ return CodeModeFailure.make({
894
+ errorTag: error._tag,
895
+ message,
896
+ logs: budgetedLogs(logs, remaining),
897
+ ...(includeThrown ? { thrown: candidateThrown } : {}),
898
+ });
899
+ });
900
+
901
+ const invoke = Effect.fn(`CodeMode.${name}`)(function* (parameters: { readonly code: string }) {
902
+ const broker = yield* ToolBroker;
903
+ // Resolve invocation authority before restoring captured construction services. A Layer
904
+ // built under an older Run must not restore that Run's catalogue or hidden method names.
905
+ const catalogue = yield* Effect.serviceOption(CurrentToolCatalog);
906
+
907
+ const visiblePaths = Option.isNone(catalogue)
908
+ ? undefined
909
+ : new Set(
910
+ catalogue.value.entries.flatMap((entry) =>
911
+ entry.kind === "code-mode" &&
912
+ entry.nativeToolName === name &&
913
+ methodsByPath.get(`${entry.namespace}.${entry.method}`)?.tool.name === entry.tool.name
914
+ ? [`${entry.namespace}.${entry.method}`]
915
+ : [],
916
+ ),
917
+ );
918
+
919
+ const visibleNamespaces =
920
+ visiblePaths === undefined
921
+ ? namespaces
922
+ : namespaces.flatMap((namespace) => {
923
+ const allowed = namespace.methods.filter((method) =>
924
+ visiblePaths.has(`${namespace.name}.${method}`),
925
+ );
926
+
927
+ return allowed.length === 0
928
+ ? []
929
+ : [CodeExecutionNamespace.make({ name: namespace.name, methods: allowed })];
930
+ });
931
+
932
+ let calls: ReadonlyArray<ProgrammaticCallRecord> = [];
933
+
934
+ const execution = Effect.gen(function* () {
935
+ const pass = yield* broker.openPass(withHandler, {
936
+ maxResultBytes: limits.maxHostCallResultBytes,
937
+ concurrency: limits.maxHostCallConcurrency ?? 4,
938
+ });
939
+
940
+ const host = CodeExecutionHost.of({
941
+ call: (hostCall) => routeHostCall(pass, hostCall, visiblePaths),
942
+ });
943
+
944
+ return yield* executor.execute(executionRequest(parameters.code, visibleNamespaces)).pipe(
945
+ Effect.provideService(CodeExecutionHost, host),
946
+ Effect.scoped,
947
+ Effect.onExit((exit) =>
948
+ Effect.gen(function* () {
949
+ calls = yield* pass.snapshot;
950
+ if (options.onPassExit !== undefined) {
951
+ yield* Effect.scoped(
952
+ options.onPassExit({
953
+ status: Exit.isSuccess(exit)
954
+ ? "completed"
955
+ : Cause.hasInterrupts(exit.cause)
956
+ ? "interrupted"
957
+ : Cause.hasDies(exit.cause)
958
+ ? "defect"
959
+ : "failed",
960
+ calls,
961
+ }),
962
+ ).pipe(Effect.provideContext(redactionServices));
963
+ }
964
+ }),
965
+ ),
966
+ );
967
+ }).pipe(
968
+ Effect.scoped,
969
+ // The live engine broker is re-provided innermost so a Layer built
970
+ // inside another Run can never shadow it; the captured construction
971
+ // context supplies the selected handlers' services (same idiom as
972
+ // Subagent.layer). TypeScript cannot reduce the deferred Exclude
973
+ // over the generic namespace record, so the same private-assertion
974
+ // contract as the engine's provideHookServices pins the identity
975
+ // that providing the captured Context leaves no requirements; it
976
+ // never bypasses validation.
977
+ Effect.provideService(ToolBroker, broker),
978
+ Effect.provideContext(captured),
979
+ ) as Effect.Effect<
980
+ CodeExecutionResult,
981
+ CodeExecutionError | ToolBrokerUnavailableError | ToolBrokerConfigurationError
982
+ >;
983
+
984
+ return yield* execution.pipe(
985
+ Effect.catch((error) => failureEgress(error).pipe(Effect.flatMap(Effect.fail))),
986
+ Effect.flatMap(successEgress),
987
+ Effect.mapError((failure) => {
988
+ if (calls.length === 0) return failure;
989
+
990
+ const complete = CodeModeFailure.make({
991
+ errorTag: failure.errorTag,
992
+ message: failure.message,
993
+ logs: failure.logs,
994
+ ...(failure.thrown === undefined ? {} : { thrown: failure.thrown }),
995
+ calls,
996
+ omittedCalls: 0,
997
+ });
998
+
999
+ if ((encodedJsonByteLength(complete) ?? Infinity) <= maxEgressBytes) return complete;
1000
+
1001
+ // Evidence takes priority over logs and thrown values. Never silently omit calls.
1002
+ const base = {
1003
+ errorTag: failure.errorTag,
1004
+ message: truncateToUtf8Bytes(failure.message, Math.min(256, maxEgressBytes / 4)),
1005
+ logs: [],
1006
+ };
1007
+
1008
+ const kept: Array<ProgrammaticCallRecord> = [];
1009
+
1010
+ for (const call of calls) {
1011
+ const candidate = CodeModeFailure.make({
1012
+ ...base,
1013
+ calls: [...kept, call],
1014
+ omittedCalls: calls.length - kept.length - 1,
1015
+ });
1016
+
1017
+ if ((encodedJsonByteLength(candidate) ?? Infinity) > maxEgressBytes) break;
1018
+ kept.push(call);
1019
+ }
1020
+
1021
+ return CodeModeFailure.make({
1022
+ ...base,
1023
+ calls: kept,
1024
+ omittedCalls: calls.length - kept.length,
1025
+ });
1026
+ }),
1027
+ );
1028
+ });
1029
+
1030
+ return { [name]: invoke } as unknown as Toolkit.HandlersFrom<CodeModeTools<Name>>;
1031
+ });
1032
+
1033
+ /**
1034
+ * TypeScript cannot unify the two spellings of the singleton Tool record
1035
+ * (`CodeModeTools<Name>` versus the toolkit's name-remapped form) over a
1036
+ * generic `Name`, nor reduce the deferred `Exclude` when `toLayer`
1037
+ * subtracts what `build` consumed; the assertions pin the layer to its
1038
+ * documented requirement surface and never bypass validation.
1039
+ */
1040
+ const handlers = outerToolkit.toLayer(
1041
+ build as unknown as Effect.Effect<
1042
+ Toolkit.HandlersFrom<Toolkit.ToolsByName<readonly [CodeModeTool<Name>]>>,
1043
+ never,
1044
+ | CodeExecutor
1045
+ | Tool.HandlersFor<CodeModeSelectedRecord<Namespaces>>
1046
+ | Exclude<RedactionRequirements, Scope.Scope>
1047
+ >,
1048
+ ) as unknown as Layer.Layer<
1049
+ Tool.HandlersFor<CodeModeTools<Name>>,
1050
+ never,
1051
+ CodeModeLayerRequirements<Namespaces, RedactionRequirements>
1052
+ >;
1053
+
1054
+ return Object.freeze({
1055
+ name,
1056
+ description,
1057
+ declarations,
1058
+ describe,
1059
+ namespaces,
1060
+ limits,
1061
+ maxEgressBytes,
1062
+ tool,
1063
+ handlers,
1064
+ });
1065
+ };
1066
+
1067
+ /**
1068
+ * Fail-closed JSON boundary for broker outcomes: hostile values can throw
1069
+ * from trap getters during decode, and a value outside the JSON surface must
1070
+ * become a typed failure envelope — never a fabricated success.
1071
+ */
1072
+ const decodeBrokerJson = (value: unknown): Option.Option<Schema.Json> => {
1073
+ try {
1074
+ return Schema.decodeUnknownOption(Schema.Json)(value);
1075
+ } catch {
1076
+ return Option.none();
1077
+ }
1078
+ };
1079
+
1080
+ const brokerProtocolEnvelope: Schema.Json = {
1081
+ _tag: "CodeModeProtocolError",
1082
+ message: "The broker returned a value outside the JSON surface",
1083
+ };
1084
+
1085
+ // The engine annotation is imported under a local alias to keep the builder
1086
+ // readable next to Effect AI's own `Tool.Readonly` annotation.
1087
+ import { ToolExecutionClass as ToolExecutionClassAnnotation } from "../engine/DurableStep.ts";
1088
+
1089
+ /** Code Mode builder namespace (capability spec §9.1). */
1090
+ export { make };