@blockrun/clawrouter 0.12.290 → 0.12.292
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/cli.js +2688 -1079
- package/dist/index.js +2686 -1077
- package/dist/router/index.js +237 -46
- package/package.json +3 -3
package/dist/router/index.js
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
import { createRequire as __blockrun_createRequire } from 'node:module'; const require = __blockrun_createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// node_modules/@blockrun/router-core/dist/index.js
|
|
4
|
+
var UNSEGMENTED_SCRIPT = /[-ۿ -ヿ㐀-䶿一-鿿가-豈--]/;
|
|
5
|
+
var WORD_CHAR = /[\p{L}\p{N}]/u;
|
|
6
|
+
var ASCII_PHRASE = /^[a-z0-9' -]+$/;
|
|
7
|
+
var SEGMENTED_WORD_CHAR = "\\p{Script=Latin}\\p{Script=Cyrillic}\\p{Script=Greek}\\p{N}";
|
|
8
|
+
var BOUNDARY_BEFORE = `(?<![${SEGMENTED_WORD_CHAR}])`;
|
|
9
|
+
var BOUNDARY_AFTER = `(?![${SEGMENTED_WORD_CHAR}])`;
|
|
10
|
+
var BOUNDED_LAST_WORD_LENGTH = 6;
|
|
11
|
+
var SHORT_SUFFIXES = "(?:s|ed|ing)?";
|
|
12
|
+
var SIBILANT_PLURAL = "es";
|
|
13
|
+
var MID_SUFFIXES = "(?:s|es|ed|d|ing|er|ers|ly|ment|ments|ation|ations|e|en|n|a|as|o|os|em|et|ung|ungen)?";
|
|
14
|
+
var DROPPED_E_SUFFIXES = "(?:ing|ed|es|er|ers|ation|ations)";
|
|
15
|
+
var DOUBLED_CONSONANT_SUFFIXES = "(?:ing|ed|er|ers)";
|
|
16
|
+
var matcherCache = /* @__PURE__ */ new Map();
|
|
17
|
+
function escapeRegExp(value) {
|
|
18
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
19
|
+
}
|
|
20
|
+
function keywordMatcher(keyword) {
|
|
21
|
+
const cached = matcherCache.get(keyword);
|
|
22
|
+
if (cached) return cached;
|
|
23
|
+
const kw = keyword.toLowerCase();
|
|
24
|
+
let matcher;
|
|
25
|
+
if (UNSEGMENTED_SCRIPT.test(kw) || kw.length === 0) {
|
|
26
|
+
matcher = { needle: kw, pattern: null };
|
|
27
|
+
} else {
|
|
28
|
+
const lead = WORD_CHAR.test(kw[0]) ? BOUNDARY_BEFORE : "";
|
|
29
|
+
const escaped = escapeRegExp(kw);
|
|
30
|
+
let body = escaped;
|
|
31
|
+
let trail = "";
|
|
32
|
+
let needle = kw;
|
|
33
|
+
const lastWord = kw.slice(kw.lastIndexOf(" ") + 1);
|
|
34
|
+
if (WORD_CHAR.test(kw[kw.length - 1]) && ASCII_PHRASE.test(kw) && lastWord.length <= BOUNDED_LAST_WORD_LENGTH) {
|
|
35
|
+
const forms = [];
|
|
36
|
+
if (/\d$/.test(kw)) {
|
|
37
|
+
forms.push(escaped);
|
|
38
|
+
} else if (lastWord.length <= 3) {
|
|
39
|
+
forms.push(`${escaped}${SHORT_SUFFIXES}`);
|
|
40
|
+
if (/(?:x|s|z|ch|sh)$/.test(kw)) forms.push(`${escaped}${SIBILANT_PLURAL}`);
|
|
41
|
+
} else {
|
|
42
|
+
forms.push(`${escaped}${MID_SUFFIXES}`);
|
|
43
|
+
if (kw.endsWith("e")) {
|
|
44
|
+
forms.push(`${escaped.slice(0, -1)}${DROPPED_E_SUFFIXES}`);
|
|
45
|
+
needle = kw.slice(0, -1);
|
|
46
|
+
} else if (kw.endsWith("y")) {
|
|
47
|
+
forms.push(`${escaped.slice(0, -1)}(?:ies|ied)`);
|
|
48
|
+
needle = kw.slice(0, -1);
|
|
49
|
+
} else if (/[aeiou][bdgmnprt]$/.test(kw)) {
|
|
50
|
+
forms.push(`${escaped}${kw[kw.length - 1]}${DOUBLED_CONSONANT_SUFFIXES}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
body = `(?:${forms.join("|")})`;
|
|
54
|
+
trail = BOUNDARY_AFTER;
|
|
55
|
+
}
|
|
56
|
+
matcher = { needle, pattern: new RegExp(`${lead}${body}${trail}`, "u") };
|
|
57
|
+
}
|
|
58
|
+
matcherCache.set(keyword, matcher);
|
|
59
|
+
return matcher;
|
|
60
|
+
}
|
|
61
|
+
function matchesKeyword(text, keyword) {
|
|
62
|
+
const { needle, pattern } = keywordMatcher(keyword);
|
|
63
|
+
if (!text.includes(needle)) return false;
|
|
64
|
+
return pattern === null ? true : pattern.test(text);
|
|
65
|
+
}
|
|
4
66
|
function scoreTokenCount(estimatedTokens, thresholds) {
|
|
5
67
|
if (estimatedTokens < thresholds.simple) {
|
|
6
68
|
return { name: "tokenCount", score: -1, signal: `short (${estimatedTokens} tokens)` };
|
|
@@ -11,7 +73,7 @@ function scoreTokenCount(estimatedTokens, thresholds) {
|
|
|
11
73
|
return { name: "tokenCount", score: 0, signal: null };
|
|
12
74
|
}
|
|
13
75
|
function scoreKeywordMatch(text, keywords, name, signalLabel, thresholds, scores) {
|
|
14
|
-
const matches = keywords.filter((kw) => text
|
|
76
|
+
const matches = keywords.filter((kw) => matchesKeyword(text, kw));
|
|
15
77
|
if (matches.length >= thresholds.high) {
|
|
16
78
|
return {
|
|
17
79
|
name,
|
|
@@ -47,7 +109,7 @@ function scoreAgenticTask(text, keywords) {
|
|
|
47
109
|
let matchCount = 0;
|
|
48
110
|
const signals = [];
|
|
49
111
|
for (const keyword of keywords) {
|
|
50
|
-
if (text
|
|
112
|
+
if (matchesKeyword(text, keyword)) {
|
|
51
113
|
matchCount++;
|
|
52
114
|
if (signals.length < 3) {
|
|
53
115
|
signals.push(keyword);
|
|
@@ -194,9 +256,7 @@ function classifyByRules(prompt, systemPrompt, estimatedTokens, config) {
|
|
|
194
256
|
const w = weights[d.name] ?? 0;
|
|
195
257
|
weightedScore += d.score * w;
|
|
196
258
|
}
|
|
197
|
-
const reasoningMatches = config.reasoningKeywords.filter(
|
|
198
|
-
(kw) => userText.includes(kw.toLowerCase())
|
|
199
|
-
);
|
|
259
|
+
const reasoningMatches = config.reasoningKeywords.filter((kw) => matchesKeyword(userText, kw));
|
|
200
260
|
if (reasoningMatches.length >= 2) {
|
|
201
261
|
const confidence2 = calibrateConfidence(
|
|
202
262
|
Math.max(weightedScore, 0.3),
|
|
@@ -261,7 +321,7 @@ function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPric
|
|
|
261
321
|
const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
|
|
262
322
|
const baselineOutput = maxOutputTokens / 1e6 * opusOutputPrice;
|
|
263
323
|
const baselineCost = baselineInput + baselineOutput;
|
|
264
|
-
const savings = routingProfile === "premium" ? 0 : baselineCost > 0 ? Math.max(0, (baselineCost - costEstimate) / baselineCost) : 0;
|
|
324
|
+
const savings = routingProfile === "premium" || pricing === void 0 ? 0 : baselineCost > 0 ? Math.max(0, (baselineCost - costEstimate) / baselineCost) : 0;
|
|
265
325
|
return {
|
|
266
326
|
model,
|
|
267
327
|
tier,
|
|
@@ -341,6 +401,21 @@ function filterCandidatesByCapacity(models, estimatedInputTokens, requestedOutpu
|
|
|
341
401
|
});
|
|
342
402
|
return filtered;
|
|
343
403
|
}
|
|
404
|
+
var CJK_CHARS = /[ -ヿ㐀-䶿一-鿿가-豈--]/g;
|
|
405
|
+
function estimateTokens(text) {
|
|
406
|
+
if (text.length === 0) return 0;
|
|
407
|
+
const cjk = text.match(CJK_CHARS)?.length ?? 0;
|
|
408
|
+
return cjk + Math.ceil((text.length - cjk) / 4);
|
|
409
|
+
}
|
|
410
|
+
function scanLimit(promptTruncationChars) {
|
|
411
|
+
return Math.max(1, Math.min(8e3, promptTruncationChars));
|
|
412
|
+
}
|
|
413
|
+
function sampleForScan(value, limit) {
|
|
414
|
+
if (value.length <= limit) return value;
|
|
415
|
+
const prefixLength = Math.ceil(limit / 2);
|
|
416
|
+
return `${value.slice(0, prefixLength)}
|
|
417
|
+
${value.slice(-(limit - prefixLength))}`;
|
|
418
|
+
}
|
|
344
419
|
function applyPromotions(tierConfigs, promotions, profile, now = /* @__PURE__ */ new Date()) {
|
|
345
420
|
if (!promotions || promotions.length === 0) return tierConfigs;
|
|
346
421
|
let result = tierConfigs;
|
|
@@ -383,16 +458,10 @@ var RulesStrategy = class {
|
|
|
383
458
|
route(prompt, systemPrompt, maxOutputTokens, options) {
|
|
384
459
|
const { config, modelPricing } = options;
|
|
385
460
|
const fullText = `${systemPrompt ?? ""} ${prompt}`;
|
|
386
|
-
const estimatedTokens =
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
const prefixLength = Math.ceil(scanLimit / 2);
|
|
391
|
-
return `${value.slice(0, prefixLength)}
|
|
392
|
-
${value.slice(-(scanLimit - prefixLength))}`;
|
|
393
|
-
};
|
|
394
|
-
const scannedPrompt = sample(prompt);
|
|
395
|
-
const scannedSystemPrompt = systemPrompt ? sample(systemPrompt) : void 0;
|
|
461
|
+
const estimatedTokens = estimateTokens(fullText);
|
|
462
|
+
const limit = scanLimit(config.classifier.promptTruncationChars);
|
|
463
|
+
const scannedPrompt = sampleForScan(prompt, limit);
|
|
464
|
+
const scannedSystemPrompt = systemPrompt ? sampleForScan(systemPrompt, limit) : void 0;
|
|
396
465
|
const ruleResult = classifyByRules(
|
|
397
466
|
scannedPrompt,
|
|
398
467
|
scannedSystemPrompt,
|
|
@@ -446,7 +515,7 @@ ${value.slice(-(scanLimit - prefixLength))}`;
|
|
|
446
515
|
);
|
|
447
516
|
return { ...decision2, tierConfigs, profile };
|
|
448
517
|
}
|
|
449
|
-
const hasStructuredOutput = options.requiresStructuredOutput === true
|
|
518
|
+
const hasStructuredOutput = options.requiresStructuredOutput === true;
|
|
450
519
|
let tier;
|
|
451
520
|
let confidence;
|
|
452
521
|
const method = "rules";
|
|
@@ -502,6 +571,12 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
502
571
|
supportsTools: true,
|
|
503
572
|
supportsVision: true
|
|
504
573
|
},
|
|
574
|
+
"anthropic/claude-fable-5.1": {
|
|
575
|
+
contextWindow: 1e6,
|
|
576
|
+
maxOutputTokens: 128e3,
|
|
577
|
+
supportsTools: true,
|
|
578
|
+
supportsVision: true
|
|
579
|
+
},
|
|
505
580
|
"anthropic/claude-haiku-4.5": {
|
|
506
581
|
// override: The public catalog's `categories` omit "vision" for this Anthropic model even though the gateway accepts image input for it (the prior hand-maintained snapshot had it, and Anthropic's model card lists it). Without this the vision filter would silently drop it — reported against the catalog; remove once the categories carry vision.
|
|
507
582
|
contextWindow: 2e5,
|
|
@@ -533,6 +608,12 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
533
608
|
supportsTools: true,
|
|
534
609
|
supportsVision: true
|
|
535
610
|
},
|
|
611
|
+
"anthropic/claude-opus-5.5": {
|
|
612
|
+
contextWindow: 1e6,
|
|
613
|
+
maxOutputTokens: 128e3,
|
|
614
|
+
supportsTools: true,
|
|
615
|
+
supportsVision: true
|
|
616
|
+
},
|
|
536
617
|
"anthropic/claude-sonnet-4.5": {
|
|
537
618
|
contextWindow: 2e5,
|
|
538
619
|
maxOutputTokens: 64e3,
|
|
@@ -552,6 +633,12 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
552
633
|
supportsTools: true,
|
|
553
634
|
supportsVision: true
|
|
554
635
|
},
|
|
636
|
+
"anthropic/claude-sonnet-5.5": {
|
|
637
|
+
contextWindow: 1e6,
|
|
638
|
+
maxOutputTokens: 128e3,
|
|
639
|
+
supportsTools: true,
|
|
640
|
+
supportsVision: true
|
|
641
|
+
},
|
|
555
642
|
"cohere/north-mini-code": {
|
|
556
643
|
// supportsTools: not probed — fails closed
|
|
557
644
|
contextWindow: 256e3,
|
|
@@ -571,6 +658,12 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
571
658
|
supportsTools: true,
|
|
572
659
|
supportsVision: false
|
|
573
660
|
},
|
|
661
|
+
"deepseek/deepseek-v4-flash-vision-exp": {
|
|
662
|
+
contextWindow: 1048576,
|
|
663
|
+
maxOutputTokens: 65536,
|
|
664
|
+
supportsTools: false,
|
|
665
|
+
supportsVision: true
|
|
666
|
+
},
|
|
574
667
|
"deepseek/deepseek-v4-pro": {
|
|
575
668
|
contextWindow: 1048576,
|
|
576
669
|
maxOutputTokens: 65536,
|
|
@@ -631,6 +724,12 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
631
724
|
supportsTools: true,
|
|
632
725
|
supportsVision: true
|
|
633
726
|
},
|
|
727
|
+
"google/gemini-3.8-flash": {
|
|
728
|
+
contextWindow: 1048576,
|
|
729
|
+
maxOutputTokens: 65536,
|
|
730
|
+
supportsTools: true,
|
|
731
|
+
supportsVision: true
|
|
732
|
+
},
|
|
634
733
|
"minimax/minimax-m2.7": {
|
|
635
734
|
contextWindow: 204800,
|
|
636
735
|
maxOutputTokens: 16384,
|
|
@@ -656,6 +755,13 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
656
755
|
supportsTools: false,
|
|
657
756
|
supportsVision: true
|
|
658
757
|
},
|
|
758
|
+
"nvidia/muse-glimmer-30b": {
|
|
759
|
+
// supportsTools: not probed — fails closed
|
|
760
|
+
contextWindow: 131072,
|
|
761
|
+
maxOutputTokens: 16384,
|
|
762
|
+
supportsTools: false,
|
|
763
|
+
supportsVision: false
|
|
764
|
+
},
|
|
659
765
|
"nvidia/nemotron-3-nano-omni-30b-a3b-reasoning": {
|
|
660
766
|
// override: The catalog tags this model "vision", but a correctly sized probe does not hold up (ClawRouter, 2026-08-31): a 64x64 solid-red PNG was named correctly 1 of 4 times on Base, and on Solana the image was silently dropped and a text model answered "white". An HTTP 200 with a confident wrong answer gives the caller nothing to branch on, so image turns must not be routed here. It is ecoTiers.SIMPLE.fallback[0] since nemotron-3-nano-30b was delisted (2026-09-08); remove once a probe of this size comes back right on both chains.
|
|
661
767
|
contextWindow: 256e3,
|
|
@@ -719,6 +825,12 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
719
825
|
supportsTools: true,
|
|
720
826
|
supportsVision: false
|
|
721
827
|
},
|
|
828
|
+
"openai/gpt-5.1": {
|
|
829
|
+
contextWindow: 4e5,
|
|
830
|
+
maxOutputTokens: 128e3,
|
|
831
|
+
supportsTools: true,
|
|
832
|
+
supportsVision: true
|
|
833
|
+
},
|
|
722
834
|
"openai/gpt-5.2": {
|
|
723
835
|
contextWindow: 4e5,
|
|
724
836
|
maxOutputTokens: 128e3,
|
|
@@ -813,6 +925,24 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
813
925
|
supportsTools: true,
|
|
814
926
|
supportsVision: true
|
|
815
927
|
},
|
|
928
|
+
"openai/gpt-6-astra": {
|
|
929
|
+
contextWindow: 105e4,
|
|
930
|
+
maxOutputTokens: 128e3,
|
|
931
|
+
supportsTools: true,
|
|
932
|
+
supportsVision: true
|
|
933
|
+
},
|
|
934
|
+
"openai/gpt-6-luna": {
|
|
935
|
+
contextWindow: 105e4,
|
|
936
|
+
maxOutputTokens: 128e3,
|
|
937
|
+
supportsTools: true,
|
|
938
|
+
supportsVision: true
|
|
939
|
+
},
|
|
940
|
+
"openai/gpt-6-sol": {
|
|
941
|
+
contextWindow: 105e4,
|
|
942
|
+
maxOutputTokens: 128e3,
|
|
943
|
+
supportsTools: true,
|
|
944
|
+
supportsVision: true
|
|
945
|
+
},
|
|
816
946
|
"openai/o1": {
|
|
817
947
|
contextWindow: 2e5,
|
|
818
948
|
maxOutputTokens: 1e5,
|
|
@@ -837,6 +967,13 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
837
967
|
supportsTools: true,
|
|
838
968
|
supportsVision: false
|
|
839
969
|
},
|
|
970
|
+
"poolside/laguna-s-2.1": {
|
|
971
|
+
// supportsTools: not probed — fails closed
|
|
972
|
+
contextWindow: 1048576,
|
|
973
|
+
maxOutputTokens: 131072,
|
|
974
|
+
supportsTools: false,
|
|
975
|
+
supportsVision: false
|
|
976
|
+
},
|
|
840
977
|
"poolside/laguna-xs-2.1": {
|
|
841
978
|
// supportsTools: not probed — fails closed
|
|
842
979
|
contextWindow: 131072,
|
|
@@ -862,10 +999,24 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
862
999
|
supportsTools: true,
|
|
863
1000
|
supportsVision: false
|
|
864
1001
|
},
|
|
865
|
-
"
|
|
866
|
-
contextWindow:
|
|
867
|
-
maxOutputTokens:
|
|
868
|
-
supportsTools:
|
|
1002
|
+
"qwen/qwen3.8-flash": {
|
|
1003
|
+
contextWindow: 1e6,
|
|
1004
|
+
maxOutputTokens: 131072,
|
|
1005
|
+
supportsTools: false,
|
|
1006
|
+
supportsVision: true
|
|
1007
|
+
},
|
|
1008
|
+
"qwen/qwen3.8-max": {
|
|
1009
|
+
// supportsTools: not probed — fails closed
|
|
1010
|
+
contextWindow: 1e6,
|
|
1011
|
+
maxOutputTokens: 131072,
|
|
1012
|
+
supportsTools: false,
|
|
1013
|
+
supportsVision: false
|
|
1014
|
+
},
|
|
1015
|
+
"tencent/hy4-preview": {
|
|
1016
|
+
// supportsTools: not probed — fails closed
|
|
1017
|
+
contextWindow: 1048576,
|
|
1018
|
+
maxOutputTokens: 64e3,
|
|
1019
|
+
supportsTools: false,
|
|
869
1020
|
supportsVision: false
|
|
870
1021
|
},
|
|
871
1022
|
"xai/grok-4.3": {
|
|
@@ -880,12 +1031,30 @@ var DEFAULT_MODEL_CAPABILITIES = Object.freeze({
|
|
|
880
1031
|
supportsTools: true,
|
|
881
1032
|
supportsVision: true
|
|
882
1033
|
},
|
|
1034
|
+
"xai/grok-4.6": {
|
|
1035
|
+
contextWindow: 5e5,
|
|
1036
|
+
maxOutputTokens: 16384,
|
|
1037
|
+
supportsTools: true,
|
|
1038
|
+
supportsVision: true
|
|
1039
|
+
},
|
|
1040
|
+
"xai/grok-4.7": {
|
|
1041
|
+
contextWindow: 5e5,
|
|
1042
|
+
maxOutputTokens: 16384,
|
|
1043
|
+
supportsTools: true,
|
|
1044
|
+
supportsVision: true
|
|
1045
|
+
},
|
|
883
1046
|
"xai/grok-build-0.1": {
|
|
884
1047
|
contextWindow: 256e3,
|
|
885
1048
|
maxOutputTokens: 16384,
|
|
886
1049
|
supportsTools: true,
|
|
887
1050
|
supportsVision: false
|
|
888
1051
|
},
|
|
1052
|
+
"xiaomi/mimo-v2.5": {
|
|
1053
|
+
contextWindow: 1048576,
|
|
1054
|
+
maxOutputTokens: 131072,
|
|
1055
|
+
supportsTools: true,
|
|
1056
|
+
supportsVision: true
|
|
1057
|
+
},
|
|
889
1058
|
"xiaomi/mimo-v2.5-pro": {
|
|
890
1059
|
contextWindow: 1048576,
|
|
891
1060
|
maxOutputTokens: 131072,
|
|
@@ -1599,16 +1768,10 @@ function likelyNeedsParallelToolCalls(prompt, needsTools, toolCount, toolNames)
|
|
|
1599
1768
|
}
|
|
1600
1769
|
function classifyTask(prompt, systemPrompt, options) {
|
|
1601
1770
|
const fullText = `${systemPrompt ?? ""} ${prompt}`;
|
|
1602
|
-
const estimatedInputTokens =
|
|
1603
|
-
const
|
|
1604
|
-
const
|
|
1605
|
-
|
|
1606
|
-
const prefixLength = Math.ceil(scanLimit / 2);
|
|
1607
|
-
return `${value.slice(0, prefixLength)}
|
|
1608
|
-
${value.slice(-(scanLimit - prefixLength))}`;
|
|
1609
|
-
};
|
|
1610
|
-
const scannedPrompt = sample(prompt);
|
|
1611
|
-
const scannedSystemPrompt = sample(systemPrompt ?? "");
|
|
1771
|
+
const estimatedInputTokens = estimateTokens(fullText);
|
|
1772
|
+
const limit = scanLimit(options.config.classifier.promptTruncationChars);
|
|
1773
|
+
const scannedPrompt = sampleForScan(prompt, limit);
|
|
1774
|
+
const scannedSystemPrompt = sampleForScan(systemPrompt ?? "", limit);
|
|
1612
1775
|
const scannedFullText = `${scannedSystemPrompt} ${scannedPrompt}`;
|
|
1613
1776
|
const text = scannedPrompt.toLowerCase();
|
|
1614
1777
|
const explicitCodeSignal = /```|\b(?:typescript|javascript|python|rust|java|sql|stack trace|traceback|exception)\b|\.(?:ts|tsx|js|py|go|rs)\b/i.test(
|
|
@@ -1620,7 +1783,9 @@ ${value.slice(-(scanLimit - prefixLength))}`;
|
|
|
1620
1783
|
const nativeCodeSignal = /\b(?:programmed|written|implemented?|code)\s+(?:in|using)\s+(?:c\+\+|c|rust|go)\b/i.test(
|
|
1621
1784
|
scannedPrompt
|
|
1622
1785
|
);
|
|
1623
|
-
const
|
|
1786
|
+
const errorClassSignal = /\b[A-Z][A-Za-z]*(?:Error|Exception)\b/.test(scannedPrompt);
|
|
1787
|
+
const hasCode = explicitCodeSignal || codeConstructSignal || nativeCodeSignal || errorClassSignal;
|
|
1788
|
+
const codeArtifact = /```|\b(?:stack trace|traceback)\b|\.(?:ts|tsx|js|py|go|rs)\b/i.test(scannedPrompt) || codeConstructSignal || nativeCodeSignal || errorClassSignal;
|
|
1624
1789
|
const toolsAvailable = options.hasTools ?? false;
|
|
1625
1790
|
const needsTools = options.requiresTools ?? (toolsAvailable && inferToolRequirement(scannedPrompt, scannedSystemPrompt));
|
|
1626
1791
|
const likelyParallelToolCalls = likelyNeedsParallelToolCalls(
|
|
@@ -1692,10 +1857,10 @@ ${value.slice(-(scanLimit - prefixLength))}`;
|
|
|
1692
1857
|
const needsVision = options.hasVision ?? false;
|
|
1693
1858
|
const needsStructuredOutput = options.requiresStructuredOutput ?? false;
|
|
1694
1859
|
const latencySensitive = /\b(?:urgent|asap|fast|quick|low latency|real[- ]time)\b|尽快|马上|快速|低延迟/i.test(
|
|
1695
|
-
|
|
1860
|
+
scannedPrompt
|
|
1696
1861
|
);
|
|
1697
1862
|
const highStakes = /\b(?:production|security|payment|legal|medical|financial|audit)\b|生产|安全|支付|法律|医疗|财务|审计/i.test(
|
|
1698
|
-
|
|
1863
|
+
scannedPrompt
|
|
1699
1864
|
);
|
|
1700
1865
|
const terminalToolSignal = normalizedToolNames.some(
|
|
1701
1866
|
(name) => /^(?:terminalexec|terminalinspect|terminalsendkeys)$/.test(name)
|
|
@@ -1731,7 +1896,7 @@ ${value.slice(-(scanLimit - prefixLength))}`;
|
|
|
1731
1896
|
);
|
|
1732
1897
|
const terminalSafetySensitive = terminalToolSignal && (highStakes || terminalCredentialSignal);
|
|
1733
1898
|
const implicitTerminalCode = needsTools && terminalToolSignal && agentRisk === "standard" && !highStakes && !complexTerminalOperation && numberedSteps < 3 && prompt.length <= 1e3 && simpleTerminalArtifact;
|
|
1734
|
-
const language = /[\u3400-\u9fff]/.test(
|
|
1899
|
+
const language = /[\u3400-\u9fff]/.test(scannedPrompt) ? "zh" : "other";
|
|
1735
1900
|
const multipleChoiceSignals = (scannedPrompt.match(/(?:^|\n)\s*[A-D][.)]\s+/gim) ?? []).length;
|
|
1736
1901
|
const numericSignals = (scannedPrompt.match(/-?\d+(?:[.,]\d+)?/g) ?? []).length;
|
|
1737
1902
|
const compactMathProblem = !hasCode && prompt.length < 2500 && numericSignals >= 2 && (/[+×÷=%$€£¥]|\b(?:total|each|per|times|half|twice|percent|how many|how much|calculate)\b/i.test(
|
|
@@ -1746,7 +1911,7 @@ ${value.slice(-(scanLimit - prefixLength))}`;
|
|
|
1746
1911
|
else if (needsTools) taskType = "tool_agent";
|
|
1747
1912
|
else if (multipleChoiceSignals >= 3) taskType = "reasoning_mcq";
|
|
1748
1913
|
else if (compactMathProblem) taskType = "reasoning_math";
|
|
1749
|
-
else if (/\b(?:bug|debug|error|failure|failing|regression|crash|修复|报错|错误|调试)\b/i.test(text))
|
|
1914
|
+
else if (errorClassSignal || /\b(?:bug|debug|error|failure|failing|regression|crash|修复|报错|错误|调试)\b/i.test(text))
|
|
1750
1915
|
taskType = "debug";
|
|
1751
1916
|
else if (hasCode || /\b(?:refactor|implement|patch|edit|rewrite|重构|实现|修改)\b/i.test(text))
|
|
1752
1917
|
taskType = "code_edit";
|
|
@@ -1772,7 +1937,8 @@ ${value.slice(-(scanLimit - prefixLength))}`;
|
|
|
1772
1937
|
agentRisk,
|
|
1773
1938
|
terminalToolSignal,
|
|
1774
1939
|
terminalSafetySensitive,
|
|
1775
|
-
implicitTerminalCode
|
|
1940
|
+
implicitTerminalCode,
|
|
1941
|
+
codeArtifact
|
|
1776
1942
|
};
|
|
1777
1943
|
}
|
|
1778
1944
|
function affinity(modelId, task, language = "other", agentDomain = "other", deepWebResearch = false, agentRisk = "standard", terminalToolSignal = false, terminalSafetySensitive = false) {
|
|
@@ -2128,6 +2294,19 @@ function evidenceCandidates(task) {
|
|
|
2128
2294
|
}
|
|
2129
2295
|
return [];
|
|
2130
2296
|
}
|
|
2297
|
+
var VERIFIED_TOOL_FALLBACKS = [
|
|
2298
|
+
"anthropic/claude-fable-5.1",
|
|
2299
|
+
"anthropic/claude-opus-5.5",
|
|
2300
|
+
"anthropic/claude-sonnet-5.5",
|
|
2301
|
+
"google/gemini-3.8-flash",
|
|
2302
|
+
"openai/gpt-5.1",
|
|
2303
|
+
"openai/gpt-6-astra",
|
|
2304
|
+
"openai/gpt-6-luna",
|
|
2305
|
+
"openai/gpt-6-sol",
|
|
2306
|
+
"xai/grok-4.6",
|
|
2307
|
+
"xai/grok-4.7",
|
|
2308
|
+
"xiaomi/mimo-v2.5"
|
|
2309
|
+
];
|
|
2131
2310
|
function isEligible(modelId, features, maxOutputTokens, options) {
|
|
2132
2311
|
const model = options.modelCapabilities?.[modelId] ?? DEFAULT_MODEL_CAPABILITIES[modelId];
|
|
2133
2312
|
if (!model) return true;
|
|
@@ -2162,27 +2341,38 @@ function profileScore(modelId, options, now) {
|
|
|
2162
2341
|
}
|
|
2163
2342
|
var PortfolioStrategy = class {
|
|
2164
2343
|
name = "portfolio";
|
|
2344
|
+
// Rules set the capability tier; the strategy is stateless, so one instance serves every request.
|
|
2345
|
+
rules = new RulesStrategy();
|
|
2165
2346
|
route(prompt, systemPrompt, maxOutputTokens, options) {
|
|
2166
2347
|
const features = classifyTask(prompt, systemPrompt, options);
|
|
2167
|
-
const base =
|
|
2348
|
+
const base = this.rules.route(prompt, systemPrompt, maxOutputTokens, {
|
|
2168
2349
|
...options,
|
|
2169
2350
|
requiresTools: features.needsTools
|
|
2170
2351
|
});
|
|
2171
2352
|
const tierConfigs = base.tierConfigs;
|
|
2172
2353
|
if (!tierConfigs) return base;
|
|
2173
|
-
const targetTier = (features.taskType === "reasoning_mcq" || features.taskType === "reasoning_math") && (base.tier === "SIMPLE" || base.tier === "MEDIUM") ? "REASONING" : base.tier;
|
|
2354
|
+
const targetTier = (features.taskType === "reasoning_mcq" || features.taskType === "reasoning_math") && (base.tier === "SIMPLE" || base.tier === "MEDIUM") ? "REASONING" : (features.taskType === "debug" || features.taskType === "code_edit") && features.codeArtifact && base.tier === "SIMPLE" ? "MEDIUM" : base.tier;
|
|
2174
2355
|
const tierConfig = tierConfigs[targetTier];
|
|
2175
2356
|
const configuredCandidates = tierConfig ? getFallbackChain(targetTier, tierConfigs) : [];
|
|
2176
2357
|
const unavailable = new Set(options.unavailableModels ?? []);
|
|
2358
|
+
const verifiedToolFallbacks = features.needsTools ? VERIFIED_TOOL_FALLBACKS.filter((model2) => options.modelPricing.has(model2)) : [];
|
|
2359
|
+
if (options.routingProfile !== "premium") {
|
|
2360
|
+
const fallbackCost = (model2) => estimatedCost(model2, options, features.estimatedInputTokens, maxOutputTokens);
|
|
2361
|
+
verifiedToolFallbacks.sort((a, b) => fallbackCost(a) - fallbackCost(b));
|
|
2362
|
+
}
|
|
2177
2363
|
const chain = [
|
|
2178
|
-
.../* @__PURE__ */ new Set([
|
|
2364
|
+
.../* @__PURE__ */ new Set([
|
|
2365
|
+
...configuredCandidates,
|
|
2366
|
+
...evidenceCandidates(features.taskType),
|
|
2367
|
+
...verifiedToolFallbacks
|
|
2368
|
+
])
|
|
2179
2369
|
].filter(
|
|
2180
2370
|
(model2) => typeof model2 === "string" && model2.length > 0 && !unavailable.has(model2)
|
|
2181
2371
|
);
|
|
2182
|
-
const eligible =
|
|
2183
|
-
(model2) => isEligible(model2, features, maxOutputTokens, options)
|
|
2372
|
+
const eligible = new Set(
|
|
2373
|
+
chain.filter((model2) => isEligible(model2, features, maxOutputTokens, options))
|
|
2184
2374
|
);
|
|
2185
|
-
const eligibleCandidates = eligible.
|
|
2375
|
+
const eligibleCandidates = eligible.size > 0 ? [...eligible] : chain;
|
|
2186
2376
|
if (eligibleCandidates.length === 0) return base;
|
|
2187
2377
|
const profileName = options.routingProfile === "eco" ? "eco" : options.routingProfile === "premium" ? "premium" : "auto";
|
|
2188
2378
|
const portfolio = options.config.portfolio ?? DEFAULT_PORTFOLIO_WEIGHTS;
|
|
@@ -2217,11 +2407,11 @@ var PortfolioStrategy = class {
|
|
|
2217
2407
|
const rankedEntries = candidates.map((model2, index) => {
|
|
2218
2408
|
const cost = estimatedCost(model2, options, features.estimatedInputTokens, maxOutputTokens);
|
|
2219
2409
|
const costScore = Number.isFinite(cost) && maxCost > minCost ? 1 - (cost - minCost) / (maxCost - minCost) : 0.5;
|
|
2220
|
-
const capabilityScore =
|
|
2410
|
+
const capabilityScore = eligible.has(model2) ? 1 : 0;
|
|
2221
2411
|
const profile = profileScore(model2, options, now);
|
|
2222
2412
|
const observedQuality = profile?.quality === void 0 ? getAffinity(model2) : getAffinity(model2) * (1 - profile.freshness) + profile.quality * profile.freshness;
|
|
2223
|
-
const observedSpeed = profile ? profile.speed * profile.freshness : 0.5;
|
|
2224
|
-
const observedTailSpeed = profile ? profile.tailSpeed * profile.freshness : 0.5;
|
|
2413
|
+
const observedSpeed = profile ? profile.speed * profile.freshness + 0.5 * (1 - profile.freshness) : 0.5;
|
|
2414
|
+
const observedTailSpeed = profile ? profile.tailSpeed * profile.freshness + 0.5 * (1 - profile.freshness) : 0.5;
|
|
2225
2415
|
const observedReliability = profile ? profile.reliability * profile.freshness + (1 - profile.freshness) : 1;
|
|
2226
2416
|
const legacyScore = 1 - index / Math.max(1, candidates.length - 1);
|
|
2227
2417
|
const qualityWeight = profileWeights.quality + (features.highStakes ? portfolio.highStakesBoost.quality : 0);
|
|
@@ -3792,6 +3982,7 @@ export {
|
|
|
3792
3982
|
applyUnavailableModels,
|
|
3793
3983
|
calculateModelCost,
|
|
3794
3984
|
classifyByRules,
|
|
3985
|
+
estimateTokens,
|
|
3795
3986
|
filterByExcludeList,
|
|
3796
3987
|
filterByToolCalling,
|
|
3797
3988
|
filterByVision,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockrun/clawrouter",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.292",
|
|
4
4
|
"description": "Smart LLM router — save 84% on inference costs. 88 models (7 free). Pay by credit card (API key) or USDC (x402 wallet).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"bs58": "^6.0.0",
|
|
105
105
|
"https-proxy-agent": "^9.1.0",
|
|
106
106
|
"undici": "^8.11.2",
|
|
107
|
-
"viem": "~2.
|
|
107
|
+
"viem": "~2.57.5"
|
|
108
108
|
},
|
|
109
109
|
"peerDependencies": {
|
|
110
110
|
"openclaw": ">=2025.1.0"
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
},
|
|
117
117
|
"devDependencies": {
|
|
118
118
|
"@blockrun/model-catalog": "https://codeload.github.com/BlockRunAI/model-catalog/tar.gz/465c45941fb8ea9d6858fe8402abc8ba8934be90",
|
|
119
|
-
"@blockrun/router-core": "https://codeload.github.com/BlockRunAI/router-core/tar.gz/
|
|
119
|
+
"@blockrun/router-core": "https://codeload.github.com/BlockRunAI/router-core/tar.gz/65a92c85ea1f187a64e7611302ef6add236b0cba",
|
|
120
120
|
"@eslint/js": "^10.0.1",
|
|
121
121
|
"eslint": "^10.2.0",
|
|
122
122
|
"openclaw": "^2026.7.2-beta.7",
|