@humain/humain-code-contracts 0.3.3 → 0.4.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/CHANGELOG.md +4 -4
- package/dist/flow-admission.d.ts +209 -0
- package/dist/flow-admission.d.ts.map +1 -0
- package/dist/flow-admission.js +59 -0
- package/dist/flow-admission.js.map +1 -0
- package/dist/flow-common.d.ts +103 -0
- package/dist/flow-common.d.ts.map +1 -0
- package/dist/flow-common.js +282 -0
- package/dist/flow-common.js.map +1 -0
- package/dist/flow-control.d.ts +107 -0
- package/dist/flow-control.d.ts.map +1 -0
- package/dist/flow-control.js +144 -0
- package/dist/flow-control.js.map +1 -0
- package/dist/flow-events.d.ts +345 -0
- package/dist/flow-events.d.ts.map +1 -0
- package/dist/flow-events.js +147 -0
- package/dist/flow-events.js.map +1 -0
- package/dist/flow-profile.d.ts +200 -0
- package/dist/flow-profile.d.ts.map +1 -0
- package/dist/flow-profile.js +89 -0
- package/dist/flow-profile.js.map +1 -0
- package/dist/flow-sizing.d.ts +30 -0
- package/dist/flow-sizing.d.ts.map +1 -0
- package/dist/flow-sizing.js +568 -0
- package/dist/flow-sizing.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/rpc.d.ts +27 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +283 -18
- package/dist/rpc.js.map +1 -1
- package/package.json +25 -1
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
export { FlowProfileRefSchema, type FlowProfileRefV1 } from "./flow-common.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Privacy rule: every string in an event is an Id, a Digest, an enum literal, or an ISO timestamp.
|
|
5
|
+
* There is no free-text field, so prompts, messages and model output have no place to go. Syntax checks cannot tell
|
|
6
|
+
* semantic content, though: a path-like string can match an Id or model pattern. Producers must put only catalog
|
|
7
|
+
* provider/model identifiers in those fields (see docs/flow-contracts.md, trust boundaries).
|
|
8
|
+
*/
|
|
9
|
+
export declare const FLOW_EVENT_KINDS: readonly ["run_started", "size_decided", "escalated", "route_bound", "fallback", "attempt", "request_usage", "verdict", "budget", "control", "message", "run_settled"];
|
|
10
|
+
export type FlowEventKind = (typeof FLOW_EVENT_KINDS)[number];
|
|
11
|
+
export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
|
|
12
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
13
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
14
|
+
readonly eventId: Type.TString;
|
|
15
|
+
readonly runId: Type.TString;
|
|
16
|
+
readonly seq: Type.TInteger;
|
|
17
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
18
|
+
readonly profile: Type.TObject<{
|
|
19
|
+
readonly id: Type.TString;
|
|
20
|
+
readonly version: Type.TInteger;
|
|
21
|
+
readonly digest: Type.TString;
|
|
22
|
+
}>;
|
|
23
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
24
|
+
readonly kind: Type.TLiteral<"run_started">;
|
|
25
|
+
readonly payload: Type.TObject<{
|
|
26
|
+
readonly mode: Type.TUnion<[Type.TLiteral<"auto">, Type.TLiteral<"direct">]>;
|
|
27
|
+
readonly surface: Type.TUnion<[Type.TLiteral<"cli">, Type.TLiteral<"web">]>;
|
|
28
|
+
readonly admissionDigest: Type.TString;
|
|
29
|
+
readonly inputsCount: Type.TInteger;
|
|
30
|
+
readonly goalSha256: Type.TString;
|
|
31
|
+
}>;
|
|
32
|
+
}>, Type.TObject<{
|
|
33
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
34
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
35
|
+
readonly eventId: Type.TString;
|
|
36
|
+
readonly runId: Type.TString;
|
|
37
|
+
readonly seq: Type.TInteger;
|
|
38
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
39
|
+
readonly profile: Type.TObject<{
|
|
40
|
+
readonly id: Type.TString;
|
|
41
|
+
readonly version: Type.TInteger;
|
|
42
|
+
readonly digest: Type.TString;
|
|
43
|
+
}>;
|
|
44
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
45
|
+
readonly kind: Type.TLiteral<"size_decided">;
|
|
46
|
+
readonly payload: Type.TObject<{
|
|
47
|
+
readonly size: Type.TUnion<[Type.TLiteral<"small">, Type.TLiteral<"medium">, Type.TLiteral<"large">]>;
|
|
48
|
+
readonly source: Type.TUnion<[Type.TLiteral<"rules">, Type.TLiteral<"triage">, Type.TLiteral<"override">]>;
|
|
49
|
+
readonly ruleScore: Type.TNumber;
|
|
50
|
+
readonly thresholds: Type.TObject<{
|
|
51
|
+
readonly mediumAt: Type.TNumber;
|
|
52
|
+
readonly largeAt: Type.TNumber;
|
|
53
|
+
}>;
|
|
54
|
+
}>;
|
|
55
|
+
}>, Type.TObject<{
|
|
56
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
57
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
58
|
+
readonly eventId: Type.TString;
|
|
59
|
+
readonly runId: Type.TString;
|
|
60
|
+
readonly seq: Type.TInteger;
|
|
61
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
62
|
+
readonly profile: Type.TObject<{
|
|
63
|
+
readonly id: Type.TString;
|
|
64
|
+
readonly version: Type.TInteger;
|
|
65
|
+
readonly digest: Type.TString;
|
|
66
|
+
}>;
|
|
67
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
68
|
+
readonly kind: Type.TLiteral<"escalated">;
|
|
69
|
+
readonly payload: Type.TObject<{
|
|
70
|
+
readonly from: Type.TUnion<[Type.TLiteral<"small">, Type.TLiteral<"medium">, Type.TLiteral<"large">]>;
|
|
71
|
+
readonly to: Type.TUnion<[Type.TLiteral<"small">, Type.TLiteral<"medium">, Type.TLiteral<"large">]>;
|
|
72
|
+
readonly reasonClass: Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">]>, Type.TLiteral<"size_underestimated">]>;
|
|
73
|
+
}>;
|
|
74
|
+
}>, Type.TObject<{
|
|
75
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
76
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
77
|
+
readonly eventId: Type.TString;
|
|
78
|
+
readonly runId: Type.TString;
|
|
79
|
+
readonly seq: Type.TInteger;
|
|
80
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
81
|
+
readonly profile: Type.TObject<{
|
|
82
|
+
readonly id: Type.TString;
|
|
83
|
+
readonly version: Type.TInteger;
|
|
84
|
+
readonly digest: Type.TString;
|
|
85
|
+
}>;
|
|
86
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
87
|
+
readonly kind: Type.TLiteral<"route_bound">;
|
|
88
|
+
readonly payload: Type.TObject<{
|
|
89
|
+
readonly taskId: Type.TString;
|
|
90
|
+
readonly role: Type.TUnion<[Type.TLiteral<"scout">, Type.TLiteral<"worker">, Type.TLiteral<"implementer">, Type.TLiteral<"lead">, Type.TLiteral<"lead_large">, Type.TLiteral<"architect">, Type.TLiteral<"reviewer">, Type.TLiteral<"security_reviewer">, Type.TLiteral<"qa">, Type.TLiteral<"triage">]>;
|
|
91
|
+
readonly model: Type.TObject<{
|
|
92
|
+
readonly provider: Type.TString;
|
|
93
|
+
readonly model: Type.TString;
|
|
94
|
+
}>;
|
|
95
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
96
|
+
readonly binding: Type.TUnion<[Type.TLiteral<"primary">, Type.TLiteral<"backup">]>;
|
|
97
|
+
readonly backupIndex: Type.TInteger;
|
|
98
|
+
}>;
|
|
99
|
+
}>, Type.TObject<{
|
|
100
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
101
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
102
|
+
readonly eventId: Type.TString;
|
|
103
|
+
readonly runId: Type.TString;
|
|
104
|
+
readonly seq: Type.TInteger;
|
|
105
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
106
|
+
readonly profile: Type.TObject<{
|
|
107
|
+
readonly id: Type.TString;
|
|
108
|
+
readonly version: Type.TInteger;
|
|
109
|
+
readonly digest: Type.TString;
|
|
110
|
+
}>;
|
|
111
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
112
|
+
readonly kind: Type.TLiteral<"fallback">;
|
|
113
|
+
readonly payload: Type.TObject<{
|
|
114
|
+
readonly taskId: Type.TString;
|
|
115
|
+
readonly role: Type.TUnion<[Type.TLiteral<"scout">, Type.TLiteral<"worker">, Type.TLiteral<"implementer">, Type.TLiteral<"lead">, Type.TLiteral<"lead_large">, Type.TLiteral<"architect">, Type.TLiteral<"reviewer">, Type.TLiteral<"security_reviewer">, Type.TLiteral<"qa">, Type.TLiteral<"triage">]>;
|
|
116
|
+
readonly from: Type.TObject<{
|
|
117
|
+
readonly provider: Type.TString;
|
|
118
|
+
readonly model: Type.TString;
|
|
119
|
+
}>;
|
|
120
|
+
readonly to: Type.TObject<{
|
|
121
|
+
readonly provider: Type.TString;
|
|
122
|
+
readonly model: Type.TString;
|
|
123
|
+
}>;
|
|
124
|
+
readonly reasonClass: Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">]>, Type.TLiteral<"size_underestimated">]>;
|
|
125
|
+
}>;
|
|
126
|
+
}>, Type.TObject<{
|
|
127
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
128
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
129
|
+
readonly eventId: Type.TString;
|
|
130
|
+
readonly runId: Type.TString;
|
|
131
|
+
readonly seq: Type.TInteger;
|
|
132
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
133
|
+
readonly profile: Type.TObject<{
|
|
134
|
+
readonly id: Type.TString;
|
|
135
|
+
readonly version: Type.TInteger;
|
|
136
|
+
readonly digest: Type.TString;
|
|
137
|
+
}>;
|
|
138
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
139
|
+
readonly kind: Type.TLiteral<"attempt">;
|
|
140
|
+
readonly payload: Type.TObject<{
|
|
141
|
+
readonly taskId: Type.TString;
|
|
142
|
+
readonly role: Type.TUnion<[Type.TLiteral<"scout">, Type.TLiteral<"worker">, Type.TLiteral<"implementer">, Type.TLiteral<"lead">, Type.TLiteral<"lead_large">, Type.TLiteral<"architect">, Type.TLiteral<"reviewer">, Type.TLiteral<"security_reviewer">, Type.TLiteral<"qa">, Type.TLiteral<"triage">]>;
|
|
143
|
+
readonly attempt: Type.TInteger;
|
|
144
|
+
readonly state: Type.TUnion<[Type.TLiteral<"started">, Type.TLiteral<"succeeded">, Type.TLiteral<"failed">, Type.TLiteral<"retried">, Type.TLiteral<"cancelled">]>;
|
|
145
|
+
readonly failureClass: Type.TOptional<Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">]>>;
|
|
146
|
+
}>;
|
|
147
|
+
}>, Type.TObject<{
|
|
148
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
149
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
150
|
+
readonly eventId: Type.TString;
|
|
151
|
+
readonly runId: Type.TString;
|
|
152
|
+
readonly seq: Type.TInteger;
|
|
153
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
154
|
+
readonly profile: Type.TObject<{
|
|
155
|
+
readonly id: Type.TString;
|
|
156
|
+
readonly version: Type.TInteger;
|
|
157
|
+
readonly digest: Type.TString;
|
|
158
|
+
}>;
|
|
159
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
160
|
+
readonly kind: Type.TLiteral<"request_usage">;
|
|
161
|
+
readonly payload: Type.TObject<{
|
|
162
|
+
readonly requestId: Type.TString;
|
|
163
|
+
readonly taskId: Type.TString;
|
|
164
|
+
readonly role: Type.TUnion<[Type.TLiteral<"scout">, Type.TLiteral<"worker">, Type.TLiteral<"implementer">, Type.TLiteral<"lead">, Type.TLiteral<"lead_large">, Type.TLiteral<"architect">, Type.TLiteral<"reviewer">, Type.TLiteral<"security_reviewer">, Type.TLiteral<"qa">, Type.TLiteral<"triage">]>;
|
|
165
|
+
readonly model: Type.TObject<{
|
|
166
|
+
readonly provider: Type.TString;
|
|
167
|
+
readonly model: Type.TString;
|
|
168
|
+
}>;
|
|
169
|
+
readonly inputTokens: Type.TInteger;
|
|
170
|
+
readonly outputTokens: Type.TInteger;
|
|
171
|
+
readonly cacheReadTokens: Type.TInteger;
|
|
172
|
+
readonly cacheWriteTokens: Type.TInteger;
|
|
173
|
+
readonly costMicrousd: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
174
|
+
readonly costBasis: Type.TUnion<[Type.TLiteral<"reported">, Type.TLiteral<"estimated">, Type.TLiteral<"unknown">]>;
|
|
175
|
+
readonly durationMs: Type.TInteger;
|
|
176
|
+
}>;
|
|
177
|
+
}>, Type.TObject<{
|
|
178
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
179
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
180
|
+
readonly eventId: Type.TString;
|
|
181
|
+
readonly runId: Type.TString;
|
|
182
|
+
readonly seq: Type.TInteger;
|
|
183
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
184
|
+
readonly profile: Type.TObject<{
|
|
185
|
+
readonly id: Type.TString;
|
|
186
|
+
readonly version: Type.TInteger;
|
|
187
|
+
readonly digest: Type.TString;
|
|
188
|
+
}>;
|
|
189
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
190
|
+
readonly kind: Type.TLiteral<"verdict">;
|
|
191
|
+
readonly payload: Type.TObject<{
|
|
192
|
+
readonly stage: Type.TUnion<[Type.TLiteral<"check">, Type.TLiteral<"review">, Type.TLiteral<"qa">]>;
|
|
193
|
+
readonly taskId: Type.TString;
|
|
194
|
+
readonly verdict: Type.TUnion<[Type.TLiteral<"pass">, Type.TLiteral<"fail">, Type.TLiteral<"blocked">]>;
|
|
195
|
+
readonly findingsCount: Type.TInteger;
|
|
196
|
+
readonly checkId: Type.TOptional<Type.TString>;
|
|
197
|
+
}>;
|
|
198
|
+
}>, Type.TObject<{
|
|
199
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
200
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
201
|
+
readonly eventId: Type.TString;
|
|
202
|
+
readonly runId: Type.TString;
|
|
203
|
+
readonly seq: Type.TInteger;
|
|
204
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
205
|
+
readonly profile: Type.TObject<{
|
|
206
|
+
readonly id: Type.TString;
|
|
207
|
+
readonly version: Type.TInteger;
|
|
208
|
+
readonly digest: Type.TString;
|
|
209
|
+
}>;
|
|
210
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
211
|
+
readonly kind: Type.TLiteral<"budget">;
|
|
212
|
+
readonly payload: Type.TObject<{
|
|
213
|
+
readonly spentMicrousd: Type.TInteger;
|
|
214
|
+
readonly capMicrousd: Type.TInteger;
|
|
215
|
+
readonly pct: Type.TNumber;
|
|
216
|
+
readonly state: Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"warn">, Type.TLiteral<"stop">]>;
|
|
217
|
+
}>;
|
|
218
|
+
}>, Type.TObject<{
|
|
219
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
220
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
221
|
+
readonly eventId: Type.TString;
|
|
222
|
+
readonly runId: Type.TString;
|
|
223
|
+
readonly seq: Type.TInteger;
|
|
224
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
225
|
+
readonly profile: Type.TObject<{
|
|
226
|
+
readonly id: Type.TString;
|
|
227
|
+
readonly version: Type.TInteger;
|
|
228
|
+
readonly digest: Type.TString;
|
|
229
|
+
}>;
|
|
230
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
231
|
+
readonly kind: Type.TLiteral<"control">;
|
|
232
|
+
readonly payload: Type.TObject<{
|
|
233
|
+
readonly action: Type.TUnion<[Type.TLiteral<"pause">, Type.TLiteral<"resume">, Type.TLiteral<"cancel">, Type.TLiteral<"message">, Type.TLiteral<"status">]>;
|
|
234
|
+
readonly commandId: Type.TString;
|
|
235
|
+
readonly state: Type.TUnion<[Type.TLiteral<"accepted">, Type.TLiteral<"applied">, Type.TLiteral<"rejected">]>;
|
|
236
|
+
readonly latencyMs: Type.TInteger;
|
|
237
|
+
}>;
|
|
238
|
+
}>, Type.TObject<{
|
|
239
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
240
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
241
|
+
readonly eventId: Type.TString;
|
|
242
|
+
readonly runId: Type.TString;
|
|
243
|
+
readonly seq: Type.TInteger;
|
|
244
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
245
|
+
readonly profile: Type.TObject<{
|
|
246
|
+
readonly id: Type.TString;
|
|
247
|
+
readonly version: Type.TInteger;
|
|
248
|
+
readonly digest: Type.TString;
|
|
249
|
+
}>;
|
|
250
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
251
|
+
readonly kind: Type.TLiteral<"message">;
|
|
252
|
+
readonly payload: Type.TObject<{
|
|
253
|
+
readonly messageId: Type.TString;
|
|
254
|
+
readonly disposition: Type.TUnion<[Type.TLiteral<"live">, Type.TLiteral<"queued">, Type.TLiteral<"rejected">]>;
|
|
255
|
+
readonly targetRole: Type.TUnion<[Type.TLiteral<"scout">, Type.TLiteral<"worker">, Type.TLiteral<"implementer">, Type.TLiteral<"lead">, Type.TLiteral<"lead_large">, Type.TLiteral<"architect">, Type.TLiteral<"reviewer">, Type.TLiteral<"security_reviewer">, Type.TLiteral<"qa">, Type.TLiteral<"triage">]>;
|
|
256
|
+
readonly textSha256: Type.TString;
|
|
257
|
+
readonly textLength: Type.TInteger;
|
|
258
|
+
}>;
|
|
259
|
+
}>, Type.TObject<{
|
|
260
|
+
readonly schema: Type.TLiteral<"humain-flow-event">;
|
|
261
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
262
|
+
readonly eventId: Type.TString;
|
|
263
|
+
readonly runId: Type.TString;
|
|
264
|
+
readonly seq: Type.TInteger;
|
|
265
|
+
readonly ts: Type.TRefine<Type.TString>;
|
|
266
|
+
readonly profile: Type.TObject<{
|
|
267
|
+
readonly id: Type.TString;
|
|
268
|
+
readonly version: Type.TInteger;
|
|
269
|
+
readonly digest: Type.TString;
|
|
270
|
+
}>;
|
|
271
|
+
readonly causes: Type.TArray<Type.TString>;
|
|
272
|
+
readonly kind: Type.TLiteral<"run_settled">;
|
|
273
|
+
readonly payload: Type.TObject<{
|
|
274
|
+
readonly outcome: Type.TUnion<[Type.TLiteral<"succeeded">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"budget_stopped">, Type.TLiteral<"interrupted">]>;
|
|
275
|
+
readonly failureClass: Type.TOptional<Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">]>>;
|
|
276
|
+
readonly settledCleanly: Type.TBoolean;
|
|
277
|
+
readonly retryOffer: Type.TArray<Type.TUnion<[Type.TLiteral<"flow">, Type.TLiteral<"direct">]>>;
|
|
278
|
+
readonly totals: Type.TObject<{
|
|
279
|
+
readonly scout: Type.TOptional<Type.TObject<{
|
|
280
|
+
readonly tokens: Type.TInteger;
|
|
281
|
+
readonly costMicrousd: Type.TInteger;
|
|
282
|
+
readonly durationMs: Type.TInteger;
|
|
283
|
+
readonly requests: Type.TInteger;
|
|
284
|
+
}>>;
|
|
285
|
+
readonly worker: Type.TOptional<Type.TObject<{
|
|
286
|
+
readonly tokens: Type.TInteger;
|
|
287
|
+
readonly costMicrousd: Type.TInteger;
|
|
288
|
+
readonly durationMs: Type.TInteger;
|
|
289
|
+
readonly requests: Type.TInteger;
|
|
290
|
+
}>>;
|
|
291
|
+
readonly implementer: Type.TOptional<Type.TObject<{
|
|
292
|
+
readonly tokens: Type.TInteger;
|
|
293
|
+
readonly costMicrousd: Type.TInteger;
|
|
294
|
+
readonly durationMs: Type.TInteger;
|
|
295
|
+
readonly requests: Type.TInteger;
|
|
296
|
+
}>>;
|
|
297
|
+
readonly lead: Type.TOptional<Type.TObject<{
|
|
298
|
+
readonly tokens: Type.TInteger;
|
|
299
|
+
readonly costMicrousd: Type.TInteger;
|
|
300
|
+
readonly durationMs: Type.TInteger;
|
|
301
|
+
readonly requests: Type.TInteger;
|
|
302
|
+
}>>;
|
|
303
|
+
readonly lead_large: Type.TOptional<Type.TObject<{
|
|
304
|
+
readonly tokens: Type.TInteger;
|
|
305
|
+
readonly costMicrousd: Type.TInteger;
|
|
306
|
+
readonly durationMs: Type.TInteger;
|
|
307
|
+
readonly requests: Type.TInteger;
|
|
308
|
+
}>>;
|
|
309
|
+
readonly architect: Type.TOptional<Type.TObject<{
|
|
310
|
+
readonly tokens: Type.TInteger;
|
|
311
|
+
readonly costMicrousd: Type.TInteger;
|
|
312
|
+
readonly durationMs: Type.TInteger;
|
|
313
|
+
readonly requests: Type.TInteger;
|
|
314
|
+
}>>;
|
|
315
|
+
readonly reviewer: Type.TOptional<Type.TObject<{
|
|
316
|
+
readonly tokens: Type.TInteger;
|
|
317
|
+
readonly costMicrousd: Type.TInteger;
|
|
318
|
+
readonly durationMs: Type.TInteger;
|
|
319
|
+
readonly requests: Type.TInteger;
|
|
320
|
+
}>>;
|
|
321
|
+
readonly security_reviewer: Type.TOptional<Type.TObject<{
|
|
322
|
+
readonly tokens: Type.TInteger;
|
|
323
|
+
readonly costMicrousd: Type.TInteger;
|
|
324
|
+
readonly durationMs: Type.TInteger;
|
|
325
|
+
readonly requests: Type.TInteger;
|
|
326
|
+
}>>;
|
|
327
|
+
readonly qa: Type.TOptional<Type.TObject<{
|
|
328
|
+
readonly tokens: Type.TInteger;
|
|
329
|
+
readonly costMicrousd: Type.TInteger;
|
|
330
|
+
readonly durationMs: Type.TInteger;
|
|
331
|
+
readonly requests: Type.TInteger;
|
|
332
|
+
}>>;
|
|
333
|
+
readonly triage: Type.TOptional<Type.TObject<{
|
|
334
|
+
readonly tokens: Type.TInteger;
|
|
335
|
+
readonly costMicrousd: Type.TInteger;
|
|
336
|
+
readonly durationMs: Type.TInteger;
|
|
337
|
+
readonly requests: Type.TInteger;
|
|
338
|
+
}>>;
|
|
339
|
+
}>;
|
|
340
|
+
}>;
|
|
341
|
+
}>]>;
|
|
342
|
+
export type FlowEventV1 = Static<typeof FlowEventV1Schema>;
|
|
343
|
+
/** Validates a plain-data snapshot of `input` and returns the snapshot (never the caller's object). */
|
|
344
|
+
export declare function parseFlowEventV1(input: unknown): FlowEventV1;
|
|
345
|
+
//# sourceMappingURL=flow-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-events.d.ts","sourceRoot":"","sources":["../src/flow-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,IAAI,EAAE,MAAM,SAAS,CAAC;AAqB1D,OAAO,EAAE,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/E;;;;;GAKG;AAEH,eAAO,MAAM,gBAAgB,YAC5B,aAAa,EACb,cAAc,EACd,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,eAAe,EACf,SAAS,EACT,QAAQ,EACR,SAAS,EACT,SAAS,EACT,aAAa,CACJ,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AA2B9D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwH5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAe3D,uGAAuG;AACvG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAE5D"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { compileFlow, FLOW_ID_PATTERN, FlowCountSchema, FlowDigestSchema, FlowFailureClassSchema, FlowIdSchema, FlowMicrousdSchema, FlowPositiveIntSchema, FlowProfileRefSchema, FlowReasonClassSchema, FlowRoleSchema, FlowSizeSchema, FlowTimestampSchema, lit, parseFlowData, partialByRole, StrictObject, } from "./flow-common.js";
|
|
3
|
+
export { FlowProfileRefSchema } from "./flow-common.js";
|
|
4
|
+
/**
|
|
5
|
+
* Privacy rule: every string in an event is an Id, a Digest, an enum literal, or an ISO timestamp.
|
|
6
|
+
* There is no free-text field, so prompts, messages and model output have no place to go. Syntax checks cannot tell
|
|
7
|
+
* semantic content, though: a path-like string can match an Id or model pattern. Producers must put only catalog
|
|
8
|
+
* provider/model identifiers in those fields (see docs/flow-contracts.md, trust boundaries).
|
|
9
|
+
*/
|
|
10
|
+
export const FLOW_EVENT_KINDS = [
|
|
11
|
+
"run_started",
|
|
12
|
+
"size_decided",
|
|
13
|
+
"escalated",
|
|
14
|
+
"route_bound",
|
|
15
|
+
"fallback",
|
|
16
|
+
"attempt",
|
|
17
|
+
"request_usage",
|
|
18
|
+
"verdict",
|
|
19
|
+
"budget",
|
|
20
|
+
"control",
|
|
21
|
+
"message",
|
|
22
|
+
"run_settled",
|
|
23
|
+
];
|
|
24
|
+
const Mode = lit("auto", "direct");
|
|
25
|
+
const Effort = lit("low", "medium", "high");
|
|
26
|
+
const EventModelRefSchema = StrictObject({ provider: FlowIdSchema, model: Type.String({ pattern: FLOW_ID_PATTERN }) });
|
|
27
|
+
const event = (kind, payload) => StrictObject({
|
|
28
|
+
schema: Type.Literal("humain-flow-event"),
|
|
29
|
+
schemaVersion: Type.Literal(1),
|
|
30
|
+
eventId: FlowIdSchema,
|
|
31
|
+
runId: FlowIdSchema,
|
|
32
|
+
seq: FlowPositiveIntSchema,
|
|
33
|
+
ts: FlowTimestampSchema,
|
|
34
|
+
profile: FlowProfileRefSchema,
|
|
35
|
+
causes: Type.Array(FlowIdSchema, { maxItems: 16 }),
|
|
36
|
+
kind: Type.Literal(kind),
|
|
37
|
+
payload,
|
|
38
|
+
});
|
|
39
|
+
const RoleTotals = StrictObject({
|
|
40
|
+
tokens: FlowCountSchema,
|
|
41
|
+
costMicrousd: FlowMicrousdSchema,
|
|
42
|
+
durationMs: FlowCountSchema,
|
|
43
|
+
requests: FlowCountSchema,
|
|
44
|
+
});
|
|
45
|
+
export const FlowEventV1Schema = Type.Union([
|
|
46
|
+
event("run_started", StrictObject({
|
|
47
|
+
mode: Mode,
|
|
48
|
+
surface: lit("cli", "web"),
|
|
49
|
+
admissionDigest: FlowDigestSchema,
|
|
50
|
+
inputsCount: FlowCountSchema,
|
|
51
|
+
goalSha256: FlowDigestSchema,
|
|
52
|
+
})),
|
|
53
|
+
event("size_decided", StrictObject({
|
|
54
|
+
size: FlowSizeSchema,
|
|
55
|
+
source: lit("rules", "triage", "override"),
|
|
56
|
+
ruleScore: Type.Number({ minimum: 0, maximum: 1_000_000 }),
|
|
57
|
+
thresholds: StrictObject({
|
|
58
|
+
mediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),
|
|
59
|
+
largeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),
|
|
60
|
+
}),
|
|
61
|
+
})),
|
|
62
|
+
event("escalated", StrictObject({ from: FlowSizeSchema, to: FlowSizeSchema, reasonClass: FlowReasonClassSchema })),
|
|
63
|
+
event("route_bound", StrictObject({
|
|
64
|
+
taskId: FlowIdSchema,
|
|
65
|
+
role: FlowRoleSchema,
|
|
66
|
+
model: EventModelRefSchema,
|
|
67
|
+
effort: Effort,
|
|
68
|
+
binding: lit("primary", "backup"),
|
|
69
|
+
backupIndex: Type.Integer({ minimum: 0, maximum: 7 }),
|
|
70
|
+
})),
|
|
71
|
+
event("fallback", StrictObject({
|
|
72
|
+
taskId: FlowIdSchema,
|
|
73
|
+
role: FlowRoleSchema,
|
|
74
|
+
from: EventModelRefSchema,
|
|
75
|
+
to: EventModelRefSchema,
|
|
76
|
+
reasonClass: FlowReasonClassSchema,
|
|
77
|
+
})),
|
|
78
|
+
event("attempt", StrictObject({
|
|
79
|
+
taskId: FlowIdSchema,
|
|
80
|
+
role: FlowRoleSchema,
|
|
81
|
+
attempt: FlowPositiveIntSchema,
|
|
82
|
+
state: lit("started", "succeeded", "failed", "retried", "cancelled"),
|
|
83
|
+
failureClass: Type.Optional(FlowFailureClassSchema),
|
|
84
|
+
})),
|
|
85
|
+
event("request_usage", StrictObject({
|
|
86
|
+
requestId: FlowIdSchema,
|
|
87
|
+
taskId: FlowIdSchema,
|
|
88
|
+
role: FlowRoleSchema,
|
|
89
|
+
model: EventModelRefSchema,
|
|
90
|
+
inputTokens: FlowCountSchema,
|
|
91
|
+
outputTokens: FlowCountSchema,
|
|
92
|
+
cacheReadTokens: FlowCountSchema,
|
|
93
|
+
cacheWriteTokens: FlowCountSchema,
|
|
94
|
+
costMicrousd: Type.Union([FlowMicrousdSchema, Type.Null()]),
|
|
95
|
+
costBasis: lit("reported", "estimated", "unknown"),
|
|
96
|
+
durationMs: FlowCountSchema,
|
|
97
|
+
})),
|
|
98
|
+
event("verdict", StrictObject({
|
|
99
|
+
stage: lit("check", "review", "qa"),
|
|
100
|
+
taskId: FlowIdSchema,
|
|
101
|
+
verdict: lit("pass", "fail", "blocked"),
|
|
102
|
+
findingsCount: FlowCountSchema,
|
|
103
|
+
checkId: Type.Optional(FlowIdSchema),
|
|
104
|
+
})),
|
|
105
|
+
event("budget", StrictObject({
|
|
106
|
+
spentMicrousd: FlowMicrousdSchema,
|
|
107
|
+
capMicrousd: FlowMicrousdSchema,
|
|
108
|
+
pct: Type.Number({ minimum: 0, maximum: 100 }),
|
|
109
|
+
state: lit("ok", "warn", "stop"),
|
|
110
|
+
})),
|
|
111
|
+
event("control", StrictObject({
|
|
112
|
+
action: lit("pause", "resume", "cancel", "message", "status"),
|
|
113
|
+
commandId: FlowIdSchema,
|
|
114
|
+
state: lit("accepted", "applied", "rejected"),
|
|
115
|
+
latencyMs: FlowCountSchema,
|
|
116
|
+
})),
|
|
117
|
+
event("message", StrictObject({
|
|
118
|
+
messageId: FlowIdSchema,
|
|
119
|
+
disposition: lit("live", "queued", "rejected"),
|
|
120
|
+
targetRole: FlowRoleSchema,
|
|
121
|
+
textSha256: FlowDigestSchema,
|
|
122
|
+
textLength: Type.Integer({ minimum: 1, maximum: 16_000 }),
|
|
123
|
+
})),
|
|
124
|
+
event("run_settled", StrictObject({
|
|
125
|
+
outcome: lit("succeeded", "failed", "cancelled", "budget_stopped", "interrupted"),
|
|
126
|
+
failureClass: Type.Optional(FlowFailureClassSchema),
|
|
127
|
+
settledCleanly: Type.Boolean(),
|
|
128
|
+
// Subset of the two retry modes offered to the user; unique, order-free (full offer = both).
|
|
129
|
+
retryOffer: Type.Array(lit("flow", "direct"), { maxItems: 2, uniqueItems: true }),
|
|
130
|
+
totals: partialByRole(RoleTotals),
|
|
131
|
+
})),
|
|
132
|
+
]);
|
|
133
|
+
const Validator = compileFlow(FlowEventV1Schema);
|
|
134
|
+
/** `request_usage.costMicrousd` is null exactly when `costBasis` is "unknown"; never 0 for unknown. */
|
|
135
|
+
function crossFieldsValid(doc) {
|
|
136
|
+
if (doc.kind === "request_usage")
|
|
137
|
+
return (doc.payload.costMicrousd === null) === (doc.payload.costBasis === "unknown");
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
function isEvent(value) {
|
|
141
|
+
return Validator.Check(value) && crossFieldsValid(value);
|
|
142
|
+
}
|
|
143
|
+
/** Validates a plain-data snapshot of `input` and returns the snapshot (never the caller's object). */
|
|
144
|
+
export function parseFlowEventV1(input) {
|
|
145
|
+
return parseFlowData("event_invalid", input, isEvent);
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=flow-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-events.js","sourceRoot":"","sources":["../src/flow-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,SAAS,CAAC;AAC1D,OA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BAAsB,CAAC;QACnD,cAAc,EAAE,IAAI,CAAC,OAAO,EAAE;QAC9B,6FAA6F;QAC7F,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;QACjF,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC;KACjC,CAAC,CACF;CACD,CAAC,CAAC;AAGH,MAAM,SAAS,GAAG,WAAW,CAAC,iBAAiB,CAAC,CAAC;AAEjD,uGAAuG;AACvG,SAAS,gBAAgB,CAAC,GAAgB;IACzC,IAAI,GAAG,CAAC,IAAI,KAAK,eAAe;QAC/B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC9B,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC9C,OAAO,aAAa,CAAC,eAAe,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { type Static, type TSchema, Type } from \"typebox\";\nimport {\n\tcompileFlow,\n\tFLOW_ID_PATTERN,\n\tFlowCountSchema,\n\tFlowDigestSchema,\n\tFlowFailureClassSchema,\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\tFlowPositiveIntSchema,\n\tFlowProfileRefSchema,\n\tFlowReasonClassSchema,\n\tFlowRoleSchema,\n\tFlowSizeSchema,\n\tFlowTimestampSchema,\n\tlit,\n\tparseFlowData,\n\tpartialByRole,\n\tStrictObject,\n} from \"./flow-common.ts\";\n\nexport { FlowProfileRefSchema, type FlowProfileRefV1 } from \"./flow-common.ts\";\n\n/**\n * Privacy rule: every string in an event is an Id, a Digest, an enum literal, or an ISO timestamp.\n * There is no free-text field, so prompts, messages and model output have no place to go. Syntax checks cannot tell\n * semantic content, though: a path-like string can match an Id or model pattern. Producers must put only catalog\n * provider/model identifiers in those fields (see docs/flow-contracts.md, trust boundaries).\n */\n\nexport const FLOW_EVENT_KINDS = [\n\t\"run_started\",\n\t\"size_decided\",\n\t\"escalated\",\n\t\"route_bound\",\n\t\"fallback\",\n\t\"attempt\",\n\t\"request_usage\",\n\t\"verdict\",\n\t\"budget\",\n\t\"control\",\n\t\"message\",\n\t\"run_settled\",\n] as const;\nexport type FlowEventKind = (typeof FLOW_EVENT_KINDS)[number];\n\nconst Mode = lit(\"auto\", \"direct\");\nconst Effort = lit(\"low\", \"medium\", \"high\");\nconst EventModelRefSchema = StrictObject({ provider: FlowIdSchema, model: Type.String({ pattern: FLOW_ID_PATTERN }) });\n\nconst event = <const K extends string, P extends TSchema>(kind: K, payload: P) =>\n\tStrictObject({\n\t\tschema: Type.Literal(\"humain-flow-event\"),\n\t\tschemaVersion: Type.Literal(1),\n\t\teventId: FlowIdSchema,\n\t\trunId: FlowIdSchema,\n\t\tseq: FlowPositiveIntSchema,\n\t\tts: FlowTimestampSchema,\n\t\tprofile: FlowProfileRefSchema,\n\t\tcauses: Type.Array(FlowIdSchema, { maxItems: 16 }),\n\t\tkind: Type.Literal(kind),\n\t\tpayload,\n\t});\n\nconst RoleTotals = StrictObject({\n\ttokens: FlowCountSchema,\n\tcostMicrousd: FlowMicrousdSchema,\n\tdurationMs: FlowCountSchema,\n\trequests: FlowCountSchema,\n});\n\nexport const FlowEventV1Schema = Type.Union([\n\tevent(\n\t\t\"run_started\",\n\t\tStrictObject({\n\t\t\tmode: Mode,\n\t\t\tsurface: lit(\"cli\", \"web\"),\n\t\t\tadmissionDigest: FlowDigestSchema,\n\t\t\tinputsCount: FlowCountSchema,\n\t\t\tgoalSha256: FlowDigestSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"size_decided\",\n\t\tStrictObject({\n\t\t\tsize: FlowSizeSchema,\n\t\t\tsource: lit(\"rules\", \"triage\", \"override\"),\n\t\t\truleScore: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\tthresholds: StrictObject({\n\t\t\t\tmediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t\tlargeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t}),\n\t\t}),\n\t),\n\tevent(\"escalated\", StrictObject({ from: FlowSizeSchema, to: FlowSizeSchema, reasonClass: FlowReasonClassSchema })),\n\tevent(\n\t\t\"route_bound\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tmodel: EventModelRefSchema,\n\t\t\teffort: Effort,\n\t\t\tbinding: lit(\"primary\", \"backup\"),\n\t\t\tbackupIndex: Type.Integer({ minimum: 0, maximum: 7 }),\n\t\t}),\n\t),\n\tevent(\n\t\t\"fallback\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tfrom: EventModelRefSchema,\n\t\t\tto: EventModelRefSchema,\n\t\t\treasonClass: FlowReasonClassSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"attempt\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tattempt: FlowPositiveIntSchema,\n\t\t\tstate: lit(\"started\", \"succeeded\", \"failed\", \"retried\", \"cancelled\"),\n\t\t\tfailureClass: Type.Optional(FlowFailureClassSchema),\n\t\t}),\n\t),\n\tevent(\n\t\t\"request_usage\",\n\t\tStrictObject({\n\t\t\trequestId: FlowIdSchema,\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tmodel: EventModelRefSchema,\n\t\t\tinputTokens: FlowCountSchema,\n\t\t\toutputTokens: FlowCountSchema,\n\t\t\tcacheReadTokens: FlowCountSchema,\n\t\t\tcacheWriteTokens: FlowCountSchema,\n\t\t\tcostMicrousd: Type.Union([FlowMicrousdSchema, Type.Null()]),\n\t\t\tcostBasis: lit(\"reported\", \"estimated\", \"unknown\"),\n\t\t\tdurationMs: FlowCountSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"verdict\",\n\t\tStrictObject({\n\t\t\tstage: lit(\"check\", \"review\", \"qa\"),\n\t\t\ttaskId: FlowIdSchema,\n\t\t\tverdict: lit(\"pass\", \"fail\", \"blocked\"),\n\t\t\tfindingsCount: FlowCountSchema,\n\t\t\tcheckId: Type.Optional(FlowIdSchema),\n\t\t}),\n\t),\n\tevent(\n\t\t\"budget\",\n\t\tStrictObject({\n\t\t\tspentMicrousd: FlowMicrousdSchema,\n\t\t\tcapMicrousd: FlowMicrousdSchema,\n\t\t\tpct: Type.Number({ minimum: 0, maximum: 100 }),\n\t\t\tstate: lit(\"ok\", \"warn\", \"stop\"),\n\t\t}),\n\t),\n\tevent(\n\t\t\"control\",\n\t\tStrictObject({\n\t\t\taction: lit(\"pause\", \"resume\", \"cancel\", \"message\", \"status\"),\n\t\t\tcommandId: FlowIdSchema,\n\t\t\tstate: lit(\"accepted\", \"applied\", \"rejected\"),\n\t\t\tlatencyMs: FlowCountSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"message\",\n\t\tStrictObject({\n\t\t\tmessageId: FlowIdSchema,\n\t\t\tdisposition: lit(\"live\", \"queued\", \"rejected\"),\n\t\t\ttargetRole: FlowRoleSchema,\n\t\t\ttextSha256: FlowDigestSchema,\n\t\t\ttextLength: Type.Integer({ minimum: 1, maximum: 16_000 }),\n\t\t}),\n\t),\n\tevent(\n\t\t\"run_settled\",\n\t\tStrictObject({\n\t\t\toutcome: lit(\"succeeded\", \"failed\", \"cancelled\", \"budget_stopped\", \"interrupted\"),\n\t\t\tfailureClass: Type.Optional(FlowFailureClassSchema),\n\t\t\tsettledCleanly: Type.Boolean(),\n\t\t\t// Subset of the two retry modes offered to the user; unique, order-free (full offer = both).\n\t\t\tretryOffer: Type.Array(lit(\"flow\", \"direct\"), { maxItems: 2, uniqueItems: true }),\n\t\t\ttotals: partialByRole(RoleTotals),\n\t\t}),\n\t),\n]);\nexport type FlowEventV1 = Static<typeof FlowEventV1Schema>;\n\nconst Validator = compileFlow(FlowEventV1Schema);\n\n/** `request_usage.costMicrousd` is null exactly when `costBasis` is \"unknown\"; never 0 for unknown. */\nfunction crossFieldsValid(doc: FlowEventV1): boolean {\n\tif (doc.kind === \"request_usage\")\n\t\treturn (doc.payload.costMicrousd === null) === (doc.payload.costBasis === \"unknown\");\n\treturn true;\n}\n\nfunction isEvent(value: unknown): value is FlowEventV1 {\n\treturn Validator.Check(value) && crossFieldsValid(value);\n}\n\n/** Validates a plain-data snapshot of `input` and returns the snapshot (never the caller's object). */\nexport function parseFlowEventV1(input: unknown): FlowEventV1 {\n\treturn parseFlowData(\"event_invalid\", input, isEvent);\n}\n"]}
|