import type { ComponentChannels } from './channels.js'; import { type GenuiValidation, type JsonSchema, type JsonSchemaValidator, type PropsSchema } from './schema.js'; /** * One component a server may push into a conversation. Data only — how it LOOKS is each app's own * renderer, looked up by {@link name}. The same definition serves the model (description + props * schema), the server (validation), text-only channels ({@link fallbackText}) and the client * (validation before rendering). */ export interface ComponentDefinition
> {
/** Registry key, e.g. `DataTable`. What a `ui` frame's `component` names. */
name: string;
/** Human label: "Data table". */
title: string;
/** Shown to the model: what the component is for and when to use it. */
description: string;
/** The props schema: a Standard Schema (Zod, Valibot, ArkType) or a JSON Schema object. */
props: PropsSchema;
/** Portable normalized props schema. Required when input transformations are not idempotent. */
outputProps?: PropsSchema;
/**
* The component takes nested elements (a layout: `Stack`, `Card`). Only meaningful in tree mode,
* where a node's `children` are validated against the catalog too. Outside tree mode such a
* component has nothing to hold, so it gets no `ui__show_*` tool and the generic show tool does
* not offer it.
*/
children?: boolean;
/**
* Plain text / Slack mrkdwn rendering of these props, for a channel that cannot draw the
* component. Absent → {@link componentToText} prints the props as JSON. An empty string renders
* nothing (a layout with nothing of its own to say); in a tree its children still render.
*/
fallbackText?(props: P): string;
/**
* Pushed by the server (e.g. an approval card), never offered to the model. Excluded from
* {@link catalogToModelText} and from the tool factories.
*/
internal?: boolean;
/**
* Schema version of {@link props}. Stamped on every `ui` frame the component is pushed with, so a
* client can keep rendering messages persisted under an older shape.
*/
version?: number;
/**
* How this component appears in a tree the model is still writing (tree mode with streaming
* previews — see `GenuiToolsOptions.streaming`). Absent → the tree's default.
*
* - `'partial'`: drawn as soon as its type is known, its props filling in as they arrive (the
* node is flagged `incomplete` until its object closes).
* - `'complete'`: held back until its whole subtree has arrived — the node is sent as a
* placeholder (`held`, no props, no children) and drawn once it closes. For a component that
* cannot draw half its data: a chart, a map.
*/
streaming?: GenuiStreaming;
/**
* What a preview may show of props the model is still writing (a `streaming: 'partial'` node, or
* a per-component call being previewed): drop what must not be drawn or run half written. Called
* with the raw partial props and the parser's view of them. Absent → the props as they are.
*/
partialProps?(props: Record ;
/**
* Checks beyond the props schema, run on the server once the props are valid — the sandbox parses
* its code here. An `error` refuses the call (the model gets its message and retries); a
* `warning` lets it through and is handed back with the result.
*/
check?(props: P): GenuiCheck[] | Promise {
channels?: ComponentChannels ;
}
/** How a tree node appears while the model writes it ({@link ComponentDefinition.streaming}). */
export type GenuiStreaming = 'partial' | 'complete';
/** Component names: an identifier a registry key, a tool name and a snake_case slug can all be derived from. */
export declare const COMPONENT_NAME: RegExp;
/** Declare a component. Validates the name and returns the definition unchanged (typed). */
export declare function defineComponent >(definition: ComponentDefinition , extras?: DefineComponentExtras ): ComponentDefinition ;
export interface CatalogOptions {
/** How JSON Schema props are checked. Default: {@link builtinJsonSchemaValidator}; pass `ajvValidator(new Ajv())` for full JSON Schema. */
jsonSchemaValidator?: JsonSchemaValidator;
}
/** An immutable set of component definitions, looked up by name. */
export interface Catalog {
readonly components: readonly ComponentDefinition