























@@ -3,6 +3,10 @@ import type { Command } from "commander";
33import JSON5 from "json5";
44import { readConfigFileSnapshot, replaceConfigFile } from "../config/config.js";
55import { formatConfigIssueLines, normalizeConfigIssues } from "../config/issue-format.js";
6+import {
7+normalizeAgentModelMapForConfig,
8+normalizeAgentModelRefForConfig,
9+} from "../config/model-input.js";
610import { CONFIG_PATH } from "../config/paths.js";
711import { isBlockedObjectKey } from "../config/prototype-keys.js";
812import { redactConfigObject } from "../config/redact-snapshot.js";
@@ -90,6 +94,53 @@ type ConfigMutationOptions = {
9094replace?: boolean | undefined;
9195};
929697+function normalizeAgentDefaultModelValueForConfigMutation(value: unknown): unknown {
98+if (typeof value === "string") {
99+return normalizeAgentModelRefForConfig(value);
100+}
101+if (!isPlainRecord(value)) {
102+return value;
103+}
104+105+const next: Record<string, unknown> = { ...value };
106+if (typeof next.primary === "string") {
107+next.primary = normalizeAgentModelRefForConfig(next.primary);
108+}
109+if (Array.isArray(next.fallbacks)) {
110+next.fallbacks = next.fallbacks.map((fallback) =>
111+typeof fallback === "string" ? normalizeAgentModelRefForConfig(fallback) : fallback,
112+);
113+}
114+return next;
115+}
116+117+function normalizeConfigMutationModelRefs(cfg: OpenClawConfig): OpenClawConfig {
118+const defaults = cfg.agents?.defaults;
119+if (!defaults) {
120+return cfg;
121+}
122+123+return {
124+ ...cfg,
125+agents: {
126+ ...cfg.agents,
127+defaults: {
128+ ...defaults,
129+ ...(defaults.model !== undefined
130+ ? {
131+model: normalizeAgentDefaultModelValueForConfigMutation(
132+defaults.model,
133+) as typeof defaults.model,
134+}
135+ : undefined),
136+ ...(defaults.models !== undefined
137+ ? { models: normalizeAgentModelMapForConfig(defaults.models) }
138+ : undefined),
139+},
140+},
141+};
142+}
143+93144const GATEWAY_AUTH_MODE_PATH: PathSegment[] = ["gateway", "auth", "mode"];
94145const SECRET_PROVIDER_PATH_PREFIX: PathSegment[] = ["secrets", "providers"];
95146const PLUGIN_INSTALL_RECORD_PATH_PREFIX: PathSegment[] = ["plugins", "installs"];
@@ -1418,7 +1469,7 @@ async function runConfigOperations(params: {
14181469root: next,
14191470 operations,
14201471});
1421-const nextConfig = next as OpenClawConfig;
1472+const nextConfig = normalizeConfigMutationModelRefs(next as OpenClawConfig);
14221473const policyIssues = collectUnsupportedSecretRefPolicyIssues(nextConfig);
14231474const policyIssueLines = formatConfigIssueLines(policyIssues, "", { normalizeRoot: true }).map(
14241475(line) => line.trim(),
@@ -1529,7 +1580,7 @@ async function runConfigOperations(params: {
15291580}
1530158115311582await replaceConfigFile({
1532-nextConfig: next,
1583+ nextConfig,
15331584 ...(snapshot.hash !== undefined ? { baseHash: snapshot.hash } : {}),
15341585 ...(unsetPaths.length > 0 ? { writeOptions: { unsetPaths } } : {}),
15351586});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。