mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 11:10:20 +00:00
fix: respect approval request filters in ambiguity checks
This commit is contained in:
@@ -292,6 +292,59 @@ describe("telegram exec approvals", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("uses request filters when checking foreign-channel telegram ambiguity", () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
telegram: {
|
||||
accounts: {
|
||||
default: {
|
||||
botToken: "tok-default",
|
||||
execApprovals: {
|
||||
enabled: true,
|
||||
approvers: ["123"],
|
||||
agentFilter: ["ops"],
|
||||
},
|
||||
},
|
||||
ops: {
|
||||
botToken: "tok-ops",
|
||||
execApprovals: {
|
||||
enabled: true,
|
||||
approvers: ["123"],
|
||||
agentFilter: ["other"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const request = {
|
||||
id: "req-5",
|
||||
request: {
|
||||
command: "echo hi",
|
||||
sessionKey: "agent:ops:missing",
|
||||
turnSourceChannel: "slack",
|
||||
turnSourceTo: "channel:C123",
|
||||
},
|
||||
createdAtMs: 0,
|
||||
expiresAtMs: 1000,
|
||||
};
|
||||
|
||||
expect(
|
||||
shouldHandleTelegramExecApprovalRequest({
|
||||
cfg,
|
||||
accountId: "default",
|
||||
request,
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldHandleTelegramExecApprovalRequest({
|
||||
cfg,
|
||||
accountId: "ops",
|
||||
request,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("ignores disabled telegram accounts when checking foreign-channel ambiguity", () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
@@ -317,7 +370,7 @@ describe("telegram exec approvals", () => {
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const request = {
|
||||
id: "req-5",
|
||||
id: "req-6",
|
||||
request: {
|
||||
command: "echo hi",
|
||||
sessionKey: "agent:ops:missing",
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
createChannelExecApprovalProfile,
|
||||
isChannelExecApprovalClientEnabledFromConfig,
|
||||
isChannelExecApprovalTargetRecipient,
|
||||
matchesApprovalRequestFilters,
|
||||
resolveApprovalRequestChannelAccountId,
|
||||
resolveApprovalApprovers,
|
||||
} from "openclaw/plugin-sdk/approval-runtime";
|
||||
@@ -73,16 +74,31 @@ export function isTelegramExecApprovalTargetRecipient(params: {
|
||||
});
|
||||
}
|
||||
|
||||
function countTelegramExecApprovalHandlerAccounts(cfg: OpenClawConfig): number {
|
||||
return listTelegramAccountIds(cfg).filter((accountId) => {
|
||||
const account = resolveTelegramAccount({ cfg, accountId });
|
||||
function countTelegramExecApprovalEligibleAccounts(params: {
|
||||
cfg: OpenClawConfig;
|
||||
request: ExecApprovalRequest | PluginApprovalRequest;
|
||||
}): number {
|
||||
return listTelegramAccountIds(params.cfg).filter((accountId) => {
|
||||
const account = resolveTelegramAccount({ cfg: params.cfg, accountId });
|
||||
if (!account.enabled || account.tokenSource === "none") {
|
||||
return false;
|
||||
}
|
||||
return isChannelExecApprovalClientEnabledFromConfig({
|
||||
enabled: resolveTelegramExecApprovalConfig({ cfg, accountId })?.enabled,
|
||||
approverCount: getTelegramExecApprovalApprovers({ cfg, accountId }).length,
|
||||
const config = resolveTelegramExecApprovalConfig({
|
||||
cfg: params.cfg,
|
||||
accountId,
|
||||
});
|
||||
return (
|
||||
isChannelExecApprovalClientEnabledFromConfig({
|
||||
enabled: config?.enabled,
|
||||
approverCount: getTelegramExecApprovalApprovers({ cfg: params.cfg, accountId }).length,
|
||||
}) &&
|
||||
matchesApprovalRequestFilters({
|
||||
request: params.request.request,
|
||||
agentFilter: config?.agentFilter,
|
||||
sessionFilter: config?.sessionFilter,
|
||||
fallbackAgentIdFromSessionKey: true,
|
||||
})
|
||||
);
|
||||
}).length;
|
||||
}
|
||||
|
||||
@@ -98,7 +114,12 @@ function matchesTelegramRequestAccount(params: {
|
||||
channel: "telegram",
|
||||
});
|
||||
if (turnSourceChannel && turnSourceChannel !== "telegram" && !boundAccountId) {
|
||||
return countTelegramExecApprovalHandlerAccounts(params.cfg) <= 1;
|
||||
return (
|
||||
countTelegramExecApprovalEligibleAccounts({
|
||||
cfg: params.cfg,
|
||||
request: params.request,
|
||||
}) <= 1
|
||||
);
|
||||
}
|
||||
return (
|
||||
!boundAccountId ||
|
||||
|
||||
Reference in New Issue
Block a user