feat: make context compaction visible in channels (#5656)
* feat: surface context compaction lifecycle * fix: complete and simplify context compaction notifications
This commit is contained in:
1 parent
455533169d
commit
5229989f28
52 files changed
+1849
-140
No files matched your search
@@ -771,6 +771,35 @@ export function useNanobotStream(
|
||||
return;
|
||||
}
|
||||
const sideChannelEvent = isSideChannelEvent(ev);
|
||||
if (ev.event === "context_compaction") {
|
||||
flushPendingStreamEvents({ closeAnswerSegment: true });
|
||||
clearActivitySegment();
|
||||
const compaction = {
|
||||
id: ev.compaction_id,
|
||||
phase: ev.phase,
|
||||
announce: true,
|
||||
};
|
||||
setMessages((prev) => {
|
||||
const id = `compaction-${ev.compaction_id}`;
|
||||
const existing = prev.findIndex((message) => message.id === id);
|
||||
const next = {
|
||||
id,
|
||||
role: "assistant" as const,
|
||||
content: "",
|
||||
kind: "compaction" as const,
|
||||
createdAt: Date.now(),
|
||||
compaction,
|
||||
...turnFieldsFromEvent(ev, "activity"),
|
||||
};
|
||||
if (existing < 0) return [...prev, next];
|
||||
return prev.map((message, index) => (
|
||||
index === existing
|
||||
? { ...next, createdAt: message.createdAt }
|
||||
: message
|
||||
));
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (ev.event === "delta") {
|
||||
if (suppressStreamUntilTurnEndRef.current) return;
|
||||
const chunk = typeof ev.text === "string" ? ev.text : "";
|
||||
@@ -854,6 +883,7 @@ export function useNanobotStream(
|
||||
}
|
||||
|
||||
if (ev.event === "turn_end") {
|
||||
if (typeof ev.turn_id === "string") sideChannelTurnIdsRef.current.delete(ev.turn_id);
|
||||
if ("goal_state" in ev && ev.goal_state != null && typeof ev.goal_state === "object") {
|
||||
setGoalState(ev.goal_state);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user