feat(frontend): build chronological activity timeline

This commit is contained in:
User
2026-07-14 22:56:41 +02:00
parent e0a97a01f3
commit f0f6c3c223
6 changed files with 272 additions and 26 deletions
+97 -4
View File
@@ -15,18 +15,111 @@ test("text_delta accumulates into transcript", () => {
expect(useSessionStore.getState().transcript.at(-1)?.text).toBe("Analisi");
});
test("folds prompt, lifecycle, streams, tool updates, and gates in chronological order", () => {
const store = useSessionStore.getState();
store.setPhase("F1");
store.setLastUserEntry({ kind: "input", text: "How many patients?" });
store.applyEvent({ type: "system_event", event: "agent_start" });
store.applyEvent({ type: "activity_delta", text: "Inspect " });
store.applyEvent({ type: "activity_delta", text: "schema" });
store.applyEvent({
type: "activity_event",
activity: { kind: "tool", toolCallId: "t1", toolName: "bash", status: "running" },
});
store.applyEvent({ type: "text_delta", text: "I found " });
store.applyEvent({ type: "text_delta", text: "the candidates." });
store.applyEvent({
type: "activity_event",
activity: { kind: "tool", toolCallId: "t1", toolName: "bash", status: "completed" },
});
store.applyEvent({
type: "ui_request",
ui_request: { id: "g1", widget: "select", phase: "F1_understanding", title: "Confirm intent" },
});
const log = useSessionStore.getState().activityLog;
expect(log.map((entry) => entry.kind)).toEqual([
"prompt",
"lifecycle",
"thinking",
"tool",
"assistant",
"gate",
]);
expect(log.map((entry) => entry.phase)).toEqual(["F1", "F1", "F1", "F1", "F1", "F1"]);
expect(log.find((entry) => entry.kind === "thinking")?.text).toBe("Inspect schema");
expect(log.find((entry) => entry.kind === "assistant")?.text).toBe("I found the candidates.");
expect(log[3]).toEqual({
kind: "tool",
phase: "F1",
text: "bash",
toolCallId: "t1",
status: "completed",
});
expect(log.at(-1)?.text).toBe("Confirm intent");
});
test("stream chunks coalesce only across adjacent rows of the same kind", () => {
const store = useSessionStore.getState();
store.applyEvent({ type: "activity_delta", text: "before" });
store.applyEvent({ type: "info", level: "info", text: "checkpoint" });
store.applyEvent({ type: "activity_delta", text: "after" });
expect(useSessionStore.getState().activityLog.map((entry) => [entry.kind, entry.text])).toEqual([
["thinking", "before"],
["status", "checkpoint"],
["thinking", "after"],
]);
});
test("activity_delta accumulates separately from the assistant transcript", () => {
const s = useSessionStore.getState();
s.applyEvent({ type: "activity_delta", text: "Valuto " });
s.applyEvent({ type: "activity_delta", text: "le ambiguità" });
expect(useSessionStore.getState().activity.at(-1)?.text).toBe("Valuto le ambiguità");
expect(useSessionStore.getState().activityLog.at(-1)).toMatchObject({
kind: "thinking",
text: "Valuto le ambiguità",
});
expect(useSessionStore.getState().transcript).toEqual([]);
});
test("info appends to stepMessages", () => {
test("info appends to stepMessages and the chronological status log", () => {
useSessionStore.getState().applyEvent({ type: "info", level: "warning", text: "attenzione" });
expect(useSessionStore.getState().stepMessages.at(-1)).toEqual({ level: "warning", text: "attenzione" });
expect(useSessionStore.getState().activityLog.at(-1)).toEqual({
kind: "status",
phase: null,
text: "attenzione",
level: "warning",
});
});
test("a terminal tool event without a start appends a correlated terminal row", () => {
useSessionStore.getState().applyEvent({
type: "activity_event",
activity: { kind: "tool", toolCallId: "t2", toolName: "read", status: "failed" },
});
expect(useSessionStore.getState().activityLog).toEqual([
{
kind: "tool",
phase: null,
text: "read",
toolCallId: "t2",
status: "failed",
},
]);
});
test("recordLifecycle appends a local lifecycle row using the current phase", () => {
const store = useSessionStore.getState();
store.setPhase("F4");
store.recordLifecycle("Resuming session");
expect(useSessionStore.getState().activityLog).toEqual([
{ kind: "lifecycle", phase: "F4", text: "Resuming session" },
]);
});
test("clearPending removes the widget", () => {
@@ -124,12 +217,12 @@ test("setLastUserEntry records the entry and clears stepMessages", () => {
expect(useSessionStore.getState().stepMessages).toEqual([]);
});
test("resetSession clears lastUserEntry and stepMessages", () => {
test("resetSession clears lastUserEntry, stepMessages, and the complete activity log", () => {
const st = useSessionStore.getState();
st.setLastUserEntry({ kind: "choice", text: "promote" });
st.applyEvent({ type: "info", level: "info", text: "y" });
st.resetSession();
expect(useSessionStore.getState().lastUserEntry).toBeNull();
expect(useSessionStore.getState().stepMessages).toEqual([]);
expect(useSessionStore.getState().activity).toEqual([]);
expect(useSessionStore.getState().activityLog).toEqual([]);
});