@vercel/sandbox 2.0.0-beta.11 → 2.0.0-beta.13

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 (196) hide show
  1. package/README.md +8 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/api-client/api-client.cjs +456 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +790 -0
  6. package/dist/api-client/api-client.d.ts +784 -777
  7. package/dist/api-client/api-client.js +445 -471
  8. package/dist/api-client/api-client.js.map +1 -1
  9. package/dist/api-client/api-error.cjs +32 -0
  10. package/dist/api-client/api-error.cjs.map +1 -0
  11. package/dist/api-client/api-error.d.cts +29 -0
  12. package/dist/api-client/api-error.d.ts +21 -18
  13. package/dist/api-client/api-error.js +28 -33
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +125 -0
  16. package/dist/api-client/base-client.cjs.map +1 -0
  17. package/dist/api-client/base-client.d.cts +38 -0
  18. package/dist/api-client/base-client.d.ts +31 -36
  19. package/dist/api-client/base-client.js +110 -130
  20. package/dist/api-client/base-client.js.map +1 -1
  21. package/dist/api-client/file-writer.cjs +62 -0
  22. package/dist/api-client/file-writer.cjs.map +1 -0
  23. package/dist/api-client/file-writer.d.cts +66 -0
  24. package/dist/api-client/file-writer.d.ts +56 -52
  25. package/dist/api-client/file-writer.js +57 -61
  26. package/dist/api-client/file-writer.js.map +1 -1
  27. package/dist/api-client/index.cjs +2 -0
  28. package/dist/api-client/index.d.ts +2 -2
  29. package/dist/api-client/index.js +4 -21
  30. package/dist/api-client/validators.cjs +182 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +1469 -0
  33. package/dist/api-client/validators.d.ts +1282 -3699
  34. package/dist/api-client/validators.js +155 -170
  35. package/dist/api-client/validators.js.map +1 -1
  36. package/dist/api-client/with-retry.cjs +89 -0
  37. package/dist/api-client/with-retry.cjs.map +1 -0
  38. package/dist/api-client/with-retry.d.cts +10 -0
  39. package/dist/api-client/with-retry.d.ts +9 -13
  40. package/dist/api-client/with-retry.js +81 -102
  41. package/dist/api-client/with-retry.js.map +1 -1
  42. package/dist/auth/api.cjs +29 -0
  43. package/dist/auth/api.cjs.map +1 -0
  44. package/dist/auth/api.js +26 -25
  45. package/dist/auth/api.js.map +1 -1
  46. package/dist/auth/error.cjs +13 -0
  47. package/dist/auth/error.cjs.map +1 -0
  48. package/dist/auth/error.js +11 -11
  49. package/dist/auth/error.js.map +1 -1
  50. package/dist/auth/file.cjs +64 -0
  51. package/dist/auth/file.cjs.map +1 -0
  52. package/dist/auth/file.d.cts +26 -0
  53. package/dist/auth/file.d.ts +19 -15
  54. package/dist/auth/file.js +49 -64
  55. package/dist/auth/file.js.map +1 -1
  56. package/dist/auth/index.cjs +12 -0
  57. package/dist/auth/index.d.cts +5 -0
  58. package/dist/auth/index.d.ts +5 -6
  59. package/dist/auth/index.js +6 -27
  60. package/dist/auth/linked-project.cjs +38 -0
  61. package/dist/auth/linked-project.cjs.map +1 -0
  62. package/dist/auth/linked-project.js +30 -64
  63. package/dist/auth/linked-project.js.map +1 -1
  64. package/dist/auth/oauth.cjs +205 -0
  65. package/dist/auth/oauth.cjs.map +1 -0
  66. package/dist/auth/oauth.d.cts +135 -0
  67. package/dist/auth/oauth.d.ts +113 -109
  68. package/dist/auth/oauth.js +185 -252
  69. package/dist/auth/oauth.js.map +1 -1
  70. package/dist/auth/poll-for-token.cjs +82 -0
  71. package/dist/auth/poll-for-token.cjs.map +1 -0
  72. package/dist/auth/poll-for-token.d.cts +28 -0
  73. package/dist/auth/poll-for-token.d.ts +23 -15
  74. package/dist/auth/poll-for-token.js +79 -64
  75. package/dist/auth/poll-for-token.js.map +1 -1
  76. package/dist/auth/project.cjs +80 -0
  77. package/dist/auth/project.cjs.map +1 -0
  78. package/dist/auth/project.d.cts +44 -0
  79. package/dist/auth/project.d.ts +12 -8
  80. package/dist/auth/project.js +70 -72
  81. package/dist/auth/project.js.map +1 -1
  82. package/dist/auth/zod.cjs +22 -0
  83. package/dist/auth/zod.cjs.map +1 -0
  84. package/dist/auth/zod.js +18 -17
  85. package/dist/auth/zod.js.map +1 -1
  86. package/dist/command.cjs +328 -0
  87. package/dist/command.cjs.map +1 -0
  88. package/dist/command.d.cts +289 -0
  89. package/dist/command.d.ts +265 -171
  90. package/dist/command.js +323 -226
  91. package/dist/command.js.map +1 -1
  92. package/dist/constants.d.cts +5 -0
  93. package/dist/constants.d.ts +5 -1
  94. package/dist/index.cjs +13 -0
  95. package/dist/index.d.cts +7 -0
  96. package/dist/index.d.ts +7 -6
  97. package/dist/index.js +7 -17
  98. package/dist/network-policy.d.cts +100 -0
  99. package/dist/network-policy.d.ts +32 -28
  100. package/dist/sandbox.cjs +694 -0
  101. package/dist/sandbox.cjs.map +1 -0
  102. package/dist/sandbox.d.cts +796 -0
  103. package/dist/sandbox.d.ts +783 -711
  104. package/dist/sandbox.js +684 -615
  105. package/dist/sandbox.js.map +1 -1
  106. package/dist/session.cjs +520 -0
  107. package/dist/session.cjs.map +1 -0
  108. package/dist/session.d.cts +406 -0
  109. package/dist/session.d.ts +398 -367
  110. package/dist/session.js +517 -505
  111. package/dist/session.js.map +1 -1
  112. package/dist/snapshot.cjs +116 -0
  113. package/dist/snapshot.cjs.map +1 -0
  114. package/dist/snapshot.d.cts +107 -0
  115. package/dist/snapshot.d.ts +98 -91
  116. package/dist/snapshot.js +114 -115
  117. package/dist/snapshot.js.map +1 -1
  118. package/dist/utils/array.cjs +17 -0
  119. package/dist/utils/array.cjs.map +1 -0
  120. package/dist/utils/array.js +12 -15
  121. package/dist/utils/array.js.map +1 -1
  122. package/dist/utils/consume-readable.cjs +18 -0
  123. package/dist/utils/consume-readable.cjs.map +1 -0
  124. package/dist/utils/consume-readable.js +13 -12
  125. package/dist/utils/consume-readable.js.map +1 -1
  126. package/dist/utils/decode-base64-url.cjs +15 -0
  127. package/dist/utils/decode-base64-url.cjs.map +1 -0
  128. package/dist/utils/decode-base64-url.js +10 -9
  129. package/dist/utils/decode-base64-url.js.map +1 -1
  130. package/dist/utils/dev-credentials.cjs +142 -0
  131. package/dist/utils/dev-credentials.cjs.map +1 -0
  132. package/dist/utils/dev-credentials.js +126 -184
  133. package/dist/utils/dev-credentials.js.map +1 -1
  134. package/dist/utils/get-credentials.cjs +123 -0
  135. package/dist/utils/get-credentials.cjs.map +1 -0
  136. package/dist/utils/get-credentials.d.cts +21 -0
  137. package/dist/utils/get-credentials.d.ts +19 -61
  138. package/dist/utils/get-credentials.js +106 -140
  139. package/dist/utils/get-credentials.js.map +1 -1
  140. package/dist/utils/log.cjs +25 -0
  141. package/dist/utils/log.cjs.map +1 -0
  142. package/dist/utils/log.js +15 -17
  143. package/dist/utils/log.js.map +1 -1
  144. package/dist/utils/network-policy.cjs +65 -0
  145. package/dist/utils/network-policy.cjs.map +1 -0
  146. package/dist/utils/network-policy.js +58 -77
  147. package/dist/utils/network-policy.js.map +1 -1
  148. package/dist/utils/normalizePath.cjs +27 -0
  149. package/dist/utils/normalizePath.cjs.map +1 -0
  150. package/dist/utils/normalizePath.js +21 -28
  151. package/dist/utils/normalizePath.js.map +1 -1
  152. package/dist/utils/resolveSignal.cjs +20 -0
  153. package/dist/utils/resolveSignal.cjs.map +1 -0
  154. package/dist/utils/resolveSignal.d.cts +15 -0
  155. package/dist/utils/resolveSignal.d.ts +12 -10
  156. package/dist/utils/resolveSignal.js +14 -17
  157. package/dist/utils/resolveSignal.js.map +1 -1
  158. package/dist/utils/sandbox-snapshot.cjs +14 -0
  159. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  160. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  161. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  162. package/dist/utils/sandbox-snapshot.js +14 -0
  163. package/dist/utils/sandbox-snapshot.js.map +1 -0
  164. package/dist/utils/types.cjs +13 -0
  165. package/dist/utils/types.cjs.map +1 -0
  166. package/dist/utils/types.d.cts +11 -0
  167. package/dist/utils/types.d.ts +5 -7
  168. package/dist/utils/types.js +8 -8
  169. package/dist/utils/types.js.map +1 -1
  170. package/dist/version.cjs +7 -0
  171. package/dist/version.cjs.map +1 -0
  172. package/dist/version.js +5 -5
  173. package/dist/version.js.map +1 -1
  174. package/package.json +23 -3
  175. package/dist/api-client/index.js.map +0 -1
  176. package/dist/auth/api.d.ts +0 -6
  177. package/dist/auth/error.d.ts +0 -11
  178. package/dist/auth/index.js.map +0 -1
  179. package/dist/auth/linked-project.d.ts +0 -10
  180. package/dist/auth/zod.d.ts +0 -5
  181. package/dist/constants.js +0 -3
  182. package/dist/constants.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/network-policy.js +0 -3
  185. package/dist/network-policy.js.map +0 -1
  186. package/dist/utils/array.d.ts +0 -9
  187. package/dist/utils/consume-readable.d.ts +0 -5
  188. package/dist/utils/convert-sandbox.d.ts +0 -6
  189. package/dist/utils/convert-sandbox.js +0 -14
  190. package/dist/utils/convert-sandbox.js.map +0 -1
  191. package/dist/utils/decode-base64-url.d.ts +0 -7
  192. package/dist/utils/dev-credentials.d.ts +0 -37
  193. package/dist/utils/log.d.ts +0 -2
  194. package/dist/utils/network-policy.d.ts +0 -7
  195. package/dist/utils/normalizePath.d.ts +0 -17
  196. package/dist/version.d.ts +0 -1
@@ -0,0 +1,328 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_api_client = require('./api-client/api-client.cjs');
3
+ require('./api-client/index.cjs');
4
+ const require_get_credentials = require('./utils/get-credentials.cjs');
5
+ const require_resolveSignal = require('./utils/resolveSignal.cjs');
6
+ let __workflow_serde = require("@workflow/serde");
7
+
8
+ //#region src/command.ts
9
+ /**
10
+ * A command executed in a Sandbox.
11
+ *
12
+ * For detached commands, you can {@link wait} to get a {@link CommandFinished} instance
13
+ * with the populated exit code. For non-detached commands, {@link Sandbox.runCommand}
14
+ * automatically waits and returns a {@link CommandFinished} instance.
15
+ *
16
+ * You can iterate over command output with {@link logs}.
17
+ *
18
+ * @see {@link Sandbox.runCommand} to start a command.
19
+ *
20
+ * @hideconstructor
21
+ */
22
+ var Command = class Command {
23
+ /**
24
+ * Lazily resolve credentials and construct an API client.
25
+ * @internal
26
+ */
27
+ async ensureClient() {
28
+ "use step";
29
+ if (this._client) return this._client;
30
+ const credentials = await require_get_credentials.getCredentials();
31
+ this._client = new require_api_client.APIClient({
32
+ teamId: credentials.teamId,
33
+ token: credentials.token
34
+ });
35
+ return this._client;
36
+ }
37
+ /**
38
+ * ID of the command execution.
39
+ */
40
+ get cmdId() {
41
+ return this.cmd.id;
42
+ }
43
+ get cwd() {
44
+ return this.cmd.cwd;
45
+ }
46
+ get startedAt() {
47
+ return this.cmd.startedAt;
48
+ }
49
+ /**
50
+ * @param params - Object containing the client, sandbox ID, and command data.
51
+ * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.
52
+ * @param params.sessionId - The ID of the session where the command is running.
53
+ * @param params.cmd - The command data.
54
+ * @param params.output - Optional cached output to restore (used during deserialization).
55
+ */
56
+ constructor({ client, sessionId, cmd, output }) {
57
+ this._client = null;
58
+ this.outputCache = null;
59
+ this._resolvedOutput = null;
60
+ this._client = client ?? null;
61
+ this.sessionId = sessionId;
62
+ this.cmd = cmd;
63
+ this.exitCode = cmd.exitCode ?? null;
64
+ if (output) {
65
+ this._resolvedOutput = output;
66
+ this.outputCache = Promise.resolve({
67
+ stdout: output.stdout,
68
+ stderr: output.stderr,
69
+ both: output.stdout + output.stderr
70
+ });
71
+ }
72
+ }
73
+ /**
74
+ * Serialize a Command instance to plain data for @workflow/serde.
75
+ *
76
+ * @param instance - The Command instance to serialize
77
+ * @returns A plain object containing the sandbox ID, command data, and output if fetched
78
+ */
79
+ static [__workflow_serde.WORKFLOW_SERIALIZE](instance) {
80
+ const serialized = {
81
+ sandboxId: instance.sessionId,
82
+ cmd: instance.cmd
83
+ };
84
+ if (instance._resolvedOutput) serialized.output = instance._resolvedOutput;
85
+ return serialized;
86
+ }
87
+ /**
88
+ * Deserialize plain data back into a Command instance for @workflow/serde.
89
+ *
90
+ * The deserialized instance will lazily create an API client using
91
+ * OIDC or environment credentials when needed.
92
+ *
93
+ * @param data - The serialized command data
94
+ * @returns The reconstructed Command instance
95
+ */
96
+ static [__workflow_serde.WORKFLOW_DESERIALIZE](data) {
97
+ return new Command({
98
+ sessionId: data.sandboxId,
99
+ cmd: data.cmd,
100
+ output: data.output
101
+ });
102
+ }
103
+ /**
104
+ * Iterate over the output of this command.
105
+ *
106
+ * ```
107
+ * for await (const log of cmd.logs()) {
108
+ * if (log.stream === "stdout") {
109
+ * process.stdout.write(log.data);
110
+ * } else {
111
+ * process.stderr.write(log.data);
112
+ * }
113
+ * }
114
+ * ```
115
+ *
116
+ * @param opts - Optional parameters.
117
+ * @param opts.signal - An AbortSignal to cancel log streaming.
118
+ * @returns An async iterable of log entries from the command output.
119
+ *
120
+ * @see {@link Command.stdout}, {@link Command.stderr}, and {@link Command.output}
121
+ * to access output as a string.
122
+ */
123
+ logs(opts) {
124
+ if (!this._client) throw new Error("logs() requires an API client. Call an async method first to initialize the client.");
125
+ return this._client.getLogs({
126
+ sessionId: this.sessionId,
127
+ cmdId: this.cmd.id,
128
+ signal: opts?.signal
129
+ });
130
+ }
131
+ /**
132
+ * Wait for a command to exit and populate its exit code.
133
+ *
134
+ * This method is useful for detached commands where you need to wait
135
+ * for completion. For non-detached commands, {@link Sandbox.runCommand}
136
+ * automatically waits and returns a {@link CommandFinished} instance.
137
+ *
138
+ * ```
139
+ * const detachedCmd = await sandbox.runCommand({ cmd: 'sleep', args: ['5'], detached: true });
140
+ * const result = await detachedCmd.wait();
141
+ * if (result.exitCode !== 0) {
142
+ * console.error("Something went wrong...")
143
+ * }
144
+ * ```
145
+ *
146
+ * @param params - Optional parameters.
147
+ * @param params.signal - An AbortSignal to cancel waiting.
148
+ * @returns A {@link CommandFinished} instance with populated exit code.
149
+ */
150
+ async wait(params) {
151
+ "use step";
152
+ const client = await this.ensureClient();
153
+ params?.signal?.throwIfAborted();
154
+ const command = await client.getCommand({
155
+ sessionId: this.sessionId,
156
+ cmdId: this.cmd.id,
157
+ wait: true,
158
+ signal: params?.signal
159
+ });
160
+ return new CommandFinished({
161
+ client,
162
+ sessionId: this.sessionId,
163
+ cmd: command.json.command,
164
+ exitCode: command.json.command.exitCode
165
+ });
166
+ }
167
+ /**
168
+ * Get cached output, fetching logs only once and reusing for concurrent calls.
169
+ * This prevents race conditions when stdout() and stderr() are called in parallel.
170
+ */
171
+ async getCachedOutput(opts) {
172
+ if (!this.outputCache) this.outputCache = (async () => {
173
+ try {
174
+ opts?.signal?.throwIfAborted();
175
+ await this.ensureClient();
176
+ let stdout = "";
177
+ let stderr = "";
178
+ let both = "";
179
+ for await (const log of this.logs({ signal: opts?.signal })) {
180
+ both += log.data;
181
+ if (log.stream === "stdout") stdout += log.data;
182
+ else stderr += log.data;
183
+ }
184
+ this._resolvedOutput = {
185
+ stdout,
186
+ stderr
187
+ };
188
+ return {
189
+ stdout,
190
+ stderr,
191
+ both
192
+ };
193
+ } catch (err) {
194
+ this.outputCache = null;
195
+ throw err;
196
+ }
197
+ })();
198
+ return this.outputCache;
199
+ }
200
+ /**
201
+ * Get the output of `stdout`, `stderr`, or both as a string.
202
+ *
203
+ * NOTE: This may throw string conversion errors if the command does
204
+ * not output valid Unicode.
205
+ *
206
+ * @param stream - The output stream to read: "stdout", "stderr", or "both".
207
+ * @param opts - Optional parameters.
208
+ * @param opts.signal - An AbortSignal to cancel output streaming.
209
+ * @returns The output of the specified stream(s) as a string.
210
+ */
211
+ async output(stream = "both", opts) {
212
+ "use step";
213
+ return (await this.getCachedOutput(opts))[stream];
214
+ }
215
+ /**
216
+ * Get the output of `stdout` as a string.
217
+ *
218
+ * NOTE: This may throw string conversion errors if the command does
219
+ * not output valid Unicode.
220
+ *
221
+ * @param opts - Optional parameters.
222
+ * @param opts.signal - An AbortSignal to cancel output streaming.
223
+ * @returns The standard output of the command.
224
+ */
225
+ async stdout(opts) {
226
+ "use step";
227
+ return this.output("stdout", opts);
228
+ }
229
+ /**
230
+ * Get the output of `stderr` as a string.
231
+ *
232
+ * NOTE: This may throw string conversion errors if the command does
233
+ * not output valid Unicode.
234
+ *
235
+ * @param opts - Optional parameters.
236
+ * @param opts.signal - An AbortSignal to cancel output streaming.
237
+ * @returns The standard error output of the command.
238
+ */
239
+ async stderr(opts) {
240
+ "use step";
241
+ return this.output("stderr", opts);
242
+ }
243
+ /**
244
+ * Kill a running command in a sandbox.
245
+ *
246
+ * @param signal - The signal to send the running process. Defaults to SIGTERM.
247
+ * @param opts - Optional parameters.
248
+ * @param opts.abortSignal - An AbortSignal to cancel the kill operation.
249
+ * @returns Promise<void>.
250
+ */
251
+ async kill(signal, opts) {
252
+ "use step";
253
+ await (await this.ensureClient()).killCommand({
254
+ sessionId: this.sessionId,
255
+ commandId: this.cmd.id,
256
+ signal: require_resolveSignal.resolveSignal(signal ?? "SIGTERM"),
257
+ abortSignal: opts?.abortSignal
258
+ });
259
+ }
260
+ };
261
+ /**
262
+ * A command that has finished executing.
263
+ *
264
+ * The exit code is immediately available and populated upon creation.
265
+ * Unlike {@link Command}, you don't need to call wait() - the command
266
+ * has already completed execution.
267
+ *
268
+ * @hideconstructor
269
+ */
270
+ var CommandFinished = class CommandFinished extends Command {
271
+ /**
272
+ * @param params - Object containing client, sandbox ID, command data, and exit code.
273
+ * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.
274
+ * @param params.sessionId - The ID of the session where the command ran.
275
+ * @param params.cmd - The command data.
276
+ * @param params.exitCode - The exit code of the completed command.
277
+ * @param params.output - Optional cached output to restore (used during deserialization).
278
+ */
279
+ constructor(params) {
280
+ super({ ...params });
281
+ this.exitCode = params.exitCode;
282
+ }
283
+ /**
284
+ * Serialize a CommandFinished instance to plain data for @workflow/serde.
285
+ *
286
+ * @param instance - The CommandFinished instance to serialize
287
+ * @returns A plain object containing the sandbox ID, command data, exit code, and output if fetched
288
+ */
289
+ static [__workflow_serde.WORKFLOW_SERIALIZE](instance) {
290
+ return {
291
+ ...Command[__workflow_serde.WORKFLOW_SERIALIZE](instance),
292
+ exitCode: instance.exitCode
293
+ };
294
+ }
295
+ /**
296
+ * Deserialize plain data back into a CommandFinished instance for @workflow/serde.
297
+ *
298
+ * The deserialized instance will lazily create an API client using
299
+ * OIDC or environment credentials when needed.
300
+ *
301
+ * @param data - The serialized command finished data
302
+ * @returns The reconstructed CommandFinished instance
303
+ */
304
+ static [__workflow_serde.WORKFLOW_DESERIALIZE](data) {
305
+ return new CommandFinished({
306
+ sessionId: data.sandboxId,
307
+ cmd: data.cmd,
308
+ exitCode: data.exitCode,
309
+ output: data.output
310
+ });
311
+ }
312
+ /**
313
+ * The wait method is not needed for CommandFinished instances since
314
+ * the command has already completed and exitCode is populated.
315
+ *
316
+ * @deprecated This method is redundant for CommandFinished instances.
317
+ * The exitCode is already available.
318
+ * @returns This CommandFinished instance.
319
+ */
320
+ async wait() {
321
+ return this;
322
+ }
323
+ };
324
+
325
+ //#endregion
326
+ exports.Command = Command;
327
+ exports.CommandFinished = CommandFinished;
328
+ //# sourceMappingURL=command.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.cjs","names":["getCredentials","APIClient","WORKFLOW_SERIALIZE","serialized: SerializedCommand","WORKFLOW_DESERIALIZE","resolveSignal"],"sources":["../src/command.ts"],"sourcesContent":["import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from \"@workflow/serde\";\nimport { APIClient, type CommandData } from \"./api-client/index.js\";\nimport { getCredentials } from \"./utils/get-credentials.js\";\nimport { resolveSignal, type Signal } from \"./utils/resolveSignal.js\";\n\n/**\n * Cached output from a command execution.\n */\nexport interface CommandOutput {\n stdout: string;\n stderr: string;\n}\n\n/**\n * Serialized representation of a Command for @workflow/serde.\n */\nexport interface SerializedCommand {\n sandboxId: string;\n cmd: CommandData;\n /** Cached output, included if output was fetched before serialization */\n output?: CommandOutput;\n}\n\n/**\n * Serialized representation of a CommandFinished for @workflow/serde.\n */\nexport interface SerializedCommandFinished extends SerializedCommand {\n exitCode: number;\n}\n\n/**\n * A command executed in a Sandbox.\n *\n * For detached commands, you can {@link wait} to get a {@link CommandFinished} instance\n * with the populated exit code. For non-detached commands, {@link Sandbox.runCommand}\n * automatically waits and returns a {@link CommandFinished} instance.\n *\n * You can iterate over command output with {@link logs}.\n *\n * @see {@link Sandbox.runCommand} to start a command.\n *\n * @hideconstructor\n */\nexport class Command {\n /**\n * Cached API client instance.\n * @internal\n */\n protected _client: APIClient | null = null;\n\n /**\n * Lazily resolve credentials and construct an API client.\n * @internal\n */\n protected async ensureClient(): Promise<APIClient> {\n \"use step\";\n if (this._client) return this._client;\n const credentials = await getCredentials();\n this._client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n return this._client;\n }\n\n /**\n * ID of the session this command is running in.\n */\n protected sessionId: string;\n\n /**\n * Data for the command execution.\n */\n protected cmd: CommandData;\n\n public exitCode: number | null;\n\n protected outputCache: Promise<{\n stdout: string;\n stderr: string;\n both: string;\n }> | null = null;\n\n /**\n * Synchronously accessible resolved output, populated after output is fetched.\n * Used for serialization.\n * @internal\n */\n protected _resolvedOutput: CommandOutput | null = null;\n\n /**\n * ID of the command execution.\n */\n get cmdId() {\n return this.cmd.id;\n }\n\n get cwd() {\n return this.cmd.cwd;\n }\n\n get startedAt() {\n return this.cmd.startedAt;\n }\n\n /**\n * @param params - Object containing the client, sandbox ID, and command data.\n * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.\n * @param params.sessionId - The ID of the session where the command is running.\n * @param params.cmd - The command data.\n * @param params.output - Optional cached output to restore (used during deserialization).\n */\n constructor({\n client,\n sessionId,\n cmd,\n output,\n }: {\n client?: APIClient;\n sessionId: string;\n cmd: CommandData;\n output?: CommandOutput;\n }) {\n this._client = client ?? null;\n this.sessionId = sessionId;\n this.cmd = cmd;\n this.exitCode = cmd.exitCode ?? null;\n if (output) {\n this._resolvedOutput = output;\n // Note: `both` is reconstructed as stdout + stderr concatenation,\n // which loses the original interleaved order of the streams.\n this.outputCache = Promise.resolve({\n stdout: output.stdout,\n stderr: output.stderr,\n both: output.stdout + output.stderr,\n });\n }\n }\n\n /**\n * Serialize a Command instance to plain data for @workflow/serde.\n *\n * @param instance - The Command instance to serialize\n * @returns A plain object containing the sandbox ID, command data, and output if fetched\n */\n static [WORKFLOW_SERIALIZE](instance: Command): SerializedCommand {\n const serialized: SerializedCommand = {\n sandboxId: instance.sessionId,\n cmd: instance.cmd,\n };\n if (instance._resolvedOutput) {\n serialized.output = instance._resolvedOutput;\n }\n return serialized;\n }\n\n /**\n * Deserialize plain data back into a Command instance for @workflow/serde.\n *\n * The deserialized instance will lazily create an API client using\n * OIDC or environment credentials when needed.\n *\n * @param data - The serialized command data\n * @returns The reconstructed Command instance\n */\n static [WORKFLOW_DESERIALIZE](data: SerializedCommand): Command {\n return new Command({\n sessionId: data.sandboxId,\n cmd: data.cmd,\n output: data.output,\n });\n }\n\n /**\n * Iterate over the output of this command.\n *\n * ```\n * for await (const log of cmd.logs()) {\n * if (log.stream === \"stdout\") {\n * process.stdout.write(log.data);\n * } else {\n * process.stderr.write(log.data);\n * }\n * }\n * ```\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel log streaming.\n * @returns An async iterable of log entries from the command output.\n *\n * @see {@link Command.stdout}, {@link Command.stderr}, and {@link Command.output}\n * to access output as a string.\n */\n logs(opts?: { signal?: AbortSignal }) {\n if (!this._client) {\n throw new Error(\n \"logs() requires an API client. Call an async method first to initialize the client.\",\n );\n }\n return this._client.getLogs({\n sessionId: this.sessionId,\n cmdId: this.cmd.id,\n signal: opts?.signal,\n });\n }\n\n /**\n * Wait for a command to exit and populate its exit code.\n *\n * This method is useful for detached commands where you need to wait\n * for completion. For non-detached commands, {@link Sandbox.runCommand}\n * automatically waits and returns a {@link CommandFinished} instance.\n *\n * ```\n * const detachedCmd = await sandbox.runCommand({ cmd: 'sleep', args: ['5'], detached: true });\n * const result = await detachedCmd.wait();\n * if (result.exitCode !== 0) {\n * console.error(\"Something went wrong...\")\n * }\n * ```\n *\n * @param params - Optional parameters.\n * @param params.signal - An AbortSignal to cancel waiting.\n * @returns A {@link CommandFinished} instance with populated exit code.\n */\n async wait(params?: { signal?: AbortSignal }) {\n \"use step\";\n const client = await this.ensureClient();\n params?.signal?.throwIfAborted();\n\n const command = await client.getCommand({\n sessionId: this.sessionId,\n cmdId: this.cmd.id,\n wait: true,\n signal: params?.signal,\n });\n\n return new CommandFinished({\n client,\n sessionId: this.sessionId,\n cmd: command.json.command,\n exitCode: command.json.command.exitCode,\n });\n }\n\n /**\n * Get cached output, fetching logs only once and reusing for concurrent calls.\n * This prevents race conditions when stdout() and stderr() are called in parallel.\n */\n protected async getCachedOutput(opts?: { signal?: AbortSignal }): Promise<{\n stdout: string;\n stderr: string;\n both: string;\n }> {\n if (!this.outputCache) {\n this.outputCache = (async () => {\n try {\n opts?.signal?.throwIfAborted();\n // Ensure the API client is initialized before calling logs(),\n // since logs() is synchronous and requires _client to be set.\n await this.ensureClient();\n let stdout = \"\";\n let stderr = \"\";\n let both = \"\";\n for await (const log of this.logs({ signal: opts?.signal })) {\n both += log.data;\n if (log.stream === \"stdout\") {\n stdout += log.data;\n } else {\n stderr += log.data;\n }\n }\n // Store resolved output for serialization\n this._resolvedOutput = { stdout, stderr };\n return { stdout, stderr, both };\n } catch (err) {\n // Clear the promise so future calls can retry\n this.outputCache = null;\n throw err;\n }\n })();\n }\n\n return this.outputCache;\n }\n\n /**\n * Get the output of `stdout`, `stderr`, or both as a string.\n *\n * NOTE: This may throw string conversion errors if the command does\n * not output valid Unicode.\n *\n * @param stream - The output stream to read: \"stdout\", \"stderr\", or \"both\".\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel output streaming.\n * @returns The output of the specified stream(s) as a string.\n */\n async output(\n stream: \"stdout\" | \"stderr\" | \"both\" = \"both\",\n opts?: { signal?: AbortSignal },\n ) {\n \"use step\";\n const cached = await this.getCachedOutput(opts);\n return cached[stream];\n }\n\n /**\n * Get the output of `stdout` as a string.\n *\n * NOTE: This may throw string conversion errors if the command does\n * not output valid Unicode.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel output streaming.\n * @returns The standard output of the command.\n */\n async stdout(opts?: { signal?: AbortSignal }) {\n \"use step\";\n return this.output(\"stdout\", opts);\n }\n\n /**\n * Get the output of `stderr` as a string.\n *\n * NOTE: This may throw string conversion errors if the command does\n * not output valid Unicode.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel output streaming.\n * @returns The standard error output of the command.\n */\n async stderr(opts?: { signal?: AbortSignal }) {\n \"use step\";\n return this.output(\"stderr\", opts);\n }\n\n /**\n * Kill a running command in a sandbox.\n *\n * @param signal - The signal to send the running process. Defaults to SIGTERM.\n * @param opts - Optional parameters.\n * @param opts.abortSignal - An AbortSignal to cancel the kill operation.\n * @returns Promise<void>.\n */\n async kill(signal?: Signal, opts?: { abortSignal?: AbortSignal }) {\n \"use step\";\n const client = await this.ensureClient();\n await client.killCommand({\n sessionId: this.sessionId,\n commandId: this.cmd.id,\n signal: resolveSignal(signal ?? \"SIGTERM\"),\n abortSignal: opts?.abortSignal,\n });\n }\n}\n\n/**\n * A command that has finished executing.\n *\n * The exit code is immediately available and populated upon creation.\n * Unlike {@link Command}, you don't need to call wait() - the command\n * has already completed execution.\n *\n * @hideconstructor\n */\nexport class CommandFinished extends Command {\n /**\n * The exit code of the command. This is always populated for\n * CommandFinished instances.\n */\n public exitCode: number;\n\n /**\n * @param params - Object containing client, sandbox ID, command data, and exit code.\n * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.\n * @param params.sessionId - The ID of the session where the command ran.\n * @param params.cmd - The command data.\n * @param params.exitCode - The exit code of the completed command.\n * @param params.output - Optional cached output to restore (used during deserialization).\n */\n constructor(params: {\n client?: APIClient;\n sessionId: string;\n cmd: CommandData;\n exitCode: number;\n output?: CommandOutput;\n }) {\n super({ ...params });\n this.exitCode = params.exitCode;\n }\n\n /**\n * Serialize a CommandFinished instance to plain data for @workflow/serde.\n *\n * @param instance - The CommandFinished instance to serialize\n * @returns A plain object containing the sandbox ID, command data, exit code, and output if fetched\n */\n static [WORKFLOW_SERIALIZE](\n instance: CommandFinished,\n ): SerializedCommandFinished {\n return {\n ...Command[WORKFLOW_SERIALIZE](instance),\n exitCode: instance.exitCode,\n };\n }\n\n /**\n * Deserialize plain data back into a CommandFinished instance for @workflow/serde.\n *\n * The deserialized instance will lazily create an API client using\n * OIDC or environment credentials when needed.\n *\n * @param data - The serialized command finished data\n * @returns The reconstructed CommandFinished instance\n */\n static [WORKFLOW_DESERIALIZE](\n data: SerializedCommandFinished,\n ): CommandFinished {\n return new CommandFinished({\n sessionId: data.sandboxId,\n cmd: data.cmd,\n exitCode: data.exitCode,\n output: data.output,\n });\n }\n\n /**\n * The wait method is not needed for CommandFinished instances since\n * the command has already completed and exitCode is populated.\n *\n * @deprecated This method is redundant for CommandFinished instances.\n * The exitCode is already available.\n * @returns This CommandFinished instance.\n */\n async wait(): Promise<CommandFinished> {\n return this;\n }\n}\n"],"mappings":"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"}
@@ -0,0 +1,289 @@
1
+ import { CommandData } from "./api-client/validators.cjs";
2
+ import { APIClient } from "./api-client/api-client.cjs";
3
+ import { Signal } from "./utils/resolveSignal.cjs";
4
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
5
+
6
+ //#region src/command.d.ts
7
+ /**
8
+ * Cached output from a command execution.
9
+ */
10
+ interface CommandOutput {
11
+ stdout: string;
12
+ stderr: string;
13
+ }
14
+ /**
15
+ * Serialized representation of a Command for @workflow/serde.
16
+ */
17
+ interface SerializedCommand {
18
+ sandboxId: string;
19
+ cmd: CommandData;
20
+ /** Cached output, included if output was fetched before serialization */
21
+ output?: CommandOutput;
22
+ }
23
+ /**
24
+ * Serialized representation of a CommandFinished for @workflow/serde.
25
+ */
26
+ interface SerializedCommandFinished extends SerializedCommand {
27
+ exitCode: number;
28
+ }
29
+ /**
30
+ * A command executed in a Sandbox.
31
+ *
32
+ * For detached commands, you can {@link wait} to get a {@link CommandFinished} instance
33
+ * with the populated exit code. For non-detached commands, {@link Sandbox.runCommand}
34
+ * automatically waits and returns a {@link CommandFinished} instance.
35
+ *
36
+ * You can iterate over command output with {@link logs}.
37
+ *
38
+ * @see {@link Sandbox.runCommand} to start a command.
39
+ *
40
+ * @hideconstructor
41
+ */
42
+ declare class Command {
43
+ /**
44
+ * Cached API client instance.
45
+ * @internal
46
+ */
47
+ protected _client: APIClient | null;
48
+ /**
49
+ * Lazily resolve credentials and construct an API client.
50
+ * @internal
51
+ */
52
+ protected ensureClient(): Promise<APIClient>;
53
+ /**
54
+ * ID of the session this command is running in.
55
+ */
56
+ protected sessionId: string;
57
+ /**
58
+ * Data for the command execution.
59
+ */
60
+ protected cmd: CommandData;
61
+ exitCode: number | null;
62
+ protected outputCache: Promise<{
63
+ stdout: string;
64
+ stderr: string;
65
+ both: string;
66
+ }> | null;
67
+ /**
68
+ * Synchronously accessible resolved output, populated after output is fetched.
69
+ * Used for serialization.
70
+ * @internal
71
+ */
72
+ protected _resolvedOutput: CommandOutput | null;
73
+ /**
74
+ * ID of the command execution.
75
+ */
76
+ get cmdId(): string;
77
+ get cwd(): string;
78
+ get startedAt(): number;
79
+ /**
80
+ * @param params - Object containing the client, sandbox ID, and command data.
81
+ * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.
82
+ * @param params.sessionId - The ID of the session where the command is running.
83
+ * @param params.cmd - The command data.
84
+ * @param params.output - Optional cached output to restore (used during deserialization).
85
+ */
86
+ constructor({
87
+ client,
88
+ sessionId,
89
+ cmd,
90
+ output
91
+ }: {
92
+ client?: APIClient;
93
+ sessionId: string;
94
+ cmd: CommandData;
95
+ output?: CommandOutput;
96
+ });
97
+ /**
98
+ * Serialize a Command instance to plain data for @workflow/serde.
99
+ *
100
+ * @param instance - The Command instance to serialize
101
+ * @returns A plain object containing the sandbox ID, command data, and output if fetched
102
+ */
103
+ static [WORKFLOW_SERIALIZE](instance: Command): SerializedCommand;
104
+ /**
105
+ * Deserialize plain data back into a Command instance for @workflow/serde.
106
+ *
107
+ * The deserialized instance will lazily create an API client using
108
+ * OIDC or environment credentials when needed.
109
+ *
110
+ * @param data - The serialized command data
111
+ * @returns The reconstructed Command instance
112
+ */
113
+ static [WORKFLOW_DESERIALIZE](data: SerializedCommand): Command;
114
+ /**
115
+ * Iterate over the output of this command.
116
+ *
117
+ * ```
118
+ * for await (const log of cmd.logs()) {
119
+ * if (log.stream === "stdout") {
120
+ * process.stdout.write(log.data);
121
+ * } else {
122
+ * process.stderr.write(log.data);
123
+ * }
124
+ * }
125
+ * ```
126
+ *
127
+ * @param opts - Optional parameters.
128
+ * @param opts.signal - An AbortSignal to cancel log streaming.
129
+ * @returns An async iterable of log entries from the command output.
130
+ *
131
+ * @see {@link Command.stdout}, {@link Command.stderr}, and {@link Command.output}
132
+ * to access output as a string.
133
+ */
134
+ logs(opts?: {
135
+ signal?: AbortSignal;
136
+ }): AsyncGenerator<{
137
+ data: string;
138
+ stream: "stdout";
139
+ } | {
140
+ data: string;
141
+ stream: "stderr";
142
+ }, void, void> & Disposable & {
143
+ close(): void;
144
+ };
145
+ /**
146
+ * Wait for a command to exit and populate its exit code.
147
+ *
148
+ * This method is useful for detached commands where you need to wait
149
+ * for completion. For non-detached commands, {@link Sandbox.runCommand}
150
+ * automatically waits and returns a {@link CommandFinished} instance.
151
+ *
152
+ * ```
153
+ * const detachedCmd = await sandbox.runCommand({ cmd: 'sleep', args: ['5'], detached: true });
154
+ * const result = await detachedCmd.wait();
155
+ * if (result.exitCode !== 0) {
156
+ * console.error("Something went wrong...")
157
+ * }
158
+ * ```
159
+ *
160
+ * @param params - Optional parameters.
161
+ * @param params.signal - An AbortSignal to cancel waiting.
162
+ * @returns A {@link CommandFinished} instance with populated exit code.
163
+ */
164
+ wait(params?: {
165
+ signal?: AbortSignal;
166
+ }): Promise<CommandFinished>;
167
+ /**
168
+ * Get cached output, fetching logs only once and reusing for concurrent calls.
169
+ * This prevents race conditions when stdout() and stderr() are called in parallel.
170
+ */
171
+ protected getCachedOutput(opts?: {
172
+ signal?: AbortSignal;
173
+ }): Promise<{
174
+ stdout: string;
175
+ stderr: string;
176
+ both: string;
177
+ }>;
178
+ /**
179
+ * Get the output of `stdout`, `stderr`, or both as a string.
180
+ *
181
+ * NOTE: This may throw string conversion errors if the command does
182
+ * not output valid Unicode.
183
+ *
184
+ * @param stream - The output stream to read: "stdout", "stderr", or "both".
185
+ * @param opts - Optional parameters.
186
+ * @param opts.signal - An AbortSignal to cancel output streaming.
187
+ * @returns The output of the specified stream(s) as a string.
188
+ */
189
+ output(stream?: "stdout" | "stderr" | "both", opts?: {
190
+ signal?: AbortSignal;
191
+ }): Promise<string>;
192
+ /**
193
+ * Get the output of `stdout` as a string.
194
+ *
195
+ * NOTE: This may throw string conversion errors if the command does
196
+ * not output valid Unicode.
197
+ *
198
+ * @param opts - Optional parameters.
199
+ * @param opts.signal - An AbortSignal to cancel output streaming.
200
+ * @returns The standard output of the command.
201
+ */
202
+ stdout(opts?: {
203
+ signal?: AbortSignal;
204
+ }): Promise<string>;
205
+ /**
206
+ * Get the output of `stderr` as a string.
207
+ *
208
+ * NOTE: This may throw string conversion errors if the command does
209
+ * not output valid Unicode.
210
+ *
211
+ * @param opts - Optional parameters.
212
+ * @param opts.signal - An AbortSignal to cancel output streaming.
213
+ * @returns The standard error output of the command.
214
+ */
215
+ stderr(opts?: {
216
+ signal?: AbortSignal;
217
+ }): Promise<string>;
218
+ /**
219
+ * Kill a running command in a sandbox.
220
+ *
221
+ * @param signal - The signal to send the running process. Defaults to SIGTERM.
222
+ * @param opts - Optional parameters.
223
+ * @param opts.abortSignal - An AbortSignal to cancel the kill operation.
224
+ * @returns Promise<void>.
225
+ */
226
+ kill(signal?: Signal, opts?: {
227
+ abortSignal?: AbortSignal;
228
+ }): Promise<void>;
229
+ }
230
+ /**
231
+ * A command that has finished executing.
232
+ *
233
+ * The exit code is immediately available and populated upon creation.
234
+ * Unlike {@link Command}, you don't need to call wait() - the command
235
+ * has already completed execution.
236
+ *
237
+ * @hideconstructor
238
+ */
239
+ declare class CommandFinished extends Command {
240
+ /**
241
+ * The exit code of the command. This is always populated for
242
+ * CommandFinished instances.
243
+ */
244
+ exitCode: number;
245
+ /**
246
+ * @param params - Object containing client, sandbox ID, command data, and exit code.
247
+ * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.
248
+ * @param params.sessionId - The ID of the session where the command ran.
249
+ * @param params.cmd - The command data.
250
+ * @param params.exitCode - The exit code of the completed command.
251
+ * @param params.output - Optional cached output to restore (used during deserialization).
252
+ */
253
+ constructor(params: {
254
+ client?: APIClient;
255
+ sessionId: string;
256
+ cmd: CommandData;
257
+ exitCode: number;
258
+ output?: CommandOutput;
259
+ });
260
+ /**
261
+ * Serialize a CommandFinished instance to plain data for @workflow/serde.
262
+ *
263
+ * @param instance - The CommandFinished instance to serialize
264
+ * @returns A plain object containing the sandbox ID, command data, exit code, and output if fetched
265
+ */
266
+ static [WORKFLOW_SERIALIZE](instance: CommandFinished): SerializedCommandFinished;
267
+ /**
268
+ * Deserialize plain data back into a CommandFinished instance for @workflow/serde.
269
+ *
270
+ * The deserialized instance will lazily create an API client using
271
+ * OIDC or environment credentials when needed.
272
+ *
273
+ * @param data - The serialized command finished data
274
+ * @returns The reconstructed CommandFinished instance
275
+ */
276
+ static [WORKFLOW_DESERIALIZE](data: SerializedCommandFinished): CommandFinished;
277
+ /**
278
+ * The wait method is not needed for CommandFinished instances since
279
+ * the command has already completed and exitCode is populated.
280
+ *
281
+ * @deprecated This method is redundant for CommandFinished instances.
282
+ * The exitCode is already available.
283
+ * @returns This CommandFinished instance.
284
+ */
285
+ wait(): Promise<CommandFinished>;
286
+ }
287
+ //#endregion
288
+ export { Command, CommandFinished, CommandOutput, SerializedCommand, SerializedCommandFinished };
289
+ //# sourceMappingURL=command.d.cts.map