Add chat sources and citations

This commit is contained in:
Matthias
2026-06-16 10:58:15 +02:00
parent 85af9d7078
commit 9f17d4d1e1
9 changed files with 356 additions and 13 deletions

View File

@@ -6,7 +6,11 @@ import {
AgentPromptInput,
type AgentChatMessage,
} from "./AgentChat";
import { buildReasoningSteps, getToolTraceSummary } from "./agentChatModel";
import {
buildSourcesFromToolTrace,
buildReasoningSteps,
getToolTraceSummary,
} from "./agentChatModel";
const assistantMessage: AgentChatMessage = {
id: "assistant-1",
@@ -148,3 +152,46 @@ describe("AgentChat phase 2 reasoning disclosure", () => {
expect(markup).toContain("data-status=\"active\"");
});
});
describe("AgentChat phase 3 sources and inline citations", () => {
test("builds private finance sources from tool traces", () => {
expect(buildSourcesFromToolTrace(assistantMessage.toolTrace)).toEqual([
{
id: "tool-1",
title: "summarize_transactions",
description: "12 Umsaetze zusammengefasst",
},
{
id: "tool-2",
title: "list_transactions",
description: "1 Treffer",
},
]);
});
test("renders source list and inline citation markers for assistant messages", () => {
const markup = renderToStaticMarkup(
<AgentMessage
message={{
id: "assistant-cited",
role: "assistant",
content: "Die Miete war der groesste Posten [1].",
sources: [
{
id: "tool-1",
title: "list_transactions",
description: "1 Mietumsatz gefunden",
},
],
citations: [{ marker: "1", sourceId: "tool-1" }],
}}
/>,
);
expect(markup).toContain("Quellen");
expect(markup).toContain("list_transactions");
expect(markup).toContain("1 Mietumsatz gefunden");
expect(markup).toContain("[1]");
expect(markup).toContain("data-source-id=\"tool-1\"");
});
});