From 7ed9b521c47ece816f390297566a744d77568416 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 16 Jun 2026 11:10:10 +0200 Subject: [PATCH] Unify chat evidence display --- ...Unify-savings-chat-tools-and-sources-UI.md | 42 +++++++++++++++++++ src/components/chat/AgentChat.test.tsx | 36 +++++++++++++++- src/components/chat/AgentChat.tsx | 34 +++++++++++---- 3 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 backlog/tasks/task-12 - Unify-savings-chat-tools-and-sources-UI.md diff --git a/backlog/tasks/task-12 - Unify-savings-chat-tools-and-sources-UI.md b/backlog/tasks/task-12 - Unify-savings-chat-tools-and-sources-UI.md new file mode 100644 index 0000000..f8d2ec3 --- /dev/null +++ b/backlog/tasks/task-12 - Unify-savings-chat-tools-and-sources-UI.md @@ -0,0 +1,42 @@ +--- +id: TASK-12 +title: Unify savings chat tools and sources UI +status: In Progress +assignee: [] +created_date: '2026-06-16 09:07' +updated_date: '2026-06-16 09:09' +labels: [] +dependencies: [] +priority: high +ordinal: 12000 +--- + +## Description + + +Replace duplicated Tools and Quellen panels in savings chat assistant messages with one combined evidence block when tool traces and generated sources describe the same data basis. + + +## Acceptance Criteria + +- [x] #1 Assistant messages with both toolTrace and matching sources render a single Nachweis & Arbeitsweg block +- [x] #2 The combined block exposes citation source ids on the evidence rows so inline markers still point at the same evidence +- [x] #3 Sources-only assistant messages can still render a Quellen block for genuinely external sources +- [x] #4 Focused component tests, targeted lint, and build pass + + +## Implementation Plan + + +1. Add regression tests for assistant messages where toolTrace and sources describe the same evidence. +2. Replace the separate Tools + Quellen rendering path with a single Nachweis & Arbeitsweg evidence panel when toolTrace exists. +3. Keep the Quellen-only fallback for messages that have sources without tool traces. +4. Verify focused component tests, targeted lint, and production build. +5. Commit the UI refinement; keep task In Progress until user confirms manual behavior. + + +## Implementation Notes + + +Unified generated tool traces and generated sources in AgentChat. Assistant messages with toolTrace now render one Nachweis & Arbeitsweg disclosure and attach source ids to the evidence rows, so inline citation markers still resolve to the same evidence. Sources-only messages still render the Quellen fallback for external/document sources. Verification passed: npx vitest src/components/chat/AgentChat.test.tsx --run (13 tests), targeted eslint, npm run build (existing Vite chunk-size warning only). + diff --git a/src/components/chat/AgentChat.test.tsx b/src/components/chat/AgentChat.test.tsx index dfd8a39..1225401 100644 --- a/src/components/chat/AgentChat.test.tsx +++ b/src/components/chat/AgentChat.test.tsx @@ -150,7 +150,7 @@ describe("AgentChat phase 2 reasoning disclosure", () => { test("renders an assistant work-progress disclosure from tool traces", () => { const markup = renderToStaticMarkup(); - expect(markup).toContain("So wurde gearbeitet"); + expect(markup).toContain("Nachweis & Arbeitsweg"); expect(markup).toContain("summarize_transactions"); expect(markup).toContain("12 Umsaetze zusammengefasst"); }); @@ -206,4 +206,38 @@ describe("AgentChat phase 3 sources and inline citations", () => { expect(markup).toContain("[1]"); expect(markup).toContain("data-source-id=\"tool-1\""); }); + + test("combines matching tool traces and sources into one evidence block", () => { + const markup = renderToStaticMarkup( + , + ); + + expect(markup).toContain("Nachweis & Arbeitsweg"); + expect(markup).toContain("1 Werkzeug verwendet"); + expect(markup).toContain("get_transactions"); + expect(markup).toContain("24 Umsaetze, Saldo -13483.41€, vollstaendig"); + expect(markup).toContain("data-source-id=\"tool-1\""); + expect(markup).not.toContain(">Quellen<"); + }); }); diff --git a/src/components/chat/AgentChat.tsx b/src/components/chat/AgentChat.tsx index c98089d..60f438a 100644 --- a/src/components/chat/AgentChat.tsx +++ b/src/components/chat/AgentChat.tsx @@ -89,9 +89,9 @@ export function AgentMessage({ message, className, ...props }: AgentMessageProps />

{!isUser && message.toolTrace && message.toolTrace.length > 0 && ( - + )} - {!isUser && message.sources && message.sources.length > 0 && ( + {!isUser && (!message.toolTrace || message.toolTrace.length === 0) && message.sources && message.sources.length > 0 && ( )} @@ -154,27 +154,47 @@ function AgentSources({ sources }: { sources: AgentSource[] }) { ); } -function AgentToolTracePanel({ toolTrace }: { toolTrace: AgentToolTrace[] }) { +function AgentEvidencePanel({ + sources, + toolTrace, +}: { + sources?: AgentSource[]; + toolTrace: AgentToolTrace[]; +}) { const steps = buildReasoningSteps(toolTrace); return (
- So wurde gearbeitet ({getToolTraceSummary(toolTrace)}) + Nachweis & Arbeitsweg ({getToolTraceSummary(toolTrace)})
{steps.map((step, stepIndex) => ( - + ))}
); } -function ReasoningStep({ step }: { step: AgentReasoningStep }) { +function ReasoningStep({ + sourceId, + step, +}: { + sourceId?: string; + step: AgentReasoningStep; +}) { return ( -
+

{step.label}

{step.description}