@openai/agents-core 0.8.5 → 0.9.0

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 (462) hide show
  1. package/dist/agentToolRunConfig.js +3 -0
  2. package/dist/agentToolRunConfig.js.map +1 -1
  3. package/dist/agentToolRunConfig.mjs +3 -0
  4. package/dist/agentToolRunConfig.mjs.map +1 -1
  5. package/dist/errors.d.ts +10 -0
  6. package/dist/errors.js +15 -1
  7. package/dist/errors.js.map +1 -1
  8. package/dist/errors.mjs +13 -0
  9. package/dist/errors.mjs.map +1 -1
  10. package/dist/handoff.js +1 -1
  11. package/dist/handoff.js.map +1 -1
  12. package/dist/handoff.mjs +1 -1
  13. package/dist/handoff.mjs.map +1 -1
  14. package/dist/index.d.ts +5 -4
  15. package/dist/index.js +6 -2
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +3 -2
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/items.d.ts +13 -0
  20. package/dist/items.js +15 -0
  21. package/dist/items.js.map +1 -1
  22. package/dist/items.mjs +15 -0
  23. package/dist/items.mjs.map +1 -1
  24. package/dist/memory/historyMutations.d.ts +6 -0
  25. package/dist/memory/historyMutations.js +32 -0
  26. package/dist/memory/historyMutations.js.map +1 -0
  27. package/dist/memory/historyMutations.mjs +29 -0
  28. package/dist/memory/historyMutations.mjs.map +1 -0
  29. package/dist/memory/memorySession.d.ts +3 -2
  30. package/dist/memory/memorySession.js +7 -0
  31. package/dist/memory/memorySession.js.map +1 -1
  32. package/dist/memory/memorySession.mjs +7 -0
  33. package/dist/memory/memorySession.mjs.map +1 -1
  34. package/dist/memory/session.d.ts +15 -0
  35. package/dist/memory/session.js +6 -0
  36. package/dist/memory/session.js.map +1 -1
  37. package/dist/memory/session.mjs +5 -0
  38. package/dist/memory/session.mjs.map +1 -1
  39. package/dist/metadata.js +2 -2
  40. package/dist/metadata.mjs +2 -2
  41. package/dist/model.d.ts +21 -0
  42. package/dist/run.d.ts +7 -1
  43. package/dist/run.js +116 -57
  44. package/dist/run.js.map +1 -1
  45. package/dist/run.mjs +117 -58
  46. package/dist/run.mjs.map +1 -1
  47. package/dist/runState.d.ts +83 -1
  48. package/dist/runState.js +96 -11
  49. package/dist/runState.js.map +1 -1
  50. package/dist/runState.mjs +95 -11
  51. package/dist/runState.mjs.map +1 -1
  52. package/dist/runner/errorHandlers.d.ts +13 -4
  53. package/dist/runner/errorHandlers.js +22 -4
  54. package/dist/runner/errorHandlers.js.map +1 -1
  55. package/dist/runner/errorHandlers.mjs +21 -4
  56. package/dist/runner/errorHandlers.mjs.map +1 -1
  57. package/dist/runner/items.js +11 -1
  58. package/dist/runner/items.js.map +1 -1
  59. package/dist/runner/items.mjs +11 -1
  60. package/dist/runner/items.mjs.map +1 -1
  61. package/dist/runner/modelPreparation.d.ts +1 -1
  62. package/dist/runner/modelPreparation.js +7 -7
  63. package/dist/runner/modelPreparation.js.map +1 -1
  64. package/dist/runner/modelPreparation.mjs +7 -7
  65. package/dist/runner/modelPreparation.mjs.map +1 -1
  66. package/dist/runner/runLoop.d.ts +2 -1
  67. package/dist/runner/runLoop.js +2 -2
  68. package/dist/runner/runLoop.js.map +1 -1
  69. package/dist/runner/runLoop.mjs +2 -2
  70. package/dist/runner/runLoop.mjs.map +1 -1
  71. package/dist/runner/sandbox.d.ts +33 -0
  72. package/dist/runner/sandbox.js +92 -0
  73. package/dist/runner/sandbox.js.map +1 -0
  74. package/dist/runner/sandbox.mjs +83 -0
  75. package/dist/runner/sandbox.mjs.map +1 -0
  76. package/dist/runner/toolExecution.js +25 -13
  77. package/dist/runner/toolExecution.js.map +1 -1
  78. package/dist/runner/toolExecution.mjs +25 -13
  79. package/dist/runner/toolExecution.mjs.map +1 -1
  80. package/dist/runner/tracing.js +1 -0
  81. package/dist/runner/tracing.js.map +1 -1
  82. package/dist/runner/tracing.mjs +1 -0
  83. package/dist/runner/tracing.mjs.map +1 -1
  84. package/dist/runner/turnPreparation.d.ts +2 -4
  85. package/dist/runner/turnPreparation.js +7 -3
  86. package/dist/runner/turnPreparation.js.map +1 -1
  87. package/dist/runner/turnPreparation.mjs +7 -3
  88. package/dist/runner/turnPreparation.mjs.map +1 -1
  89. package/dist/runner/turnResolution.js +158 -31
  90. package/dist/runner/turnResolution.js.map +1 -1
  91. package/dist/runner/turnResolution.mjs +160 -33
  92. package/dist/runner/turnResolution.mjs.map +1 -1
  93. package/dist/runner/types.d.ts +8 -8
  94. package/dist/sandbox/agent.d.ts +24 -0
  95. package/dist/sandbox/agent.js +68 -0
  96. package/dist/sandbox/agent.js.map +1 -0
  97. package/dist/sandbox/agent.mjs +64 -0
  98. package/dist/sandbox/agent.mjs.map +1 -0
  99. package/dist/sandbox/brand.d.ts +1 -0
  100. package/dist/sandbox/brand.js +5 -0
  101. package/dist/sandbox/brand.js.map +1 -0
  102. package/dist/sandbox/brand.mjs +2 -0
  103. package/dist/sandbox/brand.mjs.map +1 -0
  104. package/dist/sandbox/capabilities/base.d.ts +25 -0
  105. package/dist/sandbox/capabilities/base.js +89 -0
  106. package/dist/sandbox/capabilities/base.js.map +1 -0
  107. package/dist/sandbox/capabilities/base.mjs +84 -0
  108. package/dist/sandbox/capabilities/base.mjs.map +1 -0
  109. package/dist/sandbox/capabilities/compaction.d.ts +33 -0
  110. package/dist/sandbox/capabilities/compaction.js +172 -0
  111. package/dist/sandbox/capabilities/compaction.js.map +1 -0
  112. package/dist/sandbox/capabilities/compaction.mjs +164 -0
  113. package/dist/sandbox/capabilities/compaction.mjs.map +1 -0
  114. package/dist/sandbox/capabilities/filesystem.d.ts +14 -0
  115. package/dist/sandbox/capabilities/filesystem.js +447 -0
  116. package/dist/sandbox/capabilities/filesystem.js.map +1 -0
  117. package/dist/sandbox/capabilities/filesystem.mjs +444 -0
  118. package/dist/sandbox/capabilities/filesystem.mjs.map +1 -0
  119. package/dist/sandbox/capabilities/index.d.ts +19 -0
  120. package/dist/sandbox/capabilities/index.js +31 -0
  121. package/dist/sandbox/capabilities/index.js.map +1 -0
  122. package/dist/sandbox/capabilities/index.mjs +17 -0
  123. package/dist/sandbox/capabilities/index.mjs.map +1 -0
  124. package/dist/sandbox/capabilities/memory.d.ts +52 -0
  125. package/dist/sandbox/capabilities/memory.js +290 -0
  126. package/dist/sandbox/capabilities/memory.js.map +1 -0
  127. package/dist/sandbox/capabilities/memory.mjs +286 -0
  128. package/dist/sandbox/capabilities/memory.mjs.map +1 -0
  129. package/dist/sandbox/capabilities/shell.d.ts +15 -0
  130. package/dist/sandbox/capabilities/shell.js +130 -0
  131. package/dist/sandbox/capabilities/shell.js.map +1 -0
  132. package/dist/sandbox/capabilities/shell.mjs +127 -0
  133. package/dist/sandbox/capabilities/shell.mjs.map +1 -0
  134. package/dist/sandbox/capabilities/skills.d.ts +47 -0
  135. package/dist/sandbox/capabilities/skills.js +453 -0
  136. package/dist/sandbox/capabilities/skills.js.map +1 -0
  137. package/dist/sandbox/capabilities/skills.mjs +449 -0
  138. package/dist/sandbox/capabilities/skills.mjs.map +1 -0
  139. package/dist/sandbox/capabilities/transport.d.ts +3 -0
  140. package/dist/sandbox/capabilities/transport.js +33 -0
  141. package/dist/sandbox/capabilities/transport.js.map +1 -0
  142. package/dist/sandbox/capabilities/transport.mjs +28 -0
  143. package/dist/sandbox/capabilities/transport.mjs.map +1 -0
  144. package/dist/sandbox/client.d.ts +53 -0
  145. package/dist/sandbox/client.js +34 -0
  146. package/dist/sandbox/client.js.map +1 -0
  147. package/dist/sandbox/client.mjs +31 -0
  148. package/dist/sandbox/client.mjs.map +1 -0
  149. package/dist/sandbox/entries/factories.d.ts +17 -0
  150. package/dist/sandbox/entries/factories.js +112 -0
  151. package/dist/sandbox/entries/factories.js.map +1 -0
  152. package/dist/sandbox/entries/factories.mjs +94 -0
  153. package/dist/sandbox/entries/factories.mjs.map +1 -0
  154. package/dist/sandbox/entries/guards.d.ts +5 -0
  155. package/dist/sandbox/entries/guards.js +19 -0
  156. package/dist/sandbox/entries/guards.js.map +1 -0
  157. package/dist/sandbox/entries/guards.mjs +13 -0
  158. package/dist/sandbox/entries/guards.mjs.map +1 -0
  159. package/dist/sandbox/entries/index.d.ts +3 -0
  160. package/dist/sandbox/entries/index.js +26 -0
  161. package/dist/sandbox/entries/index.js.map +1 -0
  162. package/dist/sandbox/entries/index.mjs +3 -0
  163. package/dist/sandbox/entries/index.mjs.map +1 -0
  164. package/dist/sandbox/entries/types.d.ts +177 -0
  165. package/dist/sandbox/entries/types.js +3 -0
  166. package/dist/sandbox/entries/types.js.map +1 -0
  167. package/dist/sandbox/entries/types.mjs +2 -0
  168. package/dist/sandbox/entries/types.mjs.map +1 -0
  169. package/dist/sandbox/errors.d.ts +151 -0
  170. package/dist/sandbox/errors.js +303 -0
  171. package/dist/sandbox/errors.js.map +1 -0
  172. package/dist/sandbox/errors.mjs +251 -0
  173. package/dist/sandbox/errors.mjs.map +1 -0
  174. package/dist/sandbox/events.d.ts +51 -0
  175. package/dist/sandbox/events.js +104 -0
  176. package/dist/sandbox/events.js.map +1 -0
  177. package/dist/sandbox/events.mjs +95 -0
  178. package/dist/sandbox/events.mjs.map +1 -0
  179. package/dist/sandbox/index.d.ts +14 -0
  180. package/dist/sandbox/index.js +31 -0
  181. package/dist/sandbox/index.js.map +1 -0
  182. package/dist/sandbox/index.mjs +15 -0
  183. package/dist/sandbox/index.mjs.map +1 -0
  184. package/dist/sandbox/internal.d.ts +7 -0
  185. package/dist/sandbox/internal.js +46 -0
  186. package/dist/sandbox/internal.js.map +1 -0
  187. package/dist/sandbox/internal.mjs +8 -0
  188. package/dist/sandbox/internal.mjs.map +1 -0
  189. package/dist/sandbox/local.d.ts +3 -0
  190. package/dist/sandbox/local.js +20 -0
  191. package/dist/sandbox/local.js.map +1 -0
  192. package/dist/sandbox/local.mjs +4 -0
  193. package/dist/sandbox/local.mjs.map +1 -0
  194. package/dist/sandbox/localSkills.d.ts +13 -0
  195. package/dist/sandbox/localSkills.js +62 -0
  196. package/dist/sandbox/localSkills.js.map +1 -0
  197. package/dist/sandbox/localSkills.mjs +59 -0
  198. package/dist/sandbox/localSkills.mjs.map +1 -0
  199. package/dist/sandbox/manifest.d.ts +86 -0
  200. package/dist/sandbox/manifest.js +553 -0
  201. package/dist/sandbox/manifest.js.map +1 -0
  202. package/dist/sandbox/manifest.mjs +545 -0
  203. package/dist/sandbox/manifest.mjs.map +1 -0
  204. package/dist/sandbox/memory/generation.d.ts +56 -0
  205. package/dist/sandbox/memory/generation.js +426 -0
  206. package/dist/sandbox/memory/generation.js.map +1 -0
  207. package/dist/sandbox/memory/generation.mjs +385 -0
  208. package/dist/sandbox/memory/generation.mjs.map +1 -0
  209. package/dist/sandbox/memory/prompts.d.ts +16 -0
  210. package/dist/sandbox/memory/prompts.js +1685 -0
  211. package/dist/sandbox/memory/prompts.js.map +1 -0
  212. package/dist/sandbox/memory/prompts.mjs +1679 -0
  213. package/dist/sandbox/memory/prompts.mjs.map +1 -0
  214. package/dist/sandbox/memory/rollouts.d.ts +33 -0
  215. package/dist/sandbox/memory/rollouts.js +228 -0
  216. package/dist/sandbox/memory/rollouts.js.map +1 -0
  217. package/dist/sandbox/memory/rollouts.mjs +221 -0
  218. package/dist/sandbox/memory/rollouts.mjs.map +1 -0
  219. package/dist/sandbox/memory/storage.d.ts +70 -0
  220. package/dist/sandbox/memory/storage.js +543 -0
  221. package/dist/sandbox/memory/storage.js.map +1 -0
  222. package/dist/sandbox/memory/storage.mjs +537 -0
  223. package/dist/sandbox/memory/storage.mjs.map +1 -0
  224. package/dist/sandbox/pathGrants.d.ts +11 -0
  225. package/dist/sandbox/pathGrants.js +28 -0
  226. package/dist/sandbox/pathGrants.js.map +1 -0
  227. package/dist/sandbox/pathGrants.mjs +25 -0
  228. package/dist/sandbox/pathGrants.mjs.map +1 -0
  229. package/dist/sandbox/permissions.d.ts +29 -0
  230. package/dist/sandbox/permissions.js +140 -0
  231. package/dist/sandbox/permissions.js.map +1 -0
  232. package/dist/sandbox/permissions.mjs +134 -0
  233. package/dist/sandbox/permissions.mjs.map +1 -0
  234. package/dist/sandbox/runtime/agentKeys.d.ts +7 -0
  235. package/dist/sandbox/runtime/agentKeys.js +76 -0
  236. package/dist/sandbox/runtime/agentKeys.js.map +1 -0
  237. package/dist/sandbox/runtime/agentKeys.mjs +69 -0
  238. package/dist/sandbox/runtime/agentKeys.mjs.map +1 -0
  239. package/dist/sandbox/runtime/agentPreparation.d.ts +20 -0
  240. package/dist/sandbox/runtime/agentPreparation.js +178 -0
  241. package/dist/sandbox/runtime/agentPreparation.js.map +1 -0
  242. package/dist/sandbox/runtime/agentPreparation.mjs +172 -0
  243. package/dist/sandbox/runtime/agentPreparation.mjs.map +1 -0
  244. package/dist/sandbox/runtime/index.d.ts +5 -0
  245. package/dist/sandbox/runtime/index.js +22 -0
  246. package/dist/sandbox/runtime/index.js.map +1 -0
  247. package/dist/sandbox/runtime/index.mjs +6 -0
  248. package/dist/sandbox/runtime/index.mjs.map +1 -0
  249. package/dist/sandbox/runtime/livePreservedSessions.d.ts +25 -0
  250. package/dist/sandbox/runtime/livePreservedSessions.js +58 -0
  251. package/dist/sandbox/runtime/livePreservedSessions.js.map +1 -0
  252. package/dist/sandbox/runtime/livePreservedSessions.mjs +51 -0
  253. package/dist/sandbox/runtime/livePreservedSessions.mjs.map +1 -0
  254. package/dist/sandbox/runtime/manager.d.ts +68 -0
  255. package/dist/sandbox/runtime/manager.js +704 -0
  256. package/dist/sandbox/runtime/manager.js.map +1 -0
  257. package/dist/sandbox/runtime/manager.mjs +697 -0
  258. package/dist/sandbox/runtime/manager.mjs.map +1 -0
  259. package/dist/sandbox/runtime/prompts.d.ts +6 -0
  260. package/dist/sandbox/runtime/prompts.js +108 -0
  261. package/dist/sandbox/runtime/prompts.js.map +1 -0
  262. package/dist/sandbox/runtime/prompts.mjs +101 -0
  263. package/dist/sandbox/runtime/prompts.mjs.map +1 -0
  264. package/dist/sandbox/runtime/providedSessionManifest.d.ts +3 -0
  265. package/dist/sandbox/runtime/providedSessionManifest.js +175 -0
  266. package/dist/sandbox/runtime/providedSessionManifest.js.map +1 -0
  267. package/dist/sandbox/runtime/providedSessionManifest.mjs +172 -0
  268. package/dist/sandbox/runtime/providedSessionManifest.mjs.map +1 -0
  269. package/dist/sandbox/runtime/runAsManifest.d.ts +4 -0
  270. package/dist/sandbox/runtime/runAsManifest.js +40 -0
  271. package/dist/sandbox/runtime/runAsManifest.js.map +1 -0
  272. package/dist/sandbox/runtime/runAsManifest.mjs +36 -0
  273. package/dist/sandbox/runtime/runAsManifest.mjs.map +1 -0
  274. package/dist/sandbox/runtime/sessionLifecycle.d.ts +6 -0
  275. package/dist/sandbox/runtime/sessionLifecycle.js +222 -0
  276. package/dist/sandbox/runtime/sessionLifecycle.js.map +1 -0
  277. package/dist/sandbox/runtime/sessionLifecycle.mjs +215 -0
  278. package/dist/sandbox/runtime/sessionLifecycle.mjs.map +1 -0
  279. package/dist/sandbox/runtime/sessionSerialization.d.ts +12 -0
  280. package/dist/sandbox/runtime/sessionSerialization.js +74 -0
  281. package/dist/sandbox/runtime/sessionSerialization.js.map +1 -0
  282. package/dist/sandbox/runtime/sessionSerialization.mjs +71 -0
  283. package/dist/sandbox/runtime/sessionSerialization.mjs.map +1 -0
  284. package/dist/sandbox/runtime/sessionState.d.ts +26 -0
  285. package/dist/sandbox/runtime/sessionState.js +113 -0
  286. package/dist/sandbox/runtime/sessionState.js.map +1 -0
  287. package/dist/sandbox/runtime/sessionState.mjs +104 -0
  288. package/dist/sandbox/runtime/sessionState.mjs.map +1 -0
  289. package/dist/sandbox/runtime/spans.d.ts +1 -0
  290. package/dist/sandbox/runtime/spans.js +51 -0
  291. package/dist/sandbox/runtime/spans.js.map +1 -0
  292. package/dist/sandbox/runtime/spans.mjs +48 -0
  293. package/dist/sandbox/runtime/spans.mjs.map +1 -0
  294. package/dist/sandbox/runtime/toolRehydration.d.ts +34 -0
  295. package/dist/sandbox/runtime/toolRehydration.js +207 -0
  296. package/dist/sandbox/runtime/toolRehydration.js.map +1 -0
  297. package/dist/sandbox/runtime/toolRehydration.mjs +200 -0
  298. package/dist/sandbox/runtime/toolRehydration.mjs.map +1 -0
  299. package/dist/sandbox/sandboxes/docker.d.ts +75 -0
  300. package/dist/sandbox/sandboxes/docker.js +2015 -0
  301. package/dist/sandbox/sandboxes/docker.js.map +1 -0
  302. package/dist/sandbox/sandboxes/docker.mjs +2010 -0
  303. package/dist/sandbox/sandboxes/docker.mjs.map +1 -0
  304. package/dist/sandbox/sandboxes/index.d.ts +3 -0
  305. package/dist/sandbox/sandboxes/index.js +20 -0
  306. package/dist/sandbox/sandboxes/index.js.map +1 -0
  307. package/dist/sandbox/sandboxes/index.mjs +4 -0
  308. package/dist/sandbox/sandboxes/index.mjs.map +1 -0
  309. package/dist/sandbox/sandboxes/shared/localSnapshotPaths.d.ts +1 -0
  310. package/dist/sandbox/sandboxes/shared/localSnapshotPaths.js +22 -0
  311. package/dist/sandbox/sandboxes/shared/localSnapshotPaths.js.map +1 -0
  312. package/dist/sandbox/sandboxes/shared/localSnapshotPaths.mjs +19 -0
  313. package/dist/sandbox/sandboxes/shared/localSnapshotPaths.mjs.map +1 -0
  314. package/dist/sandbox/sandboxes/shared/localSnapshots.d.ts +34 -0
  315. package/dist/sandbox/sandboxes/shared/localSnapshots.js +525 -0
  316. package/dist/sandbox/sandboxes/shared/localSnapshots.js.map +1 -0
  317. package/dist/sandbox/sandboxes/shared/localSnapshots.mjs +508 -0
  318. package/dist/sandbox/sandboxes/shared/localSnapshots.mjs.map +1 -0
  319. package/dist/sandbox/sandboxes/shared/localWorkspace.d.ts +27 -0
  320. package/dist/sandbox/sandboxes/shared/localWorkspace.js +693 -0
  321. package/dist/sandbox/sandboxes/shared/localWorkspace.js.map +1 -0
  322. package/dist/sandbox/sandboxes/shared/localWorkspace.mjs +684 -0
  323. package/dist/sandbox/sandboxes/shared/localWorkspace.mjs.map +1 -0
  324. package/dist/sandbox/sandboxes/shared/manifestPersistence.d.ts +15 -0
  325. package/dist/sandbox/sandboxes/shared/manifestPersistence.js +191 -0
  326. package/dist/sandbox/sandboxes/shared/manifestPersistence.js.map +1 -0
  327. package/dist/sandbox/sandboxes/shared/manifestPersistence.mjs +182 -0
  328. package/dist/sandbox/sandboxes/shared/manifestPersistence.mjs.map +1 -0
  329. package/dist/sandbox/sandboxes/shared/pty.d.ts +9 -0
  330. package/dist/sandbox/sandboxes/shared/pty.js +151 -0
  331. package/dist/sandbox/sandboxes/shared/pty.js.map +1 -0
  332. package/dist/sandbox/sandboxes/shared/pty.mjs +148 -0
  333. package/dist/sandbox/sandboxes/shared/pty.mjs.map +1 -0
  334. package/dist/sandbox/sandboxes/shared/runProcess.d.ts +16 -0
  335. package/dist/sandbox/sandboxes/shared/runProcess.js +90 -0
  336. package/dist/sandbox/sandboxes/shared/runProcess.js.map +1 -0
  337. package/dist/sandbox/sandboxes/shared/runProcess.mjs +86 -0
  338. package/dist/sandbox/sandboxes/shared/runProcess.mjs.map +1 -0
  339. package/dist/sandbox/sandboxes/shared/sessionStateValues.d.ts +18 -0
  340. package/dist/sandbox/sandboxes/shared/sessionStateValues.js +40 -0
  341. package/dist/sandbox/sandboxes/shared/sessionStateValues.js.map +1 -0
  342. package/dist/sandbox/sandboxes/shared/sessionStateValues.mjs +35 -0
  343. package/dist/sandbox/sandboxes/shared/sessionStateValues.mjs.map +1 -0
  344. package/dist/sandbox/sandboxes/shared/shellCommand.d.ts +17 -0
  345. package/dist/sandbox/sandboxes/shared/shellCommand.js +38 -0
  346. package/dist/sandbox/sandboxes/shared/shellCommand.js.map +1 -0
  347. package/dist/sandbox/sandboxes/shared/shellCommand.mjs +34 -0
  348. package/dist/sandbox/sandboxes/shared/shellCommand.mjs.map +1 -0
  349. package/dist/sandbox/sandboxes/types.d.ts +11 -0
  350. package/dist/sandbox/sandboxes/types.js +3 -0
  351. package/dist/sandbox/sandboxes/types.js.map +1 -0
  352. package/dist/sandbox/sandboxes/types.mjs +2 -0
  353. package/dist/sandbox/sandboxes/types.mjs.map +1 -0
  354. package/dist/sandbox/sandboxes/unixLocal.d.ts +95 -0
  355. package/dist/sandbox/sandboxes/unixLocal.js +863 -0
  356. package/dist/sandbox/sandboxes/unixLocal.js.map +1 -0
  357. package/dist/sandbox/sandboxes/unixLocal.mjs +858 -0
  358. package/dist/sandbox/sandboxes/unixLocal.mjs.map +1 -0
  359. package/dist/sandbox/session.d.ts +123 -0
  360. package/dist/sandbox/session.js +58 -0
  361. package/dist/sandbox/session.js.map +1 -0
  362. package/dist/sandbox/session.mjs +50 -0
  363. package/dist/sandbox/session.mjs.map +1 -0
  364. package/dist/sandbox/shared/compare.d.ts +2 -0
  365. package/dist/sandbox/shared/compare.js +13 -0
  366. package/dist/sandbox/shared/compare.js.map +1 -0
  367. package/dist/sandbox/shared/compare.mjs +9 -0
  368. package/dist/sandbox/shared/compare.mjs.map +1 -0
  369. package/dist/sandbox/shared/environment.d.ts +14 -0
  370. package/dist/sandbox/shared/environment.js +69 -0
  371. package/dist/sandbox/shared/environment.js.map +1 -0
  372. package/dist/sandbox/shared/environment.mjs +59 -0
  373. package/dist/sandbox/shared/environment.mjs.map +1 -0
  374. package/dist/sandbox/shared/hostPath.d.ts +4 -0
  375. package/dist/sandbox/shared/hostPath.js +22 -0
  376. package/dist/sandbox/shared/hostPath.js.map +1 -0
  377. package/dist/sandbox/shared/hostPath.mjs +16 -0
  378. package/dist/sandbox/shared/hostPath.mjs.map +1 -0
  379. package/dist/sandbox/shared/manifestCollections.d.ts +12 -0
  380. package/dist/sandbox/shared/manifestCollections.js +40 -0
  381. package/dist/sandbox/shared/manifestCollections.js.map +1 -0
  382. package/dist/sandbox/shared/manifestCollections.mjs +34 -0
  383. package/dist/sandbox/shared/manifestCollections.mjs.map +1 -0
  384. package/dist/sandbox/shared/media.d.ts +6 -0
  385. package/dist/sandbox/shared/media.js +126 -0
  386. package/dist/sandbox/shared/media.js.map +1 -0
  387. package/dist/sandbox/shared/media.mjs +119 -0
  388. package/dist/sandbox/shared/media.mjs.map +1 -0
  389. package/dist/sandbox/shared/output.d.ts +12 -0
  390. package/dist/sandbox/shared/output.js +108 -0
  391. package/dist/sandbox/shared/output.js.map +1 -0
  392. package/dist/sandbox/shared/output.mjs +103 -0
  393. package/dist/sandbox/shared/output.mjs.map +1 -0
  394. package/dist/sandbox/shared/posixPath.d.ts +7 -0
  395. package/dist/sandbox/shared/posixPath.js +90 -0
  396. package/dist/sandbox/shared/posixPath.js.map +1 -0
  397. package/dist/sandbox/shared/posixPath.mjs +81 -0
  398. package/dist/sandbox/shared/posixPath.mjs.map +1 -0
  399. package/dist/sandbox/shared/remoteMountCommandAllowlist.d.ts +3 -0
  400. package/dist/sandbox/shared/remoteMountCommandAllowlist.js +33 -0
  401. package/dist/sandbox/shared/remoteMountCommandAllowlist.js.map +1 -0
  402. package/dist/sandbox/shared/remoteMountCommandAllowlist.mjs +28 -0
  403. package/dist/sandbox/shared/remoteMountCommandAllowlist.mjs.map +1 -0
  404. package/dist/sandbox/shared/shell.d.ts +1 -0
  405. package/dist/sandbox/shared/shell.js +7 -0
  406. package/dist/sandbox/shared/shell.js.map +1 -0
  407. package/dist/sandbox/shared/shell.mjs +4 -0
  408. package/dist/sandbox/shared/shell.mjs.map +1 -0
  409. package/dist/sandbox/shared/stableJson.d.ts +12 -0
  410. package/dist/sandbox/shared/stableJson.js +40 -0
  411. package/dist/sandbox/shared/stableJson.js.map +1 -0
  412. package/dist/sandbox/shared/stableJson.mjs +35 -0
  413. package/dist/sandbox/shared/stableJson.mjs.map +1 -0
  414. package/dist/sandbox/shared/typeGuards.d.ts +6 -0
  415. package/dist/sandbox/shared/typeGuards.js +34 -0
  416. package/dist/sandbox/shared/typeGuards.js.map +1 -0
  417. package/dist/sandbox/shared/typeGuards.mjs +26 -0
  418. package/dist/sandbox/shared/typeGuards.mjs.map +1 -0
  419. package/dist/sandbox/snapshot.d.ts +60 -0
  420. package/dist/sandbox/snapshot.js +45 -0
  421. package/dist/sandbox/snapshot.js.map +1 -0
  422. package/dist/sandbox/snapshot.mjs +39 -0
  423. package/dist/sandbox/snapshot.mjs.map +1 -0
  424. package/dist/sandbox/users.d.ts +11 -0
  425. package/dist/sandbox/users.js +31 -0
  426. package/dist/sandbox/users.js.map +1 -0
  427. package/dist/sandbox/users.mjs +26 -0
  428. package/dist/sandbox/users.mjs.map +1 -0
  429. package/dist/sandbox/workspacePaths.d.ts +20 -0
  430. package/dist/sandbox/workspacePaths.js +73 -0
  431. package/dist/sandbox/workspacePaths.js.map +1 -0
  432. package/dist/sandbox/workspacePaths.mjs +69 -0
  433. package/dist/sandbox/workspacePaths.mjs.map +1 -0
  434. package/dist/tool.js +1 -1
  435. package/dist/tool.js.map +1 -1
  436. package/dist/tool.mjs +1 -1
  437. package/dist/tool.mjs.map +1 -1
  438. package/dist/types/protocol.d.ts +8 -0
  439. package/dist/types/protocol.js +1 -0
  440. package/dist/types/protocol.js.map +1 -1
  441. package/dist/types/protocol.mjs +1 -0
  442. package/dist/types/protocol.mjs.map +1 -1
  443. package/dist/utils/messages.d.ts +6 -0
  444. package/dist/utils/messages.js +21 -0
  445. package/dist/utils/messages.js.map +1 -1
  446. package/dist/utils/messages.mjs +20 -0
  447. package/dist/utils/messages.mjs.map +1 -1
  448. package/dist/utils/strictToolSchema.d.ts +4 -0
  449. package/dist/utils/strictToolSchema.js +358 -0
  450. package/dist/utils/strictToolSchema.js.map +1 -0
  451. package/dist/utils/strictToolSchema.mjs +353 -0
  452. package/dist/utils/strictToolSchema.mjs.map +1 -0
  453. package/dist/utils/tools.d.ts +3 -1
  454. package/dist/utils/tools.js +18 -7
  455. package/dist/utils/tools.js.map +1 -1
  456. package/dist/utils/tools.mjs +18 -7
  457. package/dist/utils/tools.mjs.map +1 -1
  458. package/dist/utils/zodJsonSchemaCompat.js +18 -16
  459. package/dist/utils/zodJsonSchemaCompat.js.map +1 -1
  460. package/dist/utils/zodJsonSchemaCompat.mjs +18 -16
  461. package/dist/utils/zodJsonSchemaCompat.mjs.map +1 -1
  462. package/package.json +25 -1
@@ -0,0 +1,704 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SandboxRuntimeManager = void 0;
7
+ const logger_1 = __importDefault(require("../../logger.js"));
8
+ const errors_1 = require("../../errors.js");
9
+ const memory_1 = require("../capabilities/memory.js");
10
+ const errors_2 = require("../errors.js");
11
+ const manifest_1 = require("../manifest.js");
12
+ const remoteMountCommandAllowlist_1 = require("../shared/remoteMountCommandAllowlist.js");
13
+ const environment_1 = require("../shared/environment.js");
14
+ const stableJson_1 = require("../shared/stableJson.js");
15
+ const generation_1 = require("../memory/generation.js");
16
+ const agentPreparation_1 = require("./agentPreparation.js");
17
+ const agentKeys_1 = require("./agentKeys.js");
18
+ const livePreservedSessions_1 = require("./livePreservedSessions.js");
19
+ const providedSessionManifest_1 = require("./providedSessionManifest.js");
20
+ const sessionSerialization_1 = require("./sessionSerialization.js");
21
+ const sessionLifecycle_1 = require("./sessionLifecycle.js");
22
+ const sessionState_1 = require("./sessionState.js");
23
+ const spans_1 = require("./spans.js");
24
+ const runAsManifest_1 = require("./runAsManifest.js");
25
+ class SandboxRuntimeManager {
26
+ sandboxConfig;
27
+ runState;
28
+ agentKeys;
29
+ acquiredAgents = new Map();
30
+ sessionsByAgent = new Map();
31
+ sessionsByAgentKey = new Map();
32
+ sessionAgentNamesByKey = new Map();
33
+ preparedAgents = new Map();
34
+ preparedSessions = new Map();
35
+ preparedManifestSignatures = new Map();
36
+ ownedSessionAgentKeys = new Set();
37
+ sessionStartPromises = new WeakMap();
38
+ activeMemory;
39
+ currentAgentId;
40
+ constructor(args) {
41
+ this.sandboxConfig = args.sandboxConfig;
42
+ this.runState = args.runState;
43
+ this.agentKeys = (0, agentKeys_1.allocateAgentKeys)(args.startingAgent);
44
+ }
45
+ async prepareAgent(args) {
46
+ const { currentAgent, turnInput, runConfigModel } = args;
47
+ if (!(0, agentKeys_1.isSandboxAgent)(currentAgent)) {
48
+ this.activeMemory = undefined;
49
+ return {
50
+ executionAgent: currentAgent,
51
+ turnInput,
52
+ };
53
+ }
54
+ if (!this.sandboxConfig) {
55
+ throw new errors_1.UserError('SandboxAgent execution requires `RunConfig.sandbox`.');
56
+ }
57
+ return await (0, spans_1.withSandboxSpan)('sandbox.prepare_agent', {
58
+ agent_name: currentAgent.name,
59
+ }, async () => {
60
+ this.acquireAgent(currentAgent);
61
+ const session = await this.ensureSession(currentAgent);
62
+ // Bind a clone to the live session so capability tools and instructions can carry
63
+ // per-session state without mutating the public SandboxAgent instance.
64
+ const executionAgent = this.getPreparedAgent(currentAgent, session, runConfigModel);
65
+ const memory = executionAgent.capabilities.find(memory_1.isMemoryCapability);
66
+ if (memory) {
67
+ this.activeMemory = {
68
+ session,
69
+ memory,
70
+ runAs: (0, runAsManifest_1.sandboxRunAsName)(currentAgent.runAs),
71
+ };
72
+ }
73
+ else {
74
+ this.activeMemory = undefined;
75
+ }
76
+ return {
77
+ executionAgent,
78
+ turnInput: executionAgent.capabilities.reduce((input, capability) => capability.processContext(input), turnInput),
79
+ };
80
+ });
81
+ }
82
+ async cleanup(state, options = {}) {
83
+ const preserveOwnedSessions = options.preserveOwnedSessions ?? false;
84
+ const runCleanup = async () => {
85
+ let preserveCleanupHandles = false;
86
+ try {
87
+ const cleanupPlan = await this.planCleanup(state, {
88
+ preserveOwnedSessions,
89
+ });
90
+ await this.executeCleanupPlan(state, cleanupPlan, {
91
+ onCloseError: () => {
92
+ preserveCleanupHandles = true;
93
+ },
94
+ preserveOwnedSessions,
95
+ });
96
+ }
97
+ finally {
98
+ this.releaseAgents();
99
+ this.sessionsByAgent.clear();
100
+ if (!preserveCleanupHandles) {
101
+ this.sessionsByAgentKey.clear();
102
+ this.sessionAgentNamesByKey.clear();
103
+ this.ownedSessionAgentKeys.clear();
104
+ }
105
+ this.preparedAgents.clear();
106
+ this.preparedSessions.clear();
107
+ this.preparedManifestSignatures.clear();
108
+ this.activeMemory = undefined;
109
+ this.currentAgentId = undefined;
110
+ }
111
+ };
112
+ if (this.sessionsByAgentKey.size === 0 &&
113
+ this.preparedAgents.size === 0 &&
114
+ this.ownedSessionAgentKeys.size === 0) {
115
+ await runCleanup();
116
+ return;
117
+ }
118
+ await (0, spans_1.withSandboxSpan)('sandbox.cleanup', {}, runCleanup);
119
+ }
120
+ async planCleanup(state, options) {
121
+ if (this.sessionsByAgentKey.size > 0) {
122
+ return await this.planCleanupForActiveSessions(state, options);
123
+ }
124
+ return await this.planCleanupForSerializedStateOnly(state, options);
125
+ }
126
+ async planCleanupForActiveSessions(state, options) {
127
+ const cleanupPlan = options.preserveOwnedSessions
128
+ ? {}
129
+ : {
130
+ ownedSessionCloseTarget: 'all',
131
+ afterOwnedSessionClose: {
132
+ forgetLivePreservedSessions: true,
133
+ },
134
+ };
135
+ try {
136
+ await this.runPreStopHooksBeforeRelease();
137
+ const serializedState = await this.serializeState({
138
+ includeOwnedSessions: options.preserveOwnedSessions,
139
+ });
140
+ state._sandbox = serializedState;
141
+ if (options.preserveOwnedSessions && serializedState) {
142
+ (0, livePreservedSessions_1.rememberLivePreservedOwnedSessions)({
143
+ state,
144
+ serializedState,
145
+ sessionsByAgentKey: this.sessionsByAgentKey,
146
+ });
147
+ const serializedOnlySessionAgentKeys = (0, livePreservedSessions_1.preservedOwnedSessionAgentKeysWithoutLiveReuse)(serializedState);
148
+ if (serializedOnlySessionAgentKeys.size > 0) {
149
+ cleanupPlan.ownedSessionCloseTarget = serializedOnlySessionAgentKeys;
150
+ }
151
+ }
152
+ if (options.preserveOwnedSessions &&
153
+ !serializedState &&
154
+ this.ownedSessionAgentKeys.size > 0) {
155
+ cleanupPlan.ownedSessionCloseTarget = 'all';
156
+ cleanupPlan.afterOwnedSessionClose = {
157
+ forgetLivePreservedSessions: true,
158
+ };
159
+ }
160
+ }
161
+ catch (error) {
162
+ cleanupPlan.deferredError = error;
163
+ if (this.ownedSessionAgentKeys.size > 0) {
164
+ cleanupPlan.ownedSessionCloseTarget = 'all';
165
+ cleanupPlan.afterOwnedSessionClose = {
166
+ forgetLivePreservedSessions: true,
167
+ };
168
+ }
169
+ }
170
+ return cleanupPlan;
171
+ }
172
+ async planCleanupForSerializedStateOnly(state, options) {
173
+ const cleanupPlan = options.preserveOwnedSessions
174
+ ? {}
175
+ : {
176
+ ownedSessionCloseTarget: 'all',
177
+ afterOwnedSessionClose: {
178
+ forgetLivePreservedSessions: true,
179
+ },
180
+ };
181
+ let sandboxState = (0, sessionState_1.getSerializedSandboxState)(state);
182
+ if ((0, sessionState_1.hasPreservedOwnedSessions)(sandboxState) &&
183
+ !options.preserveOwnedSessions) {
184
+ const closedLiveSessionAgentKeys = await this.closeLivePreservedOwnedSessions(state);
185
+ if (closedLiveSessionAgentKeys.size > 0) {
186
+ (0, livePreservedSessions_1.forgetLivePreservedOwnedSessions)(state);
187
+ if (sandboxState &&
188
+ !removeClosedPreservedOwnedSessions(sandboxState, closedLiveSessionAgentKeys)) {
189
+ state._sandbox = undefined;
190
+ sandboxState = undefined;
191
+ }
192
+ }
193
+ if ((0, sessionState_1.hasPreservedOwnedSessions)(sandboxState)) {
194
+ if (this.sandboxConfig?.client) {
195
+ try {
196
+ await this.adoptPreservedOwnedSessions();
197
+ if (this.ownedSessionAgentKeys.size > 0) {
198
+ cleanupPlan.ownedSessionCloseTarget = 'all';
199
+ cleanupPlan.afterOwnedSessionClose = {
200
+ clearSandboxState: true,
201
+ forgetLivePreservedSessions: true,
202
+ };
203
+ }
204
+ else {
205
+ cleanupPlan.ownedSessionCloseTarget = undefined;
206
+ cleanupPlan.afterOwnedSessionClose = undefined;
207
+ }
208
+ }
209
+ catch (error) {
210
+ cleanupPlan.deferredError = error;
211
+ }
212
+ }
213
+ else {
214
+ state._sandbox = undefined;
215
+ (0, livePreservedSessions_1.forgetLivePreservedOwnedSessions)(state);
216
+ cleanupPlan.ownedSessionCloseTarget = undefined;
217
+ cleanupPlan.afterOwnedSessionClose = undefined;
218
+ }
219
+ }
220
+ else if (closedLiveSessionAgentKeys.size > 0) {
221
+ state._sandbox = undefined;
222
+ }
223
+ }
224
+ else if (!(0, sessionState_1.hasPreservedOwnedSessions)(sandboxState)) {
225
+ state._sandbox = undefined;
226
+ (0, livePreservedSessions_1.forgetLivePreservedOwnedSessions)(state);
227
+ }
228
+ return cleanupPlan;
229
+ }
230
+ async executeCleanupPlan(state, plan, options) {
231
+ if (plan.ownedSessionCloseTarget) {
232
+ try {
233
+ await this.closeOwnedSessions(plan.ownedSessionCloseTarget === 'all'
234
+ ? undefined
235
+ : plan.ownedSessionCloseTarget, {
236
+ preserveOwnedSessions: options.preserveOwnedSessions,
237
+ });
238
+ }
239
+ catch (error) {
240
+ options.onCloseError();
241
+ throw error;
242
+ }
243
+ if (plan.afterOwnedSessionClose?.forgetLivePreservedSessions) {
244
+ (0, livePreservedSessions_1.forgetLivePreservedOwnedSessions)(state);
245
+ }
246
+ if (plan.afterOwnedSessionClose?.clearSandboxState) {
247
+ state._sandbox = undefined;
248
+ }
249
+ }
250
+ if (plan.deferredError) {
251
+ throw plan.deferredError;
252
+ }
253
+ }
254
+ async closeLivePreservedOwnedSessions(state) {
255
+ const sessionAgentKeys = new Map();
256
+ for (const entry of (0, livePreservedSessions_1.livePreservedOwnedSessionEntries)(state)) {
257
+ const agentKeys = sessionAgentKeys.get(entry.session) ?? [];
258
+ agentKeys.push(entry.agentKey);
259
+ sessionAgentKeys.set(entry.session, agentKeys);
260
+ }
261
+ const closedAgentKeys = new Set();
262
+ const closeErrors = [];
263
+ for (const [session, agentKeys] of sessionAgentKeys) {
264
+ try {
265
+ await (0, sessionLifecycle_1.cleanupSandboxSession)(session);
266
+ for (const agentKey of agentKeys) {
267
+ closedAgentKeys.add(agentKey);
268
+ }
269
+ }
270
+ catch (error) {
271
+ closeErrors.push(error);
272
+ }
273
+ }
274
+ if (closeErrors.length === 1) {
275
+ throw closeErrors[0];
276
+ }
277
+ if (closeErrors.length > 1) {
278
+ throw new errors_2.SandboxLifecycleError('Failed to close one or more live preserved owned sandbox sessions.', { errors: closeErrors });
279
+ }
280
+ return closedAgentKeys;
281
+ }
282
+ async runPreStopHooksBeforeRelease() {
283
+ const shouldRunForOwnedSessions = Boolean(this.sandboxConfig?.client?.serializeSessionState);
284
+ const sessionsForPreStop = new Set();
285
+ const sessionsForHooks = new Set();
286
+ for (const [agentKey, session] of this.sessionsByAgentKey) {
287
+ if (!this.ownedSessionAgentKeys.has(agentKey)) {
288
+ sessionsForPreStop.add(session);
289
+ continue;
290
+ }
291
+ // Owned sessions without serialization run hooks through the close lifecycle.
292
+ if (shouldRunForOwnedSessions) {
293
+ sessionsForHooks.add(session);
294
+ }
295
+ }
296
+ for (const session of sessionsForPreStop) {
297
+ await (0, sessionLifecycle_1.runSandboxSessionPreStop)(session);
298
+ }
299
+ for (const session of sessionsForHooks) {
300
+ if (!sessionsForPreStop.has(session)) {
301
+ await (0, sessionLifecycle_1.runSandboxSessionPreStopHooks)(session);
302
+ }
303
+ }
304
+ }
305
+ async enqueueMemoryGeneration(state, args) {
306
+ if (!this.activeMemory || this.activeMemory.memory.generate === null) {
307
+ return;
308
+ }
309
+ try {
310
+ const manager = (0, generation_1.getOrCreateSandboxMemoryGenerationManager)({
311
+ session: this.activeMemory.session,
312
+ memory: this.activeMemory.memory,
313
+ runAs: this.activeMemory.runAs,
314
+ runAgent: args.runAgent,
315
+ });
316
+ await manager.enqueueState(state, {
317
+ exception: args.exception,
318
+ inputOverride: args.inputOverride,
319
+ rolloutIdentity: {
320
+ conversationId: state._conversationId ?? undefined,
321
+ sdkSessionId: await args.sdkSessionId?.(),
322
+ groupId: args.groupId,
323
+ },
324
+ });
325
+ }
326
+ catch (error) {
327
+ logger_1.default.warn(`Failed to enqueue sandbox memory generation: ${error}`);
328
+ }
329
+ }
330
+ async adoptPreservedOwnedSessions() {
331
+ const sandboxState = (0, sessionState_1.getSerializedSandboxState)(this.runState);
332
+ if (!(0, sessionState_1.hasPreservedOwnedSessions)(sandboxState)) {
333
+ return false;
334
+ }
335
+ const client = this.sandboxConfig?.client;
336
+ if (!client) {
337
+ throw new errors_1.UserError('Sandbox client must be configured to restore preserved sandbox sessions.');
338
+ }
339
+ if (sandboxState && sandboxState.backendId !== client.backendId) {
340
+ throw new errors_1.UserError('RunState sandbox backend does not match the configured sandbox client.');
341
+ }
342
+ const preservedEntries = Object.entries((0, sessionState_1.getPreviousSerializedSessionsByAgent)(sandboxState, client)).filter(([, entry]) => entry.preservedOwnedSession);
343
+ let resumedSession = false;
344
+ for (const [agentKey, entry] of preservedEntries) {
345
+ if (this.sessionsByAgentKey.has(agentKey)) {
346
+ continue;
347
+ }
348
+ const liveEntry = (0, livePreservedSessions_1.livePreservedOwnedSession)({
349
+ runState: this.runState,
350
+ client,
351
+ agentKey,
352
+ serializedEntry: entry,
353
+ });
354
+ if (liveEntry) {
355
+ // Same RunState can resume immediately without round-tripping through provider
356
+ // reconnect APIs when the backend says its live handle is reusable.
357
+ this.sessionsByAgentKey.set(agentKey, liveEntry.session);
358
+ this.sessionAgentNamesByKey.set(agentKey, liveEntry.currentAgentName);
359
+ this.ownedSessionAgentKeys.add(agentKey);
360
+ continue;
361
+ }
362
+ if (!client.resume) {
363
+ throw new errors_1.UserError('Sandbox client must implement resume() to restore preserved sandbox sessions.');
364
+ }
365
+ const serializedState = await (0, sessionState_1.deserializeSandboxSessionStateEntry)(client, entry);
366
+ if (!serializedState) {
367
+ continue;
368
+ }
369
+ const session = await (0, spans_1.withSandboxSpan)('sandbox.resume_session', {
370
+ agent_name: entry.currentAgentName,
371
+ backend_id: client.backendId,
372
+ }, async () => await client.resume(serializedState));
373
+ this.sessionsByAgentKey.set(agentKey, session);
374
+ this.sessionAgentNamesByKey.set(agentKey, entry.currentAgentName);
375
+ this.ownedSessionAgentKeys.add(agentKey);
376
+ resumedSession = true;
377
+ }
378
+ return resumedSession;
379
+ }
380
+ acquireAgent(agent) {
381
+ const agentId = (0, agentKeys_1.getObjectId)(agent);
382
+ if (this.acquiredAgents.has(agentId)) {
383
+ return;
384
+ }
385
+ (0, agentKeys_1.acquireSandboxAgent)(agent);
386
+ this.acquiredAgents.set(agentId, agent);
387
+ }
388
+ async ensureSession(agent) {
389
+ const agentId = (0, agentKeys_1.getObjectId)(agent);
390
+ const agentKey = this.agentKey(agent);
391
+ const existing = this.sessionsByAgent.get(agentId);
392
+ if (existing) {
393
+ this.currentAgentId = agentId;
394
+ return existing;
395
+ }
396
+ const existingByKey = this.sessionsByAgentKey.get(agentKey);
397
+ if (existingByKey) {
398
+ await this.ensureSessionStarted(existingByKey, agent, 'resume', {
399
+ oncePerSession: true,
400
+ });
401
+ this.currentAgentId = agentId;
402
+ this.sessionsByAgent.set(agentId, existingByKey);
403
+ this.sessionAgentNamesByKey.set(agentKey, agent.name);
404
+ return existingByKey;
405
+ }
406
+ if (this.sandboxConfig?.session) {
407
+ const session = this.sandboxConfig.session;
408
+ const configuredManifest = this.resolveConfiguredManifest(agent, {
409
+ providedSession: session,
410
+ });
411
+ // Provided sessions are already running, so only a safe additive manifest delta can
412
+ // be applied instead of reprovisioning root, env, users, groups, or mounts.
413
+ await (0, providedSessionManifest_1.applyManifestToProvidedSession)(session, configuredManifest.manifest, (0, runAsManifest_1.sandboxRunAsName)(agent.runAs));
414
+ await this.ensureSessionStarted(session, agent, 'provided', {
415
+ oncePerSession: true,
416
+ });
417
+ this.registerSessionForAgent(agent, session);
418
+ return session;
419
+ }
420
+ const configuredManifest = this.resolveConfiguredManifest(agent);
421
+ const client = this.requireClient();
422
+ const resumed = await this.resumeSessionForAgent(client, agent);
423
+ if (resumed) {
424
+ await this.ensureSessionStarted(resumed, agent, 'resume');
425
+ this.registerSessionForAgent(agent, resumed, { owned: true });
426
+ return resumed;
427
+ }
428
+ if (!client.create) {
429
+ throw new errors_1.UserError('Sandbox execution requires a sandbox client with create() support.');
430
+ }
431
+ const createSession = client.create.bind(client);
432
+ const createArgs = {
433
+ snapshot: this.resolveSnapshotSpec(client),
434
+ options: this.sandboxConfig?.options,
435
+ concurrencyLimits: this.sandboxConfig?.concurrencyLimits,
436
+ };
437
+ if (configuredManifest.passToCreate) {
438
+ createArgs.manifest = configuredManifest.manifest;
439
+ }
440
+ const session = await (0, spans_1.withSandboxSpan)('sandbox.create_session', {
441
+ agent_name: agent.name,
442
+ backend_id: client.backendId,
443
+ }, async () => await createSession(createArgs));
444
+ await this.ensureSessionStarted(session, agent, 'create');
445
+ this.registerSessionForAgent(agent, session, { owned: true });
446
+ return session;
447
+ }
448
+ registerSessionForAgent(agent, session, options = {}) {
449
+ const agentId = (0, agentKeys_1.getObjectId)(agent);
450
+ const agentKey = this.agentKey(agent);
451
+ this.currentAgentId = agentId;
452
+ this.sessionsByAgent.set(agentId, session);
453
+ this.sessionsByAgentKey.set(agentKey, session);
454
+ this.sessionAgentNamesByKey.set(agentKey, agent.name);
455
+ if (options.owned) {
456
+ this.ownedSessionAgentKeys.add(agentKey);
457
+ }
458
+ }
459
+ async ensureSessionStarted(session, agent, reason, options = {}) {
460
+ if (!session.start) {
461
+ return;
462
+ }
463
+ if (options.oncePerSession) {
464
+ // Provided and resumed sessions may be shared by multiple agents in one run; keep
465
+ // their provider-specific start hook idempotent.
466
+ const started = this.sessionStartPromises.get(session);
467
+ if (started) {
468
+ await started;
469
+ return;
470
+ }
471
+ }
472
+ if (session.running && (await session.running())) {
473
+ if (options.oncePerSession) {
474
+ this.sessionStartPromises.set(session, Promise.resolve());
475
+ }
476
+ return;
477
+ }
478
+ const startPromise = (0, spans_1.withSandboxSpan)('sandbox.start', {
479
+ agent_name: agent.name,
480
+ }, async () => {
481
+ await session.start({ reason });
482
+ });
483
+ if (options.oncePerSession) {
484
+ this.sessionStartPromises.set(session, startPromise);
485
+ }
486
+ try {
487
+ await startPromise;
488
+ }
489
+ catch (error) {
490
+ if (options.oncePerSession) {
491
+ this.sessionStartPromises.delete(session);
492
+ }
493
+ throw error;
494
+ }
495
+ }
496
+ getPreparedAgent(agent, session, runConfigModel) {
497
+ const agentId = (0, agentKeys_1.getObjectId)(agent);
498
+ const manifestSignature = getManifestSignature(session.state.manifest);
499
+ const cached = this.preparedAgents.get(agentId);
500
+ if (cached &&
501
+ this.preparedSessions.get(agentId) === session &&
502
+ this.preparedManifestSignatures.get(agentId) === manifestSignature) {
503
+ return cached;
504
+ }
505
+ // Capability instructions include a rendered filesystem view, so a manifest change
506
+ // invalidates the prepared-agent cache even when the live session object is unchanged.
507
+ const prepared = (0, agentPreparation_1.prepareSandboxAgent)({
508
+ agent,
509
+ session,
510
+ capabilities: (0, agentPreparation_1.cloneSandboxCapabilities)(agent.capabilities),
511
+ runConfigModel,
512
+ processManifest: false,
513
+ });
514
+ this.preparedAgents.set(agentId, prepared);
515
+ this.preparedSessions.set(agentId, session);
516
+ this.preparedManifestSignatures.set(agentId, manifestSignature);
517
+ return prepared;
518
+ }
519
+ async resumeSessionForAgent(client, agent) {
520
+ const agentKey = this.agentKey(agent);
521
+ const serializedEntry = (0, sessionState_1.getSerializedSessionEntryForAgent)((0, sessionState_1.getSerializedSandboxState)(this.runState), agentKey);
522
+ if (!client.resume) {
523
+ if (this.sandboxConfig?.sessionState || serializedEntry) {
524
+ throw new errors_1.UserError('Sandbox client must implement resume() to restore sandbox session state.');
525
+ }
526
+ return undefined;
527
+ }
528
+ const liveEntry = (0, livePreservedSessions_1.livePreservedOwnedSession)({
529
+ runState: this.runState,
530
+ client,
531
+ agentKey,
532
+ serializedEntry,
533
+ });
534
+ if (liveEntry) {
535
+ return liveEntry.session;
536
+ }
537
+ if (this.sandboxConfig?.sessionState) {
538
+ return await (0, spans_1.withSandboxSpan)('sandbox.resume_session', {
539
+ agent_name: agent.name,
540
+ backend_id: client.backendId,
541
+ }, async () => await client.resume(this.sandboxConfig.sessionState));
542
+ }
543
+ const serializedState = await (0, sessionState_1.deserializeSandboxSessionStateEntry)(client, serializedEntry);
544
+ if (!serializedState) {
545
+ return undefined;
546
+ }
547
+ return await (0, spans_1.withSandboxSpan)('sandbox.resume_session', {
548
+ agent_name: agent.name,
549
+ backend_id: client.backendId,
550
+ }, async () => await client.resume(serializedState));
551
+ }
552
+ async serializeState(args = {}) {
553
+ const currentAgent = this.currentAgentId
554
+ ? this.acquiredAgents.get(this.currentAgentId)
555
+ : undefined;
556
+ const sandboxState = (0, sessionState_1.getSerializedSandboxState)(this.runState);
557
+ const preferredCurrentAgentKey = currentAgent
558
+ ? this.agentKey(currentAgent)
559
+ : sandboxState?.currentAgentKey;
560
+ return await (0, sessionSerialization_1.serializeSandboxRuntimeState)({
561
+ client: this.sandboxConfig?.client,
562
+ sandboxState,
563
+ sessionsByAgentKey: this.sessionsByAgentKey,
564
+ sessionAgentNamesByKey: this.sessionAgentNamesByKey,
565
+ ownedSessionAgentKeys: this.ownedSessionAgentKeys,
566
+ includeOwnedSessions: args.includeOwnedSessions,
567
+ preferredCurrentAgentKey,
568
+ });
569
+ }
570
+ requireClient() {
571
+ if (!this.sandboxConfig?.client) {
572
+ throw new errors_1.UserError('Sandbox execution requires `RunConfig.sandbox.client` unless a live session is provided.');
573
+ }
574
+ return this.sandboxConfig.client;
575
+ }
576
+ resolveSnapshotSpec(client) {
577
+ if (this.sandboxConfig?.snapshot) {
578
+ return this.sandboxConfig.snapshot;
579
+ }
580
+ if (!client.supportsDefaultOptions) {
581
+ return undefined;
582
+ }
583
+ return { type: 'local' };
584
+ }
585
+ agentKey(agent) {
586
+ const agentId = (0, agentKeys_1.getObjectId)(agent);
587
+ const existing = this.agentKeys.get(agentId);
588
+ if (existing) {
589
+ return existing;
590
+ }
591
+ const agentKey = this.allocateRuntimeAgentKey(agent.name);
592
+ this.agentKeys.set(agentId, agentKey);
593
+ return agentKey;
594
+ }
595
+ allocateRuntimeAgentKey(agentName) {
596
+ const usedKeys = new Set(this.agentKeys.values());
597
+ if (!usedKeys.has(agentName)) {
598
+ return agentName;
599
+ }
600
+ let suffix = 2;
601
+ while (usedKeys.has(`${agentName}_${suffix}`)) {
602
+ suffix += 1;
603
+ }
604
+ return `${agentName}_${suffix}`;
605
+ }
606
+ resolveConfiguredManifest(agent, options = {}) {
607
+ const baseManifest = this.sandboxConfig?.manifest ??
608
+ agent.defaultManifest ??
609
+ options.providedSession?.state.manifest;
610
+ const initialManifest = baseManifest
611
+ ? (0, manifest_1.cloneManifest)(baseManifest)
612
+ : new manifest_1.Manifest();
613
+ const manifestWithIdentity = options.providedSession
614
+ ? initialManifest
615
+ : (0, runAsManifest_1.manifestWithRunAsUser)(initialManifest, agent.runAs);
616
+ const configuredManifest = (0, agentPreparation_1.cloneSandboxCapabilities)(agent.capabilities).reduce((manifest, capability) => capability.processManifest(manifest), manifestWithIdentity);
617
+ // Passing a truly default manifest to providers can override their natural root
618
+ // defaults, so create() receives a manifest only when configuration changed it.
619
+ return {
620
+ manifest: configuredManifest,
621
+ passToCreate: baseManifest !== undefined || !isDefaultManifest(configuredManifest),
622
+ };
623
+ }
624
+ async closeOwnedSessions(agentKeys, options = {}) {
625
+ const keysToClose = [...(agentKeys ?? this.ownedSessionAgentKeys)].filter((agentKey) => this.ownedSessionAgentKeys.has(agentKey));
626
+ const sessionsToClose = new Map();
627
+ for (const agentKey of keysToClose) {
628
+ const session = this.sessionsByAgentKey.get(agentKey);
629
+ if (!session || !(0, sessionLifecycle_1.hasSessionCleanup)(session)) {
630
+ continue;
631
+ }
632
+ if (!sessionsToClose.has(session)) {
633
+ sessionsToClose.set(session, this.sessionAgentNamesByKey.get(agentKey));
634
+ }
635
+ }
636
+ if (sessionsToClose.size === 0) {
637
+ return;
638
+ }
639
+ await (0, spans_1.withSandboxSpan)('sandbox.cleanup_sessions', {
640
+ session_count: sessionsToClose.size,
641
+ }, async () => {
642
+ await Promise.all([...sessionsToClose].map(async ([session, agentName]) => {
643
+ await (0, spans_1.withSandboxSpan)('sandbox.shutdown', {
644
+ agent_name: agentName,
645
+ }, async () => {
646
+ await (0, sessionLifecycle_1.cleanupSandboxSession)(session, options.preserveOwnedSessions
647
+ ? { preserveOwnedSessions: true }
648
+ : undefined);
649
+ });
650
+ }));
651
+ });
652
+ }
653
+ releaseAgents() {
654
+ (0, agentKeys_1.releaseSandboxAgents)(this.acquiredAgents.values());
655
+ this.acquiredAgents.clear();
656
+ }
657
+ }
658
+ exports.SandboxRuntimeManager = SandboxRuntimeManager;
659
+ function getManifestSignature(manifest) {
660
+ return (0, stableJson_1.stableJsonStringify)({
661
+ version: manifest.version,
662
+ root: manifest.root,
663
+ entries: manifest.entries,
664
+ environment: (0, environment_1.serializeManifestEnvironment)(manifest),
665
+ users: manifest.users,
666
+ groups: manifest.groups,
667
+ extraPathGrants: manifest.extraPathGrants,
668
+ remoteMountCommandAllowlist: manifest.remoteMountCommandAllowlist,
669
+ });
670
+ }
671
+ function isDefaultManifest(manifest) {
672
+ const defaultManifest = new manifest_1.Manifest();
673
+ return (manifest.version === defaultManifest.version &&
674
+ manifest.root === defaultManifest.root &&
675
+ Object.keys(manifest.entries).length === 0 &&
676
+ Object.keys(manifest.environment).length === 0 &&
677
+ manifest.users.length === 0 &&
678
+ manifest.groups.length === 0 &&
679
+ manifest.extraPathGrants.length === 0 &&
680
+ (0, remoteMountCommandAllowlist_1.isDefaultRemoteMountCommandAllowlist)(manifest.remoteMountCommandAllowlist));
681
+ }
682
+ function removeClosedPreservedOwnedSessions(sandboxState, agentKeys) {
683
+ for (const agentKey of agentKeys) {
684
+ delete sandboxState.sessionsByAgent[agentKey];
685
+ }
686
+ if (!(0, sessionState_1.hasPreservedOwnedSessions)(sandboxState)) {
687
+ return false;
688
+ }
689
+ const currentEntry = sandboxState.sessionsByAgent[sandboxState.currentAgentKey];
690
+ if (currentEntry) {
691
+ sandboxState.currentAgentName = currentEntry.currentAgentName;
692
+ sandboxState.sessionState = currentEntry.sessionState;
693
+ return true;
694
+ }
695
+ const nextEntry = Object.values(sandboxState.sessionsByAgent).find((entry) => entry.preservedOwnedSession);
696
+ if (!nextEntry) {
697
+ return false;
698
+ }
699
+ sandboxState.currentAgentKey = nextEntry.currentAgentKey;
700
+ sandboxState.currentAgentName = nextEntry.currentAgentName;
701
+ sandboxState.sessionState = nextEntry.sessionState;
702
+ return true;
703
+ }
704
+ //# sourceMappingURL=manager.js.map