Skip to content

@alneas/react-ai API Reference

Binds a component to a pure, synchronous validator. Components receive only the validated data prop. Callbacks, current records and credentials belong to trusted application code (for example React Context), never the generated document. Optional dataSchema is snapshotted and validated before the custom validator. It uses the inline draft-07 subset documented by createGenerativeUIContract.

export function defineGenerativeUIComponent<TData>(definition:
Parameter Type Required Description
definition { readonly type: string; readonly dataSchema?: GenerativeUIObject; readonly validate: (data: GenerativeUIObject) => GenerativeUIDataResult<TData>; readonly component: ComponentType<{ data: TData; }>; } Yes
  • Type: GenerativeUIComponent
```tsx
import { defineGenerativeUIComponent } from '@alneas/react-ai/generative-ui';
const greeting = defineGenerativeUIComponent({
type: 'greeting',
validate: (data) => typeof data.text === 'string'
? { ok: true, data: { text: data.text } } : { ok: false },
component: ({ data }) => <p>{data.text}</p>,
});
---
### `FUNCTION` `createGenerativeUIRegistry`
Creates an allowlist of application-defined UI components. No global registration,
dynamic imports, HTML evaluation or Action execution occurs. Validators must be pure;
their failures are isolated per block. Rendering exceptions are handled by the renderer.
documentSchema is available only if every component declares dataSchema; missing
schemas are not guessed. It covers structural validation, not custom business rules.
```typescript
export function createGenerativeUIRegistry(components: readonly GenerativeUIComponent[]): GenerativeUIRegistry
Parameter Type Required Description
components readonly GenerativeUIComponent[] Yes
  • Type: GenerativeUIRegistry

A pure application validator may transform JSON data into the component’s typed input.

type GenerativeUIDataResult

Safe diagnostic metadata; no raw payload, exception or validator message is exposed.

interface GenerativeUIIssue

Validated component resolution, before React renders the element.

type GenerativeUIResolution

Application-owned component registration produced by defineGenerativeUIComponent.

interface GenerativeUIComponent

Immutable registry. Create a new registry to change the permitted components.

interface GenerativeUIRegistry

Finite JSON data. Executable values and React nodes are never part of a UI document.

type GenerativeUIValue

Immutable object payload passed to a registered component validator.

interface GenerativeUIObject

One explicitly named UI component and its data. The application defines what each type accepts.

interface GenerativeUIBlock

A flat, versioned UI response. No layout code, executable props or remote component references.

interface GenerativeUIDocument

Envelope validation result. Component-specific validation belongs to the UI registry.

type GenerativeUIDocumentResult