@alneas/react-ai API リファレンス
@alneas/react-ai API リファレンス
Section titled “@alneas/react-ai API リファレンス”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)”| 引数 | 型 | 必須 | 説明 |
|---|---|---|---|
definition |
{ readonly type: string; readonly dataSchema?: GenerativeUIObject; readonly validate: (data: GenerativeUIObject) => GenerativeUIDataResult<TData>; readonly component: ComponentType<{ data: TData; }>; } |
必須 |
戻り値 (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[]): GenerativeUIRegistry引数 (Parameters)
Section titled “引数 (Parameters)”| 引数 | 型 | 必須 | 説明 |
|---|---|---|---|
components |
readonly GenerativeUIComponent[] |
必須 |
戻り値 (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