Skip to content

feat: JSX preview in chat with artifact and web preview support#141

Merged
shzd-tridz merged 32 commits intodevelopfrom
feature/jsx-in-chat
Feb 13, 2026
Merged

feat: JSX preview in chat with artifact and web preview support#141
shzd-tridz merged 32 commits intodevelopfrom
feature/jsx-in-chat

Conversation

@esafwan
Copy link
Contributor

@esafwan esafwan commented Feb 9, 2026

Summary

Adds JSX preview rendering in chat messages, along with artifact and web preview infrastructure.

Changes

  • Parsing: artifact, web-preview, and jsx-preview tag parsers with code fence unwrapping
  • Renderers: MessageContentWithArtifacts, ArtifactRenderer, WebPreviewRenderer, Mermaid
  • JSX Preview: Recharts, shadcn/ui, Lucide icons, data utilities; PNG export via html-to-image (oklch-compatible)
  • Chat integration: Full-width assistant messages, compact collapsible sidebar (Recents default)
  • Documentation: AI elements usage and web preview guides

esafwan and others added 22 commits February 9, 2026 22:53
- Add artifact.types for ParsedArtifact, ParsedWebPreview, ParsedJSXPreview
- Add artifactParser for <artifact> tag parsing
- Add webPreviewParser for <web-preview> tag parsing
- Add jsxPreviewParser for <jsx-preview> tag parsing
- Support code fence unwrapping for jsx-preview in markdown
- Add MessageContentWithArtifacts to parse and render artifacts, web previews, JSX
- Add ArtifactRenderer for code, html, svg, mermaid artifacts
- Add WebPreviewRenderer for iframe-based web previews
- Add Mermaid component for diagram rendering
- Decode HTML entities for escaped tags
- Add JSXPreview component with react-jsx-parser, streaming support
- Support Recharts (BarChart, LineChart, PieChart, etc.)
- Support shadcn/ui (Card, Badge, Alert, Table, Tabs, etc.)
- Support Lucide icons and data formatting utilities
- Add JSXPreviewRenderer for chat message integration
- Use html-to-image for PNG export (oklch-compatible)
- Hide export buttons during PNG capture
- Add html-to-image dependency, remove html2canvas
- Use MessageContentWithArtifacts in ChatMessage for V2 chat
- Add MessageContentWithArtifacts to ChatWindow for legacy chat
- Full-width assistant messages for JSX preview
- Rename sidebar title from Workspaces to Chat
- Default to Recents tab to prioritize conversations
- Reduce padding and spacing for compact layout
- Add collapsible sidebar with toggle button
- Narrow sidebar width (w-96 to w-80)
- Add left padding to header for toggle alignment
- Add AI-ELEMENTS-USAGE.md for artifact usage
- Add AI-ELEMENTS-WEBPREVIEW-ARTIFACT-GUIDE.md for web previews
- Update agent_message doctype if applicable
Add utility functions to determine OCR processing strategy and select
appropriate models based on file type and provider.

- _determine_ocr_strategy(): Routes PDFs to OCR endpoint, images to vision models
- _get_default_ocr_model(): Auto-selects model based on provider and strategy

These functions enable intelligent file-type routing for optimal OCR results.
Add create_ocr_document_tool() function to register OCR tool in
Agent Tool Function system.

Features:
- Creates OCR tool type if not exists
- Registers tool with parameters: file_id, file_url, pages, include_images, model
- Updates after_install() and after_migrate() hooks
- Idempotent (handles both creation and updates)

Tool enables agents to extract text from PDFs and images using
intelligent routing to OCR endpoint or vision models.
Add _process_with_ocr_endpoint() function to handle PDF and multi-page
document processing using LiteLLM's OCR endpoint.

Features:
- Base64 encoding of document content
- Multi-page support with page selection
- Optional embedded image extraction
- Markdown-formatted text output
- Page-by-page breakdown with dimensions

Uses litellm.ocr() API for optimal PDF processing results.
Add _process_with_vision_model() function to handle single image OCR
using LiteLLM vision models (GPT-4o, Claude, Gemini, etc.).

Features:
- Base64 encoding of image content
- Vision model integration via litellm.completion()
- Markdown-formatted text output
- Better context understanding for images

Uses vision models for optimal single-image OCR results.
Add handle_ocr_document() function that intelligently routes documents
to appropriate processing method based on file type.

Features:
- File lookup by file_id or file_url with fallback
- Intelligent strategy selection (OCR for PDFs, Vision for images)
- Auto-model detection based on provider and strategy
- Agent Message creation with extracted text
- WebSocket events for real-time updates
- Comprehensive error handling

Routes PDFs to OCR endpoint and images to vision models for optimal results.
- Add 'upload_file_and_process' whitelist method to handle file uploads.
- Decode base64 file data and save as 'Agent Message' attachment.
- Asynchronously trigger 'handle_ocr_document' for processing.
- Ensure correct agent and conversation context is maintained.
- Add file upload button for PDFs and images in chat interface.
- Implement 'sendDocToServer' to handle file uploads via 'upload_file_and_process'.
- Handle real-time WebSocket updates to display extracted text immediately.
- Update 'append_message' to support new message types.
- Added 'Standard Tools' section to AGENTS.md
- Documented 'ocr_document' parameters and functionality for text extraction
- Documented 'generate_image'parameters for AI image creation
- Clarified that these tools are automatically registered and available to agents
@shzd-tridz shzd-tridz marked this pull request as ready for review February 13, 2026 10:22
Add a Select field (Text, JSX, Mermaid, Markdown, Artifact, HTML, Image)
to Agent Message for future categorization and filtering of message
content types. Not required; purely additive.
Add PreviewViewPage at /huf/view/:messageId that fetches an Agent
Message, parses JSX previews and artifacts, and renders them full-screen
with a minimal toolbar (back-to-chat link + export).

Also includes the official ai-elements jsx-preview component installed
via npx ai-elements for future migration reference.
Add an "Open full screen" button to JSXPreviewRenderer and
ArtifactRenderer (for jsx/chart types) that opens the message content
in the new /huf/view/:messageId page in a new tab.

Thread messageId (Agent Message doc name) from
MessageContentWithArtifacts and ChatWindow through to the renderers.
Replace toReversed() with [...stack].reverse() (ES2023 not in lib).
Add explicit type for map callback parameter (tag: string).
Parse and display full message content (text, JSX, web previews, artifacts)
in the same order and structure as chat. Use MessageResponse,
JSXPreviewRenderer, WebPreviewRenderer, and ArtifactRenderer. Show
'No content' only when message is empty. Omit messageId on view page
so Open button is not shown.
…erlay content

Wrap content in pt-10 in JSXPreviewRenderer and in ArtifactRenderer
(jsx/chart case) so PNG, SVG, and Open buttons sit above the content.
Default view shows only JSX previews and jsx/chart artifacts. Use
?preview=full for full message. Move Full message / JSX only toggle
to right-aligned toolbar next to Export PNG.
@shzd-tridz shzd-tridz merged commit 63f5e04 into develop Feb 13, 2026
1 of 3 checks passed
@Sanjusha-tridz Sanjusha-tridz deleted the feature/jsx-in-chat branch February 13, 2026 14:07
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.

4 participants