Skip to content

Fix Chat Interactions shows "!caption" text instead of preview images when an answer also offers a download - #236

Open
JackTelford wants to merge 1 commit into
CrestApps:mainfrom
JackTelford:jt-fix-chat-interaction-image-previews
Open

JackTelford wants to merge 1 commit into
CrestApps:mainfrom
JackTelford:jt-fix-chat-interaction-image-previews

Conversation

@JackTelford

Copy link
Copy Markdown
Contributor

Fixes #235

The bug

On the MVC sample's Chat Interactions page, an answer that both previews a document and offers it as a download showed the preview captions as plain text with a stray ! (!Slide 9: Executive Summary: Key KPIs) instead of the images. It affected the PowerPoint, Word and PDF agents alike. Previews without a download rendered fine, which made it look intermittent.

Why it happened

Chat.cshtml has its own inline rendering pipeline:

  1. expandImageMarkers turns [fig:N] into ![caption](/ai/documents/{id}/download).
  2. When the message carries download references, replaceGeneratedMarkdownLinks rewrites markdown links with /\[([^\]]+)\]\(([^)]+)\)/g.
  3. That pattern also matched the [caption](url) inside the image syntax. The image matched no download, so it was replaced by its label, leaving !caption as text before markdown ran.

The fix

The pattern now also captures an optional leading !. When it is present, the match is image markdown and is returned untouched. Ordinary links are handled exactly as before.

return content.replace(/(!?)\[([^\]]+)\]\(([^)]+)\)/g, function (match, imagePrefix, label, url) {
    if (imagePrefix) {
        return match;
    }
    // unchanged link handling
});

Scope

  • One function in src/Startup/CrestApps.Core.Mvc.Web/Areas/ChatInteractions/Views/ChatInteraction/Chat.cshtml.
  • The shared ai-chat.js and chat-interaction.js never had this function and are unchanged.
  • No library package changes, so CrestApps.OrchardCore is unaffected.
  • Existing messages render correctly after the fix, since the stored content was never wrong.

How to test

In a Chat Interaction with the presentation tools, send:

Create a 3-slide deck titled "Repro Test": a title slide, one slide with a column chart of Q1=10, Q2=20, Q3=15, and a closing slide. In this same reply, show me a preview of all 3 slides and give me the .pptx download.

Expected: the slide previews render as an image carousel, and the .pptx link appears below them. The same check applies to Word (.docx) and PDF (.pdf).

🤖 Generated with Claude Code

…wnload

replaceGeneratedMarkdownLinks matched the [caption](url) inside an expanded
figure image and rewrote it to its label, leaving "!caption" as text. Image
syntax is now left untouched.

Fixes CrestApps#235
@JackTelford JackTelford changed the title Keep preview images in Chat Interactions answers that also offer a download Allow preview images in Chat Interactions that also offer a download link Oct 9, 2026
@JackTelford JackTelford changed the title Allow preview images in Chat Interactions that also offer a download link Chat Interactions shows "!caption" text instead of preview images when an answer also offers a download Oct 9, 2026
@JackTelford JackTelford changed the title Chat Interactions shows "!caption" text instead of preview images when an answer also offers a download Fix Chat Interactions shows "!caption" text instead of preview images when an answer also offers a download Oct 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat Interactions shows "!caption" text instead of preview images when an answer also offers a download

1 participant