@agentuity/sandbox 3.0.12 → 3.1.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/AGENTS.md +3 -3
- package/dist/api-reference.d.ts +1221 -0
- package/dist/api-reference.d.ts.map +1 -0
- package/dist/api-reference.js +1046 -0
- package/dist/api-reference.js.map +1 -0
- package/dist/base64.d.ts +2 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/base64.js +14 -0
- package/dist/base64.js.map +1 -0
- package/dist/client.d.ts +431 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +632 -0
- package/dist/client.js.map +1 -0
- package/dist/create.d.ts +203 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +235 -0
- package/dist/create.js.map +1 -0
- package/dist/destroy.d.ts +23 -0
- package/dist/destroy.d.ts.map +1 -0
- package/dist/destroy.js +30 -0
- package/dist/destroy.js.map +1 -0
- package/dist/disk-checkpoint.d.ts +108 -0
- package/dist/disk-checkpoint.d.ts.map +1 -0
- package/dist/disk-checkpoint.js +124 -0
- package/dist/disk-checkpoint.js.map +1 -0
- package/dist/events.d.ts +56 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +54 -0
- package/dist/events.js.map +1 -0
- package/dist/execute.d.ts +99 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +138 -0
- package/dist/execute.js.map +1 -0
- package/dist/execution.d.ts +150 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +120 -0
- package/dist/execution.js.map +1 -0
- package/dist/files.d.ts +283 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +471 -0
- package/dist/files.js.map +1 -0
- package/dist/get.d.ts +288 -0
- package/dist/get.d.ts.map +1 -0
- package/dist/get.js +256 -0
- package/dist/get.js.map +1 -0
- package/dist/getStatus.d.ts +23 -0
- package/dist/getStatus.d.ts.map +1 -0
- package/dist/getStatus.js +53 -0
- package/dist/getStatus.js.map +1 -0
- package/dist/index.d.ts +42 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/job.d.ts +227 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +109 -0
- package/dist/job.js.map +1 -0
- package/dist/list.d.ts +330 -0
- package/dist/list.d.ts.map +1 -0
- package/dist/list.js +209 -0
- package/dist/list.js.map +1 -0
- package/dist/pause.d.ts +39 -0
- package/dist/pause.d.ts.map +1 -0
- package/dist/pause.js +48 -0
- package/dist/pause.js.map +1 -0
- package/dist/resolve.d.ts +75 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +76 -0
- package/dist/resolve.js.map +1 -0
- package/dist/resume.d.ts +23 -0
- package/dist/resume.d.ts.map +1 -0
- package/dist/resume.js +30 -0
- package/dist/resume.js.map +1 -0
- package/dist/run.d.ts +73 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +568 -0
- package/dist/run.js.map +1 -0
- package/dist/runtime.d.ts +94 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +82 -0
- package/dist/runtime.js.map +1 -0
- package/dist/snapshot-build.d.ts +48 -0
- package/dist/snapshot-build.d.ts.map +1 -0
- package/dist/snapshot-build.js +72 -0
- package/dist/snapshot-build.js.map +1 -0
- package/dist/snapshot.d.ts +596 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +612 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/types.d.ts +1010 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +853 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +296 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +234 -0
- package/dist/util.js.map +1 -0
- package/package.json +7 -2
- package/src/api-reference.ts +1094 -0
- package/src/base64.ts +14 -0
- package/src/client.ts +998 -0
- package/src/create.ts +273 -0
- package/src/destroy.ts +43 -0
- package/src/disk-checkpoint.ts +184 -0
- package/src/events.ts +72 -0
- package/src/execute.ts +167 -0
- package/src/execution.ts +152 -0
- package/src/files.ts +637 -0
- package/src/get.ts +291 -0
- package/src/getStatus.ts +72 -0
- package/src/index.ts +252 -18
- package/src/job.ts +161 -0
- package/src/list.ts +239 -0
- package/src/pause.ts +75 -0
- package/src/resolve.ts +96 -0
- package/src/resume.ts +41 -0
- package/src/run.ts +783 -0
- package/src/runtime.ts +106 -0
- package/src/snapshot-build.ts +94 -0
- package/src/snapshot.ts +791 -0
- package/src/types.ts +1033 -0
- package/src/util.ts +280 -0
package/src/create.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type { SandboxCreateOptions } from './types.ts';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type APIClient, APIResponseSchema } from '@agentuity/api';
|
|
4
|
+
import { NPM_PACKAGE_NAME_PATTERN } from './snapshot-build.ts';
|
|
5
|
+
import { throwSandboxError } from './util.ts';
|
|
6
|
+
import { base64Encode } from './base64.ts';
|
|
7
|
+
|
|
8
|
+
export const SandboxCreateRequestSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
projectId: z.string().optional().describe('Project ID to associate the sandbox with'),
|
|
11
|
+
runtime: z.string().optional().describe('Runtime name (e.g., "bun:1", "python:3.14")'),
|
|
12
|
+
runtimeId: z.string().optional().describe('Runtime ID (e.g., "srt_xxx")'),
|
|
13
|
+
name: z.string().optional().describe('Optional sandbox name'),
|
|
14
|
+
description: z.string().optional().describe('Optional sandbox description'),
|
|
15
|
+
resources: z
|
|
16
|
+
.object({
|
|
17
|
+
memory: z.string().optional().describe('Memory limit (e.g., "512Mi", "1Gi")'),
|
|
18
|
+
cpu: z.string().optional().describe('CPU limit (e.g., "0.5", "1")'),
|
|
19
|
+
disk: z.string().optional().describe('Disk size limit (e.g., "1Gi", "10Gi")'),
|
|
20
|
+
})
|
|
21
|
+
.optional()
|
|
22
|
+
.describe('Resource constraints for the sandbox'),
|
|
23
|
+
env: z
|
|
24
|
+
.record(z.string(), z.string())
|
|
25
|
+
.optional()
|
|
26
|
+
.describe('Environment variables to set in the sandbox'),
|
|
27
|
+
network: z
|
|
28
|
+
.object({
|
|
29
|
+
enabled: z.boolean().optional().describe('Whether network access is enabled'),
|
|
30
|
+
port: z
|
|
31
|
+
.number()
|
|
32
|
+
.int()
|
|
33
|
+
.min(1024)
|
|
34
|
+
.max(65535)
|
|
35
|
+
.optional()
|
|
36
|
+
.describe('Port to expose from the sandbox (1024-65535)'),
|
|
37
|
+
})
|
|
38
|
+
.optional()
|
|
39
|
+
.describe('Network configuration for the sandbox'),
|
|
40
|
+
stream: z
|
|
41
|
+
.object({
|
|
42
|
+
stdout: z.string().optional().describe('Stream ID for stdout output'),
|
|
43
|
+
stderr: z.string().optional().describe('Stream ID for stderr output'),
|
|
44
|
+
stdin: z.string().optional().describe('Stream ID for stdin input'),
|
|
45
|
+
timestamps: z.boolean().optional().describe('Whether to include timestamps in output'),
|
|
46
|
+
})
|
|
47
|
+
.optional()
|
|
48
|
+
.describe('Stream configuration for I/O redirection'),
|
|
49
|
+
timeout: z
|
|
50
|
+
.object({
|
|
51
|
+
idle: z.string().optional().describe('Idle timeout duration (e.g., "5m", "1h")'),
|
|
52
|
+
execution: z.string().optional().describe('Maximum execution time (e.g., "30m", "2h")'),
|
|
53
|
+
paused: z
|
|
54
|
+
.string()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe(
|
|
57
|
+
'Maximum time sandbox can remain paused before termination (e.g., "24h", "0s" for infinite)'
|
|
58
|
+
),
|
|
59
|
+
})
|
|
60
|
+
.optional()
|
|
61
|
+
.describe('Timeout settings for the sandbox'),
|
|
62
|
+
command: z
|
|
63
|
+
.object({
|
|
64
|
+
exec: z.array(z.string()).describe('Command and arguments to execute'),
|
|
65
|
+
files: z
|
|
66
|
+
.array(
|
|
67
|
+
z.object({
|
|
68
|
+
path: z
|
|
69
|
+
.string()
|
|
70
|
+
.describe('Path to the file relative to the sandbox workspace'),
|
|
71
|
+
content: z.string().describe('Base64-encoded file content'),
|
|
72
|
+
})
|
|
73
|
+
)
|
|
74
|
+
.optional()
|
|
75
|
+
.describe('Files to write before execution (deprecated: use top-level files)'),
|
|
76
|
+
mode: z
|
|
77
|
+
.enum(['oneshot', 'interactive'])
|
|
78
|
+
.optional()
|
|
79
|
+
.describe('Execution mode: oneshot runs once, interactive keeps running'),
|
|
80
|
+
})
|
|
81
|
+
.optional()
|
|
82
|
+
.describe('Initial command to run in the sandbox'),
|
|
83
|
+
files: z
|
|
84
|
+
.array(
|
|
85
|
+
z.object({
|
|
86
|
+
path: z.string().describe('Path to the file relative to the sandbox workspace'),
|
|
87
|
+
content: z.string().describe('Base64-encoded file content'),
|
|
88
|
+
})
|
|
89
|
+
)
|
|
90
|
+
.optional()
|
|
91
|
+
.describe('Files to write to sandbox on creation'),
|
|
92
|
+
snapshot: z.string().optional().describe('Snapshot ID to restore the sandbox from'),
|
|
93
|
+
dependencies: z
|
|
94
|
+
.array(z.string())
|
|
95
|
+
.optional()
|
|
96
|
+
.describe('Apt packages to install when creating the sandbox'),
|
|
97
|
+
packages: z
|
|
98
|
+
.array(
|
|
99
|
+
z
|
|
100
|
+
.string()
|
|
101
|
+
.regex(
|
|
102
|
+
NPM_PACKAGE_NAME_PATTERN,
|
|
103
|
+
'Invalid npm/bun package specifier: must not contain whitespace, semicolons, backticks, pipes, or dollar signs'
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
.optional()
|
|
107
|
+
.describe('npm/bun packages to install globally when creating the sandbox'),
|
|
108
|
+
metadata: z
|
|
109
|
+
.record(z.string(), z.unknown())
|
|
110
|
+
.optional()
|
|
111
|
+
.describe('Optional user-defined metadata to associate with the sandbox'),
|
|
112
|
+
scopes: z
|
|
113
|
+
.array(z.string())
|
|
114
|
+
.optional()
|
|
115
|
+
.describe(
|
|
116
|
+
'Permission scopes for automatic service access (e.g., "services:read", "services:write").'
|
|
117
|
+
),
|
|
118
|
+
})
|
|
119
|
+
.refine(
|
|
120
|
+
(data) => {
|
|
121
|
+
// If snapshot is provided, runtime and runtimeId must not be provided
|
|
122
|
+
if (data.snapshot) {
|
|
123
|
+
return !data.runtime && !data.runtimeId;
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
message: 'cannot specify both snapshot and runtime; snapshot includes its own runtime',
|
|
129
|
+
path: ['snapshot'],
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
.describe('Request body for creating a new sandbox');
|
|
133
|
+
|
|
134
|
+
export const SandboxCreateDataSchema = z
|
|
135
|
+
.object({
|
|
136
|
+
sandboxId: z.string().describe('Unique identifier for the created sandbox'),
|
|
137
|
+
status: z
|
|
138
|
+
.enum([
|
|
139
|
+
'creating',
|
|
140
|
+
'idle',
|
|
141
|
+
'running',
|
|
142
|
+
'paused',
|
|
143
|
+
'stopping',
|
|
144
|
+
'suspended',
|
|
145
|
+
'terminated',
|
|
146
|
+
'failed',
|
|
147
|
+
])
|
|
148
|
+
.describe('Current status of the sandbox'),
|
|
149
|
+
executionId: z
|
|
150
|
+
.string()
|
|
151
|
+
.optional()
|
|
152
|
+
.describe('Initial execution identifier for oneshot sandbox creation'),
|
|
153
|
+
url: z
|
|
154
|
+
.string()
|
|
155
|
+
.optional()
|
|
156
|
+
.describe('Public URL for the sandbox (only set when a network port is configured)'),
|
|
157
|
+
stdoutStreamId: z.string().optional().describe('Stream ID for reading stdout'),
|
|
158
|
+
stdoutStreamUrl: z.string().optional().describe('URL for streaming stdout output'),
|
|
159
|
+
stderrStreamId: z.string().optional().describe('Stream ID for reading stderr'),
|
|
160
|
+
stderrStreamUrl: z.string().optional().describe('URL for streaming stderr output'),
|
|
161
|
+
auditStreamId: z.string().optional().describe('Stream ID for reading audit events'),
|
|
162
|
+
auditStreamUrl: z.string().optional().describe('URL for streaming audit events'),
|
|
163
|
+
})
|
|
164
|
+
.describe('Response data from sandbox creation');
|
|
165
|
+
|
|
166
|
+
export const SandboxCreateResponseSchema = APIResponseSchema(SandboxCreateDataSchema);
|
|
167
|
+
|
|
168
|
+
export type SandboxCreateResponse = z.infer<typeof SandboxCreateDataSchema>;
|
|
169
|
+
|
|
170
|
+
export const SandboxCreateParamsSchema = z.object({
|
|
171
|
+
options: z.custom<SandboxCreateOptions>().optional().describe('Optional sandbox create options'),
|
|
172
|
+
orgId: z.string().optional().describe('Optional org id for CLI auth context'),
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
export type SandboxCreateParams = z.infer<typeof SandboxCreateParamsSchema>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Creates a new sandbox instance.
|
|
179
|
+
*
|
|
180
|
+
* @param client - The API client to use for the request
|
|
181
|
+
* @param params - Parameters for creating the sandbox
|
|
182
|
+
* @returns The created sandbox response including sandbox ID and stream URLs
|
|
183
|
+
* @throws {SandboxResponseError} If the sandbox creation fails
|
|
184
|
+
*/
|
|
185
|
+
export async function sandboxCreate(
|
|
186
|
+
client: APIClient,
|
|
187
|
+
params: SandboxCreateParams = {}
|
|
188
|
+
): Promise<SandboxCreateResponse> {
|
|
189
|
+
const { options = {}, orgId } = params;
|
|
190
|
+
const body: z.infer<typeof SandboxCreateRequestSchema> = {};
|
|
191
|
+
|
|
192
|
+
if (options.projectId) {
|
|
193
|
+
body.projectId = options.projectId;
|
|
194
|
+
}
|
|
195
|
+
if (options.runtime) {
|
|
196
|
+
body.runtime = options.runtime;
|
|
197
|
+
}
|
|
198
|
+
if (options.runtimeId) {
|
|
199
|
+
body.runtimeId = options.runtimeId;
|
|
200
|
+
}
|
|
201
|
+
if (options.name) {
|
|
202
|
+
body.name = options.name;
|
|
203
|
+
}
|
|
204
|
+
if (options.description) {
|
|
205
|
+
body.description = options.description;
|
|
206
|
+
}
|
|
207
|
+
if (options.resources) {
|
|
208
|
+
body.resources = options.resources;
|
|
209
|
+
}
|
|
210
|
+
if (options.env) {
|
|
211
|
+
body.env = options.env;
|
|
212
|
+
}
|
|
213
|
+
if (options.network) {
|
|
214
|
+
body.network = options.network;
|
|
215
|
+
}
|
|
216
|
+
if (options.stream) {
|
|
217
|
+
body.stream = options.stream;
|
|
218
|
+
}
|
|
219
|
+
if (options.timeout) {
|
|
220
|
+
body.timeout = options.timeout;
|
|
221
|
+
}
|
|
222
|
+
if (options.command) {
|
|
223
|
+
body.command = {
|
|
224
|
+
exec: options.command.exec,
|
|
225
|
+
mode: options.command.mode,
|
|
226
|
+
files: options.command.files?.map((f) => ({
|
|
227
|
+
path: f.path,
|
|
228
|
+
content: base64Encode(f.content),
|
|
229
|
+
})),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (options.files && options.files.length > 0) {
|
|
233
|
+
body.files = options.files.map((f) => ({
|
|
234
|
+
path: f.path,
|
|
235
|
+
content: base64Encode(f.content),
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
if (options.snapshot) {
|
|
239
|
+
body.snapshot = options.snapshot;
|
|
240
|
+
}
|
|
241
|
+
if (options.dependencies && options.dependencies.length > 0) {
|
|
242
|
+
body.dependencies = options.dependencies;
|
|
243
|
+
}
|
|
244
|
+
if (options.packages && options.packages.length > 0) {
|
|
245
|
+
body.packages = options.packages;
|
|
246
|
+
}
|
|
247
|
+
if (options.metadata) {
|
|
248
|
+
body.metadata = options.metadata;
|
|
249
|
+
}
|
|
250
|
+
if (options.scopes && options.scopes.length > 0) {
|
|
251
|
+
body.scopes = options.scopes;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const queryParams = new URLSearchParams();
|
|
255
|
+
if (orgId) {
|
|
256
|
+
queryParams.set('orgId', orgId);
|
|
257
|
+
}
|
|
258
|
+
const queryString = queryParams.toString();
|
|
259
|
+
const url = `/sandbox${queryString ? `?${queryString}` : ''}`;
|
|
260
|
+
|
|
261
|
+
const resp = await client.post<z.infer<typeof SandboxCreateResponseSchema>>(
|
|
262
|
+
url,
|
|
263
|
+
body,
|
|
264
|
+
SandboxCreateResponseSchema,
|
|
265
|
+
SandboxCreateRequestSchema
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
if (resp.success) {
|
|
269
|
+
return resp.data;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
throwSandboxError(resp, {});
|
|
273
|
+
}
|
package/src/destroy.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type APIClient, APIResponseSchemaNoData } from '@agentuity/api';
|
|
3
|
+
import { throwSandboxError } from './util.ts';
|
|
4
|
+
|
|
5
|
+
export const DestroyResponseSchema = APIResponseSchemaNoData();
|
|
6
|
+
|
|
7
|
+
export const SandboxDestroyParamsSchema = z.object({
|
|
8
|
+
sandboxId: z.string().describe('Sandbox ID to destroy'),
|
|
9
|
+
orgId: z.string().optional().describe('Optional org id for CLI auth context'),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type SandboxDestroyParams = z.infer<typeof SandboxDestroyParamsSchema>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Destroys a sandbox and releases all associated resources.
|
|
16
|
+
*
|
|
17
|
+
* @param client - The API client to use for the request
|
|
18
|
+
* @param params - Parameters including the sandbox ID to destroy
|
|
19
|
+
* @throws {SandboxResponseError} If the sandbox is not found or destruction fails
|
|
20
|
+
*/
|
|
21
|
+
export async function sandboxDestroy(
|
|
22
|
+
client: APIClient,
|
|
23
|
+
params: SandboxDestroyParams
|
|
24
|
+
): Promise<void> {
|
|
25
|
+
const { sandboxId, orgId } = params;
|
|
26
|
+
const queryParams = new URLSearchParams();
|
|
27
|
+
if (orgId) {
|
|
28
|
+
queryParams.set('orgId', orgId);
|
|
29
|
+
}
|
|
30
|
+
const queryString = queryParams.toString();
|
|
31
|
+
const url = `/sandbox/${sandboxId}${queryString ? `?${queryString}` : ''}`;
|
|
32
|
+
|
|
33
|
+
const resp = await client.delete<z.infer<typeof DestroyResponseSchema>>(
|
|
34
|
+
url,
|
|
35
|
+
DestroyResponseSchema
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (resp.success) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throwSandboxError(resp, { sandboxId });
|
|
43
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type { z as zType } from 'zod';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { type APIClient, APIResponseSchema, APIResponseSchemaNoData } from '@agentuity/api';
|
|
4
|
+
import { throwSandboxError } from './util.ts';
|
|
5
|
+
|
|
6
|
+
// --- Schemas ---
|
|
7
|
+
|
|
8
|
+
export const DiskCheckpointInfoSchema = z.object({
|
|
9
|
+
id: z.string().describe('Globally unique checkpoint ID (ckpt_xxx)'),
|
|
10
|
+
name: z.string().describe('User-provided checkpoint name'),
|
|
11
|
+
createdAt: z.string().describe('ISO timestamp of creation'),
|
|
12
|
+
parent: z.string().describe('Parent checkpoint name (empty for base)'),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export type DiskCheckpointInfo = z.infer<typeof DiskCheckpointInfoSchema>;
|
|
16
|
+
|
|
17
|
+
const CreateDiskCheckpointDataSchema = DiskCheckpointInfoSchema;
|
|
18
|
+
export const CreateDiskCheckpointResponseSchema = APIResponseSchema(CreateDiskCheckpointDataSchema);
|
|
19
|
+
|
|
20
|
+
const ListDiskCheckpointsDataSchema = z.object({
|
|
21
|
+
checkpoints: z.array(DiskCheckpointInfoSchema),
|
|
22
|
+
});
|
|
23
|
+
export const ListDiskCheckpointsResponseSchema = APIResponseSchema(ListDiskCheckpointsDataSchema);
|
|
24
|
+
|
|
25
|
+
export const RestoreDiskCheckpointResponseSchema = APIResponseSchemaNoData();
|
|
26
|
+
export const DeleteDiskCheckpointResponseSchema = APIResponseSchemaNoData();
|
|
27
|
+
|
|
28
|
+
// --- Params ---
|
|
29
|
+
|
|
30
|
+
export const DiskCheckpointCreateParamsSchema = z.object({
|
|
31
|
+
sandboxId: z.string().describe('Sandbox ID for checkpoint creation'),
|
|
32
|
+
name: z.string().describe('Name to assign to the new checkpoint'),
|
|
33
|
+
orgId: z.string().optional().describe('Optional org id for CLI auth context'),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const DiskCheckpointListParamsSchema = z.object({
|
|
37
|
+
sandboxId: z.string().describe('Sandbox ID to list checkpoints for'),
|
|
38
|
+
orgId: z.string().optional().describe('Optional org id for CLI auth context'),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const DiskCheckpointRestoreParamsSchema = z.object({
|
|
42
|
+
sandboxId: z.string().describe('Sandbox ID to restore'),
|
|
43
|
+
checkpointId: z.string().describe('Checkpoint ID to restore from'),
|
|
44
|
+
orgId: z.string().optional().describe('Optional org id for CLI auth context'),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const DiskCheckpointDeleteParamsSchema = z.object({
|
|
48
|
+
sandboxId: z.string().describe('Sandbox ID containing the checkpoint'),
|
|
49
|
+
checkpointId: z.string().describe('Checkpoint ID to delete'),
|
|
50
|
+
orgId: z.string().optional().describe('Optional org id for CLI auth context'),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export type DiskCheckpointCreateParams = z.infer<typeof DiskCheckpointCreateParamsSchema>;
|
|
54
|
+
export type DiskCheckpointListParams = z.infer<typeof DiskCheckpointListParamsSchema>;
|
|
55
|
+
export type DiskCheckpointRestoreParams = z.infer<typeof DiskCheckpointRestoreParamsSchema>;
|
|
56
|
+
export type DiskCheckpointDeleteParams = z.infer<typeof DiskCheckpointDeleteParamsSchema>;
|
|
57
|
+
|
|
58
|
+
// --- API Functions ---
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new disk checkpoint for a sandbox.
|
|
62
|
+
*
|
|
63
|
+
* @param client - The API client to use for the request
|
|
64
|
+
* @param params - Parameters including the sandbox ID and checkpoint name
|
|
65
|
+
* @throws {SandboxResponseError} If the sandbox is not found or checkpoint creation fails
|
|
66
|
+
*/
|
|
67
|
+
export async function diskCheckpointCreate(
|
|
68
|
+
client: APIClient,
|
|
69
|
+
params: DiskCheckpointCreateParams
|
|
70
|
+
): Promise<DiskCheckpointInfo> {
|
|
71
|
+
const { sandboxId, name, orgId } = params;
|
|
72
|
+
const queryParams = new URLSearchParams();
|
|
73
|
+
if (orgId) {
|
|
74
|
+
queryParams.set('orgId', orgId);
|
|
75
|
+
}
|
|
76
|
+
const queryString = queryParams.toString();
|
|
77
|
+
const url = `/sandbox/${encodeURIComponent(sandboxId)}/checkpoint${queryString ? `?${queryString}` : ''}`;
|
|
78
|
+
|
|
79
|
+
const resp = await client.post<zType.infer<typeof CreateDiskCheckpointResponseSchema>>(
|
|
80
|
+
url,
|
|
81
|
+
{ name },
|
|
82
|
+
CreateDiskCheckpointResponseSchema
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (resp.success) {
|
|
86
|
+
return resp.data;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
throwSandboxError(resp, { sandboxId });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Lists all disk checkpoints for a sandbox.
|
|
94
|
+
*
|
|
95
|
+
* @param client - The API client to use for the request
|
|
96
|
+
* @param params - Parameters including the sandbox ID
|
|
97
|
+
* @throws {SandboxResponseError} If the sandbox is not found or listing fails
|
|
98
|
+
*/
|
|
99
|
+
export async function diskCheckpointList(
|
|
100
|
+
client: APIClient,
|
|
101
|
+
params: DiskCheckpointListParams
|
|
102
|
+
): Promise<DiskCheckpointInfo[]> {
|
|
103
|
+
const { sandboxId, orgId } = params;
|
|
104
|
+
const queryParams = new URLSearchParams();
|
|
105
|
+
if (orgId) {
|
|
106
|
+
queryParams.set('orgId', orgId);
|
|
107
|
+
}
|
|
108
|
+
const queryString = queryParams.toString();
|
|
109
|
+
const url = `/sandbox/checkpoints/${encodeURIComponent(sandboxId)}${queryString ? `?${queryString}` : ''}`;
|
|
110
|
+
|
|
111
|
+
const resp = await client.get<zType.infer<typeof ListDiskCheckpointsResponseSchema>>(
|
|
112
|
+
url,
|
|
113
|
+
ListDiskCheckpointsResponseSchema
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
if (resp.success) {
|
|
117
|
+
return resp.data.checkpoints;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
throwSandboxError(resp, { sandboxId });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Restores a sandbox to a specific disk checkpoint.
|
|
125
|
+
*
|
|
126
|
+
* @param client - The API client to use for the request
|
|
127
|
+
* @param params - Parameters including the sandbox ID and checkpoint ID
|
|
128
|
+
* @throws {SandboxResponseError} If the sandbox or checkpoint is not found, or restore fails
|
|
129
|
+
*/
|
|
130
|
+
export async function diskCheckpointRestore(
|
|
131
|
+
client: APIClient,
|
|
132
|
+
params: DiskCheckpointRestoreParams
|
|
133
|
+
): Promise<void> {
|
|
134
|
+
const { sandboxId, checkpointId, orgId } = params;
|
|
135
|
+
const queryParams = new URLSearchParams();
|
|
136
|
+
if (orgId) {
|
|
137
|
+
queryParams.set('orgId', orgId);
|
|
138
|
+
}
|
|
139
|
+
const queryString = queryParams.toString();
|
|
140
|
+
const url = `/sandbox/${encodeURIComponent(sandboxId)}/checkpoint/${encodeURIComponent(checkpointId)}/restore${queryString ? `?${queryString}` : ''}`;
|
|
141
|
+
|
|
142
|
+
const resp = await client.post<zType.infer<typeof RestoreDiskCheckpointResponseSchema>>(
|
|
143
|
+
url,
|
|
144
|
+
undefined,
|
|
145
|
+
RestoreDiskCheckpointResponseSchema
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (resp.success) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
throwSandboxError(resp, { sandboxId });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Deletes a disk checkpoint from a sandbox.
|
|
157
|
+
*
|
|
158
|
+
* @param client - The API client to use for the request
|
|
159
|
+
* @param params - Parameters including the sandbox ID and checkpoint ID
|
|
160
|
+
* @throws {SandboxResponseError} If the sandbox or checkpoint is not found, or deletion fails
|
|
161
|
+
*/
|
|
162
|
+
export async function diskCheckpointDelete(
|
|
163
|
+
client: APIClient,
|
|
164
|
+
params: DiskCheckpointDeleteParams
|
|
165
|
+
): Promise<void> {
|
|
166
|
+
const { sandboxId, checkpointId, orgId } = params;
|
|
167
|
+
const queryParams = new URLSearchParams();
|
|
168
|
+
if (orgId) {
|
|
169
|
+
queryParams.set('orgId', orgId);
|
|
170
|
+
}
|
|
171
|
+
const queryString = queryParams.toString();
|
|
172
|
+
const url = `/sandbox/${encodeURIComponent(sandboxId)}/checkpoint/${encodeURIComponent(checkpointId)}${queryString ? `?${queryString}` : ''}`;
|
|
173
|
+
|
|
174
|
+
const resp = await client.delete<zType.infer<typeof DeleteDiskCheckpointResponseSchema>>(
|
|
175
|
+
url,
|
|
176
|
+
DeleteDiskCheckpointResponseSchema
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
if (resp.success) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
throwSandboxError(resp, { sandboxId });
|
|
184
|
+
}
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type APIClient, APIResponseSchema } from '@agentuity/api';
|
|
3
|
+
import { SortDirectionSchema } from '@agentuity/client';
|
|
4
|
+
import { throwSandboxError } from './util.ts';
|
|
5
|
+
|
|
6
|
+
export const SandboxEventInfoSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
eventId: z.string().describe('Unique identifier for the event'),
|
|
9
|
+
sandboxId: z.string().describe('ID of the sandbox this event belongs to'),
|
|
10
|
+
type: z.string().describe('Type of event (e.g., create, destroy, lifecycle:started)'),
|
|
11
|
+
event: z.record(z.string(), z.unknown()).describe('Event data payload'),
|
|
12
|
+
createdAt: z.string().describe('ISO timestamp when the event was recorded'),
|
|
13
|
+
})
|
|
14
|
+
.describe('Information about a sandbox event');
|
|
15
|
+
|
|
16
|
+
export const SandboxEventListDataSchema = z
|
|
17
|
+
.object({
|
|
18
|
+
events: z.array(SandboxEventInfoSchema).describe('List of sandbox events'),
|
|
19
|
+
})
|
|
20
|
+
.describe('List of events for a sandbox');
|
|
21
|
+
|
|
22
|
+
export const SandboxEventListResponseSchema = APIResponseSchema(SandboxEventListDataSchema);
|
|
23
|
+
|
|
24
|
+
export type SandboxEventInfo = z.infer<typeof SandboxEventInfoSchema>;
|
|
25
|
+
|
|
26
|
+
export const SandboxEventListParamsSchema = z.object({
|
|
27
|
+
sandboxId: z.string().describe('sandbox id'),
|
|
28
|
+
orgId: z.string().optional().describe('organization id'),
|
|
29
|
+
limit: z.number().optional().describe('limit'),
|
|
30
|
+
direction: SortDirectionSchema.optional().describe('sort direction (default: asc)'),
|
|
31
|
+
});
|
|
32
|
+
export type SandboxEventListParams = z.infer<typeof SandboxEventListParamsSchema>;
|
|
33
|
+
|
|
34
|
+
export type SandboxEventListResponse = z.infer<typeof SandboxEventListDataSchema>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Lists all events for a specific sandbox, ordered by creation time (oldest first by default).
|
|
38
|
+
*
|
|
39
|
+
* @param client - The API client to use for the request
|
|
40
|
+
* @param params - Parameters including the sandbox ID, optional limit, and sort direction
|
|
41
|
+
* @returns List of event information for the sandbox
|
|
42
|
+
* @throws {SandboxResponseError} If the sandbox is not found or request fails
|
|
43
|
+
*/
|
|
44
|
+
export async function sandboxEventList(
|
|
45
|
+
client: APIClient,
|
|
46
|
+
params: SandboxEventListParams
|
|
47
|
+
): Promise<SandboxEventListResponse> {
|
|
48
|
+
const { sandboxId, orgId, limit, direction } = params;
|
|
49
|
+
const queryParams = new URLSearchParams();
|
|
50
|
+
if (orgId) {
|
|
51
|
+
queryParams.set('orgId', orgId);
|
|
52
|
+
}
|
|
53
|
+
if (limit !== undefined) {
|
|
54
|
+
queryParams.set('limit', String(limit));
|
|
55
|
+
}
|
|
56
|
+
if (direction) {
|
|
57
|
+
queryParams.set('direction', direction);
|
|
58
|
+
}
|
|
59
|
+
const queryString = queryParams.toString();
|
|
60
|
+
const url = `/sandbox/sandboxes/${sandboxId}/events${queryString ? `?${queryString}` : ''}`;
|
|
61
|
+
|
|
62
|
+
const resp = await client.get<z.infer<typeof SandboxEventListResponseSchema>>(
|
|
63
|
+
url,
|
|
64
|
+
SandboxEventListResponseSchema
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
if (resp.success) {
|
|
68
|
+
return resp.data;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
throwSandboxError(resp, { sandboxId });
|
|
72
|
+
}
|