refactor: share trimmed string entry normalization

This commit is contained in:
Peter Steinberger
2026-03-07 23:11:04 +00:00
parent 6647d02846
commit d228a62143
12 changed files with 29 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ import { getChannelDock, listChannelDocks } from "../channels/dock.js";
import type { ChannelId } from "../channels/plugins/types.js";
import { normalizeAnyChannelId } from "../channels/registry.js";
import type { OpenClawConfig } from "../config/config.js";
import { normalizeStringEntries } from "../shared/string-normalization.js";
import {
INTERNAL_MESSAGE_CHANNEL,
isInternalMessageChannel,
@@ -85,7 +86,7 @@ function formatAllowFromList(params: {
if (dock?.config?.formatAllowFrom) {
return dock.config.formatAllowFrom({ cfg, accountId, allowFrom });
}
return allowFrom.map((entry) => String(entry).trim()).filter(Boolean);
return normalizeStringEntries(allowFrom);
}
function normalizeAllowFromEntry(params: {

View File

@@ -23,6 +23,7 @@ import {
normalizeAccountId,
normalizeOptionalAccountId,
} from "../../routing/session-key.js";
import { normalizeStringEntries } from "../../shared/string-normalization.js";
import { resolveSignalAccount } from "../../signal/accounts.js";
import { resolveSlackAccount } from "../../slack/accounts.js";
import { resolveSlackUserAllowlist } from "../../slack/resolve-users.js";
@@ -165,7 +166,7 @@ function normalizeAllowFrom(params: {
allowFrom: params.values,
});
}
return params.values.map((entry) => String(entry).trim()).filter(Boolean);
return normalizeStringEntries(params.values);
}
function formatEntryList(entries: string[], resolved?: Map<string, string>): string {

View File

@@ -12,6 +12,7 @@ import { type OpenClawConfig, loadConfig } from "../../config/config.js";
import { applyLinkUnderstanding } from "../../link-understanding/apply.js";
import { applyMediaUnderstanding } from "../../media-understanding/apply.js";
import { defaultRuntime } from "../../runtime.js";
import { normalizeStringEntries } from "../../shared/string-normalization.js";
import { resolveCommandAuthorization } from "../command-auth.js";
import type { MsgContext } from "../templating.js";
import { SILENT_REPLY_TOKEN } from "../tokens.js";
@@ -33,7 +34,7 @@ function mergeSkillFilters(channelFilter?: string[], agentFilter?: string[]): st
if (!Array.isArray(list)) {
return undefined;
}
return list.map((entry) => String(entry).trim()).filter(Boolean);
return normalizeStringEntries(list);
};
const channel = normalize(channelFilter);
const agent = normalize(agentFilter);

View File

@@ -2,6 +2,7 @@ import { resolveAgentConfig } from "../../agents/agent-scope.js";
import { getChannelDock } from "../../channels/dock.js";
import { normalizeChannelId } from "../../channels/plugins/index.js";
import type { AgentElevatedAllowFromConfig, OpenClawConfig } from "../../config/config.js";
import { normalizeStringEntries } from "../../shared/string-normalization.js";
import type { MsgContext } from "../templating.js";
import {
type AllowFromFormatter,
@@ -36,7 +37,7 @@ function resolveAllowFromFormatter(params: {
const dock = normalizedProvider ? getChannelDock(normalizedProvider) : undefined;
const formatAllowFrom = dock?.config?.formatAllowFrom;
if (!formatAllowFrom) {
return (values) => values.map((entry) => String(entry).trim()).filter(Boolean);
return (values) => normalizeStringEntries(values);
}
return (values) =>
formatAllowFrom({
@@ -64,7 +65,7 @@ function isApprovedElevatedSender(params: {
return false;
}
const allowTokens = rawAllow.map((entry) => String(entry).trim()).filter(Boolean);
const allowTokens = normalizeStringEntries(rawAllow);
if (allowTokens.length === 0) {
return false;
}