@bizzywork/routing 0.3.0 → 0.4.1
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.
|
@@ -24,7 +24,7 @@ async function readStdin() {
|
|
|
24
24
|
for await (const chunk of process.stdin) text += String(chunk);
|
|
25
25
|
return text;
|
|
26
26
|
}
|
|
27
|
-
var { run } = await import("./main-
|
|
27
|
+
var { run } = await import("./main-ELNMGFLI.js");
|
|
28
28
|
var { plainUi } = await import("./ui-PEKFVWX7.js");
|
|
29
29
|
var { clackUi, showError } = await import("./clack-ui-KG2I32T5.js");
|
|
30
30
|
var interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
@@ -35,7 +35,7 @@ try {
|
|
|
35
35
|
home: homedir(),
|
|
36
36
|
execPath: process.execPath,
|
|
37
37
|
bundleDir: dirname(fileURLToPath(import.meta.url)),
|
|
38
|
-
version: true ? "0.
|
|
38
|
+
version: true ? "0.4.1" : "dev",
|
|
39
39
|
platform: process.platform,
|
|
40
40
|
uid: process.getuid?.(),
|
|
41
41
|
interactive,
|
|
@@ -24,6 +24,8 @@ interface Decision {
|
|
|
24
24
|
rule: string;
|
|
25
25
|
reason: string;
|
|
26
26
|
notice?: string;
|
|
27
|
+
/** Set when a live routing-vs-control comparison sampled this turn. "control" keeps the native model. */
|
|
28
|
+
arm?: "treatment" | "control";
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
const WINDOW = 24;
|
|
@@ -338,12 +340,20 @@ export const register: Register = (on) => {
|
|
|
338
340
|
);
|
|
339
341
|
if (!claudeModel.test(decision.model)) throw new Error("not a Claude model id");
|
|
340
342
|
if (first) notice = decision.notice;
|
|
341
|
-
|
|
343
|
+
// Control keeps the request on Claude Code's own model: the comparison needs a sample of
|
|
344
|
+
// turns Bizzy never touched, not just an opinion it kept to itself.
|
|
345
|
+
const control = decision.arm === "control";
|
|
346
|
+
show(
|
|
347
|
+
$,
|
|
348
|
+
control
|
|
349
|
+
? `Bizzy Auto · control · keeping ${current}`
|
|
350
|
+
: `Bizzy Auto · ${decision.model} · ${notice ? "own rules" : decision.rule}${decision.arm ? " · treatment" : ""}`,
|
|
351
|
+
);
|
|
342
352
|
if (notice && !noticed) {
|
|
343
353
|
noticed = true;
|
|
344
354
|
$.ui.toast(`Bizzy Auto: ${notice}`);
|
|
345
355
|
}
|
|
346
|
-
routed = { ...e, model: decision.model };
|
|
356
|
+
if (!control) routed = { ...e, model: decision.model };
|
|
347
357
|
}
|
|
348
358
|
} catch (error) {
|
|
349
359
|
show(
|
|
@@ -33,6 +33,8 @@ interface Decision {
|
|
|
33
33
|
rule: string;
|
|
34
34
|
reason: string;
|
|
35
35
|
notice?: string;
|
|
36
|
+
/** Set when a live routing-vs-control comparison sampled this turn. "control" keeps the native model. */
|
|
37
|
+
arm?: "treatment" | "control";
|
|
36
38
|
}
|
|
37
39
|
interface ModelsReply {
|
|
38
40
|
picks: { efficient: string; capable: string } | null;
|
|
@@ -245,6 +247,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
245
247
|
const session = safeId(options?.sessionId ?? "omp");
|
|
246
248
|
const turn = turnOf(context.messages as never);
|
|
247
249
|
let target: Model = fallbackModel;
|
|
250
|
+
// Set once Bizzy samples this turn into control: the comparison needs turns Bizzy never
|
|
251
|
+
// touched, including on failure, not just an opinion it kept to itself.
|
|
252
|
+
let control = false;
|
|
248
253
|
if (shared.enabled) {
|
|
249
254
|
try {
|
|
250
255
|
if (shared.sent !== JSON.stringify(candidates(c).map(modelId))) await sendModels(c);
|
|
@@ -269,9 +274,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
269
274
|
return ask();
|
|
270
275
|
});
|
|
271
276
|
shared.compacted = false;
|
|
272
|
-
|
|
277
|
+
control = decision.arm === "control";
|
|
278
|
+
target = control ? fallbackModel : (pick(c, decision.model) ?? fallbackModel);
|
|
273
279
|
if (turn.index === 0) shared.notice = decision.notice;
|
|
274
|
-
show(
|
|
280
|
+
show(
|
|
281
|
+
control
|
|
282
|
+
? `Bizzy Auto · control · keeping ${modelId(target)}`
|
|
283
|
+
: `Bizzy Auto · ${modelId(target)} · ${shared.notice ? "own rules" : decision.rule}${decision.arm ? " · treatment" : ""}`,
|
|
284
|
+
);
|
|
275
285
|
if (shared.notice && !shared.noticed) {
|
|
276
286
|
shared.noticed = true;
|
|
277
287
|
c.ui.notify(`Bizzy Auto: ${shared.notice}`, "info");
|
|
@@ -321,6 +331,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
321
331
|
opened.failed &&
|
|
322
332
|
opened.failed.stopReason !== "aborted" &&
|
|
323
333
|
shared.enabled &&
|
|
334
|
+
!control &&
|
|
324
335
|
!options?.signal?.aborted
|
|
325
336
|
) {
|
|
326
337
|
const text = opened.failed.errorMessage ?? "";
|
|
@@ -7419,7 +7419,7 @@ var require_public_api = __commonJS({
|
|
|
7419
7419
|
}
|
|
7420
7420
|
return doc;
|
|
7421
7421
|
}
|
|
7422
|
-
function
|
|
7422
|
+
function parse6(src, reviver, options) {
|
|
7423
7423
|
let _reviver = void 0;
|
|
7424
7424
|
if (typeof reviver === "function") {
|
|
7425
7425
|
_reviver = reviver;
|
|
@@ -7460,7 +7460,7 @@ var require_public_api = __commonJS({
|
|
|
7460
7460
|
return value.toString(options);
|
|
7461
7461
|
return new Document.Document(value, _replacer, options).toString(options);
|
|
7462
7462
|
}
|
|
7463
|
-
exports.parse =
|
|
7463
|
+
exports.parse = parse6;
|
|
7464
7464
|
exports.parseAllDocuments = parseAllDocuments;
|
|
7465
7465
|
exports.parseDocument = parseDocument;
|
|
7466
7466
|
exports.stringify = stringify;
|
|
@@ -8357,7 +8357,7 @@ var require_fast_uri = __commonJS({
|
|
|
8357
8357
|
normalizeString(uri, options);
|
|
8358
8358
|
} else if (typeof uri === "object") {
|
|
8359
8359
|
uri = /** @type {T} */
|
|
8360
|
-
|
|
8360
|
+
parse6(serialize(uri, options), options);
|
|
8361
8361
|
}
|
|
8362
8362
|
return uri;
|
|
8363
8363
|
}
|
|
@@ -8400,8 +8400,8 @@ var require_fast_uri = __commonJS({
|
|
|
8400
8400
|
function resolveComponent(base, relative, options, skipNormalization) {
|
|
8401
8401
|
const target = {};
|
|
8402
8402
|
if (!skipNormalization) {
|
|
8403
|
-
base =
|
|
8404
|
-
relative =
|
|
8403
|
+
base = parse6(serialize(base, options), options);
|
|
8404
|
+
relative = parse6(serialize(relative, options), options);
|
|
8405
8405
|
}
|
|
8406
8406
|
options = options || {};
|
|
8407
8407
|
if (!options.tolerant && relative.scheme) {
|
|
@@ -8719,7 +8719,7 @@ var require_fast_uri = __commonJS({
|
|
|
8719
8719
|
}
|
|
8720
8720
|
return { parsed: parsed2, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme };
|
|
8721
8721
|
}
|
|
8722
|
-
function
|
|
8722
|
+
function parse6(uri, opts) {
|
|
8723
8723
|
return parseWithStatus(uri, opts).parsed;
|
|
8724
8724
|
}
|
|
8725
8725
|
function normalizeString(uri, opts) {
|
|
@@ -8756,7 +8756,7 @@ var require_fast_uri = __commonJS({
|
|
|
8756
8756
|
resolveComponent,
|
|
8757
8757
|
equal,
|
|
8758
8758
|
serialize,
|
|
8759
|
-
parse:
|
|
8759
|
+
parse: parse6
|
|
8760
8760
|
};
|
|
8761
8761
|
module.exports = fastUri;
|
|
8762
8762
|
module.exports.default = fastUri;
|
|
@@ -8966,7 +8966,7 @@ var require_ms = __commonJS({
|
|
|
8966
8966
|
options = options || {};
|
|
8967
8967
|
var type = typeof val;
|
|
8968
8968
|
if (type === "string" && val.length > 0) {
|
|
8969
|
-
return
|
|
8969
|
+
return parse6(val);
|
|
8970
8970
|
} else if (type === "number" && isFinite(val)) {
|
|
8971
8971
|
return options.long ? fmtLong(val) : fmtShort(val);
|
|
8972
8972
|
}
|
|
@@ -8974,7 +8974,7 @@ var require_ms = __commonJS({
|
|
|
8974
8974
|
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
|
|
8975
8975
|
);
|
|
8976
8976
|
};
|
|
8977
|
-
function
|
|
8977
|
+
function parse6(str) {
|
|
8978
8978
|
str = String(str);
|
|
8979
8979
|
if (str.length > 100) {
|
|
8980
8980
|
return;
|
|
@@ -15057,7 +15057,7 @@ var require_dist2 = __commonJS({
|
|
|
15057
15057
|
var HOUR = MIN * 60;
|
|
15058
15058
|
var DAY = HOUR * 24;
|
|
15059
15059
|
var YEAR = DAY * 365.25;
|
|
15060
|
-
function
|
|
15060
|
+
function parse6(val) {
|
|
15061
15061
|
var num, arr = val.toLowerCase().match(RGX);
|
|
15062
15062
|
if (arr != null && (num = parseFloat(arr[1]))) {
|
|
15063
15063
|
if (arr[3] != null) return num * SEC;
|
|
@@ -15083,7 +15083,7 @@ var require_dist2 = __commonJS({
|
|
|
15083
15083
|
return fmt(abs / YEAR, pfx, "year", long);
|
|
15084
15084
|
}
|
|
15085
15085
|
exports.format = format2;
|
|
15086
|
-
exports.parse =
|
|
15086
|
+
exports.parse = parse6;
|
|
15087
15087
|
}
|
|
15088
15088
|
});
|
|
15089
15089
|
|
|
@@ -16546,14 +16546,14 @@ var require_accept_negotiator = __commonJS({
|
|
|
16546
16546
|
}
|
|
16547
16547
|
return false;
|
|
16548
16548
|
}
|
|
16549
|
-
|
|
16549
|
+
parse6(header, processMatch);
|
|
16550
16550
|
return preferredEncoding;
|
|
16551
16551
|
}
|
|
16552
16552
|
var BEGIN = 0;
|
|
16553
16553
|
var TOKEN = 1;
|
|
16554
16554
|
var QUALITY = 2;
|
|
16555
16555
|
var END = 3;
|
|
16556
|
-
function
|
|
16556
|
+
function parse6(header, processMatch) {
|
|
16557
16557
|
let str = "";
|
|
16558
16558
|
let quality;
|
|
16559
16559
|
let state = BEGIN;
|
|
@@ -30393,10 +30393,10 @@ var require_forwarded = __commonJS({
|
|
|
30393
30393
|
const remote = header.trim();
|
|
30394
30394
|
return remote.length ? [socketAddr, remote] : [socketAddr];
|
|
30395
30395
|
} else {
|
|
30396
|
-
return
|
|
30396
|
+
return parse6(header, socketAddr);
|
|
30397
30397
|
}
|
|
30398
30398
|
}
|
|
30399
|
-
function
|
|
30399
|
+
function parse6(header, socketAddr) {
|
|
30400
30400
|
const result = [socketAddr];
|
|
30401
30401
|
let end = header.length;
|
|
30402
30402
|
let start = end;
|
|
@@ -31914,7 +31914,7 @@ var require_secure_json_parse = __commonJS({
|
|
|
31914
31914
|
}
|
|
31915
31915
|
return obj;
|
|
31916
31916
|
}
|
|
31917
|
-
function
|
|
31917
|
+
function parse6(text, reviver, options) {
|
|
31918
31918
|
const { stackTraceLimit } = Error;
|
|
31919
31919
|
Error.stackTraceLimit = 0;
|
|
31920
31920
|
try {
|
|
@@ -31936,9 +31936,9 @@ var require_secure_json_parse = __commonJS({
|
|
|
31936
31936
|
}
|
|
31937
31937
|
return result;
|
|
31938
31938
|
}
|
|
31939
|
-
module.exports =
|
|
31940
|
-
module.exports.default =
|
|
31941
|
-
module.exports.parse =
|
|
31939
|
+
module.exports = parse6;
|
|
31940
|
+
module.exports.default = parse6;
|
|
31941
|
+
module.exports.parse = parse6;
|
|
31942
31942
|
module.exports.safeParse = safeParse3;
|
|
31943
31943
|
module.exports.scan = filter;
|
|
31944
31944
|
}
|
|
@@ -36133,7 +36133,7 @@ var require_fast_uri2 = __commonJS({
|
|
|
36133
36133
|
normalizeString(uri, options);
|
|
36134
36134
|
} else if (typeof uri === "object") {
|
|
36135
36135
|
uri = /** @type {T} */
|
|
36136
|
-
|
|
36136
|
+
parse6(serialize(uri, options), options);
|
|
36137
36137
|
}
|
|
36138
36138
|
return uri;
|
|
36139
36139
|
}
|
|
@@ -36176,8 +36176,8 @@ var require_fast_uri2 = __commonJS({
|
|
|
36176
36176
|
function resolveComponent(base, relative, options, skipNormalization) {
|
|
36177
36177
|
const target = {};
|
|
36178
36178
|
if (!skipNormalization) {
|
|
36179
|
-
base =
|
|
36180
|
-
relative =
|
|
36179
|
+
base = parse6(serialize(base, options), options);
|
|
36180
|
+
relative = parse6(serialize(relative, options), options);
|
|
36181
36181
|
}
|
|
36182
36182
|
options = options || {};
|
|
36183
36183
|
if (!options.tolerant && relative.scheme) {
|
|
@@ -36495,7 +36495,7 @@ var require_fast_uri2 = __commonJS({
|
|
|
36495
36495
|
}
|
|
36496
36496
|
return { parsed: parsed2, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme };
|
|
36497
36497
|
}
|
|
36498
|
-
function
|
|
36498
|
+
function parse6(uri, opts) {
|
|
36499
36499
|
return parseWithStatus(uri, opts).parsed;
|
|
36500
36500
|
}
|
|
36501
36501
|
function normalizeString(uri, opts) {
|
|
@@ -36532,7 +36532,7 @@ var require_fast_uri2 = __commonJS({
|
|
|
36532
36532
|
resolveComponent,
|
|
36533
36533
|
equal,
|
|
36534
36534
|
serialize,
|
|
36535
|
-
parse:
|
|
36535
|
+
parse: parse6
|
|
36536
36536
|
};
|
|
36537
36537
|
module.exports = fastUri;
|
|
36538
36538
|
module.exports.default = fastUri;
|
|
@@ -40507,9 +40507,9 @@ var require_parse = __commonJS({
|
|
|
40507
40507
|
const parseFuncCode = gen.toString();
|
|
40508
40508
|
sourceCode = `${gen.scopeRefs(names_1.default.scope)}return ${parseFuncCode}`;
|
|
40509
40509
|
const makeParse = new Function(`${names_1.default.scope}`, sourceCode);
|
|
40510
|
-
const
|
|
40511
|
-
this.scope.value(parseName, { ref:
|
|
40512
|
-
sch.parse =
|
|
40510
|
+
const parse6 = makeParse(this.scope.get());
|
|
40511
|
+
this.scope.value(parseName, { ref: parse6 });
|
|
40512
|
+
sch.parse = parse6;
|
|
40513
40513
|
} catch (e) {
|
|
40514
40514
|
if (sourceCode)
|
|
40515
40515
|
this.logger.error("Error compiling parser, function code:", sourceCode);
|
|
@@ -41961,7 +41961,7 @@ var require_fast_uri3 = __commonJS({
|
|
|
41961
41961
|
normalizeString(uri, options);
|
|
41962
41962
|
} else if (typeof uri === "object") {
|
|
41963
41963
|
uri = /** @type {T} */
|
|
41964
|
-
|
|
41964
|
+
parse6(serialize(uri, options), options);
|
|
41965
41965
|
}
|
|
41966
41966
|
return uri;
|
|
41967
41967
|
}
|
|
@@ -42018,8 +42018,8 @@ var require_fast_uri3 = __commonJS({
|
|
|
42018
42018
|
function resolveComponent(base, relative, options, skipNormalization) {
|
|
42019
42019
|
const target = {};
|
|
42020
42020
|
if (!skipNormalization) {
|
|
42021
|
-
base =
|
|
42022
|
-
relative =
|
|
42021
|
+
base = parse6(serialize(base, options), options);
|
|
42022
|
+
relative = parse6(serialize(relative, options), options);
|
|
42023
42023
|
}
|
|
42024
42024
|
options = options || {};
|
|
42025
42025
|
if (!options.tolerant && relative.scheme) {
|
|
@@ -42358,7 +42358,7 @@ var require_fast_uri3 = __commonJS({
|
|
|
42358
42358
|
}
|
|
42359
42359
|
return { parsed: parsed2, malformedAuthorityOrPort, malformedReferenceEdge, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme };
|
|
42360
42360
|
}
|
|
42361
|
-
function
|
|
42361
|
+
function parse6(uri, opts) {
|
|
42362
42362
|
return parseWithStatus(uri, opts).parsed;
|
|
42363
42363
|
}
|
|
42364
42364
|
function normalizeString(uri, opts) {
|
|
@@ -42396,7 +42396,7 @@ var require_fast_uri3 = __commonJS({
|
|
|
42396
42396
|
resolveComponent,
|
|
42397
42397
|
equal,
|
|
42398
42398
|
serialize,
|
|
42399
|
-
parse:
|
|
42399
|
+
parse: parse6
|
|
42400
42400
|
};
|
|
42401
42401
|
module.exports = fastUri;
|
|
42402
42402
|
module.exports.default = fastUri;
|
|
@@ -47130,7 +47130,7 @@ var require_parse2 = __commonJS({
|
|
|
47130
47130
|
"node_modules/semver/functions/parse.js"(exports, module) {
|
|
47131
47131
|
"use strict";
|
|
47132
47132
|
var SemVer = require_semver();
|
|
47133
|
-
var
|
|
47133
|
+
var parse6 = (version2, options, throwErrors = false) => {
|
|
47134
47134
|
if (version2 instanceof SemVer) {
|
|
47135
47135
|
return version2;
|
|
47136
47136
|
}
|
|
@@ -47143,7 +47143,7 @@ var require_parse2 = __commonJS({
|
|
|
47143
47143
|
throw er;
|
|
47144
47144
|
}
|
|
47145
47145
|
};
|
|
47146
|
-
module.exports =
|
|
47146
|
+
module.exports = parse6;
|
|
47147
47147
|
}
|
|
47148
47148
|
});
|
|
47149
47149
|
|
|
@@ -47151,9 +47151,9 @@ var require_parse2 = __commonJS({
|
|
|
47151
47151
|
var require_valid = __commonJS({
|
|
47152
47152
|
"node_modules/semver/functions/valid.js"(exports, module) {
|
|
47153
47153
|
"use strict";
|
|
47154
|
-
var
|
|
47154
|
+
var parse6 = require_parse2();
|
|
47155
47155
|
var valid = (version2, options) => {
|
|
47156
|
-
const v =
|
|
47156
|
+
const v = parse6(version2, options);
|
|
47157
47157
|
return v ? v.version : null;
|
|
47158
47158
|
};
|
|
47159
47159
|
module.exports = valid;
|
|
@@ -47164,9 +47164,9 @@ var require_valid = __commonJS({
|
|
|
47164
47164
|
var require_clean = __commonJS({
|
|
47165
47165
|
"node_modules/semver/functions/clean.js"(exports, module) {
|
|
47166
47166
|
"use strict";
|
|
47167
|
-
var
|
|
47167
|
+
var parse6 = require_parse2();
|
|
47168
47168
|
var clean = (version2, options) => {
|
|
47169
|
-
const s =
|
|
47169
|
+
const s = parse6(version2.trim().replace(/^[=v]+/, ""), options);
|
|
47170
47170
|
return s ? s.version : null;
|
|
47171
47171
|
};
|
|
47172
47172
|
module.exports = clean;
|
|
@@ -47201,10 +47201,10 @@ var require_inc = __commonJS({
|
|
|
47201
47201
|
var require_diff = __commonJS({
|
|
47202
47202
|
"node_modules/semver/functions/diff.js"(exports, module) {
|
|
47203
47203
|
"use strict";
|
|
47204
|
-
var
|
|
47204
|
+
var parse6 = require_parse2();
|
|
47205
47205
|
var diff = (version1, version2) => {
|
|
47206
|
-
const v1 =
|
|
47207
|
-
const v2 =
|
|
47206
|
+
const v1 = parse6(version1, null, true);
|
|
47207
|
+
const v2 = parse6(version2, null, true);
|
|
47208
47208
|
const comparison = v1.compare(v2);
|
|
47209
47209
|
if (comparison === 0) {
|
|
47210
47210
|
return null;
|
|
@@ -47275,9 +47275,9 @@ var require_patch = __commonJS({
|
|
|
47275
47275
|
var require_prerelease = __commonJS({
|
|
47276
47276
|
"node_modules/semver/functions/prerelease.js"(exports, module) {
|
|
47277
47277
|
"use strict";
|
|
47278
|
-
var
|
|
47278
|
+
var parse6 = require_parse2();
|
|
47279
47279
|
var prerelease = (version2, options) => {
|
|
47280
|
-
const parsed2 =
|
|
47280
|
+
const parsed2 = parse6(version2, options);
|
|
47281
47281
|
return parsed2 && parsed2.prerelease.length ? parsed2.prerelease : null;
|
|
47282
47282
|
};
|
|
47283
47283
|
module.exports = prerelease;
|
|
@@ -47463,7 +47463,7 @@ var require_coerce = __commonJS({
|
|
|
47463
47463
|
"node_modules/semver/functions/coerce.js"(exports, module) {
|
|
47464
47464
|
"use strict";
|
|
47465
47465
|
var SemVer = require_semver();
|
|
47466
|
-
var
|
|
47466
|
+
var parse6 = require_parse2();
|
|
47467
47467
|
var { safeRe: re, t } = require_re();
|
|
47468
47468
|
var coerce = (version2, options) => {
|
|
47469
47469
|
if (version2 instanceof SemVer) {
|
|
@@ -47498,7 +47498,7 @@ var require_coerce = __commonJS({
|
|
|
47498
47498
|
const patch = match[4] || "0";
|
|
47499
47499
|
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : "";
|
|
47500
47500
|
const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
|
|
47501
|
-
return
|
|
47501
|
+
return parse6(`${major}.${minor}.${patch}${prerelease}${build}`, options);
|
|
47502
47502
|
};
|
|
47503
47503
|
module.exports = coerce;
|
|
47504
47504
|
}
|
|
@@ -47508,7 +47508,7 @@ var require_coerce = __commonJS({
|
|
|
47508
47508
|
var require_truncate = __commonJS({
|
|
47509
47509
|
"node_modules/semver/functions/truncate.js"(exports, module) {
|
|
47510
47510
|
"use strict";
|
|
47511
|
-
var
|
|
47511
|
+
var parse6 = require_parse2();
|
|
47512
47512
|
var constants5 = require_constants4();
|
|
47513
47513
|
var SemVer = require_semver();
|
|
47514
47514
|
var truncate = (version2, truncation, options) => {
|
|
@@ -47520,7 +47520,7 @@ var require_truncate = __commonJS({
|
|
|
47520
47520
|
};
|
|
47521
47521
|
var cloneInputVersion = (version2, options) => {
|
|
47522
47522
|
const versionStringToParse = version2 instanceof SemVer ? version2.version : version2;
|
|
47523
|
-
return
|
|
47523
|
+
return parse6(versionStringToParse, options);
|
|
47524
47524
|
};
|
|
47525
47525
|
var doTruncation = (version2, truncation) => {
|
|
47526
47526
|
if (isPrerelease(truncation)) {
|
|
@@ -48564,7 +48564,7 @@ var require_semver2 = __commonJS({
|
|
|
48564
48564
|
var constants5 = require_constants4();
|
|
48565
48565
|
var SemVer = require_semver();
|
|
48566
48566
|
var identifiers = require_identifiers();
|
|
48567
|
-
var
|
|
48567
|
+
var parse6 = require_parse2();
|
|
48568
48568
|
var valid = require_valid();
|
|
48569
48569
|
var clean = require_clean();
|
|
48570
48570
|
var inc = require_inc();
|
|
@@ -48603,7 +48603,7 @@ var require_semver2 = __commonJS({
|
|
|
48603
48603
|
var simplifyRange = require_simplify();
|
|
48604
48604
|
var subset = require_subset();
|
|
48605
48605
|
module.exports = {
|
|
48606
|
-
parse:
|
|
48606
|
+
parse: parse6,
|
|
48607
48607
|
valid,
|
|
48608
48608
|
clean,
|
|
48609
48609
|
inc,
|
|
@@ -48831,7 +48831,7 @@ var require_parse3 = __commonJS({
|
|
|
48831
48831
|
var Empty = function() {
|
|
48832
48832
|
};
|
|
48833
48833
|
Empty.prototype = /* @__PURE__ */ Object.create(null);
|
|
48834
|
-
function
|
|
48834
|
+
function parse6(input2) {
|
|
48835
48835
|
const result = new Empty();
|
|
48836
48836
|
if (typeof input2 !== "string") {
|
|
48837
48837
|
return result;
|
|
@@ -48911,7 +48911,7 @@ var require_parse3 = __commonJS({
|
|
|
48911
48911
|
}
|
|
48912
48912
|
return result;
|
|
48913
48913
|
}
|
|
48914
|
-
module.exports =
|
|
48914
|
+
module.exports = parse6;
|
|
48915
48915
|
}
|
|
48916
48916
|
});
|
|
48917
48917
|
|
|
@@ -49163,15 +49163,15 @@ var require_stringify2 = __commonJS({
|
|
|
49163
49163
|
var require_lib = __commonJS({
|
|
49164
49164
|
"node_modules/fast-querystring/lib/index.js"(exports, module) {
|
|
49165
49165
|
"use strict";
|
|
49166
|
-
var
|
|
49166
|
+
var parse6 = require_parse3();
|
|
49167
49167
|
var stringify = require_stringify2();
|
|
49168
49168
|
var fastQuerystring = {
|
|
49169
|
-
parse:
|
|
49169
|
+
parse: parse6,
|
|
49170
49170
|
stringify
|
|
49171
49171
|
};
|
|
49172
49172
|
module.exports = fastQuerystring;
|
|
49173
49173
|
module.exports.default = fastQuerystring;
|
|
49174
|
-
module.exports.parse =
|
|
49174
|
+
module.exports.parse = parse6;
|
|
49175
49175
|
module.exports.stringify = stringify;
|
|
49176
49176
|
}
|
|
49177
49177
|
});
|
|
@@ -49971,7 +49971,7 @@ var require_dist5 = __commonJS({
|
|
|
49971
49971
|
var require_safe_regex2 = __commonJS({
|
|
49972
49972
|
"node_modules/safe-regex2/index.js"(exports, module) {
|
|
49973
49973
|
"use strict";
|
|
49974
|
-
var
|
|
49974
|
+
var parse6 = require_dist5();
|
|
49975
49975
|
var { types } = require_dist5();
|
|
49976
49976
|
function walk(node2, opts, starHeight) {
|
|
49977
49977
|
let i;
|
|
@@ -50006,7 +50006,7 @@ var require_safe_regex2 = __commonJS({
|
|
|
50006
50006
|
if (isRegExp(re)) re = re.source;
|
|
50007
50007
|
else if (typeof re !== "string") re = String(re);
|
|
50008
50008
|
try {
|
|
50009
|
-
return walk(
|
|
50009
|
+
return walk(parse6(re), opts, 0);
|
|
50010
50010
|
} catch {
|
|
50011
50011
|
return false;
|
|
50012
50012
|
}
|
|
@@ -58570,18 +58570,18 @@ var validateAsync = async (schema, value, _ctx) => {
|
|
|
58570
58570
|
return result.issues.length === 0;
|
|
58571
58571
|
};
|
|
58572
58572
|
var _encode = (_Err) => {
|
|
58573
|
-
const
|
|
58573
|
+
const parse6 = _parse(_Err);
|
|
58574
58574
|
const fn = (schema, value, _ctx, _params) => {
|
|
58575
58575
|
const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
|
|
58576
|
-
return
|
|
58576
|
+
return parse6(schema, value, ctx, finalizeParams(fn, _params));
|
|
58577
58577
|
};
|
|
58578
58578
|
return fn;
|
|
58579
58579
|
};
|
|
58580
58580
|
var encode = /* @__PURE__ */ _encode($ZodRealError);
|
|
58581
58581
|
var _decode = (_Err) => {
|
|
58582
|
-
const
|
|
58582
|
+
const parse6 = _parse(_Err);
|
|
58583
58583
|
const fn = (schema, value, _ctx, _params) => {
|
|
58584
|
-
return
|
|
58584
|
+
return parse6(schema, value, _ctx, finalizeParams(fn, _params));
|
|
58585
58585
|
};
|
|
58586
58586
|
return fn;
|
|
58587
58587
|
};
|
|
@@ -60076,7 +60076,7 @@ function capSize(inst, size) {
|
|
|
60076
60076
|
if (!caps.length)
|
|
60077
60077
|
return;
|
|
60078
60078
|
const cap = Math.min(...caps.map((c) => c[0]));
|
|
60079
|
-
const
|
|
60079
|
+
const parse6 = inst._zod.parse;
|
|
60080
60080
|
inst._zod.parse = (payload, ctx) => {
|
|
60081
60081
|
const n = size(payload.value);
|
|
60082
60082
|
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
|
|
@@ -60090,7 +60090,7 @@ function capSize(inst, size) {
|
|
|
60090
60090
|
}
|
|
60091
60091
|
}
|
|
60092
60092
|
}
|
|
60093
|
-
return
|
|
60093
|
+
return parse6(payload, ctx);
|
|
60094
60094
|
};
|
|
60095
60095
|
}
|
|
60096
60096
|
var arraySize = (input2) => Array.isArray(input2) ? input2.length : -1;
|
|
@@ -76470,7 +76470,8 @@ var DecisionSourceSchema = external_exports.enum([
|
|
|
76470
76470
|
"stage",
|
|
76471
76471
|
"plan-execute",
|
|
76472
76472
|
"escalation",
|
|
76473
|
-
"judge-select"
|
|
76473
|
+
"judge-select",
|
|
76474
|
+
"judge-grade"
|
|
76474
76475
|
]);
|
|
76475
76476
|
var TaskEnvelopeSchema = external_exports.object({
|
|
76476
76477
|
version: external_exports.literal("2"),
|
|
@@ -76521,6 +76522,13 @@ var RunRecordSchema = external_exports.object({
|
|
|
76521
76522
|
judgeAdvantage: UnitSchema.exactOptional(),
|
|
76522
76523
|
/** Set when a calibration trial served the rule against the judge's verdict. */
|
|
76523
76524
|
judgeTrial: external_exports.boolean().exactOptional(),
|
|
76525
|
+
/** The judge's own token usage for this run's route call, regardless of which strategy asked it.
|
|
76526
|
+
* `costUsd` is null when no judge price was configured, not a guessed number. */
|
|
76527
|
+
judgeUsage: external_exports.object({
|
|
76528
|
+
inputTokens: CountSchema,
|
|
76529
|
+
outputTokens: CountSchema,
|
|
76530
|
+
costUsd: external_exports.number().min(0).nullable()
|
|
76531
|
+
}).exactOptional(),
|
|
76524
76532
|
/** Set by the caller when a live routing-vs-control comparison chose this run's arm;
|
|
76525
76533
|
* unset outside a comparison. The caller decides the arm itself and reports it here —
|
|
76526
76534
|
* bizzy-v2 never sees or sets it. */
|
|
@@ -76589,6 +76597,7 @@ function validateRoutingState(value) {
|
|
|
76589
76597
|
}
|
|
76590
76598
|
|
|
76591
76599
|
// bizzy-routing/contracts/src/step.ts
|
|
76600
|
+
var gradeQuestionId = (rank) => `grade_${rank}`;
|
|
76592
76601
|
function answerSchema(question) {
|
|
76593
76602
|
switch (question.kind) {
|
|
76594
76603
|
case "yes-no":
|
|
@@ -76615,6 +76624,7 @@ function validateTurnSignals(input2) {
|
|
|
76615
76624
|
}
|
|
76616
76625
|
|
|
76617
76626
|
// bizzy-routing/contracts/src/schemas/step.ts
|
|
76627
|
+
var OpenWindowSchema = external_exports.object({ id: SafeIdSchema, controlRatio: UnitSchema });
|
|
76618
76628
|
var RouteDecisionSchema = external_exports.object({
|
|
76619
76629
|
model: ModelCandidateSchema,
|
|
76620
76630
|
mode: ModeSchema,
|
|
@@ -76643,7 +76653,9 @@ var DoneStepSchema = external_exports.object({
|
|
|
76643
76653
|
decision: RouteDecisionSchema,
|
|
76644
76654
|
state: RoutingStateSchema,
|
|
76645
76655
|
/** Set by the host when a question went unanswered, so the decision is the rules' alone; for the user to see. */
|
|
76646
|
-
notice: external_exports.string().exactOptional()
|
|
76656
|
+
notice: external_exports.string().exactOptional(),
|
|
76657
|
+
/** Set when a live routing-vs-control comparison is open; unset otherwise. */
|
|
76658
|
+
window: OpenWindowSchema.exactOptional()
|
|
76647
76659
|
});
|
|
76648
76660
|
var StepSchema = external_exports.discriminatedUnion("kind", [AskJudgeStepSchema, DoneStepSchema]);
|
|
76649
76661
|
|
|
@@ -76653,9 +76665,14 @@ var strategies = [
|
|
|
76653
76665
|
"stage",
|
|
76654
76666
|
"plan-execute",
|
|
76655
76667
|
"escalate",
|
|
76656
|
-
"judge-select"
|
|
76668
|
+
"judge-select",
|
|
76669
|
+
"judge-grade"
|
|
76670
|
+
];
|
|
76671
|
+
var profiles = [
|
|
76672
|
+
"jev",
|
|
76673
|
+
"cascade",
|
|
76674
|
+
"jev-grade"
|
|
76657
76675
|
];
|
|
76658
|
-
var profiles = ["jev", "cascade"];
|
|
76659
76676
|
var maximumCandidates = 64;
|
|
76660
76677
|
var maximumSummary = 8e3;
|
|
76661
76678
|
var RouteBodySchema = external_exports.strictObject({
|
|
@@ -76731,7 +76748,9 @@ __export(src_exports, {
|
|
|
76731
76748
|
getPromoted: () => getPromoted,
|
|
76732
76749
|
has: () => has,
|
|
76733
76750
|
isTrialDue: () => isTrialDue,
|
|
76751
|
+
jevGradeProfile: () => jevGradeProfile,
|
|
76734
76752
|
jevProfile: () => jevProfile,
|
|
76753
|
+
judgeGradeStrategy: () => judgeGradeStrategy,
|
|
76735
76754
|
judgeSelectConstants: () => judgeSelectConstants,
|
|
76736
76755
|
judgeSelectStrategy: () => judgeSelectStrategy,
|
|
76737
76756
|
list: () => list,
|
|
@@ -76782,6 +76801,7 @@ var cascadeProfile = {
|
|
|
76782
76801
|
trigger: "new-session",
|
|
76783
76802
|
context: "summary"
|
|
76784
76803
|
};
|
|
76804
|
+
var jevGradeProfile = { name: "jev-grade" };
|
|
76785
76805
|
|
|
76786
76806
|
// bizzy-routing/decision/src/registry/memory-store.ts
|
|
76787
76807
|
var entryKey = (id2, taskType) => `${taskType}::${id2}`;
|
|
@@ -77138,10 +77158,13 @@ var harnessFor = (mode) => mode === "enhance" ? "robust" : "standard";
|
|
|
77138
77158
|
function effectiveFloor(task, mode) {
|
|
77139
77159
|
return mode === "enhance" ? Math.max(task.qualityFloor, task.risk === "high" ? 0.9 : 0.75) : task.qualityFloor;
|
|
77140
77160
|
}
|
|
77141
|
-
function
|
|
77142
|
-
|
|
77161
|
+
function permittedCandidates(input2) {
|
|
77162
|
+
return input2.candidates.filter(
|
|
77143
77163
|
(candidate) => candidate.available && candidate.credentialed && (input2.accessible?.(candidate.id) ?? true) && (candidate.provider !== "openrouter" || input2.allowOpenRouter === true)
|
|
77144
77164
|
);
|
|
77165
|
+
}
|
|
77166
|
+
function contextFor(input2) {
|
|
77167
|
+
const permitted = permittedCandidates(input2);
|
|
77145
77168
|
const context = {
|
|
77146
77169
|
input: input2,
|
|
77147
77170
|
floor: effectiveFloor(input2.task, input2.mode),
|
|
@@ -77313,6 +77336,38 @@ function escalateStrategy(constants5 = escalationConstants) {
|
|
|
77313
77336
|
};
|
|
77314
77337
|
}
|
|
77315
77338
|
|
|
77339
|
+
// bizzy-routing/decision/src/strategies/judge-grade.ts
|
|
77340
|
+
var judgeGradeStrategy = function* (input2) {
|
|
77341
|
+
const state = validateRoutingState(input2.state);
|
|
77342
|
+
const base = cascade(input2, [pin, trial, registry2, history, coldStart]);
|
|
77343
|
+
if (input2.pin) return { kind: "done", decision: base, state };
|
|
77344
|
+
const ranked = [...permittedCandidates(input2)].sort((a, b) => a.costPer1k - b.costPer1k);
|
|
77345
|
+
if (!ranked.length) return { kind: "done", decision: base, state };
|
|
77346
|
+
const questions2 = ranked.map((_, i) => ({
|
|
77347
|
+
id: gradeQuestionId(i + 1),
|
|
77348
|
+
kind: "score",
|
|
77349
|
+
min: 0,
|
|
77350
|
+
max: 1
|
|
77351
|
+
}));
|
|
77352
|
+
const result = yield { kind: "ask-judge", questions: questions2, context: "summary" };
|
|
77353
|
+
if (result.kind !== "answers") return { kind: "done", decision: base, state };
|
|
77354
|
+
const winner = ranked.find((_, i) => {
|
|
77355
|
+
const answer = result.answers[gradeQuestionId(i + 1)];
|
|
77356
|
+
return typeof answer === "number" && answer > 0.5;
|
|
77357
|
+
});
|
|
77358
|
+
if (!winner || winner === base.model) return { kind: "done", decision: base, state };
|
|
77359
|
+
return {
|
|
77360
|
+
kind: "done",
|
|
77361
|
+
decision: decisionForModel(
|
|
77362
|
+
base,
|
|
77363
|
+
winner,
|
|
77364
|
+
"judge-grade",
|
|
77365
|
+
"judge-grade: cheapest candidate Jev rated capable of the task"
|
|
77366
|
+
),
|
|
77367
|
+
state
|
|
77368
|
+
};
|
|
77369
|
+
};
|
|
77370
|
+
|
|
77316
77371
|
// bizzy-routing/decision/src/strategies/judge-select.ts
|
|
77317
77372
|
var judgeSelectConstants = { cutoff: 0.05, margin: defaultMargin };
|
|
77318
77373
|
function judgeSelectStrategy(constants5 = judgeSelectConstants) {
|
|
@@ -77410,12 +77465,14 @@ var strategies2 = {
|
|
|
77410
77465
|
stage: (tuning) => stageStrategy(tuning.stage),
|
|
77411
77466
|
"plan-execute": () => planExecuteStrategy,
|
|
77412
77467
|
escalate: (tuning) => escalateStrategy(tuning.escalation),
|
|
77413
|
-
"judge-select": (tuning) => judgeSelectStrategy(tuning.judgeSelect)
|
|
77468
|
+
"judge-select": (tuning) => judgeSelectStrategy(tuning.judgeSelect),
|
|
77469
|
+
"judge-grade": () => judgeGradeStrategy
|
|
77414
77470
|
};
|
|
77415
77471
|
function plan(input2) {
|
|
77416
77472
|
const tuning = input2.tuning ?? {};
|
|
77417
77473
|
if (input2.strategy) return strategies2[input2.strategy](tuning)(input2);
|
|
77418
77474
|
const profile = input2.profile ?? jevProfile;
|
|
77475
|
+
if (profile.name === "jev-grade") return judgeGradeStrategy(input2);
|
|
77419
77476
|
const profiled = { ...input2, margin: input2.margin ?? profile.margin };
|
|
77420
77477
|
if (profile.name === "cascade") return cascadeStrategy(profiled);
|
|
77421
77478
|
return judgeSelectStrategy({
|
|
@@ -77470,8 +77527,8 @@ function routeFromRegistry(input2) {
|
|
|
77470
77527
|
|
|
77471
77528
|
// bizzy-routing/decision/src/benchmarks.ts
|
|
77472
77529
|
function deviation(values) {
|
|
77473
|
-
const
|
|
77474
|
-
return Math.sqrt(values.reduce((sum, value) => sum + (value -
|
|
77530
|
+
const mean3 = values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
77531
|
+
return Math.sqrt(values.reduce((sum, value) => sum + (value - mean3) ** 2, 0) / values.length);
|
|
77475
77532
|
}
|
|
77476
77533
|
function intelligenceScale(catalog) {
|
|
77477
77534
|
const both = catalog.filter(
|
|
@@ -81314,7 +81371,10 @@ async function routeInput(envelope, options) {
|
|
|
81314
81371
|
};
|
|
81315
81372
|
}
|
|
81316
81373
|
function profileFor({ envelope, material }) {
|
|
81317
|
-
|
|
81374
|
+
if (material.policy === "none") return cascadeProfile;
|
|
81375
|
+
if (envelope.profile === "cascade") return cascadeProfile;
|
|
81376
|
+
if (envelope.profile === "jev-grade") return jevGradeProfile;
|
|
81377
|
+
return jevProfile;
|
|
81318
81378
|
}
|
|
81319
81379
|
var routeNotices = {
|
|
81320
81380
|
absent: "no OpenRouter key: routing with Bizzy's own rules",
|
|
@@ -81322,24 +81382,25 @@ var routeNotices = {
|
|
|
81322
81382
|
};
|
|
81323
81383
|
var noContextNotice = "no context set: routing with Bizzy's own rules";
|
|
81324
81384
|
async function routeSteps(body, options, onStep, signal) {
|
|
81325
|
-
const done = await driveRoute(
|
|
81326
|
-
body,
|
|
81327
|
-
await routeInput(body.envelope, options),
|
|
81328
|
-
options,
|
|
81385
|
+
const done = await driveRoute(body, await routeInput(body.envelope, options), options, {
|
|
81329
81386
|
onStep,
|
|
81330
|
-
signal
|
|
81331
|
-
);
|
|
81387
|
+
...signal ? { signal } : {}
|
|
81388
|
+
});
|
|
81332
81389
|
const implicitCascade = body.envelope.profile !== "cascade" && body.material.policy === "none";
|
|
81333
81390
|
return implicitCascade && !done.notice ? { ...done, notice: noContextNotice } : done;
|
|
81334
81391
|
}
|
|
81335
|
-
function driveRoute(body, input2, options,
|
|
81336
|
-
|
|
81337
|
-
const executor = options.judgeFor ? withContextPolicy(
|
|
81392
|
+
function driveRoute(body, input2, options, extra = {}) {
|
|
81393
|
+
const judgeUsage = extra.judgeUsage ?? { inputTokens: 0, outputTokens: 0 };
|
|
81394
|
+
const executor = options.judgeFor ? withContextPolicy(
|
|
81395
|
+
body.material.policy,
|
|
81396
|
+
options.judgeFor(body.material, input2.candidates.length, judgeUsage)
|
|
81397
|
+
) : void 0;
|
|
81338
81398
|
return drive(
|
|
81339
81399
|
plan({ ...input2, profile: profileFor(body) }),
|
|
81340
81400
|
executor,
|
|
81341
|
-
signal,
|
|
81342
|
-
onStep
|
|
81401
|
+
extra.signal,
|
|
81402
|
+
extra.onStep ?? (() => {
|
|
81403
|
+
}),
|
|
81343
81404
|
options.notices ?? routeNotices
|
|
81344
81405
|
);
|
|
81345
81406
|
}
|
|
@@ -81354,6 +81415,12 @@ async function settleBody(raw, options) {
|
|
|
81354
81415
|
options.calibration
|
|
81355
81416
|
);
|
|
81356
81417
|
}
|
|
81418
|
+
function trialWindowOpenBody(raw) {
|
|
81419
|
+
const controlRatio = typeof raw === "object" && raw !== null ? raw.controlRatio : void 0;
|
|
81420
|
+
if (typeof controlRatio !== "number" || !(controlRatio > 0 && controlRatio < 1))
|
|
81421
|
+
throw new TypeError("controlRatio must be a number strictly between 0 and 1");
|
|
81422
|
+
return controlRatio;
|
|
81423
|
+
}
|
|
81357
81424
|
|
|
81358
81425
|
// bizzy-routing/api/src/harness.ts
|
|
81359
81426
|
import { createHash, randomUUID as randomUUID2 } from "node:crypto";
|
|
@@ -81394,6 +81461,7 @@ function createHostedRoute(options) {
|
|
|
81394
81461
|
candidates: envelope.candidates,
|
|
81395
81462
|
mode: envelope.mode,
|
|
81396
81463
|
state: envelope.state,
|
|
81464
|
+
...envelope.profile ? { profile: envelope.profile } : {},
|
|
81397
81465
|
...envelope.newUserTurn ? { newUserTurn: true } : {},
|
|
81398
81466
|
...shared ? { context: "summary", summary: shared } : {}
|
|
81399
81467
|
};
|
|
@@ -81590,6 +81658,7 @@ function harnessOutcomes(messages) {
|
|
|
81590
81658
|
function createHarnessRouter(options, server) {
|
|
81591
81659
|
const sessions = /* @__PURE__ */ new Map();
|
|
81592
81660
|
const now = options.now ?? Date.now;
|
|
81661
|
+
const random = options.random ?? Math.random;
|
|
81593
81662
|
const ttl = options.sessionTtlMs ?? 6 * 60 * 60 * 1e3;
|
|
81594
81663
|
const refusalCooldown = options.refusalCooldownMs ?? 10 * 60 * 1e3;
|
|
81595
81664
|
const transientCooldown = options.transientCooldownMs ?? 60 * 1e3;
|
|
@@ -81622,14 +81691,26 @@ function createHarnessRouter(options, server) {
|
|
|
81622
81691
|
sessions.set(key, found);
|
|
81623
81692
|
return found;
|
|
81624
81693
|
}
|
|
81625
|
-
async function
|
|
81626
|
-
|
|
81694
|
+
async function withLocalWindow(done) {
|
|
81695
|
+
const window2 = server.trialWindow?.load();
|
|
81696
|
+
return window2 ? { ...done, window: { id: window2.id, controlRatio: window2.controlRatio } } : done;
|
|
81697
|
+
}
|
|
81698
|
+
async function routed(envelope, material, input2, prompt, judgeUsage) {
|
|
81699
|
+
if (!server.hosted)
|
|
81700
|
+
return withLocalWindow(
|
|
81701
|
+
await driveRoute({ envelope, material }, input2, server, { judgeUsage })
|
|
81702
|
+
);
|
|
81627
81703
|
try {
|
|
81628
81704
|
return await server.hosted.route(envelope, prompt);
|
|
81629
81705
|
} catch (error62) {
|
|
81630
81706
|
const reason = error62 instanceof HostedError ? error62.message : "failed";
|
|
81631
|
-
const local = await driveRoute({ envelope, material: { policy: "none" } }, input2, server
|
|
81632
|
-
|
|
81707
|
+
const local = await driveRoute({ envelope, material: { policy: "none" } }, input2, server, {
|
|
81708
|
+
judgeUsage
|
|
81709
|
+
});
|
|
81710
|
+
return withLocalWindow({
|
|
81711
|
+
...local,
|
|
81712
|
+
notice: `hosted routing ${reason}: routing with Bizzy's own rules`
|
|
81713
|
+
});
|
|
81633
81714
|
}
|
|
81634
81715
|
}
|
|
81635
81716
|
async function decide(current, body, models2, signals) {
|
|
@@ -81646,22 +81727,26 @@ function createHarnessRouter(options, server) {
|
|
|
81646
81727
|
candidates: models2.pool,
|
|
81647
81728
|
mode: "auto",
|
|
81648
81729
|
state: current.state,
|
|
81649
|
-
newUserTurn: true
|
|
81730
|
+
newUserTurn: true,
|
|
81731
|
+
...options.profile ? { profile: options.profile } : {}
|
|
81650
81732
|
};
|
|
81651
81733
|
const material = body.prompt ? { policy: "summary", summary: body.prompt } : { policy: "none" };
|
|
81652
81734
|
const input2 = await routeInput(envelope, server);
|
|
81653
|
-
const
|
|
81735
|
+
const judgeUsage = { inputTokens: 0, outputTokens: 0 };
|
|
81736
|
+
const done = await routed(envelope, material, input2, body.prompt, judgeUsage);
|
|
81654
81737
|
const rule = done.decision.rule === "capable" ? "capable" : "efficient";
|
|
81655
81738
|
current.state = { ...done.state, tier: rule, capableHold: 0 };
|
|
81656
81739
|
const sent = server.hosted ? server.hosted.sharesPrompts && body.prompt : body.prompt;
|
|
81657
81740
|
const notice = done.notice ?? (sent ? void 0 : noPrompt);
|
|
81658
81741
|
const judged = done.decision.source === "judge-select" && !done.notice;
|
|
81742
|
+
const arm = done.window ? random() < done.window.controlRatio ? "control" : "treatment" : void 0;
|
|
81659
81743
|
const chosen = {
|
|
81660
81744
|
model: done.decision.model.id,
|
|
81661
81745
|
rule,
|
|
81662
81746
|
source: done.decision.source,
|
|
81663
81747
|
reason: done.decision.reason,
|
|
81664
|
-
...notice ? { notice } : {}
|
|
81748
|
+
...notice ? { notice } : {},
|
|
81749
|
+
...arm ? { arm } : {}
|
|
81665
81750
|
};
|
|
81666
81751
|
return {
|
|
81667
81752
|
chosen,
|
|
@@ -81670,6 +81755,8 @@ function createHarnessRouter(options, server) {
|
|
|
81670
81755
|
input: input2,
|
|
81671
81756
|
...judged && typeof done.state.judgeAdvantage === "number" ? { judgeAdvantage: done.state.judgeAdvantage } : {},
|
|
81672
81757
|
...judged && done.state.judgeTrial ? { judgeTrial: true } : {},
|
|
81758
|
+
...done.window ? { windowId: done.window.id } : {},
|
|
81759
|
+
...judgeUsage.inputTokens || judgeUsage.outputTokens ? { judgeUsage } : {},
|
|
81673
81760
|
startedAt: now(),
|
|
81674
81761
|
signals
|
|
81675
81762
|
};
|
|
@@ -81685,7 +81772,8 @@ function createHarnessRouter(options, server) {
|
|
|
81685
81772
|
rule,
|
|
81686
81773
|
source: "stage",
|
|
81687
81774
|
reason: capable.reason ? `stage: capable; ${capable.reason}` : "stage: capable",
|
|
81688
|
-
...turn.chosen.notice ? { notice: turn.chosen.notice } : {}
|
|
81775
|
+
...turn.chosen.notice ? { notice: turn.chosen.notice } : {},
|
|
81776
|
+
...turn.chosen.arm ? { arm: turn.chosen.arm } : {}
|
|
81689
81777
|
};
|
|
81690
81778
|
}
|
|
81691
81779
|
async function step(body, given) {
|
|
@@ -81718,7 +81806,8 @@ function createHarnessRouter(options, server) {
|
|
|
81718
81806
|
const decision = {
|
|
81719
81807
|
...instead,
|
|
81720
81808
|
source: failed.source,
|
|
81721
|
-
reason: `fallback: ${body.model} ${body.transient ? "failed" : "refused"}
|
|
81809
|
+
reason: `fallback: ${body.model} ${body.transient ? "failed" : "refused"}`,
|
|
81810
|
+
...turn?.served.arm ? { arm: turn.served.arm } : {}
|
|
81722
81811
|
};
|
|
81723
81812
|
if (turn) turn.served = decision;
|
|
81724
81813
|
if (current.last?.turnId === body.turnId) current.last = { ...current.last, decision };
|
|
@@ -81747,7 +81836,14 @@ function createHarnessRouter(options, server) {
|
|
|
81747
81836
|
source: turn.served.source,
|
|
81748
81837
|
rule: turn.served.rule,
|
|
81749
81838
|
...turn.judgeAdvantage === void 0 ? {} : { judgeAdvantage: turn.judgeAdvantage },
|
|
81750
|
-
...turn.judgeTrial ? { judgeTrial: true } : {}
|
|
81839
|
+
...turn.judgeTrial ? { judgeTrial: true } : {},
|
|
81840
|
+
...turn.judgeUsage ? {
|
|
81841
|
+
judgeUsage: {
|
|
81842
|
+
...turn.judgeUsage,
|
|
81843
|
+
costUsd: server.judgePricePer1k ? turn.judgeUsage.inputTokens / 1e3 * server.judgePricePer1k.input + turn.judgeUsage.outputTokens / 1e3 * server.judgePricePer1k.output : null
|
|
81844
|
+
}
|
|
81845
|
+
} : {},
|
|
81846
|
+
...turn.served.arm ? { arm: turn.served.arm, windowId: turn.windowId } : {}
|
|
81751
81847
|
},
|
|
81752
81848
|
startedAt: new Date(turn.startedAt).toISOString(),
|
|
81753
81849
|
settledAt: new Date(settledAt).toISOString(),
|
|
@@ -82070,10 +82166,14 @@ function createCodexRelay(options, server) {
|
|
|
82070
82166
|
const list2 = position ? await accountModels(base, forward) : null;
|
|
82071
82167
|
const matched = position ? await matchedOf(list2) : void 0;
|
|
82072
82168
|
let model = typeof body.model === "string" ? body.model : void 0;
|
|
82169
|
+
let control = false;
|
|
82073
82170
|
if (position) {
|
|
82074
82171
|
try {
|
|
82075
82172
|
const decision = matched && await router.step({ ...position, compacted: false }, matched);
|
|
82076
|
-
|
|
82173
|
+
control = decision?.arm === "control";
|
|
82174
|
+
model = control ? visibleModels(list2)[0]?.slug : decision?.model;
|
|
82175
|
+
if (control)
|
|
82176
|
+
options.log?.(`codex ${position.session}: sampled into control, keeping ${model}`);
|
|
82077
82177
|
if (decision?.notice && !noticed.has(position.session)) {
|
|
82078
82178
|
noticed.add(position.session);
|
|
82079
82179
|
options.log?.(`codex ${position.session}: ${decision.notice}`);
|
|
@@ -82115,7 +82215,7 @@ function createCodexRelay(options, server) {
|
|
|
82115
82215
|
unreachable = error62 instanceof Error ? error62.message : String(error62);
|
|
82116
82216
|
failed = { transient: true };
|
|
82117
82217
|
}
|
|
82118
|
-
const next = position && failed && model ? router.fallback(
|
|
82218
|
+
const next = position && failed && model && !control ? router.fallback(
|
|
82119
82219
|
{
|
|
82120
82220
|
session: position.session,
|
|
82121
82221
|
turnId: position.turnId,
|
|
@@ -82287,6 +82387,73 @@ function openApiDocument({ auth }) {
|
|
|
82287
82387
|
})
|
|
82288
82388
|
}
|
|
82289
82389
|
},
|
|
82390
|
+
"/v1/trial-window": {
|
|
82391
|
+
get: {
|
|
82392
|
+
summary: "Check the live routing-vs-control comparison",
|
|
82393
|
+
description: "A cheap, standalone check for whether a routing-vs-control comparison is open, for a caller like Kif that otherwise skips `/v1/route` entirely when sampled into control. A caller already streaming `/v1/route` sees the same thing on its `done` step and doesn't need this.",
|
|
82394
|
+
...guard({
|
|
82395
|
+
"200": {
|
|
82396
|
+
description: "The open window, or `null` when none is open.",
|
|
82397
|
+
content: { "application/json": { schema: ref("TrialWindow") } }
|
|
82398
|
+
}
|
|
82399
|
+
})
|
|
82400
|
+
},
|
|
82401
|
+
post: {
|
|
82402
|
+
summary: "Open a routing-vs-control comparison",
|
|
82403
|
+
description: "Opens a new trial window at `controlRatio` (strictly between 0 and 1): that share of sampled sessions keep their own routing (control) instead of Bizzy's (treatment). Refused with 409 while one is already open, rather than silently replacing it and reassigning every session's arm mid-comparison; close it first.",
|
|
82404
|
+
requestBody: {
|
|
82405
|
+
required: true,
|
|
82406
|
+
content: {
|
|
82407
|
+
"application/json": {
|
|
82408
|
+
schema: { type: "object", properties: { controlRatio: { type: "number" } } }
|
|
82409
|
+
}
|
|
82410
|
+
}
|
|
82411
|
+
},
|
|
82412
|
+
...guard({
|
|
82413
|
+
"200": {
|
|
82414
|
+
description: "`{ id, controlRatio, openedAt }`: the window just opened.",
|
|
82415
|
+
content: { "application/json": { schema: { type: "object" } } }
|
|
82416
|
+
},
|
|
82417
|
+
"400": failure2("controlRatio is missing or not strictly between 0 and 1."),
|
|
82418
|
+
"409": failure2("A trial window is already open; its id and controlRatio are included."),
|
|
82419
|
+
"501": failure2("This server has no trial window store configured.")
|
|
82420
|
+
})
|
|
82421
|
+
},
|
|
82422
|
+
delete: {
|
|
82423
|
+
summary: "Close the live routing-vs-control comparison",
|
|
82424
|
+
description: "Idempotent: succeeds whether or not one was open.",
|
|
82425
|
+
...guard({
|
|
82426
|
+
"200": {
|
|
82427
|
+
description: "`{ closed }`: whether a window was actually open to close.",
|
|
82428
|
+
content: { "application/json": { schema: { type: "object" } } }
|
|
82429
|
+
}
|
|
82430
|
+
})
|
|
82431
|
+
}
|
|
82432
|
+
},
|
|
82433
|
+
"/v1/trial-report": {
|
|
82434
|
+
get: {
|
|
82435
|
+
summary: "Report the routing-vs-control comparison",
|
|
82436
|
+
description: "Per window, per arm and task kind: runs, cost per completed run (every attempt's cost over the runs that succeeded), success rate, average quality and latency. Aggregates only. Takes a key from BIZZY_API_KEYS or a read-only one from BIZZY_REPORT_KEYS.",
|
|
82437
|
+
...guard({
|
|
82438
|
+
"200": {
|
|
82439
|
+
description: "`{ open, windows }`: `open` is the open window or null; `windows` has one `{ windowId, firstSettledAt, lastSettledAt, rows }` per window with sampled runs, oldest first, and `rows` holds `{ arm, taskKind, runs, costPerCompleted, successRate, avgQuality, avgLatencyMs }` (`costPerCompleted` null when nothing succeeded).",
|
|
82440
|
+
content: { "application/json": { schema: { type: "object" } } }
|
|
82441
|
+
}
|
|
82442
|
+
})
|
|
82443
|
+
}
|
|
82444
|
+
},
|
|
82445
|
+
"/v1/routing-report": {
|
|
82446
|
+
get: {
|
|
82447
|
+
summary: "Report Bizzy's own standing routing performance",
|
|
82448
|
+
description: "Per day and task kind, over every run Bizzy actually routed (a trial's control arm is excluded; it isn't Bizzy's routing): runs, cost per completed run, success rate, average quality, latency and token usage, how often routing escalated to the capable model, and Jev's own call rate and cost. Aggregates only. Independent of any trial window. Takes a key from BIZZY_API_KEYS or a read-only one from BIZZY_REPORT_KEYS.",
|
|
82449
|
+
...guard({
|
|
82450
|
+
"200": {
|
|
82451
|
+
description: "`{ rows }`: one `{ date, taskKind, runs, costPerCompleted, successRate, avgQuality, avgLatencyMs, avgInputTokens, avgOutputTokens, capableRate, judgeCallRate, avgJudgeCostUsd }` per day and task kind, oldest first (`costPerCompleted` and `avgJudgeCostUsd` null when nothing succeeded, or nothing priced the judge).",
|
|
82452
|
+
content: { "application/json": { schema: { type: "object" } } }
|
|
82453
|
+
}
|
|
82454
|
+
})
|
|
82455
|
+
}
|
|
82456
|
+
},
|
|
82290
82457
|
"/v1/settle": {
|
|
82291
82458
|
post: {
|
|
82292
82459
|
summary: "Record a finished run",
|
|
@@ -82321,6 +82488,7 @@ function openApiDocument({ auth }) {
|
|
|
82321
82488
|
Step: json2(StepSchema, "output"),
|
|
82322
82489
|
ErrorLine: json2(ErrorLineSchema, "output"),
|
|
82323
82490
|
RouteStreamLine: { oneOf: [ref("Step"), ref("ErrorLine")] },
|
|
82491
|
+
TrialWindow: json2(OpenWindowSchema.nullable(), "output"),
|
|
82324
82492
|
SettleReply: json2(SettleReplySchema, "output"),
|
|
82325
82493
|
ErrorBody: json2(ErrorBodySchema, "output")
|
|
82326
82494
|
}
|
|
@@ -82328,11 +82496,109 @@ function openApiDocument({ auth }) {
|
|
|
82328
82496
|
};
|
|
82329
82497
|
}
|
|
82330
82498
|
|
|
82499
|
+
// bizzy-routing/api/src/routing-report.ts
|
|
82500
|
+
var mean = (values) => values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
82501
|
+
function judgeCostAverage(runs) {
|
|
82502
|
+
const priced = runs.flatMap(
|
|
82503
|
+
(run3) => typeof run3.route.judgeUsage?.costUsd === "number" ? [run3.route.judgeUsage.costUsd] : []
|
|
82504
|
+
);
|
|
82505
|
+
return priced.length ? mean(priced) : null;
|
|
82506
|
+
}
|
|
82507
|
+
function summarizeRouting(records2) {
|
|
82508
|
+
const groups = /* @__PURE__ */ new Map();
|
|
82509
|
+
for (const record5 of records2) {
|
|
82510
|
+
if (record5.route.arm === "control") continue;
|
|
82511
|
+
const date5 = record5.settledAt.slice(0, 10);
|
|
82512
|
+
const key = `${date5}\0${record5.task.kind}`;
|
|
82513
|
+
const group = groups.get(key) ?? [];
|
|
82514
|
+
group.push(record5);
|
|
82515
|
+
groups.set(key, group);
|
|
82516
|
+
}
|
|
82517
|
+
return [...groups.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([key, runs]) => {
|
|
82518
|
+
const [date5, taskKind] = key.split("\0");
|
|
82519
|
+
const completed = runs.filter((run3) => run3.taskSuccess);
|
|
82520
|
+
const totalCost = runs.reduce((sum, run3) => sum + run3.usage.costUsd, 0);
|
|
82521
|
+
return {
|
|
82522
|
+
date: date5,
|
|
82523
|
+
taskKind,
|
|
82524
|
+
runs: runs.length,
|
|
82525
|
+
costPerCompleted: completed.length ? totalCost / completed.length : null,
|
|
82526
|
+
successRate: completed.length / runs.length,
|
|
82527
|
+
avgQuality: mean(runs.map((run3) => run3.quality)),
|
|
82528
|
+
avgLatencyMs: mean(runs.map((run3) => run3.latencyMs)),
|
|
82529
|
+
avgInputTokens: mean(runs.map((run3) => run3.usage.inputTokens)),
|
|
82530
|
+
avgOutputTokens: mean(runs.map((run3) => run3.usage.outputTokens)),
|
|
82531
|
+
capableRate: runs.filter((run3) => run3.route.rule === "capable").length / runs.length,
|
|
82532
|
+
judgeCallRate: runs.filter((run3) => run3.route.judgeUsage).length / runs.length,
|
|
82533
|
+
avgJudgeCostUsd: judgeCostAverage(runs)
|
|
82534
|
+
};
|
|
82535
|
+
});
|
|
82536
|
+
}
|
|
82537
|
+
|
|
82538
|
+
// bizzy-routing/api/src/trial-report.ts
|
|
82539
|
+
var mean2 = (values) => values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
82540
|
+
function summarizeWindow(records2) {
|
|
82541
|
+
const groups = /* @__PURE__ */ new Map();
|
|
82542
|
+
for (const record5 of records2) {
|
|
82543
|
+
if (!record5.route.arm) continue;
|
|
82544
|
+
const key = `${record5.route.arm}\0${record5.task.kind}`;
|
|
82545
|
+
const group = groups.get(key) ?? [];
|
|
82546
|
+
group.push(record5);
|
|
82547
|
+
groups.set(key, group);
|
|
82548
|
+
}
|
|
82549
|
+
return [...groups.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([key, runs]) => {
|
|
82550
|
+
const [arm, taskKind] = key.split("\0");
|
|
82551
|
+
const completed = runs.filter((run3) => run3.taskSuccess);
|
|
82552
|
+
const totalCost = runs.reduce((sum, run3) => sum + run3.usage.costUsd, 0);
|
|
82553
|
+
return {
|
|
82554
|
+
arm,
|
|
82555
|
+
taskKind,
|
|
82556
|
+
runs: runs.length,
|
|
82557
|
+
costPerCompleted: completed.length ? totalCost / completed.length : null,
|
|
82558
|
+
successRate: completed.length / runs.length,
|
|
82559
|
+
avgQuality: mean2(runs.map((run3) => run3.quality)),
|
|
82560
|
+
avgLatencyMs: mean2(runs.map((run3) => run3.latencyMs))
|
|
82561
|
+
};
|
|
82562
|
+
});
|
|
82563
|
+
}
|
|
82564
|
+
function trialReport(records2, open3) {
|
|
82565
|
+
const byWindow = /* @__PURE__ */ new Map();
|
|
82566
|
+
for (const record5 of records2) {
|
|
82567
|
+
const { windowId } = record5.route;
|
|
82568
|
+
if (windowId) byWindow.set(windowId, [...byWindow.get(windowId) ?? [], record5]);
|
|
82569
|
+
}
|
|
82570
|
+
const windows = [...byWindow.entries()].map(([windowId, runs]) => {
|
|
82571
|
+
const settled = runs.map((run3) => run3.settledAt).sort();
|
|
82572
|
+
return {
|
|
82573
|
+
windowId,
|
|
82574
|
+
firstSettledAt: settled[0],
|
|
82575
|
+
lastSettledAt: settled.at(-1),
|
|
82576
|
+
rows: summarizeWindow(runs)
|
|
82577
|
+
};
|
|
82578
|
+
});
|
|
82579
|
+
return {
|
|
82580
|
+
open: open3,
|
|
82581
|
+
windows: windows.sort((a, b) => a.firstSettledAt.localeCompare(b.firstSettledAt))
|
|
82582
|
+
};
|
|
82583
|
+
}
|
|
82584
|
+
|
|
82331
82585
|
// bizzy-routing/api/src/server.ts
|
|
82332
|
-
var baseRoutes = [
|
|
82586
|
+
var baseRoutes = [
|
|
82587
|
+
"/v1/route",
|
|
82588
|
+
"/v1/settle",
|
|
82589
|
+
"/v1/trial-window",
|
|
82590
|
+
"/v1/trial-report",
|
|
82591
|
+
"/v1/routing-report",
|
|
82592
|
+
"/docs",
|
|
82593
|
+
"/openapi.json"
|
|
82594
|
+
];
|
|
82333
82595
|
var harnessActions = ["step", "fallback", "models", "complete"];
|
|
82334
82596
|
var codexBodyBytes = 64 * 1024 * 1024;
|
|
82335
82597
|
var message2 = (error62) => error62 instanceof Error ? error62.message : String(error62);
|
|
82598
|
+
var openWindowOf = (window2) => ({
|
|
82599
|
+
id: window2.id,
|
|
82600
|
+
controlRatio: window2.controlRatio
|
|
82601
|
+
});
|
|
82336
82602
|
function createRoutingServer(options) {
|
|
82337
82603
|
useRegistryStore(options.registry);
|
|
82338
82604
|
const app = (0, import_fastify.default)({ bodyLimit: options.maxBodyBytes ?? 256 * 1024 });
|
|
@@ -82376,6 +82642,38 @@ function createRoutingServer(options) {
|
|
|
82376
82642
|
throw error62;
|
|
82377
82643
|
}
|
|
82378
82644
|
});
|
|
82645
|
+
app.get("/v1/trial-window", guarded, async () => {
|
|
82646
|
+
const window2 = options.trialWindow?.load();
|
|
82647
|
+
return window2 ? openWindowOf(window2) : null;
|
|
82648
|
+
});
|
|
82649
|
+
app.post("/v1/trial-window", guarded, async (request, reply) => {
|
|
82650
|
+
if (!options.trialWindow)
|
|
82651
|
+
return reply.code(501).send({ error: "no trial window store configured" });
|
|
82652
|
+
const existing = options.trialWindow.load();
|
|
82653
|
+
if (existing)
|
|
82654
|
+
return reply.code(409).send({ error: "a trial window is already open", window: openWindowOf(existing) });
|
|
82655
|
+
let controlRatio;
|
|
82656
|
+
try {
|
|
82657
|
+
controlRatio = trialWindowOpenBody(request.body);
|
|
82658
|
+
} catch (error62) {
|
|
82659
|
+
return reply.code(400).send({ error: message2(error62) });
|
|
82660
|
+
}
|
|
82661
|
+
return options.trialWindow.open(controlRatio);
|
|
82662
|
+
});
|
|
82663
|
+
app.delete("/v1/trial-window", guarded, async () => {
|
|
82664
|
+
const was = options.trialWindow?.load();
|
|
82665
|
+
options.trialWindow?.close();
|
|
82666
|
+
return { closed: Boolean(was) };
|
|
82667
|
+
});
|
|
82668
|
+
const reportKeys = [...keys, ...options.reportKeys ?? []];
|
|
82669
|
+
const reportGuard = reportKeys.length ? { onRequest: requireApiKey(reportKeys) } : {};
|
|
82670
|
+
app.get("/v1/trial-report", reportGuard, async () => {
|
|
82671
|
+
const window2 = options.trialWindow?.load();
|
|
82672
|
+
return trialReport(options.trialRuns?.() ?? [], window2 ? openWindowOf(window2) : null);
|
|
82673
|
+
});
|
|
82674
|
+
app.get("/v1/routing-report", reportGuard, async () => ({
|
|
82675
|
+
rows: summarizeRouting(options.allRuns?.() ?? [])
|
|
82676
|
+
}));
|
|
82379
82677
|
app.post("/v1/route", guarded, async (request, reply) => {
|
|
82380
82678
|
let parsed2;
|
|
82381
82679
|
try {
|
|
@@ -82392,8 +82690,15 @@ function createRoutingServer(options) {
|
|
|
82392
82690
|
await routeSteps(
|
|
82393
82691
|
parsed2,
|
|
82394
82692
|
options,
|
|
82395
|
-
|
|
82396
|
-
|
|
82693
|
+
// The done step picks up the open window here, at the one place that actually reaches the
|
|
82694
|
+
// client — routeSteps()'s own return value is never read, only what onStep writes.
|
|
82695
|
+
(step) => {
|
|
82696
|
+
const window2 = step.kind === "done" ? options.trialWindow?.load() : void 0;
|
|
82697
|
+
raw.write(
|
|
82698
|
+
`${JSON.stringify(window2 ? { ...step, window: openWindowOf(window2) } : step)}
|
|
82699
|
+
`
|
|
82700
|
+
);
|
|
82701
|
+
},
|
|
82397
82702
|
abort.signal
|
|
82398
82703
|
);
|
|
82399
82704
|
} catch (error62) {
|
|
@@ -82532,7 +82837,13 @@ var SqliteRunRecordStore = class {
|
|
|
82532
82837
|
#insert;
|
|
82533
82838
|
#comparable;
|
|
82534
82839
|
#observed;
|
|
82840
|
+
#trial;
|
|
82841
|
+
#all;
|
|
82535
82842
|
constructor(database) {
|
|
82843
|
+
this.#trial = database.prepare(
|
|
82844
|
+
"SELECT record FROM runs WHERE json_extract(record, '$.route.arm') IS NOT NULL AND json_extract(record, '$.route.windowId') IS NOT NULL ORDER BY seq"
|
|
82845
|
+
);
|
|
82846
|
+
this.#all = database.prepare("SELECT record FROM runs ORDER BY seq");
|
|
82536
82847
|
this.#insert = database.prepare(
|
|
82537
82848
|
"INSERT INTO runs (kind, risk, mode, harness_id, succeeded, record) VALUES (?, ?, ?, ?, ?, ?)"
|
|
82538
82849
|
);
|
|
@@ -82565,11 +82876,22 @@ var SqliteRunRecordStore = class {
|
|
|
82565
82876
|
async loadObserved(task, mode, harnessId) {
|
|
82566
82877
|
return records(this.#observed, task, mode, harnessId);
|
|
82567
82878
|
}
|
|
82879
|
+
/** Every run sampled into a routing-vs-control window, oldest first. */
|
|
82880
|
+
trialRuns() {
|
|
82881
|
+
return parse4(this.#trial.all());
|
|
82882
|
+
}
|
|
82883
|
+
/** Every run ever settled, oldest first. */
|
|
82884
|
+
allRuns() {
|
|
82885
|
+
return parse4(this.#all.all());
|
|
82886
|
+
}
|
|
82568
82887
|
};
|
|
82569
82888
|
function records(statement, task, mode, harnessId) {
|
|
82570
82889
|
const rows2 = statement.all(task.kind, task.risk, mode, harnessId);
|
|
82890
|
+
return parse4(rows2.reverse());
|
|
82891
|
+
}
|
|
82892
|
+
function parse4(rows2) {
|
|
82571
82893
|
const parsed2 = [];
|
|
82572
|
-
for (const { record: record5 } of rows2
|
|
82894
|
+
for (const { record: record5 } of rows2) {
|
|
82573
82895
|
try {
|
|
82574
82896
|
parsed2.push(sanitizeRunRecord(JSON.parse(record5)));
|
|
82575
82897
|
} catch {
|
|
@@ -82635,6 +82957,10 @@ var migrations = [
|
|
|
82635
82957
|
CREATE TABLE calibration (
|
|
82636
82958
|
slot INTEGER PRIMARY KEY CHECK (slot = 1),
|
|
82637
82959
|
stored TEXT NOT NULL
|
|
82960
|
+
);`,
|
|
82961
|
+
`CREATE TABLE trial_window (
|
|
82962
|
+
slot INTEGER PRIMARY KEY CHECK (slot = 1),
|
|
82963
|
+
stored TEXT NOT NULL
|
|
82638
82964
|
);`
|
|
82639
82965
|
];
|
|
82640
82966
|
|
|
@@ -82681,10 +83007,53 @@ async function openRoutingDatabase(cwd) {
|
|
|
82681
83007
|
}
|
|
82682
83008
|
}
|
|
82683
83009
|
|
|
83010
|
+
// bizzy-routing/api/src/sqlite/window.ts
|
|
83011
|
+
function parse5(stored) {
|
|
83012
|
+
try {
|
|
83013
|
+
const value = JSON.parse(stored);
|
|
83014
|
+
return typeof value.id === "string" && typeof value.controlRatio === "number" && typeof value.openedAt === "string" ? value : null;
|
|
83015
|
+
} catch {
|
|
83016
|
+
return null;
|
|
83017
|
+
}
|
|
83018
|
+
}
|
|
83019
|
+
var SqliteTrialWindowStore = class {
|
|
83020
|
+
#load;
|
|
83021
|
+
#save;
|
|
83022
|
+
#close;
|
|
83023
|
+
#now;
|
|
83024
|
+
constructor(database, now = () => /* @__PURE__ */ new Date()) {
|
|
83025
|
+
this.#load = database.prepare("SELECT stored FROM trial_window WHERE slot = 1");
|
|
83026
|
+
this.#save = database.prepare(
|
|
83027
|
+
`INSERT INTO trial_window (slot, stored) VALUES (1, ?)
|
|
83028
|
+
ON CONFLICT (slot) DO UPDATE SET stored = excluded.stored`
|
|
83029
|
+
);
|
|
83030
|
+
this.#close = database.prepare("DELETE FROM trial_window WHERE slot = 1");
|
|
83031
|
+
this.#now = now;
|
|
83032
|
+
}
|
|
83033
|
+
load() {
|
|
83034
|
+
const row = this.#load.get();
|
|
83035
|
+
return row ? parse5(row.stored) : null;
|
|
83036
|
+
}
|
|
83037
|
+
open(controlRatio) {
|
|
83038
|
+
if (!(controlRatio > 0 && controlRatio < 1))
|
|
83039
|
+
throw new RangeError("controlRatio must be between 0 and 1, exclusive");
|
|
83040
|
+
const window2 = {
|
|
83041
|
+
id: `w-${Math.floor(this.#now().getTime() / 1e3)}`,
|
|
83042
|
+
controlRatio,
|
|
83043
|
+
openedAt: this.#now().toISOString()
|
|
83044
|
+
};
|
|
83045
|
+
this.#save.run(JSON.stringify(window2));
|
|
83046
|
+
return window2;
|
|
83047
|
+
}
|
|
83048
|
+
close() {
|
|
83049
|
+
this.#close.run();
|
|
83050
|
+
}
|
|
83051
|
+
};
|
|
83052
|
+
|
|
82684
83053
|
// bizzy-routing/api/src/setup.ts
|
|
82685
83054
|
import { mkdir as mkdir2 } from "node:fs/promises";
|
|
82686
|
-
function claudeHarness() {
|
|
82687
|
-
return { harnessId: "claude-code", provider: "anthropic" };
|
|
83055
|
+
function claudeHarness(profile) {
|
|
83056
|
+
return { harnessId: "claude-code", provider: "anthropic", ...profile ? { profile } : {} };
|
|
82688
83057
|
}
|
|
82689
83058
|
function ompHarness() {
|
|
82690
83059
|
return { harnessId: "omp" };
|
|
@@ -82706,13 +83075,17 @@ async function openServerState(dataDir, env, log) {
|
|
|
82706
83075
|
log(
|
|
82707
83076
|
`routing.db created; imported ${imported.runs.length} runs, ${imported.registry.length} registry entries and ${imported.calibration ? 1 : 0} calibration from the old files`
|
|
82708
83077
|
);
|
|
83078
|
+
const evidence = new SqliteRunRecordStore(database);
|
|
82709
83079
|
return {
|
|
82710
83080
|
database,
|
|
82711
83081
|
noKey,
|
|
82712
83082
|
stores: {
|
|
82713
|
-
evidence
|
|
83083
|
+
evidence,
|
|
83084
|
+
trialRuns: () => evidence.trialRuns(),
|
|
83085
|
+
allRuns: () => evidence.allRuns(),
|
|
82714
83086
|
registry: new SqliteRegistryStore(database),
|
|
82715
83087
|
calibration: new SqliteCalibrationStore(database),
|
|
83088
|
+
trialWindow: new SqliteTrialWindowStore(database),
|
|
82716
83089
|
// The same key fetches the daily catalog that prices callers' candidates and scores them.
|
|
82717
83090
|
catalog: bundled ? async () => bundled : () => loadCatalog({ cwd: dataDir, apiKey: env.OPENROUTER_API_KEY }),
|
|
82718
83091
|
aliases: () => loadAliases(dataDir)
|
|
@@ -82743,6 +83116,9 @@ function hostedFrom(env, log) {
|
|
|
82743
83116
|
);
|
|
82744
83117
|
return createHostedRoute({ url: url2.origin, key, sharePrompts, log });
|
|
82745
83118
|
}
|
|
83119
|
+
function claudeCodeProfileFrom(env) {
|
|
83120
|
+
return env.BIZZY_API_CLAUDE_CODE_PROFILE === "jev-grade" ? "jev-grade" : void 0;
|
|
83121
|
+
}
|
|
82746
83122
|
async function startLocalServer(env, log, { docsDir } = {}) {
|
|
82747
83123
|
const dataDir = env.BIZZY_API_DATA_DIR;
|
|
82748
83124
|
if (!dataDir) throw new Error("BIZZY_API_DATA_DIR is required");
|
|
@@ -82751,14 +83127,16 @@ async function startLocalServer(env, log, { docsDir } = {}) {
|
|
|
82751
83127
|
throw new Error(`invalid PORT: ${env.PORT}`);
|
|
82752
83128
|
const { database, noKey, stores } = await openServerState(dataDir, env, log);
|
|
82753
83129
|
const hosted = hostedFrom(env, log);
|
|
83130
|
+
const claudeCodeProfile = claudeCodeProfileFrom(env);
|
|
82754
83131
|
const app = createRoutingServer({
|
|
82755
83132
|
...stores,
|
|
82756
83133
|
...hosted ? { hosted } : {},
|
|
82757
83134
|
...docsDir ? { docsDir } : {},
|
|
82758
83135
|
notices: { ...routeNotices, absent: noKey ?? noJudge },
|
|
82759
|
-
harnesses: { "claude-code": claudeHarness(), omp: ompHarness() },
|
|
83136
|
+
harnesses: { "claude-code": claudeHarness(claudeCodeProfile), omp: ompHarness() },
|
|
82760
83137
|
codex: { ...codexRelay(env), log }
|
|
82761
83138
|
});
|
|
83139
|
+
if (claudeCodeProfile) log(`claude-code: ${claudeCodeProfile}`);
|
|
82762
83140
|
if (!hosted) log(noJudge);
|
|
82763
83141
|
if (noKey) log(noKey);
|
|
82764
83142
|
app.addHook("onClose", async () => database.close());
|
package/package.json
CHANGED