refactor: share allowFrom stringification helpers

This commit is contained in:
Peter Steinberger
2026-03-07 23:24:45 +00:00
parent 99d14a820a
commit c5bd84309a
7 changed files with 16 additions and 16 deletions

View File

@@ -5,6 +5,7 @@ import type { OpenClawConfig } from "../../config/config.js";
import type { SessionEntry } from "../../config/sessions.js";
import type { AgentDefaultsConfig } from "../../config/types.agent-defaults.js";
import { parseDiscordTarget } from "../../discord/targets.js";
import { mapAllowFromEntries } from "../../plugin-sdk/channel-config-helpers.js";
import { normalizeAccountId } from "../../routing/session-key.js";
import { parseSlackTarget } from "../../slack/targets.js";
import { parseTelegramTarget, resolveTelegramTargetChatType } from "../../telegram/targets.js";
@@ -203,7 +204,7 @@ export function resolveOutboundTarget(params: {
accountId: params.accountId ?? undefined,
})
: undefined);
const allowFrom = allowFromRaw?.map((entry) => String(entry));
const allowFrom = allowFromRaw ? mapAllowFromEntries(allowFromRaw) : undefined;
// Fall back to per-channel defaultTo when no explicit target is provided.
const effectiveTo =
@@ -496,9 +497,7 @@ function resolveHeartbeatSenderId(params: {
provider && lastTo ? `${provider}:${lastTo}` : undefined,
].filter((val): val is string => Boolean(val?.trim()));
const allowList = allowFrom
.map((entry) => String(entry))
.filter((entry) => entry && entry !== "*");
const allowList = mapAllowFromEntries(allowFrom).filter((entry) => entry && entry !== "*");
if (allowFrom.includes("*")) {
return candidates[0] ?? "heartbeat";
}
@@ -536,7 +535,7 @@ export function resolveHeartbeatSenderContext(params: {
accountId,
}) ?? [])
: [];
const allowFrom = allowFromRaw.map((entry) => String(entry));
const allowFrom = mapAllowFromEntries(allowFromRaw);
const sender = resolveHeartbeatSenderId({
allowFrom,

View File

@@ -1,3 +1,5 @@
import { mapAllowFromEntries } from "../plugin-sdk/channel-config-helpers.js";
export function normalizeNonEmptyString(value: unknown): string | null {
if (typeof value !== "string") {
return null;
@@ -7,5 +9,5 @@ export function normalizeNonEmptyString(value: unknown): string | null {
}
export function normalizeStringArray(value: unknown): string[] {
return Array.isArray(value) ? value.map((entry) => String(entry)) : [];
return Array.isArray(value) ? mapAllowFromEntries(value) : [];
}