refactor(models): share primary/fallback merge

This commit is contained in:
Peter Steinberger
2026-02-15 17:13:09 +00:00
parent 3ce0e80f57
commit cbf6ee3a64
5 changed files with 64 additions and 62 deletions

View File

@@ -1,6 +1,11 @@
import type { RuntimeEnv } from "../../runtime.js";
import { logConfigUpdated } from "../../config/logging.js";
import { resolveModelTarget, updateConfig } from "./shared.js";
import {
mergePrimaryFallbackConfig,
type PrimaryFallbackConfig,
resolveModelTarget,
updateConfig,
} from "./shared.js";
export async function modelsSetCommand(modelRaw: string, runtime: RuntimeEnv) {
const updated = await updateConfig((cfg) => {
@@ -10,19 +15,16 @@ export async function modelsSetCommand(modelRaw: string, runtime: RuntimeEnv) {
if (!nextModels[key]) {
nextModels[key] = {};
}
const existingModel = cfg.agents?.defaults?.model as
| { primary?: string; fallbacks?: string[] }
| undefined;
return {
...cfg,
agents: {
...cfg.agents,
defaults: {
...cfg.agents?.defaults,
model: {
...(existingModel?.fallbacks ? { fallbacks: existingModel.fallbacks } : undefined),
primary: key,
},
model: mergePrimaryFallbackConfig(
cfg.agents?.defaults?.model as unknown as PrimaryFallbackConfig | undefined,
{ primary: key },
),
models: nextModels,
},
},