UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

58 lines (57 loc) • 2.79 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { n as sanitizeForLog } from "./ansi-CZa2t0Hf.mjs"; import { t as formatTokenCount } from "./token-format-BaacASOf.mjs"; import { t as parseCompactionDetails } from "./compaction-details-C4gVqcO-.mjs"; import { t as BOUNDED_CONTEXT_NOTICE } from "./transcript-byte-limit-SRI2OVpS.mjs"; //#region 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) { if (parseCompactionDetails(e.result?.details)?.qualityDegraded) return { phase: "degraded", text: t ? `${COMPACTION_NOTICE_TEXT.degraded}\n\n${COMPACTION_NOTICE_TEXT.context_bounded}` : void 0 }; if (t) return { phase: "context_bounded" }; const n = e.result?.tokensBefore; const r = e.result?.tokensAfter; return { phase: "end", text: e.compactionKind === "server-endpoint" && n !== void 0 && r !== void 0 ? `🧹 Server-side compaction complete (${formatTokenCount(n)} → ${formatTokenCount(r)})` : 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 createCompactionNoticePayload(e) { return createNoticePayload(e.text ?? COMPACTION_NOTICE_TEXT[e.phase], e); } function createCompactionHookNoticePayload(e) { if (e.messages.length === 0) return; return createNoticePayload(e.messages.join("\n\n"), e); } //#endregion export { resolveCompactionCompletionNotice as a, formatCompactionStatus as i, createCompactionNoticePayload as n, shouldNotifyUserAboutCompaction as o, formatCompactionModelRef as r, createCompactionHookNoticePayload as t };