UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

24 lines (23 loc) • 1.12 kB
import { s as wrapExternalContent } from "./external-content-DZI9vlJn.js"; //#region src/security/channel-metadata.ts const DEFAULT_MAX_CHARS = 800; const DEFAULT_MAX_ENTRY_CHARS = 400; function normalizeEntry(entry) { return entry.replace(/\s+/g, " ").trim(); } function truncateText(value, maxChars) { if (maxChars <= 0) return ""; if (value.length <= maxChars) return value; return `${value.slice(0, Math.max(0, maxChars - 3)).trimEnd()}...`; } function buildUntrustedChannelMetadata(params) { const deduped = params.entries.map((entry) => typeof entry === "string" ? normalizeEntry(entry) : "").filter((entry) => Boolean(entry)).map((entry) => truncateText(entry, DEFAULT_MAX_ENTRY_CHARS)).filter((entry, index, list) => list.indexOf(entry) === index); if (deduped.length === 0) return; const body = deduped.join("\n"); return wrapExternalContent(truncateText(`${`UNTRUSTED channel metadata (${params.source})`}\n${`${params.label}:\n${body}`}`, params.maxChars ?? DEFAULT_MAX_CHARS), { source: "channel_metadata", includeWarning: false }); } //#endregion export { buildUntrustedChannelMetadata as t };