* chore: apply local workspace updates * fix: resolve prep findings after rebase (#9898) (thanks @gumadeiras) * refactor: centralize model allowlist normalization (#9898) (thanks @gumadeiras) * fix: guard model allowlist initialization (#9911) * docs: update changelog scope for #9911 * docs: remove model names from changelog entry (#9911) * fix: satisfy type-aware lint in model allowlist (#9911)
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import type { OpenClawConfig } from "../config/config.js";
|
|
import type { AgentModelListConfig } from "../config/types.js";
|
|
|
|
export const OPENCODE_ZEN_DEFAULT_MODEL = "opencode/claude-opus-4-6";
|
|
const LEGACY_OPENCODE_ZEN_DEFAULT_MODELS = new Set([
|
|
"opencode/claude-opus-4-5",
|
|
"opencode-zen/claude-opus-4-5",
|
|
]);
|
|
|
|
function resolvePrimaryModel(model?: AgentModelListConfig | string): string | undefined {
|
|
if (typeof model === "string") {
|
|
return model;
|
|
}
|
|
if (model && typeof model === "object" && typeof model.primary === "string") {
|
|
return model.primary;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function applyOpencodeZenModelDefault(cfg: OpenClawConfig): {
|
|
next: OpenClawConfig;
|
|
changed: boolean;
|
|
} {
|
|
const current = resolvePrimaryModel(cfg.agents?.defaults?.model)?.trim();
|
|
const normalizedCurrent =
|
|
current && LEGACY_OPENCODE_ZEN_DEFAULT_MODELS.has(current)
|
|
? OPENCODE_ZEN_DEFAULT_MODEL
|
|
: current;
|
|
if (normalizedCurrent === OPENCODE_ZEN_DEFAULT_MODEL) {
|
|
return { next: cfg, changed: false };
|
|
}
|
|
|
|
return {
|
|
next: {
|
|
...cfg,
|
|
agents: {
|
|
...cfg.agents,
|
|
defaults: {
|
|
...cfg.agents?.defaults,
|
|
model:
|
|
cfg.agents?.defaults?.model && typeof cfg.agents.defaults.model === "object"
|
|
? {
|
|
...cfg.agents.defaults.model,
|
|
primary: OPENCODE_ZEN_DEFAULT_MODEL,
|
|
}
|
|
: { primary: OPENCODE_ZEN_DEFAULT_MODEL },
|
|
},
|
|
},
|
|
},
|
|
changed: true,
|
|
};
|
|
}
|