Hi everyone,
I’m experimenting with the v0 Chat Completion API and want to build my own UI around it—similar to how the Playground works, but completely custom. Here’s what I’ve run into so far:
- What happens today
- I send a prompt like:
{ "model": "v0-chat", "messages": [{ "role": "user", "content": "Generate a landing page for a website." }], "stream": false }
-
- The API returns a single markdown-formatted string that includes both the agent’s explanations and any code blocks (HTML/CSS/JS).
- Example response:
Sure! Here’s a simple landing page:
```html
<!DOCTYPE html>
<html lang="en">
<head>…</head>
<body>…</body>
</html>
- My requirement
- Code editor pane: Extract the HTML/CSS/JS from the API response and load it into an embeddable editor (e.g. Monaco, CodeMirror), so users can tweak the code inline.
- Live preview pane: Render the edited code in real time (or on “Preview” click) so users see exactly what the landing page will look like. also I can see the agent responds with only limited files that can be added/replaced in a next js application. how can I use these generated files and generate a preview of the output
- Specific questions:
- Parsing & extraction: What’s the best way to reliably parse out only the code blocks from the markdown? Are there existing JS libraries you’d recommend, or do I need to regex it myself?
- Editor integration: Does anyone have examples of plugging streamed or batched API output into Monaco/CodeMirror? Handling incremental updates without flicker has been tricky.
- Streaming & rendering: If I set stream=true, can I get partial markdown chunks that let me start rendering the preview before the full response arrives? Is streaming support in v0 robust enough for this use case?
- Workarounds or roadmap: If it’s not possible today, has anyone built a workaround? And is there any timeline for richer UI-friendly features (e.g. separate “code” and “explanation” fields) in a future v0 update?
I’m building this in NextJS + TypeScript, but vanilla JS or other frameworks are fine too. Any pointers, sample code snippets, or links to repos/docs would be massively appreciated!