@docyrus/generative-ui
v0.1.0
Published
Generative UI package for Docyrus-backed JSON render and code-react-ts experiences.
Keywords
Readme
@docyrus/generative-ui
React UI package for Docyrus-backed generative interfaces built on top of @json-render plus a work-file-driven code-react-ts mode.
This package is the frontend/runtime layer. It gives you:
- the
GenerativeUIReact component - React registry helpers for adapter-based preview rendering
- the shared mode catalogs and compile helpers re-exported from
@docyrus/generative-ui-core - typed mode/adaptor contracts for dashboard, widget, data-grid, form, email, PDF, image, and
code-react-tsgeneration
If you need backend-safe catalogs, prompt metadata, or compile helpers without a React runtime, use @docyrus/generative-ui-core directly.
Package Split
The generative UI system is intentionally split into two packages:
@docyrus/generative-uiFrontend/runtime package. Use this in React applications.@docyrus/generative-ui-coreShared non-React package. Use this in backend services, API layers, validators, and generators.
In practice:
- browser app ->
@docyrus/generative-ui - backend API ->
@docyrus/generative-ui-core
Installation
pnpm add @docyrus/generative-ui @docyrus/signin react react-domPeer dependencies:
reactreact-dom@docyrus/signin
What GenerativeUI Does
GenerativeUI is a two-pane experience:
- left side: chat / prompt history
- right side: rendered preview, raw JSON, or a code workspace depending on mode
It talks to a Docyrus backend that streams AI SDK UIMessage responses and integrates with client-created threads, persisted works, and per-generation work versions.
Mode behavior:
- json-render modes stream renderable spec data and preview it immediately
code-react-tsuses the generation stream for chat, then hydrates its editor/preview from the generated work version's files
Default backend route shape:
/v1/ai/generate-ui/:modeAdditional default endpoints:
/v1/inbox/threads
/v1/ai/worksYou can override these with the endpoints prop. endpointBasePath is still supported as a backward-compatible alias for the generate endpoint.
Supported Modes
dashboardwidgetdata-gridformcode-react-tsemailpdfimage
Adapter requirements:
dashboard-> requiresadapters.dashboardwidget-> requiresadapters.widgetdata-grid-> requiresadapters.widgetform-> requiresadapters.formemail,pdf,image,code-react-ts-> no React adapter required
Quick Start
import {
GenerativeUI,
type FormAdapterProps,
type SmartCanvasValue,
type SmartCanvasWidget,
} from "@docyrus/generative-ui";
function DashboardAdapter({ value }: { value: SmartCanvasValue }) {
return <pre>{JSON.stringify(value, null, 2)}</pre>;
}
function WidgetAdapter({ widget }: { widget: SmartCanvasWidget }) {
return <pre>{JSON.stringify(widget, null, 2)}</pre>;
}
function FormAdapter({ definition }: FormAdapterProps) {
return <pre>{JSON.stringify(definition, null, 2)}</pre>;
}
export function Example() {
return (
<GenerativeUI
modes={["dashboard", "widget", "data-grid", "form", "email", "pdf", "image", "code-react-ts"]}
adapters={{
dashboard: DashboardAdapter,
widget: WidgetAdapter,
form: FormAdapter,
}}
endpoints={{
generate: "/v1/ai/generate-ui",
threads: "/v1/inbox/threads",
works: "/v1/ai/works",
}}
initialSessions={{
dashboard: {
threadId: "thread-id",
workId: "work-id",
workVersionId: "work-version-id",
messages: [],
},
}}
codeReact={{
imports: {
react: "https://esm.sh/react@19",
"react-dom/client": "https://esm.sh/react-dom@19/client",
"react/jsx-runtime": "https://esm.sh/react@19/jsx-runtime",
},
}}
defaultMode="dashboard"
className="h-[900px]"
/>
);
}GenerativeUI Props
interface GenerativeUIProps {
modes?: GenerativeUIMode[];
defaultMode?: GenerativeUIMode;
chatSurfaceMode?: "fixed" | "floating";
endpointBasePath?: string;
endpoints?: {
generate?: string;
threads?: string;
works?: string;
};
floatingPlaceholder?: string;
initialSessions?: Partial<Record<GenerativeUIMode, GenerativeUIResumeSession>>;
codeReact?: {
wasmUrl?: string;
imports?: Record<string, string>;
};
adapters?: {
dashboard?: DashboardAdapter;
widget?: WidgetAdapter;
form?: FormAdapter;
};
className?: string;
onModeChange?: (mode: GenerativeUIMode) => void;
onSessionChange?: (mode: GenerativeUIMode, session: GenerativeUISessionState) => void;
onCreditsDepleted?: (usage: {
remainingCredits: number;
usedCredits: number;
totalCredits: number;
}) => void;
}Notes:
- if
modesis omitted, the component enables all supported modes it can satisfy from the provided adapters data-gridreuses thewidgetadapter because its compiled output is still aSmartCanvasWidgetchatSurfaceMode="floating"is useful when embedding the generator as an assistant-style overlay- the component manages per-mode
threadId,workId, andworkVersionIdinternally initialSessionslets a host restore a known thread/work/message state without building a works library into the packagecodeReactconfig controls the browser compiler/runtime for thecode-react-tsworkspace
Adapter Model
The model does not directly generate the final adapter payloads for the json-render React modes.
Instead, the flow is:
- the backend streams a child-based json-render spec
- the frontend parses that spec
- the frontend compiles it into the final adapter shape
- the preview is rendered through your adapter component
This is why the package exports both:
- catalogs / schemas / compile helpers
- registry helpers for preview rendering
code-react-ts is different:
- the backend creates or updates a work and work version
- the frontend captures
X-Work-IdandX-Work-Version-Id - the frontend loads the generated files from the work file endpoints
- Monaco +
esbuild-wasmprovide the in-browser editor and preview
Common Exports
Component:
GenerativeUI
Registry helpers:
createDashboardRegistrycreateWidgetRegistrycreateFormRegistry
Compile helpers and adapter-spec helpers:
compileDashboardSpeccompileWidgetSpeccompileDataGridSpeccompileFormSpeccreateDashboardAdapterSpeccreateWidgetAdapterSpeccreateDataGridAdapterSpeccreateFormAdapterSpec
Catalogs and schemas:
dashboardCatalogwidgetCatalogdataGridCatalogformCatalogdashboardSchemawidgetSchemadataGridSchemaformSchema
Types:
GenerativeUIModeGenerativeUIResumeSessionGenerativeUISessionStateSmartCanvasWidgetSmartCanvasValueGeneratedFormDefinitionGeneratedFormFieldDashboardAdapterPropsWidgetAdapterPropsFormAdapterProps
Backend Expectations
For best results, pair this package with a backend that uses @docyrus/generative-ui-core.
The backend should:
- accept
POST /api/v1/ai/generate-ui/:mode - stream AI SDK
UIMessageresponses - create or reuse a work and create a new work version for each generation
- return
X-Work-IdandX-Work-Version-Idresponse headers - persist thread history when
threadIdis provided - emit json-render patches for json-render modes
- write generated files to work storage for
code-react-ts - validate React-based json-render modes with the compile helpers from core
Minimal backend usage looks like:
import {
getCatalogForMode,
getGenerationModeEntry,
ROOT_ELEMENT_TYPES,
} from "@docyrus/generative-ui-core";When To Use @docyrus/generative-ui-core Instead
Use core directly when you need:
- mode metadata such as
SUPPORTED_MODES - backend prompt generation via
getCatalogForMode() - compile-time validation on the server
- React-free access to catalogs and schemas
- CommonJS support in Node backends
Development Notes
- this package is published as a dist-based package
- it depends on
@docyrus/generative-ui-corefor all non-React mode logic - image preview rendering uses a browser-side helper module and may rely on bundler-specific behavior when
@json-render/imageis involved
Related Packages
@docyrus/generative-ui-core@json-render/core@json-render/react@json-render/react-email@json-render/react-pdf@json-render/image
