mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:20:43 +00:00
refactor: share configured account id helper
This commit is contained in:
17
src/plugin-sdk/account-configured-ids.ts
Normal file
17
src/plugin-sdk/account-configured-ids.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/** List normalized configured account ids from a raw channel account record map. */
|
||||
export function listConfiguredAccountIds(params: {
|
||||
accounts: Record<string, unknown> | undefined;
|
||||
normalizeAccountId: (accountId: string) => string;
|
||||
}): string[] {
|
||||
if (!params.accounts) {
|
||||
return [];
|
||||
}
|
||||
const ids = new Set<string>();
|
||||
for (const key of Object.keys(params.accounts)) {
|
||||
if (!key) {
|
||||
continue;
|
||||
}
|
||||
ids.add(params.normalizeAccountId(key));
|
||||
}
|
||||
return [...ids];
|
||||
}
|
||||
@@ -17,6 +17,7 @@ export {
|
||||
normalizeOptionalAccountId,
|
||||
} from "../routing/session-key.js";
|
||||
export { normalizeE164, pathExists, resolveUserPath } from "../utils.js";
|
||||
export { listConfiguredAccountIds } from "./account-configured-ids.js";
|
||||
|
||||
/** Resolve an account by id, then fall back to the default account when the primary lacks credentials. */
|
||||
export function resolveAccountWithDefaultFallback<TAccount>(params: {
|
||||
@@ -43,21 +44,3 @@ export function resolveAccountWithDefaultFallback<TAccount>(params: {
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/** List normalized configured account ids from a raw channel account record map. */
|
||||
export function listConfiguredAccountIds(params: {
|
||||
accounts: Record<string, unknown> | undefined;
|
||||
normalizeAccountId: (accountId: string) => string;
|
||||
}): string[] {
|
||||
if (!params.accounts) {
|
||||
return [];
|
||||
}
|
||||
const ids = new Set<string>();
|
||||
for (const key of Object.keys(params.accounts)) {
|
||||
if (!key) {
|
||||
continue;
|
||||
}
|
||||
ids.add(params.normalizeAccountId(key));
|
||||
}
|
||||
return [...ids];
|
||||
}
|
||||
|
||||
@@ -1,20 +1,3 @@
|
||||
export { resolveMergedAccountConfig } from "../channels/plugins/account-helpers.js";
|
||||
export { resolveNormalizedAccountEntry } from "../routing/account-lookup.js";
|
||||
|
||||
/** List normalized configured account ids from a raw channel account record map. */
|
||||
export function listConfiguredAccountIds(params: {
|
||||
accounts: Record<string, unknown> | undefined;
|
||||
normalizeAccountId: (accountId: string) => string;
|
||||
}): string[] {
|
||||
if (!params.accounts) {
|
||||
return [];
|
||||
}
|
||||
const ids = new Set<string>();
|
||||
for (const key of Object.keys(params.accounts)) {
|
||||
if (!key) {
|
||||
continue;
|
||||
}
|
||||
ids.add(params.normalizeAccountId(key));
|
||||
}
|
||||
return [...ids];
|
||||
}
|
||||
export { listConfiguredAccountIds } from "./account-configured-ids.js";
|
||||
|
||||
Reference in New Issue
Block a user