mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +03:00
Validado numa worktree combinada com as 16 PRs desta leva sobre `release/v3.8.51`: typecheck:core limpo, check-file-size e check-changelog-integrity OK, complexity 2788/3218 e cognitive 1261/1437, ESLint 0 erros nos 152 arquivos alterados, 771 testes unitários focados, 49 de integração e a suíte vitest:ui completa (2149) verdes. Guardar os contratos com testes ANTES de levantar o bloco (`05059880` no irmão, e o `287658f5` marcando os `executeTargetGates` como lift-as-is) é o que torna um refactor deste tamanho auditável. Sem essa ordem, um extract de 3 mil linhas é indistinguível de uma reescrita. Revalidei depois do merge da base: `combo-attempt-loop`, `execute-target-attempt`, `execute-target-gates` e `combo-loop-safety-timer-leak-11804` — 20/20 — mais typecheck:core limpo e o cap de arquivo OK. O #12811 entra na sequência logo em seguida, com os três commits do round-robin sobre este.
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
/**
|
|
* Pure classify helpers for executeTarget's retry loop.
|
|
* Lift-as-is from combo.ts #8375 / #2101 / #4279. No I/O.
|
|
*
|
|
* @internal — not part of the public combo.ts barrel.
|
|
*/
|
|
import {
|
|
isContextOverflow400,
|
|
isInputBoundRequestFailure,
|
|
isModelScoped400,
|
|
isParamValidation400,
|
|
} from "./comboPredicates.ts";
|
|
|
|
export function remainderIsHomogeneous(
|
|
orderedTargets: { modelStr: string }[],
|
|
index: number,
|
|
modelStr: string
|
|
): boolean {
|
|
return orderedTargets.slice(index + 1).every((nextInPool) => nextInPool.modelStr === modelStr);
|
|
}
|
|
|
|
export function shouldAbortOnInputBoundFailure(opts: {
|
|
structuredError: unknown;
|
|
remainderIsHomogeneous: boolean;
|
|
}): boolean {
|
|
const structured = opts.structuredError as
|
|
{ code?: string | null; type?: string | null } | undefined;
|
|
return isInputBoundRequestFailure(structured) && opts.remainderIsHomogeneous;
|
|
}
|
|
|
|
/**
|
|
* #2101 / #4279: body-specific 400 must surface via {ok,response}, not null.
|
|
* Same predicate chain as combo.ts (overflow / param / model-scoped excluded).
|
|
*/
|
|
export function shouldSurfaceBodySpecific400(opts: {
|
|
status: number;
|
|
errorText: string;
|
|
shouldFallback: boolean;
|
|
}): boolean {
|
|
const errorText = opts.errorText;
|
|
return (
|
|
opts.status === 400 &&
|
|
opts.shouldFallback &&
|
|
!isContextOverflow400(errorText) &&
|
|
!isParamValidation400(errorText) &&
|
|
!isModelScoped400(errorText) &&
|
|
(errorText.toLowerCase().includes("context") ||
|
|
errorText.toLowerCase().includes("prompt") ||
|
|
errorText.toLowerCase().includes("token") ||
|
|
errorText.toLowerCase().includes("malformed") ||
|
|
errorText.toLowerCase().includes("invalid") ||
|
|
errorText.toLowerCase().includes("bad request"))
|
|
);
|
|
}
|