@dudousxd/nestjs-agent-react 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -352,46 +352,50 @@ menu (`ChatCommandPalette`, grown into the combobox's listbox) above the compose
352
352
 
353
353
  `@dudousxd/nestjs-agent-react/genui` draws server-pushed components (`ui` frames, persisted `ui[]`)
354
354
  with YOUR renderers. Headless: it adds no element and no style — only what your registry renders.
355
+ Set it up once, at the root; `MessageItem` / `MessageList` then draw every pushed component with no
356
+ `renderUi` of their own:
355
357
 
356
358
  ```tsx
357
- import { GenerativeUI, type GenuiRegistry } from '@dudousxd/nestjs-agent-react/genui';
358
- import { catalog } from './catalog'; // optional: a @dudousxd/nestjs-agent-genui catalog
359
+ import { GenuiProvider, type GenuiRegistry } from '@dudousxd/nestjs-agent-react/genui';
360
+ import { catalog } from './catalog'; // optional: the same file the server uses (@dudousxd/nestjs-agent-core/genui)
359
361
 
360
362
  const registry: GenuiRegistry = { DataTable: MyTable, Chart: MyChart, Card: MyCard, Text: MyText };
361
363
 
362
- <MessageItem
363
- message={message}
364
- renderUi={(block) => (
365
- <GenerativeUI
366
- part={block}
367
- registry={registry}
368
- catalog={catalog}
369
- resolveComponent={(name, version) => loadTenantComponent(name, version)}
370
- fallback={({ reason, item }) => <UnknownComponent name={item.component} reason={reason} />}
371
- loading={<Skeleton />}
372
- />
373
- )}
374
- />;
364
+ <GenuiProvider
365
+ registry={registry}
366
+ catalog={catalog}
367
+ resolveComponent={(name, version) => loadTenantComponent(name, version)}
368
+ fallback={({ reason, item }) => <UnknownComponent name={item.component} reason={reason} />}
369
+ loading={<Skeleton />}
370
+ >
371
+ <App />
372
+ </GenuiProvider>;
375
373
  ```
376
374
 
377
375
  | Prop | |
378
376
  |---|---|
379
- | `part` | A transcript `ui` block, a `data-ui` message part, or a stored `{ id, component, props, version? }`. |
380
377
  | `registry` | Component name → your renderer. It receives the props spread (and `children` as a tree layout node). |
381
378
  | `catalog?` | Validate props before drawing (`catalog.validateSync` when it can, so no placeholder flashes). Components the catalog does not know render unvalidated. |
382
379
  | `resolveComponent?(name, version)` | For components the registry lacks, e.g. a tenant's own, at the exact version a message was rendered with. Sync or async, cached per resolver/name/version. |
383
380
  | `fallback?` | A node, or `({ reason: 'unknown' \| 'invalid' \| 'error', item, issues?, error? }) => node`. Default: nothing. |
384
381
  | `loading?`, `onError?` | While a resolver or async validation is pending; a renderer threw (each item has its own error boundary). |
382
+ | `treeRenderer?` | Draws a whole `genui:tree` frame (e.g. json-render, below). Default: node by node through `registry`. |
383
+
384
+ `<GenerativeUI part={block} />` draws one component (a transcript `ui` block, a `data-ui` message
385
+ part, or a stored `{ id, component, props, version? }`) with the provider's settings; any of the
386
+ props above passed to it win over the provider's. An explicit `renderUi` on `MessageItem` still
387
+ wins too, and `useAmbientRenderUi()` (main entry) hands a custom transcript the provider's renderer.
385
388
 
386
389
  A `genui:tree` frame (tree mode) is drawn node by node through the same registry, catalog and
387
- fallbacks, each node in its own boundary; put a `genui:tree` entry in the registry to take over.
388
- `useGenerativeUI(part, options)` returns the state (`ready` with `Component`/`props`, `loading`,
389
- `problem`) for your own chrome; wrap it in `<GenerativeUIScope>` when it may draw a tree.
390
+ fallbacks, each node in its own boundary. `useGenerativeUI(part, options?)` returns the state
391
+ (`ready` with `Component`/`props`, `loading`, `problem`) for your own chrome, defaulting to the
392
+ provider's settings; wrap it in `<GenerativeUIScope>` when it may draw a tree.
390
393
 
391
- **json-render** (optional peer `@json-render/react` >= 0.21):
392
- `@dudousxd/nestjs-agent-react/genui/json-render` renders tree frames through json-render's
393
- `Renderer` — `registry[GENUI_TREE_COMPONENT] = jsonRenderTree(toJsonRenderRegistry(registry))` —
394
- plus `JsonRenderTree` and `treeToJsonRenderSpec`.
394
+ **json-render** (optional peer `@json-render/react` >= 0.21): import `GenuiProvider` from
395
+ `@dudousxd/nestjs-agent-react/genui/json-render` instead — the same provider plus
396
+ `jsonRender={myJsonRenderRegistry}` (or `jsonRender` alone, to derive one from `registry`), which
397
+ draws tree frames through json-render's `Renderer`. `JsonRenderTree`, `jsonRenderTree`,
398
+ `toJsonRenderRegistry` and `treeToJsonRenderSpec` are exported for hand wiring.
395
399
 
396
400
  ### Designed components, as copy-in source
397
401
 
@@ -662,15 +666,52 @@ merged. For a single already-atomic row, `storedMessageToUiMessage` maps it 1:1
662
666
  Persisted reasoning comes back as a `reasoning` part before the text (with its duration), and
663
667
  persisted pushed components as `data-ui` parts, so a reloaded thread shows what the live one did.
664
668
 
665
- ### Attachments and the raw client
669
+ ### Attachments
666
670
 
667
- `uploadAttachment` and the rest of `AgentClient` work outside `useAgentChat` too — e.g. from a
668
- file-picker or a standalone approvals-inbox screen:
671
+ `useAttachments` is the composer's file tray without the tray: validation, one upload per file
672
+ with progress and cancel, retry, image previews, and the handlers for a file input, a drop zone and
673
+ paste.
669
674
 
670
- ```ts
671
- const attachment = await chat.client.uploadAttachment(file); // → MessageAttachment
672
- await chat.sendMessage({ text: 'what is in this?' }, { body: { attachments: [attachment] } });
675
+ ```tsx
676
+ import { messageFiles, useAttachments } from '@dudousxd/nestjs-agent-react';
677
+
678
+ const files = useAttachments({
679
+ backend: chat.backend, // or `upload: (file, { signal, onProgress }) => myUpload(file)`
680
+ accept: 'image/*,.pdf',
681
+ maxBytes: 20 * 1024 * 1024,
682
+ maxFiles: 5,
683
+ });
684
+
685
+ <div {...files.dropZoneProps} data-dragging={files.isDragging}>
686
+ <textarea onPaste={files.onPaste} />
687
+ <input {...files.inputProps} hidden ref={pickerRef} />
688
+ {files.items.map((item) => (
689
+ <span key={item.id} data-status={item.status}>
690
+ {item.previewUrl ? <img src={item.previewUrl} alt="" /> : item.name}
691
+ {item.status === 'uploading' ? ` ${Math.round(item.progress * 100)}%` : null}
692
+ {item.error}
693
+ <button onClick={() => files.remove(item.id)}>Remove</button>
694
+ </span>
695
+ ))}
696
+ </div>
697
+
698
+ <button
699
+ disabled={files.isUploading}
700
+ onClick={async () => {
701
+ await chat.sendMessage({ text }, { body: { attachments: files.refs } });
702
+ files.clear();
703
+ }}
704
+ />
705
+ ```
673
706
 
707
+ An item is `uploading`, `ready`, `error` (retry with `files.retry(id)`) or `rejected` (failed
708
+ `accept`/`maxBytes`/`maxFiles` and never uploaded; `error` says why). `remove` cancels an upload in
709
+ flight. `messageFiles(message)` reads the files back off any message — live or replayed — with a
710
+ `kind` (`image`, `pdf`, `text`, …), the extension and, for replayed ones, the stored `mediaId`.
711
+
712
+ The rest of `AgentClient` works outside `useAgentChat` too — e.g. a standalone approvals inbox:
713
+
714
+ ```ts
674
715
  // Human-in-the-loop, callable from any component — not just the chat screen that raised it:
675
716
  await chat.approve({ toolCallId });
676
717
  await chat.reject({ toolCallId, reason: 'not now' });
@@ -0,0 +1,167 @@
1
+ import * as React from 'react';
2
+ import { ComponentType, ReactNode } from 'react';
3
+ import { T as TranscriptUiBlock } from './model-gHqjNjLJ.js';
4
+
5
+ /** The `ui` frame component a composed tree is pushed under (`GENUI_TREE_COMPONENT` of `@dudousxd/nestjs-agent-core/genui`). */
6
+ declare const GENUI_TREE_COMPONENT = "genui:tree";
7
+ /** One pushed component, normalized from whatever carried it (a transcript block, a `data-ui` part, a stored entry). */
8
+ interface GenerativeUIItem {
9
+ id: string;
10
+ component: string;
11
+ props: Record<string, unknown>;
12
+ version: number | null;
13
+ toolCallId: string | null;
14
+ }
15
+ /** A node of a composed tree (`genui:tree` frames): `{ type, props, children? }`. */
16
+ interface GenerativeUIElement {
17
+ type: string;
18
+ props: Record<string, unknown>;
19
+ children?: GenerativeUIElement[];
20
+ }
21
+ /**
22
+ * An app's renderer for one component: it receives the component's props spread, plus `children`
23
+ * when it is a layout node in a tree. Any React component — the library never styles anything.
24
+ */
25
+ type GenuiRenderer<P = any> = ComponentType<P & {
26
+ children?: ReactNode;
27
+ }>;
28
+ /** Component name → the app's renderer. */
29
+ type GenuiRegistry = Record<string, GenuiRenderer>;
30
+ /**
31
+ * Resolve a component the registry does not have — typically a tenant's own component, fetched for
32
+ * the exact `version` a message was rendered with. Return `null`/`undefined` for "no such
33
+ * component". May be async; results are cached per resolver, name and version.
34
+ */
35
+ type ResolveComponent = (name: string, version: number | null) => GenuiRenderer | null | undefined | Promise<GenuiRenderer | null | undefined>;
36
+ interface GenuiIssueLike {
37
+ path: (string | number)[];
38
+ message: string;
39
+ }
40
+ type ValidationLike = {
41
+ ok: true;
42
+ value: Record<string, unknown>;
43
+ } | {
44
+ ok: false;
45
+ issues: GenuiIssueLike[];
46
+ };
47
+ /**
48
+ * What the renderer needs from a catalog to validate props before drawing them. A `Catalog` from
49
+ * `@dudousxd/nestjs-agent-core/genui` satisfies it; declared structurally so any catalog-shaped
50
+ * object does too.
51
+ */
52
+ interface GenuiCatalogLike {
53
+ has(name: string): boolean;
54
+ validate(name: string, props: unknown): Promise<ValidationLike>;
55
+ validateSync?(name: string, props: unknown): ValidationLike | undefined;
56
+ }
57
+ interface GenerativeUIOptions {
58
+ registry: GenuiRegistry;
59
+ /** Validate props against it before rendering. Components the catalog does not know render unvalidated. */
60
+ catalog?: GenuiCatalogLike;
61
+ resolveComponent?: ResolveComponent;
62
+ /**
63
+ * Draws a composed tree frame (`genui:tree`) whole — e.g. through json-render (see the
64
+ * `/genui/json-render` subpath's `GenuiProvider`). Omitted → trees render node by node through
65
+ * `registry`.
66
+ */
67
+ treeRenderer?: GenuiRenderer<{
68
+ root?: GenerativeUIElement;
69
+ }>;
70
+ }
71
+ /** Why an item did not render. */
72
+ type GenerativeUIProblem = {
73
+ reason: 'unknown';
74
+ item: GenerativeUIItem;
75
+ } | {
76
+ reason: 'invalid';
77
+ item: GenerativeUIItem;
78
+ issues: GenuiIssueLike[];
79
+ } | {
80
+ reason: 'error';
81
+ item: GenerativeUIItem;
82
+ error: unknown;
83
+ };
84
+ type GenerativeUIState = {
85
+ status: 'ready';
86
+ item: GenerativeUIItem;
87
+ Component: GenuiRenderer;
88
+ props: Record<string, unknown>;
89
+ } | {
90
+ status: 'loading';
91
+ item: GenerativeUIItem;
92
+ } | ({
93
+ status: 'problem';
94
+ } & GenerativeUIProblem);
95
+
96
+ /** What to draw instead of a component that did not render. Default: nothing. */
97
+ type GenerativeUIFallback = ReactNode | ((problem: GenerativeUIProblem) => ReactNode);
98
+ /**
99
+ * Renders a `genui:tree` frame's `{ root }` node by node through the same registry, catalog and
100
+ * resolver as top-level components. Used automatically for tree frames unless a `treeRenderer`
101
+ * (e.g. the json-render one) or a registry entry for `genui:tree` takes over.
102
+ */
103
+ declare function GenuiTree({ root }: {
104
+ root?: GenerativeUIElement;
105
+ }): React.JSX.Element | null;
106
+ interface GenerativeUIScopeProps extends GenerativeUIOptions {
107
+ fallback?: GenerativeUIFallback;
108
+ loading?: ReactNode;
109
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
110
+ children?: ReactNode;
111
+ }
112
+ /**
113
+ * The registry, catalog and fallbacks tree nodes render with. `<GenerativeUI>` provides it; wrap
114
+ * your own chrome in it when you draw `useGenerativeUI`'s `Component` yourself and it may be a tree.
115
+ */
116
+ declare function GenerativeUIScope({ registry, catalog, resolveComponent, fallback, loading, onError, children, }: GenerativeUIScopeProps): React.JSX.Element;
117
+ /** What `<GenuiProvider>` hands every `<GenerativeUI>` / `useGenerativeUI` below it. */
118
+ interface GenuiProviderValue extends Partial<GenerativeUIOptions> {
119
+ fallback?: GenerativeUIFallback;
120
+ loading?: ReactNode;
121
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
122
+ }
123
+ /** The enclosing `<GenuiProvider>`'s settings, or `null` outside one. */
124
+ declare function useGenuiProvider(): GenuiProviderValue | null;
125
+ interface GenuiProviderProps extends GenuiProviderValue {
126
+ children?: ReactNode;
127
+ }
128
+ /**
129
+ * Set generative UI up once, at the app root: the registry of your renderers, the catalog to
130
+ * validate against, a resolver for components the registry lacks, and what to draw when one does
131
+ * not render. Every `<GenerativeUI>` below reads it (its own props still win), and `MessageItem` /
132
+ * `MessageList` draw pushed components with it — no `renderUi` per message.
133
+ *
134
+ * ```tsx
135
+ * <GenuiProvider registry={registry} catalog={catalog} fallback={({ item }) => <Unknown name={item.component} />}>
136
+ * <App />
137
+ * </GenuiProvider>
138
+ * ```
139
+ */
140
+ declare function GenuiProvider({ registry, catalog, resolveComponent, treeRenderer, fallback, loading, onError, children, }: GenuiProviderProps): React.JSX.Element;
141
+ /**
142
+ * The headless half of {@link GenerativeUI}: what to draw for one pushed component, or `null` when
143
+ * `part` is not one. Options default to the enclosing `<GenuiProvider>`'s.
144
+ */
145
+ declare function useGenerativeUI(part: unknown, options?: Partial<GenerativeUIOptions>): GenerativeUIState | null;
146
+ interface GenerativeUIProps extends Partial<GenerativeUIOptions> {
147
+ /** A transcript `ui` block, a `data-ui` message part, or a stored `{ id, component, props, version? }`. */
148
+ part: TranscriptUiBlock | GenerativeUIItem | unknown;
149
+ /** Drawn for an unknown component, invalid props, or a renderer that threw. Default: the provider's, else nothing. */
150
+ fallback?: GenerativeUIFallback;
151
+ /** Drawn while a resolver or an async validation is pending. Default: the provider's, else nothing. */
152
+ loading?: ReactNode;
153
+ /** A renderer threw (the item shows `fallback`). */
154
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
155
+ }
156
+ /**
157
+ * Draws one server-pushed component with the app's own renderer. Headless: it adds no element and
158
+ * no style of its own — only what the registry's component renders (and whatever `fallback` /
159
+ * `loading` you pass). Everything but `part` defaults to the enclosing `<GenuiProvider>`.
160
+ *
161
+ * ```tsx
162
+ * <GenerativeUI part={block} />
163
+ * ```
164
+ */
165
+ declare function GenerativeUI({ part, registry, catalog, resolveComponent, treeRenderer, fallback: ownFallback, loading: ownLoading, onError: ownOnError, }: GenerativeUIProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
166
+
167
+ export { type GenerativeUIItem as G, type ResolveComponent as R, GENUI_TREE_COMPONENT as a, GenerativeUI as b, type GenerativeUIElement as c, type GenerativeUIFallback as d, type GenerativeUIOptions as e, type GenerativeUIProblem as f, type GenerativeUIProps as g, GenerativeUIScope as h, type GenerativeUIScopeProps as i, type GenerativeUIState as j, type GenuiCatalogLike as k, type GenuiIssueLike as l, GenuiProvider as m, type GenuiProviderProps as n, type GenuiProviderValue as o, type GenuiRegistry as p, type GenuiRenderer as q, GenuiTree as r, useGenuiProvider as s, useGenerativeUI as u };
@@ -0,0 +1,167 @@
1
+ import * as React from 'react';
2
+ import { ComponentType, ReactNode } from 'react';
3
+ import { T as TranscriptUiBlock } from './model-gHqjNjLJ.cjs';
4
+
5
+ /** The `ui` frame component a composed tree is pushed under (`GENUI_TREE_COMPONENT` of `@dudousxd/nestjs-agent-core/genui`). */
6
+ declare const GENUI_TREE_COMPONENT = "genui:tree";
7
+ /** One pushed component, normalized from whatever carried it (a transcript block, a `data-ui` part, a stored entry). */
8
+ interface GenerativeUIItem {
9
+ id: string;
10
+ component: string;
11
+ props: Record<string, unknown>;
12
+ version: number | null;
13
+ toolCallId: string | null;
14
+ }
15
+ /** A node of a composed tree (`genui:tree` frames): `{ type, props, children? }`. */
16
+ interface GenerativeUIElement {
17
+ type: string;
18
+ props: Record<string, unknown>;
19
+ children?: GenerativeUIElement[];
20
+ }
21
+ /**
22
+ * An app's renderer for one component: it receives the component's props spread, plus `children`
23
+ * when it is a layout node in a tree. Any React component — the library never styles anything.
24
+ */
25
+ type GenuiRenderer<P = any> = ComponentType<P & {
26
+ children?: ReactNode;
27
+ }>;
28
+ /** Component name → the app's renderer. */
29
+ type GenuiRegistry = Record<string, GenuiRenderer>;
30
+ /**
31
+ * Resolve a component the registry does not have — typically a tenant's own component, fetched for
32
+ * the exact `version` a message was rendered with. Return `null`/`undefined` for "no such
33
+ * component". May be async; results are cached per resolver, name and version.
34
+ */
35
+ type ResolveComponent = (name: string, version: number | null) => GenuiRenderer | null | undefined | Promise<GenuiRenderer | null | undefined>;
36
+ interface GenuiIssueLike {
37
+ path: (string | number)[];
38
+ message: string;
39
+ }
40
+ type ValidationLike = {
41
+ ok: true;
42
+ value: Record<string, unknown>;
43
+ } | {
44
+ ok: false;
45
+ issues: GenuiIssueLike[];
46
+ };
47
+ /**
48
+ * What the renderer needs from a catalog to validate props before drawing them. A `Catalog` from
49
+ * `@dudousxd/nestjs-agent-core/genui` satisfies it; declared structurally so any catalog-shaped
50
+ * object does too.
51
+ */
52
+ interface GenuiCatalogLike {
53
+ has(name: string): boolean;
54
+ validate(name: string, props: unknown): Promise<ValidationLike>;
55
+ validateSync?(name: string, props: unknown): ValidationLike | undefined;
56
+ }
57
+ interface GenerativeUIOptions {
58
+ registry: GenuiRegistry;
59
+ /** Validate props against it before rendering. Components the catalog does not know render unvalidated. */
60
+ catalog?: GenuiCatalogLike;
61
+ resolveComponent?: ResolveComponent;
62
+ /**
63
+ * Draws a composed tree frame (`genui:tree`) whole — e.g. through json-render (see the
64
+ * `/genui/json-render` subpath's `GenuiProvider`). Omitted → trees render node by node through
65
+ * `registry`.
66
+ */
67
+ treeRenderer?: GenuiRenderer<{
68
+ root?: GenerativeUIElement;
69
+ }>;
70
+ }
71
+ /** Why an item did not render. */
72
+ type GenerativeUIProblem = {
73
+ reason: 'unknown';
74
+ item: GenerativeUIItem;
75
+ } | {
76
+ reason: 'invalid';
77
+ item: GenerativeUIItem;
78
+ issues: GenuiIssueLike[];
79
+ } | {
80
+ reason: 'error';
81
+ item: GenerativeUIItem;
82
+ error: unknown;
83
+ };
84
+ type GenerativeUIState = {
85
+ status: 'ready';
86
+ item: GenerativeUIItem;
87
+ Component: GenuiRenderer;
88
+ props: Record<string, unknown>;
89
+ } | {
90
+ status: 'loading';
91
+ item: GenerativeUIItem;
92
+ } | ({
93
+ status: 'problem';
94
+ } & GenerativeUIProblem);
95
+
96
+ /** What to draw instead of a component that did not render. Default: nothing. */
97
+ type GenerativeUIFallback = ReactNode | ((problem: GenerativeUIProblem) => ReactNode);
98
+ /**
99
+ * Renders a `genui:tree` frame's `{ root }` node by node through the same registry, catalog and
100
+ * resolver as top-level components. Used automatically for tree frames unless a `treeRenderer`
101
+ * (e.g. the json-render one) or a registry entry for `genui:tree` takes over.
102
+ */
103
+ declare function GenuiTree({ root }: {
104
+ root?: GenerativeUIElement;
105
+ }): React.JSX.Element | null;
106
+ interface GenerativeUIScopeProps extends GenerativeUIOptions {
107
+ fallback?: GenerativeUIFallback;
108
+ loading?: ReactNode;
109
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
110
+ children?: ReactNode;
111
+ }
112
+ /**
113
+ * The registry, catalog and fallbacks tree nodes render with. `<GenerativeUI>` provides it; wrap
114
+ * your own chrome in it when you draw `useGenerativeUI`'s `Component` yourself and it may be a tree.
115
+ */
116
+ declare function GenerativeUIScope({ registry, catalog, resolveComponent, fallback, loading, onError, children, }: GenerativeUIScopeProps): React.JSX.Element;
117
+ /** What `<GenuiProvider>` hands every `<GenerativeUI>` / `useGenerativeUI` below it. */
118
+ interface GenuiProviderValue extends Partial<GenerativeUIOptions> {
119
+ fallback?: GenerativeUIFallback;
120
+ loading?: ReactNode;
121
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
122
+ }
123
+ /** The enclosing `<GenuiProvider>`'s settings, or `null` outside one. */
124
+ declare function useGenuiProvider(): GenuiProviderValue | null;
125
+ interface GenuiProviderProps extends GenuiProviderValue {
126
+ children?: ReactNode;
127
+ }
128
+ /**
129
+ * Set generative UI up once, at the app root: the registry of your renderers, the catalog to
130
+ * validate against, a resolver for components the registry lacks, and what to draw when one does
131
+ * not render. Every `<GenerativeUI>` below reads it (its own props still win), and `MessageItem` /
132
+ * `MessageList` draw pushed components with it — no `renderUi` per message.
133
+ *
134
+ * ```tsx
135
+ * <GenuiProvider registry={registry} catalog={catalog} fallback={({ item }) => <Unknown name={item.component} />}>
136
+ * <App />
137
+ * </GenuiProvider>
138
+ * ```
139
+ */
140
+ declare function GenuiProvider({ registry, catalog, resolveComponent, treeRenderer, fallback, loading, onError, children, }: GenuiProviderProps): React.JSX.Element;
141
+ /**
142
+ * The headless half of {@link GenerativeUI}: what to draw for one pushed component, or `null` when
143
+ * `part` is not one. Options default to the enclosing `<GenuiProvider>`'s.
144
+ */
145
+ declare function useGenerativeUI(part: unknown, options?: Partial<GenerativeUIOptions>): GenerativeUIState | null;
146
+ interface GenerativeUIProps extends Partial<GenerativeUIOptions> {
147
+ /** A transcript `ui` block, a `data-ui` message part, or a stored `{ id, component, props, version? }`. */
148
+ part: TranscriptUiBlock | GenerativeUIItem | unknown;
149
+ /** Drawn for an unknown component, invalid props, or a renderer that threw. Default: the provider's, else nothing. */
150
+ fallback?: GenerativeUIFallback;
151
+ /** Drawn while a resolver or an async validation is pending. Default: the provider's, else nothing. */
152
+ loading?: ReactNode;
153
+ /** A renderer threw (the item shows `fallback`). */
154
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
155
+ }
156
+ /**
157
+ * Draws one server-pushed component with the app's own renderer. Headless: it adds no element and
158
+ * no style of its own — only what the registry's component renders (and whatever `fallback` /
159
+ * `loading` you pass). Everything but `part` defaults to the enclosing `<GenuiProvider>`.
160
+ *
161
+ * ```tsx
162
+ * <GenerativeUI part={block} />
163
+ * ```
164
+ */
165
+ declare function GenerativeUI({ part, registry, catalog, resolveComponent, treeRenderer, fallback: ownFallback, loading: ownLoading, onError: ownOnError, }: GenerativeUIProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
166
+
167
+ export { type GenerativeUIItem as G, type ResolveComponent as R, GENUI_TREE_COMPONENT as a, GenerativeUI as b, type GenerativeUIElement as c, type GenerativeUIFallback as d, type GenerativeUIOptions as e, type GenerativeUIProblem as f, type GenerativeUIProps as g, GenerativeUIScope as h, type GenerativeUIScopeProps as i, type GenerativeUIState as j, type GenuiCatalogLike as k, type GenuiIssueLike as l, GenuiProvider as m, type GenuiProviderProps as n, type GenuiProviderValue as o, type GenuiRegistry as p, type GenuiRenderer as q, GenuiTree as r, useGenuiProvider as s, useGenerativeUI as u };