Skip to content

Add Vercel AI SDK stream adapter and message format#260

Open
ankit-thesys wants to merge 4 commits intothesysdev:mainfrom
ankit-thesys:feature/versel-sdk-adaptor
Open

Add Vercel AI SDK stream adapter and message format#260
ankit-thesys wants to merge 4 commits intothesysdev:mainfrom
ankit-thesys:feature/versel-sdk-adaptor

Conversation

@ankit-thesys
Copy link
Copy Markdown
Contributor

Summary

This PR adds first-class support for the Vercel AI SDK in @openuidev/react-headless, enabling developers to use OpenUI with Vercel's ai package out of the box.

What's included

  • vercelAIAdapter — a new StreamProtocolAdapter that parses Vercel AI SDK's UI message stream protocol (data-stream format with 0:, 2:, 9:, a:, e: prefixed lines) and converts them into AG-UI events
  • vercelAIMessageFormat — a new MessageFormat implementation that converts between AG-UI Message[] and Vercel AI SDK's ModelMessage[], supporting:
    • User, assistant, and system messages
    • Tool calls and tool results (including multi-step tool interactions)
    • File/image attachments via experimental_attachments
    • Reasoning content parts
  • vercel-ai-chat example app — a full Next.js example demonstrating both a simple chat page and an agent page with tool use, using streamText from the Vercel AI SDK on the server and FullScreen + the new adapters on the client
  • Comprehensive test suites — tests for both vercelAIAdapter (stream parsing, text streaming, tool calls, finish reasons, errors, multi-step) and vercelAIMessageFormat (round-trip conversions, edge cases)

Other changes

  • Added ai SDK as a devDependency in react-headless (for type imports only — no runtime dependency)
  • Fixed RUN_ERROR event handler to read event.message instead of event.error
  • Applied lint/format fixes across react-headless and react-ui (import ordering, formatting)

How to test

  1. pnpm install from the repo root
  2. Run the adapter and message format tests:
    cd packages/react-headless && pnpm test
  3. Try the example app:
    cd examples/vercel-ai-chat
    cp .env.local.example .env.local  # add your OpenAI API key
    pnpm dev
    • Visit http://localhost:3000 for the basic chat
    • Visit http://localhost:3000/agent for the agent with tool use

Test plan

  • vercelAIAdapter unit tests pass (text streaming, tool calls, finish events, error handling, multi-step)
  • vercelAIMessageFormat unit tests pass (user/assistant/system messages, tool calls, tool results, attachments, reasoning, round-trip conversions)
  • Existing react-headless tests still pass
  • Manual testing with the vercel-ai-chat example app against a live OpenAI API key

Made with Cursor

- Add vercelAIAdapter (StreamProtocolAdapter) and vercelAIMessageFormat
  (MessageFormat) to react-headless for Vercel AI SDK compatibility
- Add comprehensive test suites for both the adapter and message format
- Add vercel-ai-chat example app demonstrating usage with Next.js
- Add `ai` SDK as a devDependency in react-headless
- Fix RUN_ERROR event to read `message` instead of `error`
- Apply lint/format fixes across react-headless and react-ui

Made-with: Cursor
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 5, 2026

@ankit-thesys is attempting to deploy a commit to the thesys-devs Team on Vercel.

A member of the Team first needs to authorize it.

@ankit-thesys ankit-thesys reopened this Mar 5, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openui-docs Ready Ready Preview, Comment Mar 5, 2026 1:04pm

Request Review

@ankit-thesys ankit-thesys self-assigned this Mar 5, 2026
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