mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-02 13:22:11 +03:00
* feat(qoder): native cosy integration * feat(qoder): implement native COSY encryption algorithm and remove CLI child instances, plus workflow bumps * feat(resilience): context overflow fallback, OAuth token detection, empty content guard & context-optimized combo strategy - Add isContextOverflowError + isContextOverflow detectors (400 + token-limit signals) - Auto-fallback to next family model on context overflow in chatCore - Add isEmptyContentResponse to catch fake-success empty responses, trigger fallback + recursive retry - Add OAUTH_INVALID_TOKEN error type (T11) with isOAuthInvalidToken signal matching; warn instead of deactivating node - Add getModelContextLimit helper in modelsDevSync (reads limit_context from synced capabilities) - Upgrade getTokenLimit in contextManager to check models.dev DB before registry (fixes gemini-2.5-pro: 1000000→1048576) - Add findLargerContextModel in modelFamilyFallback for context-aware model selection - Add sortModelsByContextSize + context-optimized combo strategy in combo.ts - Update context-manager unit test for corrected gemini-2.5-pro limit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(review): address Gemini code review — tool_calls path, infinite recursion, dedup signals, findLargerContextModel - Fix isEmptyContentResponse: check message.tool_calls/delta.tool_calls instead of firstChoice.tool_calls (wrong OpenAI API path, caused tool-call responses to be falsely flagged as empty) - Fix empty content fallback: replace recursive handleChatCore call (infinite recursion risk + wrong model due to original body.model) with non-recursive pattern — call executeProviderRequest, parse fallback response body, reassign responseBody and fall through to existing processing - Fix context overflow: use findLargerContextModel over family candidates first, fall back to getNextFamilyFallback — ensures we pick a model with actually larger context window on overflow - Fix signal dedup: export CONTEXT_OVERFLOW_SIGNALS + CONTEXT_OVERFLOW_REGEX from errorClassifier.ts; import shared regex in modelFamilyFallback.ts, removing duplicate signal list and per-call RegExp construction Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(UI): add context-optimized strategy to frontend schema and options * fix(sse): preserve Responses API events in stream translation When translating Claude-format responses (e.g. GLM) to Responses API format for Codex CLI, the sanitizer stripped {event, data} structured items to {"object":"chat.completion.chunk"}, losing all content and the critical response.completed event. Only run sanitizeStreamingChunk on OpenAI Chat Completions chunks, skipping items that have the Responses API {event, data} structure. * test(sse): add regression test for Claude→Responses stream sanitization Verifies that {event,data} structured items from the Responses API translator bypass sanitizeStreamingChunk when translating Claude-format providers (e.g. GLM) to Responses API format for Codex CLI. * fix(sse): strengthen Responses API event detection with response. prefix check Use explicit `response.` prefix check instead of generic `event && data` presence check, as recommended in PR review. * fix: pin Next.js to 16.0.10 to prevent Turbopack hashed module bug Remove ^ prefix from next and eslint-config-next to prevent automatic upgrades to 16.1.x+ which introduced content-based hashing for external module references in Turbopack. Also remove duplicate Material Symbols @import from globals.css (font already loaded via <link> in layout.tsx). Fixes #509 * align cc-compatible cache handling with client passthrough * chore: integrate resilience and turbopack fixes (PRs #992, #990, #987) * chore(release): bump to v3.5.2 — changelog, docs, version sync * docs(i18n): sync documentation updates to 33 languages * fix(qoder): replace any with unknown to comply with strict any-budget --------- Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com> Co-authored-by: oyi77 <oyi77@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Chris Staley <christopher-s@users.noreply.github.com> Co-authored-by: Ivan <shanin-i2011@yandex.ru> Co-authored-by: R.D. <rogerproself@gmail.com>
133 lines
3.8 KiB
TypeScript
133 lines
3.8 KiB
TypeScript
import {
|
|
isAccountDeactivated,
|
|
isCreditsExhausted,
|
|
isOAuthInvalidToken,
|
|
} from "./accountFallback.ts";
|
|
|
|
export function isEmptyContentResponse(responseBody: unknown): boolean {
|
|
if (!responseBody || typeof responseBody !== "object") return false;
|
|
|
|
const body = responseBody as Record<string, unknown>;
|
|
|
|
if (Array.isArray(body.choices)) {
|
|
const firstChoice = body.choices[0] as Record<string, unknown> | undefined;
|
|
if (!firstChoice) return true;
|
|
|
|
const message = firstChoice.message as Record<string, unknown> | undefined;
|
|
const delta = firstChoice.delta as Record<string, unknown> | undefined;
|
|
|
|
const content = message?.content ?? delta?.content;
|
|
const hasToolCalls =
|
|
(Array.isArray(message?.tool_calls) && (message.tool_calls as unknown[]).length > 0) ||
|
|
(Array.isArray(delta?.tool_calls) && (delta.tool_calls as unknown[]).length > 0);
|
|
|
|
const hasContent = content !== null && content !== undefined && content !== "";
|
|
return !hasContent && !hasToolCalls;
|
|
}
|
|
|
|
if (Array.isArray(body.content)) {
|
|
return body.content.length === 0;
|
|
}
|
|
|
|
if (typeof body.text === "string") {
|
|
return body.text.trim() === "";
|
|
}
|
|
|
|
if ("content" in body) {
|
|
const content = body.content;
|
|
return content === null || content === undefined || content === "";
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
export const PROVIDER_ERROR_TYPES = {
|
|
RATE_LIMITED: "rate_limited",
|
|
UNAUTHORIZED: "unauthorized",
|
|
ACCOUNT_DEACTIVATED: "account_deactivated",
|
|
FORBIDDEN: "forbidden",
|
|
SERVER_ERROR: "server_error",
|
|
QUOTA_EXHAUSTED: "quota_exhausted",
|
|
PROJECT_ROUTE_ERROR: "project_route_error",
|
|
CONTEXT_OVERFLOW: "context_overflow",
|
|
OAUTH_INVALID_TOKEN: "oauth_invalid_token",
|
|
EMPTY_CONTENT: "empty_content",
|
|
};
|
|
|
|
export const CONTEXT_OVERFLOW_SIGNALS = [
|
|
"context overflow",
|
|
"prompt too large",
|
|
"context window",
|
|
"maximum context",
|
|
"exceeds context",
|
|
"input too long",
|
|
"token limit",
|
|
"too many tokens",
|
|
"context length",
|
|
"exceed.*context",
|
|
"messages exceed",
|
|
];
|
|
|
|
export const CONTEXT_OVERFLOW_REGEX = new RegExp(CONTEXT_OVERFLOW_SIGNALS.join("|"), "i");
|
|
|
|
export function isContextOverflow(errorText: string): boolean {
|
|
return CONTEXT_OVERFLOW_REGEX.test(String(errorText || ""));
|
|
}
|
|
|
|
function responseBodyToString(responseBody: unknown): string {
|
|
if (typeof responseBody === "string") return responseBody;
|
|
if (responseBody !== null && typeof responseBody === "object") {
|
|
try {
|
|
return JSON.stringify(responseBody);
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
export function classifyProviderError(statusCode: number, responseBody: unknown): string | null {
|
|
const bodyStr = responseBodyToString(responseBody);
|
|
const creditsExhausted = isCreditsExhausted(bodyStr);
|
|
const accountDeactivated = isAccountDeactivated(bodyStr);
|
|
const oauthInvalid = isOAuthInvalidToken(bodyStr);
|
|
|
|
if (
|
|
creditsExhausted &&
|
|
(statusCode === 400 || statusCode === 402 || statusCode === 429 || statusCode === 403)
|
|
) {
|
|
return PROVIDER_ERROR_TYPES.QUOTA_EXHAUSTED;
|
|
}
|
|
|
|
if (statusCode === 429) {
|
|
return PROVIDER_ERROR_TYPES.RATE_LIMITED;
|
|
}
|
|
|
|
if (statusCode === 401) {
|
|
if (oauthInvalid) {
|
|
return PROVIDER_ERROR_TYPES.OAUTH_INVALID_TOKEN;
|
|
}
|
|
return accountDeactivated
|
|
? PROVIDER_ERROR_TYPES.ACCOUNT_DEACTIVATED
|
|
: PROVIDER_ERROR_TYPES.UNAUTHORIZED;
|
|
}
|
|
|
|
if (statusCode === 402) return PROVIDER_ERROR_TYPES.QUOTA_EXHAUSTED;
|
|
if (statusCode === 403 && accountDeactivated) {
|
|
return PROVIDER_ERROR_TYPES.ACCOUNT_DEACTIVATED;
|
|
}
|
|
if (statusCode === 403) {
|
|
if (bodyStr.includes("has not been used in project")) {
|
|
return PROVIDER_ERROR_TYPES.PROJECT_ROUTE_ERROR;
|
|
}
|
|
return PROVIDER_ERROR_TYPES.FORBIDDEN;
|
|
}
|
|
if (statusCode >= 500) return PROVIDER_ERROR_TYPES.SERVER_ERROR;
|
|
|
|
if (statusCode === 400 && isContextOverflow(bodyStr)) {
|
|
return PROVIDER_ERROR_TYPES.CONTEXT_OVERFLOW;
|
|
}
|
|
|
|
return null;
|
|
}
|