@vercel/sandbox 1.9.0 → 1.9.2

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 (190) 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 +375 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +403 -0
  6. package/dist/api-client/api-client.d.ts +397 -392
  7. package/dist/api-client/api-client.js +365 -405
  8. package/dist/api-client/api-client.js.map +1 -1
  9. package/dist/api-client/api-error.cjs +31 -0
  10. package/dist/api-client/api-error.cjs.map +1 -0
  11. package/dist/api-client/api-error.d.cts +27 -0
  12. package/dist/api-client/api-error.d.ts +19 -16
  13. package/dist/api-client/api-error.js +27 -32
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +113 -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 +101 -118
  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 +149 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +1677 -0
  33. package/dist/api-client/validators.d.ts +1501 -2412
  34. package/dist/api-client/validators.js +124 -154
  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 +11 -0
  95. package/dist/index.d.cts +6 -0
  96. package/dist/index.d.ts +6 -5
  97. package/dist/index.js +6 -15
  98. package/dist/network-policy.d.cts +100 -0
  99. package/dist/network-policy.d.ts +32 -28
  100. package/dist/sandbox.cjs +543 -0
  101. package/dist/sandbox.cjs.map +1 -0
  102. package/dist/sandbox.d.cts +538 -0
  103. package/dist/sandbox.d.ts +521 -479
  104. package/dist/sandbox.js +539 -512
  105. package/dist/sandbox.js.map +1 -1
  106. package/dist/snapshot.cjs +116 -0
  107. package/dist/snapshot.cjs.map +1 -0
  108. package/dist/snapshot.d.cts +109 -0
  109. package/dist/snapshot.d.ts +100 -92
  110. package/dist/snapshot.js +114 -114
  111. package/dist/snapshot.js.map +1 -1
  112. package/dist/utils/array.cjs +17 -0
  113. package/dist/utils/array.cjs.map +1 -0
  114. package/dist/utils/array.js +12 -15
  115. package/dist/utils/array.js.map +1 -1
  116. package/dist/utils/consume-readable.cjs +18 -0
  117. package/dist/utils/consume-readable.cjs.map +1 -0
  118. package/dist/utils/consume-readable.js +13 -12
  119. package/dist/utils/consume-readable.js.map +1 -1
  120. package/dist/utils/decode-base64-url.cjs +15 -0
  121. package/dist/utils/decode-base64-url.cjs.map +1 -0
  122. package/dist/utils/decode-base64-url.js +10 -9
  123. package/dist/utils/decode-base64-url.js.map +1 -1
  124. package/dist/utils/dev-credentials.cjs +142 -0
  125. package/dist/utils/dev-credentials.cjs.map +1 -0
  126. package/dist/utils/dev-credentials.js +126 -184
  127. package/dist/utils/dev-credentials.js.map +1 -1
  128. package/dist/utils/get-credentials.cjs +123 -0
  129. package/dist/utils/get-credentials.cjs.map +1 -0
  130. package/dist/utils/get-credentials.d.cts +21 -0
  131. package/dist/utils/get-credentials.d.ts +19 -61
  132. package/dist/utils/get-credentials.js +106 -140
  133. package/dist/utils/get-credentials.js.map +1 -1
  134. package/dist/utils/log.cjs +25 -0
  135. package/dist/utils/log.cjs.map +1 -0
  136. package/dist/utils/log.js +15 -17
  137. package/dist/utils/log.js.map +1 -1
  138. package/dist/utils/network-policy.cjs +65 -0
  139. package/dist/utils/network-policy.cjs.map +1 -0
  140. package/dist/utils/network-policy.js +58 -77
  141. package/dist/utils/network-policy.js.map +1 -1
  142. package/dist/utils/normalizePath.cjs +27 -0
  143. package/dist/utils/normalizePath.cjs.map +1 -0
  144. package/dist/utils/normalizePath.js +21 -28
  145. package/dist/utils/normalizePath.js.map +1 -1
  146. package/dist/utils/resolveSignal.cjs +20 -0
  147. package/dist/utils/resolveSignal.cjs.map +1 -0
  148. package/dist/utils/resolveSignal.d.cts +15 -0
  149. package/dist/utils/resolveSignal.d.ts +12 -10
  150. package/dist/utils/resolveSignal.js +14 -17
  151. package/dist/utils/resolveSignal.js.map +1 -1
  152. package/dist/utils/sandbox-snapshot.cjs +14 -0
  153. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  154. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  155. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  156. package/dist/utils/sandbox-snapshot.js +14 -0
  157. package/dist/utils/sandbox-snapshot.js.map +1 -0
  158. package/dist/utils/types.cjs +13 -0
  159. package/dist/utils/types.cjs.map +1 -0
  160. package/dist/utils/types.d.cts +11 -0
  161. package/dist/utils/types.d.ts +5 -7
  162. package/dist/utils/types.js +8 -8
  163. package/dist/utils/types.js.map +1 -1
  164. package/dist/version.cjs +7 -0
  165. package/dist/version.cjs.map +1 -0
  166. package/dist/version.js +5 -5
  167. package/dist/version.js.map +1 -1
  168. package/package.json +23 -3
  169. package/dist/api-client/index.js.map +0 -1
  170. package/dist/auth/api.d.ts +0 -6
  171. package/dist/auth/error.d.ts +0 -11
  172. package/dist/auth/index.js.map +0 -1
  173. package/dist/auth/linked-project.d.ts +0 -10
  174. package/dist/auth/zod.d.ts +0 -5
  175. package/dist/constants.js +0 -3
  176. package/dist/constants.js.map +0 -1
  177. package/dist/index.js.map +0 -1
  178. package/dist/network-policy.js +0 -3
  179. package/dist/network-policy.js.map +0 -1
  180. package/dist/utils/array.d.ts +0 -9
  181. package/dist/utils/consume-readable.d.ts +0 -5
  182. package/dist/utils/convert-sandbox.d.ts +0 -6
  183. package/dist/utils/convert-sandbox.js +0 -14
  184. package/dist/utils/convert-sandbox.js.map +0 -1
  185. package/dist/utils/decode-base64-url.d.ts +0 -7
  186. package/dist/utils/dev-credentials.d.ts +0 -37
  187. package/dist/utils/log.d.ts +0 -2
  188. package/dist/utils/network-policy.d.ts +0 -7
  189. package/dist/utils/normalizePath.d.ts +0 -17
  190. package/dist/version.d.ts +0 -1
package/dist/command.js CHANGED
@@ -1,229 +1,326 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandFinished = exports.Command = void 0;
4
- const resolveSignal_1 = require("./utils/resolveSignal");
1
+ import { APIClient } from "./api-client/api-client.js";
2
+ import "./api-client/index.js";
3
+ import { getCredentials } from "./utils/get-credentials.js";
4
+ import { resolveSignal } from "./utils/resolveSignal.js";
5
+ import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
6
+
7
+ //#region src/command.ts
5
8
  /**
6
- * A command executed in a Sandbox.
7
- *
8
- * For detached commands, you can {@link wait} to get a {@link CommandFinished} instance
9
- * with the populated exit code. For non-detached commands, {@link Sandbox.runCommand}
10
- * automatically waits and returns a {@link CommandFinished} instance.
11
- *
12
- * You can iterate over command output with {@link logs}.
13
- *
14
- * @see {@link Sandbox.runCommand} to start a command.
15
- *
16
- * @hideconstructor
17
- */
18
- class Command {
19
- /**
20
- * ID of the command execution.
21
- */
22
- get cmdId() {
23
- return this.cmd.id;
24
- }
25
- get cwd() {
26
- return this.cmd.cwd;
27
- }
28
- get startedAt() {
29
- return this.cmd.startedAt;
30
- }
31
- /**
32
- * @param params - Object containing the client, sandbox ID, and command ID.
33
- * @param params.client - API client used to interact with the backend.
34
- * @param params.sandboxId - The ID of the sandbox where the command is running.
35
- * @param params.cmdId - The ID of the command execution.
36
- */
37
- constructor({ client, sandboxId, cmd, }) {
38
- this.outputCache = null;
39
- this.client = client;
40
- this.sandboxId = sandboxId;
41
- this.cmd = cmd;
42
- this.exitCode = cmd.exitCode ?? null;
43
- }
44
- /**
45
- * Iterate over the output of this command.
46
- *
47
- * ```
48
- * for await (const log of cmd.logs()) {
49
- * if (log.stream === "stdout") {
50
- * process.stdout.write(log.data);
51
- * } else {
52
- * process.stderr.write(log.data);
53
- * }
54
- * }
55
- * ```
56
- *
57
- * @param opts - Optional parameters.
58
- * @param opts.signal - An AbortSignal to cancel log streaming.
59
- * @returns An async iterable of log entries from the command output.
60
- *
61
- * @see {@link Command.stdout}, {@link Command.stderr}, and {@link Command.output}
62
- * to access output as a string.
63
- */
64
- logs(opts) {
65
- return this.client.getLogs({
66
- sandboxId: this.sandboxId,
67
- cmdId: this.cmd.id,
68
- signal: opts?.signal,
69
- });
70
- }
71
- /**
72
- * Wait for a command to exit and populate its exit code.
73
- *
74
- * This method is useful for detached commands where you need to wait
75
- * for completion. For non-detached commands, {@link Sandbox.runCommand}
76
- * automatically waits and returns a {@link CommandFinished} instance.
77
- *
78
- * ```
79
- * const detachedCmd = await sandbox.runCommand({ cmd: 'sleep', args: ['5'], detached: true });
80
- * const result = await detachedCmd.wait();
81
- * if (result.exitCode !== 0) {
82
- * console.error("Something went wrong...")
83
- * }
84
- * ```
85
- *
86
- * @param params - Optional parameters.
87
- * @param params.signal - An AbortSignal to cancel waiting.
88
- * @returns A {@link CommandFinished} instance with populated exit code.
89
- */
90
- async wait(params) {
91
- params?.signal?.throwIfAborted();
92
- const command = await this.client.getCommand({
93
- sandboxId: this.sandboxId,
94
- cmdId: this.cmd.id,
95
- wait: true,
96
- signal: params?.signal,
97
- });
98
- return new CommandFinished({
99
- client: this.client,
100
- sandboxId: this.sandboxId,
101
- cmd: command.json.command,
102
- exitCode: command.json.command.exitCode,
103
- });
104
- }
105
- /**
106
- * Get cached output, fetching logs only once and reusing for concurrent calls.
107
- * This prevents race conditions when stdout() and stderr() are called in parallel.
108
- */
109
- async getCachedOutput(opts) {
110
- if (!this.outputCache) {
111
- this.outputCache = (async () => {
112
- try {
113
- let stdout = "";
114
- let stderr = "";
115
- let both = "";
116
- for await (const log of this.logs({ signal: opts?.signal })) {
117
- both += log.data;
118
- if (log.stream === "stdout") {
119
- stdout += log.data;
120
- }
121
- else {
122
- stderr += log.data;
123
- }
124
- }
125
- return { stdout, stderr, both };
126
- }
127
- catch (err) {
128
- // Clear the promise so future calls can retry
129
- this.outputCache = null;
130
- throw err;
131
- }
132
- })();
133
- }
134
- return this.outputCache;
135
- }
136
- /**
137
- * Get the output of `stdout`, `stderr`, or both as a string.
138
- *
139
- * NOTE: This may throw string conversion errors if the command does
140
- * not output valid Unicode.
141
- *
142
- * @param stream - The output stream to read: "stdout", "stderr", or "both".
143
- * @param opts - Optional parameters.
144
- * @param opts.signal - An AbortSignal to cancel output streaming.
145
- * @returns The output of the specified stream(s) as a string.
146
- */
147
- async output(stream = "both", opts) {
148
- const cached = await this.getCachedOutput(opts);
149
- return cached[stream];
150
- }
151
- /**
152
- * Get the output of `stdout` as a string.
153
- *
154
- * NOTE: This may throw string conversion errors if the command does
155
- * not output valid Unicode.
156
- *
157
- * @param opts - Optional parameters.
158
- * @param opts.signal - An AbortSignal to cancel output streaming.
159
- * @returns The standard output of the command.
160
- */
161
- async stdout(opts) {
162
- return this.output("stdout", opts);
163
- }
164
- /**
165
- * Get the output of `stderr` as a string.
166
- *
167
- * NOTE: This may throw string conversion errors if the command does
168
- * not output valid Unicode.
169
- *
170
- * @param opts - Optional parameters.
171
- * @param opts.signal - An AbortSignal to cancel output streaming.
172
- * @returns The standard error output of the command.
173
- */
174
- async stderr(opts) {
175
- return this.output("stderr", opts);
176
- }
177
- /**
178
- * Kill a running command in a sandbox.
179
- *
180
- * @param signal - The signal to send the running process. Defaults to SIGTERM.
181
- * @param opts - Optional parameters.
182
- * @param opts.abortSignal - An AbortSignal to cancel the kill operation.
183
- * @returns Promise<void>.
184
- */
185
- async kill(signal, opts) {
186
- await this.client.killCommand({
187
- sandboxId: this.sandboxId,
188
- commandId: this.cmd.id,
189
- signal: (0, resolveSignal_1.resolveSignal)(signal ?? "SIGTERM"),
190
- abortSignal: opts?.abortSignal,
191
- });
192
- }
193
- }
194
- exports.Command = Command;
9
+ * A command executed in a Sandbox.
10
+ *
11
+ * For detached commands, you can {@link wait} to get a {@link CommandFinished} instance
12
+ * with the populated exit code. For non-detached commands, {@link Sandbox.runCommand}
13
+ * automatically waits and returns a {@link CommandFinished} instance.
14
+ *
15
+ * You can iterate over command output with {@link logs}.
16
+ *
17
+ * @see {@link Sandbox.runCommand} to start a command.
18
+ *
19
+ * @hideconstructor
20
+ */
21
+ var Command = class Command {
22
+ /**
23
+ * Lazily resolve credentials and construct an API client.
24
+ * @internal
25
+ */
26
+ async ensureClient() {
27
+ "use step";
28
+ if (this._client) return this._client;
29
+ const credentials = await getCredentials();
30
+ this._client = new APIClient({
31
+ teamId: credentials.teamId,
32
+ token: credentials.token
33
+ });
34
+ return this._client;
35
+ }
36
+ /**
37
+ * ID of the command execution.
38
+ */
39
+ get cmdId() {
40
+ return this.cmd.id;
41
+ }
42
+ get cwd() {
43
+ return this.cmd.cwd;
44
+ }
45
+ get startedAt() {
46
+ return this.cmd.startedAt;
47
+ }
48
+ /**
49
+ * @param params - Object containing the client, sandbox ID, and command data.
50
+ * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.
51
+ * @param params.sandboxId - The ID of the sandbox where the command is running.
52
+ * @param params.cmd - The command data.
53
+ * @param params.output - Optional cached output to restore (used during deserialization).
54
+ */
55
+ constructor({ client, sandboxId, cmd, output }) {
56
+ this._client = null;
57
+ this.outputCache = null;
58
+ this._resolvedOutput = null;
59
+ this._client = client ?? null;
60
+ this.sandboxId = sandboxId;
61
+ this.cmd = cmd;
62
+ this.exitCode = cmd.exitCode ?? null;
63
+ if (output) {
64
+ this._resolvedOutput = output;
65
+ this.outputCache = Promise.resolve({
66
+ stdout: output.stdout,
67
+ stderr: output.stderr,
68
+ both: output.stdout + output.stderr
69
+ });
70
+ }
71
+ }
72
+ /**
73
+ * Serialize a Command instance to plain data for @workflow/serde.
74
+ *
75
+ * @param instance - The Command instance to serialize
76
+ * @returns A plain object containing the sandbox ID, command data, and output if fetched
77
+ */
78
+ static [WORKFLOW_SERIALIZE](instance) {
79
+ const serialized = {
80
+ sandboxId: instance.sandboxId,
81
+ cmd: instance.cmd
82
+ };
83
+ if (instance._resolvedOutput) serialized.output = instance._resolvedOutput;
84
+ return serialized;
85
+ }
86
+ /**
87
+ * Deserialize plain data back into a Command instance for @workflow/serde.
88
+ *
89
+ * The deserialized instance will lazily create an API client using
90
+ * OIDC or environment credentials when needed.
91
+ *
92
+ * @param data - The serialized command data
93
+ * @returns The reconstructed Command instance
94
+ */
95
+ static [WORKFLOW_DESERIALIZE](data) {
96
+ return new Command({
97
+ sandboxId: data.sandboxId,
98
+ cmd: data.cmd,
99
+ output: data.output
100
+ });
101
+ }
102
+ /**
103
+ * Iterate over the output of this command.
104
+ *
105
+ * ```
106
+ * for await (const log of cmd.logs()) {
107
+ * if (log.stream === "stdout") {
108
+ * process.stdout.write(log.data);
109
+ * } else {
110
+ * process.stderr.write(log.data);
111
+ * }
112
+ * }
113
+ * ```
114
+ *
115
+ * @param opts - Optional parameters.
116
+ * @param opts.signal - An AbortSignal to cancel log streaming.
117
+ * @returns An async iterable of log entries from the command output.
118
+ *
119
+ * @see {@link Command.stdout}, {@link Command.stderr}, and {@link Command.output}
120
+ * to access output as a string.
121
+ */
122
+ logs(opts) {
123
+ if (!this._client) throw new Error("logs() requires an API client. Call an async method first to initialize the client.");
124
+ return this._client.getLogs({
125
+ sandboxId: this.sandboxId,
126
+ cmdId: this.cmd.id,
127
+ signal: opts?.signal
128
+ });
129
+ }
130
+ /**
131
+ * Wait for a command to exit and populate its exit code.
132
+ *
133
+ * This method is useful for detached commands where you need to wait
134
+ * for completion. For non-detached commands, {@link Sandbox.runCommand}
135
+ * automatically waits and returns a {@link CommandFinished} instance.
136
+ *
137
+ * ```
138
+ * const detachedCmd = await sandbox.runCommand({ cmd: 'sleep', args: ['5'], detached: true });
139
+ * const result = await detachedCmd.wait();
140
+ * if (result.exitCode !== 0) {
141
+ * console.error("Something went wrong...")
142
+ * }
143
+ * ```
144
+ *
145
+ * @param params - Optional parameters.
146
+ * @param params.signal - An AbortSignal to cancel waiting.
147
+ * @returns A {@link CommandFinished} instance with populated exit code.
148
+ */
149
+ async wait(params) {
150
+ "use step";
151
+ const client = await this.ensureClient();
152
+ params?.signal?.throwIfAborted();
153
+ const command = await client.getCommand({
154
+ sandboxId: this.sandboxId,
155
+ cmdId: this.cmd.id,
156
+ wait: true,
157
+ signal: params?.signal
158
+ });
159
+ return new CommandFinished({
160
+ client,
161
+ sandboxId: this.sandboxId,
162
+ cmd: command.json.command,
163
+ exitCode: command.json.command.exitCode
164
+ });
165
+ }
166
+ /**
167
+ * Get cached output, fetching logs only once and reusing for concurrent calls.
168
+ * This prevents race conditions when stdout() and stderr() are called in parallel.
169
+ */
170
+ async getCachedOutput(opts) {
171
+ if (!this.outputCache) this.outputCache = (async () => {
172
+ try {
173
+ opts?.signal?.throwIfAborted();
174
+ await this.ensureClient();
175
+ let stdout = "";
176
+ let stderr = "";
177
+ let both = "";
178
+ for await (const log of this.logs({ signal: opts?.signal })) {
179
+ both += log.data;
180
+ if (log.stream === "stdout") stdout += log.data;
181
+ else stderr += log.data;
182
+ }
183
+ this._resolvedOutput = {
184
+ stdout,
185
+ stderr
186
+ };
187
+ return {
188
+ stdout,
189
+ stderr,
190
+ both
191
+ };
192
+ } catch (err) {
193
+ this.outputCache = null;
194
+ throw err;
195
+ }
196
+ })();
197
+ return this.outputCache;
198
+ }
199
+ /**
200
+ * Get the output of `stdout`, `stderr`, or both as a string.
201
+ *
202
+ * NOTE: This may throw string conversion errors if the command does
203
+ * not output valid Unicode.
204
+ *
205
+ * @param stream - The output stream to read: "stdout", "stderr", or "both".
206
+ * @param opts - Optional parameters.
207
+ * @param opts.signal - An AbortSignal to cancel output streaming.
208
+ * @returns The output of the specified stream(s) as a string.
209
+ */
210
+ async output(stream = "both", opts) {
211
+ "use step";
212
+ return (await this.getCachedOutput(opts))[stream];
213
+ }
214
+ /**
215
+ * Get the output of `stdout` as a string.
216
+ *
217
+ * NOTE: This may throw string conversion errors if the command does
218
+ * not output valid Unicode.
219
+ *
220
+ * @param opts - Optional parameters.
221
+ * @param opts.signal - An AbortSignal to cancel output streaming.
222
+ * @returns The standard output of the command.
223
+ */
224
+ async stdout(opts) {
225
+ "use step";
226
+ return this.output("stdout", opts);
227
+ }
228
+ /**
229
+ * Get the output of `stderr` as a string.
230
+ *
231
+ * NOTE: This may throw string conversion errors if the command does
232
+ * not output valid Unicode.
233
+ *
234
+ * @param opts - Optional parameters.
235
+ * @param opts.signal - An AbortSignal to cancel output streaming.
236
+ * @returns The standard error output of the command.
237
+ */
238
+ async stderr(opts) {
239
+ "use step";
240
+ return this.output("stderr", opts);
241
+ }
242
+ /**
243
+ * Kill a running command in a sandbox.
244
+ *
245
+ * @param signal - The signal to send the running process. Defaults to SIGTERM.
246
+ * @param opts - Optional parameters.
247
+ * @param opts.abortSignal - An AbortSignal to cancel the kill operation.
248
+ * @returns Promise<void>.
249
+ */
250
+ async kill(signal, opts) {
251
+ "use step";
252
+ await (await this.ensureClient()).killCommand({
253
+ sandboxId: this.sandboxId,
254
+ commandId: this.cmd.id,
255
+ signal: resolveSignal(signal ?? "SIGTERM"),
256
+ abortSignal: opts?.abortSignal
257
+ });
258
+ }
259
+ };
195
260
  /**
196
- * A command that has finished executing.
197
- *
198
- * The exit code is immediately available and populated upon creation.
199
- * Unlike {@link Command}, you don't need to call wait() - the command
200
- * has already completed execution.
201
- *
202
- * @hideconstructor
203
- */
204
- class CommandFinished extends Command {
205
- /**
206
- * @param params - Object containing client, sandbox ID, command ID, and exit code.
207
- * @param params.client - API client used to interact with the backend.
208
- * @param params.sandboxId - The ID of the sandbox where the command ran.
209
- * @param params.cmdId - The ID of the command execution.
210
- * @param params.exitCode - The exit code of the completed command.
211
- */
212
- constructor(params) {
213
- super({ ...params });
214
- this.exitCode = params.exitCode;
215
- }
216
- /**
217
- * The wait method is not needed for CommandFinished instances since
218
- * the command has already completed and exitCode is populated.
219
- *
220
- * @deprecated This method is redundant for CommandFinished instances.
221
- * The exitCode is already available.
222
- * @returns This CommandFinished instance.
223
- */
224
- async wait() {
225
- return this;
226
- }
227
- }
228
- exports.CommandFinished = CommandFinished;
261
+ * A command that has finished executing.
262
+ *
263
+ * The exit code is immediately available and populated upon creation.
264
+ * Unlike {@link Command}, you don't need to call wait() - the command
265
+ * has already completed execution.
266
+ *
267
+ * @hideconstructor
268
+ */
269
+ var CommandFinished = class CommandFinished extends Command {
270
+ /**
271
+ * @param params - Object containing client, sandbox ID, command data, and exit code.
272
+ * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.
273
+ * @param params.sandboxId - The ID of the sandbox where the command ran.
274
+ * @param params.cmd - The command data.
275
+ * @param params.exitCode - The exit code of the completed command.
276
+ * @param params.output - Optional cached output to restore (used during deserialization).
277
+ */
278
+ constructor(params) {
279
+ super({ ...params });
280
+ this.exitCode = params.exitCode;
281
+ }
282
+ /**
283
+ * Serialize a CommandFinished instance to plain data for @workflow/serde.
284
+ *
285
+ * @param instance - The CommandFinished instance to serialize
286
+ * @returns A plain object containing the sandbox ID, command data, exit code, and output if fetched
287
+ */
288
+ static [WORKFLOW_SERIALIZE](instance) {
289
+ return {
290
+ ...Command[WORKFLOW_SERIALIZE](instance),
291
+ exitCode: instance.exitCode
292
+ };
293
+ }
294
+ /**
295
+ * Deserialize plain data back into a CommandFinished instance for @workflow/serde.
296
+ *
297
+ * The deserialized instance will lazily create an API client using
298
+ * OIDC or environment credentials when needed.
299
+ *
300
+ * @param data - The serialized command finished data
301
+ * @returns The reconstructed CommandFinished instance
302
+ */
303
+ static [WORKFLOW_DESERIALIZE](data) {
304
+ return new CommandFinished({
305
+ sandboxId: data.sandboxId,
306
+ cmd: data.cmd,
307
+ exitCode: data.exitCode,
308
+ output: data.output
309
+ });
310
+ }
311
+ /**
312
+ * The wait method is not needed for CommandFinished instances since
313
+ * the command has already completed and exitCode is populated.
314
+ *
315
+ * @deprecated This method is redundant for CommandFinished instances.
316
+ * The exitCode is already available.
317
+ * @returns This CommandFinished instance.
318
+ */
319
+ async wait() {
320
+ return this;
321
+ }
322
+ };
323
+
324
+ //#endregion
325
+ export { Command, CommandFinished };
229
326
  //# sourceMappingURL=command.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";;;AACA,yDAA8D;AAE9D;;;;;;;;;;;;GAYG;AACH,MAAa,OAAO;IAyBlB;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACrB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,YAAY,EACV,MAAM,EACN,SAAS,EACT,GAAG,GAKJ;QAnCO,gBAAW,GAIP,IAAI,CAAC;QAgCf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B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AAC,MAAM,CAAC,WAAW,CAAC;YAC5B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE;YACtB,MAAM,EAAE,IAAA,6BAAa,EAAC,MAAM,IAAI,SAAS,CAAC;YAC1C,WAAW,EAAE,IAAI,EAAE,WAAW;SAC/B,CAAC,CAAC;IACL,CAAC;CACF;AAhOD,0BAgOC;AAED;;;;;;;;GAQG;AACH,MAAa,eAAgB,SAAQ,OAAO;IAO1C;;;;;;OAMG;IACH,YAAY,MAKX;QACC,KAAK,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAnCD,0CAmCC"}
1
+ {"version":3,"file":"command.js","names":["serialized: SerializedCommand"],"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 sandbox this command is running in.\n */\n protected sandboxId: 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.sandboxId - The ID of the sandbox 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 sandboxId,\n cmd,\n output,\n }: {\n client?: APIClient;\n sandboxId: string;\n cmd: CommandData;\n output?: CommandOutput;\n }) {\n this._client = client ?? null;\n this.sandboxId = sandboxId;\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.sandboxId,\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 sandboxId: 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 sandboxId: this.sandboxId,\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 sandboxId: this.sandboxId,\n cmdId: this.cmd.id,\n wait: true,\n signal: params?.signal,\n });\n\n return new CommandFinished({\n client,\n sandboxId: this.sandboxId,\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 sandboxId: this.sandboxId,\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.sandboxId - The ID of the sandbox 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 sandboxId: 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 sandboxId: 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":";;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,UAAb,MAAa,QAAQ;;;;;CAWnB,MAAgB,eAAmC;AACjD;AACA,MAAI,KAAK,QAAS,QAAO,KAAK;EAC9B,MAAM,cAAc,MAAM,gBAAgB;AAC1C,OAAK,UAAU,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AACF,SAAO,KAAK;;;;;CA+Bd,IAAI,QAAQ;AACV,SAAO,KAAK,IAAI;;CAGlB,IAAI,MAAM;AACR,SAAO,KAAK,IAAI;;CAGlB,IAAI,YAAY;AACd,SAAO,KAAK,IAAI;;;;;;;;;CAUlB,YAAY,EACV,QACA,WACA,KACA,UAMC;OA1EO,UAA4B;OA6B5B,cAIE;OAOF,kBAAwC;AAmChD,OAAK,UAAU,UAAU;AACzB,OAAK,YAAY;AACjB,OAAK,MAAM;AACX,OAAK,WAAW,IAAI,YAAY;AAChC,MAAI,QAAQ;AACV,QAAK,kBAAkB;AAGvB,QAAK,cAAc,QAAQ,QAAQ;IACjC,QAAQ,OAAO;IACf,QAAQ,OAAO;IACf,MAAM,OAAO,SAAS,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lB,SAAK,kBAAkB;KAAE;KAAQ;KAAQ;AACzC,WAAO;KAAE;KAAQ;KAAQ;KAAM;YACxB,KAAK;AAEZ,SAAK,cAAc;AACnB,UAAM;;MAEN;AAGN,SAAO,KAAK;;;;;;;;;;;;;CAcd,MAAM,OACJ,SAAuC,QACvC,MACA;AACA;AAEA,UADe,MAAM,KAAK,gBAAgB,KAAK,EACjC;;;;;;;;;;;;CAahB,MAAM,OAAO,MAAiC;AAC5C;AACA,SAAO,KAAK,OAAO,UAAU,KAAK;;;;;;;;;;;;CAapC,MAAM,OAAO,MAAiC;AAC5C;AACA,SAAO,KAAK,OAAO,UAAU,KAAK;;;;;;;;;;CAWpC,MAAM,KAAK,QAAiB,MAAsC;AAChE;AAEA,SADe,MAAM,KAAK,cAAc,EAC3B,YAAY;GACvB,WAAW,KAAK;GAChB,WAAW,KAAK,IAAI;GACpB,QAAQ,cAAc,UAAU,UAAU;GAC1C,aAAa,MAAM;GACpB,CAAC;;;;;;;;;;;;AAaN,IAAa,kBAAb,MAAa,wBAAwB,QAAQ;;;;;;;;;CAe3C,YAAY,QAMT;AACD,QAAM,EAAE,GAAG,QAAQ,CAAC;AACpB,OAAK,WAAW,OAAO;;;;;;;;CASzB,QAAQ,oBACN,UAC2B;AAC3B,SAAO;GACL,GAAG,QAAQ,oBAAoB,SAAS;GACxC,UAAU,SAAS;GACpB;;;;;;;;;;;CAYH,QAAQ,sBACN,MACiB;AACjB,SAAO,IAAI,gBAAgB;GACzB,WAAW,KAAK;GAChB,KAAK,KAAK;GACV,UAAU,KAAK;GACf,QAAQ,KAAK;GACd,CAAC;;;;;;;;;;CAWJ,MAAM,OAAiC;AACrC,SAAO"}
@@ -0,0 +1,5 @@
1
+ //#region src/constants.d.ts
2
+ type RUNTIMES = "node24" | "node22" | "python3.13";
3
+ //#endregion
4
+ export { RUNTIMES };
5
+ //# sourceMappingURL=constants.d.cts.map
@@ -1 +1,5 @@
1
- export type RUNTIMES = "node24" | "node22" | "python3.13";
1
+ //#region src/constants.d.ts
2
+ type RUNTIMES = "node24" | "node22" | "python3.13";
3
+ //#endregion
4
+ export { RUNTIMES };
5
+ //# sourceMappingURL=constants.d.ts.map
package/dist/index.cjs ADDED
@@ -0,0 +1,11 @@
1
+ const require_api_error = require('./api-client/api-error.cjs');
2
+ const require_command = require('./command.cjs');
3
+ const require_snapshot = require('./snapshot.cjs');
4
+ const require_sandbox = require('./sandbox.cjs');
5
+
6
+ exports.APIError = require_api_error.APIError;
7
+ exports.Command = require_command.Command;
8
+ exports.CommandFinished = require_command.CommandFinished;
9
+ exports.Sandbox = require_sandbox.Sandbox;
10
+ exports.Snapshot = require_snapshot.Snapshot;
11
+ exports.StreamError = require_api_error.StreamError;
@@ -0,0 +1,6 @@
1
+ import { APIError, StreamError } from "./api-client/api-error.cjs";
2
+ import { NetworkPolicy, NetworkPolicyRule, NetworkTransformer } from "./network-policy.cjs";
3
+ import { Command, CommandFinished, CommandOutput, SerializedCommand, SerializedCommandFinished } from "./command.cjs";
4
+ import { Snapshot } from "./snapshot.cjs";
5
+ import { Sandbox, SerializedSandbox } from "./sandbox.cjs";
6
+ export { APIError, Command, CommandFinished, type CommandOutput, type NetworkPolicy, type NetworkPolicyRule, type NetworkTransformer, Sandbox, type SerializedCommand, type SerializedCommandFinished, type SerializedSandbox, Snapshot, StreamError };