withruntime 0.27.1 → 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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/withruntime/generated/apps.rb +192 -0
  3. data/lib/withruntime/generated/audit.rb +78 -0
  4. data/lib/withruntime/generated/browsers.rb +192 -0
  5. data/lib/withruntime/generated/builds.rb +192 -0
  6. data/lib/withruntime/generated/ci.rb +192 -0
  7. data/lib/withruntime/generated/containers.rb +192 -0
  8. data/lib/withruntime/generated/desktops.rb +192 -0
  9. data/lib/withruntime/generated/domains.rb +152 -0
  10. data/lib/withruntime/generated/egress_ips.rb +81 -0
  11. data/lib/withruntime/generated/events.rb +60 -0
  12. data/lib/withruntime/generated/feedback.rb +96 -0
  13. data/lib/withruntime/generated/functions.rb +192 -0
  14. data/lib/withruntime/generated/identities.rb +68 -0
  15. data/lib/withruntime/generated/images.rb +391 -0
  16. data/lib/withruntime/generated/job_runs.rb +110 -0
  17. data/lib/withruntime/generated/jobs.rb +333 -0
  18. data/lib/withruntime/generated/keys.rb +261 -0
  19. data/lib/withruntime/generated/kit.rb +111 -0
  20. data/lib/withruntime/generated/me.rb +69 -0
  21. data/lib/withruntime/generated/networks.rb +72 -0
  22. data/lib/withruntime/generated/notebooks.rb +192 -0
  23. data/lib/withruntime/generated/otel.rb +94 -0
  24. data/lib/withruntime/generated/ports.rb +118 -0
  25. data/lib/withruntime/generated/previews.rb +124 -0
  26. data/lib/withruntime/generated/projects.rb +108 -0
  27. data/lib/withruntime/generated/roles.rb +68 -0
  28. data/lib/withruntime/generated/routes.rb +11 -0
  29. data/lib/withruntime/generated/runtime.rb +188 -0
  30. data/lib/withruntime/generated/sandboxes.rb +1835 -0
  31. data/lib/withruntime/generated/secrets.rb +294 -0
  32. data/lib/withruntime/generated/sessions.rb +143 -0
  33. data/lib/withruntime/generated/sites.rb +192 -0
  34. data/lib/withruntime/generated/snapshots.rb +32 -0
  35. data/lib/withruntime/generated/tunnels.rb +165 -0
  36. data/lib/withruntime/generated/usage.rb +287 -0
  37. data/lib/withruntime/generated/volumes.rb +61 -0
  38. data/lib/withruntime/generated/webhooks.rb +91 -0
  39. data/lib/withruntime/generated/workspaces.rb +192 -0
  40. data/lib/withruntime/signing.rb +162 -0
  41. data/lib/withruntime/version.rb +2 -2
  42. data/lib/withruntime.rb +5 -43
  43. metadata +45 -35
  44. data/lib/withruntime/agents.rb +0 -877
  45. data/lib/withruntime/api_defaults.rb +0 -17
  46. data/lib/withruntime/apps.rb +0 -377
  47. data/lib/withruntime/browsers.rb +0 -104
  48. data/lib/withruntime/builds.rb +0 -218
  49. data/lib/withruntime/ci.rb +0 -164
  50. data/lib/withruntime/client.rb +0 -140
  51. data/lib/withruntime/containers.rb +0 -39
  52. data/lib/withruntime/credentials.rb +0 -111
  53. data/lib/withruntime/fields.rb +0 -40
  54. data/lib/withruntime/file_watch.rb +0 -73
  55. data/lib/withruntime/images.rb +0 -258
  56. data/lib/withruntime/network_products.rb +0 -49
  57. data/lib/withruntime/parity_products.rb +0 -51
  58. data/lib/withruntime/products.rb +0 -560
  59. data/lib/withruntime/record.rb +0 -99
  60. data/lib/withruntime/reservations.rb +0 -76
  61. data/lib/withruntime/sandbox.rb +0 -770
  62. data/lib/withruntime/tar.rb +0 -292
  63. data/lib/withruntime/transport.rb +0 -575
  64. data/lib/withruntime/tunnel.rb +0 -275
  65. data/lib/withruntime/wallet.rb +0 -68
  66. data/lib/withruntime/websocket.rb +0 -384
@@ -0,0 +1,192 @@
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
+
4
+ require "uri"
5
+ require_relative "runtime"
6
+ require_relative "sandboxes"
7
+
8
+ module Withruntime
9
+ module Generated
10
+ # The machine an image's build runs on: Docker's own builder (BuildKit), its run `runtime-image-build`, deleted once its image is made. Made by an image's create, and billed as any machine is, for the CPU it uses and the memory it holds while it builds.
11
+ class Builds
12
+ def initialize(transport)
13
+ @transport = transport
14
+ end
15
+
16
+ # Creates a build. Asked again with the same Idempotency-Key, it returns the same build.
17
+ def create(vcpu: nil, memory_gb: nil, disk_gb: nil, image: nil, secrets: nil, start: nil, user: nil, volumes: nil, run: nil, name: nil, labels: nil, get_or_create: nil, max_cost: nil, idle_pause_seconds: nil, snapshot: nil, network: nil, env: nil, idempotency_key: nil)
18
+ Sandbox.from(@transport.request("POST", "/v2/builds", body: { "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "image" => image, "secrets" => secrets, "start" => start, "user" => user, "volumes" => volumes, "run" => run, "name" => name, "labels" => labels, "getOrCreate" => get_or_create, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds, "snapshot" => snapshot, "network" => network, "env" => env }.compact, idempotency_key: idempotency_key, idempotent: true))
19
+ end
20
+
21
+ # Returns a build.
22
+ def get(id, wait: nil, if_state: nil)
23
+ Sandbox.from(@transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}", query: { "wait" => wait, "ifState" => if_state }, idempotent: true))
24
+ end
25
+
26
+ # Lists the project's builds, newest first.
27
+ def list(state: nil, name: nil, label: nil, cursor: nil, limit: nil)
28
+ Generated.page(@transport.request("GET", "/v2/builds", query: { "state" => state, "name" => name, "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Sandbox.from(i) }
29
+ end
30
+
31
+ # Deletes a build, its memory and its disk.
32
+ def delete(id, idempotency_key: nil)
33
+ Sandbox.from(@transport.request("DELETE", "/v2/builds/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key))
34
+ end
35
+
36
+ # Pauses a build with its memory and disk kept. A call to it resumes it.
37
+ def pause(id, idempotency_key: nil)
38
+ Sandbox.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}:pause", idempotency_key: idempotency_key))
39
+ end
40
+
41
+ # Resumes a paused build where it was, its memory and processes as they were.
42
+ def resume(id, idempotency_key: nil)
43
+ Sandbox.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}:resume", idempotency_key: idempotency_key))
44
+ end
45
+
46
+ # 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 build 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.
47
+ def exec(id, cmd:, cwd: nil, env: nil, stdin: nil, timeout_seconds: nil, stream: nil, wait: nil, stdin_open: nil, output_encoding: nil, pty: nil, user: nil, idempotency_key: nil)
48
+ Process.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}:exec", body: { "cmd" => cmd, "cwd" => cwd, "env" => env, "stdin" => stdin, "timeoutSeconds" => timeout_seconds, "stream" => stream, "wait" => wait, "stdinOpen" => stdin_open, "outputEncoding" => output_encoding, "pty" => pty, "user" => user }.compact, idempotency_key: idempotency_key, idempotent: true, runs: true, runs_seconds: timeout_seconds))
49
+ end
50
+
51
+ # Returns a file's bytes.
52
+ def read(id, path:)
53
+ @transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}/files", query: { "path" => path }, raw: true, idempotent: true)
54
+ end
55
+
56
+ # 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.
57
+ def write(id, data, path:, mode: nil, offset: nil, sha256: nil, idempotency_key: nil)
58
+ FileWritten.from(@transport.request("PUT", "/v2/builds/#{URI.encode_www_form_component(id)}/files", query: { "path" => path, "mode" => mode, "offset" => offset, "sha256" => sha256 }, data: data, idempotency_key: idempotency_key))
59
+ end
60
+
61
+ # 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.
62
+ def process_output(id, process, cursor: nil, wait_seconds: nil, max_bytes: nil, follow: nil)
63
+ ProcessOutput.from(@transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}/output", query: { "cursor" => cursor, "waitSeconds" => wait_seconds, "maxBytes" => max_bytes, "follow" => follow }, idempotent: true))
64
+ end
65
+
66
+ # Sends input to a process started with stdinOpen or a pty, and returns how much of its input it has taken.
67
+ def write_process(id, process, data: nil, offset: nil, eof: nil, idempotency_key: nil)
68
+ ProcessWritten.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:write", body: { "data" => data, "offset" => offset, "eof" => eof }.compact, idempotency_key: idempotency_key))
69
+ end
70
+
71
+ # Sends a signal to a process and its group; a process that ended is not signalled, so a retry is safe.
72
+ def signal_process(id, process, signal: nil, idempotency_key: nil)
73
+ Process.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:signal", body: { "signal" => signal }.compact, idempotency_key: idempotency_key, idempotent: true))
74
+ end
75
+
76
+ # Lists a build's processes, newest first: those running and those that ended lately.
77
+ def list_processes(id)
78
+ ProcessList.from(@transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}/processes", idempotent: true))
79
+ end
80
+
81
+ # Removes a file, a link or a directory (recursive for one with contents). One missing is success, removed false.
82
+ def remove(id, path:, recursive: nil, idempotency_key: nil)
83
+ FileRemoved.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/files:remove", body: { "path" => path, "recursive" => recursive }.compact, idempotency_key: idempotency_key))
84
+ end
85
+
86
+ # 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.
87
+ def stat(id, path:, sha256: nil)
88
+ FileInfo.from(@transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}/files/stat", query: { "path" => path, "sha256" => sha256 }, idempotent: true))
89
+ end
90
+
91
+ # Lists a directory's entries in path order, to a depth.
92
+ def list_files(id, path: nil, depth: nil, limit: nil, hidden: nil, glob: nil)
93
+ FileList.from(@transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}/files/list", query: { "path" => path, "depth" => depth, "limit" => limit, "hidden" => hidden, "glob" => glob }, idempotent: true))
94
+ end
95
+
96
+ # Returns a folder as a tar archive (`application/x-tar`, or `application/gzip` with gzip), packed by tar in the build 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 a build. A paused build is woken first.
97
+ def download_folder(id, path:, gzip: nil, user: nil, exclude: nil)
98
+ @transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "gzip" => gzip, "user" => user, "exclude" => exclude }, raw: true, idempotent: true)
99
+ end
100
+
101
+ # 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 build 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 build is woken first.
102
+ def upload_folder(id, data, path:, user: nil, idempotency_key: nil)
103
+ FolderUnpacked.from(@transport.request("PUT", "/v2/builds/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "user" => user }, data: data, idempotency_key: idempotency_key, idempotent: true))
104
+ end
105
+
106
+ # Begins a folder's upload in parts: tar starts in the build, 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 build is woken first.
107
+ def begin_folder_upload(id, path:, gzip: nil, user: nil, idempotency_key: nil)
108
+ FolderUpload.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/files/archive/uploads", body: { "path" => path, "gzip" => gzip, "user" => user }.compact, idempotency_key: idempotency_key))
109
+ end
110
+
111
+ # 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.
112
+ def write_folder_upload(id, upload, data, offset: nil, idempotency_key: nil)
113
+ FolderUploadReceived.from(@transport.request("PUT", "/v2/builds/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}", query: { "offset" => offset }, data: data, idempotency_key: idempotency_key, idempotent: true))
114
+ end
115
+
116
+ # 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.
117
+ def commit_folder_upload(id, upload, idempotency_key: nil)
118
+ FolderUnpacked.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:commit", idempotency_key: idempotency_key, idempotent: true))
119
+ end
120
+
121
+ # Stops a folder upload's tar; what it unpacked so far stays.
122
+ def abort_folder_upload(id, upload, idempotency_key: nil)
123
+ FolderUploadAborted.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:abort", idempotency_key: idempotency_key, idempotent: true))
124
+ end
125
+
126
+ # Makes a directory, and its parents unless parents is false. One there already is success, created false.
127
+ def mkdir(id, path:, parents: nil, idempotency_key: nil)
128
+ FileMade.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/files:mkdir", body: { "path" => path, "parents" => parents }.compact, idempotency_key: idempotency_key, idempotent: true))
129
+ end
130
+
131
+ # 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.
132
+ def rename(id, from:, to:, overwrite: nil, sha256: nil, size: nil, idempotency_key: nil)
133
+ FileRenamed.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/files:rename", body: { "from" => from, "to" => to, "overwrite" => overwrite, "sha256" => sha256, "size" => size }.compact, idempotency_key: idempotency_key))
134
+ end
135
+
136
+ # 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 build. A paused build is woken for it unless wake is false.
137
+ def link(id, path:, method: nil, expires_in_seconds: nil, filename: nil, max_bytes: nil, wake: nil, archive: nil, idempotency_key: nil)
138
+ FileLink.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/files:link", body: { "path" => path, "method" => method, "expiresInSeconds" => expires_in_seconds, "filename" => filename, "maxBytes" => max_bytes, "wake" => wake, "archive" => archive }.compact, idempotency_key: idempotency_key))
139
+ end
140
+
141
+ # Ends every file link made for a build so far; links made after work.
142
+ def revoke_links(id, idempotency_key: nil)
143
+ FileLinksRevoked.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}/files:revokeLinks", idempotency_key: idempotency_key))
144
+ end
145
+
146
+ # Returns where a build may connect out.
147
+ def get_network(id)
148
+ SandboxNetwork.from(@transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}/network", idempotent: true))
149
+ end
150
+
151
+ # Returns a build's CPU, memory, disks and pressure, as its host reads them from the build's own cgroup over a fifth of a second: never a call into the build, so it does not wake a paused one nor keep one from its idle pause. One that is not running has no reading.
152
+ def metrics(id, range: nil)
153
+ SandboxMetrics.from(@transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}/metrics", query: { "range" => range }, idempotent: true))
154
+ end
155
+
156
+ # Replaces where a build may connect out, for its next connection and within a second for its open ones: those the new rules refuse are cut.
157
+ def set_network(id, allow_outbound: nil, deny_outbound: nil, idempotency_key: nil)
158
+ SandboxNetwork.from(@transport.request("PUT", "/v2/builds/#{URI.encode_www_form_component(id)}/network", body: { "allowOutbound" => allow_outbound, "denyOutbound" => deny_outbound }.compact, idempotency_key: idempotency_key))
159
+ end
160
+
161
+ # Copies a build 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.
162
+ def fork(id, count: nil, name: nil, labels: nil, secrets: nil, max_cost: nil, idle_pause_seconds: nil, idempotency_key: nil)
163
+ Forked.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}:fork", body: { "count" => count, "name" => name, "labels" => labels, "secrets" => secrets, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds }.compact, idempotency_key: idempotency_key, idempotent: true))
164
+ end
165
+
166
+ # Keeps a build's memory and disk as they are now, a snapshot to start builds from; with `image`, its disk alone as that image's next version. The build runs on. Asked again with the same Idempotency-Key, it returns the same snapshot.
167
+ def snapshot(id, name: nil, labels: nil, image: nil, start: nil, idempotency_key: nil)
168
+ Stored.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}:snapshot", body: { "name" => name, "labels" => labels, "image" => image, "start" => start }.compact, idempotency_key: idempotency_key, idempotent: true))
169
+ end
170
+
171
+ # Changes its name, labels, idle pause, maxCost, environment or sizes; each field left out stays as it is. 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; a smaller size, or a sandbox that is not running, is refused 409 naming why, and nothing is changed. With If-Match, made only while its revision is that one, else 412.
172
+ def update(id, name: nil, labels: nil, idle_pause_seconds: nil, vcpu: nil, memory_gb: nil, disk_gb: nil, user: nil, env: nil, remove_env: nil, max_cost: nil, idempotency_key: nil)
173
+ Sandbox.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}:update", body: { "name" => name, "labels" => labels, "idlePauseSeconds" => idle_pause_seconds, "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "user" => user, "env" => env, "removeEnv" => remove_env, "maxCost" => max_cost }.compact, idempotency_key: idempotency_key))
174
+ end
175
+
176
+ # Returns what a build'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 build is resumed first.
177
+ def screenshot(id, format: nil, quality: nil)
178
+ @transport.request("GET", "/v2/builds/#{URI.encode_www_form_component(id)}/screenshot", query: { "format" => format, "quality" => quality }, raw: true, idempotent: true)
179
+ end
180
+
181
+ # Moves, clicks, drags and scrolls the mouse and types on the keyboard of a build'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 build is resumed first.
182
+ def act(id, actions:, idempotency_key: nil)
183
+ Acted.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}:act", body: { "actions" => actions }.compact, idempotency_key: idempotency_key))
184
+ end
185
+
186
+ # Runs a cell of Python in a build 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 build is resumed first.
187
+ def run_code(id, code:, language: nil, context: nil, timeout_seconds: nil, idempotency_key: nil)
188
+ CodeRun.from(@transport.request("POST", "/v2/builds/#{URI.encode_www_form_component(id)}:runCode", body: { "code" => code, "language" => language, "context" => context, "timeoutSeconds" => timeout_seconds }.compact, idempotency_key: idempotency_key))
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,192 @@
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
+
4
+ require "uri"
5
+ require_relative "runtime"
6
+ require_relative "sandboxes"
7
+
8
+ module Withruntime
9
+ module Generated
10
+ # 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. As an Actions runner, it starts GitHub's runner for the one job of its just-in-time configuration (`run` `runtime-runner`, `RUNNER_JITCONFIG` in its environment) and stops with it; a job of a GitHub account connected through Runtime's GitHub App gets one by itself.
11
+ class Ci
12
+ def initialize(transport)
13
+ @transport = transport
14
+ end
15
+
16
+ # Creates a CI machine. Asked again with the same Idempotency-Key, it returns the same ci.
17
+ def create(vcpu: nil, memory_gb: nil, disk_gb: nil, image: nil, secrets: nil, start: nil, user: nil, volumes: nil, run: nil, name: nil, labels: nil, get_or_create: nil, max_cost: nil, idle_pause_seconds: nil, snapshot: nil, network: nil, env: nil, idempotency_key: nil)
18
+ Sandbox.from(@transport.request("POST", "/v2/ci", body: { "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "image" => image, "secrets" => secrets, "start" => start, "user" => user, "volumes" => volumes, "run" => run, "name" => name, "labels" => labels, "getOrCreate" => get_or_create, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds, "snapshot" => snapshot, "network" => network, "env" => env }.compact, idempotency_key: idempotency_key, idempotent: true))
19
+ end
20
+
21
+ # Returns a CI machine.
22
+ def get(id, wait: nil, if_state: nil)
23
+ Sandbox.from(@transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}", query: { "wait" => wait, "ifState" => if_state }, idempotent: true))
24
+ end
25
+
26
+ # Lists the project's ci, newest first.
27
+ def list(state: nil, name: nil, label: nil, cursor: nil, limit: nil)
28
+ Generated.page(@transport.request("GET", "/v2/ci", query: { "state" => state, "name" => name, "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Sandbox.from(i) }
29
+ end
30
+
31
+ # Deletes a CI machine, its memory and its disk.
32
+ def delete(id, idempotency_key: nil)
33
+ Sandbox.from(@transport.request("DELETE", "/v2/ci/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key))
34
+ end
35
+
36
+ # Pauses a CI machine with its memory and disk kept. A call to it resumes it.
37
+ def pause(id, idempotency_key: nil)
38
+ Sandbox.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}:pause", idempotency_key: idempotency_key))
39
+ end
40
+
41
+ # Resumes a paused ci where it was, its memory and processes as they were.
42
+ def resume(id, idempotency_key: nil)
43
+ Sandbox.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}:resume", idempotency_key: idempotency_key))
44
+ end
45
+
46
+ # 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 ci 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.
47
+ def exec(id, cmd:, cwd: nil, env: nil, stdin: nil, timeout_seconds: nil, stream: nil, wait: nil, stdin_open: nil, output_encoding: nil, pty: nil, user: nil, idempotency_key: nil)
48
+ Process.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}:exec", body: { "cmd" => cmd, "cwd" => cwd, "env" => env, "stdin" => stdin, "timeoutSeconds" => timeout_seconds, "stream" => stream, "wait" => wait, "stdinOpen" => stdin_open, "outputEncoding" => output_encoding, "pty" => pty, "user" => user }.compact, idempotency_key: idempotency_key, idempotent: true, runs: true, runs_seconds: timeout_seconds))
49
+ end
50
+
51
+ # Returns a file's bytes.
52
+ def read(id, path:)
53
+ @transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}/files", query: { "path" => path }, raw: true, idempotent: true)
54
+ end
55
+
56
+ # 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.
57
+ def write(id, data, path:, mode: nil, offset: nil, sha256: nil, idempotency_key: nil)
58
+ FileWritten.from(@transport.request("PUT", "/v2/ci/#{URI.encode_www_form_component(id)}/files", query: { "path" => path, "mode" => mode, "offset" => offset, "sha256" => sha256 }, data: data, idempotency_key: idempotency_key))
59
+ end
60
+
61
+ # 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.
62
+ def process_output(id, process, cursor: nil, wait_seconds: nil, max_bytes: nil, follow: nil)
63
+ ProcessOutput.from(@transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}/output", query: { "cursor" => cursor, "waitSeconds" => wait_seconds, "maxBytes" => max_bytes, "follow" => follow }, idempotent: true))
64
+ end
65
+
66
+ # Sends input to a process started with stdinOpen or a pty, and returns how much of its input it has taken.
67
+ def write_process(id, process, data: nil, offset: nil, eof: nil, idempotency_key: nil)
68
+ ProcessWritten.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:write", body: { "data" => data, "offset" => offset, "eof" => eof }.compact, idempotency_key: idempotency_key))
69
+ end
70
+
71
+ # Sends a signal to a process and its group; a process that ended is not signalled, so a retry is safe.
72
+ def signal_process(id, process, signal: nil, idempotency_key: nil)
73
+ Process.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:signal", body: { "signal" => signal }.compact, idempotency_key: idempotency_key, idempotent: true))
74
+ end
75
+
76
+ # Lists a CI machine's processes, newest first: those running and those that ended lately.
77
+ def list_processes(id)
78
+ ProcessList.from(@transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}/processes", idempotent: true))
79
+ end
80
+
81
+ # Removes a file, a link or a directory (recursive for one with contents). One missing is success, removed false.
82
+ def remove(id, path:, recursive: nil, idempotency_key: nil)
83
+ FileRemoved.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/files:remove", body: { "path" => path, "recursive" => recursive }.compact, idempotency_key: idempotency_key))
84
+ end
85
+
86
+ # 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.
87
+ def stat(id, path:, sha256: nil)
88
+ FileInfo.from(@transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}/files/stat", query: { "path" => path, "sha256" => sha256 }, idempotent: true))
89
+ end
90
+
91
+ # Lists a directory's entries in path order, to a depth.
92
+ def list_files(id, path: nil, depth: nil, limit: nil, hidden: nil, glob: nil)
93
+ FileList.from(@transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}/files/list", query: { "path" => path, "depth" => depth, "limit" => limit, "hidden" => hidden, "glob" => glob }, idempotent: true))
94
+ end
95
+
96
+ # Returns a folder as a tar archive (`application/x-tar`, or `application/gzip` with gzip), packed by tar in the ci 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 a CI machine. A paused ci is woken first.
97
+ def download_folder(id, path:, gzip: nil, user: nil, exclude: nil)
98
+ @transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "gzip" => gzip, "user" => user, "exclude" => exclude }, raw: true, idempotent: true)
99
+ end
100
+
101
+ # 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 ci 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 ci is woken first.
102
+ def upload_folder(id, data, path:, user: nil, idempotency_key: nil)
103
+ FolderUnpacked.from(@transport.request("PUT", "/v2/ci/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "user" => user }, data: data, idempotency_key: idempotency_key, idempotent: true))
104
+ end
105
+
106
+ # Begins a folder's upload in parts: tar starts in the ci, 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 ci is woken first.
107
+ def begin_folder_upload(id, path:, gzip: nil, user: nil, idempotency_key: nil)
108
+ FolderUpload.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/files/archive/uploads", body: { "path" => path, "gzip" => gzip, "user" => user }.compact, idempotency_key: idempotency_key))
109
+ end
110
+
111
+ # 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.
112
+ def write_folder_upload(id, upload, data, offset: nil, idempotency_key: nil)
113
+ FolderUploadReceived.from(@transport.request("PUT", "/v2/ci/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}", query: { "offset" => offset }, data: data, idempotency_key: idempotency_key, idempotent: true))
114
+ end
115
+
116
+ # 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.
117
+ def commit_folder_upload(id, upload, idempotency_key: nil)
118
+ FolderUnpacked.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:commit", idempotency_key: idempotency_key, idempotent: true))
119
+ end
120
+
121
+ # Stops a folder upload's tar; what it unpacked so far stays.
122
+ def abort_folder_upload(id, upload, idempotency_key: nil)
123
+ FolderUploadAborted.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:abort", idempotency_key: idempotency_key, idempotent: true))
124
+ end
125
+
126
+ # Makes a directory, and its parents unless parents is false. One there already is success, created false.
127
+ def mkdir(id, path:, parents: nil, idempotency_key: nil)
128
+ FileMade.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/files:mkdir", body: { "path" => path, "parents" => parents }.compact, idempotency_key: idempotency_key, idempotent: true))
129
+ end
130
+
131
+ # 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.
132
+ def rename(id, from:, to:, overwrite: nil, sha256: nil, size: nil, idempotency_key: nil)
133
+ FileRenamed.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/files:rename", body: { "from" => from, "to" => to, "overwrite" => overwrite, "sha256" => sha256, "size" => size }.compact, idempotency_key: idempotency_key))
134
+ end
135
+
136
+ # 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 ci. A paused ci is woken for it unless wake is false.
137
+ def link(id, path:, method: nil, expires_in_seconds: nil, filename: nil, max_bytes: nil, wake: nil, archive: nil, idempotency_key: nil)
138
+ FileLink.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/files:link", body: { "path" => path, "method" => method, "expiresInSeconds" => expires_in_seconds, "filename" => filename, "maxBytes" => max_bytes, "wake" => wake, "archive" => archive }.compact, idempotency_key: idempotency_key))
139
+ end
140
+
141
+ # Ends every file link made for a CI machine so far; links made after work.
142
+ def revoke_links(id, idempotency_key: nil)
143
+ FileLinksRevoked.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}/files:revokeLinks", idempotency_key: idempotency_key))
144
+ end
145
+
146
+ # Returns where a CI machine may connect out.
147
+ def get_network(id)
148
+ SandboxNetwork.from(@transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}/network", idempotent: true))
149
+ end
150
+
151
+ # Returns a CI machine's CPU, memory, disks and pressure, as its host reads them from the ci's own cgroup over a fifth of a second: never a call into the ci, so it does not wake a paused one nor keep one from its idle pause. One that is not running has no reading.
152
+ def metrics(id, range: nil)
153
+ SandboxMetrics.from(@transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}/metrics", query: { "range" => range }, idempotent: true))
154
+ end
155
+
156
+ # Replaces where a CI machine may connect out, for its next connection and within a second for its open ones: those the new rules refuse are cut.
157
+ def set_network(id, allow_outbound: nil, deny_outbound: nil, idempotency_key: nil)
158
+ SandboxNetwork.from(@transport.request("PUT", "/v2/ci/#{URI.encode_www_form_component(id)}/network", body: { "allowOutbound" => allow_outbound, "denyOutbound" => deny_outbound }.compact, idempotency_key: idempotency_key))
159
+ end
160
+
161
+ # Copies a CI machine 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.
162
+ def fork(id, count: nil, name: nil, labels: nil, secrets: nil, max_cost: nil, idle_pause_seconds: nil, idempotency_key: nil)
163
+ Forked.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}:fork", body: { "count" => count, "name" => name, "labels" => labels, "secrets" => secrets, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds }.compact, idempotency_key: idempotency_key, idempotent: true))
164
+ end
165
+
166
+ # Keeps a CI machine's memory and disk as they are now, a snapshot to start ci from; with `image`, its disk alone as that image's next version. The ci runs on. Asked again with the same Idempotency-Key, it returns the same snapshot.
167
+ def snapshot(id, name: nil, labels: nil, image: nil, start: nil, idempotency_key: nil)
168
+ Stored.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}:snapshot", body: { "name" => name, "labels" => labels, "image" => image, "start" => start }.compact, idempotency_key: idempotency_key, idempotent: true))
169
+ end
170
+
171
+ # Changes its name, labels, idle pause, maxCost, environment or sizes; each field left out stays as it is. 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; a smaller size, or a sandbox that is not running, is refused 409 naming why, and nothing is changed. With If-Match, made only while its revision is that one, else 412.
172
+ def update(id, name: nil, labels: nil, idle_pause_seconds: nil, vcpu: nil, memory_gb: nil, disk_gb: nil, user: nil, env: nil, remove_env: nil, max_cost: nil, idempotency_key: nil)
173
+ Sandbox.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}:update", body: { "name" => name, "labels" => labels, "idlePauseSeconds" => idle_pause_seconds, "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "user" => user, "env" => env, "removeEnv" => remove_env, "maxCost" => max_cost }.compact, idempotency_key: idempotency_key))
174
+ end
175
+
176
+ # Returns what a CI machine'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 ci is resumed first.
177
+ def screenshot(id, format: nil, quality: nil)
178
+ @transport.request("GET", "/v2/ci/#{URI.encode_www_form_component(id)}/screenshot", query: { "format" => format, "quality" => quality }, raw: true, idempotent: true)
179
+ end
180
+
181
+ # Moves, clicks, drags and scrolls the mouse and types on the keyboard of a CI machine'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 ci is resumed first.
182
+ def act(id, actions:, idempotency_key: nil)
183
+ Acted.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}:act", body: { "actions" => actions }.compact, idempotency_key: idempotency_key))
184
+ end
185
+
186
+ # Runs a cell of Python in a CI machine 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 ci is resumed first.
187
+ def run_code(id, code:, language: nil, context: nil, timeout_seconds: nil, idempotency_key: nil)
188
+ CodeRun.from(@transport.request("POST", "/v2/ci/#{URI.encode_www_form_component(id)}:runCode", body: { "code" => code, "language" => language, "context" => context, "timeoutSeconds" => timeout_seconds }.compact, idempotency_key: idempotency_key))
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,192 @@
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
+
4
+ require "uri"
5
+ require_relative "runtime"
6
+ require_relative "sandboxes"
7
+
8
+ module Withruntime
9
+ module Generated
10
+ # 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.
11
+ class Containers
12
+ def initialize(transport)
13
+ @transport = transport
14
+ end
15
+
16
+ # Creates a container. Asked again with the same Idempotency-Key, it returns the same container.
17
+ def create(vcpu: nil, memory_gb: nil, disk_gb: nil, image: nil, secrets: nil, start: nil, user: nil, volumes: nil, run: nil, name: nil, labels: nil, get_or_create: nil, max_cost: nil, idle_pause_seconds: nil, snapshot: nil, network: nil, env: nil, idempotency_key: nil)
18
+ Sandbox.from(@transport.request("POST", "/v2/containers", body: { "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "image" => image, "secrets" => secrets, "start" => start, "user" => user, "volumes" => volumes, "run" => run, "name" => name, "labels" => labels, "getOrCreate" => get_or_create, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds, "snapshot" => snapshot, "network" => network, "env" => env }.compact, idempotency_key: idempotency_key, idempotent: true))
19
+ end
20
+
21
+ # Returns a container.
22
+ def get(id, wait: nil, if_state: nil)
23
+ Sandbox.from(@transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}", query: { "wait" => wait, "ifState" => if_state }, idempotent: true))
24
+ end
25
+
26
+ # Lists the project's containers, newest first.
27
+ def list(state: nil, name: nil, label: nil, cursor: nil, limit: nil)
28
+ Generated.page(@transport.request("GET", "/v2/containers", query: { "state" => state, "name" => name, "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Sandbox.from(i) }
29
+ end
30
+
31
+ # Deletes a container, its memory and its disk.
32
+ def delete(id, idempotency_key: nil)
33
+ Sandbox.from(@transport.request("DELETE", "/v2/containers/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key))
34
+ end
35
+
36
+ # Pauses a container with its memory and disk kept. A call to it resumes it.
37
+ def pause(id, idempotency_key: nil)
38
+ Sandbox.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}:pause", idempotency_key: idempotency_key))
39
+ end
40
+
41
+ # Resumes a paused container where it was, its memory and processes as they were.
42
+ def resume(id, idempotency_key: nil)
43
+ Sandbox.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}:resume", idempotency_key: idempotency_key))
44
+ end
45
+
46
+ # 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 container 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.
47
+ def exec(id, cmd:, cwd: nil, env: nil, stdin: nil, timeout_seconds: nil, stream: nil, wait: nil, stdin_open: nil, output_encoding: nil, pty: nil, user: nil, idempotency_key: nil)
48
+ Process.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}:exec", body: { "cmd" => cmd, "cwd" => cwd, "env" => env, "stdin" => stdin, "timeoutSeconds" => timeout_seconds, "stream" => stream, "wait" => wait, "stdinOpen" => stdin_open, "outputEncoding" => output_encoding, "pty" => pty, "user" => user }.compact, idempotency_key: idempotency_key, idempotent: true, runs: true, runs_seconds: timeout_seconds))
49
+ end
50
+
51
+ # Returns a file's bytes.
52
+ def read(id, path:)
53
+ @transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}/files", query: { "path" => path }, raw: true, idempotent: true)
54
+ end
55
+
56
+ # 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.
57
+ def write(id, data, path:, mode: nil, offset: nil, sha256: nil, idempotency_key: nil)
58
+ FileWritten.from(@transport.request("PUT", "/v2/containers/#{URI.encode_www_form_component(id)}/files", query: { "path" => path, "mode" => mode, "offset" => offset, "sha256" => sha256 }, data: data, idempotency_key: idempotency_key))
59
+ end
60
+
61
+ # 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.
62
+ def process_output(id, process, cursor: nil, wait_seconds: nil, max_bytes: nil, follow: nil)
63
+ ProcessOutput.from(@transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}/output", query: { "cursor" => cursor, "waitSeconds" => wait_seconds, "maxBytes" => max_bytes, "follow" => follow }, idempotent: true))
64
+ end
65
+
66
+ # Sends input to a process started with stdinOpen or a pty, and returns how much of its input it has taken.
67
+ def write_process(id, process, data: nil, offset: nil, eof: nil, idempotency_key: nil)
68
+ ProcessWritten.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:write", body: { "data" => data, "offset" => offset, "eof" => eof }.compact, idempotency_key: idempotency_key))
69
+ end
70
+
71
+ # Sends a signal to a process and its group; a process that ended is not signalled, so a retry is safe.
72
+ def signal_process(id, process, signal: nil, idempotency_key: nil)
73
+ Process.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/processes/#{URI.encode_www_form_component(process)}:signal", body: { "signal" => signal }.compact, idempotency_key: idempotency_key, idempotent: true))
74
+ end
75
+
76
+ # Lists a container's processes, newest first: those running and those that ended lately.
77
+ def list_processes(id)
78
+ ProcessList.from(@transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}/processes", idempotent: true))
79
+ end
80
+
81
+ # Removes a file, a link or a directory (recursive for one with contents). One missing is success, removed false.
82
+ def remove(id, path:, recursive: nil, idempotency_key: nil)
83
+ FileRemoved.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/files:remove", body: { "path" => path, "recursive" => recursive }.compact, idempotency_key: idempotency_key))
84
+ end
85
+
86
+ # 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.
87
+ def stat(id, path:, sha256: nil)
88
+ FileInfo.from(@transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}/files/stat", query: { "path" => path, "sha256" => sha256 }, idempotent: true))
89
+ end
90
+
91
+ # Lists a directory's entries in path order, to a depth.
92
+ def list_files(id, path: nil, depth: nil, limit: nil, hidden: nil, glob: nil)
93
+ FileList.from(@transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}/files/list", query: { "path" => path, "depth" => depth, "limit" => limit, "hidden" => hidden, "glob" => glob }, idempotent: true))
94
+ end
95
+
96
+ # Returns a folder as a tar archive (`application/x-tar`, or `application/gzip` with gzip), packed by tar in the container 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 a container. A paused container is woken first.
97
+ def download_folder(id, path:, gzip: nil, user: nil, exclude: nil)
98
+ @transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "gzip" => gzip, "user" => user, "exclude" => exclude }, raw: true, idempotent: true)
99
+ end
100
+
101
+ # 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 container 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 container is woken first.
102
+ def upload_folder(id, data, path:, user: nil, idempotency_key: nil)
103
+ FolderUnpacked.from(@transport.request("PUT", "/v2/containers/#{URI.encode_www_form_component(id)}/files/archive", query: { "path" => path, "user" => user }, data: data, idempotency_key: idempotency_key, idempotent: true))
104
+ end
105
+
106
+ # Begins a folder's upload in parts: tar starts in the container, 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 container is woken first.
107
+ def begin_folder_upload(id, path:, gzip: nil, user: nil, idempotency_key: nil)
108
+ FolderUpload.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/files/archive/uploads", body: { "path" => path, "gzip" => gzip, "user" => user }.compact, idempotency_key: idempotency_key))
109
+ end
110
+
111
+ # 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.
112
+ def write_folder_upload(id, upload, data, offset: nil, idempotency_key: nil)
113
+ FolderUploadReceived.from(@transport.request("PUT", "/v2/containers/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}", query: { "offset" => offset }, data: data, idempotency_key: idempotency_key, idempotent: true))
114
+ end
115
+
116
+ # 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.
117
+ def commit_folder_upload(id, upload, idempotency_key: nil)
118
+ FolderUnpacked.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:commit", idempotency_key: idempotency_key, idempotent: true))
119
+ end
120
+
121
+ # Stops a folder upload's tar; what it unpacked so far stays.
122
+ def abort_folder_upload(id, upload, idempotency_key: nil)
123
+ FolderUploadAborted.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/files/archive/uploads/#{URI.encode_www_form_component(upload)}:abort", idempotency_key: idempotency_key, idempotent: true))
124
+ end
125
+
126
+ # Makes a directory, and its parents unless parents is false. One there already is success, created false.
127
+ def mkdir(id, path:, parents: nil, idempotency_key: nil)
128
+ FileMade.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/files:mkdir", body: { "path" => path, "parents" => parents }.compact, idempotency_key: idempotency_key, idempotent: true))
129
+ end
130
+
131
+ # 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.
132
+ def rename(id, from:, to:, overwrite: nil, sha256: nil, size: nil, idempotency_key: nil)
133
+ FileRenamed.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/files:rename", body: { "from" => from, "to" => to, "overwrite" => overwrite, "sha256" => sha256, "size" => size }.compact, idempotency_key: idempotency_key))
134
+ end
135
+
136
+ # 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 container. A paused container is woken for it unless wake is false.
137
+ def link(id, path:, method: nil, expires_in_seconds: nil, filename: nil, max_bytes: nil, wake: nil, archive: nil, idempotency_key: nil)
138
+ FileLink.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/files:link", body: { "path" => path, "method" => method, "expiresInSeconds" => expires_in_seconds, "filename" => filename, "maxBytes" => max_bytes, "wake" => wake, "archive" => archive }.compact, idempotency_key: idempotency_key))
139
+ end
140
+
141
+ # Ends every file link made for a container so far; links made after work.
142
+ def revoke_links(id, idempotency_key: nil)
143
+ FileLinksRevoked.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}/files:revokeLinks", idempotency_key: idempotency_key))
144
+ end
145
+
146
+ # Returns where a container may connect out.
147
+ def get_network(id)
148
+ SandboxNetwork.from(@transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}/network", idempotent: true))
149
+ end
150
+
151
+ # Returns a container's CPU, memory, disks and pressure, as its host reads them from the container's own cgroup over a fifth of a second: never a call into the container, so it does not wake a paused one nor keep one from its idle pause. One that is not running has no reading.
152
+ def metrics(id, range: nil)
153
+ SandboxMetrics.from(@transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}/metrics", query: { "range" => range }, idempotent: true))
154
+ end
155
+
156
+ # Replaces where a container may connect out, for its next connection and within a second for its open ones: those the new rules refuse are cut.
157
+ def set_network(id, allow_outbound: nil, deny_outbound: nil, idempotency_key: nil)
158
+ SandboxNetwork.from(@transport.request("PUT", "/v2/containers/#{URI.encode_www_form_component(id)}/network", body: { "allowOutbound" => allow_outbound, "denyOutbound" => deny_outbound }.compact, idempotency_key: idempotency_key))
159
+ end
160
+
161
+ # Copies a container 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.
162
+ def fork(id, count: nil, name: nil, labels: nil, secrets: nil, max_cost: nil, idle_pause_seconds: nil, idempotency_key: nil)
163
+ Forked.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}:fork", body: { "count" => count, "name" => name, "labels" => labels, "secrets" => secrets, "maxCost" => max_cost, "idlePauseSeconds" => idle_pause_seconds }.compact, idempotency_key: idempotency_key, idempotent: true))
164
+ end
165
+
166
+ # Keeps a container's memory and disk as they are now, a snapshot to start containers from; with `image`, its disk alone as that image's next version. The container runs on. Asked again with the same Idempotency-Key, it returns the same snapshot.
167
+ def snapshot(id, name: nil, labels: nil, image: nil, start: nil, idempotency_key: nil)
168
+ Stored.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}:snapshot", body: { "name" => name, "labels" => labels, "image" => image, "start" => start }.compact, idempotency_key: idempotency_key, idempotent: true))
169
+ end
170
+
171
+ # Changes its name, labels, idle pause, maxCost, environment or sizes; each field left out stays as it is. 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; a smaller size, or a sandbox that is not running, is refused 409 naming why, and nothing is changed. With If-Match, made only while its revision is that one, else 412.
172
+ def update(id, name: nil, labels: nil, idle_pause_seconds: nil, vcpu: nil, memory_gb: nil, disk_gb: nil, user: nil, env: nil, remove_env: nil, max_cost: nil, idempotency_key: nil)
173
+ Sandbox.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}:update", body: { "name" => name, "labels" => labels, "idlePauseSeconds" => idle_pause_seconds, "vcpu" => vcpu, "memoryGB" => memory_gb, "diskGB" => disk_gb, "user" => user, "env" => env, "removeEnv" => remove_env, "maxCost" => max_cost }.compact, idempotency_key: idempotency_key))
174
+ end
175
+
176
+ # Returns what a container'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 container is resumed first.
177
+ def screenshot(id, format: nil, quality: nil)
178
+ @transport.request("GET", "/v2/containers/#{URI.encode_www_form_component(id)}/screenshot", query: { "format" => format, "quality" => quality }, raw: true, idempotent: true)
179
+ end
180
+
181
+ # Moves, clicks, drags and scrolls the mouse and types on the keyboard of a container'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 container is resumed first.
182
+ def act(id, actions:, idempotency_key: nil)
183
+ Acted.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}:act", body: { "actions" => actions }.compact, idempotency_key: idempotency_key))
184
+ end
185
+
186
+ # Runs a cell of Python in a container 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 container is resumed first.
187
+ def run_code(id, code:, language: nil, context: nil, timeout_seconds: nil, idempotency_key: nil)
188
+ CodeRun.from(@transport.request("POST", "/v2/containers/#{URI.encode_www_form_component(id)}:runCode", body: { "code" => code, "language" => language, "context" => context, "timeoutSeconds" => timeout_seconds }.compact, idempotency_key: idempotency_key))
189
+ end
190
+ end
191
+ end
192
+ end