openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 4.13 kB
JavaScript
import{i as truncateWithMarker}from"./utf16-slice-DA3Mllbx.mjs";import{n as buildSystemAgentApprovalResolvedText,r as formatApprovalDecisionLabel}from"./approval-terminal-BEKbbZHB.mjs";import"./approval-runtime-CQqZ5Nic.mjs";
//!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(`
`),TELEGRAM_APPROVAL_TERMINAL_MAX_CHARS)}function appendApprovalSubject(e,t,n,r){e.push(``,t,truncateDetail(n));if(r)e.push(truncateDetail(r))}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)}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)}function buildTelegramInvalidApprovalTerminalText(){return`ℹ️ Approval action unavailable
This button is invalid or no longer actionable.`}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)}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)}export{buildTelegramNativeResolvedApprovalText as a,buildTelegramNativeExpiredApprovalText as i,buildTelegramInvalidApprovalTerminalText as n,buildTelegramLegacyApprovalTerminalText as r,buildTelegramCanonicalApprovalTerminalText as t};