UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines (4 loc) • 3.11 kB
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{n as sanitizeForLog}from"./ansi-54CEWBZf.mjs";import{t as formatTokenCount}from"./token-format-BM-Ss3Co.mjs";import{t as parseCompactionDetails}from"./compaction-details-DqL6yAQA.mjs";import{r as logVerbose}from"./globals-l9I53ZKA.mjs";import{t as BOUNDED_CONTEXT_NOTICE}from"./transcript-byte-limit-_Kdc5zSm.mjs"; //!src/auto-reply/reply/compaction-notice.ts const COMPACTION_NOTICE_TEXT={start:`🧹 Compacting context...`,end:`🧹 Compaction complete`,degraded:`⚠️ Compaction completed with a degraded summary. Older details, exact identifiers, or pending requests may be missing. Resend important context; /new or a larger model can help.`,incomplete:`🧹 Compaction incomplete`,skipped:`🧹 Compaction not needed`,memory_flush_degraded:`⚠️ Memory maintenance temporarily failed; continuing your reply.`,context_bounded:BOUNDED_CONTEXT_NOTICE};function formatCompactionStatus(e){const t=e?.compactionCount??0;return e?.compactionQualityDegraded?`${t} · degraded history (details may be lost)`:t>0?String(t):void 0}function resolveCompactionCompletionNotice(e,t){const n=parseCompactionDetails(e.result?.details);if(n?.qualityDegraded){const e=compactionNoticeText(`degraded`,n.summaryRefused);return{phase:`degraded`,text:t?`${e}\n\n${COMPACTION_NOTICE_TEXT.context_bounded}`:e}}if(t)return{phase:`context_bounded`};const r=e.result?.tokensBefore;const i=e.result?.tokensAfter;return{phase:`end`,text:e.compactionKind===`server-endpoint`&&r!==void 0&&i!==void 0?`🧹 Server-side compaction complete (${formatTokenCount(r)} → ${formatTokenCount(i)})`:void 0}}function formatCompactionModelRef(e,t){const n=[e,t].map(e=>normalizeOptionalString(e)).filter(e=>e!==void 0);return n.length>0?n.map(e=>sanitizeForLog(e)).join(`/`):`unknown model`}function shouldNotifyUserAboutCompaction(e){return e?.agents?.defaults?.compaction?.notifyUser===true}function createNoticePayload(e,t){const n={text:e,...t.currentMessageId?{replyToId:t.currentMessageId}:{},replyToCurrent:true,isCompactionNotice:true};return t.applyReplyToMode?t.applyReplyToMode(n):n}function compactionNoticeText(e,t){return e===`degraded`&&t?`⚠️ Context trimmed because the summarizer refused. Recent turns were kept verbatim; older messages remain in saved history but are outside active context. Resend essential older details to continue.`:COMPACTION_NOTICE_TEXT[e]}function createCompactionNoticePayload(e){return createNoticePayload(e.text??compactionNoticeText(e.phase,e.summaryRefused),e)}function createCompactionHookNoticePayload(e){if(e.messages.length===0)return;return createNoticePayload(e.messages.join(` `),e)}async function deliverCompactionNoticePayload(e,t,n){if(!t)return;try{await t(e)}catch(e){logVerbose(`compaction ${n} notice delivery failed (non-fatal): ${String(e)}`)}}export{formatCompactionStatus as a,formatCompactionModelRef as i,createCompactionNoticePayload as n,resolveCompactionCompletionNotice as o,deliverCompactionNoticePayload as r,shouldNotifyUserAboutCompaction as s,createCompactionHookNoticePayload as t};