mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 19:02:17 +03:00
* feat(routing): add reasoning-based model and effort routing * refactor(routing): modularize reasoning and auto-routing pipeline * fix(routing): remove redundant DB re-export and prevent SQL scan false positives * fix(routing): resolve reasoning routing review blockers * fix(i18n): keep release ranking fallbacks outside reasoning * fix(db): renumber reasoning-routing migration past release tip (124→125) 124_generic_session_affinity_ttl.sql (#7274) has since landed on release/v3.8.49 at version 124, colliding with this PR's own 124_reasoning_routing_rules.sql. Renumbers to 125 (the next free slot past the current release tip) and updates the one filename reference in docs/routing/REASONING_ROUTING.md. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * chore(db): renumber reasoning-routing migration 125→126 (slot taken by #7360) Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * refactor(api): compact temp-path decls in exportAll GET (complexity-ratchet lines budget) Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * refactor(api): single-statement auth guard in exportAll GET (function under 80-line cap) Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import type { ReasoningRoutingRuleInput } from "@/lib/db/reasoningRoutingRules";
|
|
|
|
type RuleScope = ReasoningRoutingRuleInput["scope"];
|
|
type TargetKind = ReasoningRoutingRuleInput["targetKind"];
|
|
|
|
function scopedString(
|
|
data: Record<string, unknown>,
|
|
scope: RuleScope,
|
|
expected: RuleScope,
|
|
key: string
|
|
) {
|
|
return scope === expected ? ((data[key] as string | null) ?? null) : null;
|
|
}
|
|
|
|
function scopedModelPattern(data: Record<string, unknown>, scope: RuleScope) {
|
|
return scope === "model" || scope === "apiKey"
|
|
? ((data.modelPattern as string | null) ?? null)
|
|
: null;
|
|
}
|
|
|
|
function targetValue(
|
|
data: Record<string, unknown>,
|
|
kind: TargetKind,
|
|
expected: TargetKind,
|
|
key: string
|
|
) {
|
|
return kind === expected ? ((data[key] as string | null) ?? null) : null;
|
|
}
|
|
|
|
export function reasoningRuleDataToInput(data: Record<string, unknown>): ReasoningRoutingRuleInput {
|
|
const scope = data.scope as RuleScope;
|
|
const targetKind = (scope === "connection" ? "keep" : data.targetKind) as TargetKind;
|
|
return {
|
|
name: String(data.name),
|
|
description: String(data.description ?? ""),
|
|
scope,
|
|
apiKeyId: scopedString(data, scope, "apiKey", "apiKeyId"),
|
|
comboId: scopedString(data, scope, "combo", "comboId"),
|
|
connectionId: scopedString(data, scope, "connection", "connectionId"),
|
|
modelPattern: scopedModelPattern(data, scope),
|
|
sourceEffort: data.sourceEffort as ReasoningRoutingRuleInput["sourceEffort"],
|
|
requestTags: data.requestTags as string[],
|
|
tagMatchMode: data.tagMatchMode as ReasoningRoutingRuleInput["tagMatchMode"],
|
|
effortMode: data.effortMode as ReasoningRoutingRuleInput["effortMode"],
|
|
targetEffort: (data.targetEffort as ReasoningRoutingRuleInput["targetEffort"]) ?? null,
|
|
targetKind,
|
|
targetModel: targetValue(data, targetKind, "model", "targetModel"),
|
|
targetComboId: targetValue(data, targetKind, "combo", "targetComboId"),
|
|
budgetAction: data.budgetAction as ReasoningRoutingRuleInput["budgetAction"],
|
|
budgetTokens: (data.budgetTokens as number | null) ?? null,
|
|
priority: Number(data.priority ?? 0),
|
|
enabled: data.enabled !== false,
|
|
};
|
|
}
|