Skip to content

The Open Standard for Generative UI

chore(examples): standardize example chat wiring on fetchLLM (#711)

Ankit Das1e96f7620275
diff --git a/docs/public/AGENTS.md b/docs/public/AGENTS.md
index 0ac348586..e6f5163f2 100644
--- a/docs/public/AGENTS.md
+++ b/docs/public/AGENTS.md
@@ -211,8 +211,8 @@ export async function POST(req: Request) {
}
```
-`fetchLLM` POSTs `{ threadId, messages: messageFormat.toApi(messages) }` to `url`
-and forwards the abort signal. Here `messages` is the **full thread history** (the
+`fetchLLM` POSTs `{ threadId, runId, messages: messageFormat.toApi(messages), tools: [], context: [] }`
+to `url` and forwards the abort signal. Here `messages` is the **full thread history** (the
SDK loads it from `storage` and holds it client-side), so forward all of it to your
provider. (Contrast Cloud, where you send only the latest because Cloud replays the
conversation.) Your route must **stream** and **close the stream when done** (the
diff --git a/examples/form-generator/src/app/page.tsx b/examples/form-generator/src/app/page.tsx
index 41ed70788..ff3054b81 100644
--- a/examples/form-generator/src/app/page.tsx
+++ b/examples/form-generator/src/app/page.tsx
@@ -3,6 +3,7 @@
import { herouiChatLibrary } from "@/lib/heroui-genui";
import type { Message } from "@openuidev/react-headless";
import {
+ fetchLLM,
openAIAdapter,
openAIMessageFormat,
processStreamedMessage,
@@ -34,6 +35,12 @@ const STARTERS = [
];
+const llm = fetchLLM({
+ url: "/api/chat",
+ streamAdapter: openAIAdapter(),
+ messageFormat: openAIMessageFormat,
+});
+
export default function Page() {
const [instruction, setInstruction] = useState("");
const [messages, setMessages] = useState<Message[]>([]);
@@ -68,13 +75,9 @@ export default function Page() {
let draftContent = "";
try {
- const response = await fetch("/api/chat", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- messages: openAIMessageFormat.toApi(nextMessages as any),
- }),
+ const response = await llm.send({
+ threadId: "form",
+ messages: nextMessages,
signal: abortController.signal,
});
@@ -89,7 +92,7 @@ export default function Page() {
await processStreamedMessage({
response,
- adapter: openAIAdapter(),
+ adapter: llm.streamProtocol,
createMessage: applyContent,
updateMessage: applyContent,
});
diff --git a/examples/hands-on-table-chat/src/app/api/chat/route.ts b/examples/hands-on-table-chat/src/app/api/chat/route.ts
index a88de26d0..d9aa96c81 100644
--- a/examples/hands-on-table-chat/src/app/api/chat/route.ts
+++ b/examples/hands-on-table-chat/src/app/api/chat/route.ts
@@ -142,9 +142,9 @@ function sseToolCallArgs(
}
export async function POST(req: NextRequest) {
- const { messages, threadId } = await req.json();
+ const { messages } = await req.json();
- setCurrentThreadId(threadId ?? "default");
+ setCurrentThreadId("default");
/* eslint-disable @typescript-eslint/no-explicit-any */
const lastUserMsg = (messages as any[])
diff --git a/examples/hands-on-table-chat/src/app/page.tsx b/examples/hands-on-table-chat/src/app/page.tsx
index fc3f3ea24..7d418e52e 100644
--- a/examples/hands-on-table-chat/src/app/page.tsx
+++ b/examples/hands-on-table-chat/src/app/page.tsx
@@ -1,40 +1,26 @@
"use client";
import { spreadsheetLibrary } from "@/lib/spreadsheet-library";
-import {
- AgentInterface,
- openAIAdapter,
- openAIMessageFormat,
- type ChatLLM,
-} from "@openuidev/react-ui";
+import { AgentInterface, fetchLLM, openAIAdapter, openAIMessageFormat } from "@openuidev/react-ui";
import { MessageSquare, PanelRightClose } from "lucide-react";
import dynamic from "next/dynamic";
import { useCallback, useEffect, useMemo, useState } from "react";
-import { TableProvider, useTableContext } from "./TableContext";
+import { TableProvider } from "./TableContext";
const PersistentSpreadsheet = dynamic(() => import("./PersistentSpreadsheet"), { ssr: false });
function ChatPanel({ onClose }: { onClose: () => void }) {
- const { threadId } = useTableContext();
-
// AgentInterface uses its built-in in-memory storage default (wiped on reload).
- // The backend call is unchanged — only the chat surface moved from Copilot to
- // AgentInterface.
- const llm = useMemo<ChatLLM>(
- () => ({
- send: ({ messages, signal }) =>
- fetch("/api/chat", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({
- messages: openAIMessageFormat.toApi(messages),
- threadId,
- }),
- signal,
- }),
- streamProtocol: openAIAdapter(),
- }),
- [threadId],
+ // fetchLLM sends AgentInterface's per-thread id, but the server ignores it and
+ // keys the shared table store on "default" (see api/chat/route.ts).
+ const llm = useMemo(
+ () =>
+ fetchLLM({
+ url: "/api/chat",
+ streamAdapter: openAIAdapter(),
+ messageFormat: openAIMessageFormat,
+ }),
+ [],
);
return (
diff --git a/examples/harnesses/vercel-eve/AGENTS.md b/examples/harnesses/vercel-eve/AGENTS.md
index ef84069db..e2cdf6fcd 100644
--- a/examples/harnesses/vercel-eve/AGENTS.md
+++ b/examples/harnesses/vercel-eve/AGENTS.md
@@ -1,3 +1,7 @@
# eve Agent App
This project uses the eve framework. Before writing code, always read the relevant guide in `node_modules/eve/docs/`.
+
+## OpenUI chat wiring
+
+The hand-written `ChatLLM` in `src/eve-chat.ts` is an intentional exception to the repo's fetchLLM-first convention: there is no HTTP chat endpoint here. Its `send` drives Eve's native session protocol (`POST /eve/v1/session`, resumable NDJSON event stream) and synthesizes the AG-UI SSE stream client-side from Eve session events, so `fetchLLM` does not apply — do not migrate it. Normal HTTP chat backends should use `fetchLLM` from `@openuidev/react-ui` instead of hand-writing a `ChatLLM`.
diff --git a/examples/mastra-chat/src/app/page.tsx b/examples/mastra-chat/src/app/page.tsx
index 8571dbdfe..58fd715a1 100644
--- a/examples/mastra-chat/src/app/page.tsx
+++ b/examples/mastra-chat/src/app/page.tsx
@@ -1,27 +1,22 @@
"use client";
import { useTheme } from "@/hooks/use-system-theme";
-import { AgentInterface, agUIAdapter, type ChatLLM } from "@openuidev/react-ui";
+import { AgentInterface, agUIAdapter, fetchLLM } from "@openuidev/react-ui";
import { openuiChatLibrary } from "@openuidev/react-ui/genui-lib";
import { useMemo } from "react";
export default function Page() {
const mode = useTheme();
- // The backend call is unchanged — only the chat surface moved from FullScreen
- // to AgentInterface. Storage is omitted, so AgentInterface uses its built-in
- // in-memory default (wiped on reload).
- const llm = useMemo<ChatLLM>(
- () => ({
- send: ({ messages, threadId, signal }) =>
- fetch("/api/chat", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ messages, threadId }),
- signal,
- }),
- streamProtocol: agUIAdapter(),
- }),
+ // fetchLLM's default message format POSTs { messages, threadId, ... } —
+ // exactly what the Mastra route expects. Storage is omitted, so
+ // AgentInterface uses its built-in in-memory default (wiped on reload).
+ const llm = useMemo(
+ () =>
+ fetchLLM({
+ url: "/api/chat",
+ streamAdapter: agUIAdapter(),
+ }),
[],
);
diff --git a/examples/material-ui-chat/src/app/page.tsx b/examples/material-ui-chat/src/app/page.tsx
index 264e23e90..da8a4899e 100644
--- a/examples/material-ui-chat/src/app/page.tsx
+++ b/examples/material-ui-chat/src/app/page.tsx
@@ -5,12 +5,7 @@ import LightModeIcon from "@mui/icons-material/LightMode";
import Box from "@mui/material/Box";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
-import {
- AgentInterface,
- openAIAdapter,
- openAIMessageFormat,
- type ChatLLM,
-} from "@openuidev/react-ui";
+import { AgentInterface, fetchLLM, openAIAdapter, openAIMessageFormat } from "@openuidev/react-ui";
import { useMemo } from "react";
import { useColorMode } from "@/hooks/use-system-theme";
@@ -19,17 +14,13 @@ import { muiChatLibrary } from "@/lib/mui-genui";
export default function Page() {
const { mode, toggle } = useColorMode();
- const llm = useMemo<ChatLLM>(
- () => ({
- send: ({ messages, signal }) =>
- fetch("/api/chat", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ messages: openAIMessageFormat.toApi(messages) }),
- signal,
- }),
- streamProtocol: openAIAdapter(),
- }),
+ const llm = useMemo(
+ () =>
+ fetchLLM({
+ url: "/api/chat",
+ streamAdapter: openAIAdapter(),
+ messageFormat: openAIMessageFormat,
+ }),
[],
);
diff --git a/examples/openui-chat/src/app/page.tsx b/examples/openui-chat/src/app/page.tsx
index f3d7d3433..ad2913f65 100644
--- a/examples/openui-chat/src/app/page.tsx
+++ b/examples/openui-chat/src/app/page.tsx
@@ -1,32 +1,23 @@
"use client";
import { useTheme } from "@/hooks/use-system-theme";
-import {
- AgentInterface,
- openAIAdapter,
- openAIMessageFormat,
- type ChatLLM,
-} from "@openuidev/react-ui";
+import { AgentInterface, fetchLLM, openAIAdapter, openAIMessageFormat } from "@openuidev/react-ui";
import { openuiChatLibrary } from "@openuidev/react-ui/genui-lib";
import { useMemo } from "react";
export default function Page() {
const mode = useTheme();
- // AgentInterface uses its built-in in-memory storage (wiped on reload). The
- // backend call is unchanged — only the chat surface moved from FullScreen to
- // AgentInterface.
- const llm = useMemo<ChatLLM>(
- () => ({
- send: ({ messages, signal }) =>
- fetch("/api/chat", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ messages: openAIMessageFormat.toApi(messages) }),
- signal,
- }),
- streamProtocol: openAIAdapter(),
- }),
+ // AgentInterface uses its built-in in-memory storage (wiped on reload).
+ // fetchLLM POSTs the run payload to /api/chat, sending messages in OpenAI
+ // format and parsing the OpenAI-style SSE response.
+ const llm = useMemo(
+ () =>
+ fetchLLM({
+ url: "/api/chat",
+ streamAdapter: openAIAdapter(),
+ messageFormat: openAIMessageFormat,
+ }),
[],
);
diff --git a/examples/react-email/package.json b/examples/react-email/package.json
index b5d656cf9..9281e8e5d 100644
--- a/examples/react-email/package.json
+++ b/examples/react-email/package.json
@@ -11,9 +11,9 @@
},
"dependencies": {
"@openuidev/cli": "workspace:*",
- "@openuidev/react-email": "0.2.4",
- "@openuidev/react-headless": "0.8.2",
- "@openuidev/react-lang": "0.2.6",
+ "@openuidev/react-email": "workspace:*",
+ "@openuidev/react-headless": "workspace:*",
+ "@openuidev/react-lang": "workspace:*",
"@react-email/components": "^0.0.41",
"@react-email/render": "^1.0.6",
"lucide-react": "^0.562.0",
diff --git a/examples/react-email/src/app/page.tsx b/examples/react-email/src/app/page.tsx
index baf037f3d..36dc1f817 100644
--- a/examples/react-email/src/app/page.tsx
+++ b/examples/react-email/src/app/page.tsx
@@ -1,8 +1,9 @@
"use client";
-import { useCallback, useEffect, useRef, useState } from "react";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import {
ChatProvider,
+ fetchLLM,
openAIAdapter,
openAIMessageFormat,
useThread,
@@ -70,21 +71,21 @@ function EmailApp() {
// ── Page Root ──
export default function Page() {
+ // fetchLLM POSTs the run payload to /api/chat, sending messages in OpenAI
+ // format and parsing the OpenAI-style SSE response.
+ const llm = useMemo(
+ () =>
+ fetchLLM({
+ url: "/api/chat",
+ streamAdapter: openAIAdapter(),
+ messageFormat: openAIMessageFormat,
+ }),
+ [],
+ );
+
return (
<div style={{ height: "100vh", width: "100vw", overflow: "hidden" }}>
- <ChatProvider
- processMessage={async ({ messages, abortController }) => {
- return fetch("/api/chat", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({
- messages: openAIMessageFormat.toApi(messages),
- }),
- signal: abortController.signal,
- });
- }}
- streamProtocol={openAIAdapter()}
- >
+ <ChatProvider llm={llm}>
<EmailApp />
</ChatProvider>
</div>
diff --git a/examples/shadcn-chat/src/app/page.tsx b/examples/shadcn-chat/src/app/page.tsx
index 51561636b..42bec3125 100644
--- a/examples/shadcn-chat/src/app/page.tsx
+++ b/examples/shadcn-chat/src/app/page.tsx
@@ -2,30 +2,19 @@
import { useTheme } from "@/hooks/use-system-theme";
import { shadcnChatLibrary } from "@/lib/shadcn-genui";
-import {
- AgentInterface,
- openAIAdapter,
- openAIMessageFormat,
- type ChatLLM,
-} from "@openuidev/react-ui";
+import { AgentInterface, fetchLLM, openAIAdapter, openAIMessageFormat } from "@openuidev/react-ui";
import { useMemo } from "react";
export default function Page() {
const mode = useTheme();
- const llm = useMemo<ChatLLM>(
- () => ({
- send: ({ messages, signal }) =>
- fetch("/api/chat", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({
- messages: openAIMessageFormat.toApi(messages),
- }),
- signal,
- }),
- streamProtocol: openAIAdapter(),
- }),
+ const llm = useMemo(
+ () =>
+ fetchLLM({
+ url: "/api/chat",
+ streamAdapter: openAIAdapter(),
+ messageFormat: openAIMessageFormat,
+ }),
[],
);
diff --git a/examples/supabase-chat/src/app/page.tsx b/examples/supabase-chat/src/app/page.tsx
index d51769e64..f12ffc413 100644
--- a/examples/supabase-chat/src/app/page.tsx
+++ b/examples/supabase-chat/src/app/page.tsx
@@ -3,10 +3,10 @@
import { createSupabaseBrowser } from "@/lib/supabase/browser";
import {
AgentInterface,
+ fetchLLM,
openAIAdapter,
openAIMessageFormat,
restStorage,
- type ChatLLM,
} from "@openuidev/react-ui";
import type { RealtimeChannel } from "@supabase/supabase-js";
import { useEffect, useMemo, useState } from "react";
@@ -24,21 +24,16 @@ export default function Page() {
() => restStorage({ baseUrl: "/api/threads", messageFormat: openAIMessageFormat }),
[],
);
- const llm = useMemo<ChatLLM>(
- () => ({
- send: ({ threadId, messages, signal }) =>
- fetch("/api/chat", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({
- // Convert from OpenUI's internal format to OpenAI chat format
- messages: openAIMessageFormat.toApi(messages),
- threadId,
- }),
- signal,
- }),
- streamProtocol: openAIAdapter(),
- }),
+ // fetchLLM POSTs { threadId, runId, messages, tools, context }; the route
+ // reads the top-level threadId and messages (OpenAI chat format via
+ // openAIMessageFormat) and ignores the rest.
+ const llm = useMemo(
+ () =>
+ fetchLLM({
+ url: "/api/chat",
+ streamAdapter: openAIAdapter(),
+ messageFormat: openAIMessageFormat,
+ }),
[],
);
diff --git a/packages/react-headless/AGENTS.md b/packages/react-headless/AGENTS.md
index dcdb9d58a..4e689e05a 100644
--- a/packages/react-headless/AGENTS.md
+++ b/packages/react-headless/AGENTS.md
@@ -56,18 +56,32 @@ Build order: **`react-headless`** → `react-lang` → `react-ui`. This package
1. Create a file in `src/stream/adapters/` implementing the `MessageFormat` interface (`toApi` + `fromApi`).
2. Export it from `src/stream/adapters/index.ts` and `src/index.ts`.
-### ChatProviderProps config pattern
+### ChatProviderProps
+
+```ts
+interface ChatProviderProps {
+ llm: ChatLLM; // required — drives message sending and stream parsing
+ storage?: ChatStorage; // default: internal in-memory storage (no persistence)
+ artifactRenderers?: ReadonlyArray<ArtifactRendererConfig<any>>; // captured at mount
+ artifactCategories?: ArtifactCategory[];
+ children: React.ReactNode;
+}
+```
-`ChatProviderProps` uses a **discriminated union** so TypeScript enforces "URL string OR custom functions, not both":
+Typical wiring uses the built-in adapter factories:
-- `ThreadApiConfig`: provide `threadApiUrl` string **or** individual functions (`fetchThreadList`, `createThread`, etc.)
-- `ChatApiConfig`: provide `apiUrl` string **or** a `processMessage` function
+```tsx
+<ChatProvider
+ llm={fetchLLM({ url: "/api/chat", streamAdapter: openAIAdapter() })}
+ storage={restStorage({ baseUrl: "/api/threads" })}
+>
+```
-When `threadApiUrl` is given, `createChatStore` generates default REST implementations (`/get`, `/create`, `/delete/:id`, `/update/:id`, `/get/:id`).
+- **Stream adapters are factories** — pass `openAIAdapter()`, never the bare `openAIAdapter` function.
### How streaming works
-`processMessage()` in the store → `fetch(apiUrl)` → `StreamProtocolAdapter.parse(response)` → yields `AGUIEvent`s → `processStreamedMessage()` accumulates text deltas and tool calls into an `AssistantMessage`, calling `createMessage` on first event and `updateMessage` on subsequent events.
+`processMessage()` in the store → `llm.send({ threadId, messages, signal })` → `llm.streamProtocol.parse(response)` → yields `AGUIEvent`s → `processStreamedMessage()` accumulates text deltas and tool calls into an `AssistantMessage`, calling `createMessage` on first event and `updateMessage` on subsequent events.
### OpenAI adapter types
diff --git a/packages/react-headless/README.md b/packages/react-headless/README.md
index 61b172c8a..046526c15 100644
--- a/packages/react-headless/README.md
+++ b/packages/react-headless/README.md
@@ -31,17 +31,17 @@ Use `@openuidev/react-headless` when you want OpenUI's chat behavior without Ope
### URL-based setup
-The simplest configuration points to your API and lets the provider handle REST calls and streaming automatically:
+The simplest configuration points to your API and lets the provider handle the requests and streaming automatically:
```tsx
-import { ChatProvider } from "@openuidev/react-headless";
+import { agUIAdapter, ChatProvider, fetchLLM, restStorage } from "@openuidev/react-headless";
+
+const llm = fetchLLM({ url: "/api/chat", streamAdapter: agUIAdapter() });
+const storage = restStorage({ baseUrl: "/api/threads" });
function App() {
return (
- <ChatProvider
- apiUrl="/api/chat"
- threadApiUrl="/api/threads"
- >
+ <ChatProvider llm={llm} storage={storage}>
<YourChatUI />
</ChatProvider>
);
@@ -50,31 +50,21 @@ function App() {
### Custom functions
-For full control, provide your own functions instead of URLs:
+For full control, implement the `ChatLLM` interface instead:
```tsx
-<ChatProvider
- processMessage={async ({ threadId, messages, abortController }) => {
- return fetch("/api/chat", {
- method: "POST",
- body: JSON.stringify({ threadId, messages }),
- signal: abortController.signal,
- });
- }}
- fetchThreadList={async () => {
- const res = await fetch("/api/threads");
- return res.json();
- }}
- createThread={async (firstMessage) => {
- const res = await fetch("/api/threads", {
+import { openAIAdapter, openAIMessageFormat, type ChatLLM } from "@openuidev/react-headless";
+
+const llm: ChatLLM = {
+ send: ({ threadId, messages, signal }) =>
+ fetch("/api/chat", {
method: "POST",
- body: JSON.stringify({ message: firstMessage }),
- });
- return res.json();
- }}
->
- <YourChatUI />
-</ChatProvider>
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ threadId, messages: openAIMessageFormat.toApi(messages) }),
+ signal,
+ }),
+ streamProtocol: openAIAdapter(),
+};
```
## Hooks
@@ -175,22 +165,20 @@ function MessageBubble() {
## Streaming Adapters
-Adapters transform HTTP responses into the internal event stream. Pass one to `ChatProvider` via `streamProtocol`:
+Adapters transform HTTP responses into the internal event stream. They are factories — call one and pass the result to `fetchLLM` via `streamAdapter`:
```tsx
-import { ChatProvider, openAIAdapter } from "@openuidev/react-headless";
+import { fetchLLM, openAIAdapter } from "@openuidev/react-headless";
-<ChatProvider apiUrl="/api/chat" streamProtocol={openAIAdapter}>
- {children}
-</ChatProvider>
+const llm = fetchLLM({ url: "/api/chat", streamAdapter: openAIAdapter() });
```
| Adapter | Description |
| :--- | :--- |
-| `agUIAdapter` | Default adapter for AG-UI SSE events (`data: {json}\n`) |
-| `openAIAdapter` | Parses OpenAI Chat Completions streaming (`ChatCompletionChunk`) |
-| `openAIResponsesAdapter` | Parses OpenAI Responses API streaming (`ResponseStreamEvent`) |
-| `openAIReadableStreamAdapter` | Parses OpenAI SDK's `Stream.toReadableStream()` NDJSON output |
+| `agUIAdapter()` | Parses AG-UI SSE events (`data: {json}\n`) |
+| `openAIAdapter()` | Parses OpenAI Chat Completions streaming (`ChatCompletionChunk`) |
+| `openAIResponsesAdapter()` | Parses OpenAI Responses API streaming (`ResponseStreamEvent`) |
+| `openAIReadableStreamAdapter()` | Parses OpenAI SDK's `Stream.toReadableStream()` NDJSON output |
### Custom adapter
@@ -208,14 +196,16 @@ const myAdapter: StreamProtocolAdapter = {
## Message Formats
-Message formats convert between your API's message shape and the internal AG-UI format. Pass one to `ChatProvider` via `messageFormat`:
+Message formats convert between your API's message shape and the internal AG-UI format. Pass one to `fetchLLM` via the `messageFormat` option:
```tsx
-import { ChatProvider, openAIMessageFormat } from "@openuidev/react-headless";
+import { fetchLLM, openAIAdapter, openAIMessageFormat } from "@openuidev/react-headless";
-<ChatProvider apiUrl="/api/chat" messageFormat={openAIMessageFormat}>
- {children}
-</ChatProvider>
+const llm = fetchLLM({
+ url: "/api/chat",
+ streamAdapter: openAIAdapter(),
+ messageFormat: openAIMessageFormat,
+});
```
| Format | Description |
diff --git a/packages/react-ui/README.md b/packages/react-ui/README.md
index 544875ec7..fda89b82a 100644
--- a/packages/react-ui/README.md
+++ b/packages/react-ui/README.md
@@ -37,25 +37,17 @@ This package provides three layers:
The fastest way to get a working chat app is `AgentInterface`. Give it an `llm` transport that talks to your backend. Storage is optional — without it, threads live in memory and are wiped on reload:
```tsx
-import {
- AgentInterface,
- openAIAdapter,
- openAIMessageFormat,
- type ChatLLM,
-} from "@openuidev/react-ui";
+import { AgentInterface, fetchLLM, openAIAdapter, openAIMessageFormat } from "@openuidev/react-ui";
import { openuiChatLibrary } from "@openuidev/react-ui/genui-lib";
import "@openuidev/react-ui/styles/index.css";
-const llm: ChatLLM = {
- send: ({ messages, signal }) =>
- fetch("/api/chat", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ messages: openAIMessageFormat.toApi(messages) }),
- signal,
- }),
- streamProtocol: openAIAdapter(),
-};
+// POSTs { threadId, runId, messages, tools, context } to /api/chat and parses
+// the streamed response — here an OpenAI Chat Completions stream.
+const llm = fetchLLM({
+ url: "/api/chat",
+ streamAdapter: openAIAdapter(),
+ messageFormat: openAIMessageFormat,
+});
function App() {
return (
@@ -75,8 +67,8 @@ function App() {
| Prop | Description |
| :----------------- | :------------------------------------------------------------------------------------------- |
-| `storage` | Optional persistence adapter for thread history; defaults to in-memory (wiped on reload). Use `restStorage` from `@openuidev/react-ui` to back it with your own REST API |
-| `llm` | Chat transport: `{ send({ messages, signal }), streamProtocol }` |
+| `storage` | Optional persistence adapter for thread history; defaults to in-memory (wiped on reload). Use `restStorage({ baseUrl })` from `@openuidev/react-ui` to back it with your own REST API |
+| `llm` | Chat transport, usually built with `fetchLLM`; any `ChatLLM` (`{ send({ threadId, messages, signal }), streamProtocol }`) works |
| `componentLibrary` | OpenUI Lang library used to render assistant messages (e.g. `openuiChatLibrary`) |
| `theme` | Theme configuration, e.g. `{ mode: "light" }` |
| `agentName` | Name displayed in the header |
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 914e86164..54f283c9f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1165,14 +1165,14 @@ importers:
specifier: workspace:*
version: link:../../packages/openui-cli
'@openuidev/react-email':
- specifier: 0.2.4
+ specifier: workspace:*
+ version: link:../../packages/react-email
'@openuidev/react-headless':
- specifier: 0.8.2
+ specifier: workspace:*
+ version: link:../../packages/react-headless
'@openuidev/react-lang':
- specifier: 0.2.6
+ specifier: workspace:*
+ version: link:../../packages/react-lang
'@react-email/components':
specifier: ^0.0.41
@@ -2070,8 +2070,6 @@ packages:
resolution: {integrity: sha512-G6LTsdULw91sqLBeqW6VBqQjdrMJ0d91gtNr7mvaVVEoQX5pM5qVt7cf61ZNh6uv3UIwEG4oLSwH+v9unVzbtg==}
- '@ag-ui/[email protected]':
- resolution: {integrity: sha512-Ccsarxb23TChONOWXDbNBqp1fIbOSMht8g7w6AsSYBTtdOwZ7h7AkjNkr3LSdVv+RbT30JMdSLtieJE0YepNPg==}
resolution: {integrity: sha512-5/gC9n20ImA10LMFLLYKOowqn2Btrr3UYXWGosmLc1+KJqREI0t35NXnwqoKlw7TWySznF1bpwY6uIvMtO/ZUg==}
@@ -5715,43 +5713,14 @@ packages:
resolution: {integrity: sha512-/UhIkaZgPutTFmQ7RnIJGgDXZmtEJ7Dvi86xNTFWcnRxVRNk/aotsqDJYeEvDP+FSMB2SdW+pQzNMcWP0rwuNA==}
engines: {node: '>=14'}
- '@openuidev/[email protected]':
- resolution: {integrity: sha512-a/WkffvnclxSYBGhJxho8mvaVDYCBNw9GBMP5J2tl17mK6ukA6YmSQvwSmlC0UNi3FiLdj6Wk6qJIjESZ8EOUg==}
- peerDependencies:
- '@modelcontextprotocol/sdk': '>=1.0.0'
- zod: ^3.25.0 || ^4.0.0
- peerDependenciesMeta:
- '@modelcontextprotocol/sdk':
- optional: true
- '@openuidev/[email protected]':
- resolution: {integrity: sha512-n8z4Zv3Df/cXksMwQo9RNL1aeC/M0REQclvp44TGfhiMiCi1mvWlYZ3uX5qzrerIwHBS+m7NUdI6LugCpFeiaQ==}
- peerDependencies:
- '@openuidev/react-lang': 0.2.6
- react: ^18.3.1 || ^19.0.0
- react-dom: ^18.0.0 || ^19.0.0
- zod: ^3.25.0 || ^4.0.0
- '@openuidev/[email protected]':
- resolution: {integrity: sha512-o70dZnwVli25JWYFFZBEtXpCVrdJAkQRoW1/La58C6jVvga/Q2KTnz+rXCLUHX/e9iZpHQ9doZZht+GZ9vRfjA==}
- peerDependencies:
- react: ^18.3.1 || ^19.0.0
- zustand: ^4.5.5
'@openuidev/[email protected]':
resolution: {integrity: sha512-+/sVNVOFFzmnAsR8y+5W/la5U485OGXPFNtgY7wu0XdBdKSkbljNUGBA1XiHkzcxSVoATWOSy9eQ/J4UeHSPuQ==}
peerDependencies:
react: '>=19.0.0'
- '@openuidev/[email protected]':
- resolution: {integrity: sha512-5lfnMUiUyTQli0fPFwQtUhxV0B5T/PJntgZzUb0IXiJSyWm+FNpYOIozJxim0xxmqmuYwmk1geLTNcjzYIS6mA==}
- peerDependencies:
- '@modelcontextprotocol/sdk': '>=1.0.0'
- react: ^18.3.1 || ^19.0.0
- zod: ^3.25.0 || ^4.0.0
- peerDependenciesMeta:
- '@modelcontextprotocol/sdk':
- optional: true
'@openuidev/[email protected]':
resolution: {integrity: sha512-8lPyh01/j7NYKIXO3h/VpDW+dF8Ii/QuwogAmxpVeh33VsPweot5yxqkvw+4TOrsYTXJSGm+DvcGMEzytBKP6A==}
@@ -19420,10 +19389,6 @@ snapshots:
uuid: 11.1.1
zod: 3.25.76
- '@ag-ui/[email protected]':
- dependencies:
- rxjs: 7.8.1
- zod: 3.25.76
dependencies:
@@ -24308,25 +24273,8 @@ snapshots:
'@opentelemetry/[email protected]': {}
- dependencies:
- zod: 4.3.6
- optionalDependencies:
- '@modelcontextprotocol/sdk': 1.29.0(@cfworker/[email protected])([email protected])
- dependencies:
- '@openuidev/react-lang': 0.2.6(@modelcontextprotocol/[email protected](@cfworker/[email protected])([email protected]))([email protected])([email protected])
- '@react-email/components': 0.0.41([email protected]([email protected]))([email protected])
- react: 19.2.3
- react-dom: 19.2.3([email protected])
- zod: 4.3.6
- dependencies:
- '@ag-ui/core': 0.0.45
- react: 19.2.3
- zustand: 4.5.7(@types/[email protected])([email protected])
dependencies:
@@ -24338,13 +24286,6 @@ snapshots:
react: 19.2.4
zod: 4.4.3
- dependencies:
- '@openuidev/lang-core': 0.2.6(@modelcontextprotocol/[email protected](@cfworker/[email protected])([email protected]))([email protected])
- react: 19.2.3
- zod: 4.3.6
- optionalDependencies:
- '@modelcontextprotocol/sdk': 1.29.0(@cfworker/[email protected])([email protected])
'@openuidev/[email protected]': {}