withruntime 0.28.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/withruntime/generated/apps.rb +192 -0
- data/lib/withruntime/generated/audit.rb +78 -0
- data/lib/withruntime/generated/browsers.rb +192 -0
- data/lib/withruntime/generated/builds.rb +192 -0
- data/lib/withruntime/generated/ci.rb +192 -0
- data/lib/withruntime/generated/containers.rb +192 -0
- data/lib/withruntime/generated/desktops.rb +192 -0
- data/lib/withruntime/generated/domains.rb +152 -0
- data/lib/withruntime/generated/egress_ips.rb +81 -0
- data/lib/withruntime/generated/events.rb +60 -0
- data/lib/withruntime/generated/feedback.rb +96 -0
- data/lib/withruntime/generated/functions.rb +192 -0
- data/lib/withruntime/generated/identities.rb +68 -0
- data/lib/withruntime/generated/images.rb +391 -0
- data/lib/withruntime/generated/job_runs.rb +110 -0
- data/lib/withruntime/generated/jobs.rb +333 -0
- data/lib/withruntime/generated/keys.rb +261 -0
- data/lib/withruntime/generated/kit.rb +111 -0
- data/lib/withruntime/generated/me.rb +69 -0
- data/lib/withruntime/generated/networks.rb +72 -0
- data/lib/withruntime/generated/notebooks.rb +192 -0
- data/lib/withruntime/generated/otel.rb +94 -0
- data/lib/withruntime/generated/ports.rb +118 -0
- data/lib/withruntime/generated/previews.rb +124 -0
- data/lib/withruntime/generated/projects.rb +108 -0
- data/lib/withruntime/generated/roles.rb +68 -0
- data/lib/withruntime/generated/routes.rb +11 -0
- data/lib/withruntime/generated/runtime.rb +188 -0
- data/lib/withruntime/generated/sandboxes.rb +1835 -0
- data/lib/withruntime/generated/secrets.rb +294 -0
- data/lib/withruntime/generated/sessions.rb +143 -0
- data/lib/withruntime/generated/sites.rb +192 -0
- data/lib/withruntime/generated/snapshots.rb +32 -0
- data/lib/withruntime/generated/tunnels.rb +165 -0
- data/lib/withruntime/generated/usage.rb +287 -0
- data/lib/withruntime/generated/volumes.rb +61 -0
- data/lib/withruntime/generated/webhooks.rb +91 -0
- data/lib/withruntime/generated/workspaces.rb +192 -0
- data/lib/withruntime/signing.rb +162 -0
- data/lib/withruntime/version.rb +2 -2
- data/lib/withruntime.rb +5 -43
- metadata +45 -35
- data/lib/withruntime/agents.rb +0 -877
- data/lib/withruntime/api_defaults.rb +0 -17
- data/lib/withruntime/apps.rb +0 -377
- data/lib/withruntime/browsers.rb +0 -104
- data/lib/withruntime/builds.rb +0 -218
- data/lib/withruntime/ci.rb +0 -164
- data/lib/withruntime/client.rb +0 -140
- data/lib/withruntime/containers.rb +0 -39
- data/lib/withruntime/credentials.rb +0 -111
- data/lib/withruntime/fields.rb +0 -40
- data/lib/withruntime/file_watch.rb +0 -73
- data/lib/withruntime/images.rb +0 -258
- data/lib/withruntime/network_products.rb +0 -49
- data/lib/withruntime/parity_products.rb +0 -51
- data/lib/withruntime/products.rb +0 -560
- data/lib/withruntime/record.rb +0 -99
- data/lib/withruntime/reservations.rb +0 -76
- data/lib/withruntime/sandbox.rb +0 -775
- data/lib/withruntime/tar.rb +0 -292
- data/lib/withruntime/transport.rb +0 -575
- data/lib/withruntime/tunnel.rb +0 -275
- data/lib/withruntime/wallet.rb +0 -68
- data/lib/withruntime/websocket.rb +0 -384
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8943023881df216ab72522a1ea54d690aa396df741098e57044706d5cc05ff0a
|
|
4
|
+
data.tar.gz: abe987cc81f6b69adcf3185ad8d2b9886da0bf42b20739534154a6981b6ee870
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e9e8fbf679e3dbcdad66234835f5427e7c9a2c93f3981ed885eb15ef694b091335ffbfb9cad3642cf2b86c1ecb4f5103f2ede1c2cc1ab310d1af9c56c23a5429
|
|
7
|
+
data.tar.gz: f620ccaa6e7fce5ec80c284cd250200f10fa3e72b901814b471a890ca6077e9bb1d810d4cbb42d9f5de8370b389765a32ae4b6fa06773c416c1efb18df8f5332
|
|
@@ -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 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. It never pauses for being idle.
|
|
11
|
+
class Apps
|
|
12
|
+
def initialize(transport)
|
|
13
|
+
@transport = transport
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Creates an app. Asked again with the same Idempotency-Key, it returns the same app.
|
|
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/apps", 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 an app.
|
|
22
|
+
def get(id, wait: nil, if_state: nil)
|
|
23
|
+
Sandbox.from(@transport.request("GET", "/v2/apps/#{URI.encode_www_form_component(id)}", query: { "wait" => wait, "ifState" => if_state }, idempotent: true))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Lists the project's apps, newest first.
|
|
27
|
+
def list(state: nil, name: nil, label: nil, cursor: nil, limit: nil)
|
|
28
|
+
Generated.page(@transport.request("GET", "/v2/apps", query: { "state" => state, "name" => name, "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Sandbox.from(i) }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Deletes an app, its memory and its disk.
|
|
32
|
+
def delete(id, idempotency_key: nil)
|
|
33
|
+
Sandbox.from(@transport.request("DELETE", "/v2/apps/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Pauses an app 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/apps/#{URI.encode_www_form_component(id)}:pause", idempotency_key: idempotency_key))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Resumes a paused app where it was, its memory and processes as they were.
|
|
42
|
+
def resume(id, idempotency_key: nil)
|
|
43
|
+
Sandbox.from(@transport.request("POST", "/v2/apps/#{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 app 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/apps/#{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/apps/#{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/apps/#{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/apps/#{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/apps/#{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/apps/#{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 an app's processes, newest first: those running and those that ended lately.
|
|
77
|
+
def list_processes(id)
|
|
78
|
+
ProcessList.from(@transport.request("GET", "/v2/apps/#{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/apps/#{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/apps/#{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/apps/#{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 app 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 app. A paused app is woken first.
|
|
97
|
+
def download_folder(id, path:, gzip: nil, user: nil, exclude: nil)
|
|
98
|
+
@transport.request("GET", "/v2/apps/#{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 app 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 app is woken first.
|
|
102
|
+
def upload_folder(id, data, path:, user: nil, idempotency_key: nil)
|
|
103
|
+
FolderUnpacked.from(@transport.request("PUT", "/v2/apps/#{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 app, 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 app is woken first.
|
|
107
|
+
def begin_folder_upload(id, path:, gzip: nil, user: nil, idempotency_key: nil)
|
|
108
|
+
FolderUpload.from(@transport.request("POST", "/v2/apps/#{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/apps/#{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/apps/#{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/apps/#{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/apps/#{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/apps/#{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 app. A paused app 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/apps/#{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 an app so far; links made after work.
|
|
142
|
+
def revoke_links(id, idempotency_key: nil)
|
|
143
|
+
FileLinksRevoked.from(@transport.request("POST", "/v2/apps/#{URI.encode_www_form_component(id)}/files:revokeLinks", idempotency_key: idempotency_key))
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Returns where an app may connect out.
|
|
147
|
+
def get_network(id)
|
|
148
|
+
SandboxNetwork.from(@transport.request("GET", "/v2/apps/#{URI.encode_www_form_component(id)}/network", idempotent: true))
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Returns an app's CPU, memory, disks and pressure, as its host reads them from the app's own cgroup over a fifth of a second: never a call into the app, 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/apps/#{URI.encode_www_form_component(id)}/metrics", query: { "range" => range }, idempotent: true))
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Replaces where an app 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/apps/#{URI.encode_www_form_component(id)}/network", body: { "allowOutbound" => allow_outbound, "denyOutbound" => deny_outbound }.compact, idempotency_key: idempotency_key))
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Copies an app 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/apps/#{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 an app's memory and disk as they are now, a snapshot to start apps from; with `image`, its disk alone as that image's next version. The app 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/apps/#{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/apps/#{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 an app'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 app is resumed first.
|
|
177
|
+
def screenshot(id, format: nil, quality: nil)
|
|
178
|
+
@transport.request("GET", "/v2/apps/#{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 an app'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 app is resumed first.
|
|
182
|
+
def act(id, actions:, idempotency_key: nil)
|
|
183
|
+
Acted.from(@transport.request("POST", "/v2/apps/#{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 an app 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 app 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/apps/#{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,78 @@
|
|
|
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
|
+
|
|
7
|
+
module Withruntime
|
|
8
|
+
module Generated
|
|
9
|
+
# One line of the audit log: a call Access judged, allowed or refused.
|
|
10
|
+
# - +id+: Its ID.
|
|
11
|
+
# - +object+: Always `audit`.
|
|
12
|
+
# - +action+: What was asked (`sandboxes:create`, `keys:delete`).
|
|
13
|
+
# - +allowed+: Whether it was allowed.
|
|
14
|
+
# - +reason+: Why it was refused, or what it changed, when it says.
|
|
15
|
+
# - +target+: What it acted on: a resource's ID, when it names one.
|
|
16
|
+
# - +account_id+: The person who asked, or for whom an agent asked.
|
|
17
|
+
# - +agent_id+: The agent or CI pipeline that asked.
|
|
18
|
+
# - +key_id+: The key it was asked with; none for the console.
|
|
19
|
+
# - +project_id+: The project it acted in.
|
|
20
|
+
# - +cost+: What it committed, in US dollars.
|
|
21
|
+
# - +address+: The client address it came from.
|
|
22
|
+
# - +request_id+: The request's ID.
|
|
23
|
+
# - +created_at+: When it was asked.
|
|
24
|
+
AuditLine = Struct.new(:id, :object, :action, :allowed, :reason, :target, :account_id, :agent_id, :key_id, :project_id, :cost, :address, :request_id, :created_at, keyword_init: true) do
|
|
25
|
+
def self.from(h)
|
|
26
|
+
return nil if h.nil?
|
|
27
|
+
|
|
28
|
+
new(
|
|
29
|
+
id: h["id"],
|
|
30
|
+
object: h["object"],
|
|
31
|
+
action: h["action"],
|
|
32
|
+
allowed: h["allowed"],
|
|
33
|
+
reason: h["reason"],
|
|
34
|
+
target: h["target"],
|
|
35
|
+
account_id: h["accountId"],
|
|
36
|
+
agent_id: h["agentId"],
|
|
37
|
+
key_id: h["keyId"],
|
|
38
|
+
project_id: h["projectId"],
|
|
39
|
+
cost: h["cost"],
|
|
40
|
+
address: h["address"],
|
|
41
|
+
request_id: h["requestId"],
|
|
42
|
+
created_at: h["createdAt"],
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def to_wire
|
|
47
|
+
{
|
|
48
|
+
"id" => self.id,
|
|
49
|
+
"object" => self.object,
|
|
50
|
+
"action" => self.action,
|
|
51
|
+
"allowed" => self.allowed,
|
|
52
|
+
"reason" => self.reason,
|
|
53
|
+
"target" => self.target,
|
|
54
|
+
"accountId" => self.account_id,
|
|
55
|
+
"agentId" => self.agent_id,
|
|
56
|
+
"keyId" => self.key_id,
|
|
57
|
+
"projectId" => self.project_id,
|
|
58
|
+
"cost" => self.cost,
|
|
59
|
+
"address" => self.address,
|
|
60
|
+
"requestId" => self.request_id,
|
|
61
|
+
"createdAt" => self.created_at,
|
|
62
|
+
}.compact
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# The organization's audit log: every write and every refused call, with who asked, from where, and what it committed. On the Scale and Enterprise plans.
|
|
67
|
+
class Audit
|
|
68
|
+
def initialize(transport)
|
|
69
|
+
@transport = transport
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Lists the organization's audit log, newest first, paginated: each write and each refused call, over the days the plan keeps (365 on Scale). On other plans it returns 403.
|
|
73
|
+
def list(cursor: nil, limit: nil, action: nil)
|
|
74
|
+
Generated.page(@transport.request("GET", "/v2/audit", query: { "cursor" => cursor, "limit" => limit, "action" => action }, idempotent: true)) { |i| AuditLine.from(i) }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
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 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. It pauses after 60 seconds with nothing happening, its memory kept, and a connection resumes it.
|
|
11
|
+
class Browsers
|
|
12
|
+
def initialize(transport)
|
|
13
|
+
@transport = transport
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Creates a browser. Asked again with the same Idempotency-Key, it returns the same browser.
|
|
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/browsers", 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 browser.
|
|
22
|
+
def get(id, wait: nil, if_state: nil)
|
|
23
|
+
Sandbox.from(@transport.request("GET", "/v2/browsers/#{URI.encode_www_form_component(id)}", query: { "wait" => wait, "ifState" => if_state }, idempotent: true))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Lists the project's browsers, newest first.
|
|
27
|
+
def list(state: nil, name: nil, label: nil, cursor: nil, limit: nil)
|
|
28
|
+
Generated.page(@transport.request("GET", "/v2/browsers", query: { "state" => state, "name" => name, "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Sandbox.from(i) }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Deletes a browser, its memory and its disk.
|
|
32
|
+
def delete(id, idempotency_key: nil)
|
|
33
|
+
Sandbox.from(@transport.request("DELETE", "/v2/browsers/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Pauses a browser 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/browsers/#{URI.encode_www_form_component(id)}:pause", idempotency_key: idempotency_key))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Resumes a paused browser where it was, its memory and processes as they were.
|
|
42
|
+
def resume(id, idempotency_key: nil)
|
|
43
|
+
Sandbox.from(@transport.request("POST", "/v2/browsers/#{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 browser 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/browsers/#{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/browsers/#{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/browsers/#{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/browsers/#{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/browsers/#{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/browsers/#{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 browser's processes, newest first: those running and those that ended lately.
|
|
77
|
+
def list_processes(id)
|
|
78
|
+
ProcessList.from(@transport.request("GET", "/v2/browsers/#{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/browsers/#{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/browsers/#{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/browsers/#{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 browser 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 browser. A paused browser is woken first.
|
|
97
|
+
def download_folder(id, path:, gzip: nil, user: nil, exclude: nil)
|
|
98
|
+
@transport.request("GET", "/v2/browsers/#{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 browser 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 browser is woken first.
|
|
102
|
+
def upload_folder(id, data, path:, user: nil, idempotency_key: nil)
|
|
103
|
+
FolderUnpacked.from(@transport.request("PUT", "/v2/browsers/#{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 browser, 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 browser is woken first.
|
|
107
|
+
def begin_folder_upload(id, path:, gzip: nil, user: nil, idempotency_key: nil)
|
|
108
|
+
FolderUpload.from(@transport.request("POST", "/v2/browsers/#{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/browsers/#{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/browsers/#{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/browsers/#{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/browsers/#{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/browsers/#{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 browser. A paused browser 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/browsers/#{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 browser so far; links made after work.
|
|
142
|
+
def revoke_links(id, idempotency_key: nil)
|
|
143
|
+
FileLinksRevoked.from(@transport.request("POST", "/v2/browsers/#{URI.encode_www_form_component(id)}/files:revokeLinks", idempotency_key: idempotency_key))
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Returns where a browser may connect out.
|
|
147
|
+
def get_network(id)
|
|
148
|
+
SandboxNetwork.from(@transport.request("GET", "/v2/browsers/#{URI.encode_www_form_component(id)}/network", idempotent: true))
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Returns a browser's CPU, memory, disks and pressure, as its host reads them from the browser's own cgroup over a fifth of a second: never a call into the browser, 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/browsers/#{URI.encode_www_form_component(id)}/metrics", query: { "range" => range }, idempotent: true))
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Replaces where a browser 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/browsers/#{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 browser 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/browsers/#{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 browser's memory and disk as they are now, a snapshot to start browsers from; with `image`, its disk alone as that image's next version. The browser 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/browsers/#{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/browsers/#{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 browser's screen shows now, as `image/png` (or `image/jpeg`): its page, read and driven by the browser itself over the Chrome DevTools Protocol, whole. Refused 409 `browser_not_running` when its Chromium does not answer. A paused browser is resumed first.
|
|
177
|
+
def screenshot(id, format: nil, quality: nil)
|
|
178
|
+
@transport.request("GET", "/v2/browsers/#{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 browser's screen (its page, read and driven by the browser itself over the Chrome DevTools Protocol), 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 `browser_not_running` when its Chromium does not answer. A paused browser is resumed first.
|
|
182
|
+
def act(id, actions:, idempotency_key: nil)
|
|
183
|
+
Acted.from(@transport.request("POST", "/v2/browsers/#{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 browser 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 browser 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/browsers/#{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
|