






















@@ -1,7 +1,7 @@
11import { isDeepStrictEqual } from "node:util";
22import { isRecord } from "../utils.js";
33import { applyMergePatch } from "./merge-patch.js";
4-import { normalizeAgentModelRefForConfig } from "./model-input.js";
4+import { normalizeAgentModelMapForConfig, normalizeAgentModelRefForConfig } from "./model-input.js";
55import { isBlockedObjectKey } from "./prototype-keys.js";
66import type { OpenClawConfig } from "./types.js";
77@@ -258,6 +258,58 @@ function preserveAuthoredAgentParams(params: {
258258return next;
259259}
260260261+function normalizeAgentModelConfigForWrite(value: unknown): unknown {
262+if (typeof value === "string") {
263+const normalized = normalizeAgentModelRefForConfig(value);
264+return normalized === value ? value : normalized;
265+}
266+if (!isRecord(value)) {
267+return value;
268+}
269+270+let mutated = false;
271+const next: Record<string, unknown> = { ...value };
272+if (typeof value.primary === "string") {
273+const primary = normalizeAgentModelRefForConfig(value.primary);
274+if (primary !== value.primary) {
275+next.primary = primary;
276+mutated = true;
277+}
278+}
279+if (Array.isArray(value.fallbacks)) {
280+const fallbacks = value.fallbacks.map((fallback) =>
281+typeof fallback === "string" ? normalizeAgentModelRefForConfig(fallback) : fallback,
282+);
283+if (!isDeepStrictEqual(fallbacks, value.fallbacks)) {
284+next.fallbacks = fallbacks;
285+mutated = true;
286+}
287+}
288+return mutated ? next : value;
289+}
290+291+function normalizeAgentDefaultModelRefsForWrite(config: unknown): unknown {
292+const defaults = getPathValue(config, ["agents", "defaults"]);
293+if (!isRecord(defaults)) {
294+return config;
295+}
296+297+let next = config;
298+if (Object.prototype.hasOwnProperty.call(defaults, "model")) {
299+const normalizedModel = normalizeAgentModelConfigForWrite(defaults.model);
300+if (normalizedModel !== defaults.model) {
301+next = setPathValue(next, ["agents", "defaults", "model"], normalizedModel);
302+}
303+}
304+if (isRecord(defaults.models)) {
305+const normalizedModels = normalizeAgentModelMapForConfig(defaults.models);
306+if (normalizedModels !== defaults.models) {
307+next = setPathValue(next, ["agents", "defaults", "models"], normalizedModels);
308+}
309+}
310+return next;
311+}
312+261313function preserveUntouchedIncludes(params: {
262314patch: unknown;
263315rootAuthoredConfig: unknown;
@@ -297,13 +349,14 @@ export function resolvePersistCandidateForWrite(params: {
297349nextConfig: params.nextConfig,
298350persistedCandidate: persisted,
299351});
300-return preserveAuthoredAgentParams({
352+const withAuthoredParams = preserveAuthoredAgentParams({
301353sourceConfig: params.sourceConfig,
302354nextConfig: params.nextConfig,
303355 rootAuthoredConfig,
304356persistedCandidate: withSchema,
305357unsetPaths: params.unsetPaths,
306358});
359+return normalizeAgentDefaultModelRefsForWrite(withAuthoredParams);
307360}
308361309362function readRootSchemaUri(value: unknown): string | undefined {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。