mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 20:16:38 +00:00
Channels: move single-account config into accounts.default (#27334)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 50b5771808
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
da6a96ed33
commit
dfa0b5b4fc
@@ -1,3 +1,4 @@
|
||||
import { shouldMoveSingleAccountChannelKey } from "../channels/plugins/setup-helpers.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import {
|
||||
resolveDiscordPreviewStreamMode,
|
||||
@@ -5,6 +6,7 @@ import {
|
||||
resolveSlackStreamingMode,
|
||||
resolveTelegramPreviewStreamMode,
|
||||
} from "../config/discord-preview-streaming.js";
|
||||
import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js";
|
||||
|
||||
export function normalizeLegacyConfigValues(cfg: OpenClawConfig): {
|
||||
config: OpenClawConfig;
|
||||
@@ -289,9 +291,80 @@ export function normalizeLegacyConfigValues(cfg: OpenClawConfig): {
|
||||
}
|
||||
};
|
||||
|
||||
const seedMissingDefaultAccountsFromSingleAccountBase = () => {
|
||||
const channels = next.channels as Record<string, unknown> | undefined;
|
||||
if (!channels) {
|
||||
return;
|
||||
}
|
||||
|
||||
let channelsChanged = false;
|
||||
const nextChannels = { ...channels };
|
||||
for (const [channelId, rawChannel] of Object.entries(channels)) {
|
||||
if (!isRecord(rawChannel)) {
|
||||
continue;
|
||||
}
|
||||
const rawAccounts = rawChannel.accounts;
|
||||
if (!isRecord(rawAccounts)) {
|
||||
continue;
|
||||
}
|
||||
const accountKeys = Object.keys(rawAccounts);
|
||||
if (accountKeys.length === 0) {
|
||||
continue;
|
||||
}
|
||||
const hasDefault = accountKeys.some((key) => key.trim().toLowerCase() === DEFAULT_ACCOUNT_ID);
|
||||
if (hasDefault) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const keysToMove = Object.entries(rawChannel)
|
||||
.filter(
|
||||
([key, value]) =>
|
||||
key !== "accounts" &&
|
||||
key !== "enabled" &&
|
||||
value !== undefined &&
|
||||
shouldMoveSingleAccountChannelKey({ channelKey: channelId, key }),
|
||||
)
|
||||
.map(([key]) => key);
|
||||
if (keysToMove.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const defaultAccount: Record<string, unknown> = {};
|
||||
for (const key of keysToMove) {
|
||||
const value = rawChannel[key];
|
||||
defaultAccount[key] = value && typeof value === "object" ? structuredClone(value) : value;
|
||||
}
|
||||
const nextChannel: Record<string, unknown> = {
|
||||
...rawChannel,
|
||||
};
|
||||
for (const key of keysToMove) {
|
||||
delete nextChannel[key];
|
||||
}
|
||||
nextChannel.accounts = {
|
||||
...rawAccounts,
|
||||
[DEFAULT_ACCOUNT_ID]: defaultAccount,
|
||||
};
|
||||
|
||||
nextChannels[channelId] = nextChannel;
|
||||
channelsChanged = true;
|
||||
changes.push(
|
||||
`Moved channels.${channelId} single-account top-level values into channels.${channelId}.accounts.default.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (!channelsChanged) {
|
||||
return;
|
||||
}
|
||||
next = {
|
||||
...next,
|
||||
channels: nextChannels as OpenClawConfig["channels"],
|
||||
};
|
||||
};
|
||||
|
||||
normalizeProvider("telegram");
|
||||
normalizeProvider("slack");
|
||||
normalizeProvider("discord");
|
||||
seedMissingDefaultAccountsFromSingleAccountBase();
|
||||
|
||||
const normalizeBrowserSsrFPolicyAlias = () => {
|
||||
const rawBrowser = next.browser;
|
||||
|
||||
Reference in New Issue
Block a user