@agentuity/core 3.0.0-alpha.7 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/services/coder/client.d.ts +13 -1
  2. package/dist/services/coder/client.d.ts.map +1 -1
  3. package/dist/services/coder/client.js +22 -1
  4. package/dist/services/coder/client.js.map +1 -1
  5. package/dist/services/coder/protocol.d.ts +121 -5
  6. package/dist/services/coder/protocol.d.ts.map +1 -1
  7. package/dist/services/coder/protocol.js +117 -0
  8. package/dist/services/coder/protocol.js.map +1 -1
  9. package/dist/services/coder/types.d.ts +73 -0
  10. package/dist/services/coder/types.d.ts.map +1 -1
  11. package/dist/services/coder/types.js +83 -1
  12. package/dist/services/coder/types.js.map +1 -1
  13. package/dist/services/coder/workspaces.d.ts +11 -1
  14. package/dist/services/coder/workspaces.d.ts.map +1 -1
  15. package/dist/services/coder/workspaces.js +34 -1
  16. package/dist/services/coder/workspaces.js.map +1 -1
  17. package/dist/services/keyvalue/service.d.ts +9 -3
  18. package/dist/services/keyvalue/service.d.ts.map +1 -1
  19. package/dist/services/keyvalue/service.js +6 -3
  20. package/dist/services/keyvalue/service.js.map +1 -1
  21. package/dist/services/sandbox/api-reference.js +8 -8
  22. package/dist/services/sandbox/api-reference.js.map +1 -1
  23. package/dist/services/sandbox/client.d.ts +3 -2
  24. package/dist/services/sandbox/client.d.ts.map +1 -1
  25. package/dist/services/sandbox/client.js.map +1 -1
  26. package/dist/services/sandbox/create.d.ts +5 -0
  27. package/dist/services/sandbox/create.d.ts.map +1 -1
  28. package/dist/services/sandbox/create.js +8 -0
  29. package/dist/services/sandbox/create.js.map +1 -1
  30. package/dist/services/sandbox/get.d.ts +8 -4
  31. package/dist/services/sandbox/get.d.ts.map +1 -1
  32. package/dist/services/sandbox/get.js +28 -3
  33. package/dist/services/sandbox/get.js.map +1 -1
  34. package/dist/services/sandbox/getStatus.d.ts +3 -0
  35. package/dist/services/sandbox/getStatus.d.ts.map +1 -1
  36. package/dist/services/sandbox/getStatus.js +19 -2
  37. package/dist/services/sandbox/getStatus.js.map +1 -1
  38. package/dist/services/sandbox/index.d.ts +1 -1
  39. package/dist/services/sandbox/index.d.ts.map +1 -1
  40. package/dist/services/sandbox/list.d.ts +3 -0
  41. package/dist/services/sandbox/list.d.ts.map +1 -1
  42. package/dist/services/sandbox/list.js +5 -0
  43. package/dist/services/sandbox/list.js.map +1 -1
  44. package/dist/services/sandbox/pause.d.ts +17 -1
  45. package/dist/services/sandbox/pause.d.ts.map +1 -1
  46. package/dist/services/sandbox/pause.js +21 -3
  47. package/dist/services/sandbox/pause.js.map +1 -1
  48. package/dist/services/sandbox/run.d.ts +3 -2
  49. package/dist/services/sandbox/run.d.ts.map +1 -1
  50. package/dist/services/sandbox/run.js +229 -82
  51. package/dist/services/sandbox/run.js.map +1 -1
  52. package/dist/services/sandbox/types.d.ts +11 -4
  53. package/dist/services/sandbox/types.d.ts.map +1 -1
  54. package/dist/services/sandbox/types.js +12 -0
  55. package/dist/services/sandbox/types.js.map +1 -1
  56. package/dist/services/stream/namespaces.d.ts +2 -2
  57. package/dist/services/stream/namespaces.js +2 -2
  58. package/dist/services/stream/namespaces.js.map +1 -1
  59. package/dist/services/vector/service.d.ts +11 -11
  60. package/dist/services/vector/service.d.ts.map +1 -1
  61. package/dist/services/vector/service.js.map +1 -1
  62. package/package.json +3 -3
  63. package/src/services/coder/client.ts +34 -0
  64. package/src/services/coder/protocol.ts +121 -0
  65. package/src/services/coder/types.ts +94 -1
  66. package/src/services/coder/workspaces.ts +74 -0
  67. package/src/services/keyvalue/service.ts +16 -7
  68. package/src/services/sandbox/api-reference.ts +8 -8
  69. package/src/services/sandbox/client.ts +4 -4
  70. package/src/services/sandbox/create.ts +10 -0
  71. package/src/services/sandbox/get.ts +32 -3
  72. package/src/services/sandbox/getStatus.ts +23 -2
  73. package/src/services/sandbox/index.ts +1 -1
  74. package/src/services/sandbox/list.ts +5 -0
  75. package/src/services/sandbox/pause.ts +38 -4
  76. package/src/services/sandbox/run.ts +339 -103
  77. package/src/services/sandbox/types.ts +17 -2
  78. package/src/services/stream/namespaces.ts +2 -2
  79. package/src/services/vector/service.ts +11 -21
@@ -113,6 +113,33 @@ export const CoderWorkspaceDetailSchema = z
113
113
  ownerUserId: z.string().describe('Owner user ID'),
114
114
  repos: z.array(CoderSessionRepositoryRefSchema).describe('Repositories in workspace'),
115
115
  repoCount: z.number().describe('Number of repositories'),
116
+ dependencies: z
117
+ .array(z.string())
118
+ .optional()
119
+ .default([])
120
+ .describe('APT package dependencies installed into workspace snapshots'),
121
+ setupScript: z
122
+ .string()
123
+ .optional()
124
+ .default('')
125
+ .describe('Shell script run while preparing workspace snapshots'),
126
+ snapshot: z
127
+ .object({
128
+ status: z.string().describe('Workspace snapshot build status'),
129
+ snapshotId: z.string().optional().describe('Created sandbox snapshot ID'),
130
+ snapshotRef: z.string().optional().describe('Snapshot reference used for sessions'),
131
+ baseSnapshotRef: z.string().optional().describe('Base session snapshot reference'),
132
+ baseDriverVersion: z.string().optional().describe('Base driver version stamp'),
133
+ configHash: z.string().optional().describe('Workspace snapshot input hash'),
134
+ buildId: z.string().optional().describe('Workspace snapshot build identifier'),
135
+ requestedAt: z.string().optional().describe('Snapshot build request timestamp'),
136
+ updatedAt: z.string().optional().describe('Snapshot build update timestamp'),
137
+ createdAt: z.string().optional().describe('Snapshot creation timestamp'),
138
+ error: z.string().optional().describe('Snapshot build error message'),
139
+ })
140
+ .passthrough()
141
+ .optional()
142
+ .describe('Workspace snapshot metadata'),
116
143
  savedSkillIds: z.array(z.string()).describe('Saved skill IDs in workspace'),
117
144
  skillBucketIds: z.array(z.string()).describe('Skill bucket IDs in workspace'),
118
145
  enabledAgents: z
@@ -324,12 +351,16 @@ export type CoderWorkspaceListResponse = z.infer<typeof CoderWorkspaceListRespon
324
351
 
325
352
  function hasWorkspaceSelections(input: {
326
353
  repos?: unknown[];
354
+ dependencies?: unknown[];
355
+ setupScript?: string;
327
356
  savedSkillIds?: unknown[];
328
357
  skillBucketIds?: unknown[];
329
358
  enabledAgents?: unknown[];
330
359
  }): boolean {
331
360
  return (
332
361
  (input.repos?.length ?? 0) > 0 ||
362
+ (input.dependencies?.length ?? 0) > 0 ||
363
+ Boolean(input.setupScript?.trim()) ||
333
364
  (input.savedSkillIds?.length ?? 0) > 0 ||
334
365
  (input.skillBucketIds?.length ?? 0) > 0 ||
335
366
  (input.enabledAgents?.length ?? 0) > 0
@@ -342,6 +373,14 @@ export const CoderCreateWorkspaceRequestSchema = z
342
373
  description: z.string().optional().describe('Workspace description'),
343
374
  scope: z.enum(['user', 'org']).optional().describe('Workspace scope'),
344
375
  repos: z.array(CoderSessionRepositoryRefSchema).optional().describe('Repositories'),
376
+ dependencies: z
377
+ .array(z.string())
378
+ .optional()
379
+ .describe('APT package dependencies installed into workspace snapshots'),
380
+ setupScript: z
381
+ .string()
382
+ .optional()
383
+ .describe('Shell script run while preparing workspace snapshots'),
345
384
  savedSkillIds: z.array(z.string()).optional().describe('Saved skill IDs'),
346
385
  skillBucketIds: z.array(z.string()).optional().describe('Skill bucket IDs'),
347
386
  enabledAgents: z
@@ -350,11 +389,65 @@ export const CoderCreateWorkspaceRequestSchema = z
350
389
  .describe('Effective agent roster to store on the workspace'),
351
390
  })
352
391
  .refine(hasWorkspaceSelections, {
353
- message: 'A workspace needs at least one repo, saved skill, skill bucket, or agent',
392
+ message:
393
+ 'A workspace needs at least one repo, dependency, setup script, saved skill, skill bucket, or agent',
354
394
  })
355
395
  .describe('Request body for creating a workspace');
356
396
  export type CoderCreateWorkspaceRequest = z.infer<typeof CoderCreateWorkspaceRequestSchema>;
357
397
 
398
+ export const CoderUpdateWorkspaceRequestSchema = z
399
+ .object({
400
+ name: z.string().optional().describe('Workspace name'),
401
+ description: z.string().optional().describe('Workspace description'),
402
+ scope: z.enum(['user', 'org']).optional().describe('Workspace scope'),
403
+ repos: z.array(CoderSessionRepositoryRefSchema).optional().describe('Repositories'),
404
+ dependencies: z
405
+ .array(z.string())
406
+ .optional()
407
+ .describe('APT package dependencies installed into workspace snapshots'),
408
+ setupScript: z
409
+ .string()
410
+ .optional()
411
+ .describe('Shell script run while preparing workspace snapshots'),
412
+ savedSkillIds: z.array(z.string()).optional().describe('Saved skill IDs'),
413
+ skillBucketIds: z.array(z.string()).optional().describe('Skill bucket IDs'),
414
+ enabledAgents: z
415
+ .array(z.string())
416
+ .optional()
417
+ .describe('Effective agent roster to store on the workspace'),
418
+ })
419
+ .refine((input) => Object.keys(input).length > 0, {
420
+ message: 'At least one workspace field must be provided',
421
+ })
422
+ .describe('Request body for updating a workspace');
423
+ export type CoderUpdateWorkspaceRequest = z.infer<typeof CoderUpdateWorkspaceRequestSchema>;
424
+
425
+ export const CoderWorkspaceDependencyValidationResponseSchema = z
426
+ .object({
427
+ valid: z.array(z.string()).describe('Valid dependency package specs'),
428
+ invalid: z
429
+ .array(
430
+ z
431
+ .object({
432
+ package: z.string().describe('Invalid dependency package spec'),
433
+ error: z.string().describe('Validation error'),
434
+ requestedVersion: z.string().optional().describe('Requested package version'),
435
+ availableVersions: z
436
+ .array(z.string())
437
+ .optional()
438
+ .describe('Available package versions returned by validation'),
439
+ searchUrl: z.string().describe('Package search URL'),
440
+ })
441
+ .passthrough()
442
+ )
443
+ .describe('Invalid dependency package specs'),
444
+ })
445
+ .passthrough()
446
+ .describe('Workspace dependency validation result');
447
+ export type CoderWorkspaceDependencyValidationResponse = z.infer<
448
+ typeof CoderWorkspaceDependencyValidationResponseSchema
449
+ >;
450
+
358
451
  export const CoderCreateCustomAgentRequestSchema = z
359
452
  .object({
360
453
  slug: z.string().describe('Stable custom agent slug'),
@@ -2,9 +2,13 @@ import { z } from 'zod/v4';
2
2
  import { type APIClient } from '../api.ts';
3
3
  import {
4
4
  CoderCreateWorkspaceRequestSchema,
5
+ CoderUpdateWorkspaceRequestSchema,
6
+ CoderWorkspaceDependencyValidationResponseSchema,
5
7
  CoderWorkspaceDetailSchema,
6
8
  CoderWorkspaceListResponseSchema,
7
9
  type CoderCreateWorkspaceRequest,
10
+ type CoderUpdateWorkspaceRequest,
11
+ type CoderWorkspaceDependencyValidationResponse,
8
12
  type CoderWorkspaceDetail,
9
13
  type CoderWorkspaceListResponse,
10
14
  } from './types.ts';
@@ -25,6 +29,34 @@ const WorkspaceCreateResponseSchema = z
25
29
  .passthrough()
26
30
  .describe('Wrapped workspace create response from coder hub');
27
31
 
32
+ const WorkspaceUpdateResponseSchema = z
33
+ .object({
34
+ workspace: CoderWorkspaceDetailSchema.describe(
35
+ 'Updated workspace payload returned by coder hub'
36
+ ),
37
+ })
38
+ .passthrough()
39
+ .describe('Wrapped workspace update response from coder hub');
40
+
41
+ const WorkspaceSnapshotRefreshResponseSchema = z
42
+ .object({
43
+ workspace: CoderWorkspaceDetailSchema.describe(
44
+ 'Workspace payload returned after refreshing its snapshot'
45
+ ),
46
+ })
47
+ .passthrough()
48
+ .describe('Wrapped workspace snapshot refresh response from coder hub');
49
+
50
+ const WorkspaceDependencyValidationWrappedResponseSchema = z
51
+ .object({
52
+ success: z.boolean().describe('Validation request success indicator'),
53
+ data: CoderWorkspaceDependencyValidationResponseSchema.describe(
54
+ 'Dependency validation result'
55
+ ),
56
+ })
57
+ .passthrough()
58
+ .describe('Wrapped workspace dependency validation response from coder hub');
59
+
28
60
  const OkResponseSchema = z
29
61
  .object({
30
62
  ok: z.boolean().describe('Operation success indicator'),
@@ -68,6 +100,48 @@ export async function coderCreateWorkspace(
68
100
  return resp.workspace;
69
101
  }
70
102
 
103
+ export async function coderUpdateWorkspace(
104
+ client: APIClient,
105
+ params: { workspaceId: string; body: CoderUpdateWorkspaceRequest }
106
+ ): Promise<CoderWorkspaceDetail> {
107
+ const path = `/hub/workspaces/${encodeURIComponent(params.workspaceId)}`;
108
+ const resp = await client.patch<
109
+ z.infer<typeof WorkspaceUpdateResponseSchema>,
110
+ CoderUpdateWorkspaceRequest
111
+ >(path, params.body, WorkspaceUpdateResponseSchema, CoderUpdateWorkspaceRequestSchema);
112
+
113
+ return resp.workspace;
114
+ }
115
+
116
+ export async function coderRefreshWorkspaceSnapshot(
117
+ client: APIClient,
118
+ params: { workspaceId: string }
119
+ ): Promise<CoderWorkspaceDetail> {
120
+ const path = `/hub/workspaces/${encodeURIComponent(params.workspaceId)}/snapshot/refresh`;
121
+ const resp = await client.post<z.infer<typeof WorkspaceSnapshotRefreshResponseSchema>>(
122
+ path,
123
+ undefined,
124
+ WorkspaceSnapshotRefreshResponseSchema
125
+ );
126
+
127
+ return resp.workspace;
128
+ }
129
+
130
+ export async function coderValidateWorkspaceDependencies(
131
+ client: APIClient,
132
+ params: { dependencies: string[] }
133
+ ): Promise<CoderWorkspaceDependencyValidationResponse> {
134
+ const resp = await client.post<
135
+ z.infer<typeof WorkspaceDependencyValidationWrappedResponseSchema>
136
+ >(
137
+ '/hub/workspaces/dependencies/validate',
138
+ { dependencies: params.dependencies },
139
+ WorkspaceDependencyValidationWrappedResponseSchema
140
+ );
141
+
142
+ return resp.data;
143
+ }
144
+
71
145
  export async function coderDeleteWorkspace(
72
146
  client: APIClient,
73
147
  params: { workspaceId: string }
@@ -317,12 +317,18 @@ export interface KeyValueStorage {
317
317
  *
318
318
  * @param name - the name of the key value storage
319
319
  * @param keyword - the keyword to search for
320
- * @returns map of keys to items with metadata
320
+ * @returns a Map of keys to items with metadata, in the order returned by the server.
321
+ *
322
+ * @remarks
323
+ * Returns a `Map` (not a plain object) for consistency with other multi-result
324
+ * SDK methods such as `vector.getMany()`. Iterate with `for (const [key, item] of results)`
325
+ * or `results.entries()` / `results.keys()` / `results.values()`. Use `results.size`
326
+ * for the count and `results.get(key)` for direct lookup.
321
327
  */
322
328
  search<T = unknown>(
323
329
  name: string,
324
330
  keyword: string
325
- ): Promise<Record<string, KeyValueItemWithMetadata<T>>>;
331
+ ): Promise<Map<string, KeyValueItemWithMetadata<T>>>;
326
332
 
327
333
  /**
328
334
  * get all keys in a namespace
@@ -361,7 +367,8 @@ function base64ToBytes(base64: string): Uint8Array {
361
367
  }
362
368
 
363
369
  /**
364
- * Deserializes search result values from the server's wire format.
370
+ * Deserializes search result values from the server's wire format and
371
+ * returns them as a Map preserving insertion order.
365
372
  *
366
373
  * The Go server stores values as []byte, which Go's json.Marshal
367
374
  * base64-encodes when embedding in a JSON response. This function
@@ -370,8 +377,9 @@ function base64ToBytes(base64: string): Uint8Array {
370
377
  */
371
378
  function deserializeSearchResults<T>(
372
379
  data: Record<string, KeyValueItemWithMetadata<T>>
373
- ): Record<string, KeyValueItemWithMetadata<T>> {
374
- for (const item of Object.values(data)) {
380
+ ): Map<string, KeyValueItemWithMetadata<T>> {
381
+ const out = new Map<string, KeyValueItemWithMetadata<T>>();
382
+ for (const [key, item] of Object.entries(data)) {
375
383
  if (typeof item.value === 'string') {
376
384
  try {
377
385
  const bytes = base64ToBytes(item.value);
@@ -389,8 +397,9 @@ function deserializeSearchResults<T>(
389
397
  // If base64 decoding or parsing fails, leave value as-is
390
398
  }
391
399
  }
400
+ out.set(key, item);
392
401
  }
393
- return data;
402
+ return out;
394
403
  }
395
404
 
396
405
  export class KeyValueStorageService implements KeyValueStorage {
@@ -601,7 +610,7 @@ export class KeyValueStorageService implements KeyValueStorage {
601
610
  async search<T = unknown>(
602
611
  name: string,
603
612
  keyword: string
604
- ): Promise<Record<string, KeyValueItemWithMetadata<T>>> {
613
+ ): Promise<Map<string, KeyValueItemWithMetadata<T>>> {
605
614
  const url = buildUrl(
606
615
  this.#baseUrl,
607
616
  `/kv/search/${encodeURIComponent(name)}/${encodeURIComponent(keyword)}`
@@ -613,7 +613,7 @@ const service: Service = {
613
613
  ],
614
614
  requestBody: {
615
615
  description: 'Snapshot creation payload.',
616
- fields: { schema: SnapshotCreateOptionsSchema },
616
+ fields: { schema: SnapshotCreateOptionsSchema.omit({ orgId: true }) },
617
617
  },
618
618
  responseDescription: 'Returns the created snapshot.',
619
619
  statuses: [
@@ -887,15 +887,15 @@ const service: Service = {
887
887
  exampleHeaders: { 'Content-Type': 'application/gzip' },
888
888
  exampleBody: '<binary gzip data>',
889
889
  },
890
- // ── Disk Checkpoints ──────────────────────────────────────────────
890
+ // ── Sandbox Checkpoints ───────────────────────────────────────────
891
891
  {
892
892
  id: 'create-checkpoint',
893
893
  title: 'Create Checkpoint',
894
- sectionTitle: 'Disk Checkpoints',
894
+ sectionTitle: 'Sandbox Checkpoints',
895
895
  method: 'POST',
896
896
  path: '/sandbox/{sandboxId}/checkpoint',
897
897
  description:
898
- 'Create a named checkpoint of the sandbox filesystem. Checkpoint names must be unique — creating a checkpoint with a name that already exists returns 409 Conflict. Disk checkpoints are persisted across pause/resume cycles.',
898
+ 'Create a named checkpoint of the sandbox filesystem. Checkpoint names must be unique — creating a checkpoint with a name that already exists returns 409 Conflict. Checkpoints are persisted across pause/resume cycles.',
899
899
  pathParams: [
900
900
  { name: 'sandboxId', type: 'string', description: 'Sandbox ID', required: true },
901
901
  ],
@@ -923,11 +923,11 @@ const service: Service = {
923
923
  {
924
924
  id: 'list-checkpoints',
925
925
  title: 'List Checkpoints',
926
- sectionTitle: 'Disk Checkpoints',
926
+ sectionTitle: 'Sandbox Checkpoints',
927
927
  method: 'GET',
928
928
  path: '/sandbox/checkpoints/{sandboxId}',
929
929
  description:
930
- 'List checkpoints for a specific sandbox. Disk checkpoints are persisted across pause/resume cycles.',
930
+ 'List checkpoints for a specific sandbox. Checkpoints are persisted across pause/resume cycles.',
931
931
  pathParams: [
932
932
  { name: 'sandboxId', type: 'string', description: 'Sandbox ID', required: true },
933
933
  ],
@@ -947,7 +947,7 @@ const service: Service = {
947
947
  {
948
948
  id: 'restore-checkpoint',
949
949
  title: 'Restore Checkpoint',
950
- sectionTitle: 'Disk Checkpoints',
950
+ sectionTitle: 'Sandbox Checkpoints',
951
951
  method: 'POST',
952
952
  path: '/sandbox/{sandboxId}/checkpoint/{checkpointId}/restore',
953
953
  description: 'Restore the sandbox filesystem to a checkpoint state.',
@@ -971,7 +971,7 @@ const service: Service = {
971
971
  {
972
972
  id: 'delete-checkpoint',
973
973
  title: 'Delete Checkpoint',
974
- sectionTitle: 'Disk Checkpoints',
974
+ sectionTitle: 'Sandbox Checkpoints',
975
975
  method: 'DELETE',
976
976
  path: '/sandbox/{sandboxId}/checkpoint/{checkpointId}',
977
977
  description: 'Delete a checkpoint.',
@@ -34,7 +34,7 @@ import {
34
34
  sandboxRmDir,
35
35
  sandboxSetEnv,
36
36
  } from './files.ts';
37
- import { sandboxPause } from './pause.ts';
37
+ import { sandboxPause, type SandboxPauseResult } from './pause.ts';
38
38
  import { sandboxResume } from './resume.ts';
39
39
  import { sandboxRun } from './run.ts';
40
40
  import {
@@ -281,7 +281,7 @@ export interface SandboxInstance {
281
281
  /**
282
282
  * Pause the sandbox, creating a checkpoint of its current state
283
283
  */
284
- pause(): Promise<void>;
284
+ pause(): Promise<SandboxPauseResult>;
285
285
 
286
286
  /**
287
287
  * Resume the sandbox from a paused or evacuated state
@@ -399,7 +399,7 @@ function createSandboxInstanceMethods(
399
399
  return sandboxGet(client, { sandboxId, orgId });
400
400
  },
401
401
 
402
- async pause(): Promise<void> {
402
+ async pause(): Promise<SandboxPauseResult> {
403
403
  return sandboxPause(client, { sandboxId, orgId });
404
404
  },
405
405
 
@@ -725,7 +725,7 @@ export class SandboxClient {
725
725
  *
726
726
  * @param sandboxId - The sandbox ID to pause
727
727
  */
728
- async pause(sandboxId: string): Promise<void> {
728
+ async pause(sandboxId: string): Promise<SandboxPauseResult> {
729
729
  return sandboxPause(this.#client, { sandboxId, orgId: this.#orgId });
730
730
  }
731
731
 
@@ -49,6 +49,12 @@ export const SandboxCreateRequestSchema = z
49
49
  .object({
50
50
  idle: z.string().optional().describe('Idle timeout duration (e.g., "5m", "1h")'),
51
51
  execution: z.string().optional().describe('Maximum execution time (e.g., "30m", "2h")'),
52
+ paused: z
53
+ .string()
54
+ .optional()
55
+ .describe(
56
+ 'Maximum time sandbox can remain paused before termination (e.g., "24h", "0s" for infinite)'
57
+ ),
52
58
  })
53
59
  .optional()
54
60
  .describe('Timeout settings for the sandbox'),
@@ -139,6 +145,10 @@ export const SandboxCreateDataSchema = z
139
145
  'failed',
140
146
  ])
141
147
  .describe('Current status of the sandbox'),
148
+ executionId: z
149
+ .string()
150
+ .optional()
151
+ .describe('Initial execution identifier for oneshot sandbox creation'),
142
152
  url: z
143
153
  .string()
144
154
  .optional()
@@ -156,7 +156,7 @@ export const SandboxInfoDataSchema = z
156
156
  user: SandboxUserInfoSchema.optional().describe('User who created the sandbox'),
157
157
  agent: SandboxAgentInfoSchema.optional().describe('Agent associated with the sandbox'),
158
158
  project: SandboxProjectInfoSchema.optional().describe('Project associated with the sandbox'),
159
- org: SandboxOrgInfoSchema.describe('Organization associated with the sandbox'),
159
+ org: SandboxOrgInfoSchema.nullish().describe('Organization associated with the sandbox'),
160
160
  timeout: z
161
161
  .object({
162
162
  idle: z.string().optional().describe('Idle timeout duration (e.g., "5m", "1h").'),
@@ -164,6 +164,10 @@ export const SandboxInfoDataSchema = z
164
164
  .string()
165
165
  .optional()
166
166
  .describe('Execution timeout duration (e.g., "30m", "2h").'),
167
+ paused: z
168
+ .string()
169
+ .optional()
170
+ .describe('Paused timeout duration (e.g., "24h", "0s" for infinite).'),
167
171
  })
168
172
  .optional()
169
173
  .describe('Timeout configuration for the sandbox.'),
@@ -189,6 +193,16 @@ export const SandboxGetParamsSchema = z.object({
189
193
  .boolean()
190
194
  .optional()
191
195
  .describe('Whether deleted sandboxes should be included in lookup'),
196
+ waitForStatus: z
197
+ .union([z.string(), z.array(z.string())])
198
+ .optional()
199
+ .describe('Optional desired status or statuses to wait for before responding'),
200
+ waitMs: z
201
+ .number()
202
+ .int()
203
+ .nonnegative()
204
+ .optional()
205
+ .describe('Maximum time in milliseconds to wait for the desired status'),
192
206
  });
193
207
 
194
208
  export type SandboxGetParams = z.infer<typeof SandboxGetParamsSchema>;
@@ -205,7 +219,7 @@ export async function sandboxGet(
205
219
  client: APIClient,
206
220
  params: SandboxGetParams
207
221
  ): Promise<SandboxInfo> {
208
- const { sandboxId, orgId, includeDeleted } = params;
222
+ const { sandboxId, orgId, includeDeleted, waitForStatus, waitMs } = params;
209
223
  const queryParams = new URLSearchParams();
210
224
  if (orgId) {
211
225
  queryParams.set('orgId', orgId);
@@ -213,6 +227,15 @@ export async function sandboxGet(
213
227
  if (includeDeleted) {
214
228
  queryParams.set('includeDeleted', 'true');
215
229
  }
230
+ if (waitForStatus) {
231
+ queryParams.set(
232
+ 'waitForStatus',
233
+ Array.isArray(waitForStatus) ? waitForStatus.join(',') : waitForStatus
234
+ );
235
+ }
236
+ if (waitMs != null) {
237
+ queryParams.set('waitMs', String(waitMs));
238
+ }
216
239
  const queryString = queryParams.toString();
217
240
  const url = `/sandbox/${encodeURIComponent(sandboxId)}${queryString ? `?${queryString}` : ''}`;
218
241
 
@@ -222,6 +245,12 @@ export async function sandboxGet(
222
245
  );
223
246
 
224
247
  if (resp.success) {
248
+ // Newly created sandboxes can be served from the server's pending cache before
249
+ // the backing row and related org hydration are fully available. That response
250
+ // serializes `org: null`, so normalize it to a placeholder object instead of
251
+ // failing response validation for an otherwise valid sandbox status poll.
252
+ const org = resp.data.org ?? { id: orgId ?? '', name: '' };
253
+
225
254
  return {
226
255
  sandboxId: resp.data.sandboxId,
227
256
  identifier: resp.data.identifier,
@@ -252,7 +281,7 @@ export async function sandboxGet(
252
281
  user: resp.data.user,
253
282
  agent: resp.data.agent,
254
283
  project: resp.data.project,
255
- org: resp.data.org,
284
+ org,
256
285
  timeout: resp.data.timeout,
257
286
  command: resp.data.command,
258
287
  };
@@ -13,6 +13,17 @@ const SandboxStatusResponseSchema = APIResponseSchema(SandboxStatusDataSchema);
13
13
  export const SandboxGetStatusParamsSchema = z.object({
14
14
  sandboxId: z.string().describe('Sandbox ID to retrieve status for'),
15
15
  orgId: z.string().optional().describe('Optional org id for CLI auth context'),
16
+ waitForStatus: z
17
+ .union([z.string(), z.array(z.string())])
18
+ .optional()
19
+ .describe('Optional desired status or statuses to wait for before responding'),
20
+ waitMs: z
21
+ .number()
22
+ .int()
23
+ .nonnegative()
24
+ .optional()
25
+ .describe('Maximum time in milliseconds to wait for the desired status'),
26
+ signal: z.custom<AbortSignal>().optional().describe('abort signal for cancellation'),
16
27
  });
17
28
 
18
29
  export type SandboxGetStatusParams = z.infer<typeof SandboxGetStatusParamsSchema>;
@@ -26,17 +37,27 @@ export async function sandboxGetStatus(
26
37
  client: APIClient,
27
38
  params: SandboxGetStatusParams
28
39
  ): Promise<SandboxStatusResult> {
29
- const { sandboxId, orgId } = params;
40
+ const { sandboxId, orgId, waitForStatus, waitMs, signal } = params;
30
41
  const queryParams = new URLSearchParams();
31
42
  if (orgId) {
32
43
  queryParams.set('orgId', orgId);
33
44
  }
45
+ if (waitForStatus) {
46
+ queryParams.set(
47
+ 'waitForStatus',
48
+ Array.isArray(waitForStatus) ? waitForStatus.join(',') : waitForStatus
49
+ );
50
+ }
51
+ if (waitMs != null) {
52
+ queryParams.set('waitMs', String(waitMs));
53
+ }
34
54
  const queryString = queryParams.toString();
35
55
  const url = `/sandbox/status/${sandboxId}${queryString ? `?${queryString}` : ''}`;
36
56
 
37
57
  const resp = await client.get<z.infer<typeof SandboxStatusResponseSchema>>(
38
58
  url,
39
- SandboxStatusResponseSchema
59
+ SandboxStatusResponseSchema,
60
+ signal
40
61
  );
41
62
 
42
63
  if (resp.success) {
@@ -52,7 +52,7 @@ export {
52
52
  diskCheckpointRestore,
53
53
  diskCheckpointDelete,
54
54
  } from './disk-checkpoint.ts';
55
- export type { SandboxPauseParams } from './pause.ts';
55
+ export type { SandboxPauseParams, SandboxPauseResult } from './pause.ts';
56
56
  export { PauseResponseSchema, SandboxPauseParamsSchema, sandboxPause } from './pause.ts';
57
57
  export type { SandboxResumeParams } from './resume.ts';
58
58
  export { ResumeResponseSchema, SandboxResumeParamsSchema, sandboxResume } from './resume.ts';
@@ -112,6 +112,10 @@ export const SandboxInfoSchema = z
112
112
  .string()
113
113
  .optional()
114
114
  .describe('Execution timeout duration (e.g., "30m", "2h").'),
115
+ paused: z
116
+ .string()
117
+ .optional()
118
+ .describe('Paused timeout duration (e.g., "24h", "0s" for infinite).'),
115
119
  })
116
120
  .optional()
117
121
  .describe('Timeout configuration for the sandbox.'),
@@ -225,6 +229,7 @@ export async function sandboxList(
225
229
  networkPort: s.networkPort,
226
230
  url: s.url,
227
231
  org: s.org,
232
+ timeout: s.timeout,
228
233
  })),
229
234
  total: resp.data.total,
230
235
  };
@@ -1,8 +1,21 @@
1
1
  import { z } from 'zod';
2
- import { type APIClient, APIResponseSchemaNoData } from '../api.ts';
2
+ import { type APIClient } from '../api.ts';
3
3
  import { throwSandboxError } from './util.ts';
4
4
 
5
- export const PauseResponseSchema = APIResponseSchemaNoData();
5
+ export const PauseResponseSchema = z.discriminatedUnion('success', [
6
+ z.object({
7
+ success: z.literal<false>(false),
8
+ message: z.string(),
9
+ code: z.string().optional(),
10
+ }),
11
+ z.object({
12
+ success: z.literal<true>(true),
13
+ sandboxId: z.string(),
14
+ status: z.string(),
15
+ checkpointId: z.string().optional(),
16
+ terminatesAt: z.string().optional(),
17
+ }),
18
+ ]);
6
19
 
7
20
  export const SandboxPauseParamsSchema = z.object({
8
21
  sandboxId: z.string().describe('Sandbox ID to pause'),
@@ -11,14 +24,30 @@ export const SandboxPauseParamsSchema = z.object({
11
24
 
12
25
  export type SandboxPauseParams = z.infer<typeof SandboxPauseParamsSchema>;
13
26
 
27
+ /** Result returned from pausing a sandbox */
28
+ export interface SandboxPauseResult {
29
+ /** The sandbox ID that was paused */
30
+ sandboxId: string;
31
+ /** New status (typically "suspended") */
32
+ status: string;
33
+ /** Checkpoint ID created during pause */
34
+ checkpointId?: string;
35
+ /** ISO 8601 timestamp when sandbox will auto-terminate if not resumed (omitted if no paused timeout) */
36
+ terminatesAt?: string;
37
+ }
38
+
14
39
  /**
15
40
  * Pauses a running sandbox, creating a checkpoint of its current state.
16
41
  *
17
42
  * @param client - The API client to use for the request
18
43
  * @param params - Parameters including the sandbox ID to pause
44
+ * @returns Pause result including terminatesAt if a paused timeout is configured
19
45
  * @throws {SandboxResponseError} If the sandbox is not found or pause fails
20
46
  */
21
- export async function sandboxPause(client: APIClient, params: SandboxPauseParams): Promise<void> {
47
+ export async function sandboxPause(
48
+ client: APIClient,
49
+ params: SandboxPauseParams
50
+ ): Promise<SandboxPauseResult> {
22
51
  const { sandboxId, orgId } = params;
23
52
  const queryParams = new URLSearchParams();
24
53
  if (orgId) {
@@ -34,7 +63,12 @@ export async function sandboxPause(client: APIClient, params: SandboxPauseParams
34
63
  );
35
64
 
36
65
  if (resp.success) {
37
- return;
66
+ return {
67
+ sandboxId: resp.sandboxId,
68
+ status: resp.status,
69
+ checkpointId: resp.checkpointId,
70
+ terminatesAt: resp.terminatesAt,
71
+ };
38
72
  }
39
73
 
40
74
  throwSandboxError(resp, { sandboxId });