mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-04 14:22:09 +03:00
- Add auto-prefix parser (autoPrefix.ts) for auto/Cvariant detection - Add virtual auto-combo factory (virtualFactory.ts) building combos from active providers - Integrate auto/ prefix into chat routing (chat.ts) - supports bare 'auto' and 'auto/variant' - Add system provider 'auto' in providers.ts (systemOnly) - Add AutoRoutingBanner component with localStorage dismissal - Add auto-routing settings in RoutingTab (toggle + variant selector) - Add auto-routing analytics tab (AutoRoutingAnalyticsTab) + API endpoint - Add Case 0 zero-config documentation to README.md - Add autoRoutingEnabled/enforcement and autoRoutingDefaultVariant settings - Add analytics endpoint auth via requireManagementAuth - Add empty-pool graceful handling in virtualFactory - Add dynamic import error handling with try/catch - Tests: 126/126 passing
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
export type AutoVariant = "coding" | "fast" | "cheap" | "offline" | "smart" | "lkgp";
|
|
|
|
export interface AutoPrefixParseResult {
|
|
valid: boolean;
|
|
variant?: AutoVariant;
|
|
error?: string;
|
|
}
|
|
|
|
const VALID_VARIANTS: AutoVariant[] = ["coding", "fast", "cheap", "offline", "smart", "lkgp"];
|
|
|
|
/**
|
|
* Parses a model name to determine if it's an auto-prefixed model and extracts the variant.
|
|
*
|
|
* Examples:
|
|
* - "auto" -> { valid: true, variant: undefined } (default)
|
|
* - "auto/coding" -> { valid: true, variant: "coding" }
|
|
* - "auto/lkgp" -> { valid: true, variant: "lkgp" }
|
|
* - "auto/" -> { valid: true, variant: undefined } (default)
|
|
* - "autocoding" -> { valid: false, error: "Invalid auto prefix format" }
|
|
* - "otherModel" -> { valid: false, error: "Not an auto-prefixed model" }
|
|
*/
|
|
export function parseAutoPrefix(model: string | null | undefined): AutoPrefixParseResult {
|
|
// Guard against null/undefined (called with non-string inputs)
|
|
if (typeof model !== "string") {
|
|
return { valid: false, error: "Not an auto-prefixed model" };
|
|
}
|
|
if (!model.startsWith("auto")) {
|
|
return { valid: false, error: "Not an auto-prefixed model" };
|
|
}
|
|
|
|
const parts = model.split("/");
|
|
|
|
if (parts.length === 1) {
|
|
if (parts[0] === "auto") {
|
|
return { valid: true, variant: undefined }; // Default auto
|
|
} else {
|
|
return { valid: false, error: "Invalid auto prefix format" };
|
|
}
|
|
}
|
|
|
|
if (parts.length === 2) {
|
|
if (parts[0] !== "auto") {
|
|
return { valid: false, error: "Invalid auto prefix format" };
|
|
}
|
|
const variantStr: string = parts[1];
|
|
if (variantStr === "" || VALID_VARIANTS.includes(variantStr as AutoVariant)) {
|
|
return { valid: true, variant: variantStr === "" ? undefined : (variantStr as AutoVariant) };
|
|
} else {
|
|
return { valid: false, error: `Invalid auto variant: ${variantStr}` };
|
|
}
|
|
}
|
|
|
|
return { valid: false, error: "Invalid auto prefix format" };
|
|
}
|