@crewhaus/runtime-core 0.5.8 → 0.7.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/dist/alert-watchdog.d.ts +53 -0
- package/dist/alert-watchdog.js +88 -7
- package/dist/ephemeral.d.ts +6 -0
- package/dist/ephemeral.js +88 -0
- package/dist/index.d.ts +795 -21
- package/dist/index.js +2575 -210
- package/dist/model-latency.d.ts +43 -0
- package/dist/model-latency.js +61 -0
- package/dist/observability.d.ts +47 -2
- package/dist/observability.js +110 -8
- package/dist/pre-route.d.ts +149 -0
- package/dist/pre-route.js +271 -0
- package/dist/slo-monitor.d.ts +20 -0
- package/dist/slo-monitor.js +45 -1
- package/package.json +42 -40
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { cheapestEligible, eligibleCandidates, evaluateRules, resolveDirectiveTarget, strongestArm, } from "@crewhaus/model-plan";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Synthetic-message marker
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
const SYNTHETIC_MESSAGES = new WeakSet();
|
|
6
|
+
/** Mark a runtime-injected `role: "user"` message as NOT human input. Returns it. */
|
|
7
|
+
export function markSynthetic(message) {
|
|
8
|
+
SYNTHETIC_MESSAGES.add(message);
|
|
9
|
+
return message;
|
|
10
|
+
}
|
|
11
|
+
/** Was this message injected by the runtime (or replayed from a `synthetic: true` log line)? */
|
|
12
|
+
export function isSyntheticMessage(message) {
|
|
13
|
+
return SYNTHETIC_MESSAGES.has(message);
|
|
14
|
+
}
|
|
15
|
+
/** The text blocks of a message joined by newlines (`""` for a tool-result-only message). */
|
|
16
|
+
export function messageText(message) {
|
|
17
|
+
if (typeof message.content === "string")
|
|
18
|
+
return message.content;
|
|
19
|
+
return message.content
|
|
20
|
+
.filter((b) => b.type === "text")
|
|
21
|
+
.map((b) => b.text)
|
|
22
|
+
.join("\n");
|
|
23
|
+
}
|
|
24
|
+
/** Does the message carry an image block (directly, not inside a tool_result)? */
|
|
25
|
+
export function messageHasImages(message) {
|
|
26
|
+
if (typeof message.content === "string")
|
|
27
|
+
return false;
|
|
28
|
+
return message.content.some((b) => b.type === "image");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The latest HUMAN user message: the last `role: "user"` entry that is not
|
|
32
|
+
* synthetic and carries human words or an image (a bare tool-result tail is
|
|
33
|
+
* skipped). `undefined` when none exists.
|
|
34
|
+
*/
|
|
35
|
+
export function latestHumanUserMessage(messages) {
|
|
36
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
37
|
+
const m = messages[i];
|
|
38
|
+
if (m === undefined || m.role !== "user" || isSyntheticMessage(m))
|
|
39
|
+
continue;
|
|
40
|
+
if (messageText(m).length > 0 || messageHasImages(m))
|
|
41
|
+
return m;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The request-local copy of a user message with its `/model …` token
|
|
47
|
+
* removed: a string message becomes `rest`; a block message keeps every
|
|
48
|
+
* non-text block and replaces its text with `rest` (dropping the text block
|
|
49
|
+
* when `rest` is empty and other blocks remain). The PERSISTED transcript
|
|
50
|
+
* keeps the token — only the request copy is stripped (§7.2.1).
|
|
51
|
+
*/
|
|
52
|
+
export function stripDirectiveFromMessage(message, rest) {
|
|
53
|
+
if (typeof message.content === "string")
|
|
54
|
+
return { ...message, content: rest };
|
|
55
|
+
const others = message.content.filter((b) => b.type !== "text");
|
|
56
|
+
const firstText = message.content.find((b) => b.type === "text");
|
|
57
|
+
if (rest.length === 0) {
|
|
58
|
+
return others.length > 0 ? { ...message, content: others } : { ...message, content: rest };
|
|
59
|
+
}
|
|
60
|
+
const text = {
|
|
61
|
+
...(firstText ?? { type: "text", text: "" }),
|
|
62
|
+
text: rest,
|
|
63
|
+
};
|
|
64
|
+
return { ...message, content: [text, ...others] };
|
|
65
|
+
}
|
|
66
|
+
export async function preRoute(ctx) {
|
|
67
|
+
const base = eligibleCandidates(ctx.roster, ctx.turn);
|
|
68
|
+
let eligible = base.eligible;
|
|
69
|
+
const excluded = [...base.excluded];
|
|
70
|
+
const notes = [];
|
|
71
|
+
const skippedRules = [];
|
|
72
|
+
const onRoster = (armId) => ctx.roster.some((a) => a.armId === armId);
|
|
73
|
+
const isEligible = (armId) => eligible.includes(armId);
|
|
74
|
+
const exclusionOf = (armId) => excluded.find((e) => e.armId === armId)?.reason ?? "not eligible";
|
|
75
|
+
const directiveRoster = ctx.roster.map((a) => ({
|
|
76
|
+
armId: a.armId,
|
|
77
|
+
model: a.modelString,
|
|
78
|
+
tags: a.tags,
|
|
79
|
+
}));
|
|
80
|
+
const done = (hint, extra = {}) => ({
|
|
81
|
+
hint,
|
|
82
|
+
eligible,
|
|
83
|
+
excluded,
|
|
84
|
+
skippedRules,
|
|
85
|
+
notes,
|
|
86
|
+
...extra,
|
|
87
|
+
});
|
|
88
|
+
const excludedArms = () => excluded.length > 0 ? { excludedArms: excluded.map((e) => e.armId) } : {};
|
|
89
|
+
// 1. forced — first, so nothing below can disarm a safety lane. The forced
|
|
90
|
+
// arm still passes the N1 requirement check: a rung that cannot take
|
|
91
|
+
// the turn's images (or its transcript, or its tools) would 400, so an
|
|
92
|
+
// ineligible one gives way to an eligible roster arm — the cheapest for
|
|
93
|
+
// the budget lane (the breach still wants the least spend), the
|
|
94
|
+
// strongest for the escalation lane. With nothing eligible the forced
|
|
95
|
+
// arm stands and the loop records `no-eligible-candidate`.
|
|
96
|
+
if (ctx.forced !== undefined) {
|
|
97
|
+
const forced = ctx.forced;
|
|
98
|
+
const forcedArmId = forced.armId ?? forced.candidate?.armId;
|
|
99
|
+
const evidence = { lane: forced.lane, reason: forced.reason };
|
|
100
|
+
const forcedReason = forced.armId !== undefined
|
|
101
|
+
? onRoster(forced.armId) && !isEligible(forced.armId)
|
|
102
|
+
? exclusionOf(forced.armId)
|
|
103
|
+
: undefined
|
|
104
|
+
: forced.candidate !== undefined
|
|
105
|
+
? eligibleCandidates([forced.candidate], ctx.turn).excluded[0]?.reason
|
|
106
|
+
: undefined;
|
|
107
|
+
if (forcedReason === undefined || forcedArmId === undefined) {
|
|
108
|
+
return done({
|
|
109
|
+
source: "forced",
|
|
110
|
+
...(forced.armId !== undefined ? { forcedArm: forced.armId } : {}),
|
|
111
|
+
...excludedArms(),
|
|
112
|
+
eligible,
|
|
113
|
+
evidence,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const served = forced.lane === "budget"
|
|
117
|
+
? cheapestEligible({ eligible, excluded: [] }, ctx.roster)
|
|
118
|
+
: strongestArm(ctx.roster.filter((a) => eligible.includes(a.armId)), ctx.strongTag)?.armId;
|
|
119
|
+
notes.push(`forced ${forced.lane} arm "${forcedArmId}" ineligible this turn (${forcedReason})${served !== undefined ? `; served ${served} instead` : ""}`);
|
|
120
|
+
return done({
|
|
121
|
+
source: "forced",
|
|
122
|
+
...(served !== undefined
|
|
123
|
+
? { forcedArm: served }
|
|
124
|
+
: forced.armId !== undefined
|
|
125
|
+
? { forcedArm: forced.armId }
|
|
126
|
+
: {}),
|
|
127
|
+
...excludedArms(),
|
|
128
|
+
eligible,
|
|
129
|
+
evidence: {
|
|
130
|
+
...evidence,
|
|
131
|
+
ineligible: forcedArmId,
|
|
132
|
+
...(served !== undefined ? { served } : {}),
|
|
133
|
+
},
|
|
134
|
+
}, {
|
|
135
|
+
forcedIneligible: {
|
|
136
|
+
armId: forcedArmId,
|
|
137
|
+
reason: forcedReason,
|
|
138
|
+
...(served !== undefined ? { served } : {}),
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
// 2. directive — the session pin, when it is on the roster and eligible.
|
|
143
|
+
if (ctx.pin !== undefined) {
|
|
144
|
+
if (!onRoster(ctx.pin)) {
|
|
145
|
+
notes.push(`pin "${ctx.pin}" is not on the roster; routing automatically`);
|
|
146
|
+
}
|
|
147
|
+
else if (!isEligible(ctx.pin)) {
|
|
148
|
+
notes.push(`pin "${ctx.pin}" ineligible this turn (${exclusionOf(ctx.pin)}); routing automatically`);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
return done({
|
|
152
|
+
source: "directive",
|
|
153
|
+
forcedArm: ctx.pin,
|
|
154
|
+
...excludedArms(),
|
|
155
|
+
eligible,
|
|
156
|
+
evidence: { pin: ctx.pin },
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// 3. rules — first match wins; the id is persisted either way it resolves.
|
|
161
|
+
if (ctx.rules !== undefined && ctx.rules.length > 0) {
|
|
162
|
+
const result = evaluateRules(ctx.rules, ctx.signals);
|
|
163
|
+
skippedRules.push(...result.skipped);
|
|
164
|
+
const match = result.match;
|
|
165
|
+
if (match !== undefined) {
|
|
166
|
+
if (typeof match.use === "string") {
|
|
167
|
+
const target = resolveDirectiveTarget(match.use, directiveRoster);
|
|
168
|
+
if (target === undefined) {
|
|
169
|
+
notes.push(`rule "${match.ruleId}" names "${match.use}", which is not on the roster`);
|
|
170
|
+
}
|
|
171
|
+
else if (!isEligible(target)) {
|
|
172
|
+
notes.push(`rule "${match.ruleId}" target "${target}" ineligible this turn (${exclusionOf(target)})`);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return done({
|
|
176
|
+
source: "rule",
|
|
177
|
+
forcedArm: target,
|
|
178
|
+
...excludedArms(),
|
|
179
|
+
eligible,
|
|
180
|
+
evidence: { ruleId: match.ruleId, use: match.use },
|
|
181
|
+
}, { ruleId: match.ruleId });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
// `use: { requires }` — narrow eligibility to the arms that satisfy
|
|
186
|
+
// the demanded capability and pick the cheapest survivor (N1 tie-break).
|
|
187
|
+
const narrowed = eligibleCandidates(ctx.roster, {
|
|
188
|
+
...ctx.turn,
|
|
189
|
+
requires: { ...(ctx.turn.requires ?? {}), ...match.use.requires },
|
|
190
|
+
});
|
|
191
|
+
const survivors = narrowed.eligible.filter((id) => eligible.includes(id));
|
|
192
|
+
if (survivors.length === 0) {
|
|
193
|
+
notes.push(`rule "${match.ruleId}" requires ${Object.keys(match.use.requires).join(",")}, which no eligible candidate satisfies`);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
for (const e of narrowed.excluded) {
|
|
197
|
+
if (!excluded.some((x) => x.armId === e.armId))
|
|
198
|
+
excluded.push(e);
|
|
199
|
+
}
|
|
200
|
+
eligible = survivors;
|
|
201
|
+
const pick = cheapestEligible({ eligible: survivors, excluded: [] }, ctx.roster);
|
|
202
|
+
return done({
|
|
203
|
+
source: "rule",
|
|
204
|
+
...(pick !== undefined ? { forcedArm: pick } : {}),
|
|
205
|
+
...excludedArms(),
|
|
206
|
+
eligible,
|
|
207
|
+
evidence: {
|
|
208
|
+
ruleId: match.ruleId,
|
|
209
|
+
requires: Object.keys(match.use.requires).join(","),
|
|
210
|
+
},
|
|
211
|
+
}, { ruleId: match.ruleId });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// 4. classifier — opt-in, model-driven, always with a deterministic fallback.
|
|
217
|
+
let classifierVerdict;
|
|
218
|
+
if (ctx.policy === "classifier") {
|
|
219
|
+
if (ctx.classifierSkipReason !== undefined) {
|
|
220
|
+
notes.push(`classifier skipped (${ctx.classifierSkipReason}); routing heuristically`);
|
|
221
|
+
}
|
|
222
|
+
else if (ctx.classifier === undefined) {
|
|
223
|
+
notes.push("classifier failed: no classifier wired; routing heuristically");
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
try {
|
|
227
|
+
const verdict = await ctx.classifier();
|
|
228
|
+
const labels = ctx.classifierLabels ?? [];
|
|
229
|
+
if (!labels.includes(verdict.label)) {
|
|
230
|
+
notes.push(`classifier failed: label "${verdict.label}" is not one of ${labels.join(",")}; routing heuristically`);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
classifierVerdict = verdict;
|
|
234
|
+
const target = resolveDirectiveTarget(verdict.label, directiveRoster);
|
|
235
|
+
if (target === undefined) {
|
|
236
|
+
notes.push(`classifier label "${verdict.label}" names no roster arm; routing heuristically`);
|
|
237
|
+
}
|
|
238
|
+
else if (!isEligible(target)) {
|
|
239
|
+
notes.push(`classifier label "${verdict.label}" → "${target}" ineligible this turn (${exclusionOf(target)}); routing heuristically`);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
return done({
|
|
243
|
+
source: "classifier",
|
|
244
|
+
forcedArm: target,
|
|
245
|
+
...excludedArms(),
|
|
246
|
+
eligible,
|
|
247
|
+
evidence: { label: verdict.label },
|
|
248
|
+
}, { classifierVerdict });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
notes.push(`classifier failed: ${err instanceof Error ? err.message : String(err)}; routing heuristically`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// 5. the policy decides over eligible[].
|
|
258
|
+
return done({
|
|
259
|
+
source: eligible.length < ctx.roster.length ? "eligibility" : "none",
|
|
260
|
+
...excludedArms(),
|
|
261
|
+
eligible,
|
|
262
|
+
evidence: {},
|
|
263
|
+
}, classifierVerdict !== undefined ? { classifierVerdict } : {});
|
|
264
|
+
}
|
|
265
|
+
/** Render a hint's evidence as `k=v` pairs for the persisted `hint.evidence` string. */
|
|
266
|
+
export function describeHintEvidence(evidence) {
|
|
267
|
+
return Object.entries(evidence)
|
|
268
|
+
.filter(([, v]) => v !== undefined)
|
|
269
|
+
.map(([k, v]) => `${k}=${typeof v === "string" ? v : JSON.stringify(v)}`)
|
|
270
|
+
.join(", ");
|
|
271
|
+
}
|
package/dist/slo-monitor.d.ts
CHANGED
|
@@ -39,6 +39,12 @@ export type SloTargets = {
|
|
|
39
39
|
readonly ttftMs?: number;
|
|
40
40
|
readonly costPerHourUsd?: number;
|
|
41
41
|
readonly egressBlockRate?: number;
|
|
42
|
+
/** Escalations per turn (see alert-watchdog's `isEscalationEvent`). */
|
|
43
|
+
readonly escalationRate?: number;
|
|
44
|
+
/** Failing in-loop grades + judge-gate verdicts over all of them. */
|
|
45
|
+
readonly judgeFailRate?: number;
|
|
46
|
+
/** `model_route` decisions the quality floor forced onto the floor arm, over all decisions. */
|
|
47
|
+
readonly floorBlockRate?: number;
|
|
42
48
|
/** Rolling window (ms) a breach must persist before the ladder fires. */
|
|
43
49
|
readonly windowMs?: number;
|
|
44
50
|
readonly mitigation: ReadonlyArray<SloMitigationRung>;
|
|
@@ -102,6 +108,11 @@ export declare class SloWindow {
|
|
|
102
108
|
private readonly unrecoveredErrors;
|
|
103
109
|
private readonly externalCalls;
|
|
104
110
|
private readonly egressBlocks;
|
|
111
|
+
private readonly escalations;
|
|
112
|
+
private readonly judgeVerdicts;
|
|
113
|
+
private readonly judgeFails;
|
|
114
|
+
private readonly routeDecisions;
|
|
115
|
+
private readonly floorBlocks;
|
|
105
116
|
private readonly requestStarts;
|
|
106
117
|
private readonly ttftSeen;
|
|
107
118
|
/** Wall-clock time of the FIRST event ever folded — lets `evaluate` report how
|
|
@@ -133,6 +144,15 @@ export type SloWindowMetrics = {
|
|
|
133
144
|
readonly windowElapsedMs: number;
|
|
134
145
|
readonly egressBlockRate: number;
|
|
135
146
|
readonly externalCalls: number;
|
|
147
|
+
/** escalations / turns in the window (0 with no turns). */
|
|
148
|
+
readonly escalationRate: number;
|
|
149
|
+
readonly escalations: number;
|
|
150
|
+
/** failing verdicts / all in-loop + judge-gate verdicts in the window. */
|
|
151
|
+
readonly judgeFailRate: number;
|
|
152
|
+
readonly judgeVerdicts: number;
|
|
153
|
+
/** floor-blocked decisions / all `model_route` decisions in the window. */
|
|
154
|
+
readonly floorBlockRate: number;
|
|
155
|
+
readonly routeDecisions: number;
|
|
136
156
|
};
|
|
137
157
|
/**
|
|
138
158
|
* Minimum samples a rate/percentile metric needs before it can breach — a
|
package/dist/slo-monitor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { percentile } from "./alert-watchdog";
|
|
1
|
+
import { isEscalationEvent, isFloorBlockedRoute, percentile } from "./alert-watchdog";
|
|
2
2
|
/** Default rolling window when the spec omits `window_seconds`: 5 minutes. */
|
|
3
3
|
export const DEFAULT_SLO_WINDOW_MS = 5 * 60 * 1000;
|
|
4
4
|
/**
|
|
@@ -18,6 +18,12 @@ export class SloWindow {
|
|
|
18
18
|
unrecoveredErrors = [];
|
|
19
19
|
externalCalls = [];
|
|
20
20
|
egressBlocks = [];
|
|
21
|
+
// 0.6.0 (design §8.4) — hybrid-routing samples.
|
|
22
|
+
escalations = [];
|
|
23
|
+
judgeVerdicts = [];
|
|
24
|
+
judgeFails = [];
|
|
25
|
+
routeDecisions = [];
|
|
26
|
+
floorBlocks = [];
|
|
21
27
|
requestStarts = new Map();
|
|
22
28
|
ttftSeen = new Set();
|
|
23
29
|
/** Wall-clock time of the FIRST event ever folded — lets `evaluate` report how
|
|
@@ -84,6 +90,24 @@ export class SloWindow {
|
|
|
84
90
|
this.egressBlocks.push({ ts: t, value: 1 });
|
|
85
91
|
}
|
|
86
92
|
return;
|
|
93
|
+
// ---- 0.6.0 (design §8.4) — hybrid-routing signals, the same event
|
|
94
|
+
// vocabulary the alert watchdog folds. ----
|
|
95
|
+
case "model_stage":
|
|
96
|
+
case "model_tier_route":
|
|
97
|
+
if (isEscalationEvent(ev))
|
|
98
|
+
this.escalations.push({ ts: t, value: 1 });
|
|
99
|
+
return;
|
|
100
|
+
case "eval_graded":
|
|
101
|
+
case "judge_verdict":
|
|
102
|
+
this.judgeVerdicts.push({ ts: t, value: 1 });
|
|
103
|
+
if (ev.verdict === "fail")
|
|
104
|
+
this.judgeFails.push({ ts: t, value: 1 });
|
|
105
|
+
return;
|
|
106
|
+
case "model_route":
|
|
107
|
+
this.routeDecisions.push({ ts: t, value: 1 });
|
|
108
|
+
if (isFloorBlockedRoute(ev))
|
|
109
|
+
this.floorBlocks.push({ ts: t, value: 1 });
|
|
110
|
+
return;
|
|
87
111
|
default:
|
|
88
112
|
return;
|
|
89
113
|
}
|
|
@@ -106,7 +130,15 @@ export class SloWindow {
|
|
|
106
130
|
prune(this.unrecoveredErrors);
|
|
107
131
|
prune(this.externalCalls);
|
|
108
132
|
prune(this.egressBlocks);
|
|
133
|
+
prune(this.escalations);
|
|
134
|
+
prune(this.judgeVerdicts);
|
|
135
|
+
prune(this.judgeFails);
|
|
136
|
+
prune(this.routeDecisions);
|
|
137
|
+
prune(this.floorBlocks);
|
|
109
138
|
const modelCalls = this.modelCalls.length;
|
|
139
|
+
const turns = this.turnLatencies.length;
|
|
140
|
+
const judgeVerdicts = this.judgeVerdicts.length;
|
|
141
|
+
const routeDecisions = this.routeDecisions.length;
|
|
110
142
|
const externalCalls = this.externalCalls.length;
|
|
111
143
|
const costUsd = this.costMicros.reduce((s, x) => s + x.value, 0) / 1_000_000;
|
|
112
144
|
// How long the monitor has actually been observing, capped at the rolling
|
|
@@ -134,6 +166,12 @@ export class SloWindow {
|
|
|
134
166
|
windowElapsedMs: observedMs,
|
|
135
167
|
egressBlockRate: externalCalls > 0 ? this.egressBlocks.length / externalCalls : 0,
|
|
136
168
|
externalCalls,
|
|
169
|
+
escalationRate: turns > 0 ? this.escalations.length / turns : 0,
|
|
170
|
+
escalations: this.escalations.length,
|
|
171
|
+
judgeFailRate: judgeVerdicts > 0 ? this.judgeFails.length / judgeVerdicts : 0,
|
|
172
|
+
judgeVerdicts,
|
|
173
|
+
floorBlockRate: routeDecisions > 0 ? this.floorBlocks.length / routeDecisions : 0,
|
|
174
|
+
routeDecisions,
|
|
137
175
|
};
|
|
138
176
|
}
|
|
139
177
|
}
|
|
@@ -191,6 +229,12 @@ export function detectSloBreaches(metrics, targets) {
|
|
|
191
229
|
add("ttft_ms", metrics.ttftP95Ms, targets.ttftMs, metrics.ttftSamples >= MIN_SLO_SAMPLES, ms);
|
|
192
230
|
add("cost_per_hour_usd", metrics.costPerHourUsd, targets.costPerHourUsd, metrics.costSamples >= MIN_COST_SAMPLES && metrics.windowElapsedMs >= MIN_COST_ELAPSED_MS, usd);
|
|
193
231
|
add("egress_block_rate", metrics.egressBlockRate, targets.egressBlockRate, metrics.externalCalls >= MIN_SLO_SAMPLES, rate);
|
|
232
|
+
// 0.6.0 (design §8.4) — hybrid-routing rates, each gated on its own
|
|
233
|
+
// denominator reaching MIN_SLO_SAMPLES (one escalation on one turn is a
|
|
234
|
+
// 100% rate, not an SLO violation).
|
|
235
|
+
add("escalation_rate", metrics.escalationRate, targets.escalationRate, metrics.turnSamples >= MIN_SLO_SAMPLES, rate);
|
|
236
|
+
add("judge_fail_rate", metrics.judgeFailRate, targets.judgeFailRate, metrics.judgeVerdicts >= MIN_SLO_SAMPLES, rate);
|
|
237
|
+
add("floor_block_rate", metrics.floorBlockRate, targets.floorBlockRate, metrics.routeDecisions >= MIN_SLO_SAMPLES, rate);
|
|
194
238
|
return breaches;
|
|
195
239
|
}
|
|
196
240
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/runtime-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Minimal runtime imported by generated harness bundles",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,45 +16,47 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@anthropic-ai/sdk": "^0.96.0",
|
|
19
|
-
"@crewhaus/abort-controller": "0.
|
|
20
|
-
"@crewhaus/adapter-anthropic": "0.
|
|
21
|
-
"@crewhaus/agent-context-isolation": "0.
|
|
22
|
-
"@crewhaus/boundary-classifier": "0.
|
|
23
|
-
"@crewhaus/circuit-breaker": "0.
|
|
24
|
-
"@crewhaus/compaction-autocompact": "0.
|
|
25
|
-
"@crewhaus/compaction-curator": "0.
|
|
26
|
-
"@crewhaus/compaction-snip": "0.
|
|
27
|
-
"@crewhaus/cost-tracker": "0.
|
|
28
|
-
"@crewhaus/egress-classifier": "0.
|
|
29
|
-
"@crewhaus/errors": "0.
|
|
30
|
-
"@crewhaus/event-log": "0.
|
|
31
|
-
"@crewhaus/hooks-engine": "0.
|
|
32
|
-
"@crewhaus/metrics-collector": "0.
|
|
33
|
-
"@crewhaus/model-
|
|
34
|
-
"@crewhaus/
|
|
35
|
-
"@crewhaus/
|
|
36
|
-
"@crewhaus/
|
|
37
|
-
"@crewhaus/prompt-
|
|
38
|
-
"@crewhaus/
|
|
39
|
-
"@crewhaus/
|
|
40
|
-
"@crewhaus/
|
|
41
|
-
"@crewhaus/
|
|
42
|
-
"@crewhaus/
|
|
43
|
-
"@crewhaus/
|
|
44
|
-
"@crewhaus/
|
|
45
|
-
"@crewhaus/
|
|
46
|
-
"@crewhaus/
|
|
47
|
-
"@crewhaus/
|
|
48
|
-
"@crewhaus/
|
|
49
|
-
"@crewhaus/
|
|
50
|
-
"@crewhaus/
|
|
51
|
-
"@crewhaus/
|
|
52
|
-
"@crewhaus/tool-
|
|
53
|
-
"@crewhaus/tool-
|
|
54
|
-
"@crewhaus/tool-
|
|
55
|
-
"@crewhaus/
|
|
56
|
-
"@crewhaus/
|
|
57
|
-
"@crewhaus/
|
|
19
|
+
"@crewhaus/abort-controller": "0.7.0",
|
|
20
|
+
"@crewhaus/adapter-anthropic": "0.7.0",
|
|
21
|
+
"@crewhaus/agent-context-isolation": "0.7.0",
|
|
22
|
+
"@crewhaus/boundary-classifier": "0.7.0",
|
|
23
|
+
"@crewhaus/circuit-breaker": "0.7.0",
|
|
24
|
+
"@crewhaus/compaction-autocompact": "0.7.0",
|
|
25
|
+
"@crewhaus/compaction-curator": "0.7.0",
|
|
26
|
+
"@crewhaus/compaction-snip": "0.7.0",
|
|
27
|
+
"@crewhaus/cost-tracker": "0.7.0",
|
|
28
|
+
"@crewhaus/egress-classifier": "0.7.0",
|
|
29
|
+
"@crewhaus/errors": "0.7.0",
|
|
30
|
+
"@crewhaus/event-log": "0.7.0",
|
|
31
|
+
"@crewhaus/hooks-engine": "0.7.0",
|
|
32
|
+
"@crewhaus/metrics-collector": "0.7.0",
|
|
33
|
+
"@crewhaus/model-plan": "0.7.0",
|
|
34
|
+
"@crewhaus/model-router": "0.7.0",
|
|
35
|
+
"@crewhaus/otel-exporter": "0.7.0",
|
|
36
|
+
"@crewhaus/permission-engine": "0.7.0",
|
|
37
|
+
"@crewhaus/prompt-cache-manager": "0.7.0",
|
|
38
|
+
"@crewhaus/prompt-injection-detector": "0.7.0",
|
|
39
|
+
"@crewhaus/rate-limiter": "0.7.0",
|
|
40
|
+
"@crewhaus/recovery-engine": "0.7.0",
|
|
41
|
+
"@crewhaus/routing-store": "0.7.0",
|
|
42
|
+
"@crewhaus/run-context": "0.7.0",
|
|
43
|
+
"@crewhaus/session-store": "0.7.0",
|
|
44
|
+
"@crewhaus/skills-registry": "0.7.0",
|
|
45
|
+
"@crewhaus/slash-commands": "0.7.0",
|
|
46
|
+
"@crewhaus/state-store": "0.7.0",
|
|
47
|
+
"@crewhaus/streaming-tool-executor": "0.7.0",
|
|
48
|
+
"@crewhaus/sub-agent-permission-inheritance": "0.7.0",
|
|
49
|
+
"@crewhaus/structured-event-printer": "0.7.0",
|
|
50
|
+
"@crewhaus/tenancy": "0.7.0",
|
|
51
|
+
"@crewhaus/token-budget": "0.7.0",
|
|
52
|
+
"@crewhaus/tool-catalog": "0.7.0",
|
|
53
|
+
"@crewhaus/tool-executor": "0.7.0",
|
|
54
|
+
"@crewhaus/tool-loop-detection": "0.7.0",
|
|
55
|
+
"@crewhaus/tool-orchestrator": "0.7.0",
|
|
56
|
+
"@crewhaus/tool-result-store": "0.7.0",
|
|
57
|
+
"@crewhaus/trace-event-bus": "0.7.0",
|
|
58
|
+
"@crewhaus/turn-state-machine": "0.7.0",
|
|
59
|
+
"@crewhaus/worker-runtime": "0.7.0",
|
|
58
60
|
"zod": "^3.23.8",
|
|
59
61
|
"zod-to-json-schema": "^3.23.5"
|
|
60
62
|
},
|