@@ -4,34 +4,24 @@ import type { ReplyPayload } from "../types.js";
|
4 | 4 | |
5 | 5 | export type CompactionNoticePhase = "start" | "end" | "incomplete" | "skipped"; |
6 | 6 | |
| 7 | +const COMPACTION_NOTICE_TEXT: Record<CompactionNoticePhase, string> = { |
| 8 | +start: "🧹 Compacting context...", |
| 9 | +end: "🧹 Compaction complete", |
| 10 | +incomplete: "🧹 Compaction incomplete", |
| 11 | +skipped: "🧹 Compaction not needed", |
| 12 | +}; |
| 13 | + |
7 | 14 | export function shouldNotifyUserAboutCompaction(cfg?: OpenClawConfig): boolean { |
8 | 15 | return cfg?.agents?.defaults?.compaction?.notifyUser === true; |
9 | 16 | } |
10 | 17 | |
11 | | -export function formatCompactionNoticeText(phase: CompactionNoticePhase): string { |
12 | | -switch (phase) { |
13 | | -case "start": |
14 | | -return "🧹 Compacting context..."; |
15 | | -case "end": |
16 | | -return "🧹 Compaction complete"; |
17 | | -case "incomplete": |
18 | | -return "🧹 Compaction incomplete"; |
19 | | -case "skipped": |
20 | | -return "🧹 Compaction not needed"; |
21 | | -default: { |
22 | | -phase satisfies never; |
23 | | -throw new Error("unknown compaction notice phase"); |
24 | | -} |
25 | | -} |
26 | | -} |
27 | | - |
28 | 18 | export function createCompactionNoticePayload(params: { |
29 | 19 | phase: CompactionNoticePhase; |
30 | 20 | currentMessageId?: string; |
31 | 21 | applyReplyToMode?: (payload: ReplyPayload) => ReplyPayload; |
32 | 22 | }): ReplyPayload { |
33 | 23 | const payload: ReplyPayload = { |
34 | | -text: formatCompactionNoticeText(params.phase), |
| 24 | +text: COMPACTION_NOTICE_TEXT[params.phase], |
35 | 25 | ...(params.currentMessageId ? { replyToId: params.currentMessageId } : {}), |
36 | 26 | replyToCurrent: true, |
37 | 27 | isCompactionNotice: true, |
|