@alneas/react-ai API Reference
@alneas/react-ai API Reference
Section titled “@alneas/react-ai API Reference”FUNCTION defineGenerativeUIComponent
Section titled “FUNCTION defineGenerativeUIComponent”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:Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
definition |
{ readonly type: string; readonly dataSchema?: GenerativeUIObject; readonly validate: (data: GenerativeUIObject) => GenerativeUIDataResult<TData>; readonly component: ComponentType<{ data: TData; }>; } |
Yes |
Returns
Section titled “Returns”- Type:
GenerativeUIComponent
Example
Section titled “Example”```tsximport { 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; missingschemas are not guessed. It covers structural validation, not custom business rules.
```typescriptexport function createGenerativeUIRegistry(components: readonly GenerativeUIComponent[]): GenerativeUIRegistryParameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
components |
readonly GenerativeUIComponent[] |
Yes |
Returns
Section titled “Returns”- Type:
GenerativeUIRegistry
TYPE GenerativeUIDataResult
Section titled “TYPE GenerativeUIDataResult”A pure application validator may transform JSON data into the component’s typed input.
type GenerativeUIDataResultINTERFACE GenerativeUIIssue
Section titled “INTERFACE GenerativeUIIssue”Safe diagnostic metadata; no raw payload, exception or validator message is exposed.
interface GenerativeUIIssueTYPE GenerativeUIResolution
Section titled “TYPE GenerativeUIResolution”Validated component resolution, before React renders the element.
type GenerativeUIResolutionINTERFACE GenerativeUIComponent
Section titled “INTERFACE GenerativeUIComponent”Application-owned component registration produced by defineGenerativeUIComponent.
interface GenerativeUIComponentINTERFACE GenerativeUIRegistry
Section titled “INTERFACE GenerativeUIRegistry”Immutable registry. Create a new registry to change the permitted components.
interface GenerativeUIRegistryTYPE GenerativeUIValue
Section titled “TYPE GenerativeUIValue”Finite JSON data. Executable values and React nodes are never part of a UI document.
type GenerativeUIValueINTERFACE GenerativeUIObject
Section titled “INTERFACE GenerativeUIObject”Immutable object payload passed to a registered component validator.
interface GenerativeUIObjectINTERFACE GenerativeUIBlock
Section titled “INTERFACE GenerativeUIBlock”One explicitly named UI component and its data. The application defines what each type accepts.
interface GenerativeUIBlockINTERFACE GenerativeUIDocument
Section titled “INTERFACE GenerativeUIDocument”A flat, versioned UI response. No layout code, executable props or remote component references.
interface GenerativeUIDocumentTYPE GenerativeUIDocumentResult
Section titled “TYPE GenerativeUIDocumentResult”Envelope validation result. Component-specific validation belongs to the UI registry.
type GenerativeUIDocumentResult