mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-22 10:28:10 +00:00
refactor: share scoped account config patching
This commit is contained in:
@@ -9,7 +9,10 @@ import { promptAccountId as promptAccountIdSdk } from "../../../plugin-sdk/onboa
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../../../routing/session-key.js";
|
||||
import type { WizardPrompter } from "../../../wizard/prompts.js";
|
||||
import type { PromptAccountId, PromptAccountIdParams } from "../onboarding-types.js";
|
||||
import { moveSingleAccountChannelSectionToDefaultAccount } from "../setup-helpers.js";
|
||||
import {
|
||||
moveSingleAccountChannelSectionToDefaultAccount,
|
||||
patchScopedAccountConfig,
|
||||
} from "../setup-helpers.js";
|
||||
|
||||
export const promptAccountId: PromptAccountId = async (params: PromptAccountIdParams) => {
|
||||
return await promptAccountIdSdk(params);
|
||||
@@ -364,50 +367,14 @@ function patchConfigForScopedAccount(params: {
|
||||
cfg,
|
||||
channelKey: channel,
|
||||
});
|
||||
const channelConfig =
|
||||
(seededCfg.channels?.[channel] as Record<string, unknown> | undefined) ?? {};
|
||||
|
||||
if (accountId === DEFAULT_ACCOUNT_ID) {
|
||||
return {
|
||||
...seededCfg,
|
||||
channels: {
|
||||
...seededCfg.channels,
|
||||
[channel]: {
|
||||
...channelConfig,
|
||||
...(ensureEnabled ? { enabled: true } : {}),
|
||||
...patch,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const accounts =
|
||||
(channelConfig.accounts as Record<string, Record<string, unknown>> | undefined) ?? {};
|
||||
const existingAccount = accounts[accountId] ?? {};
|
||||
|
||||
return {
|
||||
...seededCfg,
|
||||
channels: {
|
||||
...seededCfg.channels,
|
||||
[channel]: {
|
||||
...channelConfig,
|
||||
...(ensureEnabled ? { enabled: true } : {}),
|
||||
accounts: {
|
||||
...accounts,
|
||||
[accountId]: {
|
||||
...existingAccount,
|
||||
...(ensureEnabled
|
||||
? {
|
||||
enabled:
|
||||
typeof existingAccount.enabled === "boolean" ? existingAccount.enabled : true,
|
||||
}
|
||||
: {}),
|
||||
...patch,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
return patchScopedAccountConfig({
|
||||
cfg: seededCfg,
|
||||
channelKey: channel,
|
||||
accountId,
|
||||
patch,
|
||||
ensureChannelEnabled: ensureEnabled,
|
||||
ensureAccountEnabled: ensureEnabled,
|
||||
});
|
||||
}
|
||||
|
||||
export function patchChannelConfigForAccount(params: {
|
||||
|
||||
@@ -125,6 +125,23 @@ export function applySetupAccountConfigPatch(params: {
|
||||
channelKey: string;
|
||||
accountId: string;
|
||||
patch: Record<string, unknown>;
|
||||
}): OpenClawConfig {
|
||||
return patchScopedAccountConfig({
|
||||
cfg: params.cfg,
|
||||
channelKey: params.channelKey,
|
||||
accountId: params.accountId,
|
||||
patch: params.patch,
|
||||
});
|
||||
}
|
||||
|
||||
export function patchScopedAccountConfig(params: {
|
||||
cfg: OpenClawConfig;
|
||||
channelKey: string;
|
||||
accountId: string;
|
||||
patch: Record<string, unknown>;
|
||||
accountPatch?: Record<string, unknown>;
|
||||
ensureChannelEnabled?: boolean;
|
||||
ensureAccountEnabled?: boolean;
|
||||
}): OpenClawConfig {
|
||||
const accountId = normalizeAccountId(params.accountId);
|
||||
const channels = params.cfg.channels as Record<string, unknown> | undefined;
|
||||
@@ -135,6 +152,10 @@ export function applySetupAccountConfigPatch(params: {
|
||||
accounts?: Record<string, Record<string, unknown>>;
|
||||
})
|
||||
: undefined;
|
||||
const ensureChannelEnabled = params.ensureChannelEnabled ?? true;
|
||||
const ensureAccountEnabled = params.ensureAccountEnabled ?? ensureChannelEnabled;
|
||||
const patch = params.patch;
|
||||
const accountPatch = params.accountPatch ?? patch;
|
||||
if (accountId === DEFAULT_ACCOUNT_ID) {
|
||||
return {
|
||||
...params.cfg,
|
||||
@@ -142,27 +163,33 @@ export function applySetupAccountConfigPatch(params: {
|
||||
...params.cfg.channels,
|
||||
[params.channelKey]: {
|
||||
...base,
|
||||
enabled: true,
|
||||
...params.patch,
|
||||
...(ensureChannelEnabled ? { enabled: true } : {}),
|
||||
...patch,
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
}
|
||||
|
||||
const accounts = base?.accounts ?? {};
|
||||
const existingAccount = accounts[accountId] ?? {};
|
||||
return {
|
||||
...params.cfg,
|
||||
channels: {
|
||||
...params.cfg.channels,
|
||||
[params.channelKey]: {
|
||||
...base,
|
||||
enabled: true,
|
||||
...(ensureChannelEnabled ? { enabled: true } : {}),
|
||||
accounts: {
|
||||
...accounts,
|
||||
[accountId]: {
|
||||
...accounts[accountId],
|
||||
enabled: true,
|
||||
...params.patch,
|
||||
...existingAccount,
|
||||
...(ensureAccountEnabled
|
||||
? {
|
||||
enabled:
|
||||
typeof existingAccount.enabled === "boolean" ? existingAccount.enabled : true,
|
||||
}
|
||||
: {}),
|
||||
...accountPatch,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -46,6 +46,7 @@ export { PAIRING_APPROVED_MESSAGE } from "../channels/plugins/pairing-message.js
|
||||
export {
|
||||
applyAccountNameToChannelSection,
|
||||
migrateBaseNameToDefaultAccount,
|
||||
patchScopedAccountConfig,
|
||||
} from "../channels/plugins/setup-helpers.js";
|
||||
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||
export { collectBlueBubblesStatusIssues } from "../channels/plugins/status-issues/bluebubbles.js";
|
||||
|
||||
@@ -546,7 +546,9 @@ export {
|
||||
} from "../channels/plugins/config-helpers.js";
|
||||
export {
|
||||
applyAccountNameToChannelSection,
|
||||
applySetupAccountConfigPatch,
|
||||
migrateBaseNameToDefaultAccount,
|
||||
patchScopedAccountConfig,
|
||||
} from "../channels/plugins/setup-helpers.js";
|
||||
export {
|
||||
buildOpenGroupPolicyConfigureRouteAllowlistWarning,
|
||||
|
||||
@@ -23,6 +23,7 @@ export {
|
||||
setTopLevelChannelDmPolicyWithAllowFrom,
|
||||
} from "../channels/plugins/onboarding/helpers.js";
|
||||
export { PAIRING_APPROVED_MESSAGE } from "../channels/plugins/pairing-message.js";
|
||||
export { patchScopedAccountConfig } from "../channels/plugins/setup-helpers.js";
|
||||
export type { BaseProbeResult } from "../channels/plugins/types.js";
|
||||
export type { ChannelPlugin } from "../channels/plugins/types.plugin.js";
|
||||
export { getChatChannelMeta } from "../channels/registry.js";
|
||||
|
||||
@@ -30,7 +30,10 @@ export {
|
||||
resolveAccountIdForConfigure,
|
||||
setTopLevelChannelDmPolicyWithAllowFrom,
|
||||
} from "../channels/plugins/onboarding/helpers.js";
|
||||
export { applyAccountNameToChannelSection } from "../channels/plugins/setup-helpers.js";
|
||||
export {
|
||||
applyAccountNameToChannelSection,
|
||||
patchScopedAccountConfig,
|
||||
} from "../channels/plugins/setup-helpers.js";
|
||||
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||
export type { ChannelGroupContext, ChannelSetupInput } from "../channels/plugins/types.js";
|
||||
export type { ChannelPlugin } from "../channels/plugins/types.plugin.js";
|
||||
|
||||
@@ -8,7 +8,10 @@ export {
|
||||
promptAccountId,
|
||||
resolveAccountIdForConfigure,
|
||||
} from "../channels/plugins/onboarding/helpers.js";
|
||||
export { applyAccountNameToChannelSection } from "../channels/plugins/setup-helpers.js";
|
||||
export {
|
||||
applyAccountNameToChannelSection,
|
||||
patchScopedAccountConfig,
|
||||
} from "../channels/plugins/setup-helpers.js";
|
||||
export type {
|
||||
ChannelAccountSnapshot,
|
||||
ChannelOutboundAdapter,
|
||||
|
||||
@@ -27,6 +27,7 @@ export {
|
||||
applyAccountNameToChannelSection,
|
||||
applySetupAccountConfigPatch,
|
||||
migrateBaseNameToDefaultAccount,
|
||||
patchScopedAccountConfig,
|
||||
} from "../channels/plugins/setup-helpers.js";
|
||||
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||
export type {
|
||||
|
||||
Reference in New Issue
Block a user