@dudousxd/nestjs-agent-react 0.13.0 → 0.14.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/dist/genui.cjs ADDED
@@ -0,0 +1,450 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/genui/index.ts
22
+ var genui_exports = {};
23
+ __export(genui_exports, {
24
+ GENUI_TREE_COMPONENT: () => GENUI_TREE_COMPONENT,
25
+ GenerativeUI: () => GenerativeUI,
26
+ GenerativeUIScope: () => GenerativeUIScope,
27
+ GenuiTree: () => GenuiTree,
28
+ toGenerativeUIItem: () => toGenerativeUIItem,
29
+ useGenerativeUI: () => useGenerativeUI
30
+ });
31
+ module.exports = __toCommonJS(genui_exports);
32
+
33
+ // src/genui/generative-ui.tsx
34
+ var import_react2 = require("react");
35
+
36
+ // src/genui/use-generative-ui.ts
37
+ var import_react = require("react");
38
+
39
+ // src/genui/types.ts
40
+ var GENUI_TREE_COMPONENT = "genui:tree";
41
+
42
+ // src/genui/use-generative-ui.ts
43
+ function isRecord(value) {
44
+ return typeof value === "object" && value !== null && !Array.isArray(value);
45
+ }
46
+ __name(isRecord, "isRecord");
47
+ function toGenerativeUIItem(part) {
48
+ if (!isRecord(part)) return null;
49
+ const source = part.type === "data-ui" && isRecord(part.data) ? part.data : part;
50
+ if (typeof source.component !== "string") return null;
51
+ const id = typeof source.id === "string" ? source.id : typeof part.id === "string" ? part.id : null;
52
+ if (id === null) return null;
53
+ return {
54
+ id,
55
+ component: source.component,
56
+ props: isRecord(source.props) ? source.props : {},
57
+ version: typeof source.version === "number" ? source.version : null,
58
+ toolCallId: typeof source.toolCallId === "string" ? source.toolCallId : null
59
+ };
60
+ }
61
+ __name(toGenerativeUIItem, "toGenerativeUIItem");
62
+ var resolverCaches = /* @__PURE__ */ new WeakMap();
63
+ function resolveCached(resolve, name, version) {
64
+ let cache = resolverCaches.get(resolve);
65
+ if (cache === void 0) {
66
+ cache = /* @__PURE__ */ new Map();
67
+ resolverCaches.set(resolve, cache);
68
+ }
69
+ const key = `${name}@${version ?? ""}`;
70
+ const hit = cache.get(key);
71
+ if (hit !== void 0) return hit;
72
+ let entry;
73
+ try {
74
+ const result = resolve(name, version);
75
+ if (result instanceof Promise) {
76
+ entry = {
77
+ resolution: {
78
+ status: "loading"
79
+ },
80
+ settled: null
81
+ };
82
+ entry.settled = result.then((Component2) => {
83
+ entry.resolution = Component2 ? {
84
+ status: "ready",
85
+ Component: Component2
86
+ } : {
87
+ status: "unknown"
88
+ };
89
+ }, (error) => {
90
+ entry.resolution = {
91
+ status: "error",
92
+ error
93
+ };
94
+ });
95
+ } else {
96
+ entry = {
97
+ resolution: result ? {
98
+ status: "ready",
99
+ Component: result
100
+ } : {
101
+ status: "unknown"
102
+ },
103
+ settled: null
104
+ };
105
+ }
106
+ } catch (error) {
107
+ entry = {
108
+ resolution: {
109
+ status: "error",
110
+ error
111
+ },
112
+ settled: null
113
+ };
114
+ }
115
+ cache.set(key, entry);
116
+ return entry;
117
+ }
118
+ __name(resolveCached, "resolveCached");
119
+ function useResolvedComponent(name, version, registry, resolve, fallbackTree) {
120
+ const [, setTick] = (0, import_react.useState)(0);
121
+ const own = registry[name];
122
+ const entry = own !== void 0 || resolve === void 0 ? null : resolveCached(resolve, name, version);
123
+ const pending = entry?.resolution.status === "loading" ? entry.settled : null;
124
+ (0, import_react.useEffect)(() => {
125
+ if (pending === null) return;
126
+ let live = true;
127
+ void pending.then(() => {
128
+ if (live) setTick((tick) => tick + 1);
129
+ });
130
+ return () => {
131
+ live = false;
132
+ };
133
+ }, [
134
+ pending
135
+ ]);
136
+ if (own !== void 0) return {
137
+ status: "ready",
138
+ Component: own
139
+ };
140
+ if (entry !== null && entry.resolution.status !== "unknown") return entry.resolution;
141
+ if (name === GENUI_TREE_COMPONENT && fallbackTree !== void 0) {
142
+ return {
143
+ status: "ready",
144
+ Component: fallbackTree
145
+ };
146
+ }
147
+ return {
148
+ status: "unknown"
149
+ };
150
+ }
151
+ __name(useResolvedComponent, "useResolvedComponent");
152
+ function useValidatedProps(catalog, name, props) {
153
+ const checked = catalog?.has(name) === true;
154
+ const immediate = (0, import_react.useMemo)(() => {
155
+ if (!checked || catalog === void 0) return {
156
+ status: "ok",
157
+ props
158
+ };
159
+ const result = catalog.validateSync?.(name, props);
160
+ if (result === void 0) return null;
161
+ return result.ok ? {
162
+ status: "ok",
163
+ props: result.value
164
+ } : {
165
+ status: "invalid",
166
+ issues: result.issues
167
+ };
168
+ }, [
169
+ checked,
170
+ catalog,
171
+ name,
172
+ props
173
+ ]);
174
+ const [late, setLate] = (0, import_react.useState)(null);
175
+ (0, import_react.useEffect)(() => {
176
+ if (immediate !== null || catalog === void 0) return;
177
+ let live = true;
178
+ catalog.validate(name, props).then((result) => {
179
+ if (!live) return;
180
+ setLate({
181
+ props,
182
+ result: result.ok ? {
183
+ status: "ok",
184
+ props: result.value
185
+ } : {
186
+ status: "invalid",
187
+ issues: result.issues
188
+ }
189
+ });
190
+ }, (error) => {
191
+ if (!live) return;
192
+ setLate({
193
+ props,
194
+ result: {
195
+ status: "invalid",
196
+ issues: [
197
+ {
198
+ path: [],
199
+ message: error instanceof Error ? error.message : String(error)
200
+ }
201
+ ]
202
+ }
203
+ });
204
+ });
205
+ return () => {
206
+ live = false;
207
+ };
208
+ }, [
209
+ immediate,
210
+ catalog,
211
+ name,
212
+ props
213
+ ]);
214
+ if (immediate !== null) return immediate;
215
+ return late !== null && late.props === props ? late.result : {
216
+ status: "pending"
217
+ };
218
+ }
219
+ __name(useValidatedProps, "useValidatedProps");
220
+ function useGenerativeUIState(part, options, fallbackTree) {
221
+ const item = (0, import_react.useMemo)(() => toGenerativeUIItem(part), [
222
+ part
223
+ ]);
224
+ const name = item?.component ?? "";
225
+ const resolution = useResolvedComponent(name, item?.version ?? null, options.registry, item === null ? void 0 : options.resolveComponent, fallbackTree);
226
+ const empty = (0, import_react.useMemo)(() => ({}), []);
227
+ const validation = useValidatedProps(item === null || name === GENUI_TREE_COMPONENT ? void 0 : options.catalog, name, item?.props ?? empty);
228
+ if (item === null) return null;
229
+ if (resolution.status === "loading") return {
230
+ status: "loading",
231
+ item
232
+ };
233
+ if (resolution.status === "unknown") return {
234
+ status: "problem",
235
+ reason: "unknown",
236
+ item
237
+ };
238
+ if (resolution.status === "error") {
239
+ return {
240
+ status: "problem",
241
+ reason: "error",
242
+ item,
243
+ error: resolution.error
244
+ };
245
+ }
246
+ if (validation.status === "pending") return {
247
+ status: "loading",
248
+ item
249
+ };
250
+ if (validation.status === "invalid") {
251
+ return {
252
+ status: "problem",
253
+ reason: "invalid",
254
+ item,
255
+ issues: validation.issues
256
+ };
257
+ }
258
+ return {
259
+ status: "ready",
260
+ item,
261
+ Component: resolution.Component,
262
+ props: validation.props
263
+ };
264
+ }
265
+ __name(useGenerativeUIState, "useGenerativeUIState");
266
+
267
+ // src/genui/generative-ui.tsx
268
+ var TreeScopeContext = /* @__PURE__ */ (0, import_react2.createContext)(null);
269
+ function renderFallback(fallback, problem) {
270
+ if (typeof fallback === "function") return fallback(problem);
271
+ return fallback ?? null;
272
+ }
273
+ __name(renderFallback, "renderFallback");
274
+ var ItemBoundary = class ItemBoundary2 extends import_react2.Component {
275
+ static {
276
+ __name(this, "ItemBoundary");
277
+ }
278
+ state = {
279
+ error: void 0,
280
+ failed: false
281
+ };
282
+ static getDerivedStateFromError(error) {
283
+ return {
284
+ error,
285
+ failed: true
286
+ };
287
+ }
288
+ componentDidCatch(error, _info) {
289
+ this.props.onError?.(error, this.props.item);
290
+ }
291
+ componentDidUpdate(previous) {
292
+ if (this.state.failed && previous.item !== this.props.item) {
293
+ this.setState({
294
+ error: void 0,
295
+ failed: false
296
+ });
297
+ }
298
+ }
299
+ render() {
300
+ if (this.state.failed) {
301
+ return renderFallback(this.props.fallback, {
302
+ reason: "error",
303
+ item: this.props.item,
304
+ error: this.state.error
305
+ });
306
+ }
307
+ return this.props.children;
308
+ }
309
+ };
310
+ function nodeItem(node, id) {
311
+ return {
312
+ id,
313
+ component: node.type,
314
+ props: node.props ?? {},
315
+ version: null,
316
+ toolCallId: null
317
+ };
318
+ }
319
+ __name(nodeItem, "nodeItem");
320
+ function TreeNode({ node, id }) {
321
+ const scope = (0, import_react2.useContext)(TreeScopeContext);
322
+ const item = (0, import_react2.useMemo)(() => nodeItem(node, id), [
323
+ node,
324
+ id
325
+ ]);
326
+ const resolution = useResolvedComponent(node.type, null, scope?.options.registry ?? {}, scope?.options.resolveComponent);
327
+ const validation = useValidatedProps(scope?.options.catalog, node.type, item.props);
328
+ if (scope === null) return null;
329
+ if (resolution.status === "loading" || validation.status === "pending") return scope.loading;
330
+ if (resolution.status === "unknown") {
331
+ return renderFallback(scope.fallback, {
332
+ reason: "unknown",
333
+ item
334
+ });
335
+ }
336
+ if (resolution.status === "error") {
337
+ return renderFallback(scope.fallback, {
338
+ reason: "error",
339
+ item,
340
+ error: resolution.error
341
+ });
342
+ }
343
+ if (validation.status === "invalid") {
344
+ return renderFallback(scope.fallback, {
345
+ reason: "invalid",
346
+ item,
347
+ issues: validation.issues
348
+ });
349
+ }
350
+ const Renderer = resolution.Component;
351
+ const children = Array.isArray(node.children) ? node.children : [];
352
+ return /* @__PURE__ */ React.createElement(Renderer, validation.props, children.length > 0 ? children.map((child, index) => {
353
+ const childId = `${id}.${index}`;
354
+ return /* @__PURE__ */ React.createElement(ItemBoundary, {
355
+ key: childId,
356
+ item: nodeItem(child, childId),
357
+ fallback: scope.fallback,
358
+ onError: scope.onError
359
+ }, /* @__PURE__ */ React.createElement(TreeNode, {
360
+ node: child,
361
+ id: childId
362
+ }));
363
+ }) : void 0);
364
+ }
365
+ __name(TreeNode, "TreeNode");
366
+ function GenuiTree({ root }) {
367
+ if (root === void 0 || root === null || typeof root.type !== "string") return null;
368
+ return /* @__PURE__ */ React.createElement(TreeNode, {
369
+ node: root,
370
+ id: "root"
371
+ });
372
+ }
373
+ __name(GenuiTree, "GenuiTree");
374
+ function GenerativeUIScope({ registry, catalog, resolveComponent, fallback, loading = null, onError, children }) {
375
+ const scope = (0, import_react2.useMemo)(() => ({
376
+ options: {
377
+ registry,
378
+ ...catalog !== void 0 ? {
379
+ catalog
380
+ } : {},
381
+ ...resolveComponent !== void 0 ? {
382
+ resolveComponent
383
+ } : {}
384
+ },
385
+ fallback,
386
+ loading,
387
+ onError
388
+ }), [
389
+ registry,
390
+ catalog,
391
+ resolveComponent,
392
+ fallback,
393
+ loading,
394
+ onError
395
+ ]);
396
+ return /* @__PURE__ */ React.createElement(TreeScopeContext.Provider, {
397
+ value: scope
398
+ }, children);
399
+ }
400
+ __name(GenerativeUIScope, "GenerativeUIScope");
401
+ function useGenerativeUI(part, options) {
402
+ return useGenerativeUIState(part, options, GenuiTree);
403
+ }
404
+ __name(useGenerativeUI, "useGenerativeUI");
405
+ function GenerativeUI({ part, registry, catalog, resolveComponent, fallback, loading = null, onError }) {
406
+ const options = (0, import_react2.useMemo)(() => ({
407
+ registry,
408
+ ...catalog !== void 0 ? {
409
+ catalog
410
+ } : {},
411
+ ...resolveComponent !== void 0 ? {
412
+ resolveComponent
413
+ } : {}
414
+ }), [
415
+ registry,
416
+ catalog,
417
+ resolveComponent
418
+ ]);
419
+ const state = useGenerativeUI(part, options);
420
+ if (state === null) return null;
421
+ if (state.status === "loading") return loading;
422
+ if (state.status === "problem") {
423
+ const { status: _status, ...problem } = state;
424
+ return renderFallback(fallback, problem);
425
+ }
426
+ const Renderer = state.Component;
427
+ return /* @__PURE__ */ React.createElement(GenerativeUIScope, {
428
+ ...options,
429
+ fallback,
430
+ loading,
431
+ ...onError !== void 0 ? {
432
+ onError
433
+ } : {}
434
+ }, /* @__PURE__ */ React.createElement(ItemBoundary, {
435
+ item: state.item,
436
+ fallback,
437
+ onError
438
+ }, /* @__PURE__ */ React.createElement(Renderer, state.props)));
439
+ }
440
+ __name(GenerativeUI, "GenerativeUI");
441
+ // Annotate the CommonJS export names for ESM import in node:
442
+ 0 && (module.exports = {
443
+ GENUI_TREE_COMPONENT,
444
+ GenerativeUI,
445
+ GenerativeUIScope,
446
+ GenuiTree,
447
+ toGenerativeUIItem,
448
+ useGenerativeUI
449
+ });
450
+ //# sourceMappingURL=genui.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/genui/index.ts","../src/genui/generative-ui.tsx","../src/genui/use-generative-ui.ts","../src/genui/types.ts"],"sourcesContent":["export {\n GenerativeUI,\n type GenerativeUIFallback,\n type GenerativeUIProps,\n GenerativeUIScope,\n type GenerativeUIScopeProps,\n GenuiTree,\n useGenerativeUI,\n} from './generative-ui.js';\nexport {\n GENUI_TREE_COMPONENT,\n type GenerativeUIElement,\n type GenerativeUIItem,\n type GenerativeUIOptions,\n type GenerativeUIProblem,\n type GenerativeUIState,\n type GenuiCatalogLike,\n type GenuiIssueLike,\n type GenuiRegistry,\n type GenuiRenderer,\n type ResolveComponent,\n} from './types.js';\nexport { toGenerativeUIItem } from './use-generative-ui.js';\n","import {\n Component,\n type ErrorInfo,\n type ReactNode,\n createContext,\n useContext,\n useMemo,\n} from 'react';\nimport type { TranscriptUiBlock } from '../transcript/model.js';\nimport type {\n GenerativeUIElement,\n GenerativeUIItem,\n GenerativeUIOptions,\n GenerativeUIProblem,\n GenerativeUIState,\n GenuiRenderer,\n} from './types.js';\nimport {\n useGenerativeUIState,\n useResolvedComponent,\n useValidatedProps,\n} from './use-generative-ui.js';\n\n/** What to draw instead of a component that did not render. Default: nothing. */\nexport type GenerativeUIFallback = ReactNode | ((problem: GenerativeUIProblem) => ReactNode);\n\ninterface TreeScope {\n options: GenerativeUIOptions;\n fallback: GenerativeUIFallback | undefined;\n loading: ReactNode;\n onError: ((error: unknown, item: GenerativeUIItem) => void) | undefined;\n}\n\nconst TreeScopeContext = createContext<TreeScope | null>(null);\n\nfunction renderFallback(fallback: GenerativeUIFallback | undefined, problem: GenerativeUIProblem) {\n if (typeof fallback === 'function') return fallback(problem);\n return fallback ?? null;\n}\n\ninterface BoundaryProps {\n item: GenerativeUIItem;\n fallback: GenerativeUIFallback | undefined;\n onError: ((error: unknown, item: GenerativeUIItem) => void) | undefined;\n children: ReactNode;\n}\n\n/** One failing renderer takes down its own item, never the message around it. */\nclass ItemBoundary extends Component<BoundaryProps, { error: unknown; failed: boolean }> {\n override state = { error: undefined as unknown, failed: false };\n\n static getDerivedStateFromError(error: unknown) {\n return { error, failed: true };\n }\n\n override componentDidCatch(error: unknown, _info: ErrorInfo) {\n this.props.onError?.(error, this.props.item);\n }\n\n override componentDidUpdate(previous: BoundaryProps) {\n // New props for the same item (a streamed update) get a fresh chance to render.\n if (this.state.failed && previous.item !== this.props.item) {\n this.setState({ error: undefined, failed: false });\n }\n }\n\n override render() {\n if (this.state.failed) {\n return renderFallback(this.props.fallback, {\n reason: 'error',\n item: this.props.item,\n error: this.state.error,\n });\n }\n return this.props.children;\n }\n}\n\nfunction nodeItem(node: GenerativeUIElement, id: string): GenerativeUIItem {\n return { id, component: node.type, props: node.props ?? {}, version: null, toolCallId: null };\n}\n\n/** One tree node: resolved and validated like a top-level item, children rendered as its `children`. */\nfunction TreeNode({ node, id }: { node: GenerativeUIElement; id: string }) {\n const scope = useContext(TreeScopeContext);\n const item = useMemo(() => nodeItem(node, id), [node, id]);\n const resolution = useResolvedComponent(\n node.type,\n null,\n scope?.options.registry ?? {},\n scope?.options.resolveComponent,\n );\n const validation = useValidatedProps(scope?.options.catalog, node.type, item.props);\n if (scope === null) return null;\n if (resolution.status === 'loading' || validation.status === 'pending') return scope.loading;\n if (resolution.status === 'unknown') {\n return renderFallback(scope.fallback, { reason: 'unknown', item });\n }\n if (resolution.status === 'error') {\n return renderFallback(scope.fallback, { reason: 'error', item, error: resolution.error });\n }\n if (validation.status === 'invalid') {\n return renderFallback(scope.fallback, { reason: 'invalid', item, issues: validation.issues });\n }\n const Renderer = resolution.Component;\n const children = Array.isArray(node.children) ? node.children : [];\n return (\n <Renderer {...validation.props}>\n {children.length > 0\n ? children.map((child, index) => {\n const childId = `${id}.${index}`;\n return (\n <ItemBoundary\n key={childId}\n item={nodeItem(child, childId)}\n fallback={scope.fallback}\n onError={scope.onError}\n >\n <TreeNode node={child} id={childId} />\n </ItemBoundary>\n );\n })\n : undefined}\n </Renderer>\n );\n}\n\n/**\n * Renders a `genui:tree` frame's `{ root }` node by node through the same registry, catalog and\n * resolver as top-level components. Used automatically for tree frames unless the registry\n * overrides `genui:tree` (e.g. with the json-render adapter).\n */\nexport function GenuiTree({ root }: { root?: GenerativeUIElement }) {\n if (root === undefined || root === null || typeof root.type !== 'string') return null;\n return <TreeNode node={root} id=\"root\" />;\n}\n\nexport interface GenerativeUIScopeProps extends GenerativeUIOptions {\n fallback?: GenerativeUIFallback;\n loading?: ReactNode;\n onError?: (error: unknown, item: GenerativeUIItem) => void;\n children?: ReactNode;\n}\n\n/**\n * The registry, catalog and fallbacks tree nodes render with. `<GenerativeUI>` provides it; wrap\n * your own chrome in it when you draw `useGenerativeUI`'s `Component` yourself and it may be a tree.\n */\nexport function GenerativeUIScope({\n registry,\n catalog,\n resolveComponent,\n fallback,\n loading = null,\n onError,\n children,\n}: GenerativeUIScopeProps) {\n const scope = useMemo<TreeScope>(\n () => ({\n options: {\n registry,\n ...(catalog !== undefined ? { catalog } : {}),\n ...(resolveComponent !== undefined ? { resolveComponent } : {}),\n },\n fallback,\n loading,\n onError,\n }),\n [registry, catalog, resolveComponent, fallback, loading, onError],\n );\n return <TreeScopeContext.Provider value={scope}>{children}</TreeScopeContext.Provider>;\n}\n\n/** The headless half of {@link GenerativeUI}: what to draw for one pushed component, or `null` when `part` is not one. */\nexport function useGenerativeUI(\n part: unknown,\n options: GenerativeUIOptions,\n): GenerativeUIState | null {\n return useGenerativeUIState(part, options, GenuiTree as GenuiRenderer);\n}\n\nexport interface GenerativeUIProps extends GenerativeUIOptions {\n /** A transcript `ui` block, a `data-ui` message part, or a stored `{ id, component, props, version? }`. */\n part: TranscriptUiBlock | GenerativeUIItem | unknown;\n /** Drawn for an unknown component, invalid props, or a renderer that threw. Default: nothing. */\n fallback?: GenerativeUIFallback;\n /** Drawn while a resolver or an async validation is pending. Default: nothing. */\n loading?: ReactNode;\n /** A renderer threw (the item shows `fallback`). */\n onError?: (error: unknown, item: GenerativeUIItem) => void;\n}\n\n/**\n * Draws one server-pushed component with the app's own renderer. Headless: it adds no element and\n * no style of its own — only what the registry's component renders (and whatever `fallback` /\n * `loading` you pass).\n *\n * ```tsx\n * <MessageItem message={m} renderUi={(block) => (\n * <GenerativeUI part={block} registry={registry} catalog={catalog} fallback={({ item }) => <Unknown name={item.component} />} />\n * )} />\n * ```\n */\nexport function GenerativeUI({\n part,\n registry,\n catalog,\n resolveComponent,\n fallback,\n loading = null,\n onError,\n}: GenerativeUIProps) {\n const options = useMemo<GenerativeUIOptions>(\n () => ({\n registry,\n ...(catalog !== undefined ? { catalog } : {}),\n ...(resolveComponent !== undefined ? { resolveComponent } : {}),\n }),\n [registry, catalog, resolveComponent],\n );\n const state = useGenerativeUI(part, options);\n if (state === null) return null;\n if (state.status === 'loading') return loading;\n if (state.status === 'problem') {\n const { status: _status, ...problem } = state;\n return renderFallback(fallback, problem);\n }\n const Renderer = state.Component;\n return (\n <GenerativeUIScope\n {...options}\n fallback={fallback}\n loading={loading}\n {...(onError !== undefined ? { onError } : {})}\n >\n <ItemBoundary item={state.item} fallback={fallback} onError={onError}>\n <Renderer {...state.props} />\n </ItemBoundary>\n </GenerativeUIScope>\n );\n}\n","import { useEffect, useMemo, useState } from 'react';\nimport {\n GENUI_TREE_COMPONENT,\n type GenerativeUIItem,\n type GenerativeUIOptions,\n type GenerativeUIState,\n type GenuiCatalogLike,\n type GenuiIssueLike,\n type GenuiRegistry,\n type GenuiRenderer,\n type ResolveComponent,\n} from './types.js';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Normalize whatever carries a pushed component: a transcript `ui` block, a `data-ui` message part\n * (`{ type: 'data-ui', id, data }`), a stored `{ id, component, props, version? }` entry. `null` for\n * anything else.\n */\nexport function toGenerativeUIItem(part: unknown): GenerativeUIItem | null {\n if (!isRecord(part)) return null;\n const source = part.type === 'data-ui' && isRecord(part.data) ? part.data : part;\n if (typeof source.component !== 'string') return null;\n const id =\n typeof source.id === 'string' ? source.id : typeof part.id === 'string' ? part.id : null;\n if (id === null) return null;\n return {\n id,\n component: source.component,\n props: isRecord(source.props) ? source.props : {},\n version: typeof source.version === 'number' ? source.version : null,\n toolCallId: typeof source.toolCallId === 'string' ? source.toolCallId : null,\n };\n}\n\ntype Resolution =\n | { status: 'ready'; Component: GenuiRenderer }\n | { status: 'loading' }\n | { status: 'unknown' }\n | { status: 'error'; error: unknown };\n\ninterface CacheEntry {\n resolution: Resolution;\n settled: Promise<void> | null;\n}\n\nconst resolverCaches = new WeakMap<ResolveComponent, Map<string, CacheEntry>>();\n\nfunction resolveCached(\n resolve: ResolveComponent,\n name: string,\n version: number | null,\n): CacheEntry {\n let cache = resolverCaches.get(resolve);\n if (cache === undefined) {\n cache = new Map();\n resolverCaches.set(resolve, cache);\n }\n const key = `${name}@${version ?? ''}`;\n const hit = cache.get(key);\n if (hit !== undefined) return hit;\n let entry: CacheEntry;\n try {\n const result = resolve(name, version);\n if (result instanceof Promise) {\n entry = { resolution: { status: 'loading' }, settled: null };\n entry.settled = result.then(\n (Component) => {\n entry.resolution = Component ? { status: 'ready', Component } : { status: 'unknown' };\n },\n (error: unknown) => {\n entry.resolution = { status: 'error', error };\n },\n );\n } else {\n entry = {\n resolution: result ? { status: 'ready', Component: result } : { status: 'unknown' },\n settled: null,\n };\n }\n } catch (error) {\n entry = { resolution: { status: 'error', error }, settled: null };\n }\n cache.set(key, entry);\n return entry;\n}\n\n/**\n * Which renderer draws `name`: the registry first, then `resolveComponent` (cached; async results\n * re-render the caller when they land). `fallbackTree` answers the tree component when the\n * registry does not override it.\n */\nexport function useResolvedComponent(\n name: string,\n version: number | null,\n registry: GenuiRegistry,\n resolve: ResolveComponent | undefined,\n fallbackTree?: GenuiRenderer,\n): Resolution {\n const [, setTick] = useState(0);\n const own = registry[name];\n const entry =\n own !== undefined || resolve === undefined ? null : resolveCached(resolve, name, version);\n const pending = entry?.resolution.status === 'loading' ? entry.settled : null;\n useEffect(() => {\n if (pending === null) return;\n let live = true;\n void pending.then(() => {\n if (live) setTick((tick) => tick + 1);\n });\n return () => {\n live = false;\n };\n }, [pending]);\n if (own !== undefined) return { status: 'ready', Component: own };\n if (entry !== null && entry.resolution.status !== 'unknown') return entry.resolution;\n if (name === GENUI_TREE_COMPONENT && fallbackTree !== undefined) {\n return { status: 'ready', Component: fallbackTree };\n }\n return { status: 'unknown' };\n}\n\ntype Validation =\n | { status: 'ok'; props: Record<string, unknown> }\n | { status: 'pending' }\n | { status: 'invalid'; issues: GenuiIssueLike[] };\n\n/**\n * Props checked against the catalog: synchronously when the catalog can (`validateSync`), else\n * after the async check settles. A component the catalog does not know passes through unchecked.\n */\nexport function useValidatedProps(\n catalog: GenuiCatalogLike | undefined,\n name: string,\n props: Record<string, unknown>,\n): Validation {\n const checked = catalog?.has(name) === true;\n const immediate = useMemo<Validation | null>(() => {\n if (!checked || catalog === undefined) return { status: 'ok', props };\n const result = catalog.validateSync?.(name, props);\n if (result === undefined) return null;\n return result.ok\n ? { status: 'ok', props: result.value }\n : { status: 'invalid', issues: result.issues };\n }, [checked, catalog, name, props]);\n const [late, setLate] = useState<{ props: Record<string, unknown>; result: Validation } | null>(\n null,\n );\n useEffect(() => {\n if (immediate !== null || catalog === undefined) return;\n let live = true;\n catalog.validate(name, props).then(\n (result) => {\n if (!live) return;\n setLate({\n props,\n result: result.ok\n ? { status: 'ok', props: result.value }\n : { status: 'invalid', issues: result.issues },\n });\n },\n (error: unknown) => {\n if (!live) return;\n setLate({\n props,\n result: {\n status: 'invalid',\n issues: [{ path: [], message: error instanceof Error ? error.message : String(error) }],\n },\n });\n },\n );\n return () => {\n live = false;\n };\n }, [immediate, catalog, name, props]);\n if (immediate !== null) return immediate;\n return late !== null && late.props === props ? late.result : { status: 'pending' };\n}\n\n/** {@link import('./generative-ui.js').useGenerativeUI}, with the tree renderer handed in (avoids an import cycle). */\nexport function useGenerativeUIState(\n part: unknown,\n options: GenerativeUIOptions,\n fallbackTree: GenuiRenderer | undefined,\n): GenerativeUIState | null {\n const item = useMemo(() => toGenerativeUIItem(part), [part]);\n const name = item?.component ?? '';\n const resolution = useResolvedComponent(\n name,\n item?.version ?? null,\n options.registry,\n item === null ? undefined : options.resolveComponent,\n fallbackTree,\n );\n const empty = useMemo<Record<string, unknown>>(() => ({}), []);\n // A tree is validated node by node as it renders, not as one component.\n const validation = useValidatedProps(\n item === null || name === GENUI_TREE_COMPONENT ? undefined : options.catalog,\n name,\n item?.props ?? empty,\n );\n if (item === null) return null;\n if (resolution.status === 'loading') return { status: 'loading', item };\n if (resolution.status === 'unknown') return { status: 'problem', reason: 'unknown', item };\n if (resolution.status === 'error') {\n return { status: 'problem', reason: 'error', item, error: resolution.error };\n }\n if (validation.status === 'pending') return { status: 'loading', item };\n if (validation.status === 'invalid') {\n return { status: 'problem', reason: 'invalid', item, issues: validation.issues };\n }\n return { status: 'ready', item, Component: resolution.Component, props: validation.props };\n}\n","import type { ComponentType, ReactNode } from 'react';\n\n/** The `ui` frame component a composed tree is pushed under (`@dudousxd/nestjs-agent-genui`'s `GENUI_TREE_COMPONENT`). */\nexport const GENUI_TREE_COMPONENT = 'genui:tree';\n\n/** One pushed component, normalized from whatever carried it (a transcript block, a `data-ui` part, a stored entry). */\nexport interface GenerativeUIItem {\n id: string;\n component: string;\n props: Record<string, unknown>;\n version: number | null;\n toolCallId: string | null;\n}\n\n/** A node of a composed tree (`genui:tree` frames): `{ type, props, children? }`. */\nexport interface GenerativeUIElement {\n type: string;\n props: Record<string, unknown>;\n children?: GenerativeUIElement[];\n}\n\n/**\n * An app's renderer for one component: it receives the component's props spread, plus `children`\n * when it is a layout node in a tree. Any React component — the library never styles anything.\n */\nexport type GenuiRenderer<P = any> = ComponentType<P & { children?: ReactNode }>;\n\n/** Component name → the app's renderer. */\nexport type GenuiRegistry = Record<string, GenuiRenderer>;\n\n/**\n * Resolve a component the registry does not have — typically a tenant's own component, fetched for\n * the exact `version` a message was rendered with. Return `null`/`undefined` for \"no such\n * component\". May be async; results are cached per resolver, name and version.\n */\nexport type ResolveComponent = (\n name: string,\n version: number | null,\n) => GenuiRenderer | null | undefined | Promise<GenuiRenderer | null | undefined>;\n\nexport interface GenuiIssueLike {\n path: (string | number)[];\n message: string;\n}\n\ntype ValidationLike =\n | { ok: true; value: Record<string, unknown> }\n | { ok: false; issues: GenuiIssueLike[] };\n\n/**\n * What the renderer needs from a catalog to validate props before drawing them. A\n * `@dudousxd/nestjs-agent-genui` `Catalog` satisfies it; declared structurally so this subpath does\n * not depend on that package.\n */\nexport interface GenuiCatalogLike {\n has(name: string): boolean;\n validate(name: string, props: unknown): Promise<ValidationLike>;\n validateSync?(name: string, props: unknown): ValidationLike | undefined;\n}\n\nexport interface GenerativeUIOptions {\n registry: GenuiRegistry;\n /** Validate props against it before rendering. Components the catalog does not know render unvalidated. */\n catalog?: GenuiCatalogLike;\n resolveComponent?: ResolveComponent;\n}\n\n/** Why an item did not render. */\nexport type GenerativeUIProblem =\n | { reason: 'unknown'; item: GenerativeUIItem }\n | { reason: 'invalid'; item: GenerativeUIItem; issues: GenuiIssueLike[] }\n | { reason: 'error'; item: GenerativeUIItem; error: unknown };\n\nexport type GenerativeUIState =\n | {\n status: 'ready';\n item: GenerativeUIItem;\n Component: GenuiRenderer;\n props: Record<string, unknown>;\n }\n | { status: 'loading'; item: GenerativeUIItem }\n | ({ status: 'problem' } & GenerativeUIProblem);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA,IAAAA,gBAOO;;;ACPP,mBAA6C;;;ACGtC,IAAMC,uBAAuB;;;ADUpC,SAASC,SAASC,OAAc;AAC9B,SAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,QAAQF,KAAAA;AACvE;AAFSD;AASF,SAASI,mBAAmBC,MAAa;AAC9C,MAAI,CAACL,SAASK,IAAAA,EAAO,QAAO;AAC5B,QAAMC,SAASD,KAAKE,SAAS,aAAaP,SAASK,KAAKG,IAAI,IAAIH,KAAKG,OAAOH;AAC5E,MAAI,OAAOC,OAAOG,cAAc,SAAU,QAAO;AACjD,QAAMC,KACJ,OAAOJ,OAAOI,OAAO,WAAWJ,OAAOI,KAAK,OAAOL,KAAKK,OAAO,WAAWL,KAAKK,KAAK;AACtF,MAAIA,OAAO,KAAM,QAAO;AACxB,SAAO;IACLA;IACAD,WAAWH,OAAOG;IAClBE,OAAOX,SAASM,OAAOK,KAAK,IAAIL,OAAOK,QAAQ,CAAC;IAChDC,SAAS,OAAON,OAAOM,YAAY,WAAWN,OAAOM,UAAU;IAC/DC,YAAY,OAAOP,OAAOO,eAAe,WAAWP,OAAOO,aAAa;EAC1E;AACF;AAdgBT;AA2BhB,IAAMU,iBAAiB,oBAAIC,QAAAA;AAE3B,SAASC,cACPC,SACAC,MACAN,SAAsB;AAEtB,MAAIO,QAAQL,eAAeM,IAAIH,OAAAA;AAC/B,MAAIE,UAA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MxB,OAAAA;AACpC,MAAI7B,UAAU,KAAM,QAAO;AAC3B,MAAIA,MAAMmC,WAAW,UAAW,QAAOC;AACvC,MAAIpC,MAAMmC,WAAW,WAAW;AAC9B,UAAM,EAAEA,QAAQqB,SAAS,GAAG3D,QAAAA,IAAYG;AACxC,WAAOL,eAAeC,UAAUC,OAAAA;EAClC;AACA,QAAMyC,WAAWtC,MAAMD;AACvB,SACE,sBAAA,cAACkD,mBAAAA;IACE,GAAGpB;IACJjC;IACAwC;IACC,GAAI5B,YAAYN,SAAY;MAAEM;IAAQ,IAAI,CAAC;KAE5C,sBAAA,cAACV,cAAAA;IAAaW,MAAMT,MAAMS;IAAMb;IAAoBY;KAClD,sBAAA,cAAC8B,UAAatC,MAAMO,KAAK,CAAA,CAAA;AAIjC;AArCgBgD;","names":["import_react","GENUI_TREE_COMPONENT","isRecord","value","Array","isArray","toGenerativeUIItem","part","source","type","data","component","id","props","version","toolCallId","resolverCaches","WeakMap","resolveCached","resolve","name","cache","get","undefined","Map","set","key","hit","entry","result","Promise","resolution","status","settled","then","Component","error","useResolvedComponent","registry","fallbackTree","setTick","useState","own","pending","useEffect","live","tick","GENUI_TREE_COMPONENT","useValidatedProps","catalog","checked","has","immediate","useMemo","validateSync","ok","issues","late","setLate","validate","path","message","Error","String","useGenerativeUIState","options","item","resolveComponent","empty","validation","reason","TreeScopeContext","createContext","renderFallback","fallback","problem","ItemBoundary","Component","state","error","undefined","failed","getDerivedStateFromError","componentDidCatch","_info","props","onError","item","componentDidUpdate","previous","setState","render","reason","children","nodeItem","node","id","component","type","version","toolCallId","TreeNode","scope","useContext","useMemo","resolution","useResolvedComponent","options","registry","resolveComponent","validation","useValidatedProps","catalog","status","loading","issues","Renderer","Array","isArray","length","map","child","index","childId","key","GenuiTree","root","GenerativeUIScope","Provider","value","useGenerativeUI","part","useGenerativeUIState","GenerativeUI","_status"]}
@@ -0,0 +1,62 @@
1
+ import * as React from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { T as TranscriptUiBlock } from './model-CMNhyau6.cjs';
4
+ import { G as GenerativeUIOptions, a as GenerativeUIItem, b as GenerativeUIProblem, c as GenerativeUIElement, d as GenerativeUIState } from './types-DFD-soWU.cjs';
5
+ export { e as GENUI_TREE_COMPONENT, f as GenuiCatalogLike, g as GenuiIssueLike, h as GenuiRegistry, i as GenuiRenderer, R as ResolveComponent } from './types-DFD-soWU.cjs';
6
+ import '@dudousxd/nestjs-agent-core';
7
+ import 'ai';
8
+
9
+ /** What to draw instead of a component that did not render. Default: nothing. */
10
+ type GenerativeUIFallback = ReactNode | ((problem: GenerativeUIProblem) => ReactNode);
11
+ /**
12
+ * Renders a `genui:tree` frame's `{ root }` node by node through the same registry, catalog and
13
+ * resolver as top-level components. Used automatically for tree frames unless the registry
14
+ * overrides `genui:tree` (e.g. with the json-render adapter).
15
+ */
16
+ declare function GenuiTree({ root }: {
17
+ root?: GenerativeUIElement;
18
+ }): React.JSX.Element | null;
19
+ interface GenerativeUIScopeProps extends GenerativeUIOptions {
20
+ fallback?: GenerativeUIFallback;
21
+ loading?: ReactNode;
22
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
23
+ children?: ReactNode;
24
+ }
25
+ /**
26
+ * The registry, catalog and fallbacks tree nodes render with. `<GenerativeUI>` provides it; wrap
27
+ * your own chrome in it when you draw `useGenerativeUI`'s `Component` yourself and it may be a tree.
28
+ */
29
+ declare function GenerativeUIScope({ registry, catalog, resolveComponent, fallback, loading, onError, children, }: GenerativeUIScopeProps): React.JSX.Element;
30
+ /** The headless half of {@link GenerativeUI}: what to draw for one pushed component, or `null` when `part` is not one. */
31
+ declare function useGenerativeUI(part: unknown, options: GenerativeUIOptions): GenerativeUIState | null;
32
+ interface GenerativeUIProps extends GenerativeUIOptions {
33
+ /** A transcript `ui` block, a `data-ui` message part, or a stored `{ id, component, props, version? }`. */
34
+ part: TranscriptUiBlock | GenerativeUIItem | unknown;
35
+ /** Drawn for an unknown component, invalid props, or a renderer that threw. Default: nothing. */
36
+ fallback?: GenerativeUIFallback;
37
+ /** Drawn while a resolver or an async validation is pending. Default: nothing. */
38
+ loading?: ReactNode;
39
+ /** A renderer threw (the item shows `fallback`). */
40
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
41
+ }
42
+ /**
43
+ * Draws one server-pushed component with the app's own renderer. Headless: it adds no element and
44
+ * no style of its own — only what the registry's component renders (and whatever `fallback` /
45
+ * `loading` you pass).
46
+ *
47
+ * ```tsx
48
+ * <MessageItem message={m} renderUi={(block) => (
49
+ * <GenerativeUI part={block} registry={registry} catalog={catalog} fallback={({ item }) => <Unknown name={item.component} />} />
50
+ * )} />
51
+ * ```
52
+ */
53
+ declare function GenerativeUI({ part, registry, catalog, resolveComponent, fallback, loading, onError, }: 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;
54
+
55
+ /**
56
+ * Normalize whatever carries a pushed component: a transcript `ui` block, a `data-ui` message part
57
+ * (`{ type: 'data-ui', id, data }`), a stored `{ id, component, props, version? }` entry. `null` for
58
+ * anything else.
59
+ */
60
+ declare function toGenerativeUIItem(part: unknown): GenerativeUIItem | null;
61
+
62
+ export { GenerativeUI, GenerativeUIElement, type GenerativeUIFallback, GenerativeUIItem, GenerativeUIOptions, GenerativeUIProblem, type GenerativeUIProps, GenerativeUIScope, type GenerativeUIScopeProps, GenerativeUIState, GenuiTree, toGenerativeUIItem, useGenerativeUI };
@@ -0,0 +1,62 @@
1
+ import * as React from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { T as TranscriptUiBlock } from './model-CMNhyau6.js';
4
+ import { G as GenerativeUIOptions, a as GenerativeUIItem, b as GenerativeUIProblem, c as GenerativeUIElement, d as GenerativeUIState } from './types-DFD-soWU.js';
5
+ export { e as GENUI_TREE_COMPONENT, f as GenuiCatalogLike, g as GenuiIssueLike, h as GenuiRegistry, i as GenuiRenderer, R as ResolveComponent } from './types-DFD-soWU.js';
6
+ import '@dudousxd/nestjs-agent-core';
7
+ import 'ai';
8
+
9
+ /** What to draw instead of a component that did not render. Default: nothing. */
10
+ type GenerativeUIFallback = ReactNode | ((problem: GenerativeUIProblem) => ReactNode);
11
+ /**
12
+ * Renders a `genui:tree` frame's `{ root }` node by node through the same registry, catalog and
13
+ * resolver as top-level components. Used automatically for tree frames unless the registry
14
+ * overrides `genui:tree` (e.g. with the json-render adapter).
15
+ */
16
+ declare function GenuiTree({ root }: {
17
+ root?: GenerativeUIElement;
18
+ }): React.JSX.Element | null;
19
+ interface GenerativeUIScopeProps extends GenerativeUIOptions {
20
+ fallback?: GenerativeUIFallback;
21
+ loading?: ReactNode;
22
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
23
+ children?: ReactNode;
24
+ }
25
+ /**
26
+ * The registry, catalog and fallbacks tree nodes render with. `<GenerativeUI>` provides it; wrap
27
+ * your own chrome in it when you draw `useGenerativeUI`'s `Component` yourself and it may be a tree.
28
+ */
29
+ declare function GenerativeUIScope({ registry, catalog, resolveComponent, fallback, loading, onError, children, }: GenerativeUIScopeProps): React.JSX.Element;
30
+ /** The headless half of {@link GenerativeUI}: what to draw for one pushed component, or `null` when `part` is not one. */
31
+ declare function useGenerativeUI(part: unknown, options: GenerativeUIOptions): GenerativeUIState | null;
32
+ interface GenerativeUIProps extends GenerativeUIOptions {
33
+ /** A transcript `ui` block, a `data-ui` message part, or a stored `{ id, component, props, version? }`. */
34
+ part: TranscriptUiBlock | GenerativeUIItem | unknown;
35
+ /** Drawn for an unknown component, invalid props, or a renderer that threw. Default: nothing. */
36
+ fallback?: GenerativeUIFallback;
37
+ /** Drawn while a resolver or an async validation is pending. Default: nothing. */
38
+ loading?: ReactNode;
39
+ /** A renderer threw (the item shows `fallback`). */
40
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
41
+ }
42
+ /**
43
+ * Draws one server-pushed component with the app's own renderer. Headless: it adds no element and
44
+ * no style of its own — only what the registry's component renders (and whatever `fallback` /
45
+ * `loading` you pass).
46
+ *
47
+ * ```tsx
48
+ * <MessageItem message={m} renderUi={(block) => (
49
+ * <GenerativeUI part={block} registry={registry} catalog={catalog} fallback={({ item }) => <Unknown name={item.component} />} />
50
+ * )} />
51
+ * ```
52
+ */
53
+ declare function GenerativeUI({ part, registry, catalog, resolveComponent, fallback, loading, onError, }: 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;
54
+
55
+ /**
56
+ * Normalize whatever carries a pushed component: a transcript `ui` block, a `data-ui` message part
57
+ * (`{ type: 'data-ui', id, data }`), a stored `{ id, component, props, version? }` entry. `null` for
58
+ * anything else.
59
+ */
60
+ declare function toGenerativeUIItem(part: unknown): GenerativeUIItem | null;
61
+
62
+ export { GenerativeUI, GenerativeUIElement, type GenerativeUIFallback, GenerativeUIItem, GenerativeUIOptions, GenerativeUIProblem, type GenerativeUIProps, GenerativeUIScope, type GenerativeUIScopeProps, GenerativeUIState, GenuiTree, toGenerativeUIItem, useGenerativeUI };