@sema-agent/server 1.185.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/LICENSE +102 -0
- package/README.md +207 -0
- package/deploy/sema-up/README.md +145 -0
- package/deploy/sema-up/chart/Chart.yaml +11 -0
- package/deploy/sema-up/chart/templates/gitea.yaml +63 -0
- package/deploy/sema-up/chart/templates/minio.yaml +62 -0
- package/deploy/sema-up/chart/templates/namespace-sandbox.yaml +9 -0
- package/deploy/sema-up/chart/templates/pg-cluster.yaml +57 -0
- package/deploy/sema-up/chart/templates/registry.yaml +88 -0
- package/deploy/sema-up/chart/templates/sandbox-rbac.yaml +45 -0
- package/deploy/sema-up/chart/templates/server-v4pro.yaml +76 -0
- package/deploy/sema-up/chart/templates/server.yaml +88 -0
- package/deploy/sema-up/chart/values-full-single.yaml +9 -0
- package/deploy/sema-up/chart/values.yaml +100 -0
- package/deploy/sema-up/cluster-up.sh +432 -0
- package/deploy/sema-up/kube-up.sh +377 -0
- package/deploy/sema-up/lib/parse-machines.py +117 -0
- package/deploy/sema-up/machines.example.yaml +53 -0
- package/deploy/sema-up/preflight.sh +168 -0
- package/deploy/sema-up/sema-up.sh +758 -0
- package/deploy/sema-up/smoke.sh +100 -0
- package/deploy/sema-up/stack/compose.dataroot.yaml +16 -0
- package/deploy/sema-up/stack/compose.yaml +155 -0
- package/deploy/sema-up/stack/sema-stack-cluster.yaml +189 -0
- package/dist/approval.d.ts +27 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +127 -0
- package/dist/approval.js.map +1 -0
- package/dist/audit.d.ts +29 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +95 -0
- package/dist/audit.js.map +1 -0
- package/dist/auth-bridge.d.ts +29 -0
- package/dist/auth-bridge.d.ts.map +1 -0
- package/dist/auth-bridge.js +145 -0
- package/dist/auth-bridge.js.map +1 -0
- package/dist/bake-runner/main.d.ts +20 -0
- package/dist/bake-runner/main.d.ts.map +1 -0
- package/dist/bake-runner/main.js +216 -0
- package/dist/bake-runner/main.js.map +1 -0
- package/dist/bake-runner/protocol.d.ts +49 -0
- package/dist/bake-runner/protocol.d.ts.map +1 -0
- package/dist/bake-runner/protocol.js +86 -0
- package/dist/bake-runner/protocol.js.map +1 -0
- package/dist/bake-runner/runner.d.ts +86 -0
- package/dist/bake-runner/runner.d.ts.map +1 -0
- package/dist/bake-runner/runner.js +228 -0
- package/dist/bake-runner/runner.js.map +1 -0
- package/dist/bench/l8/artifact.d.ts +62 -0
- package/dist/bench/l8/artifact.d.ts.map +1 -0
- package/dist/bench/l8/artifact.js +129 -0
- package/dist/bench/l8/artifact.js.map +1 -0
- package/dist/bench/l8/escape.d.ts +18 -0
- package/dist/bench/l8/escape.d.ts.map +1 -0
- package/dist/bench/l8/escape.js +9 -0
- package/dist/bench/l8/escape.js.map +1 -0
- package/dist/bench/l8/index.d.ts +5 -0
- package/dist/bench/l8/index.d.ts.map +1 -0
- package/dist/bench/l8/index.js +5 -0
- package/dist/bench/l8/index.js.map +1 -0
- package/dist/bench/l8/probes.d.ts +75 -0
- package/dist/bench/l8/probes.d.ts.map +1 -0
- package/dist/bench/l8/probes.js +178 -0
- package/dist/bench/l8/probes.js.map +1 -0
- package/dist/bench/l8/run-probes.d.ts +21 -0
- package/dist/bench/l8/run-probes.d.ts.map +1 -0
- package/dist/bench/l8/run-probes.js +130 -0
- package/dist/bench/l8/run-probes.js.map +1 -0
- package/dist/bench/s1/arms.d.ts +84 -0
- package/dist/bench/s1/arms.d.ts.map +1 -0
- package/dist/bench/s1/arms.js +329 -0
- package/dist/bench/s1/arms.js.map +1 -0
- package/dist/bench/s1/live-deps.d.ts +25 -0
- package/dist/bench/s1/live-deps.d.ts.map +1 -0
- package/dist/bench/s1/live-deps.js +449 -0
- package/dist/bench/s1/live-deps.js.map +1 -0
- package/dist/bench/s1/oracle.d.ts +34 -0
- package/dist/bench/s1/oracle.d.ts.map +1 -0
- package/dist/bench/s1/oracle.js +29 -0
- package/dist/bench/s1/oracle.js.map +1 -0
- package/dist/bench/s1/repair-oracle-adapter.d.ts +9 -0
- package/dist/bench/s1/repair-oracle-adapter.d.ts.map +1 -0
- package/dist/bench/s1/repair-oracle-adapter.js +27 -0
- package/dist/bench/s1/repair-oracle-adapter.js.map +1 -0
- package/dist/bench/s1/reviewer.d.ts +31 -0
- package/dist/bench/s1/reviewer.d.ts.map +1 -0
- package/dist/bench/s1/reviewer.js +26 -0
- package/dist/bench/s1/reviewer.js.map +1 -0
- package/dist/bench/s1/row.d.ts +29 -0
- package/dist/bench/s1/row.d.ts.map +1 -0
- package/dist/bench/s1/row.js +55 -0
- package/dist/bench/s1/row.js.map +1 -0
- package/dist/bench/s1/run-firm.d.ts +49 -0
- package/dist/bench/s1/run-firm.d.ts.map +1 -0
- package/dist/bench/s1/run-firm.js +291 -0
- package/dist/bench/s1/run-firm.js.map +1 -0
- package/dist/bench/s1/runner-ctx.d.ts +44 -0
- package/dist/bench/s1/runner-ctx.d.ts.map +1 -0
- package/dist/bench/s1/runner-ctx.js +59 -0
- package/dist/bench/s1/runner-ctx.js.map +1 -0
- package/dist/bench/s1/tasks.d.ts +48 -0
- package/dist/bench/s1/tasks.d.ts.map +1 -0
- package/dist/bench/s1/tasks.js +194 -0
- package/dist/bench/s1/tasks.js.map +1 -0
- package/dist/boot-reclaim.d.ts +10 -0
- package/dist/boot-reclaim.d.ts.map +1 -0
- package/dist/boot-reclaim.js +13 -0
- package/dist/boot-reclaim.js.map +1 -0
- package/dist/brain.d.ts +8 -0
- package/dist/brain.d.ts.map +1 -0
- package/dist/brain.js +83 -0
- package/dist/brain.js.map +1 -0
- package/dist/budget.d.ts +25 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +107 -0
- package/dist/budget.js.map +1 -0
- package/dist/capabilities/builtin-tools.d.ts +3 -0
- package/dist/capabilities/builtin-tools.d.ts.map +1 -0
- package/dist/capabilities/builtin-tools.js +11 -0
- package/dist/capabilities/builtin-tools.js.map +1 -0
- package/dist/capabilities/code-review-council.d.ts +21 -0
- package/dist/capabilities/code-review-council.d.ts.map +1 -0
- package/dist/capabilities/code-review-council.js +113 -0
- package/dist/capabilities/code-review-council.js.map +1 -0
- package/dist/capabilities/collab-wire.d.ts +34 -0
- package/dist/capabilities/collab-wire.d.ts.map +1 -0
- package/dist/capabilities/collab-wire.js +2 -0
- package/dist/capabilities/collab-wire.js.map +1 -0
- package/dist/capabilities/collab-workflows.d.ts +40 -0
- package/dist/capabilities/collab-workflows.d.ts.map +1 -0
- package/dist/capabilities/collab-workflows.js +90 -0
- package/dist/capabilities/collab-workflows.js.map +1 -0
- package/dist/capabilities/oa-tools.d.ts +9 -0
- package/dist/capabilities/oa-tools.d.ts.map +1 -0
- package/dist/capabilities/oa-tools.js +44 -0
- package/dist/capabilities/oa-tools.js.map +1 -0
- package/dist/capabilities/prompt.d.ts +3 -0
- package/dist/capabilities/prompt.d.ts.map +1 -0
- package/dist/capabilities/prompt.js +6 -0
- package/dist/capabilities/prompt.js.map +1 -0
- package/dist/capabilities/prompts/code-review.d.ts +11 -0
- package/dist/capabilities/prompts/code-review.d.ts.map +1 -0
- package/dist/capabilities/prompts/code-review.js +39 -0
- package/dist/capabilities/prompts/code-review.js.map +1 -0
- package/dist/capabilities/prompts/identity.d.ts +2 -0
- package/dist/capabilities/prompts/identity.d.ts.map +1 -0
- package/dist/capabilities/prompts/identity.js +6 -0
- package/dist/capabilities/prompts/identity.js.map +1 -0
- package/dist/capabilities/prompts/team.d.ts +6 -0
- package/dist/capabilities/prompts/team.d.ts.map +1 -0
- package/dist/capabilities/prompts/team.js +6 -0
- package/dist/capabilities/prompts/team.js.map +1 -0
- package/dist/capabilities/repo-tools.d.ts +19 -0
- package/dist/capabilities/repo-tools.d.ts.map +1 -0
- package/dist/capabilities/repo-tools.js +98 -0
- package/dist/capabilities/repo-tools.js.map +1 -0
- package/dist/capabilities/scenarios.d.ts +72 -0
- package/dist/capabilities/scenarios.d.ts.map +1 -0
- package/dist/capabilities/scenarios.js +241 -0
- package/dist/capabilities/scenarios.js.map +1 -0
- package/dist/capabilities/select-environment-tool.d.ts +22 -0
- package/dist/capabilities/select-environment-tool.d.ts.map +1 -0
- package/dist/capabilities/select-environment-tool.js +86 -0
- package/dist/capabilities/select-environment-tool.js.map +1 -0
- package/dist/capabilities/skills.d.ts +12 -0
- package/dist/capabilities/skills.d.ts.map +1 -0
- package/dist/capabilities/skills.js +50 -0
- package/dist/capabilities/skills.js.map +1 -0
- package/dist/capabilities/team.d.ts +31 -0
- package/dist/capabilities/team.d.ts.map +1 -0
- package/dist/capabilities/team.js +66 -0
- package/dist/capabilities/team.js.map +1 -0
- package/dist/config-provider.d.ts +47 -0
- package/dist/config-provider.d.ts.map +1 -0
- package/dist/config-provider.js +156 -0
- package/dist/config-provider.js.map +1 -0
- package/dist/config.d.ts +272 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +605 -0
- package/dist/config.js.map +1 -0
- package/dist/degenerate-instrument.d.ts +17 -0
- package/dist/degenerate-instrument.d.ts.map +1 -0
- package/dist/degenerate-instrument.js +113 -0
- package/dist/degenerate-instrument.js.map +1 -0
- package/dist/elicitation.d.ts +47 -0
- package/dist/elicitation.d.ts.map +1 -0
- package/dist/elicitation.js +151 -0
- package/dist/elicitation.js.map +1 -0
- package/dist/env-facts.d.ts +18 -0
- package/dist/env-facts.d.ts.map +1 -0
- package/dist/env-facts.js +26 -0
- package/dist/env-facts.js.map +1 -0
- package/dist/finance/cost-taxonomy.d.ts +34 -0
- package/dist/finance/cost-taxonomy.d.ts.map +1 -0
- package/dist/finance/cost-taxonomy.js +26 -0
- package/dist/finance/cost-taxonomy.js.map +1 -0
- package/dist/fleet/fleet-bus.d.ts +137 -0
- package/dist/fleet/fleet-bus.d.ts.map +1 -0
- package/dist/fleet/fleet-bus.js +249 -0
- package/dist/fleet/fleet-bus.js.map +1 -0
- package/dist/fleet-client.d.ts +50 -0
- package/dist/fleet-client.d.ts.map +1 -0
- package/dist/fleet-client.js +150 -0
- package/dist/fleet-client.js.map +1 -0
- package/dist/fleet-lease.d.ts +76 -0
- package/dist/fleet-lease.d.ts.map +1 -0
- package/dist/fleet-lease.js +124 -0
- package/dist/fleet-lease.js.map +1 -0
- package/dist/hooks/hook-runner.d.ts +41 -0
- package/dist/hooks/hook-runner.d.ts.map +1 -0
- package/dist/hooks/hook-runner.js +975 -0
- package/dist/hooks/hook-runner.js.map +1 -0
- package/dist/http/idempotency.d.ts +12 -0
- package/dist/http/idempotency.d.ts.map +1 -0
- package/dist/http/idempotency.js +49 -0
- package/dist/http/idempotency.js.map +1 -0
- package/dist/http/server.d.ts +185 -0
- package/dist/http/server.d.ts.map +1 -0
- package/dist/http/server.js +4845 -0
- package/dist/http/server.js.map +1 -0
- package/dist/http/wire-gate.d.ts +3 -0
- package/dist/http/wire-gate.d.ts.map +1 -0
- package/dist/http/wire-gate.js +6 -0
- package/dist/http/wire-gate.js.map +1 -0
- package/dist/images/bake-validate.d.ts +41 -0
- package/dist/images/bake-validate.d.ts.map +1 -0
- package/dist/images/bake-validate.js +183 -0
- package/dist/images/bake-validate.js.map +1 -0
- package/dist/images/manifest.d.ts +36 -0
- package/dist/images/manifest.d.ts.map +1 -0
- package/dist/images/manifest.js +69 -0
- package/dist/images/manifest.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/key-resolver.d.ts +5 -0
- package/dist/key-resolver.d.ts.map +1 -0
- package/dist/key-resolver.js +15 -0
- package/dist/key-resolver.js.map +1 -0
- package/dist/leader/diffout.d.ts +24 -0
- package/dist/leader/diffout.d.ts.map +1 -0
- package/dist/leader/diffout.js +54 -0
- package/dist/leader/diffout.js.map +1 -0
- package/dist/leader/diffup.d.ts +14 -0
- package/dist/leader/diffup.d.ts.map +1 -0
- package/dist/leader/diffup.js +81 -0
- package/dist/leader/diffup.js.map +1 -0
- package/dist/leader/endpoint.d.ts +30 -0
- package/dist/leader/endpoint.d.ts.map +1 -0
- package/dist/leader/endpoint.js +76 -0
- package/dist/leader/endpoint.js.map +1 -0
- package/dist/leader/fanout.d.ts +46 -0
- package/dist/leader/fanout.d.ts.map +1 -0
- package/dist/leader/fanout.js +109 -0
- package/dist/leader/fanout.js.map +1 -0
- package/dist/leader/grader-env-factory.d.ts +36 -0
- package/dist/leader/grader-env-factory.d.ts.map +1 -0
- package/dist/leader/grader-env-factory.js +73 -0
- package/dist/leader/grader-env-factory.js.map +1 -0
- package/dist/leader/leader.d.ts +102 -0
- package/dist/leader/leader.d.ts.map +1 -0
- package/dist/leader/leader.js +354 -0
- package/dist/leader/leader.js.map +1 -0
- package/dist/leader/merge.d.ts +109 -0
- package/dist/leader/merge.d.ts.map +1 -0
- package/dist/leader/merge.js +184 -0
- package/dist/leader/merge.js.map +1 -0
- package/dist/leader/planner.d.ts +26 -0
- package/dist/leader/planner.d.ts.map +1 -0
- package/dist/leader/planner.js +137 -0
- package/dist/leader/planner.js.map +1 -0
- package/dist/leader/repair-oracle.d.ts +34 -0
- package/dist/leader/repair-oracle.d.ts.map +1 -0
- package/dist/leader/repair-oracle.js +83 -0
- package/dist/leader/repair-oracle.js.map +1 -0
- package/dist/leader/repair-wire.d.ts +49 -0
- package/dist/leader/repair-wire.d.ts.map +1 -0
- package/dist/leader/repair-wire.js +90 -0
- package/dist/leader/repair-wire.js.map +1 -0
- package/dist/leader/wire.d.ts +66 -0
- package/dist/leader/wire.d.ts.map +1 -0
- package/dist/leader/wire.js +452 -0
- package/dist/leader/wire.js.map +1 -0
- package/dist/lsp/e2b-bridge.d.ts +8 -0
- package/dist/lsp/e2b-bridge.d.ts.map +1 -0
- package/dist/lsp/e2b-bridge.js +71 -0
- package/dist/lsp/e2b-bridge.js.map +1 -0
- package/dist/lsp/e2b-manager.d.ts +16 -0
- package/dist/lsp/e2b-manager.d.ts.map +1 -0
- package/dist/lsp/e2b-manager.js +49 -0
- package/dist/lsp/e2b-manager.js.map +1 -0
- package/dist/lsp/lsp-frames.d.ts +2 -0
- package/dist/lsp/lsp-frames.d.ts.map +1 -0
- package/dist/lsp/lsp-frames.js +25 -0
- package/dist/lsp/lsp-frames.js.map +1 -0
- package/dist/lsp/manager.d.ts +41 -0
- package/dist/lsp/manager.d.ts.map +1 -0
- package/dist/lsp/manager.js +84 -0
- package/dist/lsp/manager.js.map +1 -0
- package/dist/lsp/types.d.ts +2 -0
- package/dist/lsp/types.d.ts.map +1 -0
- package/dist/lsp/types.js +2 -0
- package/dist/lsp/types.js.map +1 -0
- package/dist/lsp/ws-transport.d.ts +28 -0
- package/dist/lsp/ws-transport.d.ts.map +1 -0
- package/dist/lsp/ws-transport.js +209 -0
- package/dist/lsp/ws-transport.js.map +1 -0
- package/dist/lsp-evict.d.ts +2 -0
- package/dist/lsp-evict.d.ts.map +1 -0
- package/dist/lsp-evict.js +14 -0
- package/dist/lsp-evict.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +1526 -0
- package/dist/main.js.map +1 -0
- package/dist/memory-export.d.ts +3 -0
- package/dist/memory-export.d.ts.map +1 -0
- package/dist/memory-export.js +8 -0
- package/dist/memory-export.js.map +1 -0
- package/dist/memory-sync-client.d.ts +29 -0
- package/dist/memory-sync-client.d.ts.map +1 -0
- package/dist/memory-sync-client.js +133 -0
- package/dist/memory-sync-client.js.map +1 -0
- package/dist/memory-sync.d.ts +41 -0
- package/dist/memory-sync.d.ts.map +1 -0
- package/dist/memory-sync.js +183 -0
- package/dist/memory-sync.js.map +1 -0
- package/dist/model-select.d.ts +8 -0
- package/dist/model-select.d.ts.map +1 -0
- package/dist/model-select.js +12 -0
- package/dist/model-select.js.map +1 -0
- package/dist/observability/cost-quota.d.ts +21 -0
- package/dist/observability/cost-quota.d.ts.map +1 -0
- package/dist/observability/cost-quota.js +42 -0
- package/dist/observability/cost-quota.js.map +1 -0
- package/dist/observability/logger.d.ts +9 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +35 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +76 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +263 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/otel-exporter.d.ts +37 -0
- package/dist/observability/otel-exporter.d.ts.map +1 -0
- package/dist/observability/otel-exporter.js +95 -0
- package/dist/observability/otel-exporter.js.map +1 -0
- package/dist/observability/principal-context.d.ts +5 -0
- package/dist/observability/principal-context.d.ts.map +1 -0
- package/dist/observability/principal-context.js +9 -0
- package/dist/observability/principal-context.js.map +1 -0
- package/dist/observability/rate-limit.d.ts +18 -0
- package/dist/observability/rate-limit.d.ts.map +1 -0
- package/dist/observability/rate-limit.js +30 -0
- package/dist/observability/rate-limit.js.map +1 -0
- package/dist/observability/tool-trace.d.ts +6 -0
- package/dist/observability/tool-trace.d.ts.map +1 -0
- package/dist/observability/tool-trace.js +73 -0
- package/dist/observability/tool-trace.js.map +1 -0
- package/dist/orchestration/hardened-vm-runner.d.ts +26 -0
- package/dist/orchestration/hardened-vm-runner.d.ts.map +1 -0
- package/dist/orchestration/hardened-vm-runner.js +217 -0
- package/dist/orchestration/hardened-vm-runner.js.map +1 -0
- package/dist/orchestration/hardened-vm-worker-runner.d.ts +4 -0
- package/dist/orchestration/hardened-vm-worker-runner.d.ts.map +1 -0
- package/dist/orchestration/hardened-vm-worker-runner.js +79 -0
- package/dist/orchestration/hardened-vm-worker-runner.js.map +1 -0
- package/dist/orchestration/hardened-vm-worker.d.ts +2 -0
- package/dist/orchestration/hardened-vm-worker.d.ts.map +1 -0
- package/dist/orchestration/hardened-vm-worker.js +80 -0
- package/dist/orchestration/hardened-vm-worker.js.map +1 -0
- package/dist/orchestration/subagent-steer.d.ts +12 -0
- package/dist/orchestration/subagent-steer.d.ts.map +1 -0
- package/dist/orchestration/subagent-steer.js +45 -0
- package/dist/orchestration/subagent-steer.js.map +1 -0
- package/dist/orchestration/workflow-agent-steer.d.ts +14 -0
- package/dist/orchestration/workflow-agent-steer.d.ts.map +1 -0
- package/dist/orchestration/workflow-agent-steer.js +41 -0
- package/dist/orchestration/workflow-agent-steer.js.map +1 -0
- package/dist/orchestration/workflow-completion-inbox.d.ts +101 -0
- package/dist/orchestration/workflow-completion-inbox.d.ts.map +1 -0
- package/dist/orchestration/workflow-completion-inbox.js +327 -0
- package/dist/orchestration/workflow-completion-inbox.js.map +1 -0
- package/dist/orchestration/workflow-notify-journal.d.ts +120 -0
- package/dist/orchestration/workflow-notify-journal.d.ts.map +1 -0
- package/dist/orchestration/workflow-notify-journal.js +297 -0
- package/dist/orchestration/workflow-notify-journal.js.map +1 -0
- package/dist/per-task-image.d.ts +27 -0
- package/dist/per-task-image.d.ts.map +1 -0
- package/dist/per-task-image.js +37 -0
- package/dist/per-task-image.js.map +1 -0
- package/dist/plan-cache-probe.d.ts +21 -0
- package/dist/plan-cache-probe.d.ts.map +1 -0
- package/dist/plan-cache-probe.js +79 -0
- package/dist/plan-cache-probe.js.map +1 -0
- package/dist/plugins/approval-exemption-store.d.ts +56 -0
- package/dist/plugins/approval-exemption-store.d.ts.map +1 -0
- package/dist/plugins/approval-exemption-store.js +216 -0
- package/dist/plugins/approval-exemption-store.js.map +1 -0
- package/dist/plugins/background-shell-support.d.ts +64 -0
- package/dist/plugins/background-shell-support.d.ts.map +1 -0
- package/dist/plugins/background-shell-support.js +235 -0
- package/dist/plugins/background-shell-support.js.map +1 -0
- package/dist/plugins/blob-backend.d.ts +44 -0
- package/dist/plugins/blob-backend.d.ts.map +1 -0
- package/dist/plugins/blob-backend.js +188 -0
- package/dist/plugins/blob-backend.js.map +1 -0
- package/dist/plugins/caching-session-store.d.ts +51 -0
- package/dist/plugins/caching-session-store.d.ts.map +1 -0
- package/dist/plugins/caching-session-store.js +142 -0
- package/dist/plugins/caching-session-store.js.map +1 -0
- package/dist/plugins/file-outcome-sink.d.ts +20 -0
- package/dist/plugins/file-outcome-sink.d.ts.map +1 -0
- package/dist/plugins/file-outcome-sink.js +14 -0
- package/dist/plugins/file-outcome-sink.js.map +1 -0
- package/dist/plugins/file-resume-anchor-store.d.ts +19 -0
- package/dist/plugins/file-resume-anchor-store.d.ts.map +1 -0
- package/dist/plugins/file-resume-anchor-store.js +103 -0
- package/dist/plugins/file-resume-anchor-store.js.map +1 -0
- package/dist/plugins/file-run-store.d.ts +95 -0
- package/dist/plugins/file-run-store.d.ts.map +1 -0
- package/dist/plugins/file-run-store.js +446 -0
- package/dist/plugins/file-run-store.js.map +1 -0
- package/dist/plugins/file-workflow-journal-store.d.ts +2 -0
- package/dist/plugins/file-workflow-journal-store.d.ts.map +1 -0
- package/dist/plugins/file-workflow-journal-store.js +2 -0
- package/dist/plugins/file-workflow-journal-store.js.map +1 -0
- package/dist/plugins/host-platform.d.ts +19 -0
- package/dist/plugins/host-platform.d.ts.map +1 -0
- package/dist/plugins/host-platform.js +71 -0
- package/dist/plugins/host-platform.js.map +1 -0
- package/dist/plugins/local-checkpoint-store.d.ts +41 -0
- package/dist/plugins/local-checkpoint-store.d.ts.map +1 -0
- package/dist/plugins/local-checkpoint-store.js +217 -0
- package/dist/plugins/local-checkpoint-store.js.map +1 -0
- package/dist/plugins/local-session-store.d.ts +69 -0
- package/dist/plugins/local-session-store.d.ts.map +1 -0
- package/dist/plugins/local-session-store.js +431 -0
- package/dist/plugins/local-session-store.js.map +1 -0
- package/dist/plugins/memory-engine-pg.d.ts +47 -0
- package/dist/plugins/memory-engine-pg.d.ts.map +1 -0
- package/dist/plugins/memory-engine-pg.js +306 -0
- package/dist/plugins/memory-engine-pg.js.map +1 -0
- package/dist/plugins/memory-engine-tidb.d.ts +40 -0
- package/dist/plugins/memory-engine-tidb.d.ts.map +1 -0
- package/dist/plugins/memory-engine-tidb.js +296 -0
- package/dist/plugins/memory-engine-tidb.js.map +1 -0
- package/dist/plugins/memory-engine-vector-util.d.ts +2 -0
- package/dist/plugins/memory-engine-vector-util.d.ts.map +1 -0
- package/dist/plugins/memory-engine-vector-util.js +2 -0
- package/dist/plugins/memory-engine-vector-util.js.map +1 -0
- package/dist/plugins/memory-resume-anchor-store.d.ts +12 -0
- package/dist/plugins/memory-resume-anchor-store.d.ts.map +1 -0
- package/dist/plugins/memory-resume-anchor-store.js +31 -0
- package/dist/plugins/memory-resume-anchor-store.js.map +1 -0
- package/dist/plugins/memory-run-store.d.ts +75 -0
- package/dist/plugins/memory-run-store.d.ts.map +1 -0
- package/dist/plugins/memory-run-store.js +267 -0
- package/dist/plugins/memory-run-store.js.map +1 -0
- package/dist/plugins/memory-sync-store-pg.d.ts +78 -0
- package/dist/plugins/memory-sync-store-pg.d.ts.map +1 -0
- package/dist/plugins/memory-sync-store-pg.js +152 -0
- package/dist/plugins/memory-sync-store-pg.js.map +1 -0
- package/dist/plugins/memory-sync-store-tidb.d.ts +32 -0
- package/dist/plugins/memory-sync-store-tidb.d.ts.map +1 -0
- package/dist/plugins/memory-sync-store-tidb.js +146 -0
- package/dist/plugins/memory-sync-store-tidb.js.map +1 -0
- package/dist/plugins/pg-approval-store.d.ts +28 -0
- package/dist/plugins/pg-approval-store.d.ts.map +1 -0
- package/dist/plugins/pg-approval-store.js +107 -0
- package/dist/plugins/pg-approval-store.js.map +1 -0
- package/dist/plugins/pg-breaker-state.d.ts +20 -0
- package/dist/plugins/pg-breaker-state.d.ts.map +1 -0
- package/dist/plugins/pg-breaker-state.js +89 -0
- package/dist/plugins/pg-breaker-state.js.map +1 -0
- package/dist/plugins/pg-checkpoint-store.d.ts +34 -0
- package/dist/plugins/pg-checkpoint-store.d.ts.map +1 -0
- package/dist/plugins/pg-checkpoint-store.js +193 -0
- package/dist/plugins/pg-checkpoint-store.js.map +1 -0
- package/dist/plugins/pg-cost-quota.d.ts +18 -0
- package/dist/plugins/pg-cost-quota.d.ts.map +1 -0
- package/dist/plugins/pg-cost-quota.js +189 -0
- package/dist/plugins/pg-cost-quota.js.map +1 -0
- package/dist/plugins/pg-file-snapshot-store.d.ts +26 -0
- package/dist/plugins/pg-file-snapshot-store.d.ts.map +1 -0
- package/dist/plugins/pg-file-snapshot-store.js +181 -0
- package/dist/plugins/pg-file-snapshot-store.js.map +1 -0
- package/dist/plugins/pg-image-bake.d.ts +42 -0
- package/dist/plugins/pg-image-bake.d.ts.map +1 -0
- package/dist/plugins/pg-image-bake.js +471 -0
- package/dist/plugins/pg-image-bake.js.map +1 -0
- package/dist/plugins/pg-image-index.d.ts +23 -0
- package/dist/plugins/pg-image-index.d.ts.map +1 -0
- package/dist/plugins/pg-image-index.js +252 -0
- package/dist/plugins/pg-image-index.js.map +1 -0
- package/dist/plugins/pg-outcome-ledger.d.ts +23 -0
- package/dist/plugins/pg-outcome-ledger.d.ts.map +1 -0
- package/dist/plugins/pg-outcome-ledger.js +102 -0
- package/dist/plugins/pg-outcome-ledger.js.map +1 -0
- package/dist/plugins/pg-pool.d.ts +7 -0
- package/dist/plugins/pg-pool.d.ts.map +1 -0
- package/dist/plugins/pg-pool.js +233 -0
- package/dist/plugins/pg-pool.js.map +1 -0
- package/dist/plugins/pg-rate-limiter.d.ts +49 -0
- package/dist/plugins/pg-rate-limiter.d.ts.map +1 -0
- package/dist/plugins/pg-rate-limiter.js +193 -0
- package/dist/plugins/pg-rate-limiter.js.map +1 -0
- package/dist/plugins/pg-resume-anchor-store.d.ts +14 -0
- package/dist/plugins/pg-resume-anchor-store.d.ts.map +1 -0
- package/dist/plugins/pg-resume-anchor-store.js +23 -0
- package/dist/plugins/pg-resume-anchor-store.js.map +1 -0
- package/dist/plugins/pg-run-store.d.ts +76 -0
- package/dist/plugins/pg-run-store.d.ts.map +1 -0
- package/dist/plugins/pg-run-store.js +301 -0
- package/dist/plugins/pg-run-store.js.map +1 -0
- package/dist/plugins/pg-session-policy-store.d.ts +12 -0
- package/dist/plugins/pg-session-policy-store.d.ts.map +1 -0
- package/dist/plugins/pg-session-policy-store.js +88 -0
- package/dist/plugins/pg-session-policy-store.js.map +1 -0
- package/dist/plugins/pg-session-storage.d.ts +59 -0
- package/dist/plugins/pg-session-storage.d.ts.map +1 -0
- package/dist/plugins/pg-session-storage.js +484 -0
- package/dist/plugins/pg-session-storage.js.map +1 -0
- package/dist/plugins/pg-session-store.d.ts +2 -0
- package/dist/plugins/pg-session-store.d.ts.map +1 -0
- package/dist/plugins/pg-session-store.js +2 -0
- package/dist/plugins/pg-session-store.js.map +1 -0
- package/dist/plugins/pg-tool-result-store.d.ts +16 -0
- package/dist/plugins/pg-tool-result-store.d.ts.map +1 -0
- package/dist/plugins/pg-tool-result-store.js +52 -0
- package/dist/plugins/pg-tool-result-store.js.map +1 -0
- package/dist/plugins/pg-workflow-journal-store.d.ts +11 -0
- package/dist/plugins/pg-workflow-journal-store.d.ts.map +1 -0
- package/dist/plugins/pg-workflow-journal-store.js +28 -0
- package/dist/plugins/pg-workflow-journal-store.js.map +1 -0
- package/dist/plugins/pg-workflow-run-store.d.ts +55 -0
- package/dist/plugins/pg-workflow-run-store.d.ts.map +1 -0
- package/dist/plugins/pg-workflow-run-store.js +216 -0
- package/dist/plugins/pg-workflow-run-store.js.map +1 -0
- package/dist/plugins/remote-env-adb.d.ts +119 -0
- package/dist/plugins/remote-env-adb.d.ts.map +1 -0
- package/dist/plugins/remote-env-adb.js +502 -0
- package/dist/plugins/remote-env-adb.js.map +1 -0
- package/dist/plugins/remote-env-e2b.d.ts +162 -0
- package/dist/plugins/remote-env-e2b.d.ts.map +1 -0
- package/dist/plugins/remote-env-e2b.js +931 -0
- package/dist/plugins/remote-env-e2b.js.map +1 -0
- package/dist/plugins/remote-env-host.d.ts +141 -0
- package/dist/plugins/remote-env-host.d.ts.map +1 -0
- package/dist/plugins/remote-env-host.js +868 -0
- package/dist/plugins/remote-env-host.js.map +1 -0
- package/dist/plugins/remote-env-k8s.d.ts +209 -0
- package/dist/plugins/remote-env-k8s.d.ts.map +1 -0
- package/dist/plugins/remote-env-k8s.js +1206 -0
- package/dist/plugins/remote-env-k8s.js.map +1 -0
- package/dist/plugins/remote-env-local-docker.d.ts +124 -0
- package/dist/plugins/remote-env-local-docker.d.ts.map +1 -0
- package/dist/plugins/remote-env-local-docker.js +597 -0
- package/dist/plugins/remote-env-local-docker.js.map +1 -0
- package/dist/plugins/remote-env-ssh.d.ts +122 -0
- package/dist/plugins/remote-env-ssh.d.ts.map +1 -0
- package/dist/plugins/remote-env-ssh.js +511 -0
- package/dist/plugins/remote-env-ssh.js.map +1 -0
- package/dist/plugins/remote-shell.d.ts +7 -0
- package/dist/plugins/remote-shell.d.ts.map +1 -0
- package/dist/plugins/remote-shell.js +25 -0
- package/dist/plugins/remote-shell.js.map +1 -0
- package/dist/plugins/s3-presign.d.ts +13 -0
- package/dist/plugins/s3-presign.d.ts.map +1 -0
- package/dist/plugins/s3-presign.js +55 -0
- package/dist/plugins/s3-presign.js.map +1 -0
- package/dist/plugins/scheduler-support.d.ts +39 -0
- package/dist/plugins/scheduler-support.d.ts.map +1 -0
- package/dist/plugins/scheduler-support.js +141 -0
- package/dist/plugins/scheduler-support.js.map +1 -0
- package/dist/plugins/session-store.d.ts +7 -0
- package/dist/plugins/session-store.d.ts.map +1 -0
- package/dist/plugins/session-store.js +14 -0
- package/dist/plugins/session-store.js.map +1 -0
- package/dist/plugins/store-backend.d.ts +88 -0
- package/dist/plugins/store-backend.d.ts.map +1 -0
- package/dist/plugins/store-backend.js +197 -0
- package/dist/plugins/store-backend.js.map +1 -0
- package/dist/plugins/tidb-approval-store.d.ts +39 -0
- package/dist/plugins/tidb-approval-store.d.ts.map +1 -0
- package/dist/plugins/tidb-approval-store.js +81 -0
- package/dist/plugins/tidb-approval-store.js.map +1 -0
- package/dist/plugins/tidb-breaker-state.d.ts +18 -0
- package/dist/plugins/tidb-breaker-state.d.ts.map +1 -0
- package/dist/plugins/tidb-breaker-state.js +75 -0
- package/dist/plugins/tidb-breaker-state.js.map +1 -0
- package/dist/plugins/tidb-checkpoint-store.d.ts +50 -0
- package/dist/plugins/tidb-checkpoint-store.d.ts.map +1 -0
- package/dist/plugins/tidb-checkpoint-store.js +196 -0
- package/dist/plugins/tidb-checkpoint-store.js.map +1 -0
- package/dist/plugins/tidb-cost-quota.d.ts +16 -0
- package/dist/plugins/tidb-cost-quota.d.ts.map +1 -0
- package/dist/plugins/tidb-cost-quota.js +34 -0
- package/dist/plugins/tidb-cost-quota.js.map +1 -0
- package/dist/plugins/tidb-file-snapshot-store.d.ts +26 -0
- package/dist/plugins/tidb-file-snapshot-store.d.ts.map +1 -0
- package/dist/plugins/tidb-file-snapshot-store.js +183 -0
- package/dist/plugins/tidb-file-snapshot-store.js.map +1 -0
- package/dist/plugins/tidb-image-bake.d.ts +102 -0
- package/dist/plugins/tidb-image-bake.d.ts.map +1 -0
- package/dist/plugins/tidb-image-bake.js +400 -0
- package/dist/plugins/tidb-image-bake.js.map +1 -0
- package/dist/plugins/tidb-image-index.d.ts +71 -0
- package/dist/plugins/tidb-image-index.d.ts.map +1 -0
- package/dist/plugins/tidb-image-index.js +192 -0
- package/dist/plugins/tidb-image-index.js.map +1 -0
- package/dist/plugins/tidb-outcome-ledger.d.ts +58 -0
- package/dist/plugins/tidb-outcome-ledger.d.ts.map +1 -0
- package/dist/plugins/tidb-outcome-ledger.js +98 -0
- package/dist/plugins/tidb-outcome-ledger.js.map +1 -0
- package/dist/plugins/tidb-pool.d.ts +11 -0
- package/dist/plugins/tidb-pool.d.ts.map +1 -0
- package/dist/plugins/tidb-pool.js +485 -0
- package/dist/plugins/tidb-pool.js.map +1 -0
- package/dist/plugins/tidb-rate-limiter.d.ts +15 -0
- package/dist/plugins/tidb-rate-limiter.d.ts.map +1 -0
- package/dist/plugins/tidb-rate-limiter.js +34 -0
- package/dist/plugins/tidb-rate-limiter.js.map +1 -0
- package/dist/plugins/tidb-resume-anchor-store.d.ts +14 -0
- package/dist/plugins/tidb-resume-anchor-store.d.ts.map +1 -0
- package/dist/plugins/tidb-resume-anchor-store.js +23 -0
- package/dist/plugins/tidb-resume-anchor-store.js.map +1 -0
- package/dist/plugins/tidb-run-store.d.ts +107 -0
- package/dist/plugins/tidb-run-store.d.ts.map +1 -0
- package/dist/plugins/tidb-run-store.js +321 -0
- package/dist/plugins/tidb-run-store.js.map +1 -0
- package/dist/plugins/tidb-session-policy-store.d.ts +12 -0
- package/dist/plugins/tidb-session-policy-store.d.ts.map +1 -0
- package/dist/plugins/tidb-session-policy-store.js +88 -0
- package/dist/plugins/tidb-session-policy-store.js.map +1 -0
- package/dist/plugins/tidb-session-storage.d.ts +15 -0
- package/dist/plugins/tidb-session-storage.d.ts.map +1 -0
- package/dist/plugins/tidb-session-storage.js +101 -0
- package/dist/plugins/tidb-session-storage.js.map +1 -0
- package/dist/plugins/tidb-session-store.d.ts +46 -0
- package/dist/plugins/tidb-session-store.d.ts.map +1 -0
- package/dist/plugins/tidb-session-store.js +360 -0
- package/dist/plugins/tidb-session-store.js.map +1 -0
- package/dist/plugins/tidb-tool-result-store.d.ts +15 -0
- package/dist/plugins/tidb-tool-result-store.d.ts.map +1 -0
- package/dist/plugins/tidb-tool-result-store.js +41 -0
- package/dist/plugins/tidb-tool-result-store.js.map +1 -0
- package/dist/plugins/tidb-workflow-journal-store.d.ts +11 -0
- package/dist/plugins/tidb-workflow-journal-store.d.ts.map +1 -0
- package/dist/plugins/tidb-workflow-journal-store.js +28 -0
- package/dist/plugins/tidb-workflow-journal-store.js.map +1 -0
- package/dist/plugins/tidb-workflow-run-store.d.ts +61 -0
- package/dist/plugins/tidb-workflow-run-store.d.ts.map +1 -0
- package/dist/plugins/tidb-workflow-run-store.js +227 -0
- package/dist/plugins/tidb-workflow-run-store.js.map +1 -0
- package/dist/plugins/web-search.d.ts +27 -0
- package/dist/plugins/web-search.d.ts.map +1 -0
- package/dist/plugins/web-search.js +143 -0
- package/dist/plugins/web-search.js.map +1 -0
- package/dist/plugins/workflow-journal-limits.d.ts +2 -0
- package/dist/plugins/workflow-journal-limits.d.ts.map +1 -0
- package/dist/plugins/workflow-journal-limits.js +2 -0
- package/dist/plugins/workflow-journal-limits.js.map +1 -0
- package/dist/plugins/worktree-isolation.d.ts +16 -0
- package/dist/plugins/worktree-isolation.d.ts.map +1 -0
- package/dist/plugins/worktree-isolation.js +55 -0
- package/dist/plugins/worktree-isolation.js.map +1 -0
- package/dist/plugins/write-behind-counter.d.ts +43 -0
- package/dist/plugins/write-behind-counter.d.ts.map +1 -0
- package/dist/plugins/write-behind-counter.js +144 -0
- package/dist/plugins/write-behind-counter.js.map +1 -0
- package/dist/project-memory.d.ts +14 -0
- package/dist/project-memory.d.ts.map +1 -0
- package/dist/project-memory.js +96 -0
- package/dist/project-memory.js.map +1 -0
- package/dist/question.d.ts +42 -0
- package/dist/question.d.ts.map +1 -0
- package/dist/question.js +140 -0
- package/dist/question.js.map +1 -0
- package/dist/resource-suspend.d.ts +11 -0
- package/dist/resource-suspend.d.ts.map +1 -0
- package/dist/resource-suspend.js +6 -0
- package/dist/resource-suspend.js.map +1 -0
- package/dist/router/route-orchestration.d.ts +31 -0
- package/dist/router/route-orchestration.d.ts.map +1 -0
- package/dist/router/route-orchestration.js +49 -0
- package/dist/router/route-orchestration.js.map +1 -0
- package/dist/run-local.d.ts +26 -0
- package/dist/run-local.d.ts.map +1 -0
- package/dist/run-local.js +337 -0
- package/dist/run-local.js.map +1 -0
- package/dist/runs.d.ts +39 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +392 -0
- package/dist/runs.js.map +1 -0
- package/dist/runtime-caps-resolver.d.ts +32 -0
- package/dist/runtime-caps-resolver.d.ts.map +1 -0
- package/dist/runtime-caps-resolver.js +134 -0
- package/dist/runtime-caps-resolver.js.map +1 -0
- package/dist/runtime-governance.d.ts +18 -0
- package/dist/runtime-governance.d.ts.map +1 -0
- package/dist/runtime-governance.js +103 -0
- package/dist/runtime-governance.js.map +1 -0
- package/dist/sandbox-pkg-source.d.ts +11 -0
- package/dist/sandbox-pkg-source.d.ts.map +1 -0
- package/dist/sandbox-pkg-source.js +56 -0
- package/dist/sandbox-pkg-source.js.map +1 -0
- package/dist/sealed-key.d.ts +29 -0
- package/dist/sealed-key.d.ts.map +1 -0
- package/dist/sealed-key.js +122 -0
- package/dist/sealed-key.js.map +1 -0
- package/dist/security.d.ts +153 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +292 -0
- package/dist/security.js.map +1 -0
- package/dist/sema-registry.d.ts +187 -0
- package/dist/sema-registry.d.ts.map +1 -0
- package/dist/sema-registry.js +456 -0
- package/dist/sema-registry.js.map +1 -0
- package/dist/session-sync.d.ts +96 -0
- package/dist/session-sync.d.ts.map +1 -0
- package/dist/session-sync.js +181 -0
- package/dist/session-sync.js.map +1 -0
- package/dist/session-titler.d.ts +30 -0
- package/dist/session-titler.d.ts.map +1 -0
- package/dist/session-titler.js +77 -0
- package/dist/session-titler.js.map +1 -0
- package/dist/spec-fields.d.ts +5 -0
- package/dist/spec-fields.d.ts.map +1 -0
- package/dist/spec-fields.js +43 -0
- package/dist/spec-fields.js.map +1 -0
- package/dist/task-cwd.d.ts +15 -0
- package/dist/task-cwd.d.ts.map +1 -0
- package/dist/task-cwd.js +33 -0
- package/dist/task-cwd.js.map +1 -0
- package/dist/task-mcp.d.ts +20 -0
- package/dist/task-mcp.d.ts.map +1 -0
- package/dist/task-mcp.js +93 -0
- package/dist/task-mcp.js.map +1 -0
- package/dist/task-settings.d.ts +36 -0
- package/dist/task-settings.d.ts.map +1 -0
- package/dist/task-settings.js +141 -0
- package/dist/task-settings.js.map +1 -0
- package/dist/task-workflow.d.ts +25 -0
- package/dist/task-workflow.d.ts.map +1 -0
- package/dist/task-workflow.js +43 -0
- package/dist/task-workflow.js.map +1 -0
- package/dist/trace/artifacts.d.ts +17 -0
- package/dist/trace/artifacts.d.ts.map +1 -0
- package/dist/trace/artifacts.js +65 -0
- package/dist/trace/artifacts.js.map +1 -0
- package/dist/trace/project.d.ts +170 -0
- package/dist/trace/project.d.ts.map +1 -0
- package/dist/trace/project.js +239 -0
- package/dist/trace/project.js.map +1 -0
- package/dist/trace/redact.d.ts +5 -0
- package/dist/trace/redact.d.ts.map +1 -0
- package/dist/trace/redact.js +83 -0
- package/dist/trace/redact.js.map +1 -0
- package/dist/usage-analytics.d.ts +36 -0
- package/dist/usage-analytics.d.ts.map +1 -0
- package/dist/usage-analytics.js +89 -0
- package/dist/usage-analytics.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { Sandbox, CommandExitError, FileType } from "e2b";
|
|
3
|
+
import { FileError, ExecutionError, RemoteExecutionError, RollingTailBuffer, markTruncated, } from "@sema-agent/core";
|
|
4
|
+
import { BackgroundShellManager } from "./background-shell-support.js";
|
|
5
|
+
const PROVIDER = "e2b";
|
|
6
|
+
const DEFAULT_MOUNT_PATH = "/home/user";
|
|
7
|
+
const DEFAULT_TIMEOUT_MS = 5 * 60_000;
|
|
8
|
+
const E2B_SANDBOX_MAX_MS = Math.max(60_000, Math.floor(Number(process.env.E2B_SANDBOX_MAX_MS ?? "")) || 3_600_000);
|
|
9
|
+
const DEFAULT_RPC_TIMEOUT_MS = 60_000;
|
|
10
|
+
const DEFAULT_LIVENESS_MS = 120_000;
|
|
11
|
+
const DEFAULT_DATA_TIMEOUT_MS = 5 * 60_000;
|
|
12
|
+
const E2B_BG_MAX_CONCURRENT = Math.max(1, Math.floor(Number(process.env.E2B_BG_MAX_CONCURRENT ?? "")) || 8);
|
|
13
|
+
const E2B_BG_DEFAULT_TIMEOUT_SEC = Math.max(1, Math.floor(Number(process.env.E2B_BG_DEFAULT_TIMEOUT_SEC ?? "")) || 300);
|
|
14
|
+
const E2B_BG_MAX_TIMEOUT_SEC = Math.max(E2B_BG_DEFAULT_TIMEOUT_SEC, Math.floor(Number(process.env.E2B_BG_MAX_TIMEOUT_SEC ?? "")) || 1800);
|
|
15
|
+
const E2B_BG_PROVIDER_BACKSTOP_PAD_SEC = 30;
|
|
16
|
+
const ok = (value) => ({ ok: true, value });
|
|
17
|
+
export class RemoteContainerExecutionEnv {
|
|
18
|
+
cwd;
|
|
19
|
+
cfg;
|
|
20
|
+
sandboxApi;
|
|
21
|
+
sbx;
|
|
22
|
+
keepAlive;
|
|
23
|
+
handle;
|
|
24
|
+
destroyed = false;
|
|
25
|
+
connecting;
|
|
26
|
+
activeCommands = 0;
|
|
27
|
+
paused = false;
|
|
28
|
+
constructor(config, deps = {}) {
|
|
29
|
+
this.cfg = {
|
|
30
|
+
...config,
|
|
31
|
+
mountPath: config.mountPath ?? DEFAULT_MOUNT_PATH,
|
|
32
|
+
timeoutMs: Math.min(config.timeoutMs ?? DEFAULT_TIMEOUT_MS, E2B_SANDBOX_MAX_MS),
|
|
33
|
+
allowInternetAccess: config.allowInternetAccess ?? true,
|
|
34
|
+
rpcTimeoutMs: config.rpcTimeoutMs ?? DEFAULT_RPC_TIMEOUT_MS,
|
|
35
|
+
livenessMs: config.livenessMs ?? DEFAULT_LIVENESS_MS,
|
|
36
|
+
dataTimeoutMs: config.dataTimeoutMs ?? DEFAULT_DATA_TIMEOUT_MS,
|
|
37
|
+
};
|
|
38
|
+
this.cwd = this.cfg.mountPath;
|
|
39
|
+
this.sandboxApi = deps.sandboxApi ?? Sandbox;
|
|
40
|
+
}
|
|
41
|
+
capabilities = { isolation: true, suspendable: true };
|
|
42
|
+
workspaceHandle() {
|
|
43
|
+
if (!this.handle) {
|
|
44
|
+
throw new RemoteExecutionError("connect_failed", "workspaceHandle() called before connect()");
|
|
45
|
+
}
|
|
46
|
+
return this.handle;
|
|
47
|
+
}
|
|
48
|
+
async getHost(port) {
|
|
49
|
+
const conn = await this.ensureConnected();
|
|
50
|
+
return conn.ok ? conn.value.getHost(port) : undefined;
|
|
51
|
+
}
|
|
52
|
+
async startBackground(command) {
|
|
53
|
+
const conn = await this.ensureConnected();
|
|
54
|
+
if (conn.ok)
|
|
55
|
+
await conn.value.commands.run(command, { background: true });
|
|
56
|
+
}
|
|
57
|
+
async connect(config) {
|
|
58
|
+
if (config?.snapshotId) {
|
|
59
|
+
return this.resumeVM(config.snapshotId, config.abortSignal ? { abortSignal: config.abortSignal } : undefined);
|
|
60
|
+
}
|
|
61
|
+
if (this.destroyed)
|
|
62
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "execution env already destroyed") };
|
|
63
|
+
if (this.paused)
|
|
64
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "execution env is suspended (paused) — resumeVM(snapshotId) before use") };
|
|
65
|
+
if (this.sbx)
|
|
66
|
+
return ok(this.workspaceHandle());
|
|
67
|
+
if (this.connecting)
|
|
68
|
+
return this.connecting;
|
|
69
|
+
this.connecting = this.doConnect(config);
|
|
70
|
+
const r = await this.connecting;
|
|
71
|
+
if (!r.ok)
|
|
72
|
+
this.connecting = undefined;
|
|
73
|
+
return r;
|
|
74
|
+
}
|
|
75
|
+
async doConnect(config) {
|
|
76
|
+
try {
|
|
77
|
+
const sbx = await this.rpc("sandbox.create", () => this.sandboxApi.create({
|
|
78
|
+
...(this.cfg.template ? { template: this.cfg.template } : {}),
|
|
79
|
+
apiKey: this.cfg.apiKey,
|
|
80
|
+
timeoutMs: this.cfg.timeoutMs,
|
|
81
|
+
allowInternetAccess: this.cfg.allowInternetAccess,
|
|
82
|
+
...(this.cfg.metadata ? { metadata: this.cfg.metadata } : {}),
|
|
83
|
+
...(this.cfg.sandboxEnv && Object.keys(this.cfg.sandboxEnv).length > 0 ? { envs: this.cfg.sandboxEnv } : {}),
|
|
84
|
+
}), config?.abortSignal, this.cfg.dataTimeoutMs);
|
|
85
|
+
if (this.destroyed) {
|
|
86
|
+
await sbx.kill().catch(() => { });
|
|
87
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "execution env destroyed during connect") };
|
|
88
|
+
}
|
|
89
|
+
this.sbx = sbx;
|
|
90
|
+
this.paused = false;
|
|
91
|
+
this.startKeepAlive();
|
|
92
|
+
this.cfg.logger?.info?.("remote_env_connect", { sandboxId: sbx.sandboxId });
|
|
93
|
+
this.handle = {
|
|
94
|
+
sandboxId: sbx.sandboxId,
|
|
95
|
+
provider: PROVIDER,
|
|
96
|
+
mountPath: this.cfg.mountPath,
|
|
97
|
+
sessionToken: sbx.sandboxId,
|
|
98
|
+
};
|
|
99
|
+
if (config?.secrets?.length) {
|
|
100
|
+
this.cfg.logger?.warn?.("remote-env: connect secrets are not injected in v1 (control-plane resolution deferred)", {
|
|
101
|
+
count: config.secrets.length,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
this.cfg.metrics?.inc("remote_env_connect_total", { provider: PROVIDER, result: "ok" });
|
|
105
|
+
return ok(this.handle);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
this.cfg.metrics?.inc("remote_env_connect_total", { provider: PROVIDER, result: "error" });
|
|
109
|
+
return { ok: false, error: this.remoteError(e, "connect_failed") };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async suspendVM(options) {
|
|
113
|
+
const sbx = this.sbx;
|
|
114
|
+
if (!sbx)
|
|
115
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "suspendVM before connect()") };
|
|
116
|
+
if (this.destroyed)
|
|
117
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "env already destroyed") };
|
|
118
|
+
if (this.activeCommands > 0) {
|
|
119
|
+
return { ok: false, error: new RemoteExecutionError("command_in_flight", `suspendVM refused: ${this.activeCommands} command(s) in flight`) };
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
await this.rpc("sandbox.pause", (signal) => sbx.pause({ signal }), options?.abortSignal, this.cfg.dataTimeoutMs);
|
|
123
|
+
if (this.destroyed) {
|
|
124
|
+
await sbx.kill().catch((e) => this.cfg.logger?.warn?.("remote-env: suspend-recheck kill failed (snapshot may orphan)", { error: errMsg(e) }));
|
|
125
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "execution env destroyed during suspend") };
|
|
126
|
+
}
|
|
127
|
+
this.paused = true;
|
|
128
|
+
this.connecting = undefined;
|
|
129
|
+
this.cfg.metrics?.inc("remote_env_suspend_total", { provider: PROVIDER, result: "ok" });
|
|
130
|
+
this.cfg.logger?.info?.("remote_env_suspend", { snapshotId: sbx.sandboxId });
|
|
131
|
+
return ok(sbx.sandboxId);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
this.cfg.metrics?.inc("remote_env_suspend_total", { provider: PROVIDER, result: "error" });
|
|
135
|
+
return { ok: false, error: this.remoteError(e, options?.abortSignal?.aborted ? "aborted" : "unknown") };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async resumeVM(snapshotId, options) {
|
|
139
|
+
if (this.destroyed)
|
|
140
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "env already destroyed") };
|
|
141
|
+
if (this.sbx && !this.paused && this.sbx.sandboxId === snapshotId)
|
|
142
|
+
return ok(this.workspaceHandle());
|
|
143
|
+
if (this.connecting)
|
|
144
|
+
return this.connecting;
|
|
145
|
+
this.connecting = this.doResumeVM(snapshotId, options);
|
|
146
|
+
const r = await this.connecting;
|
|
147
|
+
if (!r.ok)
|
|
148
|
+
this.connecting = undefined;
|
|
149
|
+
return r;
|
|
150
|
+
}
|
|
151
|
+
async doResumeVM(snapshotId, options) {
|
|
152
|
+
try {
|
|
153
|
+
const sbx = await this.rpc("sandbox.connect", (signal) => this.sandboxApi.connect(snapshotId, { apiKey: this.cfg.apiKey, timeoutMs: this.cfg.timeoutMs, signal }), options?.abortSignal, this.cfg.dataTimeoutMs);
|
|
154
|
+
if (this.destroyed) {
|
|
155
|
+
await sbx.kill().catch(() => { });
|
|
156
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "execution env destroyed during resume") };
|
|
157
|
+
}
|
|
158
|
+
this.sbx = sbx;
|
|
159
|
+
this.paused = false;
|
|
160
|
+
this.startKeepAlive();
|
|
161
|
+
this.cfg.logger?.info?.("remote_env_resume", { requested: snapshotId, connected: sbx.sandboxId });
|
|
162
|
+
this.handle = { sandboxId: sbx.sandboxId, provider: PROVIDER, mountPath: this.cfg.mountPath, snapshotId, sessionToken: sbx.sandboxId };
|
|
163
|
+
this.cfg.metrics?.inc("remote_env_resume_total", { provider: PROVIDER, result: "ok" });
|
|
164
|
+
return ok(this.handle);
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
this.cfg.metrics?.inc("remote_env_resume_total", { provider: PROVIDER, result: "error" });
|
|
168
|
+
return { ok: false, error: this.remoteError(e, options?.abortSignal?.aborted ? "aborted" : "connect_failed") };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async reconnect(_sessionToken) {
|
|
172
|
+
return { ok: false, error: new RemoteExecutionError("unknown", "reconnect is deferred to v2 (v1.5 always snapshots → use resumeVM)") };
|
|
173
|
+
}
|
|
174
|
+
async postResumeInit() {
|
|
175
|
+
const sbx = this.sbx;
|
|
176
|
+
if (!sbx)
|
|
177
|
+
return { ok: false, error: new RemoteExecutionError("post_resume_failed", "postResumeInit before resume") };
|
|
178
|
+
try {
|
|
179
|
+
if (!(await this.rpc("sandbox.isRunning", () => sbx.isRunning()))) {
|
|
180
|
+
return { ok: false, error: new RemoteExecutionError("post_resume_failed", "resumed VM is not running") };
|
|
181
|
+
}
|
|
182
|
+
return ok(undefined);
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
return { ok: false, error: this.remoteError(e, "post_resume_failed") };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
startKeepAlive() {
|
|
189
|
+
this.stopKeepAlive();
|
|
190
|
+
const everyMs = Math.max(30_000, Math.floor(this.cfg.timeoutMs * 0.8));
|
|
191
|
+
this.keepAlive = setInterval(() => {
|
|
192
|
+
if (this.destroyed || this.paused || !this.sbx)
|
|
193
|
+
return;
|
|
194
|
+
void this.sbx.setTimeout(this.cfg.timeoutMs).catch((e) => this.cfg.logger?.warn?.("remote_env_keepalive_failed", { error: errMsg(e) }));
|
|
195
|
+
}, everyMs);
|
|
196
|
+
this.keepAlive.unref?.();
|
|
197
|
+
}
|
|
198
|
+
stopKeepAlive() {
|
|
199
|
+
if (this.keepAlive) {
|
|
200
|
+
clearInterval(this.keepAlive);
|
|
201
|
+
this.keepAlive = undefined;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async destroy() {
|
|
205
|
+
if (this.destroyed)
|
|
206
|
+
return;
|
|
207
|
+
this.destroyed = true;
|
|
208
|
+
this.connecting = undefined;
|
|
209
|
+
this.stopKeepAlive();
|
|
210
|
+
await this.disposeBackgroundShells();
|
|
211
|
+
const sbx = this.sbx;
|
|
212
|
+
this.sbx = undefined;
|
|
213
|
+
if (!sbx)
|
|
214
|
+
return;
|
|
215
|
+
const startedAt = Date.now();
|
|
216
|
+
try {
|
|
217
|
+
await this.rpc("sandbox.kill", () => sbx.kill());
|
|
218
|
+
this.cfg.metrics?.inc("remote_env_destroy_total", { provider: PROVIDER, result: "ok" });
|
|
219
|
+
this.cfg.logger?.info?.("remote_env_destroy", { sandboxId: sbx.sandboxId, ms: Date.now() - startedAt });
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
this.cfg.metrics?.inc("remote_env_destroy_total", { provider: PROVIDER, result: "error" });
|
|
223
|
+
this.cfg.logger?.warn?.("remote_env_destroy_failed", { sandboxId: sbx.sandboxId, ms: Date.now() - startedAt, error: errMsg(e) });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async cleanup() {
|
|
227
|
+
await this.destroy();
|
|
228
|
+
}
|
|
229
|
+
async exec(command, options) {
|
|
230
|
+
if (options?.abortSignal?.aborted)
|
|
231
|
+
return { ok: false, error: new ExecutionError("aborted", "exec aborted before start") };
|
|
232
|
+
const conn = await this.ensureConnected();
|
|
233
|
+
if (!conn.ok)
|
|
234
|
+
return { ok: false, error: new ExecutionError("shell_unavailable", `remote connect failed: ${conn.error.message}`, conn.error) };
|
|
235
|
+
const sbx = conn.value;
|
|
236
|
+
this.activeCommands++;
|
|
237
|
+
const detachSignal = options?.detachSignal;
|
|
238
|
+
const tee = detachSignal
|
|
239
|
+
? {
|
|
240
|
+
stdout: { tail: new RollingTailBuffer(), total: 0, cursor: 0 },
|
|
241
|
+
stderr: { tail: new RollingTailBuffer(), total: 0, cursor: 0 },
|
|
242
|
+
}
|
|
243
|
+
: undefined;
|
|
244
|
+
let detached = false;
|
|
245
|
+
const teePush = (s, d) => {
|
|
246
|
+
const b = Buffer.from(d, "utf8");
|
|
247
|
+
s.tail.push(b);
|
|
248
|
+
s.total += b.length;
|
|
249
|
+
};
|
|
250
|
+
let lastProgress = Date.now();
|
|
251
|
+
let handle;
|
|
252
|
+
try {
|
|
253
|
+
handle = await this.rpc("commands.run", () => sbx.commands.run(command, {
|
|
254
|
+
background: true,
|
|
255
|
+
cwd: this.resolve(options?.cwd ?? this.cwd),
|
|
256
|
+
...(options?.env ? { envs: options.env } : {}),
|
|
257
|
+
timeoutMs: tee
|
|
258
|
+
? Math.max(this.commandTimeoutMs(options?.timeout), (E2B_BG_MAX_TIMEOUT_SEC + E2B_BG_PROVIDER_BACKSTOP_PAD_SEC) * 1000)
|
|
259
|
+
: this.commandTimeoutMs(options?.timeout),
|
|
260
|
+
onStdout: (d) => {
|
|
261
|
+
if (tee)
|
|
262
|
+
teePush(tee.stdout, d);
|
|
263
|
+
if (!detached) {
|
|
264
|
+
lastProgress = Date.now();
|
|
265
|
+
options?.onStdout?.(d);
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
onStderr: (d) => {
|
|
269
|
+
if (tee)
|
|
270
|
+
teePush(tee.stderr, d);
|
|
271
|
+
if (!detached) {
|
|
272
|
+
lastProgress = Date.now();
|
|
273
|
+
options?.onStderr?.(d);
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
}), options?.abortSignal, this.cfg.livenessMs);
|
|
277
|
+
}
|
|
278
|
+
catch (e) {
|
|
279
|
+
this.activeCommands--;
|
|
280
|
+
return { ok: false, error: this.execError(e, options?.abortSignal) };
|
|
281
|
+
}
|
|
282
|
+
const onAbort = () => { if (!detached)
|
|
283
|
+
void handle.kill().catch(() => { }); };
|
|
284
|
+
if (options?.abortSignal) {
|
|
285
|
+
if (options.abortSignal.aborted)
|
|
286
|
+
onAbort();
|
|
287
|
+
else
|
|
288
|
+
options.abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
289
|
+
}
|
|
290
|
+
const waitP = handle.wait();
|
|
291
|
+
let fgResolved = false;
|
|
292
|
+
const markResolved = () => { fgResolved = true; };
|
|
293
|
+
waitP.then(markResolved, markResolved);
|
|
294
|
+
let fgSettled = false;
|
|
295
|
+
let adoptedShellId;
|
|
296
|
+
let onDetach;
|
|
297
|
+
const detachedP = detachSignal && tee
|
|
298
|
+
? new Promise((res) => {
|
|
299
|
+
onDetach = () => {
|
|
300
|
+
if (detached || fgSettled || fgResolved || options?.abortSignal?.aborted)
|
|
301
|
+
return;
|
|
302
|
+
const adopted = this.bgManager.adoptSync((ctx) => {
|
|
303
|
+
waitP
|
|
304
|
+
.then((r) => ctx.onTerminal(false, r.exitCode))
|
|
305
|
+
.catch((e) => {
|
|
306
|
+
if (e instanceof CommandExitError)
|
|
307
|
+
ctx.onTerminal(false, e.exitCode);
|
|
308
|
+
else
|
|
309
|
+
ctx.onTerminal(true);
|
|
310
|
+
});
|
|
311
|
+
return { handle, stdout: tee.stdout, stderr: tee.stderr };
|
|
312
|
+
});
|
|
313
|
+
if (!adopted)
|
|
314
|
+
return;
|
|
315
|
+
adoptedShellId = adopted.shellId;
|
|
316
|
+
detached = true;
|
|
317
|
+
res("detached");
|
|
318
|
+
};
|
|
319
|
+
if (detachSignal.aborted)
|
|
320
|
+
onDetach();
|
|
321
|
+
else
|
|
322
|
+
detachSignal.addEventListener("abort", onDetach, { once: true });
|
|
323
|
+
})
|
|
324
|
+
: undefined;
|
|
325
|
+
try {
|
|
326
|
+
const fg = this.waitWithLiveness(handle, () => lastProgress, {
|
|
327
|
+
waitP,
|
|
328
|
+
disarmed: () => detached,
|
|
329
|
+
...(tee ? { wallMs: this.commandTimeoutMs(options?.timeout) } : {}),
|
|
330
|
+
});
|
|
331
|
+
const winner = await (detachedP ? Promise.race([fg, detachedP]) : fg);
|
|
332
|
+
if (winner === "detached") {
|
|
333
|
+
const o = tee.stdout.tail.result();
|
|
334
|
+
const e = tee.stderr.tail.result();
|
|
335
|
+
return ok({
|
|
336
|
+
stdout: markTruncated(o.text, o.droppedBytes),
|
|
337
|
+
stderr: markTruncated(e.text, e.droppedBytes),
|
|
338
|
+
exitCode: 0,
|
|
339
|
+
detached: { shellId: adoptedShellId },
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
if (options?.abortSignal?.aborted && !detached) {
|
|
343
|
+
return { ok: false, error: new ExecutionError("aborted", "exec aborted (remote process killed)") };
|
|
344
|
+
}
|
|
345
|
+
return ok({ stdout: winner.stdout, stderr: winner.stderr, exitCode: winner.exitCode });
|
|
346
|
+
}
|
|
347
|
+
catch (e) {
|
|
348
|
+
if (options?.abortSignal?.aborted && !detached) {
|
|
349
|
+
return { ok: false, error: this.execError(e, options.abortSignal) };
|
|
350
|
+
}
|
|
351
|
+
if (e instanceof CommandExitError) {
|
|
352
|
+
return ok({ stdout: e.stdout, stderr: e.stderr, exitCode: e.exitCode });
|
|
353
|
+
}
|
|
354
|
+
return { ok: false, error: this.execError(e, options?.abortSignal) };
|
|
355
|
+
}
|
|
356
|
+
finally {
|
|
357
|
+
fgSettled = true;
|
|
358
|
+
if (onDetach && detachSignal)
|
|
359
|
+
detachSignal.removeEventListener("abort", onDetach);
|
|
360
|
+
this.activeCommands--;
|
|
361
|
+
options?.abortSignal?.removeEventListener("abort", onAbort);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
async *execStream(command, options) {
|
|
365
|
+
const conn = await this.ensureConnected();
|
|
366
|
+
if (!conn.ok)
|
|
367
|
+
throw conn.error;
|
|
368
|
+
const sbx = conn.value;
|
|
369
|
+
const queue = [];
|
|
370
|
+
let finished = false;
|
|
371
|
+
let failure;
|
|
372
|
+
let exitCode = 0;
|
|
373
|
+
let wake;
|
|
374
|
+
const signalReady = () => {
|
|
375
|
+
const w = wake;
|
|
376
|
+
wake = undefined;
|
|
377
|
+
w?.();
|
|
378
|
+
};
|
|
379
|
+
let bytes = 0;
|
|
380
|
+
const cap = options?.maxOutputBytes;
|
|
381
|
+
const push = (type, data) => {
|
|
382
|
+
if (finished)
|
|
383
|
+
return;
|
|
384
|
+
bytes += Buffer.byteLength(data, "utf8");
|
|
385
|
+
queue.push({ type, data });
|
|
386
|
+
signalReady();
|
|
387
|
+
};
|
|
388
|
+
this.activeCommands++;
|
|
389
|
+
let handle;
|
|
390
|
+
try {
|
|
391
|
+
handle = await this.rpc("commands.run", () => sbx.commands.run(command, {
|
|
392
|
+
background: true,
|
|
393
|
+
cwd: this.resolve(options?.cwd ?? this.cwd),
|
|
394
|
+
...(options?.env ? { envs: options.env } : {}),
|
|
395
|
+
timeoutMs: this.commandTimeoutMs(options?.timeout),
|
|
396
|
+
onStdout: (d) => push("stdout", d),
|
|
397
|
+
onStderr: (d) => push("stderr", d),
|
|
398
|
+
}), options?.signal, this.cfg.livenessMs);
|
|
399
|
+
}
|
|
400
|
+
catch (e) {
|
|
401
|
+
this.activeCommands--;
|
|
402
|
+
throw this.remoteError(e, "connect_failed");
|
|
403
|
+
}
|
|
404
|
+
handle
|
|
405
|
+
.wait()
|
|
406
|
+
.then((r) => {
|
|
407
|
+
if (finished)
|
|
408
|
+
return;
|
|
409
|
+
exitCode = r.exitCode;
|
|
410
|
+
finished = true;
|
|
411
|
+
signalReady();
|
|
412
|
+
})
|
|
413
|
+
.catch((e) => {
|
|
414
|
+
if (finished)
|
|
415
|
+
return;
|
|
416
|
+
if (e instanceof CommandExitError) {
|
|
417
|
+
exitCode = e.exitCode;
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
failure = this.remoteError(e, "unknown");
|
|
421
|
+
}
|
|
422
|
+
finished = true;
|
|
423
|
+
signalReady();
|
|
424
|
+
});
|
|
425
|
+
const onAbort = () => {
|
|
426
|
+
if (finished)
|
|
427
|
+
return;
|
|
428
|
+
failure = new RemoteExecutionError("aborted", "execStream aborted");
|
|
429
|
+
finished = true;
|
|
430
|
+
void handle.kill().catch(() => { });
|
|
431
|
+
signalReady();
|
|
432
|
+
};
|
|
433
|
+
if (options?.signal) {
|
|
434
|
+
if (options.signal.aborted)
|
|
435
|
+
onAbort();
|
|
436
|
+
else
|
|
437
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
438
|
+
}
|
|
439
|
+
let head = 0;
|
|
440
|
+
const drainQueued = function* () {
|
|
441
|
+
while (head < queue.length) {
|
|
442
|
+
const chunk = queue[head++];
|
|
443
|
+
yield chunk;
|
|
444
|
+
if (cap != null && bytes > cap) {
|
|
445
|
+
finished = true;
|
|
446
|
+
void handle.kill().catch(() => { });
|
|
447
|
+
throw new RemoteExecutionError("unknown", `execStream output exceeded maxOutputBytes=${cap}`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
queue.length = 0;
|
|
451
|
+
head = 0;
|
|
452
|
+
};
|
|
453
|
+
try {
|
|
454
|
+
while (true) {
|
|
455
|
+
yield* drainQueued();
|
|
456
|
+
if (finished)
|
|
457
|
+
break;
|
|
458
|
+
const next = new Promise((resolve) => {
|
|
459
|
+
wake = resolve;
|
|
460
|
+
});
|
|
461
|
+
const idleMs = options?.readTimeoutMs ?? this.cfg.livenessMs;
|
|
462
|
+
let timer;
|
|
463
|
+
const idle = new Promise((_, reject) => {
|
|
464
|
+
timer = setTimeout(() => reject(new RemoteExecutionError("timeout", `execStream idle > ${idleMs}ms (provider hang / unreachable sandbox)`)), idleMs);
|
|
465
|
+
});
|
|
466
|
+
try {
|
|
467
|
+
await Promise.race([next, idle]);
|
|
468
|
+
}
|
|
469
|
+
catch (e) {
|
|
470
|
+
finished = true;
|
|
471
|
+
void handle.kill().catch(() => { });
|
|
472
|
+
this.cfg.metrics?.inc("remote_env_exec_stream_read_timeout_total", { provider: PROVIDER });
|
|
473
|
+
throw e instanceof RemoteExecutionError ? e : this.remoteError(e);
|
|
474
|
+
}
|
|
475
|
+
finally {
|
|
476
|
+
if (timer)
|
|
477
|
+
clearTimeout(timer);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
yield* drainQueued();
|
|
481
|
+
if (failure)
|
|
482
|
+
throw failure;
|
|
483
|
+
yield { type: "exit", exitCode };
|
|
484
|
+
}
|
|
485
|
+
finally {
|
|
486
|
+
if (!finished) {
|
|
487
|
+
finished = true;
|
|
488
|
+
void handle.kill().catch(() => { });
|
|
489
|
+
}
|
|
490
|
+
this.activeCommands--;
|
|
491
|
+
options?.signal?.removeEventListener("abort", onAbort);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
backgroundCapabilities = {
|
|
495
|
+
supported: true,
|
|
496
|
+
maxConcurrent: E2B_BG_MAX_CONCURRENT,
|
|
497
|
+
defaultBgTimeoutSec: E2B_BG_DEFAULT_TIMEOUT_SEC,
|
|
498
|
+
maxBgTimeoutSec: E2B_BG_MAX_TIMEOUT_SEC,
|
|
499
|
+
supportsDetach: true,
|
|
500
|
+
};
|
|
501
|
+
_bgManager;
|
|
502
|
+
get bgManager() {
|
|
503
|
+
return (this._bgManager ??= new BackgroundShellManager(this.makeBgDriver(), this.backgroundCapabilities));
|
|
504
|
+
}
|
|
505
|
+
makeBgDriver() {
|
|
506
|
+
const self = this;
|
|
507
|
+
return {
|
|
508
|
+
async launch(command, options, ctx) {
|
|
509
|
+
const conn = await self.ensureConnected();
|
|
510
|
+
if (!conn.ok)
|
|
511
|
+
throw new Error(`remote connect failed: ${conn.error.message}`);
|
|
512
|
+
const sbx = conn.value;
|
|
513
|
+
const stdout = { tail: new RollingTailBuffer(), total: 0, cursor: 0 };
|
|
514
|
+
const stderr = { tail: new RollingTailBuffer(), total: 0, cursor: 0 };
|
|
515
|
+
const handle = await self.rpc("commands.run.bg", () => sbx.commands.run(command, {
|
|
516
|
+
background: true,
|
|
517
|
+
cwd: self.resolve(options?.cwd ?? self.cwd),
|
|
518
|
+
...(options?.env ? { envs: options.env } : {}),
|
|
519
|
+
timeoutMs: (ctx.bgTimeoutSec + E2B_BG_PROVIDER_BACKSTOP_PAD_SEC) * 1000,
|
|
520
|
+
onStdout: (d) => {
|
|
521
|
+
const b = Buffer.from(d, "utf8");
|
|
522
|
+
stdout.tail.push(b);
|
|
523
|
+
stdout.total += b.length;
|
|
524
|
+
},
|
|
525
|
+
onStderr: (d) => {
|
|
526
|
+
const b = Buffer.from(d, "utf8");
|
|
527
|
+
stderr.tail.push(b);
|
|
528
|
+
stderr.total += b.length;
|
|
529
|
+
},
|
|
530
|
+
}), undefined, self.cfg.livenessMs);
|
|
531
|
+
handle
|
|
532
|
+
.wait()
|
|
533
|
+
.then((r) => ctx.onTerminal(false, r.exitCode))
|
|
534
|
+
.catch((e) => {
|
|
535
|
+
if (e instanceof CommandExitError)
|
|
536
|
+
ctx.onTerminal(false, e.exitCode);
|
|
537
|
+
else
|
|
538
|
+
ctx.onTerminal(true);
|
|
539
|
+
});
|
|
540
|
+
return { handle, stdout, stderr };
|
|
541
|
+
},
|
|
542
|
+
async read(state) {
|
|
543
|
+
const slice = (s) => {
|
|
544
|
+
const { text, droppedBytes } = s.tail.result();
|
|
545
|
+
const droppedBeforeCursor = Math.max(0, droppedBytes - s.cursor);
|
|
546
|
+
const startByte = Math.max(s.cursor, droppedBytes);
|
|
547
|
+
const startInTail = startByte - droppedBytes;
|
|
548
|
+
const reencoded = Buffer.from(text, "utf8");
|
|
549
|
+
const delta = reencoded.length - (s.total - droppedBytes);
|
|
550
|
+
const inc = startInTail <= 0 ? text : reencoded.subarray(startInTail + delta).toString("utf8");
|
|
551
|
+
s.cursor = s.total;
|
|
552
|
+
return { inc, droppedBeforeCursor };
|
|
553
|
+
};
|
|
554
|
+
const out = slice(state.stdout);
|
|
555
|
+
const er = slice(state.stderr);
|
|
556
|
+
return {
|
|
557
|
+
stdout: out.inc,
|
|
558
|
+
stderr: er.inc,
|
|
559
|
+
bytesFromStart: state.stdout.total + state.stderr.total,
|
|
560
|
+
bytesDroppedBeforeCursor: out.droppedBeforeCursor + er.droppedBeforeCursor,
|
|
561
|
+
};
|
|
562
|
+
},
|
|
563
|
+
async kill(state) {
|
|
564
|
+
await state.handle.kill().catch(() => { });
|
|
565
|
+
},
|
|
566
|
+
async disposeOne(state) {
|
|
567
|
+
await state.handle.kill().catch(() => { });
|
|
568
|
+
},
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
spawnBackground(command, options) {
|
|
572
|
+
return this.bgManager.spawn(command, options);
|
|
573
|
+
}
|
|
574
|
+
pollBackground(shellId) {
|
|
575
|
+
return this.bgManager.poll(shellId);
|
|
576
|
+
}
|
|
577
|
+
killBackground(shellId) {
|
|
578
|
+
return this.bgManager.kill(shellId);
|
|
579
|
+
}
|
|
580
|
+
disposeBackgroundShells(opts) {
|
|
581
|
+
return this._bgManager ? this._bgManager.dispose(opts) : Promise.resolve();
|
|
582
|
+
}
|
|
583
|
+
async absolutePath(p) {
|
|
584
|
+
return ok(this.resolve(p));
|
|
585
|
+
}
|
|
586
|
+
async joinPath(parts) {
|
|
587
|
+
return ok(path.posix.join(...parts));
|
|
588
|
+
}
|
|
589
|
+
async readTextFile(p, abortSignal) {
|
|
590
|
+
const sbx = await this.fsReady(p);
|
|
591
|
+
if (!sbx.ok)
|
|
592
|
+
return sbx;
|
|
593
|
+
try {
|
|
594
|
+
const content = await this.rpc("files.read", (signal) => sbx.value.files.read(this.resolve(p), { format: "text", signal }), abortSignal, this.cfg.dataTimeoutMs);
|
|
595
|
+
return ok(content);
|
|
596
|
+
}
|
|
597
|
+
catch (e) {
|
|
598
|
+
return { ok: false, error: this.fileError(e, this.resolve(p), abortSignal) };
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
async readTextLines(p, options) {
|
|
602
|
+
const r = await this.readTextFile(p, options?.abortSignal);
|
|
603
|
+
if (!r.ok)
|
|
604
|
+
return r;
|
|
605
|
+
let lines = r.value.split(/\r?\n/);
|
|
606
|
+
if (lines.length > 0 && lines[lines.length - 1] === "")
|
|
607
|
+
lines.pop();
|
|
608
|
+
if (options?.maxLines != null)
|
|
609
|
+
lines = lines.slice(0, options.maxLines);
|
|
610
|
+
return ok(lines);
|
|
611
|
+
}
|
|
612
|
+
async readBinaryFile(p, abortSignal) {
|
|
613
|
+
const sbx = await this.fsReady(p);
|
|
614
|
+
if (!sbx.ok)
|
|
615
|
+
return sbx;
|
|
616
|
+
try {
|
|
617
|
+
const content = await this.rpc("files.read", (signal) => sbx.value.files.read(this.resolve(p), { format: "bytes", signal }), abortSignal, this.cfg.dataTimeoutMs);
|
|
618
|
+
return ok(content);
|
|
619
|
+
}
|
|
620
|
+
catch (e) {
|
|
621
|
+
return { ok: false, error: this.fileError(e, this.resolve(p), abortSignal) };
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
async writeFile(p, content, abortSignal) {
|
|
625
|
+
const sbx = await this.fsReady(p);
|
|
626
|
+
if (!sbx.ok)
|
|
627
|
+
return sbx;
|
|
628
|
+
try {
|
|
629
|
+
const data = typeof content === "string" ? content : toArrayBuffer(content);
|
|
630
|
+
await this.rpc("files.write", (signal) => sbx.value.files.write(this.resolve(p), data, { signal }), abortSignal, this.cfg.dataTimeoutMs);
|
|
631
|
+
return ok(undefined);
|
|
632
|
+
}
|
|
633
|
+
catch (e) {
|
|
634
|
+
return { ok: false, error: this.fileError(e, this.resolve(p), abortSignal) };
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
async appendFile(p, content, abortSignal) {
|
|
638
|
+
const abs = this.resolve(p);
|
|
639
|
+
const existing = await this.readBinaryFile(abs, abortSignal);
|
|
640
|
+
let base;
|
|
641
|
+
if (existing.ok) {
|
|
642
|
+
base = existing.value;
|
|
643
|
+
}
|
|
644
|
+
else if (existing.error.code === "not_found") {
|
|
645
|
+
base = new Uint8Array(0);
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
return existing;
|
|
649
|
+
}
|
|
650
|
+
const add = typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
651
|
+
const merged = new Uint8Array(base.length + add.length);
|
|
652
|
+
merged.set(base, 0);
|
|
653
|
+
merged.set(add, base.length);
|
|
654
|
+
return this.writeFile(abs, merged, abortSignal);
|
|
655
|
+
}
|
|
656
|
+
async fileInfo(p, abortSignal) {
|
|
657
|
+
const sbx = await this.fsReady(p);
|
|
658
|
+
if (!sbx.ok)
|
|
659
|
+
return sbx;
|
|
660
|
+
try {
|
|
661
|
+
const info = await this.rpc("files.getInfo", (signal) => sbx.value.files.getInfo(this.resolve(p), { signal }), abortSignal);
|
|
662
|
+
return ok(this.toFileInfo(info));
|
|
663
|
+
}
|
|
664
|
+
catch (e) {
|
|
665
|
+
return { ok: false, error: this.fileError(e, this.resolve(p), abortSignal) };
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
async listDir(p, abortSignal) {
|
|
669
|
+
const sbx = await this.fsReady(p);
|
|
670
|
+
if (!sbx.ok)
|
|
671
|
+
return sbx;
|
|
672
|
+
try {
|
|
673
|
+
const entries = await this.rpc("files.list", (signal) => sbx.value.files.list(this.resolve(p), { signal }), abortSignal);
|
|
674
|
+
return ok(entries.map((e) => this.toFileInfo(e)));
|
|
675
|
+
}
|
|
676
|
+
catch (e) {
|
|
677
|
+
return { ok: false, error: this.fileError(e, this.resolve(p), abortSignal) };
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
async canonicalPath(p, abortSignal) {
|
|
681
|
+
const abs = this.resolve(p);
|
|
682
|
+
const r = await this.exec(`realpath -- ${shellQuote(abs)}`, { abortSignal });
|
|
683
|
+
if (!r.ok)
|
|
684
|
+
return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
|
|
685
|
+
if (r.value.exitCode !== 0) {
|
|
686
|
+
const msg = r.value.stderr.trim();
|
|
687
|
+
if (/permission denied|access denied/i.test(msg))
|
|
688
|
+
return { ok: false, error: new FileError("permission_denied", msg, abs) };
|
|
689
|
+
if (/not a directory/i.test(msg))
|
|
690
|
+
return { ok: false, error: new FileError("not_directory", msg, abs) };
|
|
691
|
+
return { ok: false, error: new FileError("not_found", msg || `realpath failed for ${abs}`, abs) };
|
|
692
|
+
}
|
|
693
|
+
return ok(r.value.stdout.trim());
|
|
694
|
+
}
|
|
695
|
+
async exists(p, abortSignal) {
|
|
696
|
+
const sbx = await this.fsReady(p);
|
|
697
|
+
if (!sbx.ok)
|
|
698
|
+
return sbx;
|
|
699
|
+
try {
|
|
700
|
+
const exists = await this.rpc("files.exists", (signal) => sbx.value.files.exists(this.resolve(p), { signal }), abortSignal);
|
|
701
|
+
return ok(exists);
|
|
702
|
+
}
|
|
703
|
+
catch (e) {
|
|
704
|
+
const fe = this.fileError(e, this.resolve(p), abortSignal);
|
|
705
|
+
if (fe.code === "not_found")
|
|
706
|
+
return ok(false);
|
|
707
|
+
return { ok: false, error: fe };
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
async createDir(p, options) {
|
|
711
|
+
const sbx = await this.fsReady(p);
|
|
712
|
+
if (!sbx.ok)
|
|
713
|
+
return sbx;
|
|
714
|
+
try {
|
|
715
|
+
await this.rpc("files.makeDir", (signal) => sbx.value.files.makeDir(this.resolve(p), { signal }), options?.abortSignal);
|
|
716
|
+
return ok(undefined);
|
|
717
|
+
}
|
|
718
|
+
catch (e) {
|
|
719
|
+
return { ok: false, error: this.fileError(e, this.resolve(p), options?.abortSignal) };
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
async remove(p, options) {
|
|
723
|
+
const sbx = await this.fsReady(p);
|
|
724
|
+
if (!sbx.ok)
|
|
725
|
+
return sbx;
|
|
726
|
+
const abs = this.resolve(p);
|
|
727
|
+
if (options?.recursive) {
|
|
728
|
+
const flags = options.force ? "-rf" : "-r";
|
|
729
|
+
const r = await this.exec(`rm ${flags} -- ${shellQuote(abs)}`, { abortSignal: options.abortSignal });
|
|
730
|
+
if (!r.ok)
|
|
731
|
+
return { ok: false, error: new FileError("unknown", r.error.message, abs, r.error) };
|
|
732
|
+
if (r.value.exitCode !== 0)
|
|
733
|
+
return { ok: false, error: new FileError("unknown", r.value.stderr.trim() || `rm failed for ${abs}`, abs) };
|
|
734
|
+
return ok(undefined);
|
|
735
|
+
}
|
|
736
|
+
try {
|
|
737
|
+
await this.rpc("files.remove", (signal) => sbx.value.files.remove(abs, { signal }), options?.abortSignal);
|
|
738
|
+
return ok(undefined);
|
|
739
|
+
}
|
|
740
|
+
catch (e) {
|
|
741
|
+
const fe = this.fileError(e, abs, options?.abortSignal);
|
|
742
|
+
if (options?.force && fe.code === "not_found")
|
|
743
|
+
return ok(undefined);
|
|
744
|
+
return { ok: false, error: fe };
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
async createTempDir(prefix = "tmp-", abortSignal) {
|
|
748
|
+
const r = await this.exec(`mktemp -d -t ${shellQuote(`${prefix}XXXXXX`)}`, { abortSignal });
|
|
749
|
+
return this.tempResult(r, "mktemp -d");
|
|
750
|
+
}
|
|
751
|
+
async createTempFile(options) {
|
|
752
|
+
const prefix = options?.prefix ?? "";
|
|
753
|
+
const suffix = options?.suffix ?? "";
|
|
754
|
+
const suffixArg = suffix ? `--suffix=${shellQuote(suffix)} -t` : "-t";
|
|
755
|
+
const r = await this.exec(`mktemp ${suffixArg} ${shellQuote(`${prefix}XXXXXX`)}`, { abortSignal: options?.abortSignal });
|
|
756
|
+
return this.tempResult(r, "mktemp");
|
|
757
|
+
}
|
|
758
|
+
resolve(p) {
|
|
759
|
+
return path.posix.isAbsolute(p) ? path.posix.normalize(p) : path.posix.normalize(path.posix.join(this.cwd, p));
|
|
760
|
+
}
|
|
761
|
+
async rpc(label, op, userSignal, timeoutMs = this.cfg.rpcTimeoutMs) {
|
|
762
|
+
const deadline = new AbortController();
|
|
763
|
+
const timer = setTimeout(() => deadline.abort(), timeoutMs);
|
|
764
|
+
const combined = userSignal ? anySignal([userSignal, deadline.signal]) : undefined;
|
|
765
|
+
const signal = combined?.signal ?? deadline.signal;
|
|
766
|
+
const onDeadline = new Promise((_, reject) => deadline.signal.addEventListener("abort", () => {
|
|
767
|
+
this.cfg.metrics?.inc("remote_env_rpc_timeout_total", { provider: PROVIDER, op: label });
|
|
768
|
+
reject(new RemoteExecutionError("timeout", `remote ${label} exceeded ${timeoutMs}ms (provider RPC hang)`));
|
|
769
|
+
}, { once: true }));
|
|
770
|
+
try {
|
|
771
|
+
return await Promise.race([op(signal), onDeadline]);
|
|
772
|
+
}
|
|
773
|
+
finally {
|
|
774
|
+
clearTimeout(timer);
|
|
775
|
+
combined?.dispose();
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
commandTimeoutMs(timeoutSec) {
|
|
779
|
+
return timeoutSec != null ? timeoutSec * 1000 : this.cfg.timeoutMs;
|
|
780
|
+
}
|
|
781
|
+
async waitWithLiveness(handle, lastProgress, opts) {
|
|
782
|
+
let timer;
|
|
783
|
+
let wallTimer;
|
|
784
|
+
const idle = new Promise((_, reject) => {
|
|
785
|
+
const arm = () => {
|
|
786
|
+
timer = setTimeout(() => {
|
|
787
|
+
if (opts?.disarmed?.())
|
|
788
|
+
return;
|
|
789
|
+
const idleFor = Date.now() - lastProgress();
|
|
790
|
+
if (idleFor >= this.cfg.livenessMs) {
|
|
791
|
+
void handle.kill().catch(() => { });
|
|
792
|
+
this.cfg.metrics?.inc("remote_env_exec_idle_timeout_total", { provider: PROVIDER });
|
|
793
|
+
reject(new RemoteExecutionError("timeout", `exec idle > ${this.cfg.livenessMs}ms (provider hang / unreachable sandbox)`));
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
arm();
|
|
797
|
+
}
|
|
798
|
+
}, Math.max(this.cfg.livenessMs - (Date.now() - lastProgress()), 0));
|
|
799
|
+
};
|
|
800
|
+
arm();
|
|
801
|
+
if (opts?.wallMs != null) {
|
|
802
|
+
wallTimer = setTimeout(() => {
|
|
803
|
+
if (opts.disarmed?.())
|
|
804
|
+
return;
|
|
805
|
+
void handle.kill().catch(() => { });
|
|
806
|
+
reject(new RemoteExecutionError("timeout", `exec exceeded ${opts.wallMs}ms`));
|
|
807
|
+
}, opts.wallMs);
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
try {
|
|
811
|
+
return await Promise.race([opts?.waitP ?? handle.wait(), idle]);
|
|
812
|
+
}
|
|
813
|
+
finally {
|
|
814
|
+
if (timer)
|
|
815
|
+
clearTimeout(timer);
|
|
816
|
+
if (wallTimer)
|
|
817
|
+
clearTimeout(wallTimer);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
async ensureConnected() {
|
|
821
|
+
if (this.paused)
|
|
822
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "execution env is suspended (paused) — resume before fs/exec") };
|
|
823
|
+
if (this.sbx)
|
|
824
|
+
return ok(this.sbx);
|
|
825
|
+
if (this.destroyed)
|
|
826
|
+
return { ok: false, error: new RemoteExecutionError("connect_failed", "execution env already destroyed") };
|
|
827
|
+
const r = await this.connect();
|
|
828
|
+
if (!r.ok)
|
|
829
|
+
return { ok: false, error: r.error };
|
|
830
|
+
return ok(this.sbx);
|
|
831
|
+
}
|
|
832
|
+
async fsReady(p) {
|
|
833
|
+
const conn = await this.ensureConnected();
|
|
834
|
+
if (!conn.ok)
|
|
835
|
+
return { ok: false, error: new FileError("unknown", `remote connect failed: ${conn.error.message}`, this.resolve(p), conn.error) };
|
|
836
|
+
return ok(conn.value);
|
|
837
|
+
}
|
|
838
|
+
tempResult(r, op) {
|
|
839
|
+
if (!r.ok)
|
|
840
|
+
return { ok: false, error: new FileError("unknown", r.error.message, undefined, r.error) };
|
|
841
|
+
if (r.value.exitCode !== 0)
|
|
842
|
+
return { ok: false, error: new FileError("unknown", r.value.stderr.trim() || `${op} failed`) };
|
|
843
|
+
return ok(r.value.stdout.trim());
|
|
844
|
+
}
|
|
845
|
+
toFileInfo(e) {
|
|
846
|
+
const kind = e.symlinkTarget ? "symlink" : e.type === FileType.DIR ? "directory" : "file";
|
|
847
|
+
return {
|
|
848
|
+
name: e.name,
|
|
849
|
+
path: e.path,
|
|
850
|
+
kind,
|
|
851
|
+
size: e.size ?? 0,
|
|
852
|
+
mtimeMs: e.modifiedTime ? e.modifiedTime.getTime() : 0,
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
fileError(e, p, abortSignal) {
|
|
856
|
+
if (e instanceof FileError)
|
|
857
|
+
return e;
|
|
858
|
+
const msg = errMsg(e);
|
|
859
|
+
const name = e?.name;
|
|
860
|
+
if (abortSignal?.aborted || name === "AbortError")
|
|
861
|
+
return new FileError("aborted", msg, p);
|
|
862
|
+
if (e instanceof RemoteExecutionError && e.code === "timeout") {
|
|
863
|
+
this.cfg.metrics?.inc("remote_env_file_timeout_total", { provider: PROVIDER });
|
|
864
|
+
return new FileError("timeout", msg, p, e);
|
|
865
|
+
}
|
|
866
|
+
if (name === "SandboxNotFoundError" || /sandbox .*not found|sandbox .*not running|sandbox was not found/i.test(msg)) {
|
|
867
|
+
return new FileError("unknown", msg, p);
|
|
868
|
+
}
|
|
869
|
+
if (name === "FileNotFoundError" || name === "NotFoundError" || /no such file|file not found/i.test(msg)) {
|
|
870
|
+
return new FileError("not_found", msg, p);
|
|
871
|
+
}
|
|
872
|
+
if (name === "InvalidArgumentError")
|
|
873
|
+
return new FileError("invalid", msg, p);
|
|
874
|
+
if (/permission denied|access denied/i.test(msg))
|
|
875
|
+
return new FileError("permission_denied", msg, p);
|
|
876
|
+
if (/not a directory/i.test(msg))
|
|
877
|
+
return new FileError("not_directory", msg, p);
|
|
878
|
+
if (/is a directory/i.test(msg))
|
|
879
|
+
return new FileError("is_directory", msg, p);
|
|
880
|
+
return new FileError("unknown", msg, p);
|
|
881
|
+
}
|
|
882
|
+
execError(e, abortSignal) {
|
|
883
|
+
if (e instanceof ExecutionError)
|
|
884
|
+
return e;
|
|
885
|
+
const msg = errMsg(e);
|
|
886
|
+
const name = e?.name;
|
|
887
|
+
if (abortSignal?.aborted || name === "AbortError")
|
|
888
|
+
return new ExecutionError("aborted", msg);
|
|
889
|
+
if (name === "TimeoutError" || /timeout|timed out/i.test(msg))
|
|
890
|
+
return new ExecutionError("timeout", msg);
|
|
891
|
+
return new ExecutionError("unknown", msg, e instanceof Error ? e : undefined);
|
|
892
|
+
}
|
|
893
|
+
remoteError(e, code = "unknown") {
|
|
894
|
+
if (e instanceof RemoteExecutionError)
|
|
895
|
+
return e;
|
|
896
|
+
return new RemoteExecutionError(code, errMsg(e), e instanceof Error ? e : undefined);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
export function e2bExecutionEnvFactory(config, deps) {
|
|
900
|
+
return (ctx) => new RemoteContainerExecutionEnv({
|
|
901
|
+
...config,
|
|
902
|
+
metadata: { ...config.metadata, sessionId: ctx.sessionId, ...(ctx.taskId ? { taskId: ctx.taskId } : {}) },
|
|
903
|
+
}, deps);
|
|
904
|
+
}
|
|
905
|
+
function errMsg(e) {
|
|
906
|
+
return e instanceof Error ? e.message : String(e);
|
|
907
|
+
}
|
|
908
|
+
function anySignal(signals) {
|
|
909
|
+
const ctor = AbortSignal;
|
|
910
|
+
if (typeof ctor.any === "function")
|
|
911
|
+
return { signal: ctor.any(signals), dispose: () => { } };
|
|
912
|
+
const ctrl = new AbortController();
|
|
913
|
+
const onAbort = () => ctrl.abort();
|
|
914
|
+
const cleanups = [];
|
|
915
|
+
for (const s of signals) {
|
|
916
|
+
if (s.aborted) {
|
|
917
|
+
ctrl.abort();
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
920
|
+
s.addEventListener("abort", onAbort, { once: true });
|
|
921
|
+
cleanups.push(() => s.removeEventListener("abort", onAbort));
|
|
922
|
+
}
|
|
923
|
+
return { signal: ctrl.signal, dispose: () => cleanups.forEach((c) => c()) };
|
|
924
|
+
}
|
|
925
|
+
function shellQuote(s) {
|
|
926
|
+
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
927
|
+
}
|
|
928
|
+
function toArrayBuffer(u) {
|
|
929
|
+
return u.buffer.slice(u.byteOffset, u.byteOffset + u.byteLength);
|
|
930
|
+
}
|
|
931
|
+
//# sourceMappingURL=remote-env-e2b.js.map
|