@blockrun/clawrouter 0.9.27 → 0.9.28
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 +96 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +96 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -667,16 +667,16 @@ declare const blockrunProvider: ProviderPlugin;
|
|
|
667
667
|
|
|
668
668
|
/**
|
|
669
669
|
* Model aliases for convenient shorthand access.
|
|
670
|
-
* Users can type `/model claude` instead of `/model blockrun/anthropic/claude-sonnet-4
|
|
670
|
+
* Users can type `/model claude` instead of `/model blockrun/anthropic/claude-sonnet-4-6`.
|
|
671
671
|
*/
|
|
672
672
|
declare const MODEL_ALIASES: Record<string, string>;
|
|
673
673
|
/**
|
|
674
674
|
* Resolve a model alias to its full model ID.
|
|
675
675
|
* Also strips "blockrun/" prefix for direct model paths.
|
|
676
676
|
* Examples:
|
|
677
|
-
* - "claude" -> "anthropic/claude-sonnet-4
|
|
678
|
-
* - "blockrun/claude" -> "anthropic/claude-sonnet-4
|
|
679
|
-
* - "blockrun/anthropic/claude-sonnet-4
|
|
677
|
+
* - "claude" -> "anthropic/claude-sonnet-4-6" (alias)
|
|
678
|
+
* - "blockrun/claude" -> "anthropic/claude-sonnet-4-6" (alias with prefix)
|
|
679
|
+
* - "blockrun/anthropic/claude-sonnet-4-6" -> "anthropic/claude-sonnet-4-6" (prefix stripped)
|
|
680
680
|
* - "openai/gpt-4o" -> "openai/gpt-4o" (unchanged)
|
|
681
681
|
*/
|
|
682
682
|
declare function resolveModelAlias(model: string): string;
|
package/dist/index.js
CHANGED
|
@@ -1004,6 +1004,7 @@ function calibrateConfidence(distance, steepness) {
|
|
|
1004
1004
|
}
|
|
1005
1005
|
|
|
1006
1006
|
// src/router/selector.ts
|
|
1007
|
+
var BASELINE_MODEL_ID = "anthropic/claude-opus-4-5";
|
|
1007
1008
|
function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPricing, estimatedInputTokens, maxOutputTokens, routingProfile) {
|
|
1008
1009
|
const tierConfig = tierConfigs[tier];
|
|
1009
1010
|
const model = tierConfig.primary;
|
|
@@ -1013,7 +1014,7 @@ function selectModel(tier, confidence, method, reasoning, tierConfigs, modelPric
|
|
|
1013
1014
|
const inputCost = estimatedInputTokens / 1e6 * inputPrice;
|
|
1014
1015
|
const outputCost = maxOutputTokens / 1e6 * outputPrice;
|
|
1015
1016
|
const costEstimate = inputCost + outputCost;
|
|
1016
|
-
const opusPricing = modelPricing.get(
|
|
1017
|
+
const opusPricing = modelPricing.get(BASELINE_MODEL_ID);
|
|
1017
1018
|
const opusInputPrice = opusPricing?.inputPrice ?? 0;
|
|
1018
1019
|
const opusOutputPrice = opusPricing?.outputPrice ?? 0;
|
|
1019
1020
|
const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
|
|
@@ -1042,7 +1043,7 @@ function calculateModelCost(model, modelPricing, estimatedInputTokens, maxOutput
|
|
|
1042
1043
|
const inputCost = estimatedInputTokens / 1e6 * inputPrice;
|
|
1043
1044
|
const outputCost = maxOutputTokens / 1e6 * outputPrice;
|
|
1044
1045
|
const costEstimate = inputCost + outputCost;
|
|
1045
|
-
const opusPricing = modelPricing.get(
|
|
1046
|
+
const opusPricing = modelPricing.get(BASELINE_MODEL_ID);
|
|
1046
1047
|
const opusInputPrice = opusPricing?.inputPrice ?? 0;
|
|
1047
1048
|
const opusOutputPrice = opusPricing?.outputPrice ?? 0;
|
|
1048
1049
|
const baselineInput = estimatedInputTokens / 1e6 * opusInputPrice;
|
|
@@ -3929,6 +3930,83 @@ var PROVIDER_ERROR_PATTERNS = [
|
|
|
3929
3930
|
/request.*size.*exceeds/i,
|
|
3930
3931
|
/payload too large/i
|
|
3931
3932
|
];
|
|
3933
|
+
var DEGRADED_RESPONSE_PATTERNS = [
|
|
3934
|
+
/the ai service is temporarily overloaded/i,
|
|
3935
|
+
/service is temporarily overloaded/i,
|
|
3936
|
+
/please try again in a moment/i
|
|
3937
|
+
];
|
|
3938
|
+
var DEGRADED_LOOP_PATTERNS = [
|
|
3939
|
+
/the boxed is the response\./i,
|
|
3940
|
+
/the response is the text\./i,
|
|
3941
|
+
/the final answer is the boxed\./i
|
|
3942
|
+
];
|
|
3943
|
+
function extractAssistantContent(payload) {
|
|
3944
|
+
if (!payload || typeof payload !== "object") return void 0;
|
|
3945
|
+
const record = payload;
|
|
3946
|
+
const choices = record.choices;
|
|
3947
|
+
if (!Array.isArray(choices) || choices.length === 0) return void 0;
|
|
3948
|
+
const firstChoice = choices[0];
|
|
3949
|
+
if (!firstChoice || typeof firstChoice !== "object") return void 0;
|
|
3950
|
+
const choice = firstChoice;
|
|
3951
|
+
const message = choice.message;
|
|
3952
|
+
if (!message || typeof message !== "object") return void 0;
|
|
3953
|
+
const content = message.content;
|
|
3954
|
+
return typeof content === "string" ? content : void 0;
|
|
3955
|
+
}
|
|
3956
|
+
function hasKnownLoopSignature(text) {
|
|
3957
|
+
const matchCount = DEGRADED_LOOP_PATTERNS.reduce(
|
|
3958
|
+
(count, pattern) => pattern.test(text) ? count + 1 : count,
|
|
3959
|
+
0
|
|
3960
|
+
);
|
|
3961
|
+
if (matchCount >= 2) return true;
|
|
3962
|
+
const lines = text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
3963
|
+
if (lines.length < 8) return false;
|
|
3964
|
+
const counts = /* @__PURE__ */ new Map();
|
|
3965
|
+
for (const line of lines) {
|
|
3966
|
+
counts.set(line, (counts.get(line) ?? 0) + 1);
|
|
3967
|
+
}
|
|
3968
|
+
const maxRepeat = Math.max(...counts.values());
|
|
3969
|
+
const uniqueRatio = counts.size / lines.length;
|
|
3970
|
+
return maxRepeat >= 3 && uniqueRatio <= 0.45;
|
|
3971
|
+
}
|
|
3972
|
+
function detectDegradedSuccessResponse(body) {
|
|
3973
|
+
const trimmed = body.trim();
|
|
3974
|
+
if (!trimmed) return void 0;
|
|
3975
|
+
if (DEGRADED_RESPONSE_PATTERNS.some((pattern) => pattern.test(trimmed))) {
|
|
3976
|
+
return "degraded response: overloaded placeholder";
|
|
3977
|
+
}
|
|
3978
|
+
if (hasKnownLoopSignature(trimmed)) {
|
|
3979
|
+
return "degraded response: repetitive loop output";
|
|
3980
|
+
}
|
|
3981
|
+
try {
|
|
3982
|
+
const parsed = JSON.parse(trimmed);
|
|
3983
|
+
const errorField = parsed.error;
|
|
3984
|
+
let errorText = "";
|
|
3985
|
+
if (typeof errorField === "string") {
|
|
3986
|
+
errorText = errorField;
|
|
3987
|
+
} else if (errorField && typeof errorField === "object") {
|
|
3988
|
+
const errObj = errorField;
|
|
3989
|
+
errorText = [
|
|
3990
|
+
typeof errObj.message === "string" ? errObj.message : "",
|
|
3991
|
+
typeof errObj.type === "string" ? errObj.type : "",
|
|
3992
|
+
typeof errObj.code === "string" ? errObj.code : ""
|
|
3993
|
+
].filter(Boolean).join(" ");
|
|
3994
|
+
}
|
|
3995
|
+
if (errorText && PROVIDER_ERROR_PATTERNS.some((pattern) => pattern.test(errorText))) {
|
|
3996
|
+
return `degraded response: ${errorText.slice(0, 120)}`;
|
|
3997
|
+
}
|
|
3998
|
+
const assistantContent = extractAssistantContent(parsed);
|
|
3999
|
+
if (!assistantContent) return void 0;
|
|
4000
|
+
if (DEGRADED_RESPONSE_PATTERNS.some((pattern) => pattern.test(assistantContent))) {
|
|
4001
|
+
return "degraded response: overloaded assistant content";
|
|
4002
|
+
}
|
|
4003
|
+
if (hasKnownLoopSignature(assistantContent)) {
|
|
4004
|
+
return "degraded response: repetitive assistant loop";
|
|
4005
|
+
}
|
|
4006
|
+
} catch {
|
|
4007
|
+
}
|
|
4008
|
+
return void 0;
|
|
4009
|
+
}
|
|
3932
4010
|
var FALLBACK_STATUS_CODES = [
|
|
3933
4011
|
400,
|
|
3934
4012
|
// Bad request - sometimes used for billing errors
|
|
@@ -4468,6 +4546,22 @@ async function tryModelRequest(upstreamUrl, method, headers, body, modelId, maxT
|
|
|
4468
4546
|
isProviderError: isProviderErr
|
|
4469
4547
|
};
|
|
4470
4548
|
}
|
|
4549
|
+
const contentType = response.headers.get("content-type") || "";
|
|
4550
|
+
if (contentType.includes("json") || contentType.includes("text")) {
|
|
4551
|
+
try {
|
|
4552
|
+
const responseBody = await response.clone().text();
|
|
4553
|
+
const degradedReason = detectDegradedSuccessResponse(responseBody);
|
|
4554
|
+
if (degradedReason) {
|
|
4555
|
+
return {
|
|
4556
|
+
success: false,
|
|
4557
|
+
errorBody: degradedReason,
|
|
4558
|
+
errorStatus: 503,
|
|
4559
|
+
isProviderError: true
|
|
4560
|
+
};
|
|
4561
|
+
}
|
|
4562
|
+
} catch {
|
|
4563
|
+
}
|
|
4564
|
+
}
|
|
4471
4565
|
return { success: true, response };
|
|
4472
4566
|
} catch (err) {
|
|
4473
4567
|
const errorMsg = err instanceof Error ? err.message : String(err);
|