@dudousxd/nestjs-agent-react 0.20.0 → 0.22.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,4 +1,4 @@
1
- import { ThreadSummary, ThreadDetail, MessageAttachment, ToolCatalogEntry, SkillCatalogEntry, QuotaView, QuotaReport, ModelCatalogView, AgentCatalogEntry, MessageFeedbackValue, MessageFeedback } from '@dudousxd/nestjs-agent-core';
1
+ import { ThreadSummary, ThreadDetail, MessageAttachment, ToolCatalogEntry, SkillCatalogEntry, QuotaReport, ModelCatalogView, AgentCatalogEntry, MessageFeedbackValue, MessageFeedback } from '@dudousxd/nestjs-agent-core';
2
2
 
3
3
  /**
4
4
  * Partial update accepted by `PATCH <base>/threads/:threadId`. `defaultAgent: null` clears a
@@ -54,15 +54,17 @@ interface UploadAttachmentOptions {
54
54
  }
55
55
  /** How {@link AgentClient} reaches the server — handed to an {@link AttachmentUploadStrategy}. */
56
56
  interface AgentConnection {
57
- /** Origin + base path, trailing slash removed (`''` for same-origin). */
57
+ /** The server's origin, trailing slash removed (`''` for same-origin). */
58
58
  baseUrl: string;
59
+ /** The agent's route prefix, normalized to a leading slash (`'/agent'`), or `''`. */
60
+ path: string;
59
61
  /** The client's static + per-request headers, resolved now (auth, CSRF). */
60
62
  headers: () => Promise<Record<string, string>>;
61
63
  credentials?: RequestCredentials;
62
64
  fetch: typeof fetch;
63
65
  }
64
66
  /**
65
- * Replaces {@link AgentClient}'s own `uploadAttachment` (`POST <base>/agent/attachments`) — e.g.
67
+ * Replaces {@link AgentClient}'s own `uploadAttachment` (`POST <path>/attachments`) — e.g.
66
68
  * `mediaAttachments()` from `@dudousxd/nestjs-agent-react/media`, or your own storage. Gets the
67
69
  * client's connection so it needs no configuration of its own. Resolve with the attachment your
68
70
  * server's `AGENT_ATTACHMENT_STAGING` recognises by `mediaId`.
@@ -73,7 +75,8 @@ type AttachmentUploadStrategy = (file: File, options: UploadAttachmentOptions, c
73
75
  * hooks) and whatever serves the agent. {@link AgentClient} is the default implementation, over the
74
76
  * library's own REST routes with `fetch`. An app with its own client — a generated one, a different
75
77
  * auth scheme (cookie session + CSRF header), a backend that is not this library at all but speaks
76
- * docs/stream-protocol.md — implements this instead and passes it as `useAgentChat({ backend })`.
78
+ * docs/stream-protocol.md — implements this instead and passes it as `<AgentProvider backend>` (or
79
+ * per hook, `useAgentChat({ backend })`).
77
80
  *
78
81
  * The streaming, thread and cancel members are required: without them there is no chat. The rest
79
82
  * are optional; a hook that needs one the backend does not have throws
@@ -114,7 +117,6 @@ interface AgentBackend {
114
117
  uploadAttachment?(file: File, options?: UploadAttachmentOptions): Promise<MessageAttachment>;
115
118
  listTools?(agent?: string): Promise<ToolCatalogEntry[]>;
116
119
  listSkills?(threadId?: string): Promise<SkillCatalogEntry[]>;
117
- getQuotaToday?(): Promise<QuotaView>;
118
120
  /** `GET <base>/quota` — every budget window, and which one blocks sends, if any. */
119
121
  getQuota?(): Promise<QuotaReport>;
120
122
  /** `GET <base>/models?agent=` — what a model picker offers. */
@@ -149,8 +151,6 @@ declare class AgentHttpError extends Error {
149
151
  readonly path: string;
150
152
  constructor(status: number, method: string, path: string, statusText: string);
151
153
  }
152
- /** The quota-today read-model: usage, the configured limit (null → unlimited), and USD spend. */
153
- type QuotaToday = QuotaView;
154
154
  interface CancelResult {
155
155
  aborted: boolean;
156
156
  }
@@ -158,8 +158,16 @@ interface OkResult {
158
158
  ok: boolean;
159
159
  }
160
160
  interface AgentClientOptions {
161
- /** Origin + base path, e.g. `https://api.example.com`. Defaults to `''`. */
161
+ /**
162
+ * The server's origin, e.g. `https://api.example.com`. Defaults to `''` (same origin). The
163
+ * agent's route prefix is {@link AgentClientOptions.path}, not part of this.
164
+ */
162
165
  baseUrl?: string;
166
+ /**
167
+ * The agent's route prefix — `AgentModule`'s `path`, with any global prefix in front
168
+ * (`'api/agent'`). Leading/trailing slashes are optional. Defaults to `'agent'`.
169
+ */
170
+ path?: string;
163
171
  /** Static headers merged into every request. */
164
172
  headers?: Record<string, string>;
165
173
  /**
@@ -175,12 +183,15 @@ interface AgentClientOptions {
175
183
  credentials?: RequestCredentials;
176
184
  /** Injectable for tests / non-browser runtimes. */
177
185
  fetch?: typeof fetch;
178
- /**
179
- * How `uploadAttachment` uploads. Omitted → `POST <base>/agent/attachments` (multipart). Pass
180
- * `mediaAttachments()` from `@dudousxd/nestjs-agent-react/media` for resumable uploads through
181
- * nestjs-media, or your own {@link AttachmentUploadStrategy}.
182
- */
183
- attachments?: AttachmentUploadStrategy;
186
+ /** Attachment uploads. */
187
+ attachments?: {
188
+ /**
189
+ * How `uploadAttachment` uploads. Omitted → `POST <path>/attachments` (multipart). Pass
190
+ * `mediaAttachments()` from `@dudousxd/nestjs-agent-react/media` for resumable uploads through
191
+ * nestjs-media, or your own {@link AttachmentUploadStrategy}.
192
+ */
193
+ upload?: AttachmentUploadStrategy;
194
+ };
184
195
  }
185
196
  /**
186
197
  * Framework-agnostic REST client for the nestjs-agent endpoints — the default {@link AgentBackend}.
@@ -189,10 +200,10 @@ interface AgentClientOptions {
189
200
  declare class AgentClient implements AgentBackend {
190
201
  private readonly options;
191
202
  constructor(options?: AgentClientOptions);
192
- /** `POST /agent/chat` → the turn's SSE stream. Throws {@link AgentHttpError} on a non-2xx. */
203
+ /** `POST <path>/chat` → the turn's SSE stream. Throws {@link AgentHttpError} on a non-2xx. */
193
204
  openChatStream(request: ChatStreamRequest): Promise<ChatStreamResponse>;
194
205
  /**
195
- * `GET /agent/chat/:runId/stream[?after=<seq>]` → the run's SSE stream, or `null` when nothing is
206
+ * `GET <path>/chat/:runId/stream[?after=<seq>]` → the run's SSE stream, or `null` when nothing is
196
207
  * streaming under that id (404).
197
208
  */
198
209
  resumeChatStream(request: ResumeStreamRequest): Promise<ChatStreamResponse | null>;
@@ -220,25 +231,23 @@ declare class AgentClient implements AgentBackend {
220
231
  getThread(id: string): Promise<ThreadDetail>;
221
232
  deleteThread(id: string): Promise<void>;
222
233
  forkFromMessage(threadId: string, messageId: string): Promise<ThreadSummary>;
223
- renameThread(id: string, title: string): Promise<OkResult>;
224
- /** General `PATCH /agent/threads/:threadId` — title and/or the thread's pinned default agent. */
234
+ /** General `PATCH <path>/threads/:threadId` — title and/or the thread's pinned default agent. */
225
235
  updateThread(id: string, patch: ThreadPatch): Promise<OkResult>;
226
236
  /**
227
237
  * Uploads a file (image/PDF) for a vision-capable model turn. Multipart, field name `file` —
228
- * mirrors the backend's `POST /agent/attachments`. The returned {@link MessageAttachment} is
238
+ * mirrors the backend's `POST <path>/attachments`. The returned {@link MessageAttachment} is
229
239
  * what a caller then rides on `sendMessage({ text }, { body: { attachments: [...] } })`.
230
240
  */
231
241
  uploadAttachment(file: File, options?: UploadAttachmentOptions): Promise<MessageAttachment>;
232
242
  private uploadWithProgress;
233
243
  promoteThread(id: string): Promise<OkResult>;
234
244
  truncateFromMessage(threadId: string, messageId: string): Promise<OkResult>;
235
- /** `GET /agent/models?agent=` — the models this caller may pick, grouped by provider. */
245
+ /** `GET <path>/models?agent=` — the models this caller may pick, grouped by provider. */
236
246
  listModels(agent?: string): Promise<ModelCatalogView>;
237
- /** `GET /agent/agents` — the registered agents, the default one flagged. */
247
+ /** `GET <path>/agents` — the registered agents, the default one flagged. */
238
248
  listAgents(): Promise<AgentCatalogEntry[]>;
239
- /** `GET /agent/quota` — the caller's budget windows and the one blocking sends, if any. */
249
+ /** `GET <path>/quota` — the caller's budget windows and the one blocking sends, if any. */
240
250
  getQuota(): Promise<QuotaReport>;
241
- getQuotaToday(): Promise<QuotaToday>;
242
251
  cancelStream(runId: string): Promise<CancelResult>;
243
252
  /**
244
253
  * `remember` approves later calls of the same tool in the same thread; `via` names the surface
@@ -276,10 +285,13 @@ declare class AgentClient implements AgentBackend {
276
285
  /** This client's connection, for an {@link AttachmentUploadStrategy}. */
277
286
  private connection;
278
287
  private baseUrl;
288
+ private agentPath;
289
+ /** Origin + agent path: what every route hangs off. */
290
+ private root;
279
291
  private resolveHeaders;
280
292
  private credentials;
281
293
  private request;
282
294
  private handleResponse;
283
295
  }
284
296
 
285
- export { type AgentBackend as A, type CancelResult as C, type MessageFeedbackInput as M, type QuotaToday as Q, type ResumeStreamRequest as R, type ThreadPatch as T, type UploadAttachmentOptions as U, AgentClient as a, type AttachmentUploadStrategy as b, AgentBackendUnsupportedError as c, type AgentClientOptions as d, type AgentConnection as e, AgentHttpError as f, type ChatStreamRequest as g, type ChatStreamResponse as h, requireBackendMethod as r };
297
+ export { type AgentBackend as A, type CancelResult as C, type MessageFeedbackInput as M, type ResumeStreamRequest as R, type ThreadPatch as T, type UploadAttachmentOptions as U, type AttachmentUploadStrategy as a, AgentBackendUnsupportedError as b, AgentClient as c, type AgentClientOptions as d, type AgentConnection as e, AgentHttpError as f, type ChatStreamRequest as g, type ChatStreamResponse as h, requireBackendMethod as r };
@@ -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,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