@agentuity/server 0.0.105 → 0.0.107

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 (105) hide show
  1. package/dist/api/api.d.ts +11 -6
  2. package/dist/api/api.d.ts.map +1 -1
  3. package/dist/api/api.js +21 -13
  4. package/dist/api/api.js.map +1 -1
  5. package/dist/api/index.d.ts +1 -0
  6. package/dist/api/index.d.ts.map +1 -1
  7. package/dist/api/index.js +1 -0
  8. package/dist/api/index.js.map +1 -1
  9. package/dist/api/project/deploy.d.ts +0 -6
  10. package/dist/api/project/deploy.d.ts.map +1 -1
  11. package/dist/api/project/deploy.js +0 -2
  12. package/dist/api/project/deploy.js.map +1 -1
  13. package/dist/api/project/get.d.ts +2 -1
  14. package/dist/api/project/get.d.ts.map +1 -1
  15. package/dist/api/project/get.js +10 -2
  16. package/dist/api/project/get.js.map +1 -1
  17. package/dist/api/region/create.d.ts +2 -0
  18. package/dist/api/region/create.d.ts.map +1 -1
  19. package/dist/api/region/create.js +1 -0
  20. package/dist/api/region/create.js.map +1 -1
  21. package/dist/api/region/delete.d.ts +12 -2
  22. package/dist/api/region/delete.d.ts.map +1 -1
  23. package/dist/api/region/delete.js +6 -1
  24. package/dist/api/region/delete.js.map +1 -1
  25. package/dist/api/region/resources.d.ts +4 -0
  26. package/dist/api/region/resources.d.ts.map +1 -1
  27. package/dist/api/region/resources.js +2 -0
  28. package/dist/api/region/resources.js.map +1 -1
  29. package/dist/api/sandbox/client.d.ts +125 -0
  30. package/dist/api/sandbox/client.d.ts.map +1 -0
  31. package/dist/api/sandbox/client.js +202 -0
  32. package/dist/api/sandbox/client.js.map +1 -0
  33. package/dist/api/sandbox/create.d.ts +24 -0
  34. package/dist/api/sandbox/create.d.ts.map +1 -0
  35. package/dist/api/sandbox/create.js +133 -0
  36. package/dist/api/sandbox/create.js.map +1 -0
  37. package/dist/api/sandbox/destroy.d.ts +14 -0
  38. package/dist/api/sandbox/destroy.d.ts.map +1 -0
  39. package/dist/api/sandbox/destroy.js +25 -0
  40. package/dist/api/sandbox/destroy.js.map +1 -0
  41. package/dist/api/sandbox/execute.d.ts +18 -0
  42. package/dist/api/sandbox/execute.d.ts.map +1 -0
  43. package/dist/api/sandbox/execute.js +77 -0
  44. package/dist/api/sandbox/execute.js.map +1 -0
  45. package/dist/api/sandbox/execution.d.ts +46 -0
  46. package/dist/api/sandbox/execution.d.ts.map +1 -0
  47. package/dist/api/sandbox/execution.js +101 -0
  48. package/dist/api/sandbox/execution.js.map +1 -0
  49. package/dist/api/sandbox/files.d.ts +41 -0
  50. package/dist/api/sandbox/files.d.ts.map +1 -0
  51. package/dist/api/sandbox/files.js +91 -0
  52. package/dist/api/sandbox/files.js.map +1 -0
  53. package/dist/api/sandbox/get.d.ts +16 -0
  54. package/dist/api/sandbox/get.d.ts.map +1 -0
  55. package/dist/api/sandbox/get.js +57 -0
  56. package/dist/api/sandbox/get.js.map +1 -0
  57. package/dist/api/sandbox/index.d.ts +22 -0
  58. package/dist/api/sandbox/index.d.ts.map +1 -0
  59. package/dist/api/sandbox/index.js +12 -0
  60. package/dist/api/sandbox/index.js.map +1 -0
  61. package/dist/api/sandbox/list.d.ts +15 -0
  62. package/dist/api/sandbox/list.d.ts.map +1 -0
  63. package/dist/api/sandbox/list.js +75 -0
  64. package/dist/api/sandbox/list.js.map +1 -0
  65. package/dist/api/sandbox/run.d.ts +28 -0
  66. package/dist/api/sandbox/run.d.ts.map +1 -0
  67. package/dist/api/sandbox/run.js +269 -0
  68. package/dist/api/sandbox/run.js.map +1 -0
  69. package/dist/api/sandbox/snapshot.d.ts +89 -0
  70. package/dist/api/sandbox/snapshot.d.ts.map +1 -0
  71. package/dist/api/sandbox/snapshot.js +140 -0
  72. package/dist/api/sandbox/snapshot.js.map +1 -0
  73. package/dist/api/sandbox/util.d.ts +37 -0
  74. package/dist/api/sandbox/util.d.ts.map +1 -0
  75. package/dist/api/sandbox/util.js +45 -0
  76. package/dist/api/sandbox/util.js.map +1 -0
  77. package/dist/config.d.ts +1 -0
  78. package/dist/config.d.ts.map +1 -1
  79. package/dist/config.js +1 -0
  80. package/dist/config.js.map +1 -1
  81. package/dist/runtime-bootstrap.d.ts.map +1 -1
  82. package/dist/runtime-bootstrap.js +3 -0
  83. package/dist/runtime-bootstrap.js.map +1 -1
  84. package/package.json +4 -4
  85. package/src/api/api.ts +33 -13
  86. package/src/api/index.ts +1 -0
  87. package/src/api/project/deploy.ts +0 -2
  88. package/src/api/project/get.ts +10 -2
  89. package/src/api/region/create.ts +1 -0
  90. package/src/api/region/delete.ts +9 -2
  91. package/src/api/region/resources.ts +2 -0
  92. package/src/api/sandbox/client.ts +349 -0
  93. package/src/api/sandbox/create.ts +166 -0
  94. package/src/api/sandbox/destroy.ts +41 -0
  95. package/src/api/sandbox/execute.ts +102 -0
  96. package/src/api/sandbox/execution.ts +154 -0
  97. package/src/api/sandbox/files.ts +138 -0
  98. package/src/api/sandbox/get.ts +74 -0
  99. package/src/api/sandbox/index.ts +35 -0
  100. package/src/api/sandbox/list.ts +94 -0
  101. package/src/api/sandbox/run.ts +360 -0
  102. package/src/api/sandbox/snapshot.ts +247 -0
  103. package/src/api/sandbox/util.ts +55 -0
  104. package/src/config.ts +2 -0
  105. package/src/runtime-bootstrap.ts +3 -0
@@ -0,0 +1,247 @@
1
+ import { z } from 'zod';
2
+ import { APIClient, APIResponseSchema, APIResponseSchemaNoData } from '../api';
3
+ import { SandboxResponseError } from './util';
4
+
5
+ const SNAPSHOT_API_VERSION = '2025-06-26';
6
+
7
+ const SnapshotFileInfoSchema = z
8
+ .object({
9
+ path: z.string().describe('File path within the snapshot'),
10
+ size: z.number().describe('File size in bytes'),
11
+ })
12
+ .describe('Information about a file in a snapshot');
13
+
14
+ const SnapshotInfoSchema = z
15
+ .object({
16
+ snapshotId: z.string().describe('Unique identifier for the snapshot'),
17
+ sandboxId: z.string().describe('ID of the sandbox this snapshot was created from'),
18
+ tag: z.string().nullable().optional().describe('User-defined tag for the snapshot'),
19
+ sizeBytes: z.number().describe('Total size of the snapshot in bytes'),
20
+ fileCount: z.number().describe('Number of files in the snapshot'),
21
+ parentSnapshotId: z
22
+ .string()
23
+ .nullable()
24
+ .optional()
25
+ .describe('ID of the parent snapshot (for incremental snapshots)'),
26
+ createdAt: z.string().describe('ISO timestamp when the snapshot was created'),
27
+ downloadUrl: z.string().optional().describe('URL to download the snapshot archive'),
28
+ files: z.array(SnapshotFileInfoSchema).optional().describe('List of files in the snapshot'),
29
+ })
30
+ .describe('Detailed information about a snapshot');
31
+
32
+ const SnapshotCreateResponseSchema = APIResponseSchema(SnapshotInfoSchema);
33
+ const SnapshotGetResponseSchema = APIResponseSchema(SnapshotInfoSchema);
34
+ const SnapshotListDataSchema = z
35
+ .object({
36
+ snapshots: z.array(SnapshotInfoSchema).describe('List of snapshot entries'),
37
+ total: z.number().describe('Total number of snapshots matching the query'),
38
+ })
39
+ .describe('Paginated list of snapshots');
40
+ const SnapshotListResponseSchema = APIResponseSchema(SnapshotListDataSchema);
41
+ const SnapshotDeleteResponseSchema = APIResponseSchemaNoData();
42
+
43
+ export interface SnapshotFileInfo {
44
+ path: string;
45
+ size: number;
46
+ }
47
+
48
+ export interface SnapshotInfo {
49
+ snapshotId: string;
50
+ sandboxId: string;
51
+ tag?: string | null;
52
+ sizeBytes: number;
53
+ fileCount: number;
54
+ parentSnapshotId?: string | null;
55
+ createdAt: string;
56
+ downloadUrl?: string;
57
+ files?: SnapshotFileInfo[];
58
+ }
59
+
60
+ export interface SnapshotCreateParams {
61
+ sandboxId: string;
62
+ tag?: string;
63
+ orgId?: string;
64
+ }
65
+
66
+ export interface SnapshotGetParams {
67
+ snapshotId: string;
68
+ orgId?: string;
69
+ }
70
+
71
+ export interface SnapshotListParams {
72
+ sandboxId?: string;
73
+ limit?: number;
74
+ offset?: number;
75
+ orgId?: string;
76
+ }
77
+
78
+ export interface SnapshotListResponse {
79
+ snapshots: SnapshotInfo[];
80
+ total: number;
81
+ }
82
+
83
+ export interface SnapshotDeleteParams {
84
+ snapshotId: string;
85
+ orgId?: string;
86
+ }
87
+
88
+ export interface SnapshotTagParams {
89
+ snapshotId: string;
90
+ tag: string | null;
91
+ orgId?: string;
92
+ }
93
+
94
+ function buildQueryString(params: Record<string, string | number | undefined>): string {
95
+ const query = new URLSearchParams();
96
+ for (const [key, value] of Object.entries(params)) {
97
+ if (value !== undefined) {
98
+ query.set(key, String(value));
99
+ }
100
+ }
101
+ const str = query.toString();
102
+ return str ? `?${str}` : '';
103
+ }
104
+
105
+ /**
106
+ * Creates a snapshot of a sandbox's current state.
107
+ *
108
+ * @param client - The API client to use for the request
109
+ * @param params - Parameters including sandbox ID and optional tag
110
+ * @returns The created snapshot information
111
+ * @throws {SandboxResponseError} If the snapshot creation fails
112
+ */
113
+ export async function snapshotCreate(
114
+ client: APIClient,
115
+ params: SnapshotCreateParams
116
+ ): Promise<SnapshotInfo> {
117
+ const { sandboxId, tag, orgId } = params;
118
+ const queryString = buildQueryString({ orgId });
119
+ const url = `/sandbox/${SNAPSHOT_API_VERSION}/${sandboxId}/snapshot${queryString}`;
120
+
121
+ const body: Record<string, string> = {};
122
+ if (tag) {
123
+ body.tag = tag;
124
+ }
125
+
126
+ const resp = await client.post<z.infer<typeof SnapshotCreateResponseSchema>>(
127
+ url,
128
+ body,
129
+ SnapshotCreateResponseSchema
130
+ );
131
+
132
+ if (resp.success) {
133
+ return resp.data;
134
+ }
135
+
136
+ throw new SandboxResponseError({ message: resp.message });
137
+ }
138
+
139
+ /**
140
+ * Retrieves detailed information about a specific snapshot.
141
+ *
142
+ * @param client - The API client to use for the request
143
+ * @param params - Parameters including the snapshot ID
144
+ * @returns Snapshot information including files and download URL
145
+ * @throws {SandboxResponseError} If the snapshot is not found or request fails
146
+ */
147
+ export async function snapshotGet(
148
+ client: APIClient,
149
+ params: SnapshotGetParams
150
+ ): Promise<SnapshotInfo> {
151
+ const { snapshotId, orgId } = params;
152
+ const queryString = buildQueryString({ orgId });
153
+ const url = `/sandbox/${SNAPSHOT_API_VERSION}/snapshots/${snapshotId}${queryString}`;
154
+
155
+ const resp = await client.get<z.infer<typeof SnapshotGetResponseSchema>>(
156
+ url,
157
+ SnapshotGetResponseSchema
158
+ );
159
+
160
+ if (resp.success) {
161
+ return resp.data;
162
+ }
163
+
164
+ throw new SandboxResponseError({ message: resp.message });
165
+ }
166
+
167
+ /**
168
+ * Lists snapshots with optional filtering and pagination.
169
+ *
170
+ * @param client - The API client to use for the request
171
+ * @param params - Optional parameters for filtering by sandbox and pagination
172
+ * @returns Paginated list of snapshots with total count
173
+ * @throws {SandboxResponseError} If the request fails
174
+ */
175
+ export async function snapshotList(
176
+ client: APIClient,
177
+ params: SnapshotListParams = {}
178
+ ): Promise<SnapshotListResponse> {
179
+ const { sandboxId, limit, offset, orgId } = params;
180
+ const queryString = buildQueryString({ sandboxId, limit, offset, orgId });
181
+ const url = `/sandbox/${SNAPSHOT_API_VERSION}/snapshots${queryString}`;
182
+
183
+ const resp = await client.get<z.infer<typeof SnapshotListResponseSchema>>(
184
+ url,
185
+ SnapshotListResponseSchema
186
+ );
187
+
188
+ if (resp.success) {
189
+ return resp.data;
190
+ }
191
+
192
+ throw new SandboxResponseError({ message: resp.message });
193
+ }
194
+
195
+ /**
196
+ * Deletes a snapshot and releases its storage.
197
+ *
198
+ * @param client - The API client to use for the request
199
+ * @param params - Parameters including the snapshot ID to delete
200
+ * @throws {SandboxResponseError} If the snapshot is not found or deletion fails
201
+ */
202
+ export async function snapshotDelete(
203
+ client: APIClient,
204
+ params: SnapshotDeleteParams
205
+ ): Promise<void> {
206
+ const { snapshotId, orgId } = params;
207
+ const queryString = buildQueryString({ orgId });
208
+ const url = `/sandbox/${SNAPSHOT_API_VERSION}/snapshots/${snapshotId}${queryString}`;
209
+
210
+ const resp = await client.delete<z.infer<typeof SnapshotDeleteResponseSchema>>(
211
+ url,
212
+ SnapshotDeleteResponseSchema
213
+ );
214
+
215
+ if (!resp.success) {
216
+ throw new SandboxResponseError({ message: resp.message });
217
+ }
218
+ }
219
+
220
+ /**
221
+ * Updates or removes the tag on a snapshot.
222
+ *
223
+ * @param client - The API client to use for the request
224
+ * @param params - Parameters including snapshot ID and new tag (or null to remove)
225
+ * @returns Updated snapshot information
226
+ * @throws {SandboxResponseError} If the snapshot is not found or update fails
227
+ */
228
+ export async function snapshotTag(
229
+ client: APIClient,
230
+ params: SnapshotTagParams
231
+ ): Promise<SnapshotInfo> {
232
+ const { snapshotId, tag, orgId } = params;
233
+ const queryString = buildQueryString({ orgId });
234
+ const url = `/sandbox/${SNAPSHOT_API_VERSION}/snapshots/${snapshotId}${queryString}`;
235
+
236
+ const resp = await client.patch<z.infer<typeof SnapshotGetResponseSchema>>(
237
+ url,
238
+ { tag },
239
+ SnapshotGetResponseSchema
240
+ );
241
+
242
+ if (resp.success) {
243
+ return resp.data;
244
+ }
245
+
246
+ throw new SandboxResponseError({ message: resp.message });
247
+ }
@@ -0,0 +1,55 @@
1
+ import { StructuredError } from '@agentuity/core';
2
+ import type { EventEmitter } from 'node:events';
3
+
4
+ interface WritableWithDrain extends EventEmitter {
5
+ write(chunk: Uint8Array): boolean;
6
+ }
7
+
8
+ /**
9
+ * Error thrown when a sandbox API request fails.
10
+ *
11
+ * Includes optional context about which sandbox or execution caused the error.
12
+ */
13
+ export const SandboxResponseError = StructuredError('SandboxResponseError')<{
14
+ /** The sandbox ID associated with the error, if applicable */
15
+ sandboxId?: string;
16
+ /** The execution ID associated with the error, if applicable */
17
+ executionId?: string;
18
+ }>();
19
+
20
+ /** Current sandbox API version */
21
+ export const API_VERSION = '2025-03-17';
22
+
23
+ /**
24
+ * Write a chunk to a writable stream and wait for it to drain if necessary.
25
+ * Properly cleans up event listeners to avoid memory leaks.
26
+ */
27
+ export function writeAndDrain(writable: WritableWithDrain, chunk: Uint8Array): Promise<void> {
28
+ return new Promise((resolve, reject) => {
29
+ let needsDrain: boolean;
30
+ try {
31
+ needsDrain = !writable.write(chunk);
32
+ } catch (err) {
33
+ reject(err);
34
+ return;
35
+ }
36
+ if (needsDrain) {
37
+ const cleanup = () => {
38
+ writable.removeListener('drain', onDrain);
39
+ writable.removeListener('error', onError);
40
+ };
41
+ const onDrain = () => {
42
+ cleanup();
43
+ resolve();
44
+ };
45
+ const onError = (err: Error) => {
46
+ cleanup();
47
+ reject(err);
48
+ };
49
+ writable.once('drain', onDrain);
50
+ writable.once('error', onError);
51
+ } else {
52
+ resolve();
53
+ }
54
+ });
55
+ }
package/src/config.ts CHANGED
@@ -4,6 +4,7 @@ export interface ServiceUrls {
4
4
  vector: string;
5
5
  catalyst: string;
6
6
  otel: string;
7
+ sandbox: string;
7
8
  }
8
9
 
9
10
  /**
@@ -18,6 +19,7 @@ export function getServiceUrls(region?: string): ServiceUrls {
18
19
  vector: process.env.AGENTUITY_VECTOR_URL || transportUrl,
19
20
  catalyst: process.env.AGENTUITY_CATALYST_URL || transportUrl,
20
21
  otel: process.env.AGENTUITY_OTLP_URL || buildRegionalURL(region, 'otel'),
22
+ sandbox: process.env.AGENTUITY_SANDBOX_URL || transportUrl,
21
23
  };
22
24
  }
23
25
 
@@ -72,6 +72,9 @@ export function bootstrapRuntimeEnv(options: RuntimeBootstrapOptions = {}): void
72
72
  if (!process.env.AGENTUITY_KEYVALUE_URL) {
73
73
  process.env.AGENTUITY_KEYVALUE_URL = serviceUrls.keyvalue;
74
74
  }
75
+ if (!process.env.AGENTUITY_SANDBOX_URL) {
76
+ process.env.AGENTUITY_SANDBOX_URL = serviceUrls.sandbox;
77
+ }
75
78
  if (!process.env.AGENTUITY_STREAM_URL) {
76
79
  process.env.AGENTUITY_STREAM_URL = serviceUrls.stream;
77
80
  }