diff --git a/src/commands/doctor/shared/legacy-config-compatibility-base.ts b/src/commands/doctor/shared/legacy-config-compatibility-base.ts new file mode 100644 index 00000000000..37a7b56d8a4 --- /dev/null +++ b/src/commands/doctor/shared/legacy-config-compatibility-base.ts @@ -0,0 +1,42 @@ +import type { OpenClawConfig } from "../../../config/types.openclaw.js"; +import { + normalizeLegacyBrowserConfig, + normalizeLegacyCrossContextMessageConfig, + normalizeLegacyMediaProviderOptions, + normalizeLegacyMistralModelMaxTokens, + normalizeLegacyNanoBananaSkill, + normalizeLegacyTalkConfig, + seedMissingDefaultAccountsFromSingleAccountBase, +} from "./legacy-config-core-normalizers.js"; +import { migrateLegacyWebFetchConfig } from "./legacy-web-fetch-migrate.js"; +import { migrateLegacyWebSearchConfig } from "./legacy-web-search-migrate.js"; +import { migrateLegacyXSearchConfig } from "./legacy-x-search-migrate.js"; + +export function normalizeBaseCompatibilityConfigValues( + cfg: OpenClawConfig, + changes: string[], + afterBrowser?: (config: OpenClawConfig) => OpenClawConfig, +): OpenClawConfig { + let next = seedMissingDefaultAccountsFromSingleAccountBase(cfg, changes); + next = normalizeLegacyBrowserConfig(next, changes); + next = afterBrowser ? afterBrowser(next) : next; + + for (const migrate of [ + migrateLegacyWebSearchConfig, + migrateLegacyWebFetchConfig, + migrateLegacyXSearchConfig, + ]) { + const migrated = migrate(next); + if (migrated.changes.length === 0) { + continue; + } + next = migrated.config; + changes.push(...migrated.changes); + } + + next = normalizeLegacyNanoBananaSkill(next, changes); + next = normalizeLegacyTalkConfig(next, changes); + next = normalizeLegacyCrossContextMessageConfig(next, changes); + next = normalizeLegacyMediaProviderOptions(next, changes); + return normalizeLegacyMistralModelMaxTokens(next, changes); +} diff --git a/src/commands/doctor/shared/legacy-config-core-migrate.ts b/src/commands/doctor/shared/legacy-config-core-migrate.ts index 210ff4e7c90..3308906e88e 100644 --- a/src/commands/doctor/shared/legacy-config-core-migrate.ts +++ b/src/commands/doctor/shared/legacy-config-core-migrate.ts @@ -1,53 +1,23 @@ import type { OpenClawConfig } from "../../../config/types.openclaw.js"; import { runPluginSetupConfigMigrations } from "../../../plugins/setup-registry.js"; import { applyChannelDoctorCompatibilityMigrations } from "./channel-legacy-config-migrate.js"; -import { - normalizeLegacyBrowserConfig, - normalizeLegacyCrossContextMessageConfig, - normalizeLegacyMediaProviderOptions, - normalizeLegacyMistralModelMaxTokens, - normalizeLegacyNanoBananaSkill, - normalizeLegacyTalkConfig, - seedMissingDefaultAccountsFromSingleAccountBase, -} from "./legacy-config-core-normalizers.js"; -import { migrateLegacyWebFetchConfig } from "./legacy-web-fetch-migrate.js"; -import { migrateLegacyWebSearchConfig } from "./legacy-web-search-migrate.js"; -import { migrateLegacyXSearchConfig } from "./legacy-x-search-migrate.js"; +import { normalizeBaseCompatibilityConfigValues } from "./legacy-config-compatibility-base.js"; export function normalizeCompatibilityConfigValues(cfg: OpenClawConfig): { config: OpenClawConfig; changes: string[]; } { const changes: string[] = []; - let next = seedMissingDefaultAccountsFromSingleAccountBase(cfg, changes); - next = normalizeLegacyBrowserConfig(next, changes); - - const setupMigration = runPluginSetupConfigMigrations({ - config: next, - }); - if (setupMigration.changes.length > 0) { - next = setupMigration.config; - changes.push(...setupMigration.changes); - } - - for (const migrate of [ - migrateLegacyWebSearchConfig, - migrateLegacyWebFetchConfig, - migrateLegacyXSearchConfig, - ]) { - const migrated = migrate(next); - if (migrated.changes.length === 0) { - continue; + let next = normalizeBaseCompatibilityConfigValues(cfg, changes, (config) => { + const setupMigration = runPluginSetupConfigMigrations({ + config, + }); + if (setupMigration.changes.length === 0) { + return config; } - next = migrated.config; - changes.push(...migrated.changes); - } - - next = normalizeLegacyNanoBananaSkill(next, changes); - next = normalizeLegacyTalkConfig(next, changes); - next = normalizeLegacyCrossContextMessageConfig(next, changes); - next = normalizeLegacyMediaProviderOptions(next, changes); - next = normalizeLegacyMistralModelMaxTokens(next, changes); + changes.push(...setupMigration.changes); + return setupMigration.config; + }); const channelMigrations = applyChannelDoctorCompatibilityMigrations(next); if (channelMigrations.changes.length > 0) { next = channelMigrations.next; diff --git a/src/commands/doctor/shared/legacy-config-runtime-migrate.ts b/src/commands/doctor/shared/legacy-config-runtime-migrate.ts index f1b2ecdafb0..c4028ae8ec8 100644 --- a/src/commands/doctor/shared/legacy-config-runtime-migrate.ts +++ b/src/commands/doctor/shared/legacy-config-runtime-migrate.ts @@ -1,43 +1,11 @@ import type { OpenClawConfig } from "../../../config/types.openclaw.js"; -import { - normalizeLegacyBrowserConfig, - normalizeLegacyCrossContextMessageConfig, - normalizeLegacyMediaProviderOptions, - normalizeLegacyMistralModelMaxTokens, - normalizeLegacyNanoBananaSkill, - normalizeLegacyTalkConfig, - seedMissingDefaultAccountsFromSingleAccountBase, -} from "./legacy-config-core-normalizers.js"; -import { migrateLegacyWebFetchConfig } from "./legacy-web-fetch-migrate.js"; -import { migrateLegacyWebSearchConfig } from "./legacy-web-search-migrate.js"; -import { migrateLegacyXSearchConfig } from "./legacy-x-search-migrate.js"; +import { normalizeBaseCompatibilityConfigValues } from "./legacy-config-compatibility-base.js"; export function normalizeRuntimeCompatibilityConfigValues(cfg: OpenClawConfig): { config: OpenClawConfig; changes: string[]; } { const changes: string[] = []; - let next = seedMissingDefaultAccountsFromSingleAccountBase(cfg, changes); - next = normalizeLegacyBrowserConfig(next, changes); - - for (const migrate of [ - migrateLegacyWebSearchConfig, - migrateLegacyWebFetchConfig, - migrateLegacyXSearchConfig, - ]) { - const migrated = migrate(next); - if (migrated.changes.length === 0) { - continue; - } - next = migrated.config; - changes.push(...migrated.changes); - } - - next = normalizeLegacyNanoBananaSkill(next, changes); - next = normalizeLegacyTalkConfig(next, changes); - next = normalizeLegacyCrossContextMessageConfig(next, changes); - next = normalizeLegacyMediaProviderOptions(next, changes); - next = normalizeLegacyMistralModelMaxTokens(next, changes); - + const next = normalizeBaseCompatibilityConfigValues(cfg, changes); return { config: next, changes }; }