mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 07:01:40 +03:00
fix: normalize account config keys for case-insensitive matching
This commit is contained in:
committed by
Peter Steinberger
parent
c89b8d99fc
commit
a6dd50fede
@@ -18,7 +18,10 @@ function listConfiguredAccountIds(cfg: CoreConfig): string[] {
|
|||||||
if (!accounts || typeof accounts !== "object") {
|
if (!accounts || typeof accounts !== "object") {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return Object.keys(accounts).filter(Boolean);
|
// Normalize keys so listing and resolution use the same semantics
|
||||||
|
return Object.keys(accounts)
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((id) => normalizeAccountId(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listMatrixAccountIds(cfg: CoreConfig): string[] {
|
export function listMatrixAccountIds(cfg: CoreConfig): string[] {
|
||||||
@@ -43,7 +46,18 @@ function resolveAccountConfig(cfg: CoreConfig, accountId: string): MatrixConfig
|
|||||||
if (!accounts || typeof accounts !== "object") {
|
if (!accounts || typeof accounts !== "object") {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return accounts[accountId] as MatrixConfig | undefined;
|
// Direct lookup first (fast path for already-normalized keys)
|
||||||
|
if (accounts[accountId]) {
|
||||||
|
return accounts[accountId] as MatrixConfig;
|
||||||
|
}
|
||||||
|
// Fall back to case-insensitive match (user may have mixed-case keys in config)
|
||||||
|
const normalized = normalizeAccountId(accountId);
|
||||||
|
for (const key of Object.keys(accounts)) {
|
||||||
|
if (normalizeAccountId(key) === normalized) {
|
||||||
|
return accounts[key] as MatrixConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveMatrixAccount(params: {
|
export function resolveMatrixAccount(params: {
|
||||||
|
|||||||
@@ -22,8 +22,16 @@ export function resolveMatrixConfigForAccount(
|
|||||||
const normalizedAccountId = normalizeAccountId(accountId);
|
const normalizedAccountId = normalizeAccountId(accountId);
|
||||||
const matrixBase = cfg.channels?.matrix ?? {};
|
const matrixBase = cfg.channels?.matrix ?? {};
|
||||||
|
|
||||||
// Try to get account-specific config first
|
// Try to get account-specific config first (direct lookup, then case-insensitive fallback)
|
||||||
const accountConfig = matrixBase.accounts?.[normalizedAccountId];
|
let accountConfig = matrixBase.accounts?.[normalizedAccountId];
|
||||||
|
if (!accountConfig && matrixBase.accounts) {
|
||||||
|
for (const key of Object.keys(matrixBase.accounts)) {
|
||||||
|
if (normalizeAccountId(key) === normalizedAccountId) {
|
||||||
|
accountConfig = matrixBase.accounts[key];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Merge: account-specific values override top-level values
|
// Merge: account-specific values override top-level values
|
||||||
// For DEFAULT_ACCOUNT_ID with no accounts, use top-level directly
|
// For DEFAULT_ACCOUNT_ID with no accounts, use top-level directly
|
||||||
|
|||||||
Reference in New Issue
Block a user