diff --git a/frontend/src/views/chat/components/AgentStreamDisplay.vue b/frontend/src/views/chat/components/AgentStreamDisplay.vue index 99c00beb..0eb68592 100644 --- a/frontend/src/views/chat/components/AgentStreamDisplay.vue +++ b/frontend/src/views/chat/components/AgentStreamDisplay.vue @@ -916,6 +916,23 @@ onBeforeUnmount(() => { } }); +const ATTRIBUTE_REGEX = /([\w-]+)\s*=\s*"([^"]*)"/g; + +const parseTagAttributes = (attrString: string): Record => { + const attributes: Record = {}; + if (!attrString) return attributes; + + ATTRIBUTE_REGEX.lastIndex = 0; + let match: RegExpExecArray | null; + while ((match = ATTRIBUTE_REGEX.exec(attrString)) !== null) { + const key = match[1]; + const value = match[2]; + attributes[key] = value; + } + + return attributes; +}; + // Markdown rendering function const renderMarkdown = (content: any): string => { if (!content) return ''; @@ -932,8 +949,16 @@ const renderMarkdown = (content: any): string => { const processed = contentStr // Web citations -> compact clickable badges with domain text; hover shows title via native tooltip .replace( - //g, - (_m: string, url: string, title: string) => { + /]*)\/>/g, + (_m: string, attrString: string) => { + const attrs = parseTagAttributes(attrString); + const url = attrs.url || ''; + const title = attrs.title || ''; + + if (!url) { + return ''; + } + // Extract domain for compact display let domain = url; try { @@ -961,8 +986,17 @@ const renderMarkdown = (content: any): string => { ) // KB citations -> inline badges with simplified display .replace( - //g, - (_m, kbId, doc, chunkId) => { + /]*)\/>/g, + (_m, attrString: string) => { + const attrs = parseTagAttributes(attrString); + const doc = attrs.doc || ''; + const chunkId = attrs.chunk_id || attrs.chunkId || ''; + const kbId = attrs.kb_id || attrs.kbId || ''; + + if (!doc || !chunkId) { + return ''; + } + // Escape doc name for safety const safeDoc = String(doc || '').replace(/"/g, '"'); const safeKbId = String(kbId || '').replace(/"/g, '"');