refactor: share exec approval dm route checks

This commit is contained in:
Peter Steinberger 2026-03-13 17:33:45 +00:00
parent 31c8bb9167
commit 3bf3ebf514
1 changed files with 19 additions and 14 deletions

View File

@ -50,8 +50,18 @@ export function resolveExecApprovalInitiatingSurfaceState(params: {
return { kind: "unsupported", channel, channelLabel };
}
export function hasConfiguredExecApprovalDmRoute(cfg: OpenClawConfig): boolean {
for (const account of listEnabledDiscordAccounts(cfg)) {
function hasExecApprovalDmRoute(
accounts: Array<{
config: {
execApprovals?: {
enabled?: boolean;
approvers?: unknown[];
target?: string;
};
};
}>,
): boolean {
for (const account of accounts) {
const execApprovals = account.config.execApprovals;
if (!execApprovals?.enabled || (execApprovals.approvers?.length ?? 0) === 0) {
continue;
@ -61,17 +71,12 @@ export function hasConfiguredExecApprovalDmRoute(cfg: OpenClawConfig): boolean {
return true;
}
}
for (const account of listEnabledTelegramAccounts(cfg)) {
const execApprovals = account.config.execApprovals;
if (!execApprovals?.enabled || (execApprovals.approvers?.length ?? 0) === 0) {
continue;
}
const target = execApprovals.target ?? "dm";
if (target === "dm" || target === "both") {
return true;
}
}
return false;
}
export function hasConfiguredExecApprovalDmRoute(cfg: OpenClawConfig): boolean {
return (
hasExecApprovalDmRoute(listEnabledDiscordAccounts(cfg)) ||
hasExecApprovalDmRoute(listEnabledTelegramAccounts(cfg))
);
}