@shipfox/api-agent-access-dto 20.2.0 → 21.0.0

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.
@@ -0,0 +1,684 @@
1
+ import {z} from 'zod';
2
+ import type {AgentAccessObjectSchema} from './envelope.js';
3
+
4
+ export const AGENT_ACCESS_DEFAULT_PAGE_LIMIT = 50;
5
+ export const AGENT_ACCESS_PAGE_LIMIT_MAX = 100;
6
+ export const AGENT_ACCESS_RESPONSE_MAX_BYTES = 128 * 1024;
7
+ export const AGENT_ACCESS_TEXT_MAX_BYTES = 512;
8
+ export const AGENT_ACCESS_CONNECTION_NAME_MAX_BYTES = 256;
9
+ export const AGENT_ACCESS_DIAGNOSTIC_CODE_MAX_BYTES = 128;
10
+ export const AGENT_ACCESS_DIAGNOSTIC_MESSAGE_MAX_BYTES = 512;
11
+ export const AGENT_ACCESS_DIAGNOSTIC_PATH_MAX_BYTES = 512;
12
+ export const AGENT_ACCESS_DIAGNOSTIC_MAX_ITEMS = 10;
13
+ export const AGENT_ACCESS_ANNOTATION_BODY_MAX_BYTES = 8 * 1024;
14
+
15
+ const idSchema = z.string().uuid();
16
+ const dateTimeSchema = z.string().datetime();
17
+ const utf8Encoder = new TextEncoder();
18
+ const utf8CappedString = (maxBytes: number) =>
19
+ z
20
+ .string()
21
+ .max(maxBytes)
22
+ .refine((value) => utf8Encoder.encode(value).byteLength <= maxBytes, {
23
+ message: `String must contain at most ${maxBytes} UTF-8 bytes`,
24
+ });
25
+ const pageInputFields = {
26
+ limit: z
27
+ .number()
28
+ .int()
29
+ .min(1)
30
+ .max(AGENT_ACCESS_PAGE_LIMIT_MAX)
31
+ .default(AGENT_ACCESS_DEFAULT_PAGE_LIMIT),
32
+ cursor: z.string().min(1).optional(),
33
+ };
34
+ const cappedInputTextSchema = utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES);
35
+
36
+ export const listProjectsInputSchema = z.object(pageInputFields).strict();
37
+
38
+ export const listWorkflowDefinitionsInputSchema = z
39
+ .object({
40
+ project_id: idSchema,
41
+ ...pageInputFields,
42
+ })
43
+ .strict();
44
+
45
+ const workflowRunStatusSchema = z.enum(['pending', 'running', 'succeeded', 'failed', 'cancelled']);
46
+ const workflowRunOriginSchema = z.enum(['synced', 'dev']);
47
+ const AGENT_ACCESS_ATTEMPT_MAX = 2_147_483_647;
48
+ const WORKFLOW_RUN_DATE_WINDOW_MAX_MS = 365 * 24 * 60 * 60 * 1000;
49
+
50
+ export const listWorkflowRunsInputSchema = z
51
+ .object({
52
+ project_id: idSchema,
53
+ status: workflowRunStatusSchema.optional(),
54
+ definition_id: idSchema.optional(),
55
+ origin: workflowRunOriginSchema.optional(),
56
+ trigger_source: cappedInputTextSchema.optional(),
57
+ created_from: dateTimeSchema.optional(),
58
+ created_to: dateTimeSchema.optional(),
59
+ ...pageInputFields,
60
+ })
61
+ .superRefine((value, context) => {
62
+ if (
63
+ value.created_from !== undefined &&
64
+ value.created_to !== undefined &&
65
+ new Date(value.created_from) > new Date(value.created_to)
66
+ ) {
67
+ context.addIssue({
68
+ code: 'custom',
69
+ path: ['created_from'],
70
+ message: 'created_from must be before or equal to created_to',
71
+ });
72
+ } else if (
73
+ value.created_from !== undefined &&
74
+ value.created_to !== undefined &&
75
+ new Date(value.created_to).getTime() - new Date(value.created_from).getTime() >
76
+ WORKFLOW_RUN_DATE_WINDOW_MAX_MS
77
+ ) {
78
+ context.addIssue({
79
+ code: 'custom',
80
+ path: ['created_to'],
81
+ message: 'created date window must be 365 days or less',
82
+ });
83
+ }
84
+ })
85
+ .strict();
86
+
87
+ export const getRunAnnotationsInputSchema = z
88
+ .object({
89
+ run_id: idSchema,
90
+ attempt: z.number().int().min(1).max(AGENT_ACCESS_ATTEMPT_MAX).optional(),
91
+ job_execution_id: idSchema.optional(),
92
+ ...pageInputFields,
93
+ })
94
+ .strict();
95
+
96
+ const triggerEventOriginSchema = z.enum(['integration', 'manual', 'cron', 'dev']);
97
+ const triggerEventOutcomeSchema = z.enum(['received', 'routed', 'discarded', 'failed', 'errored']);
98
+
99
+ export const listTriggerEventsInputSchema = z
100
+ .object({
101
+ source: z.array(cappedInputTextSchema).optional(),
102
+ event: z.array(cappedInputTextSchema).optional(),
103
+ origin: z.array(triggerEventOriginSchema).optional(),
104
+ outcome: z.array(triggerEventOutcomeSchema).optional(),
105
+ replayable: z.literal(true).optional(),
106
+ from: dateTimeSchema.optional(),
107
+ to: dateTimeSchema.optional(),
108
+ ...pageInputFields,
109
+ })
110
+ .superRefine((value, context) => {
111
+ if (
112
+ value.from !== undefined &&
113
+ value.to !== undefined &&
114
+ new Date(value.from) > new Date(value.to)
115
+ ) {
116
+ context.addIssue({
117
+ code: 'custom',
118
+ path: ['from'],
119
+ message: 'from must be before or equal to to',
120
+ });
121
+ }
122
+ })
123
+ .strict();
124
+
125
+ export type ListProjectsInputDto = z.output<typeof listProjectsInputSchema>;
126
+ export type ListWorkflowDefinitionsInputDto = z.output<typeof listWorkflowDefinitionsInputSchema>;
127
+ export type ListWorkflowRunsInputDto = z.output<typeof listWorkflowRunsInputSchema>;
128
+ export type GetRunAnnotationsInputDto = z.output<typeof getRunAnnotationsInputSchema>;
129
+ export type ListTriggerEventsInputDto = z.output<typeof listTriggerEventsInputSchema>;
130
+
131
+ const dateTime = {type: 'string', format: 'date-time'} as const;
132
+ const pageInputJsonProperties = {
133
+ limit: {
134
+ type: 'integer',
135
+ minimum: 1,
136
+ maximum: AGENT_ACCESS_PAGE_LIMIT_MAX,
137
+ default: AGENT_ACCESS_DEFAULT_PAGE_LIMIT,
138
+ },
139
+ cursor: {type: 'string', minLength: 1},
140
+ } as const;
141
+
142
+ export const listProjectsInputJsonSchema = {
143
+ type: 'object',
144
+ properties: pageInputJsonProperties,
145
+ additionalProperties: false,
146
+ } as const satisfies AgentAccessObjectSchema;
147
+
148
+ export const listWorkflowDefinitionsInputJsonSchema = {
149
+ type: 'object',
150
+ properties: {
151
+ project_id: {type: 'string', format: 'uuid'},
152
+ ...pageInputJsonProperties,
153
+ },
154
+ required: ['project_id'],
155
+ additionalProperties: false,
156
+ } as const satisfies AgentAccessObjectSchema;
157
+
158
+ export const listWorkflowRunsInputJsonSchema = {
159
+ type: 'object',
160
+ properties: {
161
+ project_id: {type: 'string', format: 'uuid'},
162
+ status: {
163
+ type: 'string',
164
+ enum: ['pending', 'running', 'succeeded', 'failed', 'cancelled'],
165
+ },
166
+ definition_id: {type: 'string', format: 'uuid'},
167
+ origin: {type: 'string', enum: ['synced', 'dev']},
168
+ trigger_source: {type: 'string', maxLength: AGENT_ACCESS_TEXT_MAX_BYTES},
169
+ created_from: dateTime,
170
+ created_to: dateTime,
171
+ ...pageInputJsonProperties,
172
+ },
173
+ required: ['project_id'],
174
+ additionalProperties: false,
175
+ } as const satisfies AgentAccessObjectSchema;
176
+
177
+ export const getRunAnnotationsInputJsonSchema = {
178
+ type: 'object',
179
+ properties: {
180
+ run_id: {type: 'string', format: 'uuid'},
181
+ attempt: {type: 'integer', minimum: 1, maximum: AGENT_ACCESS_ATTEMPT_MAX},
182
+ job_execution_id: {type: 'string', format: 'uuid'},
183
+ ...pageInputJsonProperties,
184
+ },
185
+ required: ['run_id'],
186
+ additionalProperties: false,
187
+ } as const satisfies AgentAccessObjectSchema;
188
+
189
+ export const listTriggerEventsInputJsonSchema = {
190
+ type: 'object',
191
+ properties: {
192
+ source: {
193
+ type: 'array',
194
+ items: {type: 'string', maxLength: AGENT_ACCESS_TEXT_MAX_BYTES},
195
+ },
196
+ event: {
197
+ type: 'array',
198
+ items: {type: 'string', maxLength: AGENT_ACCESS_TEXT_MAX_BYTES},
199
+ },
200
+ origin: {
201
+ type: 'array',
202
+ items: {type: 'string', enum: ['integration', 'manual', 'cron', 'dev']},
203
+ },
204
+ outcome: {
205
+ type: 'array',
206
+ items: {type: 'string', enum: ['received', 'routed', 'discarded', 'failed', 'errored']},
207
+ },
208
+ replayable: {const: true},
209
+ from: dateTime,
210
+ to: dateTime,
211
+ ...pageInputJsonProperties,
212
+ },
213
+ additionalProperties: false,
214
+ } as const satisfies AgentAccessObjectSchema;
215
+
216
+ const projectResultItemSchema = z
217
+ .object({
218
+ id: idSchema,
219
+ name: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
220
+ slug: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
221
+ created_at: dateTimeSchema,
222
+ updated_at: dateTimeSchema,
223
+ })
224
+ .strict();
225
+
226
+ export const listProjectsResultSchema = z
227
+ .object({
228
+ projects: z.array(projectResultItemSchema),
229
+ next_cursor: z.string().nullable(),
230
+ })
231
+ .strict();
232
+
233
+ const definitionDiagnosticSchema = z
234
+ .object({
235
+ severity: z.enum(['error', 'warning']),
236
+ code: utf8CappedString(AGENT_ACCESS_DIAGNOSTIC_CODE_MAX_BYTES),
237
+ message: utf8CappedString(AGENT_ACCESS_DIAGNOSTIC_MESSAGE_MAX_BYTES),
238
+ path: utf8CappedString(AGENT_ACCESS_DIAGNOSTIC_PATH_MAX_BYTES).optional(),
239
+ file_path: utf8CappedString(AGENT_ACCESS_DIAGNOSTIC_PATH_MAX_BYTES).optional(),
240
+ })
241
+ .strict();
242
+
243
+ const definitionSyncErrorCodes = [
244
+ 'no-workflow-files',
245
+ 'invalid-definition',
246
+ 'provider-repository-not-found',
247
+ 'provider-file-not-found',
248
+ 'provider-access-denied',
249
+ 'provider-rate-limited',
250
+ 'provider-timeout',
251
+ 'provider-unavailable',
252
+ 'provider-malformed-response',
253
+ 'content-too-large',
254
+ 'too-many-files',
255
+ 'connection-unavailable',
256
+ 'unknown',
257
+ ] as const;
258
+ const definitionSyncErrorCodeSchema = z.enum(definitionSyncErrorCodes);
259
+
260
+ const definitionDiagnosticsSummarySchema = z
261
+ .object({
262
+ error_count: z.number().int().nonnegative(),
263
+ warning_count: z.number().int().nonnegative(),
264
+ items: z.array(definitionDiagnosticSchema).max(AGENT_ACCESS_DIAGNOSTIC_MAX_ITEMS),
265
+ })
266
+ .strict();
267
+
268
+ const definitionSyncSchema = z
269
+ .object({
270
+ ref: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
271
+ status: z.enum(['pending', 'syncing', 'succeeded', 'failed']),
272
+ last_sync_at: dateTimeSchema,
273
+ started_at: dateTimeSchema.nullable(),
274
+ finished_at: dateTimeSchema.nullable(),
275
+ last_error_code: definitionSyncErrorCodeSchema.nullable(),
276
+ last_error_message: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
277
+ diagnostics: definitionDiagnosticsSummarySchema,
278
+ })
279
+ .strict();
280
+
281
+ const definitionResultItemSchema = z
282
+ .object({
283
+ id: idSchema,
284
+ project_id: idSchema,
285
+ name: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
286
+ config_path: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
287
+ source: z.enum(['manual', 'vcs']),
288
+ ref: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
289
+ sha: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
290
+ })
291
+ .strict();
292
+
293
+ export const listWorkflowDefinitionsResultSchema = z
294
+ .object({
295
+ definitions: z.array(definitionResultItemSchema),
296
+ sync: definitionSyncSchema.nullable(),
297
+ next_cursor: z.string().nullable(),
298
+ })
299
+ .strict();
300
+
301
+ const runDevSourceSchema = z
302
+ .object({
303
+ ref: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
304
+ commit: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
305
+ config_path: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
306
+ initiated_by_user_id: idSchema,
307
+ replay_of_event_id: idSchema.nullable(),
308
+ })
309
+ .strict();
310
+
311
+ const runTriggerReferenceSchema = z
312
+ .object({
313
+ repository: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
314
+ ref: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
315
+ commit: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
316
+ actor: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
317
+ })
318
+ .strict();
319
+
320
+ const jobStatusCountSchema = z
321
+ .object({
322
+ status: z.enum(['pending', 'running', 'succeeded', 'failed', 'cancelled', 'skipped']),
323
+ count: z.number().int().positive(),
324
+ })
325
+ .strict();
326
+
327
+ const runResultItemSchema = z
328
+ .object({
329
+ id: idSchema,
330
+ project_id: idSchema,
331
+ definition_id: idSchema,
332
+ number: z.number().int().positive(),
333
+ name: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
334
+ workflow_name: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
335
+ status: z.enum(['pending', 'running', 'succeeded', 'failed', 'cancelled']),
336
+ origin: z.enum(['synced', 'dev']),
337
+ dev_source: runDevSourceSchema.nullable(),
338
+ current_attempt: z.number().int().positive(),
339
+ latest_attempt: z.number().int().positive(),
340
+ trigger_provider: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
341
+ trigger_source: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
342
+ trigger_event: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
343
+ trigger_reference: runTriggerReferenceSchema.nullable(),
344
+ job_status_counts: z.array(jobStatusCountSchema),
345
+ has_started_job_execution: z.boolean(),
346
+ created_at: dateTimeSchema,
347
+ updated_at: dateTimeSchema,
348
+ started_at: dateTimeSchema.nullable(),
349
+ finished_at: dateTimeSchema.nullable(),
350
+ })
351
+ .strict();
352
+
353
+ export const listWorkflowRunsResultSchema = z
354
+ .object({
355
+ runs: z.array(runResultItemSchema),
356
+ next_cursor: z.string().nullable(),
357
+ filtered_total_count: z.number().int().nonnegative().nullable(),
358
+ })
359
+ .strict();
360
+
361
+ const annotationResultItemSchema = z
362
+ .object({
363
+ id: idSchema,
364
+ origin_step_id: idSchema,
365
+ origin_step_attempt: z.number().int().min(1),
366
+ job_execution_id: idSchema,
367
+ sequence: z.number().int().min(1),
368
+ created_at: dateTimeSchema,
369
+ body: utf8CappedString(AGENT_ACCESS_ANNOTATION_BODY_MAX_BYTES),
370
+ body_truncated: z.literal(true).optional(),
371
+ body_total_bytes: z.number().int().nonnegative().optional(),
372
+ })
373
+ .strict();
374
+
375
+ export const getRunAnnotationsResultSchema = z
376
+ .object({
377
+ annotations: z.array(annotationResultItemSchema),
378
+ next_cursor: z.string().nullable(),
379
+ })
380
+ .strict();
381
+
382
+ const triggerEventResultItemSchema = z
383
+ .object({
384
+ id: idSchema,
385
+ origin: z.enum(['integration', 'manual', 'cron', 'dev']),
386
+ provider: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES).nullable(),
387
+ source: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
388
+ event: utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES),
389
+ outcome: z.enum(['received', 'routed', 'discarded', 'failed', 'errored']),
390
+ matched_count: z.number().int().nonnegative(),
391
+ connection_id: idSchema.nullable(),
392
+ connection_name: utf8CappedString(AGENT_ACCESS_CONNECTION_NAME_MAX_BYTES).nullable(),
393
+ replay_of_event_id: idSchema.nullable(),
394
+ received_at: dateTimeSchema,
395
+ processed_at: dateTimeSchema.nullable(),
396
+ })
397
+ .strict();
398
+
399
+ export const listTriggerEventsResultSchema = z
400
+ .object({
401
+ trigger_events: z.array(triggerEventResultItemSchema),
402
+ next_cursor: z.string().nullable(),
403
+ })
404
+ .strict();
405
+
406
+ export type ListProjectsResultDto = z.infer<typeof listProjectsResultSchema>;
407
+ export type ListWorkflowDefinitionsResultDto = z.infer<typeof listWorkflowDefinitionsResultSchema>;
408
+ export type ListWorkflowRunsResultDto = z.infer<typeof listWorkflowRunsResultSchema>;
409
+ export type GetRunAnnotationsResultDto = z.infer<typeof getRunAnnotationsResultSchema>;
410
+ export type ListTriggerEventsResultDto = z.infer<typeof listTriggerEventsResultSchema>;
411
+
412
+ const uuid = {type: 'string', format: 'uuid'} as const;
413
+ const cappedText = {type: 'string', maxLength: AGENT_ACCESS_TEXT_MAX_BYTES} as const;
414
+ const diagnostic = {
415
+ type: 'object',
416
+ properties: {
417
+ severity: {type: 'string', enum: ['error', 'warning']},
418
+ code: {type: 'string', maxLength: AGENT_ACCESS_DIAGNOSTIC_CODE_MAX_BYTES},
419
+ message: {type: 'string', maxLength: AGENT_ACCESS_DIAGNOSTIC_MESSAGE_MAX_BYTES},
420
+ path: {type: 'string', maxLength: AGENT_ACCESS_DIAGNOSTIC_PATH_MAX_BYTES},
421
+ file_path: {type: 'string', maxLength: AGENT_ACCESS_DIAGNOSTIC_PATH_MAX_BYTES},
422
+ },
423
+ required: ['severity', 'code', 'message'],
424
+ additionalProperties: false,
425
+ } as const;
426
+ const nullable = (schema: Record<string, unknown>) => ({anyOf: [schema, {type: 'null'}]}) as const;
427
+
428
+ const projectResultJsonSchema = {
429
+ type: 'object',
430
+ properties: {
431
+ id: uuid,
432
+ name: cappedText,
433
+ slug: cappedText,
434
+ created_at: dateTime,
435
+ updated_at: dateTime,
436
+ },
437
+ required: ['id', 'name', 'slug', 'created_at', 'updated_at'],
438
+ additionalProperties: false,
439
+ } as const;
440
+
441
+ export const listProjectsResultJsonSchema = {
442
+ type: 'object',
443
+ properties: {
444
+ projects: {type: 'array', items: projectResultJsonSchema},
445
+ next_cursor: nullable({type: 'string'}),
446
+ },
447
+ required: ['projects', 'next_cursor'],
448
+ additionalProperties: false,
449
+ } as const;
450
+
451
+ const definitionResultJsonSchema = {
452
+ type: 'object',
453
+ properties: {
454
+ id: uuid,
455
+ project_id: uuid,
456
+ name: cappedText,
457
+ config_path: nullable(cappedText),
458
+ source: {type: 'string', enum: ['manual', 'vcs']},
459
+ ref: nullable(cappedText),
460
+ sha: nullable(cappedText),
461
+ },
462
+ required: ['id', 'project_id', 'name', 'config_path', 'source', 'ref', 'sha'],
463
+ additionalProperties: false,
464
+ } as const;
465
+
466
+ const definitionSyncJsonSchema = {
467
+ type: 'object',
468
+ properties: {
469
+ ref: nullable(cappedText),
470
+ status: {type: 'string', enum: ['pending', 'syncing', 'succeeded', 'failed']},
471
+ last_sync_at: dateTime,
472
+ started_at: nullable(dateTime),
473
+ finished_at: nullable(dateTime),
474
+ last_error_code: nullable({type: 'string', enum: definitionSyncErrorCodes}),
475
+ last_error_message: nullable(cappedText),
476
+ diagnostics: {
477
+ type: 'object',
478
+ properties: {
479
+ error_count: {type: 'integer', minimum: 0},
480
+ warning_count: {type: 'integer', minimum: 0},
481
+ items: {type: 'array', maxItems: AGENT_ACCESS_DIAGNOSTIC_MAX_ITEMS, items: diagnostic},
482
+ },
483
+ required: ['error_count', 'warning_count', 'items'],
484
+ additionalProperties: false,
485
+ },
486
+ },
487
+ required: [
488
+ 'ref',
489
+ 'status',
490
+ 'last_sync_at',
491
+ 'started_at',
492
+ 'finished_at',
493
+ 'last_error_code',
494
+ 'last_error_message',
495
+ 'diagnostics',
496
+ ],
497
+ additionalProperties: false,
498
+ } as const;
499
+
500
+ export const listWorkflowDefinitionsResultJsonSchema = {
501
+ type: 'object',
502
+ properties: {
503
+ definitions: {type: 'array', items: definitionResultJsonSchema},
504
+ sync: nullable(definitionSyncJsonSchema),
505
+ next_cursor: nullable({type: 'string'}),
506
+ },
507
+ required: ['definitions', 'sync', 'next_cursor'],
508
+ additionalProperties: false,
509
+ } as const;
510
+
511
+ const runDevSourceJsonSchema = {
512
+ type: 'object',
513
+ properties: {
514
+ ref: cappedText,
515
+ commit: cappedText,
516
+ config_path: cappedText,
517
+ initiated_by_user_id: uuid,
518
+ replay_of_event_id: nullable(uuid),
519
+ },
520
+ required: ['ref', 'commit', 'config_path', 'initiated_by_user_id', 'replay_of_event_id'],
521
+ additionalProperties: false,
522
+ } as const;
523
+ const runTriggerReferenceJsonSchema = {
524
+ type: 'object',
525
+ properties: {
526
+ repository: nullable(cappedText),
527
+ ref: nullable(cappedText),
528
+ commit: nullable(cappedText),
529
+ actor: nullable(cappedText),
530
+ },
531
+ required: ['repository', 'ref', 'commit', 'actor'],
532
+ additionalProperties: false,
533
+ } as const;
534
+ const jobStatusCountJsonSchema = {
535
+ type: 'object',
536
+ properties: {
537
+ status: {
538
+ type: 'string',
539
+ enum: ['pending', 'running', 'succeeded', 'failed', 'cancelled', 'skipped'],
540
+ },
541
+ count: {type: 'integer', minimum: 1},
542
+ },
543
+ required: ['status', 'count'],
544
+ additionalProperties: false,
545
+ } as const;
546
+ const runResultJsonSchema = {
547
+ type: 'object',
548
+ properties: {
549
+ id: uuid,
550
+ project_id: uuid,
551
+ definition_id: uuid,
552
+ number: {type: 'integer', minimum: 1},
553
+ name: cappedText,
554
+ workflow_name: cappedText,
555
+ status: {type: 'string', enum: ['pending', 'running', 'succeeded', 'failed', 'cancelled']},
556
+ origin: {type: 'string', enum: ['synced', 'dev']},
557
+ dev_source: nullable(runDevSourceJsonSchema),
558
+ current_attempt: {type: 'integer', minimum: 1},
559
+ latest_attempt: {type: 'integer', minimum: 1},
560
+ trigger_provider: nullable(cappedText),
561
+ trigger_source: cappedText,
562
+ trigger_event: cappedText,
563
+ trigger_reference: nullable(runTriggerReferenceJsonSchema),
564
+ job_status_counts: {type: 'array', items: jobStatusCountJsonSchema},
565
+ has_started_job_execution: {type: 'boolean'},
566
+ created_at: dateTime,
567
+ updated_at: dateTime,
568
+ started_at: nullable(dateTime),
569
+ finished_at: nullable(dateTime),
570
+ },
571
+ required: [
572
+ 'id',
573
+ 'project_id',
574
+ 'definition_id',
575
+ 'number',
576
+ 'name',
577
+ 'workflow_name',
578
+ 'status',
579
+ 'origin',
580
+ 'dev_source',
581
+ 'current_attempt',
582
+ 'latest_attempt',
583
+ 'trigger_provider',
584
+ 'trigger_source',
585
+ 'trigger_event',
586
+ 'trigger_reference',
587
+ 'job_status_counts',
588
+ 'has_started_job_execution',
589
+ 'created_at',
590
+ 'updated_at',
591
+ 'started_at',
592
+ 'finished_at',
593
+ ],
594
+ additionalProperties: false,
595
+ } as const;
596
+
597
+ export const listWorkflowRunsResultJsonSchema = {
598
+ type: 'object',
599
+ properties: {
600
+ runs: {type: 'array', items: runResultJsonSchema},
601
+ next_cursor: nullable({type: 'string'}),
602
+ filtered_total_count: nullable({type: 'integer', minimum: 0}),
603
+ },
604
+ required: ['runs', 'next_cursor', 'filtered_total_count'],
605
+ additionalProperties: false,
606
+ } as const;
607
+
608
+ const annotationResultJsonSchema = {
609
+ type: 'object',
610
+ properties: {
611
+ id: uuid,
612
+ origin_step_id: uuid,
613
+ origin_step_attempt: {type: 'integer', minimum: 1},
614
+ job_execution_id: uuid,
615
+ sequence: {type: 'integer', minimum: 1},
616
+ created_at: dateTime,
617
+ body: {type: 'string', maxLength: AGENT_ACCESS_ANNOTATION_BODY_MAX_BYTES},
618
+ body_truncated: {const: true},
619
+ body_total_bytes: {type: 'integer', minimum: 0},
620
+ },
621
+ required: [
622
+ 'id',
623
+ 'origin_step_id',
624
+ 'origin_step_attempt',
625
+ 'job_execution_id',
626
+ 'sequence',
627
+ 'created_at',
628
+ 'body',
629
+ ],
630
+ additionalProperties: false,
631
+ } as const;
632
+
633
+ export const getRunAnnotationsResultJsonSchema = {
634
+ type: 'object',
635
+ properties: {
636
+ annotations: {type: 'array', items: annotationResultJsonSchema},
637
+ next_cursor: nullable({type: 'string'}),
638
+ },
639
+ required: ['annotations', 'next_cursor'],
640
+ additionalProperties: false,
641
+ } as const;
642
+
643
+ const triggerEventResultJsonSchema = {
644
+ type: 'object',
645
+ properties: {
646
+ id: uuid,
647
+ origin: {type: 'string', enum: ['integration', 'manual', 'cron', 'dev']},
648
+ provider: nullable(cappedText),
649
+ source: cappedText,
650
+ event: cappedText,
651
+ outcome: {type: 'string', enum: ['received', 'routed', 'discarded', 'failed', 'errored']},
652
+ matched_count: {type: 'integer', minimum: 0},
653
+ connection_id: nullable(uuid),
654
+ connection_name: nullable({type: 'string', maxLength: AGENT_ACCESS_CONNECTION_NAME_MAX_BYTES}),
655
+ replay_of_event_id: nullable(uuid),
656
+ received_at: dateTime,
657
+ processed_at: nullable(dateTime),
658
+ },
659
+ required: [
660
+ 'id',
661
+ 'origin',
662
+ 'provider',
663
+ 'source',
664
+ 'event',
665
+ 'outcome',
666
+ 'matched_count',
667
+ 'connection_id',
668
+ 'connection_name',
669
+ 'replay_of_event_id',
670
+ 'received_at',
671
+ 'processed_at',
672
+ ],
673
+ additionalProperties: false,
674
+ } as const;
675
+
676
+ export const listTriggerEventsResultJsonSchema = {
677
+ type: 'object',
678
+ properties: {
679
+ trigger_events: {type: 'array', items: triggerEventResultJsonSchema},
680
+ next_cursor: nullable({type: 'string'}),
681
+ },
682
+ required: ['trigger_events', 'next_cursor'],
683
+ additionalProperties: false,
684
+ } as const;