feat: render summarization/compact user message (#736)
This commit is contained in:
@@ -5,7 +5,11 @@ import type {
|
||||
Message,
|
||||
TextContent,
|
||||
} from "@letta-ai/letta-client/resources/agents/messages";
|
||||
import { SYSTEM_REMINDER_CLOSE, SYSTEM_REMINDER_OPEN } from "../../constants";
|
||||
import {
|
||||
COMPACTION_SUMMARY_HEADER,
|
||||
SYSTEM_REMINDER_CLOSE,
|
||||
SYSTEM_REMINDER_OPEN,
|
||||
} from "../../constants";
|
||||
import type { Buffers } from "./accumulator";
|
||||
|
||||
/**
|
||||
@@ -81,7 +85,7 @@ function truncateSystemReminder(text: string, maxLength: number): string {
|
||||
* Check if a user message is a compaction summary (system_alert with summary content).
|
||||
* Returns the summary text if found, null otherwise.
|
||||
*/
|
||||
function extractCompactionSummary(text: string): string | null {
|
||||
export function extractCompactionSummary(text: string): string | null {
|
||||
try {
|
||||
const parsed = JSON.parse(text);
|
||||
if (
|
||||
@@ -182,17 +186,12 @@ export function backfillBuffers(buffers: Buffers, history: Message[]): void {
|
||||
// Check if this is a compaction summary message (system_alert with summary)
|
||||
const compactionSummary = extractCompactionSummary(rawText);
|
||||
if (compactionSummary) {
|
||||
// Render as a synthetic tool call showing the compaction
|
||||
// Render as a user message with context header and summary
|
||||
const exists = buffers.byId.has(lineId);
|
||||
buffers.byId.set(lineId, {
|
||||
kind: "tool_call",
|
||||
kind: "user",
|
||||
id: lineId,
|
||||
toolCallId: `compaction-${lineId}`,
|
||||
name: "Compact",
|
||||
argsText: "messages[...]",
|
||||
resultText: compactionSummary,
|
||||
resultOk: true,
|
||||
phase: "finished",
|
||||
text: `${COMPACTION_SUMMARY_HEADER}\n\n${compactionSummary}`,
|
||||
});
|
||||
if (!exists) buffers.order.push(lineId);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user