refactor: share legacy config migration pipeline

This commit is contained in:
Peter Steinberger
2026-04-19 05:06:58 +01:00
parent 528f296cfc
commit 984ecd98ca
3 changed files with 54 additions and 74 deletions

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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 };
}