@humain/humain-code-contracts 0.3.2 → 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 +25 -1
- package/README.md +10 -1
- 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/dist/trace-artifact.d.ts +1 -1
- package/dist/trace-artifact.d.ts.map +1 -1
- package/dist/trace-artifact.js +3 -1
- package/dist/trace-artifact.js.map +1 -1
- package/dist/trace-http.d.ts.map +1 -1
- package/dist/trace-http.js +3 -0
- package/dist/trace-http.js.map +1 -1
- package/dist/trace-payload.d.ts +25 -1
- package/dist/trace-payload.d.ts.map +1 -1
- package/dist/trace-payload.js +2 -0
- package/dist/trace-payload.js.map +1 -1
- package/dist/trace-records.d.ts +985 -0
- package/dist/trace-records.d.ts.map +1 -0
- package/dist/trace-records.js +535 -0
- package/dist/trace-records.js.map +1 -0
- package/dist/trace.d.ts +1 -0
- package/dist/trace.d.ts.map +1 -1
- package/dist/trace.js +1 -0
- package/dist/trace.js.map +1 -1
- package/package.json +29 -5
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
import { type FlowDigestHasher } from "./flow-common.ts";
|
|
3
|
+
export { FlowProfileRefSchema, type FlowProfileRefV1 } from "./flow-common.ts";
|
|
4
|
+
export declare const FlowEffortSchema: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
5
|
+
export declare const FlowRoleBindingSchema: Type.TObject<{
|
|
6
|
+
readonly primary: Type.TObject<{
|
|
7
|
+
readonly provider: Type.TString;
|
|
8
|
+
readonly model: Type.TString;
|
|
9
|
+
}>;
|
|
10
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
11
|
+
readonly provider: Type.TString;
|
|
12
|
+
readonly model: Type.TString;
|
|
13
|
+
}>>;
|
|
14
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
15
|
+
}>;
|
|
16
|
+
export type FlowRoleBindingV1 = Static<typeof FlowRoleBindingSchema>;
|
|
17
|
+
export declare const FlowProfileV1Schema: Type.TObject<{
|
|
18
|
+
readonly schema: Type.TLiteral<"humain-flow-profile">;
|
|
19
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
20
|
+
readonly id: Type.TString;
|
|
21
|
+
readonly version: Type.TInteger;
|
|
22
|
+
readonly digest: Type.TString;
|
|
23
|
+
readonly kind: Type.TUnion<[Type.TLiteral<"direct">, Type.TLiteral<"flow">]>;
|
|
24
|
+
readonly label: Type.TString;
|
|
25
|
+
readonly description: Type.TOptional<Type.TString>;
|
|
26
|
+
readonly direct: Type.TOptional<Type.TObject<{
|
|
27
|
+
readonly model: Type.TObject<{
|
|
28
|
+
readonly provider: Type.TString;
|
|
29
|
+
readonly model: Type.TString;
|
|
30
|
+
}>;
|
|
31
|
+
readonly fallbacks: Type.TArray<Type.TObject<{
|
|
32
|
+
readonly provider: Type.TString;
|
|
33
|
+
readonly model: Type.TString;
|
|
34
|
+
}>>;
|
|
35
|
+
}>>;
|
|
36
|
+
readonly roles: Type.TOptional<Type.TObject<{
|
|
37
|
+
readonly scout: Type.TOptional<Type.TObject<{
|
|
38
|
+
readonly primary: Type.TObject<{
|
|
39
|
+
readonly provider: Type.TString;
|
|
40
|
+
readonly model: Type.TString;
|
|
41
|
+
}>;
|
|
42
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
43
|
+
readonly provider: Type.TString;
|
|
44
|
+
readonly model: Type.TString;
|
|
45
|
+
}>>;
|
|
46
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
47
|
+
}>>;
|
|
48
|
+
readonly worker: Type.TOptional<Type.TObject<{
|
|
49
|
+
readonly primary: Type.TObject<{
|
|
50
|
+
readonly provider: Type.TString;
|
|
51
|
+
readonly model: Type.TString;
|
|
52
|
+
}>;
|
|
53
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
54
|
+
readonly provider: Type.TString;
|
|
55
|
+
readonly model: Type.TString;
|
|
56
|
+
}>>;
|
|
57
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
58
|
+
}>>;
|
|
59
|
+
readonly implementer: Type.TOptional<Type.TObject<{
|
|
60
|
+
readonly primary: Type.TObject<{
|
|
61
|
+
readonly provider: Type.TString;
|
|
62
|
+
readonly model: Type.TString;
|
|
63
|
+
}>;
|
|
64
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
65
|
+
readonly provider: Type.TString;
|
|
66
|
+
readonly model: Type.TString;
|
|
67
|
+
}>>;
|
|
68
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
69
|
+
}>>;
|
|
70
|
+
readonly lead: Type.TOptional<Type.TObject<{
|
|
71
|
+
readonly primary: Type.TObject<{
|
|
72
|
+
readonly provider: Type.TString;
|
|
73
|
+
readonly model: Type.TString;
|
|
74
|
+
}>;
|
|
75
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
76
|
+
readonly provider: Type.TString;
|
|
77
|
+
readonly model: Type.TString;
|
|
78
|
+
}>>;
|
|
79
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
80
|
+
}>>;
|
|
81
|
+
readonly lead_large: Type.TOptional<Type.TObject<{
|
|
82
|
+
readonly primary: Type.TObject<{
|
|
83
|
+
readonly provider: Type.TString;
|
|
84
|
+
readonly model: Type.TString;
|
|
85
|
+
}>;
|
|
86
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
87
|
+
readonly provider: Type.TString;
|
|
88
|
+
readonly model: Type.TString;
|
|
89
|
+
}>>;
|
|
90
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
91
|
+
}>>;
|
|
92
|
+
readonly architect: Type.TOptional<Type.TObject<{
|
|
93
|
+
readonly primary: Type.TObject<{
|
|
94
|
+
readonly provider: Type.TString;
|
|
95
|
+
readonly model: Type.TString;
|
|
96
|
+
}>;
|
|
97
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
98
|
+
readonly provider: Type.TString;
|
|
99
|
+
readonly model: Type.TString;
|
|
100
|
+
}>>;
|
|
101
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
102
|
+
}>>;
|
|
103
|
+
readonly reviewer: Type.TOptional<Type.TObject<{
|
|
104
|
+
readonly primary: Type.TObject<{
|
|
105
|
+
readonly provider: Type.TString;
|
|
106
|
+
readonly model: Type.TString;
|
|
107
|
+
}>;
|
|
108
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
109
|
+
readonly provider: Type.TString;
|
|
110
|
+
readonly model: Type.TString;
|
|
111
|
+
}>>;
|
|
112
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
113
|
+
}>>;
|
|
114
|
+
readonly security_reviewer: Type.TOptional<Type.TObject<{
|
|
115
|
+
readonly primary: Type.TObject<{
|
|
116
|
+
readonly provider: Type.TString;
|
|
117
|
+
readonly model: Type.TString;
|
|
118
|
+
}>;
|
|
119
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
120
|
+
readonly provider: Type.TString;
|
|
121
|
+
readonly model: Type.TString;
|
|
122
|
+
}>>;
|
|
123
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
124
|
+
}>>;
|
|
125
|
+
readonly qa: Type.TOptional<Type.TObject<{
|
|
126
|
+
readonly primary: Type.TObject<{
|
|
127
|
+
readonly provider: Type.TString;
|
|
128
|
+
readonly model: Type.TString;
|
|
129
|
+
}>;
|
|
130
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
131
|
+
readonly provider: Type.TString;
|
|
132
|
+
readonly model: Type.TString;
|
|
133
|
+
}>>;
|
|
134
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
135
|
+
}>>;
|
|
136
|
+
readonly triage: Type.TOptional<Type.TObject<{
|
|
137
|
+
readonly primary: Type.TObject<{
|
|
138
|
+
readonly provider: Type.TString;
|
|
139
|
+
readonly model: Type.TString;
|
|
140
|
+
}>;
|
|
141
|
+
readonly backups: Type.TArray<Type.TObject<{
|
|
142
|
+
readonly provider: Type.TString;
|
|
143
|
+
readonly model: Type.TString;
|
|
144
|
+
}>>;
|
|
145
|
+
readonly effort: Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">]>;
|
|
146
|
+
}>>;
|
|
147
|
+
}>>;
|
|
148
|
+
readonly sizing: Type.TOptional<Type.TObject<{
|
|
149
|
+
readonly classifierPolicyId: Type.TString;
|
|
150
|
+
readonly thresholds: Type.TObject<{
|
|
151
|
+
readonly mediumAt: Type.TNumber;
|
|
152
|
+
readonly largeAt: Type.TNumber;
|
|
153
|
+
}>;
|
|
154
|
+
readonly triageRole: Type.TLiteral<"triage">;
|
|
155
|
+
readonly maxEscalations: Type.TUnion<[Type.TLiteral<0>, Type.TLiteral<1>]>;
|
|
156
|
+
}>>;
|
|
157
|
+
readonly limits: Type.TObject<{
|
|
158
|
+
readonly maxAgents: Type.TInteger;
|
|
159
|
+
readonly maxConcurrent: Type.TInteger;
|
|
160
|
+
readonly maxDepth: Type.TInteger;
|
|
161
|
+
readonly maxRetries: Type.TInteger;
|
|
162
|
+
readonly inactivityMs: Type.TInteger;
|
|
163
|
+
readonly ciWaitMs: Type.TInteger;
|
|
164
|
+
}>;
|
|
165
|
+
readonly spend: Type.TObject<{
|
|
166
|
+
readonly runCapMicrousd: Type.TInteger;
|
|
167
|
+
readonly warnAtPct: Type.TInteger;
|
|
168
|
+
readonly perRoleCapMicrousd: Type.TOptional<Type.TObject<{
|
|
169
|
+
readonly scout: Type.TOptional<Type.TInteger>;
|
|
170
|
+
readonly worker: Type.TOptional<Type.TInteger>;
|
|
171
|
+
readonly implementer: Type.TOptional<Type.TInteger>;
|
|
172
|
+
readonly lead: Type.TOptional<Type.TInteger>;
|
|
173
|
+
readonly lead_large: Type.TOptional<Type.TInteger>;
|
|
174
|
+
readonly architect: Type.TOptional<Type.TInteger>;
|
|
175
|
+
readonly reviewer: Type.TOptional<Type.TInteger>;
|
|
176
|
+
readonly security_reviewer: Type.TOptional<Type.TInteger>;
|
|
177
|
+
readonly qa: Type.TOptional<Type.TInteger>;
|
|
178
|
+
readonly triage: Type.TOptional<Type.TInteger>;
|
|
179
|
+
}>>;
|
|
180
|
+
}>;
|
|
181
|
+
readonly providers: Type.TOptional<Type.TObject<{
|
|
182
|
+
readonly preference: Type.TArray<Type.TString>;
|
|
183
|
+
}>>;
|
|
184
|
+
readonly approval: Type.TOptional<Type.TObject<{
|
|
185
|
+
readonly approvedBy: Type.TString;
|
|
186
|
+
readonly approvedAt: Type.TRefine<Type.TString>;
|
|
187
|
+
}>>;
|
|
188
|
+
readonly builtIn: Type.TOptional<Type.TLiteral<true>>;
|
|
189
|
+
}>;
|
|
190
|
+
export type FlowProfileV1 = Static<typeof FlowProfileV1Schema>;
|
|
191
|
+
/** Canonical text hashed (sha256 hex) to produce `digest`: the document without `digest`. */
|
|
192
|
+
export declare function flowProfileDigestInput(doc: FlowProfileV1): string;
|
|
193
|
+
/**
|
|
194
|
+
* SHAPE ONLY: validates structure and cross-field rules but does NOT verify `digest`. Use only for documents whose
|
|
195
|
+
* integrity is established elsewhere (e.g. authored drafts); prefer {@link parseFlowProfileV1}.
|
|
196
|
+
*/
|
|
197
|
+
export declare function parseFlowProfileV1Shape(input: unknown): FlowProfileV1;
|
|
198
|
+
/** Shape validation plus digest verification with the injected hasher (digests are integrity, not authentication). */
|
|
199
|
+
export declare function parseFlowProfileV1(input: unknown, hasher: FlowDigestHasher): FlowProfileV1;
|
|
200
|
+
//# sourceMappingURL=flow-profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-profile.d.ts","sourceRoot":"","sources":["../src/flow-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAIN,KAAK,gBAAgB,EAarB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,eAAO,MAAM,gBAAgB,qFAAkF,CAAC;AAEhH,eAAO,MAAM,qBAAqB;;;;;;;;;;EAIhC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAErE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwC9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAK/D,6FAA6F;AAC7F,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAEjE;AAoBD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAErE;AAED,sHAAsH;AACtH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,GAAG,aAAa,CAM1F"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { canonicalWithout, compileFlow, FlowContractError, FlowDigestSchema, FlowIdSchema, FlowMicrousdSchema, FlowModelRefSchema, FlowPositiveIntSchema, FlowTimestampSchema, hasDuplicateModels, parseFlowData, partialByRole, StrictObject, verifyFlowDigest, } from "./flow-common.js";
|
|
3
|
+
export { FlowProfileRefSchema } from "./flow-common.js";
|
|
4
|
+
export const FlowEffortSchema = Type.Union([Type.Literal("low"), Type.Literal("medium"), Type.Literal("high")]);
|
|
5
|
+
export const FlowRoleBindingSchema = StrictObject({
|
|
6
|
+
primary: FlowModelRefSchema,
|
|
7
|
+
backups: Type.Array(FlowModelRefSchema, { maxItems: 8 }),
|
|
8
|
+
effort: FlowEffortSchema,
|
|
9
|
+
});
|
|
10
|
+
export const FlowProfileV1Schema = StrictObject({
|
|
11
|
+
schema: Type.Literal("humain-flow-profile"),
|
|
12
|
+
schemaVersion: Type.Literal(1),
|
|
13
|
+
id: FlowIdSchema,
|
|
14
|
+
version: FlowPositiveIntSchema,
|
|
15
|
+
digest: FlowDigestSchema,
|
|
16
|
+
kind: Type.Union([Type.Literal("direct"), Type.Literal("flow")]),
|
|
17
|
+
label: Type.String({ minLength: 1, maxLength: 80 }),
|
|
18
|
+
description: Type.Optional(Type.String({ maxLength: 500 })),
|
|
19
|
+
direct: Type.Optional(StrictObject({ model: FlowModelRefSchema, fallbacks: Type.Array(FlowModelRefSchema, { maxItems: 8 }) })),
|
|
20
|
+
roles: Type.Optional(partialByRole(FlowRoleBindingSchema)),
|
|
21
|
+
sizing: Type.Optional(StrictObject({
|
|
22
|
+
classifierPolicyId: FlowIdSchema,
|
|
23
|
+
thresholds: StrictObject({
|
|
24
|
+
mediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),
|
|
25
|
+
largeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),
|
|
26
|
+
}),
|
|
27
|
+
triageRole: Type.Literal("triage"),
|
|
28
|
+
maxEscalations: Type.Union([Type.Literal(0), Type.Literal(1)]),
|
|
29
|
+
})),
|
|
30
|
+
limits: StrictObject({
|
|
31
|
+
maxAgents: Type.Integer({ minimum: 1, maximum: 256 }),
|
|
32
|
+
maxConcurrent: Type.Integer({ minimum: 1, maximum: 64 }),
|
|
33
|
+
maxDepth: Type.Integer({ minimum: 0, maximum: 3 }),
|
|
34
|
+
maxRetries: Type.Integer({ minimum: 0, maximum: 16 }),
|
|
35
|
+
inactivityMs: Type.Integer({ minimum: 1, maximum: 86_400_000 }),
|
|
36
|
+
ciWaitMs: Type.Integer({ minimum: 0, maximum: 86_400_000 }),
|
|
37
|
+
}),
|
|
38
|
+
spend: StrictObject({
|
|
39
|
+
runCapMicrousd: FlowMicrousdSchema,
|
|
40
|
+
warnAtPct: Type.Integer({ minimum: 1, maximum: 99 }),
|
|
41
|
+
perRoleCapMicrousd: Type.Optional(partialByRole(FlowMicrousdSchema)),
|
|
42
|
+
}),
|
|
43
|
+
providers: Type.Optional(StrictObject({ preference: Type.Array(FlowIdSchema, { maxItems: 16 }) })),
|
|
44
|
+
approval: Type.Optional(StrictObject({ approvedBy: FlowIdSchema, approvedAt: FlowTimestampSchema })),
|
|
45
|
+
builtIn: Type.Optional(Type.Literal(true)),
|
|
46
|
+
});
|
|
47
|
+
const Validator = compileFlow(FlowProfileV1Schema);
|
|
48
|
+
const REQUIRED_FLOW_ROLES = ["lead", "worker", "reviewer", "qa"];
|
|
49
|
+
/** Canonical text hashed (sha256 hex) to produce `digest`: the document without `digest`. */
|
|
50
|
+
export function flowProfileDigestInput(doc) {
|
|
51
|
+
return canonicalWithout(doc, "digest");
|
|
52
|
+
}
|
|
53
|
+
function crossFieldsValid(doc) {
|
|
54
|
+
if (doc.kind === "direct") {
|
|
55
|
+
if (doc.direct === undefined || doc.roles !== undefined || doc.sizing !== undefined)
|
|
56
|
+
return false;
|
|
57
|
+
return !hasDuplicateModels([doc.direct.model, ...doc.direct.fallbacks]);
|
|
58
|
+
}
|
|
59
|
+
if (doc.direct !== undefined || doc.roles === undefined)
|
|
60
|
+
return false;
|
|
61
|
+
for (const role of REQUIRED_FLOW_ROLES)
|
|
62
|
+
if (doc.roles[role] === undefined)
|
|
63
|
+
return false;
|
|
64
|
+
for (const binding of Object.values(doc.roles)) {
|
|
65
|
+
const refs = [binding.primary, ...binding.backups];
|
|
66
|
+
if (hasDuplicateModels(refs))
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return doc.sizing === undefined || doc.sizing.thresholds.mediumAt <= doc.sizing.thresholds.largeAt;
|
|
70
|
+
}
|
|
71
|
+
function isProfile(value) {
|
|
72
|
+
return Validator.Check(value) && crossFieldsValid(value);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* SHAPE ONLY: validates structure and cross-field rules but does NOT verify `digest`. Use only for documents whose
|
|
76
|
+
* integrity is established elsewhere (e.g. authored drafts); prefer {@link parseFlowProfileV1}.
|
|
77
|
+
*/
|
|
78
|
+
export function parseFlowProfileV1Shape(input) {
|
|
79
|
+
return parseFlowData("profile_invalid", input, isProfile);
|
|
80
|
+
}
|
|
81
|
+
/** Shape validation plus digest verification with the injected hasher (digests are integrity, not authentication). */
|
|
82
|
+
export function parseFlowProfileV1(input, hasher) {
|
|
83
|
+
const profile = parseFlowProfileV1Shape(input);
|
|
84
|
+
if (!verifyFlowDigest(hasher, flowProfileDigestInput(profile), profile.digest)) {
|
|
85
|
+
throw new FlowContractError("digest_mismatch");
|
|
86
|
+
}
|
|
87
|
+
return profile;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=flow-profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-profile.js","sourceRoot":"","sources":["../src/flow-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACN,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EAEjB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAElB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,YAAY,EACZ,gBAAgB,GAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAyB,MAAM,kBAAkB,CAAC;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAEhH,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;IACjD,OAAO,EAAE,kBAAkB;IAC3B,OAAO,EAAE,IAAI,CAA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M,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,GAAmB,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QACnE,IAAI,kBAAkB,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;IAC5C,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC;AACpG,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAChC,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACrD,OAAO,aAAa,CAAC,iBAAiB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAC3D,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,kBAAkB,CAAC,KAAc,EAAE,MAAwB;IAC1E,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAChF,MAAM,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport {\n\tcanonicalWithout,\n\tcompileFlow,\n\tFlowContractError,\n\ttype FlowDigestHasher,\n\tFlowDigestSchema,\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\ttype FlowModelRef,\n\tFlowModelRefSchema,\n\tFlowPositiveIntSchema,\n\tFlowTimestampSchema,\n\thasDuplicateModels,\n\tparseFlowData,\n\tpartialByRole,\n\tStrictObject,\n\tverifyFlowDigest,\n} from \"./flow-common.ts\";\n\nexport { FlowProfileRefSchema, type FlowProfileRefV1 } from \"./flow-common.ts\";\n\nexport const FlowEffortSchema = Type.Union([Type.Literal(\"low\"), Type.Literal(\"medium\"), Type.Literal(\"high\")]);\n\nexport const FlowRoleBindingSchema = StrictObject({\n\tprimary: FlowModelRefSchema,\n\tbackups: Type.Array(FlowModelRefSchema, { maxItems: 8 }),\n\teffort: FlowEffortSchema,\n});\nexport type FlowRoleBindingV1 = Static<typeof FlowRoleBindingSchema>;\n\nexport const FlowProfileV1Schema = StrictObject({\n\tschema: Type.Literal(\"humain-flow-profile\"),\n\tschemaVersion: Type.Literal(1),\n\tid: FlowIdSchema,\n\tversion: FlowPositiveIntSchema,\n\tdigest: FlowDigestSchema,\n\tkind: Type.Union([Type.Literal(\"direct\"), Type.Literal(\"flow\")]),\n\tlabel: Type.String({ minLength: 1, maxLength: 80 }),\n\tdescription: Type.Optional(Type.String({ maxLength: 500 })),\n\tdirect: Type.Optional(\n\t\tStrictObject({ model: FlowModelRefSchema, fallbacks: Type.Array(FlowModelRefSchema, { maxItems: 8 }) }),\n\t),\n\troles: Type.Optional(partialByRole(FlowRoleBindingSchema)),\n\tsizing: Type.Optional(\n\t\tStrictObject({\n\t\t\tclassifierPolicyId: FlowIdSchema,\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\ttriageRole: Type.Literal(\"triage\"),\n\t\t\tmaxEscalations: Type.Union([Type.Literal(0), Type.Literal(1)]),\n\t\t}),\n\t),\n\tlimits: StrictObject({\n\t\tmaxAgents: Type.Integer({ minimum: 1, maximum: 256 }),\n\t\tmaxConcurrent: Type.Integer({ minimum: 1, maximum: 64 }),\n\t\tmaxDepth: Type.Integer({ minimum: 0, maximum: 3 }),\n\t\tmaxRetries: Type.Integer({ minimum: 0, maximum: 16 }),\n\t\tinactivityMs: Type.Integer({ minimum: 1, maximum: 86_400_000 }),\n\t\tciWaitMs: Type.Integer({ minimum: 0, maximum: 86_400_000 }),\n\t}),\n\tspend: StrictObject({\n\t\trunCapMicrousd: FlowMicrousdSchema,\n\t\twarnAtPct: Type.Integer({ minimum: 1, maximum: 99 }),\n\t\tperRoleCapMicrousd: Type.Optional(partialByRole(FlowMicrousdSchema)),\n\t}),\n\tproviders: Type.Optional(StrictObject({ preference: Type.Array(FlowIdSchema, { maxItems: 16 }) })),\n\tapproval: Type.Optional(StrictObject({ approvedBy: FlowIdSchema, approvedAt: FlowTimestampSchema })),\n\tbuiltIn: Type.Optional(Type.Literal(true)),\n});\nexport type FlowProfileV1 = Static<typeof FlowProfileV1Schema>;\n\nconst Validator = compileFlow(FlowProfileV1Schema);\nconst REQUIRED_FLOW_ROLES = [\"lead\", \"worker\", \"reviewer\", \"qa\"] as const;\n\n/** Canonical text hashed (sha256 hex) to produce `digest`: the document without `digest`. */\nexport function flowProfileDigestInput(doc: FlowProfileV1): string {\n\treturn canonicalWithout(doc, \"digest\");\n}\n\nfunction crossFieldsValid(doc: FlowProfileV1): boolean {\n\tif (doc.kind === \"direct\") {\n\t\tif (doc.direct === undefined || doc.roles !== undefined || doc.sizing !== undefined) return false;\n\t\treturn !hasDuplicateModels([doc.direct.model, ...doc.direct.fallbacks]);\n\t}\n\tif (doc.direct !== undefined || doc.roles === undefined) return false;\n\tfor (const role of REQUIRED_FLOW_ROLES) if (doc.roles[role] === undefined) return false;\n\tfor (const binding of Object.values(doc.roles)) {\n\t\tconst refs: FlowModelRef[] = [binding.primary, ...binding.backups];\n\t\tif (hasDuplicateModels(refs)) return false;\n\t}\n\treturn doc.sizing === undefined || doc.sizing.thresholds.mediumAt <= doc.sizing.thresholds.largeAt;\n}\n\nfunction isProfile(value: unknown): value is FlowProfileV1 {\n\treturn Validator.Check(value) && crossFieldsValid(value);\n}\n\n/**\n * SHAPE ONLY: validates structure and cross-field rules but does NOT verify `digest`. Use only for documents whose\n * integrity is established elsewhere (e.g. authored drafts); prefer {@link parseFlowProfileV1}.\n */\nexport function parseFlowProfileV1Shape(input: unknown): FlowProfileV1 {\n\treturn parseFlowData(\"profile_invalid\", input, isProfile);\n}\n\n/** Shape validation plus digest verification with the injected hasher (digests are integrity, not authentication). */\nexport function parseFlowProfileV1(input: unknown, hasher: FlowDigestHasher): FlowProfileV1 {\n\tconst profile = parseFlowProfileV1Shape(input);\n\tif (!verifyFlowDigest(hasher, flowProfileDigestInput(profile), profile.digest)) {\n\t\tthrow new FlowContractError(\"digest_mismatch\");\n\t}\n\treturn profile;\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type IntentLane = "debug" | "mechanical" | "creative" | "fallback";
|
|
2
|
+
export type IntentDecisionSource = "keyword-classifier" | "mode-override" | "default";
|
|
3
|
+
export type FlowSize = "small" | "medium" | "large";
|
|
4
|
+
export type RiskReason = "explicit-thorough-request" | "high-risk-domain-term" | "long-multi-imperative";
|
|
5
|
+
export type PromptExecutionDepth = "quick" | "balanced" | "thorough";
|
|
6
|
+
export declare const UNIFIED_CLASSIFIER_POLICY_ID: "unified-regex-v4";
|
|
7
|
+
export interface UnifiedPromptClassification {
|
|
8
|
+
lane: IntentLane;
|
|
9
|
+
laneDecisionSource: IntentDecisionSource;
|
|
10
|
+
laneMatchedSignals: string[];
|
|
11
|
+
depth: PromptExecutionDepth;
|
|
12
|
+
riskReasons: RiskReason[];
|
|
13
|
+
policyId: typeof UNIFIED_CLASSIFIER_POLICY_ID;
|
|
14
|
+
}
|
|
15
|
+
export declare function classifyPromptLanguageBucket(prompt: string): "latin" | "non-latin";
|
|
16
|
+
export declare function classifyPromptSignals(input: {
|
|
17
|
+
prompt: string;
|
|
18
|
+
mode?: string | null;
|
|
19
|
+
}): UnifiedPromptClassification;
|
|
20
|
+
export interface FlowSizeThresholds {
|
|
21
|
+
mediumAt: number;
|
|
22
|
+
largeAt: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Maps a classifier depth to a Flow size: quick -> small, balanced -> medium, thorough -> large.
|
|
26
|
+
* When `thresholds` and a finite numeric `score` are both given, the score decides instead:
|
|
27
|
+
* score >= largeAt -> large, score >= mediumAt -> medium, else small.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sizeFromDepth(depth: PromptExecutionDepth, thresholds?: FlowSizeThresholds, score?: number): FlowSize;
|
|
30
|
+
//# sourceMappingURL=flow-sizing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-sizing.d.ts","sourceRoot":"","sources":["../src/flow-sizing.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,YAAY,GAAG,UAAU,GAAG,UAAU,CAAC;AAC1E,MAAM,MAAM,oBAAoB,GAAG,oBAAoB,GAAG,eAAe,GAAG,SAAS,CAAC;AACtF,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAmBpD,MAAM,MAAM,UAAU,GACnB,2BAA2B,GAC3B,uBAAuB,GACvB,uBAAuB,CAAC;AAE3B,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;AAErE,eAAO,MAAM,4BAA4B,EAAG,kBAA2B,CAAC;AAExE,MAAM,WAAW,2BAA2B;IAC3C,IAAI,EAAE,UAAU,CAAC;IACjB,kBAAkB,EAAE,oBAAoB,CAAC;IACzC,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,KAAK,EAAE,oBAAoB,CAAC;IAC5B,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,QAAQ,EAAE,OAAO,4BAA4B,CAAC;CAC9C;AAknBD,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,CAElF;AAED,wBAAgB,qBAAqB,CA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