import React from 'react' import { markdownToHTML } from './markdown' import { enrichOllamaErrorText, splitThinkBlocks } from './chatText' import desktopApi from './desktop/desktopApi' export default function AssistantMessageContent({ content, streamOutput, sources }) { const displayContent = enrichOllamaErrorText(content || '') const { think, answer } = splitThinkBlocks(displayContent) const [open, setOpen] = React.useState(false) const showThinkButton = !!think return (
{showThinkButton && (
{open && (
)}
)}
{Array.isArray(sources) && sources.length > 0 && (
{sources.map((u, i) => { let label = u let isFile = false try { const parsed = new URL(u) if (parsed.protocol === 'file:') { isFile = true const parts = parsed.pathname.split('/').filter(Boolean) label = decodeURIComponent(parts[parts.length - 1] || u) } else { const host = parsed.hostname || u label = host.replace(/^www\./i, '') } } catch {} return ( { if (!isFile) return event.preventDefault() try { const parsed = new URL(u) desktopApi?.openPath?.(decodeURIComponent(parsed.pathname)) } catch {} }} > {label} ) })}
)}
) }