@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.
- package/README.md +8 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/api-client/api-client.cjs +456 -0
- package/dist/api-client/api-client.cjs.map +1 -0
- package/dist/api-client/api-client.d.cts +790 -0
- package/dist/api-client/api-client.d.ts +784 -777
- package/dist/api-client/api-client.js +445 -471
- package/dist/api-client/api-client.js.map +1 -1
- package/dist/api-client/api-error.cjs +32 -0
- package/dist/api-client/api-error.cjs.map +1 -0
- package/dist/api-client/api-error.d.cts +29 -0
- package/dist/api-client/api-error.d.ts +21 -18
- package/dist/api-client/api-error.js +28 -33
- package/dist/api-client/api-error.js.map +1 -1
- package/dist/api-client/base-client.cjs +125 -0
- package/dist/api-client/base-client.cjs.map +1 -0
- package/dist/api-client/base-client.d.cts +38 -0
- package/dist/api-client/base-client.d.ts +31 -36
- package/dist/api-client/base-client.js +110 -130
- package/dist/api-client/base-client.js.map +1 -1
- package/dist/api-client/file-writer.cjs +62 -0
- package/dist/api-client/file-writer.cjs.map +1 -0
- package/dist/api-client/file-writer.d.cts +66 -0
- package/dist/api-client/file-writer.d.ts +56 -52
- package/dist/api-client/file-writer.js +57 -61
- package/dist/api-client/file-writer.js.map +1 -1
- package/dist/api-client/index.cjs +2 -0
- package/dist/api-client/index.d.ts +2 -2
- package/dist/api-client/index.js +4 -21
- package/dist/api-client/validators.cjs +182 -0
- package/dist/api-client/validators.cjs.map +1 -0
- package/dist/api-client/validators.d.cts +1469 -0
- package/dist/api-client/validators.d.ts +1282 -3699
- package/dist/api-client/validators.js +155 -170
- package/dist/api-client/validators.js.map +1 -1
- package/dist/api-client/with-retry.cjs +89 -0
- package/dist/api-client/with-retry.cjs.map +1 -0
- package/dist/api-client/with-retry.d.cts +10 -0
- package/dist/api-client/with-retry.d.ts +9 -13
- package/dist/api-client/with-retry.js +81 -102
- package/dist/api-client/with-retry.js.map +1 -1
- package/dist/auth/api.cjs +29 -0
- package/dist/auth/api.cjs.map +1 -0
- package/dist/auth/api.js +26 -25
- package/dist/auth/api.js.map +1 -1
- package/dist/auth/error.cjs +13 -0
- package/dist/auth/error.cjs.map +1 -0
- package/dist/auth/error.js +11 -11
- package/dist/auth/error.js.map +1 -1
- package/dist/auth/file.cjs +64 -0
- package/dist/auth/file.cjs.map +1 -0
- package/dist/auth/file.d.cts +26 -0
- package/dist/auth/file.d.ts +19 -15
- package/dist/auth/file.js +49 -64
- package/dist/auth/file.js.map +1 -1
- package/dist/auth/index.cjs +12 -0
- package/dist/auth/index.d.cts +5 -0
- package/dist/auth/index.d.ts +5 -6
- package/dist/auth/index.js +6 -27
- package/dist/auth/linked-project.cjs +38 -0
- package/dist/auth/linked-project.cjs.map +1 -0
- package/dist/auth/linked-project.js +30 -64
- package/dist/auth/linked-project.js.map +1 -1
- package/dist/auth/oauth.cjs +205 -0
- package/dist/auth/oauth.cjs.map +1 -0
- package/dist/auth/oauth.d.cts +135 -0
- package/dist/auth/oauth.d.ts +113 -109
- package/dist/auth/oauth.js +185 -252
- package/dist/auth/oauth.js.map +1 -1
- package/dist/auth/poll-for-token.cjs +82 -0
- package/dist/auth/poll-for-token.cjs.map +1 -0
- package/dist/auth/poll-for-token.d.cts +28 -0
- package/dist/auth/poll-for-token.d.ts +23 -15
- package/dist/auth/poll-for-token.js +79 -64
- package/dist/auth/poll-for-token.js.map +1 -1
- package/dist/auth/project.cjs +80 -0
- package/dist/auth/project.cjs.map +1 -0
- package/dist/auth/project.d.cts +44 -0
- package/dist/auth/project.d.ts +12 -8
- package/dist/auth/project.js +70 -72
- package/dist/auth/project.js.map +1 -1
- package/dist/auth/zod.cjs +22 -0
- package/dist/auth/zod.cjs.map +1 -0
- package/dist/auth/zod.js +18 -17
- package/dist/auth/zod.js.map +1 -1
- package/dist/command.cjs +328 -0
- package/dist/command.cjs.map +1 -0
- package/dist/command.d.cts +289 -0
- package/dist/command.d.ts +265 -171
- package/dist/command.js +323 -226
- package/dist/command.js.map +1 -1
- package/dist/constants.d.cts +5 -0
- package/dist/constants.d.ts +5 -1
- package/dist/index.cjs +13 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +7 -17
- package/dist/network-policy.d.cts +100 -0
- package/dist/network-policy.d.ts +32 -28
- package/dist/sandbox.cjs +694 -0
- package/dist/sandbox.cjs.map +1 -0
- package/dist/sandbox.d.cts +796 -0
- package/dist/sandbox.d.ts +783 -711
- package/dist/sandbox.js +684 -615
- package/dist/sandbox.js.map +1 -1
- package/dist/session.cjs +520 -0
- package/dist/session.cjs.map +1 -0
- package/dist/session.d.cts +406 -0
- package/dist/session.d.ts +398 -367
- package/dist/session.js +517 -505
- package/dist/session.js.map +1 -1
- package/dist/snapshot.cjs +116 -0
- package/dist/snapshot.cjs.map +1 -0
- package/dist/snapshot.d.cts +107 -0
- package/dist/snapshot.d.ts +98 -91
- package/dist/snapshot.js +114 -115
- package/dist/snapshot.js.map +1 -1
- package/dist/utils/array.cjs +17 -0
- package/dist/utils/array.cjs.map +1 -0
- package/dist/utils/array.js +12 -15
- package/dist/utils/array.js.map +1 -1
- package/dist/utils/consume-readable.cjs +18 -0
- package/dist/utils/consume-readable.cjs.map +1 -0
- package/dist/utils/consume-readable.js +13 -12
- package/dist/utils/consume-readable.js.map +1 -1
- package/dist/utils/decode-base64-url.cjs +15 -0
- package/dist/utils/decode-base64-url.cjs.map +1 -0
- package/dist/utils/decode-base64-url.js +10 -9
- package/dist/utils/decode-base64-url.js.map +1 -1
- package/dist/utils/dev-credentials.cjs +142 -0
- package/dist/utils/dev-credentials.cjs.map +1 -0
- package/dist/utils/dev-credentials.js +126 -184
- package/dist/utils/dev-credentials.js.map +1 -1
- package/dist/utils/get-credentials.cjs +123 -0
- package/dist/utils/get-credentials.cjs.map +1 -0
- package/dist/utils/get-credentials.d.cts +21 -0
- package/dist/utils/get-credentials.d.ts +19 -61
- package/dist/utils/get-credentials.js +106 -140
- package/dist/utils/get-credentials.js.map +1 -1
- package/dist/utils/log.cjs +25 -0
- package/dist/utils/log.cjs.map +1 -0
- package/dist/utils/log.js +15 -17
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/network-policy.cjs +65 -0
- package/dist/utils/network-policy.cjs.map +1 -0
- package/dist/utils/network-policy.js +58 -77
- package/dist/utils/network-policy.js.map +1 -1
- package/dist/utils/normalizePath.cjs +27 -0
- package/dist/utils/normalizePath.cjs.map +1 -0
- package/dist/utils/normalizePath.js +21 -28
- package/dist/utils/normalizePath.js.map +1 -1
- package/dist/utils/resolveSignal.cjs +20 -0
- package/dist/utils/resolveSignal.cjs.map +1 -0
- package/dist/utils/resolveSignal.d.cts +15 -0
- package/dist/utils/resolveSignal.d.ts +12 -10
- package/dist/utils/resolveSignal.js +14 -17
- package/dist/utils/resolveSignal.js.map +1 -1
- package/dist/utils/sandbox-snapshot.cjs +14 -0
- package/dist/utils/sandbox-snapshot.cjs.map +1 -0
- package/dist/utils/sandbox-snapshot.d.cts +10 -0
- package/dist/utils/sandbox-snapshot.d.ts +11 -0
- package/dist/utils/sandbox-snapshot.js +14 -0
- package/dist/utils/sandbox-snapshot.js.map +1 -0
- package/dist/utils/types.cjs +13 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +11 -0
- package/dist/utils/types.d.ts +5 -7
- package/dist/utils/types.js +8 -8
- package/dist/utils/types.js.map +1 -1
- package/dist/version.cjs +7 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +5 -5
- package/dist/version.js.map +1 -1
- package/package.json +23 -3
- package/dist/api-client/index.js.map +0 -1
- package/dist/auth/api.d.ts +0 -6
- package/dist/auth/error.d.ts +0 -11
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/linked-project.d.ts +0 -10
- package/dist/auth/zod.d.ts +0 -5
- package/dist/constants.js +0 -3
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/network-policy.js +0 -3
- package/dist/network-policy.js.map +0 -1
- package/dist/utils/array.d.ts +0 -9
- package/dist/utils/consume-readable.d.ts +0 -5
- package/dist/utils/convert-sandbox.d.ts +0 -6
- package/dist/utils/convert-sandbox.js +0 -14
- package/dist/utils/convert-sandbox.js.map +0 -1
- package/dist/utils/decode-base64-url.d.ts +0 -7
- package/dist/utils/dev-credentials.d.ts +0 -37
- package/dist/utils/log.d.ts +0 -2
- package/dist/utils/network-policy.d.ts +0 -7
- package/dist/utils/normalizePath.d.ts +0 -17
- package/dist/version.d.ts +0 -1
package/dist/session.js
CHANGED
|
@@ -1,507 +1,519 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { consumeReadable } from "./utils/consume-readable.js";
|
|
2
|
+
import { APIClient } from "./api-client/api-client.js";
|
|
3
|
+
import "./api-client/index.js";
|
|
4
|
+
import { getCredentials } from "./utils/get-credentials.js";
|
|
5
|
+
import { Command, CommandFinished } from "./command.js";
|
|
6
|
+
import { Snapshot } from "./snapshot.js";
|
|
7
|
+
import { toSandboxSnapshot } from "./utils/sandbox-snapshot.js";
|
|
8
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
|
|
9
|
+
import { dirname, resolve } from "path";
|
|
10
|
+
import { pipeline } from "stream/promises";
|
|
11
|
+
import { createWriteStream } from "fs";
|
|
12
|
+
import { mkdir } from "fs/promises";
|
|
13
|
+
|
|
14
|
+
//#region src/session.ts
|
|
12
15
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class Session {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
|
|
16
|
+
* A Session represents a running VM instance within a {@link Sandbox}.
|
|
17
|
+
*
|
|
18
|
+
* Obtain a session via {@link Sandbox.currentSession}.
|
|
19
|
+
*/
|
|
20
|
+
var Session = class Session {
|
|
21
|
+
/**
|
|
22
|
+
* Lazily resolve credentials and construct an API client.
|
|
23
|
+
* This is used in step contexts where the Sandbox was deserialized
|
|
24
|
+
* without a client (e.g. when crossing workflow/step boundaries).
|
|
25
|
+
* Uses getCredentials() which resolves from OIDC or env vars.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
async ensureClient() {
|
|
29
|
+
"use step";
|
|
30
|
+
if (this._client) return this._client;
|
|
31
|
+
const credentials = await getCredentials();
|
|
32
|
+
this._client = new APIClient({
|
|
33
|
+
teamId: credentials.teamId,
|
|
34
|
+
token: credentials.token
|
|
35
|
+
});
|
|
36
|
+
return this._client;
|
|
37
|
+
}
|
|
38
|
+
get client() {
|
|
39
|
+
if (!this._client) throw new Error("API client not initialized");
|
|
40
|
+
return this._client;
|
|
41
|
+
}
|
|
42
|
+
/** @internal */
|
|
43
|
+
get _sessionSnapshot() {
|
|
44
|
+
return this.session;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Unique ID of this session.
|
|
48
|
+
*/
|
|
49
|
+
get sessionId() {
|
|
50
|
+
return this.session.id;
|
|
51
|
+
}
|
|
52
|
+
get interactivePort() {
|
|
53
|
+
return this.session.interactivePort ?? void 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The status of this session.
|
|
57
|
+
*/
|
|
58
|
+
get status() {
|
|
59
|
+
return this.session.status;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The creation date of this session.
|
|
63
|
+
*/
|
|
64
|
+
get createdAt() {
|
|
65
|
+
return new Date(this.session.createdAt);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The timeout of this session in milliseconds.
|
|
69
|
+
*/
|
|
70
|
+
get timeout() {
|
|
71
|
+
return this.session.timeout;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The network policy of this session.
|
|
75
|
+
*/
|
|
76
|
+
get networkPolicy() {
|
|
77
|
+
return this.session.networkPolicy;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* If the session was created from a snapshot, the ID of that snapshot.
|
|
81
|
+
*/
|
|
82
|
+
get sourceSnapshotId() {
|
|
83
|
+
return this.session.sourceSnapshotId;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Memory allocated to this session in MB.
|
|
87
|
+
*/
|
|
88
|
+
get memory() {
|
|
89
|
+
return this.session.memory;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Number of vCPUs allocated to this session.
|
|
93
|
+
*/
|
|
94
|
+
get vcpus() {
|
|
95
|
+
return this.session.vcpus;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The region where this session is hosted.
|
|
99
|
+
*/
|
|
100
|
+
get region() {
|
|
101
|
+
return this.session.region;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Runtime identifier (e.g. "node24", "python3.13").
|
|
105
|
+
*/
|
|
106
|
+
get runtime() {
|
|
107
|
+
return this.session.runtime;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The working directory of this session.
|
|
111
|
+
*/
|
|
112
|
+
get cwd() {
|
|
113
|
+
return this.session.cwd;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* When this session was requested.
|
|
117
|
+
*/
|
|
118
|
+
get requestedAt() {
|
|
119
|
+
return new Date(this.session.requestedAt);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* When this session started running.
|
|
123
|
+
*/
|
|
124
|
+
get startedAt() {
|
|
125
|
+
return this.session.startedAt != null ? new Date(this.session.startedAt) : void 0;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* When this session was requested to stop.
|
|
129
|
+
*/
|
|
130
|
+
get requestedStopAt() {
|
|
131
|
+
return this.session.requestedStopAt != null ? new Date(this.session.requestedStopAt) : void 0;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* When this session was stopped.
|
|
135
|
+
*/
|
|
136
|
+
get stoppedAt() {
|
|
137
|
+
return this.session.stoppedAt != null ? new Date(this.session.stoppedAt) : void 0;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* When this session was aborted.
|
|
141
|
+
*/
|
|
142
|
+
get abortedAt() {
|
|
143
|
+
return this.session.abortedAt != null ? new Date(this.session.abortedAt) : void 0;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The wall-clock duration of this session in milliseconds.
|
|
147
|
+
*/
|
|
148
|
+
get duration() {
|
|
149
|
+
return this.session.duration;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* When a snapshot was requested for this session.
|
|
153
|
+
*/
|
|
154
|
+
get snapshottedAt() {
|
|
155
|
+
return this.session.snapshottedAt != null ? new Date(this.session.snapshottedAt) : void 0;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* When this session was last updated.
|
|
159
|
+
*/
|
|
160
|
+
get updatedAt() {
|
|
161
|
+
return new Date(this.session.updatedAt);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The amount of active CPU used by the session. Only reported once the VM is
|
|
165
|
+
* stopped.
|
|
166
|
+
*/
|
|
167
|
+
get activeCpuUsageMs() {
|
|
168
|
+
return this.session.activeCpuDurationMs;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The amount of network data used by the session. Only reported once the VM
|
|
172
|
+
* is stopped.
|
|
173
|
+
*/
|
|
174
|
+
get networkTransfer() {
|
|
175
|
+
return this.session.networkTransfer;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Serialize a Session instance to plain data for @workflow/serde.
|
|
179
|
+
*
|
|
180
|
+
* Although Sandbox handles top-level serialization, Session needs these
|
|
181
|
+
* methods so the Workflow SWC compiler can resolve the class by name.
|
|
182
|
+
* The `new Session(...)` self-reference in WORKFLOW_DESERIALIZE forces
|
|
183
|
+
* rolldown to preserve the class name in the compiled output.
|
|
184
|
+
*/
|
|
185
|
+
static [WORKFLOW_SERIALIZE](instance) {
|
|
186
|
+
return {
|
|
187
|
+
session: instance.session,
|
|
188
|
+
routes: instance.routes
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
static [WORKFLOW_DESERIALIZE](data) {
|
|
192
|
+
return new Session({
|
|
193
|
+
routes: data.routes,
|
|
194
|
+
snapshot: data.session
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
constructor(params) {
|
|
198
|
+
this._client = null;
|
|
199
|
+
this.routes = params.routes;
|
|
200
|
+
if ("snapshot" in params) this.session = params.snapshot;
|
|
201
|
+
else {
|
|
202
|
+
this._client = params.client;
|
|
203
|
+
this.session = toSandboxSnapshot(params.session);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get a previously run command by its ID.
|
|
208
|
+
*
|
|
209
|
+
* @param cmdId - ID of the command to retrieve
|
|
210
|
+
* @param opts - Optional parameters.
|
|
211
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
212
|
+
* @returns A {@link Command} instance representing the command
|
|
213
|
+
*/
|
|
214
|
+
async getCommand(cmdId, opts) {
|
|
215
|
+
"use step";
|
|
216
|
+
const client = await this.ensureClient();
|
|
217
|
+
const command = await client.getCommand({
|
|
218
|
+
sessionId: this.session.id,
|
|
219
|
+
cmdId,
|
|
220
|
+
signal: opts?.signal
|
|
221
|
+
});
|
|
222
|
+
return new Command({
|
|
223
|
+
client,
|
|
224
|
+
sessionId: this.session.id,
|
|
225
|
+
cmd: command.json.command
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
async runCommand(commandOrParams, args, opts) {
|
|
229
|
+
"use step";
|
|
230
|
+
const client = await this.ensureClient();
|
|
231
|
+
const params = typeof commandOrParams === "string" ? {
|
|
232
|
+
cmd: commandOrParams,
|
|
233
|
+
args,
|
|
234
|
+
signal: opts?.signal
|
|
235
|
+
} : commandOrParams;
|
|
236
|
+
const wait = params.detached ? false : true;
|
|
237
|
+
const pipeLogs = async (command$1) => {
|
|
238
|
+
if (!params.stdout && !params.stderr) return;
|
|
239
|
+
try {
|
|
240
|
+
for await (const log of command$1.logs({ signal: params.signal })) if (log.stream === "stdout") params.stdout?.write(log.data);
|
|
241
|
+
else if (log.stream === "stderr") params.stderr?.write(log.data);
|
|
242
|
+
} catch (err) {
|
|
243
|
+
if (params.signal?.aborted) return;
|
|
244
|
+
throw err;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
if (wait) {
|
|
248
|
+
const commandStream = await client.runCommand({
|
|
249
|
+
sessionId: this.session.id,
|
|
250
|
+
command: params.cmd,
|
|
251
|
+
args: params.args ?? [],
|
|
252
|
+
cwd: params.cwd,
|
|
253
|
+
env: params.env ?? {},
|
|
254
|
+
sudo: params.sudo ?? false,
|
|
255
|
+
wait: true,
|
|
256
|
+
signal: params.signal
|
|
257
|
+
});
|
|
258
|
+
const command$1 = new Command({
|
|
259
|
+
client,
|
|
260
|
+
sessionId: this.session.id,
|
|
261
|
+
cmd: commandStream.command
|
|
262
|
+
});
|
|
263
|
+
const [finished] = await Promise.all([commandStream.finished, pipeLogs(command$1)]);
|
|
264
|
+
return new CommandFinished({
|
|
265
|
+
client,
|
|
266
|
+
sessionId: this.session.id,
|
|
267
|
+
cmd: finished,
|
|
268
|
+
exitCode: finished.exitCode ?? 0
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
const commandResponse = await client.runCommand({
|
|
272
|
+
sessionId: this.session.id,
|
|
273
|
+
command: params.cmd,
|
|
274
|
+
args: params.args ?? [],
|
|
275
|
+
cwd: params.cwd,
|
|
276
|
+
env: params.env ?? {},
|
|
277
|
+
sudo: params.sudo ?? false,
|
|
278
|
+
signal: params.signal
|
|
279
|
+
});
|
|
280
|
+
const command = new Command({
|
|
281
|
+
client,
|
|
282
|
+
sessionId: this.session.id,
|
|
283
|
+
cmd: commandResponse.json.command
|
|
284
|
+
});
|
|
285
|
+
pipeLogs(command).catch((err) => {
|
|
286
|
+
if (params.signal?.aborted) return;
|
|
287
|
+
(params.stderr ?? params.stdout)?.emit("error", err);
|
|
288
|
+
});
|
|
289
|
+
return command;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Create a directory in the filesystem of this session.
|
|
293
|
+
*
|
|
294
|
+
* @param path - Path of the directory to create
|
|
295
|
+
* @param opts - Optional parameters.
|
|
296
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
297
|
+
*/
|
|
298
|
+
async mkDir(path$1, opts) {
|
|
299
|
+
"use step";
|
|
300
|
+
await (await this.ensureClient()).mkDir({
|
|
301
|
+
sessionId: this.session.id,
|
|
302
|
+
path: path$1,
|
|
303
|
+
signal: opts?.signal
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Read a file from the filesystem of this session as a stream.
|
|
308
|
+
*
|
|
309
|
+
* @param file - File to read, with path and optional cwd
|
|
310
|
+
* @param opts - Optional parameters.
|
|
311
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
312
|
+
* @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found
|
|
313
|
+
*/
|
|
314
|
+
async readFile(file, opts) {
|
|
315
|
+
"use step";
|
|
316
|
+
return (await this.ensureClient()).readFile({
|
|
317
|
+
sessionId: this.session.id,
|
|
318
|
+
path: file.path,
|
|
319
|
+
cwd: file.cwd,
|
|
320
|
+
signal: opts?.signal
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Read a file from the filesystem of this session as a Buffer.
|
|
325
|
+
*
|
|
326
|
+
* @param file - File to read, with path and optional cwd
|
|
327
|
+
* @param opts - Optional parameters.
|
|
328
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
329
|
+
* @returns A promise that resolves to the file contents as a Buffer, or null if file not found
|
|
330
|
+
*/
|
|
331
|
+
async readFileToBuffer(file, opts) {
|
|
332
|
+
"use step";
|
|
333
|
+
const stream = await (await this.ensureClient()).readFile({
|
|
334
|
+
sessionId: this.session.id,
|
|
335
|
+
path: file.path,
|
|
336
|
+
cwd: file.cwd,
|
|
337
|
+
signal: opts?.signal
|
|
338
|
+
});
|
|
339
|
+
if (stream === null) return null;
|
|
340
|
+
return consumeReadable(stream);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Download a file from the session to the local filesystem.
|
|
344
|
+
*
|
|
345
|
+
* @param src - Source file on the session, with path and optional cwd
|
|
346
|
+
* @param dst - Destination file on the local machine, with path and optional cwd
|
|
347
|
+
* @param opts - Optional parameters.
|
|
348
|
+
* @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.
|
|
349
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
350
|
+
* @returns The absolute path to the written file, or null if the source file was not found
|
|
351
|
+
*/
|
|
352
|
+
async downloadFile(src, dst, opts) {
|
|
353
|
+
"use step";
|
|
354
|
+
const client = await this.ensureClient();
|
|
355
|
+
if (!src?.path) throw new Error("downloadFile: source path is required");
|
|
356
|
+
if (!dst?.path) throw new Error("downloadFile: destination path is required");
|
|
357
|
+
const stream = await client.readFile({
|
|
358
|
+
sessionId: this.session.id,
|
|
359
|
+
path: src.path,
|
|
360
|
+
cwd: src.cwd,
|
|
361
|
+
signal: opts?.signal
|
|
362
|
+
});
|
|
363
|
+
if (stream === null) return null;
|
|
364
|
+
try {
|
|
365
|
+
const dstPath = resolve(dst.cwd ?? "", dst.path);
|
|
366
|
+
if (opts?.mkdirRecursive) await mkdir(dirname(dstPath), { recursive: true });
|
|
367
|
+
await pipeline(stream, createWriteStream(dstPath), { signal: opts?.signal });
|
|
368
|
+
return dstPath;
|
|
369
|
+
} finally {
|
|
370
|
+
stream.destroy();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Write files to the filesystem of this session.
|
|
375
|
+
* Defaults to writing to /vercel/sandbox unless an absolute path is specified.
|
|
376
|
+
* Writes files using the `vercel-sandbox` user.
|
|
377
|
+
*
|
|
378
|
+
* @param files - Array of files with path and stream/buffer contents
|
|
379
|
+
* @param opts - Optional parameters.
|
|
380
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
381
|
+
* @returns A promise that resolves when the files are written
|
|
382
|
+
*/
|
|
383
|
+
async writeFiles(files, opts) {
|
|
384
|
+
"use step";
|
|
385
|
+
return (await this.ensureClient()).writeFiles({
|
|
386
|
+
sessionId: this.session.id,
|
|
387
|
+
cwd: this.session.cwd,
|
|
388
|
+
extractDir: "/",
|
|
389
|
+
files,
|
|
390
|
+
signal: opts?.signal
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Get the public domain of a port of this session.
|
|
395
|
+
*
|
|
396
|
+
* @param p - Port number to resolve
|
|
397
|
+
* @returns A full domain (e.g. `https://subdomain.vercel.run`)
|
|
398
|
+
* @throws If the port has no associated route
|
|
399
|
+
*/
|
|
400
|
+
domain(p) {
|
|
401
|
+
const route = this.routes.find(({ port }) => port == p);
|
|
402
|
+
if (route) return `https://${route.subdomain}.vercel.run`;
|
|
403
|
+
else throw new Error(`No route for port ${p}`);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Stop this session.
|
|
407
|
+
*
|
|
408
|
+
* @param opts - Optional parameters.
|
|
409
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
410
|
+
* @param opts.blocking - If true, poll until the session has fully stopped and return the final state.
|
|
411
|
+
* @returns The session at the time the stop was acknowledged, or after fully stopped if `blocking` is true.
|
|
412
|
+
*/
|
|
413
|
+
async stop(opts) {
|
|
414
|
+
"use step";
|
|
415
|
+
this.session = toSandboxSnapshot((await (await this.ensureClient()).stopSession({
|
|
416
|
+
sessionId: this.session.id,
|
|
417
|
+
signal: opts?.signal,
|
|
418
|
+
blocking: opts?.blocking
|
|
419
|
+
})).json.session);
|
|
420
|
+
return this.session;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Update the current session's settings.
|
|
424
|
+
*
|
|
425
|
+
* @param params - Fields to update.
|
|
426
|
+
* @param params.networkPolicy - The new network policy to apply.
|
|
427
|
+
* @param opts - Optional parameters.
|
|
428
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* // Restrict to specific domains
|
|
432
|
+
* await session.update({
|
|
433
|
+
* networkPolicy: {
|
|
434
|
+
* allow: ["*.npmjs.org", "github.com"],
|
|
435
|
+
* }
|
|
436
|
+
* });
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* // Inject credentials with per-domain transformers
|
|
440
|
+
* await session.update({
|
|
441
|
+
* networkPolicy: {
|
|
442
|
+
* allow: {
|
|
443
|
+
* "ai-gateway.vercel.sh": [{
|
|
444
|
+
* transform: [{
|
|
445
|
+
* headers: { authorization: "Bearer ..." }
|
|
446
|
+
* }]
|
|
447
|
+
* }],
|
|
448
|
+
* "*": []
|
|
449
|
+
* }
|
|
450
|
+
* }
|
|
451
|
+
* });
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* // Deny all network access
|
|
455
|
+
* await session.update({ networkPolicy: "deny-all" });
|
|
456
|
+
*/
|
|
457
|
+
async update(params, opts) {
|
|
458
|
+
"use step";
|
|
459
|
+
if (params.networkPolicy !== void 0) this.session = toSandboxSnapshot((await (await this.ensureClient()).updateNetworkPolicy({
|
|
460
|
+
sessionId: this.session.id,
|
|
461
|
+
networkPolicy: params.networkPolicy,
|
|
462
|
+
signal: opts?.signal
|
|
463
|
+
})).json.session);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Extend the timeout of the session by the specified duration.
|
|
467
|
+
*
|
|
468
|
+
* This allows you to extend the lifetime of a session up until the maximum
|
|
469
|
+
* execution timeout for your plan.
|
|
470
|
+
*
|
|
471
|
+
* @param duration - The duration in milliseconds to extend the timeout by
|
|
472
|
+
* @param opts - Optional parameters.
|
|
473
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
474
|
+
* @returns A promise that resolves when the timeout is extended
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* const sandbox = await Sandbox.create({ timeout: ms('10m') });
|
|
478
|
+
* const session = sandbox.currentSession();
|
|
479
|
+
* // Extends timeout by 5 minutes, to a total of 15 minutes.
|
|
480
|
+
* await session.extendTimeout(ms('5m'));
|
|
481
|
+
*/
|
|
482
|
+
async extendTimeout(duration, opts) {
|
|
483
|
+
"use step";
|
|
484
|
+
this.session = toSandboxSnapshot((await (await this.ensureClient()).extendTimeout({
|
|
485
|
+
sessionId: this.session.id,
|
|
486
|
+
duration,
|
|
487
|
+
signal: opts?.signal
|
|
488
|
+
})).json.session);
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Create a snapshot from this currently running session. New sandboxes can
|
|
492
|
+
* then be created from this snapshot using {@link Sandbox.create}.
|
|
493
|
+
*
|
|
494
|
+
* Note: this session will be stopped as part of the snapshot creation process.
|
|
495
|
+
*
|
|
496
|
+
* @param opts - Optional parameters.
|
|
497
|
+
* @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.
|
|
498
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
499
|
+
* @returns A promise that resolves to the Snapshot instance
|
|
500
|
+
*/
|
|
501
|
+
async snapshot(opts) {
|
|
502
|
+
"use step";
|
|
503
|
+
const client = await this.ensureClient();
|
|
504
|
+
const response = await client.createSnapshot({
|
|
505
|
+
sessionId: this.session.id,
|
|
506
|
+
expiration: opts?.expiration,
|
|
507
|
+
signal: opts?.signal
|
|
508
|
+
});
|
|
509
|
+
this.session = toSandboxSnapshot(response.json.session);
|
|
510
|
+
return new Snapshot({
|
|
511
|
+
client,
|
|
512
|
+
snapshot: response.json.snapshot
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
//#endregion
|
|
518
|
+
export { Session };
|
|
507
519
|
//# sourceMappingURL=session.js.map
|