mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
fix: merge top-level config into per-account config so inherited settings apply
This commit is contained in:
committed by
Peter Steinberger
parent
ed5a8dff8a
commit
3985ef7b37
@@ -3,6 +3,22 @@ import type { CoreConfig, MatrixConfig } from "../types.js";
|
||||
import { resolveMatrixConfigForAccount } from "./client.js";
|
||||
import { credentialsMatchConfig, loadMatrixCredentials } from "./credentials.js";
|
||||
|
||||
/** Merge account config with top-level defaults, preserving nested objects. */
|
||||
function mergeAccountConfig(base: MatrixConfig, account: MatrixConfig): MatrixConfig {
|
||||
const merged = { ...base, ...account };
|
||||
// Deep-merge known nested objects so partial overrides inherit base fields
|
||||
for (const key of ["dm", "actions"] as const) {
|
||||
const b = base[key];
|
||||
const o = account[key];
|
||||
if (typeof b === "object" && b != null && typeof o === "object" && o != null) {
|
||||
(merged as Record<string, unknown>)[key] = { ...b, ...o };
|
||||
}
|
||||
}
|
||||
// Don't propagate the accounts map into the merged per-account config
|
||||
delete (merged as Record<string, unknown>).accounts;
|
||||
return merged;
|
||||
}
|
||||
|
||||
export type ResolvedMatrixAccount = {
|
||||
accountId: string;
|
||||
enabled: boolean;
|
||||
@@ -74,8 +90,12 @@ export function resolveMatrixAccount(params: {
|
||||
// Check if this account exists in accounts structure
|
||||
const accountConfig = resolveAccountConfig(params.cfg, accountId);
|
||||
|
||||
// Use account-specific config if available, otherwise fall back to top-level
|
||||
const base: MatrixConfig = accountConfig ?? matrixBase;
|
||||
// Merge account-specific config with top-level defaults so settings like
|
||||
// blockStreaming, groupPolicy, etc. inherit from channels.matrix when not
|
||||
// overridden per account.
|
||||
const base: MatrixConfig = accountConfig
|
||||
? mergeAccountConfig(matrixBase, accountConfig)
|
||||
: matrixBase;
|
||||
const enabled = base.enabled !== false && matrixBase.enabled !== false;
|
||||
|
||||
const resolved = resolveMatrixConfigForAccount(params.cfg, accountId, process.env);
|
||||
|
||||
Reference in New Issue
Block a user