@dudousxd/nestjs-agent-react 0.20.0 → 0.21.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.
@@ -1,3 +1,5 @@
1
+ import * as React from 'react';
2
+ import { ComponentType, ReactNode } from 'react';
1
3
  import { ElicitationQuestion, ElicitationInputType, ToolPresentation, ToolCatalogEntry, ToolResultField, ToolResultView, ToolPresentationTone, ElicitationInput } from '@dudousxd/nestjs-agent-core';
2
4
  import { ToolUIPart, DynamicToolUIPart, UIMessage } from 'ai';
3
5
 
@@ -558,4 +560,166 @@ declare function describeTimestamp(createdAt: string | null | undefined): Timest
558
560
  */
559
561
  declare function formatRelativeTime(date: Date): string;
560
562
 
561
- export { resolveResultView as $, type ApproveOptions as A, type BuildBlocksOptions as B, type ChatStatus as C, type DescribeToolCallOptions as D, type ElicitationBlockOptions as E, type TranscriptToolBlock as F, type GroupToolActivityOptions as G, type TranscriptToolCall as H, buildTranscriptBlocks as I, coerceAnswer as J, correctedCallIds as K, describeTimestamp as L, type MessageUsageInfo as M, describeToolCall as N, describeUsage as O, extractMessageText as P, fillTemplate as Q, type RawAnswer as R, type SettleAction as S, type TranscriptUiBlock as T, type UsageSummary as U, formatRelativeTime as V, groupToolActivity as W, inferResultView as X, isActionCall as Y, phraseFor as Z, readPath as _, type TranscriptBlock as a, toolCallState as a0, toolCatalogFrom as a1, type TimestampInfo as b, type ToolCatalog as c, type AnyToolUIPart as d, type TranscriptFile as e, type ApprovalBlockOptions as f, type CoercibleQuestion as g, type ResolvedReading as h, type ResolvedResultView as i, type RetrievedPassage as j, type ToolActivityGroup as k, type ToolCallDescription as l, type ToolCallState as m, type ToolCallStatus as n, type TranscriptApproval as o, type TranscriptApprovalStatus as p, type TranscriptElicitationBlock as q, type TranscriptElicitationOutcome as r, type TranscriptFilesBlock as s, type TranscriptQuestion as t, type TranscriptQuestionOption as u, type TranscriptReasoningBlock as v, type TranscriptSettleState as w, type TranscriptSource as x, type TranscriptSourcesBlock as y, type TranscriptTextBlock as z };
563
+ /** The `ui` frame component a composed tree is pushed under (`GENUI_TREE_COMPONENT` of `@dudousxd/nestjs-agent-core/genui`). */
564
+ declare const GENUI_TREE_COMPONENT = "genui:tree";
565
+ /** One pushed component, normalized from whatever carried it (a transcript block, a `data-ui` part, a stored entry). */
566
+ interface GenerativeUIItem {
567
+ id: string;
568
+ component: string;
569
+ props: Record<string, unknown>;
570
+ version: number | null;
571
+ toolCallId: string | null;
572
+ }
573
+ /** A node of a composed tree (`genui:tree` frames): `{ type, props, children? }`. */
574
+ interface GenerativeUIElement {
575
+ type: string;
576
+ props: Record<string, unknown>;
577
+ children?: GenerativeUIElement[];
578
+ }
579
+ /**
580
+ * An app's renderer for one component: it receives the component's props spread, plus `children`
581
+ * when it is a layout node in a tree. Any React component — the library never styles anything.
582
+ */
583
+ type GenuiRenderer<P = any> = ComponentType<P & {
584
+ children?: ReactNode;
585
+ }>;
586
+ /** Component name → the app's renderer. */
587
+ type GenuiRegistry = Record<string, GenuiRenderer>;
588
+ /**
589
+ * Resolve a component the registry does not have — typically a tenant's own component, fetched for
590
+ * the exact `version` a message was rendered with. Return `null`/`undefined` for "no such
591
+ * component". May be async; results are cached per resolver, name and version.
592
+ */
593
+ type ResolveComponent = (name: string, version: number | null) => GenuiRenderer | null | undefined | Promise<GenuiRenderer | null | undefined>;
594
+ interface GenuiIssueLike {
595
+ path: (string | number)[];
596
+ message: string;
597
+ }
598
+ type ValidationLike = {
599
+ ok: true;
600
+ value: Record<string, unknown>;
601
+ } | {
602
+ ok: false;
603
+ issues: GenuiIssueLike[];
604
+ };
605
+ /**
606
+ * What the renderer needs from a catalog to validate props before drawing them. A `Catalog` from
607
+ * `@dudousxd/nestjs-agent-core/genui` satisfies it; declared structurally so any catalog-shaped
608
+ * object does too.
609
+ */
610
+ interface GenuiCatalogLike {
611
+ has(name: string): boolean;
612
+ validate(name: string, props: unknown): Promise<ValidationLike>;
613
+ validateSync?(name: string, props: unknown): ValidationLike | undefined;
614
+ }
615
+ interface GenerativeUIOptions {
616
+ registry: GenuiRegistry;
617
+ /** Validate props against it before rendering. Components the catalog does not know render unvalidated. */
618
+ catalog?: GenuiCatalogLike;
619
+ resolveComponent?: ResolveComponent;
620
+ /**
621
+ * Draws a composed tree frame (`genui:tree`) whole — e.g. through json-render (see the
622
+ * `/genui/json-render` subpath's `GenuiProvider`). Omitted → trees render node by node through
623
+ * `registry`.
624
+ */
625
+ treeRenderer?: GenuiRenderer<{
626
+ root?: GenerativeUIElement;
627
+ }>;
628
+ }
629
+ /** Why an item did not render. */
630
+ type GenerativeUIProblem = {
631
+ reason: 'unknown';
632
+ item: GenerativeUIItem;
633
+ } | {
634
+ reason: 'invalid';
635
+ item: GenerativeUIItem;
636
+ issues: GenuiIssueLike[];
637
+ } | {
638
+ reason: 'error';
639
+ item: GenerativeUIItem;
640
+ error: unknown;
641
+ };
642
+ type GenerativeUIState = {
643
+ status: 'ready';
644
+ item: GenerativeUIItem;
645
+ Component: GenuiRenderer;
646
+ props: Record<string, unknown>;
647
+ } | {
648
+ status: 'loading';
649
+ item: GenerativeUIItem;
650
+ } | ({
651
+ status: 'problem';
652
+ } & GenerativeUIProblem);
653
+
654
+ /** What to draw instead of a component that did not render. Default: nothing. */
655
+ type GenerativeUIFallback = ReactNode | ((problem: GenerativeUIProblem) => ReactNode);
656
+ /**
657
+ * Renders a `genui:tree` frame's `{ root }` node by node through the same registry, catalog and
658
+ * resolver as top-level components. Used automatically for tree frames unless a `treeRenderer`
659
+ * (e.g. the json-render one) or a registry entry for `genui:tree` takes over.
660
+ */
661
+ declare function GenuiTree({ root }: {
662
+ root?: GenerativeUIElement;
663
+ }): React.JSX.Element | null;
664
+ interface GenerativeUIScopeProps extends GenerativeUIOptions {
665
+ fallback?: GenerativeUIFallback;
666
+ loading?: ReactNode;
667
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
668
+ children?: ReactNode;
669
+ }
670
+ /**
671
+ * The registry, catalog and fallbacks tree nodes render with. `<GenerativeUI>` provides it; wrap
672
+ * your own chrome in it when you draw `useGenerativeUI`'s `Component` yourself and it may be a tree.
673
+ */
674
+ declare function GenerativeUIScope({ registry, catalog, resolveComponent, fallback, loading, onError, children, }: GenerativeUIScopeProps): React.JSX.Element;
675
+ /** What `<GenuiProvider>` hands every `<GenerativeUI>` / `useGenerativeUI` below it. */
676
+ interface GenuiProviderValue extends Partial<GenerativeUIOptions> {
677
+ fallback?: GenerativeUIFallback;
678
+ loading?: ReactNode;
679
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
680
+ }
681
+ /** The enclosing `<GenuiProvider>`'s settings, or `null` outside one. */
682
+ declare function useGenuiProvider(): GenuiProviderValue | null;
683
+ interface GenuiProviderProps extends GenuiProviderValue {
684
+ children?: ReactNode;
685
+ }
686
+ /**
687
+ * Set generative UI up once, at the app root: the registry of your renderers, the catalog to
688
+ * validate against, a resolver for components the registry lacks, and what to draw when one does
689
+ * not render. Every `<GenerativeUI>` below reads it (its own props still win), and `MessageItem` /
690
+ * `MessageList` draw pushed components with it — no `renderUi` per message.
691
+ *
692
+ * ```tsx
693
+ * <GenuiProvider registry={registry} catalog={catalog} fallback={({ item }) => <Unknown name={item.component} />}>
694
+ * <App />
695
+ * </GenuiProvider>
696
+ * ```
697
+ */
698
+ declare function GenuiProvider({ registry, catalog, resolveComponent, treeRenderer, fallback, loading, onError, children, }: GenuiProviderProps): React.JSX.Element;
699
+ /**
700
+ * The headless half of {@link GenerativeUI}: what to draw for one pushed component, or `null` when
701
+ * `part` is not one. Options default to the enclosing `<GenuiProvider>`'s.
702
+ */
703
+ declare function useGenerativeUI(part: unknown, options?: Partial<GenerativeUIOptions>): GenerativeUIState | null;
704
+ interface GenerativeUIProps extends Partial<GenerativeUIOptions> {
705
+ /** A transcript `ui` block, a `data-ui` message part, or a stored `{ id, component, props, version? }`. */
706
+ part: TranscriptUiBlock | GenerativeUIItem | unknown;
707
+ /** Drawn for an unknown component, invalid props, or a renderer that threw. Default: the provider's, else nothing. */
708
+ fallback?: GenerativeUIFallback;
709
+ /** Drawn while a resolver or an async validation is pending. Default: the provider's, else nothing. */
710
+ loading?: ReactNode;
711
+ /** A renderer threw (the item shows `fallback`). */
712
+ onError?: (error: unknown, item: GenerativeUIItem) => void;
713
+ }
714
+ /**
715
+ * Draws one server-pushed component with the app's own renderer. Headless: it adds no element and
716
+ * no style of its own — only what the registry's component renders (and whatever `fallback` /
717
+ * `loading` you pass). Everything but `part` defaults to the enclosing `<GenuiProvider>`.
718
+ *
719
+ * ```tsx
720
+ * <GenerativeUI part={block} />
721
+ * ```
722
+ */
723
+ declare function GenerativeUI({ part, registry, catalog, resolveComponent, treeRenderer, fallback: ownFallback, loading: ownLoading, onError: ownOnError, }: GenerativeUIProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
724
+
725
+ export { type TranscriptQuestionOption as $, type ApproveOptions as A, type BuildBlocksOptions as B, type ChatStatus as C, type CoercibleQuestion as D, type DescribeToolCallOptions as E, type ElicitationBlockOptions as F, type GenerativeUIItem as G, type GroupToolActivityOptions as H, type RawAnswer as I, type ResolvedReading as J, type ResolvedResultView as K, type RetrievedPassage as L, type MessageUsageInfo as M, type ToolActivityGroup as N, type ToolCallDescription as O, type ToolCallState as P, type ToolCallStatus as Q, type ResolveComponent as R, type SettleAction as S, type TranscriptUiBlock as T, type UsageSummary as U, type TranscriptApproval as V, type TranscriptApprovalStatus as W, type TranscriptElicitationBlock as X, type TranscriptElicitationOutcome as Y, type TranscriptFilesBlock as Z, type TranscriptQuestion as _, GENUI_TREE_COMPONENT as a, type TranscriptReasoningBlock as a0, type TranscriptSettleState as a1, type TranscriptSource as a2, type TranscriptSourcesBlock as a3, type TranscriptTextBlock as a4, type TranscriptToolBlock as a5, type TranscriptToolCall as a6, buildTranscriptBlocks as a7, coerceAnswer as a8, correctedCallIds as a9, describeTimestamp as aa, describeToolCall as ab, describeUsage as ac, extractMessageText as ad, fillTemplate as ae, formatRelativeTime as af, groupToolActivity as ag, inferResultView as ah, isActionCall as ai, phraseFor as aj, readPath as ak, resolveResultView as al, toolCallState as am, toolCatalogFrom as an, GenerativeUI as b, type GenerativeUIElement as c, type GenerativeUIFallback as d, type GenerativeUIOptions as e, type GenerativeUIProblem as f, type GenerativeUIProps as g, GenerativeUIScope as h, type GenerativeUIScopeProps as i, type GenerativeUIState as j, type GenuiCatalogLike as k, type GenuiIssueLike as l, GenuiProvider as m, type GenuiProviderProps as n, type GenuiProviderValue as o, type GenuiRegistry as p, type GenuiRenderer as q, GenuiTree as r, useGenuiProvider as s, type TranscriptBlock as t, useGenerativeUI as u, type TimestampInfo as v, type ToolCatalog as w, type AnyToolUIPart as x, type TranscriptFile as y, type ApprovalBlockOptions as z };
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { ComponentRegistry } from '@json-render/react';
3
- import { n as GenuiProviderProps$1, c as GenerativeUIElement, q as GenuiRenderer, p as GenuiRegistry } from './generative-ui-C53b3FoA.cjs';
4
- import './model-gHqjNjLJ.cjs';
3
+ import { n as GenuiProviderProps$1, c as GenerativeUIElement, q as GenuiRenderer, p as GenuiRegistry } from './generative-ui-9AJNVKBZ.cjs';
5
4
  import '@dudousxd/nestjs-agent-core';
6
5
  import 'ai';
7
6
 
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { ComponentRegistry } from '@json-render/react';
3
- import { n as GenuiProviderProps$1, c as GenerativeUIElement, q as GenuiRenderer, p as GenuiRegistry } from './generative-ui-BhXFni8j.js';
4
- import './model-gHqjNjLJ.js';
3
+ import { n as GenuiProviderProps$1, c as GenerativeUIElement, q as GenuiRenderer, p as GenuiRegistry } from './generative-ui-9AJNVKBZ.js';
5
4
  import '@dudousxd/nestjs-agent-core';
6
5
  import 'ai';
7
6
 
package/dist/genui.d.cts CHANGED
@@ -1,7 +1,6 @@
1
- import { G as GenerativeUIItem } from './generative-ui-C53b3FoA.cjs';
2
- export { a as GENUI_TREE_COMPONENT, b as GenerativeUI, c as GenerativeUIElement, d as GenerativeUIFallback, e as GenerativeUIOptions, f as GenerativeUIProblem, g as GenerativeUIProps, h as GenerativeUIScope, i as GenerativeUIScopeProps, j as GenerativeUIState, k as GenuiCatalogLike, l as GenuiIssueLike, m as GenuiProvider, n as GenuiProviderProps, o as GenuiProviderValue, p as GenuiRegistry, q as GenuiRenderer, r as GenuiTree, R as ResolveComponent, u as useGenerativeUI, s as useGenuiProvider } from './generative-ui-C53b3FoA.cjs';
1
+ import { G as GenerativeUIItem } from './generative-ui-9AJNVKBZ.cjs';
2
+ export { a as GENUI_TREE_COMPONENT, b as GenerativeUI, c as GenerativeUIElement, d as GenerativeUIFallback, e as GenerativeUIOptions, f as GenerativeUIProblem, g as GenerativeUIProps, h as GenerativeUIScope, i as GenerativeUIScopeProps, j as GenerativeUIState, k as GenuiCatalogLike, l as GenuiIssueLike, m as GenuiProvider, n as GenuiProviderProps, o as GenuiProviderValue, p as GenuiRegistry, q as GenuiRenderer, r as GenuiTree, R as ResolveComponent, u as useGenerativeUI, s as useGenuiProvider } from './generative-ui-9AJNVKBZ.cjs';
3
3
  import 'react';
4
- import './model-gHqjNjLJ.cjs';
5
4
  import '@dudousxd/nestjs-agent-core';
6
5
  import 'ai';
7
6
 
package/dist/genui.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { G as GenerativeUIItem } from './generative-ui-BhXFni8j.js';
2
- export { a as GENUI_TREE_COMPONENT, b as GenerativeUI, c as GenerativeUIElement, d as GenerativeUIFallback, e as GenerativeUIOptions, f as GenerativeUIProblem, g as GenerativeUIProps, h as GenerativeUIScope, i as GenerativeUIScopeProps, j as GenerativeUIState, k as GenuiCatalogLike, l as GenuiIssueLike, m as GenuiProvider, n as GenuiProviderProps, o as GenuiProviderValue, p as GenuiRegistry, q as GenuiRenderer, r as GenuiTree, R as ResolveComponent, u as useGenerativeUI, s as useGenuiProvider } from './generative-ui-BhXFni8j.js';
1
+ import { G as GenerativeUIItem } from './generative-ui-9AJNVKBZ.js';
2
+ export { a as GENUI_TREE_COMPONENT, b as GenerativeUI, c as GenerativeUIElement, d as GenerativeUIFallback, e as GenerativeUIOptions, f as GenerativeUIProblem, g as GenerativeUIProps, h as GenerativeUIScope, i as GenerativeUIScopeProps, j as GenerativeUIState, k as GenuiCatalogLike, l as GenuiIssueLike, m as GenuiProvider, n as GenuiProviderProps, o as GenuiProviderValue, p as GenuiRegistry, q as GenuiRenderer, r as GenuiTree, R as ResolveComponent, u as useGenerativeUI, s as useGenuiProvider } from './generative-ui-9AJNVKBZ.js';
3
3
  import 'react';
4
- import './model-gHqjNjLJ.js';
5
4
  import '@dudousxd/nestjs-agent-core';
6
5
  import 'ai';
7
6