Skip to content

About

Generative UI two ways: json-render with an LLM vs Jev (TypeSafe System One), via the AI SDK and OpenRouter

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

json-render + Jev playground

Generative UI three ways, with the same catalog, the same renderer and the same components:

  • LLM mode: an LLM writes the UI as a json-render spec, streamed token by token as JSON patches.

  • Jev mode: Jev, TypeSafe's "System One" decision model, picks and arranges prepared component candidates. json-render turns those choices into the same spec. New UIs take two evaluations and produce no output tokens.

  • Hybrid experiment: Jev chooses and arranges components while an LLM fills their actual content props: headings, descriptions, labels and a profile bio. Both start together. Facts, data bindings and actions stay under app control.

A stopwatch and scoreboard compare completed runs. The Stream tab shows the LLM's patches, or Jev's decisions with their confidence scores.

Setup

bun install
cp .env.example .env.local   # add your OpenRouter key
bun dev

One OpenRouter key powers all three modes:

Variable Required Default
OPENROUTER_API_KEY yes —
OPENROUTER_LLM_MODEL no anthropic/claude-haiku-4.5
OPENROUTER_JEV_MODEL no typesafe/jev-1.13

Try: "Generate a sales dashboard with an orders table at the top, then revenue, orders and new customers metrics in a row, then a weekly revenue chart." Then follow up with "Move the table below the chart" to edit it.

How it works

File Role
lib/render/catalog.ts The contract: components and props the AI may use (json-render shadcn components plus custom Metric and charts)
lib/render/registry.tsx Maps catalog names to real React components; shared by all modes
lib/llm/generate.ts LLM mode: catalog.prompt() system prompt and AI SDK streamText
lib/jev/candidates.ts The menu Jev chooses from: configured component instances plus descriptions
lib/jev/evaluator.ts Runs json-render's composition evaluator on Jev through OpenRouter's Decisions API (AI SDK experimental_evaluate)
lib/jev/compose.ts Jev mode: shared composition streamed as JSON patches
app/api/generate/route.ts A single endpoint for all modes
hooks/use-generation.ts Client stream reader, spec assembly and timings

The Jev APIs in @json-render/core are experimental (experimental_*), so package versions are pinned exactly.

Hybrid research experiment

This prototype explores whether separating layout decisions from copy generation is useful. Its value over a fixed layout plus an LLM has not been established.

Select Hybrid and use the onboarding example: Maya Chen, a product designer joining Studio North, wants to share her first prototype for feedback. Jev selects a welcome, introduction and three onboarding steps. The LLM writes their text, title, description and buttonLabel values for that context. There is no separate summary card.

The copy fields are bound to reserved app-state paths. lib/hybrid/merge.ts prepares that allowlist and overlays streamed text on every layout snapshot, so a later layout change cannot erase content. The LLM returns a small JSON object of strings; it cannot change component types, layout, actions, metric values or identity fields. It gets the prepared fields up front, including options Jev may not select, which lets both requests start together. lib/hybrid/generate.ts parses partial JSON so text can appear before the response is complete.

lib/jev/onboarding.ts defines the demo user context and prepared onboarding steps. components/onboarding-step.tsx renders each step; its button marks a local checklist item complete. It does not send invitations or create a real project. In pure Jev mode the copy comes from prepared candidates and lib/demo-data.ts; Jev does not write it.

Layout complete and Copy complete show separate server timings. Preview, Spec and Stream display the combined result. Each mode keeps its own UI, prompt, timings, stream log and form state when switching. In-flight generations continue in their mode. New clears only the selected mode; completed timings remain in the scoreboard.

Hybrid calls both models, so total time is not directly comparable to a layout-only run. First-element timing measures receipt of a renderable spec, not browser paint. A failed or cancelled run can retain a partial UI. This is a custom integration, not an official json-render example.

Run the content-binding and stream-merging tests with bun test lib/hybrid/merge.test.ts.

Chat with a Jev UI tool

Open /chat (or click Open chat in the playground). The existing playground stays at /.

The AI SDK ToolLoopAgent answers normal questions in text. For a visual or interactive request, it calls renderUI with a task, relevant conversation context and optionally a previous UI ID. The tool invokes Jev through the shared composition engine and streams spec snapshots as preliminary tool results. The conversation renders them with the same catalog, registry and SpecPreview as the playground.

The main agent does not receive catalog.prompt(), component schemas or composition instructions. The tool's toModelOutput returns compact metadata (UI ID, request, component names and completion status), keeping the full spec and app-state payload out of model context on both the immediate follow-up and later turns. Full results remain in the browser conversation so the tool can retrieve an earlier spec for edits. This reduces model context; it does not remove UI payloads from browser memory or HTTP requests.

Try this sequence:

  1. “Explain generative UI in two sentences.” — text only.
  2. “Show a sales dashboard with an orders table, three metrics and a weekly revenue chart.” — Jev tool call and inline UI.
  3. “Move the table below the chart.” — a new UI result revising the earlier spec.

Expand Tool details to inspect the agent's request, the context handed to Jev and the compact result returned to the chat model. Stop cancels a response; New chat clears the current conversation. Conversations are in-memory and reset on page reload. Generated controls operate on local demo state.

File Role
lib/chat/agent.ts Main AI SDK agent and its short conversational instructions
lib/chat/tools.ts renderUI tool, streaming results and compact model output
lib/chat/protocol.ts Typed chat/tool messages and completed UI history
lib/jev/stream.ts Shared Jev composition used by chat and the Jev playground
app/api/chat/route.ts AI SDK UI message streaming endpoint
components/chat/ Chat, composer, messages and inline generated UI

Uses the existing OpenRouter key and OPENROUTER_LLM_MODEL / OPENROUTER_JEV_MODEL. Test the tool boundary and context isolation with bun test lib/chat/tools.test.ts.

Chat UI source

The chat presentation is adapted from shadcn-ui/chatbot-template at f79416827acd90244683903a34343f58193432ac. It uses the template's InputGroup composer, Message/Bubble primitives, @shadcn/react message scroller, shimmering thinking state, and markdown/typeset/code rendering. The compact header, centered welcome and conversation widths follow the template. The existing OpenRouter agent and Jev tool remain connected; the composer shows their fixed configuration instead of the template's Gateway model picker.

Template-derived components are in components/ui/ and components/chat/; typography is in app/typeset.css. The original MIT notice is retained in licenses/chatbot-template-MIT.txt.

Generated previews omit empty Card/Stack/Grid containers, while retaining the original spec for inspection and edits. Cards also shrink to their grid column; grids stack when their preview container is narrow. These rules apply to the playground as well as chat.

About

Generative UI two ways: json-render with an LLM vs Jev (TypeSafe System One), via the AI SDK and OpenRouter

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages