diff --git a/frontend/src/lib/components/AgentResultDisplay.svelte b/frontend/src/lib/components/AgentResultDisplay.svelte index 1a81944077..ec10bbaf03 100644 --- a/frontend/src/lib/components/AgentResultDisplay.svelte +++ b/frontend/src/lib/components/AgentResultDisplay.svelte @@ -4,7 +4,8 @@ import GfmMarkdown from './GfmMarkdown.svelte' import AgentTrace from './AgentTrace.svelte' import LabeledDivider from './LabeledDivider.svelte' - import { buildAgentTrace } from './agentTrace' + import WebSearchSourcesDisplay from './copilot/chat/WebSearchSourcesDisplay.svelte' + import { buildAgentTrace, splitFinalAnswer } from './agentTrace' import { runPane } from './agentScroll' import { createBottomSticker } from './stickToBottom' import { formatTokenCount, summarizeAgentResult, type AgentResult } from './aiAgentResult' @@ -29,13 +30,11 @@ let summary = $derived(summarizeAgentResult(result)) let textOutput = $derived(typeof result.output === 'string' ? result.output : undefined) - // The run's last message is what produced `output`, so it is dropped from the - // trace: the output block below is that same text, and printing it twice in - // one scroll reads as the agent having answered itself. - let trace = $derived.by(() => { - const entries = buildAgentTrace(result.messages) - return entries.at(-1)?.kind === 'assistant' ? entries.slice(0, -1) : entries - }) + // The turn that produced `output` is not a trace row: the output block below is + // that same text, and printing it twice in one scroll reads as the agent having + // answered itself. Its citations move down with it. + let answer = $derived(splitFinalAnswer(buildAgentTrace(result.messages), result.output)) + let trace = $derived(answer.trace) let anchor: HTMLElement | undefined = $state() const sticker = createBottomSticker() @@ -69,6 +68,11 @@ {:else} {@render structuredOutput(result.output)} {/if} + {#if answer.sources} +
+ +
+ {/if} diff --git a/frontend/src/lib/components/AgentStreamDisplay.svelte b/frontend/src/lib/components/AgentStreamDisplay.svelte index c7c95eb902..768c951698 100644 --- a/frontend/src/lib/components/AgentStreamDisplay.svelte +++ b/frontend/src/lib/components/AgentStreamDisplay.svelte @@ -30,6 +30,11 @@ const continues = progress.key === streamKey && raw.length >= progress.consumed const base = continues ? progress : emptyAgentStreamProgress() progress = { ...advanceAgentStream(raw, base), key: streamKey } + if (!continues) { + // Another run, so the reader's decision to stop following the previous + // one does not carry over: this one starts at its latest output. + following = true + } }) }) @@ -66,7 +71,6 @@ sticker.scrollToEnd(runPane(anchor)) } }) -