Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
Revert "fix(chat): keep RAG/web citations visible after trace collapses"
Akarshan Biswasf0c03e8c1eb6
diff --git a/web-app/src/components/ai-elements/tool.tsx b/web-app/src/components/ai-elements/tool.tsxindex 8334cd577..e221a6426 100644--- a/web-app/src/components/ai-elements/tool.tsx+++ b/web-app/src/components/ai-elements/tool.tsx@@ -24,6 +24,7 @@ import { useToolApproval } from '@/hooks/useToolApproval'import { useTranslation } from '@/i18n/react-i18next-compat'import { Button } from '@/components/ui/button'import { ShieldAlertIcon } from 'lucide-react'+import { Citations } from '@/components/Citations'import { parseCitationsFromToolOutput } from '@/lib/citation-parser'type ToolContextValue = {@@ -319,6 +320,7 @@ export type ToolOutputProps = ComponentProps<'div'> & {export const ToolOutput = memo(({ className, output, errorText, resolver, ...props }: ToolOutputProps) => {+ const { messageId } = useTool()const citationPayload = useMemo(() => (output ? parseCitationsFromToolOutput(output) : null),[output]@@ -329,11 +331,13 @@ export const ToolOutput = memo(return null}- // Citation payloads are surfaced as an always-visible card in the message- // body (see MessageItem); rendering them here too would duplicate the- // anchor ids and hide the sources inside the collapsible trace.if (citationPayload) {- return null+ return (+ <Citations+ payload={citationPayload}+ anchorPrefix={messageId ? `cite-${messageId}` : undefined}+ />+ )}// Handle string output@@ -451,7 +455,7 @@ export const ToolOutput = memo(}return <div>{output as ReactNode}</div>- }, [output, errorText, resolver, citationPayload])+ }, [output, errorText, resolver, citationPayload, messageId])if (!(output || errorText)) {return nulldiff --git a/web-app/src/containers/MessageItem.tsx b/web-app/src/containers/MessageItem.tsxindex fbc813ec7..675e98649 100644--- a/web-app/src/containers/MessageItem.tsx+++ b/web-app/src/containers/MessageItem.tsx@@ -40,8 +40,7 @@ import { PromptProgress } from '@/components/PromptProgress'import { useServiceHub } from '@/hooks/useServiceHub'import { useToolApproval } from '@/hooks/useToolApproval'import { parseCitationsFromToolOutput } from '@/lib/citation-parser'-import { Citations } from '@/components/Citations'-import type { CitationsPayload, RagCitation } from '@/components/Citations'+import type { RagCitation } from '@/components/Citations'import { useGroundingStore } from '@/stores/grounding-store'import { injectCitationMarkers } from '@/lib/grounding'@@ -164,32 +163,18 @@ export const MessageItem = memo(status === CHAT_STATUS.SUBMITTED)) ||hasPendingToolCall- // Aggregate citation payloads from every retrieve/search tool call. The RAG- // payloads are merged into one (so grounding anchors `cite-<id>-<n>` line up- // with a single ordered list); web payloads stay per-call.- const { ragPayload, webPayloads } = useMemo(() => {- const rags: Extract<CitationsPayload, { kind: 'rag' }>[] = []- const webs: Extract<CitationsPayload, { kind: 'web' }>[] = []- if (message.role === 'assistant') {- for (const part of message.parts as any[]) {- if (!part.type?.startsWith('tool-')) continue- if (part.state !== 'output-available') continue- const parsed = parseCitationsFromToolOutput(part.output)- if (parsed?.kind === 'rag') rags.push(parsed)- else if (parsed?.kind === 'web') webs.push(parsed)- }+ const ragCitations = useMemo<RagCitation[]>(() => {+ if (message.role !== 'assistant') return []+ const out: RagCitation[] = []+ for (const part of message.parts as any[]) {+ if (!part.type?.startsWith('tool-')) continue+ if (part.state !== 'output-available') continue+ const parsed = parseCitationsFromToolOutput(part.output)+ if (parsed?.kind === 'rag') out.push(...parsed.citations)}- const merged: CitationsPayload | null = rags.length- ? { ...rags[0], citations: rags.flatMap((r) => r.citations) }- : null- return { ragPayload: merged, webPayloads: webs }+ return out}, [message.parts, message.role])- const ragCitations = useMemo<RagCitation[]>(- () => (ragPayload?.kind === 'rag' ? ragPayload.citations : []),- [ragPayload]- )-const serviceHub = useServiceHub()const grounding = useGroundingStore((s) => s.byMessageId[message.id])const ensureGrounding = useGroundingStore((s) => s.ensure)@@ -679,15 +664,6 @@ export const MessageItem = memo({/* Render message parts */}{renderedParts}- {/* Sources stay in the message body so they remain visible after the- working trace auto-collapses, and so inline citation anchors resolve. */}- {ragPayload && (- <Citations payload={ragPayload} anchorPrefix={`cite-${message.id}`} />- )}- {webPayloads.map((payload, i) => (- <Citations key={`web-cite-${message.id}-${i}`} payload={payload} />- ))}-{isLastMessage &&message.role === 'assistant' &&!awaitingApproval &&