mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
refactor: dedupe opencode model default helpers
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
applyAgentDefaultModelPrimary,
|
||||
resolveAgentModelPrimaryValue,
|
||||
} from "openclaw/plugin-sdk/provider-onboard";
|
||||
import { OPENCODE_ZEN_DEFAULT_MODEL_REF } from "./onboard.js";
|
||||
export {
|
||||
applyOpencodeZenConfig,
|
||||
@@ -12,27 +16,13 @@ const LEGACY_OPENCODE_ZEN_DEFAULT_MODELS = new Set([
|
||||
|
||||
export const OPENCODE_ZEN_DEFAULT_MODEL = OPENCODE_ZEN_DEFAULT_MODEL_REF;
|
||||
|
||||
function resolveCurrentPrimaryModel(model: unknown): string | undefined {
|
||||
if (typeof model === "string") {
|
||||
return model.trim() || undefined;
|
||||
}
|
||||
if (
|
||||
model &&
|
||||
typeof model === "object" &&
|
||||
typeof (model as { primary?: unknown }).primary === "string"
|
||||
) {
|
||||
return ((model as { primary: string }).primary || "").trim() || undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function applyOpencodeZenModelDefault(
|
||||
cfg: import("openclaw/plugin-sdk/provider-onboard").OpenClawConfig,
|
||||
): {
|
||||
next: import("openclaw/plugin-sdk/provider-onboard").OpenClawConfig;
|
||||
changed: boolean;
|
||||
} {
|
||||
const current = resolveCurrentPrimaryModel(cfg.agents?.defaults?.model);
|
||||
const current = resolveAgentModelPrimaryValue(cfg.agents?.defaults?.model);
|
||||
const normalizedCurrent =
|
||||
current && LEGACY_OPENCODE_ZEN_DEFAULT_MODELS.has(current)
|
||||
? OPENCODE_ZEN_DEFAULT_MODEL
|
||||
@@ -41,22 +31,7 @@ export function applyOpencodeZenModelDefault(
|
||||
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 },
|
||||
},
|
||||
},
|
||||
},
|
||||
next: applyAgentDefaultModelPrimary(cfg, OPENCODE_ZEN_DEFAULT_MODEL),
|
||||
changed: true,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user