mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 04:57:40 +00:00
refactor(models): dedupe set default model updates
This commit is contained in:
@@ -1,34 +1,10 @@
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import { logConfigUpdated } from "../../config/logging.js";
|
||||
import {
|
||||
mergePrimaryFallbackConfig,
|
||||
type PrimaryFallbackConfig,
|
||||
resolveModelTarget,
|
||||
updateConfig,
|
||||
} from "./shared.js";
|
||||
import { applyDefaultModelPrimaryUpdate, updateConfig } from "./shared.js";
|
||||
|
||||
export async function modelsSetImageCommand(modelRaw: string, runtime: RuntimeEnv) {
|
||||
const updated = await updateConfig((cfg) => {
|
||||
const resolved = resolveModelTarget({ raw: modelRaw, cfg });
|
||||
const key = `${resolved.provider}/${resolved.model}`;
|
||||
const nextModels = { ...cfg.agents?.defaults?.models };
|
||||
if (!nextModels[key]) {
|
||||
nextModels[key] = {};
|
||||
}
|
||||
return {
|
||||
...cfg,
|
||||
agents: {
|
||||
...cfg.agents,
|
||||
defaults: {
|
||||
...cfg.agents?.defaults,
|
||||
imageModel: mergePrimaryFallbackConfig(
|
||||
cfg.agents?.defaults?.imageModel as unknown as PrimaryFallbackConfig | undefined,
|
||||
{ primary: key },
|
||||
),
|
||||
models: nextModels,
|
||||
},
|
||||
},
|
||||
};
|
||||
return applyDefaultModelPrimaryUpdate({ cfg, modelRaw, field: "imageModel" });
|
||||
});
|
||||
|
||||
logConfigUpdated(runtime);
|
||||
|
||||
Reference in New Issue
Block a user