openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
32 lines (31 loc) • 1.33 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { r as testRegexWithBoundedInput, t as compileSafeRegex } from "./safe-regex-sRheBeEI.mjs";
import { j as parseAgentSessionKey } from "./session-key-CqAyZeVk.mjs";
//#region src/infra/approval-request-filters.ts
/** Matches session filters as literal substrings first, then bounded safe regexes. */
function matchesApprovalRequestSessionFilter(e, t) {
return t.some((t) => {
if (e.includes(t)) return true;
const n = compileSafeRegex(t);
return n ? testRegexWithBoundedInput(n, e) : false;
});
}
/**
* Applies optional approval request filters for agent ids and session keys.
* Agent id can be parsed from the session key only when the caller opts in.
*/
function matchesApprovalRequestFilters(e) {
if (e.agentFilter?.length) {
const t = normalizeOptionalString(e.request.agentId);
const n = e.fallbackAgentIdFromSessionKey ? parseAgentSessionKey(e.request.sessionKey)?.agentId ?? void 0 : void 0;
const r = t ?? n;
if (!r || !e.agentFilter.includes(r)) return false;
}
if (e.sessionFilter?.length) {
const t = normalizeOptionalString(e.request.sessionKey);
if (!t || !matchesApprovalRequestSessionFilter(t, e.sessionFilter)) return false;
}
return true;
}
//#endregion
export { matchesApprovalRequestFilters as t };