(raw: string | null | undefined)
| 12 | |
| 13 | /** Normalize user-provided model input (alias resolution + gateway migration + format validation). */ |
| 14 | export function normalizeModelInput(raw: string | null | undefined): ModelInputResult { |
| 15 | const trimmed = typeof raw === "string" ? raw.trim() : ""; |
| 16 | if (!trimmed) { |
| 17 | return { model: null, isAlias: false }; |
| 18 | } |
| 19 | |
| 20 | const resolved = resolveModelAlias(trimmed); |
| 21 | const isAlias = resolved !== trimmed; |
| 22 | const selectedModel = normalizeSelectedModel(resolved); |
| 23 | |
| 24 | if (!isValidModelFormat(selectedModel)) { |
| 25 | return { model: null, isAlias, error: "invalid-format" }; |
| 26 | } |
| 27 | |
| 28 | const separatorIndex = selectedModel.indexOf(":"); |
| 29 | if (selectedModel.slice(separatorIndex + 1).startsWith(":")) { |
| 30 | return { model: null, isAlias, error: "invalid-format" }; |
| 31 | } |
| 32 | |
| 33 | return { model: selectedModel, isAlias }; |
| 34 | } |
no test coverage detected