@openai/agents-core 0.8.4 → 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,684 @@
1
+ import { UserError } from "../../../errors.mjs";
2
+ import { SandboxUnsupportedFeatureError } from "../../errors.mjs";
3
+ import { isMount } from "../../entries/index.mjs";
4
+ import { normalizeRelativePath } from "../../manifest.mjs";
5
+ import { permissionsForSandboxEntry } from "../../permissions.mjs";
6
+ import { WorkspacePathPolicy } from "../../workspacePaths.mjs";
7
+ import { formatSandboxProcessError, runSandboxProcess } from "./runProcess.mjs";
8
+ import { chmod, chown, lstat, mkdir, mkdtemp, open, readdir, readFile, realpath, rm, stat, symlink, } from 'node:fs/promises';
9
+ import { constants } from 'node:fs';
10
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
11
+ import { tmpdir } from 'node:os';
12
+ import { isHostPathWithinRoot, isHostPathStrictlyWithinRoot, relativeHostPathEscapesRoot, } from "../../shared/hostPath.mjs";
13
+ const GIT_VERSION_TIMEOUT_MS = 10_000;
14
+ const GIT_CLONE_TIMEOUT_MS = 5 * 60_000;
15
+ const COMMIT_REF_PATTERN = /^[0-9a-fA-F]{7,40}$/;
16
+ const MATERIALIZATION_FILE_WRITE_FLAGS = constants.O_WRONLY |
17
+ constants.O_CREAT |
18
+ constants.O_TRUNC |
19
+ constants.O_NOFOLLOW;
20
+ const LOCAL_SOURCE_FILE_READ_FLAGS = constants.O_RDONLY | constants.O_NOFOLLOW;
21
+ const LOCAL_SOURCE_DIRECTORY_READ_FLAGS = constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_DIRECTORY;
22
+ export async function materializeLocalWorkspaceManifest(manifest, workspaceRootPath, options = {}) {
23
+ assertLocalWorkspaceManifestMetadataSupported('Local sandbox materialization', manifest, {
24
+ supportsMount: options.supportsMount,
25
+ allowLocalBindMounts: options.allowLocalBindMounts,
26
+ allowIdentityMetadata: options.allowIdentityMetadata,
27
+ });
28
+ await mkdir(workspaceRootPath, { recursive: true });
29
+ await materializeEntries(workspaceRootPath, manifest.entries, '', {
30
+ ...options,
31
+ manifestRoot: manifest.root,
32
+ skipMountEntries: true,
33
+ });
34
+ await materializeLocalWorkspaceManifestMounts(manifest, workspaceRootPath, options);
35
+ }
36
+ export function assertLocalWorkspaceManifestMetadataSupported(providerName, manifest, options = {}) {
37
+ if (!options.allowIdentityMetadata && manifest.users.length > 0) {
38
+ throw new SandboxUnsupportedFeatureError(`${providerName} does not support manifest users yet.`);
39
+ }
40
+ if (!options.allowIdentityMetadata && manifest.groups.length > 0) {
41
+ throw new SandboxUnsupportedFeatureError(`${providerName} does not support manifest groups yet.`);
42
+ }
43
+ for (const [logicalPath, entry] of Object.entries(manifest.entries)) {
44
+ assertLocalWorkspaceEntryMetadataSupported(providerName, logicalPath, entry, options);
45
+ }
46
+ }
47
+ export async function materializeLocalWorkspaceManifestEntry(workspaceRootPath, logicalPath, entry, options = {}) {
48
+ assertLocalWorkspaceEntryMetadataSupported('Local sandbox materialization', logicalPath, entry, {
49
+ supportsMount: options.supportsMount,
50
+ allowLocalBindMounts: options.allowLocalBindMounts,
51
+ allowIdentityMetadata: options.allowIdentityMetadata,
52
+ });
53
+ if (isMount(entry)) {
54
+ if (options.materializeMount) {
55
+ await options.materializeMount({ logicalPath, entry });
56
+ return;
57
+ }
58
+ await materializeLocalBindMountEntry(workspaceRootPath, logicalPath, entry, options);
59
+ return;
60
+ }
61
+ const destination = logicalPath
62
+ ? resolve(workspaceRootPath, logicalPath)
63
+ : workspaceRootPath;
64
+ switch (entry.type) {
65
+ case 'dir':
66
+ await materializeDirEntry(workspaceRootPath, destination, entry, logicalPath, options);
67
+ break;
68
+ case 'file':
69
+ await materializeFileEntry(workspaceRootPath, destination, entry, logicalPath);
70
+ break;
71
+ case 'local_file':
72
+ await materializeLocalFileEntry(workspaceRootPath, destination, entry, logicalPath);
73
+ break;
74
+ case 'local_dir':
75
+ await materializeLocalDirEntry(workspaceRootPath, destination, entry, logicalPath, options);
76
+ break;
77
+ case 'git_repo':
78
+ await materializeGitRepoEntry(workspaceRootPath, destination, entry, logicalPath);
79
+ break;
80
+ default:
81
+ throw new UserError(`Unsupported sandbox entry type: ${entry.type}`);
82
+ }
83
+ await applyEntryPermissions(workspaceRootPath, destination, entry, logicalPath);
84
+ }
85
+ export async function materializeLocalWorkspaceManifestMounts(manifest, workspaceRootPath, options = {}) {
86
+ assertLocalWorkspaceManifestMetadataSupported('Local sandbox materialization', manifest, {
87
+ supportsMount: options.supportsMount,
88
+ allowLocalBindMounts: options.allowLocalBindMounts,
89
+ allowIdentityMetadata: options.allowIdentityMetadata,
90
+ });
91
+ for (const { logicalPath, entry, } of manifest.mountTargetsForMaterialization()) {
92
+ await materializeLocalWorkspaceManifestEntry(workspaceRootPath, logicalPath, entry, {
93
+ ...options,
94
+ manifestRoot: manifest.root,
95
+ });
96
+ }
97
+ }
98
+ export async function applyOwnershipRecursive(targetPath, uid, gid) {
99
+ const info = await lstat(targetPath).catch(() => null);
100
+ if (!info) {
101
+ return;
102
+ }
103
+ if (info.isSymbolicLink()) {
104
+ return;
105
+ }
106
+ await chown(targetPath, uid, gid);
107
+ if (!info.isDirectory()) {
108
+ return;
109
+ }
110
+ const children = await readdir(targetPath);
111
+ await Promise.all(children.map(async (child) => {
112
+ await applyOwnershipRecursive(join(targetPath, child), uid, gid);
113
+ }));
114
+ }
115
+ export async function pathExists(path) {
116
+ try {
117
+ await stat(path);
118
+ return true;
119
+ }
120
+ catch {
121
+ return false;
122
+ }
123
+ }
124
+ export function joinSandboxLogicalPath(root, logicalPath) {
125
+ if (!logicalPath) {
126
+ return root;
127
+ }
128
+ return root === '/' ? `/${logicalPath}` : `${root}/${logicalPath}`;
129
+ }
130
+ function assertLocalWorkspaceEntryMetadataSupported(providerName, logicalPath, entry, options = {}) {
131
+ const displayPath = logicalPath || '.';
132
+ if (isMount(entry)) {
133
+ if (options.supportsMount?.(entry) ||
134
+ (options.allowLocalBindMounts !== false &&
135
+ isSupportedLocalBindMount(entry))) {
136
+ return;
137
+ }
138
+ throw new SandboxUnsupportedFeatureError(`${providerName} does not support this mount entry: ${displayPath}`);
139
+ }
140
+ if (entry.group !== undefined) {
141
+ throw new SandboxUnsupportedFeatureError(`${providerName} does not support sandbox entry group ownership yet: ${displayPath}`);
142
+ }
143
+ if (entry.type !== 'dir' || !entry.children) {
144
+ return;
145
+ }
146
+ for (const [childPath, childEntry] of Object.entries(entry.children)) {
147
+ assertLocalWorkspaceEntryMetadataSupported(providerName, joinLogicalPath(logicalPath, childPath), childEntry, options);
148
+ }
149
+ }
150
+ async function materializeEntries(workspaceRootPath, entries, prefix = '', options = {}) {
151
+ await runLimited(Object.entries(entries), resolveManifestEntryConcurrency(options.concurrencyLimits), async ([path, entry]) => {
152
+ if (options.skipMountEntries && isMount(entry)) {
153
+ return;
154
+ }
155
+ const logicalPath = prefix
156
+ ? `${prefix}/${normalizeRelativePath(path)}`
157
+ : normalizeRelativePath(path);
158
+ await materializeLocalWorkspaceManifestEntry(workspaceRootPath, logicalPath, entry, options);
159
+ });
160
+ }
161
+ async function materializeLocalBindMountEntry(workspaceRootPath, logicalPath, entry, options) {
162
+ if (!isSupportedLocalBindMount(entry)) {
163
+ throw new SandboxUnsupportedFeatureError(`Local sandbox materialization only supports mount entries with an absolute source and localBindMountStrategy(): ${logicalPath || '.'}`);
164
+ }
165
+ if (entry.readOnly !== false) {
166
+ throw new SandboxUnsupportedFeatureError(`Local sandbox materialization cannot enforce read-only local bind mounts: ${logicalPath || '.'}`);
167
+ }
168
+ // A local bind mount is implemented as a symlink, so read-only semantics cannot be
169
+ // enforced by this materializer itself.
170
+ const source = await realpath(entry.source).catch(() => {
171
+ throw new UserError(`Local bind mount source does not exist: ${entry.source}`);
172
+ });
173
+ const sourceInfo = await lstat(source);
174
+ if (!sourceInfo.isDirectory()) {
175
+ throw new UserError(`Local bind mount source must be a directory: ${source}`);
176
+ }
177
+ const mountLogicalPath = resolveMountLogicalPath(options.manifestRoot ?? '/workspace', logicalPath, entry.mountPath);
178
+ if (!mountLogicalPath) {
179
+ throw new SandboxUnsupportedFeatureError('Local sandbox materialization does not support mounting over the workspace root.');
180
+ }
181
+ const destination = resolve(workspaceRootPath, mountLogicalPath);
182
+ await createMaterializationParentDirectory(workspaceRootPath, destination, mountLogicalPath);
183
+ await rm(destination, { recursive: true, force: true });
184
+ await symlink(source, destination, 'dir');
185
+ }
186
+ function isSupportedLocalBindMount(entry) {
187
+ return (entry.type === 'mount' &&
188
+ typeof entry.source === 'string' &&
189
+ isAbsolute(entry.source) &&
190
+ (entry.mountStrategy === undefined ||
191
+ entry.mountStrategy.type === 'local_bind'));
192
+ }
193
+ function resolveMountLogicalPath(root, logicalPath, mountPath) {
194
+ if (mountPath === undefined) {
195
+ return normalizeRelativePath(logicalPath);
196
+ }
197
+ const resolved = new WorkspacePathPolicy({ root }).resolve(mountPath, {
198
+ forWrite: true,
199
+ });
200
+ if (typeof resolved.workspaceRelativePath !== 'string') {
201
+ throw new UserError(`Mount path "${mountPath}" escapes the workspace root.`);
202
+ }
203
+ return normalizeRelativePath(resolved.workspaceRelativePath);
204
+ }
205
+ async function createMaterializationDirectory(workspaceRootPath, destination, logicalPath) {
206
+ await assertSafeMaterializationPath(workspaceRootPath, destination, logicalPath);
207
+ await mkdir(destination, { recursive: true });
208
+ await assertSafeMaterializationPath(workspaceRootPath, destination, logicalPath);
209
+ }
210
+ async function createMaterializationParentDirectory(workspaceRootPath, destination, logicalPath) {
211
+ const parent = dirname(destination);
212
+ await assertSafeMaterializationPath(workspaceRootPath, parent, logicalPath);
213
+ await mkdir(parent, { recursive: true });
214
+ await assertSafeMaterializationPath(workspaceRootPath, parent, logicalPath);
215
+ await assertSafeMaterializationPath(workspaceRootPath, destination, logicalPath);
216
+ }
217
+ async function assertSafeMaterializationPath(workspaceRootPath, destination, logicalPath) {
218
+ // Check after directory creation and again before writes so a concurrent symlink swap
219
+ // cannot redirect manifest materialization outside the workspace root.
220
+ const workspaceRootRealPath = await realpath(workspaceRootPath).catch(() => {
221
+ throw materializationEscapesWorkspaceError(logicalPath);
222
+ });
223
+ const relativeDestination = relative(workspaceRootPath, destination);
224
+ if (relativeHostPathEscapesRoot(relativeDestination)) {
225
+ throw materializationEscapesWorkspaceError(logicalPath);
226
+ }
227
+ if (relativeDestination === '') {
228
+ return;
229
+ }
230
+ let current = workspaceRootPath;
231
+ for (const segment of relativeDestination.split(sep)) {
232
+ if (!segment) {
233
+ continue;
234
+ }
235
+ current = join(current, segment);
236
+ const info = await lstat(current).catch((error) => {
237
+ if (error.code === 'ENOENT') {
238
+ return undefined;
239
+ }
240
+ throw error;
241
+ });
242
+ if (!info) {
243
+ return;
244
+ }
245
+ if (info.isSymbolicLink()) {
246
+ throw new UserError(`Sandbox materialization path "${logicalPath || '.'}" escapes the workspace root through a symbolic link.`);
247
+ }
248
+ const currentRealPath = await realpath(current).catch(() => {
249
+ throw materializationEscapesWorkspaceError(logicalPath);
250
+ });
251
+ if (!isHostPathWithinRoot(workspaceRootRealPath, currentRealPath)) {
252
+ throw materializationEscapesWorkspaceError(logicalPath);
253
+ }
254
+ }
255
+ }
256
+ async function materializeDirEntry(workspaceRootPath, destination, entry, logicalPath, options) {
257
+ await createMaterializationDirectory(workspaceRootPath, destination, logicalPath);
258
+ if (entry.children) {
259
+ await materializeEntries(workspaceRootPath, entry.children, logicalPath, options);
260
+ }
261
+ }
262
+ async function materializeFileEntry(workspaceRootPath, destination, entry, logicalPath) {
263
+ await createMaterializationParentDirectory(workspaceRootPath, destination, logicalPath);
264
+ await writeMaterializationFile(workspaceRootPath, destination, logicalPath, entry.content);
265
+ }
266
+ async function materializeLocalFileEntry(workspaceRootPath, destination, entry, logicalPath) {
267
+ await createMaterializationParentDirectory(workspaceRootPath, destination, logicalPath);
268
+ await writeMaterializationFile(workspaceRootPath, destination, logicalPath, await readStableLocalFile(entry.src));
269
+ }
270
+ async function materializeLocalDirEntry(workspaceRootPath, destination, entry, logicalPath, options) {
271
+ await copyLocalDirectory(entry.src, destination, options, workspaceRootPath, logicalPath);
272
+ }
273
+ async function copyLocalDirectory(sourceDir, destination, options, workspaceRootPath, logicalPath, expectedSourceStat) {
274
+ const source = await resolveStableLocalDirSource(sourceDir, expectedSourceStat);
275
+ await createMaterializationDirectory(workspaceRootPath, destination, logicalPath);
276
+ const children = await readStableLocalDirEntries(sourceDir, source.stat);
277
+ await runLimited(children, resolveLocalDirEntryConcurrency(options.concurrencyLimits), async (child) => {
278
+ const sourcePath = join(sourceDir, child.name);
279
+ const destinationPath = join(destination, child.name);
280
+ const childLogicalPath = joinLogicalPath(logicalPath, child.name);
281
+ if (child.isDirectory()) {
282
+ const childSourceStat = await assertStableLocalDirChild(source.root, sourcePath);
283
+ await copyLocalDirectory(sourcePath, destinationPath, options, workspaceRootPath, childLogicalPath, childSourceStat);
284
+ return;
285
+ }
286
+ if (child.isFile()) {
287
+ await writeMaterializationFile(workspaceRootPath, destinationPath, childLogicalPath, await readStableLocalDirFile(source.root, sourcePath));
288
+ return;
289
+ }
290
+ if (child.isSymbolicLink()) {
291
+ throw new UserError(`local_dir entries do not support symbolic links: ${sourcePath}`);
292
+ }
293
+ });
294
+ }
295
+ async function writeMaterializationFile(workspaceRootPath, destination, logicalPath, content) {
296
+ await assertSafeMaterializationPath(workspaceRootPath, destination, logicalPath);
297
+ let handle;
298
+ try {
299
+ handle = await open(destination, MATERIALIZATION_FILE_WRITE_FLAGS);
300
+ }
301
+ catch (error) {
302
+ if (isPathChangedError(error)) {
303
+ throw materializationEscapesWorkspaceError(logicalPath);
304
+ }
305
+ throw error;
306
+ }
307
+ try {
308
+ await handle.writeFile(content);
309
+ }
310
+ finally {
311
+ await handle.close();
312
+ }
313
+ await assertSafeMaterializationPath(workspaceRootPath, destination, logicalPath);
314
+ }
315
+ async function resolveStableLocalDirSource(sourceDir, expectedSourceStat) {
316
+ await assertNoLocalSourceSymlinkAncestors(sourceDir, 'local_dir', localDirPathChangedError);
317
+ const sourceStat = await statStableLocalSourcePath(sourceDir);
318
+ if (sourceStat.isSymbolicLink()) {
319
+ throw new UserError(`local_dir entries do not support symbolic links: ${sourceDir}`);
320
+ }
321
+ if (!sourceStat.isDirectory()) {
322
+ throw new UserError(`local_dir source must be a directory: ${sourceDir}`);
323
+ }
324
+ if (expectedSourceStat &&
325
+ !sameFilesystemEntry(sourceStat, expectedSourceStat)) {
326
+ throw localDirPathChangedError(sourceDir);
327
+ }
328
+ const sourceRoot = await realpathStableLocalSourcePath(sourceDir);
329
+ let handle;
330
+ try {
331
+ handle = await open(sourceDir, LOCAL_SOURCE_DIRECTORY_READ_FLAGS);
332
+ }
333
+ catch (error) {
334
+ if (isPathChangedError(error)) {
335
+ throw localDirPathChangedError(sourceDir);
336
+ }
337
+ throw error;
338
+ }
339
+ try {
340
+ const openedStat = await handle.stat();
341
+ if (!openedStat.isDirectory() ||
342
+ !sameFilesystemEntry(openedStat, sourceStat)) {
343
+ throw localDirPathChangedError(sourceDir);
344
+ }
345
+ return { root: sourceRoot, stat: openedStat };
346
+ }
347
+ finally {
348
+ await handle.close();
349
+ }
350
+ }
351
+ async function readStableLocalDirEntries(sourceDir, expectedStat) {
352
+ let children;
353
+ try {
354
+ children = await readdir(sourceDir, { withFileTypes: true });
355
+ }
356
+ catch (error) {
357
+ if (isPathChangedError(error)) {
358
+ throw localDirPathChangedError(sourceDir);
359
+ }
360
+ throw error;
361
+ }
362
+ await assertStableLocalDirPath(sourceDir, expectedStat);
363
+ return children;
364
+ }
365
+ async function assertStableLocalDirPath(sourcePath, expectedStat) {
366
+ const currentStat = await statStableLocalSourcePath(sourcePath);
367
+ if (currentStat.isSymbolicLink() ||
368
+ !currentStat.isDirectory() ||
369
+ !sameFilesystemEntry(currentStat, expectedStat)) {
370
+ throw localDirPathChangedError(sourcePath);
371
+ }
372
+ }
373
+ async function readStableLocalFile(sourcePath) {
374
+ await assertNoLocalSourceSymlinkAncestors(sourcePath, 'local_file', localFilePathChangedError);
375
+ const sourceStat = await statStableLocalSourcePath(sourcePath, localFilePathChangedError);
376
+ if (sourceStat.isSymbolicLink()) {
377
+ throw new UserError(`local_file entries do not support symbolic links: ${sourcePath}`);
378
+ }
379
+ if (!sourceStat.isFile()) {
380
+ throw localFilePathChangedError(sourcePath);
381
+ }
382
+ let handle;
383
+ try {
384
+ handle = await open(sourcePath, LOCAL_SOURCE_FILE_READ_FLAGS);
385
+ }
386
+ catch (error) {
387
+ if (isPathChangedError(error)) {
388
+ throw localFilePathChangedError(sourcePath);
389
+ }
390
+ throw error;
391
+ }
392
+ try {
393
+ const openedStat = await handle.stat();
394
+ if (!openedStat.isFile() || !sameFilesystemEntry(openedStat, sourceStat)) {
395
+ throw localFilePathChangedError(sourcePath);
396
+ }
397
+ return await handle.readFile();
398
+ }
399
+ finally {
400
+ await handle.close();
401
+ }
402
+ }
403
+ async function assertNoLocalSourceSymlinkAncestors(sourcePath, entryType, pathChangedError) {
404
+ const resolvedPath = resolve(sourcePath);
405
+ let current = dirname(resolvedPath);
406
+ while (current !== dirname(current)) {
407
+ const parent = dirname(current);
408
+ if (parent === dirname(parent)) {
409
+ break;
410
+ }
411
+ let currentStat;
412
+ try {
413
+ currentStat = await lstat(current);
414
+ }
415
+ catch (error) {
416
+ if (isPathChangedError(error)) {
417
+ throw pathChangedError(sourcePath);
418
+ }
419
+ throw error;
420
+ }
421
+ if (currentStat.isSymbolicLink()) {
422
+ throw new UserError(`${entryType} entries do not support symbolic link ancestors: ${sourcePath}`);
423
+ }
424
+ current = parent;
425
+ }
426
+ }
427
+ async function readStableLocalDirFile(sourceRoot, sourcePath) {
428
+ const sourceStat = await statStableLocalSourcePath(sourcePath);
429
+ if (sourceStat.isSymbolicLink()) {
430
+ throw new UserError(`local_dir entries do not support symbolic links: ${sourcePath}`);
431
+ }
432
+ if (!sourceStat.isFile()) {
433
+ throw localDirPathChangedError(sourcePath);
434
+ }
435
+ const resolvedSourcePath = await realpathStableLocalSourcePath(sourcePath);
436
+ if (!isHostPathStrictlyWithinRoot(sourceRoot, resolvedSourcePath)) {
437
+ throw localDirPathChangedError(sourcePath);
438
+ }
439
+ let handle;
440
+ try {
441
+ handle = await open(sourcePath, LOCAL_SOURCE_FILE_READ_FLAGS);
442
+ }
443
+ catch (error) {
444
+ if (isPathChangedError(error)) {
445
+ throw localDirPathChangedError(sourcePath);
446
+ }
447
+ throw error;
448
+ }
449
+ try {
450
+ const openedStat = await handle.stat();
451
+ if (!openedStat.isFile() || !sameFilesystemEntry(openedStat, sourceStat)) {
452
+ throw localDirPathChangedError(sourcePath);
453
+ }
454
+ return await handle.readFile();
455
+ }
456
+ finally {
457
+ await handle.close();
458
+ }
459
+ }
460
+ async function statStableLocalSourcePath(sourcePath, pathChangedError = localDirPathChangedError) {
461
+ try {
462
+ return await lstat(sourcePath);
463
+ }
464
+ catch (error) {
465
+ if (isPathChangedError(error)) {
466
+ throw pathChangedError(sourcePath);
467
+ }
468
+ throw error;
469
+ }
470
+ }
471
+ async function realpathStableLocalSourcePath(sourcePath, pathChangedError = localDirPathChangedError) {
472
+ try {
473
+ return await realpath(sourcePath);
474
+ }
475
+ catch (error) {
476
+ if (isPathChangedError(error)) {
477
+ throw pathChangedError(sourcePath);
478
+ }
479
+ throw error;
480
+ }
481
+ }
482
+ function localDirPathChangedError(sourcePath) {
483
+ return new UserError(`local_dir entry path changed while materializing: ${sourcePath}`);
484
+ }
485
+ function localFilePathChangedError(sourcePath) {
486
+ return new UserError(`local_file entry path changed while materializing: ${sourcePath}`);
487
+ }
488
+ function isPathChangedError(error) {
489
+ return (typeof error === 'object' &&
490
+ error !== null &&
491
+ 'code' in error &&
492
+ (error.code === 'ELOOP' ||
493
+ error.code === 'ENOENT' ||
494
+ error.code === 'ENOTDIR'));
495
+ }
496
+ async function assertStableLocalDirChild(sourceRoot, sourcePath) {
497
+ // local_dir deliberately rejects symlinks so a host-side source cannot smuggle
498
+ // files outside the declared directory into the sandbox.
499
+ const sourceStat = await statStableLocalSourcePath(sourcePath);
500
+ if (sourceStat.isSymbolicLink()) {
501
+ throw new UserError(`local_dir entries do not support symbolic links: ${sourcePath}`);
502
+ }
503
+ if (!sourceStat.isDirectory()) {
504
+ throw localDirPathChangedError(sourcePath);
505
+ }
506
+ const resolvedSourcePath = await realpathStableLocalSourcePath(sourcePath);
507
+ if (!isHostPathStrictlyWithinRoot(sourceRoot, resolvedSourcePath)) {
508
+ throw localDirPathChangedError(sourcePath);
509
+ }
510
+ return sourceStat;
511
+ }
512
+ function sameFilesystemEntry(left, right) {
513
+ return left.dev === right.dev && left.ino === right.ino;
514
+ }
515
+ async function materializeGitRepoEntry(workspaceRootPath, destination, entry, logicalPath) {
516
+ const gitVersion = await runSandboxProcess('git', ['--version'], {
517
+ timeoutMs: GIT_VERSION_TIMEOUT_MS,
518
+ });
519
+ if (gitVersion.status !== 0) {
520
+ throw new UserError('git_repo entries require a local `git` executable, but `git` was not found.');
521
+ }
522
+ const repository = normalizeGitRepository(entry);
523
+ const cloneIntoTemporaryDirectory = Boolean(entry.subpath) ||
524
+ Boolean(entry.ref && looksLikeCommitRef(entry.ref));
525
+ const cloneDestination = cloneIntoTemporaryDirectory
526
+ ? await mkdtemp(join(tmpdir(), 'openai-agents-git-repo-'))
527
+ : destination;
528
+ try {
529
+ if (cloneIntoTemporaryDirectory) {
530
+ await mkdir(dirname(cloneDestination), { recursive: true });
531
+ }
532
+ else {
533
+ await createMaterializationParentDirectory(workspaceRootPath, cloneDestination, logicalPath);
534
+ }
535
+ const { result: cloneResult, commitFetchError } = await cloneGitRepo(repository, cloneDestination, entry.ref);
536
+ if (cloneResult.status !== 0) {
537
+ throw new UserError(`Failed to materialize git_repo entry ${entry.repo}: ${formatSandboxProcessError(commitFetchError ?? cloneResult)}`);
538
+ }
539
+ if (!cloneIntoTemporaryDirectory) {
540
+ await assertSafeMaterializationPath(workspaceRootPath, destination, logicalPath);
541
+ return;
542
+ }
543
+ const sourcePath = entry.subpath
544
+ ? resolve(cloneDestination, entry.subpath)
545
+ : cloneDestination;
546
+ if (entry.subpath) {
547
+ const cloneRoot = await realpath(cloneDestination);
548
+ const subpathRealpath = await realpath(sourcePath);
549
+ if (!isHostPathStrictlyWithinRoot(cloneRoot, subpathRealpath)) {
550
+ throw new UserError(`git_repo subpath escapes the cloned repository: ${entry.subpath}`);
551
+ }
552
+ }
553
+ const sourceInfo = await lstat(sourcePath);
554
+ if (sourceInfo.isDirectory()) {
555
+ await copyLocalDirectory(sourcePath, destination, {}, workspaceRootPath, logicalPath);
556
+ return;
557
+ }
558
+ if (sourceInfo.isFile()) {
559
+ await createMaterializationParentDirectory(workspaceRootPath, destination, logicalPath);
560
+ await writeMaterializationFile(workspaceRootPath, destination, logicalPath, await readFile(sourcePath));
561
+ return;
562
+ }
563
+ throw new UserError(`git_repo subpath must resolve to a file or directory: ${entry.subpath}`);
564
+ }
565
+ finally {
566
+ if (cloneIntoTemporaryDirectory) {
567
+ await rm(cloneDestination, { recursive: true, force: true });
568
+ }
569
+ }
570
+ }
571
+ async function cloneGitRepo(repository, destination, ref) {
572
+ if (!ref || !looksLikeCommitRef(ref)) {
573
+ return { result: await cloneNamedRef(repository, destination, ref) };
574
+ }
575
+ // Branch/tag shallow clone does not reliably fetch arbitrary SHAs, so commit-looking
576
+ // refs take the explicit init/fetch/checkout path first.
577
+ const result = await fetchCommitRef(repository, destination, ref);
578
+ if (result.status === 0) {
579
+ return { result };
580
+ }
581
+ await rm(destination, { recursive: true, force: true });
582
+ return {
583
+ result: await cloneNamedRef(repository, destination, ref),
584
+ commitFetchError: result,
585
+ };
586
+ }
587
+ async function cloneNamedRef(repository, destination, ref) {
588
+ const args = ['clone', '--depth', '1'];
589
+ if (ref) {
590
+ args.push('--branch', ref);
591
+ }
592
+ args.push(repository, destination);
593
+ return await runSandboxProcess('git', args, {
594
+ timeoutMs: GIT_CLONE_TIMEOUT_MS,
595
+ });
596
+ }
597
+ async function fetchCommitRef(repository, destination, ref) {
598
+ const steps = [
599
+ ['init', destination],
600
+ ['-C', destination, 'remote', 'add', 'origin', repository],
601
+ ['-C', destination, 'fetch', '--depth', '1', '--no-tags', 'origin', ref],
602
+ ['-C', destination, 'checkout', '--detach', 'FETCH_HEAD'],
603
+ ];
604
+ for (const args of steps) {
605
+ const result = await runSandboxProcess('git', args, {
606
+ timeoutMs: GIT_CLONE_TIMEOUT_MS,
607
+ });
608
+ if (result.status !== 0) {
609
+ return result;
610
+ }
611
+ }
612
+ return {
613
+ status: 0,
614
+ signal: null,
615
+ stdout: '',
616
+ stderr: '',
617
+ timedOut: false,
618
+ };
619
+ }
620
+ function looksLikeCommitRef(ref) {
621
+ return COMMIT_REF_PATTERN.test(ref);
622
+ }
623
+ async function runLimited(items, limit, fn) {
624
+ if (items.length === 0) {
625
+ return;
626
+ }
627
+ if (limit <= 1) {
628
+ for (const item of items) {
629
+ await fn(item);
630
+ }
631
+ return;
632
+ }
633
+ let nextIndex = 0;
634
+ // This intentionally stays as a tiny work queue rather than adding a dependency for
635
+ // the few manifest and local_dir concurrency limits used here.
636
+ const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
637
+ while (nextIndex < items.length) {
638
+ const item = items[nextIndex++];
639
+ await fn(item);
640
+ }
641
+ });
642
+ await Promise.all(workers);
643
+ }
644
+ function resolveManifestEntryConcurrency(limits) {
645
+ return normalizeConcurrencyLimit(limits?.manifestEntries, 4);
646
+ }
647
+ function resolveLocalDirEntryConcurrency(limits) {
648
+ return normalizeConcurrencyLimit(limits?.localDirFiles, 4);
649
+ }
650
+ function normalizeConcurrencyLimit(value, fallback) {
651
+ if (value === undefined) {
652
+ return fallback;
653
+ }
654
+ if (!Number.isFinite(value) || value < 1) {
655
+ throw new UserError('Sandbox concurrency limits must be positive numbers.');
656
+ }
657
+ return Math.floor(value);
658
+ }
659
+ function joinLogicalPath(parent, child) {
660
+ const normalizedChild = normalizeRelativePath(child);
661
+ if (!parent || parent === '.') {
662
+ return normalizedChild;
663
+ }
664
+ return `${parent.replace(/\/+$/u, '')}/${normalizedChild}`;
665
+ }
666
+ async function applyEntryPermissions(workspaceRootPath, destination, entry, logicalPath) {
667
+ await assertSafeMaterializationPath(workspaceRootPath, destination, logicalPath);
668
+ const permissions = permissionsForSandboxEntry(entry.permissions);
669
+ await chmod(destination, permissions.toMode() & 0o777);
670
+ }
671
+ function materializationEscapesWorkspaceError(logicalPath) {
672
+ return new UserError(`Sandbox materialization path "${logicalPath || '.'}" escapes the workspace root.`);
673
+ }
674
+ function normalizeGitRepository(entry) {
675
+ const repository = entry.repo;
676
+ if (!repository) {
677
+ throw new UserError('git_repo entries require a repo.');
678
+ }
679
+ if (repository.includes('://') || repository.startsWith('git@')) {
680
+ return repository;
681
+ }
682
+ return `https://${entry.host ?? 'github.com'}/${repository}.git`;
683
+ }
684
+ //# sourceMappingURL=localWorkspace.mjs.map