feat(config): support object-style fallback_models with per-model settings
Add support for object-style entries in fallback_models arrays, enabling per-model configuration of variant, reasoningEffort, temperature, top_p, maxTokens, and thinking settings. - Zod schema for FallbackModelObject with full validation - normalizeFallbackModels() and flattenToFallbackModelStrings() utilities - Provider-agnostic model resolution pipeline with fallback chain - Session prompt params state management - Fallback chain construction with prefix-match lookup - Integration across delegate-task, background-agent, and plugin layers
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import type { OhMyOpenCodeConfig } from "../../config"
|
||||
import type { FallbackModelObject } from "../../config/schema/fallback-models"
|
||||
import { agentPattern } from "./agent-resolver"
|
||||
import { HOOK_NAME } from "./constants"
|
||||
import { log } from "../../shared/logger"
|
||||
import { SessionCategoryRegistry } from "../../shared/session-category-registry"
|
||||
import { normalizeFallbackModels } from "../../shared/model-resolver"
|
||||
import { normalizeFallbackModels, flattenToFallbackModelStrings } from "../../shared/model-resolver"
|
||||
|
||||
/**
|
||||
* Returns fallback model strings for the runtime-fallback system.
|
||||
* Object entries are flattened to "provider/model(variant)" strings so the
|
||||
* string-based fallback state machine can work with them unchanged.
|
||||
*/
|
||||
export function getFallbackModelsForSession(
|
||||
sessionID: string,
|
||||
agent: string | undefined,
|
||||
@@ -12,22 +18,45 @@ export function getFallbackModelsForSession(
|
||||
): string[] {
|
||||
if (!pluginConfig) return []
|
||||
|
||||
const raw = getRawFallbackModelsForSession(sessionID, agent, pluginConfig)
|
||||
return flattenToFallbackModelStrings(raw) ?? []
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw fallback model entries (strings and objects) for a session.
|
||||
* Use this when per-model settings (temperature, reasoningEffort, etc.) must be
|
||||
* preserved — e.g. before passing to buildFallbackChainFromModels.
|
||||
*/
|
||||
export function getRawFallbackModels(
|
||||
sessionID: string,
|
||||
agent: string | undefined,
|
||||
pluginConfig: OhMyOpenCodeConfig | undefined,
|
||||
): (string | FallbackModelObject)[] | undefined {
|
||||
if (!pluginConfig) return undefined
|
||||
return getRawFallbackModelsForSession(sessionID, agent, pluginConfig)
|
||||
}
|
||||
|
||||
function getRawFallbackModelsForSession(
|
||||
sessionID: string,
|
||||
agent: string | undefined,
|
||||
pluginConfig: OhMyOpenCodeConfig,
|
||||
): (string | FallbackModelObject)[] | undefined {
|
||||
const sessionCategory = SessionCategoryRegistry.get(sessionID)
|
||||
if (sessionCategory && pluginConfig.categories?.[sessionCategory]) {
|
||||
const categoryConfig = pluginConfig.categories[sessionCategory]
|
||||
if (categoryConfig?.fallback_models) {
|
||||
return normalizeFallbackModels(categoryConfig.fallback_models) ?? []
|
||||
return normalizeFallbackModels(categoryConfig.fallback_models)
|
||||
}
|
||||
}
|
||||
|
||||
const tryGetFallbackFromAgent = (agentName: string): string[] | undefined => {
|
||||
const tryGetFallbackFromAgent = (agentName: string): (string | FallbackModelObject)[] | undefined => {
|
||||
const agentConfig = pluginConfig.agents?.[agentName as keyof typeof pluginConfig.agents]
|
||||
if (!agentConfig) return undefined
|
||||
|
||||
|
||||
if (agentConfig?.fallback_models) {
|
||||
return normalizeFallbackModels(agentConfig.fallback_models)
|
||||
}
|
||||
|
||||
|
||||
const agentCategory = agentConfig?.category
|
||||
if (agentCategory && pluginConfig.categories?.[agentCategory]) {
|
||||
const categoryConfig = pluginConfig.categories[agentCategory]
|
||||
@@ -35,7 +64,7 @@ export function getFallbackModelsForSession(
|
||||
return normalizeFallbackModels(categoryConfig.fallback_models)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -53,5 +82,5 @@ export function getFallbackModelsForSession(
|
||||
|
||||
log(`[${HOOK_NAME}] No category/agent fallback models resolved for session`, { sessionID, agent })
|
||||
|
||||
return []
|
||||
return undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user