withruntime 0.50.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/apps.d.ts +309 -0
- package/dist/generated/apps.js +333 -0
- package/dist/generated/audit.d.ts +47 -0
- package/dist/generated/audit.js +14 -0
- package/dist/generated/browsers.d.ts +309 -0
- package/dist/generated/browsers.js +333 -0
- package/dist/generated/builds.d.ts +309 -0
- package/dist/generated/builds.js +333 -0
- package/dist/generated/ci.d.ts +309 -0
- package/dist/generated/ci.js +333 -0
- package/dist/generated/containers.d.ts +309 -0
- package/dist/generated/containers.js +333 -0
- package/dist/generated/desktops.d.ts +309 -0
- package/dist/generated/desktops.js +333 -0
- package/dist/generated/domains.d.ts +80 -0
- package/dist/generated/domains.js +58 -0
- package/dist/generated/egressIps.d.ts +36 -0
- package/dist/generated/egressIps.js +14 -0
- package/dist/generated/events.d.ts +37 -0
- package/dist/generated/events.js +14 -0
- package/dist/generated/feedback.d.ts +44 -0
- package/dist/generated/feedback.js +13 -0
- package/dist/generated/functions.d.ts +309 -0
- package/dist/generated/functions.js +333 -0
- package/dist/generated/identities.d.ts +36 -0
- package/dist/generated/identities.js +22 -0
- package/dist/generated/images.d.ts +200 -0
- package/dist/generated/images.js +65 -0
- package/dist/generated/index.d.ts +143 -0
- package/dist/generated/index.js +184 -0
- package/dist/generated/jobRuns.d.ts +68 -0
- package/dist/generated/jobRuns.js +22 -0
- package/dist/generated/jobs.d.ts +144 -0
- package/dist/generated/jobs.js +85 -0
- package/dist/generated/keys.d.ts +105 -0
- package/dist/generated/keys.js +26 -0
- package/dist/generated/me.d.ts +33 -0
- package/dist/generated/me.js +13 -0
- package/dist/generated/networks.d.ts +32 -0
- package/dist/generated/networks.js +14 -0
- package/dist/generated/notebooks.d.ts +309 -0
- package/dist/generated/notebooks.js +333 -0
- package/dist/generated/otel.d.ts +46 -0
- package/dist/generated/otel.js +22 -0
- package/dist/generated/ports.d.ts +55 -0
- package/dist/generated/ports.js +22 -0
- package/dist/generated/previews.d.ts +86 -0
- package/dist/generated/previews.js +67 -0
- package/dist/generated/projects.d.ts +47 -0
- package/dist/generated/projects.js +26 -0
- package/dist/generated/roles.d.ts +36 -0
- package/dist/generated/roles.js +22 -0
- package/dist/generated/routes.d.ts +3 -0
- package/dist/generated/routes.js +4 -0
- package/dist/generated/runtime.d.ts +176 -0
- package/dist/generated/runtime.js +416 -0
- package/dist/generated/sandboxes.d.ts +952 -0
- package/dist/generated/sandboxes.js +342 -0
- package/dist/generated/secrets.d.ts +116 -0
- package/dist/generated/secrets.js +54 -0
- package/dist/generated/sessions.d.ts +47 -0
- package/dist/generated/sessions.js +17 -0
- package/dist/generated/signing.d.ts +68 -0
- package/dist/generated/signing.js +187 -0
- package/dist/generated/sites.d.ts +309 -0
- package/dist/generated/sites.js +333 -0
- package/dist/generated/snapshots.d.ts +27 -0
- package/dist/generated/snapshots.js +22 -0
- package/dist/generated/tunnels.d.ts +68 -0
- package/dist/generated/tunnels.js +14 -0
- package/dist/generated/usage.d.ts +155 -0
- package/dist/generated/usage.js +17 -0
- package/dist/generated/volumes.d.ts +36 -0
- package/dist/generated/volumes.js +26 -0
- package/dist/generated/webhooks.d.ts +44 -0
- package/dist/generated/webhooks.js +22 -0
- package/dist/generated/workspaces.d.ts +309 -0
- package/dist/generated/workspaces.js +333 -0
- package/dist/v2/cli.d.ts +7 -0
- package/dist/v2/cli.js +283 -0
- package/dist/v2/index.d.ts +1 -0
- package/dist/v2/index.js +4 -0
- package/dist/v2/login.d.ts +35 -0
- package/dist/v2/login.js +225 -0
- package/dist/v2/mcp.d.ts +1 -0
- package/dist/v2/mcp.js +49 -0
- package/dist/v2/openapi.json +75750 -0
- package/dist/v2/shims/base.d.ts +33 -0
- package/dist/v2/shims/base.js +54 -0
- package/dist/v2/shims/blaxel.d.ts +60 -0
- package/dist/v2/shims/blaxel.js +71 -0
- package/dist/v2/shims/cloudflare.d.ts +52 -0
- package/dist/v2/shims/cloudflare.js +55 -0
- package/dist/v2/shims/daytona.d.ts +58 -0
- package/dist/v2/shims/daytona.js +74 -0
- package/dist/v2/shims/e2b.d.ts +142 -0
- package/dist/v2/shims/e2b.js +238 -0
- package/dist/v2/shims/fly.d.ts +6 -0
- package/dist/v2/shims/fly.js +91 -0
- package/dist/v2/shims/modal.d.ts +54 -0
- package/dist/v2/shims/modal.js +79 -0
- package/dist/v2/shims/morph.d.ts +60 -0
- package/dist/v2/shims/morph.js +87 -0
- package/dist/v2/shims/vercel.d.ts +53 -0
- package/dist/v2/shims/vercel.js +90 -0
- package/dist/v2/table.d.ts +53 -0
- package/dist/v2/table.js +122 -0
- package/package.json +20 -310
- package/BLAXEL.md +0 -290
- package/COMPATIBILITY.md +0 -447
- package/DAYTONA.md +0 -237
- package/E2B.md +0 -314
- package/README.md +0 -331
- package/README.src.md +0 -333
- package/VERCEL.md +0 -230
- package/agent-platforms-inventory.json +0 -387
- package/compatibility-lock.json +0 -305
- package/dist/agents/browser.d.ts +0 -12
- package/dist/agents/browser.js +0 -12
- package/dist/agents/index.d.ts +0 -11
- package/dist/agents/index.js +0 -11
- package/dist/agents-cli.d.ts +0 -16
- package/dist/agents-cli.js +0 -1237
- package/dist/agents-deploy.d.ts +0 -196
- package/dist/agents-deploy.js +0 -872
- package/dist/agents-file.d.ts +0 -19
- package/dist/agents-file.js +0 -135
- package/dist/ai/index.d.ts +0 -49
- package/dist/ai/index.js +0 -31
- package/dist/ai-harness/index.d.ts +0 -194
- package/dist/ai-harness/index.js +0 -522
- package/dist/api-defaults.d.ts +0 -17
- package/dist/api-defaults.js +0 -22
- package/dist/apps/index.d.ts +0 -10
- package/dist/apps/index.js +0 -11
- package/dist/apps-cli.d.ts +0 -16
- package/dist/apps-cli.js +0 -1021
- package/dist/billing-cli.d.ts +0 -23
- package/dist/billing-cli.js +0 -264
- package/dist/blaxel/client.d.ts +0 -59
- package/dist/blaxel/client.js +0 -86
- package/dist/blaxel/context.d.ts +0 -59
- package/dist/blaxel/context.js +0 -162
- package/dist/blaxel/errors.d.ts +0 -130
- package/dist/blaxel/errors.js +0 -315
- package/dist/blaxel/filesystem.d.ts +0 -147
- package/dist/blaxel/filesystem.js +0 -585
- package/dist/blaxel/index.d.ts +0 -287
- package/dist/blaxel/index.js +0 -351
- package/dist/blaxel/interpreter.d.ts +0 -71
- package/dist/blaxel/interpreter.js +0 -256
- package/dist/blaxel/lookup.d.ts +0 -39
- package/dist/blaxel/lookup.js +0 -84
- package/dist/blaxel/pagination.d.ts +0 -39
- package/dist/blaxel/pagination.js +0 -88
- package/dist/blaxel/preview.d.ts +0 -136
- package/dist/blaxel/preview.js +0 -304
- package/dist/blaxel/process.d.ts +0 -126
- package/dist/blaxel/process.js +0 -581
- package/dist/blaxel/sandbox.d.ts +0 -198
- package/dist/blaxel/sandbox.js +0 -856
- package/dist/blaxel/session.d.ts +0 -31
- package/dist/blaxel/session.js +0 -136
- package/dist/blaxel/snapshot.d.ts +0 -123
- package/dist/blaxel/snapshot.js +0 -199
- package/dist/blaxel/types.d.ts +0 -145
- package/dist/blaxel/types.js +0 -60
- package/dist/blaxel/unsupported.d.ts +0 -20
- package/dist/blaxel/unsupported.js +0 -32
- package/dist/browser-stub.d.ts +0 -1
- package/dist/browser-stub.js +0 -1
- package/dist/browsers/index.d.ts +0 -9
- package/dist/browsers/index.js +0 -10
- package/dist/browsers-cli.d.ts +0 -13
- package/dist/browsers-cli.js +0 -279
- package/dist/builds/index.d.ts +0 -10
- package/dist/builds/index.js +0 -11
- package/dist/ci/index.d.ts +0 -13
- package/dist/ci/index.js +0 -14
- package/dist/ci-cli.d.ts +0 -20
- package/dist/ci-cli.js +0 -537
- package/dist/ci-import.d.ts +0 -23
- package/dist/ci-import.js +0 -565
- package/dist/claude-agent-sdk/index.d.ts +0 -7
- package/dist/claude-agent-sdk/index.js +0 -65
- package/dist/cli/logs.d.ts +0 -21
- package/dist/cli/logs.js +0 -188
- package/dist/cli-extras.d.ts +0 -39
- package/dist/cli-extras.js +0 -267
- package/dist/cli-name.d.ts +0 -6
- package/dist/cli-name.js +0 -8
- package/dist/cli-update.d.ts +0 -11
- package/dist/cli-update.js +0 -46
- package/dist/cli-words.d.ts +0 -36
- package/dist/cli-words.js +0 -167
- package/dist/cli.d.ts +0 -92
- package/dist/cli.js +0 -5463
- package/dist/client.d.ts +0 -189
- package/dist/client.js +0 -205
- package/dist/cloudflare/errors.d.ts +0 -166
- package/dist/cloudflare/errors.js +0 -183
- package/dist/cloudflare/identity.d.ts +0 -7
- package/dist/cloudflare/identity.js +0 -13
- package/dist/cloudflare/index.d.ts +0 -545
- package/dist/cloudflare/index.js +0 -1106
- package/dist/cloudflare/interpreter.d.ts +0 -119
- package/dist/cloudflare/interpreter.js +0 -232
- package/dist/cloudflare/mime.d.ts +0 -1
- package/dist/cloudflare/mime.js +0 -66
- package/dist/cloudflare/streams.d.ts +0 -46
- package/dist/cloudflare/streams.js +0 -175
- package/dist/cloudflare/types.d.ts +0 -338
- package/dist/cloudflare/types.js +0 -80
- package/dist/cloudflare/watch.d.ts +0 -9
- package/dist/cloudflare/watch.js +0 -24
- package/dist/cloudflare/worker.d.ts +0 -706
- package/dist/cloudflare/worker.js +0 -633
- package/dist/codesandbox/guest-service.d.ts +0 -31
- package/dist/codesandbox/guest-service.js +0 -490
- package/dist/codesandbox/index.d.ts +0 -574
- package/dist/codesandbox/index.js +0 -1747
- package/dist/compat/core.d.ts +0 -58
- package/dist/compat/core.js +0 -267
- package/dist/compat/files.d.ts +0 -27
- package/dist/compat/files.js +0 -157
- package/dist/compat/lease.d.ts +0 -37
- package/dist/compat/lease.js +0 -93
- package/dist/compat/shell.d.ts +0 -4
- package/dist/compat/shell.js +0 -165
- package/dist/containers/index.d.ts +0 -10
- package/dist/containers/index.js +0 -11
- package/dist/credentials.d.ts +0 -71
- package/dist/credentials.js +0 -340
- package/dist/daytona/client.d.ts +0 -48
- package/dist/daytona/client.js +0 -45
- package/dist/daytona/computer-use.d.ts +0 -171
- package/dist/daytona/computer-use.js +0 -382
- package/dist/daytona/context.d.ts +0 -41
- package/dist/daytona/context.js +0 -50
- package/dist/daytona/daytona.d.ts +0 -213
- package/dist/daytona/daytona.js +0 -578
- package/dist/daytona/errors.d.ts +0 -117
- package/dist/daytona/errors.js +0 -201
- package/dist/daytona/filesystem.d.ts +0 -99
- package/dist/daytona/filesystem.js +0 -300
- package/dist/daytona/git.d.ts +0 -33
- package/dist/daytona/git.js +0 -128
- package/dist/daytona/image.d.ts +0 -49
- package/dist/daytona/image.js +0 -146
- package/dist/daytona/index.d.ts +0 -87
- package/dist/daytona/index.js +0 -102
- package/dist/daytona/process.d.ts +0 -143
- package/dist/daytona/process.js +0 -565
- package/dist/daytona/sandbox.d.ts +0 -222
- package/dist/daytona/sandbox.js +0 -505
- package/dist/desktops/index.d.ts +0 -9
- package/dist/desktops/index.js +0 -10
- package/dist/domains/index.d.ts +0 -9
- package/dist/domains/index.js +0 -10
- package/dist/e2b/client.d.ts +0 -76
- package/dist/e2b/client.js +0 -124
- package/dist/e2b/code-interpreter.d.ts +0 -134
- package/dist/e2b/code-interpreter.js +0 -239
- package/dist/e2b/commands.d.ts +0 -135
- package/dist/e2b/commands.js +0 -452
- package/dist/e2b/errors.d.ts +0 -125
- package/dist/e2b/errors.js +0 -247
- package/dist/e2b/filesystem.d.ts +0 -111
- package/dist/e2b/filesystem.js +0 -374
- package/dist/e2b/index.d.ts +0 -35
- package/dist/e2b/index.js +0 -69
- package/dist/e2b/pty.d.ts +0 -24
- package/dist/e2b/pty.js +0 -83
- package/dist/e2b/sandbox.d.ts +0 -248
- package/dist/e2b/sandbox.js +0 -781
- package/dist/e2b/unsupported.d.ts +0 -38
- package/dist/e2b/unsupported.js +0 -48
- package/dist/e2b/users.d.ts +0 -39
- package/dist/e2b/users.js +0 -207
- package/dist/errors.d.ts +0 -100
- package/dist/errors.js +0 -198
- package/dist/file-source.d.ts +0 -16
- package/dist/file-source.js +0 -162
- package/dist/fly/index.d.ts +0 -102
- package/dist/fly/index.js +0 -930
- package/dist/freestyle/index.d.ts +0 -629
- package/dist/freestyle/index.js +0 -1187
- package/dist/functions/index.d.ts +0 -10
- package/dist/functions/index.js +0 -11
- package/dist/identity.d.ts +0 -30
- package/dist/identity.js +0 -141
- package/dist/image-context.d.ts +0 -39
- package/dist/image-context.js +0 -176
- package/dist/images/index.d.ts +0 -9
- package/dist/images/index.js +0 -10
- package/dist/index.d.ts +0 -87
- package/dist/index.js +0 -51
- package/dist/inngest/index.d.ts +0 -96
- package/dist/inngest/index.js +0 -183
- package/dist/ips/index.d.ts +0 -9
- package/dist/ips/index.js +0 -10
- package/dist/jobs/index.d.ts +0 -9
- package/dist/jobs/index.js +0 -10
- package/dist/jobs-code/cron.d.ts +0 -12
- package/dist/jobs-code/cron.js +0 -93
- package/dist/jobs-code/registry.d.ts +0 -31
- package/dist/jobs-code/registry.js +0 -30
- package/dist/jobs-code/runner.d.ts +0 -1
- package/dist/jobs-code/runner.js +0 -74
- package/dist/jobs-deploy.d.ts +0 -22
- package/dist/jobs-deploy.js +0 -247
- package/dist/jobs-import.d.ts +0 -15
- package/dist/jobs-import.js +0 -231
- package/dist/keys.d.ts +0 -55
- package/dist/keys.js +0 -211
- package/dist/login.d.ts +0 -88
- package/dist/login.js +0 -369
- package/dist/machine.d.ts +0 -222
- package/dist/machine.js +0 -578
- package/dist/mcp.d.ts +0 -16
- package/dist/mcp.js +0 -377
- package/dist/modal/index.d.ts +0 -532
- package/dist/modal/index.js +0 -1284
- package/dist/morph/index.d.ts +0 -255
- package/dist/morph/index.js +0 -641
- package/dist/network-cli.d.ts +0 -17
- package/dist/network-cli.js +0 -523
- package/dist/networks/index.d.ts +0 -11
- package/dist/networks/index.js +0 -10
- package/dist/openai-agents/index.d.ts +0 -132
- package/dist/openai-agents/index.js +0 -738
- package/dist/page.d.ts +0 -13
- package/dist/page.js +0 -39
- package/dist/ports/index.d.ts +0 -9
- package/dist/ports/index.js +0 -10
- package/dist/product-names.d.ts +0 -52
- package/dist/product-names.js +0 -174
- package/dist/product-renames.d.ts +0 -103
- package/dist/product-renames.js +0 -189
- package/dist/products/agents.d.ts +0 -935
- package/dist/products/agents.js +0 -581
- package/dist/products/api-keys.d.ts +0 -113
- package/dist/products/api-keys.js +0 -32
- package/dist/products/apps.d.ts +0 -409
- package/dist/products/apps.js +0 -231
- package/dist/products/audit.d.ts +0 -51
- package/dist/products/audit.js +0 -10
- package/dist/products/balancers.d.ts +0 -87
- package/dist/products/balancers.js +0 -8
- package/dist/products/billing.d.ts +0 -76
- package/dist/products/billing.js +0 -26
- package/dist/products/browser.d.ts +0 -73
- package/dist/products/browser.js +0 -29
- package/dist/products/browsers.d.ts +0 -184
- package/dist/products/browsers.js +0 -180
- package/dist/products/builds.d.ts +0 -175
- package/dist/products/builds.js +0 -234
- package/dist/products/ci.d.ts +0 -406
- package/dist/products/ci.js +0 -133
- package/dist/products/containers.d.ts +0 -71
- package/dist/products/containers.js +0 -6
- package/dist/products/desktop.d.ts +0 -141
- package/dist/products/desktop.js +0 -83
- package/dist/products/desktops.d.ts +0 -71
- package/dist/products/desktops.js +0 -27
- package/dist/products/functions.d.ts +0 -2
- package/dist/products/functions.js +0 -5
- package/dist/products/images.d.ts +0 -229
- package/dist/products/images.js +0 -235
- package/dist/products/index.d.ts +0 -84
- package/dist/products/index.js +0 -105
- package/dist/products/interpreter.d.ts +0 -97
- package/dist/products/interpreter.js +0 -106
- package/dist/products/jobs.d.ts +0 -408
- package/dist/products/jobs.js +0 -256
- package/dist/products/limits.d.ts +0 -61
- package/dist/products/limits.js +0 -10
- package/dist/products/logs.d.ts +0 -245
- package/dist/products/logs.js +0 -274
- package/dist/products/mcp.d.ts +0 -88
- package/dist/products/mcp.js +0 -58
- package/dist/products/mounts.d.ts +0 -49
- package/dist/products/mounts.js +0 -21
- package/dist/products/network-products.d.ts +0 -268
- package/dist/products/network-products.js +0 -127
- package/dist/products/network.d.ts +0 -62
- package/dist/products/network.js +0 -19
- package/dist/products/observability.d.ts +0 -264
- package/dist/products/observability.js +0 -123
- package/dist/products/plans.d.ts +0 -133
- package/dist/products/plans.js +0 -24
- package/dist/products/previews.d.ts +0 -70
- package/dist/products/previews.js +0 -39
- package/dist/products/private-network.d.ts +0 -22
- package/dist/products/private-network.js +0 -10
- package/dist/products/queues.d.ts +0 -149
- package/dist/products/queues.js +0 -213
- package/dist/products/referrals.d.ts +0 -50
- package/dist/products/referrals.js +0 -8
- package/dist/products/reservations.d.ts +0 -108
- package/dist/products/reservations.js +0 -41
- package/dist/products/resources.d.ts +0 -55
- package/dist/products/resources.js +0 -122
- package/dist/products/secrets.d.ts +0 -316
- package/dist/products/secrets.js +0 -333
- package/dist/products/signed-requests.d.ts +0 -21
- package/dist/products/signed-requests.js +0 -11
- package/dist/products/sso.d.ts +0 -44
- package/dist/products/sso.js +0 -8
- package/dist/products/streams.d.ts +0 -73
- package/dist/products/streams.js +0 -17
- package/dist/products/switching.d.ts +0 -123
- package/dist/products/switching.js +0 -26
- package/dist/products/tailscale.d.ts +0 -57
- package/dist/products/tailscale.js +0 -17
- package/dist/products/uptime.d.ts +0 -97
- package/dist/products/uptime.js +0 -42
- package/dist/products/volumes.d.ts +0 -190
- package/dist/products/volumes.js +0 -114
- package/dist/products/watch.d.ts +0 -112
- package/dist/products/watch.js +0 -249
- package/dist/proxy.d.ts +0 -30
- package/dist/proxy.js +0 -200
- package/dist/record-cli.d.ts +0 -23
- package/dist/record-cli.js +0 -308
- package/dist/renamed-products.d.ts +0 -38
- package/dist/renamed-products.js +0 -34
- package/dist/resumable.d.ts +0 -32
- package/dist/resumable.js +0 -201
- package/dist/runloop/index.d.ts +0 -333
- package/dist/runloop/index.js +0 -560
- package/dist/runloop/pagination.d.ts +0 -46
- package/dist/runloop/pagination.js +0 -82
- package/dist/runloop/sdk.d.ts +0 -131
- package/dist/runloop/sdk.js +0 -167
- package/dist/runloop/snapshots.d.ts +0 -52
- package/dist/runloop/snapshots.js +0 -244
- package/dist/sandbox.d.ts +0 -371
- package/dist/sandbox.js +0 -1500
- package/dist/sandboxes/index.d.ts +0 -11
- package/dist/sandboxes/index.js +0 -12
- package/dist/sealing.d.ts +0 -6
- package/dist/sealing.js +0 -14
- package/dist/snapshots/index.d.ts +0 -9
- package/dist/snapshots/index.js +0 -11
- package/dist/snapshots.d.ts +0 -82
- package/dist/snapshots.js +0 -65
- package/dist/sprites/index.d.ts +0 -563
- package/dist/sprites/index.js +0 -1370
- package/dist/ssh.d.ts +0 -56
- package/dist/ssh.js +0 -416
- package/dist/switched-off.d.ts +0 -5
- package/dist/switched-off.js +0 -8
- package/dist/tar.d.ts +0 -15
- package/dist/tar.js +0 -526
- package/dist/terminal.d.ts +0 -24
- package/dist/terminal.js +0 -32
- package/dist/tools/index.d.ts +0 -62
- package/dist/tools/index.js +0 -181
- package/dist/transport.d.ts +0 -165
- package/dist/transport.js +0 -883
- package/dist/trigger/index.d.ts +0 -202
- package/dist/trigger/index.js +0 -244
- package/dist/tunnel.d.ts +0 -70
- package/dist/tunnel.js +0 -316
- package/dist/types.d.ts +0 -585
- package/dist/types.js +0 -1
- package/dist/vercel/client.d.ts +0 -40
- package/dist/vercel/client.js +0 -39
- package/dist/vercel/command.d.ts +0 -117
- package/dist/vercel/command.js +0 -391
- package/dist/vercel/errors.d.ts +0 -53
- package/dist/vercel/errors.js +0 -131
- package/dist/vercel/filesystem.d.ts +0 -153
- package/dist/vercel/filesystem.js +0 -297
- package/dist/vercel/index.d.ts +0 -24
- package/dist/vercel/index.js +0 -36
- package/dist/vercel/sandbox-user.d.ts +0 -70
- package/dist/vercel/sandbox-user.js +0 -207
- package/dist/vercel/sandbox.d.ts +0 -372
- package/dist/vercel/sandbox.js +0 -1037
- package/dist/vercel/snapshot.d.ts +0 -94
- package/dist/vercel/snapshot.js +0 -137
- package/dist/volumes/index.d.ts +0 -9
- package/dist/volumes/index.js +0 -10
- package/dist/wait.d.ts +0 -12
- package/dist/wait.js +0 -47
- package/dist/wallet.d.ts +0 -45
- package/dist/wallet.js +0 -56
- package/dist/wireguard.d.ts +0 -7
- package/dist/wireguard.js +0 -13
package/dist/modal/index.js
DELETED
|
@@ -1,1284 +0,0 @@
|
|
|
1
|
-
import { ConflictError as NativeConflictError, InvalidRequestError, NotFoundError as NativeNotFoundError, RateLimitError, RuntimeError, ServiceUnavailableError, } from "../errors.js";
|
|
2
|
-
import { all, client, CompatibilityError, create, destroy, execOptions, only, refuse, refusal, refused, region, } from "../compat/core.js";
|
|
3
|
-
import { GuestFiles } from "../compat/files.js";
|
|
4
|
-
export { CompatibilityError };
|
|
5
|
-
// Errors ----------------------------------------------------------------------
|
|
6
|
-
export class TimeoutError extends Error {
|
|
7
|
-
}
|
|
8
|
-
export class RemoteError extends Error {
|
|
9
|
-
}
|
|
10
|
-
export class ExecutionError extends Error {
|
|
11
|
-
}
|
|
12
|
-
export class InternalFailure extends Error {
|
|
13
|
-
}
|
|
14
|
-
export class NotFoundError extends Error {
|
|
15
|
-
}
|
|
16
|
-
export class AlreadyExistsError extends Error {
|
|
17
|
-
}
|
|
18
|
-
export class ConflictError extends Error {
|
|
19
|
-
}
|
|
20
|
-
export class InvalidError extends Error {
|
|
21
|
-
}
|
|
22
|
-
export class ResourceExhaustedError extends Error {
|
|
23
|
-
}
|
|
24
|
-
export class SandboxTimeoutError extends TimeoutError {
|
|
25
|
-
}
|
|
26
|
-
export class SnapshotCreationError extends Error {
|
|
27
|
-
}
|
|
28
|
-
export class ClientClosedError extends Error {
|
|
29
|
-
}
|
|
30
|
-
export class SandboxFilesystemError extends Error {
|
|
31
|
-
}
|
|
32
|
-
export class SandboxFilesystemDirectoryNotEmptyError extends SandboxFilesystemError {
|
|
33
|
-
}
|
|
34
|
-
export class SandboxFilesystemFileTooLargeError extends SandboxFilesystemError {
|
|
35
|
-
}
|
|
36
|
-
export class SandboxFilesystemIsADirectoryError extends SandboxFilesystemError {
|
|
37
|
-
}
|
|
38
|
-
export class SandboxFilesystemNotADirectoryError extends SandboxFilesystemError {
|
|
39
|
-
}
|
|
40
|
-
export class SandboxFilesystemNotFoundError extends SandboxFilesystemError {
|
|
41
|
-
}
|
|
42
|
-
export class SandboxFilesystemPathAlreadyExistsError extends SandboxFilesystemError {
|
|
43
|
-
}
|
|
44
|
-
export class SandboxFilesystemPermissionError extends SandboxFilesystemError {
|
|
45
|
-
}
|
|
46
|
-
/** A Runtime failure as the Modal error a caller catches. */
|
|
47
|
-
function modalError(error) {
|
|
48
|
-
if (!(error instanceof RuntimeError))
|
|
49
|
-
return error;
|
|
50
|
-
if (error.code === "name_taken")
|
|
51
|
-
return new AlreadyExistsError(error.message);
|
|
52
|
-
if (error instanceof NativeNotFoundError)
|
|
53
|
-
return new NotFoundError(error.message);
|
|
54
|
-
if (error instanceof NativeConflictError)
|
|
55
|
-
return new ConflictError(error.message);
|
|
56
|
-
if (error instanceof InvalidRequestError)
|
|
57
|
-
return new InvalidError(error.message);
|
|
58
|
-
if (error instanceof RateLimitError || error.code === "quota_exceeded")
|
|
59
|
-
return new ResourceExhaustedError(error.message);
|
|
60
|
-
if (error instanceof ServiceUnavailableError || error.status >= 500)
|
|
61
|
-
return new InternalFailure(error.message);
|
|
62
|
-
return error;
|
|
63
|
-
}
|
|
64
|
-
async function modal(run) {
|
|
65
|
-
try {
|
|
66
|
-
return await run();
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
throw modalError(error);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const FILE_ERRORS = {
|
|
73
|
-
file_not_found: SandboxFilesystemNotFoundError,
|
|
74
|
-
path_not_found: SandboxFilesystemNotFoundError,
|
|
75
|
-
is_a_directory: SandboxFilesystemIsADirectoryError,
|
|
76
|
-
not_a_directory: SandboxFilesystemNotADirectoryError,
|
|
77
|
-
directory_not_empty: SandboxFilesystemDirectoryNotEmptyError,
|
|
78
|
-
already_exists: SandboxFilesystemPathAlreadyExistsError,
|
|
79
|
-
permission_denied: SandboxFilesystemPermissionError,
|
|
80
|
-
file_too_large: SandboxFilesystemFileTooLargeError,
|
|
81
|
-
too_large: SandboxFilesystemFileTooLargeError,
|
|
82
|
-
};
|
|
83
|
-
async function fileCall(path, run) {
|
|
84
|
-
try {
|
|
85
|
-
return await run();
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
if (!(error instanceof RuntimeError))
|
|
89
|
-
throw error;
|
|
90
|
-
const Mapped = FILE_ERRORS[error.code] ?? (error.status === 404 ? SandboxFilesystemNotFoundError : null);
|
|
91
|
-
if (!Mapped)
|
|
92
|
-
throw error;
|
|
93
|
-
throw new Mapped(`${path}: ${error.message}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// Apps, secrets, volumes, bucket mounts -----------------------------------------
|
|
97
|
-
export class App {
|
|
98
|
-
appId;
|
|
99
|
-
name;
|
|
100
|
-
environmentName;
|
|
101
|
-
constructor(appId, name, environmentName) {
|
|
102
|
-
this.appId = appId;
|
|
103
|
-
this.name = name;
|
|
104
|
-
this.environmentName = environmentName;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
refuse("Modal", "App", App, {
|
|
108
|
-
info: "a Runtime app is a label on its sandboxes, with no lifecycle, Functions or Servers: list them with client.sandboxes.list({ appId: app.appId })",
|
|
109
|
-
});
|
|
110
|
-
export class AppService {
|
|
111
|
-
client;
|
|
112
|
-
constructor(client) {
|
|
113
|
-
this.client = client;
|
|
114
|
-
}
|
|
115
|
-
async fromName(name, params = {}) {
|
|
116
|
-
this.client.open();
|
|
117
|
-
only("Modal app", params, ["createIfMissing", "environment"]);
|
|
118
|
-
if (params.environment)
|
|
119
|
-
throw new CompatibilityError("Modal", "named Modal environments");
|
|
120
|
-
if (!params.createIfMissing &&
|
|
121
|
-
!(await all(this.client.runtime, "modal")).some((s) => s.info.labels["modal.app"] === name))
|
|
122
|
-
throw new NotFoundError(`App ${name} has no Runtime sandboxes; pass createIfMissing: true.`);
|
|
123
|
-
return new App(name, name);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/** Values the sandbox receives as environment variables, from the caller. */
|
|
127
|
-
export class Secret {
|
|
128
|
-
values;
|
|
129
|
-
name;
|
|
130
|
-
secretId;
|
|
131
|
-
constructor(values, name) {
|
|
132
|
-
this.values = values;
|
|
133
|
-
this.name = name;
|
|
134
|
-
this.secretId = `st-${crypto.randomUUID()}`;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const RUNTIME_SECRETS = "Runtime secrets are used without being seen: runtime.secrets.set({ value, hosts }); or pass values with secrets.fromObject";
|
|
138
|
-
export class SecretService {
|
|
139
|
-
client;
|
|
140
|
-
constructor(client) {
|
|
141
|
-
this.client = client;
|
|
142
|
-
}
|
|
143
|
-
async fromObject(entries, params = {}) {
|
|
144
|
-
this.client.open();
|
|
145
|
-
only("Modal secret", params, ["environment"]);
|
|
146
|
-
if (params.environment)
|
|
147
|
-
throw new CompatibilityError("Modal", "named Modal environments");
|
|
148
|
-
for (const [key, value] of Object.entries(entries))
|
|
149
|
-
if (typeof value !== "string")
|
|
150
|
-
throw new InvalidError(`Secret value for ${key} must be a string`);
|
|
151
|
-
return new Secret({ ...entries });
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
refuse("Modal", "SecretService", SecretService, {
|
|
155
|
-
fromName: RUNTIME_SECRETS,
|
|
156
|
-
delete: RUNTIME_SECRETS,
|
|
157
|
-
});
|
|
158
|
-
const FIXED_SIZE = "Runtime volumes have a fixed size: create one with runtime.volumes.create({ name, sizeMiB })";
|
|
159
|
-
export class Volume {
|
|
160
|
-
volumeId;
|
|
161
|
-
name;
|
|
162
|
-
readOnly;
|
|
163
|
-
constructor(volumeId, name, readOnly = false) {
|
|
164
|
-
this.volumeId = volumeId;
|
|
165
|
-
this.name = name;
|
|
166
|
-
this.readOnly = readOnly;
|
|
167
|
-
}
|
|
168
|
-
withMountOptions(params = {}) {
|
|
169
|
-
only("Modal volume mount", params, ["readOnly", "subPath"]);
|
|
170
|
-
if (params.subPath)
|
|
171
|
-
throw new CompatibilityError("Modal", "subPath; mount the whole volume");
|
|
172
|
-
return new Volume(this.volumeId, this.name, params.readOnly ?? this.readOnly);
|
|
173
|
-
}
|
|
174
|
-
closeEphemeral() {
|
|
175
|
-
throw new InvalidError(`Volume ${this.name ?? this.volumeId} is not ephemeral`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
export class VolumeService {
|
|
179
|
-
client;
|
|
180
|
-
constructor(client) {
|
|
181
|
-
this.client = client;
|
|
182
|
-
}
|
|
183
|
-
async find(name) {
|
|
184
|
-
const page = await modal(() => this.client.runtime.volumes.list({ name, limit: 100 }));
|
|
185
|
-
return page.data.find((v) => v.name === name && v.state !== "deleted");
|
|
186
|
-
}
|
|
187
|
-
async fromName(name, params = {}) {
|
|
188
|
-
this.client.open();
|
|
189
|
-
only("Modal volume", params, ["createIfMissing", "environment", "version"]);
|
|
190
|
-
if (params.environment)
|
|
191
|
-
throw new CompatibilityError("Modal", "named Modal environments");
|
|
192
|
-
if (params.version !== undefined)
|
|
193
|
-
throw new CompatibilityError("Modal", "VolumeFS versions; a Runtime volume has one format, so omit version");
|
|
194
|
-
const found = await this.find(name);
|
|
195
|
-
if (found)
|
|
196
|
-
return new Volume(found.id, name);
|
|
197
|
-
if (params.createIfMissing)
|
|
198
|
-
throw new CompatibilityError("Modal", `createIfMissing; ${FIXED_SIZE}`);
|
|
199
|
-
throw new NotFoundError(`Volume ${name} not found`);
|
|
200
|
-
}
|
|
201
|
-
async delete(name, params = {}) {
|
|
202
|
-
this.client.open();
|
|
203
|
-
only("Modal volume delete", params, ["allowMissing", "environment"]);
|
|
204
|
-
if (params.environment)
|
|
205
|
-
throw new CompatibilityError("Modal", "named Modal environments");
|
|
206
|
-
const found = await this.find(name);
|
|
207
|
-
if (!found) {
|
|
208
|
-
if (params.allowMissing)
|
|
209
|
-
return;
|
|
210
|
-
throw new NotFoundError(`Volume ${name} not found`);
|
|
211
|
-
}
|
|
212
|
-
await modal(() => this.client.runtime.volumes.delete(found.id));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
refuse("Modal", "VolumeService", VolumeService, { ephemeral: FIXED_SIZE });
|
|
216
|
-
const BUCKET_KEYS = "store the bucket key with runtime.secrets.set and mount it with the native sandbox's mounts.add";
|
|
217
|
-
export class CloudBucketMount {
|
|
218
|
-
bucketName;
|
|
219
|
-
readOnly;
|
|
220
|
-
bucketEndpointUrl;
|
|
221
|
-
keyPrefix;
|
|
222
|
-
/** Refused at creation: Runtime mounts public buckets here, keyed ones natively. */
|
|
223
|
-
secret;
|
|
224
|
-
requesterPays = false;
|
|
225
|
-
oidcAuthRoleArn;
|
|
226
|
-
constructor(bucketName, readOnly = false, bucketEndpointUrl, keyPrefix) {
|
|
227
|
-
this.bucketName = bucketName;
|
|
228
|
-
this.readOnly = readOnly;
|
|
229
|
-
this.bucketEndpointUrl = bucketEndpointUrl;
|
|
230
|
-
this.keyPrefix = keyPrefix;
|
|
231
|
-
}
|
|
232
|
-
/** The native mount for `path`: the provider read from the endpoint's host. */
|
|
233
|
-
native(path) {
|
|
234
|
-
const host = this.bucketEndpointUrl ? new URL(this.bucketEndpointUrl).hostname : undefined;
|
|
235
|
-
const r2 = host?.match(/^([0-9a-f]+)\.r2\.cloudflarestorage\.com$/);
|
|
236
|
-
return {
|
|
237
|
-
provider: r2
|
|
238
|
-
? "r2"
|
|
239
|
-
: host === "storage.googleapis.com"
|
|
240
|
-
? "gcs"
|
|
241
|
-
: "s3",
|
|
242
|
-
bucket: this.bucketName,
|
|
243
|
-
path,
|
|
244
|
-
...(r2 ? { accountId: r2[1] } : host ? { endpoint: host } : {}),
|
|
245
|
-
...(this.keyPrefix ? { prefix: this.keyPrefix } : {}),
|
|
246
|
-
readOnly: this.readOnly,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
refuse("Modal", "CloudBucketMount", CloudBucketMount, { toProto: "pass it in cloudBucketMounts" }, { sync: true });
|
|
251
|
-
export class CloudBucketMountService {
|
|
252
|
-
create(bucketName, params = {}) {
|
|
253
|
-
only("Modal bucket mount", params, [
|
|
254
|
-
"secret",
|
|
255
|
-
"readOnly",
|
|
256
|
-
"requesterPays",
|
|
257
|
-
"bucketEndpointUrl",
|
|
258
|
-
"keyPrefix",
|
|
259
|
-
"oidcAuthRoleArn",
|
|
260
|
-
]);
|
|
261
|
-
if (params.secret)
|
|
262
|
-
throw new CompatibilityError("Modal", `bucket secret; ${BUCKET_KEYS}`);
|
|
263
|
-
if (params.requesterPays || params.oidcAuthRoleArn)
|
|
264
|
-
throw new CompatibilityError("Modal", `requesterPays and oidcAuthRoleArn; ${BUCKET_KEYS}`);
|
|
265
|
-
if (params.bucketEndpointUrl)
|
|
266
|
-
new URL(params.bucketEndpointUrl);
|
|
267
|
-
return new CloudBucketMount(bucketName, params.readOnly ?? false, params.bucketEndpointUrl, params.keyPrefix);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
export class Proxy {
|
|
271
|
-
}
|
|
272
|
-
export class ProxyService {
|
|
273
|
-
}
|
|
274
|
-
const STATIC_IPS = "Runtime static egress IPs: runtime.ips";
|
|
275
|
-
refuse("Modal", "Proxy", Proxy, { proxyId: STATIC_IPS }, { sync: true });
|
|
276
|
-
refuse("Modal", "ProxyService", ProxyService, { fromName: STATIC_IPS });
|
|
277
|
-
// Modal's other products, outside its sandboxes: each call refuses, naming
|
|
278
|
-
// what to use, where it was undefined before (function-call.ts, 18 October 2026).
|
|
279
|
-
const FUNCTIONS = "Runtime runs sandboxes, not Modal Functions: run the code in a sandbox (modal.sandboxes.create), or on a schedule as a Runtime job (runtime.jobs)";
|
|
280
|
-
const QUEUES = "keep the queue in your own store, or in a file on a Runtime volume (runtime.volumes)";
|
|
281
|
-
export class FunctionService {
|
|
282
|
-
}
|
|
283
|
-
export class FunctionCallService {
|
|
284
|
-
}
|
|
285
|
-
export class ClsService {
|
|
286
|
-
}
|
|
287
|
-
export class QueueService {
|
|
288
|
-
}
|
|
289
|
-
refuse("Modal", "FunctionService", FunctionService, { fromName: FUNCTIONS, fromId: FUNCTIONS });
|
|
290
|
-
refuse("Modal", "FunctionCallService", FunctionCallService, { fromId: FUNCTIONS });
|
|
291
|
-
refuse("Modal", "ClsService", ClsService, { fromName: FUNCTIONS });
|
|
292
|
-
refuse("Modal", "QueueService", QueueService, {
|
|
293
|
-
fromName: QUEUES,
|
|
294
|
-
ephemeral: QUEUES,
|
|
295
|
-
delete: QUEUES,
|
|
296
|
-
});
|
|
297
|
-
export class ExperimentalOutboundPolicy {
|
|
298
|
-
}
|
|
299
|
-
refuse("Modal", "ExperimentalOutboundPolicy", ExperimentalOutboundPolicy, {
|
|
300
|
-
withHeaderReplacement: "Runtime secrets set the header on the way out: runtime.secrets.set({ value, hosts, header })",
|
|
301
|
-
}, { sync: true });
|
|
302
|
-
export class Probe {
|
|
303
|
-
spec;
|
|
304
|
-
constructor(spec) {
|
|
305
|
-
this.spec = spec;
|
|
306
|
-
}
|
|
307
|
-
static interval(name, intervalMs) {
|
|
308
|
-
if (!Number.isInteger(intervalMs))
|
|
309
|
-
throw new InvalidError(`${name}() expects an integer \`intervalMs\``);
|
|
310
|
-
if (intervalMs <= 0)
|
|
311
|
-
throw new InvalidError(`${name}() expects \`intervalMs\` > 0, got ${String(intervalMs)}`);
|
|
312
|
-
}
|
|
313
|
-
static withTcp(port, params = { intervalMs: 100 }) {
|
|
314
|
-
if (!Number.isInteger(port))
|
|
315
|
-
throw new InvalidError("Probe.withTcp() expects an integer `port`");
|
|
316
|
-
if (port <= 0 || port > 65535)
|
|
317
|
-
throw new InvalidError(`Probe.withTcp() expects \`port\` in [1, 65535], got ${port}`);
|
|
318
|
-
Probe.interval("Probe.withTcp", params.intervalMs);
|
|
319
|
-
return new Probe({ tcpPort: port, intervalMs: params.intervalMs });
|
|
320
|
-
}
|
|
321
|
-
static withExec(argv, params = { intervalMs: 100 }) {
|
|
322
|
-
if (!Array.isArray(argv) || argv.length === 0)
|
|
323
|
-
throw new InvalidError("Probe.withExec() requires at least one argument");
|
|
324
|
-
if (!argv.every((arg) => typeof arg === "string"))
|
|
325
|
-
throw new InvalidError("Probe.withExec() expects all arguments to be strings");
|
|
326
|
-
Probe.interval("Probe.withExec", params.intervalMs);
|
|
327
|
-
return new Probe({ execArgv: [...argv], intervalMs: params.intervalMs });
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
refuse("Modal", "Probe", Probe, { toProto: "pass it as readinessProbe" }, { sync: true });
|
|
331
|
-
// Images ------------------------------------------------------------------------
|
|
332
|
-
const BUILD_SECRETS = "a Runtime image build keeps no secret: use it at run time, with sandboxes.create(app, image, { secrets }), or runtime.secrets.set({ value, hosts }) so the sandbox never sees it";
|
|
333
|
-
export class Image {
|
|
334
|
-
runtime;
|
|
335
|
-
tag;
|
|
336
|
-
commands;
|
|
337
|
-
env;
|
|
338
|
-
cache;
|
|
339
|
-
snapshot;
|
|
340
|
-
built;
|
|
341
|
-
constructor(
|
|
342
|
-
/** Absent only for an Image that is already built. */
|
|
343
|
-
runtime, tag, id, commands = [], env = {}, cache = true,
|
|
344
|
-
/** The id is a native disk snapshot (snapshotFilesystem), not an image. */
|
|
345
|
-
snapshot = false) {
|
|
346
|
-
this.runtime = runtime;
|
|
347
|
-
this.tag = tag;
|
|
348
|
-
this.commands = commands;
|
|
349
|
-
this.env = env;
|
|
350
|
-
this.cache = cache;
|
|
351
|
-
this.snapshot = snapshot;
|
|
352
|
-
this.built = id;
|
|
353
|
-
}
|
|
354
|
-
get imageId() {
|
|
355
|
-
if (!this.built)
|
|
356
|
-
throw new Error("Image is not built; await image.build(app) first.");
|
|
357
|
-
return this.built;
|
|
358
|
-
}
|
|
359
|
-
/** A layer of Dockerfile commands. Its `secrets` refuse: a Runtime build
|
|
360
|
-
* keeps its build arguments in the image's build plan, history and cache
|
|
361
|
-
* key, and has no channel that never keeps a value, so a secret is used at
|
|
362
|
-
* run time instead (security review, 18 October 2026). */
|
|
363
|
-
dockerfileCommands(commands, params = {}) {
|
|
364
|
-
only("Modal image", params, ["env", "secrets", "gpu", "forceBuild"]);
|
|
365
|
-
if (params.gpu)
|
|
366
|
-
throw new CompatibilityError("Modal", "GPU image builds");
|
|
367
|
-
if (!this.tag)
|
|
368
|
-
throw new CompatibilityError("Modal", "extending a prebuilt Runtime image through Dockerfile layers");
|
|
369
|
-
if (params.secrets?.length)
|
|
370
|
-
throw refusal("Modal", "Image.dockerfileCommands secrets", BUILD_SECRETS);
|
|
371
|
-
return new Image(this.runtime, this.tag, undefined, [...this.commands, ...commands], { ...this.env, ...params.env }, params.forceBuild ? false : this.cache);
|
|
372
|
-
}
|
|
373
|
-
async build(_app) {
|
|
374
|
-
if (!this.built) {
|
|
375
|
-
const built = await modal(() => this.commands.length
|
|
376
|
-
? this.runtime.images.build({
|
|
377
|
-
dockerfile: [`FROM ${this.tag}`, ...this.commands].join("\n"),
|
|
378
|
-
env: this.env,
|
|
379
|
-
cache: this.cache,
|
|
380
|
-
})
|
|
381
|
-
: this.runtime.images.build({ image: this.tag, env: this.env, cache: this.cache }));
|
|
382
|
-
this.built = built.id;
|
|
383
|
-
}
|
|
384
|
-
return this;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
refuse("Modal", "Image", Image, {
|
|
388
|
-
publish: "build it under a name: runtime.images.build({ name }), then images.fromName",
|
|
389
|
-
});
|
|
390
|
-
const REGISTRY_LOGIN = "store the registry login with runtime.images.registries, then use images.fromRegistry";
|
|
391
|
-
export class ImageService {
|
|
392
|
-
client;
|
|
393
|
-
constructor(client) {
|
|
394
|
-
this.client = client;
|
|
395
|
-
}
|
|
396
|
-
fromRegistry(tag, secret) {
|
|
397
|
-
this.client.open();
|
|
398
|
-
if (secret)
|
|
399
|
-
throw new CompatibilityError("Modal", `registry Secret; ${REGISTRY_LOGIN}`);
|
|
400
|
-
return new Image(this.client.runtime, tag);
|
|
401
|
-
}
|
|
402
|
-
async fromId(imageId) {
|
|
403
|
-
this.client.open();
|
|
404
|
-
return new Image(this.client.runtime, undefined, (await modal(() => this.client.runtime.images.get(imageId))).id);
|
|
405
|
-
}
|
|
406
|
-
async fromName(name, params = {}) {
|
|
407
|
-
this.client.open();
|
|
408
|
-
only("Modal image name", params, ["environment"]);
|
|
409
|
-
if (params.environment)
|
|
410
|
-
throw new CompatibilityError("Modal", "named Modal environments");
|
|
411
|
-
return new Image(this.client.runtime, undefined, (await modal(() => this.client.runtime.images.resolve(name))).id);
|
|
412
|
-
}
|
|
413
|
-
async delete(imageId, _params = {}) {
|
|
414
|
-
this.client.open();
|
|
415
|
-
await modal(() => this.client.runtime.images.delete(imageId));
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
refuse("Modal", "ImageService", ImageService, { fromAwsEcr: REGISTRY_LOGIN, fromGcpArtifactRegistry: REGISTRY_LOGIN }, { sync: true });
|
|
419
|
-
// Snapshots ---------------------------------------------------------------------
|
|
420
|
-
export class SandboxSnapshot {
|
|
421
|
-
snapshotId;
|
|
422
|
-
constructor(snapshotId) {
|
|
423
|
-
this.snapshotId = snapshotId;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
export class SandboxSnapshotService {
|
|
427
|
-
client;
|
|
428
|
-
constructor(client) {
|
|
429
|
-
this.client = client;
|
|
430
|
-
}
|
|
431
|
-
async fromId(snapshotId) {
|
|
432
|
-
this.client.open();
|
|
433
|
-
const snapshot = await modal(() => this.client.runtime.snapshots.get(snapshotId));
|
|
434
|
-
if (snapshot.state === "deleted" || snapshot.state === "deleting")
|
|
435
|
-
throw new NotFoundError(`Sandbox snapshot ${snapshotId} not found`);
|
|
436
|
-
return new SandboxSnapshot(snapshot.id);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
// Environments ------------------------------------------------------------------
|
|
440
|
-
const NO_ENVIRONMENTS = "Runtime has no Modal environments: an account's sandboxes share one namespace, grouped by app name (client.apps.fromName) and tags";
|
|
441
|
-
/** `client.environments` (modal 0.11.1): refused, as `environment` options are. */
|
|
442
|
-
export class EnvironmentService {
|
|
443
|
-
}
|
|
444
|
-
refuse("Modal", "EnvironmentService", EnvironmentService, { fromName: NO_ENVIRONMENTS });
|
|
445
|
-
Object.defineProperty(EnvironmentService.prototype, "objects", {
|
|
446
|
-
configurable: true,
|
|
447
|
-
get() {
|
|
448
|
-
throw refusal("Modal", "EnvironmentService.objects", NO_ENVIRONMENTS);
|
|
449
|
-
},
|
|
450
|
-
});
|
|
451
|
-
export const Environment = refused("Modal", "Environment", NO_ENVIRONMENTS);
|
|
452
|
-
export const EnvironmentAppsService = refused("Modal", "EnvironmentAppsService", NO_ENVIRONMENTS);
|
|
453
|
-
export const EnvironmentObjectsService = refused("Modal", "EnvironmentObjectsService", NO_ENVIRONMENTS);
|
|
454
|
-
export class ModalClient {
|
|
455
|
-
runtime;
|
|
456
|
-
apps;
|
|
457
|
-
images;
|
|
458
|
-
sandboxes;
|
|
459
|
-
secrets;
|
|
460
|
-
volumes;
|
|
461
|
-
cloudBucketMounts = new CloudBucketMountService();
|
|
462
|
-
sandboxSnapshots;
|
|
463
|
-
proxies = new ProxyService();
|
|
464
|
-
environments = new EnvironmentService();
|
|
465
|
-
functions = new FunctionService();
|
|
466
|
-
functionCalls = new FunctionCallService();
|
|
467
|
-
cls = new ClsService();
|
|
468
|
-
queues = new QueueService();
|
|
469
|
-
#closed = false;
|
|
470
|
-
constructor(options = {}) {
|
|
471
|
-
if (options.endpoint !== undefined ||
|
|
472
|
-
options.oauthRefreshToken !== undefined ||
|
|
473
|
-
options.oauthClientId !== undefined ||
|
|
474
|
-
options.oauthClientSecret !== undefined ||
|
|
475
|
-
options.oauthJwtKey !== undefined ||
|
|
476
|
-
options.maxThrottleWaitSecs !== undefined ||
|
|
477
|
-
options.logger !== undefined ||
|
|
478
|
-
options.logLevel !== undefined ||
|
|
479
|
-
options.grpcMiddleware !== undefined ||
|
|
480
|
-
options.cpClient !== undefined)
|
|
481
|
-
throw new CompatibilityError("Modal", "Modal endpoints, OAuth, gRPC and logger options; set RUNTIME_API_KEY or pass apiKey");
|
|
482
|
-
only("Modal client", options, [
|
|
483
|
-
"apiKey",
|
|
484
|
-
"baseUrl",
|
|
485
|
-
"fetch",
|
|
486
|
-
"client",
|
|
487
|
-
"timeoutMs",
|
|
488
|
-
"maxRetries",
|
|
489
|
-
"tokenId",
|
|
490
|
-
"tokenSecret",
|
|
491
|
-
"environment",
|
|
492
|
-
]);
|
|
493
|
-
if (options.environment)
|
|
494
|
-
throw new CompatibilityError("Modal", "named Modal environments");
|
|
495
|
-
this.runtime = client(options);
|
|
496
|
-
this.apps = new AppService(this);
|
|
497
|
-
this.images = new ImageService(this);
|
|
498
|
-
this.sandboxes = new SandboxService(this.runtime, this);
|
|
499
|
-
this.secrets = new SecretService(this);
|
|
500
|
-
this.volumes = new VolumeService(this);
|
|
501
|
-
this.sandboxSnapshots = new SandboxSnapshotService(this);
|
|
502
|
-
}
|
|
503
|
-
/** Throws once close() was called, as Modal's client does. */
|
|
504
|
-
open() {
|
|
505
|
-
if (this.#closed)
|
|
506
|
-
throw new ClientClosedError("The Modal client was closed");
|
|
507
|
-
}
|
|
508
|
-
environmentName(environment) {
|
|
509
|
-
if (environment)
|
|
510
|
-
throw new CompatibilityError("Modal", "named Modal environments");
|
|
511
|
-
return "";
|
|
512
|
-
}
|
|
513
|
-
/** The Modal SDK version whose interface this adapter implements. */
|
|
514
|
-
version() {
|
|
515
|
-
return "0.11.1";
|
|
516
|
-
}
|
|
517
|
-
close() {
|
|
518
|
-
// The transport owns no background connection; later calls fail as Modal's do.
|
|
519
|
-
this.#closed = true;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
const NO_MODAL_SERVER = "Runtime has no Modal control plane; use the native client at modal.runtime";
|
|
523
|
-
refuse("Modal", "ModalClient", ModalClient, {
|
|
524
|
-
cpClient: NO_MODAL_SERVER,
|
|
525
|
-
ipClient: NO_MODAL_SERVER,
|
|
526
|
-
profile: NO_MODAL_SERVER,
|
|
527
|
-
logger: NO_MODAL_SERVER,
|
|
528
|
-
}, { sync: true });
|
|
529
|
-
refuse("Modal", "ModalClient", ModalClient, {
|
|
530
|
-
getImageBuilderVersion: "Runtime images record theirs: (await runtime.images.get(id)).build.builderVersion",
|
|
531
|
-
});
|
|
532
|
-
// Sandboxes ---------------------------------------------------------------------
|
|
533
|
-
/** Who a sandbox's processes run as: root, as in a Modal container (and a
|
|
534
|
-
* registry image's default user), where Runtime's own default is uid 1000.
|
|
535
|
-
* Modal code writes to /, installs packages and starts daemons unprefixed. */
|
|
536
|
-
const ROOT = "root";
|
|
537
|
-
/** Modal's outbound allowlists as Runtime network rules. Modal allows a
|
|
538
|
-
* connection a listed domain or a listed CIDR range admits, and a list left
|
|
539
|
-
* out admits nothing once the other is given (modal-client
|
|
540
|
-
* buildOutboundNetworkAccess; its guide: "except traffic allowed by
|
|
541
|
-
* outbound_domain_allowlist"). Runtime's `allow` is the same union, one list
|
|
542
|
-
* a connection matches any entry of. Modal's `*.example.com` also matches
|
|
543
|
-
* example.com, where Runtime's leaves the apex out, so both are listed.
|
|
544
|
-
* Every domain ("*") with narrower addresses is refused: Runtime cannot
|
|
545
|
-
* admit every name without every address. Before 18 October 2026 an empty
|
|
546
|
-
* CIDR list blocked the listed domains too, and two narrowing lists were
|
|
547
|
-
* refused (Modal's sandbox-network-policy.ts gives both). */
|
|
548
|
-
function egress(domains, cidrs) {
|
|
549
|
-
if (domains === undefined && cidrs === undefined)
|
|
550
|
-
return { internet: true };
|
|
551
|
-
// Every address is both families' whole range. One of them alone stays an
|
|
552
|
-
// ordinary rule: ::/0 by itself opened IPv4 as well, wider than Modal.
|
|
553
|
-
const whole = [...new Set(cidrs ?? [])].filter((c) => c === "0.0.0.0/0" || c === "::/0");
|
|
554
|
-
if (whole.length === 2)
|
|
555
|
-
return { internet: true };
|
|
556
|
-
if ((domains ?? []).includes("*")) {
|
|
557
|
-
// Every name beside one family's whole range: Runtime has no rule for
|
|
558
|
-
// every name, so the range alone (Modal's own examples pass "*" with
|
|
559
|
-
// 0.0.0.0/0). Narrower than Modal's by the other family, never wider.
|
|
560
|
-
if (whole.length)
|
|
561
|
-
return { internet: true, allow: whole };
|
|
562
|
-
throw new CompatibilityError("Modal", 'a domain allowlist of "*" with a narrower CIDR allowlist; pass ["0.0.0.0/0", "::/0"] with it for all traffic, or list the domains');
|
|
563
|
-
}
|
|
564
|
-
const allow = [
|
|
565
|
-
...new Set([
|
|
566
|
-
...(domains ?? []).flatMap((d) => (d.startsWith("*.") ? [d, d.slice(2)] : [d])),
|
|
567
|
-
...(cidrs ?? []),
|
|
568
|
-
]),
|
|
569
|
-
];
|
|
570
|
-
return allow.length ? { internet: true, allow } : { internet: false };
|
|
571
|
-
}
|
|
572
|
-
const ENVIRONMENTS = "named Modal environments";
|
|
573
|
-
const CREATE_OPTIONS = [
|
|
574
|
-
"name",
|
|
575
|
-
"cpu",
|
|
576
|
-
"cpuLimit",
|
|
577
|
-
"memoryMiB",
|
|
578
|
-
"memoryLimitMiB",
|
|
579
|
-
"runtime",
|
|
580
|
-
"timeoutMs",
|
|
581
|
-
"idleTimeoutMs",
|
|
582
|
-
"workdir",
|
|
583
|
-
"command",
|
|
584
|
-
"env",
|
|
585
|
-
"encryptedPorts",
|
|
586
|
-
"blockNetwork",
|
|
587
|
-
"outboundDomainAllowlist",
|
|
588
|
-
"outboundCidrAllowlist",
|
|
589
|
-
"tags",
|
|
590
|
-
"regions",
|
|
591
|
-
"gpu",
|
|
592
|
-
"pty",
|
|
593
|
-
"secrets",
|
|
594
|
-
"volumes",
|
|
595
|
-
"cloudBucketMounts",
|
|
596
|
-
"readinessProbe",
|
|
597
|
-
"experimentalEnableSnapshot",
|
|
598
|
-
"experimentalOptions",
|
|
599
|
-
];
|
|
600
|
-
export class SandboxService {
|
|
601
|
-
runtime;
|
|
602
|
-
client;
|
|
603
|
-
constructor(runtime, client) {
|
|
604
|
-
this.runtime = runtime;
|
|
605
|
-
this.client = client;
|
|
606
|
-
}
|
|
607
|
-
async create(app, image, params = {}) {
|
|
608
|
-
this.client?.open();
|
|
609
|
-
only("Modal sandbox", params, CREATE_OPTIONS);
|
|
610
|
-
if (params.gpu)
|
|
611
|
-
throw new CompatibilityError("Modal", "GPU allocation");
|
|
612
|
-
if (params.runtime === "gvisor")
|
|
613
|
-
throw new CompatibilityError("Modal", 'gVisor; Runtime sandboxes are Firecracker VMs (runtime: "vm")');
|
|
614
|
-
if (params.cpuLimit !== undefined && params.cpuLimit !== params.cpu)
|
|
615
|
-
throw new CompatibilityError("Modal", "separate CPU reservation and hard limit");
|
|
616
|
-
if (params.memoryLimitMiB !== undefined && params.memoryLimitMiB !== params.memoryMiB)
|
|
617
|
-
throw new CompatibilityError("Modal", "separate memory reservation and hard limit");
|
|
618
|
-
if (params.regions && params.regions.length !== 1)
|
|
619
|
-
throw new CompatibilityError("Modal", "multiple region placement");
|
|
620
|
-
if (params.cpu !== undefined && !Number.isInteger(params.cpu))
|
|
621
|
-
throw new CompatibilityError("Modal", "fractional CPU reservations");
|
|
622
|
-
if (image.snapshot && (params.cpu !== undefined || params.memoryMiB !== undefined))
|
|
623
|
-
throw new CompatibilityError("Modal", "cpu or memoryMiB with a snapshot image; it keeps the snapshot's shape, resize it after");
|
|
624
|
-
if (params.blockNetwork && (params.outboundDomainAllowlist || params.outboundCidrAllowlist))
|
|
625
|
-
throw new TypeError("blockNetwork cannot be combined with allowlists");
|
|
626
|
-
if (params.runtime !== undefined && params.runtime !== "vm")
|
|
627
|
-
throw new InvalidError(`Unknown sandbox runtime ${String(params.runtime)}`);
|
|
628
|
-
for (const [option, value] of Object.entries(params.experimentalOptions ?? {}))
|
|
629
|
-
throw option === "enable_exit_snapshot" && value
|
|
630
|
-
? refusal("Modal", "experimentalOptions.enable_exit_snapshot", "call sandbox.snapshotFilesystem() before terminate(), then start new sandboxes from that Image")
|
|
631
|
-
: new CompatibilityError("Modal", `experimental option ${option}`);
|
|
632
|
-
if (params.timeoutMs !== undefined && !(params.timeoutMs > 0))
|
|
633
|
-
throw new InvalidError(`timeoutMs must be positive, got ${params.timeoutMs}`);
|
|
634
|
-
if (params.idleTimeoutMs !== undefined &&
|
|
635
|
-
(!(params.idleTimeoutMs > 0) || params.idleTimeoutMs % 1000 !== 0))
|
|
636
|
-
throw new InvalidError(`idleTimeoutMs must be a positive multiple of 1000ms, got ${params.idleTimeoutMs}`);
|
|
637
|
-
const network = params.blockNetwork
|
|
638
|
-
? { internet: false }
|
|
639
|
-
: egress(params.outboundDomainAllowlist, params.outboundCidrAllowlist);
|
|
640
|
-
const placement = region("Modal", params.regions?.[0]);
|
|
641
|
-
const built = await image.build(app);
|
|
642
|
-
const volumes = Object.entries(params.volumes ?? {}).map(([path, v]) => {
|
|
643
|
-
if (!(v instanceof Volume))
|
|
644
|
-
throw new InvalidError(`volumes[${path}] must be a Volume`);
|
|
645
|
-
return {
|
|
646
|
-
volumeId: v.volumeId,
|
|
647
|
-
path,
|
|
648
|
-
mode: v.readOnly ? "snapshot" : "rw",
|
|
649
|
-
};
|
|
650
|
-
});
|
|
651
|
-
const mounts = Object.entries(params.cloudBucketMounts ?? {}).map(([path, m]) => {
|
|
652
|
-
if (!(m instanceof CloudBucketMount))
|
|
653
|
-
throw new InvalidError(`cloudBucketMounts[${path}] must be a CloudBucketMount`);
|
|
654
|
-
return m.native(path);
|
|
655
|
-
});
|
|
656
|
-
let primary;
|
|
657
|
-
const input = {
|
|
658
|
-
name: params.name ? `${app.name ?? app.appId}-${params.name}` : undefined,
|
|
659
|
-
labels: {
|
|
660
|
-
"modal.app": app.name ?? app.appId,
|
|
661
|
-
...(params.name ? { "modal.name": params.name } : {}),
|
|
662
|
-
"modal.tags": JSON.stringify(params.tags ?? {}),
|
|
663
|
-
...(params.readinessProbe
|
|
664
|
-
? { "modal.probe": JSON.stringify(params.readinessProbe.spec) }
|
|
665
|
-
: {}),
|
|
666
|
-
...(volumes.some((v) => v.mode === "snapshot") ? { "modal.readonly": "1" } : {}),
|
|
667
|
-
},
|
|
668
|
-
...(image.snapshot ? { snapshot: built.imageId } : { image: built.imageId }),
|
|
669
|
-
...(image.snapshot
|
|
670
|
-
? {}
|
|
671
|
-
: { cpu: "reserved", vcpu: params.cpu, memoryMiB: params.memoryMiB }),
|
|
672
|
-
region: placement,
|
|
673
|
-
...(volumes.length ? { volumes } : {}),
|
|
674
|
-
// A timeout is the customer's limit, and the sandbox never pauses
|
|
675
|
-
// for idleness before it unless idleTimeoutMs asks. None is no time
|
|
676
|
-
// limit (0300): it runs while it works and pauses when idle. Runtime's
|
|
677
|
-
// shortest limit is a minute: a shorter one is kept by this client
|
|
678
|
-
// (below), with the minute as the bound if the client goes away.
|
|
679
|
-
...(params.timeoutMs === undefined
|
|
680
|
-
? {}
|
|
681
|
-
: {
|
|
682
|
-
timeoutSeconds: Math.max(60, Math.ceil(params.timeoutMs / 1000)),
|
|
683
|
-
idlePauseSeconds: 0,
|
|
684
|
-
}),
|
|
685
|
-
// Modal ends an idle sandbox; Runtime pauses it, memory kept and CPU
|
|
686
|
-
// no longer billed, and wakes it at the next command, file call or
|
|
687
|
-
// tunnel request. Runtime's shortest idle pause is ten seconds.
|
|
688
|
-
...(params.idleTimeoutMs === undefined
|
|
689
|
-
? {}
|
|
690
|
-
: { idlePauseSeconds: Math.max(10, params.idleTimeoutMs / 1000) }),
|
|
691
|
-
onLeaseEnd: "stop",
|
|
692
|
-
network,
|
|
693
|
-
};
|
|
694
|
-
const s = await modal(() => create(this.runtime, "modal", input, Object.assign({}, ...(params.secrets?.map((s) => s.values) ?? []), params.env ?? {}), async (s) => {
|
|
695
|
-
for (const mount of mounts)
|
|
696
|
-
await s.mounts.add(mount);
|
|
697
|
-
primary = await s.spawn(params.command ?? ["sleep", "infinity"], {
|
|
698
|
-
...(await execOptions(s, { cwd: params.workdir, user: ROOT })),
|
|
699
|
-
stdin: "pipe",
|
|
700
|
-
pty: params.pty ? {} : undefined,
|
|
701
|
-
});
|
|
702
|
-
await s.update({ labels: { ...s.info.labels, "modal.entrypoint": primary.id } });
|
|
703
|
-
for (const port of params.encryptedPorts ?? [])
|
|
704
|
-
await s.previews.create(port, { visibility: "public" });
|
|
705
|
-
}));
|
|
706
|
-
const sandbox = new Sandbox(s, new ContainerProcess(primary, "text"), this.client);
|
|
707
|
-
sandbox.monitorEntrypoint();
|
|
708
|
-
if (params.timeoutMs !== undefined && params.timeoutMs < 60_000)
|
|
709
|
-
sandbox.terminateAfter(params.timeoutMs);
|
|
710
|
-
return sandbox;
|
|
711
|
-
}
|
|
712
|
-
async experimentalCreate(app, image, params = {}) {
|
|
713
|
-
only("Modal sandbox", params, CREATE_OPTIONS);
|
|
714
|
-
return this.create(app, image, params);
|
|
715
|
-
}
|
|
716
|
-
async fromId(id) {
|
|
717
|
-
this.client?.open();
|
|
718
|
-
const s = await modal(() => this.runtime.sandboxes.get(id));
|
|
719
|
-
const p = s.info.labels["modal.entrypoint"];
|
|
720
|
-
if (!p)
|
|
721
|
-
throw new NotFoundError("Sandbox is not a Modal-compatible sandbox");
|
|
722
|
-
return new Sandbox(s, new ContainerProcess(await modal(() => s.processes.get(p)), "text"), this.client);
|
|
723
|
-
}
|
|
724
|
-
/** The running sandbox of that name; with includeTerminated, when none
|
|
725
|
-
* runs, the one that stopped last (modal 0.11.1). */
|
|
726
|
-
async fromName(appName, name, params = {}) {
|
|
727
|
-
this.client?.open();
|
|
728
|
-
only("Modal sandbox name", params, ["environment", "includeTerminated"]);
|
|
729
|
-
if (params.environment)
|
|
730
|
-
throw new CompatibilityError("Modal", ENVIRONMENTS);
|
|
731
|
-
const named = (await all(this.runtime, "modal")).filter((s) => s.info.labels["modal.app"] === appName && s.info.labels["modal.name"] === name);
|
|
732
|
-
const ended = (s) => s.info.endedAt ?? s.info.createdAt ?? "";
|
|
733
|
-
const s = named.find((s) => s.state === "running") ??
|
|
734
|
-
(params.includeTerminated
|
|
735
|
-
? named
|
|
736
|
-
.filter((s) => s.state === "stopped")
|
|
737
|
-
.sort((a, b) => ended(b).localeCompare(ended(a)))[0]
|
|
738
|
-
: undefined);
|
|
739
|
-
if (!s)
|
|
740
|
-
throw new NotFoundError(`Sandbox ${name} not found`);
|
|
741
|
-
return this.fromId(s.id);
|
|
742
|
-
}
|
|
743
|
-
experimentalFromName(appName, name, params = {}) {
|
|
744
|
-
return this.fromName(appName, name, params);
|
|
745
|
-
}
|
|
746
|
-
/** A new sandbox continuing a memory snapshot: its files, memory and
|
|
747
|
-
* running entrypoint, under the snapshot's app and tags. */
|
|
748
|
-
async experimentalFromSnapshot(snapshot, params = {}) {
|
|
749
|
-
this.client?.open();
|
|
750
|
-
only("Modal snapshot restore", params, ["name"]);
|
|
751
|
-
const saved = await modal(() => this.runtime.snapshots.get(snapshot.snapshotId));
|
|
752
|
-
const labels = (saved.labels ?? {});
|
|
753
|
-
const entrypoint = labels["modal.entrypoint"];
|
|
754
|
-
if (!entrypoint || saved.mode === "disk")
|
|
755
|
-
throw new InvalidError(`Snapshot ${snapshot.snapshotId} was not taken with sandbox.experimentalSnapshot()`);
|
|
756
|
-
const app = labels["modal.app"];
|
|
757
|
-
const s = await modal(() => create(this.runtime, "modal", {
|
|
758
|
-
snapshot: saved.id,
|
|
759
|
-
...(params.name ? { name: `${app}-${params.name}` } : {}),
|
|
760
|
-
labels: {
|
|
761
|
-
...Object.fromEntries(Object.entries(labels).filter(([k]) => k.startsWith("modal."))),
|
|
762
|
-
...(params.name ? { "modal.name": params.name } : {}),
|
|
763
|
-
},
|
|
764
|
-
onLeaseEnd: "stop",
|
|
765
|
-
}));
|
|
766
|
-
let process;
|
|
767
|
-
try {
|
|
768
|
-
process = await s.processes.get(entrypoint);
|
|
769
|
-
}
|
|
770
|
-
catch (error) {
|
|
771
|
-
await destroy(s);
|
|
772
|
-
throw modalError(error);
|
|
773
|
-
}
|
|
774
|
-
const sandbox = new Sandbox(s, new ContainerProcess(process, "text"), this.client);
|
|
775
|
-
sandbox.monitorEntrypoint();
|
|
776
|
-
return sandbox;
|
|
777
|
-
}
|
|
778
|
-
async *list(params = {}) {
|
|
779
|
-
this.client?.open();
|
|
780
|
-
only("Modal list", params, ["appId", "tags", "environment"]);
|
|
781
|
-
if (params.environment)
|
|
782
|
-
throw new CompatibilityError("Modal", ENVIRONMENTS);
|
|
783
|
-
for (const s of await all(this.runtime, "modal"))
|
|
784
|
-
if (s.state === "running" &&
|
|
785
|
-
(!params.appId || s.info.labels["modal.app"] === params.appId) &&
|
|
786
|
-
Object.entries(params.tags ?? {}).every(([k, v]) => JSON.parse(s.info.labels["modal.tags"] ?? "{}")[k] === v))
|
|
787
|
-
yield await this.fromId(s.id);
|
|
788
|
-
}
|
|
789
|
-
experimentalList(params = {}) {
|
|
790
|
-
return this.list(params);
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
export class ModalReadStream extends ReadableStream {
|
|
794
|
-
constructor(process, channel, mode, ignore = false) {
|
|
795
|
-
const iterator = mode === "binary" ? process.outputBytes() : process.output();
|
|
796
|
-
super({
|
|
797
|
-
async pull(controller) {
|
|
798
|
-
if (ignore) {
|
|
799
|
-
controller.close();
|
|
800
|
-
return;
|
|
801
|
-
}
|
|
802
|
-
try {
|
|
803
|
-
while (true) {
|
|
804
|
-
const next = await iterator.next();
|
|
805
|
-
if (next.done) {
|
|
806
|
-
controller.close();
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
if (next.value.type === "truncated")
|
|
810
|
-
throw new Error("Process output was truncated");
|
|
811
|
-
if (next.value.type === channel) {
|
|
812
|
-
controller.enqueue(next.value.data);
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
catch (error) {
|
|
818
|
-
controller.error(error);
|
|
819
|
-
}
|
|
820
|
-
},
|
|
821
|
-
async cancel() {
|
|
822
|
-
await iterator.return(undefined);
|
|
823
|
-
},
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
async readBytes() {
|
|
827
|
-
const reader = this.getReader();
|
|
828
|
-
const chunks = [];
|
|
829
|
-
let size = 0;
|
|
830
|
-
try {
|
|
831
|
-
while (true) {
|
|
832
|
-
const next = await reader.read();
|
|
833
|
-
if (next.done)
|
|
834
|
-
break;
|
|
835
|
-
const bytes = typeof next.value === "string" ? new TextEncoder().encode(next.value) : next.value;
|
|
836
|
-
chunks.push(bytes);
|
|
837
|
-
size += bytes.length;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
finally {
|
|
841
|
-
reader.releaseLock();
|
|
842
|
-
}
|
|
843
|
-
const output = new Uint8Array(size);
|
|
844
|
-
let offset = 0;
|
|
845
|
-
for (const chunk of chunks) {
|
|
846
|
-
output.set(chunk, offset);
|
|
847
|
-
offset += chunk.length;
|
|
848
|
-
}
|
|
849
|
-
return output;
|
|
850
|
-
}
|
|
851
|
-
async readText() {
|
|
852
|
-
return new TextDecoder().decode(await this.readBytes());
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
export class ModalWriteStream extends WritableStream {
|
|
856
|
-
process;
|
|
857
|
-
constructor(process) {
|
|
858
|
-
super({ write: (data) => process.write(data), close: () => process.write("", { eof: true }) });
|
|
859
|
-
this.process = process;
|
|
860
|
-
}
|
|
861
|
-
async writeText(text) {
|
|
862
|
-
const writer = this.getWriter();
|
|
863
|
-
try {
|
|
864
|
-
await writer.write(text);
|
|
865
|
-
}
|
|
866
|
-
finally {
|
|
867
|
-
writer.releaseLock();
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
async writeBytes(bytes) {
|
|
871
|
-
const writer = this.getWriter();
|
|
872
|
-
try {
|
|
873
|
-
await writer.write(bytes);
|
|
874
|
-
}
|
|
875
|
-
finally {
|
|
876
|
-
writer.releaseLock();
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
export class ContainerProcess {
|
|
881
|
-
native;
|
|
882
|
-
stdin;
|
|
883
|
-
stdout;
|
|
884
|
-
stderr;
|
|
885
|
-
constructor(native, mode, params = {}) {
|
|
886
|
-
this.native = native;
|
|
887
|
-
this.stdin = new ModalWriteStream(native);
|
|
888
|
-
this.stdout = new ModalReadStream(native, "stdout", mode, params.stdout === "ignore");
|
|
889
|
-
this.stderr = new ModalReadStream(native, "stderr", mode, params.stderr === "ignore");
|
|
890
|
-
}
|
|
891
|
-
/** The exit code, once seen: a poll after the sandbox ended still has it. */
|
|
892
|
-
#exitCode;
|
|
893
|
-
async wait() {
|
|
894
|
-
const r = await this.native.wait();
|
|
895
|
-
if (r.timedOut)
|
|
896
|
-
throw new SandboxTimeoutError("Process timed out");
|
|
897
|
-
this.#exitCode = r.exitCode ?? -1;
|
|
898
|
-
return this.#exitCode;
|
|
899
|
-
}
|
|
900
|
-
closeStdin() {
|
|
901
|
-
return this.native.write("", { eof: true });
|
|
902
|
-
}
|
|
903
|
-
/** null while it runs, then its exit code. A process whose sandbox ended
|
|
904
|
-
* before its exit was seen was killed with it: 137, as Modal reports. */
|
|
905
|
-
async _poll() {
|
|
906
|
-
if (this.#exitCode !== undefined)
|
|
907
|
-
return this.#exitCode;
|
|
908
|
-
try {
|
|
909
|
-
const p = await this.native.refresh();
|
|
910
|
-
if (p.state === "running")
|
|
911
|
-
return null;
|
|
912
|
-
return (this.#exitCode = p.exitCode ?? -1);
|
|
913
|
-
}
|
|
914
|
-
catch (error) {
|
|
915
|
-
if (error instanceof RuntimeError &&
|
|
916
|
-
(error.code === "sandbox_stopped" || error.status === 404))
|
|
917
|
-
return (this.#exitCode = 137);
|
|
918
|
-
throw error;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
/** Host and port of a sandbox port's public HTTPS address. Runtime previews
|
|
923
|
-
* are HTTPS only, so there is no unencrypted address. */
|
|
924
|
-
export class Tunnel {
|
|
925
|
-
host;
|
|
926
|
-
port;
|
|
927
|
-
unencryptedHost;
|
|
928
|
-
unencryptedPort;
|
|
929
|
-
constructor(host, port, unencryptedHost, unencryptedPort) {
|
|
930
|
-
this.host = host;
|
|
931
|
-
this.port = port;
|
|
932
|
-
this.unencryptedHost = unencryptedHost;
|
|
933
|
-
this.unencryptedPort = unencryptedPort;
|
|
934
|
-
}
|
|
935
|
-
get url() {
|
|
936
|
-
return this.port === 443 ? `https://${this.host}` : `https://${this.host}:${this.port}`;
|
|
937
|
-
}
|
|
938
|
-
get tlsSocket() {
|
|
939
|
-
return [this.host, this.port];
|
|
940
|
-
}
|
|
941
|
-
get tcpSocket() {
|
|
942
|
-
if (!this.unencryptedHost || this.unencryptedPort === undefined)
|
|
943
|
-
throw new InvalidError("This tunnel is not configured for unencrypted TCP.");
|
|
944
|
-
return [this.unencryptedHost, this.unencryptedPort];
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
const NEW_SANDBOX_FROM_SNAPSHOT = "take sandbox.snapshotFilesystem() and start a new sandbox from that image";
|
|
948
|
-
export class SandboxLogsManager {
|
|
949
|
-
}
|
|
950
|
-
refuse("Modal", "SandboxLogsManager", SandboxLogsManager, {
|
|
951
|
-
fetch: "read sandbox.stdout and sandbox.stderr",
|
|
952
|
-
tail: "read sandbox.stdout and sandbox.stderr",
|
|
953
|
-
}, { sync: true });
|
|
954
|
-
const SECOND_SANDBOX = "start a second Runtime sandbox and join both to a private network";
|
|
955
|
-
export class SidecarService {
|
|
956
|
-
}
|
|
957
|
-
refuse("Modal", "SidecarService", SidecarService, { create: SECOND_SANDBOX, get: SECOND_SANDBOX });
|
|
958
|
-
refuse("Modal", "SidecarService", SidecarService, { list: SECOND_SANDBOX }, { sync: true });
|
|
959
|
-
export class SidecarContainer {
|
|
960
|
-
}
|
|
961
|
-
refuse("Modal", "SidecarContainer", SidecarContainer, { containerId: SECOND_SANDBOX, containerName: SECOND_SANDBOX, filesystem: SECOND_SANDBOX }, { sync: true });
|
|
962
|
-
refuse("Modal", "SidecarContainer", SidecarContainer, Object.fromEntries([
|
|
963
|
-
"exec",
|
|
964
|
-
"mountImage",
|
|
965
|
-
"poll",
|
|
966
|
-
"reloadVolumes",
|
|
967
|
-
"snapshotDirectory",
|
|
968
|
-
"snapshotFilesystem",
|
|
969
|
-
"terminate",
|
|
970
|
-
"unmountImage",
|
|
971
|
-
"wait",
|
|
972
|
-
].map((m) => [m, SECOND_SANDBOX])));
|
|
973
|
-
export class Sandbox {
|
|
974
|
-
native;
|
|
975
|
-
primary;
|
|
976
|
-
client;
|
|
977
|
-
filesystem;
|
|
978
|
-
stdin;
|
|
979
|
-
stdout;
|
|
980
|
-
stderr;
|
|
981
|
-
logs = new SandboxLogsManager();
|
|
982
|
-
experimentalSidecars = new SidecarService();
|
|
983
|
-
detached = false;
|
|
984
|
-
lifecycle;
|
|
985
|
-
monitorEntrypoint() {
|
|
986
|
-
this.lifecycle = this.primary.wait().then(async (code) => {
|
|
987
|
-
await destroy(this.native);
|
|
988
|
-
return code;
|
|
989
|
-
});
|
|
990
|
-
this.lifecycle.catch(() => undefined);
|
|
991
|
-
}
|
|
992
|
-
constructor(native, primary, client) {
|
|
993
|
-
this.native = native;
|
|
994
|
-
this.primary = primary;
|
|
995
|
-
this.client = client;
|
|
996
|
-
this.filesystem = new SandboxFilesystem(native);
|
|
997
|
-
this.stdin = primary.stdin;
|
|
998
|
-
this.stdout = primary.stdout;
|
|
999
|
-
this.stderr = primary.stderr;
|
|
1000
|
-
}
|
|
1001
|
-
get sandboxId() {
|
|
1002
|
-
return this.native.id;
|
|
1003
|
-
}
|
|
1004
|
-
/** Ends the sandbox after `ms`, for a Modal timeout under Runtime's
|
|
1005
|
-
* shortest time limit (a minute, which stays the bound if this client
|
|
1006
|
-
* goes away). The timer never keeps the program running. */
|
|
1007
|
-
terminateAfter(ms) {
|
|
1008
|
-
const timer = setTimeout(() => void this.terminate().catch(() => undefined), ms);
|
|
1009
|
-
timer.unref?.();
|
|
1010
|
-
}
|
|
1011
|
-
attached() {
|
|
1012
|
-
this.client?.open();
|
|
1013
|
-
if (this.detached)
|
|
1014
|
-
throw new ClientClosedError("Sandbox is detached");
|
|
1015
|
-
}
|
|
1016
|
-
async exec(command, params = {}) {
|
|
1017
|
-
this.attached();
|
|
1018
|
-
only("Modal exec", params, [
|
|
1019
|
-
"mode",
|
|
1020
|
-
"stdout",
|
|
1021
|
-
"stderr",
|
|
1022
|
-
"workdir",
|
|
1023
|
-
"timeoutMs",
|
|
1024
|
-
"env",
|
|
1025
|
-
"pty",
|
|
1026
|
-
"secrets",
|
|
1027
|
-
]);
|
|
1028
|
-
const p = await this.native.spawn(command, {
|
|
1029
|
-
...(await execOptions(this.native, {
|
|
1030
|
-
user: ROOT,
|
|
1031
|
-
cwd: params.workdir,
|
|
1032
|
-
timeoutMs: params.timeoutMs === 0 ? 86_400_000 : params.timeoutMs,
|
|
1033
|
-
env: Object.assign({}, ...(params.secrets?.map((s) => s.values) ?? []), params.env ?? {}),
|
|
1034
|
-
})),
|
|
1035
|
-
stdin: "pipe",
|
|
1036
|
-
...(params.mode === "binary" ? { outputEncoding: "base64" } : {}),
|
|
1037
|
-
pty: params.pty ? {} : undefined,
|
|
1038
|
-
});
|
|
1039
|
-
return new ContainerProcess(p, params.mode ?? "text", params);
|
|
1040
|
-
}
|
|
1041
|
-
async setTags(tags) {
|
|
1042
|
-
this.attached();
|
|
1043
|
-
await this.native.update({
|
|
1044
|
-
labels: {
|
|
1045
|
-
...Object.fromEntries(Object.entries(this.native.info.labels).filter(([k]) => k.startsWith("modal.") || k === "compat.provider")),
|
|
1046
|
-
"modal.tags": JSON.stringify(tags),
|
|
1047
|
-
},
|
|
1048
|
-
});
|
|
1049
|
-
}
|
|
1050
|
-
async getTags() {
|
|
1051
|
-
this.attached();
|
|
1052
|
-
await this.native.refresh();
|
|
1053
|
-
return JSON.parse(this.native.info.labels["modal.tags"] ?? "{}");
|
|
1054
|
-
}
|
|
1055
|
-
/** Names the sandbox so sandboxes.fromName(app, name) finds it. */
|
|
1056
|
-
async experimentalSetName(name) {
|
|
1057
|
-
this.attached();
|
|
1058
|
-
if (!name)
|
|
1059
|
-
throw new InvalidError("Sandbox name must not be empty");
|
|
1060
|
-
const app = this.native.info.labels["modal.app"];
|
|
1061
|
-
await modal(() => this.native.update({
|
|
1062
|
-
name: `${app}-${name}`,
|
|
1063
|
-
labels: { ...this.native.info.labels, "modal.name": name },
|
|
1064
|
-
}));
|
|
1065
|
-
}
|
|
1066
|
-
async terminate(params = {}) {
|
|
1067
|
-
await destroy(this.native);
|
|
1068
|
-
return params.wait ? this.primary.wait() : undefined;
|
|
1069
|
-
}
|
|
1070
|
-
detach() {
|
|
1071
|
-
this.detached = true;
|
|
1072
|
-
}
|
|
1073
|
-
async wait() {
|
|
1074
|
-
if (this.lifecycle)
|
|
1075
|
-
return this.lifecycle;
|
|
1076
|
-
const code = await this.primary.wait();
|
|
1077
|
-
await destroy(this.native);
|
|
1078
|
-
return code;
|
|
1079
|
-
}
|
|
1080
|
-
poll() {
|
|
1081
|
-
return this.primary._poll();
|
|
1082
|
-
}
|
|
1083
|
-
/** Runs the sandbox's readinessProbe until it passes. */
|
|
1084
|
-
async waitUntilReady(timeoutMs = 300_000) {
|
|
1085
|
-
this.attached();
|
|
1086
|
-
if (timeoutMs <= 0)
|
|
1087
|
-
throw new InvalidError(`timeoutMs must be positive, got ${timeoutMs}`);
|
|
1088
|
-
const raw = this.native.info.labels["modal.probe"];
|
|
1089
|
-
if (!raw)
|
|
1090
|
-
throw new InvalidError("Sandbox has no readinessProbe");
|
|
1091
|
-
const probe = JSON.parse(raw);
|
|
1092
|
-
const argv = probe.execArgv ?? ["bash", "-c", `exec 3<>/dev/tcp/127.0.0.1/${probe.tcpPort}`];
|
|
1093
|
-
const until = performance.now() + timeoutMs;
|
|
1094
|
-
while (true) {
|
|
1095
|
-
const left = Math.ceil(until - performance.now());
|
|
1096
|
-
if (left <= 0)
|
|
1097
|
-
throw new TimeoutError("Timeout expired");
|
|
1098
|
-
const result = await this.native.exec(argv, { timeoutMs: left, user: ROOT });
|
|
1099
|
-
if (result.exitCode === 0)
|
|
1100
|
-
return;
|
|
1101
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(probe.intervalMs, left)));
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
async tunnels(timeoutMs = 50_000) {
|
|
1105
|
-
this.attached();
|
|
1106
|
-
const tunnels = {};
|
|
1107
|
-
for (const p of await this.native.previews.list({ timeoutMs }))
|
|
1108
|
-
tunnels[p.port] = new Tunnel(new URL(p.url).hostname, 443);
|
|
1109
|
-
return tunnels;
|
|
1110
|
-
}
|
|
1111
|
-
async updateNetworkPolicy(params) {
|
|
1112
|
-
this.attached();
|
|
1113
|
-
only("Modal network policy", params, ["outboundCidrAllowlist", "outboundDomainAllowlist"]);
|
|
1114
|
-
if (!params.outboundCidrAllowlist || !params.outboundDomainAllowlist)
|
|
1115
|
-
throw new InvalidError("Both outboundCidrAllowlist and outboundDomainAllowlist must be provided");
|
|
1116
|
-
await this.native.network.set(egress(params.outboundDomainAllowlist, params.outboundCidrAllowlist));
|
|
1117
|
-
}
|
|
1118
|
-
/** Runtime volumes are block devices with one writer: a read-write mount
|
|
1119
|
-
* always shows the latest writes. A read-only mount is a copy taken at
|
|
1120
|
-
* start, which cannot reload. */
|
|
1121
|
-
async reloadVolumes(params = {}) {
|
|
1122
|
-
this.attached();
|
|
1123
|
-
only("Modal reload volumes", params, ["timeoutMs"]);
|
|
1124
|
-
if (this.native.info.labels["modal.readonly"])
|
|
1125
|
-
throw new CompatibilityError("Modal", "reloading a read-only volume; it is a copy taken at start");
|
|
1126
|
-
}
|
|
1127
|
-
/** The whole sandbox, memory and running processes included. */
|
|
1128
|
-
async experimentalSnapshot() {
|
|
1129
|
-
this.attached();
|
|
1130
|
-
const snapshot = await modal(() => this.native.snapshot({
|
|
1131
|
-
labels: Object.fromEntries(Object.entries(this.native.info.labels).filter(([k]) => k.startsWith("modal."))),
|
|
1132
|
-
})).catch((error) => {
|
|
1133
|
-
throw error instanceof Error && !(error instanceof NotFoundError)
|
|
1134
|
-
? new SnapshotCreationError(error.message)
|
|
1135
|
-
: error;
|
|
1136
|
-
});
|
|
1137
|
-
return new SandboxSnapshot(snapshot.id);
|
|
1138
|
-
}
|
|
1139
|
-
/** The sandbox's files as an Image new sandboxes start from. `ttlMs` is
|
|
1140
|
-
* kept in whole days. */
|
|
1141
|
-
async snapshotFilesystem(params = {}) {
|
|
1142
|
-
this.attached();
|
|
1143
|
-
only("Modal filesystem snapshot", params, ["timeoutMs", "ttlMs"]);
|
|
1144
|
-
const day = 86_400_000;
|
|
1145
|
-
if (params.ttlMs === null ||
|
|
1146
|
-
(params.ttlMs !== undefined && (!Number.isInteger(params.ttlMs / day) || params.ttlMs <= 0)))
|
|
1147
|
-
throw new CompatibilityError("Modal", "ttlMs that is null or not whole days; Runtime keeps snapshots for a number of days");
|
|
1148
|
-
const snapshot = await this.native
|
|
1149
|
-
.snapshot({
|
|
1150
|
-
mode: "disk",
|
|
1151
|
-
...(params.ttlMs === undefined ? {} : { retentionDays: params.ttlMs / day }),
|
|
1152
|
-
...(params.timeoutMs === undefined ? {} : { timeoutMs: params.timeoutMs }),
|
|
1153
|
-
})
|
|
1154
|
-
.catch((error) => {
|
|
1155
|
-
throw error instanceof RuntimeError && error.code === "timeout"
|
|
1156
|
-
? new TimeoutError(error.message)
|
|
1157
|
-
: new SnapshotCreationError(error instanceof Error ? error.message : String(error));
|
|
1158
|
-
});
|
|
1159
|
-
return new Image(undefined, undefined, snapshot.id, [], {}, true, true);
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
refuse("Modal", "Sandbox", Sandbox, {
|
|
1163
|
-
createConnectToken: "a private preview: sandbox.native.previews.create(port), sending its token as x-runtime-preview-token",
|
|
1164
|
-
experimentalGetExitSnapshot: NEW_SANDBOX_FROM_SNAPSHOT,
|
|
1165
|
-
snapshotDirectory: NEW_SANDBOX_FROM_SNAPSHOT,
|
|
1166
|
-
mountImage: NEW_SANDBOX_FROM_SNAPSHOT,
|
|
1167
|
-
unmountImage: NEW_SANDBOX_FROM_SNAPSHOT,
|
|
1168
|
-
experimentalUpdateOutboundPolicy: "updateNetworkPolicy for allowlists; runtime.secrets.set({ value, hosts, header }) for header replacement",
|
|
1169
|
-
});
|
|
1170
|
-
const WATCHED = {
|
|
1171
|
-
Access: ["access"],
|
|
1172
|
-
Create: ["create"],
|
|
1173
|
-
Modify: ["write", "chmod", "rename"],
|
|
1174
|
-
Remove: ["remove"],
|
|
1175
|
-
};
|
|
1176
|
-
export class SandboxFilesystem {
|
|
1177
|
-
native;
|
|
1178
|
-
files;
|
|
1179
|
-
constructor(native) {
|
|
1180
|
-
this.native = native;
|
|
1181
|
-
this.files = new GuestFiles(async () => native, "/");
|
|
1182
|
-
}
|
|
1183
|
-
readBytes(path) {
|
|
1184
|
-
return fileCall(path, () => this.files.readFile(path));
|
|
1185
|
-
}
|
|
1186
|
-
readText(path) {
|
|
1187
|
-
return fileCall(path, () => this.files.readTextFile(path));
|
|
1188
|
-
}
|
|
1189
|
-
writeBytes(content, path) {
|
|
1190
|
-
return fileCall(path, () => this.files.writeFile(path, content instanceof Uint8Array ? content : new Uint8Array(content)));
|
|
1191
|
-
}
|
|
1192
|
-
writeText(content, path) {
|
|
1193
|
-
return fileCall(path, () => this.files.writeTextFile(path, content));
|
|
1194
|
-
}
|
|
1195
|
-
makeDirectory(path, options = {}) {
|
|
1196
|
-
return fileCall(path, () => this.files.mkdir(path, options.createParents ?? true));
|
|
1197
|
-
}
|
|
1198
|
-
remove(path, options = {}) {
|
|
1199
|
-
return fileCall(path, () => this.files.remove(path, options.recursive));
|
|
1200
|
-
}
|
|
1201
|
-
copyFromLocal(localPath, remotePath) {
|
|
1202
|
-
return fileCall(remotePath, () => this.native.files.upload(localPath, remotePath));
|
|
1203
|
-
}
|
|
1204
|
-
copyToLocal(remotePath, localPath) {
|
|
1205
|
-
return fileCall(remotePath, () => this.native.files.download(remotePath, localPath));
|
|
1206
|
-
}
|
|
1207
|
-
async listFiles(path) {
|
|
1208
|
-
const entries = await fileCall(path, () => this.files.readdir(path));
|
|
1209
|
-
return Promise.all(entries.sort((a, b) => a.name.localeCompare(b.name)).map((e) => this.stat(e.path)));
|
|
1210
|
-
}
|
|
1211
|
-
async stat(path) {
|
|
1212
|
-
const e = await fileCall(path, () => this.files.stat(path));
|
|
1213
|
-
const r = await this.native.exec(["stat", "-c", "%U:%G", "--", this.files.path(path)], {
|
|
1214
|
-
check: true,
|
|
1215
|
-
});
|
|
1216
|
-
const [owner, group] = r.stdout.trim().split(":");
|
|
1217
|
-
return {
|
|
1218
|
-
name: e.name,
|
|
1219
|
-
path: e.path,
|
|
1220
|
-
type: e.type,
|
|
1221
|
-
size: e.size,
|
|
1222
|
-
mode: parseInt(e.mode, 8),
|
|
1223
|
-
permissions: e.mode,
|
|
1224
|
-
owner: owner,
|
|
1225
|
-
group: group,
|
|
1226
|
-
modifiedTime: Date.parse(e.modifiedAt) / 1000,
|
|
1227
|
-
symlinkTarget: e.type === "symlink"
|
|
1228
|
-
? (await this.native.exec(["readlink", "--", this.files.path(path)], { check: true })).stdout.trimEnd()
|
|
1229
|
-
: null,
|
|
1230
|
-
};
|
|
1231
|
-
}
|
|
1232
|
-
/** Changes under `remotePath` until `timeoutMs` passes or the loop stops. */
|
|
1233
|
-
async *watch(remotePath, params = {}) {
|
|
1234
|
-
only("Modal watch", params, ["filter", "recursive", "timeoutMs"]);
|
|
1235
|
-
if (!remotePath.startsWith("/"))
|
|
1236
|
-
throw new InvalidError(`watch() expects an absolute path, got ${remotePath}`);
|
|
1237
|
-
const types = (params.filter ?? ["Access", "Create", "Modify", "Remove"]).flatMap((t) => (t === "Unknown" ? [] : WATCHED[t]));
|
|
1238
|
-
const queue = [];
|
|
1239
|
-
let ended = false;
|
|
1240
|
-
let wake;
|
|
1241
|
-
const notify = () => {
|
|
1242
|
-
wake?.();
|
|
1243
|
-
wake = undefined;
|
|
1244
|
-
};
|
|
1245
|
-
const handle = await fileCall(remotePath, () => this.native.files.watch(remotePath, undefined, {
|
|
1246
|
-
recursive: params.recursive ?? false,
|
|
1247
|
-
events: [...new Set(types)],
|
|
1248
|
-
timeoutMs: params.timeoutMs ?? 0,
|
|
1249
|
-
onBatch: (events) => {
|
|
1250
|
-
for (const e of events)
|
|
1251
|
-
queue.push({
|
|
1252
|
-
eventType: e.type === "create"
|
|
1253
|
-
? "Create"
|
|
1254
|
-
: e.type === "remove"
|
|
1255
|
-
? "Remove"
|
|
1256
|
-
: e.type === "access"
|
|
1257
|
-
? "Access"
|
|
1258
|
-
: "Modify",
|
|
1259
|
-
paths: e.type === "rename" && e.oldPath ? [e.oldPath, e.path] : [e.path],
|
|
1260
|
-
});
|
|
1261
|
-
notify();
|
|
1262
|
-
},
|
|
1263
|
-
onExit: () => {
|
|
1264
|
-
ended = true;
|
|
1265
|
-
notify();
|
|
1266
|
-
},
|
|
1267
|
-
}));
|
|
1268
|
-
try {
|
|
1269
|
-
while (true) {
|
|
1270
|
-
const next = queue.shift();
|
|
1271
|
-
if (next)
|
|
1272
|
-
yield next;
|
|
1273
|
-
else if (ended)
|
|
1274
|
-
return;
|
|
1275
|
-
else
|
|
1276
|
-
await new Promise((resolve) => (wake = resolve));
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
finally {
|
|
1280
|
-
if (!ended)
|
|
1281
|
-
await handle.stop().catch(() => undefined);
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
}
|