openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
51 lines (50 loc) • 2.3 kB
JavaScript
import { y as uniqueStrings } from "./string-normalization-DsCfAx8q.js";
import { i as truncateWithMarker } from "./utf16-slice-D_ngcYKd.js";
import "./fs-safe-defaults-DGE52WTl.js";
import "./redact-BtvPPfTi.js";
import "./fs-safe-B6pvPGnf.js";
import "./path-guards-Cp-mGr3-.js";
import "./safe-regex-BQnlv3bA.js";
import "./errors-Db3Ymjlb.js";
import "./replace-file-BAJ-TWzD.js";
import "./private-file-store-CaBdNw0y.js";
import "./proxy-env-BepksPz2.js";
import "./ports-CU06KPCY.js";
import "./ssrf-0QyXWOVG.js";
import { a as wrapExternalContent } from "./external-content-CpqslxXH.js";
import "./dm-policy-shared-BrXqldwA.js";
import "./file-access-runtime-CfcyqU8y.js";
import { pathScope, resolveExistingPathsWithinRoot, resolveStrictExistingPathsWithinRoot } from "@openclaw/fs-safe/advanced";
//#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 "";
return truncateWithMarker(value, maxChars, {
marker: "...",
reserve: 3,
trimEnd: true
});
}
/**
* Build bounded, externally wrapped channel metadata for prompt context.
* Channel-provided labels can be user-controlled, so keep the result externally wrapped.
*/
function buildChannelMetadata(params) {
const cleaned = params.entries.map((entry) => typeof entry === "string" ? normalizeEntry(entry) : "").filter((entry) => Boolean(entry)).map((entry) => truncateText(entry, DEFAULT_MAX_ENTRY_CHARS));
const deduped = uniqueStrings(cleaned);
if (deduped.length === 0) return;
const body = deduped.join("\n");
const truncated = truncateText(`${`Channel metadata (${params.source})`}\n${`${params.label}:\n${body}`}`, params.maxChars ?? DEFAULT_MAX_CHARS);
return wrapExternalContent(truncated, {
source: "channel_metadata",
includeWarning: false
});
}
/** @deprecated Use buildChannelMetadata. Removal: after 2026-09-08 (see sdk-untrusted-context-identifier-aliases). */
const buildUntrustedChannelMetadata = buildChannelMetadata;
//#endregion
export { buildUntrustedChannelMetadata as a, buildChannelMetadata as i, resolveExistingPathsWithinRoot as n, resolveStrictExistingPathsWithinRoot as r, pathScope as t };