@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,1253 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Queue type schema for validation.
5
+ *
6
+ * - `worker`: Messages are consumed by workers with acknowledgment. Each message is processed by exactly one consumer.
7
+ * - `pubsub`: Messages are broadcast to all subscribers. Multiple consumers can receive the same message.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const queueType = QueueTypeSchema.parse('worker'); // 'worker' | 'pubsub'
12
+ * ```
13
+ */
14
+ export const QueueTypeSchema = z.enum(['worker', 'pubsub']);
15
+
16
+ /**
17
+ * Queue type - either 'worker' for task queues or 'pubsub' for broadcast messaging.
18
+ */
19
+ export type QueueType = z.infer<typeof QueueTypeSchema>;
20
+
21
+ /**
22
+ * Base queue settings schema without defaults - used for partial updates.
23
+ *
24
+ * This schema is used for PATCH operations where we don't want Zod to apply
25
+ * default values for missing fields (which would overwrite existing values).
26
+ */
27
+ const QueueSettingsSchemaBase = z.object({
28
+ /** Default time-to-live for messages in seconds. Null means no expiration. */
29
+ default_ttl_seconds: z.number().nullable().optional(),
30
+ /** Time in seconds a message is invisible after being received. */
31
+ default_visibility_timeout_seconds: z.number().optional(),
32
+ /** Maximum number of delivery attempts before moving to DLQ. */
33
+ default_max_retries: z.number().optional(),
34
+ /** Initial backoff delay in milliseconds for retries. */
35
+ default_retry_backoff_ms: z.number().optional(),
36
+ /** Maximum backoff delay in milliseconds for retries. */
37
+ default_retry_max_backoff_ms: z.number().optional(),
38
+ /** Multiplier for exponential backoff. */
39
+ default_retry_multiplier: z.number().optional(),
40
+ /** Maximum number of messages a single client can process concurrently. */
41
+ max_in_flight_per_client: z.number().optional(),
42
+ /** Retention period for acknowledged messages in seconds. */
43
+ retention_seconds: z.number().optional(),
44
+ });
45
+
46
+ /**
47
+ * Queue settings schema for configuring queue behavior.
48
+ *
49
+ * These settings control message lifecycle, retry behavior, and concurrency limits.
50
+ * This schema includes defaults and is used for output types and documentation.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const settings = QueueSettingsSchema.parse({
55
+ * default_ttl_seconds: 3600, // Messages expire after 1 hour
56
+ * default_visibility_timeout_seconds: 60, // Processing timeout
57
+ * default_max_retries: 3, // Retry failed messages 3 times
58
+ * });
59
+ * ```
60
+ */
61
+ export const QueueSettingsSchema = z.object({
62
+ /** Default time-to-live for messages in seconds. Null means no expiration. */
63
+ default_ttl_seconds: z.number().nullable().optional(),
64
+ /** Time in seconds a message is invisible after being received (default: 30). */
65
+ default_visibility_timeout_seconds: z.number().default(30),
66
+ /** Maximum number of delivery attempts before moving to DLQ (default: 5). */
67
+ default_max_retries: z.number().default(5),
68
+ /** Initial backoff delay in milliseconds for retries (default: 1000). */
69
+ default_retry_backoff_ms: z.number().default(1000),
70
+ /** Maximum backoff delay in milliseconds for retries (default: 60000). */
71
+ default_retry_max_backoff_ms: z.number().default(60000),
72
+ /** Multiplier for exponential backoff (default: 2.0). */
73
+ default_retry_multiplier: z.number().default(2.0),
74
+ /** Maximum number of messages a single client can process concurrently (default: 10). */
75
+ max_in_flight_per_client: z.number().default(10),
76
+ /** Retention period for acknowledged messages in seconds (default: 30 days). */
77
+ retention_seconds: z.number().default(2592000),
78
+ });
79
+
80
+ /**
81
+ * Queue settings configuration type.
82
+ */
83
+ export type QueueSettings = z.infer<typeof QueueSettingsSchema>;
84
+
85
+ /**
86
+ * Queue statistics schema showing current queue state.
87
+ */
88
+ export const QueueStatsSchema = z.object({
89
+ /** Total number of messages currently in the queue. */
90
+ message_count: z.number(),
91
+ /** Number of messages in the dead letter queue. */
92
+ dlq_count: z.number(),
93
+ /** The next offset that will be assigned to a new message. */
94
+ next_offset: z.number(),
95
+ });
96
+
97
+ /**
98
+ * Queue statistics type.
99
+ */
100
+ export type QueueStats = z.infer<typeof QueueStatsSchema>;
101
+
102
+ /**
103
+ * Queue schema representing a message queue.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const queue = await getQueue(client, 'my-queue');
108
+ * console.log(`Queue ${queue.name} has ${queue.message_count} messages`);
109
+ * ```
110
+ */
111
+ export const QueueSchema = z.object({
112
+ /** Unique identifier for the queue. */
113
+ id: z.string(),
114
+ /** Human-readable queue name (used for API operations). */
115
+ name: z.string(),
116
+ /** Optional description of the queue's purpose. */
117
+ description: z.string().nullable().optional(),
118
+ /** The type of queue (worker or pubsub). */
119
+ queue_type: QueueTypeSchema,
120
+ /** Default time-to-live for messages in seconds. Null means no expiration. */
121
+ default_ttl_seconds: z.number().nullable().optional(),
122
+ /** Time in seconds a message is invisible after being received. */
123
+ default_visibility_timeout_seconds: z.number().optional(),
124
+ /** Maximum number of delivery attempts before moving to DLQ. */
125
+ default_max_retries: z.number().optional(),
126
+ /** Initial backoff delay in milliseconds for retries. */
127
+ default_retry_backoff_ms: z.number().optional(),
128
+ /** Maximum backoff delay in milliseconds for retries. */
129
+ default_retry_max_backoff_ms: z.number().optional(),
130
+ /** Multiplier for exponential backoff. */
131
+ default_retry_multiplier: z.number().optional(),
132
+ /** Maximum number of messages a single client can process concurrently. */
133
+ max_in_flight_per_client: z.number().optional(),
134
+ /** The next offset that will be assigned to a new message. */
135
+ next_offset: z.number().optional(),
136
+ /** Total number of messages currently in the queue. */
137
+ message_count: z.number().optional(),
138
+ /** Number of messages in the dead letter queue. */
139
+ dlq_count: z.number().optional(),
140
+ /** ISO 8601 timestamp when the queue was created. */
141
+ created_at: z.string(),
142
+ /** ISO 8601 timestamp when the queue was last updated. */
143
+ updated_at: z.string(),
144
+ /** ISO 8601 timestamp when the queue was paused (null if not paused). */
145
+ paused_at: z.string().nullable().optional(),
146
+ /** Retention period for acknowledged messages in seconds. */
147
+ retention_seconds: z.number().optional(),
148
+ });
149
+
150
+ /**
151
+ * Queue type representing a message queue instance.
152
+ */
153
+ export type Queue = z.infer<typeof QueueSchema>;
154
+
155
+ /**
156
+ * Message state schema for tracking message lifecycle.
157
+ *
158
+ * - `pending`: Message is waiting to be processed.
159
+ * - `leased`: Message has been received and is currently being processed by a consumer.
160
+ * - `processing`: Message has been received and is being processed (legacy, equivalent to leased).
161
+ * - `delivered`: Message was successfully acknowledged.
162
+ * - `failed`: Message processing failed but may be retried.
163
+ * - `dead`: Message exceeded retry limit and was moved to DLQ.
164
+ */
165
+ export const MessageStateSchema = z.enum([
166
+ 'pending',
167
+ 'leased',
168
+ 'processing',
169
+ 'delivered',
170
+ 'failed',
171
+ 'dead',
172
+ ]);
173
+
174
+ /**
175
+ * Message state type.
176
+ */
177
+ export type MessageState = z.infer<typeof MessageStateSchema>;
178
+
179
+ /**
180
+ * Message schema representing a queue message.
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const message = await publishMessage(client, 'my-queue', { payload: 'Hello' });
185
+ * console.log(`Published message ${message.id} at offset ${message.offset}`);
186
+ * ```
187
+ */
188
+ export const MessageSchema = z.object({
189
+ /** Unique identifier for the message (prefixed with msg_). */
190
+ id: z.string(),
191
+ /** ID of the queue this message belongs to. */
192
+ queue_id: z.string(),
193
+ /** Sequential offset within the queue. */
194
+ offset: z.number(),
195
+ /** The message payload (JSON object). */
196
+ payload: z.unknown(),
197
+ /** Size of the message payload in bytes. */
198
+ size: z.number().optional(),
199
+ /** Optional metadata attached to the message. */
200
+ metadata: z.record(z.string(), z.unknown()).nullable().optional(),
201
+ /** Current state of the message. */
202
+ state: MessageStateSchema.optional(),
203
+ /** Optional key for message deduplication. */
204
+ idempotency_key: z.string().nullable().optional(),
205
+ /** Optional key for message ordering. */
206
+ partition_key: z.string().nullable().optional(),
207
+ /** Time-to-live in seconds (null means no expiration). */
208
+ ttl_seconds: z.number().nullable().optional(),
209
+ /** Number of times delivery has been attempted. */
210
+ delivery_attempts: z.number().optional(),
211
+ /** Maximum number of delivery attempts allowed. */
212
+ max_retries: z.number().optional(),
213
+ /** ISO 8601 timestamp when the message was published. */
214
+ published_at: z.string().optional(),
215
+ /** ISO 8601 timestamp when the message will expire (if TTL set). */
216
+ expires_at: z.string().nullable().optional(),
217
+ /** ISO 8601 timestamp when the message was delivered. */
218
+ delivered_at: z.string().nullable().optional(),
219
+ /** ISO 8601 timestamp when the message was acknowledged. */
220
+ acknowledged_at: z.string().nullable().optional(),
221
+ /** ISO 8601 timestamp when the message was created. */
222
+ created_at: z.string().optional(),
223
+ /** ISO 8601 timestamp when the message was last updated. */
224
+ updated_at: z.string().optional(),
225
+ });
226
+
227
+ /**
228
+ * Message type representing a queue message.
229
+ */
230
+ export type Message = z.infer<typeof MessageSchema>;
231
+
232
+ /**
233
+ * Destination type schema. Currently only HTTP webhooks are supported.
234
+ */
235
+ export const DestinationTypeSchema = z.enum(['http']);
236
+
237
+ /**
238
+ * Destination type.
239
+ */
240
+ export type DestinationType = z.infer<typeof DestinationTypeSchema>;
241
+
242
+ /**
243
+ * HTTP destination configuration schema for webhook delivery.
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * const config: HttpDestinationConfig = {
248
+ * url: 'https://api.example.com/webhook',
249
+ * method: 'POST',
250
+ * headers: { 'X-Custom-Header': 'value' },
251
+ * timeout_ms: 10000,
252
+ * retry_policy: { max_attempts: 3 },
253
+ * };
254
+ * ```
255
+ */
256
+ export const HttpDestinationConfigSchema = z.object({
257
+ /** The URL to send messages to. */
258
+ url: z.string(),
259
+ /** Optional custom headers to include in requests. */
260
+ headers: z.record(z.string(), z.string()).optional(),
261
+ /** HTTP method to use (default: POST). */
262
+ method: z.string().default('POST'),
263
+ /** Request timeout in milliseconds (default: 30000). */
264
+ timeout_ms: z.number().default(30000),
265
+ /** Optional retry policy for failed deliveries. */
266
+ retry_policy: z
267
+ .object({
268
+ /** Maximum number of delivery attempts (default: 5). */
269
+ max_attempts: z.number().default(5),
270
+ /** Initial backoff delay in milliseconds (default: 1000). */
271
+ initial_backoff_ms: z.number().default(1000),
272
+ /** Maximum backoff delay in milliseconds (default: 60000). */
273
+ max_backoff_ms: z.number().default(60000),
274
+ /** Backoff multiplier for exponential backoff (default: 2.0). */
275
+ backoff_multiplier: z.number().default(2.0),
276
+ })
277
+ .optional(),
278
+ /** Optional request signing configuration. */
279
+ signing: z
280
+ .object({
281
+ /** Whether signing is enabled (default: false). */
282
+ enabled: z.boolean().default(false),
283
+ /** Secret key for HMAC signing. */
284
+ secret_key: z.string().optional(),
285
+ })
286
+ .optional(),
287
+ });
288
+
289
+ /**
290
+ * HTTP destination configuration type.
291
+ */
292
+ export type HttpDestinationConfig = z.infer<typeof HttpDestinationConfigSchema>;
293
+
294
+ /**
295
+ * Destination statistics schema showing delivery metrics.
296
+ */
297
+ export const DestinationStatsSchema = z.object({
298
+ /** Total number of delivery attempts. */
299
+ total_deliveries: z.number(),
300
+ /** Number of successful deliveries. */
301
+ successful_deliveries: z.number(),
302
+ /** Number of failed deliveries. */
303
+ failed_deliveries: z.number(),
304
+ /** ISO 8601 timestamp of the last delivery attempt. */
305
+ last_delivery_at: z.string().nullable().optional(),
306
+ /** ISO 8601 timestamp of the last successful delivery. */
307
+ last_success_at: z.string().nullable().optional(),
308
+ /** ISO 8601 timestamp of the last failed delivery. */
309
+ last_failure_at: z.string().nullable().optional(),
310
+ });
311
+
312
+ /**
313
+ * Destination statistics type.
314
+ */
315
+ export type DestinationStats = z.infer<typeof DestinationStatsSchema>;
316
+
317
+ /**
318
+ * Destination schema representing a webhook endpoint for message delivery.
319
+ *
320
+ * Destinations are attached to queues and automatically receive messages when published.
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * const destination = await createDestination(client, 'my-queue', {
325
+ * destination_type: 'http',
326
+ * config: { url: 'https://api.example.com/webhook' },
327
+ * enabled: true,
328
+ * });
329
+ * ```
330
+ */
331
+ export const DestinationSchema = z.object({
332
+ /** Unique identifier for the destination (prefixed with dest_). */
333
+ id: z.string(),
334
+ /** ID of the queue this destination is attached to. */
335
+ queue_id: z.string(),
336
+ /** Type of destination (currently only 'http'). */
337
+ destination_type: DestinationTypeSchema,
338
+ /** HTTP configuration for the destination. */
339
+ config: HttpDestinationConfigSchema,
340
+ /** Whether the destination is enabled for delivery. */
341
+ enabled: z.boolean(),
342
+ /** Delivery statistics for this destination. */
343
+ stats: DestinationStatsSchema.optional(),
344
+ /** ISO 8601 timestamp when the destination was created. */
345
+ created_at: z.string(),
346
+ /** ISO 8601 timestamp when the destination was last updated. */
347
+ updated_at: z.string(),
348
+ });
349
+
350
+ /**
351
+ * Destination type representing a webhook endpoint.
352
+ */
353
+ export type Destination = z.infer<typeof DestinationSchema>;
354
+
355
+ /**
356
+ * Dead letter message schema for messages that failed processing.
357
+ *
358
+ * Messages are moved to the dead letter queue (DLQ) after exceeding the maximum
359
+ * retry limit. They can be inspected, replayed, or deleted.
360
+ *
361
+ * @example
362
+ * ```typescript
363
+ * const { messages } = await listDeadLetterMessages(client, 'my-queue');
364
+ * for (const msg of messages) {
365
+ * console.log(`Failed message: ${msg.failure_reason}`);
366
+ * await replayDeadLetterMessage(client, 'my-queue', msg.id);
367
+ * }
368
+ * ```
369
+ */
370
+ export const DeadLetterMessageSchema = z.object({
371
+ /** Unique identifier for the DLQ entry. */
372
+ id: z.string(),
373
+ /** ID of the queue this message belongs to. */
374
+ queue_id: z.string(),
375
+ /** ID of the original message that failed. */
376
+ original_message_id: z.string(),
377
+ /** Offset of the original message in the queue. */
378
+ offset: z.number(),
379
+ /** The message payload (JSON object). */
380
+ payload: z.unknown(),
381
+ /** Optional metadata from the original message. */
382
+ metadata: z.record(z.string(), z.unknown()).nullable().optional(),
383
+ /** Reason why the message was moved to DLQ. */
384
+ failure_reason: z.string().nullable().optional(),
385
+ /** Number of delivery attempts before failure. */
386
+ delivery_attempts: z.number(),
387
+ /** ISO 8601 timestamp when the message was moved to DLQ. */
388
+ moved_at: z.string(),
389
+ /** ISO 8601 timestamp when the original message was published. */
390
+ original_published_at: z.string(),
391
+ /** ISO 8601 timestamp when the DLQ entry was created. */
392
+ created_at: z.string(),
393
+ });
394
+
395
+ /**
396
+ * Dead letter message type.
397
+ */
398
+ export type DeadLetterMessage = z.infer<typeof DeadLetterMessageSchema>;
399
+
400
+ // ============================================================================
401
+ // API Options
402
+ // ============================================================================
403
+
404
+ /**
405
+ * Common options for queue API calls.
406
+ *
407
+ * Used to pass organization context when calling from CLI or other
408
+ * contexts where the org is not implicit in the authentication token.
409
+ */
410
+ export interface QueueApiOptions {
411
+ /**
412
+ * Organization ID for the request.
413
+ * Required when using user authentication (CLI) instead of SDK key.
414
+ */
415
+ orgId?: string;
416
+ }
417
+
418
+ // ============================================================================
419
+ // Request Schemas
420
+ // ============================================================================
421
+
422
+ /**
423
+ * Request schema for creating a new queue.
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * const request: CreateQueueRequest = {
428
+ * name: 'my-worker-queue',
429
+ * queue_type: 'worker',
430
+ * description: 'Processes background jobs',
431
+ * settings: { default_max_retries: 3 },
432
+ * };
433
+ * ```
434
+ */
435
+ export const CreateQueueRequestSchema = z.object({
436
+ /** Optional queue name (auto-generated if not provided). */
437
+ name: z.string().optional(),
438
+ /** Optional description of the queue's purpose. */
439
+ description: z.string().optional(),
440
+ /** Type of queue to create. */
441
+ queue_type: QueueTypeSchema,
442
+ /** Optional settings to customize queue behavior (server applies defaults for missing fields). */
443
+ settings: QueueSettingsSchemaBase.partial().optional(),
444
+ });
445
+
446
+ /** Request type for creating a queue. */
447
+ export type CreateQueueRequest = z.infer<typeof CreateQueueRequestSchema>;
448
+
449
+ /**
450
+ * Request schema for updating an existing queue.
451
+ */
452
+ export const UpdateQueueRequestSchema = z.object({
453
+ /** New description for the queue. */
454
+ description: z.string().optional(),
455
+ /** Settings to update (partial update supported, only provided fields are updated). */
456
+ settings: QueueSettingsSchemaBase.partial().optional(),
457
+ });
458
+
459
+ /** Request type for updating a queue. */
460
+ export type UpdateQueueRequest = z.infer<typeof UpdateQueueRequestSchema>;
461
+
462
+ /**
463
+ * Request schema for listing queues with pagination.
464
+ */
465
+ export const ListQueuesRequestSchema = z.object({
466
+ /** Maximum number of queues to return. */
467
+ limit: z.number().optional(),
468
+ /** Number of queues to skip for pagination. */
469
+ offset: z.number().optional(),
470
+ });
471
+
472
+ /** Request type for listing queues. */
473
+ export type ListQueuesRequest = z.infer<typeof ListQueuesRequestSchema>;
474
+
475
+ /**
476
+ * Request schema for publishing a message to a queue.
477
+ *
478
+ * @example
479
+ * ```typescript
480
+ * const request: PublishMessageRequest = {
481
+ * payload: { task: 'process-order', orderId: 123 },
482
+ * metadata: { priority: 'high' },
483
+ * idempotency_key: 'order-123-v1',
484
+ * ttl_seconds: 3600,
485
+ * };
486
+ * ```
487
+ */
488
+ export const PublishMessageRequestSchema = z.object({
489
+ /** The message payload (JSON object). */
490
+ payload: z.unknown(),
491
+ /** Optional metadata to attach to the message. */
492
+ metadata: z.record(z.string(), z.unknown()).optional(),
493
+ /** Optional key for deduplication (prevents duplicate messages). */
494
+ idempotency_key: z.string().optional(),
495
+ /** Optional key for message ordering within a partition. */
496
+ partition_key: z.string().optional(),
497
+ /** Optional time-to-live in seconds. */
498
+ ttl_seconds: z.number().optional(),
499
+ });
500
+
501
+ /** Request type for publishing a message. */
502
+ export type PublishMessageRequest = z.infer<typeof PublishMessageRequestSchema>;
503
+
504
+ /**
505
+ * Request schema for batch publishing multiple messages.
506
+ *
507
+ * @example
508
+ * ```typescript
509
+ * const request: BatchPublishMessagesRequest = {
510
+ * messages: [
511
+ * { payload: { task: 'a' } },
512
+ * { payload: { task: 'b' } },
513
+ * ],
514
+ * };
515
+ * ```
516
+ */
517
+ export const BatchPublishMessagesRequestSchema = z.object({
518
+ /** Array of messages to publish (max 1000 per batch). */
519
+ messages: z.array(PublishMessageRequestSchema).max(1000),
520
+ });
521
+
522
+ /** Request type for batch publishing messages. */
523
+ export type BatchPublishMessagesRequest = z.infer<typeof BatchPublishMessagesRequestSchema>;
524
+
525
+ /**
526
+ * Request schema for listing messages with pagination and filtering.
527
+ */
528
+ export const ListMessagesRequestSchema = z.object({
529
+ /** Maximum number of messages to return. */
530
+ limit: z.number().optional(),
531
+ /** Number of messages to skip for pagination. */
532
+ offset: z.number().optional(),
533
+ /** Filter messages by state. */
534
+ state: MessageStateSchema.optional(),
535
+ });
536
+
537
+ /** Request type for listing messages. */
538
+ export type ListMessagesRequest = z.infer<typeof ListMessagesRequestSchema>;
539
+
540
+ /**
541
+ * Request schema for consuming messages from a specific offset.
542
+ */
543
+ export const ConsumeMessagesRequestSchema = z.object({
544
+ /** Starting offset to consume from. */
545
+ offset: z.number(),
546
+ /** Maximum number of messages to consume. */
547
+ limit: z.number().optional(),
548
+ });
549
+
550
+ /** Request type for consuming messages. */
551
+ export type ConsumeMessagesRequest = z.infer<typeof ConsumeMessagesRequestSchema>;
552
+
553
+ /**
554
+ * Request schema for creating a destination webhook.
555
+ *
556
+ * @example
557
+ * ```typescript
558
+ * const request: CreateDestinationRequest = {
559
+ * destination_type: 'http',
560
+ * config: {
561
+ * url: 'https://api.example.com/webhook',
562
+ * method: 'POST',
563
+ * },
564
+ * enabled: true,
565
+ * };
566
+ * ```
567
+ */
568
+ export const CreateDestinationRequestSchema = z.object({
569
+ /** Type of destination to create. */
570
+ destination_type: DestinationTypeSchema,
571
+ /** HTTP configuration for the destination. */
572
+ config: HttpDestinationConfigSchema,
573
+ /** Whether the destination should be enabled (default: true). */
574
+ enabled: z.boolean().default(true),
575
+ });
576
+
577
+ /** Request type for creating a destination. */
578
+ export type CreateDestinationRequest = z.infer<typeof CreateDestinationRequestSchema>;
579
+
580
+ /**
581
+ * Request schema for updating a destination.
582
+ */
583
+ export const UpdateDestinationRequestSchema = z.object({
584
+ /** HTTP configuration updates (partial update supported). */
585
+ config: HttpDestinationConfigSchema.partial().optional(),
586
+ /** Enable or disable the destination. */
587
+ enabled: z.boolean().optional(),
588
+ });
589
+
590
+ /** Request type for updating a destination. */
591
+ export type UpdateDestinationRequest = z.infer<typeof UpdateDestinationRequestSchema>;
592
+
593
+ /**
594
+ * Request schema for listing dead letter queue messages with pagination.
595
+ */
596
+ export const ListDlqRequestSchema = z.object({
597
+ /** Maximum number of messages to return. */
598
+ limit: z.number().optional(),
599
+ /** Number of messages to skip for pagination. */
600
+ offset: z.number().optional(),
601
+ });
602
+
603
+ /** Request type for listing DLQ messages. */
604
+ export type ListDlqRequest = z.infer<typeof ListDlqRequestSchema>;
605
+
606
+ // ============================================================================
607
+ // Analytics Types
608
+ // ============================================================================
609
+
610
+ /**
611
+ * Time bucket granularity for analytics queries.
612
+ *
613
+ * - `minute`: 1-minute buckets, max range 24 hours. Best for real-time monitoring.
614
+ * - `hour`: 1-hour buckets, max range 7 days. Best for short-term trend analysis.
615
+ * - `day`: 1-day buckets, max range 90 days. Best for long-term analysis.
616
+ *
617
+ * @example
618
+ * ```typescript
619
+ * const analytics = await getQueueAnalytics(client, 'my-queue', {
620
+ * granularity: 'hour',
621
+ * start: '2026-01-14T00:00:00Z',
622
+ * });
623
+ * ```
624
+ */
625
+ export const AnalyticsGranularitySchema = z.enum(['minute', 'hour', 'day']);
626
+
627
+ /**
628
+ * Time bucket granularity type.
629
+ */
630
+ export type AnalyticsGranularity = z.infer<typeof AnalyticsGranularitySchema>;
631
+
632
+ /**
633
+ * Options for analytics queries.
634
+ *
635
+ * Use these options to filter and configure analytics requests by time range,
636
+ * granularity, and optional filters like project or agent ID.
637
+ *
638
+ * @example
639
+ * ```typescript
640
+ * const options: AnalyticsOptions = {
641
+ * start: '2026-01-14T00:00:00Z',
642
+ * end: '2026-01-15T00:00:00Z',
643
+ * granularity: 'hour',
644
+ * projectId: 'proj_abc123',
645
+ * };
646
+ * const analytics = await getQueueAnalytics(client, 'my-queue', options);
647
+ * ```
648
+ */
649
+ export interface AnalyticsOptions extends QueueApiOptions {
650
+ /**
651
+ * Start of time range in ISO8601 format.
652
+ * @default 24 hours ago
653
+ * @example '2026-01-14T00:00:00Z'
654
+ */
655
+ start?: string;
656
+
657
+ /**
658
+ * End of time range in ISO8601 format.
659
+ * @default Current time
660
+ * @example '2026-01-15T00:00:00Z'
661
+ */
662
+ end?: string;
663
+
664
+ /**
665
+ * Time bucket granularity for aggregation.
666
+ * @default 'hour'
667
+ */
668
+ granularity?: AnalyticsGranularity;
669
+
670
+ /**
671
+ * Filter analytics to messages from a specific project.
672
+ * Only messages with matching `project_id` will be included.
673
+ */
674
+ projectId?: string;
675
+
676
+ /**
677
+ * Filter analytics to messages from a specific agent.
678
+ * Only messages with matching `agent_id` will be included.
679
+ */
680
+ agentId?: string;
681
+ }
682
+
683
+ /**
684
+ * Options for real-time SSE streaming analytics.
685
+ *
686
+ * SSE (Server-Sent Events) streams provide live updates of queue statistics
687
+ * at a configurable interval. The stream stays open until closed by the client.
688
+ *
689
+ * @example
690
+ * ```typescript
691
+ * const stream = streamQueueAnalytics(client, 'my-queue', { interval: 5 });
692
+ * for await (const event of stream) {
693
+ * console.log(`Backlog: ${event.backlog}`);
694
+ * }
695
+ * ```
696
+ */
697
+ export interface StreamAnalyticsOptions extends QueueApiOptions {
698
+ /**
699
+ * Interval between stats updates in seconds.
700
+ * @default 5
701
+ * @minimum 1
702
+ * @maximum 60
703
+ */
704
+ interval?: number;
705
+ }
706
+
707
+ /**
708
+ * Time period for analytics responses.
709
+ *
710
+ * Represents the time range and granularity of the analytics data.
711
+ */
712
+ export const TimePeriodSchema = z.object({
713
+ /** Start of the time period in ISO8601 format. */
714
+ start: z.string(),
715
+ /** End of the time period in ISO8601 format. */
716
+ end: z.string(),
717
+ /** Time bucket granularity used for aggregation. */
718
+ granularity: AnalyticsGranularitySchema.optional(),
719
+ });
720
+
721
+ /**
722
+ * Time period type representing a date range for analytics.
723
+ */
724
+ export type TimePeriod = z.infer<typeof TimePeriodSchema>;
725
+
726
+ /**
727
+ * Latency statistics with percentile distributions.
728
+ *
729
+ * Provides average, percentile (p50, p95, p99), and maximum latency values
730
+ * for message delivery operations.
731
+ *
732
+ * @example
733
+ * ```typescript
734
+ * const { latency } = await getQueueAnalytics(client, 'my-queue');
735
+ * console.log(`Average: ${latency.avg_ms}ms, P95: ${latency.p95_ms}ms`);
736
+ * ```
737
+ */
738
+ export const LatencyStatsSchema = z.object({
739
+ /** Average latency in milliseconds. */
740
+ avg_ms: z.number(),
741
+ /** 50th percentile (median) latency in milliseconds. */
742
+ p50_ms: z.number().optional(),
743
+ /** 95th percentile latency in milliseconds. */
744
+ p95_ms: z.number().optional(),
745
+ /** 99th percentile latency in milliseconds. */
746
+ p99_ms: z.number().optional(),
747
+ /** Maximum observed latency in milliseconds. */
748
+ max_ms: z.number().optional(),
749
+ });
750
+
751
+ /**
752
+ * Latency statistics type.
753
+ */
754
+ export type LatencyStats = z.infer<typeof LatencyStatsSchema>;
755
+
756
+ /**
757
+ * Current real-time queue state.
758
+ *
759
+ * Represents the instantaneous state of a queue, useful for monitoring
760
+ * dashboards and alerting on queue health.
761
+ *
762
+ * @example
763
+ * ```typescript
764
+ * const { current } = await getQueueAnalytics(client, 'my-queue');
765
+ * if (current.backlog > 1000) {
766
+ * console.warn('Queue backlog is high!');
767
+ * }
768
+ * ```
769
+ */
770
+ export const QueueCurrentStatsSchema = z.object({
771
+ /** Number of messages waiting to be processed. */
772
+ backlog: z.number(),
773
+ /** Number of messages in the dead letter queue. */
774
+ dlq_count: z.number(),
775
+ /** Number of messages currently leased by consumers. */
776
+ messages_in_flight: z.number(),
777
+ /** Number of active WebSocket/long-poll consumers. */
778
+ active_consumers: z.number(),
779
+ /** Age in seconds of the oldest pending message (null if queue is empty). */
780
+ oldest_message_age_seconds: z.number().nullable().optional(),
781
+ });
782
+
783
+ /**
784
+ * Current queue state type.
785
+ */
786
+ export type QueueCurrentStats = z.infer<typeof QueueCurrentStatsSchema>;
787
+
788
+ /**
789
+ * Aggregated statistics for a time period.
790
+ *
791
+ * Contains counts and metrics aggregated over the requested time range.
792
+ *
793
+ * @example
794
+ * ```typescript
795
+ * const { period_stats } = await getQueueAnalytics(client, 'my-queue');
796
+ * const successRate = period_stats.messages_acknowledged / period_stats.messages_published;
797
+ * console.log(`Success rate: ${(successRate * 100).toFixed(1)}%`);
798
+ * ```
799
+ */
800
+ export const QueuePeriodStatsSchema = z.object({
801
+ /** Total messages published during the period. */
802
+ messages_published: z.number(),
803
+ /** Total messages delivered to consumers during the period. */
804
+ messages_delivered: z.number(),
805
+ /** Total messages successfully acknowledged during the period. */
806
+ messages_acknowledged: z.number(),
807
+ /** Total messages that failed and moved to DLQ during the period. */
808
+ messages_failed: z.number(),
809
+ /** Total messages replayed from DLQ during the period. */
810
+ messages_replayed: z.number(),
811
+ /** Total bytes of message payloads published during the period. */
812
+ bytes_published: z.number(),
813
+ /** Total delivery attempts (includes retries) during the period. */
814
+ delivery_attempts: z.number(),
815
+ /** Number of retry attempts (delivery_attempts - messages_delivered). */
816
+ retry_count: z.number(),
817
+ });
818
+
819
+ /**
820
+ * Period statistics type.
821
+ */
822
+ export type QueuePeriodStats = z.infer<typeof QueuePeriodStatsSchema>;
823
+
824
+ /**
825
+ * Analytics for a webhook destination.
826
+ *
827
+ * Provides delivery statistics for a configured webhook endpoint.
828
+ *
829
+ * @example
830
+ * ```typescript
831
+ * const { destinations } = await getQueueAnalytics(client, 'my-queue');
832
+ * for (const dest of destinations ?? []) {
833
+ * const successRate = dest.success_count / (dest.success_count + dest.failure_count);
834
+ * console.log(`${dest.url}: ${(successRate * 100).toFixed(1)}% success`);
835
+ * }
836
+ * ```
837
+ */
838
+ export const DestinationAnalyticsSchema = z.object({
839
+ /** Unique destination identifier (prefixed with dest_). */
840
+ id: z.string(),
841
+ /** Destination type (currently only 'http'). */
842
+ type: z.string(),
843
+ /** Webhook URL. */
844
+ url: z.string(),
845
+ /** Total successful deliveries. */
846
+ success_count: z.number(),
847
+ /** Total failed deliveries. */
848
+ failure_count: z.number(),
849
+ /** Average response time in milliseconds. */
850
+ avg_response_time_ms: z.number().optional(),
851
+ /** ISO8601 timestamp of last successful delivery. */
852
+ last_success_at: z.string().nullable().optional(),
853
+ /** ISO8601 timestamp of last failed delivery. */
854
+ last_failure_at: z.string().nullable().optional(),
855
+ });
856
+
857
+ /**
858
+ * Destination analytics type.
859
+ */
860
+ export type DestinationAnalytics = z.infer<typeof DestinationAnalyticsSchema>;
861
+
862
+ /**
863
+ * Complete analytics for a single queue.
864
+ *
865
+ * Provides comprehensive analytics including current state, period statistics,
866
+ * latency metrics, and destination performance.
867
+ *
868
+ * @example
869
+ * ```typescript
870
+ * const analytics = await getQueueAnalytics(client, 'order-processing');
871
+ * console.log(`Queue: ${analytics.queue_name} (${analytics.queue_type})`);
872
+ * console.log(`Backlog: ${analytics.current.backlog}`);
873
+ * console.log(`Published (24h): ${analytics.period_stats.messages_published}`);
874
+ * console.log(`P95 Latency: ${analytics.latency.p95_ms}ms`);
875
+ * ```
876
+ */
877
+ export const QueueAnalyticsSchema = z.object({
878
+ /** Unique queue identifier (prefixed with queue_). */
879
+ queue_id: z.string(),
880
+ /** Human-readable queue name. */
881
+ queue_name: z.string(),
882
+ /** Queue type: 'worker' or 'pubsub'. */
883
+ queue_type: z.string(),
884
+ /** Time period for the analytics data. */
885
+ period: TimePeriodSchema,
886
+ /** Current real-time queue state. */
887
+ current: QueueCurrentStatsSchema,
888
+ /** Aggregated statistics for the time period. */
889
+ period_stats: QueuePeriodStatsSchema,
890
+ /** Message delivery latency statistics. */
891
+ latency: LatencyStatsSchema,
892
+ /** Consumer processing latency (delivery-to-ack time). */
893
+ consumer_latency: LatencyStatsSchema,
894
+ /** Analytics for each configured webhook destination. */
895
+ destinations: z.array(DestinationAnalyticsSchema).optional(),
896
+ });
897
+
898
+ /**
899
+ * Queue analytics type.
900
+ */
901
+ export type QueueAnalytics = z.infer<typeof QueueAnalyticsSchema>;
902
+
903
+ /**
904
+ * Summary statistics for a queue in org-level analytics.
905
+ *
906
+ * Provides a condensed view of queue metrics for listing in dashboards.
907
+ */
908
+ export const QueueSummarySchema = z.object({
909
+ /** Unique queue identifier. */
910
+ id: z.string(),
911
+ /** Human-readable queue name. */
912
+ name: z.string(),
913
+ /** Queue type: 'worker' or 'pubsub'. */
914
+ queue_type: z.string(),
915
+ /** Messages published during the period. */
916
+ messages_published: z.number(),
917
+ /** Messages delivered during the period. */
918
+ messages_delivered: z.number(),
919
+ /** Messages acknowledged during the period. */
920
+ messages_acknowledged: z.number(),
921
+ /** Current pending message count. */
922
+ backlog: z.number(),
923
+ /** Current dead letter queue count. */
924
+ dlq_count: z.number(),
925
+ /** Average delivery latency in milliseconds. */
926
+ avg_latency_ms: z.number(),
927
+ /** Percentage of messages that failed (0-100). */
928
+ error_rate_percent: z.number(),
929
+ });
930
+
931
+ /**
932
+ * Queue summary type for org-level listings.
933
+ */
934
+ export type QueueSummary = z.infer<typeof QueueSummarySchema>;
935
+
936
+ /**
937
+ * Aggregated summary across all queues in an organization.
938
+ *
939
+ * @example
940
+ * ```typescript
941
+ * const { summary } = await getOrgAnalytics(client);
942
+ * console.log(`Total queues: ${summary.total_queues}`);
943
+ * console.log(`Total messages: ${summary.total_messages_published}`);
944
+ * console.log(`Error rate: ${summary.error_rate_percent.toFixed(2)}%`);
945
+ * ```
946
+ */
947
+ export const OrgAnalyticsSummarySchema = z.object({
948
+ /** Total number of queues in the organization. */
949
+ total_queues: z.number(),
950
+ /** Total messages published across all queues. */
951
+ total_messages_published: z.number(),
952
+ /** Total messages delivered across all queues. */
953
+ total_messages_delivered: z.number(),
954
+ /** Total messages acknowledged across all queues. */
955
+ total_messages_acknowledged: z.number(),
956
+ /** Total messages in all dead letter queues. */
957
+ total_dlq_messages: z.number(),
958
+ /** Total bytes published across all queues. */
959
+ total_bytes_published: z.number(),
960
+ /** Average delivery latency across all queues in milliseconds. */
961
+ avg_latency_ms: z.number(),
962
+ /** 95th percentile latency across all queues in milliseconds. */
963
+ p95_latency_ms: z.number(),
964
+ /** Overall error rate as percentage (0-100). */
965
+ error_rate_percent: z.number(),
966
+ });
967
+
968
+ /**
969
+ * Org-level analytics summary type.
970
+ */
971
+ export type OrgAnalyticsSummary = z.infer<typeof OrgAnalyticsSummarySchema>;
972
+
973
+ /**
974
+ * Complete organization-level analytics.
975
+ *
976
+ * Provides an overview of all queues with aggregated metrics and per-queue summaries.
977
+ *
978
+ * @example
979
+ * ```typescript
980
+ * const analytics = await getOrgAnalytics(client);
981
+ * console.log(`Org: ${analytics.org_id}`);
982
+ * console.log(`Queues: ${analytics.summary.total_queues}`);
983
+ * for (const queue of analytics.queues) {
984
+ * console.log(` ${queue.name}: ${queue.backlog} pending`);
985
+ * }
986
+ * ```
987
+ */
988
+ export const OrgAnalyticsSchema = z.object({
989
+ /** Organization identifier. */
990
+ org_id: z.string(),
991
+ /** Time period for the analytics data. */
992
+ period: TimePeriodSchema,
993
+ /** Aggregated summary across all queues. */
994
+ summary: OrgAnalyticsSummarySchema,
995
+ /** Per-queue summary statistics. */
996
+ queues: z.array(QueueSummarySchema),
997
+ });
998
+
999
+ /**
1000
+ * Org-level analytics type.
1001
+ */
1002
+ export type OrgAnalytics = z.infer<typeof OrgAnalyticsSchema>;
1003
+
1004
+ /**
1005
+ * Single data point in a time series.
1006
+ *
1007
+ * Represents metrics for one time bucket (minute, hour, or day).
1008
+ * Used for building charts and visualizing trends over time.
1009
+ *
1010
+ * @example
1011
+ * ```typescript
1012
+ * const { series } = await getQueueTimeSeries(client, 'my-queue', { granularity: 'hour' });
1013
+ * for (const point of series) {
1014
+ * console.log(`${point.timestamp}: ${point.throughput} msg/h, ${point.avg_latency_ms}ms avg`);
1015
+ * }
1016
+ * ```
1017
+ */
1018
+ export const TimeSeriesPointSchema = z.object({
1019
+ /** ISO8601 timestamp for the start of this time bucket. */
1020
+ timestamp: z.string(),
1021
+ /** Messages published during this bucket. */
1022
+ throughput: z.number(),
1023
+ /** Messages delivered during this bucket. */
1024
+ delivery_rate: z.number(),
1025
+ /** Messages acknowledged during this bucket. */
1026
+ ack_rate: z.number(),
1027
+ /** Messages that failed during this bucket. */
1028
+ error_rate: z.number(),
1029
+ /** Average delivery latency in milliseconds for this bucket. */
1030
+ avg_latency_ms: z.number(),
1031
+ /** 95th percentile latency in milliseconds for this bucket. */
1032
+ p95_latency_ms: z.number().optional(),
1033
+ /** Queue backlog at the end of this bucket (snapshot). */
1034
+ backlog: z.number().optional(),
1035
+ /** Messages in flight at the end of this bucket (snapshot). */
1036
+ messages_in_flight: z.number().optional(),
1037
+ });
1038
+
1039
+ /**
1040
+ * Time series data point type.
1041
+ */
1042
+ export type TimeSeriesPoint = z.infer<typeof TimeSeriesPointSchema>;
1043
+
1044
+ /**
1045
+ * Time series analytics data for charting and visualization.
1046
+ *
1047
+ * Contains an array of data points at the requested granularity for building
1048
+ * time-based charts and dashboards.
1049
+ *
1050
+ * @example
1051
+ * ```typescript
1052
+ * const timeseries = await getQueueTimeSeries(client, 'order-processing', {
1053
+ * granularity: 'hour',
1054
+ * start: '2026-01-14T00:00:00Z',
1055
+ * end: '2026-01-15T00:00:00Z',
1056
+ * });
1057
+ *
1058
+ * // Plot throughput over time
1059
+ * const chartData = timeseries.series.map(p => ({
1060
+ * x: new Date(p.timestamp),
1061
+ * y: p.throughput,
1062
+ * }));
1063
+ * ```
1064
+ */
1065
+ export const TimeSeriesDataSchema = z.object({
1066
+ /** Unique queue identifier. */
1067
+ queue_id: z.string(),
1068
+ /** Human-readable queue name. */
1069
+ queue_name: z.string(),
1070
+ /** Time period and granularity for the data. */
1071
+ period: TimePeriodSchema,
1072
+ /** Array of time-bucketed data points. */
1073
+ series: z.array(TimeSeriesPointSchema),
1074
+ });
1075
+
1076
+ /**
1077
+ * Time series data type.
1078
+ */
1079
+ export type TimeSeriesData = z.infer<typeof TimeSeriesDataSchema>;
1080
+
1081
+ /**
1082
+ * Real-time stats event from SSE stream.
1083
+ *
1084
+ * Represents a single snapshot of queue statistics delivered via Server-Sent Events.
1085
+ * Events are pushed at the interval specified when opening the stream.
1086
+ *
1087
+ * @example
1088
+ * ```typescript
1089
+ * const stream = streamQueueAnalytics(client, 'my-queue', { interval: 5 });
1090
+ * for await (const event of stream) {
1091
+ * updateDashboard({
1092
+ * backlog: event.backlog,
1093
+ * throughput: event.throughput_1m,
1094
+ * latency: event.avg_latency_ms,
1095
+ * consumers: event.active_consumers,
1096
+ * });
1097
+ * }
1098
+ * ```
1099
+ */
1100
+ export const SSEStatsEventSchema = z.object({
1101
+ /** ISO8601 timestamp when this snapshot was taken. */
1102
+ timestamp: z.string(),
1103
+ /** Current number of pending messages. */
1104
+ backlog: z.number(),
1105
+ /** Current number of messages being processed. */
1106
+ messages_in_flight: z.number(),
1107
+ /** Messages published in the last minute. */
1108
+ throughput_1m: z.number(),
1109
+ /** Messages delivered in the last minute. */
1110
+ delivery_rate_1m: z.number(),
1111
+ /** Messages that failed in the last minute. */
1112
+ error_rate_1m: z.number(),
1113
+ /** Current average delivery latency in milliseconds. */
1114
+ avg_latency_ms: z.number(),
1115
+ /** Current number of connected consumers. */
1116
+ active_consumers: z.number(),
1117
+ });
1118
+
1119
+ /**
1120
+ * SSE stats event type for real-time streaming.
1121
+ */
1122
+ export type SSEStatsEvent = z.infer<typeof SSEStatsEventSchema>;
1123
+
1124
+ // ============================================================================
1125
+ // Source Types
1126
+ // ============================================================================
1127
+
1128
+ /**
1129
+ * Source authentication type schema.
1130
+ */
1131
+ export const SourceAuthTypeSchema = z.enum(['none', 'basic', 'header']);
1132
+
1133
+ /**
1134
+ * Source authentication type.
1135
+ */
1136
+ export type SourceAuthType = z.infer<typeof SourceAuthTypeSchema>;
1137
+
1138
+ /**
1139
+ * Queue source schema representing an HTTP ingestion endpoint.
1140
+ *
1141
+ * Sources provide public URLs for ingesting data into queues from external sources.
1142
+ * They support various authentication methods to secure access.
1143
+ *
1144
+ * @example
1145
+ * ```typescript
1146
+ * const source = await getSource(client, 'my-queue', 'qsrc_abc123');
1147
+ * console.log(`Source URL: ${source.url}`);
1148
+ * console.log(`Success rate: ${source.success_count}/${source.request_count}`);
1149
+ * ```
1150
+ */
1151
+ export const SourceSchema = z.object({
1152
+ /** Unique identifier for the source (prefixed with qsrc_). */
1153
+ id: z.string(),
1154
+ /** ID of the queue this source publishes to. */
1155
+ queue_id: z.string(),
1156
+ /** Human-readable source name. */
1157
+ name: z.string(),
1158
+ /** Optional description of the source's purpose. */
1159
+ description: z.string().nullable().optional(),
1160
+ /** Authentication type for the public endpoint. */
1161
+ auth_type: SourceAuthTypeSchema,
1162
+ /** Whether the source is enabled. */
1163
+ enabled: z.boolean(),
1164
+ /** Public URL to send data to this source. */
1165
+ url: z.string(),
1166
+ /** Total number of requests received. */
1167
+ request_count: z.number(),
1168
+ /** Number of successful ingestions. */
1169
+ success_count: z.number(),
1170
+ /** Number of failed ingestions. */
1171
+ failure_count: z.number(),
1172
+ /** ISO 8601 timestamp of last request. */
1173
+ last_request_at: z.string().nullable().optional(),
1174
+ /** ISO 8601 timestamp of last success. */
1175
+ last_success_at: z.string().nullable().optional(),
1176
+ /** ISO 8601 timestamp of last failure. */
1177
+ last_failure_at: z.string().nullable().optional(),
1178
+ /** Error message from last failure. */
1179
+ last_failure_error: z.string().nullable().optional(),
1180
+ /** ISO 8601 timestamp when the source was created. */
1181
+ created_at: z.string(),
1182
+ /** ISO 8601 timestamp when the source was last updated. */
1183
+ updated_at: z.string(),
1184
+ });
1185
+
1186
+ /**
1187
+ * Queue source type.
1188
+ */
1189
+ export type Source = z.infer<typeof SourceSchema>;
1190
+
1191
+ /**
1192
+ * Create source request schema.
1193
+ *
1194
+ * @example
1195
+ * ```typescript
1196
+ * const request: CreateSourceRequest = {
1197
+ * name: 'webhook-ingestion',
1198
+ * description: 'Receives webhooks from external service',
1199
+ * auth_type: 'header',
1200
+ * auth_value: 'Bearer my-secret-token',
1201
+ * };
1202
+ * ```
1203
+ */
1204
+ export const CreateSourceRequestSchema = z.object({
1205
+ /** Human-readable name for the source. */
1206
+ name: z.string().min(1).max(256),
1207
+ /** Optional description. */
1208
+ description: z.string().max(1024).optional(),
1209
+ /** Authentication type (default: none). */
1210
+ auth_type: SourceAuthTypeSchema.optional().default('none'),
1211
+ /** Authentication value (format depends on auth_type). */
1212
+ auth_value: z.string().optional(),
1213
+ });
1214
+
1215
+ /**
1216
+ * Create source request type.
1217
+ */
1218
+ export type CreateSourceRequest = z.infer<typeof CreateSourceRequestSchema>;
1219
+
1220
+ /**
1221
+ * Update source request schema.
1222
+ *
1223
+ * All fields are optional - only provided fields will be updated.
1224
+ *
1225
+ * @example
1226
+ * ```typescript
1227
+ * // Disable a source
1228
+ * const request: UpdateSourceRequest = { enabled: false };
1229
+ *
1230
+ * // Update authentication
1231
+ * const request: UpdateSourceRequest = {
1232
+ * auth_type: 'basic',
1233
+ * auth_value: 'user:password',
1234
+ * };
1235
+ * ```
1236
+ */
1237
+ export const UpdateSourceRequestSchema = z.object({
1238
+ /** New name for the source. */
1239
+ name: z.string().min(1).max(256).optional(),
1240
+ /** New description. */
1241
+ description: z.string().max(1024).nullable().optional(),
1242
+ /** New authentication type. */
1243
+ auth_type: SourceAuthTypeSchema.optional(),
1244
+ /** New authentication value. */
1245
+ auth_value: z.string().optional(),
1246
+ /** Whether the source is enabled. */
1247
+ enabled: z.boolean().optional(),
1248
+ });
1249
+
1250
+ /**
1251
+ * Update source request type.
1252
+ */
1253
+ export type UpdateSourceRequest = z.infer<typeof UpdateSourceRequestSchema>;