@agentuity/core 3.0.0-alpha.7 → 3.0.0-beta.1
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 +2 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/services/coder/client.d.ts +13 -1
- package/dist/services/coder/client.d.ts.map +1 -1
- package/dist/services/coder/client.js +22 -1
- package/dist/services/coder/client.js.map +1 -1
- package/dist/services/coder/protocol.d.ts +121 -5
- package/dist/services/coder/protocol.d.ts.map +1 -1
- package/dist/services/coder/protocol.js +117 -0
- package/dist/services/coder/protocol.js.map +1 -1
- package/dist/services/coder/types.d.ts +73 -0
- package/dist/services/coder/types.d.ts.map +1 -1
- package/dist/services/coder/types.js +83 -1
- package/dist/services/coder/types.js.map +1 -1
- package/dist/services/coder/workspaces.d.ts +11 -1
- package/dist/services/coder/workspaces.d.ts.map +1 -1
- package/dist/services/coder/workspaces.js +34 -1
- package/dist/services/coder/workspaces.js.map +1 -1
- package/dist/services/keyvalue/service.d.ts +9 -3
- package/dist/services/keyvalue/service.d.ts.map +1 -1
- package/dist/services/keyvalue/service.js +6 -3
- package/dist/services/keyvalue/service.js.map +1 -1
- package/dist/services/oauth/token-storage.d.ts +4 -1
- package/dist/services/oauth/token-storage.d.ts.map +1 -1
- package/dist/services/oauth/token-storage.js +4 -1
- package/dist/services/oauth/token-storage.js.map +1 -1
- package/dist/services/queue/service.d.ts +31 -33
- package/dist/services/queue/service.d.ts.map +1 -1
- package/dist/services/queue/service.js +13 -13
- package/dist/services/queue/service.js.map +1 -1
- package/dist/services/sandbox/api-reference.js +8 -8
- package/dist/services/sandbox/api-reference.js.map +1 -1
- package/dist/services/sandbox/client.d.ts +3 -2
- package/dist/services/sandbox/client.d.ts.map +1 -1
- package/dist/services/sandbox/client.js.map +1 -1
- package/dist/services/sandbox/create.d.ts +5 -0
- package/dist/services/sandbox/create.d.ts.map +1 -1
- package/dist/services/sandbox/create.js +8 -0
- package/dist/services/sandbox/create.js.map +1 -1
- package/dist/services/sandbox/get.d.ts +8 -4
- package/dist/services/sandbox/get.d.ts.map +1 -1
- package/dist/services/sandbox/get.js +28 -3
- package/dist/services/sandbox/get.js.map +1 -1
- package/dist/services/sandbox/getStatus.d.ts +3 -0
- package/dist/services/sandbox/getStatus.d.ts.map +1 -1
- package/dist/services/sandbox/getStatus.js +19 -2
- package/dist/services/sandbox/getStatus.js.map +1 -1
- package/dist/services/sandbox/index.d.ts +1 -1
- package/dist/services/sandbox/index.d.ts.map +1 -1
- package/dist/services/sandbox/list.d.ts +3 -0
- package/dist/services/sandbox/list.d.ts.map +1 -1
- package/dist/services/sandbox/list.js +5 -0
- package/dist/services/sandbox/list.js.map +1 -1
- package/dist/services/sandbox/pause.d.ts +17 -1
- package/dist/services/sandbox/pause.d.ts.map +1 -1
- package/dist/services/sandbox/pause.js +21 -3
- package/dist/services/sandbox/pause.js.map +1 -1
- package/dist/services/sandbox/run.d.ts +3 -2
- package/dist/services/sandbox/run.d.ts.map +1 -1
- package/dist/services/sandbox/run.js +229 -82
- package/dist/services/sandbox/run.js.map +1 -1
- package/dist/services/sandbox/types.d.ts +11 -4
- package/dist/services/sandbox/types.d.ts.map +1 -1
- package/dist/services/sandbox/types.js +12 -0
- package/dist/services/sandbox/types.js.map +1 -1
- package/dist/services/session/get.d.ts +0 -2
- package/dist/services/session/get.d.ts.map +1 -1
- package/dist/services/session/get.js.map +1 -1
- package/dist/services/stream/namespaces.d.ts +2 -2
- package/dist/services/stream/namespaces.js +2 -2
- package/dist/services/stream/namespaces.js.map +1 -1
- package/dist/services/vector/service.d.ts +11 -11
- package/dist/services/vector/service.d.ts.map +1 -1
- package/dist/services/vector/service.js.map +1 -1
- package/package.json +3 -4
- package/src/env.d.ts +1 -31
- package/src/index.ts +0 -1
- package/src/services/coder/client.ts +34 -0
- package/src/services/coder/protocol.ts +121 -0
- package/src/services/coder/types.ts +94 -1
- package/src/services/coder/workspaces.ts +74 -0
- package/src/services/keyvalue/service.ts +16 -7
- package/src/services/oauth/token-storage.ts +4 -1
- package/src/services/queue/service.ts +31 -33
- package/src/services/sandbox/api-reference.ts +8 -8
- package/src/services/sandbox/client.ts +4 -4
- package/src/services/sandbox/create.ts +10 -0
- package/src/services/sandbox/get.ts +32 -3
- package/src/services/sandbox/getStatus.ts +23 -2
- package/src/services/sandbox/index.ts +1 -1
- package/src/services/sandbox/list.ts +5 -0
- package/src/services/sandbox/pause.ts +38 -4
- package/src/services/sandbox/run.ts +339 -103
- package/src/services/sandbox/types.ts +17 -2
- package/src/services/session/get.ts +0 -2
- package/src/services/stream/namespaces.ts +2 -2
- package/src/services/vector/service.ts +11 -21
- package/dist/deprecation.d.ts +0 -20
- package/dist/deprecation.d.ts.map +0 -1
- package/dist/deprecation.js +0 -102
- package/dist/deprecation.js.map +0 -1
- package/src/deprecation.ts +0 -120
|
@@ -112,9 +112,12 @@ function toStoredToken(token: OAuthTokenResponse): StoredToken {
|
|
|
112
112
|
* @example
|
|
113
113
|
* ```typescript
|
|
114
114
|
* import { KeyValueTokenStorage } from '@agentuity/core/oauth';
|
|
115
|
+
* import { KeyValueClient } from '@agentuity/keyvalue';
|
|
116
|
+
*
|
|
117
|
+
* const kv = new KeyValueClient();
|
|
115
118
|
*
|
|
116
119
|
* // Create storage with auto-refresh enabled
|
|
117
|
-
* const storage = new KeyValueTokenStorage(
|
|
120
|
+
* const storage = new KeyValueTokenStorage(kv, {
|
|
118
121
|
* config: { issuer: 'https://auth.example.com' },
|
|
119
122
|
* });
|
|
120
123
|
*
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Queue service for publishing messages to Agentuity queues.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* the `@agentuity/server` package.
|
|
6
|
+
* Used internally by `@agentuity/queue`'s `QueueClient`. App code should
|
|
7
|
+
* use `QueueClient` directly rather than reaching for these primitives.
|
|
9
8
|
*
|
|
10
|
-
* @example
|
|
9
|
+
* @example
|
|
11
10
|
* ```typescript
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* import { QueueClient } from '@agentuity/queue';
|
|
12
|
+
*
|
|
13
|
+
* const queue = new QueueClient();
|
|
14
|
+
* const result = await queue.publish('order-queue', {
|
|
14
15
|
* orderId: 123,
|
|
15
16
|
* action: 'process',
|
|
16
17
|
* });
|
|
@@ -121,7 +122,7 @@ export type QueuePublishResult = z.infer<typeof QueuePublishResultSchema>;
|
|
|
121
122
|
*
|
|
122
123
|
* @example
|
|
123
124
|
* ```typescript
|
|
124
|
-
* const result = await
|
|
125
|
+
* const result = await queue.createQueue('my-queue', {
|
|
125
126
|
* queueType: 'pubsub',
|
|
126
127
|
* settings: { defaultTtlSeconds: 86400 },
|
|
127
128
|
* });
|
|
@@ -195,25 +196,23 @@ export type QueueCreateResult = z.infer<typeof QueueCreateResultSchema>;
|
|
|
195
196
|
/**
|
|
196
197
|
* Queue service interface for publishing messages.
|
|
197
198
|
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
199
|
+
* Provides a simple publish-only surface suitable for app handlers.
|
|
200
|
+
* Implemented by `QueueStorageService` (cloud) and `LocalQueueStorage`
|
|
201
|
+
* (local dev).
|
|
200
202
|
*
|
|
201
|
-
* For full queue management (create queues, consume messages, manage
|
|
202
|
-
* use the `@agentuity/
|
|
203
|
+
* For full queue management (create queues, consume messages, manage
|
|
204
|
+
* destinations), use the `@agentuity/queue` package directly.
|
|
203
205
|
*
|
|
204
206
|
* @example
|
|
205
207
|
* ```typescript
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* });
|
|
215
|
-
* return { success: true };
|
|
216
|
-
* },
|
|
208
|
+
* import { QueueClient } from '@agentuity/queue';
|
|
209
|
+
*
|
|
210
|
+
* const queue = new QueueClient();
|
|
211
|
+
*
|
|
212
|
+
* await queue.publish('notifications', {
|
|
213
|
+
* type: 'email',
|
|
214
|
+
* to: 'user@example.com',
|
|
215
|
+
* subject: 'Welcome!',
|
|
217
216
|
* });
|
|
218
217
|
* ```
|
|
219
218
|
*/
|
|
@@ -234,12 +233,12 @@ export interface QueueService {
|
|
|
234
233
|
*
|
|
235
234
|
* @example Publishing a simple message
|
|
236
235
|
* ```typescript
|
|
237
|
-
* const result = await
|
|
236
|
+
* const result = await queue.publish('my-queue', 'Hello, World!');
|
|
238
237
|
* ```
|
|
239
238
|
*
|
|
240
239
|
* @example Publishing with options
|
|
241
240
|
* ```typescript
|
|
242
|
-
* const result = await
|
|
241
|
+
* const result = await queue.publish('my-queue', { task: 'process' }, {
|
|
243
242
|
* metadata: { priority: 'high' },
|
|
244
243
|
* idempotencyKey: 'task-123',
|
|
245
244
|
* ttl: 3600,
|
|
@@ -265,12 +264,12 @@ export interface QueueService {
|
|
|
265
264
|
*
|
|
266
265
|
* @example Creating a worker queue
|
|
267
266
|
* ```typescript
|
|
268
|
-
* const result = await
|
|
267
|
+
* const result = await queue.createQueue('task-queue');
|
|
269
268
|
* ```
|
|
270
269
|
*
|
|
271
270
|
* @example Creating a pubsub queue with settings
|
|
272
271
|
* ```typescript
|
|
273
|
-
* const result = await
|
|
272
|
+
* const result = await queue.createQueue('events', {
|
|
274
273
|
* queueType: 'pubsub',
|
|
275
274
|
* settings: { defaultTtlSeconds: 86400 },
|
|
276
275
|
* });
|
|
@@ -290,7 +289,7 @@ export interface QueueService {
|
|
|
290
289
|
*
|
|
291
290
|
* @example Deleting a queue
|
|
292
291
|
* ```typescript
|
|
293
|
-
* await
|
|
292
|
+
* await queue.deleteQueue('old-queue');
|
|
294
293
|
* ```
|
|
295
294
|
*/
|
|
296
295
|
deleteQueue(queueName: string): Promise<void>;
|
|
@@ -322,7 +321,7 @@ export const QueueCreateError = StructuredError('QueueCreateError');
|
|
|
322
321
|
* @example
|
|
323
322
|
* ```typescript
|
|
324
323
|
* try {
|
|
325
|
-
* await
|
|
324
|
+
* await queue.publish('non-existent', 'payload');
|
|
326
325
|
* } catch (error) {
|
|
327
326
|
* if (error instanceof QueueNotFoundError) {
|
|
328
327
|
* console.error('Queue does not exist');
|
|
@@ -429,12 +428,11 @@ function unwrapApiResponse<T>(data: unknown, key: string): T {
|
|
|
429
428
|
// ============================================================================
|
|
430
429
|
|
|
431
430
|
/**
|
|
432
|
-
* HTTP-based implementation of the QueueService interface.
|
|
433
|
-
*
|
|
434
|
-
* This service communicates with the Agentuity Queue API to publish messages.
|
|
435
|
-
* It is automatically configured and available via `ctx.queue` in agent handlers.
|
|
431
|
+
* HTTP-based implementation of the {@link QueueService} interface.
|
|
436
432
|
*
|
|
437
|
-
*
|
|
433
|
+
* This service communicates with the Agentuity Queue API to publish
|
|
434
|
+
* messages. App code should use `QueueClient` from `@agentuity/queue`
|
|
435
|
+
* rather than instantiating this class directly.
|
|
438
436
|
*/
|
|
439
437
|
export class QueueStorageService implements QueueService {
|
|
440
438
|
#adapter: FetchAdapter;
|
|
@@ -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
|
-
// ──
|
|
890
|
+
// ── Sandbox Checkpoints ───────────────────────────────────────────
|
|
891
891
|
{
|
|
892
892
|
id: 'create-checkpoint',
|
|
893
893
|
title: 'Create Checkpoint',
|
|
894
|
-
sectionTitle: '
|
|
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.
|
|
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: '
|
|
926
|
+
sectionTitle: 'Sandbox Checkpoints',
|
|
927
927
|
method: 'GET',
|
|
928
928
|
path: '/sandbox/checkpoints/{sandboxId}',
|
|
929
929
|
description:
|
|
930
|
-
'List checkpoints for a specific sandbox.
|
|
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: '
|
|
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: '
|
|
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<
|
|
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<
|
|
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<
|
|
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
|
|
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
|
|
2
|
+
import { type APIClient } from '../api.ts';
|
|
3
3
|
import { throwSandboxError } from './util.ts';
|
|
4
4
|
|
|
5
|
-
export const PauseResponseSchema =
|
|
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(
|
|
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 });
|