@toshicloud/sdk 0.0.0-stage → 0.3.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 (45) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +250 -2
  3. package/dist/client.d.ts +153 -0
  4. package/dist/client.js +92 -0
  5. package/dist/errors.d.ts +28 -0
  6. package/dist/errors.js +77 -0
  7. package/dist/execute.d.ts +7 -0
  8. package/dist/execute.js +380 -0
  9. package/dist/gen/toshi/workspace/v1/artifacts_pb.d.ts +843 -0
  10. package/dist/gen/toshi/workspace/v1/artifacts_pb.js +96 -0
  11. package/dist/gen/toshi/workspace/v1/channels_pb.d.ts +2713 -0
  12. package/dist/gen/toshi/workspace/v1/channels_pb.js +336 -0
  13. package/dist/gen/toshi/workspace/v1/display_pb.d.ts +1166 -0
  14. package/dist/gen/toshi/workspace/v1/display_pb.js +214 -0
  15. package/dist/gen/toshi/workspace/v1/projects_pb.d.ts +1540 -0
  16. package/dist/gen/toshi/workspace/v1/projects_pb.js +207 -0
  17. package/dist/gen/toshi/workspace/v1/recordings_pb.d.ts +1024 -0
  18. package/dist/gen/toshi/workspace/v1/recordings_pb.js +201 -0
  19. package/dist/gen/toshi/workspace/v1/secrets_pb.d.ts +1214 -0
  20. package/dist/gen/toshi/workspace/v1/secrets_pb.js +182 -0
  21. package/dist/gen/toshi/workspace/v1/volumes_pb.d.ts +444 -0
  22. package/dist/gen/toshi/workspace/v1/volumes_pb.js +107 -0
  23. package/dist/gen/toshi/workspace/v1/webhook_pb.d.ts +1018 -0
  24. package/dist/gen/toshi/workspace/v1/webhook_pb.js +153 -0
  25. package/dist/gen/toshi/workspace/v1/workloads_pb.d.ts +2858 -0
  26. package/dist/gen/toshi/workspace/v1/workloads_pb.js +261 -0
  27. package/dist/gen/toshi/workspace/v1/workspace_pb.d.ts +5380 -0
  28. package/dist/gen/toshi/workspace/v1/workspace_pb.js +855 -0
  29. package/dist/index.d.ts +15 -0
  30. package/dist/index.js +14 -0
  31. package/dist/interceptors.d.ts +10 -0
  32. package/dist/interceptors.js +159 -0
  33. package/dist/output.d.ts +7 -0
  34. package/dist/output.js +77 -0
  35. package/dist/retry.d.ts +42 -0
  36. package/dist/retry.js +254 -0
  37. package/dist/run.d.ts +10 -0
  38. package/dist/run.js +175 -0
  39. package/dist/stream.d.ts +21 -0
  40. package/dist/stream.js +84 -0
  41. package/dist/wait.d.ts +13 -0
  42. package/dist/wait.js +41 -0
  43. package/dist/watch.d.ts +16 -0
  44. package/dist/watch.js +277 -0
  45. package/package.json +47 -4
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,251 @@
1
- # Temporary Holding Version
1
+ # toshi-ts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A TypeScript client for the Toshi Workspace API, `toshi.workspace.v1`,
4
+ published as ES modules with type declarations.
5
+
6
+ ```sh
7
+ npm install @toshicloud/sdk @connectrpc/connect @connectrpc/connect-node
8
+ ```
9
+
10
+ Versions up to 0.1.2 were published as `@toshicloud/toshi-ts`.
11
+
12
+ ## Using the client
13
+
14
+ `createToshiClient` takes one set of options. The transport belongs to
15
+ the caller: the client hands its interceptors to the `transport`
16
+ function, and that function builds a transport with them. Every call then
17
+ gets the same token, scope and retries: the helpers below and the
18
+ generated clients alike.
19
+
20
+ In Node, with `@connectrpc/connect-node`:
21
+
22
+ ```ts
23
+ import { readFileSync } from "node:fs";
24
+ import { createConnectTransport } from "@connectrpc/connect-node";
25
+ import { createToshiClient } from "@toshicloud/sdk";
26
+
27
+ const toshi = createToshiClient({
28
+ transport: (interceptors) =>
29
+ createConnectTransport({
30
+ baseUrl: "https://toshi.example.com",
31
+ httpVersion: "2",
32
+ interceptors,
33
+ // Only for a server whose certificate a private CA signed.
34
+ nodeOptions: { ca: readFileSync("ca.pem") },
35
+ }),
36
+ token: process.env.TOSHI_TOKEN,
37
+ project: "default",
38
+ });
39
+
40
+ const { projects } = await toshi.project.listProjects({});
41
+ ```
42
+
43
+ In a browser, with `@connectrpc/connect-web`:
44
+
45
+ ```ts
46
+ import { createConnectTransport } from "@connectrpc/connect-web";
47
+ import { createToshiClient } from "@toshicloud/sdk";
48
+
49
+ const toshi = createToshiClient({
50
+ transport: (interceptors) =>
51
+ createConnectTransport({ baseUrl: "https://toshi.example.com", interceptors }),
52
+ token,
53
+ project: "default",
54
+ });
55
+ ```
56
+
57
+ To add interceptors of your own, put them before the client's:
58
+ `interceptors: [...mine, ...interceptors]`.
59
+
60
+ The package reads no environment variable and no file. The token, the
61
+ server and any CA come from the caller.
62
+
63
+ ### Options
64
+
65
+ - `token`: sent as `Authorization: Bearer <token>` on every call.
66
+ - `project`, `environment`: fill the request's `project` and
67
+ `environment` fields when they are empty. A value in the request wins.
68
+ `environment` is left empty on a request with `shared: true`.
69
+ - `retry`: `{ maxAttempts, initialBackoffMs, maxBackoffMs }`, by default
70
+ 5, 200 ms and 10 s, with full jitter. `retry: false` turns off retries
71
+ and watch reconnects.
72
+
73
+ ### The client's shape
74
+
75
+ The client has one field per Workspace API service: `project`, `secret`,
76
+ `webhook`, `display`, `channel`, `recording`, `volume`, `artifact` and
77
+ `artifactUpload`, each holding that service's generated client.
78
+ `workload` holds `WorkloadService`'s calls, grouped by the type they
79
+ name: `workload.jobs`, `workload.sandboxes` and `workload.services`, one
80
+ method for each call (`create`, `get`, `list`, `update`, `delete`,
81
+ `wait`, `watch`, and `cancel` on a job, `execute` on a sandbox, `start`,
82
+ `stop`, `setMode`, `listRuns`, `wake`, `hold` and `release` on a service). The calls that
83
+ span the three types sit on `workload` itself: `watchEvents` and
84
+ `waitOperation`. `run` sits at the top of the client, as `toshi run`
85
+ sits at the top of the CLI.
86
+
87
+ ```ts
88
+ const { jobs } = await toshi.workload.jobs.list({ pageSize: 10 });
89
+ const job = await toshi.workload.jobs.get({ id: jobs[0].id });
90
+ ```
91
+
92
+ ### Retries
93
+
94
+ The client retries a read, and a write that carries a request key, when
95
+ the connection fails: a `ConnectError` with code `Unavailable`, a
96
+ connection reset or destroyed stream that `@connectrpc/connect-node`
97
+ reports, or a stream the server refused before reading it
98
+ (`REFUSED_STREAM`). A write that takes a request key gets a random one when the
99
+ request has none, so the server applies a retried write once. Other
100
+ writes are never retried. An error the server sends, including
101
+ `Aborted`, `InvalidArgument` and `ResourceExhausted`, reaches the caller
102
+ unchanged. So does any connection failure the client cannot tell apart
103
+ from a server error.
104
+
105
+ ### Waiting and watching
106
+
107
+ - `workload.jobs.wait(req)`, `workload.sandboxes.wait(req)` and
108
+ `workload.services.wait(req)` ask again until the workload reaches the
109
+ state; `workload.waitOperation(req)` asks until the operation is done.
110
+ - `workload.jobs.watch(req)`, `workload.sandboxes.watch(req)`,
111
+ `workload.services.watch(req)`, `workload.watchEvents(req)` and
112
+ `workload.jobs.watchOutput(req)` resolve to a watch you read with
113
+ `for await`. A watch opens its stream when you start reading and
114
+ reconnects after a connection failure from where it stopped: `cursor`
115
+ for the typed watches and events, `offsets` (bytes, as `bigint`) for
116
+ output. With no cursor, a typed watch lists that type first, and
117
+ `snapshot` holds them once its promise resolves; `watchEvents`
118
+ yields the past events page by page before the live ones. `close()` or
119
+ leaving the loop ends the stream. The output watch ends at the output's
120
+ end.
121
+ - Every watch yields the stream's responses: a job watch yields
122
+ `WatchJobsResponse` (`job`, `cursor`, `type`), an event watch yields
123
+ `WatchEventsResponse` (`event`), and the output watch yields
124
+ `WatchOutputResponse` (`stdout`, `stderr` or `end`).
125
+
126
+ ```ts
127
+ const watch = await toshi.workload.watchEvents({ workloadId: id });
128
+ for await (const { event } of watch) {
129
+ console.log(event?.name);
130
+ }
131
+ // watch.cursor resumes a later watch after the last event read.
132
+ ```
133
+
134
+ Every helper takes `{ signal }`, an `AbortSignal` that ends it.
135
+
136
+ ### Running a command
137
+
138
+ `workload.sandboxes.execute(start)` runs a command in a running sandbox
139
+ and resolves once the server has started it. The process is one stream of output chunks, `{ stream: "stdout" |
140
+ "stderr", data: Uint8Array }`. `write` sends standard input in frames of
141
+ at most 64 KiB and resolves once the stream has taken the last one; await
142
+ it before the next `write`, which is refused while one is pending, so the
143
+ client holds at most one buffer of input. `closeStdin` ends standard input
144
+ after a pending write, and a later `write` is refused. `wait` settles when
145
+ the command ends.
146
+
147
+ ```ts
148
+ const proc = await toshi.workload.sandboxes.execute({
149
+ sandboxId: id,
150
+ command: { argv: ["cat"] },
151
+ });
152
+ await proc.write("hello\n");
153
+ await proc.closeStdin();
154
+ for await (const chunk of proc) {
155
+ process[chunk.stream].write(chunk.data);
156
+ }
157
+ await proc.wait(); // rejects with ExitError on a non-zero exit
158
+ ```
159
+
160
+ Without a loop, `wait()` reads and drops the output itself. It rejects
161
+ with `ExitError` when the command fails, is cancelled or ends without an
162
+ exit status, and with `StreamLostError` when the stream ends first. The
163
+ client never runs a command again by itself. Standard input cannot be
164
+ replayed, so the caller decides whether to start again with the same
165
+ `requestKey`. Leaving the loop early cancels the stream, and `wait()`
166
+ then rejects with a `Canceled` error.
167
+
168
+ Execute needs a bidirectional stream: `@connectrpc/connect-node` with
169
+ `httpVersion: "2"`. In a browser, `execute` rejects at once and makes no
170
+ call. Over a transport without HTTP/2, the call fails with the
171
+ transport's or the server's error.
172
+
173
+ ### Running a job
174
+
175
+ `run(req)` creates a job with a `CreateJobRequest` and resolves to the
176
+ job and its output, which is what `toshi run` does: `CreateJob`, then
177
+ `WatchOutput`. It yields output chunks like an execution, and `wait()`
178
+ resolves when the job exits 0 and rejects with `JobExitError` otherwise.
179
+
180
+ ```ts
181
+ const run = await toshi.run({
182
+ spec: { command: { argv: ["./test.sh"] } },
183
+ });
184
+ for await (const chunk of run) {
185
+ process[chunk.stream].write(chunk.data);
186
+ }
187
+ await run.wait(); // rejects with JobExitError on a non-zero exit
188
+ ```
189
+
190
+ Stopping the loop stops only the output stream: the job keeps running,
191
+ and `workload.jobs.cancel` ends it.
192
+
193
+ ## Generated code
194
+
195
+ `src/gen/toshi/workspace/v1/` is generated by
196
+ [`protoc-gen-es`](https://github.com/bufbuild/protobuf-es) from the protos
197
+ in `proto/toshi/workspace/v1` of the
198
+ [toshi-api](https://github.com/toshicloud/toshi-api) repository, one
199
+ `*_pb.ts` file per proto. The generated code is committed and imports
200
+ only `@bufbuild/protobuf`, so installing the package needs no generator.
201
+
202
+ `pin.env` names the toshi-api commit (or, once one exists, the release
203
+ tag) the code is generated from. `mise.toml` pins the versions of Node,
204
+ pnpm, `buf` and `protoc-gen-es`.
205
+
206
+ To regenerate:
207
+
208
+ ```sh
209
+ mise install
210
+ mise exec -- scripts/generate.sh
211
+ ```
212
+
213
+ Moving to another commit or tag is one pull request that changes
214
+ `pin.env` and `src/gen/` together. CI regenerates the code from `pin.env`
215
+ and fails if the result differs from what is committed
216
+ (`scripts/check-generated.sh`).
217
+
218
+ ## Versions
219
+
220
+ The package's major version follows the API's: `1.x` will serve
221
+ `toshi.workspace.v1`, and a `toshi.workspace.v2` gets a new major
222
+ version. Until a Toshi release serves the API, the package stays at
223
+ `0.x` and is generated from a pinned commit.
224
+
225
+ ## Publishing
226
+
227
+ Releases are published to npm by the publish workflow
228
+ (`.github/workflows/publish.yml`) through npm trusted publishing: the
229
+ workflow authenticates with its GitHub OIDC token, and no npm token
230
+ exists. It runs on a `vX.Y.Z` tag that matches the version in
231
+ `package.json`. A new version is a commit on `main` that sets the version
232
+ in `package.json`, followed by its tag.
233
+
234
+ ## Integration test
235
+
236
+ `test/integration/` runs the client against a real `toshi serve` over
237
+ HTTPS with a test CA it mints itself. `TOSHI_INTEGRATION_BIN` names the
238
+ `toshi` binary it runs; when `TOSHI_INTEGRATION_EXPECT_COMMIT` is set, the
239
+ binary must report that commit:
240
+
241
+ ```sh
242
+ TOSHI_INTEGRATION_BIN=/path/to/toshi mise exec -- pnpm vitest run test/integration
243
+ ```
244
+
245
+ The Toshi server's CI runs it against each server change. Without
246
+ `TOSHI_INTEGRATION_BIN`, `pnpm test` skips the integration test and says
247
+ why.
248
+
249
+ ## Licence
250
+
251
+ Apache License 2.0, see LICENSE.
@@ -0,0 +1,153 @@
1
+ import type { MessageInitShape } from "@bufbuild/protobuf";
2
+ import type { Client, Interceptor, Transport } from "@connectrpc/connect";
3
+ import { ArtifactService, ArtifactUploadService } from "./gen/toshi/workspace/v1/artifacts_pb.js";
4
+ import { ChannelService } from "./gen/toshi/workspace/v1/channels_pb.js";
5
+ import { DisplayService } from "./gen/toshi/workspace/v1/display_pb.js";
6
+ import { ProjectService } from "./gen/toshi/workspace/v1/projects_pb.js";
7
+ import { RecordingService } from "./gen/toshi/workspace/v1/recordings_pb.js";
8
+ import { SecretService } from "./gen/toshi/workspace/v1/secrets_pb.js";
9
+ import { VolumeService } from "./gen/toshi/workspace/v1/volumes_pb.js";
10
+ import { WebhookService } from "./gen/toshi/workspace/v1/webhook_pb.js";
11
+ import { CancelJobRequestSchema, CreateJobRequestSchema, CreateSandboxRequestSchema, CreateServiceRequestSchema, DeleteJobRequestSchema, DeleteSandboxRequestSchema, DeleteServiceRequestSchema, GetJobRequestSchema, GetSandboxRequestSchema, GetServiceRequestSchema, ListJobsRequestSchema, ListSandboxesRequestSchema, ListServicesRequestSchema, UpdateJobRequestSchema, UpdateSandboxRequestSchema, UpdateServiceRequestSchema, WaitJobRequestSchema, WaitSandboxRequestSchema, WaitServiceRequestSchema, WatchJobsRequestSchema, WatchSandboxesRequestSchema, WatchServicesRequestSchema } from "./gen/toshi/workspace/v1/workloads_pb.js";
12
+ import type { CancelJobResponse, CreateJobResponse, CreateSandboxResponse, CreateServiceResponse, DeleteJobResponse, DeleteSandboxResponse, DeleteServiceResponse, GetJobResponse, GetSandboxResponse, GetServiceResponse, ListJobsResponse, ListSandboxesResponse, ListServicesResponse, UpdateJobResponse, UpdateSandboxResponse, UpdateServiceResponse, WaitJobResponse, WaitSandboxResponse, WaitServiceResponse, WatchJobsResponse, WatchSandboxesResponse, WatchServicesResponse } from "./gen/toshi/workspace/v1/workloads_pb.js";
13
+ import { ExecuteStartSchema, HoldServiceRequestSchema, ListServiceRunsRequestSchema, ReleaseServiceRequestSchema, SetServiceModeRequestSchema, StartServiceRequestSchema, StopServiceRequestSchema, WaitOperationRequestSchema, WakeServiceRequestSchema, WatchEventsRequestSchema, WatchOutputRequestSchema } from "./gen/toshi/workspace/v1/workspace_pb.js";
14
+ import type { HoldServiceResponse, Job, ListServiceRunsResponse, Operation, ReleaseServiceResponse, Sandbox, Service, SetServiceModeResponse, StartServiceResponse, StopServiceResponse, WakeServiceResponse, WatchEventsResponse, WatchOutputResponse } from "./gen/toshi/workspace/v1/workspace_pb.js";
15
+ import type { RetryPolicy } from "./retry.js";
16
+ /** How the client is configured; the caller builds the transport. */
17
+ export interface ToshiOptions {
18
+ /** Builds the caller's transport (connect-node or connect-web) with the client's interceptors. */
19
+ transport: (interceptors: Interceptor[]) => Transport;
20
+ token?: string;
21
+ project?: string;
22
+ environment?: string;
23
+ /** false turns off retries and watch reconnects. */
24
+ retry?: Partial<RetryPolicy> | false;
25
+ }
26
+ /** Per-call options. */
27
+ export interface CallOptions {
28
+ signal?: AbortSignal;
29
+ }
30
+ /** One client per Workspace API service, plus the helpers that live on top of them. */
31
+ export interface ToshiClient {
32
+ readonly project: Client<typeof ProjectService>;
33
+ readonly secret: Client<typeof SecretService>;
34
+ readonly webhook: Client<typeof WebhookService>;
35
+ readonly display: Client<typeof DisplayService>;
36
+ readonly channel: Client<typeof ChannelService>;
37
+ readonly recording: Client<typeof RecordingService>;
38
+ readonly volume: Client<typeof VolumeService>;
39
+ readonly artifact: Client<typeof ArtifactService>;
40
+ readonly artifactUpload: Client<typeof ArtifactUploadService>;
41
+ readonly workload: WorkloadClient;
42
+ run(req: MessageInitShape<typeof CreateJobRequestSchema>, opts?: CallOptions): Promise<JobRun>;
43
+ }
44
+ /** WorkloadService's calls, grouped by the type they name. */
45
+ export interface WorkloadClient {
46
+ readonly jobs: JobsClient;
47
+ readonly sandboxes: SandboxesClient;
48
+ readonly services: ServicesClient;
49
+ waitOperation(req: MessageInitShape<typeof WaitOperationRequestSchema>, opts?: CallOptions): Promise<Operation>;
50
+ watchEvents(req: MessageInitShape<typeof WatchEventsRequestSchema>, opts?: CallOptions): Promise<EventWatch>;
51
+ }
52
+ /** A job's calls: one method for each of WorkloadService's job calls. */
53
+ export interface JobsClient {
54
+ create(req: MessageInitShape<typeof CreateJobRequestSchema>, opts?: CallOptions): Promise<CreateJobResponse>;
55
+ get(req: MessageInitShape<typeof GetJobRequestSchema>, opts?: CallOptions): Promise<GetJobResponse>;
56
+ list(req: MessageInitShape<typeof ListJobsRequestSchema>, opts?: CallOptions): Promise<ListJobsResponse>;
57
+ update(req: MessageInitShape<typeof UpdateJobRequestSchema>, opts?: CallOptions): Promise<UpdateJobResponse>;
58
+ delete(req: MessageInitShape<typeof DeleteJobRequestSchema>, opts?: CallOptions): Promise<DeleteJobResponse>;
59
+ cancel(req: MessageInitShape<typeof CancelJobRequestSchema>, opts?: CallOptions): Promise<CancelJobResponse>;
60
+ wait(req: MessageInitShape<typeof WaitJobRequestSchema>, opts?: CallOptions): Promise<WaitJobResponse>;
61
+ watch(req: MessageInitShape<typeof WatchJobsRequestSchema>, opts?: CallOptions): Promise<JobWatch>;
62
+ watchOutput(req: MessageInitShape<typeof WatchOutputRequestSchema>, opts?: CallOptions): Promise<OutputWatch>;
63
+ }
64
+ /** A sandbox's calls: one method for each of WorkloadService's sandbox calls. */
65
+ export interface SandboxesClient {
66
+ create(req: MessageInitShape<typeof CreateSandboxRequestSchema>, opts?: CallOptions): Promise<CreateSandboxResponse>;
67
+ get(req: MessageInitShape<typeof GetSandboxRequestSchema>, opts?: CallOptions): Promise<GetSandboxResponse>;
68
+ list(req: MessageInitShape<typeof ListSandboxesRequestSchema>, opts?: CallOptions): Promise<ListSandboxesResponse>;
69
+ update(req: MessageInitShape<typeof UpdateSandboxRequestSchema>, opts?: CallOptions): Promise<UpdateSandboxResponse>;
70
+ delete(req: MessageInitShape<typeof DeleteSandboxRequestSchema>, opts?: CallOptions): Promise<DeleteSandboxResponse>;
71
+ wait(req: MessageInitShape<typeof WaitSandboxRequestSchema>, opts?: CallOptions): Promise<WaitSandboxResponse>;
72
+ watch(req: MessageInitShape<typeof WatchSandboxesRequestSchema>, opts?: CallOptions): Promise<SandboxWatch>;
73
+ execute(start: MessageInitShape<typeof ExecuteStartSchema>, opts?: CallOptions): Promise<Process>;
74
+ }
75
+ /** A service's calls: one method for each of WorkloadService's service calls. */
76
+ export interface ServicesClient {
77
+ create(req: MessageInitShape<typeof CreateServiceRequestSchema>, opts?: CallOptions): Promise<CreateServiceResponse>;
78
+ get(req: MessageInitShape<typeof GetServiceRequestSchema>, opts?: CallOptions): Promise<GetServiceResponse>;
79
+ list(req: MessageInitShape<typeof ListServicesRequestSchema>, opts?: CallOptions): Promise<ListServicesResponse>;
80
+ update(req: MessageInitShape<typeof UpdateServiceRequestSchema>, opts?: CallOptions): Promise<UpdateServiceResponse>;
81
+ delete(req: MessageInitShape<typeof DeleteServiceRequestSchema>, opts?: CallOptions): Promise<DeleteServiceResponse>;
82
+ wait(req: MessageInitShape<typeof WaitServiceRequestSchema>, opts?: CallOptions): Promise<WaitServiceResponse>;
83
+ watch(req: MessageInitShape<typeof WatchServicesRequestSchema>, opts?: CallOptions): Promise<ServiceWatch>;
84
+ start(req: MessageInitShape<typeof StartServiceRequestSchema>, opts?: CallOptions): Promise<StartServiceResponse>;
85
+ stop(req: MessageInitShape<typeof StopServiceRequestSchema>, opts?: CallOptions): Promise<StopServiceResponse>;
86
+ setMode(req: MessageInitShape<typeof SetServiceModeRequestSchema>, opts?: CallOptions): Promise<SetServiceModeResponse>;
87
+ release(req: MessageInitShape<typeof ReleaseServiceRequestSchema>, opts?: CallOptions): Promise<ReleaseServiceResponse>;
88
+ wake(req: MessageInitShape<typeof WakeServiceRequestSchema>, opts?: CallOptions): Promise<WakeServiceResponse>;
89
+ hold(req: MessageInitShape<typeof HoldServiceRequestSchema>, opts?: CallOptions): Promise<HoldServiceResponse>;
90
+ listRuns(req: MessageInitShape<typeof ListServiceRunsRequestSchema>, opts?: CallOptions): Promise<ListServiceRunsResponse>;
91
+ }
92
+ /** A live stream of a job's changes. */
93
+ export interface JobWatch extends AsyncIterable<WatchJobsResponse> {
94
+ readonly cursor: string;
95
+ readonly snapshot: Job[] | undefined;
96
+ close(): void;
97
+ }
98
+ /** A live stream of a sandbox's changes. */
99
+ export interface SandboxWatch extends AsyncIterable<WatchSandboxesResponse> {
100
+ readonly cursor: string;
101
+ readonly snapshot: Sandbox[] | undefined;
102
+ close(): void;
103
+ }
104
+ /** A live stream of a service's changes. */
105
+ export interface ServiceWatch extends AsyncIterable<WatchServicesResponse> {
106
+ readonly cursor: string;
107
+ readonly snapshot: Service[] | undefined;
108
+ close(): void;
109
+ }
110
+ /** A live stream of events; every message is the stream's response. */
111
+ export interface EventWatch extends AsyncIterable<WatchEventsResponse> {
112
+ readonly cursor: string;
113
+ close(): void;
114
+ }
115
+ /** A live stream of a job's output. */
116
+ export interface OutputWatch extends AsyncIterable<WatchOutputResponse> {
117
+ readonly offsets: {
118
+ readonly stdout: bigint;
119
+ readonly stderr: bigint;
120
+ };
121
+ close(): void;
122
+ }
123
+ /** One chunk of output. */
124
+ export type OutputChunk = {
125
+ stream: "stdout";
126
+ data: Uint8Array;
127
+ } | {
128
+ stream: "stderr";
129
+ data: Uint8Array;
130
+ };
131
+ /** A running execution. */
132
+ export interface Process extends AsyncIterable<OutputChunk> {
133
+ readonly executionId: string;
134
+ readonly requestKey: string;
135
+ write(data: Uint8Array | string): Promise<void>;
136
+ closeStdin(): Promise<void>;
137
+ wait(): Promise<void>;
138
+ }
139
+ /** A job started by `run`: its output as it comes, then its outcome. */
140
+ export interface JobRun extends AsyncIterable<OutputChunk> {
141
+ readonly job: Job;
142
+ wait(): Promise<void>;
143
+ }
144
+ /**
145
+ * Creates the client: one normalized retry setting, the auth, scope, key and
146
+ * retry interceptors (auth outermost, retry innermost), one transport for every
147
+ * client and helper.
148
+ *
149
+ * Since 0.2.0 the public contract is WorkloadService, not WorkspaceService: its
150
+ * calls are grouped by the type they name under `workload`, and the generated
151
+ * client is not handed out whole.
152
+ */
153
+ export declare function createToshiClient(options: ToshiOptions): ToshiClient;