refactor: dedupe auto-reply lowercase readers

This commit is contained in:
Peter Steinberger
2026-04-07 12:09:07 +01:00
parent 934927fd13
commit 353678ec05
13 changed files with 67 additions and 39 deletions

View File

@@ -1,3 +1,5 @@
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
export type {
AllowlistMatch,
AllowlistMatchSource,
@@ -36,7 +38,8 @@ export function formatAllowFromLowercase(params: {
.map((entry) => String(entry).trim())
.filter(Boolean)
.map((entry) => (params.stripPrefixRe ? entry.replace(params.stripPrefixRe, "") : entry))
.map((entry) => entry.toLowerCase());
.map((entry) => normalizeOptionalLowercaseString(entry))
.filter((entry): entry is string => Boolean(entry));
}
/** Normalize allowlist entries through a channel-provided parser or canonicalizer. */
@@ -67,7 +70,7 @@ export function isNormalizedSenderAllowed(params: {
if (normalizedAllow.includes("*")) {
return true;
}
const sender = String(params.senderId).trim().toLowerCase();
const sender = normalizeOptionalLowercaseString(String(params.senderId));
return normalizedAllow.includes(sender);
}

View File

@@ -4,7 +4,10 @@ import { matchesApprovalRequestFilters } from "../infra/approval-request-filters
import { getExecApprovalReplyMetadata } from "../infra/exec-approval-reply.js";
import type { ExecApprovalRequest } from "../infra/exec-approvals.js";
import type { PluginApprovalRequest } from "../infra/plugin-approvals.js";
import { normalizeOptionalString } from "../shared/string-coerce.js";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
} from "../shared/string-coerce.js";
import type { OpenClawConfig } from "./config-runtime.js";
import { normalizeAccountId } from "./routing.js";
@@ -58,7 +61,7 @@ export function isChannelExecApprovalTargetRecipient(params: {
}): boolean {
const normalizeSenderId = params.normalizeSenderId ?? normalizeOptionalString;
const normalizedSenderId = params.senderId ? normalizeSenderId(params.senderId) : undefined;
const normalizedChannel = params.channel.trim().toLowerCase();
const normalizedChannel = normalizeOptionalLowercaseString(params.channel);
if (!normalizedSenderId || !isApprovalTargetsMode(params.cfg)) {
return false;
}
@@ -68,7 +71,7 @@ export function isChannelExecApprovalTargetRecipient(params: {
}
const normalizedAccountId = params.accountId ? normalizeAccountId(params.accountId) : undefined;
return targets.some((target) => {
if (target.channel?.trim().toLowerCase() !== normalizedChannel) {
if (normalizeOptionalLowercaseString(target.channel) !== normalizedChannel) {
return false;
}
if (

View File

@@ -15,6 +15,7 @@ import type { ChannelConfigAdapter } from "../channels/plugins/types.adapters.js
import { formatCliCommand } from "../cli/command-format.js";
import type { OpenClawConfig } from "../config/config.js";
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
import { normalizeStringEntries } from "../shared/string-normalization.js";
const INTERNAL_MESSAGE_CHANNEL = "webchat";
@@ -113,7 +114,7 @@ export function canBypassConfigWritePolicy(params: {
return canBypassConfigWritePolicyShared({
...params,
isInternalMessageChannel: (channel) =>
channel?.trim().toLowerCase() === INTERNAL_MESSAGE_CHANNEL,
normalizeOptionalLowercaseString(channel) === INTERNAL_MESSAGE_CHANNEL,
});
}