Files
OmniRoute/src/shared/constants/routingStrategies.ts
Jan Leon f879a394f4 feat(routing): add prompt-cache affinity (#8008)
* Add prompt cache locality routing

* fix: preserve weighted cache-affinity routing

* feat(routing): add cache-optimized combos

* fix(routing): preserve normal ordering on cache misses

* fix(routing): bind cache affinity to concrete accounts

* feat(routing): add prompt-cache affinity + align combo-auto-config test with new defaults

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
Co-authored-by: JxnLexn <JxnLexn@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
2026-07-22 06:43:31 -03:00

225 lines
5.6 KiB
TypeScript

export const ROUTING_STRATEGY_VALUES = [
"priority",
"weighted",
"round-robin",
"context-relay",
"fill-first",
"p2c",
"random",
"least-used",
"cost-optimized",
"reset-aware",
"reset-window",
"headroom",
"strict-random",
"auto",
"lkgp",
"context-optimized",
"cache-optimized",
"fusion",
"pipeline",
] as const;
export type RoutingStrategyValue = (typeof ROUTING_STRATEGY_VALUES)[number];
/**
* Internal-only routing strategy values. These are used by system-generated
* combos (e.g. the auto-minted quota-share `qtSd/` combos) and are NEVER exposed
* in the UI or user-facing API — deliberately kept OUT of ROUTING_STRATEGY_VALUES
* and ROUTING_STRATEGIES so they never appear as a selectable option.
*/
export const INTERNAL_ROUTING_STRATEGY_VALUES = ["quota-share"] as const;
export type InternalRoutingStrategyValue = (typeof INTERNAL_ROUTING_STRATEGY_VALUES)[number];
/** Any routing strategy value, including internal ones. Used for combo dispatch. */
export type AnyRoutingStrategyValue = RoutingStrategyValue | InternalRoutingStrategyValue;
export const AUTO_ROUTING_STRATEGY_VALUES = [
"rules",
"cost",
"eco",
"latency",
"fast",
"sla-aware",
"sla",
"lkgp",
] as const;
export type AutoRoutingStrategyValue = (typeof AUTO_ROUTING_STRATEGY_VALUES)[number];
export const ACCOUNT_FALLBACK_STRATEGY_VALUES = [
"priority",
"weighted",
"fill-first",
"round-robin",
"p2c",
"random",
"least-used",
"cost-optimized",
"strict-random",
] as const;
export type AccountFallbackStrategyValue = (typeof ACCOUNT_FALLBACK_STRATEGY_VALUES)[number];
export function normalizeRoutingStrategy(value: unknown): AnyRoutingStrategyValue {
if (typeof value !== "string") return "priority";
const normalized = value.trim().toLowerCase();
if (normalized === "usage") return "least-used";
if (normalized === "context") return "context-optimized";
if (normalized === "weekly-reset" || normalized === "reset-window-order") return "reset-window";
// Internal strategies (e.g. quota-share) are preserved verbatim, never stripped
// to "priority", so system-minted combos resolve to their dedicated dispatch.
if ((INTERNAL_ROUTING_STRATEGY_VALUES as readonly string[]).includes(normalized))
return normalized as InternalRoutingStrategyValue;
return (ROUTING_STRATEGY_VALUES as readonly string[]).includes(normalized)
? (normalized as RoutingStrategyValue)
: "priority";
}
type RoutingStrategyOption = {
value: RoutingStrategyValue;
labelKey: string;
combosDescKey: string;
settingsDescKey: string;
icon: string;
};
export const ROUTING_STRATEGIES: RoutingStrategyOption[] = [
{
value: "priority",
labelKey: "priority",
combosDescKey: "priorityDesc",
settingsDescKey: "priorityDesc",
icon: "sort",
},
{
value: "weighted",
labelKey: "weighted",
combosDescKey: "weightedDesc",
settingsDescKey: "weightedDesc",
icon: "percent",
},
{
value: "round-robin",
labelKey: "roundRobin",
combosDescKey: "roundRobinDesc",
settingsDescKey: "roundRobinDesc",
icon: "autorenew",
},
{
value: "context-relay",
labelKey: "contextRelay",
combosDescKey: "contextRelayDesc",
settingsDescKey: "contextRelayDesc",
icon: "sync_alt",
},
{
value: "fill-first",
labelKey: "fillFirst",
combosDescKey: "fillFirstDesc",
settingsDescKey: "fillFirstDesc",
icon: "vertical_align_top",
},
{
value: "p2c",
labelKey: "p2c",
combosDescKey: "p2cDesc",
settingsDescKey: "p2cDesc",
icon: "balance",
},
{
value: "random",
labelKey: "random",
combosDescKey: "randomDesc",
settingsDescKey: "randomDesc",
icon: "shuffle",
},
{
value: "least-used",
labelKey: "leastUsed",
combosDescKey: "leastUsedDesc",
settingsDescKey: "leastUsedDesc",
icon: "low_priority",
},
{
value: "cost-optimized",
labelKey: "costOpt",
combosDescKey: "costOptimizedDesc",
settingsDescKey: "costOptDesc",
icon: "savings",
},
{
value: "reset-aware",
labelKey: "resetAware",
combosDescKey: "resetAwareDesc",
settingsDescKey: "resetAwareDesc",
icon: "event_repeat",
},
{
value: "reset-window",
labelKey: "resetWindow",
combosDescKey: "resetWindowDesc",
settingsDescKey: "resetWindowDesc",
icon: "schedule",
},
{
value: "headroom",
labelKey: "headroom",
combosDescKey: "headroomDesc",
settingsDescKey: "headroomDesc",
icon: "battery_charging_full",
},
{
value: "strict-random",
labelKey: "strictRandom",
combosDescKey: "strictRandomDesc",
settingsDescKey: "strictRandomDesc",
icon: "casino",
},
{
value: "auto",
labelKey: "auto",
combosDescKey: "autoDesc",
settingsDescKey: "autoDesc",
icon: "auto_awesome",
},
{
value: "lkgp",
labelKey: "lkgp",
combosDescKey: "lkgpDesc",
settingsDescKey: "lkgpDesc",
icon: "verified",
},
{
value: "context-optimized",
labelKey: "contextOpt",
combosDescKey: "contextOptimizedDesc",
settingsDescKey: "contextOptDesc",
icon: "text_snippet",
},
{
value: "cache-optimized",
labelKey: "cacheOpt",
combosDescKey: "cacheOptimizedDesc",
settingsDescKey: "cacheOptDesc",
icon: "cached",
},
{
value: "fusion",
labelKey: "fusion",
combosDescKey: "fusionDesc",
settingsDescKey: "fusionDesc",
icon: "hub",
},
{
value: "pipeline",
labelKey: "pipeline",
combosDescKey: "pipelineDesc",
settingsDescKey: "pipelineDesc",
icon: "linear_scale",
},
];
export const SETTINGS_FALLBACK_STRATEGY_VALUES = ACCOUNT_FALLBACK_STRATEGY_VALUES;