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