@dudousxd/nestjs-agent-react 0.35.1 → 0.35.3

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 CHANGED
@@ -49,6 +49,39 @@ function sharedContext(key) {
49
49
  }
50
50
  var AmbientRenderUiContext = sharedContext("@dudousxd/nestjs-agent-react:ambient-render-ui");
51
51
 
52
+ // src/genui/share-structure.ts
53
+ function isPlainObject(value) {
54
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
55
+ const prototype = Object.getPrototypeOf(value);
56
+ return prototype === Object.prototype || prototype === null;
57
+ }
58
+ function shareStructure(previous, next) {
59
+ if (Object.is(previous, next)) return next;
60
+ if (Array.isArray(next)) {
61
+ if (!Array.isArray(previous)) return next;
62
+ let same = previous.length === next.length;
63
+ const shared = next.map((value, index) => {
64
+ const kept = shareStructure(previous[index], value);
65
+ if (kept !== previous[index]) same = false;
66
+ return kept;
67
+ });
68
+ return same ? previous : shared;
69
+ }
70
+ if (isPlainObject(next)) {
71
+ if (!isPlainObject(previous)) return next;
72
+ const keys = Object.keys(next);
73
+ let same = keys.length === Object.keys(previous).length;
74
+ const shared = {};
75
+ for (const key of keys) {
76
+ const kept = shareStructure(previous[key], next[key]);
77
+ if (kept !== previous[key] || !Object.hasOwn(previous, key)) same = false;
78
+ shared[key] = kept;
79
+ }
80
+ return same ? previous : shared;
81
+ }
82
+ return next;
83
+ }
84
+
52
85
  // src/genui/use-generative-ui.ts
53
86
  var import_react2 = require("react");
54
87
 
@@ -223,10 +256,10 @@ var GenuiNodeContext = sharedContext(
223
256
  function useGenuiNode() {
224
257
  return (0, import_react3.useContext)(GenuiNodeContext);
225
258
  }
226
- function renderPlaceholder(scope, node) {
227
- const { placeholder } = scope;
259
+ function renderPlaceholder(look, node) {
260
+ const { placeholder } = look;
228
261
  if (typeof placeholder === "function") return placeholder(node);
229
- return placeholder !== void 0 ? placeholder : scope.loading;
262
+ return placeholder !== void 0 ? placeholder : look.loading;
230
263
  }
231
264
  function renderFallback(fallback, problem) {
232
265
  if (typeof fallback === "function") return fallback(problem);
@@ -260,9 +293,33 @@ var ItemBoundary = class extends import_react3.Component {
260
293
  function nodeItem(node, id) {
261
294
  return { id, component: node.type, props: node.props ?? {}, version: null, toolCallId: null };
262
295
  }
263
- function TreeNode({ node, id }) {
296
+ function failsWhole(scope) {
297
+ return !scope.hasFallback && scope.fallbackText !== void 0;
298
+ }
299
+ var TreeNode = (0, import_react3.memo)(
300
+ function TreeNode2({ node, id, bounded }) {
301
+ const scope = (0, import_react3.useContext)(TreeScopeContext);
302
+ const item = (0, import_react3.useMemo)(() => nodeItem(node, id), [node, id]);
303
+ if (scope === null) return null;
304
+ if (!bounded || failsWhole(scope)) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TreeNodeBody, { node, id, item });
305
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
306
+ ItemBoundary,
307
+ {
308
+ item,
309
+ fallback: scope.look.current.fallback,
310
+ onError: scope.look.current.onError,
311
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TreeNodeBody, { node, id, item })
312
+ }
313
+ );
314
+ },
315
+ (previous, next) => previous.node === next.node && previous.id === next.id && previous.bounded === next.bounded
316
+ );
317
+ function TreeNodeBody({
318
+ node,
319
+ id,
320
+ item
321
+ }) {
264
322
  const scope = (0, import_react3.useContext)(TreeScopeContext);
265
- const item = (0, import_react3.useMemo)(() => nodeItem(node, id), [node, id]);
266
323
  const incomplete = node.incomplete === true;
267
324
  const held = node.held === true;
268
325
  const state = (0, import_react3.useMemo)(
@@ -284,45 +341,37 @@ function TreeNode({ node, id }) {
284
341
  item.props
285
342
  );
286
343
  if (scope === null) return null;
344
+ const look = scope.look.current;
287
345
  if (held) {
288
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GenuiNodeContext.Provider, { value: state, children: renderPlaceholder(scope, state) });
346
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GenuiNodeContext.Provider, { value: state, children: renderPlaceholder(look, state) });
289
347
  }
290
- if (resolution.status === "loading" || validation.status === "pending") return scope.loading;
348
+ if (resolution.status === "loading" || validation.status === "pending") return look.loading;
291
349
  if (resolution.status === "unknown") {
292
- if (scope.fallback === void 0 && scope.fallbackText !== void 0)
293
- throw new Error("Unknown tree component");
294
- return renderFallback(scope.fallback, { reason: "unknown", item });
350
+ if (failsWhole(scope)) throw new Error("Unknown tree component");
351
+ return renderFallback(look.fallback, { reason: "unknown", item });
295
352
  }
296
353
  if (resolution.status === "error") {
297
- if (scope.fallback === void 0 && scope.fallbackText !== void 0) throw resolution.error;
298
- return renderFallback(scope.fallback, { reason: "error", item, error: resolution.error });
354
+ if (failsWhole(scope)) throw resolution.error;
355
+ return renderFallback(look.fallback, { reason: "error", item, error: resolution.error });
299
356
  }
300
357
  if (validation.status === "invalid") {
301
- if (scope.fallback === void 0 && scope.fallbackText !== void 0)
302
- throw new Error("Invalid tree component");
303
- return renderFallback(scope.fallback, { reason: "invalid", item, issues: validation.issues });
358
+ if (failsWhole(scope)) throw new Error("Invalid tree component");
359
+ return renderFallback(look.fallback, { reason: "invalid", item, issues: validation.issues });
304
360
  }
305
361
  const Renderer = resolution.Component;
306
362
  const children = Array.isArray(node.children) ? node.children : [];
307
363
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GenuiNodeContext.Provider, { value: state, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Renderer, { ...validation.props, children: children.length > 0 ? children.map((child, index) => {
308
364
  const childId = `${id}.${index}`;
309
- if (scope.fallback === void 0 && scope.fallbackText !== void 0)
310
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TreeNode, { node: child, id: childId }, childId);
311
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
312
- ItemBoundary,
313
- {
314
- item: nodeItem(child, childId),
315
- fallback: scope.fallback,
316
- onError: scope.onError,
317
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TreeNode, { node: child, id: childId })
318
- },
319
- childId
320
- );
365
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TreeNode, { node: child, id: childId, bounded: true }, childId);
321
366
  }) : void 0 }) });
322
367
  }
323
368
  function GenuiTree({ root }) {
324
- if (root === void 0 || root === null || typeof root.type !== "string") return null;
325
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TreeNode, { node: root, id: "root" });
369
+ const previous = (0, import_react3.useRef)(void 0);
370
+ const valid = root !== void 0 && root !== null && typeof root.type === "string";
371
+ const shared = valid ? shareStructure(previous.current, root) : void 0;
372
+ previous.current = shared;
373
+ if (shared === void 0) return null;
374
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TreeNode, { node: shared, id: "root", bounded: false });
326
375
  }
327
376
  function GenerativeUIScope({
328
377
  registry,
@@ -336,6 +385,12 @@ function GenerativeUIScope({
336
385
  onError,
337
386
  children
338
387
  }) {
388
+ const versionsRef = (0, import_react3.useRef)(void 0);
389
+ const versions = shareStructure(versionsRef.current, componentVersions);
390
+ versionsRef.current = versions;
391
+ const look = (0, import_react3.useRef)({ fallback, loading, placeholder, onError });
392
+ look.current = { fallback, loading, placeholder, onError };
393
+ const hasFallback = fallback !== void 0;
339
394
  const scope = (0, import_react3.useMemo)(
340
395
  () => ({
341
396
  options: {
@@ -343,24 +398,12 @@ function GenerativeUIScope({
343
398
  ...catalog !== void 0 ? { catalog } : {},
344
399
  ...resolveComponent !== void 0 ? { resolveComponent } : {}
345
400
  },
346
- fallback,
347
- ...componentVersions !== void 0 ? { componentVersions } : {},
401
+ hasFallback,
402
+ ...versions !== void 0 ? { componentVersions: versions } : {},
348
403
  ...fallbackText !== void 0 ? { fallbackText } : {},
349
- loading,
350
- placeholder,
351
- onError
404
+ look
352
405
  }),
353
- [
354
- registry,
355
- catalog,
356
- resolveComponent,
357
- fallback,
358
- fallbackText,
359
- componentVersions,
360
- loading,
361
- placeholder,
362
- onError
363
- ]
406
+ [registry, catalog, resolveComponent, hasFallback, fallbackText, versions]
364
407
  );
365
408
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TreeScopeContext.Provider, { value: scope, children });
366
409
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/genui/index.ts","../src/genui/generative-ui.tsx","../src/components/ambient-ui.ts","../src/genui/use-generative-ui.ts","../src/genui/types.ts","../src/genui/react-registry.ts"],"sourcesContent":["export {\n GenerativeUI,\n type GenerativeUIFallback,\n type GenerativeUIProps,\n GenerativeUIScope,\n type GenerativeUIScopeProps,\n GenuiProvider,\n type GenuiProviderProps,\n type GenuiProviderValue,\n GenuiTree,\n useGenerativeUI,\n useGenuiNode,\n useGenuiProvider,\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 GenuiNodeState,\n type GenuiPlaceholder,\n type GenuiRegistry,\n type GenuiRenderer,\n type ResolveComponent,\n} from './types.js';\nexport { toGenerativeUIItem } from './use-generative-ui.js';\n\nexport {\n createReactComponentRegistry,\n type ReactComponentRegistry,\n type ReactComponentRenderers,\n} from './react-registry.js';\n","import {\n Component,\n type Context,\n type ErrorInfo,\n type ReactNode,\n createContext,\n useCallback,\n useContext,\n useMemo,\n} from 'react';\nimport { AmbientRenderUiContext, sharedContext } from '../components/ambient-ui.js';\nimport type { TranscriptUiBlock } from '../transcript/model.js';\nimport type {\n GenerativeUIElement,\n GenerativeUIItem,\n GenerativeUIOptions,\n GenerativeUIProblem,\n GenerativeUIState,\n GenuiNodeState,\n GenuiPlaceholder,\n GenuiRegistry,\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 fallbackText?: string;\n componentVersions?: Record<string, number>;\n options: GenerativeUIOptions;\n fallback: GenerativeUIFallback | undefined;\n loading: ReactNode;\n placeholder: GenuiPlaceholder | undefined;\n onError: ((error: unknown, item: GenerativeUIItem) => void) | undefined;\n}\n\nconst TreeScopeContext = createContext<TreeScope | null>(null);\n\n// Shared by key, like the provider's: a renderer imports the hook from `/genui` while the tree may\n// be drawn by the `/genui/json-render` bundle's copy of this module.\nconst GenuiNodeContext: Context<GenuiNodeState | null> = sharedContext<GenuiNodeState>(\n '@dudousxd/nestjs-agent-react:genui-node',\n);\n\n/**\n * The tree node being rendered — read it in a renderer to draw a skeleton while the model is still\n * writing the node (`incomplete`), e.g. a chart's axes before its data. `null` outside a tree.\n *\n * ```tsx\n * function Chart(props: ChartProps) {\n * const node = useGenuiNode();\n * if (node?.incomplete && !props.data?.length) return <ChartSkeleton title={props.title} />;\n * return <BarChart {...props} />;\n * }\n * ```\n */\nexport function useGenuiNode(): GenuiNodeState | null {\n return useContext(GenuiNodeContext);\n}\n\nfunction renderPlaceholder(scope: TreeScope, node: GenuiNodeState): ReactNode {\n const { placeholder } = scope;\n if (typeof placeholder === 'function') return placeholder(node);\n return placeholder !== undefined ? placeholder : scope.loading;\n}\n\nfunction renderFallback(fallback: GenerativeUIFallback | undefined, problem: GenerativeUIProblem) {\n if (typeof fallback === 'function') return fallback(problem);\n if (fallback !== undefined) return fallback;\n return problem.item.fallbackText !== undefined ? (\n <span style={{ whiteSpace: 'pre-wrap' }}>{problem.item.fallbackText}</span>\n ) : 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 // A node of a preview the model is still writing: its props are half there, so they are not\n // validated (the final frame is) — the renderer is told instead, through `useGenuiNode`.\n const incomplete = node.incomplete === true;\n const held = node.held === true;\n const state = useMemo<GenuiNodeState>(\n () => ({ id, type: node.type, incomplete, held }),\n [id, node.type, incomplete, held],\n );\n const storedVersion = scope?.componentVersions?.[node.type];\n const definition = scope?.options.catalog?.get?.(node.type);\n const incompatible =\n storedVersion !== undefined &&\n definition !== undefined &&\n storedVersion !== (definition.version ?? 1);\n const resolution = useResolvedComponent(\n node.type,\n storedVersion ?? null,\n incompatible ? {} : (scope?.options.registry ?? {}),\n scope?.options.resolveComponent,\n );\n const validation = useValidatedProps(\n incompatible || incomplete ? undefined : scope?.options.catalog,\n node.type,\n item.props,\n );\n if (scope === null) return null;\n if (held) {\n return (\n <GenuiNodeContext.Provider value={state}>\n {renderPlaceholder(scope, state)}\n </GenuiNodeContext.Provider>\n );\n }\n if (resolution.status === 'loading' || validation.status === 'pending') return scope.loading;\n if (resolution.status === 'unknown') {\n if (scope.fallback === undefined && scope.fallbackText !== undefined)\n throw new Error('Unknown tree component');\n return renderFallback(scope.fallback, { reason: 'unknown', item });\n }\n if (resolution.status === 'error') {\n if (scope.fallback === undefined && scope.fallbackText !== undefined) throw resolution.error;\n return renderFallback(scope.fallback, { reason: 'error', item, error: resolution.error });\n }\n if (validation.status === 'invalid') {\n if (scope.fallback === undefined && scope.fallbackText !== undefined)\n throw new Error('Invalid tree component');\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 <GenuiNodeContext.Provider value={state}>\n <Renderer {...validation.props}>\n {children.length > 0\n ? children.map((child, index) => {\n const childId = `${id}.${index}`;\n if (scope.fallback === undefined && scope.fallbackText !== undefined)\n return <TreeNode key={childId} node={child} id={childId} />;\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 </GenuiNodeContext.Provider>\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 a `treeRenderer`\n * (e.g. the json-render one) or a registry entry for `genui:tree` takes over.\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 fallbackText?: string;\n componentVersions?: Record<string, number>;\n fallback?: GenerativeUIFallback;\n loading?: ReactNode;\n /** Drawn for a tree node held back while the model writes it. Default: `loading`. */\n placeholder?: GenuiPlaceholder;\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 fallbackText,\n componentVersions,\n loading = null,\n placeholder,\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 ...(componentVersions !== undefined ? { componentVersions } : {}),\n ...(fallbackText !== undefined ? { fallbackText } : {}),\n loading,\n placeholder,\n onError,\n }),\n [\n registry,\n catalog,\n resolveComponent,\n fallback,\n fallbackText,\n componentVersions,\n loading,\n placeholder,\n onError,\n ],\n );\n return <TreeScopeContext.Provider value={scope}>{children}</TreeScopeContext.Provider>;\n}\n\n/** What `<GenuiProvider>` hands every `<GenerativeUI>` / `useGenerativeUI` below it. */\nexport interface GenuiProviderValue extends Partial<GenerativeUIOptions> {\n fallback?: GenerativeUIFallback;\n loading?: ReactNode;\n /** Drawn for a tree node held back while the model writes it (`streaming: 'complete'`). */\n placeholder?: GenuiPlaceholder;\n onError?: (error: unknown, item: GenerativeUIItem) => void;\n}\n\n// Shared by key: `/genui` and `/genui/json-render` are separate bundles, and a provider from one\n// must reach a `<GenerativeUI>` from the other.\nconst GenuiContext: Context<GenuiProviderValue | null> = sharedContext<GenuiProviderValue>(\n '@dudousxd/nestjs-agent-react:genui-provider',\n);\n\n/** The enclosing `<GenuiProvider>`'s settings, or `null` outside one. */\nexport function useGenuiProvider(): GenuiProviderValue | null {\n return useContext(GenuiContext);\n}\n\nexport interface GenuiProviderProps extends GenuiProviderValue {\n children?: ReactNode;\n}\n\n/**\n * Set generative UI up once, at the app root: the registry of your renderers, the catalog to\n * validate against, a resolver for components the registry lacks, and what to draw when one does\n * not render. Every `<GenerativeUI>` below reads it (its own props still win), and `MessageItem` /\n * `MessageList` draw pushed components with it — no `renderUi` per message.\n *\n * ```tsx\n * <GenuiProvider registry={registry} catalog={catalog} fallback={({ item }) => <Unknown name={item.component} />}>\n * <App />\n * </GenuiProvider>\n * ```\n */\nexport function GenuiProvider({\n registry,\n catalog,\n resolveComponent,\n treeRenderer,\n fallback,\n loading,\n placeholder,\n onError,\n children,\n}: GenuiProviderProps) {\n const value = useMemo<GenuiProviderValue>(\n () => ({\n ...(registry !== undefined ? { registry } : {}),\n ...(catalog !== undefined ? { catalog } : {}),\n ...(resolveComponent !== undefined ? { resolveComponent } : {}),\n ...(treeRenderer !== undefined ? { treeRenderer } : {}),\n ...(fallback !== undefined ? { fallback } : {}),\n ...(loading !== undefined ? { loading } : {}),\n ...(placeholder !== undefined ? { placeholder } : {}),\n ...(onError !== undefined ? { onError } : {}),\n }),\n [registry, catalog, resolveComponent, treeRenderer, fallback, loading, placeholder, onError],\n );\n const renderUi = useCallback((block: TranscriptUiBlock) => <GenerativeUI part={block} />, []);\n return (\n <GenuiContext.Provider value={value}>\n <AmbientRenderUiContext.Provider value={renderUi}>{children}</AmbientRenderUiContext.Provider>\n </GenuiContext.Provider>\n );\n}\n\nconst NO_REGISTRY: GenuiRegistry = {};\n\n/** Provider settings overlaid with explicit ones (explicit wins), memoized on their parts. */\nfunction useMergedOptions(own: Partial<GenerativeUIOptions>): GenerativeUIOptions {\n const provided = useContext(GenuiContext);\n const registry = own.registry ?? provided?.registry ?? NO_REGISTRY;\n const catalog = own.catalog ?? provided?.catalog;\n const resolveComponent = own.resolveComponent ?? provided?.resolveComponent;\n const treeRenderer = own.treeRenderer ?? provided?.treeRenderer;\n return useMemo(\n () => ({\n registry,\n ...(catalog !== undefined ? { catalog } : {}),\n ...(resolveComponent !== undefined ? { resolveComponent } : {}),\n ...(treeRenderer !== undefined ? { treeRenderer } : {}),\n }),\n [registry, catalog, resolveComponent, treeRenderer],\n );\n}\n\n/**\n * The headless half of {@link GenerativeUI}: what to draw for one pushed component, or `null` when\n * `part` is not one. Options default to the enclosing `<GenuiProvider>`'s.\n */\nexport function useGenerativeUI(\n part: unknown,\n options: Partial<GenerativeUIOptions> = {},\n): GenerativeUIState | null {\n const merged = useMergedOptions(options);\n return useGenerativeUIState(part, merged, merged.treeRenderer ?? (GenuiTree as GenuiRenderer));\n}\n\nexport interface GenerativeUIProps extends Partial<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: the provider's, then the item's persisted text. */\n fallback?: GenerativeUIFallback;\n /** Drawn while a resolver or an async validation is pending. Default: the provider's, else nothing. */\n loading?: ReactNode;\n /**\n * Drawn for a tree node held back while the model writes it (its component streams `complete`).\n * Default: the provider's, else `loading`.\n */\n placeholder?: GenuiPlaceholder;\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). Everything but `part` defaults to the enclosing `<GenuiProvider>`.\n *\n * ```tsx\n * <GenerativeUI part={block} />\n * ```\n */\nexport function GenerativeUI({\n part,\n registry,\n catalog,\n resolveComponent,\n treeRenderer,\n fallback: ownFallback,\n loading: ownLoading,\n placeholder: ownPlaceholder,\n onError: ownOnError,\n}: GenerativeUIProps) {\n const provided = useContext(GenuiContext);\n const fallback = ownFallback !== undefined ? ownFallback : provided?.fallback;\n const loading = ownLoading ?? provided?.loading ?? null;\n const placeholder = ownPlaceholder !== undefined ? ownPlaceholder : provided?.placeholder;\n const onError = ownOnError ?? provided?.onError;\n const options = useMergedOptions({\n ...(registry !== undefined ? { registry } : {}),\n ...(catalog !== undefined ? { catalog } : {}),\n ...(resolveComponent !== undefined ? { resolveComponent } : {}),\n ...(treeRenderer !== undefined ? { treeRenderer } : {}),\n });\n const state = useGenerativeUIState(\n part,\n options,\n options.treeRenderer ?? (GenuiTree as GenuiRenderer),\n );\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 {...(state.item.componentVersions !== undefined\n ? { componentVersions: state.item.componentVersions }\n : {})}\n {...(state.item.fallbackText !== undefined ? { fallbackText: state.item.fallbackText } : {})}\n fallback={fallback}\n loading={loading}\n {...(placeholder !== undefined ? { placeholder } : {})}\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 { type Context, type ReactNode, createContext, useContext } from 'react';\nimport type { TranscriptUiBlock } from '../transcript/model.js';\n\n/** Draws a server-pushed component block. */\nexport type AmbientRenderUi = (block: TranscriptUiBlock) => ReactNode;\n\n/**\n * A context stored on `globalThis` under a registered symbol. Each entry point (`.`, `/genui`,\n * `/genui/json-render`) is its own bundle with its own copy of every module, so a context one entry\n * provides and another reads has to be found by key, not by module identity.\n */\nexport function sharedContext<T>(key: string): Context<T | null> {\n const symbol = Symbol.for(key);\n const holder = globalThis as Record<symbol, Context<T | null> | undefined>;\n const existing = holder[symbol];\n if (existing !== undefined) return existing;\n const created = createContext<T | null>(null);\n holder[symbol] = created;\n return created;\n}\n\n/**\n * How pushed components are drawn when no `renderUi` is passed — set by `<GenuiProvider>` (the\n * `/genui` subpath) and read by `MessageItem`.\n */\nexport const AmbientRenderUiContext: Context<AmbientRenderUi | null> =\n sharedContext<AmbientRenderUi>('@dudousxd/nestjs-agent-react:ambient-render-ui');\n\n/**\n * The renderer `<GenuiProvider>` installed for pushed components, or `null` outside one. For a\n * custom transcript built on `useTranscriptItem`: draw a `ui` block with it and you get what\n * `MessageItem` draws.\n */\nexport function useAmbientRenderUi(): AmbientRenderUi | null {\n return useContext(AmbientRenderUiContext);\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 ...(isRecord(source.componentVersions) &&\n Object.values(source.componentVersions).every(\n (version) => typeof version === 'number' && Number.isSafeInteger(version) && version > 0,\n )\n ? { componentVersions: { ...source.componentVersions } as Record<string, number> }\n : {}),\n ...(typeof source.fallbackText === 'string' ? { fallbackText: source.fallbackText } : {}),\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 ...(source.partial === true ? { partial: true as const } : {}),\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 definition = options.catalog?.get?.(name);\n const incompatible =\n item?.fallbackText !== undefined &&\n item.version !== null &&\n definition !== undefined &&\n item.version !== (definition.version ?? 1);\n const resolution = useResolvedComponent(\n name,\n item?.version ?? null,\n incompatible ? {} : 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 || incompatible ? undefined : options.catalog,\n name,\n item?.props ?? empty,\n );\n if (item === null) return null;\n // A withdrawn preview (partial, nothing to draw): the call will not replace it.\n if (item.partial === true && Object.keys(item.props).length === 0) return null;\n if (\n name === GENUI_TREE_COMPONENT &&\n item.fallbackText !== undefined &&\n (!isRecord(item.props.root) || typeof item.props.root.type !== 'string')\n )\n return {\n status: 'problem',\n reason: 'invalid',\n item,\n issues: [{ path: ['root'], message: 'Invalid UI tree root' }],\n };\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 (`GENUI_TREE_COMPONENT` of `@dudousxd/nestjs-agent-core/genui`). */\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 fallbackText?: string;\n componentVersions?: Record<string, number>;\n id: string;\n component: string;\n props: Record<string, unknown>;\n version: number | null;\n toolCallId: string | null;\n /**\n * A preview drawn while the model is still writing the call (genui `streaming: 'partial'`):\n * unvalidated, and replaced in place by the final frame under the same `id`.\n */\n partial?: true;\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 * The node's position (`root`, `root.0`, `root.0.2`), carried by partial frames. Stable as the\n * tree grows, and the same rule names the final tree's nodes.\n */\n id?: string;\n /** Partial frames only: the model has not finished writing this node. */\n incomplete?: true;\n /** Partial frames only: a `streaming: 'complete'` component held back until it closes (no props). */\n held?: true;\n}\n\n/**\n * What a tree node's renderer can learn about its node ({@link useGenuiNode}): which node it is,\n * and whether the model is still writing it. Room is left for more states (data a node is bound\n * to, loading) as separate fields — `incomplete` only ever means \"still being written\".\n */\nexport interface GenuiNodeState {\n /** The node's position id (`root`, `root.1.0`): stable from the first preview to the final frame. */\n id: string;\n type: string;\n /** The model has not finished writing this node: props (and children) may still grow. */\n incomplete: boolean;\n /** The node is a placeholder for a component that is only drawn whole (`streaming: 'complete'`). */\n held: boolean;\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 `Catalog` from\n * `@dudousxd/nestjs-agent-core/genui` satisfies it; declared structurally so any catalog-shaped\n * object does too.\n */\nexport interface GenuiCatalogLike {\n get?(name: string): { version?: number } | undefined;\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 * Draws a composed tree frame (`genui:tree`) whole — e.g. through json-render (see the\n * `/genui/json-render` subpath's `GenuiProvider`). Omitted → trees render node by node through\n * `registry`.\n */\n treeRenderer?: GenuiRenderer<{ root?: GenerativeUIElement }>;\n}\n\n/**\n * Drawn in place of a tree node that is not drawable yet — a `held` node (its component streams\n * `complete`) while the model writes it. Default: the `loading` element.\n */\nexport type GenuiPlaceholder = ReactNode | ((node: GenuiNodeState) => ReactNode);\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","import {\n type CatalogOptions,\n type ComponentDefinition,\n type ComponentPresentation,\n createComponentRegistry,\n} from '@dudousxd/nestjs-agent-core/genui';\nimport { type ComponentType, type ReactNode, createElement } from 'react';\nimport type { GenuiRegistry } from './types.js';\n\nexport interface ReactComponentRenderers<P extends object> {\n react?: ComponentType<P>;\n text?: (props: P) => string | Promise<string>;\n /** Return each page's complete props. Each page is validated again before SSR. */\n paginate?: (props: P, rowsPerPage: number) => readonly P[] | Promise<readonly P[]>;\n}\n\n/** App-scoped registry shared by GenuiProvider and static server rendering. */\nexport function createReactComponentRegistry(options?: CatalogOptions) {\n const registry = createComponentRegistry(options);\n const components: GenuiRegistry = Object.create(null);\n const texts = new Map<string, (props: Record<string, unknown>) => string | Promise<string>>();\n const paginators = new Map<\n string,\n (props: Record<string, unknown>, size: number) => Promise<readonly Record<string, unknown>[]>\n >();\n const adapter = {\n get catalog() {\n return registry.catalog;\n },\n get manifest() {\n return registry.manifest;\n },\n get components(): GenuiRegistry {\n return { ...components };\n },\n prepare: (presentation: ComponentPresentation<object>) =>\n registry.prepare({ ...presentation, props: presentation.props as Record<string, unknown> }),\n render: (presentation: ComponentPresentation<object>, channel: string) =>\n registry.render(\n { ...presentation, props: presentation.props as Record<string, unknown> },\n channel,\n ),\n register<P extends object>(\n definition: ComponentDefinition<P>,\n renderers: ReactComponentRenderers<P>,\n ) {\n const ReactComponent = renderers.react;\n registry.register(definition, {\n ...(ReactComponent ? { react: (props: P) => createElement(ReactComponent, props) } : {}),\n ...(renderers.text ? { text: renderers.text } : {}),\n });\n if (renderers.react) components[definition.name] = renderers.react;\n if (renderers.text) {\n const text = renderers.text;\n texts.set(definition.name, (props) => text(props as P));\n }\n if (renderers.paginate) {\n const paginate = renderers.paginate;\n paginators.set(\n definition.name,\n async (props, size) =>\n (await paginate(props as P, size)) as readonly Record<string, unknown>[],\n );\n }\n return adapter;\n },\n async renderPages(\n presentation: ComponentPresentation<object>,\n size: number,\n ): Promise<ReactNode[]> {\n const pages = await adapter.paginate(presentation, size);\n return Promise.all(\n pages.map(async (page) => {\n const ReactComponent = components[page.component];\n if (ReactComponent) return createElement(ReactComponent, page.props);\n return texts.get(page.component)?.(page.props) ?? page.fallbackText;\n }),\n );\n },\n async paginate(\n presentation: ComponentPresentation<object>,\n size: number,\n ): Promise<ComponentPresentation[]> {\n if (!Number.isInteger(size) || size < 1 || size > 500)\n throw new RangeError('genui: rowsPerPage must be 1–500');\n const prepared = await registry.prepare({\n ...presentation,\n props: presentation.props as Record<string, unknown>,\n });\n const custom = paginators.get(prepared.component);\n const rows = prepared.props.rows;\n const pages = custom\n ? await custom(prepared.props, size)\n : prepared.component === 'DataTable' && Array.isArray(rows) && rows.length > size\n ? Array.from({ length: Math.ceil(rows.length / size) }, (_, index) => ({\n ...prepared.props,\n rows: rows.slice(index * size, (index + 1) * size),\n }))\n : [prepared.props];\n if (!pages.length || pages.length > 100)\n throw new RangeError('genui: capture requires 1–100 pages');\n return Promise.all(pages.map((props) => registry.prepare({ ...prepared, props })));\n },\n };\n return adapter;\n}\nexport type ReactComponentRegistry = ReturnType<typeof createReactComponentRegistry>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBASO;;;ACTP,mBAAwE;AAWjE,SAAS,cAAiB,KAAgC;AAC/D,QAAM,SAAS,OAAO,IAAI,GAAG;AAC7B,QAAM,SAAS;AACf,QAAM,WAAW,OAAO,MAAM;AA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;AAAA,QACtC,GAAG;AAAA,QACH,OAAO,aAAa;AAAA,MACtB,CAAC;AACD,YAAM,SAAS,WAAW,IAAI,SAAS,SAAS;AAChD,YAAM,OAAO,SAAS,MAAM;AAC5B,YAAM,QAAQ,SACV,MAAM,OAAO,SAAS,OAAO,IAAI,IACjC,SAAS,cAAc,eAAe,MAAM,QAAQ,IAAI,KAAK,KAAK,SAAS,OACzE,MAAM,KAAK,EAAE,QAAQ,KAAK,KAAK,KAAK,SAAS,IAAI,EAAE,GAAG,CAAC,GAAG,WAAW;AAAA,QACnE,GAAG,SAAS;AAAA,QACZ,MAAM,KAAK,MAAM,QAAQ,OAAO,QAAQ,KAAK,IAAI;AAAA,MACnD,EAAE,IACF,CAAC,SAAS,KAAK;AACrB,UAAI,CAAC,MAAM,UAAU,MAAM,SAAS;AAClC,cAAM,IAAI,WAAW,0CAAqC;AAC5D,aAAO,QAAQ,IAAI,MAAM,IAAI,CAAC,UAAU,SAAS,QAAQ,EAAE,GAAG,UAAU,MAAM,CAAC,CAAC,CAAC;AAAA,IACnF;AAAA,EACF;AACA,SAAO;AACT;","names":["import_react","import_react","Component","import_react"]}
1
+ {"version":3,"sources":["../src/genui/index.ts","../src/genui/generative-ui.tsx","../src/components/ambient-ui.ts","../src/genui/share-structure.ts","../src/genui/use-generative-ui.ts","../src/genui/types.ts","../src/genui/react-registry.ts"],"sourcesContent":["export {\n GenerativeUI,\n type GenerativeUIFallback,\n type GenerativeUIProps,\n GenerativeUIScope,\n type GenerativeUIScopeProps,\n GenuiProvider,\n type GenuiProviderProps,\n type GenuiProviderValue,\n GenuiTree,\n useGenerativeUI,\n useGenuiNode,\n useGenuiProvider,\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 GenuiNodeState,\n type GenuiPlaceholder,\n type GenuiRegistry,\n type GenuiRenderer,\n type ResolveComponent,\n} from './types.js';\nexport { toGenerativeUIItem } from './use-generative-ui.js';\n\nexport {\n createReactComponentRegistry,\n type ReactComponentRegistry,\n type ReactComponentRenderers,\n} from './react-registry.js';\n","import {\n Component,\n type Context,\n type ErrorInfo,\n type ReactNode,\n createContext,\n memo,\n useCallback,\n useContext,\n useMemo,\n useRef,\n} from 'react';\nimport { AmbientRenderUiContext, sharedContext } from '../components/ambient-ui.js';\nimport type { TranscriptUiBlock } from '../transcript/model.js';\nimport { shareStructure } from './share-structure.js';\nimport type {\n GenerativeUIElement,\n GenerativeUIItem,\n GenerativeUIOptions,\n GenerativeUIProblem,\n GenerativeUIState,\n GenuiNodeState,\n GenuiPlaceholder,\n GenuiRegistry,\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\n/** How a tree draws what is not a node: read when a node renders, never a reason to re-render one. */\ninterface TreeLook {\n fallback: GenerativeUIFallback | undefined;\n loading: ReactNode;\n placeholder: GenuiPlaceholder | undefined;\n onError: ((error: unknown, item: GenerativeUIItem) => void) | undefined;\n}\n\ninterface TreeScope {\n fallbackText?: string;\n componentVersions?: Record<string, number>;\n options: GenerativeUIOptions;\n /** A fallback was given: a failing node draws it rather than failing the whole tree. */\n hasFallback: boolean;\n /**\n * The latest fallback, loading, placeholder and onError. Behind a ref so an inline element or\n * callback from a host that re-renders on every token does not re-render every node with it.\n */\n look: { readonly current: TreeLook };\n}\n\nconst TreeScopeContext = createContext<TreeScope | null>(null);\n\n// Shared by key, like the provider's: a renderer imports the hook from `/genui` while the tree may\n// be drawn by the `/genui/json-render` bundle's copy of this module.\nconst GenuiNodeContext: Context<GenuiNodeState | null> = sharedContext<GenuiNodeState>(\n '@dudousxd/nestjs-agent-react:genui-node',\n);\n\n/**\n * The tree node being rendered — read it in a renderer to draw a skeleton while the model is still\n * writing the node (`incomplete`), e.g. a chart's axes before its data. `null` outside a tree.\n *\n * ```tsx\n * function Chart(props: ChartProps) {\n * const node = useGenuiNode();\n * if (node?.incomplete && !props.data?.length) return <ChartSkeleton title={props.title} />;\n * return <BarChart {...props} />;\n * }\n * ```\n */\nexport function useGenuiNode(): GenuiNodeState | null {\n return useContext(GenuiNodeContext);\n}\n\nfunction renderPlaceholder(look: TreeLook, node: GenuiNodeState): ReactNode {\n const { placeholder } = look;\n if (typeof placeholder === 'function') return placeholder(node);\n return placeholder !== undefined ? placeholder : look.loading;\n}\n\nfunction renderFallback(fallback: GenerativeUIFallback | undefined, problem: GenerativeUIProblem) {\n if (typeof fallback === 'function') return fallback(problem);\n if (fallback !== undefined) return fallback;\n return problem.item.fallbackText !== undefined ? (\n <span style={{ whiteSpace: 'pre-wrap' }}>{problem.item.fallbackText}</span>\n ) : 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/** A failing node takes the whole tree to the item's fallback text — no fallback of its own given. */\nfunction failsWhole(scope: TreeScope): boolean {\n return !scope.hasFallback && scope.fallbackText !== undefined;\n}\n\ninterface TreeNodeProps {\n node: GenerativeUIElement;\n id: string;\n /** Wrap the node in its own error boundary (every node but the root, which its item's has). */\n bounded: boolean;\n}\n\n/**\n * One tree node, re-rendered only when its node is a different object (or the scope changed).\n * {@link GenuiTree} keeps an unchanged node the same object from frame to frame, so as a preview\n * streams in only the nodes that grew — and their ancestors — render again; a node turning from\n * `incomplete`/`held` to final is a changed node and renders.\n */\nconst TreeNode = memo(\n function TreeNode({ node, id, bounded }: TreeNodeProps) {\n const scope = useContext(TreeScopeContext);\n const item = useMemo(() => nodeItem(node, id), [node, id]);\n if (scope === null) return null;\n if (!bounded || failsWhole(scope)) return <TreeNodeBody node={node} id={id} item={item} />;\n return (\n <ItemBoundary\n item={item}\n fallback={scope.look.current.fallback}\n onError={scope.look.current.onError}\n >\n <TreeNodeBody node={node} id={id} item={item} />\n </ItemBoundary>\n );\n },\n (previous, next) =>\n previous.node === next.node && previous.id === next.id && previous.bounded === next.bounded,\n);\n\n/** A tree node resolved and validated like a top-level item, children rendered as its `children`. */\nfunction TreeNodeBody({\n node,\n id,\n item,\n}: {\n node: GenerativeUIElement;\n id: string;\n item: GenerativeUIItem;\n}) {\n const scope = useContext(TreeScopeContext);\n // A node of a preview the model is still writing: its props are half there, so they are not\n // validated (the final frame is) — the renderer is told instead, through `useGenuiNode`.\n const incomplete = node.incomplete === true;\n const held = node.held === true;\n const state = useMemo<GenuiNodeState>(\n () => ({ id, type: node.type, incomplete, held }),\n [id, node.type, incomplete, held],\n );\n const storedVersion = scope?.componentVersions?.[node.type];\n const definition = scope?.options.catalog?.get?.(node.type);\n const incompatible =\n storedVersion !== undefined &&\n definition !== undefined &&\n storedVersion !== (definition.version ?? 1);\n const resolution = useResolvedComponent(\n node.type,\n storedVersion ?? null,\n incompatible ? {} : (scope?.options.registry ?? {}),\n scope?.options.resolveComponent,\n );\n const validation = useValidatedProps(\n incompatible || incomplete ? undefined : scope?.options.catalog,\n node.type,\n item.props,\n );\n if (scope === null) return null;\n const look = scope.look.current;\n if (held) {\n return (\n <GenuiNodeContext.Provider value={state}>\n {renderPlaceholder(look, state)}\n </GenuiNodeContext.Provider>\n );\n }\n if (resolution.status === 'loading' || validation.status === 'pending') return look.loading;\n if (resolution.status === 'unknown') {\n if (failsWhole(scope)) throw new Error('Unknown tree component');\n return renderFallback(look.fallback, { reason: 'unknown', item });\n }\n if (resolution.status === 'error') {\n if (failsWhole(scope)) throw resolution.error;\n return renderFallback(look.fallback, { reason: 'error', item, error: resolution.error });\n }\n if (validation.status === 'invalid') {\n if (failsWhole(scope)) throw new Error('Invalid tree component');\n return renderFallback(look.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 <GenuiNodeContext.Provider value={state}>\n <Renderer {...validation.props}>\n {children.length > 0\n ? children.map((child, index) => {\n const childId = `${id}.${index}`;\n return <TreeNode key={childId} node={child} id={childId} bounded />;\n })\n : undefined}\n </Renderer>\n </GenuiNodeContext.Provider>\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 a `treeRenderer`\n * (e.g. the json-render one) or a registry entry for `genui:tree` takes over.\n *\n * Each frame's tree is structurally shared with the previous one: a node equal to the one before\n * keeps that object, and its renderer does not run again.\n */\nexport function GenuiTree({ root }: { root?: GenerativeUIElement }) {\n const previous = useRef<GenerativeUIElement | undefined>(undefined);\n const valid = root !== undefined && root !== null && typeof root.type === 'string';\n const shared = valid ? shareStructure(previous.current, root) : undefined;\n previous.current = shared;\n if (shared === undefined) return null;\n return <TreeNode node={shared} id=\"root\" bounded={false} />;\n}\n\nexport interface GenerativeUIScopeProps extends GenerativeUIOptions {\n fallbackText?: string;\n componentVersions?: Record<string, number>;\n fallback?: GenerativeUIFallback;\n loading?: ReactNode;\n /** Drawn for a tree node held back while the model writes it. Default: `loading`. */\n placeholder?: GenuiPlaceholder;\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 fallbackText,\n componentVersions,\n loading = null,\n placeholder,\n onError,\n children,\n}: GenerativeUIScopeProps) {\n // Read afresh from every frame of the item that carries them: kept the same object while equal.\n const versionsRef = useRef<Record<string, number> | undefined>(undefined);\n const versions = shareStructure(versionsRef.current, componentVersions);\n versionsRef.current = versions;\n const look = useRef<TreeLook>({ fallback, loading, placeholder, onError });\n look.current = { fallback, loading, placeholder, onError };\n const hasFallback = fallback !== undefined;\n const scope = useMemo<TreeScope>(\n () => ({\n options: {\n registry,\n ...(catalog !== undefined ? { catalog } : {}),\n ...(resolveComponent !== undefined ? { resolveComponent } : {}),\n },\n hasFallback,\n ...(versions !== undefined ? { componentVersions: versions } : {}),\n ...(fallbackText !== undefined ? { fallbackText } : {}),\n look,\n }),\n [registry, catalog, resolveComponent, hasFallback, fallbackText, versions],\n );\n return <TreeScopeContext.Provider value={scope}>{children}</TreeScopeContext.Provider>;\n}\n\n/** What `<GenuiProvider>` hands every `<GenerativeUI>` / `useGenerativeUI` below it. */\nexport interface GenuiProviderValue extends Partial<GenerativeUIOptions> {\n fallback?: GenerativeUIFallback;\n loading?: ReactNode;\n /** Drawn for a tree node held back while the model writes it (`streaming: 'complete'`). */\n placeholder?: GenuiPlaceholder;\n onError?: (error: unknown, item: GenerativeUIItem) => void;\n}\n\n// Shared by key: `/genui` and `/genui/json-render` are separate bundles, and a provider from one\n// must reach a `<GenerativeUI>` from the other.\nconst GenuiContext: Context<GenuiProviderValue | null> = sharedContext<GenuiProviderValue>(\n '@dudousxd/nestjs-agent-react:genui-provider',\n);\n\n/** The enclosing `<GenuiProvider>`'s settings, or `null` outside one. */\nexport function useGenuiProvider(): GenuiProviderValue | null {\n return useContext(GenuiContext);\n}\n\nexport interface GenuiProviderProps extends GenuiProviderValue {\n children?: ReactNode;\n}\n\n/**\n * Set generative UI up once, at the app root: the registry of your renderers, the catalog to\n * validate against, a resolver for components the registry lacks, and what to draw when one does\n * not render. Every `<GenerativeUI>` below reads it (its own props still win), and `MessageItem` /\n * `MessageList` draw pushed components with it — no `renderUi` per message.\n *\n * ```tsx\n * <GenuiProvider registry={registry} catalog={catalog} fallback={({ item }) => <Unknown name={item.component} />}>\n * <App />\n * </GenuiProvider>\n * ```\n */\nexport function GenuiProvider({\n registry,\n catalog,\n resolveComponent,\n treeRenderer,\n fallback,\n loading,\n placeholder,\n onError,\n children,\n}: GenuiProviderProps) {\n const value = useMemo<GenuiProviderValue>(\n () => ({\n ...(registry !== undefined ? { registry } : {}),\n ...(catalog !== undefined ? { catalog } : {}),\n ...(resolveComponent !== undefined ? { resolveComponent } : {}),\n ...(treeRenderer !== undefined ? { treeRenderer } : {}),\n ...(fallback !== undefined ? { fallback } : {}),\n ...(loading !== undefined ? { loading } : {}),\n ...(placeholder !== undefined ? { placeholder } : {}),\n ...(onError !== undefined ? { onError } : {}),\n }),\n [registry, catalog, resolveComponent, treeRenderer, fallback, loading, placeholder, onError],\n );\n const renderUi = useCallback((block: TranscriptUiBlock) => <GenerativeUI part={block} />, []);\n return (\n <GenuiContext.Provider value={value}>\n <AmbientRenderUiContext.Provider value={renderUi}>{children}</AmbientRenderUiContext.Provider>\n </GenuiContext.Provider>\n );\n}\n\nconst NO_REGISTRY: GenuiRegistry = {};\n\n/** Provider settings overlaid with explicit ones (explicit wins), memoized on their parts. */\nfunction useMergedOptions(own: Partial<GenerativeUIOptions>): GenerativeUIOptions {\n const provided = useContext(GenuiContext);\n const registry = own.registry ?? provided?.registry ?? NO_REGISTRY;\n const catalog = own.catalog ?? provided?.catalog;\n const resolveComponent = own.resolveComponent ?? provided?.resolveComponent;\n const treeRenderer = own.treeRenderer ?? provided?.treeRenderer;\n return useMemo(\n () => ({\n registry,\n ...(catalog !== undefined ? { catalog } : {}),\n ...(resolveComponent !== undefined ? { resolveComponent } : {}),\n ...(treeRenderer !== undefined ? { treeRenderer } : {}),\n }),\n [registry, catalog, resolveComponent, treeRenderer],\n );\n}\n\n/**\n * The headless half of {@link GenerativeUI}: what to draw for one pushed component, or `null` when\n * `part` is not one. Options default to the enclosing `<GenuiProvider>`'s.\n */\nexport function useGenerativeUI(\n part: unknown,\n options: Partial<GenerativeUIOptions> = {},\n): GenerativeUIState | null {\n const merged = useMergedOptions(options);\n return useGenerativeUIState(part, merged, merged.treeRenderer ?? (GenuiTree as GenuiRenderer));\n}\n\nexport interface GenerativeUIProps extends Partial<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: the provider's, then the item's persisted text. */\n fallback?: GenerativeUIFallback;\n /** Drawn while a resolver or an async validation is pending. Default: the provider's, else nothing. */\n loading?: ReactNode;\n /**\n * Drawn for a tree node held back while the model writes it (its component streams `complete`).\n * Default: the provider's, else `loading`.\n */\n placeholder?: GenuiPlaceholder;\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). Everything but `part` defaults to the enclosing `<GenuiProvider>`.\n *\n * ```tsx\n * <GenerativeUI part={block} />\n * ```\n */\nexport function GenerativeUI({\n part,\n registry,\n catalog,\n resolveComponent,\n treeRenderer,\n fallback: ownFallback,\n loading: ownLoading,\n placeholder: ownPlaceholder,\n onError: ownOnError,\n}: GenerativeUIProps) {\n const provided = useContext(GenuiContext);\n const fallback = ownFallback !== undefined ? ownFallback : provided?.fallback;\n const loading = ownLoading ?? provided?.loading ?? null;\n const placeholder = ownPlaceholder !== undefined ? ownPlaceholder : provided?.placeholder;\n const onError = ownOnError ?? provided?.onError;\n const options = useMergedOptions({\n ...(registry !== undefined ? { registry } : {}),\n ...(catalog !== undefined ? { catalog } : {}),\n ...(resolveComponent !== undefined ? { resolveComponent } : {}),\n ...(treeRenderer !== undefined ? { treeRenderer } : {}),\n });\n const state = useGenerativeUIState(\n part,\n options,\n options.treeRenderer ?? (GenuiTree as GenuiRenderer),\n );\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 {...(state.item.componentVersions !== undefined\n ? { componentVersions: state.item.componentVersions }\n : {})}\n {...(state.item.fallbackText !== undefined ? { fallbackText: state.item.fallbackText } : {})}\n fallback={fallback}\n loading={loading}\n {...(placeholder !== undefined ? { placeholder } : {})}\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 { type Context, type ReactNode, createContext, useContext } from 'react';\nimport type { TranscriptUiBlock } from '../transcript/model.js';\n\n/** Draws a server-pushed component block. */\nexport type AmbientRenderUi = (block: TranscriptUiBlock) => ReactNode;\n\n/**\n * A context stored on `globalThis` under a registered symbol. Each entry point (`.`, `/genui`,\n * `/genui/json-render`) is its own bundle with its own copy of every module, so a context one entry\n * provides and another reads has to be found by key, not by module identity.\n */\nexport function sharedContext<T>(key: string): Context<T | null> {\n const symbol = Symbol.for(key);\n const holder = globalThis as Record<symbol, Context<T | null> | undefined>;\n const existing = holder[symbol];\n if (existing !== undefined) return existing;\n const created = createContext<T | null>(null);\n holder[symbol] = created;\n return created;\n}\n\n/**\n * How pushed components are drawn when no `renderUi` is passed — set by `<GenuiProvider>` (the\n * `/genui` subpath) and read by `MessageItem`.\n */\nexport const AmbientRenderUiContext: Context<AmbientRenderUi | null> =\n sharedContext<AmbientRenderUi>('@dudousxd/nestjs-agent-react:ambient-render-ui');\n\n/**\n * The renderer `<GenuiProvider>` installed for pushed components, or `null` outside one. For a\n * custom transcript built on `useTranscriptItem`: draw a `ui` block with it and you get what\n * `MessageItem` draws.\n */\nexport function useAmbientRenderUi(): AmbientRenderUi | null {\n return useContext(AmbientRenderUiContext);\n}\n","function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * `next`, with every part structurally equal to the same part of `previous` replaced by that part\n * of `previous` — `previous` itself when the two are equal throughout. Plain objects and arrays are\n * compared member by member (arrays by position); anything else by `Object.is`.\n *\n * The chat reaches React as a fresh deep copy on every update (the AI SDK clones the streaming\n * message on each chunk), so a pushed component's props and a tree's nodes are new objects on every\n * token even when nothing in them changed. Run through this, an unchanged node keeps its identity\n * and a memoized renderer skips it; a changed one (more props, `incomplete` → final) is new, and so\n * is every ancestor of it, which is what re-renders.\n */\nexport function shareStructure<T>(previous: unknown, next: T): T {\n if (Object.is(previous, next)) return next;\n if (Array.isArray(next)) {\n if (!Array.isArray(previous)) return next;\n let same = previous.length === next.length;\n const shared = next.map((value, index) => {\n const kept = shareStructure(previous[index], value);\n if (kept !== previous[index]) same = false;\n return kept;\n });\n return (same ? previous : shared) as T;\n }\n if (isPlainObject(next)) {\n if (!isPlainObject(previous)) return next;\n const keys = Object.keys(next);\n let same = keys.length === Object.keys(previous).length;\n const shared: Record<string, unknown> = {};\n for (const key of keys) {\n const kept = shareStructure(previous[key], next[key]);\n if (kept !== previous[key] || !Object.hasOwn(previous, key)) same = false;\n shared[key] = kept;\n }\n return (same ? previous : shared) as T;\n }\n return next;\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 ...(isRecord(source.componentVersions) &&\n Object.values(source.componentVersions).every(\n (version) => typeof version === 'number' && Number.isSafeInteger(version) && version > 0,\n )\n ? { componentVersions: { ...source.componentVersions } as Record<string, number> }\n : {}),\n ...(typeof source.fallbackText === 'string' ? { fallbackText: source.fallbackText } : {}),\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 ...(source.partial === true ? { partial: true as const } : {}),\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 definition = options.catalog?.get?.(name);\n const incompatible =\n item?.fallbackText !== undefined &&\n item.version !== null &&\n definition !== undefined &&\n item.version !== (definition.version ?? 1);\n const resolution = useResolvedComponent(\n name,\n item?.version ?? null,\n incompatible ? {} : 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 || incompatible ? undefined : options.catalog,\n name,\n item?.props ?? empty,\n );\n if (item === null) return null;\n // A withdrawn preview (partial, nothing to draw): the call will not replace it.\n if (item.partial === true && Object.keys(item.props).length === 0) return null;\n if (\n name === GENUI_TREE_COMPONENT &&\n item.fallbackText !== undefined &&\n (!isRecord(item.props.root) || typeof item.props.root.type !== 'string')\n )\n return {\n status: 'problem',\n reason: 'invalid',\n item,\n issues: [{ path: ['root'], message: 'Invalid UI tree root' }],\n };\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 (`GENUI_TREE_COMPONENT` of `@dudousxd/nestjs-agent-core/genui`). */\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 fallbackText?: string;\n componentVersions?: Record<string, number>;\n id: string;\n component: string;\n props: Record<string, unknown>;\n version: number | null;\n toolCallId: string | null;\n /**\n * A preview drawn while the model is still writing the call (genui `streaming: 'partial'`):\n * unvalidated, and replaced in place by the final frame under the same `id`.\n */\n partial?: true;\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 * The node's position (`root`, `root.0`, `root.0.2`), carried by partial frames. Stable as the\n * tree grows, and the same rule names the final tree's nodes.\n */\n id?: string;\n /** Partial frames only: the model has not finished writing this node. */\n incomplete?: true;\n /** Partial frames only: a `streaming: 'complete'` component held back until it closes (no props). */\n held?: true;\n}\n\n/**\n * What a tree node's renderer can learn about its node ({@link useGenuiNode}): which node it is,\n * and whether the model is still writing it. Room is left for more states (data a node is bound\n * to, loading) as separate fields — `incomplete` only ever means \"still being written\".\n */\nexport interface GenuiNodeState {\n /** The node's position id (`root`, `root.1.0`): stable from the first preview to the final frame. */\n id: string;\n type: string;\n /** The model has not finished writing this node: props (and children) may still grow. */\n incomplete: boolean;\n /** The node is a placeholder for a component that is only drawn whole (`streaming: 'complete'`). */\n held: boolean;\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 `Catalog` from\n * `@dudousxd/nestjs-agent-core/genui` satisfies it; declared structurally so any catalog-shaped\n * object does too.\n */\nexport interface GenuiCatalogLike {\n get?(name: string): { version?: number } | undefined;\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 * Draws a composed tree frame (`genui:tree`) whole — e.g. through json-render (see the\n * `/genui/json-render` subpath's `GenuiProvider`). Omitted → trees render node by node through\n * `registry`.\n */\n treeRenderer?: GenuiRenderer<{ root?: GenerativeUIElement }>;\n}\n\n/**\n * Drawn in place of a tree node that is not drawable yet — a `held` node (its component streams\n * `complete`) while the model writes it. Default: the `loading` element.\n */\nexport type GenuiPlaceholder = ReactNode | ((node: GenuiNodeState) => ReactNode);\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","import {\n type CatalogOptions,\n type ComponentDefinition,\n type ComponentPresentation,\n createComponentRegistry,\n} from '@dudousxd/nestjs-agent-core/genui';\nimport { type ComponentType, type ReactNode, createElement } from 'react';\nimport type { GenuiRegistry } from './types.js';\n\nexport interface ReactComponentRenderers<P extends object> {\n react?: ComponentType<P>;\n text?: (props: P) => string | Promise<string>;\n /** Return each page's complete props. Each page is validated again before SSR. */\n paginate?: (props: P, rowsPerPage: number) => readonly P[] | Promise<readonly P[]>;\n}\n\n/** App-scoped registry shared by GenuiProvider and static server rendering. */\nexport function createReactComponentRegistry(options?: CatalogOptions) {\n const registry = createComponentRegistry(options);\n const components: GenuiRegistry = Object.create(null);\n const texts = new Map<string, (props: Record<string, unknown>) => string | Promise<string>>();\n const paginators = new Map<\n string,\n (props: Record<string, unknown>, size: number) => Promise<readonly Record<string, unknown>[]>\n >();\n const adapter = {\n get catalog() {\n return registry.catalog;\n },\n get manifest() {\n return registry.manifest;\n },\n get components(): GenuiRegistry {\n return { ...components };\n },\n prepare: (presentation: ComponentPresentation<object>) =>\n registry.prepare({ ...presentation, props: presentation.props as Record<string, unknown> }),\n render: (presentation: ComponentPresentation<object>, channel: string) =>\n registry.render(\n { ...presentation, props: presentation.props as Record<string, unknown> },\n channel,\n ),\n register<P extends object>(\n definition: ComponentDefinition<P>,\n renderers: ReactComponentRenderers<P>,\n ) {\n const ReactComponent = renderers.react;\n registry.register(definition, {\n ...(ReactComponent ? { react: (props: P) => createElement(ReactComponent, props) } : {}),\n ...(renderers.text ? { text: renderers.text } : {}),\n });\n if (renderers.react) components[definition.name] = renderers.react;\n if (renderers.text) {\n const text = renderers.text;\n texts.set(definition.name, (props) => text(props as P));\n }\n if (renderers.paginate) {\n const paginate = renderers.paginate;\n paginators.set(\n definition.name,\n async (props, size) =>\n (await paginate(props as P, size)) as readonly Record<string, unknown>[],\n );\n }\n return adapter;\n },\n async renderPages(\n presentation: ComponentPresentation<object>,\n size: number,\n ): Promise<ReactNode[]> {\n const pages = await adapter.paginate(presentation, size);\n return Promise.all(\n pages.map(async (page) => {\n const ReactComponent = components[page.component];\n if (ReactComponent) return createElement(ReactComponent, page.props);\n return texts.get(page.component)?.(page.props) ?? page.fallbackText;\n }),\n );\n },\n async paginate(\n presentation: ComponentPresentation<object>,\n size: number,\n ): Promise<ComponentPresentation[]> {\n if (!Number.isInteger(size) || size < 1 || size > 500)\n throw new RangeError('genui: rowsPerPage must be 1–500');\n const prepared = await registry.prepare({\n ...presentation,\n props: presentation.props as Record<string, unknown>,\n });\n const custom = paginators.get(prepared.component);\n const rows = prepared.props.rows;\n const pages = custom\n ? await custom(prepared.props, size)\n : prepared.component === 'DataTable' && Array.isArray(rows) && rows.length > size\n ? Array.from({ length: Math.ceil(rows.length / size) }, (_, index) => ({\n ...prepared.props,\n rows: rows.slice(index * size, (index + 1) * size),\n }))\n : [prepared.props];\n if (!pages.length || pages.length > 100)\n throw new RangeError('genui: capture requires 1–100 pages');\n return Promise.all(pages.map((props) => registry.prepare({ ...prepared, props })));\n },\n };\n return adapter;\n}\nexport type ReactComponentRegistry = ReturnType<typeof createReactComponentRegistry>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAWO;;;ACXP,mBAAwE;AAWjE,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AACA,SAAO;AACT;","names":["import_react","import_react","Component","TreeNode","import_react"]}
package/dist/genui.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { G as GenerativeUI, a as GenerativeUIFallback, b as GenerativeUIProps, c as GenerativeUIScope, d as GenerativeUIScopeProps, e as GenuiProvider, f as GenuiProviderProps, g as GenuiProviderValue, h as GenuiTree, u as useGenerativeUI, i as useGenuiNode, j as useGenuiProvider } from './generative-ui-ClYT7OgL.cjs';
1
+ export { G as GenerativeUI, a as GenerativeUIFallback, b as GenerativeUIProps, c as GenerativeUIScope, d as GenerativeUIScopeProps, e as GenuiProvider, f as GenuiProviderProps, g as GenuiProviderValue, h as GenuiTree, u as useGenerativeUI, i as useGenuiNode, j as useGenuiProvider } from './generative-ui-Pz1t-Ap3.cjs';
2
2
  import { G as GenerativeUIItem } from './types-COuArD3c.cjs';
3
3
  export { a as GENUI_TREE_COMPONENT, b as GenerativeUIElement, c as GenerativeUIOptions, d as GenerativeUIProblem, e as GenerativeUIState, f as GenuiCatalogLike, g as GenuiIssueLike, h as GenuiNodeState, i as GenuiPlaceholder, j as GenuiRegistry, k as GenuiRenderer, R as ResolveComponent } from './types-COuArD3c.cjs';
4
4
  export { R as ReactComponentRegistry, a as ReactComponentRenderers, c as createReactComponentRegistry } from './react-registry-R0eFtDCG.cjs';
package/dist/genui.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { G as GenerativeUI, a as GenerativeUIFallback, b as GenerativeUIProps, c as GenerativeUIScope, d as GenerativeUIScopeProps, e as GenuiProvider, f as GenuiProviderProps, g as GenuiProviderValue, h as GenuiTree, u as useGenerativeUI, i as useGenuiNode, j as useGenuiProvider } from './generative-ui-D1efzu_K.js';
1
+ export { G as GenerativeUI, a as GenerativeUIFallback, b as GenerativeUIProps, c as GenerativeUIScope, d as GenerativeUIScopeProps, e as GenuiProvider, f as GenuiProviderProps, g as GenuiProviderValue, h as GenuiTree, u as useGenerativeUI, i as useGenuiNode, j as useGenuiProvider } from './generative-ui-DySIh0up.js';
2
2
  import { G as GenerativeUIItem } from './types-COuArD3c.js';
3
3
  export { a as GENUI_TREE_COMPONENT, b as GenerativeUIElement, c as GenerativeUIOptions, d as GenerativeUIProblem, e as GenerativeUIState, f as GenuiCatalogLike, g as GenuiIssueLike, h as GenuiNodeState, i as GenuiPlaceholder, j as GenuiRegistry, k as GenuiRenderer, R as ResolveComponent } from './types-COuArD3c.js';
4
4
  export { R as ReactComponentRegistry, a as ReactComponentRenderers, c as createReactComponentRegistry } from './react-registry-CC84Jm3U.js';