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:
chengyongru authored and GitHub committed 2026-09-05 20:21:54 +08:00
1 parent 455533169d
commit 5229989f28
52 files changed
+1849 -140

No files matched your search

+48
View File
@@ -197,6 +197,54 @@ async function flushStreamFrame() {
}
describe("useNanobotStream", () => {
it.each(["succeeded", "cancelled"] as const)("updates one stable compaction row to %s", (phase) => {
const fake = fakeClient();
const { result } = renderHook(
() => useNanobotStream("chat-compaction", EMPTY_MESSAGES),
{ wrapper: wrap(fake.client) },
);
act(() => {
fake.emit("chat-compaction", {
event: "context_compaction",
chat_id: "chat-compaction",
compaction_id: "compact-1",
phase: "started",
});
});
expect(result.current.messages).toHaveLength(1);
const createdAt = result.current.messages[0].createdAt;
expect(result.current.messages[0]).toMatchObject({
id: "compaction-compact-1",
kind: "compaction",
compaction: {
id: "compact-1",
phase: "started",
announce: true,
},
});
act(() => {
fake.emit("chat-compaction", {
event: "context_compaction",
chat_id: "chat-compaction",
compaction_id: "compact-1",
phase,
});
});
expect(result.current.messages).toHaveLength(1);
expect(result.current.messages[0]).toMatchObject({
id: "compaction-compact-1",
createdAt,
compaction: {
phase,
announce: true,
},
});
});
it("batches answer deltas into one animation-frame update", async () => {
const fake = fakeClient();
const requestFrame = vi.spyOn(window, "requestAnimationFrame");