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.
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 -775
  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
+ # A development environment: a machine running VS Code in the browser (code-server) on port 8080 over /workspace, reached at its private preview, as Codespaces and Gitpod give one. It pauses after 30 minutes with nothing happening, its memory kept.
11
+ class Workspaces
12
+ def initialize(transport)
13
+ @transport = transport
14
+ end
15
+
16
+ # Creates a workspace. Asked again with the same Idempotency-Key, it returns the same workspace.
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/workspaces", 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 workspace.
22
+ def get(id, wait: nil, if_state: nil)
23
+ Sandbox.from(@transport.request("GET", "/v2/workspaces/#{URI.encode_www_form_component(id)}", query: { "wait" => wait, "ifState" => if_state }, idempotent: true))
24
+ end
25
+
26
+ # Lists the project's workspaces, newest first.
27
+ def list(state: nil, name: nil, label: nil, cursor: nil, limit: nil)
28
+ Generated.page(@transport.request("GET", "/v2/workspaces", query: { "state" => state, "name" => name, "label" => label, "cursor" => cursor, "limit" => limit }, idempotent: true)) { |i| Sandbox.from(i) }
29
+ end
30
+
31
+ # Deletes a workspace, its memory and its disk.
32
+ def delete(id, idempotency_key: nil)
33
+ Sandbox.from(@transport.request("DELETE", "/v2/workspaces/#{URI.encode_www_form_component(id)}", idempotency_key: idempotency_key))
34
+ end
35
+
36
+ # Pauses a workspace 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/workspaces/#{URI.encode_www_form_component(id)}:pause", idempotency_key: idempotency_key))
39
+ end
40
+
41
+ # Resumes a paused workspace where it was, its memory and processes as they were.
42
+ def resume(id, idempotency_key: nil)
43
+ Sandbox.from(@transport.request("POST", "/v2/workspaces/#{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 workspace 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/workspaces/#{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/workspaces/#{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/workspaces/#{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/workspaces/#{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/workspaces/#{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/workspaces/#{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 workspace's processes, newest first: those running and those that ended lately.
77
+ def list_processes(id)
78
+ ProcessList.from(@transport.request("GET", "/v2/workspaces/#{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/workspaces/#{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/workspaces/#{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/workspaces/#{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 workspace 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 workspace. A paused workspace is woken first.
97
+ def download_folder(id, path:, gzip: nil, user: nil, exclude: nil)
98
+ @transport.request("GET", "/v2/workspaces/#{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 workspace 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 workspace is woken first.
102
+ def upload_folder(id, data, path:, user: nil, idempotency_key: nil)
103
+ FolderUnpacked.from(@transport.request("PUT", "/v2/workspaces/#{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 workspace, 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 workspace is woken first.
107
+ def begin_folder_upload(id, path:, gzip: nil, user: nil, idempotency_key: nil)
108
+ FolderUpload.from(@transport.request("POST", "/v2/workspaces/#{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/workspaces/#{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/workspaces/#{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/workspaces/#{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/workspaces/#{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/workspaces/#{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 workspace. A paused workspace 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/workspaces/#{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 workspace so far; links made after work.
142
+ def revoke_links(id, idempotency_key: nil)
143
+ FileLinksRevoked.from(@transport.request("POST", "/v2/workspaces/#{URI.encode_www_form_component(id)}/files:revokeLinks", idempotency_key: idempotency_key))
144
+ end
145
+
146
+ # Returns where a workspace may connect out.
147
+ def get_network(id)
148
+ SandboxNetwork.from(@transport.request("GET", "/v2/workspaces/#{URI.encode_www_form_component(id)}/network", idempotent: true))
149
+ end
150
+
151
+ # Returns a workspace's CPU, memory, disks and pressure, as its host reads them from the workspace's own cgroup over a fifth of a second: never a call into the workspace, 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/workspaces/#{URI.encode_www_form_component(id)}/metrics", query: { "range" => range }, idempotent: true))
154
+ end
155
+
156
+ # Replaces where a workspace 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/workspaces/#{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 workspace 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/workspaces/#{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 workspace's memory and disk as they are now, a snapshot to start workspaces from; with `image`, its disk alone as that image's next version. The workspace 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/workspaces/#{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/workspaces/#{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 workspace'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 workspace is resumed first.
177
+ def screenshot(id, format: nil, quality: nil)
178
+ @transport.request("GET", "/v2/workspaces/#{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 workspace'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 workspace is resumed first.
182
+ def act(id, actions:, idempotency_key: nil)
183
+ Acted.from(@transport.request("POST", "/v2/workspaces/#{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 workspace 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 workspace 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/workspaces/#{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,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "openssl"
5
+ require "securerandom"
6
+ require_relative "errors"
7
+
8
+ module WithRuntime
9
+ # API keys as key pairs (ARCHITECTURE.md section 11): the SDK holds the
10
+ # private half and signs each request; the server stores only the public
11
+ # half, so no bearer secret crosses the network.
12
+ #
13
+ # Authorization: Runtime-Ed25519 Credential=<32 hex>,Timestamp=<ns>,Nonce=<32 hex>,Signature=<128 hex>
14
+ # Runtime-Project: <32 hex>
15
+ #
16
+ # The signature is Ed25519 over
17
+ #
18
+ # "rtr\x01" | credential (16, LE) | project (16, LE) | timestamp ns (8, LE)
19
+ # | nonce (16) | SHA-256(body) (32) | method | "\n" | path and query | "\n"
20
+ # | Idempotency-Key (empty when none)
21
+ #
22
+ # so it is good for one request, on one project, within 60 seconds of the
23
+ # server's clock. A signed write must carry an Idempotency-Key: a copy
24
+ # replayed within the minute is then answered from the first one's commit,
25
+ # not run again. The front's side is engines/front/crates/front/src/signed.rs;
26
+ # every SDK signs the same test vector to the same header. OpenSSL signs.
27
+ module Signing
28
+ SCHEME = "Runtime-Ed25519"
29
+ # A key pair's secret, as RUNTIME_API_KEY or +api_key+ holds it.
30
+ PREFIX = "rtsk_"
31
+ DOMAIN = "rtr\x01".b.freeze
32
+ # PKCS #8 for an Ed25519 private key, before its 32-byte seed (RFC 8410).
33
+ PKCS8_PREFIX = ["302e020100300506032b657004220420"].pack("H*").freeze
34
+ ID = /\A[0-9a-f]{32}\z/
35
+ SEED = /\A[0-9a-f]{64}\z/
36
+
37
+ # A key pair as an API key: +credential+, the ID its public half was
38
+ # registered as (32 hex characters), and its private key (seed), 64 hex
39
+ # characters.
40
+ class Key
41
+ attr_reader :credential
42
+
43
+ def initialize(credential, private_key)
44
+ unless ID.match?(credential) && SEED.match?(private_key)
45
+ raise ArgumentError, "A signing key is a 32-character credential ID and a 64-character private key, in lowercase hex."
46
+ end
47
+
48
+ @credential = credential
49
+ @credential_bytes = Signing.id_bytes(credential)
50
+ @key = OpenSSL::PKey.read(PKCS8_PREFIX + [private_key].pack("H*"))
51
+ end
52
+
53
+ # Never the private key: an inspect reaches logs.
54
+ def inspect = "#<WithRuntime::Signing::Key credential=#{@credential}>"
55
+
56
+ # The public key, 64 hex characters: what is registered.
57
+ def public_key = @key.public_to_der.byteslice(-32, 32).unpack1("H*")
58
+
59
+ # The headers that sign one request: Authorization and Runtime-Project.
60
+ # +target+ is the path and query exactly as sent; +body+ the bytes as
61
+ # sent; +idempotency_key+ the Idempotency-Key header sent, which a write
62
+ # must have. Sign each attempt anew: the server takes a nonce once.
63
+ def sign_request(project, method, target, body = nil, idempotency_key: nil, timestamp_ns: nil, nonce: nil)
64
+ raise ArgumentError, "The project is its 32-character ID, in lowercase hex." unless ID.match?(project)
65
+
66
+ nonce ||= SecureRandom.random_bytes(16)
67
+ raise ArgumentError, "A nonce is 16 bytes." unless nonce.bytesize == 16
68
+
69
+ at = timestamp_ns || Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
70
+ message = String.new(capacity: 94 + method.bytesize + target.bytesize + idempotency_key.to_s.bytesize,
71
+ encoding: Encoding::BINARY)
72
+ message << DOMAIN << @credential_bytes << Signing.id_bytes(project) << [at].pack("Q<") << nonce.b
73
+ message << Digest::SHA256.digest(body.to_s) << method.b << "\n" << target.b << "\n" << idempotency_key.to_s.b
74
+ signature = @key.sign(nil, message)
75
+ { "Authorization" => "#{SCHEME} Credential=#{@credential},Timestamp=#{at},Nonce=#{nonce.unpack1('H*')},Signature=#{signature.unpack1('H*')}",
76
+ "Runtime-Project" => project }
77
+ end
78
+ end
79
+
80
+ module_function
81
+
82
+ # A 128-bit ID's 16 bytes, little-endian, as the server reads it.
83
+ def id_bytes(id) = [id].pack("H*").reverse
84
+
85
+ # A new key pair, made on this machine: [private_key, public_key], each 64
86
+ # hex characters. Register the public key as an API key; keep the private
87
+ # key secret. The server never sees it.
88
+ def generate_key_pair
89
+ seed = SecureRandom.random_bytes(32).unpack1("H*")
90
+ [seed, public_key_of(seed)]
91
+ end
92
+
93
+ # The public key (64 hex characters) of a private key.
94
+ def public_key_of(private_key) = Key.new("0" * 32, private_key).public_key
95
+
96
+ # A key pair's secret, rtsk_<credential>_<private_key>: what
97
+ # RUNTIME_API_KEY or +api_key+ holds to sign requests instead of sending a
98
+ # bearer key.
99
+ def secret(credential, private_key)
100
+ Key.new(credential, private_key)
101
+ "#{PREFIX}#{credential}_#{private_key}"
102
+ end
103
+
104
+ # The key pair in an rtsk_ secret, or nil for any other key.
105
+ def parse(secret)
106
+ return nil unless secret.start_with?(PREFIX)
107
+
108
+ parts = secret.delete_prefix(PREFIX).split("_", -1)
109
+ return nil unless parts.size == 2 && ID.match?(parts[0]) && SEED.match?(parts[1])
110
+
111
+ Key.new(parts[0], parts[1])
112
+ end
113
+
114
+ # An rtsk_ secret is a private key: every call that authorizes with the
115
+ # API key goes through +authorize+ (signs) or +bearer_key+ (refuses it),
116
+ # so it is never sent, whatever the call.
117
+
118
+ # Whether +key+ is a key pair's secret (rtsk_): a private key, which signs
119
+ # requests and is never sent.
120
+ def signing_key?(key) = key.to_s.start_with?(PREFIX)
121
+
122
+ # +key+, for a call that can only send a bearer key (another platform's
123
+ # SDK pointed at Runtime). A key pair's secret is never sent: raises for
124
+ # one, before anything leaves this machine.
125
+ def bearer_key(key, what)
126
+ return key unless signing_key?(key)
127
+
128
+ raise Error.new("#{what} sends the API key as a bearer token, and this key is a key pair's private key (rtsk_), " \
129
+ "which is never sent. Nothing was sent.",
130
+ code: "invalid_request", hint: "Use a bearer API key (rtkey_) here; the SDK's own calls sign with the rtsk_ key.")
131
+ end
132
+
133
+ # The key pair in +key+, or nil for a bearer key. Raises for a malformed
134
+ # rtsk_ secret, or one with no +project+ to sign for: callers check before
135
+ # sending anything.
136
+ def key_for(key, project)
137
+ return nil unless signing_key?(key)
138
+
139
+ signing = (@parsed ||= {})[key] ||= parse(key)
140
+ unless signing
141
+ raise Error.new("The API key starts with rtsk_ but is not a key pair's secret (rtsk_<32 hex>_<64 hex>). Nothing was sent.",
142
+ code: "invalid_request", hint: "Use the whole secret, as WithRuntime::Signing.secret wrote it.")
143
+ end
144
+ unless ID.match?(project.to_s)
145
+ raise Error.new("A signing key (rtsk_) signs each request for one project, and none was given. Nothing was sent.",
146
+ code: "invalid_request", hint: "Set RUNTIME_PROJECT to the project's 32-character ID, or pass project:.")
147
+ end
148
+ signing
149
+ end
150
+
151
+ # The headers that authorize one attempt with +key+: a key pair's
152
+ # signature, else Authorization: Bearer. Raises, sending nothing, for a
153
+ # malformed rtsk_ secret or one with no project. Call it for each attempt:
154
+ # the server takes a nonce once.
155
+ def authorize(key, project, method, target, body = nil, idempotency_key: nil)
156
+ signing = key_for(key, project)
157
+ return { "Authorization" => "Bearer #{key}" } unless signing
158
+
159
+ signing.sign_request(project, method, target, body, idempotency_key: idempotency_key)
160
+ end
161
+ end
162
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module WithRuntime
4
- VERSION = "0.28.0"
3
+ module Withruntime
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/withruntime.rb CHANGED
@@ -1,46 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # The Ruby client for Runtime Cloud: Linux sandboxes for agents, and every
4
- # other Runtime product as it launches. Standard library only.
5
- #
6
- # require "withruntime"
7
- #
8
- # runtime = WithRuntime::Client.new # RUNTIME_API_KEY, or this machine's saved connection
9
- # sbx = runtime.sandboxes.create
10
- # sbx.files.write("/workspace/invoice.py", "print(sum([125, 250, 375]))\n")
11
- # puts sbx.exec("python3 /workspace/invoice.py", check: true).stdout
12
- # sbx.stop
13
- #
14
- # Agents are set up from a runtime.yml in your repo by the CLI, which makes
15
- # the account's agents match the file: npx withruntime agents deploy. This
16
- # gem has no deploy of its own.
17
- #
18
- # The guide is at https://withruntime.com/docs/ruby.
19
- require "json"
20
- require "openssl"
21
-
22
3
  require_relative "withruntime/version"
23
- require_relative "withruntime/errors"
24
- require_relative "withruntime/api_defaults"
25
- require_relative "withruntime/record"
26
- require_relative "withruntime/fields"
27
- require_relative "withruntime/transport"
28
- require_relative "withruntime/credentials"
29
- require_relative "withruntime/wallet"
30
- require_relative "withruntime/tar"
31
- require_relative "withruntime/sandbox"
32
- require_relative "withruntime/products"
33
- require_relative "withruntime/reservations"
34
- require_relative "withruntime/agents"
35
- require_relative "withruntime/images"
36
- require_relative "withruntime/apps"
37
- require_relative "withruntime/builds"
38
- require_relative "withruntime/ci"
39
- require_relative "withruntime/containers"
40
- require_relative "withruntime/browsers"
41
- require_relative "withruntime/network_products"
42
- require_relative "withruntime/parity_products"
43
- require_relative "withruntime/file_watch"
44
- require_relative "withruntime/websocket"
45
- require_relative "withruntime/tunnel"
46
- require_relative "withruntime/client"
4
+ require_relative "withruntime/generated/kit"
5
+
6
+ module Withruntime
7
+ Runtime = Generated::Runtime
8
+ end
metadata CHANGED
@@ -1,18 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: withruntime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Runtime
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-31 00:00:00.000000000 Z
11
+ date: 2026-11-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: 'Linux sandboxes for agents, and every other Runtime Cloud product: streaming
14
- commands and terminals, files and watches, images, durable volumes and backups,
15
- domains, TCP ports, private networking and secrets. Standard library only.'
13
+ description:
16
14
  email:
17
15
  executables: []
18
16
  extensions: []
@@ -20,40 +18,51 @@ extra_rdoc_files: []
20
18
  files:
21
19
  - LICENSE
22
20
  - lib/withruntime.rb
23
- - lib/withruntime/agents.rb
24
- - lib/withruntime/api_defaults.rb
25
- - lib/withruntime/apps.rb
26
- - lib/withruntime/browsers.rb
27
- - lib/withruntime/builds.rb
28
- - lib/withruntime/ci.rb
29
- - lib/withruntime/client.rb
30
- - lib/withruntime/containers.rb
31
- - lib/withruntime/credentials.rb
32
21
  - lib/withruntime/errors.rb
33
- - lib/withruntime/fields.rb
34
- - lib/withruntime/file_watch.rb
35
- - lib/withruntime/images.rb
36
- - lib/withruntime/network_products.rb
37
- - lib/withruntime/parity_products.rb
38
- - lib/withruntime/products.rb
39
- - lib/withruntime/record.rb
40
- - lib/withruntime/reservations.rb
41
- - lib/withruntime/sandbox.rb
42
- - lib/withruntime/tar.rb
43
- - lib/withruntime/transport.rb
44
- - lib/withruntime/tunnel.rb
22
+ - lib/withruntime/generated/apps.rb
23
+ - lib/withruntime/generated/audit.rb
24
+ - lib/withruntime/generated/browsers.rb
25
+ - lib/withruntime/generated/builds.rb
26
+ - lib/withruntime/generated/ci.rb
27
+ - lib/withruntime/generated/containers.rb
28
+ - lib/withruntime/generated/desktops.rb
29
+ - lib/withruntime/generated/domains.rb
30
+ - lib/withruntime/generated/egress_ips.rb
31
+ - lib/withruntime/generated/events.rb
32
+ - lib/withruntime/generated/feedback.rb
33
+ - lib/withruntime/generated/functions.rb
34
+ - lib/withruntime/generated/identities.rb
35
+ - lib/withruntime/generated/images.rb
36
+ - lib/withruntime/generated/job_runs.rb
37
+ - lib/withruntime/generated/jobs.rb
38
+ - lib/withruntime/generated/keys.rb
39
+ - lib/withruntime/generated/kit.rb
40
+ - lib/withruntime/generated/me.rb
41
+ - lib/withruntime/generated/networks.rb
42
+ - lib/withruntime/generated/notebooks.rb
43
+ - lib/withruntime/generated/otel.rb
44
+ - lib/withruntime/generated/ports.rb
45
+ - lib/withruntime/generated/previews.rb
46
+ - lib/withruntime/generated/projects.rb
47
+ - lib/withruntime/generated/roles.rb
48
+ - lib/withruntime/generated/routes.rb
49
+ - lib/withruntime/generated/runtime.rb
50
+ - lib/withruntime/generated/sandboxes.rb
51
+ - lib/withruntime/generated/secrets.rb
52
+ - lib/withruntime/generated/sessions.rb
53
+ - lib/withruntime/generated/sites.rb
54
+ - lib/withruntime/generated/snapshots.rb
55
+ - lib/withruntime/generated/tunnels.rb
56
+ - lib/withruntime/generated/usage.rb
57
+ - lib/withruntime/generated/volumes.rb
58
+ - lib/withruntime/generated/webhooks.rb
59
+ - lib/withruntime/generated/workspaces.rb
60
+ - lib/withruntime/signing.rb
45
61
  - lib/withruntime/version.rb
46
- - lib/withruntime/wallet.rb
47
- - lib/withruntime/websocket.rb
48
62
  homepage: https://withruntime.com
49
63
  licenses:
50
64
  - Apache-2.0
51
- metadata:
52
- homepage_uri: https://withruntime.com
53
- documentation_uri: https://withruntime.com/docs/ruby
54
- source_code_uri: https://github.com/withruntime/runtime/tree/main/sdks/ruby
55
- bug_tracker_uri: https://github.com/withruntime/runtime/issues
56
- rubygems_mfa_required: 'true'
65
+ metadata: {}
57
66
  post_install_message:
58
67
  rdoc_options: []
59
68
  require_paths:
@@ -72,5 +81,6 @@ requirements: []
72
81
  rubygems_version: 3.4.20
73
82
  signing_key:
74
83
  specification_version: 4
75
- summary: 'Runtime Cloud: one client for every Runtime product. Sandboxes first.'
84
+ summary: 'Runtime Cloud: Linux sandboxes for agents. The typed client for every verb
85
+ of the API.'
76
86
  test_files: []