UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

118 lines • 6.83 kB
import { type Context, type ReactNode } from 'react'; import type { UiAction } from '../../../genui/actions.js'; import type { TranscriptUiBlock } from '../transcript/model.js'; import type { GenerativeUIElement, GenerativeUIItem, GenerativeUIOptions, GenerativeUIProblem, GenerativeUIState, GenuiNodeState, GenuiPlaceholder } from './types.js'; /** What to draw instead of a component that did not render. Default: nothing. */ export type GenerativeUIFallback = ReactNode | ((problem: GenerativeUIProblem) => ReactNode); /** Where UI actions go — `GenuiActionProvider` (sandbox.tsx) and `GenuiProvider`'s `onAction`. */ export declare const GenuiActionContext: Context<((action: UiAction) => void) | null>; /** * The tree node being rendered — read it in a renderer to draw a skeleton while the model is still * writing the node (`incomplete`), e.g. a chart's axes before its data. `null` outside a tree. * * ```tsx * function Chart(props: ChartProps) { * const node = useGenuiNode(); * if (node?.incomplete && !props.data?.length) return <ChartSkeleton title={props.title} />; * return <BarChart {...props} />; * } * ``` */ export declare function useGenuiNode(): GenuiNodeState | null; /** * Set the node a renderer sees through {@link useGenuiNode} — for glue that draws components outside * a `genui:tree` frame (a framework's own tool-call renderer) and knows the call is still streaming: * `<GenuiNodeScope node={{ id: 'root', type: 'Sandbox', incomplete: true, held: false }}>`. */ export declare function GenuiNodeScope({ node, children, }: { node: GenuiNodeState | null; children?: ReactNode; }): import("react").JSX.Element; /** * Renders a `genui:tree` frame's `{ root }` node by node through the same registry, catalog and * resolver as top-level components. Used automatically for tree frames unless a `treeRenderer` * (e.g. the json-render one) or a registry entry for `genui:tree` takes over. * * Each frame's tree is structurally shared with the previous one: a node equal to the one before * keeps that object, and its renderer does not run again. */ export declare function GenuiTree({ root }: { root?: GenerativeUIElement; }): import("react").JSX.Element | null; export interface GenerativeUIScopeProps extends GenerativeUIOptions { fallbackText?: string; componentVersions?: Record<string, number>; fallback?: GenerativeUIFallback; loading?: ReactNode; /** Drawn for a tree node held back while the model writes it. Default: `loading`. */ placeholder?: GenuiPlaceholder; onError?: (error: unknown, item: GenerativeUIItem) => void; children?: ReactNode; } /** * The registry, catalog and fallbacks tree nodes render with. `<GenerativeUI>` provides it; wrap * your own chrome in it when you draw `useGenerativeUI`'s `Component` yourself and it may be a tree. */ export declare function GenerativeUIScope({ registry, catalog, resolveComponent, fallback, fallbackText, componentVersions, loading, placeholder, onError, children, }: GenerativeUIScopeProps): import("react").JSX.Element; /** What `<GenuiProvider>` hands every `<GenerativeUI>` / `useGenerativeUI` below it. */ export interface GenuiProviderValue extends Partial<GenerativeUIOptions> { fallback?: GenerativeUIFallback; loading?: ReactNode; /** Drawn for a tree node held back while the model writes it (`streaming: 'complete'`). */ placeholder?: GenuiPlaceholder; onError?: (error: unknown, item: GenerativeUIItem) => void; /** * Where UI actions go (a sandbox's `agent.send`, an A2UI button): typically the chat's * `sendUiAction`. Same as wrapping the tree in a `GenuiActionProvider`. */ onAction?: (action: UiAction) => void; } /** The enclosing `<GenuiProvider>`'s settings, or `null` outside one. */ export declare function useGenuiProvider(): GenuiProviderValue | null; export interface GenuiProviderProps extends GenuiProviderValue { children?: ReactNode; } /** * Set generative UI up once, at the app root: the registry of your renderers, the catalog to * validate against, a resolver for components the registry lacks, and what to draw when one does * not render. Every `<GenerativeUI>` below reads it (its own props still win), and `MessageItem` / * `MessageList` draw pushed components with it — no `renderUi` per message. * * ```tsx * <GenuiProvider registry={registry} catalog={catalog} fallback={({ item }) => <Unknown name={item.component} />}> * <App /> * </GenuiProvider> * ``` */ export declare function GenuiProvider({ registry, catalog, resolveComponent, treeRenderer, fallback, loading, placeholder, onError, onAction, children, }: GenuiProviderProps): import("react").JSX.Element; /** * The headless half of {@link GenerativeUI}: what to draw for one pushed component, or `null` when * `part` is not one. Options default to the enclosing `<GenuiProvider>`'s. */ export declare function useGenerativeUI(part: unknown, options?: Partial<GenerativeUIOptions>): GenerativeUIState | null; export interface GenerativeUIProps extends Partial<GenerativeUIOptions> { /** A transcript `ui` block, a `data-ui` message part, or a stored `{ id, component, props, version? }`. */ part: TranscriptUiBlock | GenerativeUIItem | unknown; /** Drawn for an unknown component, invalid props, or a renderer that threw. Default: the provider's, then the item's persisted text. */ fallback?: GenerativeUIFallback; /** Drawn while a resolver or an async validation is pending. Default: the provider's, else nothing. */ loading?: ReactNode; /** * Drawn for a tree node held back while the model writes it (its component streams `complete`). * Default: the provider's, else `loading`. */ placeholder?: GenuiPlaceholder; /** A renderer threw (the item shows `fallback`). */ onError?: (error: unknown, item: GenerativeUIItem) => void; } /** * Draws one server-pushed component with the app's own renderer. Headless: it adds no element and * no style of its own — only what the registry's component renders (and whatever `fallback` / * `loading` you pass). Everything but `part` defaults to the enclosing `<GenuiProvider>`. * * ```tsx * <GenerativeUI part={block} /> * ``` */ export declare function GenerativeUI({ part, registry, catalog, resolveComponent, treeRenderer, fallback: ownFallback, loading: ownLoading, placeholder: ownPlaceholder, onError: ownOnError, }: GenerativeUIProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | null | undefined; //# sourceMappingURL=generative-ui.d.ts.map