@agentuity/server 0.1.16 → 0.1.18

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 (93) 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 +19 -12
  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/org/env-delete.d.ts.map +1 -1
  10. package/dist/api/org/env-delete.js.map +1 -1
  11. package/dist/api/org/env-get.d.ts.map +1 -1
  12. package/dist/api/org/env-get.js.map +1 -1
  13. package/dist/api/org/env-update.d.ts.map +1 -1
  14. package/dist/api/org/env-update.js.map +1 -1
  15. package/dist/api/queue/analytics.d.ts +108 -0
  16. package/dist/api/queue/analytics.d.ts.map +1 -0
  17. package/dist/api/queue/analytics.js +245 -0
  18. package/dist/api/queue/analytics.js.map +1 -0
  19. package/dist/api/queue/destinations.d.ts +108 -0
  20. package/dist/api/queue/destinations.d.ts.map +1 -0
  21. package/dist/api/queue/destinations.js +238 -0
  22. package/dist/api/queue/destinations.js.map +1 -0
  23. package/dist/api/queue/dlq.d.ts +100 -0
  24. package/dist/api/queue/dlq.d.ts.map +1 -0
  25. package/dist/api/queue/dlq.js +204 -0
  26. package/dist/api/queue/dlq.js.map +1 -0
  27. package/dist/api/queue/index.d.ts +55 -0
  28. package/dist/api/queue/index.d.ts.map +1 -0
  29. package/dist/api/queue/index.js +86 -0
  30. package/dist/api/queue/index.js.map +1 -0
  31. package/dist/api/queue/messages.d.ts +332 -0
  32. package/dist/api/queue/messages.d.ts.map +1 -0
  33. package/dist/api/queue/messages.js +637 -0
  34. package/dist/api/queue/messages.js.map +1 -0
  35. package/dist/api/queue/queues.d.ts +153 -0
  36. package/dist/api/queue/queues.d.ts.map +1 -0
  37. package/dist/api/queue/queues.js +319 -0
  38. package/dist/api/queue/queues.js.map +1 -0
  39. package/dist/api/queue/sources.d.ts +132 -0
  40. package/dist/api/queue/sources.d.ts.map +1 -0
  41. package/dist/api/queue/sources.js +285 -0
  42. package/dist/api/queue/sources.js.map +1 -0
  43. package/dist/api/queue/types.d.ts +1129 -0
  44. package/dist/api/queue/types.d.ts.map +1 -0
  45. package/dist/api/queue/types.js +949 -0
  46. package/dist/api/queue/types.js.map +1 -0
  47. package/dist/api/queue/util.d.ts +262 -0
  48. package/dist/api/queue/util.d.ts.map +1 -0
  49. package/dist/api/queue/util.js +171 -0
  50. package/dist/api/queue/util.js.map +1 -0
  51. package/dist/api/queue/validation.d.ts +247 -0
  52. package/dist/api/queue/validation.d.ts.map +1 -0
  53. package/dist/api/queue/validation.js +513 -0
  54. package/dist/api/queue/validation.js.map +1 -0
  55. package/dist/api/sandbox/get.d.ts.map +1 -1
  56. package/dist/api/sandbox/get.js +5 -0
  57. package/dist/api/sandbox/get.js.map +1 -1
  58. package/dist/api/sandbox/index.d.ts +3 -3
  59. package/dist/api/sandbox/index.d.ts.map +1 -1
  60. package/dist/api/sandbox/index.js +1 -1
  61. package/dist/api/sandbox/index.js.map +1 -1
  62. package/dist/api/sandbox/run.d.ts.map +1 -1
  63. package/dist/api/sandbox/run.js +5 -2
  64. package/dist/api/sandbox/run.js.map +1 -1
  65. package/dist/api/sandbox/snapshot-build.d.ts +2 -0
  66. package/dist/api/sandbox/snapshot-build.d.ts.map +1 -1
  67. package/dist/api/sandbox/snapshot-build.js +4 -0
  68. package/dist/api/sandbox/snapshot-build.js.map +1 -1
  69. package/dist/api/sandbox/snapshot.d.ts +143 -1
  70. package/dist/api/sandbox/snapshot.d.ts.map +1 -1
  71. package/dist/api/sandbox/snapshot.js +183 -4
  72. package/dist/api/sandbox/snapshot.js.map +1 -1
  73. package/package.json +4 -4
  74. package/src/api/api.ts +62 -13
  75. package/src/api/index.ts +1 -0
  76. package/src/api/org/env-delete.ts +1 -4
  77. package/src/api/org/env-get.ts +1 -4
  78. package/src/api/org/env-update.ts +1 -4
  79. package/src/api/queue/analytics.ts +313 -0
  80. package/src/api/queue/destinations.ts +321 -0
  81. package/src/api/queue/dlq.ts +283 -0
  82. package/src/api/queue/index.ts +261 -0
  83. package/src/api/queue/messages.ts +875 -0
  84. package/src/api/queue/queues.ts +448 -0
  85. package/src/api/queue/sources.ts +384 -0
  86. package/src/api/queue/types.ts +1253 -0
  87. package/src/api/queue/util.ts +204 -0
  88. package/src/api/queue/validation.ts +560 -0
  89. package/src/api/sandbox/get.ts +5 -0
  90. package/src/api/sandbox/index.ts +13 -1
  91. package/src/api/sandbox/run.ts +5 -2
  92. package/src/api/sandbox/snapshot-build.ts +4 -0
  93. package/src/api/sandbox/snapshot.ts +223 -5
@@ -0,0 +1,560 @@
1
+ /**
2
+ * @module validation
3
+ * Queue validation utilities with constants matching the Catalyst backend.
4
+ *
5
+ * These validation functions perform client-side validation before API calls,
6
+ * providing immediate feedback and reducing unnecessary network requests.
7
+ */
8
+
9
+ import { StructuredError } from '@agentuity/core';
10
+
11
+ // ============================================================================
12
+ // Validation Constants
13
+ // ============================================================================
14
+
15
+ /** Maximum allowed length for queue names. */
16
+ export const MAX_QUEUE_NAME_LENGTH = 256;
17
+
18
+ /** Minimum allowed length for queue names. */
19
+ export const MIN_QUEUE_NAME_LENGTH = 1;
20
+
21
+ /** Maximum payload size in bytes (1MB). */
22
+ export const MAX_PAYLOAD_SIZE = 1048576;
23
+
24
+ /** Maximum description length in characters. */
25
+ export const MAX_DESCRIPTION_LENGTH = 1024;
26
+
27
+ /** Maximum number of messages in a single batch operation. */
28
+ export const MAX_BATCH_SIZE = 1000;
29
+
30
+ /** Maximum metadata size in bytes (64KB). */
31
+ export const MAX_METADATA_SIZE = 65536;
32
+
33
+ /** Maximum partition key length in characters. */
34
+ export const MAX_PARTITION_KEY_LENGTH = 256;
35
+
36
+ /** Maximum idempotency key length in characters. */
37
+ export const MAX_IDEMPOTENCY_KEY_LENGTH = 256;
38
+
39
+ /** Maximum visibility timeout in seconds (12 hours). */
40
+ export const MAX_VISIBILITY_TIMEOUT = 43200;
41
+
42
+ /** Maximum number of retry attempts allowed. */
43
+ export const MAX_RETRIES = 100;
44
+
45
+ /** Maximum number of in-flight messages per client. */
46
+ export const MAX_IN_FLIGHT = 1000;
47
+
48
+ /** Queue name pattern: starts with letter/underscore, contains lowercase alphanumerics, underscores, hyphens. */
49
+ const VALID_QUEUE_NAME_REGEX = /^[a-z_][a-z0-9_-]*$/;
50
+
51
+ /** Message ID pattern: must start with qmsg_ prefix. */
52
+ const VALID_MESSAGE_ID_REGEX = /^qmsg_[a-zA-Z0-9]+$/;
53
+
54
+ /** Destination ID pattern: must start with qdest_ prefix. */
55
+ const VALID_DESTINATION_ID_REGEX = /^qdest_[a-zA-Z0-9]+$/;
56
+
57
+ /** Source ID pattern: must start with qsrc_ prefix. */
58
+ const VALID_SOURCE_ID_REGEX = /^qsrc_[a-zA-Z0-9]+$/;
59
+
60
+ /** Maximum source name length. */
61
+ export const MAX_SOURCE_NAME_LENGTH = 256;
62
+
63
+ // ============================================================================
64
+ // Validation Error
65
+ // ============================================================================
66
+
67
+ /**
68
+ * Error thrown when validation fails for queue operations.
69
+ *
70
+ * Includes the field name and optionally the invalid value for debugging.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * try {
75
+ * validateQueueName('Invalid Name!');
76
+ * } catch (error) {
77
+ * if (error instanceof QueueValidationError) {
78
+ * console.error(`Invalid ${error.field}: ${error.message}`);
79
+ * }
80
+ * }
81
+ * ```
82
+ */
83
+ export const QueueValidationError = StructuredError('QueueValidationError')<{
84
+ field: string;
85
+ value?: unknown;
86
+ }>();
87
+
88
+ // ============================================================================
89
+ // Validation Functions
90
+ // ============================================================================
91
+
92
+ /**
93
+ * Validates a queue name against naming rules.
94
+ *
95
+ * Queue names must:
96
+ * - Be 1-256 characters long
97
+ * - Start with a lowercase letter or underscore
98
+ * - Contain only lowercase letters, digits, underscores, and hyphens
99
+ *
100
+ * @param name - The queue name to validate
101
+ * @throws {QueueValidationError} If the name is invalid
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * validateQueueName('my_queue'); // OK
106
+ * validateQueueName('order-queue'); // OK
107
+ * validateQueueName('Invalid Name!'); // Throws
108
+ * ```
109
+ */
110
+ export function validateQueueName(name: string): void {
111
+ if (!name || name.length < MIN_QUEUE_NAME_LENGTH) {
112
+ throw new QueueValidationError({
113
+ message: 'Queue name cannot be empty',
114
+ field: 'name',
115
+ value: name,
116
+ });
117
+ }
118
+ if (name.length > MAX_QUEUE_NAME_LENGTH) {
119
+ throw new QueueValidationError({
120
+ message: `Queue name must not exceed ${MAX_QUEUE_NAME_LENGTH} characters`,
121
+ field: 'name',
122
+ value: name,
123
+ });
124
+ }
125
+ if (!VALID_QUEUE_NAME_REGEX.test(name)) {
126
+ throw new QueueValidationError({
127
+ message:
128
+ 'Queue name must start with a letter or underscore and contain only lowercase letters, digits, underscores, and hyphens',
129
+ field: 'name',
130
+ value: name,
131
+ });
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Validates a queue type.
137
+ *
138
+ * @param type - The queue type to validate
139
+ * @throws {QueueValidationError} If the type is not 'worker' or 'pubsub'
140
+ */
141
+ export function validateQueueType(type: string): void {
142
+ if (type !== 'worker' && type !== 'pubsub') {
143
+ throw new QueueValidationError({
144
+ message: "Queue type must be 'worker' or 'pubsub'",
145
+ field: 'queue_type',
146
+ value: type,
147
+ });
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Validates a message payload.
153
+ *
154
+ * Payloads must be non-empty JSON and not exceed 1MB when serialized.
155
+ *
156
+ * @param payload - The payload to validate (must be JSON-serializable)
157
+ * @throws {QueueValidationError} If the payload is empty or too large
158
+ */
159
+ export function validatePayload(payload: unknown): void {
160
+ if (payload === undefined || payload === null) {
161
+ throw new QueueValidationError({
162
+ message: 'Payload cannot be empty',
163
+ field: 'payload',
164
+ });
165
+ }
166
+ const serialized = JSON.stringify(payload);
167
+ const payloadBytes = new TextEncoder().encode(serialized).length;
168
+ if (payloadBytes > MAX_PAYLOAD_SIZE) {
169
+ throw new QueueValidationError({
170
+ message: `Payload size exceeds ${MAX_PAYLOAD_SIZE} byte limit (${payloadBytes} bytes)`,
171
+ field: 'payload',
172
+ value: payloadBytes,
173
+ });
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Validates a message ID format.
179
+ *
180
+ * Message IDs must start with the `qmsg_` prefix.
181
+ *
182
+ * @param id - The message ID to validate
183
+ * @throws {QueueValidationError} If the ID format is invalid
184
+ */
185
+ export function validateMessageId(id: string): void {
186
+ if (!id || !VALID_MESSAGE_ID_REGEX.test(id)) {
187
+ throw new QueueValidationError({
188
+ message: 'Invalid message ID format (must start with qmsg_ prefix)',
189
+ field: 'message_id',
190
+ value: id,
191
+ });
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Validates a destination ID format.
197
+ *
198
+ * Destination IDs must start with the `qdest_` prefix.
199
+ *
200
+ * @param id - The destination ID to validate
201
+ * @throws {QueueValidationError} If the ID format is invalid
202
+ */
203
+ export function validateDestinationId(id: string): void {
204
+ if (!id || !VALID_DESTINATION_ID_REGEX.test(id)) {
205
+ throw new QueueValidationError({
206
+ message: 'Invalid destination ID format (must start with qdest_ prefix)',
207
+ field: 'destination_id',
208
+ value: id,
209
+ });
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Validates a queue or message description.
215
+ *
216
+ * @param description - The description to validate (optional)
217
+ * @throws {QueueValidationError} If the description exceeds the maximum length
218
+ */
219
+ export function validateDescription(description?: string): void {
220
+ if (description && description.length > MAX_DESCRIPTION_LENGTH) {
221
+ throw new QueueValidationError({
222
+ message: `Description must not exceed ${MAX_DESCRIPTION_LENGTH} characters`,
223
+ field: 'description',
224
+ value: description.length,
225
+ });
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Validates a partition key length.
231
+ *
232
+ * Partition keys are used for message ordering within a queue.
233
+ *
234
+ * @param key - The partition key to validate (optional)
235
+ * @throws {QueueValidationError} If the key exceeds the maximum length
236
+ */
237
+ export function validatePartitionKey(key?: string): void {
238
+ if (key && key.length > MAX_PARTITION_KEY_LENGTH) {
239
+ throw new QueueValidationError({
240
+ message: `Partition key must not exceed ${MAX_PARTITION_KEY_LENGTH} characters`,
241
+ field: 'partition_key',
242
+ value: key.length,
243
+ });
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Validates an idempotency key length.
249
+ *
250
+ * Idempotency keys are used to prevent duplicate message processing.
251
+ *
252
+ * @param key - The idempotency key to validate (optional)
253
+ * @throws {QueueValidationError} If the key exceeds the maximum length
254
+ */
255
+ export function validateIdempotencyKey(key?: string): void {
256
+ if (key && key.length > MAX_IDEMPOTENCY_KEY_LENGTH) {
257
+ throw new QueueValidationError({
258
+ message: `Idempotency key must not exceed ${MAX_IDEMPOTENCY_KEY_LENGTH} characters`,
259
+ field: 'idempotency_key',
260
+ value: key.length,
261
+ });
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Validates a time-to-live value.
267
+ *
268
+ * TTL specifies how long a message should be kept before expiring.
269
+ *
270
+ * @param ttl - The TTL in seconds to validate (optional)
271
+ * @throws {QueueValidationError} If the TTL is negative
272
+ */
273
+ export function validateTTL(ttl?: number): void {
274
+ if (ttl !== undefined && ttl < 0) {
275
+ throw new QueueValidationError({
276
+ message: 'TTL cannot be negative',
277
+ field: 'ttl',
278
+ value: ttl,
279
+ });
280
+ }
281
+ }
282
+
283
+ /**
284
+ * Validates a visibility timeout.
285
+ *
286
+ * Visibility timeout is how long a message is hidden after being received,
287
+ * giving the consumer time to process it before it becomes visible again.
288
+ *
289
+ * @param timeout - The timeout in seconds to validate (optional)
290
+ * @throws {QueueValidationError} If the timeout is out of valid range (1-43200 seconds)
291
+ */
292
+ export function validateVisibilityTimeout(timeout?: number): void {
293
+ if (timeout !== undefined) {
294
+ if (timeout < 1) {
295
+ throw new QueueValidationError({
296
+ message: 'Visibility timeout must be at least 1 second',
297
+ field: 'visibility_timeout',
298
+ value: timeout,
299
+ });
300
+ }
301
+ if (timeout > MAX_VISIBILITY_TIMEOUT) {
302
+ throw new QueueValidationError({
303
+ message: `Visibility timeout must not exceed ${MAX_VISIBILITY_TIMEOUT} seconds (12 hours)`,
304
+ field: 'visibility_timeout',
305
+ value: timeout,
306
+ });
307
+ }
308
+ }
309
+ }
310
+
311
+ /**
312
+ * Validates the maximum retry count.
313
+ *
314
+ * @param retries - The max retries value to validate (optional)
315
+ * @throws {QueueValidationError} If retries is negative or exceeds maximum
316
+ */
317
+ export function validateMaxRetries(retries?: number): void {
318
+ if (retries !== undefined) {
319
+ if (retries < 0) {
320
+ throw new QueueValidationError({
321
+ message: 'Max retries cannot be negative',
322
+ field: 'max_retries',
323
+ value: retries,
324
+ });
325
+ }
326
+ if (retries > MAX_RETRIES) {
327
+ throw new QueueValidationError({
328
+ message: `Max retries must not exceed ${MAX_RETRIES}`,
329
+ field: 'max_retries',
330
+ value: retries,
331
+ });
332
+ }
333
+ }
334
+ }
335
+
336
+ /**
337
+ * Validates the maximum in-flight messages per client.
338
+ *
339
+ * This controls how many messages a single consumer can process concurrently.
340
+ *
341
+ * @param maxInFlight - The max in-flight value to validate (optional)
342
+ * @throws {QueueValidationError} If the value is out of valid range (1-1000)
343
+ */
344
+ export function validateMaxInFlight(maxInFlight?: number): void {
345
+ if (maxInFlight !== undefined) {
346
+ if (maxInFlight < 1) {
347
+ throw new QueueValidationError({
348
+ message: 'Max in-flight per client must be at least 1',
349
+ field: 'max_in_flight',
350
+ value: maxInFlight,
351
+ });
352
+ }
353
+ if (maxInFlight > MAX_IN_FLIGHT) {
354
+ throw new QueueValidationError({
355
+ message: `Max in-flight per client must not exceed ${MAX_IN_FLIGHT}`,
356
+ field: 'max_in_flight',
357
+ value: maxInFlight,
358
+ });
359
+ }
360
+ }
361
+ }
362
+
363
+ /**
364
+ * Validates a message offset.
365
+ *
366
+ * Offsets are sequential positions in the queue, starting from 0.
367
+ *
368
+ * @param offset - The offset value to validate
369
+ * @throws {QueueValidationError} If the offset is negative
370
+ */
371
+ export function validateOffset(offset: number): void {
372
+ if (offset < 0) {
373
+ throw new QueueValidationError({
374
+ message: 'Offset cannot be negative',
375
+ field: 'offset',
376
+ value: offset,
377
+ });
378
+ }
379
+ }
380
+
381
+ /**
382
+ * Validates a limit for list/consume operations.
383
+ *
384
+ * @param limit - The limit value to validate
385
+ * @throws {QueueValidationError} If the limit is less than 1 or exceeds maximum
386
+ */
387
+ export function validateLimit(limit: number): void {
388
+ if (limit < 1) {
389
+ throw new QueueValidationError({
390
+ message: 'Limit must be at least 1',
391
+ field: 'limit',
392
+ value: limit,
393
+ });
394
+ }
395
+ if (limit > MAX_BATCH_SIZE) {
396
+ throw new QueueValidationError({
397
+ message: `Limit must not exceed ${MAX_BATCH_SIZE}`,
398
+ field: 'limit',
399
+ value: limit,
400
+ });
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Validates a batch size for batch operations.
406
+ *
407
+ * @param size - The batch size to validate
408
+ * @throws {QueueValidationError} If the size is less than 1 or exceeds maximum
409
+ */
410
+ export function validateBatchSize(size: number): void {
411
+ if (size <= 0) {
412
+ throw new QueueValidationError({
413
+ message: 'Batch size must be greater than 0',
414
+ field: 'batch_size',
415
+ value: size,
416
+ });
417
+ }
418
+ if (size > MAX_BATCH_SIZE) {
419
+ throw new QueueValidationError({
420
+ message: `Batch size must not exceed ${MAX_BATCH_SIZE}`,
421
+ field: 'batch_size',
422
+ value: size,
423
+ });
424
+ }
425
+ }
426
+
427
+ /**
428
+ * Validates a webhook URL for destinations.
429
+ *
430
+ * URLs must use HTTP or HTTPS protocol.
431
+ *
432
+ * @param url - The URL to validate
433
+ * @throws {QueueValidationError} If the URL is missing or not HTTP/HTTPS
434
+ */
435
+ export function validateWebhookUrl(url: string): void {
436
+ if (!url) {
437
+ throw new QueueValidationError({
438
+ message: 'Webhook URL is required',
439
+ field: 'url',
440
+ });
441
+ }
442
+ if (!url.startsWith('http://') && !url.startsWith('https://')) {
443
+ throw new QueueValidationError({
444
+ message: 'Webhook URL must be a valid HTTP or HTTPS URL',
445
+ field: 'url',
446
+ value: url,
447
+ });
448
+ }
449
+ }
450
+
451
+ /**
452
+ * Validates a destination configuration object.
453
+ *
454
+ * Checks that the config contains a valid URL and optional method/timeout settings.
455
+ *
456
+ * @param config - The destination config object to validate
457
+ * @throws {QueueValidationError} If the config is invalid
458
+ */
459
+ export function validateDestinationConfig(config: Record<string, unknown>): void {
460
+ if (!config) {
461
+ throw new QueueValidationError({
462
+ message: 'Destination config is required',
463
+ field: 'config',
464
+ });
465
+ }
466
+
467
+ const url = config.url;
468
+ if (typeof url !== 'string' || !url) {
469
+ throw new QueueValidationError({
470
+ message: 'config.url is required',
471
+ field: 'config.url',
472
+ });
473
+ }
474
+ validateWebhookUrl(url);
475
+
476
+ const method = config.method;
477
+ if (method !== undefined) {
478
+ if (method !== 'POST' && method !== 'PUT' && method !== 'PATCH') {
479
+ throw new QueueValidationError({
480
+ message: 'config.method must be POST, PUT, or PATCH',
481
+ field: 'config.method',
482
+ value: method,
483
+ });
484
+ }
485
+ }
486
+
487
+ const timeoutMs = config.timeout_ms;
488
+ if (timeoutMs !== undefined) {
489
+ if (typeof timeoutMs !== 'number' || timeoutMs < 1000 || timeoutMs > 300000) {
490
+ throw new QueueValidationError({
491
+ message: 'config.timeout_ms must be between 1000 and 300000',
492
+ field: 'config.timeout_ms',
493
+ value: timeoutMs,
494
+ });
495
+ }
496
+ }
497
+ }
498
+
499
+ /**
500
+ * Validates a source ID format.
501
+ *
502
+ * Source IDs must start with the `qsrc_` prefix.
503
+ *
504
+ * @param id - The source ID to validate
505
+ * @throws {QueueValidationError} If the ID format is invalid
506
+ *
507
+ * @example
508
+ * ```typescript
509
+ * validateSourceId('qsrc_abc123'); // OK
510
+ * validateSourceId('invalid'); // Throws
511
+ * ```
512
+ */
513
+ export function validateSourceId(id: string): void {
514
+ if (!id || typeof id !== 'string') {
515
+ throw new QueueValidationError({
516
+ field: 'source_id',
517
+ value: id,
518
+ message: 'Source ID is required',
519
+ });
520
+ }
521
+ if (!VALID_SOURCE_ID_REGEX.test(id)) {
522
+ throw new QueueValidationError({
523
+ field: 'source_id',
524
+ value: id,
525
+ message:
526
+ 'Source ID must start with "qsrc_" prefix and contain only alphanumeric characters',
527
+ });
528
+ }
529
+ }
530
+
531
+ /**
532
+ * Validates a source name.
533
+ *
534
+ * Source names must be non-empty and not exceed the maximum length.
535
+ *
536
+ * @param name - The source name to validate
537
+ * @throws {QueueValidationError} If the name is invalid
538
+ *
539
+ * @example
540
+ * ```typescript
541
+ * validateSourceName('my-source'); // OK
542
+ * validateSourceName(''); // Throws
543
+ * ```
544
+ */
545
+ export function validateSourceName(name: string): void {
546
+ if (!name || typeof name !== 'string') {
547
+ throw new QueueValidationError({
548
+ field: 'source_name',
549
+ value: name,
550
+ message: 'Source name is required',
551
+ });
552
+ }
553
+ if (name.length > MAX_SOURCE_NAME_LENGTH) {
554
+ throw new QueueValidationError({
555
+ field: 'source_name',
556
+ value: name,
557
+ message: `Source name must be at most ${MAX_SOURCE_NAME_LENGTH} characters`,
558
+ });
559
+ }
560
+ }
@@ -58,6 +58,10 @@ const SandboxInfoDataSchema = z
58
58
  snapshotId: z.string().optional().describe('Snapshot ID this sandbox was created from'),
59
59
  snapshotTag: z.string().optional().describe('Snapshot tag this sandbox was created from'),
60
60
  executions: z.number().describe('Total number of executions in this sandbox'),
61
+ exitCode: z
62
+ .number()
63
+ .optional()
64
+ .describe('Exit code from the last execution (only for terminated/failed sandboxes)'),
61
65
  stdoutStreamUrl: z.string().optional().describe('URL for streaming stdout output'),
62
66
  stderrStreamUrl: z.string().optional().describe('URL for streaming stderr output'),
63
67
  dependencies: z
@@ -137,6 +141,7 @@ export async function sandboxGet(
137
141
  snapshotId: resp.data.snapshotId,
138
142
  snapshotTag: resp.data.snapshotTag,
139
143
  executions: resp.data.executions,
144
+ exitCode: resp.data.exitCode,
140
145
  stdoutStreamUrl: resp.data.stdoutStreamUrl,
141
146
  stderrStreamUrl: resp.data.stderrStreamUrl,
142
147
  dependencies: resp.data.dependencies,
@@ -21,7 +21,12 @@ export type {
21
21
  } from './execution';
22
22
  export { SandboxResponseError, writeAndDrain } from './util';
23
23
  export { SandboxClient } from './client';
24
- export type { SandboxClientOptions, SandboxClientRunIO, SandboxInstance, ExecuteOptions } from './client';
24
+ export type {
25
+ SandboxClientOptions,
26
+ SandboxClientRunIO,
27
+ SandboxInstance,
28
+ ExecuteOptions,
29
+ } from './client';
25
30
  export {
26
31
  sandboxWriteFiles,
27
32
  sandboxReadFile,
@@ -55,8 +60,10 @@ export {
55
60
  snapshotList,
56
61
  snapshotDelete,
57
62
  snapshotTag,
63
+ snapshotLineage,
58
64
  snapshotBuildInit,
59
65
  snapshotBuildFinalize,
66
+ snapshotUpload,
60
67
  } from './snapshot';
61
68
  export type {
62
69
  SnapshotInfo,
@@ -67,9 +74,14 @@ export type {
67
74
  SnapshotListResponse,
68
75
  SnapshotDeleteParams,
69
76
  SnapshotTagParams,
77
+ SnapshotLineageParams,
78
+ SnapshotLineageEntry,
79
+ SnapshotLineageResponse,
70
80
  SnapshotBuildInitParams,
71
81
  SnapshotBuildInitResponse,
72
82
  SnapshotBuildFinalizeParams,
83
+ SnapshotUploadParams,
84
+ SnapshotUploadResponse,
73
85
  } from './snapshot';
74
86
  export { SnapshotBuildFileSchema } from './snapshot-build';
75
87
  export type { SnapshotBuildFile } from './snapshot-build';
@@ -138,6 +138,7 @@ export async function sandboxRun(
138
138
  // Poll for sandbox completion in parallel with streaming
139
139
  let attempts = 0;
140
140
  let finalStatus: 'terminated' | 'failed' | null = null;
141
+ let finalExitCode: number | undefined;
141
142
 
142
143
  while (attempts < MAX_POLL_ATTEMPTS) {
143
144
  if (signal?.aborted) {
@@ -156,11 +157,13 @@ export async function sandboxRun(
156
157
 
157
158
  if (sandboxInfo.status === 'terminated') {
158
159
  finalStatus = 'terminated';
160
+ finalExitCode = sandboxInfo.exitCode;
159
161
  break;
160
162
  }
161
163
 
162
164
  if (sandboxInfo.status === 'failed') {
163
165
  finalStatus = 'failed';
166
+ finalExitCode = sandboxInfo.exitCode;
164
167
  break;
165
168
  }
166
169
  } catch {
@@ -179,7 +182,7 @@ export async function sandboxRun(
179
182
  if (finalStatus === 'terminated') {
180
183
  return {
181
184
  sandboxId,
182
- exitCode: 0,
185
+ exitCode: finalExitCode ?? 0,
183
186
  durationMs: Date.now() - started,
184
187
  };
185
188
  }
@@ -187,7 +190,7 @@ export async function sandboxRun(
187
190
  if (finalStatus === 'failed') {
188
191
  return {
189
192
  sandboxId,
190
- exitCode: 1,
193
+ exitCode: finalExitCode ?? 1,
191
194
  durationMs: Date.now() - started,
192
195
  };
193
196
  }
@@ -40,6 +40,10 @@ export const SnapshotBuildFileBaseSchema = z
40
40
  .describe(
41
41
  'User-defined metadata key-value pairs. Use ${VAR} syntax for build-time substitution via --metadata flag'
42
42
  ),
43
+ public: z
44
+ .boolean()
45
+ .optional()
46
+ .describe('Whether to make the snapshot publicly accessible (default: false)'),
43
47
  })
44
48
  .describe('Agentuity Snapshot Build File - defines a reproducible sandbox environment');
45
49