|
| 1 | +# @mcpjam/chat-ui |
| 2 | + |
| 3 | +A reusable, **read-only transcript renderer** for AI SDK-style chat messages |
| 4 | +(`UIMessage`). Renders text, reasoning, files, sources, JSON/data parts, |
| 5 | +approvals-as-state, and tool call/result blocks. |
| 6 | + |
| 7 | +This is **Tier A**: it does **not** render MCP Apps widgets. Widget-bearing tool |
| 8 | +calls render a deterministic placeholder (or are hidden). It has **zero runtime |
| 9 | +imports** from Convex, PostHog, inspector stores/state/contexts, the MCP Apps |
| 10 | +renderer, sandbox/iframe code, or widget replay — enforced by |
| 11 | +`scripts/check-no-tier-b-imports.mjs`. |
| 12 | + |
| 13 | +## Install |
| 14 | + |
| 15 | +```bash |
| 16 | +npm install @mcpjam/chat-ui |
| 17 | +``` |
| 18 | + |
| 19 | +Peer deps: `react`, `react-dom`, `ai`, `@ai-sdk/react`. |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +```tsx |
| 24 | +import { ReadOnlyTranscript } from "@mcpjam/chat-ui"; |
| 25 | +import "@mcpjam/chat-ui/styles.css"; |
| 26 | + |
| 27 | +export function Transcript({ messages }) { |
| 28 | + return ( |
| 29 | + <ReadOnlyTranscript |
| 30 | + messages={messages} |
| 31 | + model={{ id: "gpt-5", name: "GPT-5", provider: "openai" }} |
| 32 | + reasoningDisplayMode="collapsed" |
| 33 | + widgetPolicy="placeholder" |
| 34 | + themeMode="system" |
| 35 | + /> |
| 36 | + ); |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### `ReadOnlyTranscript` props |
| 41 | + |
| 42 | +| Prop | Type | Default | |
| 43 | +| ---------------------- | ----------------------------------------------- | -------------------------------------------------- | |
| 44 | +| `messages` | `UIMessage[]` | — | |
| 45 | +| `model` | `ChatUiModel` | `{ id: "unknown", name: "Unknown", provider: "custom" }` | |
| 46 | +| `toolsMetadata` | `Record<string, Record<string, unknown>>` | `{}` | |
| 47 | +| `toolServerMap` | `Record<string, string>` | `{}` | |
| 48 | +| `toolRenderOverrides` | `Record<string, ToolRenderOverride>` | — | |
| 49 | +| `themeMode` | `"light" \| "dark" \| "system"` | `"system"` | |
| 50 | +| `reasoningDisplayMode` | `"inline" \| "collapsible" \| "collapsed" \| "hidden"` | `"inline"` | |
| 51 | +| `widgetPolicy` | `"placeholder" \| "hidden"` | `"placeholder"` | |
| 52 | +| `className` | `string` | — | |
| 53 | + |
| 54 | +### Host integration (interactive embedders) |
| 55 | + |
| 56 | +`ReadOnlyTranscript` is fully static. Hosts that need interactivity (e.g. the |
| 57 | +MCPJam inspector) use the lower-level `Transcript` and inject seams — keeping |
| 58 | +the package free of their wiring: |
| 59 | + |
| 60 | +- `renderTool(ctx)` — render your own interactive tool block (save-view, |
| 61 | + display-mode controls, etc.) instead of the static `ToolCallPart`. |
| 62 | +- `renderWidget(input)` — mount a real widget surface instead of the placeholder. |
| 63 | + |
| 64 | +```tsx |
| 65 | +import { Transcript } from "@mcpjam/chat-ui"; |
| 66 | + |
| 67 | +<Transcript |
| 68 | + messages={messages} |
| 69 | + renderWidget={(input) => <MyWidget {...input} />} |
| 70 | + renderTool={(ctx) => <MyInteractiveToolPart {...ctx} />} |
| 71 | +/>; |
| 72 | +``` |
| 73 | + |
| 74 | +## Styling |
| 75 | + |
| 76 | +The renderer uses shadcn-style semantic utility classes |
| 77 | +(`text-muted-foreground`, `bg-card`, `border-border`, …). Consumers need a |
| 78 | +Tailwind v4-compatible utility layer. `@mcpjam/chat-ui/styles.css` ships the |
| 79 | +token *values* (scoped to `.mcpjam-chat-ui`) with light/dark defaults; override |
| 80 | +any `--token` to theme. |
| 81 | + |
| 82 | +> A fully self-contained compiled CSS bundle (so consumers don't need their own |
| 83 | +> Tailwind) is a planned follow-up. |
| 84 | +
|
| 85 | +## Scope |
| 86 | + |
| 87 | +Tier A is read-only transcript review. Full MCP Apps widget replay (sandbox |
| 88 | +origin, CSP, security review) is a separate Tier B effort. |
0 commit comments