コンテンツにスキップ

@alneas/react-ai API リファレンス

【未翻訳】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:
引数 型 必須 説明
definition { readonly type: string; readonly dataSchema?: GenerativeUIObject; readonly validate: (data: GenerativeUIObject) => GenerativeUIDataResult<TData>; readonly component: ComponentType<{ data: TData; }>; } 必須
  • 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
引数 型 必須 説明
components readonly GenerativeUIComponent[] 必須
  • 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