From 17d43672ad45a399eb659a5b8d049f2b917826ca Mon Sep 17 00:00:00 2001 From: um1ng Date: Thu, 5 Feb 2026 23:15:31 +0900 Subject: [PATCH] refactor(shared): add normalizeFallbackModels utility function Add shared utility to normalize fallback_models config values. Handles both single string and array inputs consistently. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- src/agents/types.ts | 1 + src/shared/index.ts | 1 + src/shared/model-resolver.ts | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/src/agents/types.ts b/src/agents/types.ts index 92834883..4ee1b3a6 100644 --- a/src/agents/types.ts +++ b/src/agents/types.ts @@ -100,6 +100,7 @@ export type AgentName = BuiltinAgentName export type AgentOverrideConfig = Partial & { prompt_append?: string variant?: string + fallback_models?: string | string[] } export type AgentOverrides = Partial> diff --git a/src/shared/index.ts b/src/shared/index.ts index 263d50ba..09187602 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -34,6 +34,7 @@ export * from "./system-directive" export * from "./agent-tool-restrictions" export * from "./model-requirements" export * from "./model-resolver" +export { normalizeFallbackModels } from "./model-resolver" export { resolveModelPipeline } from "./model-resolution-pipeline" export type { ModelResolutionRequest, diff --git a/src/shared/model-resolver.ts b/src/shared/model-resolver.ts index 84cbcbe2..a9e450fb 100644 --- a/src/shared/model-resolver.ts +++ b/src/shared/model-resolver.ts @@ -7,6 +7,17 @@ export type ModelResolutionInput = { systemDefault?: string } +/** + * Normalizes fallback_models to an array. + * Handles single string or array input, returns undefined for falsy values. + */ +export function normalizeFallbackModels( + fallbackModels: string | string[] | undefined | null +): string[] | undefined { + if (!fallbackModels) return undefined + return Array.isArray(fallbackModels) ? fallbackModels : [fallbackModels] +} + export type ModelSource = | "override" | "category-default"