@anchrd/intel-contract 0.13.0 → 0.15.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.
- package/README.md +80 -0
- package/dist/contract/bundle.d.ts +85 -0
- package/dist/contract/bundle.js +63 -0
- package/dist/contract/contract.d.ts +3 -2245
- package/dist/contract/contract.js +24 -1108
- package/dist/contract/flow-run.d.ts +346 -0
- package/dist/contract/flow-run.js +181 -0
- package/dist/contract/flow.d.ts +995 -0
- package/dist/contract/flow.js +417 -0
- package/dist/contract/node.d.ts +402 -0
- package/dist/contract/node.js +310 -0
- package/dist/contract/share.d.ts +142 -0
- package/dist/contract/share.js +67 -0
- package/dist/contract/table.d.ts +162 -0
- package/dist/contract/table.js +117 -0
- package/dist/contract/tool.d.ts +122 -0
- package/dist/contract/tool.js +172 -0
- package/package.json +29 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const FlowRunStatus: z.ZodEnum<{
|
|
3
|
+
queued: "queued";
|
|
4
|
+
running: "running";
|
|
5
|
+
completed: "completed";
|
|
6
|
+
failed: "failed";
|
|
7
|
+
cancelled: "cancelled";
|
|
8
|
+
}>;
|
|
9
|
+
export type FlowRunStatus = z.infer<typeof FlowRunStatus>;
|
|
10
|
+
export declare const FlowRun: z.ZodObject<{
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
flowId: z.ZodString;
|
|
13
|
+
versionId: z.ZodString;
|
|
14
|
+
status: z.ZodEnum<{
|
|
15
|
+
queued: "queued";
|
|
16
|
+
running: "running";
|
|
17
|
+
completed: "completed";
|
|
18
|
+
failed: "failed";
|
|
19
|
+
cancelled: "cancelled";
|
|
20
|
+
}>;
|
|
21
|
+
currentNodeId: z.ZodNullable<z.ZodString>;
|
|
22
|
+
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
23
|
+
output: z.ZodNullable<z.ZodUnknown>;
|
|
24
|
+
error: z.ZodNullable<z.ZodString>;
|
|
25
|
+
initiatedBy: z.ZodString;
|
|
26
|
+
parentRunId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
27
|
+
parentNodeId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
28
|
+
createdAt: z.ZodISODateTime;
|
|
29
|
+
updatedAt: z.ZodISODateTime;
|
|
30
|
+
completedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
export type FlowRun = z.infer<typeof FlowRun>;
|
|
33
|
+
export declare const FlowRunTrailEntry: z.ZodObject<{
|
|
34
|
+
runId: z.ZodString;
|
|
35
|
+
flowId: z.ZodString;
|
|
36
|
+
flowTitle: z.ZodString;
|
|
37
|
+
nodeId: z.ZodNullable<z.ZodString>;
|
|
38
|
+
nodeLabel: z.ZodNullable<z.ZodString>;
|
|
39
|
+
}, z.core.$strict>;
|
|
40
|
+
export type FlowRunTrailEntry = z.infer<typeof FlowRunTrailEntry>;
|
|
41
|
+
export declare const FlowRunStep: z.ZodObject<{
|
|
42
|
+
run: z.ZodObject<{
|
|
43
|
+
id: z.ZodString;
|
|
44
|
+
flowId: z.ZodString;
|
|
45
|
+
versionId: z.ZodString;
|
|
46
|
+
status: z.ZodEnum<{
|
|
47
|
+
queued: "queued";
|
|
48
|
+
running: "running";
|
|
49
|
+
completed: "completed";
|
|
50
|
+
failed: "failed";
|
|
51
|
+
cancelled: "cancelled";
|
|
52
|
+
}>;
|
|
53
|
+
currentNodeId: z.ZodNullable<z.ZodString>;
|
|
54
|
+
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
55
|
+
output: z.ZodNullable<z.ZodUnknown>;
|
|
56
|
+
error: z.ZodNullable<z.ZodString>;
|
|
57
|
+
initiatedBy: z.ZodString;
|
|
58
|
+
parentRunId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
59
|
+
parentNodeId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
60
|
+
createdAt: z.ZodISODateTime;
|
|
61
|
+
updatedAt: z.ZodISODateTime;
|
|
62
|
+
completedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
63
|
+
}, z.core.$strict>;
|
|
64
|
+
node: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
65
|
+
kind: z.ZodLiteral<"trigger">;
|
|
66
|
+
configuration: z.ZodObject<{
|
|
67
|
+
mode: z.ZodLiteral<"manual">;
|
|
68
|
+
}, z.core.$strict>;
|
|
69
|
+
id: z.ZodString;
|
|
70
|
+
position: z.ZodObject<{
|
|
71
|
+
x: z.ZodNumber;
|
|
72
|
+
y: z.ZodNumber;
|
|
73
|
+
}, z.core.$strict>;
|
|
74
|
+
label: z.ZodString;
|
|
75
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
76
|
+
kind: z.ZodLiteral<"instruction">;
|
|
77
|
+
configuration: z.ZodObject<{
|
|
78
|
+
prompt: z.ZodString;
|
|
79
|
+
}, z.core.$strict>;
|
|
80
|
+
id: z.ZodString;
|
|
81
|
+
position: z.ZodObject<{
|
|
82
|
+
x: z.ZodNumber;
|
|
83
|
+
y: z.ZodNumber;
|
|
84
|
+
}, z.core.$strict>;
|
|
85
|
+
label: z.ZodString;
|
|
86
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
87
|
+
kind: z.ZodLiteral<"folder">;
|
|
88
|
+
configuration: z.ZodObject<{
|
|
89
|
+
resourceId: z.ZodString;
|
|
90
|
+
}, z.core.$strict>;
|
|
91
|
+
id: z.ZodString;
|
|
92
|
+
position: z.ZodObject<{
|
|
93
|
+
x: z.ZodNumber;
|
|
94
|
+
y: z.ZodNumber;
|
|
95
|
+
}, z.core.$strict>;
|
|
96
|
+
label: z.ZodString;
|
|
97
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
98
|
+
kind: z.ZodLiteral<"document">;
|
|
99
|
+
configuration: z.ZodObject<{
|
|
100
|
+
resourceId: z.ZodString;
|
|
101
|
+
}, z.core.$strict>;
|
|
102
|
+
id: z.ZodString;
|
|
103
|
+
position: z.ZodObject<{
|
|
104
|
+
x: z.ZodNumber;
|
|
105
|
+
y: z.ZodNumber;
|
|
106
|
+
}, z.core.$strict>;
|
|
107
|
+
label: z.ZodString;
|
|
108
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
109
|
+
kind: z.ZodLiteral<"upload">;
|
|
110
|
+
configuration: z.ZodObject<{
|
|
111
|
+
resourceId: z.ZodString;
|
|
112
|
+
}, z.core.$strict>;
|
|
113
|
+
id: z.ZodString;
|
|
114
|
+
position: z.ZodObject<{
|
|
115
|
+
x: z.ZodNumber;
|
|
116
|
+
y: z.ZodNumber;
|
|
117
|
+
}, z.core.$strict>;
|
|
118
|
+
label: z.ZodString;
|
|
119
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
120
|
+
kind: z.ZodLiteral<"table">;
|
|
121
|
+
configuration: z.ZodObject<{
|
|
122
|
+
resourceId: z.ZodString;
|
|
123
|
+
}, z.core.$strict>;
|
|
124
|
+
id: z.ZodString;
|
|
125
|
+
position: z.ZodObject<{
|
|
126
|
+
x: z.ZodNumber;
|
|
127
|
+
y: z.ZodNumber;
|
|
128
|
+
}, z.core.$strict>;
|
|
129
|
+
label: z.ZodString;
|
|
130
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
131
|
+
kind: z.ZodLiteral<"tool">;
|
|
132
|
+
configuration: z.ZodObject<{
|
|
133
|
+
toolName: z.ZodString;
|
|
134
|
+
fingerprint: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
135
|
+
arguments: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
136
|
+
}, z.core.$strict>;
|
|
137
|
+
id: z.ZodString;
|
|
138
|
+
position: z.ZodObject<{
|
|
139
|
+
x: z.ZodNumber;
|
|
140
|
+
y: z.ZodNumber;
|
|
141
|
+
}, z.core.$strict>;
|
|
142
|
+
label: z.ZodString;
|
|
143
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
144
|
+
kind: z.ZodLiteral<"condition">;
|
|
145
|
+
configuration: z.ZodObject<{
|
|
146
|
+
mode: z.ZodLiteral<"semantic">;
|
|
147
|
+
instruction: z.ZodString;
|
|
148
|
+
}, z.core.$strict>;
|
|
149
|
+
id: z.ZodString;
|
|
150
|
+
position: z.ZodObject<{
|
|
151
|
+
x: z.ZodNumber;
|
|
152
|
+
y: z.ZodNumber;
|
|
153
|
+
}, z.core.$strict>;
|
|
154
|
+
label: z.ZodString;
|
|
155
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
156
|
+
kind: z.ZodLiteral<"subflow">;
|
|
157
|
+
configuration: z.ZodObject<{
|
|
158
|
+
flowId: z.ZodString;
|
|
159
|
+
version: z.ZodDefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
160
|
+
mode: z.ZodLiteral<"latest">;
|
|
161
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
162
|
+
mode: z.ZodLiteral<"follows">;
|
|
163
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
164
|
+
mode: z.ZodLiteral<"pinned">;
|
|
165
|
+
versionId: z.ZodString;
|
|
166
|
+
}, z.core.$strict>], "mode">>;
|
|
167
|
+
}, z.core.$strict>;
|
|
168
|
+
id: z.ZodString;
|
|
169
|
+
position: z.ZodObject<{
|
|
170
|
+
x: z.ZodNumber;
|
|
171
|
+
y: z.ZodNumber;
|
|
172
|
+
}, z.core.$strict>;
|
|
173
|
+
label: z.ZodString;
|
|
174
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
175
|
+
kind: z.ZodLiteral<"output">;
|
|
176
|
+
configuration: z.ZodObject<{}, z.core.$strict>;
|
|
177
|
+
id: z.ZodString;
|
|
178
|
+
position: z.ZodObject<{
|
|
179
|
+
x: z.ZodNumber;
|
|
180
|
+
y: z.ZodNumber;
|
|
181
|
+
}, z.core.$strict>;
|
|
182
|
+
label: z.ZodString;
|
|
183
|
+
}, z.core.$strict>], "kind">>;
|
|
184
|
+
trail: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
185
|
+
runId: z.ZodString;
|
|
186
|
+
flowId: z.ZodString;
|
|
187
|
+
flowTitle: z.ZodString;
|
|
188
|
+
nodeId: z.ZodNullable<z.ZodString>;
|
|
189
|
+
nodeLabel: z.ZodNullable<z.ZodString>;
|
|
190
|
+
}, z.core.$strict>>>;
|
|
191
|
+
}, z.core.$strict>;
|
|
192
|
+
export type FlowRunStep = z.infer<typeof FlowRunStep>;
|
|
193
|
+
export declare const StartFlowRunInput: z.ZodObject<{
|
|
194
|
+
flowId: z.ZodString;
|
|
195
|
+
input: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
196
|
+
parent: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
197
|
+
runId: z.ZodString;
|
|
198
|
+
nodeId: z.ZodString;
|
|
199
|
+
}, z.core.$strict>>>;
|
|
200
|
+
idempotencyKey: z.ZodString;
|
|
201
|
+
}, z.core.$strict>;
|
|
202
|
+
export type StartFlowRunInput = z.infer<typeof StartFlowRunInput>;
|
|
203
|
+
export declare const GetFlowRunInput: z.ZodObject<{
|
|
204
|
+
runId: z.ZodString;
|
|
205
|
+
}, z.core.$strict>;
|
|
206
|
+
export type GetFlowRunInput = z.infer<typeof GetFlowRunInput>;
|
|
207
|
+
export declare const CancelFlowRunInput: z.ZodObject<{
|
|
208
|
+
runId: z.ZodString;
|
|
209
|
+
idempotencyKey: z.ZodString;
|
|
210
|
+
}, z.core.$strict>;
|
|
211
|
+
export type CancelFlowRunInput = z.infer<typeof CancelFlowRunInput>;
|
|
212
|
+
export declare const CompleteFlowRunStepInput: z.ZodObject<{
|
|
213
|
+
runId: z.ZodString;
|
|
214
|
+
nodeId: z.ZodString;
|
|
215
|
+
outcome: z.ZodEnum<{
|
|
216
|
+
completed: "completed";
|
|
217
|
+
failed: "failed";
|
|
218
|
+
}>;
|
|
219
|
+
branch: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
220
|
+
output: z.ZodDefault<z.ZodNullable<z.ZodUnknown>>;
|
|
221
|
+
error: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
222
|
+
idempotencyKey: z.ZodString;
|
|
223
|
+
}, z.core.$strict>;
|
|
224
|
+
export type CompleteFlowRunStepInput = z.infer<typeof CompleteFlowRunStepInput>;
|
|
225
|
+
export declare const FlowRunTrigger: z.ZodEnum<{
|
|
226
|
+
subflow: "subflow";
|
|
227
|
+
manual: "manual";
|
|
228
|
+
}>;
|
|
229
|
+
export type FlowRunTrigger = z.infer<typeof FlowRunTrigger>;
|
|
230
|
+
export declare const FlowRunFailure: z.ZodObject<{
|
|
231
|
+
nodeId: z.ZodString;
|
|
232
|
+
nodeLabel: z.ZodString;
|
|
233
|
+
detail: z.ZodString;
|
|
234
|
+
calledRunId: z.ZodNullable<z.ZodString>;
|
|
235
|
+
}, z.core.$strict>;
|
|
236
|
+
export type FlowRunFailure = z.infer<typeof FlowRunFailure>;
|
|
237
|
+
export declare const FlowRunSummary: z.ZodObject<{
|
|
238
|
+
id: z.ZodString;
|
|
239
|
+
flowId: z.ZodString;
|
|
240
|
+
versionId: z.ZodString;
|
|
241
|
+
status: z.ZodEnum<{
|
|
242
|
+
queued: "queued";
|
|
243
|
+
running: "running";
|
|
244
|
+
completed: "completed";
|
|
245
|
+
failed: "failed";
|
|
246
|
+
cancelled: "cancelled";
|
|
247
|
+
}>;
|
|
248
|
+
trigger: z.ZodEnum<{
|
|
249
|
+
subflow: "subflow";
|
|
250
|
+
manual: "manual";
|
|
251
|
+
}>;
|
|
252
|
+
startedAt: z.ZodISODateTime;
|
|
253
|
+
completedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
254
|
+
durationMs: z.ZodNullable<z.ZodNumber>;
|
|
255
|
+
initiatedBy: z.ZodString;
|
|
256
|
+
parentRunId: z.ZodNullable<z.ZodString>;
|
|
257
|
+
failure: z.ZodNullable<z.ZodObject<{
|
|
258
|
+
nodeId: z.ZodString;
|
|
259
|
+
nodeLabel: z.ZodString;
|
|
260
|
+
detail: z.ZodString;
|
|
261
|
+
calledRunId: z.ZodNullable<z.ZodString>;
|
|
262
|
+
}, z.core.$strict>>;
|
|
263
|
+
}, z.core.$strict>;
|
|
264
|
+
export type FlowRunSummary = z.infer<typeof FlowRunSummary>;
|
|
265
|
+
export declare const ListFlowRunsInput: z.ZodObject<{
|
|
266
|
+
flowId: z.ZodString;
|
|
267
|
+
failedOnly: z.ZodDefault<z.ZodBoolean>;
|
|
268
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
269
|
+
cursor: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
270
|
+
}, z.core.$strict>;
|
|
271
|
+
export type ListFlowRunsInput = z.infer<typeof ListFlowRunsInput>;
|
|
272
|
+
export declare const FlowRunList: z.ZodObject<{
|
|
273
|
+
items: z.ZodArray<z.ZodObject<{
|
|
274
|
+
id: z.ZodString;
|
|
275
|
+
flowId: z.ZodString;
|
|
276
|
+
versionId: z.ZodString;
|
|
277
|
+
status: z.ZodEnum<{
|
|
278
|
+
queued: "queued";
|
|
279
|
+
running: "running";
|
|
280
|
+
completed: "completed";
|
|
281
|
+
failed: "failed";
|
|
282
|
+
cancelled: "cancelled";
|
|
283
|
+
}>;
|
|
284
|
+
trigger: z.ZodEnum<{
|
|
285
|
+
subflow: "subflow";
|
|
286
|
+
manual: "manual";
|
|
287
|
+
}>;
|
|
288
|
+
startedAt: z.ZodISODateTime;
|
|
289
|
+
completedAt: z.ZodNullable<z.ZodISODateTime>;
|
|
290
|
+
durationMs: z.ZodNullable<z.ZodNumber>;
|
|
291
|
+
initiatedBy: z.ZodString;
|
|
292
|
+
parentRunId: z.ZodNullable<z.ZodString>;
|
|
293
|
+
failure: z.ZodNullable<z.ZodObject<{
|
|
294
|
+
nodeId: z.ZodString;
|
|
295
|
+
nodeLabel: z.ZodString;
|
|
296
|
+
detail: z.ZodString;
|
|
297
|
+
calledRunId: z.ZodNullable<z.ZodString>;
|
|
298
|
+
}, z.core.$strict>>;
|
|
299
|
+
}, z.core.$strict>>;
|
|
300
|
+
nextCursor: z.ZodNullable<z.ZodString>;
|
|
301
|
+
}, z.core.$strict>;
|
|
302
|
+
export type FlowRunList = z.infer<typeof FlowRunList>;
|
|
303
|
+
export declare const FlowRunStepRecord: z.ZodObject<{
|
|
304
|
+
nodeId: z.ZodString;
|
|
305
|
+
nodeLabel: z.ZodString;
|
|
306
|
+
outcome: z.ZodEnum<{
|
|
307
|
+
completed: "completed";
|
|
308
|
+
failed: "failed";
|
|
309
|
+
}>;
|
|
310
|
+
branch: z.ZodNullable<z.ZodString>;
|
|
311
|
+
detail: z.ZodNullable<z.ZodString>;
|
|
312
|
+
calledRunId: z.ZodNullable<z.ZodString>;
|
|
313
|
+
completedAt: z.ZodISODateTime;
|
|
314
|
+
}, z.core.$strict>;
|
|
315
|
+
export type FlowRunStepRecord = z.infer<typeof FlowRunStepRecord>;
|
|
316
|
+
export declare const FlowRunHistory: z.ZodObject<{
|
|
317
|
+
runId: z.ZodString;
|
|
318
|
+
flowId: z.ZodString;
|
|
319
|
+
status: z.ZodEnum<{
|
|
320
|
+
queued: "queued";
|
|
321
|
+
running: "running";
|
|
322
|
+
completed: "completed";
|
|
323
|
+
failed: "failed";
|
|
324
|
+
cancelled: "cancelled";
|
|
325
|
+
}>;
|
|
326
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
327
|
+
nodeId: z.ZodString;
|
|
328
|
+
nodeLabel: z.ZodString;
|
|
329
|
+
outcome: z.ZodEnum<{
|
|
330
|
+
completed: "completed";
|
|
331
|
+
failed: "failed";
|
|
332
|
+
}>;
|
|
333
|
+
branch: z.ZodNullable<z.ZodString>;
|
|
334
|
+
detail: z.ZodNullable<z.ZodString>;
|
|
335
|
+
calledRunId: z.ZodNullable<z.ZodString>;
|
|
336
|
+
completedAt: z.ZodISODateTime;
|
|
337
|
+
}, z.core.$strict>>;
|
|
338
|
+
trail: z.ZodArray<z.ZodObject<{
|
|
339
|
+
runId: z.ZodString;
|
|
340
|
+
flowId: z.ZodString;
|
|
341
|
+
flowTitle: z.ZodString;
|
|
342
|
+
nodeId: z.ZodNullable<z.ZodString>;
|
|
343
|
+
nodeLabel: z.ZodNullable<z.ZodString>;
|
|
344
|
+
}, z.core.$strict>>;
|
|
345
|
+
}, z.core.$strict>;
|
|
346
|
+
export type FlowRunHistory = z.infer<typeof FlowRunHistory>;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { IdempotencyKey, IntelId, IsoDateTime } from "./contract.js";
|
|
3
|
+
import { FlowNode, FlowNodeId } from "./flow.js";
|
|
4
|
+
// ⚠️ No `waiting`. It was written for the approval node and never set by anything — the two places
|
|
5
|
+
// that tested for it only ever saw `running` (#73). The column's CHECK constraint still allows the
|
|
6
|
+
// value, deliberately: rewriting it means rebuilding the table in D1 for a value nothing writes,
|
|
7
|
+
// and migration 0007 turns any row that somehow carries it into `failed` rather than leave a status
|
|
8
|
+
// the contract cannot parse.
|
|
9
|
+
export const FlowRunStatus = z.enum(["queued", "running", "completed", "failed", "cancelled"]);
|
|
10
|
+
export const FlowRun = z.strictObject({
|
|
11
|
+
id: IntelId,
|
|
12
|
+
flowId: IntelId,
|
|
13
|
+
versionId: IntelId,
|
|
14
|
+
status: FlowRunStatus,
|
|
15
|
+
currentNodeId: FlowNodeId.nullable(),
|
|
16
|
+
input: z.record(z.string(), z.unknown()),
|
|
17
|
+
output: z.unknown().nullable(),
|
|
18
|
+
error: z.string().max(2_000).nullable(),
|
|
19
|
+
initiatedBy: IntelId,
|
|
20
|
+
// The subflow node this run was called from, and the run that node belongs to. A called run is a
|
|
21
|
+
// run of its own: it has its own version, its own steps and its own authorization, and only these
|
|
22
|
+
// two fields say where its result goes back to.
|
|
23
|
+
parentRunId: IntelId.nullable().default(null),
|
|
24
|
+
parentNodeId: FlowNodeId.nullable().default(null),
|
|
25
|
+
createdAt: IsoDateTime,
|
|
26
|
+
updatedAt: IsoDateTime,
|
|
27
|
+
completedAt: IsoDateTime.nullable(),
|
|
28
|
+
});
|
|
29
|
+
// Which step of which flow is running, outermost caller first. Readable rather than reconstructed
|
|
30
|
+
// from `parentRunId` by whoever is looking (#17).
|
|
31
|
+
export const FlowRunTrailEntry = z.strictObject({
|
|
32
|
+
runId: IntelId,
|
|
33
|
+
flowId: IntelId,
|
|
34
|
+
flowTitle: z.string().min(1).max(240),
|
|
35
|
+
nodeId: FlowNodeId.nullable(),
|
|
36
|
+
nodeLabel: z.string().max(160).nullable(),
|
|
37
|
+
});
|
|
38
|
+
export const FlowRunStep = z.strictObject({
|
|
39
|
+
run: FlowRun,
|
|
40
|
+
node: FlowNode.nullable(),
|
|
41
|
+
trail: z.array(FlowRunTrailEntry).default([]),
|
|
42
|
+
});
|
|
43
|
+
export const StartFlowRunInput = z.strictObject({
|
|
44
|
+
flowId: IntelId.describe("Flow to run. It has to be published; the run takes the published version, not the newest one."),
|
|
45
|
+
input: z
|
|
46
|
+
.record(z.string(), z.unknown())
|
|
47
|
+
.default({})
|
|
48
|
+
.describe("The values the flow's trigger node declares. An empty object is right for a flow that asks for nothing."),
|
|
49
|
+
// Present when this run is the call a subflow node makes. It names a place, never a permission:
|
|
50
|
+
// the callee's `execute` is asked of the user exactly as it is for a run they start themselves,
|
|
51
|
+
// and the parent run must be the caller's own and standing on that very node.
|
|
52
|
+
parent: z
|
|
53
|
+
.strictObject({
|
|
54
|
+
runId: IntelId.describe("The calling run."),
|
|
55
|
+
nodeId: FlowNodeId.describe("The subflow node in that run which is making the call."),
|
|
56
|
+
})
|
|
57
|
+
.nullable()
|
|
58
|
+
.default(null)
|
|
59
|
+
.describe("Leave at `null`. It is set only when a subflow node makes this call, and it names a place rather than a permission: the callee's `execute` is still asked of the user."),
|
|
60
|
+
idempotencyKey: IdempotencyKey,
|
|
61
|
+
});
|
|
62
|
+
export const GetFlowRunInput = z.strictObject({
|
|
63
|
+
runId: IntelId.describe("Run to read. A run has an address of its own because it outlives its flow; the id comes from flow_run_start or flow_run_list."),
|
|
64
|
+
});
|
|
65
|
+
// Ending a run on purpose (#145). Until this existed the only way off a parked manual step was
|
|
66
|
+
// `completeStep` with `outcome: "failed"` — which recorded a step failure that never happened.
|
|
67
|
+
// Cancelling records nothing into the step history: the run ends, the history stays true.
|
|
68
|
+
export const CancelFlowRunInput = z.strictObject({
|
|
69
|
+
runId: IntelId.describe("Run to end on purpose. This is the way off a run parked on a manual step — it records nothing into the step history, unlike completing the step as `failed`, which would report a failure that never happened."),
|
|
70
|
+
idempotencyKey: IdempotencyKey,
|
|
71
|
+
});
|
|
72
|
+
export const CompleteFlowRunStepInput = z.strictObject({
|
|
73
|
+
runId: IntelId.describe("Run that is waiting."),
|
|
74
|
+
nodeId: FlowNodeId.describe("The node the run is standing on, from flow_run_get. Answering any other node is refused: this completes the step that is waiting, not a step of one's choosing."),
|
|
75
|
+
outcome: z
|
|
76
|
+
.enum(["completed", "failed"])
|
|
77
|
+
.describe("Whether the step is done or could not be done. `failed` ends the run at this node."),
|
|
78
|
+
branch: z
|
|
79
|
+
.string()
|
|
80
|
+
.min(1)
|
|
81
|
+
.max(120)
|
|
82
|
+
.nullable()
|
|
83
|
+
.default(null)
|
|
84
|
+
.describe("Which way out of a branching node the run takes, by the label on the edge. `null` for a node with one way out."),
|
|
85
|
+
output: z
|
|
86
|
+
.unknown()
|
|
87
|
+
.nullable()
|
|
88
|
+
.default(null)
|
|
89
|
+
.describe("What the step produced, for the nodes after it to read. `null` when it produced nothing."),
|
|
90
|
+
error: z
|
|
91
|
+
.string()
|
|
92
|
+
.max(2_000)
|
|
93
|
+
.nullable()
|
|
94
|
+
.default(null)
|
|
95
|
+
.describe('Why it could not be done. Belongs with `outcome: "failed"` and is what the run\'s failure will say.'),
|
|
96
|
+
idempotencyKey: IdempotencyKey,
|
|
97
|
+
});
|
|
98
|
+
// Why a run started. Derived when it is read and deliberately not a column: `subflow` when the run
|
|
99
|
+
// is the call another run made, otherwise the mode of the trigger node in the immutable version the
|
|
100
|
+
// run took. A stored copy would be a second answer that could disagree with the graph that ran.
|
|
101
|
+
//
|
|
102
|
+
// ⚠️ `webhook` and `schedule` stood here until #39 took them out of the trigger node. Being derived
|
|
103
|
+
// rather than stored is exactly what makes that safe: no run carries a trigger of its own, so once
|
|
104
|
+
// the 0005 migration has rewritten every stored trigger to `manual`, there is nowhere left for the
|
|
105
|
+
// old values to come from. Had this been a column, the enum would have had to keep reading them or
|
|
106
|
+
// every old run would have failed to parse the moment somebody opened the list.
|
|
107
|
+
export const FlowRunTrigger = z.enum(["manual", "subflow"]);
|
|
108
|
+
// Which step ended a run, and why, in the words the failure already used (#20).
|
|
109
|
+
//
|
|
110
|
+
// ⚠️ A call that failed carries its reason in the *called* run, and that run is a run of its own
|
|
111
|
+
// with its own authorization. `calledRunId` is therefore filled only when the asking user may see
|
|
112
|
+
// that run through the very rule every other run answer uses; otherwise the failure is named by the
|
|
113
|
+
// calling step alone — the caller's own label — and `detail` says no more than that it did not
|
|
114
|
+
// finish. Naming a callee's step or document here would be the leak #17, #19 and #20 each closed.
|
|
115
|
+
export const FlowRunFailure = z.strictObject({
|
|
116
|
+
nodeId: FlowNodeId,
|
|
117
|
+
nodeLabel: z.string().max(160),
|
|
118
|
+
detail: z.string().max(2_000),
|
|
119
|
+
calledRunId: IntelId.nullable(),
|
|
120
|
+
});
|
|
121
|
+
// One run as a list shows it: what it did, never what it produced.
|
|
122
|
+
//
|
|
123
|
+
// ⚠️ Neither `input` nor `output` is in here, on purpose. A run reaches its nodes and its tools
|
|
124
|
+
// with the rights of whoever started it, so its result is a way to content the next reader of this
|
|
125
|
+
// list may have no claim to. Whoever wants a result asks for the run itself, where the same rule
|
|
126
|
+
// decides again.
|
|
127
|
+
export const FlowRunSummary = z.strictObject({
|
|
128
|
+
id: IntelId,
|
|
129
|
+
flowId: IntelId,
|
|
130
|
+
// The version the run took. Together with the run's stored input it is what a later "run this
|
|
131
|
+
// again with the old data" would need; replaying is a separate ticket, this only keeps it possible.
|
|
132
|
+
versionId: IntelId,
|
|
133
|
+
status: FlowRunStatus,
|
|
134
|
+
trigger: FlowRunTrigger,
|
|
135
|
+
startedAt: IsoDateTime,
|
|
136
|
+
completedAt: IsoDateTime.nullable(),
|
|
137
|
+
durationMs: z.number().int().nonnegative().nullable(),
|
|
138
|
+
initiatedBy: IntelId,
|
|
139
|
+
parentRunId: IntelId.nullable(),
|
|
140
|
+
failure: FlowRunFailure.nullable(),
|
|
141
|
+
});
|
|
142
|
+
// One filter and nothing else: "only the failed ones" is the question asked in almost every case,
|
|
143
|
+
// and every further facet is a report rather than a search for a fault.
|
|
144
|
+
export const ListFlowRunsInput = z.strictObject({
|
|
145
|
+
flowId: IntelId.describe("Flow whose runs to list, newest first."),
|
|
146
|
+
failedOnly: z.boolean().default(false).describe("List only the runs that failed."),
|
|
147
|
+
limit: z.number().int().min(1).max(50).default(20).describe("How many runs per page."),
|
|
148
|
+
// The `nextCursor` of the previous page. Keyset rather than an offset, because runs arrive while
|
|
149
|
+
// someone reads and an offset would skip or repeat rows exactly when a flow is busy.
|
|
150
|
+
cursor: z
|
|
151
|
+
.string()
|
|
152
|
+
.min(1)
|
|
153
|
+
.max(400)
|
|
154
|
+
.nullable()
|
|
155
|
+
.default(null)
|
|
156
|
+
.describe("The `nextCursor` of the previous page, or `null` for the first. It is a keyset rather than an offset, so runs arriving while someone reads neither skip nor repeat a row."),
|
|
157
|
+
});
|
|
158
|
+
export const FlowRunList = z.strictObject({
|
|
159
|
+
items: z.array(FlowRunSummary),
|
|
160
|
+
nextCursor: z.string().max(400).nullable(),
|
|
161
|
+
});
|
|
162
|
+
// One completed step of one run. `detail` is the step's own error text; an output is absent for the
|
|
163
|
+
// same reason it is absent from the summary.
|
|
164
|
+
export const FlowRunStepRecord = z.strictObject({
|
|
165
|
+
nodeId: FlowNodeId,
|
|
166
|
+
nodeLabel: z.string().max(160),
|
|
167
|
+
outcome: z.enum(["completed", "failed"]),
|
|
168
|
+
branch: z.string().max(120).nullable(),
|
|
169
|
+
detail: z.string().max(2_000).nullable(),
|
|
170
|
+
calledRunId: IntelId.nullable(),
|
|
171
|
+
completedAt: IsoDateTime,
|
|
172
|
+
});
|
|
173
|
+
// What one run did, step by step, oldest first, with the call chain it belongs to (#17). The trail
|
|
174
|
+
// is what makes a nested run readable: which step of which flow this run is.
|
|
175
|
+
export const FlowRunHistory = z.strictObject({
|
|
176
|
+
runId: IntelId,
|
|
177
|
+
flowId: IntelId,
|
|
178
|
+
status: FlowRunStatus,
|
|
179
|
+
steps: z.array(FlowRunStepRecord),
|
|
180
|
+
trail: z.array(FlowRunTrailEntry),
|
|
181
|
+
});
|