@shipfox/api-agent-access-dto 20.3.0 → 21.1.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.
Files changed (41) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +14 -0
  3. package/dist/index.d.ts +4 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +4 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/schemas/diagnostic-tools.d.ts +322 -0
  8. package/dist/schemas/diagnostic-tools.d.ts.map +1 -0
  9. package/dist/schemas/diagnostic-tools.js +325 -0
  10. package/dist/schemas/diagnostic-tools.js.map +1 -0
  11. package/dist/schemas/log-tools.d.ts +215 -0
  12. package/dist/schemas/log-tools.d.ts.map +1 -0
  13. package/dist/schemas/log-tools.js +224 -0
  14. package/dist/schemas/log-tools.js.map +1 -0
  15. package/dist/schemas/paged-tools.d.ts.map +1 -1
  16. package/dist/schemas/paged-tools.js +1 -6
  17. package/dist/schemas/paged-tools.js.map +1 -1
  18. package/dist/schemas/primitives.d.ts +5 -0
  19. package/dist/schemas/primitives.d.ts.map +1 -0
  20. package/dist/schemas/primitives.js +9 -0
  21. package/dist/schemas/primitives.js.map +1 -0
  22. package/dist/schemas/workflow-diagnostics.d.ts +862 -0
  23. package/dist/schemas/workflow-diagnostics.d.ts.map +1 -0
  24. package/dist/schemas/workflow-diagnostics.js +876 -0
  25. package/dist/schemas/workflow-diagnostics.js.map +1 -0
  26. package/dist/schemas/workflow-tools.d.ts +1305 -0
  27. package/dist/schemas/workflow-tools.d.ts.map +1 -0
  28. package/dist/schemas/workflow-tools.js +938 -0
  29. package/dist/schemas/workflow-tools.js.map +1 -0
  30. package/dist/tsconfig.test.tsbuildinfo +1 -1
  31. package/package.json +3 -2
  32. package/src/index.ts +115 -0
  33. package/src/schemas/diagnostic-tools.ts +255 -0
  34. package/src/schemas/log-tools.ts +209 -0
  35. package/src/schemas/paged-tools.ts +1 -10
  36. package/src/schemas/primitives.ts +14 -0
  37. package/src/schemas/workflow-diagnostics.test.ts +277 -0
  38. package/src/schemas/workflow-diagnostics.ts +693 -0
  39. package/src/schemas/workflow-tools.test.ts +202 -0
  40. package/src/schemas/workflow-tools.ts +738 -0
  41. package/tsconfig.build.tsbuildinfo +1 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipfox/api-agent-access-dto",
3
3
  "license": "MIT",
4
- "version": "20.3.0",
4
+ "version": "21.1.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ShipfoxHQ/shipfox.git",
@@ -31,7 +31,8 @@
31
31
  }
32
32
  },
33
33
  "dependencies": {
34
- "zod": "^4.4.3"
34
+ "zod": "^4.4.3",
35
+ "@shipfox/api-logs-dto": "20.0.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@shipfox/biome": "1.10.1",
package/src/index.ts CHANGED
@@ -1,3 +1,22 @@
1
+ export {
2
+ AGENT_ACCESS_FACET_MAX_ITEMS,
3
+ AGENT_ACCESS_FACET_VALUE_MAX_BYTES,
4
+ AGENT_ACCESS_SERIALIZED_JSON_MAX_BYTES,
5
+ AGENT_ACCESS_TRIGGER_DECISION_MAX_ITEMS,
6
+ AGENT_ACCESS_TRIGGER_REPLAY_MAX_ITEMS,
7
+ type GetTriggerEventFacetsInputDto,
8
+ type GetTriggerEventFacetsResultDto,
9
+ type GetTriggerEventInputDto,
10
+ type GetTriggerEventResultDto,
11
+ getTriggerEventFacetsInputJsonSchema,
12
+ getTriggerEventFacetsInputSchema,
13
+ getTriggerEventFacetsResultJsonSchema,
14
+ getTriggerEventFacetsResultSchema,
15
+ getTriggerEventInputJsonSchema,
16
+ getTriggerEventInputSchema,
17
+ getTriggerEventResultJsonSchema,
18
+ getTriggerEventResultSchema,
19
+ } from './schemas/diagnostic-tools.js';
1
20
  export {
2
21
  AGENT_ACCESS_ERROR_CODE_MAX_LENGTH,
3
22
  AGENT_ACCESS_ERROR_MESSAGE_MAX_LENGTH,
@@ -10,6 +29,19 @@ export {
10
29
  agentAccessErrorSchema,
11
30
  agentAccessOutputSchema,
12
31
  } from './schemas/envelope.js';
32
+ export {
33
+ AGENT_ACCESS_LOG_ATTEMPT_MAX,
34
+ AGENT_ACCESS_LOG_CONTENT_MAX_BYTES,
35
+ AGENT_ACCESS_LOG_SECTION_MAX_ITEMS,
36
+ AGENT_ACCESS_LOG_TAIL_LINES_DEFAULT,
37
+ AGENT_ACCESS_LOG_TAIL_LINES_MAX,
38
+ type GetStepLogsInputDto,
39
+ type GetStepLogsResultDto,
40
+ getStepLogsInputJsonSchema,
41
+ getStepLogsInputSchema,
42
+ getStepLogsResultJsonSchema,
43
+ getStepLogsResultSchema,
44
+ } from './schemas/log-tools.js';
13
45
  export {
14
46
  AGENT_ACCESS_ANNOTATION_BODY_MAX_BYTES,
15
47
  AGENT_ACCESS_CONNECTION_NAME_MAX_BYTES,
@@ -52,3 +84,86 @@ export {
52
84
  listWorkflowRunsResultJsonSchema,
53
85
  listWorkflowRunsResultSchema,
54
86
  } from './schemas/paged-tools.js';
87
+ export {
88
+ AGENT_ACCESS_WORKFLOW_DIAGNOSTIC_VALUE_MAX_BYTES,
89
+ AGENT_ACCESS_WORKFLOW_SOURCE_MAX_BYTES,
90
+ type AgentAccessOversizedFieldDto,
91
+ type AgentAccessWorkflowDiagnosticFieldDto,
92
+ agentAccessOversizedFieldSchema,
93
+ agentAccessWorkflowDiagnosticFieldSchema,
94
+ type GetStepAttemptInputDto,
95
+ type GetStepAttemptResultDto,
96
+ type GetWorkflowExecutionContextInputDto,
97
+ type GetWorkflowExecutionContextResultDto,
98
+ type GetWorkflowRunSourceInputDto,
99
+ type GetWorkflowRunSourceResultDto,
100
+ getStepAttemptInputJsonSchema,
101
+ getStepAttemptInputSchema,
102
+ getStepAttemptResultJsonSchema,
103
+ getStepAttemptResultSchema,
104
+ getWorkflowExecutionContextInputJsonSchema,
105
+ getWorkflowExecutionContextInputSchema,
106
+ getWorkflowExecutionContextResultJsonSchema,
107
+ getWorkflowExecutionContextResultSchema,
108
+ getWorkflowRunSourceInputJsonSchema,
109
+ getWorkflowRunSourceInputSchema,
110
+ getWorkflowRunSourceResultJsonSchema,
111
+ getWorkflowRunSourceResultSchema,
112
+ type ListWorkflowRunJobExplanationsInputDto,
113
+ type ListWorkflowRunJobExplanationsResultDto,
114
+ listWorkflowRunJobExplanationsInputJsonSchema,
115
+ listWorkflowRunJobExplanationsInputSchema,
116
+ listWorkflowRunJobExplanationsResultJsonSchema,
117
+ listWorkflowRunJobExplanationsResultSchema,
118
+ } from './schemas/workflow-diagnostics.js';
119
+ export {
120
+ AGENT_ACCESS_WORKFLOW_ATTEMPT_MAX,
121
+ AGENT_ACCESS_WORKFLOW_EXECUTION_COUNT_MAX,
122
+ AGENT_ACCESS_WORKFLOW_EXECUTION_PAGE_LIMIT,
123
+ AGENT_ACCESS_WORKFLOW_JOB_PAGE_LIMIT,
124
+ AGENT_ACCESS_WORKFLOW_RUN_ATTEMPT_PAGE_LIMIT,
125
+ AGENT_ACCESS_WORKFLOW_STEP_ATTEMPT_PAGE_LIMIT,
126
+ AGENT_ACCESS_WORKFLOW_STEP_PAGE_LIMIT,
127
+ type GetWorkflowJobInputDto,
128
+ type GetWorkflowJobResultDto,
129
+ type GetWorkflowRunInputDto,
130
+ type GetWorkflowRunResultDto,
131
+ getWorkflowJobInputJsonSchema,
132
+ getWorkflowJobInputSchema,
133
+ getWorkflowJobResultJsonSchema,
134
+ getWorkflowJobResultSchema,
135
+ getWorkflowRunInputJsonSchema,
136
+ getWorkflowRunInputSchema,
137
+ getWorkflowRunResultJsonSchema,
138
+ getWorkflowRunResultSchema,
139
+ type ListWorkflowExecutionStepsInputDto,
140
+ type ListWorkflowExecutionStepsResultDto,
141
+ type ListWorkflowJobExecutionsInputDto,
142
+ type ListWorkflowJobExecutionsResultDto,
143
+ type ListWorkflowRunAttemptsInputDto,
144
+ type ListWorkflowRunAttemptsResultDto,
145
+ type ListWorkflowRunJobsInputDto,
146
+ type ListWorkflowRunJobsResultDto,
147
+ type ListWorkflowStepAttemptsInputDto,
148
+ type ListWorkflowStepAttemptsResultDto,
149
+ listWorkflowExecutionStepsInputJsonSchema,
150
+ listWorkflowExecutionStepsInputSchema,
151
+ listWorkflowExecutionStepsResultJsonSchema,
152
+ listWorkflowExecutionStepsResultSchema,
153
+ listWorkflowJobExecutionsInputJsonSchema,
154
+ listWorkflowJobExecutionsInputSchema,
155
+ listWorkflowJobExecutionsResultJsonSchema,
156
+ listWorkflowJobExecutionsResultSchema,
157
+ listWorkflowRunAttemptsInputJsonSchema,
158
+ listWorkflowRunAttemptsInputSchema,
159
+ listWorkflowRunAttemptsResultJsonSchema,
160
+ listWorkflowRunAttemptsResultSchema,
161
+ listWorkflowRunJobsInputJsonSchema,
162
+ listWorkflowRunJobsInputSchema,
163
+ listWorkflowRunJobsResultJsonSchema,
164
+ listWorkflowRunJobsResultSchema,
165
+ listWorkflowStepAttemptsInputJsonSchema,
166
+ listWorkflowStepAttemptsInputSchema,
167
+ listWorkflowStepAttemptsResultJsonSchema,
168
+ listWorkflowStepAttemptsResultSchema,
169
+ } from './schemas/workflow-tools.js';
@@ -0,0 +1,255 @@
1
+ import {z} from 'zod';
2
+ import type {AgentAccessObjectSchema} from './envelope.js';
3
+ import {
4
+ AGENT_ACCESS_CONNECTION_NAME_MAX_BYTES,
5
+ AGENT_ACCESS_TEXT_MAX_BYTES,
6
+ } from './paged-tools.js';
7
+ import {dateTimeSchema, idSchema, utf8CappedString} from './primitives.js';
8
+
9
+ export const AGENT_ACCESS_SERIALIZED_JSON_MAX_BYTES = 16 * 1024;
10
+ export const AGENT_ACCESS_TRIGGER_DECISION_MAX_ITEMS = 50;
11
+ export const AGENT_ACCESS_TRIGGER_REPLAY_MAX_ITEMS = 20;
12
+ export const AGENT_ACCESS_FACET_MAX_ITEMS = 50;
13
+ export const AGENT_ACCESS_FACET_VALUE_MAX_BYTES = 256;
14
+
15
+ const textSchema = utf8CappedString(AGENT_ACCESS_TEXT_MAX_BYTES);
16
+ const shortTextSchema = utf8CappedString(AGENT_ACCESS_CONNECTION_NAME_MAX_BYTES);
17
+ const serializedJsonSchema = utf8CappedString(AGENT_ACCESS_SERIALIZED_JSON_MAX_BYTES).refine(
18
+ isSerializedJson,
19
+ {message: 'String must contain valid serialized JSON'},
20
+ );
21
+
22
+ export const getTriggerEventInputSchema = z.object({event_id: idSchema}).strict();
23
+
24
+ export const getTriggerEventFacetsInputSchema = z.object({}).strict();
25
+
26
+ export type GetTriggerEventInputDto = z.infer<typeof getTriggerEventInputSchema>;
27
+ export type GetTriggerEventFacetsInputDto = z.infer<typeof getTriggerEventFacetsInputSchema>;
28
+
29
+ const triggerOriginSchema = z.enum(['integration', 'manual', 'cron', 'dev']);
30
+ const triggerOutcomeSchema = z.enum(['received', 'routed', 'discarded', 'failed', 'errored']);
31
+ const triggerDecisionOutcomeSchema = z.enum(['triggered', 'filter-error', 'dispatch-error']);
32
+ const triggerDecisionSchema = z
33
+ .object({
34
+ id: idSchema,
35
+ subscription_kind: z.enum(['trigger', 'listener', 'dev']),
36
+ outcome: triggerDecisionOutcomeSchema,
37
+ reason: textSchema.nullable(),
38
+ workflow_definition_id: idSchema.nullable(),
39
+ project_id: idSchema.nullable(),
40
+ workflow_run_id: idSchema.nullable(),
41
+ job_id: idSchema.nullable(),
42
+ })
43
+ .strict();
44
+
45
+ const triggerReplaySchema = z
46
+ .object({
47
+ id: idSchema,
48
+ workflow_run_id: idSchema.nullable(),
49
+ created_at: dateTimeSchema,
50
+ })
51
+ .strict();
52
+
53
+ export const getTriggerEventResultSchema = z
54
+ .object({
55
+ id: idSchema,
56
+ origin: triggerOriginSchema,
57
+ provider: textSchema.nullable(),
58
+ source: textSchema,
59
+ event: textSchema,
60
+ outcome: triggerOutcomeSchema,
61
+ matched_count: z.number().int().nonnegative(),
62
+ connection_id: idSchema.nullable(),
63
+ connection_name: shortTextSchema.nullable(),
64
+ replay_of_event_id: idSchema.nullable(),
65
+ received_at: dateTimeSchema,
66
+ processed_at: dateTimeSchema.nullable(),
67
+ payload_preview: serializedJsonSchema,
68
+ payload_preview_truncated: z.literal(true).optional(),
69
+ payload_preview_total_bytes: z.number().int().nonnegative().optional(),
70
+ decisions: z.array(triggerDecisionSchema).max(AGENT_ACCESS_TRIGGER_DECISION_MAX_ITEMS),
71
+ decisions_truncated: z.literal(true).optional(),
72
+ decisions_total_count: z.number().int().nonnegative(),
73
+ replays: z.array(triggerReplaySchema).max(AGENT_ACCESS_TRIGGER_REPLAY_MAX_ITEMS),
74
+ replays_truncated: z.literal(true).optional(),
75
+ replays_total_count: z.number().int().nonnegative(),
76
+ })
77
+ .strict();
78
+
79
+ const facetSchema = z
80
+ .object({
81
+ value: utf8CappedString(AGENT_ACCESS_FACET_VALUE_MAX_BYTES),
82
+ count: z.number().int().nonnegative(),
83
+ })
84
+ .strict();
85
+
86
+ export const getTriggerEventFacetsResultSchema = z
87
+ .object({
88
+ sources: z.array(facetSchema).max(AGENT_ACCESS_FACET_MAX_ITEMS),
89
+ events: z.array(facetSchema).max(AGENT_ACCESS_FACET_MAX_ITEMS),
90
+ origins: z.array(facetSchema).max(AGENT_ACCESS_FACET_MAX_ITEMS),
91
+ })
92
+ .strict();
93
+
94
+ export type GetTriggerEventResultDto = z.infer<typeof getTriggerEventResultSchema>;
95
+ export type GetTriggerEventFacetsResultDto = z.infer<typeof getTriggerEventFacetsResultSchema>;
96
+
97
+ const uuid = {type: 'string', format: 'uuid'} as const;
98
+ const dateTime = {type: 'string', format: 'date-time'} as const;
99
+ const text = {type: 'string', maxLength: AGENT_ACCESS_TEXT_MAX_BYTES} as const;
100
+ const shortText = {
101
+ type: 'string',
102
+ maxLength: AGENT_ACCESS_CONNECTION_NAME_MAX_BYTES,
103
+ } as const;
104
+ const serializedJson = {
105
+ type: 'string',
106
+ maxLength: AGENT_ACCESS_SERIALIZED_JSON_MAX_BYTES,
107
+ contentMediaType: 'application/json',
108
+ } as const;
109
+ const nullable = (schema: Record<string, unknown>) => ({anyOf: [schema, {type: 'null'}]}) as const;
110
+
111
+ export const getTriggerEventInputJsonSchema = {
112
+ type: 'object',
113
+ properties: {event_id: uuid},
114
+ required: ['event_id'],
115
+ additionalProperties: false,
116
+ } as const satisfies AgentAccessObjectSchema;
117
+
118
+ function isSerializedJson(value: string): boolean {
119
+ try {
120
+ JSON.parse(value);
121
+ return true;
122
+ } catch {
123
+ return false;
124
+ }
125
+ }
126
+
127
+ export const getTriggerEventFacetsInputJsonSchema = {
128
+ type: 'object',
129
+ properties: {},
130
+ additionalProperties: false,
131
+ } as const satisfies AgentAccessObjectSchema;
132
+
133
+ const triggerDecisionJsonSchema = {
134
+ type: 'object',
135
+ properties: {
136
+ id: uuid,
137
+ subscription_kind: {type: 'string', enum: ['trigger', 'listener', 'dev']},
138
+ outcome: {type: 'string', enum: ['triggered', 'filter-error', 'dispatch-error']},
139
+ reason: nullable(text),
140
+ workflow_definition_id: nullable(uuid),
141
+ project_id: nullable(uuid),
142
+ workflow_run_id: nullable(uuid),
143
+ job_id: nullable(uuid),
144
+ },
145
+ required: [
146
+ 'id',
147
+ 'subscription_kind',
148
+ 'outcome',
149
+ 'reason',
150
+ 'workflow_definition_id',
151
+ 'project_id',
152
+ 'workflow_run_id',
153
+ 'job_id',
154
+ ],
155
+ additionalProperties: false,
156
+ } as const;
157
+
158
+ const triggerReplayJsonSchema = {
159
+ type: 'object',
160
+ properties: {
161
+ id: uuid,
162
+ workflow_run_id: nullable(uuid),
163
+ created_at: dateTime,
164
+ },
165
+ required: ['id', 'workflow_run_id', 'created_at'],
166
+ additionalProperties: false,
167
+ } as const;
168
+
169
+ export const getTriggerEventResultJsonSchema = {
170
+ type: 'object',
171
+ properties: {
172
+ id: uuid,
173
+ origin: {type: 'string', enum: ['integration', 'manual', 'cron', 'dev']},
174
+ provider: nullable(text),
175
+ source: text,
176
+ event: text,
177
+ outcome: {type: 'string', enum: ['received', 'routed', 'discarded', 'failed', 'errored']},
178
+ matched_count: {type: 'integer', minimum: 0},
179
+ connection_id: nullable(uuid),
180
+ connection_name: nullable(shortText),
181
+ replay_of_event_id: nullable(uuid),
182
+ received_at: dateTime,
183
+ processed_at: nullable(dateTime),
184
+ payload_preview: serializedJson,
185
+ payload_preview_truncated: {const: true},
186
+ payload_preview_total_bytes: {type: 'integer', minimum: 0},
187
+ decisions: {
188
+ type: 'array',
189
+ maxItems: AGENT_ACCESS_TRIGGER_DECISION_MAX_ITEMS,
190
+ items: triggerDecisionJsonSchema,
191
+ },
192
+ decisions_truncated: {const: true},
193
+ decisions_total_count: {type: 'integer', minimum: 0},
194
+ replays: {
195
+ type: 'array',
196
+ maxItems: AGENT_ACCESS_TRIGGER_REPLAY_MAX_ITEMS,
197
+ items: triggerReplayJsonSchema,
198
+ },
199
+ replays_truncated: {const: true},
200
+ replays_total_count: {type: 'integer', minimum: 0},
201
+ },
202
+ required: [
203
+ 'id',
204
+ 'origin',
205
+ 'provider',
206
+ 'source',
207
+ 'event',
208
+ 'outcome',
209
+ 'matched_count',
210
+ 'connection_id',
211
+ 'connection_name',
212
+ 'replay_of_event_id',
213
+ 'received_at',
214
+ 'processed_at',
215
+ 'payload_preview',
216
+ 'decisions',
217
+ 'decisions_total_count',
218
+ 'replays',
219
+ 'replays_total_count',
220
+ ],
221
+ additionalProperties: false,
222
+ } as const satisfies AgentAccessObjectSchema;
223
+
224
+ const facetJsonSchema = {
225
+ type: 'object',
226
+ properties: {
227
+ value: {type: 'string', maxLength: AGENT_ACCESS_FACET_VALUE_MAX_BYTES},
228
+ count: {type: 'integer', minimum: 0},
229
+ },
230
+ required: ['value', 'count'],
231
+ additionalProperties: false,
232
+ } as const;
233
+
234
+ export const getTriggerEventFacetsResultJsonSchema = {
235
+ type: 'object',
236
+ properties: {
237
+ sources: {
238
+ type: 'array',
239
+ maxItems: AGENT_ACCESS_FACET_MAX_ITEMS,
240
+ items: facetJsonSchema,
241
+ },
242
+ events: {
243
+ type: 'array',
244
+ maxItems: AGENT_ACCESS_FACET_MAX_ITEMS,
245
+ items: facetJsonSchema,
246
+ },
247
+ origins: {
248
+ type: 'array',
249
+ maxItems: AGENT_ACCESS_FACET_MAX_ITEMS,
250
+ items: facetJsonSchema,
251
+ },
252
+ },
253
+ required: ['sources', 'events', 'origins'],
254
+ additionalProperties: false,
255
+ } as const satisfies AgentAccessObjectSchema;
@@ -0,0 +1,209 @@
1
+ import {
2
+ DEFAULT_STEP_LOG_TAIL_LINES,
3
+ MAX_STEP_LOG_TAIL_LINES,
4
+ } from '@shipfox/api-logs-dto/inter-module';
5
+ import {z} from 'zod';
6
+ import type {AgentAccessObjectSchema} from './envelope.js';
7
+ import {idSchema, utf8CappedString} from './primitives.js';
8
+
9
+ export const AGENT_ACCESS_LOG_CONTENT_MAX_BYTES = 64 * 1024;
10
+ export const AGENT_ACCESS_LOG_SECTION_MAX_ITEMS = 10;
11
+ export const AGENT_ACCESS_LOG_TAIL_LINES_DEFAULT = DEFAULT_STEP_LOG_TAIL_LINES;
12
+ export const AGENT_ACCESS_LOG_TAIL_LINES_MAX = MAX_STEP_LOG_TAIL_LINES;
13
+ export const AGENT_ACCESS_LOG_ATTEMPT_MAX = 2_147_483_647;
14
+
15
+ const attemptSchema = z.number().int().min(1).max(AGENT_ACCESS_LOG_ATTEMPT_MAX);
16
+ const tailLinesSchema = z
17
+ .number()
18
+ .int()
19
+ .min(1)
20
+ .max(AGENT_ACCESS_LOG_TAIL_LINES_MAX)
21
+ .default(AGENT_ACCESS_LOG_TAIL_LINES_DEFAULT);
22
+ const contentSchema = utf8CappedString(AGENT_ACCESS_LOG_CONTENT_MAX_BYTES);
23
+
24
+ export const getStepLogsInputSchema = z
25
+ .object({
26
+ step_id: idSchema.optional(),
27
+ run_id: idSchema.optional(),
28
+ attempt: attemptSchema.optional(),
29
+ failed_only: z.literal(true).optional(),
30
+ tail_lines: tailLinesSchema,
31
+ })
32
+ .superRefine((value, context) => {
33
+ const hasStep = value.step_id !== undefined;
34
+ const hasRun = value.run_id !== undefined;
35
+
36
+ if (hasStep === hasRun) {
37
+ context.addIssue({
38
+ code: 'custom',
39
+ path: [hasStep ? 'run_id' : 'step_id'],
40
+ message: 'Provide exactly one of step_id or run_id',
41
+ });
42
+ }
43
+ if (hasRun && value.failed_only !== true) {
44
+ context.addIssue({
45
+ code: 'custom',
46
+ path: ['failed_only'],
47
+ message: 'run_id requires failed_only to be true',
48
+ });
49
+ }
50
+ if (hasStep && value.failed_only !== undefined) {
51
+ context.addIssue({
52
+ code: 'custom',
53
+ path: ['failed_only'],
54
+ message: 'failed_only is only valid with run_id',
55
+ });
56
+ }
57
+ if (hasRun && value.attempt !== undefined) {
58
+ context.addIssue({
59
+ code: 'custom',
60
+ path: ['attempt'],
61
+ message: 'attempt is only valid with step_id',
62
+ });
63
+ }
64
+ })
65
+ .strict();
66
+
67
+ export type GetStepLogsInputDto = z.output<typeof getStepLogsInputSchema>;
68
+
69
+ const logSectionSchema = z
70
+ .object({
71
+ workflow_run_id: idSchema.optional(),
72
+ workflow_run_attempt: attemptSchema.optional(),
73
+ job_id: idSchema.optional(),
74
+ job_execution_id: idSchema.optional(),
75
+ step_id: idSchema,
76
+ step_attempt_id: idSchema.optional(),
77
+ attempt: attemptSchema,
78
+ content: contentSchema,
79
+ total_lines: z.number().int().nonnegative().optional(),
80
+ content_truncated: z.literal(true).optional(),
81
+ content_total_bytes: z.number().int().nonnegative().optional(),
82
+ })
83
+ .strict();
84
+
85
+ export const getStepLogsResultSchema = z
86
+ .object({
87
+ run_id: idSchema.optional(),
88
+ workflow_run_attempt: attemptSchema.optional(),
89
+ sections: z.array(logSectionSchema).max(AGENT_ACCESS_LOG_SECTION_MAX_ITEMS),
90
+ })
91
+ .superRefine((value, context) => {
92
+ const hasRun = value.run_id !== undefined;
93
+ const hasRunAttempt = value.workflow_run_attempt !== undefined;
94
+
95
+ if (hasRun !== hasRunAttempt) {
96
+ context.addIssue({
97
+ code: 'custom',
98
+ path: [hasRun ? 'workflow_run_attempt' : 'run_id'],
99
+ message: 'run_id and workflow_run_attempt must be provided together',
100
+ });
101
+ }
102
+ if (!hasRun && value.sections.length !== 1) {
103
+ context.addIssue({
104
+ code: 'custom',
105
+ path: ['sections'],
106
+ message: 'A direct step read must contain exactly one section',
107
+ });
108
+ }
109
+ })
110
+ .strict();
111
+
112
+ export type GetStepLogsResultDto = z.output<typeof getStepLogsResultSchema>;
113
+
114
+ const uuid = {type: 'string', format: 'uuid'} as const;
115
+ const attempt = {
116
+ type: 'integer',
117
+ minimum: 1,
118
+ maximum: AGENT_ACCESS_LOG_ATTEMPT_MAX,
119
+ } as const;
120
+
121
+ const directInputJsonSchema = {
122
+ type: 'object',
123
+ properties: {
124
+ step_id: uuid,
125
+ attempt,
126
+ tail_lines: {
127
+ type: 'integer',
128
+ minimum: 1,
129
+ maximum: AGENT_ACCESS_LOG_TAIL_LINES_MAX,
130
+ default: AGENT_ACCESS_LOG_TAIL_LINES_DEFAULT,
131
+ },
132
+ },
133
+ required: ['step_id'],
134
+ additionalProperties: false,
135
+ } as const;
136
+
137
+ const failedOnlyInputJsonSchema = {
138
+ type: 'object',
139
+ properties: {
140
+ run_id: uuid,
141
+ failed_only: {const: true},
142
+ tail_lines: {
143
+ type: 'integer',
144
+ minimum: 1,
145
+ maximum: AGENT_ACCESS_LOG_TAIL_LINES_MAX,
146
+ default: AGENT_ACCESS_LOG_TAIL_LINES_DEFAULT,
147
+ },
148
+ },
149
+ required: ['run_id', 'failed_only'],
150
+ additionalProperties: false,
151
+ } as const;
152
+
153
+ export const getStepLogsInputJsonSchema = {
154
+ type: 'object',
155
+ oneOf: [directInputJsonSchema, failedOnlyInputJsonSchema],
156
+ } as const satisfies AgentAccessObjectSchema;
157
+
158
+ const logSectionJsonSchema = {
159
+ type: 'object',
160
+ properties: {
161
+ workflow_run_id: uuid,
162
+ workflow_run_attempt: attempt,
163
+ job_id: uuid,
164
+ job_execution_id: uuid,
165
+ step_id: uuid,
166
+ step_attempt_id: uuid,
167
+ attempt,
168
+ content: {type: 'string', maxLength: AGENT_ACCESS_LOG_CONTENT_MAX_BYTES},
169
+ total_lines: {type: 'integer', minimum: 0},
170
+ content_truncated: {const: true},
171
+ content_total_bytes: {type: 'integer', minimum: 0},
172
+ },
173
+ required: ['step_id', 'attempt', 'content'],
174
+ additionalProperties: false,
175
+ } as const;
176
+
177
+ const directResultJsonSchema = {
178
+ type: 'object',
179
+ properties: {
180
+ sections: {
181
+ type: 'array',
182
+ minItems: 1,
183
+ maxItems: 1,
184
+ items: logSectionJsonSchema,
185
+ },
186
+ },
187
+ required: ['sections'],
188
+ additionalProperties: false,
189
+ } as const;
190
+
191
+ const aggregateResultJsonSchema = {
192
+ type: 'object',
193
+ properties: {
194
+ run_id: uuid,
195
+ workflow_run_attempt: attempt,
196
+ sections: {
197
+ type: 'array',
198
+ maxItems: AGENT_ACCESS_LOG_SECTION_MAX_ITEMS,
199
+ items: logSectionJsonSchema,
200
+ },
201
+ },
202
+ required: ['run_id', 'workflow_run_attempt', 'sections'],
203
+ additionalProperties: false,
204
+ } as const;
205
+
206
+ export const getStepLogsResultJsonSchema = {
207
+ type: 'object',
208
+ oneOf: [directResultJsonSchema, aggregateResultJsonSchema],
209
+ } as const satisfies AgentAccessObjectSchema;
@@ -1,5 +1,6 @@
1
1
  import {z} from 'zod';
2
2
  import type {AgentAccessObjectSchema} from './envelope.js';
3
+ import {dateTimeSchema, idSchema, utf8CappedString} from './primitives.js';
3
4
 
4
5
  export const AGENT_ACCESS_DEFAULT_PAGE_LIMIT = 50;
5
6
  export const AGENT_ACCESS_PAGE_LIMIT_MAX = 100;
@@ -12,16 +13,6 @@ export const AGENT_ACCESS_DIAGNOSTIC_PATH_MAX_BYTES = 512;
12
13
  export const AGENT_ACCESS_DIAGNOSTIC_MAX_ITEMS = 10;
13
14
  export const AGENT_ACCESS_ANNOTATION_BODY_MAX_BYTES = 8 * 1024;
14
15
 
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
16
  const pageInputFields = {
26
17
  limit: z
27
18
  .number()
@@ -0,0 +1,14 @@
1
+ import {z} from 'zod';
2
+
3
+ export const idSchema = z.string().uuid();
4
+ export const dateTimeSchema = z.string().datetime();
5
+
6
+ const utf8Encoder = new TextEncoder();
7
+
8
+ export const utf8CappedString = (maxBytes: number) =>
9
+ z
10
+ .string()
11
+ .max(maxBytes)
12
+ .refine((value) => utf8Encoder.encode(value).byteLength <= maxBytes, {
13
+ message: `String must contain at most ${maxBytes} UTF-8 bytes`,
14
+ });