refactor: share normalized account lookups

This commit is contained in:
Peter Steinberger
2026-03-22 18:24:20 +00:00
parent 017d295edb
commit d06413e335
10 changed files with 132 additions and 41 deletions

View File

@@ -81,6 +81,29 @@ describe("resolveDefaultIrcAccountId", () => {
});
describe("resolveIrcAccount", () => {
it("matches normalized configured account ids", () => {
const account = resolveIrcAccount({
cfg: asConfig({
channels: {
irc: {
accounts: {
"Ops Team": {
host: "irc.example.com",
nick: "claw",
},
},
},
},
}),
accountId: "ops-team",
});
expect(account.accountId).toBe("ops-team");
expect(account.host).toBe("irc.example.com");
expect(account.nick).toBe("claw");
expect(account.configured).toBe(true);
});
it("parses delimited IRC_CHANNELS env values for the default account", () => {
const previousChannels = process.env.IRC_CHANNELS;
process.env.IRC_CHANNELS = "alpha, beta\ngamma; delta";

View File

@@ -1,5 +1,6 @@
import { createAccountListHelpers, mergeAccountConfig } from "openclaw/plugin-sdk/account-helpers";
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
import { resolveNormalizedAccountEntry } from "openclaw/plugin-sdk/account-resolution";
import { parseOptionalDelimitedEntries } from "openclaw/plugin-sdk/core";
import { tryReadSecretFileSync } from "openclaw/plugin-sdk/infra-runtime";
import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
@@ -46,17 +47,11 @@ const { listAccountIds: listIrcAccountIds, resolveDefaultAccountId: resolveDefau
export { listIrcAccountIds, resolveDefaultIrcAccountId };
function resolveAccountConfig(cfg: CoreConfig, accountId: string): IrcAccountConfig | undefined {
const accounts = cfg.channels?.irc?.accounts;
if (!accounts || typeof accounts !== "object") {
return undefined;
}
const direct = accounts[accountId] as IrcAccountConfig | undefined;
if (direct) {
return direct;
}
const normalized = normalizeAccountId(accountId);
const matchKey = Object.keys(accounts).find((key) => normalizeAccountId(key) === normalized);
return matchKey ? (accounts[matchKey] as IrcAccountConfig | undefined) : undefined;
return resolveNormalizedAccountEntry(
cfg.channels?.irc?.accounts as Record<string, IrcAccountConfig> | undefined,
accountId,
normalizeAccountId,
);
}
function mergeIrcAccountConfig(cfg: CoreConfig, accountId: string): IrcAccountConfig {