@stateset/sandbox-cli 1.0.6 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/LICENSE +22 -0
- package/README.md +590 -6
- package/dist/client.d.ts +761 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +684 -12
- package/dist/client.js.map +1 -1
- package/dist/commands/alias.d.ts +5 -0
- package/dist/commands/alias.d.ts.map +1 -0
- package/dist/commands/alias.js +131 -0
- package/dist/commands/alias.js.map +1 -0
- package/dist/commands/api-key.d.ts +3 -0
- package/dist/commands/api-key.d.ts.map +1 -0
- package/dist/commands/api-key.js +119 -0
- package/dist/commands/api-key.js.map +1 -0
- package/dist/commands/artifact.d.ts.map +1 -1
- package/dist/commands/artifact.js +105 -46
- package/dist/commands/artifact.js.map +1 -1
- package/dist/commands/audit.d.ts +3 -0
- package/dist/commands/audit.d.ts.map +1 -0
- package/dist/commands/audit.js +191 -0
- package/dist/commands/audit.js.map +1 -0
- package/dist/commands/auth.d.ts +3 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +126 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/benchmark.d.ts +3 -0
- package/dist/commands/benchmark.d.ts.map +1 -0
- package/dist/commands/benchmark.js +166 -0
- package/dist/commands/benchmark.js.map +1 -0
- package/dist/commands/billing.d.ts +3 -0
- package/dist/commands/billing.d.ts.map +1 -0
- package/dist/commands/billing.js +139 -0
- package/dist/commands/billing.js.map +1 -0
- package/dist/commands/checkpoint.d.ts.map +1 -1
- package/dist/commands/checkpoint.js +105 -48
- package/dist/commands/checkpoint.js.map +1 -1
- package/dist/commands/completion.d.ts +3 -0
- package/dist/commands/completion.d.ts.map +1 -0
- package/dist/commands/completion.js +134 -0
- package/dist/commands/completion.js.map +1 -0
- package/dist/commands/computer-use.d.ts +3 -0
- package/dist/commands/computer-use.d.ts.map +1 -0
- package/dist/commands/computer-use.js +124 -0
- package/dist/commands/computer-use.js.map +1 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +2 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/context.d.ts +3 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +98 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/cp.d.ts +3 -0
- package/dist/commands/cp.d.ts.map +1 -0
- package/dist/commands/cp.js +165 -0
- package/dist/commands/cp.js.map +1 -0
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +68 -20
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/diff.d.ts +3 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +186 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/doctor.d.ts +30 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +177 -207
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/egress.d.ts +3 -0
- package/dist/commands/egress.d.ts.map +1 -0
- package/dist/commands/egress.js +155 -0
- package/dist/commands/egress.js.map +1 -0
- package/dist/commands/env.d.ts +3 -0
- package/dist/commands/env.d.ts.map +1 -0
- package/dist/commands/env.js +169 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/governance.d.ts +47 -0
- package/dist/commands/governance.d.ts.map +1 -0
- package/dist/commands/governance.js +345 -0
- package/dist/commands/governance.js.map +1 -0
- package/dist/commands/grade.d.ts +41 -0
- package/dist/commands/grade.d.ts.map +1 -1
- package/dist/commands/grade.js +255 -160
- package/dist/commands/grade.js.map +1 -1
- package/dist/commands/history.d.ts +4 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +157 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/images.d.ts +8 -0
- package/dist/commands/images.d.ts.map +1 -0
- package/dist/commands/images.js +145 -0
- package/dist/commands/images.js.map +1 -0
- package/dist/commands/info.d.ts +3 -0
- package/dist/commands/info.d.ts.map +1 -0
- package/dist/commands/info.js +86 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +185 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/logs.d.ts +3 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +129 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +141 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/open.d.ts +3 -0
- package/dist/commands/open.d.ts.map +1 -0
- package/dist/commands/open.js +96 -0
- package/dist/commands/open.js.map +1 -0
- package/dist/commands/platform-status.d.ts +25 -5
- package/dist/commands/platform-status.d.ts.map +1 -1
- package/dist/commands/platform-status.js +199 -149
- package/dist/commands/platform-status.js.map +1 -1
- package/dist/commands/plugin.d.ts +5 -0
- package/dist/commands/plugin.d.ts.map +1 -0
- package/dist/commands/plugin.js +126 -0
- package/dist/commands/plugin.js.map +1 -0
- package/dist/commands/pool.d.ts.map +1 -1
- package/dist/commands/pool.js +52 -66
- package/dist/commands/pool.js.map +1 -1
- package/dist/commands/profile.d.ts +3 -0
- package/dist/commands/profile.d.ts.map +1 -0
- package/dist/commands/profile.js +107 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/repl.d.ts +3 -0
- package/dist/commands/repl.d.ts.map +1 -0
- package/dist/commands/repl.js +390 -0
- package/dist/commands/repl.js.map +1 -0
- package/dist/commands/run.d.ts +3 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +121 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/sandbox-processes.d.ts +27 -0
- package/dist/commands/sandbox-processes.d.ts.map +1 -0
- package/dist/commands/sandbox-processes.js +195 -0
- package/dist/commands/sandbox-processes.js.map +1 -0
- package/dist/commands/sandbox.d.ts.map +1 -1
- package/dist/commands/sandbox.js +506 -98
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/secret.d.ts +3 -0
- package/dist/commands/secret.d.ts.map +1 -0
- package/dist/commands/secret.js +128 -0
- package/dist/commands/secret.js.map +1 -0
- package/dist/commands/session.d.ts.map +1 -1
- package/dist/commands/session.js +285 -52
- package/dist/commands/session.js.map +1 -1
- package/dist/commands/snapshot.d.ts +3 -0
- package/dist/commands/snapshot.d.ts.map +1 -0
- package/dist/commands/snapshot.js +253 -0
- package/dist/commands/snapshot.js.map +1 -0
- package/dist/commands/ssh.d.ts +5 -0
- package/dist/commands/ssh.d.ts.map +1 -0
- package/dist/commands/ssh.js +154 -0
- package/dist/commands/ssh.js.map +1 -0
- package/dist/commands/template.d.ts +3 -0
- package/dist/commands/template.d.ts.map +1 -0
- package/dist/commands/template.js +102 -0
- package/dist/commands/template.js.map +1 -0
- package/dist/commands/terminal.d.ts +53 -0
- package/dist/commands/terminal.d.ts.map +1 -0
- package/dist/commands/terminal.js +381 -0
- package/dist/commands/terminal.js.map +1 -0
- package/dist/commands/top.d.ts +3 -0
- package/dist/commands/top.d.ts.map +1 -0
- package/dist/commands/top.js +116 -0
- package/dist/commands/top.js.map +1 -0
- package/dist/commands/tunnel.d.ts.map +1 -1
- package/dist/commands/tunnel.js +73 -26
- package/dist/commands/tunnel.js.map +1 -1
- package/dist/commands/update.d.ts +3 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +51 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/wait.d.ts +3 -0
- package/dist/commands/wait.d.ts.map +1 -0
- package/dist/commands/wait.js +64 -0
- package/dist/commands/wait.js.map +1 -0
- package/dist/commands/webhook.d.ts +3 -0
- package/dist/commands/webhook.d.ts.map +1 -0
- package/dist/commands/webhook.js +169 -0
- package/dist/commands/webhook.js.map +1 -0
- package/dist/config.d.ts +14 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +109 -16
- package/dist/config.js.map +1 -1
- package/dist/index.js +165 -11
- package/dist/index.js.map +1 -1
- package/dist/sandboxctl.d.ts +3 -0
- package/dist/sandboxctl.d.ts.map +1 -0
- package/dist/sandboxctl.js +37 -0
- package/dist/sandboxctl.js.map +1 -0
- package/dist/utils/context.d.ts +23 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +48 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/credentials.d.ts +8 -0
- package/dist/utils/credentials.d.ts.map +1 -0
- package/dist/utils/credentials.js +120 -0
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/dry-run.d.ts +4 -0
- package/dist/utils/dry-run.d.ts.map +1 -0
- package/dist/utils/dry-run.js +24 -0
- package/dist/utils/dry-run.js.map +1 -0
- package/dist/utils/egress-policy.d.ts +31 -0
- package/dist/utils/egress-policy.d.ts.map +1 -0
- package/dist/utils/egress-policy.js +83 -0
- package/dist/utils/egress-policy.js.map +1 -0
- package/dist/utils/errors.d.ts +53 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +278 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/file-content.d.ts +10 -0
- package/dist/utils/file-content.d.ts.map +1 -0
- package/dist/utils/file-content.js +14 -0
- package/dist/utils/file-content.js.map +1 -0
- package/dist/utils/grade-target.d.ts +12 -0
- package/dist/utils/grade-target.d.ts.map +1 -0
- package/dist/utils/grade-target.js +106 -0
- package/dist/utils/grade-target.js.map +1 -0
- package/dist/utils/health-report.d.ts +18 -0
- package/dist/utils/health-report.d.ts.map +1 -0
- package/dist/utils/health-report.js +43 -0
- package/dist/utils/health-report.js.map +1 -0
- package/dist/utils/output.d.ts +20 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +123 -0
- package/dist/utils/output.js.map +1 -0
- package/dist/utils/plugins.d.ts +17 -0
- package/dist/utils/plugins.d.ts.map +1 -0
- package/dist/utils/plugins.js +57 -0
- package/dist/utils/plugins.js.map +1 -0
- package/dist/utils/resource-class.d.ts +12 -0
- package/dist/utils/resource-class.d.ts.map +1 -0
- package/dist/utils/resource-class.js +17 -0
- package/dist/utils/resource-class.js.map +1 -0
- package/dist/utils/shutdown.d.ts +14 -0
- package/dist/utils/shutdown.d.ts.map +1 -0
- package/dist/utils/shutdown.js +54 -0
- package/dist/utils/shutdown.js.map +1 -0
- package/dist/utils/tty.d.ts +44 -0
- package/dist/utils/tty.d.ts.map +1 -0
- package/dist/utils/tty.js +93 -0
- package/dist/utils/tty.js.map +1 -0
- package/dist/utils/warnings.d.ts +4 -0
- package/dist/utils/warnings.d.ts.map +1 -0
- package/dist/utils/warnings.js +22 -0
- package/dist/utils/warnings.js.map +1 -0
- package/dist/utils/watch.d.ts +7 -0
- package/dist/utils/watch.d.ts.map +1 -0
- package/dist/utils/watch.js +55 -0
- package/dist/utils/watch.js.map +1 -0
- package/dist/workbench/actions.d.ts +26 -0
- package/dist/workbench/actions.d.ts.map +1 -0
- package/dist/workbench/actions.js +38 -0
- package/dist/workbench/actions.js.map +1 -0
- package/dist/workbench/agent-chat.d.ts +71 -0
- package/dist/workbench/agent-chat.d.ts.map +1 -0
- package/dist/workbench/agent-chat.js +223 -0
- package/dist/workbench/agent-chat.js.map +1 -0
- package/dist/workbench/batch-uploads.d.ts +36 -0
- package/dist/workbench/batch-uploads.d.ts.map +1 -0
- package/dist/workbench/batch-uploads.js +154 -0
- package/dist/workbench/batch-uploads.js.map +1 -0
- package/dist/workbench/commands.d.ts +6 -0
- package/dist/workbench/commands.d.ts.map +1 -0
- package/dist/workbench/commands.js +511 -0
- package/dist/workbench/commands.js.map +1 -0
- package/dist/workbench/connection-failure.d.ts +9 -0
- package/dist/workbench/connection-failure.d.ts.map +1 -0
- package/dist/workbench/connection-failure.js +27 -0
- package/dist/workbench/connection-failure.js.map +1 -0
- package/dist/workbench/connection.d.ts +4 -0
- package/dist/workbench/connection.d.ts.map +1 -0
- package/dist/workbench/connection.js +28 -0
- package/dist/workbench/connection.js.map +1 -0
- package/dist/workbench/creation.d.ts +22 -0
- package/dist/workbench/creation.d.ts.map +1 -0
- package/dist/workbench/creation.js +102 -0
- package/dist/workbench/creation.js.map +1 -0
- package/dist/workbench/credits.d.ts +11 -0
- package/dist/workbench/credits.d.ts.map +1 -0
- package/dist/workbench/credits.js +132 -0
- package/dist/workbench/credits.js.map +1 -0
- package/dist/workbench/docker.d.ts +18 -0
- package/dist/workbench/docker.d.ts.map +1 -0
- package/dist/workbench/docker.js +207 -0
- package/dist/workbench/docker.js.map +1 -0
- package/dist/workbench/execution.d.ts +14 -0
- package/dist/workbench/execution.d.ts.map +1 -0
- package/dist/workbench/execution.js +24 -0
- package/dist/workbench/execution.js.map +1 -0
- package/dist/workbench/files.d.ts +51 -0
- package/dist/workbench/files.d.ts.map +1 -0
- package/dist/workbench/files.js +80 -0
- package/dist/workbench/files.js.map +1 -0
- package/dist/workbench/history.d.ts +34 -0
- package/dist/workbench/history.d.ts.map +1 -0
- package/dist/workbench/history.js +50 -0
- package/dist/workbench/history.js.map +1 -0
- package/dist/workbench/input-batch-commands.d.ts +6 -0
- package/dist/workbench/input-batch-commands.d.ts.map +1 -0
- package/dist/workbench/input-batch-commands.js +41 -0
- package/dist/workbench/input-batch-commands.js.map +1 -0
- package/dist/workbench/kitty-diacritics.d.ts +2 -0
- package/dist/workbench/kitty-diacritics.d.ts.map +1 -0
- package/dist/workbench/kitty-diacritics.js +22 -0
- package/dist/workbench/kitty-diacritics.js.map +1 -0
- package/dist/workbench/kitty-graphics.d.ts +59 -0
- package/dist/workbench/kitty-graphics.d.ts.map +1 -0
- package/dist/workbench/kitty-graphics.js +263 -0
- package/dist/workbench/kitty-graphics.js.map +1 -0
- package/dist/workbench/live-execution.d.ts +51 -0
- package/dist/workbench/live-execution.d.ts.map +1 -0
- package/dist/workbench/live-execution.js +222 -0
- package/dist/workbench/live-execution.js.map +1 -0
- package/dist/workbench/model.d.ts +106 -0
- package/dist/workbench/model.d.ts.map +1 -0
- package/dist/workbench/model.js +236 -0
- package/dist/workbench/model.js.map +1 -0
- package/dist/workbench/overview.d.ts +11 -0
- package/dist/workbench/overview.d.ts.map +1 -0
- package/dist/workbench/overview.js +92 -0
- package/dist/workbench/overview.js.map +1 -0
- package/dist/workbench/png.d.ts +10 -0
- package/dist/workbench/png.d.ts.map +1 -0
- package/dist/workbench/png.js +51 -0
- package/dist/workbench/png.js.map +1 -0
- package/dist/workbench/python-task.d.ts +21 -0
- package/dist/workbench/python-task.d.ts.map +1 -0
- package/dist/workbench/python-task.js +52 -0
- package/dist/workbench/python-task.js.map +1 -0
- package/dist/workbench/registry-commands.d.ts +8 -0
- package/dist/workbench/registry-commands.d.ts.map +1 -0
- package/dist/workbench/registry-commands.js +93 -0
- package/dist/workbench/registry-commands.js.map +1 -0
- package/dist/workbench/registry.d.ts +76 -0
- package/dist/workbench/registry.d.ts.map +1 -0
- package/dist/workbench/registry.js +353 -0
- package/dist/workbench/registry.js.map +1 -0
- package/dist/workbench/renderer.d.ts +6 -0
- package/dist/workbench/renderer.d.ts.map +1 -0
- package/dist/workbench/renderer.js +18 -0
- package/dist/workbench/renderer.js.map +1 -0
- package/dist/workbench/results.d.ts +15 -0
- package/dist/workbench/results.d.ts.map +1 -0
- package/dist/workbench/results.js +29 -0
- package/dist/workbench/results.js.map +1 -0
- package/dist/workbench/task-archive.d.ts +23 -0
- package/dist/workbench/task-archive.d.ts.map +1 -0
- package/dist/workbench/task-archive.js +56 -0
- package/dist/workbench/task-archive.js.map +1 -0
- package/dist/workbench/task-board.d.ts +26 -0
- package/dist/workbench/task-board.d.ts.map +1 -0
- package/dist/workbench/task-board.js +43 -0
- package/dist/workbench/task-board.js.map +1 -0
- package/dist/workbench/task-monitor.d.ts +35 -0
- package/dist/workbench/task-monitor.d.ts.map +1 -0
- package/dist/workbench/task-monitor.js +176 -0
- package/dist/workbench/task-monitor.js.map +1 -0
- package/dist/workbench/tasks.d.ts +93 -0
- package/dist/workbench/tasks.d.ts.map +1 -0
- package/dist/workbench/tasks.js +195 -0
- package/dist/workbench/tasks.js.map +1 -0
- package/dist/workbench/terminal.d.ts +82 -0
- package/dist/workbench/terminal.d.ts.map +1 -0
- package/dist/workbench/terminal.js +2577 -0
- package/dist/workbench/terminal.js.map +1 -0
- package/dist/workbench/text.d.ts +10 -0
- package/dist/workbench/text.d.ts.map +1 -0
- package/dist/workbench/text.js +72 -0
- package/dist/workbench/text.js.map +1 -0
- package/dist/workbench/uploads.d.ts +12 -0
- package/dist/workbench/uploads.d.ts.map +1 -0
- package/dist/workbench/uploads.js +16 -0
- package/dist/workbench/uploads.js.map +1 -0
- package/dist/workbench/worker-launch.d.ts +10 -0
- package/dist/workbench/worker-launch.d.ts.map +1 -0
- package/dist/workbench/worker-launch.js +30 -0
- package/dist/workbench/worker-launch.js.map +1 -0
- package/dist/workbench/worker-monitor.d.ts +33 -0
- package/dist/workbench/worker-monitor.d.ts.map +1 -0
- package/dist/workbench/worker-monitor.js +142 -0
- package/dist/workbench/worker-monitor.js.map +1 -0
- package/dist/workbench/worker-output.d.ts +8 -0
- package/dist/workbench/worker-output.d.ts.map +1 -0
- package/dist/workbench/worker-output.js +32 -0
- package/dist/workbench/worker-output.js.map +1 -0
- package/dist/workbench/worker-result.d.ts +29 -0
- package/dist/workbench/worker-result.d.ts.map +1 -0
- package/dist/workbench/worker-result.js +85 -0
- package/dist/workbench/worker-result.js.map +1 -0
- package/dist/workbench/workers.d.ts +49 -0
- package/dist/workbench/workers.d.ts.map +1 -0
- package/dist/workbench/workers.js +53 -0
- package/dist/workbench/workers.js.map +1 -0
- package/package.json +38 -17
- package/dist/__tests__/client.test.d.ts +0 -2
- package/dist/__tests__/client.test.d.ts.map +0 -1
- package/dist/__tests__/client.test.js +0 -198
- package/dist/__tests__/client.test.js.map +0 -1
- package/dist/__tests__/config.test.d.ts +0 -2
- package/dist/__tests__/config.test.d.ts.map +0 -1
- package/dist/__tests__/config.test.js +0 -74
- package/dist/__tests__/config.test.js.map +0 -1
- package/dist/__tests__/utils-cli.test.d.ts +0 -2
- package/dist/__tests__/utils-cli.test.d.ts.map +0 -1
- package/dist/__tests__/utils-cli.test.js +0 -35
- package/dist/__tests__/utils-cli.test.js.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
import { StateSetSandboxExtended } from '@stateset/sandbox-sdk';
|
|
2
2
|
import { getConfig } from './config.js';
|
|
3
|
+
import { buildEgressPolicyBody, normalizeEgressPolicy } from './utils/egress-policy.js';
|
|
4
|
+
export function toAuthContextInfo(settings) {
|
|
5
|
+
const { organization, user } = settings;
|
|
6
|
+
return {
|
|
7
|
+
auth_type: user ? 'session' : 'api_key',
|
|
8
|
+
organization: {
|
|
9
|
+
id: organization.id,
|
|
10
|
+
name: organization.name,
|
|
11
|
+
slug: organization.slug,
|
|
12
|
+
plan: organization.planType,
|
|
13
|
+
},
|
|
14
|
+
...(user
|
|
15
|
+
? { user: { id: user.id, email: user.email, role: user.role, email_verified: user.emailVerified } }
|
|
16
|
+
: {}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Call an operator-only route under /api/admin/internal (admin auth). The admin
|
|
21
|
+
* token comes from STATESET_ADMIN_TOKEN, falling back to the configured key.
|
|
22
|
+
*/
|
|
23
|
+
export async function requestAdminInternal(apiUrl, adminToken, method, path, body) {
|
|
24
|
+
const response = await fetch(`${apiUrl.replace(/\/+$/, '')}/api/admin/internal${path}`, {
|
|
25
|
+
method,
|
|
26
|
+
headers: {
|
|
27
|
+
'X-Admin-Token': adminToken,
|
|
28
|
+
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
|
29
|
+
},
|
|
30
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
31
|
+
});
|
|
32
|
+
const text = await response.text();
|
|
33
|
+
let data;
|
|
34
|
+
try {
|
|
35
|
+
data = text ? JSON.parse(text) : undefined;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
data = text;
|
|
39
|
+
}
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const message = data?.error?.message;
|
|
42
|
+
throw new Error(message || `Admin request ${method} ${path} failed with status ${response.status}`);
|
|
43
|
+
}
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
/** The SDK's raw request, for routes the installed SDK has no method for. */
|
|
47
|
+
function rawRequest(sdk, what, method, path, body, signal) {
|
|
48
|
+
const request = sdk.request;
|
|
49
|
+
if (typeof request !== 'function') {
|
|
50
|
+
throw new Error(`Installed SDK does not support ${what}`);
|
|
51
|
+
}
|
|
52
|
+
return (signal ? request.call(sdk, method, path, body, { signal })
|
|
53
|
+
: body === undefined ? request.call(sdk, method, path) : request.call(sdk, method, path, body));
|
|
54
|
+
}
|
|
55
|
+
/** POST /sandbox/:id/pause|resume through the SDK's raw request (the body's fields are optional). */
|
|
56
|
+
function pauseResumeRequest(sdk, action, sandboxId, options) {
|
|
57
|
+
const request = sdk.request;
|
|
58
|
+
if (typeof request !== 'function') {
|
|
59
|
+
throw new Error(`Installed SDK does not support sandbox ${action}`);
|
|
60
|
+
}
|
|
61
|
+
const body = {};
|
|
62
|
+
if (options.wait !== undefined)
|
|
63
|
+
body.wait = options.wait;
|
|
64
|
+
if (options.timeoutSeconds !== undefined)
|
|
65
|
+
body.timeout_seconds = options.timeoutSeconds;
|
|
66
|
+
const path = action === 'pause' ? `/sandbox/${sandboxId}/pause` : `/sandbox/${sandboxId}/resume`;
|
|
67
|
+
return request.call(sdk, 'POST', path, body);
|
|
68
|
+
}
|
|
3
69
|
let clientInstance = null;
|
|
4
70
|
export function getClient() {
|
|
5
71
|
if (clientInstance)
|
|
@@ -19,41 +85,164 @@ export function getClient() {
|
|
|
19
85
|
catch {
|
|
20
86
|
throw new Error('Configured API URL is invalid. Run `stateset config set-url <url>` with a valid URL.');
|
|
21
87
|
}
|
|
88
|
+
clientInstance = createClientWithToken(apiKey, apiUrl);
|
|
89
|
+
return clientInstance;
|
|
90
|
+
}
|
|
91
|
+
/** Build a non-singleton client for short-lived credentials such as an agent
|
|
92
|
+
* bootstrap token. Keeping this separate prevents an exchanged credential
|
|
93
|
+
* from replacing the active profile's cached client. */
|
|
94
|
+
export function createClientWithToken(authToken, apiUrl = getConfig().apiUrl, transportOptions = {}) {
|
|
95
|
+
const token = authToken.trim();
|
|
96
|
+
const endpoint = apiUrl?.trim();
|
|
97
|
+
if (!token) {
|
|
98
|
+
throw new Error('Authentication token is required.');
|
|
99
|
+
}
|
|
100
|
+
if (!endpoint) {
|
|
101
|
+
throw new Error('API URL is not configured. Run `stateset config set-url <url>` first.');
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
new URL(endpoint);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
throw new Error('Configured API URL is invalid. Run `stateset config set-url <url>` with a valid URL.');
|
|
108
|
+
}
|
|
22
109
|
const sdk = new StateSetSandboxExtended({
|
|
23
|
-
authToken:
|
|
24
|
-
baseUrl:
|
|
110
|
+
authToken: token,
|
|
111
|
+
baseUrl: endpoint,
|
|
112
|
+
...transportOptions,
|
|
25
113
|
});
|
|
26
|
-
|
|
114
|
+
const adminRequest = (method, path, body) => requestAdminInternal(endpoint, process.env.STATESET_ADMIN_TOKEN?.trim() || token, method, path, body);
|
|
115
|
+
const client = {
|
|
116
|
+
auth: {
|
|
117
|
+
introspect: async () => {
|
|
118
|
+
// The API has no dedicated introspection route; GET /settings returns the
|
|
119
|
+
// authenticated organization (and the user, for session/JWT principals).
|
|
120
|
+
const request = sdk.request?.bind(sdk);
|
|
121
|
+
return toAuthContextInfo(await request('GET', '/settings'));
|
|
122
|
+
},
|
|
123
|
+
exchangeBootstrapToken: () => {
|
|
124
|
+
const request = sdk.request?.bind(sdk);
|
|
125
|
+
return request('POST', '/agent/bootstrap/exchange');
|
|
126
|
+
},
|
|
127
|
+
},
|
|
27
128
|
sandbox: {
|
|
28
|
-
|
|
129
|
+
taskRegistry: sdk.taskRegistry,
|
|
130
|
+
// Cold Kubernetes creation can wait 180s for a node/pod. Keep the
|
|
131
|
+
// generic read timeout short, but give creation its own bounded budget.
|
|
132
|
+
create: (options) => sdk.create({ ...options,
|
|
133
|
+
...(options.startupTimeoutMs === undefined && transportOptions.timeout === undefined
|
|
134
|
+
? { startupTimeoutMs: 210_000 } : {}),
|
|
135
|
+
}),
|
|
29
136
|
list: () => sdk.list(),
|
|
30
137
|
get: (sandboxId) => sdk.get(sandboxId),
|
|
31
|
-
execute: (sandboxId, command) => sdk.execute(sandboxId, { command }),
|
|
138
|
+
execute: (sandboxId, command, timeoutMs) => sdk.execute(sandboxId, { command, ...(timeoutMs !== undefined ? { timeout: timeoutMs } : {}) }),
|
|
139
|
+
executeStream: (sandboxId, command, callbacks, options = {}) => sdk.executeStream(sandboxId, { command, timeout: options.timeout, working_dir: options.workingDir, signal: options.signal }, callbacks),
|
|
32
140
|
stop: (sandboxId) => sdk.stop(sandboxId),
|
|
141
|
+
fork: (sandboxId, options = {}) => sdk.fork(sandboxId, options),
|
|
142
|
+
promote: (sandboxId, options) => sdk.promote(sandboxId, options),
|
|
33
143
|
extend: async (sandboxId, additionalSeconds) => {
|
|
34
144
|
const maybeExtend = sdk.extend;
|
|
35
145
|
if (typeof maybeExtend === 'function') {
|
|
36
|
-
return maybeExtend(sandboxId, additionalSeconds);
|
|
146
|
+
return maybeExtend.call(sdk, sandboxId, additionalSeconds);
|
|
37
147
|
}
|
|
38
|
-
const request = sdk.request;
|
|
148
|
+
const request = sdk.request?.bind(sdk);
|
|
39
149
|
if (typeof request !== 'function') {
|
|
40
150
|
throw new Error('Installed SDK does not support sandbox extension');
|
|
41
151
|
}
|
|
42
|
-
return request('POST', `/sandbox/${sandboxId}/extend`, {
|
|
152
|
+
return request.call(sdk, 'POST', `/sandbox/${sandboxId}/extend`, {
|
|
43
153
|
additional_seconds: additionalSeconds,
|
|
44
154
|
});
|
|
45
155
|
},
|
|
156
|
+
pause: (sandboxId, options = {}) => pauseResumeRequest(sdk, 'pause', sandboxId, options),
|
|
157
|
+
resume: (sandboxId, options = {}) => pauseResumeRequest(sdk, 'resume', sandboxId, options),
|
|
46
158
|
writeFile: (sandboxId, path, content) => sdk.writeFile(sandboxId, path, content),
|
|
47
|
-
|
|
159
|
+
writeFiles: (sandboxId, files) => sdk.writeFiles(sandboxId, files),
|
|
160
|
+
readFile: (...args) => sdk.readFile(...args),
|
|
161
|
+
readFileStream: (...args) => sdk.readFileStream(...args),
|
|
48
162
|
listFiles: async (sandboxId, path = '/workspace', options) => {
|
|
49
163
|
const params = new URLSearchParams({ path });
|
|
50
164
|
if (options?.recursive)
|
|
51
165
|
params.set('recursive', 'true');
|
|
52
|
-
const request = sdk.request;
|
|
166
|
+
const request = sdk.request?.bind(sdk);
|
|
53
167
|
if (typeof request !== 'function') {
|
|
54
168
|
throw new Error('Installed SDK does not support listing files');
|
|
55
169
|
}
|
|
56
|
-
return request('GET', `/sandbox/${sandboxId}/files/list?${params}`);
|
|
170
|
+
return request.call(sdk, 'GET', `/sandbox/${sandboxId}/files/list?${params}`);
|
|
171
|
+
},
|
|
172
|
+
glob: (sandboxId, pattern) => {
|
|
173
|
+
const request = sdk.request?.bind(sdk);
|
|
174
|
+
if (typeof request !== 'function') {
|
|
175
|
+
throw new Error('Installed SDK does not support file glob');
|
|
176
|
+
}
|
|
177
|
+
// The API answers { files: [{ name, path, ... }] }; older ones a list of paths.
|
|
178
|
+
return Promise.resolve(request.call(sdk, 'POST', `/sandbox/${sandboxId}/files/glob`, { pattern })).then((result) => (Array.isArray(result) ? result : result?.files ?? []).map((f) => (typeof f === 'string' ? f : f.path)));
|
|
179
|
+
},
|
|
180
|
+
mkdir: (sandboxId, path, recursive) => {
|
|
181
|
+
const request = sdk.request?.bind(sdk);
|
|
182
|
+
if (typeof request !== 'function') {
|
|
183
|
+
throw new Error('Installed SDK does not support mkdir');
|
|
184
|
+
}
|
|
185
|
+
// Explicit: the API's default for an absent `recursive` is true.
|
|
186
|
+
return request.call(sdk, 'POST', `/sandbox/${sandboxId}/files/mkdir`, { path, recursive: recursive === true });
|
|
187
|
+
},
|
|
188
|
+
deleteFile: (sandboxId, path, recursive) => {
|
|
189
|
+
const request = sdk.request?.bind(sdk);
|
|
190
|
+
if (typeof request !== 'function') {
|
|
191
|
+
throw new Error('Installed SDK does not support file deletion');
|
|
192
|
+
}
|
|
193
|
+
return request.call(sdk, 'DELETE', `/sandbox/${sandboxId}/files`, { path, recursive });
|
|
194
|
+
},
|
|
195
|
+
moveFile: (sandboxId, source, destination) => {
|
|
196
|
+
const request = sdk.request?.bind(sdk);
|
|
197
|
+
if (typeof request !== 'function') {
|
|
198
|
+
throw new Error('Installed SDK does not support file move');
|
|
199
|
+
}
|
|
200
|
+
return request.call(sdk, 'POST', `/sandbox/${sandboxId}/files/move`, { source, destination });
|
|
201
|
+
},
|
|
202
|
+
copyFile: (sandboxId, source, destination) => {
|
|
203
|
+
const request = sdk.request?.bind(sdk);
|
|
204
|
+
if (typeof request !== 'function') {
|
|
205
|
+
throw new Error('Installed SDK does not support file copy');
|
|
206
|
+
}
|
|
207
|
+
return request.call(sdk, 'POST', `/sandbox/${sandboxId}/files/copy`, { source, destination });
|
|
208
|
+
},
|
|
209
|
+
terminals: () => {
|
|
210
|
+
const terminals = sdk.terminals;
|
|
211
|
+
if (!terminals || typeof terminals.stream !== 'function') {
|
|
212
|
+
throw new Error('Installed SDK does not support terminal sessions');
|
|
213
|
+
}
|
|
214
|
+
return terminals;
|
|
215
|
+
},
|
|
216
|
+
processes: {
|
|
217
|
+
result: (sandboxId, processId, tailBytes = 16384, signal) => {
|
|
218
|
+
if (!Number.isSafeInteger(tailBytes) || tailBytes < 1 || tailBytes > 1048576)
|
|
219
|
+
throw new Error('tailBytes must be 1-1048576.');
|
|
220
|
+
return rawRequest(sdk, 'worker results', 'GET', `/sandbox/${sandboxId}/processes/${encodeURIComponent(processId)}/result?tail_bytes=${tailBytes}`, undefined, signal);
|
|
221
|
+
},
|
|
222
|
+
start: (sandboxId, body) => rawRequest(sdk, 'processes', 'POST', `/sandbox/${sandboxId}/processes`, body),
|
|
223
|
+
list: async (sandboxId, signal) => signal ? (await sdk.processes.list(sandboxId, signal)).map(row => ({ ...row })) :
|
|
224
|
+
(await rawRequest(sdk, 'processes', 'GET', `/sandbox/${sandboxId}/processes`)).processes ?? [],
|
|
225
|
+
get: (sandboxId, processId, signal) => signal ? sdk.processes.get(sandboxId, processId, signal).then(row => ({ ...row })) :
|
|
226
|
+
rawRequest(sdk, 'processes', 'GET', `/sandbox/${sandboxId}/processes/${encodeURIComponent(processId)}`),
|
|
227
|
+
logs: (sandboxId, processId, options = {}) => {
|
|
228
|
+
const params = new URLSearchParams();
|
|
229
|
+
if (options.stream)
|
|
230
|
+
params.set('stream', options.stream);
|
|
231
|
+
if (options.offset !== undefined)
|
|
232
|
+
params.set('offset', String(options.offset));
|
|
233
|
+
if (options.limit !== undefined)
|
|
234
|
+
params.set('limit', String(options.limit));
|
|
235
|
+
const qs = params.toString();
|
|
236
|
+
return rawRequest(sdk, 'processes', 'GET', `/sandbox/${sandboxId}/processes/${encodeURIComponent(processId)}/logs${qs ? `?${qs}` : ''}`, undefined, options.signal);
|
|
237
|
+
},
|
|
238
|
+
kill: (sandboxId, processId, graceSeconds) => rawRequest(sdk, 'processes', 'DELETE', `/sandbox/${sandboxId}/processes/${encodeURIComponent(processId)}`
|
|
239
|
+
+ (graceSeconds !== undefined ? `?grace_seconds=${graceSeconds}` : '')),
|
|
240
|
+
stdin: (sandboxId, processId, data) => sdk.processes.stdin(sandboxId, processId, data),
|
|
241
|
+
},
|
|
242
|
+
executions: {
|
|
243
|
+
list: sandboxId => sdk.executions.list(sandboxId),
|
|
244
|
+
get: (sandboxId, executionId, signal) => sdk.executions.get(sandboxId, executionId, signal),
|
|
245
|
+
cancel: (sandboxId, executionId) => sdk.executions.cancel(sandboxId, executionId),
|
|
57
246
|
},
|
|
58
247
|
},
|
|
59
248
|
checkpoints: {
|
|
@@ -100,9 +289,492 @@ export function getClient() {
|
|
|
100
289
|
cancel: (sessionId) => sdk.cancelAgentSession(sessionId),
|
|
101
290
|
execute: (sessionId, options) => sdk.executeInAgentSession(sessionId, options),
|
|
102
291
|
events: (sessionId, options = {}) => sdk.getAgentSessionEvents(sessionId, options),
|
|
292
|
+
heartbeat: (sessionId) => sdk.agentSessionHeartbeat(sessionId),
|
|
293
|
+
run: async (options) => {
|
|
294
|
+
const { session: created } = await sdk.createAgentSession(options);
|
|
295
|
+
if (options.context) {
|
|
296
|
+
await sdk.updateAgentContext(created.id, options.context);
|
|
297
|
+
}
|
|
298
|
+
const { session: started } = await sdk.startAgentSession(created.id);
|
|
299
|
+
const command = options.command;
|
|
300
|
+
const execution = command?.length
|
|
301
|
+
? await sdk.executeInAgentSession(started.id, {
|
|
302
|
+
...options.exec,
|
|
303
|
+
command,
|
|
304
|
+
})
|
|
305
|
+
: undefined;
|
|
306
|
+
const stopped = options.stop_on_exit === true;
|
|
307
|
+
if (stopped) {
|
|
308
|
+
await sdk.stopAgentSession(started.id, 'command completed');
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
session: stopped ? { ...started, status: 'completed' } : started,
|
|
312
|
+
execution,
|
|
313
|
+
stopped,
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
connect: async (options) => {
|
|
317
|
+
const clientId = String(options.clientId || '');
|
|
318
|
+
const attached = clientId ? await sdk.reattachAgentSession(clientId) : { session: null };
|
|
319
|
+
if (attached.session) {
|
|
320
|
+
if (options.context) {
|
|
321
|
+
await sdk.updateAgentContext(attached.session.id, options.context);
|
|
322
|
+
}
|
|
323
|
+
const session = options.resumePaused === true && attached.session.status === 'paused'
|
|
324
|
+
? (await sdk.resumeAgentSession(attached.session.id)).session
|
|
325
|
+
: attached.session;
|
|
326
|
+
return { session, reattached: true, created: false, source: 'reattached', stopped: false };
|
|
327
|
+
}
|
|
328
|
+
const { session: created } = await sdk.createAgentSession(options);
|
|
329
|
+
if (options.context) {
|
|
330
|
+
await sdk.updateAgentContext(created.id, options.context);
|
|
331
|
+
}
|
|
332
|
+
const { session } = await sdk.startAgentSession(created.id);
|
|
333
|
+
return { session, reattached: false, created: true, source: 'created', stopped: false };
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
webhooks: {
|
|
337
|
+
list: () => {
|
|
338
|
+
const request = sdk.request?.bind(sdk);
|
|
339
|
+
if (typeof request !== 'function') {
|
|
340
|
+
throw new Error('Installed SDK does not support webhook endpoints');
|
|
341
|
+
}
|
|
342
|
+
return request('GET', '/webhooks');
|
|
343
|
+
},
|
|
344
|
+
create: (url, events, secret) => {
|
|
345
|
+
const request = sdk.request?.bind(sdk);
|
|
346
|
+
if (typeof request !== 'function') {
|
|
347
|
+
throw new Error('Installed SDK does not support webhook endpoints');
|
|
348
|
+
}
|
|
349
|
+
const body = { url, events };
|
|
350
|
+
if (secret)
|
|
351
|
+
body.secret = secret;
|
|
352
|
+
return request('POST', '/webhooks', body);
|
|
353
|
+
},
|
|
354
|
+
delete: (webhookId) => {
|
|
355
|
+
const request = sdk.request?.bind(sdk);
|
|
356
|
+
if (typeof request !== 'function') {
|
|
357
|
+
throw new Error('Installed SDK does not support webhook endpoints');
|
|
358
|
+
}
|
|
359
|
+
return request('DELETE', `/webhooks/${webhookId}`);
|
|
360
|
+
},
|
|
361
|
+
test: (webhookId) => {
|
|
362
|
+
const request = sdk.request?.bind(sdk);
|
|
363
|
+
if (typeof request !== 'function') {
|
|
364
|
+
throw new Error('Installed SDK does not support webhook endpoints');
|
|
365
|
+
}
|
|
366
|
+
return request('POST', `/webhooks/${webhookId}/test`);
|
|
367
|
+
},
|
|
368
|
+
deliveries: (webhookId, limit) => {
|
|
369
|
+
const request = sdk.request?.bind(sdk);
|
|
370
|
+
if (typeof request !== 'function') {
|
|
371
|
+
throw new Error('Installed SDK does not support webhook endpoints');
|
|
372
|
+
}
|
|
373
|
+
const params = limit ? `?limit=${limit}` : '';
|
|
374
|
+
return request('GET', `/webhooks/${webhookId}/deliveries${params}`);
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
audit: {
|
|
378
|
+
list: (options = {}) => {
|
|
379
|
+
if (typeof sdk.queryAudit !== 'function') {
|
|
380
|
+
throw new Error('Installed SDK does not support audit endpoints');
|
|
381
|
+
}
|
|
382
|
+
return sdk.queryAudit(options);
|
|
383
|
+
},
|
|
384
|
+
summary: (sandboxId) => {
|
|
385
|
+
if (typeof sdk.getAuditSummary !== 'function') {
|
|
386
|
+
throw new Error('Installed SDK does not support audit endpoints');
|
|
387
|
+
}
|
|
388
|
+
return sdk.getAuditSummary(sandboxId);
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
governance: (() => {
|
|
392
|
+
const raw = sdk.request?.bind(sdk);
|
|
393
|
+
const call = (method, path, body) => {
|
|
394
|
+
if (typeof raw !== 'function') {
|
|
395
|
+
throw new Error('Installed SDK does not support governance endpoints');
|
|
396
|
+
}
|
|
397
|
+
return body === undefined ? raw.call(sdk, method, path) : raw.call(sdk, method, path, body);
|
|
398
|
+
};
|
|
399
|
+
const qs = (params) => {
|
|
400
|
+
const search = new URLSearchParams();
|
|
401
|
+
for (const [key, value] of Object.entries(params)) {
|
|
402
|
+
if (value !== undefined && value !== '')
|
|
403
|
+
search.set(key, String(value));
|
|
404
|
+
}
|
|
405
|
+
const encoded = search.toString();
|
|
406
|
+
return encoded ? `?${encoded}` : '';
|
|
407
|
+
};
|
|
408
|
+
return {
|
|
409
|
+
timeline: (sandboxId, query = {}) => call('GET', `/sandbox/${encodeURIComponent(sandboxId)}/timeline${qs(query)}`),
|
|
410
|
+
sandboxCost: (sandboxId) => call('GET', `/sandbox/${encodeURIComponent(sandboxId)}/cost`),
|
|
411
|
+
orgCosts: (query = {}) => call('GET', `/org/costs${qs(query)}`),
|
|
412
|
+
getPolicy: () => call('GET', '/org/policy'),
|
|
413
|
+
updatePolicy: (update) => call('PUT', '/org/policy', update),
|
|
414
|
+
sandboxEgress: (sandboxId) => call('GET', `/sandbox/${encodeURIComponent(sandboxId)}/egress`),
|
|
415
|
+
updateSandboxEgress: (sandboxId, update) => call('PATCH', `/sandbox/${encodeURIComponent(sandboxId)}/egress`, update),
|
|
416
|
+
};
|
|
417
|
+
})(),
|
|
418
|
+
images: {
|
|
419
|
+
register: (options) => {
|
|
420
|
+
const request = sdk.request?.bind(sdk);
|
|
421
|
+
if (typeof request !== 'function') {
|
|
422
|
+
throw new Error('Installed SDK does not support image endpoints');
|
|
423
|
+
}
|
|
424
|
+
const body = { name: options.name, image: options.image };
|
|
425
|
+
if (options.pull_secret)
|
|
426
|
+
body.pull_secret = options.pull_secret;
|
|
427
|
+
if (options.run_image_command !== undefined)
|
|
428
|
+
body.run_image_command = options.run_image_command;
|
|
429
|
+
return request('POST', '/images', body);
|
|
430
|
+
},
|
|
431
|
+
list: () => {
|
|
432
|
+
const request = sdk.request?.bind(sdk);
|
|
433
|
+
if (typeof request !== 'function') {
|
|
434
|
+
throw new Error('Installed SDK does not support image endpoints');
|
|
435
|
+
}
|
|
436
|
+
return request('GET', '/images');
|
|
437
|
+
},
|
|
438
|
+
get: (name) => {
|
|
439
|
+
const request = sdk.request?.bind(sdk);
|
|
440
|
+
if (typeof request !== 'function') {
|
|
441
|
+
throw new Error('Installed SDK does not support image endpoints');
|
|
442
|
+
}
|
|
443
|
+
return request('GET', `/images/${encodeURIComponent(name)}`);
|
|
444
|
+
},
|
|
445
|
+
delete: (name) => {
|
|
446
|
+
const request = sdk.request?.bind(sdk);
|
|
447
|
+
if (typeof request !== 'function') {
|
|
448
|
+
throw new Error('Installed SDK does not support image endpoints');
|
|
449
|
+
}
|
|
450
|
+
return request('DELETE', `/images/${encodeURIComponent(name)}`);
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
secrets: {
|
|
454
|
+
list: () => {
|
|
455
|
+
const request = sdk.request?.bind(sdk);
|
|
456
|
+
if (typeof request !== 'function') {
|
|
457
|
+
throw new Error('Installed SDK does not support secret endpoints');
|
|
458
|
+
}
|
|
459
|
+
return request('GET', '/secrets');
|
|
460
|
+
},
|
|
461
|
+
create: (name, value, options = {}) => {
|
|
462
|
+
const request = sdk.request?.bind(sdk);
|
|
463
|
+
if (typeof request !== 'function') {
|
|
464
|
+
throw new Error('Installed SDK does not support secret endpoints');
|
|
465
|
+
}
|
|
466
|
+
const body = { name, value };
|
|
467
|
+
if (options.scope)
|
|
468
|
+
body.scope = options.scope;
|
|
469
|
+
if (options.expires_at)
|
|
470
|
+
body.expires_at = options.expires_at;
|
|
471
|
+
return request('POST', '/secrets', body);
|
|
472
|
+
},
|
|
473
|
+
delete: (name) => {
|
|
474
|
+
const request = sdk.request?.bind(sdk);
|
|
475
|
+
if (typeof request !== 'function') {
|
|
476
|
+
throw new Error('Installed SDK does not support secret endpoints');
|
|
477
|
+
}
|
|
478
|
+
return request('DELETE', `/secrets/${encodeURIComponent(name)}`);
|
|
479
|
+
},
|
|
480
|
+
inject: (sandboxId, secrets) => {
|
|
481
|
+
const request = sdk.request?.bind(sdk);
|
|
482
|
+
if (typeof request !== 'function') {
|
|
483
|
+
throw new Error('Installed SDK does not support secret endpoints');
|
|
484
|
+
}
|
|
485
|
+
return request('POST', `/sandbox/${sandboxId}/secrets/inject`, { secrets });
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
templates: {
|
|
489
|
+
list: (options = {}) => {
|
|
490
|
+
const request = sdk.request?.bind(sdk);
|
|
491
|
+
if (typeof request !== 'function') {
|
|
492
|
+
throw new Error('Installed SDK does not support template endpoints');
|
|
493
|
+
}
|
|
494
|
+
const params = new URLSearchParams();
|
|
495
|
+
if (options.category)
|
|
496
|
+
params.set('category', options.category);
|
|
497
|
+
if (options.search)
|
|
498
|
+
params.set('search', options.search);
|
|
499
|
+
const qs = params.toString();
|
|
500
|
+
return request('GET', `/templates${qs ? `?${qs}` : ''}`);
|
|
501
|
+
},
|
|
502
|
+
get: (templateId) => {
|
|
503
|
+
const request = sdk.request?.bind(sdk);
|
|
504
|
+
if (typeof request !== 'function') {
|
|
505
|
+
throw new Error('Installed SDK does not support template endpoints');
|
|
506
|
+
}
|
|
507
|
+
return request('GET', `/templates/${templateId}`);
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
apiKeys: {
|
|
511
|
+
list: () => {
|
|
512
|
+
const request = sdk.request?.bind(sdk);
|
|
513
|
+
if (typeof request !== 'function') {
|
|
514
|
+
throw new Error('Installed SDK does not support API key endpoints');
|
|
515
|
+
}
|
|
516
|
+
return request('GET', '/api-keys');
|
|
517
|
+
},
|
|
518
|
+
create: (name, options = {}) => {
|
|
519
|
+
const request = sdk.request?.bind(sdk);
|
|
520
|
+
if (typeof request !== 'function') {
|
|
521
|
+
throw new Error('Installed SDK does not support API key endpoints');
|
|
522
|
+
}
|
|
523
|
+
const body = { name };
|
|
524
|
+
if (options.scopes)
|
|
525
|
+
body.scopes = options.scopes;
|
|
526
|
+
if (options.expires_in_days)
|
|
527
|
+
body.expires_in_days = options.expires_in_days;
|
|
528
|
+
return request('POST', '/api-keys', body);
|
|
529
|
+
},
|
|
530
|
+
revoke: (keyId) => {
|
|
531
|
+
const request = sdk.request?.bind(sdk);
|
|
532
|
+
if (typeof request !== 'function') {
|
|
533
|
+
throw new Error('Installed SDK does not support API key endpoints');
|
|
534
|
+
}
|
|
535
|
+
return request('DELETE', `/api-keys/${keyId}`);
|
|
536
|
+
},
|
|
537
|
+
},
|
|
538
|
+
billing: {
|
|
539
|
+
subscription: () => {
|
|
540
|
+
const request = sdk.request?.bind(sdk);
|
|
541
|
+
if (typeof request !== 'function') {
|
|
542
|
+
throw new Error('Installed SDK does not support billing endpoints');
|
|
543
|
+
}
|
|
544
|
+
return request('GET', '/billing/subscription');
|
|
545
|
+
},
|
|
546
|
+
usage: () => {
|
|
547
|
+
const request = sdk.request?.bind(sdk);
|
|
548
|
+
if (typeof request !== 'function') {
|
|
549
|
+
throw new Error('Installed SDK does not support billing endpoints');
|
|
550
|
+
}
|
|
551
|
+
return request('GET', '/usage/current');
|
|
552
|
+
},
|
|
553
|
+
invoices: (limit) => {
|
|
554
|
+
const request = sdk.request?.bind(sdk);
|
|
555
|
+
if (typeof request !== 'function') {
|
|
556
|
+
throw new Error('Installed SDK does not support billing endpoints');
|
|
557
|
+
}
|
|
558
|
+
const qs = limit ? `?limit=${limit}` : '';
|
|
559
|
+
return request('GET', `/billing/invoices${qs}`);
|
|
560
|
+
},
|
|
561
|
+
portal: (returnUrl) => {
|
|
562
|
+
const request = sdk.request?.bind(sdk);
|
|
563
|
+
if (typeof request !== 'function') {
|
|
564
|
+
throw new Error('Installed SDK does not support billing endpoints');
|
|
565
|
+
}
|
|
566
|
+
return request('POST', '/billing/portal', { return_url: returnUrl });
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
// Snapshot management is operator-only: the controller serves it at
|
|
570
|
+
// /api/admin/internal/snapshots behind admin auth, not under /api/v1.
|
|
571
|
+
snapshots: {
|
|
572
|
+
list: () => adminRequest('GET', '/snapshots'),
|
|
573
|
+
status: () => adminRequest('GET', '/snapshots/status'),
|
|
574
|
+
create: (payload) => adminRequest('POST', '/snapshots', payload),
|
|
575
|
+
get: (profileKey) => adminRequest('GET', `/snapshots/${encodeURIComponent(profileKey)}`),
|
|
576
|
+
delete: (profileKey) => adminRequest('DELETE', `/snapshots/${encodeURIComponent(profileKey)}`),
|
|
577
|
+
restore: (profileKey) => adminRequest('POST', `/snapshots/${encodeURIComponent(profileKey)}/restore`),
|
|
578
|
+
warm: (payload) => adminRequest('POST', '/snapshots/warm', payload),
|
|
579
|
+
cleanup: (payload) => adminRequest('POST', '/snapshots/cleanup', payload),
|
|
580
|
+
},
|
|
581
|
+
computerUse: {
|
|
582
|
+
screenshot: (sandboxId, options = {}) => {
|
|
583
|
+
const request = sdk.request?.bind(sdk);
|
|
584
|
+
if (typeof request !== 'function') {
|
|
585
|
+
throw new Error('Installed SDK does not support computer use endpoints');
|
|
586
|
+
}
|
|
587
|
+
const params = new URLSearchParams();
|
|
588
|
+
if (options.format)
|
|
589
|
+
params.set('format', options.format);
|
|
590
|
+
if (options.quality !== undefined)
|
|
591
|
+
params.set('quality', options.quality.toString());
|
|
592
|
+
const qs = params.toString();
|
|
593
|
+
return request('GET', `/sandbox/${sandboxId}/screenshot${qs ? `?${qs}` : ''}`);
|
|
594
|
+
},
|
|
595
|
+
mouse: (sandboxId, action, x, y, button) => {
|
|
596
|
+
const request = sdk.request?.bind(sdk);
|
|
597
|
+
if (typeof request !== 'function') {
|
|
598
|
+
throw new Error('Installed SDK does not support computer use endpoints');
|
|
599
|
+
}
|
|
600
|
+
const body = { action, x, y };
|
|
601
|
+
if (button)
|
|
602
|
+
body.button = button;
|
|
603
|
+
return request('POST', `/sandbox/${sandboxId}/mouse`, body);
|
|
604
|
+
},
|
|
605
|
+
keyboard: (sandboxId, action, textOrKey, modifiers) => {
|
|
606
|
+
const request = sdk.request?.bind(sdk);
|
|
607
|
+
if (typeof request !== 'function') {
|
|
608
|
+
throw new Error('Installed SDK does not support computer use endpoints');
|
|
609
|
+
}
|
|
610
|
+
const body = { action };
|
|
611
|
+
if (action === 'type') {
|
|
612
|
+
body.text = textOrKey;
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
body.key = textOrKey;
|
|
616
|
+
}
|
|
617
|
+
if (modifiers && modifiers.length > 0)
|
|
618
|
+
body.modifiers = modifiers;
|
|
619
|
+
return request('POST', `/sandbox/${sandboxId}/keyboard`, body);
|
|
620
|
+
},
|
|
621
|
+
getScreenSize: (sandboxId) => {
|
|
622
|
+
const request = sdk.request?.bind(sdk);
|
|
623
|
+
if (typeof request !== 'function') {
|
|
624
|
+
throw new Error('Installed SDK does not support computer use endpoints');
|
|
625
|
+
}
|
|
626
|
+
return request('GET', `/sandbox/${sandboxId}/screen`);
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
repl: {
|
|
630
|
+
create: (sandboxId, language) => {
|
|
631
|
+
if (typeof sdk.createReplSession !== 'function') {
|
|
632
|
+
throw new Error('Installed SDK does not support REPL endpoints');
|
|
633
|
+
}
|
|
634
|
+
return sdk.createReplSession(sandboxId, language ?? 'python');
|
|
635
|
+
},
|
|
636
|
+
list: (sandboxId) => {
|
|
637
|
+
const request = sdk.request?.bind(sdk);
|
|
638
|
+
if (typeof request !== 'function') {
|
|
639
|
+
throw new Error('Installed SDK does not support REPL endpoints');
|
|
640
|
+
}
|
|
641
|
+
return request('GET', `/sandbox/${sandboxId}/repl/sessions`);
|
|
642
|
+
},
|
|
643
|
+
get: (sandboxId, sessionId) => {
|
|
644
|
+
const request = sdk.request?.bind(sdk);
|
|
645
|
+
if (typeof request !== 'function') {
|
|
646
|
+
throw new Error('Installed SDK does not support REPL endpoints');
|
|
647
|
+
}
|
|
648
|
+
return request('GET', `/sandbox/${sandboxId}/repl/sessions/${sessionId}`);
|
|
649
|
+
},
|
|
650
|
+
execute: (sandboxId, sessionId, code, timeoutMs) => {
|
|
651
|
+
if (typeof sdk.executeReplCode !== 'function') {
|
|
652
|
+
throw new Error('Installed SDK does not support REPL endpoints');
|
|
653
|
+
}
|
|
654
|
+
// Preserve the SDK's cell timeout grace and unsent-only retry policy.
|
|
655
|
+
return sdk.executeReplCode(sandboxId, sessionId, code, timeoutMs);
|
|
656
|
+
},
|
|
657
|
+
interrupt: (sandboxId, sessionId) => {
|
|
658
|
+
const request = sdk.request?.bind(sdk);
|
|
659
|
+
if (typeof request !== 'function') {
|
|
660
|
+
throw new Error('Installed SDK does not support REPL endpoints');
|
|
661
|
+
}
|
|
662
|
+
return request('POST', `/sandbox/${sandboxId}/repl/sessions/${sessionId}/interrupt`);
|
|
663
|
+
},
|
|
664
|
+
delete: (sandboxId, sessionId) => {
|
|
665
|
+
const request = sdk.request?.bind(sdk);
|
|
666
|
+
if (typeof request !== 'function') {
|
|
667
|
+
throw new Error('Installed SDK does not support REPL endpoints');
|
|
668
|
+
}
|
|
669
|
+
return request('DELETE', `/sandbox/${sandboxId}/repl/sessions/${sessionId}`);
|
|
670
|
+
},
|
|
671
|
+
},
|
|
672
|
+
mcp: {
|
|
673
|
+
start: (sandboxId, name, command, args, env, port) => {
|
|
674
|
+
const request = sdk.request?.bind(sdk);
|
|
675
|
+
if (typeof request !== 'function') {
|
|
676
|
+
throw new Error('Installed SDK does not support MCP endpoints');
|
|
677
|
+
}
|
|
678
|
+
const body = { name, command };
|
|
679
|
+
if (args && args.length > 0)
|
|
680
|
+
body.args = args;
|
|
681
|
+
if (env && Object.keys(env).length > 0)
|
|
682
|
+
body.env = env;
|
|
683
|
+
if (port !== undefined)
|
|
684
|
+
body.port = port;
|
|
685
|
+
return request('POST', `/sandbox/${sandboxId}/mcp/start`, body);
|
|
686
|
+
},
|
|
687
|
+
stop: (sandboxId, name) => {
|
|
688
|
+
const request = sdk.request?.bind(sdk);
|
|
689
|
+
if (typeof request !== 'function') {
|
|
690
|
+
throw new Error('Installed SDK does not support MCP endpoints');
|
|
691
|
+
}
|
|
692
|
+
return request('POST', `/sandbox/${sandboxId}/mcp/stop`, { name });
|
|
693
|
+
},
|
|
694
|
+
list: (sandboxId) => {
|
|
695
|
+
const request = sdk.request?.bind(sdk);
|
|
696
|
+
if (typeof request !== 'function') {
|
|
697
|
+
throw new Error('Installed SDK does not support MCP endpoints');
|
|
698
|
+
}
|
|
699
|
+
return request('GET', `/sandbox/${sandboxId}/mcp`);
|
|
700
|
+
},
|
|
701
|
+
presets: () => {
|
|
702
|
+
const request = sdk.request?.bind(sdk);
|
|
703
|
+
if (typeof request !== 'function') {
|
|
704
|
+
throw new Error('Installed SDK does not support MCP endpoints');
|
|
705
|
+
}
|
|
706
|
+
return request('GET', '/mcp/presets');
|
|
707
|
+
},
|
|
708
|
+
},
|
|
709
|
+
egress: {
|
|
710
|
+
get: () => {
|
|
711
|
+
const request = sdk.request?.bind(sdk);
|
|
712
|
+
if (typeof request !== 'function') {
|
|
713
|
+
throw new Error('Installed SDK does not support egress endpoints');
|
|
714
|
+
}
|
|
715
|
+
return Promise.resolve(request('GET', '/settings/egress')).then(normalizeEgressPolicy);
|
|
716
|
+
},
|
|
717
|
+
set: (mode, options = {}) => {
|
|
718
|
+
const request = sdk.request?.bind(sdk);
|
|
719
|
+
if (typeof request !== 'function') {
|
|
720
|
+
throw new Error('Installed SDK does not support egress endpoints');
|
|
721
|
+
}
|
|
722
|
+
const body = buildEgressPolicyBody(mode, options);
|
|
723
|
+
return Promise.resolve(request('PUT', '/settings/egress', body)).then(normalizeEgressPolicy);
|
|
724
|
+
},
|
|
725
|
+
audit: (options = {}) => {
|
|
726
|
+
const request = sdk.request?.bind(sdk);
|
|
727
|
+
if (typeof request !== 'function') {
|
|
728
|
+
throw new Error('Installed SDK does not support egress endpoints');
|
|
729
|
+
}
|
|
730
|
+
const params = new URLSearchParams();
|
|
731
|
+
if (options.sandbox_id)
|
|
732
|
+
params.set('sandbox_id', options.sandbox_id);
|
|
733
|
+
if (options.host)
|
|
734
|
+
params.set('host', options.host);
|
|
735
|
+
if (options.decision)
|
|
736
|
+
params.set('decision', options.decision);
|
|
737
|
+
if (options.limit)
|
|
738
|
+
params.set('limit', options.limit.toString());
|
|
739
|
+
const qs = params.toString();
|
|
740
|
+
return request('GET', `/egress/audit${qs ? `?${qs}` : ''}`);
|
|
741
|
+
},
|
|
742
|
+
},
|
|
743
|
+
benchmark: {
|
|
744
|
+
run: (_runs) => {
|
|
745
|
+
const request = sdk.request?.bind(sdk);
|
|
746
|
+
if (typeof request !== 'function') {
|
|
747
|
+
throw new Error('Installed SDK does not support benchmark endpoints');
|
|
748
|
+
}
|
|
749
|
+
// GET /benchmark is read-only: it returns the latest published result
|
|
750
|
+
// and ignores runs, so none is sent.
|
|
751
|
+
return request('GET', '/benchmark');
|
|
752
|
+
},
|
|
753
|
+
history: (options = {}) => {
|
|
754
|
+
const request = sdk.request?.bind(sdk);
|
|
755
|
+
if (typeof request !== 'function') {
|
|
756
|
+
throw new Error('Installed SDK does not support benchmark endpoints');
|
|
757
|
+
}
|
|
758
|
+
const params = new URLSearchParams();
|
|
759
|
+
if (options.limit)
|
|
760
|
+
params.set('limit', options.limit.toString());
|
|
761
|
+
if (options.days)
|
|
762
|
+
params.set('days', options.days.toString());
|
|
763
|
+
if (options.region)
|
|
764
|
+
params.set('region', options.region);
|
|
765
|
+
const qs = params.toString();
|
|
766
|
+
return request('GET', `/benchmark/history${qs ? `?${qs}` : ''}`);
|
|
767
|
+
},
|
|
768
|
+
summary: () => {
|
|
769
|
+
const request = sdk.request?.bind(sdk);
|
|
770
|
+
if (typeof request !== 'function') {
|
|
771
|
+
throw new Error('Installed SDK does not support benchmark endpoints');
|
|
772
|
+
}
|
|
773
|
+
return request('GET', '/benchmark/summary');
|
|
774
|
+
},
|
|
103
775
|
},
|
|
104
776
|
};
|
|
105
|
-
return
|
|
777
|
+
return client;
|
|
106
778
|
}
|
|
107
779
|
export function resetClient() {
|
|
108
780
|
clientInstance = null;
|