AI UI Generation

Generate and render AI-created user interfaces with streaming support.

Overview

The AI generation system provides hooks and utilities for creating UIs from natural language prompts using Claude AI.

@m0rphic/jsx-renderCore rendering engine and types

Note

All exports are available from the main entry point: import { renderJSX, validateElement, ... } from '@m0rphic/jsx-render'

Basic Usage

Use renderJSX to render AI-generated JSXElement structures. Here's a complete example:

ai-component.tsx

renderJSX Function

Safely renders JSXElement JSON to React components with handler binding and custom component support.

typescript

Note

renderJSX automatically applies XSS protection, validating all elements before rendering.

Security

The rendering system includes multiple security layers to prevent XSS and injection attacks:

✓Tag whitelist - only allowed HTML tags and registered components can render
✓Prop filtering - dangerous props like dangerouslySetInnerHTML are blocked
✓URL protocol whitelist - only https:, http:, mailto:, tel: are allowed
✓Handler reference system - no inline JavaScript, only registered handlers
typescript

Server Setup

Create an API endpoint that streams UI generation using the server-side generator.

app/api/generate/route.ts

Streaming Protocol

The streaming protocol uses JSONL (JSON Lines) with patch operations for incremental updates.

json

Tip

The JSONL patch protocol enables real-time UI updates as the AI generates content, providing immediate visual feedback to users.