The Open Standard for Generative UI
WIP: Documentation improvements
Rabi Shanker Guha9a783a8373ef
diff --git a/docs/docs/concepts/003-data-format.md b/docs/docs/concepts/003-data-format.mddeleted file mode 100644index 519601a57..000000000--- a/docs/docs/concepts/003-data-format.md+++ /dev/null@@ -1,13 +0,0 @@-# Streaming Protocol--To enable streaming of both text and UI, Crayon uses a standard-streaming protocol as described here:--### Text Part-`0:<text>`--### Response Template Part-`1:{name: <name>, templateProps: <templateProps>}`--### Context Part-`8:{context}`diff --git a/docs/docs/concepts/003-data-format.mdx b/docs/docs/concepts/003-data-format.mdxnew file mode 100644index 000000000..02658dd45--- /dev/null+++ b/docs/docs/concepts/003-data-format.mdx@@ -0,0 +1,28 @@+# Streaming Protocol++To enable streaming of both text and UI, Crayon uses a standard+streaming protocol inspired from [AI SDK's streaming protocol](https://sdk.vercel.ai/docs/ai-sdk-ui/stream-protocol) as described here. This stream defines the format of the data that is sent to the client. It is a simple text stream with a few special tokens that is agnostic of the backend language or the LLM model used.++You can implement this protocol in your custom backend and integrate it with Crayon to build your own. For example you can use a Python FastAPI backend that integrates with Deepseek models and use Crayon to build a UI for it.++### Text Part+```+0:<text>+```+A simple text chunk is prefixed with `0:`.+Multiple consequtive text chunks are appended to the stream as they are generated to create a single+text block.++### Response Template Part+```+1:{name: <name>, templateProps: <templateProps>}+```+A response template is prefixed with `1:`. It contains the name of the template and the props to pass to it.+Multiple response templates can be sent in a single stream.++### Context Part+```+8:{context}+```+A context is prefixed with `8:`.+Multiple consequtive context parts can be sent in a single stream.diff --git a/docs/docs/guides/004-connecting-thread-backend.md b/docs/docs/guides/004-connecting-thread-backend.mdindex daec74174..28ea8c6d0 100644--- a/docs/docs/guides/004-connecting-thread-backend.md+++ b/docs/docs/guides/004-connecting-thread-backend.md@@ -22,9 +22,11 @@ const threadManager = useThreadManager({...});import { CrayonChat } from "@crayonai/react-ui";export default function App() {- return <CrayonChat url="http://localhost:3000/api/chat"- threadListManager={threadListManager}- threadManager={threadManager} />;+ return (+ <CrayonChat {...crayonChatProps}+ threadListManager={threadListManager}+ threadManager={threadManager} />+ );}```diff --git a/docs/docs/guides/006-generative-ui.md b/docs/docs/guides/006-generative-ui.mdnew file mode 100644index 000000000..e69de29bbdiff --git a/docs/docs/guides/generative-ui/001-python-fastapi.md b/docs/docs/guides/generative-ui/001-python-fastapi.mddeleted file mode 100644index 4193ef4be..000000000--- a/docs/docs/guides/generative-ui/001-python-fastapi.md+++ /dev/null@@ -1 +0,0 @@-# Pythondiff --git a/docs/docs/guides/generative-ui/002-nextjs.md b/docs/docs/guides/generative-ui/002-nextjs.mddeleted file mode 100644index 5290a8d7c..000000000--- a/docs/docs/guides/generative-ui/002-nextjs.md+++ /dev/null@@ -1 +0,0 @@-# NextJSdiff --git a/docs/docs/guides/generative-ui/index.md b/docs/docs/guides/generative-ui/index.mddeleted file mode 100644index 2237d582b..000000000--- a/docs/docs/guides/generative-ui/index.md+++ /dev/null@@ -1 +0,0 @@-# Generative UIdiff --git a/docs/docs/quickstart/001-python-fastapi.mdx b/docs/docs/quickstart/001-python-fastapi.mdxindex 64f4f3d70..0967547b2 100644--- a/docs/docs/quickstart/001-python-fastapi.mdx+++ b/docs/docs/quickstart/001-python-fastapi.mdx@@ -9,6 +9,7 @@ pip install fastapi```### Integrate LLM with your backend route+{/* TODO: This example is not working. */}```py title="main.py"from fastapi import FastAPIdiff --git a/docs/docs/quickstart/002-nextjs.mdx b/docs/docs/quickstart/002-nextjs.mdxindex 9f19eb604..519351397 100644--- a/docs/docs/quickstart/002-nextjs.mdx+++ b/docs/docs/quickstart/002-nextjs.mdx@@ -47,27 +47,44 @@ yarn add @crayonai/crayon-ui @crayonai/react-core## Add the CrayonProvider to your app-```tsx+```tsx title="page.tsx"import { CrayonChat } from "@crayonai/react-ui";-export default function App() {- return <CrayonChat url="http://localhost:3000/api/chat" />;+export default function Home() {+ return <CrayonChat agentName="Crayon" logoUrl="" />;}+```## Integrate LLM with your backend route-```tsx+```tsx title="api/chat/route.ts"+import { NextRequest, NextResponse } from "next/server";+import OpenAI from "openai";+export async function POST(req: NextRequest) {const { messages } = await req.json();const client = new OpenAI();- const stream = client.chat.completions.create({+ const llmStream = await client.chat.completions.create({model: "gpt-4o",messages: messages,stream: true,});- const streamResponse = new NextResponse(stream);- return NextResponse.json(response);+ const responseStream = new ReadableStream({+ start: async (controller) => {+ for await (const chunk of llmStream) {+ controller.enqueue(chunk.choices[0].delta.content);+ }+ },+ });++ return new NextResponse(responseStream, {+ headers: {+ "Content-Type": "text/event-stream",+ "Cache-Control": "no-cache, no-transform",+ Connection: "keep-alive",+ },+ });}```diff --git a/docs/docs/quickstart/index.md b/docs/docs/quickstart/index.mddeleted file mode 100644index 9d9363aac..000000000--- a/docs/docs/quickstart/index.md+++ /dev/null@@ -1,5 +0,0 @@-----sidebar_position: 1------# Quickstartdiff --git a/docs/sidebars.ts b/docs/sidebars.tsindex 233e312d7..361e60a45 100644--- a/docs/sidebars.ts+++ b/docs/sidebars.ts@@ -19,11 +19,7 @@ const sidebars: SidebarsConfig = {{type: "category",label: "Quickstart",- link: {- type: "doc",- id: "quickstart/index",- },- items: ["quickstart/python-fastapi", "quickstart/nextjs"],+ items: ["quickstart/nextjs"],},{type: "category",