UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

63 lines (62 loc) • 2.23 kB
import { n as sanitizeExecApprovalDisplayText, t as exceedsApprovalTextLimit } from "./exec-approval-text-sanitize-Xx3Q87a8.mjs"; //#region src/infra/approval-scope.ts function summarizeApprovalScope(e) { switch (e.kind) { case "message-send": { const t = e.recipientCount === 1 ? "recipient" : "recipients"; const n = e.audience ? ` (${e.audience})` : ""; const r = e.recipients ?? []; const i = e.recipientCount - r.length; const a = r.length ? `: ${[...r, ...i > 0 ? [`+${i} more`] : []].join(", ")}` : ""; return `Send to ${e.recipientCount} ${t} via ${e.target}${n}${a}`; } case "payment": return `Pay ${e.amount} ${e.currency} to ${e.target}`; case "external-post": return `Post ${e.visibility === "public" ? "publicly" : "restricted"} to ${e.target}`; case "standing-grant": { const t = e.expiresInDays !== void 0 ? `for ${e.expiresInDays} days` : "until revoked"; return `Always allow runs this exact command for "${e.automation}" without asking, ${t} (revocable)`; } } throw new Error("Unsupported approval scope"); } function sanitizeApprovalScope(e) { if (e.kind === "standing-grant") { const t = sanitizeExecApprovalDisplayText(e.automation); const n = sanitizeExecApprovalDisplayText(e.command); return exceedsApprovalTextLimit(t, 128) || exceedsApprovalTextLimit(n, 256) ? null : { ...e, automation: t, command: n }; } const t = sanitizeExecApprovalDisplayText(e.target); if (exceedsApprovalTextLimit(t, 128)) return null; switch (e.kind) { case "message-send": { const n = e.recipients?.slice(0, e.recipientCount).map(sanitizeExecApprovalDisplayText); if (n?.some((e) => exceedsApprovalTextLimit(e, 128))) return null; return { ...e, target: t, ...n ? { recipients: n } : {} }; } case "payment": { const n = sanitizeExecApprovalDisplayText(e.amount); const r = sanitizeExecApprovalDisplayText(e.currency); return exceedsApprovalTextLimit(n, 40) || exceedsApprovalTextLimit(r, 12) ? null : { ...e, amount: n, currency: r, target: t }; } case "external-post": return { ...e, target: t }; } return null; } //#endregion export { summarizeApprovalScope as n, sanitizeApprovalScope as t };