@dudousxd/nestjs-agent-react 0.18.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 +28 -24
- package/dist/generative-ui-BhXFni8j.d.ts +167 -0
- package/dist/generative-ui-C53b3FoA.d.cts +167 -0
- package/dist/genui-json-render.cjs +521 -4
- package/dist/genui-json-render.cjs.map +1 -1
- package/dist/genui-json-render.d.cts +15 -2
- package/dist/genui-json-render.d.ts +15 -2
- package/dist/genui-json-render.js +518 -2
- package/dist/genui-json-render.js.map +1 -1
- package/dist/genui.cjs +120 -23
- package/dist/genui.cjs.map +1 -1
- package/dist/genui.d.cts +5 -52
- package/dist/genui.d.ts +5 -52
- package/dist/genui.js +106 -11
- package/dist/genui.js.map +1 -1
- package/dist/index.cjs +201 -174
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -7
- package/dist/index.d.ts +24 -7
- package/dist/index.js +26 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
- package/dist/types-DFD-soWU.d.cts +0 -86
- package/dist/types-DFD-soWU.d.ts +0 -86
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 {
|
|
358
|
-
import { catalog } from './catalog'; // optional:
|
|
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
|
-
<
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
**json-render** (optional peer `@json-render/react` >= 0.21):
|
|
392
|
-
`@dudousxd/nestjs-agent-react/genui/json-render`
|
|
393
|
-
`
|
|
394
|
-
|
|
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.
|
|
393
|
+
|
|
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
|
|
|
@@ -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 };
|