feat(examples): add OpenUI PDF RAG integration
PR Checklist
Please check if your PR fulfills the following requirements:
- The commit message follows our guidelines: https://voltagent.dev/docs/community/contributing/#commit-convention
Bugs / Features
- Related issue(s) linked
- Tests for the changes have been added
- Docs have been added / updated
- Changesets have been added https://voltagent.dev/docs/community/contributing/#creating-a-changeset
A changeset is not included because this adds a standalone example and does not change a published package.
What is the current behavior?
VoltAgent examples do not show how to turn retrieved agent context into streamed, interactive generative UI. There is no repository example covering an OpenUI parser and renderer, source-grounded charts, follow-up actions, and form values sent into a new VoltAgent turn.
What is the new behavior?
Adds examples/with-openui, a Next.js PDF RAG chat in which:
- VoltAgent owns agent orchestration,
BaseRetrieverretrieval, conversation IDs, andAgent.streamText()streaming. - OpenUI owns the generated component prompt,
AgentInterface, stream parsing, themed rendering, charts, forms, and follow-up actions. - The New York City Rent Guidelines Board 2025 Housing Supply Report is the only housing-data source.
- The PDF is extracted and chunked once, embedded in memory, and searched without a vector database.
- OpenUI follow-ups and
@ToAssistantform submissions return through the same/api/chatroute. - Current and legacy OpenUI action envelopes are normalized into focused retrieval queries.
The example README documents setup, supported versions, the request flow, datasource replacement, acceptance prompts, and production considerations.
Closes #1400
Validation
pnpm --filter voltagent-example-with-openui generate:prompt
pnpm --filter voltagent-example-with-openui typecheck
pnpm --filter voltagent-example-with-openui lint
pnpm --filter voltagent-example-with-openui test
pnpm --filter voltagent-example-with-openui build
All commands pass. The test suite contains 18 tests covering PDF extraction and ranking, current and legacy action-envelope retrieval, chat request preservation, and OpenUI parser acceptance for chart, dashboard, permit-impact, and form-oriented response shapes.
Browser acceptance on the local app:
| Check | Evidence |
|---|---|
| Theme provider | AgentInterface exposed 213 active --openui-* variables and rendered the configured dark green theme. |
| Parser and renderer | Assistant output rendered as components rather than raw OpenUI Lang. No browser console errors were recorded. |
| Chart | The PDF-backed borough permit chart rendered at 678 by 326 pixels with all five borough labels and page 6 citation. |
| Follow-up | Clicking Explain the impact of these permits on housing supply created one user turn and one backend request in the same conversation. The reply distinguished permits from completions and displayed exact retrieved values. |
| Form submit | Empty required fields were blocked. Submitting Vacancy rates, City planners, and Compare borough differences produced one backend request and a page 5 table with exact borough rates and an explicit Not calculable value for Staten Island. |
Notes for reviewers
- The bundled PDF is an official public report and is about 2.1 MB.
- The in-memory index is intentional for this single-document example. The README recommends persistent vector storage for larger or changing collections.
- Authentication, rate limiting, durable conversation storage, and treating uploaded PDF text as untrusted input are documented as production follow-ups.
- Local browser screenshots were used for acceptance verification but are not committed.
Summary by cubic
Adds examples/with-openui, a Next.js chat that connects VoltAgent’s single‑PDF RAG to OpenUI for streamed, interactive UI grounded in NYC’s 2025 Housing Supply Report. This demonstrates safe, source‑grounded charts/forms/follow‑ups with hardened sessions and strict request limits.
- Server:
/api/chatstreams OpenAI‑compatible SSE using@voltagent/internalsafeStringify, readsopenui/generated/system-prompt.txt, sets an HttpOnly anonymous visitor cookie, and derivesconversationIdby hashing serveruserIdwith clientthreadId. Enforces a 1 MB JSON body limit (rejects oversizedContent-Length, cancels over‑limit chunked bodies), validates a minimal messages schema, and returns 400 on invalid input. - Retrieval:
NycHousingPdfRetrieverlazily extracts/chunks the bundled PDF, embeds in memory withtext-embedding-3-small, ranks by cosine similarity, drops matches below 0.30, expands hits to full PDF pages, and setsrag.references; on errors it injects a retrieval‑unavailable context so the agent refuses to answer from memory. - Request handling: normalizes current OpenUI sentinel and legacy
<context>envelopes into focused retrieval queries, prioritizing submitted form fields; supports array‑formatted message content. - UI:
@openuidev/react-uiAgentInterfacewith the OpenAI adapter streams from the same route; a dark theme is enabled; follow‑ups and@ToAssistantform submissions round‑trip to VoltAgent. - Tests: cover PDF extraction and ranking threshold; chat request validation including the 1 MB limit, malformed JSON, and stream cancellation; OpenUI parser acceptance (charts/dashboards/forms); and anonymous session cookies plus conversation ID derivation.
- Repo:
.gitignoreexcludesopenui/generated/*;next.config.tsallowspdf-parseviaserverExternalPackages; regenerate prompts withpnpm generate:prompt. - Standalone example only; no changes to published packages and no migration required.
Summary by CodeRabbit
-
New Features
- Added a complete VoltAgent + OpenUI example for PDF-grounded NYC housing analysis.
- Supports streaming charts, dashboards, forms, citations, follow-up actions, and submitted form interactions.
- Added configurable models, starter prompts, chat endpoint setup, anonymous session continuity, and request-size validation.
-
Documentation
- Added setup, architecture, configuration, data-source replacement, and validation guidance.
-
Tests
- Added coverage for chat validation, sessions, PDF retrieval, and OpenUI response parsing.