UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

90 lines (89 loc) • 4.96 kB
import { i as truncateWithMarker } from "./utf16-slice-CuDyEXgS.mjs"; import { n as buildSystemAgentApprovalResolvedText, r as formatApprovalDecisionLabel } from "./approval-terminal-CZf0AP8U.mjs"; import "./approval-runtime-BKgoNao7.mjs"; //#region extensions/telegram/src/approval-terminal.ts const TELEGRAM_APPROVAL_DETAIL_MAX_CHARS = 2800; const TELEGRAM_APPROVAL_ID_MAX_CHARS = 512; const TELEGRAM_APPROVAL_TERMINAL_MAX_CHARS = 4e3; function formatApprovalDecision(e) { return e ? formatApprovalDecisionLabel(e) : "Resolved"; } function formatCanonicalResult(e) { if (e.status === "allowed" || e.status === "denied") return formatApprovalDecision(e.decision); return e.status === "expired" ? "Expired" : "Cancelled"; } function truncateApprovalText(e, t, n = false) { return truncateWithMarker(e, t, { marker: "…", reserve: 1, trimEnd: !n }); } function truncateDetail(e) { return truncateApprovalText(e.trim(), TELEGRAM_APPROVAL_DETAIL_MAX_CHARS); } function truncateApprovalId(e) { return truncateApprovalText(JSON.stringify(e).slice(1, -1), TELEGRAM_APPROVAL_ID_MAX_CHARS, true); } function finalizeTerminalText(e) { return truncateApprovalText(e.join("\n"), TELEGRAM_APPROVAL_TERMINAL_MAX_CHARS); } function appendApprovalSubject(e, t, n, r) { e.push("", t, truncateDetail(n)); if (r) e.push(truncateDetail(r)); } /** Render the canonical first-answer result returned to a Telegram callback surface. */ function buildTelegramCanonicalApprovalTerminalText(e) { const t = e.result.approval; if (t.presentation?.kind === "system-agent" && e.result.applied) { if (t.status === "allowed") return `✅ OpenClaw change approved. Applying: ${truncateDetail(t.presentation.description)}`; return { cancelled: "⚠️ OpenClaw change was cancelled because its run ended. No change was made. Retry.", denied: "❌ OpenClaw change denied. No change was made.", expired: "⏱️ OpenClaw change expired. No change was made." }[t.status]; } const n = t.id || e.fallbackApprovalId; const r = [ e.result.applied ? "✅ Approval resolved here" : "ℹ️ Approval already resolved", `Recorded result: ${formatCanonicalResult(t)}`, `ID: ${truncateApprovalId(n)}` ]; if (t.presentation) { const e = t.presentation; appendApprovalSubject(r, e.kind === "exec" ? "Command:" : "Request:", e.kind === "exec" ? e.commandPreview ?? e.commandText : e.title, e.kind === "exec" ? void 0 : e.description.trim()); } return finalizeTerminalText(r); } /** Render a truthful receipt for a legacy callback without a canonical snapshot. */ function buildTelegramLegacyApprovalTerminalText(e) { const t = e.outcome === "resolved-here" ? ["✅ Approval resolved here", `Result: ${formatApprovalDecision(e.decision)}`] : e.outcome === "no-longer-pending" ? ["ℹ️ Approval no longer pending", "It was already resolved or expired; the recorded decision is unavailable here."] : ["ℹ️ Approval is no longer actionable from this button", "It may have been resolved, expired, or require a different authorized approval surface."]; t.push(`ID: ${truncateApprovalId(e.approvalId)}`); return finalizeTerminalText(t); } /** Render a neutral terminal receipt for malformed callbacks in the reserved namespace. */ function buildTelegramInvalidApprovalTerminalText() { return "ℹ️ Approval action unavailable\nThis button is invalid or no longer actionable."; } /** Render a canonical native resolved event while retaining safe request context. */ function buildTelegramNativeResolvedApprovalText(e) { if (e.approvalKind === "system-agent") return buildSystemAgentApprovalResolvedText({ ...e, operationSummary: truncateDetail(e.operationSummary) }); const t = [`✅ ${e.approvalKind === "exec" ? "Exec" : "Plugin"} approval resolved`, `Recorded result: ${formatApprovalDecision(e.decision)}`]; if (e.resolvedBy?.trim()) t.push(`Resolved by: ${truncateDetail(e.resolvedBy.replace(/\s+/gu, " "))}`); return finalizeNativeApprovalText(e, t); } /** Render a canonical native expiration event while retaining safe request context. */ function buildTelegramNativeExpiredApprovalText(e) { if (e.approvalKind === "system-agent") return "⏱️ OpenClaw change expired. No change was made."; return finalizeNativeApprovalText(e, [`⏱️ ${e.approvalKind === "exec" ? "Exec" : "Plugin"} approval expired`, "Recorded result: Expired"]); } function finalizeNativeApprovalText(e, t) { t.push(`ID: ${truncateApprovalId(e.approvalId)}`); appendApprovalSubject(t, e.approvalKind === "exec" ? "Command:" : "Request:", e.approvalKind === "exec" ? e.commandPreview ?? e.commandText : e.title, e.approvalKind === "exec" ? void 0 : e.description?.trim()); return finalizeTerminalText(t); } //#endregion export { buildTelegramNativeResolvedApprovalText as a, buildTelegramNativeExpiredApprovalText as i, buildTelegramInvalidApprovalTerminalText as n, buildTelegramLegacyApprovalTerminalText as r, buildTelegramCanonicalApprovalTerminalText as t };