Unify chat evidence display
This commit is contained in:
@@ -150,7 +150,7 @@ describe("AgentChat phase 2 reasoning disclosure", () => {
|
||||
test("renders an assistant work-progress disclosure from tool traces", () => {
|
||||
const markup = renderToStaticMarkup(<AgentMessage message={assistantMessage} />);
|
||||
|
||||
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(
|
||||
<AgentMessage
|
||||
message={{
|
||||
id: "assistant-evidence",
|
||||
role: "assistant",
|
||||
content: "Es gab 24 Buchungen [1].",
|
||||
toolTrace: [
|
||||
{
|
||||
name: "get_transactions",
|
||||
inputSummary: "Kategorie Rahmenkredite",
|
||||
resultSummary: "24 Umsaetze, Saldo -13483.41€, vollstaendig",
|
||||
},
|
||||
],
|
||||
sources: [
|
||||
{
|
||||
id: "tool-1",
|
||||
title: "get_transactions",
|
||||
description: "24 Umsaetze, Saldo -13483.41€, vollstaendig",
|
||||
},
|
||||
],
|
||||
citations: [{ marker: "1", sourceId: "tool-1" }],
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
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<");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,9 +89,9 @@ export function AgentMessage({ message, className, ...props }: AgentMessageProps
|
||||
/>
|
||||
</p>
|
||||
{!isUser && message.toolTrace && message.toolTrace.length > 0 && (
|
||||
<AgentToolTracePanel toolTrace={message.toolTrace} />
|
||||
<AgentEvidencePanel sources={message.sources} toolTrace={message.toolTrace} />
|
||||
)}
|
||||
{!isUser && message.sources && message.sources.length > 0 && (
|
||||
{!isUser && (!message.toolTrace || message.toolTrace.length === 0) && message.sources && message.sources.length > 0 && (
|
||||
<AgentSources sources={message.sources} />
|
||||
)}
|
||||
</div>
|
||||
@@ -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 (
|
||||
<details className="mt-3 rounded-md border bg-muted/30 px-2 py-1.5">
|
||||
<summary className="flex cursor-pointer list-none items-center gap-2 text-xs font-medium text-muted-foreground">
|
||||
<Wrench className="h-3.5 w-3.5" />
|
||||
So wurde gearbeitet ({getToolTraceSummary(toolTrace)})
|
||||
Nachweis & Arbeitsweg ({getToolTraceSummary(toolTrace)})
|
||||
</summary>
|
||||
<div className="mt-2 space-y-2">
|
||||
{steps.map((step, stepIndex) => (
|
||||
<ReasoningStep key={`${step.label}-${stepIndex}`} step={step} />
|
||||
<ReasoningStep
|
||||
key={`${step.label}-${stepIndex}`}
|
||||
sourceId={sources?.[stepIndex]?.id}
|
||||
step={step}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</details>
|
||||
);
|
||||
}
|
||||
|
||||
function ReasoningStep({ step }: { step: AgentReasoningStep }) {
|
||||
function ReasoningStep({
|
||||
sourceId,
|
||||
step,
|
||||
}: {
|
||||
sourceId?: string;
|
||||
step: AgentReasoningStep;
|
||||
}) {
|
||||
return (
|
||||
<div className="rounded-md bg-background/80 p-2 text-xs" data-status={step.status}>
|
||||
<div
|
||||
className="rounded-md bg-background/80 p-2 text-xs"
|
||||
data-source-id={sourceId}
|
||||
data-status={step.status}
|
||||
>
|
||||
<p className="font-medium text-foreground">{step.label}</p>
|
||||
<p className="mt-1 text-muted-foreground">{step.description}</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user