Skip to content

Generative UI: structured component system for rich chat responses#210

Draft
esafwan wants to merge 3 commits into
developfrom
dev/huf-generative-ui-evaluation-ec71
Draft

Generative UI: structured component system for rich chat responses#210
esafwan wants to merge 3 commits into
developfrom
dev/huf-generative-ui-evaluation-ec71

Conversation

@esafwan
Copy link
Copy Markdown
Contributor

@esafwan esafwan commented Mar 19, 2026

Summary

Implements a structured UI component system (<ui-component> tags) that enables AI agents to render rich, interactive React components inline in chat messages. No backend changes required.

What This Adds

Structured Tag System

AI agents can now emit <ui-component> tags in their text responses to render purpose-built components:

<ui-component type="stats-card" data='{"title":"Revenue","value":48250,"change":12.5,"format":"currency"}' />

The tag is parsed, the type is looked up in a registry, and the appropriate React renderer displays a polished component inline. Surrounding text renders normally as markdown.

9 ERP/Analytics-Focused Renderers

Type Use Case
stats-card Single KPI metric with trend indicator
kpi-grid Multiple KPIs in responsive grid
bar-chart Category comparisons (vertical/horizontal/stacked)
line-chart Trends over time with multi-series support
pie-chart Distribution/proportion breakdowns (pie or donut)
area-chart Stacked/layered area visualization
data-table Formatted tables with badge-styled status columns
progress-card Target tracking with single or multi progress bars
info-card Document detail cards with key-value sections

Architecture

AI Response Text
  ↓
MessageContentWithArtifacts (existing)
  ↓ detects <ui-component> tags
uiComponentParser.ts (new)
  ↓ extracts type + JSON data
registry.ts (new)
  ↓ maps type → renderer
UIComponentRenderer.tsx (new)
  ↓ renders or shows fallback
StatsCardRenderer / BarChartRenderer / etc. (new)

Follows the exact same pattern as existing <artifact>, <jsx-preview>, and <web-preview> parsers.

Graceful Fallback

  • Unknown type → shows alert with raw JSON data
  • Invalid JSON → shows error message
  • Missing data → renderer returns null (no crash)
  • During streaming → tag only renders once /> is fully received

Files Changed

New Files

  • frontend/src/utils/uiComponentParser.ts — tag parser
  • frontend/src/components/chat/ui-components/registry.ts — type → renderer map
  • frontend/src/components/chat/ui-components/UIComponentRenderer.tsx — dispatcher
  • frontend/src/components/chat/ui-components/renderers/ — 9 renderer components
  • docs/evaluations/generative-ui-feasibility.md — feasibility analysis report
  • docs/evaluations/generative-ui-testing-guide.md — testing guide with 10 ERP examples

Modified Files

  • frontend/src/types/artifact.types.ts — added ParsedUIComponent types
  • frontend/src/components/chat/MessageContentWithArtifacts.tsx — wired in UI component parsing

How to Test

See docs/evaluations/generative-ui-testing-guide.md for detailed instructions. Quick summary:

  1. Add the agent instruction template to any AI agent's system prompt
  2. Ask ERP questions like "Show me revenue for Q1" or "List outstanding invoices"
  3. Agent responds with <ui-component> tags that render as interactive charts, tables, and cards

Alternatively, inject test messages directly via Frappe API (documented in the testing guide).

Verification

  • TypeScript: npx tsc --noEmit passes with 0 errors
  • ESLint: All new and changed files lint cleanly
  • No backend changes required — purely frontend
  • No new dependencies added — uses existing Recharts and shadcn/ui
Open in Web Open in Cursor 

cursoragent and others added 3 commits March 19, 2026 02:20
Comprehensive analysis of whether Tambo-style generative UI can be
implemented in Huf's chat feature. Key findings:

- Huf already has ~80% of the infrastructure via jsx-preview system
- react-jsx-parser + 100+ component registry already renders AI-generated
  React components in chat
- Recommends Tier 1 structured tag approach (<ui-component>) for reliable
  data/presentation separation
- No backend changes needed; ~200-300 lines of frontend additions
- No separate POC required — integrates directly into existing chat

Includes detailed architecture analysis, integration options, challenges,
and a concrete minimal implementation example.

Co-authored-by: Safwan Erooth <esafwan@users.noreply.github.com>
Add <ui-component> tag parsing and rendering pipeline alongside existing
artifact/jsx-preview/web-preview systems. Nine purpose-built renderers
for ERP/analytics use cases:

- stats-card: Single KPI metric with trend indicator
- kpi-grid: Multiple KPIs in responsive grid layout
- bar-chart: Vertical/horizontal/stacked bar charts via Recharts
- line-chart: Trend lines with multi-series support
- pie-chart: Pie/donut charts with labels
- area-chart: Stacked/layered area charts
- data-table: Sortable tables with badge-formatted status columns
- progress-card: Single or multi-bar progress tracking
- info-card: Key-value detail cards with status badges

Architecture:
- Parser (uiComponentParser.ts): Extracts <ui-component> self-closing tags
- Registry (registry.ts): Maps type strings to renderer components
- Dispatcher (UIComponentRenderer.tsx): Renders or shows graceful fallback
- Integration: Wired into MessageContentWithArtifacts parsing pipeline

No backend changes required. AI agents emit structured tags in their text
responses; the frontend handles rendering with typed, validated data.

Co-authored-by: Safwan Erooth <esafwan@users.noreply.github.com>
Detailed step-by-step documentation covering:

- 10 ERP/analytics test examples with exact agent prompts,
  expected response formats, and rendered output descriptions
- Agent instruction templates (minimal and full versions)
- Quick-test methods without an AI agent (browser console,
  Frappe API message injection, parser unit tests)
- Complete component reference with all properties and types
- Troubleshooting guide for common issues

Examples cover realistic ERP scenarios:
- Revenue KPIs and financial dashboards
- Regional sales comparison charts
- Monthly revenue trends with target overlays
- Expense breakdowns (pie/donut charts)
- Cash flow area charts
- Outstanding invoice tables with status badges
- Quarterly target progress bars
- Sales order detail cards
- Full multi-component sales reports

Co-authored-by: Safwan Erooth <esafwan@users.noreply.github.com>
@cursor cursor Bot changed the title Generative UI feasibility evaluation report Generative UI: structured component system for rich chat responses Mar 19, 2026
@shzdb
Copy link
Copy Markdown
Collaborator

shzdb commented Mar 24, 2026

Inject the system prompt with a checkbox "Use generative UI"

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.

3 participants