@agentuity/server 0.1.22 → 0.1.24
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/dist/api/api.d.ts +3 -0
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js +3 -0
- package/dist/api/api.js.map +1 -1
- package/dist/api/apikey/list.d.ts +1 -0
- package/dist/api/apikey/list.d.ts.map +1 -1
- package/dist/api/eval/get.d.ts +18 -0
- package/dist/api/eval/get.d.ts.map +1 -0
- package/dist/api/eval/get.js +23 -0
- package/dist/api/eval/get.js.map +1 -0
- package/dist/api/eval/index.d.ts +5 -0
- package/dist/api/eval/index.d.ts.map +1 -0
- package/dist/api/eval/index.js +5 -0
- package/dist/api/eval/index.js.map +1 -0
- package/dist/api/eval/list.d.ts +21 -0
- package/dist/api/eval/list.d.ts.map +1 -0
- package/dist/api/eval/list.js +30 -0
- package/dist/api/eval/list.js.map +1 -0
- package/dist/api/eval/run-get.d.ts +24 -0
- package/dist/api/eval/run-get.d.ts.map +1 -0
- package/dist/api/eval/run-get.js +29 -0
- package/dist/api/eval/run-get.js.map +1 -0
- package/dist/api/eval/run-list.d.ts +29 -0
- package/dist/api/eval/run-list.d.ts.map +1 -0
- package/dist/api/eval/run-list.js +40 -0
- package/dist/api/eval/run-list.js.map +1 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/machine/machine.d.ts +3 -1
- package/dist/api/machine/machine.d.ts.map +1 -1
- package/dist/api/machine/machine.js +6 -5
- package/dist/api/machine/machine.js.map +1 -1
- package/dist/api/org/list.d.ts +1 -0
- package/dist/api/org/list.d.ts.map +1 -1
- package/dist/api/org/resources.d.ts +1 -0
- package/dist/api/org/resources.d.ts.map +1 -1
- package/dist/api/project/create.d.ts +1 -0
- package/dist/api/project/create.d.ts.map +1 -1
- package/dist/api/project/exists.d.ts +1 -0
- package/dist/api/project/exists.d.ts.map +1 -1
- package/dist/api/project/list.d.ts +1 -0
- package/dist/api/project/list.d.ts.map +1 -1
- package/dist/api/queue/types.d.ts +4 -3
- package/dist/api/queue/types.d.ts.map +1 -1
- package/dist/api/queue/types.js +8 -6
- package/dist/api/queue/types.js.map +1 -1
- package/dist/api/region/create.d.ts +1 -0
- package/dist/api/region/create.d.ts.map +1 -1
- package/dist/api/region/delete.d.ts +1 -0
- package/dist/api/region/delete.d.ts.map +1 -1
- package/dist/api/region/list.d.ts +1 -0
- package/dist/api/region/list.d.ts.map +1 -1
- package/dist/api/region/resources.d.ts +1 -0
- package/dist/api/region/resources.d.ts.map +1 -1
- package/dist/api/sandbox/client.d.ts +8 -0
- package/dist/api/sandbox/client.d.ts.map +1 -1
- package/dist/api/sandbox/client.js +20 -6
- package/dist/api/sandbox/client.js.map +1 -1
- package/dist/api/sandbox/create.d.ts.map +1 -1
- package/dist/api/sandbox/create.js +10 -3
- package/dist/api/sandbox/create.js.map +1 -1
- package/dist/api/sandbox/destroy.js +2 -2
- package/dist/api/sandbox/destroy.js.map +1 -1
- package/dist/api/sandbox/execute.d.ts.map +1 -1
- package/dist/api/sandbox/execute.js +8 -9
- package/dist/api/sandbox/execute.js.map +1 -1
- package/dist/api/sandbox/execution.js +3 -3
- package/dist/api/sandbox/execution.js.map +1 -1
- package/dist/api/sandbox/files.js +8 -8
- package/dist/api/sandbox/files.js.map +1 -1
- package/dist/api/sandbox/get.d.ts.map +1 -1
- package/dist/api/sandbox/get.js +2 -2
- package/dist/api/sandbox/get.js.map +1 -1
- package/dist/api/sandbox/index.d.ts +2 -1
- package/dist/api/sandbox/index.d.ts.map +1 -1
- package/dist/api/sandbox/index.js +1 -1
- package/dist/api/sandbox/index.js.map +1 -1
- package/dist/api/sandbox/list.d.ts.map +1 -1
- package/dist/api/sandbox/list.js +2 -2
- package/dist/api/sandbox/list.js.map +1 -1
- package/dist/api/sandbox/run.js +3 -3
- package/dist/api/sandbox/run.js.map +1 -1
- package/dist/api/sandbox/runtime.js +2 -2
- package/dist/api/sandbox/runtime.js.map +1 -1
- package/dist/api/sandbox/snapshot.d.ts.map +1 -1
- package/dist/api/sandbox/snapshot.js +11 -11
- package/dist/api/sandbox/snapshot.js.map +1 -1
- package/dist/api/sandbox/util.d.ts +205 -0
- package/dist/api/sandbox/util.d.ts.map +1 -1
- package/dist/api/sandbox/util.js +131 -0
- package/dist/api/sandbox/util.js.map +1 -1
- package/dist/api/session/list.d.ts +1 -0
- package/dist/api/session/list.d.ts.map +1 -1
- package/dist/api/thread/list.d.ts +1 -0
- package/dist/api/thread/list.d.ts.map +1 -1
- package/dist/api/user/whoami.d.ts +1 -0
- package/dist/api/user/whoami.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/api.ts +3 -0
- package/src/api/eval/get.ts +33 -0
- package/src/api/eval/index.ts +4 -0
- package/src/api/eval/list.ts +47 -0
- package/src/api/eval/run-get.ts +39 -0
- package/src/api/eval/run-list.ts +57 -0
- package/src/api/index.ts +1 -0
- package/src/api/machine/machine.ts +7 -6
- package/src/api/queue/types.ts +8 -6
- package/src/api/sandbox/client.ts +43 -6
- package/src/api/sandbox/create.ts +12 -3
- package/src/api/sandbox/destroy.ts +2 -2
- package/src/api/sandbox/execute.ts +10 -9
- package/src/api/sandbox/execution.ts +3 -3
- package/src/api/sandbox/files.ts +8 -8
- package/src/api/sandbox/get.ts +5 -3
- package/src/api/sandbox/index.ts +12 -1
- package/src/api/sandbox/list.ts +5 -3
- package/src/api/sandbox/run.ts +3 -3
- package/src/api/sandbox/runtime.ts +2 -2
- package/src/api/sandbox/snapshot.ts +15 -15
- package/src/api/sandbox/util.ts +180 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { APIClient, APIResponseSchema, APIResponseSchemaNoData } from '../api';
|
|
3
|
-
import { SandboxResponseError, API_VERSION } from './util';
|
|
3
|
+
import { SandboxResponseError, throwSandboxError, API_VERSION } from './util';
|
|
4
4
|
|
|
5
5
|
const SnapshotFileInfoSchema = z
|
|
6
6
|
.object({
|
|
@@ -186,7 +186,9 @@ const _SnapshotLineageParamsSchema = z
|
|
|
186
186
|
snapshot: z
|
|
187
187
|
.string()
|
|
188
188
|
.optional()
|
|
189
|
-
.describe(
|
|
189
|
+
.describe(
|
|
190
|
+
'Snapshot ID or name:tag to start lineage from (e.g., "sss_xxx" or "myimage:v1")'
|
|
191
|
+
),
|
|
190
192
|
name: z
|
|
191
193
|
.string()
|
|
192
194
|
.optional()
|
|
@@ -258,7 +260,7 @@ export async function snapshotCreate(
|
|
|
258
260
|
return resp.data;
|
|
259
261
|
}
|
|
260
262
|
|
|
261
|
-
|
|
263
|
+
throwSandboxError(resp, {});
|
|
262
264
|
}
|
|
263
265
|
|
|
264
266
|
/**
|
|
@@ -286,7 +288,7 @@ export async function snapshotGet(
|
|
|
286
288
|
return resp.data;
|
|
287
289
|
}
|
|
288
290
|
|
|
289
|
-
|
|
291
|
+
throwSandboxError(resp, {});
|
|
290
292
|
}
|
|
291
293
|
|
|
292
294
|
/**
|
|
@@ -314,7 +316,7 @@ export async function snapshotList(
|
|
|
314
316
|
return resp.data;
|
|
315
317
|
}
|
|
316
318
|
|
|
317
|
-
|
|
319
|
+
throwSandboxError(resp, {});
|
|
318
320
|
}
|
|
319
321
|
|
|
320
322
|
/**
|
|
@@ -338,7 +340,7 @@ export async function snapshotDelete(
|
|
|
338
340
|
);
|
|
339
341
|
|
|
340
342
|
if (!resp.success) {
|
|
341
|
-
|
|
343
|
+
throwSandboxError(resp, {});
|
|
342
344
|
}
|
|
343
345
|
}
|
|
344
346
|
|
|
@@ -368,7 +370,7 @@ export async function snapshotTag(
|
|
|
368
370
|
return resp.data;
|
|
369
371
|
}
|
|
370
372
|
|
|
371
|
-
|
|
373
|
+
throwSandboxError(resp, {});
|
|
372
374
|
}
|
|
373
375
|
|
|
374
376
|
/**
|
|
@@ -411,7 +413,7 @@ export async function snapshotLineage(
|
|
|
411
413
|
return resp.data;
|
|
412
414
|
}
|
|
413
415
|
|
|
414
|
-
|
|
416
|
+
throwSandboxError(resp, {});
|
|
415
417
|
}
|
|
416
418
|
|
|
417
419
|
// ===== Public Snapshot API =====
|
|
@@ -420,9 +422,7 @@ const _SnapshotPublicGetParamsSchema = z
|
|
|
420
422
|
.object({
|
|
421
423
|
snapshotRef: z
|
|
422
424
|
.string()
|
|
423
|
-
.describe(
|
|
424
|
-
'Snapshot reference: ID (snp_xxx), full name (@slug/name:tag), or name:tag'
|
|
425
|
-
),
|
|
425
|
+
.describe('Snapshot reference: ID (snp_xxx), full name (@slug/name:tag), or name:tag'),
|
|
426
426
|
})
|
|
427
427
|
.describe('Parameters for getting a public snapshot');
|
|
428
428
|
|
|
@@ -469,7 +469,7 @@ export async function snapshotPublicGet(
|
|
|
469
469
|
return resp.data;
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
-
|
|
472
|
+
throwSandboxError(resp, {});
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
// ===== Snapshot Build API =====
|
|
@@ -600,7 +600,7 @@ export async function snapshotBuildInit(
|
|
|
600
600
|
return resp.data;
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
-
|
|
603
|
+
throwSandboxError(resp, {});
|
|
604
604
|
}
|
|
605
605
|
|
|
606
606
|
/**
|
|
@@ -638,7 +638,7 @@ export async function snapshotBuildFinalize(
|
|
|
638
638
|
return resp.data;
|
|
639
639
|
}
|
|
640
640
|
|
|
641
|
-
|
|
641
|
+
throwSandboxError(resp, {});
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
// ===== Snapshot Upload API (for public snapshots) =====
|
|
@@ -707,5 +707,5 @@ export async function snapshotUpload(
|
|
|
707
707
|
return data.data;
|
|
708
708
|
}
|
|
709
709
|
|
|
710
|
-
|
|
710
|
+
throwSandboxError(data, {});
|
|
711
711
|
}
|
package/src/api/sandbox/util.ts
CHANGED
|
@@ -5,6 +5,18 @@ interface WritableWithDrain extends EventEmitter {
|
|
|
5
5
|
write(chunk: Uint8Array): boolean;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Machine-readable error codes for sandbox operations.
|
|
10
|
+
* These codes allow programmatic error handling without fragile string matching.
|
|
11
|
+
*/
|
|
12
|
+
export type SandboxErrorCode =
|
|
13
|
+
| 'SANDBOX_NOT_FOUND'
|
|
14
|
+
| 'SANDBOX_TERMINATED'
|
|
15
|
+
| 'EXECUTION_NOT_FOUND'
|
|
16
|
+
| 'EXECUTION_TIMEOUT'
|
|
17
|
+
| 'EXECUTION_CANCELLED'
|
|
18
|
+
| 'SNAPSHOT_NOT_FOUND';
|
|
19
|
+
|
|
8
20
|
/**
|
|
9
21
|
* Error thrown when a sandbox API request fails.
|
|
10
22
|
*
|
|
@@ -17,8 +29,176 @@ export const SandboxResponseError = StructuredError('SandboxResponseError')<{
|
|
|
17
29
|
executionId?: string;
|
|
18
30
|
/** The session ID (trace ID) from the x-session-id response header for OTel correlation */
|
|
19
31
|
sessionId?: string | null;
|
|
32
|
+
/** Machine-readable error code for programmatic error handling */
|
|
33
|
+
code?: SandboxErrorCode;
|
|
34
|
+
}>();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Error thrown when a sandbox is not found.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* try {
|
|
42
|
+
* await sandboxGet(client, { sandboxId: 'non-existent' });
|
|
43
|
+
* } catch (error) {
|
|
44
|
+
* if (error._tag === 'SandboxNotFoundError') {
|
|
45
|
+
* console.error(`Sandbox not found: ${error.sandboxId}`);
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export const SandboxNotFoundError = StructuredError('SandboxNotFoundError')<{
|
|
51
|
+
sandboxId: string;
|
|
52
|
+
}>();
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Error thrown when a sandbox has already terminated.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* try {
|
|
60
|
+
* await sandboxExecute(client, { sandboxId: 'terminated-sandbox', command: ['ls'] });
|
|
61
|
+
* } catch (error) {
|
|
62
|
+
* if (error._tag === 'SandboxTerminatedError') {
|
|
63
|
+
* console.error(`Sandbox terminated: ${error.sandboxId}`);
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export const SandboxTerminatedError = StructuredError('SandboxTerminatedError')<{
|
|
69
|
+
sandboxId: string;
|
|
70
|
+
}>();
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Error thrown when an execution is not found.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* try {
|
|
78
|
+
* await executionGet(client, { executionId: 'non-existent' });
|
|
79
|
+
* } catch (error) {
|
|
80
|
+
* if (error._tag === 'ExecutionNotFoundError') {
|
|
81
|
+
* console.error(`Execution not found: ${error.executionId}`);
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export const ExecutionNotFoundError = StructuredError('ExecutionNotFoundError')<{
|
|
87
|
+
executionId: string;
|
|
88
|
+
sandboxId?: string;
|
|
89
|
+
}>();
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Error thrown when an execution times out.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* try {
|
|
97
|
+
* await sandboxExecute(client, { sandboxId, command: ['long-running'], timeout: '30s' });
|
|
98
|
+
* } catch (error) {
|
|
99
|
+
* if (error._tag === 'ExecutionTimeoutError') {
|
|
100
|
+
* console.error('Execution timed out');
|
|
101
|
+
* }
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export const ExecutionTimeoutError = StructuredError('ExecutionTimeoutError')<{
|
|
106
|
+
executionId?: string;
|
|
107
|
+
sandboxId?: string;
|
|
20
108
|
}>();
|
|
21
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Error thrown when an execution is cancelled.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* try {
|
|
116
|
+
* await sandboxRun(client, params, { signal: controller.signal });
|
|
117
|
+
* } catch (error) {
|
|
118
|
+
* if (error._tag === 'ExecutionCancelledError') {
|
|
119
|
+
* console.error('Execution was cancelled');
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export const ExecutionCancelledError = StructuredError('ExecutionCancelledError')<{
|
|
125
|
+
sandboxId?: string;
|
|
126
|
+
}>();
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Error thrown when a snapshot is not found.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* try {
|
|
134
|
+
* await snapshotGet(client, { snapshotId: 'non-existent' });
|
|
135
|
+
* } catch (error) {
|
|
136
|
+
* if (error._tag === 'SnapshotNotFoundError') {
|
|
137
|
+
* console.error(`Snapshot not found: ${error.snapshotId}`);
|
|
138
|
+
* }
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export const SnapshotNotFoundError = StructuredError('SnapshotNotFoundError')<{
|
|
143
|
+
snapshotId?: string;
|
|
144
|
+
}>();
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Context for throwing sandbox errors.
|
|
148
|
+
*/
|
|
149
|
+
export interface SandboxErrorContext {
|
|
150
|
+
sandboxId?: string;
|
|
151
|
+
executionId?: string;
|
|
152
|
+
sessionId?: string | null;
|
|
153
|
+
snapshotId?: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Throws the appropriate sandbox error based on the response code.
|
|
158
|
+
*
|
|
159
|
+
* This helper centralizes error mapping logic, throwing specific error types
|
|
160
|
+
* when the backend returns a known error code, and falling back to
|
|
161
|
+
* SandboxResponseError for unknown codes.
|
|
162
|
+
*
|
|
163
|
+
* @param resp - The API response containing message and optional code
|
|
164
|
+
* @param context - Context about the operation (sandbox ID, execution ID, etc.)
|
|
165
|
+
* @throws {SandboxNotFoundError} When code is 'SANDBOX_NOT_FOUND'
|
|
166
|
+
* @throws {SandboxTerminatedError} When code is 'SANDBOX_TERMINATED'
|
|
167
|
+
* @throws {ExecutionNotFoundError} When code is 'EXECUTION_NOT_FOUND'
|
|
168
|
+
* @throws {ExecutionTimeoutError} When code is 'EXECUTION_TIMEOUT'
|
|
169
|
+
* @throws {ExecutionCancelledError} When code is 'EXECUTION_CANCELLED'
|
|
170
|
+
* @throws {SnapshotNotFoundError} When code is 'SNAPSHOT_NOT_FOUND'
|
|
171
|
+
* @throws {SandboxResponseError} For unknown codes or when no code is provided
|
|
172
|
+
*/
|
|
173
|
+
export function throwSandboxError(
|
|
174
|
+
resp: { message?: string; code?: string },
|
|
175
|
+
context: SandboxErrorContext
|
|
176
|
+
): never {
|
|
177
|
+
const { sandboxId, executionId, sessionId, snapshotId } = context;
|
|
178
|
+
const code = resp.code as SandboxErrorCode | undefined;
|
|
179
|
+
|
|
180
|
+
switch (code) {
|
|
181
|
+
case 'SANDBOX_NOT_FOUND':
|
|
182
|
+
throw new SandboxNotFoundError({ message: resp.message, sandboxId: sandboxId ?? '' });
|
|
183
|
+
case 'SANDBOX_TERMINATED':
|
|
184
|
+
throw new SandboxTerminatedError({ message: resp.message, sandboxId: sandboxId ?? '' });
|
|
185
|
+
case 'EXECUTION_NOT_FOUND':
|
|
186
|
+
throw new ExecutionNotFoundError({
|
|
187
|
+
message: resp.message,
|
|
188
|
+
executionId: executionId ?? '',
|
|
189
|
+
sandboxId,
|
|
190
|
+
});
|
|
191
|
+
case 'EXECUTION_TIMEOUT':
|
|
192
|
+
throw new ExecutionTimeoutError({ message: resp.message, executionId, sandboxId });
|
|
193
|
+
case 'EXECUTION_CANCELLED':
|
|
194
|
+
throw new ExecutionCancelledError({ message: resp.message, sandboxId });
|
|
195
|
+
case 'SNAPSHOT_NOT_FOUND':
|
|
196
|
+
throw new SnapshotNotFoundError({ message: resp.message, snapshotId });
|
|
197
|
+
default:
|
|
198
|
+
throw new SandboxResponseError({ message: resp.message, sandboxId, executionId, sessionId, code });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
22
202
|
/** Current sandbox API version */
|
|
23
203
|
export const API_VERSION = '2025-03-17';
|
|
24
204
|
|