mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 05:23:31 +00:00
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import type { OpenClawConfig } from "../../config/config.js";
|
|
import { DEFAULT_ACCOUNT_ID } from "../../routing/session-key.js";
|
|
|
|
export function createAccountListHelpers(channelKey: string) {
|
|
function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
|
|
const channel = cfg.channels?.[channelKey];
|
|
const accounts = (channel as Record<string, unknown> | undefined)?.accounts;
|
|
if (!accounts || typeof accounts !== "object") {
|
|
return [];
|
|
}
|
|
return Object.keys(accounts as Record<string, unknown>).filter(Boolean);
|
|
}
|
|
|
|
function listAccountIds(cfg: OpenClawConfig): string[] {
|
|
const ids = listConfiguredAccountIds(cfg);
|
|
if (ids.length === 0) {
|
|
return [DEFAULT_ACCOUNT_ID];
|
|
}
|
|
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
}
|
|
|
|
function resolveDefaultAccountId(cfg: OpenClawConfig): string {
|
|
const ids = listAccountIds(cfg);
|
|
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
return DEFAULT_ACCOUNT_ID;
|
|
}
|
|
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
}
|
|
|
|
return { listConfiguredAccountIds, listAccountIds, resolveDefaultAccountId };
|
|
}
|