ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.
Python ai-agentsamdcomfyuidockerllama-cppllmlocal-ain8nnvidiaopen-webuiragself-hostedspeech-to-textstrix-halotext-to-speechworkflow-automation
fix(portal): label unavailable inline images clearly (#8286)
Mike Bradley63cba5626015
diff --git a/ods/extensions/services/dashboard/src/components/PortalStreamingText.jsx b/ods/extensions/services/dashboard/src/components/PortalStreamingText.jsxindex 0ecc30692..73c77e5d2 100644--- a/ods/extensions/services/dashboard/src/components/PortalStreamingText.jsx+++ b/ods/extensions/services/dashboard/src/components/PortalStreamingText.jsx@@ -47,6 +47,13 @@ function revealNewText() {}function StreamSpan({node,...props}) {return <span {...props}/>}+// ReactMarkdown passes renderers the URL after its normal security filtering.+// An invented attachment:// screenshot therefore has no usable source. Keep+// that absence visible without loading an empty URL or changing Markdown/code.+function PortalImage({renderer:Renderer='img',node,src,alt,...props}) {+ if(!src) return <span className="portal-delivery-note">Image unavailable{alt ? `: ${alt}` : ''}</span>+ return <Renderer {...props} {...(typeof Renderer==='string' ? {} : {node})} src={src} alt={alt}/>+}const EMPTY_COMPONENTS={}// Inspect Markdown structure before reveal wrappers are added. Download labels@@ -116,7 +123,8 @@ export default function PortalStreamingText({children, active=false, animate=act? [rehypeHighlight,mutePortalNotes,markDocumentDownloads,[suppressDeliveredMediaLines,{source,artifacts}],revealNewText]: PLUGINS,[delivered,revealing,source,artifacts])useLayoutEffect(()=>{onReveal?.()},[source,onReveal])- const renderers=useMemo(()=>({...components,a:props=><PortalInlineCitation {...props} artifacts={artifacts}/>,span:StreamSpan}),[components,artifacts])+ const renderers=useMemo(()=>({...components,a:props=><PortalInlineCitation {...props} artifacts={artifacts}/>,+ img:props=><PortalImage {...props} renderer={components.img}/>,span:StreamSpan}),[components,artifacts])return <div className={`portal-streaming-text ${active || revealing?'is-streaming':''}`} aria-busy={active || revealing}><ReactMarkdown remarkPlugins={[remarkGfm]} rehypePlugins={plugins} components={renderers}>{source}</ReactMarkdown>{(active || revealing) && <span className="portal-stream-cursor" aria-hidden="true"/>}diff --git a/ods/extensions/services/dashboard/src/components/PortalStreamingText.test.jsx b/ods/extensions/services/dashboard/src/components/PortalStreamingText.test.jsxindex c24a17113..1ba3851d8 100644--- a/ods/extensions/services/dashboard/src/components/PortalStreamingText.test.jsx+++ b/ods/extensions/services/dashboard/src/components/PortalStreamingText.test.jsx@@ -3,6 +3,44 @@ import PortalStreamingText from './PortalStreamingText'import {EMBED_ONLY_NOTE} from '../lib/embedDisplay'import {DELIVERY_NOTES} from '../lib/portalDeliveryNotes'+it.each([false,true])('shows the captured unavailable screenshot without losing the answer (active: %s)',active=>{+ const source='Here is your packing checklist.\n\n\n\nUse the preview card above.'+ const {container}=render(<PortalStreamingText active={active} instant>{source}</PortalStreamingText>)+ expect(container).toHaveTextContent('Here is your packing checklist.')+ expect(container).toHaveTextContent('Image unavailable: Packing Checklist')+ expect(container).toHaveTextContent('Use the preview card above.')+ expect(container.querySelector('img')).toBeNull()+})++it.each(['','![]()','![missing][shot]\n\n[shot]: attachment://missing.png'])('does not create an empty-source image: %s',source=>{+ const {container}=render(<PortalStreamingText instant>{source}</PortalStreamingText>)+ expect(container).toHaveTextContent('Image unavailable')+ expect(container.querySelector('img')).toBeNull()+})++it('keeps supported image URLs, titles and custom rendering after URL filtering',()=>{+ const Image=vi.fn(({node,...props})=><img {...props} data-custom-image="yes"/>)+ const {container}=render(<PortalStreamingText instant components={{img:Image}}>{'\n\n\n\n'}</PortalStreamingText>)+ const images=container.querySelectorAll('img')+ expect(images).toHaveLength(2)+ expect(images[0]).toHaveAttribute('src','https://example.com/chart.png')+ expect(images[0]).toHaveAttribute('alt','Remote')+ expect(images[0]).toHaveAttribute('title','Chart')+ expect(images[1]).toHaveAttribute('src','./chart.png')+ expect(images[1]).toHaveAttribute('data-custom-image','yes')+ expect(container).toHaveTextContent('Image unavailable: Missing')+ expect(Image.mock.calls.every(([props])=>Boolean(props.src))).toBe(true)+})++it('leaves image syntax in code examples literal',()=>{+ const syntax=''+ const {container}=render(<PortalStreamingText instant>{'`'+syntax+'`\n\n```text\n'+syntax+'\n```'}</PortalStreamingText>)+ expect(container.querySelector('p code')).toHaveTextContent(syntax)+ expect(container.querySelector('pre code')).toHaveTextContent(syntax)+ expect(container.textContent).not.toContain('Image unavailable')+ expect(container.querySelector('img')).toBeNull()+})+const mediaReceipt=(digit='a')=>({schemaVersion:1,kind:'ods-pixel-workspace-artifact',relativePath:'report.csv',siteId:`site-${digit.repeat(24)}`,sha256:digit.repeat(64),file:{path:'report.csv',bytes:37,sha256:'c'.repeat(64)}})