withruntime 1.0.0 → 1.1.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 +76 -0
- package/README.md +145 -0
- package/dist/generated/agentSessions.d.ts +218 -0
- package/dist/generated/agentSessions.js +154 -0
- package/dist/generated/agents.d.ts +193 -0
- package/dist/generated/agents.js +166 -0
- package/dist/generated/apps.d.ts +87 -28
- package/dist/generated/apps.js +153 -41
- package/dist/generated/audit.d.ts +2 -2
- package/dist/generated/audit.js +3 -3
- package/dist/generated/browsers.d.ts +87 -28
- package/dist/generated/browsers.js +153 -41
- package/dist/generated/builds.d.ts +87 -28
- package/dist/generated/builds.js +153 -41
- package/dist/generated/ci.d.ts +87 -28
- package/dist/generated/ci.js +153 -41
- package/dist/generated/containers.d.ts +87 -28
- package/dist/generated/containers.js +153 -41
- package/dist/generated/desktops.d.ts +89 -30
- package/dist/generated/desktops.js +155 -43
- package/dist/generated/domains.d.ts +52 -15
- package/dist/generated/domains.js +74 -14
- package/dist/generated/egressIps.d.ts +6 -6
- package/dist/generated/egressIps.js +4 -4
- package/dist/generated/events.d.ts +4 -2
- package/dist/generated/events.js +3 -3
- package/dist/generated/feedback.d.ts +1 -1
- package/dist/generated/feedback.js +3 -3
- package/dist/generated/functions.d.ts +87 -28
- package/dist/generated/functions.js +153 -41
- package/dist/generated/identities.d.ts +2 -2
- package/dist/generated/identities.js +5 -5
- package/dist/generated/images.d.ts +68 -14
- package/dist/generated/images.js +96 -15
- package/dist/generated/index.d.ts +9 -0
- package/dist/generated/index.js +12 -0
- package/dist/generated/jobRuns.d.ts +11 -4
- package/dist/generated/jobRuns.js +6 -6
- package/dist/generated/jobs.d.ts +58 -9
- package/dist/generated/jobs.js +98 -14
- package/dist/generated/keys.d.ts +8 -6
- package/dist/generated/keys.js +6 -6
- package/dist/generated/me.d.ts +2 -2
- package/dist/generated/me.js +3 -3
- package/dist/generated/messages.d.ts +67 -0
- package/dist/generated/messages.js +17 -0
- package/dist/generated/networks.d.ts +4 -4
- package/dist/generated/networks.js +4 -4
- package/dist/generated/notebooks.d.ts +87 -28
- package/dist/generated/notebooks.js +153 -41
- package/dist/generated/otel.d.ts +2 -2
- package/dist/generated/otel.js +5 -5
- package/dist/generated/ports.d.ts +11 -11
- package/dist/generated/ports.js +8 -8
- package/dist/generated/previews.d.ts +50 -15
- package/dist/generated/previews.js +70 -18
- package/dist/generated/projects.d.ts +30 -6
- package/dist/generated/projects.js +13 -9
- package/dist/generated/roles.d.ts +11 -2
- package/dist/generated/roles.js +9 -5
- package/dist/generated/routes.js +1 -1
- package/dist/generated/runtime.d.ts +15 -3
- package/dist/generated/runtime.js +31 -18
- package/dist/generated/sandboxes.d.ts +213 -66
- package/dist/generated/sandboxes.js +171 -43
- package/dist/generated/secrets.d.ts +45 -6
- package/dist/generated/secrets.js +69 -9
- package/dist/generated/sessions.d.ts +1 -1
- package/dist/generated/sessions.js +4 -4
- package/dist/generated/signing.js +3 -1
- package/dist/generated/sites.d.ts +87 -28
- package/dist/generated/sites.js +153 -41
- package/dist/generated/snapshots.d.ts +70 -5
- package/dist/generated/snapshots.js +107 -7
- package/dist/generated/tunnels.d.ts +8 -8
- package/dist/generated/tunnels.js +4 -4
- package/dist/generated/usage.d.ts +57 -6
- package/dist/generated/usage.js +4 -4
- package/dist/generated/volumes.d.ts +72 -7
- package/dist/generated/volumes.js +114 -10
- package/dist/generated/webhooks.d.ts +2 -2
- package/dist/generated/webhooks.js +5 -5
- package/dist/generated/workspaces.d.ts +87 -28
- package/dist/generated/workspaces.js +153 -41
- package/dist/v2/bin.d.ts +2 -0
- package/dist/v2/bin.js +15 -0
- package/dist/v2/cli.d.ts +15 -2
- package/dist/v2/cli.js +158 -53
- package/dist/v2/json.d.ts +9 -0
- package/dist/v2/json.js +5 -0
- package/dist/v2/mcp.js +14 -1
- package/dist/v2/openapi.json +7695 -4382
- package/dist/v2/shims/fly.js +49 -13
- package/dist/v2/shims/morph.js +1 -1
- package/dist/v2/table.d.ts +7 -4
- package/dist/v2/table.js +97 -34
- package/package.json +7 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Every release of the Runtime Cloud SDKs: npm `withruntime`, PyPI `withruntime`, RubyGems `withruntime` and the Go
|
|
4
|
+
module `withruntime.com/go`. Versions follow [Semantic Versioning](https://semver.org). Each release is generated from
|
|
5
|
+
the API's OpenAPI description, `https://api.withruntime.com/v2/openapi.json`.
|
|
6
|
+
|
|
7
|
+
## 1.1.1 (24 November 2026), npm
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- `npx withruntime <command>` runs the command. In 1.0.0 and 1.1.0 it exited at once with no output, because the CLI
|
|
12
|
+
ran only when started under the name `runtime`; `npx withruntime login`, `npx withruntime mcp` and every other
|
|
13
|
+
command did nothing. The `runtime` command was not affected.
|
|
14
|
+
|
|
15
|
+
## 1.1.0 (24 November 2026), and Go v2.0.0
|
|
16
|
+
|
|
17
|
+
npm, PyPI and RubyGems `withruntime` 1.1.0. The Go module moves to `withruntime.com/go/v2` at v2.0.0: import
|
|
18
|
+
`withruntime.com/go/v2/generated`. In Go, `Get` and `Refresh` of domains, images, jobs, job runs, previews,
|
|
19
|
+
secrets, snapshots and volumes take a query (`wait`, `ifState`) before the request options, and `Volumes.Create`,
|
|
20
|
+
`Volumes.Get` and `Snapshots.Get` return `*Volume` and `*Snapshot` handles. `withruntime.com/go` v1.0.0 stays
|
|
21
|
+
available.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- `Sandbox.create()` and the same class method on every product (`App.create()`, `Browser.create()` and so on) in
|
|
26
|
+
TypeScript and Python. Each returns a handle with a client of its own.
|
|
27
|
+
- `await using` (TypeScript) and `with` / `async with` (Python) delete a machine when the block ends.
|
|
28
|
+
- `spawn` on every machine, in TypeScript and Python: start a background process and read its output later.
|
|
29
|
+
- `processes.resize` and `resizeProcess` on every machine: resize the terminal of a process started with a pty.
|
|
30
|
+
- `update` on images, snapshots and volumes.
|
|
31
|
+
- `runtime.projects.limits`: read and set a project's limits. `Project` carries `limits`.
|
|
32
|
+
- `runtime.roles.actions`: add or remove a role's actions. `KeyCreate` takes `actions`.
|
|
33
|
+
- Machines: `autoWake`, `deleteAfterSeconds` and `deleteProtection` on create, update and fork; `from` on create;
|
|
34
|
+
`pausedAt`, `deleteAt` and `deleteProtection` on the machine.
|
|
35
|
+
- Images: `pullSecret` (a registry login), `deleteAfterSeconds` and `deleteProtection`. Volumes and snapshots take
|
|
36
|
+
`deleteAfterSeconds` and `deleteProtection`.
|
|
37
|
+
- `wait` and `ifState` on `get` and `refresh` of domains, images, jobs, job runs, previews, secrets, snapshots and
|
|
38
|
+
volumes: wait for a change instead of polling.
|
|
39
|
+
- Previews: `sandbox.previews.create()`, and `name`, the preview's hostname, which its own calls also take.
|
|
40
|
+
- Secrets: `scope.none`, a secret only Runtime uses (for example an image's `pullSecret`).
|
|
41
|
+
- Usage: `hours`, `keys` and `lines` break usage down by hour, API key and product line.
|
|
42
|
+
- `RUNTIME_PROJECT` (or the `project` option) scopes every call, with a bearer key as well as a key pair.
|
|
43
|
+
- Typed `Volume` and `Snapshot` handles from `volumes.create`, `volumes.get` and `snapshots.get`.
|
|
44
|
+
- `CardRequiredError` and `MethodNotAllowedError` (TypeScript, Python).
|
|
45
|
+
- A README in every package, and this changelog.
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
- The `runtime` CLI sends number flags such as `--memory-gb 16` as numbers; 1.0.0 sent them as text, which the API
|
|
50
|
+
refused. One `--cmd` is a shell command line, run by `bash -lc`.
|
|
51
|
+
- `runtime --help` and other long output are no longer cut off at 64 KiB when piped on macOS.
|
|
52
|
+
- `runtime mcp` answers a refused call (no key, a bad key, a limit) with a JSON-RPC error for that request, instead
|
|
53
|
+
of the API's error body, which MCP clients could not read.
|
|
54
|
+
|
|
55
|
+
- Every handle answers its record's fields as its own (`volume.sizeBytes`, `snapshot.name`), so `volumes.get`,
|
|
56
|
+
`volumes.create` and `snapshots.get`, which now return handles with `refresh`, `update` and `delete`, still answer
|
|
57
|
+
everything the record had. Every handle keeps `id` where its key is another field (`preview.name`).
|
|
58
|
+
- The query argument of every method also takes the request options, so a call written before the method had a
|
|
59
|
+
query, such as `domains.get(hostname, { signal })`, keeps working (TypeScript).
|
|
60
|
+
|
|
61
|
+
### Compatibility
|
|
62
|
+
|
|
63
|
+
Code written for 1.0.0 runs unchanged in TypeScript, Python and Ruby (Go: see above), with two exceptions for code that builds the
|
|
64
|
+
SDK's own records: Python's record classes take their fields by keyword (new fields are not added at the end), and
|
|
65
|
+
in Ruby, `Domain`, `Job`, `Preview`, `Sandbox` and `Secret` are handles now, which read their fields but no longer
|
|
66
|
+
have a Struct's setters, `to_wire` or `.from`; their records are `DomainInfo`, `JobInfo`, `PreviewInfo`,
|
|
67
|
+
`SandboxInfo` and `SecretInfo`. `Withruntime::Generated::` names still resolve.
|
|
68
|
+
|
|
69
|
+
Python 1.0.0 raised `KeyError: 'labelsAny'` reading a secret whose scope is `none` (an image's `pullSecret`); 1.1.0
|
|
70
|
+
reads it.
|
|
71
|
+
|
|
72
|
+
## 1.0.0 (17 November 2026)
|
|
73
|
+
|
|
74
|
+
The first release generated from the API's description: every product and every operation of
|
|
75
|
+
`https://api.withruntime.com/v2`, typed, in TypeScript, Python, Ruby and Go, with the `runtime` CLI and its MCP server
|
|
76
|
+
in the npm package. It replaces the hand-written 0.x SDKs, which called the v1 API.
|
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# withruntime
|
|
2
|
+
|
|
3
|
+
The official client for [Runtime Cloud](https://withruntime.com): Linux machines for AI agents and apps, each a
|
|
4
|
+
microVM with its own kernel, disk and network, created in milliseconds and billed for the CPU it uses and the memory
|
|
5
|
+
it holds. The client is generated from the API's OpenAPI description, so every product and every operation of
|
|
6
|
+
`https://api.withruntime.com/v2` is here, typed.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install withruntime
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Node.js 22.12 or later, or Bun. The package has no runtime dependencies.
|
|
15
|
+
|
|
16
|
+
## Authentication
|
|
17
|
+
|
|
18
|
+
The client reads your API key from `RUNTIME_API_KEY`. Create a key at https://withruntime.com/account/keys and keep it
|
|
19
|
+
in a secret manager, never in source code or a URL. A key pair's `rtsk_` secret also works: the client signs each
|
|
20
|
+
request with it and never sends it.
|
|
21
|
+
|
|
22
|
+
## Quickstart
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Sandbox } from "withruntime";
|
|
26
|
+
|
|
27
|
+
await using sbx = await Sandbox.create();
|
|
28
|
+
await sbx.files.write("/workspace/invoice.py", "print(sum([125, 250, 375]))\n");
|
|
29
|
+
const result = await sbx.exec("python3 /workspace/invoice.py");
|
|
30
|
+
console.log(result.exitCode, result.stdout); // 0 "750\n"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`await using` deletes the sandbox when the block ends (Node.js 24, Bun, or TypeScript 5.2 and later). Elsewhere,
|
|
34
|
+
call `await sbx.delete()` in a `finally` block.
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { Runtime } from "withruntime";
|
|
40
|
+
|
|
41
|
+
const runtime = new Runtime({
|
|
42
|
+
apiKey: process.env.RUNTIME_API_KEY, // the default
|
|
43
|
+
project: "prj_...", // default: RUNTIME_PROJECT
|
|
44
|
+
baseUrl: "https://api.withruntime.com", // default: RUNTIME_API_URL
|
|
45
|
+
maxRetries: 3,
|
|
46
|
+
});
|
|
47
|
+
const sbx = await runtime.sandboxes.create({ vcpu: 4, memoryGB: 8 });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Products
|
|
51
|
+
|
|
52
|
+
| Class | Create one | What it is |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `Sandbox` | `await Sandbox.create()` | A Linux machine with its own kernel, made in milliseconds, paused with its memory kept when idle and resumed where it was. |
|
|
55
|
+
| `FunctionMachine` | `await FunctionMachine.create()` | A machine that answers HTTP with a handler in /app/index.ts (`export default { fetch(request) }`, as Cloudflare Workers and Vercel take one) on port 8080, reached at its preview. |
|
|
56
|
+
| `App` | `await App.create()` | A machine that keeps a web app in /app running on port 8080 (its Procfile's `web:`, else `npm start`, else `python3 app.py`, as Render and Heroku start one), reached at its preview. |
|
|
57
|
+
| `Site` | `await Site.create()` | A machine that serves the static files in /site on port 8080 (as Netlify and Vercel serve a build's output), reached at its preview. |
|
|
58
|
+
| `CiMachine` | `await CiMachine.create()` | A machine that runs a repository's checks to their end (its `run`) with git, Docker, Node, Bun, Python and a compiler, and is stopped then. |
|
|
59
|
+
| `Browser` | `await Browser.create()` | A machine running headless Chromium, driven over the Chrome DevTools Protocol at its preview on port 9222: one WebSocket address for Playwright's `connectOverCDP` and Puppeteer's `connect`, as Browserbase gives one. |
|
|
60
|
+
| `Desktop` | `await Desktop.create()` | A machine running a Linux desktop with Chromium, for agents that use a computer: screenshot returns what its screen shows and act moves and clicks its mouse and types on its keyboard. |
|
|
61
|
+
| `Notebook` | `await Notebook.create()` | A machine running JupyterLab on port 8888 over /workspace, with NumPy, pandas and matplotlib, reached at its private preview. |
|
|
62
|
+
| `Workspace` | `await Workspace.create()` | A development environment: a machine running VS Code in the browser (code-server) on port 8080 over /workspace, reached at its private preview, as Codespaces and Gitpod give one. |
|
|
63
|
+
| `Container` | `await Container.create()` | A machine that runs one OCI image from any registry under Docker on its own network (`start` `runtime-container <image>`), the port it listens on reached at its preview, as Cloud Run and Fly Machines run one. |
|
|
64
|
+
| `Build` | `await Build.create()` | The machine an image's build runs on: Docker's own builder (BuildKit), its run `runtime-image-build`, deleted once its image is made. |
|
|
65
|
+
| `Job` | `await Job.create()` | A command run in a fresh machine, once or on a cron schedule in a timezone. |
|
|
66
|
+
| `Image` | `await Image.create()` | What a machine boots: a root filesystem, its environment and its start. |
|
|
67
|
+
| `Volume` | `await Volume.create()` | A disk that outlives the machines it is attached to. |
|
|
68
|
+
| `Domain` | `await Domain.create()` | Your own hostname serving a machine's port, with HTTPS. |
|
|
69
|
+
|
|
70
|
+
Every machine (each class above with `files`) has `refresh`, `delete`, `pause`, `resume`, `exec`, `metrics`, `fork`, `snapshot`, `update`, `screenshot`, `act`, `runCode`, `spawn`, `files.read`, `files.write`, `files.remove`, `files.stat`, `files.list`, `files.downloadFolder`, `files.uploadFolder`, `files.beginFolderUpload`, `files.writeFolderUpload`, `files.commitFolderUpload`, `files.abortFolderUpload`, `files.mkdir`, `files.rename`, `files.link`, `files.revokeLinks`, `processes.output`, `processes.write`, `processes.signal`, `processes.resize`, `processes.list`, `network.get`, `network.set`.
|
|
71
|
+
|
|
72
|
+
- `Sandbox` also has `execStream`, `previews.create`.
|
|
73
|
+
- `Job` also has `run`.
|
|
74
|
+
- `Image` also has `logs`.
|
|
75
|
+
- `Domain` also has `verify`.
|
|
76
|
+
|
|
77
|
+
The API's other resources (keys, projects, roles, secrets, snapshots, webhooks, usage and more) are clients on the
|
|
78
|
+
runtime object. The [API reference](https://withruntime.com/docs/reference) lists every operation.
|
|
79
|
+
|
|
80
|
+
## Errors
|
|
81
|
+
|
|
82
|
+
Every error the API returns is thrown as a `RuntimeApiError` with `code`, `message`, `status`, `requestId`,
|
|
83
|
+
`hint`, `param` and `retryable`. Each error family has its own subclass, such as `NotFoundError`,
|
|
84
|
+
`InvalidRequestError`, `RateLimitedError` and `CapacityUnavailableError`:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { NotFoundError } from "withruntime";
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
await runtime.sandboxes.get("sbx_missing");
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (err instanceof NotFoundError) console.log(err.code, err.requestId);
|
|
93
|
+
else throw err;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Retries and idempotency
|
|
98
|
+
|
|
99
|
+
The client retries a rate-limited (429) or unavailable (503) answer, and a lost connection on a call that is safe to send again, up to `maxRetries` times (default 3). Every write sends an `Idempotency-Key` header, generated when you do not pass `idempotencyKey`, so a retry never runs a write twice. Pass `signal` to cancel a call.
|
|
100
|
+
|
|
101
|
+
## Lists
|
|
102
|
+
|
|
103
|
+
A `list` call returns the first page when awaited, and every item across pages when iterated:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
for await (const s of runtime.sandboxes.list({ state: "running" })) console.log(s.id);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Command line and MCP server
|
|
110
|
+
|
|
111
|
+
The package installs the `runtime` command. It reads `RUNTIME_API_KEY`, or the key that `runtime login` saves:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npx withruntime login
|
|
115
|
+
npx withruntime sandboxes list
|
|
116
|
+
npx withruntime --help
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`runtime mcp` serves every API verb as an MCP tool over stdio. To add it to an MCP client:
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{ "mcpServers": { "runtime": { "command": "npx", "args": ["-y", "withruntime", "mcp"], "env": { "RUNTIME_API_KEY": "..." } } } }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Drop-in modules for code written against other sandbox SDKs are exported as `withruntime/e2b`, `withruntime/daytona`,
|
|
126
|
+
`withruntime/vercel`, `withruntime/blaxel`, `withruntime/morph`, `withruntime/modal`, `withruntime/cloudflare` and
|
|
127
|
+
`withruntime/fly`.
|
|
128
|
+
|
|
129
|
+
## Versioning
|
|
130
|
+
|
|
131
|
+
The package follows [Semantic Versioning](https://semver.org): a minor or patch release never breaks code written
|
|
132
|
+
for an earlier release of the same major version. Each request sends the API version the client was generated for in
|
|
133
|
+
the `Runtime-Version` header. Every release is listed in [CHANGELOG.md](CHANGELOG.md).
|
|
134
|
+
|
|
135
|
+
## Resources
|
|
136
|
+
|
|
137
|
+
- Guides: https://withruntime.com/docs
|
|
138
|
+
- API reference: https://withruntime.com/docs/reference
|
|
139
|
+
- Pricing: https://withruntime.com/pricing
|
|
140
|
+
- Status: https://status.withruntime.com
|
|
141
|
+
- Support: support@withruntime.com
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
Apache-2.0
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import type { RequestOptions, Transport } from "./runtime.js";
|
|
2
|
+
import { Paginated } from "./runtime.js";
|
|
3
|
+
import type { NetworkRules } from "./sandboxes.js";
|
|
4
|
+
import type { SandboxCreate } from "./sandboxes.js";
|
|
5
|
+
import type { SandboxInfo } from "./sandboxes.js";
|
|
6
|
+
import type { Terminal } from "./sandboxes.js";
|
|
7
|
+
import type { ExecRequest } from "./sandboxes.js";
|
|
8
|
+
import type { Process } from "./sandboxes.js";
|
|
9
|
+
import type { FileWritten } from "./sandboxes.js";
|
|
10
|
+
import type { ProcessOutput } from "./sandboxes.js";
|
|
11
|
+
import type { ProcessInput } from "./sandboxes.js";
|
|
12
|
+
import type { ProcessWritten } from "./sandboxes.js";
|
|
13
|
+
import type { ProcessSignal } from "./sandboxes.js";
|
|
14
|
+
import type { ProcessList } from "./sandboxes.js";
|
|
15
|
+
import type { FileRemove } from "./sandboxes.js";
|
|
16
|
+
import type { FileRemoved } from "./sandboxes.js";
|
|
17
|
+
import type { FileInfo } from "./sandboxes.js";
|
|
18
|
+
import type { FileList } from "./sandboxes.js";
|
|
19
|
+
import type { FolderUnpacked } from "./sandboxes.js";
|
|
20
|
+
import type { FolderUploadBegin } from "./sandboxes.js";
|
|
21
|
+
import type { FolderUpload } from "./sandboxes.js";
|
|
22
|
+
import type { FolderUploadReceived } from "./sandboxes.js";
|
|
23
|
+
import type { FolderUploadAborted } from "./sandboxes.js";
|
|
24
|
+
import type { FileMkdir } from "./sandboxes.js";
|
|
25
|
+
import type { FileMade } from "./sandboxes.js";
|
|
26
|
+
import type { FileRename } from "./sandboxes.js";
|
|
27
|
+
import type { FileRenamed } from "./sandboxes.js";
|
|
28
|
+
import type { FileLinkCreate } from "./sandboxes.js";
|
|
29
|
+
import type { FileLink } from "./sandboxes.js";
|
|
30
|
+
import type { FileLinksRevoked } from "./sandboxes.js";
|
|
31
|
+
import type { SandboxNetwork } from "./sandboxes.js";
|
|
32
|
+
import type { SandboxMetrics } from "./sandboxes.js";
|
|
33
|
+
import type { ForkRequest } from "./sandboxes.js";
|
|
34
|
+
import type { Forked } from "./sandboxes.js";
|
|
35
|
+
import type { SnapshotRequest } from "./sandboxes.js";
|
|
36
|
+
import type { Stored } from "./sandboxes.js";
|
|
37
|
+
import type { MachineUpdate } from "./sandboxes.js";
|
|
38
|
+
import type { ActRequest } from "./sandboxes.js";
|
|
39
|
+
import type { Acted } from "./sandboxes.js";
|
|
40
|
+
import type { RunCode } from "./sandboxes.js";
|
|
41
|
+
import type { CodeRun } from "./sandboxes.js";
|
|
42
|
+
/** What get takes in its query. */
|
|
43
|
+
export type AgentSessionGetQuery = {
|
|
44
|
+
/** Seconds to wait, at most 60, for its state to differ from `ifState`; it answers once it does, or as it is when the wait ends. At least 0. At most 60. */
|
|
45
|
+
wait?: number;
|
|
46
|
+
/** The state the caller last read, which `wait` waits for it to leave. */
|
|
47
|
+
ifState?: string;
|
|
48
|
+
};
|
|
49
|
+
/** What list takes in its query. */
|
|
50
|
+
export type AgentSessionListQuery = {
|
|
51
|
+
/** Only those in these states, comma-separated. */
|
|
52
|
+
state?: string;
|
|
53
|
+
/** Only the agent.session of this name. */
|
|
54
|
+
name?: string;
|
|
55
|
+
/** Only those with every label given (repeat it for several): key:value, or a key for any value. */
|
|
56
|
+
label?: string[];
|
|
57
|
+
/** The most items the page holds. At least 1. At most 200. Default: 50. */
|
|
58
|
+
limit?: number;
|
|
59
|
+
};
|
|
60
|
+
/** What read takes in its query. */
|
|
61
|
+
export type AgentSessionReadQuery = {
|
|
62
|
+
/** The file's path in the machine. */
|
|
63
|
+
path: string;
|
|
64
|
+
};
|
|
65
|
+
/** What write takes in its query. */
|
|
66
|
+
export type AgentSessionWriteQuery = {
|
|
67
|
+
/** The file's path in the machine. */
|
|
68
|
+
path: string;
|
|
69
|
+
/** Its mode, in octal (`644`). */
|
|
70
|
+
mode?: string;
|
|
71
|
+
/** Write the bytes into the file in place from this byte, keeping the bytes before and after them (the file is made when there is none); one that fails part way may leave its range written in part, so send it again. Parts of one file may be written so at once and in any order: write them to a new path, then rename it with its size and sha256 to put it in place whole. At least 0. */
|
|
72
|
+
offset?: number;
|
|
73
|
+
/** The bytes' SHA-256 in hex: refused 409 `checksum_mismatch`, the file as it was, when they differ. Not with offset. */
|
|
74
|
+
sha256?: string;
|
|
75
|
+
};
|
|
76
|
+
/** What processOutput takes in its query. */
|
|
77
|
+
export type AgentSessionProcessOutputQuery = {
|
|
78
|
+
/** Output after this byte. At least 0. Default: 0. */
|
|
79
|
+
cursor?: number;
|
|
80
|
+
/** Seconds to wait for output past the cursor or its exit, at most 8. At least 0. At most 8. */
|
|
81
|
+
waitSeconds?: number;
|
|
82
|
+
/** At most this many bytes. At least 4096. At most 196608. Default: 65536. */
|
|
83
|
+
maxBytes?: number;
|
|
84
|
+
/** Answer as NDJSON events from the cursor until it exits (stdout, stderr, truncated, exit; continue with the cursor to follow on from), as `Accept: application/x-ndjson` does. */
|
|
85
|
+
follow?: boolean;
|
|
86
|
+
};
|
|
87
|
+
/** What stat takes in its query. */
|
|
88
|
+
export type AgentSessionStatQuery = {
|
|
89
|
+
/** The file's path in the machine. */
|
|
90
|
+
path: string;
|
|
91
|
+
/** Also return a file's SHA-256, read from its bytes: to check a file you put in place (files:rename with sha256) is whole. Default: false. */
|
|
92
|
+
sha256?: boolean;
|
|
93
|
+
};
|
|
94
|
+
/** What listFiles takes in its query. */
|
|
95
|
+
export type AgentSessionListFilesQuery = {
|
|
96
|
+
/** The directory. Default: "/workspace". */
|
|
97
|
+
path?: string;
|
|
98
|
+
/** How deep to list. At least 1. At most 10. Default: 1. */
|
|
99
|
+
depth?: number;
|
|
100
|
+
/** At most this many entries. At least 1. At most 2000. Default: 2000. */
|
|
101
|
+
limit?: number;
|
|
102
|
+
/** List entries whose names start with a dot. Default: true. */
|
|
103
|
+
hidden?: boolean;
|
|
104
|
+
/** Only entries whose path relative to the directory matches: `*` within a name, `**` across folders, `?` one character, `{a,b}` either (`**\/*.py`); at most 512 characters, 32 wildcards and 64 texts in braces. The listing then reaches as deep as the glob does (10 folders for `**`) unless depth says, and is searched past its first 2,000 entries, up to 50,000. At most 512 characters. */
|
|
105
|
+
glob?: string;
|
|
106
|
+
};
|
|
107
|
+
/** What downloadFolder takes in its query. */
|
|
108
|
+
export type AgentSessionDownloadFolderQuery = {
|
|
109
|
+
/** The folder, absolute, such as `/workspace/app`. */
|
|
110
|
+
path: string;
|
|
111
|
+
/** Compress the archive with gzip. Default: false. */
|
|
112
|
+
gzip?: boolean;
|
|
113
|
+
/** Who packs it: `runtime` or `root`; the agent.session's `user` when omitted. */
|
|
114
|
+
user?: "runtime" | "root" | (string & {});
|
|
115
|
+
/** Paths in the folder to leave out, relative to it and comma-separated (`node_modules,.cache`): plain names, no wildcards, at most 32. */
|
|
116
|
+
exclude?: string;
|
|
117
|
+
};
|
|
118
|
+
/** What uploadFolder takes in its query. */
|
|
119
|
+
export type AgentSessionUploadFolderQuery = {
|
|
120
|
+
/** The folder, absolute, such as `/workspace/app`: made with its parents. */
|
|
121
|
+
path: string;
|
|
122
|
+
/** Who unpacks it: `runtime` or `root`; the agent.session's `user` when omitted. */
|
|
123
|
+
user?: "runtime" | "root" | (string & {});
|
|
124
|
+
};
|
|
125
|
+
/** What writeFolderUpload takes in its query. */
|
|
126
|
+
export type AgentSessionWriteFolderUploadQuery = {
|
|
127
|
+
/** Where the part starts in the archive: at most the bytes received so far. Bytes before them were taken already and are skipped, so a part sent again is never unpacked twice. At least 0. Default: 0. */
|
|
128
|
+
offset?: number;
|
|
129
|
+
};
|
|
130
|
+
/** What metrics takes in its query. */
|
|
131
|
+
export type AgentSessionMetricsQuery = {
|
|
132
|
+
/** The window: `15m`, `1h`, `6h`, `24h`, `7d` or `30d`. Default: "1h". */
|
|
133
|
+
range?: "15m" | "1h" | "6h" | "24h" | "7d" | "30d" | (string & {});
|
|
134
|
+
};
|
|
135
|
+
/** What screenshot takes in its query. */
|
|
136
|
+
export type AgentSessionScreenshotQuery = {
|
|
137
|
+
/** `png`, or `jpeg`: smaller and quicker to send, for a model that reads it. Default: "png". */
|
|
138
|
+
format?: "png" | "jpeg" | (string & {});
|
|
139
|
+
/** A jpeg's quality, 1 to 100. At least 1. At most 100. Default: 80. */
|
|
140
|
+
quality?: number;
|
|
141
|
+
};
|
|
142
|
+
/** A machine that runs an agent's harness: made by an agent's start, with the agent's machine, secrets and model accounts. Every machine call works on it: run a command, read its files, open its desktop, fork it to try again from where it is. Its conversation is its messages. It pauses when idle, its memory and disk kept, and a message sent to it wakes it. */
|
|
143
|
+
export declare class AgentSessions {
|
|
144
|
+
readonly transport: Transport;
|
|
145
|
+
constructor(transport: Transport);
|
|
146
|
+
/** Creates an agent session. Asked again with the same Idempotency-Key, it returns the same agent.session. */
|
|
147
|
+
create(input?: SandboxCreate, options?: RequestOptions): Promise<SandboxInfo>;
|
|
148
|
+
/** Returns an agent session. */
|
|
149
|
+
get(id: string, query?: AgentSessionGetQuery & RequestOptions, options?: RequestOptions): Promise<SandboxInfo>;
|
|
150
|
+
/** Lists the project's agent-sessions, newest first. */
|
|
151
|
+
list(query?: AgentSessionListQuery & RequestOptions, options?: RequestOptions): Paginated<SandboxInfo>;
|
|
152
|
+
/** Deletes an agent session, its memory and its disk. */
|
|
153
|
+
delete(id: string, options?: RequestOptions): Promise<SandboxInfo>;
|
|
154
|
+
/** Pauses an agent session with its memory and disk kept. A call to it resumes it. */
|
|
155
|
+
pause(id: string, options?: RequestOptions): Promise<SandboxInfo>;
|
|
156
|
+
/** Resumes a paused agent.session where it was, its memory and processes as they were. */
|
|
157
|
+
resume(id: string, options?: RequestOptions): Promise<SandboxInfo>;
|
|
158
|
+
/** Runs a command as a process and returns it once it ended, with its output; with wait false, at once, while it runs. A paused agent.session is resumed first. Asked again with the same Idempotency-Key, it runs nothing more: it returns the first run's process, waiting for its end while it runs. */
|
|
159
|
+
exec(id: string, input: ExecRequest, options?: RequestOptions): Promise<Process>;
|
|
160
|
+
/** Returns a file's bytes. */
|
|
161
|
+
read(id: string, query: AgentSessionReadQuery & RequestOptions, options?: RequestOptions): Promise<Uint8Array>;
|
|
162
|
+
/** Writes the request's bytes to a file as they come, of any size (Content-Length required), its folders made: the file whole when they all came, or as it was. With offset, they are written into it in place. */
|
|
163
|
+
write(id: string, data: Uint8Array | string, query: AgentSessionWriteQuery & RequestOptions, options?: RequestOptions): Promise<FileWritten>;
|
|
164
|
+
/** Returns a process's output after a cursor, and the cursor to read on from. The latest 1 MiB is kept; truncated says when the cursor fell behind. */
|
|
165
|
+
processOutput(id: string, process: string, query?: AgentSessionProcessOutputQuery & RequestOptions, options?: RequestOptions): Promise<ProcessOutput>;
|
|
166
|
+
/** Sends input to a process started with stdinOpen or a pty, and returns how much of its input it has taken. */
|
|
167
|
+
writeProcess(id: string, process: string, input?: ProcessInput, options?: RequestOptions): Promise<ProcessWritten>;
|
|
168
|
+
/** Sends a signal to a process and its group; a process that ended is not signalled, so a retry is safe. */
|
|
169
|
+
signalProcess(id: string, process: string, input?: ProcessSignal, options?: RequestOptions): Promise<Process>;
|
|
170
|
+
/** Resizes the terminal of a process started with a pty (its window's columns and rows, which the process is told by SIGWINCH), and returns the process; refused 409 for a process without one. A process that ended is left as it is, so a retry is safe. */
|
|
171
|
+
resizeProcess(id: string, process: string, input: Terminal, options?: RequestOptions): Promise<Process>;
|
|
172
|
+
/** Lists an agent session's processes, newest first: those running and those that ended lately. */
|
|
173
|
+
listProcesses(id: string, options?: RequestOptions): Promise<ProcessList>;
|
|
174
|
+
/** Removes a file, a link or a directory (recursive for one with contents). One missing is success, removed false. */
|
|
175
|
+
remove(id: string, input: FileRemove, options?: RequestOptions): Promise<FileRemoved>;
|
|
176
|
+
/** Returns what is at a path: a file, a directory or a link, or nothing (exists false). With sha256=true, a file's SHA-256 too. */
|
|
177
|
+
stat(id: string, query: AgentSessionStatQuery & RequestOptions, options?: RequestOptions): Promise<FileInfo>;
|
|
178
|
+
/** Lists a directory's entries in path order, to a depth. */
|
|
179
|
+
listFiles(id: string, query?: AgentSessionListFilesQuery & RequestOptions, options?: RequestOptions): Promise<FileList>;
|
|
180
|
+
/** Returns a folder as a tar archive (`application/x-tar`, or `application/gzip` with gzip), packed by tar in the agent.session as it streams, of any size; its entries are relative to the folder (`./a.txt`). A folder that fails part way (a file it may not read, or one that changes as it is read) ends as an archive every tar reader refuses, never as a short one that reads whole. At most 4 at once in an agent session. A paused agent.session is woken first. */
|
|
181
|
+
downloadFolder(id: string, query: AgentSessionDownloadFolderQuery & RequestOptions, options?: RequestOptions): Promise<Uint8Array>;
|
|
182
|
+
/** Unpacks the request's tar archive (gzip-compressed or not, told by its first bytes) into a folder, made with its parents, by tar in the agent.session as the bytes arrive, of any size, nothing of it kept on disk but what tar writes; returns once tar has ended, or 400 `invalid_archive` with what tar said. A paused agent.session is woken first. */
|
|
183
|
+
uploadFolder(id: string, data: Uint8Array | string, query: AgentSessionUploadFolderQuery & RequestOptions, options?: RequestOptions): Promise<FolderUnpacked>;
|
|
184
|
+
/** Begins a folder's upload in parts: tar starts in the agent.session, unpacking into the folder each part as it arrives. Send the parts in order by offset (writeFolderUpload), then commitFolderUpload; an upload no call names for 10 minutes is ended. A paused agent.session is woken first. */
|
|
185
|
+
beginFolderUpload(id: string, input: FolderUploadBegin, options?: RequestOptions): Promise<FolderUpload>;
|
|
186
|
+
/** Sends the request's bytes, a part of the archive at its offset, into tar's input as they arrive, of any size, and returns the bytes received in all once tar took them. A part past them is refused 409 `upload_incomplete`, naming them: send the parts in order. */
|
|
187
|
+
writeFolderUpload(id: string, upload: string, data: Uint8Array | string, query?: AgentSessionWriteFolderUploadQuery & RequestOptions, options?: RequestOptions): Promise<FolderUploadReceived>;
|
|
188
|
+
/** Ends a folder upload's input and returns once tar has ended, as an exec returns once its command has: the folder, or 400 `invalid_archive` with what tar said. A front that restarts meanwhile returns 503 `run_goes_on`; sent again, it returns how tar ended. An upload no call has named for 10 minutes since its last part or commit is ended. */
|
|
189
|
+
commitFolderUpload(id: string, upload: string, options?: RequestOptions): Promise<FolderUnpacked>;
|
|
190
|
+
/** Stops a folder upload's tar; what it unpacked so far stays. */
|
|
191
|
+
abortFolderUpload(id: string, upload: string, options?: RequestOptions): Promise<FolderUploadAborted>;
|
|
192
|
+
/** Makes a directory, and its parents unless parents is false. One there already is success, created false. */
|
|
193
|
+
mkdir(id: string, input: FileMkdir, options?: RequestOptions): Promise<FileMade>;
|
|
194
|
+
/** Moves a file, a link or a directory; refused 409 when something is at its new path, unless overwrite. With sha256 or size, a file written in parts is put in place once whole: its writes ended, then only a file of that size with every byte written and whose bytes hash to it moves; refused 409 `upload_incomplete` or `checksum_mismatch`, nothing moved. With sha256, it is safe to send again: once moved, it returns the same answer while `from` is gone and `to` holds those bytes. */
|
|
195
|
+
rename(id: string, input: FileRename, options?: RequestOptions): Promise<FileRenamed>;
|
|
196
|
+
/** Makes an expiring address for one file that anyone may open with no API key, from a browser, curl or another service: GET downloads it (Range works, so videos play and downloads resume; archive: true downloads a folder as .tar.gz), PUT with the raw body uploads it (up to maxBytes, written whole; Content-Length required). The link acts as the key that made it: an upload link needs write, and the link ends with its key, with revokeLinks or with its agent.session. A paused agent.session is woken for it unless wake is false. */
|
|
197
|
+
link(id: string, input: FileLinkCreate, options?: RequestOptions): Promise<FileLink>;
|
|
198
|
+
/** Ends every file link made for an agent session so far; links made after work. */
|
|
199
|
+
revokeLinks(id: string, options?: RequestOptions): Promise<FileLinksRevoked>;
|
|
200
|
+
/** Returns where an agent session may connect out. */
|
|
201
|
+
getNetwork(id: string, options?: RequestOptions): Promise<SandboxNetwork>;
|
|
202
|
+
/** Returns an agent session's CPU, memory, disks and pressure, as its host reads them from the agent.session's own cgroup over a fifth of a second: never a call into the agent.session, so it does not wake a paused one nor keep one from its idle pause. One that is not running has no reading. */
|
|
203
|
+
metrics(id: string, query?: AgentSessionMetricsQuery & RequestOptions, options?: RequestOptions): Promise<SandboxMetrics>;
|
|
204
|
+
/** Replaces where an agent session may connect out, for its next connection and within a second for its open ones: those the new rules refuse are cut. */
|
|
205
|
+
setNetwork(id: string, input?: NetworkRules, options?: RequestOptions): Promise<SandboxNetwork>;
|
|
206
|
+
/** Copies an agent session as it is now, memory and disk, into `count` copies of its own, each running on its host. Asked again with the same Idempotency-Key, it returns the same copies. */
|
|
207
|
+
fork(id: string, input?: ForkRequest, options?: RequestOptions): Promise<Forked>;
|
|
208
|
+
/** Keeps an agent session's memory and disk as they are now, a snapshot to start agent-sessions from; with `image`, its disk alone as that image's next version. The agent.session runs on. Asked again with the same Idempotency-Key, it returns the same snapshot. */
|
|
209
|
+
snapshot(id: string, input?: SnapshotRequest, options?: RequestOptions): Promise<Stored>;
|
|
210
|
+
/** Changes its name, labels, idle pause, maxCost, autoWake, lifetime, delete protection, environment or sizes; each field left out stays as it is. A lifetime (`deleteAfterSeconds`) sent again before its end moves the end to that many seconds from now; 0 takes it off. A lifetime is refused (409 `delete_protected`) while `deleteProtection` is true. A running one holds a changed environment before this answers (a paused one's at its wake): each process it starts after the answer has it, and its running processes keep the one they started with. Its vCPUs, memory and disk grow while it runs, its commands running on. One paused or stopped is not woken for it: judged at once as a live resize is (past the vCPUs it was made with 409, over its organization's limits `quota_exceeded`), its new sizes are returned at once, and its next wake grows it to them before the call that woke it runs. A smaller size, or a machine starting or failed, is refused 409 naming why, and nothing is changed. With If-Match, made only while its revision is that one, else 412. Sent again with the same Idempotency-Key and body while it is the latest change, it returns the current state and changes nothing; the same key with a different body returns 409 idempotency_key_reused. */
|
|
211
|
+
update(id: string, input?: MachineUpdate, options?: RequestOptions): Promise<SandboxInfo>;
|
|
212
|
+
/** Returns what an agent session's screen shows now, as `image/png` (or `image/jpeg`): its X display `:1`, whole. Refused 409 `display_not_running` when no display runs. A paused agent.session is resumed first. */
|
|
213
|
+
screenshot(id: string, query?: AgentSessionScreenshotQuery & RequestOptions, options?: RequestOptions): Promise<Uint8Array>;
|
|
214
|
+
/** Moves, clicks, drags and scrolls the mouse and types on the keyboard of an agent session's screen (its X display `:1`), each step in turn as one command, and returns where the mouse is then. It stops at the first step that fails, refused 409 `act_failed` naming it; refused 409 `display_not_running` when no display runs. A paused agent.session is resumed first. */
|
|
215
|
+
act(id: string, input: ActRequest, options?: RequestOptions): Promise<Acted>;
|
|
216
|
+
/** Runs a cell of Python in an agent session as a notebook does, in a Jupyter kernel it keeps running for the cell's `context`: variables, imports and functions stay for the next cell. Returns what it printed, its values and displays (text, HTML, images such as charts), and its exception with its traceback. The context's kernel starts on its first cell. A cell past `timeoutSeconds` is interrupted and its context kept. Refused 409 `kernel_not_installed` when the image has no ipykernel. A paused agent.session is resumed first. */
|
|
217
|
+
runCode(id: string, input: RunCode, options?: RequestOptions): Promise<CodeRun>;
|
|
218
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Generated by spec-gen from engines/front/crates/spec. Do not edit:
|
|
2
|
+
// change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
|
|
3
|
+
import { Paginated, toBytes } from "./runtime.js";
|
|
4
|
+
/** A machine that runs an agent's harness: made by an agent's start, with the agent's machine, secrets and model accounts. Every machine call works on it: run a command, read its files, open its desktop, fork it to try again from where it is. Its conversation is its messages. It pauses when idle, its memory and disk kept, and a message sent to it wakes it. */
|
|
5
|
+
export class AgentSessions {
|
|
6
|
+
transport;
|
|
7
|
+
constructor(transport) {
|
|
8
|
+
this.transport = transport;
|
|
9
|
+
}
|
|
10
|
+
/** Creates an agent session. Asked again with the same Idempotency-Key, it returns the same agent.session. */
|
|
11
|
+
create(input = {}, options) {
|
|
12
|
+
return this.transport.request("POST", `/v2/agent-sessions`, { body: input, options, idempotent: true });
|
|
13
|
+
}
|
|
14
|
+
/** Returns an agent session. */
|
|
15
|
+
get(id, query = {}, options) {
|
|
16
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}`, { query: { ...query }, options, idempotent: true });
|
|
17
|
+
}
|
|
18
|
+
/** Lists the project's agent-sessions, newest first. */
|
|
19
|
+
list(query = {}, options) {
|
|
20
|
+
return new Paginated((cursor) => this.transport.request("GET", `/v2/agent-sessions`, { query: { ...query, cursor }, options, idempotent: true }));
|
|
21
|
+
}
|
|
22
|
+
/** Deletes an agent session, its memory and its disk. */
|
|
23
|
+
delete(id, options) {
|
|
24
|
+
return this.transport.request("DELETE", `/v2/agent-sessions/${encodeURIComponent(id)}`, { options });
|
|
25
|
+
}
|
|
26
|
+
/** Pauses an agent session with its memory and disk kept. A call to it resumes it. */
|
|
27
|
+
pause(id, options) {
|
|
28
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}:pause`, { options });
|
|
29
|
+
}
|
|
30
|
+
/** Resumes a paused agent.session where it was, its memory and processes as they were. */
|
|
31
|
+
resume(id, options) {
|
|
32
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}:resume`, { options });
|
|
33
|
+
}
|
|
34
|
+
/** Runs a command as a process and returns it once it ended, with its output; with wait false, at once, while it runs. A paused agent.session is resumed first. Asked again with the same Idempotency-Key, it runs nothing more: it returns the first run's process, waiting for its end while it runs. */
|
|
35
|
+
exec(id, input, options) {
|
|
36
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}:exec`, { body: input, options, idempotent: true, runs: true, runsSeconds: input.timeoutSeconds });
|
|
37
|
+
}
|
|
38
|
+
/** Returns a file's bytes. */
|
|
39
|
+
read(id, query, options) {
|
|
40
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}/files`, { query: { ...query }, raw: true, options, idempotent: true });
|
|
41
|
+
}
|
|
42
|
+
/** Writes the request's bytes to a file as they come, of any size (Content-Length required), its folders made: the file whole when they all came, or as it was. With offset, they are written into it in place. */
|
|
43
|
+
write(id, data, query, options) {
|
|
44
|
+
return this.transport.request("PUT", `/v2/agent-sessions/${encodeURIComponent(id)}/files`, { data: toBytes(data), query: { ...query }, options });
|
|
45
|
+
}
|
|
46
|
+
/** Returns a process's output after a cursor, and the cursor to read on from. The latest 1 MiB is kept; truncated says when the cursor fell behind. */
|
|
47
|
+
processOutput(id, process, query = {}, options) {
|
|
48
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}/processes/${encodeURIComponent(process)}/output`, { query: { ...query }, options, idempotent: true });
|
|
49
|
+
}
|
|
50
|
+
/** Sends input to a process started with stdinOpen or a pty, and returns how much of its input it has taken. */
|
|
51
|
+
writeProcess(id, process, input = {}, options) {
|
|
52
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/processes/${encodeURIComponent(process)}:write`, { body: input, options });
|
|
53
|
+
}
|
|
54
|
+
/** Sends a signal to a process and its group; a process that ended is not signalled, so a retry is safe. */
|
|
55
|
+
signalProcess(id, process, input = {}, options) {
|
|
56
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/processes/${encodeURIComponent(process)}:signal`, { body: input, options, idempotent: true });
|
|
57
|
+
}
|
|
58
|
+
/** Resizes the terminal of a process started with a pty (its window's columns and rows, which the process is told by SIGWINCH), and returns the process; refused 409 for a process without one. A process that ended is left as it is, so a retry is safe. */
|
|
59
|
+
resizeProcess(id, process, input, options) {
|
|
60
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/processes/${encodeURIComponent(process)}:resize`, { body: input, options, idempotent: true });
|
|
61
|
+
}
|
|
62
|
+
/** Lists an agent session's processes, newest first: those running and those that ended lately. */
|
|
63
|
+
listProcesses(id, options) {
|
|
64
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}/processes`, { options, idempotent: true });
|
|
65
|
+
}
|
|
66
|
+
/** Removes a file, a link or a directory (recursive for one with contents). One missing is success, removed false. */
|
|
67
|
+
remove(id, input, options) {
|
|
68
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/files:remove`, { body: input, options });
|
|
69
|
+
}
|
|
70
|
+
/** Returns what is at a path: a file, a directory or a link, or nothing (exists false). With sha256=true, a file's SHA-256 too. */
|
|
71
|
+
stat(id, query, options) {
|
|
72
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}/files/stat`, { query: { ...query }, options, idempotent: true });
|
|
73
|
+
}
|
|
74
|
+
/** Lists a directory's entries in path order, to a depth. */
|
|
75
|
+
listFiles(id, query = {}, options) {
|
|
76
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}/files/list`, { query: { ...query }, options, idempotent: true });
|
|
77
|
+
}
|
|
78
|
+
/** Returns a folder as a tar archive (`application/x-tar`, or `application/gzip` with gzip), packed by tar in the agent.session as it streams, of any size; its entries are relative to the folder (`./a.txt`). A folder that fails part way (a file it may not read, or one that changes as it is read) ends as an archive every tar reader refuses, never as a short one that reads whole. At most 4 at once in an agent session. A paused agent.session is woken first. */
|
|
79
|
+
downloadFolder(id, query, options) {
|
|
80
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}/files/archive`, { query: { ...query }, raw: true, options, idempotent: true });
|
|
81
|
+
}
|
|
82
|
+
/** Unpacks the request's tar archive (gzip-compressed or not, told by its first bytes) into a folder, made with its parents, by tar in the agent.session as the bytes arrive, of any size, nothing of it kept on disk but what tar writes; returns once tar has ended, or 400 `invalid_archive` with what tar said. A paused agent.session is woken first. */
|
|
83
|
+
uploadFolder(id, data, query, options) {
|
|
84
|
+
return this.transport.request("PUT", `/v2/agent-sessions/${encodeURIComponent(id)}/files/archive`, { data: toBytes(data), query: { ...query }, options, idempotent: true });
|
|
85
|
+
}
|
|
86
|
+
/** Begins a folder's upload in parts: tar starts in the agent.session, unpacking into the folder each part as it arrives. Send the parts in order by offset (writeFolderUpload), then commitFolderUpload; an upload no call names for 10 minutes is ended. A paused agent.session is woken first. */
|
|
87
|
+
beginFolderUpload(id, input, options) {
|
|
88
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/files/archive/uploads`, { body: input, options });
|
|
89
|
+
}
|
|
90
|
+
/** Sends the request's bytes, a part of the archive at its offset, into tar's input as they arrive, of any size, and returns the bytes received in all once tar took them. A part past them is refused 409 `upload_incomplete`, naming them: send the parts in order. */
|
|
91
|
+
writeFolderUpload(id, upload, data, query = {}, options) {
|
|
92
|
+
return this.transport.request("PUT", `/v2/agent-sessions/${encodeURIComponent(id)}/files/archive/uploads/${encodeURIComponent(upload)}`, { data: toBytes(data), query: { ...query }, options, idempotent: true });
|
|
93
|
+
}
|
|
94
|
+
/** Ends a folder upload's input and returns once tar has ended, as an exec returns once its command has: the folder, or 400 `invalid_archive` with what tar said. A front that restarts meanwhile returns 503 `run_goes_on`; sent again, it returns how tar ended. An upload no call has named for 10 minutes since its last part or commit is ended. */
|
|
95
|
+
commitFolderUpload(id, upload, options) {
|
|
96
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/files/archive/uploads/${encodeURIComponent(upload)}:commit`, { options, idempotent: true });
|
|
97
|
+
}
|
|
98
|
+
/** Stops a folder upload's tar; what it unpacked so far stays. */
|
|
99
|
+
abortFolderUpload(id, upload, options) {
|
|
100
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/files/archive/uploads/${encodeURIComponent(upload)}:abort`, { options, idempotent: true });
|
|
101
|
+
}
|
|
102
|
+
/** Makes a directory, and its parents unless parents is false. One there already is success, created false. */
|
|
103
|
+
mkdir(id, input, options) {
|
|
104
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/files:mkdir`, { body: input, options, idempotent: true });
|
|
105
|
+
}
|
|
106
|
+
/** Moves a file, a link or a directory; refused 409 when something is at its new path, unless overwrite. With sha256 or size, a file written in parts is put in place once whole: its writes ended, then only a file of that size with every byte written and whose bytes hash to it moves; refused 409 `upload_incomplete` or `checksum_mismatch`, nothing moved. With sha256, it is safe to send again: once moved, it returns the same answer while `from` is gone and `to` holds those bytes. */
|
|
107
|
+
rename(id, input, options) {
|
|
108
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/files:rename`, { body: input, options });
|
|
109
|
+
}
|
|
110
|
+
/** Makes an expiring address for one file that anyone may open with no API key, from a browser, curl or another service: GET downloads it (Range works, so videos play and downloads resume; archive: true downloads a folder as .tar.gz), PUT with the raw body uploads it (up to maxBytes, written whole; Content-Length required). The link acts as the key that made it: an upload link needs write, and the link ends with its key, with revokeLinks or with its agent.session. A paused agent.session is woken for it unless wake is false. */
|
|
111
|
+
link(id, input, options) {
|
|
112
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/files:link`, { body: input, options });
|
|
113
|
+
}
|
|
114
|
+
/** Ends every file link made for an agent session so far; links made after work. */
|
|
115
|
+
revokeLinks(id, options) {
|
|
116
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}/files:revokeLinks`, { options });
|
|
117
|
+
}
|
|
118
|
+
/** Returns where an agent session may connect out. */
|
|
119
|
+
getNetwork(id, options) {
|
|
120
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}/network`, { options, idempotent: true });
|
|
121
|
+
}
|
|
122
|
+
/** Returns an agent session's CPU, memory, disks and pressure, as its host reads them from the agent.session's own cgroup over a fifth of a second: never a call into the agent.session, so it does not wake a paused one nor keep one from its idle pause. One that is not running has no reading. */
|
|
123
|
+
metrics(id, query = {}, options) {
|
|
124
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}/metrics`, { query: { ...query }, options, idempotent: true });
|
|
125
|
+
}
|
|
126
|
+
/** Replaces where an agent session may connect out, for its next connection and within a second for its open ones: those the new rules refuse are cut. */
|
|
127
|
+
setNetwork(id, input = {}, options) {
|
|
128
|
+
return this.transport.request("PUT", `/v2/agent-sessions/${encodeURIComponent(id)}/network`, { body: input, options });
|
|
129
|
+
}
|
|
130
|
+
/** Copies an agent session as it is now, memory and disk, into `count` copies of its own, each running on its host. Asked again with the same Idempotency-Key, it returns the same copies. */
|
|
131
|
+
fork(id, input = {}, options) {
|
|
132
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}:fork`, { body: input, options, idempotent: true });
|
|
133
|
+
}
|
|
134
|
+
/** Keeps an agent session's memory and disk as they are now, a snapshot to start agent-sessions from; with `image`, its disk alone as that image's next version. The agent.session runs on. Asked again with the same Idempotency-Key, it returns the same snapshot. */
|
|
135
|
+
snapshot(id, input = {}, options) {
|
|
136
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}:snapshot`, { body: input, options, idempotent: true });
|
|
137
|
+
}
|
|
138
|
+
/** Changes its name, labels, idle pause, maxCost, autoWake, lifetime, delete protection, environment or sizes; each field left out stays as it is. A lifetime (`deleteAfterSeconds`) sent again before its end moves the end to that many seconds from now; 0 takes it off. A lifetime is refused (409 `delete_protected`) while `deleteProtection` is true. A running one holds a changed environment before this answers (a paused one's at its wake): each process it starts after the answer has it, and its running processes keep the one they started with. Its vCPUs, memory and disk grow while it runs, its commands running on. One paused or stopped is not woken for it: judged at once as a live resize is (past the vCPUs it was made with 409, over its organization's limits `quota_exceeded`), its new sizes are returned at once, and its next wake grows it to them before the call that woke it runs. A smaller size, or a machine starting or failed, is refused 409 naming why, and nothing is changed. With If-Match, made only while its revision is that one, else 412. Sent again with the same Idempotency-Key and body while it is the latest change, it returns the current state and changes nothing; the same key with a different body returns 409 idempotency_key_reused. */
|
|
139
|
+
update(id, input = {}, options) {
|
|
140
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}:update`, { body: input, options });
|
|
141
|
+
}
|
|
142
|
+
/** Returns what an agent session's screen shows now, as `image/png` (or `image/jpeg`): its X display `:1`, whole. Refused 409 `display_not_running` when no display runs. A paused agent.session is resumed first. */
|
|
143
|
+
screenshot(id, query = {}, options) {
|
|
144
|
+
return this.transport.request("GET", `/v2/agent-sessions/${encodeURIComponent(id)}/screenshot`, { query: { ...query }, raw: true, options, idempotent: true });
|
|
145
|
+
}
|
|
146
|
+
/** Moves, clicks, drags and scrolls the mouse and types on the keyboard of an agent session's screen (its X display `:1`), each step in turn as one command, and returns where the mouse is then. It stops at the first step that fails, refused 409 `act_failed` naming it; refused 409 `display_not_running` when no display runs. A paused agent.session is resumed first. */
|
|
147
|
+
act(id, input, options) {
|
|
148
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}:act`, { body: input, options });
|
|
149
|
+
}
|
|
150
|
+
/** Runs a cell of Python in an agent session as a notebook does, in a Jupyter kernel it keeps running for the cell's `context`: variables, imports and functions stay for the next cell. Returns what it printed, its values and displays (text, HTML, images such as charts), and its exception with its traceback. The context's kernel starts on its first cell. A cell past `timeoutSeconds` is interrupted and its context kept. Refused 409 `kernel_not_installed` when the image has no ipykernel. A paused agent.session is resumed first. */
|
|
151
|
+
runCode(id, input, options) {
|
|
152
|
+
return this.transport.request("POST", `/v2/agent-sessions/${encodeURIComponent(id)}:runCode`, { body: input, options });
|
|
153
|
+
}
|
|
154
|
+
}
|