@openai/agents-core 0.8.5 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +15 -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 +116 -57
- package/dist/run.js.map +1 -1
- package/dist/run.mjs +117 -58
- package/dist/run.mjs.map +1 -1
- package/dist/runState.d.ts +83 -1
- package/dist/runState.js +96 -11
- package/dist/runState.js.map +1 -1
- package/dist/runState.mjs +95 -11
- 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/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/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,863 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnixLocalSandboxClient = exports.UnixLocalSandboxSession = void 0;
|
|
4
|
+
const errors_1 = require("../../errors.js");
|
|
5
|
+
const applyDiff_1 = require("../../utils/applyDiff.js");
|
|
6
|
+
const promises_1 = require("node:fs/promises");
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_child_process_1 = require("node:child_process");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const node_os_1 = require("node:os");
|
|
11
|
+
const client_1 = require("../client.js");
|
|
12
|
+
const session_1 = require("../session.js");
|
|
13
|
+
const manifest_1 = require("../manifest.js");
|
|
14
|
+
const errors_2 = require("../errors.js");
|
|
15
|
+
const workspacePaths_1 = require("../workspacePaths.js");
|
|
16
|
+
const localWorkspace_1 = require("./shared/localWorkspace.js");
|
|
17
|
+
const manifestPersistence_1 = require("./shared/manifestPersistence.js");
|
|
18
|
+
const hostPath_1 = require("../shared/hostPath.js");
|
|
19
|
+
const media_1 = require("../shared/media.js");
|
|
20
|
+
const output_1 = require("../shared/output.js");
|
|
21
|
+
const localSnapshots_1 = require("./shared/localSnapshots.js");
|
|
22
|
+
const pty_1 = require("./shared/pty.js");
|
|
23
|
+
const runProcess_1 = require("./shared/runProcess.js");
|
|
24
|
+
const shellCommand_1 = require("./shared/shellCommand.js");
|
|
25
|
+
const sessionStateValues_1 = require("./shared/sessionStateValues.js");
|
|
26
|
+
const DEFAULT_EXEC_YIELD_TIME_MS = 10_000;
|
|
27
|
+
const DEFAULT_WRITE_STDIN_YIELD_TIME_MS = 250;
|
|
28
|
+
const MAX_ACTIVE_PROCESS_OUTPUT_CHARS = 1024 * 1024;
|
|
29
|
+
const RUN_AS_LOOKUP_TIMEOUT_MS = 10_000;
|
|
30
|
+
const DEFAULT_SANDBOX_COMMAND_PATH = '/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin';
|
|
31
|
+
class UnixLocalSandboxSession {
|
|
32
|
+
state;
|
|
33
|
+
defaultShell;
|
|
34
|
+
activeProcesses = new Map();
|
|
35
|
+
nextSessionId = 1;
|
|
36
|
+
closed = false;
|
|
37
|
+
constructor(args) {
|
|
38
|
+
this.state = args.state;
|
|
39
|
+
this.defaultShell = args.defaultShell;
|
|
40
|
+
}
|
|
41
|
+
createEditor(runAs) {
|
|
42
|
+
return new UnixLocalSandboxEditor(this, runAs);
|
|
43
|
+
}
|
|
44
|
+
supportsPty() {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
async resolveExposedPort(port) {
|
|
48
|
+
const exposedPort = (0, session_1.normalizeExposedPort)(port);
|
|
49
|
+
const configuredPorts = this.state.configuredExposedPorts ?? [];
|
|
50
|
+
if (configuredPorts.length > 0 && !configuredPorts.includes(exposedPort)) {
|
|
51
|
+
throw new errors_2.SandboxConfigurationError(`UnixLocalSandboxClient was not configured to expose port ${exposedPort}.`, {
|
|
52
|
+
provider: 'UnixLocalSandboxClient',
|
|
53
|
+
port: exposedPort,
|
|
54
|
+
configuredPorts,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return (0, session_1.recordExposedPortEndpoint)(this.state, {
|
|
58
|
+
host: '127.0.0.1',
|
|
59
|
+
port: exposedPort,
|
|
60
|
+
tls: false,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async execCommand(args) {
|
|
64
|
+
return (0, output_1.formatExecResponse)(await this.exec(args));
|
|
65
|
+
}
|
|
66
|
+
async exec(args) {
|
|
67
|
+
const start = Date.now();
|
|
68
|
+
const cwd = this.resolveCommandWorkdir(args.workdir);
|
|
69
|
+
const logicalCwd = this.logicalWorkdirForPath(args.workdir);
|
|
70
|
+
const child = await this.spawnShellCommand(this.translateCommandInput(args.cmd), {
|
|
71
|
+
cwd,
|
|
72
|
+
logicalCwd,
|
|
73
|
+
shell: args.shell,
|
|
74
|
+
login: args.login ?? true,
|
|
75
|
+
runAs: args.runAs,
|
|
76
|
+
tty: args.tty ?? false,
|
|
77
|
+
});
|
|
78
|
+
const activeProcess = this.trackChildProcess(child, {
|
|
79
|
+
tty: args.tty ?? false,
|
|
80
|
+
});
|
|
81
|
+
if (!args.tty) {
|
|
82
|
+
await waitForProcessOrTimeout(activeProcess, args.yieldTimeMs ?? DEFAULT_EXEC_YIELD_TIME_MS);
|
|
83
|
+
const processOutput = consumeActiveProcessOutput(activeProcess);
|
|
84
|
+
if (activeProcess.done) {
|
|
85
|
+
const output = (0, output_1.truncateOutput)(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
86
|
+
return {
|
|
87
|
+
output: output.text,
|
|
88
|
+
stdout: this.translateCommandOutput(processOutput.stdout),
|
|
89
|
+
stderr: this.translateCommandOutput(processOutput.stderr),
|
|
90
|
+
wallTimeSeconds: (0, output_1.elapsedSeconds)(start),
|
|
91
|
+
exitCode: activeProcess.exitCode ?? 1,
|
|
92
|
+
originalTokenCount: output.originalTokenCount,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const output = (0, output_1.truncateOutput)(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
96
|
+
const sessionId = this.allocateProcessId(activeProcess);
|
|
97
|
+
return {
|
|
98
|
+
output: output.text,
|
|
99
|
+
stdout: this.translateCommandOutput(processOutput.stdout),
|
|
100
|
+
stderr: this.translateCommandOutput(processOutput.stderr),
|
|
101
|
+
wallTimeSeconds: (0, output_1.elapsedSeconds)(start),
|
|
102
|
+
sessionId,
|
|
103
|
+
originalTokenCount: output.originalTokenCount,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const yieldTimeMs = args.yieldTimeMs ?? DEFAULT_EXEC_YIELD_TIME_MS;
|
|
107
|
+
await waitForProcessOrTimeout(activeProcess, yieldTimeMs);
|
|
108
|
+
if (activeProcess.done) {
|
|
109
|
+
const processOutput = consumeActiveProcessOutput(activeProcess);
|
|
110
|
+
const output = (0, output_1.truncateOutput)(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
111
|
+
return {
|
|
112
|
+
output: output.text,
|
|
113
|
+
stdout: this.translateCommandOutput(processOutput.stdout),
|
|
114
|
+
stderr: this.translateCommandOutput(processOutput.stderr),
|
|
115
|
+
wallTimeSeconds: (0, output_1.elapsedSeconds)(start),
|
|
116
|
+
exitCode: activeProcess.exitCode ?? 1,
|
|
117
|
+
originalTokenCount: output.originalTokenCount,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const sessionId = this.allocateProcessId(activeProcess);
|
|
121
|
+
const processOutput = consumeActiveProcessOutput(activeProcess);
|
|
122
|
+
const output = (0, output_1.truncateOutput)(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
123
|
+
return {
|
|
124
|
+
output: output.text,
|
|
125
|
+
stdout: this.translateCommandOutput(processOutput.stdout),
|
|
126
|
+
stderr: this.translateCommandOutput(processOutput.stderr),
|
|
127
|
+
wallTimeSeconds: (0, output_1.elapsedSeconds)(start),
|
|
128
|
+
sessionId,
|
|
129
|
+
originalTokenCount: output.originalTokenCount,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async writeStdin(args) {
|
|
133
|
+
const activeProcess = this.activeProcesses.get(args.sessionId);
|
|
134
|
+
if (!activeProcess) {
|
|
135
|
+
return (0, output_1.formatExecResponse)({
|
|
136
|
+
output: `write_stdin failed: session not found: ${args.sessionId}`,
|
|
137
|
+
wallTimeSeconds: 0,
|
|
138
|
+
exitCode: 1,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const start = Date.now();
|
|
142
|
+
const chars = args.chars ?? '';
|
|
143
|
+
if (!activeProcess.tty && chars.includes('\u0003')) {
|
|
144
|
+
activeProcess.child.kill('SIGINT');
|
|
145
|
+
}
|
|
146
|
+
const remainingChars = activeProcess.tty
|
|
147
|
+
? chars
|
|
148
|
+
: chars.split('\u0003').join('');
|
|
149
|
+
if (remainingChars.length > 0) {
|
|
150
|
+
activeProcess.child.stdin.write(remainingChars);
|
|
151
|
+
}
|
|
152
|
+
await waitForProcessOrTimeout(activeProcess, args.yieldTimeMs ?? DEFAULT_WRITE_STDIN_YIELD_TIME_MS);
|
|
153
|
+
const processOutput = consumeActiveProcessOutput(activeProcess);
|
|
154
|
+
const output = (0, output_1.truncateOutput)(this.translateCommandOutput(processOutput.output), args.maxOutputTokens);
|
|
155
|
+
if (activeProcess.done) {
|
|
156
|
+
this.activeProcesses.delete(args.sessionId);
|
|
157
|
+
return (0, output_1.formatExecResponse)({
|
|
158
|
+
output: output.text,
|
|
159
|
+
wallTimeSeconds: (0, output_1.elapsedSeconds)(start),
|
|
160
|
+
exitCode: activeProcess.exitCode ?? 1,
|
|
161
|
+
originalTokenCount: output.originalTokenCount,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return (0, output_1.formatExecResponse)({
|
|
165
|
+
output: output.text,
|
|
166
|
+
wallTimeSeconds: (0, output_1.elapsedSeconds)(start),
|
|
167
|
+
sessionId: args.sessionId,
|
|
168
|
+
originalTokenCount: output.originalTokenCount,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async viewImage(args) {
|
|
172
|
+
await this.resolveFilesystemRunAs(args.runAs);
|
|
173
|
+
const filePath = this.resolveSandboxPath(args.path);
|
|
174
|
+
const info = await (0, promises_1.stat)(filePath).catch(() => {
|
|
175
|
+
throw new errors_1.UserError(`Image file not found: ${args.path}`);
|
|
176
|
+
});
|
|
177
|
+
if (!info.isFile()) {
|
|
178
|
+
throw new errors_1.UserError(`Image path is not a file: ${args.path}`);
|
|
179
|
+
}
|
|
180
|
+
(0, media_1.assertViewImageByteLength)(args.path, info.size);
|
|
181
|
+
const bytes = await (0, promises_1.readFile)(filePath);
|
|
182
|
+
return (0, media_1.imageOutputFromBytes)(args.path, bytes);
|
|
183
|
+
}
|
|
184
|
+
async pathExists(path, runAs) {
|
|
185
|
+
await this.resolveFilesystemRunAs(runAs);
|
|
186
|
+
return await (0, localWorkspace_1.pathExists)(this.resolveSandboxPath(path));
|
|
187
|
+
}
|
|
188
|
+
async readFile(args) {
|
|
189
|
+
await this.resolveFilesystemRunAs(args.runAs);
|
|
190
|
+
const bytes = await (0, promises_1.readFile)(this.resolveSandboxPath(args.path));
|
|
191
|
+
if (typeof args.maxBytes === 'number' && bytes.byteLength > args.maxBytes) {
|
|
192
|
+
return bytes.subarray(0, args.maxBytes);
|
|
193
|
+
}
|
|
194
|
+
return bytes;
|
|
195
|
+
}
|
|
196
|
+
async listDir(args) {
|
|
197
|
+
await this.resolveFilesystemRunAs(args.runAs);
|
|
198
|
+
const logicalPath = this.resolveLogicalPath(args.path);
|
|
199
|
+
const entries = await (0, promises_1.readdir)(this.resolveSandboxPath(args.path), {
|
|
200
|
+
withFileTypes: true,
|
|
201
|
+
});
|
|
202
|
+
return entries.map((entry) => ({
|
|
203
|
+
name: entry.name,
|
|
204
|
+
path: logicalPath ? `${logicalPath}/${entry.name}` : entry.name,
|
|
205
|
+
type: entry.isDirectory() ? 'dir' : entry.isFile() ? 'file' : 'other',
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
async materializeEntry(args) {
|
|
209
|
+
const runAs = await this.resolveFilesystemRunAs(args.runAs);
|
|
210
|
+
const logicalPath = this.resolveLogicalPath(args.path);
|
|
211
|
+
await (0, localWorkspace_1.materializeLocalWorkspaceManifestEntry)(this.state.workspaceRootPath, logicalPath, args.entry);
|
|
212
|
+
if (runAs) {
|
|
213
|
+
await (0, localWorkspace_1.applyOwnershipRecursive)(this.resolveSandboxPath(args.path), runAs.uid, runAs.gid);
|
|
214
|
+
}
|
|
215
|
+
this.state.manifest = (0, manifestPersistence_1.mergeManifestEntryDelta)(this.state.manifest, logicalPath, args.entry);
|
|
216
|
+
}
|
|
217
|
+
async applyManifest(manifest, runAs) {
|
|
218
|
+
(0, localWorkspace_1.assertLocalWorkspaceManifestMetadataSupported)('UnixLocalSandboxClient', manifest);
|
|
219
|
+
const identity = await this.resolveFilesystemRunAs(runAs);
|
|
220
|
+
await (0, localWorkspace_1.materializeLocalWorkspaceManifest)(manifest, this.state.workspaceRootPath);
|
|
221
|
+
const environment = await manifest.resolveEnvironment();
|
|
222
|
+
if (identity) {
|
|
223
|
+
for (const path of Object.keys(manifest.entries)) {
|
|
224
|
+
await (0, localWorkspace_1.applyOwnershipRecursive)(this.resolveSandboxPath(path), identity.uid, identity.gid);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
this.state.environment = {
|
|
228
|
+
...this.state.environment,
|
|
229
|
+
...environment,
|
|
230
|
+
};
|
|
231
|
+
this.state.manifest = (0, manifestPersistence_1.mergeManifestDelta)(this.state.manifest, manifest);
|
|
232
|
+
}
|
|
233
|
+
async persistWorkspace() {
|
|
234
|
+
return await (0, localSnapshots_1.createWorkspaceArchive)(this.state.workspaceRootPath, this.state.manifest.ephemeralPersistencePaths());
|
|
235
|
+
}
|
|
236
|
+
async hydrateWorkspace(data) {
|
|
237
|
+
await (0, localSnapshots_1.restoreWorkspaceArchive)(data, this.state.workspaceRootPath);
|
|
238
|
+
await this.materializeRestoredWorkspaceMounts();
|
|
239
|
+
}
|
|
240
|
+
async stop() {
|
|
241
|
+
await this.stopActiveProcesses();
|
|
242
|
+
}
|
|
243
|
+
async shutdown() {
|
|
244
|
+
await this.close();
|
|
245
|
+
}
|
|
246
|
+
async delete() {
|
|
247
|
+
await this.close();
|
|
248
|
+
}
|
|
249
|
+
async close() {
|
|
250
|
+
if (this.closed) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
this.closed = true;
|
|
254
|
+
await this.stopActiveProcesses();
|
|
255
|
+
if (this.state.workspaceRootOwned) {
|
|
256
|
+
await (0, promises_1.rm)(this.state.workspaceRootPath, { recursive: true, force: true });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async stopActiveProcesses() {
|
|
260
|
+
await Promise.all([...this.activeProcesses.values()].map(async (activeProcess) => {
|
|
261
|
+
if (!activeProcess.done) {
|
|
262
|
+
activeProcess.child.kill('SIGTERM');
|
|
263
|
+
await waitForProcessOrTimeout(activeProcess, 250);
|
|
264
|
+
}
|
|
265
|
+
if (!activeProcess.done) {
|
|
266
|
+
activeProcess.child.kill('SIGKILL');
|
|
267
|
+
await activeProcess.donePromise.catch(() => { });
|
|
268
|
+
}
|
|
269
|
+
}));
|
|
270
|
+
this.activeProcesses.clear();
|
|
271
|
+
}
|
|
272
|
+
resolveSandboxPath(path, options = {}) {
|
|
273
|
+
const resolved = this.resolveSandboxPathTarget(path, options);
|
|
274
|
+
const workspaceRelativePath = resolved.workspaceRelativePath ?? '';
|
|
275
|
+
if (!workspaceRelativePath && !resolved.grant) {
|
|
276
|
+
return this.state.workspaceRootPath;
|
|
277
|
+
}
|
|
278
|
+
if (resolved.grant) {
|
|
279
|
+
return validateResolvedHostPath({
|
|
280
|
+
path,
|
|
281
|
+
resolvedPath: resolved.path,
|
|
282
|
+
allowedRoot: resolved.grant.path,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
const mountPath = this.resolveLocalBindMountPath(workspaceRelativePath, path, options);
|
|
286
|
+
if (mountPath) {
|
|
287
|
+
return mountPath;
|
|
288
|
+
}
|
|
289
|
+
const resolvedPath = (0, node_path_1.resolve)(this.state.workspaceRootPath, workspaceRelativePath);
|
|
290
|
+
const relativeToRoot = (0, node_path_1.relative)(this.state.workspaceRootPath, resolvedPath);
|
|
291
|
+
if ((0, hostPath_1.relativeHostPathEscapesRoot)(relativeToRoot)) {
|
|
292
|
+
throw new errors_1.UserError(`Sandbox path "${path}" escapes the workspace root.`);
|
|
293
|
+
}
|
|
294
|
+
return validateResolvedHostPath({
|
|
295
|
+
path,
|
|
296
|
+
resolvedPath,
|
|
297
|
+
allowedRoot: this.state.workspaceRootPath,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
resolveCommandWorkdir(path) {
|
|
301
|
+
return this.resolveSandboxPath(path);
|
|
302
|
+
}
|
|
303
|
+
resolveSandboxPathTarget(path, options = {}) {
|
|
304
|
+
return new workspacePaths_1.WorkspacePathPolicy({
|
|
305
|
+
root: this.state.manifest.root,
|
|
306
|
+
extraPathGrants: this.state.manifest.extraPathGrants,
|
|
307
|
+
}).resolve(path, options);
|
|
308
|
+
}
|
|
309
|
+
resolveLocalBindMountPath(workspaceRelativePath, path, options) {
|
|
310
|
+
for (const { entry, mountPath } of this.state.manifest.mountTargets()) {
|
|
311
|
+
const source = localBindMountSource(entry);
|
|
312
|
+
if (!source) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const mountRelativePath = new workspacePaths_1.WorkspacePathPolicy({
|
|
316
|
+
root: this.state.manifest.root,
|
|
317
|
+
}).resolve(mountPath).workspaceRelativePath;
|
|
318
|
+
if (typeof mountRelativePath !== 'string') {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (!pathWithinLogicalRoot(workspaceRelativePath, mountRelativePath)) {
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (options.forWrite && entry.readOnly !== false) {
|
|
325
|
+
throw new errors_1.UserError(`Sandbox path "${path}" is inside a read-only local bind mount.`);
|
|
326
|
+
}
|
|
327
|
+
const childPath = workspaceRelativePath === mountRelativePath
|
|
328
|
+
? ''
|
|
329
|
+
: workspaceRelativePath.slice(mountRelativePath.length + 1);
|
|
330
|
+
const resolvedPath = childPath ? (0, node_path_1.resolve)(source, childPath) : source;
|
|
331
|
+
return validateResolvedHostPath({
|
|
332
|
+
path,
|
|
333
|
+
resolvedPath,
|
|
334
|
+
allowedRoot: source,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
resolveLogicalPath(path) {
|
|
340
|
+
if (!path || path.trim().length === 0) {
|
|
341
|
+
return '';
|
|
342
|
+
}
|
|
343
|
+
const logicalRoot = this.state.manifest.root;
|
|
344
|
+
const trimmed = path.trim();
|
|
345
|
+
if (trimmed === logicalRoot) {
|
|
346
|
+
return '';
|
|
347
|
+
}
|
|
348
|
+
if (logicalRoot === '/') {
|
|
349
|
+
return (0, manifest_1.normalizeRelativePath)(trimmed.startsWith('/') ? trimmed.slice(1) : trimmed);
|
|
350
|
+
}
|
|
351
|
+
if (trimmed.startsWith(`${logicalRoot}/`)) {
|
|
352
|
+
return (0, manifest_1.normalizeRelativePath)(trimmed.slice(logicalRoot.length + 1));
|
|
353
|
+
}
|
|
354
|
+
if (trimmed.startsWith('/')) {
|
|
355
|
+
throw new errors_1.UserError(`Sandbox path "${path}" must stay within ${logicalRoot}.`);
|
|
356
|
+
}
|
|
357
|
+
return (0, manifest_1.normalizeRelativePath)(trimmed);
|
|
358
|
+
}
|
|
359
|
+
async spawnShellCommand(command, args) {
|
|
360
|
+
const { shellPath, flag } = (0, shellCommand_1.resolveLocalShellCommand)({
|
|
361
|
+
shell: args.shell,
|
|
362
|
+
defaultShell: this.defaultShell,
|
|
363
|
+
envShell: process.env.SHELL,
|
|
364
|
+
login: args.login,
|
|
365
|
+
});
|
|
366
|
+
const runAs = await this.resolveCommandRunAs(args.runAs);
|
|
367
|
+
const env = buildCommandEnvironment({
|
|
368
|
+
environment: this.state.environment,
|
|
369
|
+
shellPath,
|
|
370
|
+
home: this.state.workspaceRootPath,
|
|
371
|
+
pwd: args.logicalCwd,
|
|
372
|
+
});
|
|
373
|
+
if (args.tty) {
|
|
374
|
+
return (0, pty_1.spawnInPseudoTerminal)(shellPath, [flag, command], {
|
|
375
|
+
cwd: args.cwd,
|
|
376
|
+
env,
|
|
377
|
+
...(runAs
|
|
378
|
+
? {
|
|
379
|
+
uid: runAs.uid,
|
|
380
|
+
gid: runAs.gid,
|
|
381
|
+
}
|
|
382
|
+
: {}),
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
return (0, node_child_process_1.spawn)(shellPath, [flag, command], {
|
|
386
|
+
cwd: args.cwd,
|
|
387
|
+
env,
|
|
388
|
+
...(runAs
|
|
389
|
+
? {
|
|
390
|
+
uid: runAs.uid,
|
|
391
|
+
gid: runAs.gid,
|
|
392
|
+
}
|
|
393
|
+
: {}),
|
|
394
|
+
stdio: 'pipe',
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
translateCommandInput(command) {
|
|
398
|
+
// Unix-local is not a chroot; command rewriting preserves manifest-root UX while
|
|
399
|
+
// filesystem APIs continue to enforce host-path containment separately.
|
|
400
|
+
if (this.state.manifest.root === '/') {
|
|
401
|
+
return translateRootManifestCommandInput(command, this.state.workspaceRootPath);
|
|
402
|
+
}
|
|
403
|
+
return translateManifestRootCommandInput(command, this.state.manifest.root, this.state.workspaceRootPath);
|
|
404
|
+
}
|
|
405
|
+
translateCommandOutput(output) {
|
|
406
|
+
if (this.state.manifest.root === '/') {
|
|
407
|
+
return translateRootManifestCommandOutput(output, this.state.workspaceRootPath);
|
|
408
|
+
}
|
|
409
|
+
return translateManifestRootCommandOutput(output, this.state.manifest.root, this.state.workspaceRootPath);
|
|
410
|
+
}
|
|
411
|
+
async materializeRestoredWorkspaceMounts() {
|
|
412
|
+
await (0, localWorkspace_1.materializeLocalWorkspaceManifestMounts)(this.state.manifest, this.state.workspaceRootPath);
|
|
413
|
+
}
|
|
414
|
+
logicalWorkdirForPath(path) {
|
|
415
|
+
return this.resolveSandboxPathTarget(path).path;
|
|
416
|
+
}
|
|
417
|
+
async resolveCommandRunAs(runAs) {
|
|
418
|
+
const identity = await this.resolveRunAsIdentity(runAs);
|
|
419
|
+
if (!identity || identity.isCurrentUser) {
|
|
420
|
+
return identity;
|
|
421
|
+
}
|
|
422
|
+
if (typeof process.getuid !== 'function' || process.getuid() !== 0) {
|
|
423
|
+
throw new errors_1.UserError(`Unix-local sandbox runAs="${runAs}" requires the host process to run as root or the requested user.`);
|
|
424
|
+
}
|
|
425
|
+
return identity;
|
|
426
|
+
}
|
|
427
|
+
async resolveFilesystemRunAs(runAs) {
|
|
428
|
+
const identity = await this.resolveRunAsIdentity(runAs);
|
|
429
|
+
if (!identity || identity.isCurrentUser) {
|
|
430
|
+
return identity;
|
|
431
|
+
}
|
|
432
|
+
if (typeof process.getuid !== 'function' || process.getuid() !== 0) {
|
|
433
|
+
throw new errors_1.UserError(`Unix-local sandbox filesystem operations cannot honor runAs="${runAs}" without root privileges.`);
|
|
434
|
+
}
|
|
435
|
+
return identity;
|
|
436
|
+
}
|
|
437
|
+
async resolveRunAsIdentity(runAs) {
|
|
438
|
+
if (!runAs || runAs.trim().length === 0) {
|
|
439
|
+
return undefined;
|
|
440
|
+
}
|
|
441
|
+
const requestedUser = runAs.trim();
|
|
442
|
+
const currentUser = (0, node_os_1.userInfo)().username;
|
|
443
|
+
const currentUid = typeof process.getuid === 'function' ? process.getuid() : undefined;
|
|
444
|
+
const currentGid = typeof process.getgid === 'function' ? process.getgid() : undefined;
|
|
445
|
+
if (requestedUser === currentUser &&
|
|
446
|
+
currentUid !== undefined &&
|
|
447
|
+
currentGid !== undefined) {
|
|
448
|
+
return {
|
|
449
|
+
username: currentUser,
|
|
450
|
+
uid: currentUid,
|
|
451
|
+
gid: currentGid,
|
|
452
|
+
isCurrentUser: true,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
const [uidResult, gidResult] = await Promise.all([
|
|
456
|
+
(0, runProcess_1.runSandboxProcess)('id', ['-u', requestedUser], {
|
|
457
|
+
timeoutMs: RUN_AS_LOOKUP_TIMEOUT_MS,
|
|
458
|
+
}),
|
|
459
|
+
(0, runProcess_1.runSandboxProcess)('id', ['-g', requestedUser], {
|
|
460
|
+
timeoutMs: RUN_AS_LOOKUP_TIMEOUT_MS,
|
|
461
|
+
}),
|
|
462
|
+
]);
|
|
463
|
+
if (uidResult.status !== 0 || gidResult.status !== 0) {
|
|
464
|
+
throw new errors_1.UserError(`Sandbox runAs user "${requestedUser}" could not be resolved on this host.`);
|
|
465
|
+
}
|
|
466
|
+
const uid = Number(uidResult.stdout.trim());
|
|
467
|
+
const gid = Number(gidResult.stdout.trim());
|
|
468
|
+
return {
|
|
469
|
+
username: requestedUser,
|
|
470
|
+
uid,
|
|
471
|
+
gid,
|
|
472
|
+
isCurrentUser: currentUid !== undefined &&
|
|
473
|
+
currentGid !== undefined &&
|
|
474
|
+
uid === currentUid &&
|
|
475
|
+
gid === currentGid,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
trackChildProcess(child, options = {}) {
|
|
479
|
+
let resolveDone = () => { };
|
|
480
|
+
const donePromise = new Promise((resolve) => {
|
|
481
|
+
resolveDone = resolve;
|
|
482
|
+
});
|
|
483
|
+
let resolveOutputClosed = () => { };
|
|
484
|
+
const outputClosedPromise = new Promise((resolve) => {
|
|
485
|
+
resolveOutputClosed = resolve;
|
|
486
|
+
});
|
|
487
|
+
const activeProcess = {
|
|
488
|
+
child,
|
|
489
|
+
tty: options.tty ?? false,
|
|
490
|
+
output: '',
|
|
491
|
+
stdout: '',
|
|
492
|
+
stderr: '',
|
|
493
|
+
droppedOutputChars: 0,
|
|
494
|
+
droppedStdoutChars: 0,
|
|
495
|
+
droppedStderrChars: 0,
|
|
496
|
+
exitCode: null,
|
|
497
|
+
done: false,
|
|
498
|
+
donePromise,
|
|
499
|
+
resolveDone,
|
|
500
|
+
outputClosedPromise,
|
|
501
|
+
resolveOutputClosed,
|
|
502
|
+
};
|
|
503
|
+
let openOutputStreams = 2;
|
|
504
|
+
const markOutputStreamClosed = () => {
|
|
505
|
+
openOutputStreams -= 1;
|
|
506
|
+
if (openOutputStreams === 0) {
|
|
507
|
+
activeProcess.resolveOutputClosed();
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
child.stdout.setEncoding('utf8');
|
|
511
|
+
child.stderr.setEncoding('utf8');
|
|
512
|
+
child.stdout.on('data', (chunk) => {
|
|
513
|
+
appendActiveProcessOutput(activeProcess, chunk, 'stdout');
|
|
514
|
+
});
|
|
515
|
+
child.stderr.on('data', (chunk) => {
|
|
516
|
+
appendActiveProcessOutput(activeProcess, chunk, 'stderr');
|
|
517
|
+
});
|
|
518
|
+
child.stdout.once('close', markOutputStreamClosed);
|
|
519
|
+
child.stderr.once('close', markOutputStreamClosed);
|
|
520
|
+
child.on('close', (code, signal) => {
|
|
521
|
+
activeProcess.exitCode = code ?? signalToExitCode(signal);
|
|
522
|
+
activeProcess.done = true;
|
|
523
|
+
activeProcess.resolveDone();
|
|
524
|
+
});
|
|
525
|
+
child.on('error', (error) => {
|
|
526
|
+
appendActiveProcessOutput(activeProcess, `${error.message}\n`, 'stderr');
|
|
527
|
+
activeProcess.exitCode = 1;
|
|
528
|
+
activeProcess.done = true;
|
|
529
|
+
activeProcess.resolveOutputClosed();
|
|
530
|
+
activeProcess.resolveDone();
|
|
531
|
+
});
|
|
532
|
+
return activeProcess;
|
|
533
|
+
}
|
|
534
|
+
allocateProcessId(activeProcess) {
|
|
535
|
+
const sessionId = this.nextSessionId++;
|
|
536
|
+
this.activeProcesses.set(sessionId, activeProcess);
|
|
537
|
+
return sessionId;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
exports.UnixLocalSandboxSession = UnixLocalSandboxSession;
|
|
541
|
+
class UnixLocalSandboxClient {
|
|
542
|
+
backendId = 'unix_local';
|
|
543
|
+
supportsDefaultOptions = true;
|
|
544
|
+
options;
|
|
545
|
+
constructor(options = {}) {
|
|
546
|
+
this.options = options;
|
|
547
|
+
}
|
|
548
|
+
async create(args, manifestOptions) {
|
|
549
|
+
const createArgs = (0, client_1.normalizeSandboxClientCreateArgs)(args, manifestOptions);
|
|
550
|
+
const manifest = createArgs.manifest;
|
|
551
|
+
const resolvedOptions = {
|
|
552
|
+
...this.options,
|
|
553
|
+
...createArgs.options,
|
|
554
|
+
...(createArgs.snapshot
|
|
555
|
+
? { snapshot: createArgs.snapshot }
|
|
556
|
+
: {}),
|
|
557
|
+
...(createArgs.concurrencyLimits
|
|
558
|
+
? { concurrencyLimits: createArgs.concurrencyLimits }
|
|
559
|
+
: {}),
|
|
560
|
+
};
|
|
561
|
+
(0, localWorkspace_1.assertLocalWorkspaceManifestMetadataSupported)('UnixLocalSandboxClient', manifest);
|
|
562
|
+
const workspaceRootPath = await (0, promises_1.mkdtemp)((0, node_path_1.join)(resolvedOptions.workspaceBaseDir ?? (0, node_os_1.tmpdir)(), 'openai-agents-sandbox-'));
|
|
563
|
+
await (0, localWorkspace_1.materializeLocalWorkspaceManifest)(manifest, workspaceRootPath, {
|
|
564
|
+
concurrencyLimits: resolvedOptions.concurrencyLimits,
|
|
565
|
+
});
|
|
566
|
+
const environment = await manifest.resolveEnvironment();
|
|
567
|
+
const configuredExposedPorts = (0, sessionStateValues_1.normalizeExposedPorts)(resolvedOptions.exposedPorts);
|
|
568
|
+
return new UnixLocalSandboxSession({
|
|
569
|
+
state: {
|
|
570
|
+
manifest,
|
|
571
|
+
workspaceRootPath,
|
|
572
|
+
workspaceRootOwned: true,
|
|
573
|
+
environment,
|
|
574
|
+
snapshotSpec: resolvedOptions.snapshot ?? null,
|
|
575
|
+
snapshot: null,
|
|
576
|
+
configuredExposedPorts,
|
|
577
|
+
},
|
|
578
|
+
defaultShell: resolvedOptions.defaultShell,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
async resume(state) {
|
|
582
|
+
const restoredState = await this.restoreIfNeeded(state);
|
|
583
|
+
return new UnixLocalSandboxSession({
|
|
584
|
+
state: restoredState,
|
|
585
|
+
defaultShell: this.options.defaultShell,
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
async serializeSessionState(state) {
|
|
589
|
+
const snapshotSpec = state.snapshotSpec ?? this.options.snapshot ?? null;
|
|
590
|
+
const snapshot = await (0, localSnapshots_1.persistLocalSnapshot)('UnixLocalSandboxClient', state, snapshotSpec);
|
|
591
|
+
state.snapshotSpec = snapshotSpec;
|
|
592
|
+
return {
|
|
593
|
+
manifest: (0, manifestPersistence_1.serializeManifest)(state.manifest),
|
|
594
|
+
workspaceRootPath: state.workspaceRootPath,
|
|
595
|
+
workspaceRootOwned: state.workspaceRootOwned,
|
|
596
|
+
environment: (0, manifestPersistence_1.sanitizeEnvironmentForPersistence)(state),
|
|
597
|
+
snapshotSpec: (0, localSnapshots_1.serializeLocalSnapshotSpec)(snapshotSpec),
|
|
598
|
+
snapshot,
|
|
599
|
+
snapshotFingerprint: state.snapshotFingerprint ?? null,
|
|
600
|
+
snapshotFingerprintVersion: state.snapshotFingerprintVersion ?? null,
|
|
601
|
+
configuredExposedPorts: state.configuredExposedPorts ?? [],
|
|
602
|
+
exposedPorts: state.exposedPorts ?? null,
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
async deserializeSessionState(state) {
|
|
606
|
+
return (0, sessionStateValues_1.deserializeLocalSandboxSessionStateValues)(state, this.options.snapshot);
|
|
607
|
+
}
|
|
608
|
+
async restoreIfNeeded(state) {
|
|
609
|
+
if (await (0, localWorkspace_1.pathExists)(state.workspaceRootPath)) {
|
|
610
|
+
if (await (0, localSnapshots_1.canReuseLocalSnapshotWorkspace)(state)) {
|
|
611
|
+
return state;
|
|
612
|
+
}
|
|
613
|
+
if (await (0, localSnapshots_1.localSnapshotIsRestorable)(state)) {
|
|
614
|
+
return await restoreSnapshotAndMounts(state, state.workspaceRootPath);
|
|
615
|
+
}
|
|
616
|
+
return state;
|
|
617
|
+
}
|
|
618
|
+
if (!(await (0, localSnapshots_1.localSnapshotIsRestorable)(state))) {
|
|
619
|
+
throw new errors_1.UserError('UnixLocal sandbox workspace is unavailable and no local snapshot could be restored.');
|
|
620
|
+
}
|
|
621
|
+
const workspaceRootPath = await (0, promises_1.mkdtemp)((0, node_path_1.join)(this.options.workspaceBaseDir ?? (0, node_os_1.tmpdir)(), 'openai-agents-sandbox-'));
|
|
622
|
+
return await restoreSnapshotAndMounts({
|
|
623
|
+
...state,
|
|
624
|
+
workspaceRootPath,
|
|
625
|
+
workspaceRootOwned: true,
|
|
626
|
+
}, workspaceRootPath);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
exports.UnixLocalSandboxClient = UnixLocalSandboxClient;
|
|
630
|
+
async function restoreSnapshotAndMounts(state, workspaceRootPath) {
|
|
631
|
+
const restoredState = await (0, localSnapshots_1.restoreLocalSnapshotToWorkspace)(state, workspaceRootPath);
|
|
632
|
+
await (0, localWorkspace_1.materializeLocalWorkspaceManifestMounts)(restoredState.manifest, restoredState.workspaceRootPath);
|
|
633
|
+
return restoredState;
|
|
634
|
+
}
|
|
635
|
+
function localBindMountSource(entry) {
|
|
636
|
+
if (entry.type !== 'mount' || typeof entry.source !== 'string') {
|
|
637
|
+
return undefined;
|
|
638
|
+
}
|
|
639
|
+
if (entry.mountStrategy !== undefined &&
|
|
640
|
+
entry.mountStrategy.type !== 'local_bind') {
|
|
641
|
+
return undefined;
|
|
642
|
+
}
|
|
643
|
+
return (0, node_path_1.isAbsolute)(entry.source) ? entry.source : undefined;
|
|
644
|
+
}
|
|
645
|
+
function pathWithinLogicalRoot(path, root) {
|
|
646
|
+
return path === root || path.startsWith(`${root}/`);
|
|
647
|
+
}
|
|
648
|
+
function validateResolvedHostPath(args) {
|
|
649
|
+
const allowedRootRealPath = realpathForValidation(args.allowedRoot, args.path);
|
|
650
|
+
const existingPath = nearestExistingPath(args.resolvedPath);
|
|
651
|
+
if (!existingPath) {
|
|
652
|
+
throw new errors_1.UserError(`Sandbox path "${args.path}" escapes the workspace root.`);
|
|
653
|
+
}
|
|
654
|
+
const realPath = realpathForValidation(existingPath, args.path);
|
|
655
|
+
if (!(0, hostPath_1.isHostPathWithinRoot)(allowedRootRealPath, realPath)) {
|
|
656
|
+
throw new errors_1.UserError(`Sandbox path "${args.path}" escapes the workspace root.`);
|
|
657
|
+
}
|
|
658
|
+
return args.resolvedPath;
|
|
659
|
+
}
|
|
660
|
+
function nearestExistingPath(path) {
|
|
661
|
+
let current = path;
|
|
662
|
+
while (true) {
|
|
663
|
+
try {
|
|
664
|
+
(0, node_fs_1.lstatSync)(current);
|
|
665
|
+
return current;
|
|
666
|
+
}
|
|
667
|
+
catch (error) {
|
|
668
|
+
if (error.code !== 'ENOENT') {
|
|
669
|
+
throw error;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const parent = (0, node_path_1.dirname)(current);
|
|
673
|
+
if (parent === current) {
|
|
674
|
+
return undefined;
|
|
675
|
+
}
|
|
676
|
+
current = parent;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function realpathForValidation(path, originalPath) {
|
|
680
|
+
try {
|
|
681
|
+
return (0, node_fs_1.realpathSync)(path);
|
|
682
|
+
}
|
|
683
|
+
catch {
|
|
684
|
+
throw new errors_1.UserError(`Sandbox path "${originalPath}" escapes the workspace root.`);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
class UnixLocalSandboxEditor {
|
|
688
|
+
session;
|
|
689
|
+
runAs;
|
|
690
|
+
constructor(session, runAs) {
|
|
691
|
+
this.session = session;
|
|
692
|
+
this.runAs = runAs;
|
|
693
|
+
}
|
|
694
|
+
async createFile(operation) {
|
|
695
|
+
const identity = await this.session.resolveFilesystemRunAs(this.runAs);
|
|
696
|
+
const filePath = this.session.resolveSandboxPath(operation.path, {
|
|
697
|
+
forWrite: true,
|
|
698
|
+
});
|
|
699
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(filePath), { recursive: true });
|
|
700
|
+
const content = (0, applyDiff_1.applyDiff)('', operation.diff, 'create');
|
|
701
|
+
await (0, promises_1.writeFile)(filePath, content, { encoding: 'utf8', flag: 'wx' });
|
|
702
|
+
if (identity) {
|
|
703
|
+
await (0, localWorkspace_1.applyOwnershipRecursive)(filePath, identity.uid, identity.gid);
|
|
704
|
+
}
|
|
705
|
+
return {};
|
|
706
|
+
}
|
|
707
|
+
async updateFile(operation) {
|
|
708
|
+
const identity = await this.session.resolveFilesystemRunAs(this.runAs);
|
|
709
|
+
const moveTo = operation.moveTo;
|
|
710
|
+
const filePath = this.session.resolveSandboxPath(operation.path, {
|
|
711
|
+
forWrite: true,
|
|
712
|
+
});
|
|
713
|
+
const destinationPath = moveTo
|
|
714
|
+
? this.session.resolveSandboxPath(moveTo, { forWrite: true })
|
|
715
|
+
: filePath;
|
|
716
|
+
const current = await (0, promises_1.readFile)(filePath, 'utf8');
|
|
717
|
+
const next = (0, applyDiff_1.applyDiff)(current, operation.diff);
|
|
718
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(destinationPath), { recursive: true });
|
|
719
|
+
await (0, promises_1.writeFile)(destinationPath, next, 'utf8');
|
|
720
|
+
if (moveTo && destinationPath !== filePath) {
|
|
721
|
+
await (0, promises_1.unlink)(filePath);
|
|
722
|
+
}
|
|
723
|
+
if (identity) {
|
|
724
|
+
await (0, localWorkspace_1.applyOwnershipRecursive)(destinationPath, identity.uid, identity.gid);
|
|
725
|
+
}
|
|
726
|
+
return {};
|
|
727
|
+
}
|
|
728
|
+
async deleteFile(operation) {
|
|
729
|
+
await this.session.resolveFilesystemRunAs(this.runAs);
|
|
730
|
+
const filePath = this.session.resolveSandboxPath(operation.path, {
|
|
731
|
+
forWrite: true,
|
|
732
|
+
});
|
|
733
|
+
await (0, promises_1.unlink)(filePath);
|
|
734
|
+
return {};
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
function buildCommandEnvironment(args) {
|
|
738
|
+
return {
|
|
739
|
+
PATH: DEFAULT_SANDBOX_COMMAND_PATH,
|
|
740
|
+
HOME: args.home,
|
|
741
|
+
USER: 'sandbox',
|
|
742
|
+
LOGNAME: 'sandbox',
|
|
743
|
+
SHELL: args.shellPath,
|
|
744
|
+
TMPDIR: '/tmp',
|
|
745
|
+
...args.environment,
|
|
746
|
+
PWD: args.pwd,
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
function translateRootManifestCommandInput(command, workspaceRootPath) {
|
|
750
|
+
return command.replace(/(^|[\s"'=<>])\/([^\s"'|&;<>(){}]*)/g, (_match, prefix, pathSuffix) => `${prefix}${workspaceRootPath}/${pathSuffix}`);
|
|
751
|
+
}
|
|
752
|
+
function translateManifestRootCommandInput(command, manifestRoot, workspaceRootPath) {
|
|
753
|
+
const escapedManifestRoot = escapeRegExp(manifestRoot);
|
|
754
|
+
const pathPrefix = String.raw `(^|[\s"'=<>])`;
|
|
755
|
+
const pathSuffix = String.raw `(?=$|[\/\s"'|&;<>(){}])`;
|
|
756
|
+
return command.replace(new RegExp(`${pathPrefix}${escapedManifestRoot}${pathSuffix}`, 'g'), (_match, prefix) => `${prefix}${workspaceRootPath}`);
|
|
757
|
+
}
|
|
758
|
+
function translateRootManifestCommandOutput(output, workspaceRootPath) {
|
|
759
|
+
return translateWorkspaceRootCommandOutput(output, '/', workspaceRootPath);
|
|
760
|
+
}
|
|
761
|
+
function translateManifestRootCommandOutput(output, manifestRoot, workspaceRootPath) {
|
|
762
|
+
return translateWorkspaceRootCommandOutput(output, manifestRoot, workspaceRootPath);
|
|
763
|
+
}
|
|
764
|
+
function translateWorkspaceRootCommandOutput(output, manifestRoot, workspaceRootPath) {
|
|
765
|
+
const nestedPathReplacement = manifestRoot === '/' ? '/' : `${manifestRoot}/`;
|
|
766
|
+
let translated = output;
|
|
767
|
+
for (const path of workspaceRootOutputPaths(workspaceRootPath)) {
|
|
768
|
+
translated = translated
|
|
769
|
+
.split(`${path}/`)
|
|
770
|
+
.join(nestedPathReplacement)
|
|
771
|
+
.split(path)
|
|
772
|
+
.join(manifestRoot);
|
|
773
|
+
}
|
|
774
|
+
return translated;
|
|
775
|
+
}
|
|
776
|
+
function workspaceRootOutputPaths(workspaceRootPath) {
|
|
777
|
+
const paths = [workspaceRootPath];
|
|
778
|
+
try {
|
|
779
|
+
paths.push((0, node_fs_1.realpathSync)(workspaceRootPath));
|
|
780
|
+
}
|
|
781
|
+
catch {
|
|
782
|
+
return paths;
|
|
783
|
+
}
|
|
784
|
+
return Array.from(new Set(paths)).sort((a, b) => b.length - a.length);
|
|
785
|
+
}
|
|
786
|
+
function escapeRegExp(value) {
|
|
787
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
788
|
+
}
|
|
789
|
+
function appendActiveProcessOutput(activeProcess, chunk, stream) {
|
|
790
|
+
if (chunk.length === 0) {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
const combined = appendBoundedOutput(activeProcess.output, activeProcess.droppedOutputChars, chunk);
|
|
794
|
+
activeProcess.output = combined.output;
|
|
795
|
+
activeProcess.droppedOutputChars = combined.droppedChars;
|
|
796
|
+
if (stream === 'stdout') {
|
|
797
|
+
const stdout = appendBoundedOutput(activeProcess.stdout, activeProcess.droppedStdoutChars, chunk);
|
|
798
|
+
activeProcess.stdout = stdout.output;
|
|
799
|
+
activeProcess.droppedStdoutChars = stdout.droppedChars;
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
const stderr = appendBoundedOutput(activeProcess.stderr, activeProcess.droppedStderrChars, chunk);
|
|
803
|
+
activeProcess.stderr = stderr.output;
|
|
804
|
+
activeProcess.droppedStderrChars = stderr.droppedChars;
|
|
805
|
+
}
|
|
806
|
+
function appendBoundedOutput(output, droppedChars, chunk) {
|
|
807
|
+
const nextLength = output.length + chunk.length;
|
|
808
|
+
if (nextLength <= MAX_ACTIVE_PROCESS_OUTPUT_CHARS) {
|
|
809
|
+
return {
|
|
810
|
+
output: output + chunk,
|
|
811
|
+
droppedChars,
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
const nextDroppedChars = droppedChars + nextLength - MAX_ACTIVE_PROCESS_OUTPUT_CHARS;
|
|
815
|
+
if (chunk.length >= MAX_ACTIVE_PROCESS_OUTPUT_CHARS) {
|
|
816
|
+
return {
|
|
817
|
+
output: chunk.slice(-MAX_ACTIVE_PROCESS_OUTPUT_CHARS),
|
|
818
|
+
droppedChars: nextDroppedChars,
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
const existingCharsToKeep = MAX_ACTIVE_PROCESS_OUTPUT_CHARS - chunk.length;
|
|
822
|
+
return {
|
|
823
|
+
output: output.slice(-existingCharsToKeep) + chunk,
|
|
824
|
+
droppedChars: nextDroppedChars,
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
function consumeActiveProcessOutput(activeProcess) {
|
|
828
|
+
const output = withDroppedOutputPrefix(activeProcess.output, activeProcess.droppedOutputChars);
|
|
829
|
+
const stdout = withDroppedOutputPrefix(activeProcess.stdout, activeProcess.droppedStdoutChars);
|
|
830
|
+
const stderr = withDroppedOutputPrefix(activeProcess.stderr, activeProcess.droppedStderrChars);
|
|
831
|
+
activeProcess.output = '';
|
|
832
|
+
activeProcess.stdout = '';
|
|
833
|
+
activeProcess.stderr = '';
|
|
834
|
+
activeProcess.droppedOutputChars = 0;
|
|
835
|
+
activeProcess.droppedStdoutChars = 0;
|
|
836
|
+
activeProcess.droppedStderrChars = 0;
|
|
837
|
+
return { output, stdout, stderr };
|
|
838
|
+
}
|
|
839
|
+
function withDroppedOutputPrefix(output, droppedChars) {
|
|
840
|
+
if (droppedChars === 0) {
|
|
841
|
+
return output;
|
|
842
|
+
}
|
|
843
|
+
return `[...${droppedChars} characters truncated from process output...]\n${output}`;
|
|
844
|
+
}
|
|
845
|
+
async function waitForProcessOrTimeout(activeProcess, timeoutMs) {
|
|
846
|
+
if (activeProcess.done) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
await Promise.race([
|
|
850
|
+
activeProcess.donePromise,
|
|
851
|
+
new Promise((resolve) => setTimeout(resolve, timeoutMs)),
|
|
852
|
+
]);
|
|
853
|
+
if (activeProcess.done) {
|
|
854
|
+
await activeProcess.outputClosedPromise;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
function signalToExitCode(signal) {
|
|
858
|
+
if (signal === 'SIGINT') {
|
|
859
|
+
return 130;
|
|
860
|
+
}
|
|
861
|
+
return 1;
|
|
862
|
+
}
|
|
863
|
+
//# sourceMappingURL=unixLocal.js.map
|