@finalai/sandbox-router-final 0.2.1 → 0.2.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 (70) hide show
  1. package/README.md +63 -6
  2. package/dist/modules/claims.d.mts +3 -0
  3. package/dist/modules/claims.mjs +24 -0
  4. package/dist/modules/claims.mjs.map +7 -0
  5. package/dist/modules/computer.d.mts +7 -0
  6. package/dist/modules/computer.mjs +57 -0
  7. package/dist/modules/computer.mjs.map +7 -0
  8. package/dist/modules/images.d.mts +23 -3
  9. package/dist/modules/images.mjs +48 -23
  10. package/dist/modules/images.mjs.map +3 -3
  11. package/dist/modules/lifecycle.d.mts +25 -0
  12. package/dist/modules/lifecycle.mjs +46 -0
  13. package/dist/modules/lifecycle.mjs.map +7 -0
  14. package/dist/modules/limits.d.mts +1 -0
  15. package/dist/modules/limits.mjs +20 -1
  16. package/dist/modules/limits.mjs.map +2 -2
  17. package/dist/modules/options.d.mts +8 -5
  18. package/dist/modules/options.mjs +8 -6
  19. package/dist/modules/options.mjs.map +2 -2
  20. package/dist/modules/provider.mjs +1016 -127
  21. package/dist/modules/provider.mjs.map +2 -2
  22. package/dist/modules/service.d.mts +12 -0
  23. package/dist/modules/service.mjs +49 -0
  24. package/dist/modules/service.mjs.map +7 -0
  25. package/dist/modules/usage.d.mts +7 -0
  26. package/dist/modules/usage.mjs +50 -0
  27. package/dist/modules/usage.mjs.map +7 -0
  28. package/dist/modules/vm/api.d.mts +2 -1
  29. package/dist/modules/vm/api.mjs +11 -3
  30. package/dist/modules/vm/api.mjs.map +2 -2
  31. package/dist/modules/vm/client.d.mts +85 -4
  32. package/dist/modules/vm/client.mjs +142 -6
  33. package/dist/modules/vm/client.mjs.map +2 -2
  34. package/dist/modules/vm/errors.d.mts +2 -0
  35. package/dist/modules/vm/errors.mjs +2 -1
  36. package/dist/modules/vm/errors.mjs.map +2 -2
  37. package/dist/modules/vm/exec.d.mts +1 -0
  38. package/dist/modules/vm/exec.mjs +2 -0
  39. package/dist/modules/vm/exec.mjs.map +2 -2
  40. package/dist/modules/vm/files.d.mts +8 -0
  41. package/dist/modules/vm/files.mjs +47 -0
  42. package/dist/modules/vm/files.mjs.map +2 -2
  43. package/dist/modules/vm/ids.d.mts +1 -0
  44. package/dist/modules/vm/ids.mjs +2 -0
  45. package/dist/modules/vm/ids.mjs.map +2 -2
  46. package/dist/modules/vm/ingress.d.mts +5 -0
  47. package/dist/modules/vm/ingress.mjs +21 -0
  48. package/dist/modules/vm/ingress.mjs.map +2 -2
  49. package/dist/modules/vm/network.d.mts +3 -1
  50. package/dist/modules/vm/network.mjs +3 -2
  51. package/dist/modules/vm/network.mjs.map +2 -2
  52. package/dist/modules/vm/resources.d.mts +251 -0
  53. package/dist/modules/vm/resources.mjs +210 -0
  54. package/dist/modules/vm/resources.mjs.map +7 -0
  55. package/dist/modules/vm/routes.d.mts +55 -0
  56. package/dist/modules/vm/routes.mjs +61 -0
  57. package/dist/modules/vm/routes.mjs.map +7 -0
  58. package/dist/modules/vm/sandbox.d.mts +92 -3
  59. package/dist/modules/vm/sandbox.mjs +234 -4
  60. package/dist/modules/vm/sandbox.mjs.map +2 -2
  61. package/dist/modules/vm/schemas.d.mts +219 -0
  62. package/dist/modules/vm/schemas.mjs +34 -3
  63. package/dist/modules/vm/schemas.mjs.map +2 -2
  64. package/dist/modules/vm/size.d.mts +10 -0
  65. package/dist/modules/vm/size.mjs +7 -0
  66. package/dist/modules/vm/size.mjs.map +7 -0
  67. package/dist/modules/vm/wire.d.mts +3 -0
  68. package/dist/modules/vm/wire.mjs +6 -0
  69. package/dist/modules/vm/wire.mjs.map +2 -2
  70. package/package.json +2 -2
@@ -1,8 +1,11 @@
1
+ import * as z from 'zod';
1
2
  import { type NetworkIface } from "./network.mjs";
2
3
  import { type ApiTransport } from "./api.mjs";
3
4
  import type { ClockIface } from "./clock.mjs";
5
+ import { type CpuOption, type MemoryOption } from "./size.mjs";
4
6
  import { type AttachOptionsIface, type ExecOptionsIface, type ExecProcessIface } from "./exec.mjs";
5
7
  import { type FileStatIface, type ReadOptionsIface, type RunOptionsIface, type RunResultIface, type WriteOptionsIface } from "./ingress.mjs";
8
+ import { desktopStatusSchema, domainListSchema, domainSchema, eventsAnswerSchema, guestStatusSchema, chargesAnswerSchema, managedProcessPageSchema, metricsAnswerSchema, type MaxLifetimeBodyIface, screenAnswerSchema, settingsAnswerSchema, tokenListSchema, workloadAnswerSchema, type IdlePolicy, type WorkloadBodyIface } from "./resources.mjs";
6
9
  import { type ConnectGrantIface, type SandboxInfoIface, type SandboxOpResultIface } from "./schemas.mjs";
7
10
  export interface SandboxContextIface {
8
11
  api: ApiTransport;
@@ -22,6 +25,7 @@ export interface SandboxIface {
22
25
  delete: () => Promise<SandboxOpResultIface>;
23
26
  checkpoint: (options?: {
24
27
  name?: string;
28
+ labels?: Record<string, string>;
25
29
  timeoutMs?: number;
26
30
  }) => Promise<{
27
31
  snapshotId: string;
@@ -30,9 +34,83 @@ export interface SandboxIface {
30
34
  snapshotId: string;
31
35
  children: SandboxIface[];
32
36
  }>;
33
- setTimeout: (wallClockLimitS: number) => Promise<SandboxOpResultIface>;
34
- updateLabels: (labels: Record<string, string>) => Promise<Record<string, string>>;
35
- connect: () => Promise<ConnectGrantIface>;
37
+ setTimeout: (wallClockLimitS: number | null) => Promise<SandboxOpResultIface>;
38
+ updateLabels: (labels: Record<string, string | null>) => Promise<Record<string, string>>;
39
+ replaceLabels: (labels: Record<string, string>) => Promise<Record<string, string>>;
40
+ metrics: (options: {
41
+ from: number;
42
+ to: number;
43
+ stepS: number;
44
+ }) => Promise<z.output<typeof metricsAnswerSchema>>;
45
+ charges: (options: {
46
+ from: number;
47
+ to: number;
48
+ }) => Promise<z.output<typeof chargesAnswerSchema>>;
49
+ connect: (options?: {
50
+ scopes?: string[];
51
+ ttlS?: number;
52
+ }) => Promise<ConnectGrantIface>;
53
+ settings: () => Promise<z.output<typeof settingsAnswerSchema>>;
54
+ updateSettings: (patch: {
55
+ idleTimeoutS?: number | null;
56
+ idlePolicy?: IdlePolicy;
57
+ autoResume?: boolean;
58
+ workload?: WorkloadBodyIface | null;
59
+ size?: {
60
+ cpu?: CpuOption;
61
+ memory?: MemoryOption;
62
+ diskGb?: number;
63
+ };
64
+ env?: Record<string, string>;
65
+ maxLifetime?: MaxLifetimeBodyIface | null;
66
+ pausedRetentionS?: number | null;
67
+ expectedRevision?: number;
68
+ }) => Promise<z.output<typeof settingsAnswerSchema>>;
69
+ events: (options: {
70
+ before?: string;
71
+ limit?: number;
72
+ }) => Promise<z.output<typeof eventsAnswerSchema>['events']>;
73
+ workload: {
74
+ get: () => Promise<z.output<typeof workloadAnswerSchema>>;
75
+ set: (workload: WorkloadBodyIface) => Promise<void>;
76
+ };
77
+ setPortPublic: (port: number, isPublic: boolean) => Promise<void>;
78
+ tokens: {
79
+ list: () => Promise<z.output<typeof tokenListSchema>['tokens']>;
80
+ revoke: (tokenId: string) => Promise<void>;
81
+ };
82
+ domains: {
83
+ add: (domain: string, port: number) => Promise<z.output<typeof domainSchema>>;
84
+ list: () => Promise<z.output<typeof domainListSchema>>;
85
+ remove: (domainId: string) => Promise<void>;
86
+ };
87
+ volumes: {
88
+ attach: (mount: {
89
+ volumeId: string;
90
+ path: string;
91
+ allowCommit: boolean;
92
+ }) => Promise<void>;
93
+ detach: (volumeId: string) => Promise<void>;
94
+ commit: (volumeId: string) => Promise<{
95
+ commitId: string;
96
+ }>;
97
+ };
98
+ desktop: {
99
+ start: () => Promise<z.output<typeof desktopStatusSchema>>;
100
+ stop: () => Promise<void>;
101
+ status: () => Promise<z.output<typeof desktopStatusSchema>>;
102
+ screen: (options: {
103
+ viewOnly: boolean;
104
+ }) => Promise<z.output<typeof screenAnswerSchema>>;
105
+ editor: () => Promise<{
106
+ token: string;
107
+ expiresAt: Date;
108
+ }>;
109
+ };
110
+ processes: (options?: {
111
+ autoResume?: boolean;
112
+ }) => Promise<z.output<typeof managedProcessPageSchema>['processes']>;
113
+ guestStatus: () => Promise<z.output<typeof guestStatusSchema>>;
36
114
  run: (cmd: string, options?: RunOptionsIface) => Promise<RunResultIface>;
37
115
  exec: (options: ExecOptionsIface) => Promise<ExecProcessIface>;
38
116
  attach: (options: AttachOptionsIface) => Promise<ExecProcessIface>;
@@ -50,6 +128,17 @@ export interface SandboxIface {
50
128
  entries: FileStatIface[];
51
129
  truncated: boolean;
52
130
  }>;
131
+ listPage: (path: string, options?: {
132
+ cursor?: string;
133
+ limit?: number;
134
+ signal?: AbortSignal;
135
+ }) => Promise<{
136
+ entries: FileStatIface[];
137
+ nextCursor: string | null;
138
+ }>;
139
+ append: (path: string, data: Uint8Array | string) => Promise<{
140
+ bytesWritten: number;
141
+ }>;
53
142
  mkdir: (path: string, options?: {
54
143
  parents?: boolean;
55
144
  }) => Promise<void>;
@@ -3,6 +3,7 @@ import { createFileReader } from "./files.mjs";
3
3
  import { createNetworkHandle } from "./network.mjs";
4
4
  import { HttpMethod } from "./api.mjs";
5
5
  import { vmError, VmErrorSource } from "./errors.mjs";
6
+ import { cpuBody, memoryBody } from "./size.mjs";
6
7
  import {
7
8
  attachExec,
8
9
  startExec
@@ -10,11 +11,27 @@ import {
10
11
  import { createGrantSource } from "./grants.mjs";
11
12
  import {
12
13
  createIngress,
14
+ ingressError,
15
+ appendFile,
13
16
  makeDirectory,
14
17
  removeFile,
15
18
  runCommand,
16
19
  writeFile
17
20
  } from "./ingress.mjs";
21
+ import {
22
+ desktopStatusSchema,
23
+ domainListSchema,
24
+ domainSchema,
25
+ eventsAnswerSchema,
26
+ guestStatusSchema,
27
+ chargesAnswerSchema,
28
+ managedProcessPageSchema,
29
+ metricsAnswerSchema,
30
+ screenAnswerSchema,
31
+ settingsAnswerSchema,
32
+ tokenListSchema,
33
+ workloadAnswerSchema
34
+ } from "./resources.mjs";
18
35
  import {
19
36
  checkpointSchema,
20
37
  snapshotSchema,
@@ -28,14 +45,16 @@ import {
28
45
  } from "./schemas.mjs";
29
46
  const CHECKPOINT_DURABLE_TIMEOUT_MS = 10 * 6e4;
30
47
  const CHECKPOINT_POLL_MS = 500;
48
+ const TOKEN_PAGE = 200;
49
+ const PROCESS_PAGE = 200;
31
50
  const path = (id, action) => `/sandboxes/${encodeURIComponent(id)}${action == null ? "" : `/${action}`}`;
32
51
  const createSandboxHandle = (ctx, initial, initialGrant) => {
33
52
  let info = initial;
34
53
  const id = initial.id;
35
- const mintGrant = (signal, refusedByHost) => ctx.api({
54
+ const mintGrant = (signal, refusedByHost, options = {}) => ctx.api({
36
55
  method: HttpMethod.Post,
37
56
  path: path(id, "connect"),
38
- body: { refused_by_host: refusedByHost },
57
+ body: { refused_by_host: refusedByHost, scopes: options.scopes, ttl_s: options.ttlS },
39
58
  idempotent: true,
40
59
  schema: connectGrantSchema,
41
60
  signal
@@ -95,11 +114,33 @@ const createSandboxHandle = (ctx, initial, initialGrant) => {
95
114
  info = { ...info, labels: result.labels };
96
115
  return result.labels;
97
116
  },
117
+ replaceLabels: async (labels) => {
118
+ const result = await ctx.api({
119
+ method: HttpMethod.Put,
120
+ path: path(id, "labels"),
121
+ body: { labels },
122
+ schema: labelsAnswerSchema
123
+ });
124
+ info = { ...info, labels: result.labels };
125
+ return result.labels;
126
+ },
127
+ metrics: (options) => ctx.api({
128
+ method: HttpMethod.Get,
129
+ path: path(id, "metrics"),
130
+ query: { from: options.from, to: options.to, step_s: options.stepS },
131
+ schema: metricsAnswerSchema
132
+ }),
133
+ charges: (options) => ctx.api({
134
+ method: HttpMethod.Get,
135
+ path: path(id, "charges"),
136
+ query: { from: options.from, to: options.to },
137
+ schema: chargesAnswerSchema
138
+ }),
98
139
  checkpoint: async (options = {}) => {
99
140
  const taken = await ctx.api({
100
141
  method: HttpMethod.Post,
101
142
  path: path(id, "checkpoint"),
102
- body: { name: options.name },
143
+ body: { name: options.name, labels: options.labels },
103
144
  schema: checkpointSchema
104
145
  });
105
146
  const deadline = ctx.clock.now() + (options.timeoutMs ?? CHECKPOINT_DURABLE_TIMEOUT_MS);
@@ -136,15 +177,204 @@ const createSandboxHandle = (ctx, initial, initialGrant) => {
136
177
  )
137
178
  };
138
179
  },
139
- connect: () => mintGrant(),
180
+ connect: (options) => mintGrant(void 0, void 0, options),
181
+ settings: () => ctx.api({ method: HttpMethod.Get, path: path(id, "settings"), schema: settingsAnswerSchema }),
182
+ updateSettings: (patch) => ctx.api({
183
+ method: HttpMethod.Patch,
184
+ path: path(id, "settings"),
185
+ body: {
186
+ idle_timeout_s: patch.idleTimeoutS,
187
+ idle_policy: patch.idlePolicy,
188
+ auto_resume: patch.autoResume,
189
+ workload: patch.workload,
190
+ size: patch.size == null ? void 0 : {
191
+ cpu: cpuBody(patch.size.cpu),
192
+ memory: memoryBody(patch.size.memory),
193
+ disk_gb: patch.size.diskGb
194
+ },
195
+ env: patch.env,
196
+ max_lifetime: patch.maxLifetime,
197
+ paused_retention_s: patch.pausedRetentionS,
198
+ expected_revision: patch.expectedRevision
199
+ },
200
+ schema: settingsAnswerSchema
201
+ }),
202
+ events: async (options) => (await ctx.api({
203
+ method: HttpMethod.Get,
204
+ path: path(id, "events"),
205
+ query: { before: options.before, limit: options.limit },
206
+ schema: eventsAnswerSchema
207
+ })).events,
208
+ workload: {
209
+ get: () => ctx.api({
210
+ method: HttpMethod.Get,
211
+ path: path(id, "workload"),
212
+ schema: workloadAnswerSchema
213
+ }),
214
+ set: async (workload) => {
215
+ await ctx.api({
216
+ method: HttpMethod.Put,
217
+ path: path(id, "workload"),
218
+ body: { workload },
219
+ schema: z.unknown()
220
+ });
221
+ }
222
+ },
223
+ setPortPublic: async (port, isPublic) => {
224
+ await ctx.api({
225
+ method: HttpMethod.Put,
226
+ path: `${path(id, "ports")}/${port}`,
227
+ body: { public: isPublic },
228
+ schema: z.unknown()
229
+ });
230
+ },
231
+ tokens: {
232
+ // Newest first, every page.
233
+ list: async () => {
234
+ const tokens = [];
235
+ let before;
236
+ for (; ; ) {
237
+ const page = (await ctx.api({
238
+ method: HttpMethod.Get,
239
+ path: path(id, "tokens"),
240
+ query: { before, limit: TOKEN_PAGE },
241
+ schema: tokenListSchema
242
+ })).tokens;
243
+ tokens.push(...page);
244
+ if (page.length < TOKEN_PAGE) return tokens;
245
+ before = page.at(-1)?.id;
246
+ }
247
+ },
248
+ revoke: async (tokenId) => {
249
+ await ctx.api({
250
+ method: HttpMethod.Delete,
251
+ path: `${path(id, "tokens")}/${encodeURIComponent(tokenId)}`,
252
+ schema: z.unknown()
253
+ });
254
+ }
255
+ },
256
+ domains: {
257
+ add: (domain, port) => ctx.api({
258
+ method: HttpMethod.Post,
259
+ path: path(id, "domains"),
260
+ body: { domain, port },
261
+ schema: domainSchema
262
+ }),
263
+ list: () => ctx.api({ method: HttpMethod.Get, path: path(id, "domains"), schema: domainListSchema }),
264
+ remove: async (domainId) => {
265
+ await ctx.api({
266
+ method: HttpMethod.Delete,
267
+ path: `${path(id, "domains")}/${encodeURIComponent(domainId)}`,
268
+ schema: z.unknown()
269
+ });
270
+ }
271
+ },
272
+ volumes: {
273
+ attach: async (mount) => {
274
+ await ctx.api({
275
+ method: HttpMethod.Post,
276
+ path: path(id, "volumes"),
277
+ body: { volume_id: mount.volumeId, path: mount.path, allow_commit: mount.allowCommit },
278
+ idempotent: true,
279
+ schema: z.unknown()
280
+ });
281
+ },
282
+ detach: async (volumeId) => {
283
+ await ctx.api({
284
+ method: HttpMethod.Delete,
285
+ path: `${path(id, "volumes")}/${encodeURIComponent(volumeId)}`,
286
+ schema: z.unknown()
287
+ });
288
+ },
289
+ commit: async (volumeId) => {
290
+ const started = await ctx.api({
291
+ method: HttpMethod.Post,
292
+ path: `${path(id, "volumes")}/${encodeURIComponent(volumeId)}/commit`,
293
+ body: {},
294
+ schema: z.object({ commit_id: z.string() })
295
+ });
296
+ return { commitId: started.commit_id };
297
+ }
298
+ },
299
+ desktop: {
300
+ editor: async () => {
301
+ const answer = await ctx.api({
302
+ method: HttpMethod.Post,
303
+ path: path(id, "desktop/editor"),
304
+ body: {},
305
+ schema: z.object({ token: z.string(), expires_at: z.number() })
306
+ });
307
+ return { token: answer.token, expiresAt: new Date(answer.expires_at) };
308
+ },
309
+ start: () => ctx.api({
310
+ method: HttpMethod.Post,
311
+ path: path(id, "desktop/start"),
312
+ body: {},
313
+ idempotent: true,
314
+ schema: desktopStatusSchema
315
+ }),
316
+ stop: async () => {
317
+ await ctx.api({
318
+ method: HttpMethod.Post,
319
+ path: path(id, "desktop/stop"),
320
+ body: {},
321
+ idempotent: true,
322
+ schema: z.unknown()
323
+ });
324
+ },
325
+ status: () => ctx.api({
326
+ method: HttpMethod.Get,
327
+ path: path(id, "desktop/status"),
328
+ schema: desktopStatusSchema
329
+ }),
330
+ screen: (options) => ctx.api({
331
+ method: HttpMethod.Post,
332
+ path: path(id, "desktop/screen"),
333
+ body: { view_only: options.viewOnly },
334
+ schema: screenAnswerSchema
335
+ })
336
+ },
337
+ processes: async (options = {}) => {
338
+ const processes = [];
339
+ let after;
340
+ for (; ; ) {
341
+ const { response } = await ingress.request({
342
+ method: "GET",
343
+ path: "/managed-processes",
344
+ query: {
345
+ limit: String(PROCESS_PAGE),
346
+ after_process_id: after,
347
+ auto_resume: options.autoResume === false ? "false" : "true"
348
+ }
349
+ });
350
+ const text = await response.text();
351
+ if (!response.ok) throw ingressError(response.status, text, "/managed-processes");
352
+ const page = managedProcessPageSchema.parse(JSON.parse(text));
353
+ processes.push(...page.processes);
354
+ if (page.next_process_id == null) return processes;
355
+ after = page.next_process_id;
356
+ }
357
+ },
358
+ guestStatus: async () => {
359
+ const { response } = await ingress.request({
360
+ method: "GET",
361
+ path: "/guest-status",
362
+ query: { auto_resume: "false" }
363
+ });
364
+ const text = await response.text();
365
+ if (!response.ok) throw ingressError(response.status, text, "/guest-status");
366
+ return guestStatusSchema.parse(JSON.parse(text));
367
+ },
140
368
  run: (cmd, options) => runCommand(ingress, cmd, options),
141
369
  exec: (options) => startExec(execTransport, options),
142
370
  attach: (options) => attachExec(execTransport, options),
143
371
  files: {
144
372
  read: fileReader.read,
145
373
  write: (filePath, data, options) => writeFile(ingress, filePath, data, options),
374
+ append: (filePath, data) => appendFile(ingress, filePath, data),
146
375
  stat: fileReader.stat,
147
376
  list: fileReader.list,
377
+ listPage: fileReader.listPage,
148
378
  mkdir: (filePath, options) => makeDirectory(ingress, filePath, options),
149
379
  remove: (filePath, options) => removeFile(ingress, filePath, options)
150
380
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/vm/sandbox.ts"],
4
- "sourcesContent": ["import * as z from 'zod';\nimport { createFileReader } from \"./files.mjs\";\nimport { createNetworkHandle, type NetworkIface } from \"./network.mjs\";\nimport { HttpMethod, type ApiTransport } from \"./api.mjs\";\nimport type { ClockIface } from \"./clock.mjs\";\nimport { vmError, VmErrorSource } from \"./errors.mjs\";\nimport {\n attachExec,\n startExec,\n type AttachOptionsIface,\n type ExecOptionsIface,\n type ExecProcessIface,\n} from \"./exec.mjs\";\nimport { createGrantSource, type GrantSourceIface } from \"./grants.mjs\";\nimport {\n createIngress,\n makeDirectory,\n removeFile,\n runCommand,\n writeFile,\n type FileStatIface,\n type IngressIface,\n type ReadOptionsIface,\n type RunOptionsIface,\n type RunResultIface,\n type WriteOptionsIface,\n} from \"./ingress.mjs\";\nimport {\n checkpointSchema,\n snapshotSchema,\n connectGrantSchema,\n forkSchema,\n labelsAnswerSchema,\n portSchema,\n previewTokenSchema,\n sandboxInfoSchema,\n sandboxOpSchema,\n type ConnectGrantIface,\n type SandboxInfoIface,\n type SandboxOpResultIface,\n} from \"./schemas.mjs\";\n\n// Lifecycle and file reads use the API. Commands and file writes use the data plane with a\n// connect grant the handle keeps fresh.\n\n// How long `checkpoint` waits for the snapshot's layers to be durable, and how often it looks.\nconst CHECKPOINT_DURABLE_TIMEOUT_MS = 10 * 60_000;\nconst CHECKPOINT_POLL_MS = 500;\n\nexport interface SandboxContextIface {\n api: ApiTransport;\n fetch: typeof fetch;\n clock: ClockIface;\n previewDomain: string;\n}\n\nexport interface SandboxIface {\n network: NetworkIface;\n // The wire id (`sbx_\u2026`).\n id: string;\n // As of the last answer about this sandbox.\n info: () => SandboxInfoIface;\n refresh: () => Promise<SandboxInfoIface>;\n pause: () => Promise<SandboxOpResultIface>;\n resume: () => Promise<SandboxOpResultIface>;\n stop: () => Promise<SandboxOpResultIface>;\n start: () => Promise<SandboxOpResultIface>;\n delete: () => Promise<SandboxOpResultIface>;\n // Returns once the snapshot is durable.\n checkpoint: (options?: { name?: string; timeoutMs?: number }) => Promise<{ snapshotId: string }>;\n // `count` running copies; this sandbox keeps running.\n fork: (count: number) => Promise<{ snapshotId: string; children: SandboxIface[] }>;\n setTimeout: (wallClockLimitS: number) => Promise<SandboxOpResultIface>;\n // Merges these labels into the sandbox's (at most 64 in all) and answers the result.\n updateLabels: (labels: Record<string, string>) => Promise<Record<string, string>>;\n // A new grant for the data plane, for callers that connect on their own.\n connect: () => Promise<ConnectGrantIface>;\n run: (cmd: string, options?: RunOptionsIface) => Promise<RunResultIface>;\n exec: (options: ExecOptionsIface) => Promise<ExecProcessIface>;\n attach: (options: AttachOptionsIface) => Promise<ExecProcessIface>;\n files: {\n read: (path: string, options?: ReadOptionsIface) => Promise<Uint8Array>;\n write: (\n path: string,\n data: Uint8Array | string,\n options?: WriteOptionsIface,\n ) => Promise<{ bytesWritten: number }>;\n stat: (path: string, options?: { signal?: AbortSignal }) => Promise<FileStatIface | null>;\n list: (\n path: string,\n options?: { signal?: AbortSignal },\n ) => Promise<{ entries: FileStatIface[]; truncated: boolean }>;\n mkdir: (path: string, options?: { parents?: boolean }) => Promise<void>;\n remove: (path: string, options?: { recursive?: boolean }) => Promise<void>;\n };\n // `https://<port>-<uuid hex>.<preview domain>`. Private unless the port is public; pass a\n // preview token (`createPreviewToken`) with the request.\n previewUrl: (port: number) => Promise<string>;\n // Ports with an explicit visibility (published at create or with `setPortPublic`).\n listPorts: () => Promise<{ port: number; public: boolean }[]>;\n createPreviewToken: (\n port: number,\n options?: { ttlS?: number },\n ) => Promise<{ token: string; expiresAt: Date }>;\n}\n\nconst path = (id: string, action?: string) =>\n `/sandboxes/${encodeURIComponent(id)}${action == null ? '' : `/${action}`}`;\n\nexport const createSandboxHandle = (\n ctx: SandboxContextIface,\n initial: SandboxInfoIface,\n // A grant that came with the answer that made or found this sandbox, and when it was asked.\n initialGrant?: { grant: ConnectGrantIface | null; requestedAt: number },\n): SandboxIface => {\n let info = initial;\n const id = initial.id;\n const mintGrant = (signal?: AbortSignal, refusedByHost?: string) =>\n ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'connect'),\n body: { refused_by_host: refusedByHost },\n idempotent: true,\n schema: connectGrantSchema,\n signal,\n });\n const grants: GrantSourceIface = createGrantSource({\n mint: (signal, refusedByHost) => mintGrant(signal, refusedByHost),\n clock: ctx.clock,\n });\n const ingress: IngressIface = createIngress({\n grants,\n fetch: ctx.fetch,\n clock: ctx.clock,\n });\n const fileReader = createFileReader({ api: ctx.api, sandboxId: id });\n const execTransport = { grants, clock: ctx.clock };\n // The API's answers carry grants for the default scopes, which this client asks for too.\n const seed = (grant: ConnectGrantIface | null, requestedAt: number) => {\n if (grant != null) grants.seed(grant, requestedAt);\n };\n if (initialGrant != null) seed(initialGrant.grant, initialGrant.requestedAt);\n\n // A transition the API ran bumped the generation, so the grant in hand would be `moved`.\n const lifecycle = async (\n action: string | null,\n method = HttpMethod.Post,\n body?: { wall_clock_limit_s: number },\n ) => {\n const requestedAt = ctx.clock.now();\n const result = await ctx.api({\n method,\n path: path(id, action ?? undefined),\n body,\n schema: sandboxOpSchema,\n // State commands: a repeat finds the state already reached.\n idempotent: true,\n });\n grants.clear();\n seed(result.connect, requestedAt);\n info = result.sandbox;\n return result;\n };\n\n return {\n network: createNetworkHandle(ctx.api, id),\n id,\n info: () => info,\n refresh: async () => {\n info = await ctx.api({ method: HttpMethod.Get, path: path(id), schema: sandboxInfoSchema });\n return info;\n },\n pause: () => lifecycle('pause'),\n // Explicit lifecycle actions recheck the caller's current authority with the API.\n resume: () => lifecycle('resume'),\n stop: () => lifecycle('stop'),\n start: () => lifecycle('start'),\n delete: () => lifecycle(null, HttpMethod.Delete),\n setTimeout: (wallClockLimitS) =>\n lifecycle('timeout', HttpMethod.Post, { wall_clock_limit_s: wallClockLimitS }),\n updateLabels: async (labels) => {\n const result = await ctx.api({\n method: HttpMethod.Patch,\n path: path(id, 'labels'),\n body: { labels },\n schema: labelsAnswerSchema,\n });\n info = { ...info, labels: result.labels };\n return result.labels;\n },\n checkpoint: async (options = {}) => {\n const taken = await ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'checkpoint'),\n body: { name: options.name },\n schema: checkpointSchema,\n });\n // The API answers once the snapshot is taken; its layers upload after. Restoring it (a\n // create from it) needs it durable, which is what this promises.\n const deadline = ctx.clock.now() + (options.timeoutMs ?? CHECKPOINT_DURABLE_TIMEOUT_MS);\n for (;;) {\n const snapshot = await ctx.api({\n method: HttpMethod.Get,\n path: `/snapshots/${encodeURIComponent(taken.snapshotId)}`,\n schema: snapshotSchema,\n });\n if (snapshot.durableAt != null) return taken;\n if (ctx.clock.now() >= deadline) {\n throw vmError({\n source: VmErrorSource.Api,\n status: null,\n code: 'timeout',\n message: `snapshot ${taken.snapshotId} is not durable yet`,\n });\n }\n await ctx.clock.sleep(CHECKPOINT_POLL_MS);\n }\n },\n fork: async (count) => {\n const requestedAt = ctx.clock.now();\n const result = await ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'fork'),\n body: { count },\n schema: forkSchema,\n });\n return {\n snapshotId: result.snapshotId,\n children: result.children.map(({ connect, ...child }) =>\n createSandboxHandle(ctx, child, { grant: connect, requestedAt }),\n ),\n };\n },\n connect: () => mintGrant(),\n run: (cmd, options) => runCommand(ingress, cmd, options),\n exec: (options) => startExec(execTransport, options),\n attach: (options) => attachExec(execTransport, options),\n files: {\n read: fileReader.read,\n write: (filePath, data, options) => writeFile(ingress, filePath, data, options),\n stat: fileReader.stat,\n list: fileReader.list,\n mkdir: (filePath, options) => makeDirectory(ingress, filePath, options),\n remove: (filePath, options) => removeFile(ingress, filePath, options),\n },\n previewUrl: async (port) => {\n if (!Number.isInteger(port) || port < 1 || port > 65_535) {\n throw new RangeError('port must be an integer between 1 and 65535');\n }\n const grant = await grants.get();\n return `https://${port}-${grant.sandboxUuid.replaceAll('-', '')}.${ctx.previewDomain}`;\n },\n listPorts: async () =>\n (\n await ctx.api({\n method: HttpMethod.Get,\n path: path(id, 'ports'),\n schema: z.object({ ports: z.array(portSchema) }),\n })\n ).ports,\n createPreviewToken: (port, options = {}) =>\n ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'preview-tokens'),\n body: { port, ttl_s: options.ttlS },\n idempotent: true,\n schema: previewTokenSchema,\n }),\n };\n};\n"],
5
- "mappings": "AAAA,YAAY,OAAO;AACnB,SAAS,wBAAwB;AACjC,SAAS,2BAA8C;AACvD,SAAS,kBAAqC;AAE9C,SAAS,SAAS,qBAAqB;AACvC;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP,SAAS,yBAAgD;AACzD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAMP,MAAM,gCAAgC,KAAK;AAC3C,MAAM,qBAAqB;AA2D3B,MAAM,OAAO,CAAC,IAAY,WACxB,cAAc,mBAAmB,EAAE,CAAC,GAAG,UAAU,OAAO,KAAK,IAAI,MAAM,EAAE;AAEpE,MAAM,sBAAsB,CACjC,KACA,SAEA,iBACiB;AACjB,MAAI,OAAO;AACX,QAAM,KAAK,QAAQ;AACnB,QAAM,YAAY,CAAC,QAAsB,kBACvC,IAAI,IAAI;AAAA,IACN,QAAQ,WAAW;AAAA,IACnB,MAAM,KAAK,IAAI,SAAS;AAAA,IACxB,MAAM,EAAE,iBAAiB,cAAc;AAAA,IACvC,YA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O;AAAA,MACtB,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,EAAE,CAAC;AAAA,IACjD,CAAC,GACD;AAAA,IACJ,oBAAoB,CAAC,MAAM,UAAU,CAAC,MACpC,IAAI,IAAI;AAAA,MACN,QAAQ,WAAW;AAAA,MACnB,MAAM,KAAK,IAAI,gBAAgB;AAAA,MAC/B,MAAM,EAAE,MAAM,OAAO,QAAQ,KAAK;AAAA,MAClC,YAAY;AAAA,MACZ,QAAQ;AAAA,IACV,CAAC;AAAA,EACL;AACF;",
4
+ "sourcesContent": ["import * as z from 'zod';\nimport { createFileReader } from \"./files.mjs\";\nimport { createNetworkHandle, type NetworkIface } from \"./network.mjs\";\nimport { HttpMethod, type ApiTransport } from \"./api.mjs\";\nimport type { ClockIface } from \"./clock.mjs\";\nimport { vmError, VmErrorSource } from \"./errors.mjs\";\nimport { cpuBody, memoryBody, type CpuOption, type MemoryOption } from \"./size.mjs\";\nimport {\n attachExec,\n startExec,\n type AttachOptionsIface,\n type ExecOptionsIface,\n type ExecProcessIface,\n} from \"./exec.mjs\";\nimport { createGrantSource, type GrantSourceIface } from \"./grants.mjs\";\nimport {\n createIngress,\n ingressError,\n appendFile,\n makeDirectory,\n removeFile,\n runCommand,\n writeFile,\n type FileStatIface,\n type IngressIface,\n type ReadOptionsIface,\n type RunOptionsIface,\n type RunResultIface,\n type WriteOptionsIface,\n} from \"./ingress.mjs\";\nimport {\n desktopStatusSchema,\n domainListSchema,\n domainSchema,\n eventsAnswerSchema,\n guestStatusSchema,\n chargesAnswerSchema,\n managedProcessPageSchema,\n metricsAnswerSchema,\n type MaxLifetimeBodyIface,\n screenAnswerSchema,\n settingsAnswerSchema,\n tokenListSchema,\n workloadAnswerSchema,\n type IdlePolicy,\n type WorkloadBodyIface,\n} from \"./resources.mjs\";\nimport {\n checkpointSchema,\n snapshotSchema,\n connectGrantSchema,\n forkSchema,\n labelsAnswerSchema,\n portSchema,\n previewTokenSchema,\n sandboxInfoSchema,\n sandboxOpSchema,\n type ConnectGrantIface,\n type SandboxInfoIface,\n type SandboxOpResultIface,\n} from \"./schemas.mjs\";\n\n// Lifecycle and file reads use the API. Commands and file writes use the data plane with a\n// connect grant the handle keeps fresh.\n\n// How long `checkpoint` waits for the snapshot's layers to be durable, and how often it looks.\nconst CHECKPOINT_DURABLE_TIMEOUT_MS = 10 * 60_000;\nconst CHECKPOINT_POLL_MS = 500;\nconst TOKEN_PAGE = 200;\nconst PROCESS_PAGE = 200;\n\nexport interface SandboxContextIface {\n api: ApiTransport;\n fetch: typeof fetch;\n clock: ClockIface;\n previewDomain: string;\n}\n\nexport interface SandboxIface {\n network: NetworkIface;\n // The wire id (`sbx_\u2026`).\n id: string;\n // As of the last answer about this sandbox.\n info: () => SandboxInfoIface;\n refresh: () => Promise<SandboxInfoIface>;\n pause: () => Promise<SandboxOpResultIface>;\n resume: () => Promise<SandboxOpResultIface>;\n stop: () => Promise<SandboxOpResultIface>;\n start: () => Promise<SandboxOpResultIface>;\n delete: () => Promise<SandboxOpResultIface>;\n // Returns once the snapshot is durable.\n checkpoint: (options?: {\n name?: string;\n labels?: Record<string, string>;\n timeoutMs?: number;\n }) => Promise<{ snapshotId: string }>;\n // `count` running copies; this sandbox keeps running.\n fork: (count: number) => Promise<{ snapshotId: string; children: SandboxIface[] }>;\n // Null removes the limit (organizations entitled to it only).\n setTimeout: (wallClockLimitS: number | null) => Promise<SandboxOpResultIface>;\n // Merges these labels into the sandbox's (at most 64 in all; null deletes a key) and answers\n // the result.\n updateLabels: (labels: Record<string, string | null>) => Promise<Record<string, string>>;\n // Replaces all its labels.\n replaceLabels: (labels: Record<string, string>) => Promise<Record<string, string>>;\n // Use per step from `from` to `to` (unix ms); `stepS` a multiple of 60 up to a day.\n metrics: (options: {\n from: number;\n to: number;\n stepS: number;\n }) => Promise<z.output<typeof metricsAnswerSchema>>;\n // What it was charged over a period (unix ms).\n charges: (options: { from: number; to: number }) => Promise<z.output<typeof chargesAnswerSchema>>;\n // A new grant for the data plane, for callers that connect on their own: limited to `scopes`\n // (default: exec and files) for `ttlS`.\n connect: (options?: { scopes?: string[]; ttlS?: number }) => Promise<ConnectGrantIface>;\n settings: () => Promise<z.output<typeof settingsAnswerSchema>>;\n // A size or environment change needs the sandbox stopped; disks only grow.\n updateSettings: (patch: {\n idleTimeoutS?: number | null;\n idlePolicy?: IdlePolicy;\n autoResume?: boolean;\n workload?: WorkloadBodyIface | null;\n size?: { cpu?: CpuOption; memory?: MemoryOption; diskGb?: number };\n env?: Record<string, string>;\n // Replaces the wall-clock limit while set; null removes it.\n maxLifetime?: MaxLifetimeBodyIface | null;\n // Null follows the organization's paused retention again.\n pausedRetentionS?: number | null;\n expectedRevision?: number;\n }) => Promise<z.output<typeof settingsAnswerSchema>>;\n events: (options: {\n before?: string;\n limit?: number;\n }) => Promise<z.output<typeof eventsAnswerSchema>['events']>;\n workload: {\n get: () => Promise<z.output<typeof workloadAnswerSchema>>;\n set: (workload: WorkloadBodyIface) => Promise<void>;\n };\n setPortPublic: (port: number, isPublic: boolean) => Promise<void>;\n tokens: {\n list: () => Promise<z.output<typeof tokenListSchema>['tokens']>;\n revoke: (tokenId: string) => Promise<void>;\n };\n domains: {\n add: (domain: string, port: number) => Promise<z.output<typeof domainSchema>>;\n list: () => Promise<z.output<typeof domainListSchema>>;\n remove: (domainId: string) => Promise<void>;\n };\n volumes: {\n attach: (mount: { volumeId: string; path: string; allowCommit: boolean }) => Promise<void>;\n detach: (volumeId: string) => Promise<void>;\n commit: (volumeId: string) => Promise<{ commitId: string }>;\n };\n desktop: {\n start: () => Promise<z.output<typeof desktopStatusSchema>>;\n stop: () => Promise<void>;\n status: () => Promise<z.output<typeof desktopStatusSchema>>;\n screen: (options: { viewOnly: boolean }) => Promise<z.output<typeof screenAnswerSchema>>;\n // A one-time link token for the editor port, to open (in the URL) before `expiresAt`; the\n // browser session it starts lasts 15 minutes.\n editor: () => Promise<{ token: string; expiresAt: Date }>;\n };\n // Commands started through exec in the current boot, running or ended; from the data plane.\n // `autoResume: false` refuses rather than wakes a paused sandbox.\n processes: (options?: {\n autoResume?: boolean;\n }) => Promise<z.output<typeof managedProcessPageSchema>['processes']>;\n // The guest's own report, read without waking the sandbox.\n guestStatus: () => Promise<z.output<typeof guestStatusSchema>>;\n run: (cmd: string, options?: RunOptionsIface) => Promise<RunResultIface>;\n exec: (options: ExecOptionsIface) => Promise<ExecProcessIface>;\n attach: (options: AttachOptionsIface) => Promise<ExecProcessIface>;\n files: {\n read: (path: string, options?: ReadOptionsIface) => Promise<Uint8Array>;\n write: (\n path: string,\n data: Uint8Array | string,\n options?: WriteOptionsIface,\n ) => Promise<{ bytesWritten: number }>;\n stat: (path: string, options?: { signal?: AbortSignal }) => Promise<FileStatIface | null>;\n list: (\n path: string,\n options?: { signal?: AbortSignal },\n ) => Promise<{ entries: FileStatIface[]; truncated: boolean }>;\n listPage: (\n path: string,\n options?: { cursor?: string; limit?: number; signal?: AbortSignal },\n ) => Promise<{ entries: FileStatIface[]; nextCursor: string | null }>;\n // Adds to the end of the file, creating it if missing.\n append: (path: string, data: Uint8Array | string) => Promise<{ bytesWritten: number }>;\n mkdir: (path: string, options?: { parents?: boolean }) => Promise<void>;\n remove: (path: string, options?: { recursive?: boolean }) => Promise<void>;\n };\n // `https://<port>-<uuid hex>.<preview domain>`. Private unless the port is public; pass a\n // preview token (`createPreviewToken`) with the request.\n previewUrl: (port: number) => Promise<string>;\n // Ports with an explicit visibility (published at create or with `setPortPublic`).\n listPorts: () => Promise<{ port: number; public: boolean }[]>;\n createPreviewToken: (\n port: number,\n options?: { ttlS?: number },\n ) => Promise<{ token: string; expiresAt: Date }>;\n}\n\nconst path = (id: string, action?: string) =>\n `/sandboxes/${encodeURIComponent(id)}${action == null ? '' : `/${action}`}`;\n\nexport const createSandboxHandle = (\n ctx: SandboxContextIface,\n initial: SandboxInfoIface,\n // A grant that came with the answer that made or found this sandbox, and when it was asked.\n initialGrant?: { grant: ConnectGrantIface | null; requestedAt: number },\n): SandboxIface => {\n let info = initial;\n const id = initial.id;\n const mintGrant = (\n signal?: AbortSignal,\n refusedByHost?: string,\n options: { scopes?: string[]; ttlS?: number } = {},\n ) =>\n ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'connect'),\n body: { refused_by_host: refusedByHost, scopes: options.scopes, ttl_s: options.ttlS },\n idempotent: true,\n schema: connectGrantSchema,\n signal,\n });\n const grants: GrantSourceIface = createGrantSource({\n mint: (signal, refusedByHost) => mintGrant(signal, refusedByHost),\n clock: ctx.clock,\n });\n const ingress: IngressIface = createIngress({\n grants,\n fetch: ctx.fetch,\n clock: ctx.clock,\n });\n const fileReader = createFileReader({ api: ctx.api, sandboxId: id });\n const execTransport = { grants, clock: ctx.clock };\n // The API's answers carry grants for the default scopes, which this client asks for too.\n const seed = (grant: ConnectGrantIface | null, requestedAt: number) => {\n if (grant != null) grants.seed(grant, requestedAt);\n };\n if (initialGrant != null) seed(initialGrant.grant, initialGrant.requestedAt);\n\n // A transition the API ran bumped the generation, so the grant in hand would be `moved`.\n const lifecycle = async (\n action: string | null,\n method = HttpMethod.Post,\n body?: { wall_clock_limit_s: number | null },\n ) => {\n const requestedAt = ctx.clock.now();\n const result = await ctx.api({\n method,\n path: path(id, action ?? undefined),\n body,\n schema: sandboxOpSchema,\n // State commands: a repeat finds the state already reached.\n idempotent: true,\n });\n grants.clear();\n seed(result.connect, requestedAt);\n info = result.sandbox;\n return result;\n };\n\n return {\n network: createNetworkHandle(ctx.api, id),\n id,\n info: () => info,\n refresh: async () => {\n info = await ctx.api({ method: HttpMethod.Get, path: path(id), schema: sandboxInfoSchema });\n return info;\n },\n pause: () => lifecycle('pause'),\n // Explicit lifecycle actions recheck the caller's current authority with the API.\n resume: () => lifecycle('resume'),\n stop: () => lifecycle('stop'),\n start: () => lifecycle('start'),\n delete: () => lifecycle(null, HttpMethod.Delete),\n setTimeout: (wallClockLimitS) =>\n lifecycle('timeout', HttpMethod.Post, { wall_clock_limit_s: wallClockLimitS }),\n updateLabels: async (labels) => {\n const result = await ctx.api({\n method: HttpMethod.Patch,\n path: path(id, 'labels'),\n body: { labels },\n schema: labelsAnswerSchema,\n });\n info = { ...info, labels: result.labels };\n return result.labels;\n },\n replaceLabels: async (labels) => {\n const result = await ctx.api({\n method: HttpMethod.Put,\n path: path(id, 'labels'),\n body: { labels },\n schema: labelsAnswerSchema,\n });\n info = { ...info, labels: result.labels };\n return result.labels;\n },\n metrics: (options) =>\n ctx.api({\n method: HttpMethod.Get,\n path: path(id, 'metrics'),\n query: { from: options.from, to: options.to, step_s: options.stepS },\n schema: metricsAnswerSchema,\n }),\n charges: (options) =>\n ctx.api({\n method: HttpMethod.Get,\n path: path(id, 'charges'),\n query: { from: options.from, to: options.to },\n schema: chargesAnswerSchema,\n }),\n checkpoint: async (options = {}) => {\n const taken = await ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'checkpoint'),\n body: { name: options.name, labels: options.labels },\n schema: checkpointSchema,\n });\n // The API answers once the snapshot is taken; its layers upload after. Restoring it (a\n // create from it) needs it durable, which is what this promises.\n const deadline = ctx.clock.now() + (options.timeoutMs ?? CHECKPOINT_DURABLE_TIMEOUT_MS);\n for (;;) {\n const snapshot = await ctx.api({\n method: HttpMethod.Get,\n path: `/snapshots/${encodeURIComponent(taken.snapshotId)}`,\n schema: snapshotSchema,\n });\n if (snapshot.durableAt != null) return taken;\n if (ctx.clock.now() >= deadline) {\n throw vmError({\n source: VmErrorSource.Api,\n status: null,\n code: 'timeout',\n message: `snapshot ${taken.snapshotId} is not durable yet`,\n });\n }\n await ctx.clock.sleep(CHECKPOINT_POLL_MS);\n }\n },\n fork: async (count) => {\n const requestedAt = ctx.clock.now();\n const result = await ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'fork'),\n body: { count },\n schema: forkSchema,\n });\n return {\n snapshotId: result.snapshotId,\n children: result.children.map(({ connect, ...child }) =>\n createSandboxHandle(ctx, child, { grant: connect, requestedAt }),\n ),\n };\n },\n connect: (options) => mintGrant(undefined, undefined, options),\n settings: () =>\n ctx.api({ method: HttpMethod.Get, path: path(id, 'settings'), schema: settingsAnswerSchema }),\n updateSettings: (patch) =>\n ctx.api({\n method: HttpMethod.Patch,\n path: path(id, 'settings'),\n body: {\n idle_timeout_s: patch.idleTimeoutS,\n idle_policy: patch.idlePolicy,\n auto_resume: patch.autoResume,\n workload: patch.workload,\n size:\n patch.size == null\n ? undefined\n : {\n cpu: cpuBody(patch.size.cpu),\n memory: memoryBody(patch.size.memory),\n disk_gb: patch.size.diskGb,\n },\n env: patch.env,\n max_lifetime: patch.maxLifetime,\n paused_retention_s: patch.pausedRetentionS,\n expected_revision: patch.expectedRevision,\n },\n schema: settingsAnswerSchema,\n }),\n events: async (options) =>\n (\n await ctx.api({\n method: HttpMethod.Get,\n path: path(id, 'events'),\n query: { before: options.before, limit: options.limit },\n schema: eventsAnswerSchema,\n })\n ).events,\n workload: {\n get: () =>\n ctx.api({\n method: HttpMethod.Get,\n path: path(id, 'workload'),\n schema: workloadAnswerSchema,\n }),\n set: async (workload) => {\n await ctx.api({\n method: HttpMethod.Put,\n path: path(id, 'workload'),\n body: { workload },\n schema: z.unknown(),\n });\n },\n },\n setPortPublic: async (port, isPublic) => {\n await ctx.api({\n method: HttpMethod.Put,\n path: `${path(id, 'ports')}/${port}`,\n body: { public: isPublic },\n schema: z.unknown(),\n });\n },\n tokens: {\n // Newest first, every page.\n list: async () => {\n const tokens: z.output<typeof tokenListSchema>['tokens'] = [];\n let before: string | undefined;\n for (;;) {\n const page = (\n await ctx.api({\n method: HttpMethod.Get,\n path: path(id, 'tokens'),\n query: { before, limit: TOKEN_PAGE },\n schema: tokenListSchema,\n })\n ).tokens;\n tokens.push(...page);\n if (page.length < TOKEN_PAGE) return tokens;\n before = page.at(-1)?.id;\n }\n },\n revoke: async (tokenId) => {\n await ctx.api({\n method: HttpMethod.Delete,\n path: `${path(id, 'tokens')}/${encodeURIComponent(tokenId)}`,\n schema: z.unknown(),\n });\n },\n },\n domains: {\n add: (domain, port) =>\n ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'domains'),\n body: { domain, port },\n schema: domainSchema,\n }),\n list: () =>\n ctx.api({ method: HttpMethod.Get, path: path(id, 'domains'), schema: domainListSchema }),\n remove: async (domainId) => {\n await ctx.api({\n method: HttpMethod.Delete,\n path: `${path(id, 'domains')}/${encodeURIComponent(domainId)}`,\n schema: z.unknown(),\n });\n },\n },\n volumes: {\n attach: async (mount) => {\n await ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'volumes'),\n body: { volume_id: mount.volumeId, path: mount.path, allow_commit: mount.allowCommit },\n idempotent: true,\n schema: z.unknown(),\n });\n },\n detach: async (volumeId) => {\n await ctx.api({\n method: HttpMethod.Delete,\n path: `${path(id, 'volumes')}/${encodeURIComponent(volumeId)}`,\n schema: z.unknown(),\n });\n },\n commit: async (volumeId) => {\n const started = await ctx.api({\n method: HttpMethod.Post,\n path: `${path(id, 'volumes')}/${encodeURIComponent(volumeId)}/commit`,\n body: {},\n schema: z.object({ commit_id: z.string() }),\n });\n return { commitId: started.commit_id };\n },\n },\n desktop: {\n editor: async () => {\n const answer = await ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'desktop/editor'),\n body: {},\n schema: z.object({ token: z.string(), expires_at: z.number() }),\n });\n return { token: answer.token, expiresAt: new Date(answer.expires_at) };\n },\n start: () =>\n ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'desktop/start'),\n body: {},\n idempotent: true,\n schema: desktopStatusSchema,\n }),\n stop: async () => {\n await ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'desktop/stop'),\n body: {},\n idempotent: true,\n schema: z.unknown(),\n });\n },\n status: () =>\n ctx.api({\n method: HttpMethod.Get,\n path: path(id, 'desktop/status'),\n schema: desktopStatusSchema,\n }),\n screen: (options) =>\n ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'desktop/screen'),\n body: { view_only: options.viewOnly },\n schema: screenAnswerSchema,\n }),\n },\n processes: async (options = {}) => {\n const processes: z.output<typeof managedProcessPageSchema>['processes'] = [];\n let after: string | undefined;\n for (;;) {\n const { response } = await ingress.request({\n method: 'GET',\n path: '/managed-processes',\n query: {\n limit: String(PROCESS_PAGE),\n after_process_id: after,\n auto_resume: options.autoResume === false ? 'false' : 'true',\n },\n });\n const text = await response.text();\n if (!response.ok) throw ingressError(response.status, text, '/managed-processes');\n const page = managedProcessPageSchema.parse(JSON.parse(text));\n processes.push(...page.processes);\n if (page.next_process_id == null) return processes;\n after = page.next_process_id;\n }\n },\n guestStatus: async () => {\n const { response } = await ingress.request({\n method: 'GET',\n path: '/guest-status',\n query: { auto_resume: 'false' },\n });\n const text = await response.text();\n if (!response.ok) throw ingressError(response.status, text, '/guest-status');\n return guestStatusSchema.parse(JSON.parse(text));\n },\n run: (cmd, options) => runCommand(ingress, cmd, options),\n exec: (options) => startExec(execTransport, options),\n attach: (options) => attachExec(execTransport, options),\n files: {\n read: fileReader.read,\n write: (filePath, data, options) => writeFile(ingress, filePath, data, options),\n append: (filePath, data) => appendFile(ingress, filePath, data),\n stat: fileReader.stat,\n list: fileReader.list,\n listPage: fileReader.listPage,\n mkdir: (filePath, options) => makeDirectory(ingress, filePath, options),\n remove: (filePath, options) => removeFile(ingress, filePath, options),\n },\n previewUrl: async (port) => {\n if (!Number.isInteger(port) || port < 1 || port > 65_535) {\n throw new RangeError('port must be an integer between 1 and 65535');\n }\n const grant = await grants.get();\n return `https://${port}-${grant.sandboxUuid.replaceAll('-', '')}.${ctx.previewDomain}`;\n },\n listPorts: async () =>\n (\n await ctx.api({\n method: HttpMethod.Get,\n path: path(id, 'ports'),\n schema: z.object({ ports: z.array(portSchema) }),\n })\n ).ports,\n createPreviewToken: (port, options = {}) =>\n ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'preview-tokens'),\n body: { port, ttl_s: options.ttlS },\n idempotent: true,\n schema: previewTokenSchema,\n }),\n };\n};\n"],
5
+ "mappings": "AAAA,YAAY,OAAO;AACnB,SAAS,wBAAwB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