@dudousxd/nestjs-agent-react 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/{client-B6EE8-AC.d.cts → client-BdHUuqy-.d.cts} +8 -8
- package/dist/{client-B6EE8-AC.d.ts → client-BdHUuqy-.d.ts} +8 -8
- package/dist/{generative-ui-DOe2RsoO.d.cts → generative-ui-CyHY8Lh1.d.cts} +6 -101
- package/dist/{generative-ui-DOe2RsoO.d.ts → generative-ui-DdUZPCXX.d.ts} +6 -101
- package/dist/genui-json-render.d.cts +2 -1
- package/dist/genui-json-render.d.ts +2 -1
- package/dist/genui-server-playwright.cjs +199 -0
- package/dist/genui-server-playwright.cjs.map +1 -0
- package/dist/genui-server-playwright.d.cts +18 -0
- package/dist/genui-server-playwright.d.ts +18 -0
- package/dist/genui-server-playwright.js +162 -0
- package/dist/genui-server-playwright.js.map +1 -0
- package/dist/genui-server.cjs +188 -0
- package/dist/genui-server.cjs.map +1 -0
- package/dist/genui-server.d.cts +36 -0
- package/dist/genui-server.d.ts +36 -0
- package/dist/genui-server.js +163 -0
- package/dist/genui-server.js.map +1 -0
- package/dist/genui.cjs +76 -0
- package/dist/genui.cjs.map +1 -1
- package/dist/genui.d.cts +5 -2
- package/dist/genui.d.ts +5 -2
- package/dist/genui.js +77 -0
- package/dist/genui.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/media.cjs.map +1 -1
- package/dist/media.d.cts +1 -1
- package/dist/media.d.ts +1 -1
- package/dist/media.js.map +1 -1
- package/dist/react-registry-Di4IVrw-.d.cts +25 -0
- package/dist/react-registry-z9GFbTm9.d.ts +25 -0
- package/dist/types-DZtFsWec.d.cts +99 -0
- package/dist/types-DZtFsWec.d.ts +99 -0
- package/package.json +35 -5
package/README.md
CHANGED
|
@@ -7,6 +7,13 @@ SSE, plus threads, personas, quota, cancel, and human-in-the-loop approve/reject
|
|
|
7
7
|
turns the streamed messages into a renderable model — grouped parts, derived values, actions as state
|
|
8
8
|
machines — and the chat components are one rendering of it. Optional rich-markdown subpath.
|
|
9
9
|
|
|
10
|
+
## Component registries and server rendering
|
|
11
|
+
|
|
12
|
+
Tools support a `present` hook in both functional and decorated class forms. Register custom components per app, share React renderers between web screens and static exports, and generate paginated PNG/PDF tables and charts for your own delivery adapters.
|
|
13
|
+
|
|
14
|
+
See the [component rendering guide](../../docs/component-rendering.md) for complete examples, schemas, text fallbacks, and capture configuration.
|
|
15
|
+
|
|
16
|
+
|
|
10
17
|
## Install
|
|
11
18
|
|
|
12
19
|
```bash
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActionProposalMutationView, ChatQueueState, ThreadSummary, ThreadDetail, ActionProposalView, MessageAttachment, ToolCatalogEntry, SkillCatalogEntry, QuotaReport, ModelCatalogView, AgentCatalogEntry, AgentClientConfig, MessageFeedbackValue, MessageFeedback } from '@dudousxd/nestjs-agent-core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* What a server said when it refused a request, read once so every error class of this package
|
|
@@ -69,7 +69,7 @@ interface ResumeStreamRequest {
|
|
|
69
69
|
interface ChatStreamResponse {
|
|
70
70
|
proposalDecision?: {
|
|
71
71
|
threadId: string;
|
|
72
|
-
proposalDecision:
|
|
72
|
+
proposalDecision: ActionProposalMutationView | {
|
|
73
73
|
status: 'ambiguous';
|
|
74
74
|
proposalIds: string[];
|
|
75
75
|
};
|
|
@@ -199,17 +199,17 @@ interface AgentBackend {
|
|
|
199
199
|
truncateFromMessage?(threadId: string, messageId: string): Promise<unknown>;
|
|
200
200
|
listActionProposals?(input: {
|
|
201
201
|
threadId: string;
|
|
202
|
-
}): Promise<
|
|
202
|
+
}): Promise<ActionProposalView[]>;
|
|
203
203
|
approveActionProposal?(input: {
|
|
204
204
|
threadId: string;
|
|
205
205
|
proposalId: string;
|
|
206
206
|
remember?: boolean;
|
|
207
|
-
}): Promise<
|
|
207
|
+
}): Promise<ActionProposalMutationView>;
|
|
208
208
|
rejectActionProposal?(input: {
|
|
209
209
|
threadId: string;
|
|
210
210
|
proposalId: string;
|
|
211
211
|
reason?: string;
|
|
212
|
-
}): Promise<
|
|
212
|
+
}): Promise<ActionProposalMutationView>;
|
|
213
213
|
approveToolCall?(input: {
|
|
214
214
|
toolCallId: string;
|
|
215
215
|
remember?: boolean;
|
|
@@ -415,17 +415,17 @@ declare class AgentClient implements AgentBackend {
|
|
|
415
415
|
*/
|
|
416
416
|
listActionProposals({ threadId }: {
|
|
417
417
|
threadId: string;
|
|
418
|
-
}): Promise<
|
|
418
|
+
}): Promise<ActionProposalView[]>;
|
|
419
419
|
approveActionProposal({ threadId, proposalId, remember, }: {
|
|
420
420
|
threadId: string;
|
|
421
421
|
proposalId: string;
|
|
422
422
|
remember?: boolean;
|
|
423
|
-
}): Promise<
|
|
423
|
+
}): Promise<ActionProposalMutationView>;
|
|
424
424
|
rejectActionProposal({ threadId, proposalId, reason, }: {
|
|
425
425
|
threadId: string;
|
|
426
426
|
proposalId: string;
|
|
427
427
|
reason?: string;
|
|
428
|
-
}): Promise<
|
|
428
|
+
}): Promise<ActionProposalMutationView>;
|
|
429
429
|
approveToolCall(input: {
|
|
430
430
|
toolCallId: string;
|
|
431
431
|
remember?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActionProposalMutationView, ChatQueueState, ThreadSummary, ThreadDetail, ActionProposalView, MessageAttachment, ToolCatalogEntry, SkillCatalogEntry, QuotaReport, ModelCatalogView, AgentCatalogEntry, AgentClientConfig, MessageFeedbackValue, MessageFeedback } from '@dudousxd/nestjs-agent-core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* What a server said when it refused a request, read once so every error class of this package
|
|
@@ -69,7 +69,7 @@ interface ResumeStreamRequest {
|
|
|
69
69
|
interface ChatStreamResponse {
|
|
70
70
|
proposalDecision?: {
|
|
71
71
|
threadId: string;
|
|
72
|
-
proposalDecision:
|
|
72
|
+
proposalDecision: ActionProposalMutationView | {
|
|
73
73
|
status: 'ambiguous';
|
|
74
74
|
proposalIds: string[];
|
|
75
75
|
};
|
|
@@ -199,17 +199,17 @@ interface AgentBackend {
|
|
|
199
199
|
truncateFromMessage?(threadId: string, messageId: string): Promise<unknown>;
|
|
200
200
|
listActionProposals?(input: {
|
|
201
201
|
threadId: string;
|
|
202
|
-
}): Promise<
|
|
202
|
+
}): Promise<ActionProposalView[]>;
|
|
203
203
|
approveActionProposal?(input: {
|
|
204
204
|
threadId: string;
|
|
205
205
|
proposalId: string;
|
|
206
206
|
remember?: boolean;
|
|
207
|
-
}): Promise<
|
|
207
|
+
}): Promise<ActionProposalMutationView>;
|
|
208
208
|
rejectActionProposal?(input: {
|
|
209
209
|
threadId: string;
|
|
210
210
|
proposalId: string;
|
|
211
211
|
reason?: string;
|
|
212
|
-
}): Promise<
|
|
212
|
+
}): Promise<ActionProposalMutationView>;
|
|
213
213
|
approveToolCall?(input: {
|
|
214
214
|
toolCallId: string;
|
|
215
215
|
remember?: boolean;
|
|
@@ -415,17 +415,17 @@ declare class AgentClient implements AgentBackend {
|
|
|
415
415
|
*/
|
|
416
416
|
listActionProposals({ threadId }: {
|
|
417
417
|
threadId: string;
|
|
418
|
-
}): Promise<
|
|
418
|
+
}): Promise<ActionProposalView[]>;
|
|
419
419
|
approveActionProposal({ threadId, proposalId, remember, }: {
|
|
420
420
|
threadId: string;
|
|
421
421
|
proposalId: string;
|
|
422
422
|
remember?: boolean;
|
|
423
|
-
}): Promise<
|
|
423
|
+
}): Promise<ActionProposalMutationView>;
|
|
424
424
|
rejectActionProposal({ threadId, proposalId, reason, }: {
|
|
425
425
|
threadId: string;
|
|
426
426
|
proposalId: string;
|
|
427
427
|
reason?: string;
|
|
428
|
-
}): Promise<
|
|
428
|
+
}): Promise<ActionProposalMutationView>;
|
|
429
429
|
approveToolCall(input: {
|
|
430
430
|
toolCallId: string;
|
|
431
431
|
remember?: boolean;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ActionProposalView, StoredMessage, ElicitationQuestion, ElicitationInputType, ToolPresentation, ToolCatalogEntry, ToolResultField, ToolResultView, ToolPresentationTone, ToolConfirmation, ElicitationInput } from '@dudousxd/nestjs-agent-core';
|
|
4
4
|
import { UIMessage, ToolUIPart, DynamicToolUIPart } from 'ai';
|
|
5
|
+
import { c as GenerativeUIOptions, G as GenerativeUIItem, d as GenerativeUIProblem, b as GenerativeUIElement, e as GenerativeUIState } from './types-DZtFsWec.cjs';
|
|
5
6
|
|
|
6
7
|
type ApprovalTarget = {
|
|
7
8
|
kind: 'legacy';
|
|
@@ -11,9 +12,9 @@ type ApprovalTarget = {
|
|
|
11
12
|
proposalId: string;
|
|
12
13
|
threadId?: string;
|
|
13
14
|
};
|
|
14
|
-
declare function proposalNeedsPolling(proposal:
|
|
15
|
+
declare function proposalNeedsPolling(proposal: ActionProposalView): boolean;
|
|
15
16
|
/** Patch proposal metadata and append outcome facts; never replace live text with stored rows. */
|
|
16
|
-
declare function reconcileProposalMessages(current: UIMessage[], proposals:
|
|
17
|
+
declare function reconcileProposalMessages(current: UIMessage[], proposals: ActionProposalView[], facts: StoredMessage[]): UIMessage[];
|
|
17
18
|
|
|
18
19
|
/** What a form control can hand over: a field's value, a checkbox's state, a picked date, a list. */
|
|
19
20
|
type RawAnswer = string | number | boolean | Date | null | undefined | readonly RawAnswer[];
|
|
@@ -595,102 +596,6 @@ declare function describeTimestamp(createdAt: string | null | undefined): Timest
|
|
|
595
596
|
*/
|
|
596
597
|
declare function formatRelativeTime(date: Date): string;
|
|
597
598
|
|
|
598
|
-
/** The `ui` frame component a composed tree is pushed under (`GENUI_TREE_COMPONENT` of `@dudousxd/nestjs-agent-core/genui`). */
|
|
599
|
-
declare const GENUI_TREE_COMPONENT = "genui:tree";
|
|
600
|
-
/** One pushed component, normalized from whatever carried it (a transcript block, a `data-ui` part, a stored entry). */
|
|
601
|
-
interface GenerativeUIItem {
|
|
602
|
-
fallbackText?: string;
|
|
603
|
-
componentVersions?: Record<string, number>;
|
|
604
|
-
id: string;
|
|
605
|
-
component: string;
|
|
606
|
-
props: Record<string, unknown>;
|
|
607
|
-
version: number | null;
|
|
608
|
-
toolCallId: string | null;
|
|
609
|
-
}
|
|
610
|
-
/** A node of a composed tree (`genui:tree` frames): `{ type, props, children? }`. */
|
|
611
|
-
interface GenerativeUIElement {
|
|
612
|
-
type: string;
|
|
613
|
-
props: Record<string, unknown>;
|
|
614
|
-
children?: GenerativeUIElement[];
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* An app's renderer for one component: it receives the component's props spread, plus `children`
|
|
618
|
-
* when it is a layout node in a tree. Any React component — the library never styles anything.
|
|
619
|
-
*/
|
|
620
|
-
type GenuiRenderer<P = any> = ComponentType<P & {
|
|
621
|
-
children?: ReactNode;
|
|
622
|
-
}>;
|
|
623
|
-
/** Component name → the app's renderer. */
|
|
624
|
-
type GenuiRegistry = Record<string, GenuiRenderer>;
|
|
625
|
-
/**
|
|
626
|
-
* Resolve a component the registry does not have — typically a tenant's own component, fetched for
|
|
627
|
-
* the exact `version` a message was rendered with. Return `null`/`undefined` for "no such
|
|
628
|
-
* component". May be async; results are cached per resolver, name and version.
|
|
629
|
-
*/
|
|
630
|
-
type ResolveComponent = (name: string, version: number | null) => GenuiRenderer | null | undefined | Promise<GenuiRenderer | null | undefined>;
|
|
631
|
-
interface GenuiIssueLike {
|
|
632
|
-
path: (string | number)[];
|
|
633
|
-
message: string;
|
|
634
|
-
}
|
|
635
|
-
type ValidationLike = {
|
|
636
|
-
ok: true;
|
|
637
|
-
value: Record<string, unknown>;
|
|
638
|
-
} | {
|
|
639
|
-
ok: false;
|
|
640
|
-
issues: GenuiIssueLike[];
|
|
641
|
-
};
|
|
642
|
-
/**
|
|
643
|
-
* What the renderer needs from a catalog to validate props before drawing them. A `Catalog` from
|
|
644
|
-
* `@dudousxd/nestjs-agent-core/genui` satisfies it; declared structurally so any catalog-shaped
|
|
645
|
-
* object does too.
|
|
646
|
-
*/
|
|
647
|
-
interface GenuiCatalogLike {
|
|
648
|
-
get?(name: string): {
|
|
649
|
-
version?: number;
|
|
650
|
-
} | undefined;
|
|
651
|
-
has(name: string): boolean;
|
|
652
|
-
validate(name: string, props: unknown): Promise<ValidationLike>;
|
|
653
|
-
validateSync?(name: string, props: unknown): ValidationLike | undefined;
|
|
654
|
-
}
|
|
655
|
-
interface GenerativeUIOptions {
|
|
656
|
-
registry: GenuiRegistry;
|
|
657
|
-
/** Validate props against it before rendering. Components the catalog does not know render unvalidated. */
|
|
658
|
-
catalog?: GenuiCatalogLike;
|
|
659
|
-
resolveComponent?: ResolveComponent;
|
|
660
|
-
/**
|
|
661
|
-
* Draws a composed tree frame (`genui:tree`) whole — e.g. through json-render (see the
|
|
662
|
-
* `/genui/json-render` subpath's `GenuiProvider`). Omitted → trees render node by node through
|
|
663
|
-
* `registry`.
|
|
664
|
-
*/
|
|
665
|
-
treeRenderer?: GenuiRenderer<{
|
|
666
|
-
root?: GenerativeUIElement;
|
|
667
|
-
}>;
|
|
668
|
-
}
|
|
669
|
-
/** Why an item did not render. */
|
|
670
|
-
type GenerativeUIProblem = {
|
|
671
|
-
reason: 'unknown';
|
|
672
|
-
item: GenerativeUIItem;
|
|
673
|
-
} | {
|
|
674
|
-
reason: 'invalid';
|
|
675
|
-
item: GenerativeUIItem;
|
|
676
|
-
issues: GenuiIssueLike[];
|
|
677
|
-
} | {
|
|
678
|
-
reason: 'error';
|
|
679
|
-
item: GenerativeUIItem;
|
|
680
|
-
error: unknown;
|
|
681
|
-
};
|
|
682
|
-
type GenerativeUIState = {
|
|
683
|
-
status: 'ready';
|
|
684
|
-
item: GenerativeUIItem;
|
|
685
|
-
Component: GenuiRenderer;
|
|
686
|
-
props: Record<string, unknown>;
|
|
687
|
-
} | {
|
|
688
|
-
status: 'loading';
|
|
689
|
-
item: GenerativeUIItem;
|
|
690
|
-
} | ({
|
|
691
|
-
status: 'problem';
|
|
692
|
-
} & GenerativeUIProblem);
|
|
693
|
-
|
|
694
599
|
/** What to draw instead of a component that did not render. Default: nothing. */
|
|
695
600
|
type GenerativeUIFallback = ReactNode | ((problem: GenerativeUIProblem) => ReactNode);
|
|
696
601
|
/**
|
|
@@ -764,4 +669,4 @@ interface GenerativeUIProps extends Partial<GenerativeUIOptions> {
|
|
|
764
669
|
*/
|
|
765
670
|
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;
|
|
766
671
|
|
|
767
|
-
export {
|
|
672
|
+
export { correctedCallIds as $, type ApproveOptions as A, type BuildBlocksOptions as B, type ChatStatus as C, type DescribeToolCallOptions as D, type ElicitationBlockOptions as E, type TranscriptApproval as F, GenerativeUI as G, type TranscriptApprovalStatus as H, type TranscriptElicitationBlock as I, type TranscriptElicitationOutcome as J, type TranscriptFilesBlock as K, type TranscriptQuestion as L, type MessageUsageInfo as M, type TranscriptQuestionOption as N, type TranscriptReasoningBlock as O, type TranscriptSettleState as P, type TranscriptSource as Q, type RawAnswer as R, type SettleAction as S, type TranscriptUiBlock as T, type UsageSummary as U, type TranscriptSourcesBlock as V, type TranscriptTextBlock as W, type TranscriptToolBlock as X, type TranscriptToolCall as Y, buildTranscriptBlocks as Z, coerceAnswer as _, type GenerativeUIFallback as a, describeTimestamp as a0, describeToolCall as a1, describeUsage as a2, extractMessageText as a3, fillTemplate as a4, formatRelativeTime as a5, groupToolActivity as a6, inferResultView as a7, isActionCall as a8, phraseFor as a9, proposalNeedsPolling as aa, readPath as ab, reconcileProposalMessages as ac, resolveResultView as ad, toolCallState as ae, toolCatalogFrom as af, type GenerativeUIProps as b, GenerativeUIScope as c, type GenerativeUIScopeProps as d, GenuiProvider as e, type GenuiProviderProps as f, type GenuiProviderValue as g, GenuiTree as h, useGenuiProvider as i, type ApprovalTarget as j, type TranscriptBlock as k, type TimestampInfo as l, type TranscriptFile as m, type ToolCatalog as n, type AnyToolUIPart as o, type ApprovalBlockOptions as p, type CoercibleQuestion as q, type GroupToolActivityOptions as r, type ResolvedReading as s, type ResolvedResultView as t, useGenerativeUI as u, type RetrievedPassage as v, type ToolActivityGroup as w, type ToolCallDescription as x, type ToolCallState as y, type ToolCallStatus as z };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ActionProposalView, StoredMessage, ElicitationQuestion, ElicitationInputType, ToolPresentation, ToolCatalogEntry, ToolResultField, ToolResultView, ToolPresentationTone, ToolConfirmation, ElicitationInput } from '@dudousxd/nestjs-agent-core';
|
|
4
4
|
import { UIMessage, ToolUIPart, DynamicToolUIPart } from 'ai';
|
|
5
|
+
import { c as GenerativeUIOptions, G as GenerativeUIItem, d as GenerativeUIProblem, b as GenerativeUIElement, e as GenerativeUIState } from './types-DZtFsWec.js';
|
|
5
6
|
|
|
6
7
|
type ApprovalTarget = {
|
|
7
8
|
kind: 'legacy';
|
|
@@ -11,9 +12,9 @@ type ApprovalTarget = {
|
|
|
11
12
|
proposalId: string;
|
|
12
13
|
threadId?: string;
|
|
13
14
|
};
|
|
14
|
-
declare function proposalNeedsPolling(proposal:
|
|
15
|
+
declare function proposalNeedsPolling(proposal: ActionProposalView): boolean;
|
|
15
16
|
/** Patch proposal metadata and append outcome facts; never replace live text with stored rows. */
|
|
16
|
-
declare function reconcileProposalMessages(current: UIMessage[], proposals:
|
|
17
|
+
declare function reconcileProposalMessages(current: UIMessage[], proposals: ActionProposalView[], facts: StoredMessage[]): UIMessage[];
|
|
17
18
|
|
|
18
19
|
/** What a form control can hand over: a field's value, a checkbox's state, a picked date, a list. */
|
|
19
20
|
type RawAnswer = string | number | boolean | Date | null | undefined | readonly RawAnswer[];
|
|
@@ -595,102 +596,6 @@ declare function describeTimestamp(createdAt: string | null | undefined): Timest
|
|
|
595
596
|
*/
|
|
596
597
|
declare function formatRelativeTime(date: Date): string;
|
|
597
598
|
|
|
598
|
-
/** The `ui` frame component a composed tree is pushed under (`GENUI_TREE_COMPONENT` of `@dudousxd/nestjs-agent-core/genui`). */
|
|
599
|
-
declare const GENUI_TREE_COMPONENT = "genui:tree";
|
|
600
|
-
/** One pushed component, normalized from whatever carried it (a transcript block, a `data-ui` part, a stored entry). */
|
|
601
|
-
interface GenerativeUIItem {
|
|
602
|
-
fallbackText?: string;
|
|
603
|
-
componentVersions?: Record<string, number>;
|
|
604
|
-
id: string;
|
|
605
|
-
component: string;
|
|
606
|
-
props: Record<string, unknown>;
|
|
607
|
-
version: number | null;
|
|
608
|
-
toolCallId: string | null;
|
|
609
|
-
}
|
|
610
|
-
/** A node of a composed tree (`genui:tree` frames): `{ type, props, children? }`. */
|
|
611
|
-
interface GenerativeUIElement {
|
|
612
|
-
type: string;
|
|
613
|
-
props: Record<string, unknown>;
|
|
614
|
-
children?: GenerativeUIElement[];
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* An app's renderer for one component: it receives the component's props spread, plus `children`
|
|
618
|
-
* when it is a layout node in a tree. Any React component — the library never styles anything.
|
|
619
|
-
*/
|
|
620
|
-
type GenuiRenderer<P = any> = ComponentType<P & {
|
|
621
|
-
children?: ReactNode;
|
|
622
|
-
}>;
|
|
623
|
-
/** Component name → the app's renderer. */
|
|
624
|
-
type GenuiRegistry = Record<string, GenuiRenderer>;
|
|
625
|
-
/**
|
|
626
|
-
* Resolve a component the registry does not have — typically a tenant's own component, fetched for
|
|
627
|
-
* the exact `version` a message was rendered with. Return `null`/`undefined` for "no such
|
|
628
|
-
* component". May be async; results are cached per resolver, name and version.
|
|
629
|
-
*/
|
|
630
|
-
type ResolveComponent = (name: string, version: number | null) => GenuiRenderer | null | undefined | Promise<GenuiRenderer | null | undefined>;
|
|
631
|
-
interface GenuiIssueLike {
|
|
632
|
-
path: (string | number)[];
|
|
633
|
-
message: string;
|
|
634
|
-
}
|
|
635
|
-
type ValidationLike = {
|
|
636
|
-
ok: true;
|
|
637
|
-
value: Record<string, unknown>;
|
|
638
|
-
} | {
|
|
639
|
-
ok: false;
|
|
640
|
-
issues: GenuiIssueLike[];
|
|
641
|
-
};
|
|
642
|
-
/**
|
|
643
|
-
* What the renderer needs from a catalog to validate props before drawing them. A `Catalog` from
|
|
644
|
-
* `@dudousxd/nestjs-agent-core/genui` satisfies it; declared structurally so any catalog-shaped
|
|
645
|
-
* object does too.
|
|
646
|
-
*/
|
|
647
|
-
interface GenuiCatalogLike {
|
|
648
|
-
get?(name: string): {
|
|
649
|
-
version?: number;
|
|
650
|
-
} | undefined;
|
|
651
|
-
has(name: string): boolean;
|
|
652
|
-
validate(name: string, props: unknown): Promise<ValidationLike>;
|
|
653
|
-
validateSync?(name: string, props: unknown): ValidationLike | undefined;
|
|
654
|
-
}
|
|
655
|
-
interface GenerativeUIOptions {
|
|
656
|
-
registry: GenuiRegistry;
|
|
657
|
-
/** Validate props against it before rendering. Components the catalog does not know render unvalidated. */
|
|
658
|
-
catalog?: GenuiCatalogLike;
|
|
659
|
-
resolveComponent?: ResolveComponent;
|
|
660
|
-
/**
|
|
661
|
-
* Draws a composed tree frame (`genui:tree`) whole — e.g. through json-render (see the
|
|
662
|
-
* `/genui/json-render` subpath's `GenuiProvider`). Omitted → trees render node by node through
|
|
663
|
-
* `registry`.
|
|
664
|
-
*/
|
|
665
|
-
treeRenderer?: GenuiRenderer<{
|
|
666
|
-
root?: GenerativeUIElement;
|
|
667
|
-
}>;
|
|
668
|
-
}
|
|
669
|
-
/** Why an item did not render. */
|
|
670
|
-
type GenerativeUIProblem = {
|
|
671
|
-
reason: 'unknown';
|
|
672
|
-
item: GenerativeUIItem;
|
|
673
|
-
} | {
|
|
674
|
-
reason: 'invalid';
|
|
675
|
-
item: GenerativeUIItem;
|
|
676
|
-
issues: GenuiIssueLike[];
|
|
677
|
-
} | {
|
|
678
|
-
reason: 'error';
|
|
679
|
-
item: GenerativeUIItem;
|
|
680
|
-
error: unknown;
|
|
681
|
-
};
|
|
682
|
-
type GenerativeUIState = {
|
|
683
|
-
status: 'ready';
|
|
684
|
-
item: GenerativeUIItem;
|
|
685
|
-
Component: GenuiRenderer;
|
|
686
|
-
props: Record<string, unknown>;
|
|
687
|
-
} | {
|
|
688
|
-
status: 'loading';
|
|
689
|
-
item: GenerativeUIItem;
|
|
690
|
-
} | ({
|
|
691
|
-
status: 'problem';
|
|
692
|
-
} & GenerativeUIProblem);
|
|
693
|
-
|
|
694
599
|
/** What to draw instead of a component that did not render. Default: nothing. */
|
|
695
600
|
type GenerativeUIFallback = ReactNode | ((problem: GenerativeUIProblem) => ReactNode);
|
|
696
601
|
/**
|
|
@@ -764,4 +669,4 @@ interface GenerativeUIProps extends Partial<GenerativeUIOptions> {
|
|
|
764
669
|
*/
|
|
765
670
|
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;
|
|
766
671
|
|
|
767
|
-
export {
|
|
672
|
+
export { correctedCallIds as $, type ApproveOptions as A, type BuildBlocksOptions as B, type ChatStatus as C, type DescribeToolCallOptions as D, type ElicitationBlockOptions as E, type TranscriptApproval as F, GenerativeUI as G, type TranscriptApprovalStatus as H, type TranscriptElicitationBlock as I, type TranscriptElicitationOutcome as J, type TranscriptFilesBlock as K, type TranscriptQuestion as L, type MessageUsageInfo as M, type TranscriptQuestionOption as N, type TranscriptReasoningBlock as O, type TranscriptSettleState as P, type TranscriptSource as Q, type RawAnswer as R, type SettleAction as S, type TranscriptUiBlock as T, type UsageSummary as U, type TranscriptSourcesBlock as V, type TranscriptTextBlock as W, type TranscriptToolBlock as X, type TranscriptToolCall as Y, buildTranscriptBlocks as Z, coerceAnswer as _, type GenerativeUIFallback as a, describeTimestamp as a0, describeToolCall as a1, describeUsage as a2, extractMessageText as a3, fillTemplate as a4, formatRelativeTime as a5, groupToolActivity as a6, inferResultView as a7, isActionCall as a8, phraseFor as a9, proposalNeedsPolling as aa, readPath as ab, reconcileProposalMessages as ac, resolveResultView as ad, toolCallState as ae, toolCatalogFrom as af, type GenerativeUIProps as b, GenerativeUIScope as c, type GenerativeUIScopeProps as d, GenuiProvider as e, type GenuiProviderProps as f, type GenuiProviderValue as g, GenuiTree as h, useGenuiProvider as i, type ApprovalTarget as j, type TranscriptBlock as k, type TimestampInfo as l, type TranscriptFile as m, type ToolCatalog as n, type AnyToolUIPart as o, type ApprovalBlockOptions as p, type CoercibleQuestion as q, type GroupToolActivityOptions as r, type ResolvedReading as s, type ResolvedResultView as t, useGenerativeUI as u, type RetrievedPassage as v, type ToolActivityGroup as w, type ToolCallDescription as x, type ToolCallState as y, type ToolCallStatus as z };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ComponentRegistry } from '@json-render/react';
|
|
3
|
-
import {
|
|
3
|
+
import { f as GenuiProviderProps$1 } from './generative-ui-CyHY8Lh1.cjs';
|
|
4
|
+
import { b as GenerativeUIElement, i as GenuiRenderer, h as GenuiRegistry } from './types-DZtFsWec.cjs';
|
|
4
5
|
import '@dudousxd/nestjs-agent-core';
|
|
5
6
|
import 'ai';
|
|
6
7
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ComponentRegistry } from '@json-render/react';
|
|
3
|
-
import {
|
|
3
|
+
import { f as GenuiProviderProps$1 } from './generative-ui-DdUZPCXX.js';
|
|
4
|
+
import { b as GenerativeUIElement, i as GenuiRenderer, h as GenuiRegistry } from './types-DZtFsWec.js';
|
|
4
5
|
import '@dudousxd/nestjs-agent-core';
|
|
5
6
|
import 'ai';
|
|
6
7
|
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/genui/playwright.ts
|
|
31
|
+
var playwright_exports = {};
|
|
32
|
+
__export(playwright_exports, {
|
|
33
|
+
createPlaywrightCaptureAdapter: () => createPlaywrightCaptureAdapter
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(playwright_exports);
|
|
36
|
+
|
|
37
|
+
// src/genui/server.ts
|
|
38
|
+
var import_promises = require("fs/promises");
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var import_server = require("react-dom/server");
|
|
41
|
+
function boundedCaptureOptions(options) {
|
|
42
|
+
const result = {
|
|
43
|
+
width: options.width ?? 1200,
|
|
44
|
+
height: options.height ?? 1600,
|
|
45
|
+
timeoutMs: options.timeoutMs ?? 15e3
|
|
46
|
+
};
|
|
47
|
+
for (const [key, value, min, max] of [
|
|
48
|
+
["width", result.width, 320, 4096],
|
|
49
|
+
["height", result.height, 200, 16384],
|
|
50
|
+
["timeoutMs", result.timeoutMs, 100, 6e4]
|
|
51
|
+
]) {
|
|
52
|
+
if (!Number.isInteger(value) || value < min || value > max)
|
|
53
|
+
throw new RangeError(`genui: ${key} must be ${min}\u2013${max}`);
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/genui/playwright.ts
|
|
59
|
+
function createPlaywrightCaptureAdapter(options = {}) {
|
|
60
|
+
async function withPage(settings, operation) {
|
|
61
|
+
const limits = boundedCaptureOptions(settings);
|
|
62
|
+
const browser = options.browser ?? await (await import("playwright-core")).chromium.launch(options.launchOptions);
|
|
63
|
+
try {
|
|
64
|
+
const context = await browser.newContext({
|
|
65
|
+
javaScriptEnabled: false,
|
|
66
|
+
serviceWorkers: "block",
|
|
67
|
+
viewport: { width: limits.width, height: limits.height }
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
const page = await context.newPage();
|
|
71
|
+
try {
|
|
72
|
+
page.setDefaultTimeout(limits.timeoutMs);
|
|
73
|
+
await context.route("**/*", async (route) => {
|
|
74
|
+
try {
|
|
75
|
+
if (!options.allowAsset?.(route.request().url())) {
|
|
76
|
+
await route.abort();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const response = await route.fetch({ maxRedirects: 0, timeout: limits.timeoutMs });
|
|
80
|
+
try {
|
|
81
|
+
if (response.status() >= 300 && response.status() < 400) {
|
|
82
|
+
await route.abort();
|
|
83
|
+
} else {
|
|
84
|
+
await route.fulfill({ response });
|
|
85
|
+
}
|
|
86
|
+
} finally {
|
|
87
|
+
await response.dispose();
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
await route.abort();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
let timer;
|
|
94
|
+
try {
|
|
95
|
+
return await Promise.race([
|
|
96
|
+
operation(page, limits),
|
|
97
|
+
new Promise((_, reject) => {
|
|
98
|
+
timer = setTimeout(
|
|
99
|
+
() => reject(new Error("genui: capture timed out")),
|
|
100
|
+
limits.timeoutMs
|
|
101
|
+
);
|
|
102
|
+
})
|
|
103
|
+
]);
|
|
104
|
+
} finally {
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
}
|
|
107
|
+
} finally {
|
|
108
|
+
await page.close();
|
|
109
|
+
}
|
|
110
|
+
} finally {
|
|
111
|
+
await context.close();
|
|
112
|
+
}
|
|
113
|
+
} finally {
|
|
114
|
+
if (!options.browser) await browser.close();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function checkPages(html) {
|
|
118
|
+
if (!html.length || html.length > 100)
|
|
119
|
+
throw new RangeError("genui: capture requires 1\u2013100 pages");
|
|
120
|
+
}
|
|
121
|
+
async function ready(page, html, limits) {
|
|
122
|
+
await page.setContent(html, { waitUntil: "load", timeout: limits.timeoutMs });
|
|
123
|
+
await page.evaluate(async (timeoutMs) => {
|
|
124
|
+
let timer;
|
|
125
|
+
try {
|
|
126
|
+
await Promise.race([
|
|
127
|
+
Promise.all([
|
|
128
|
+
document.fonts.ready,
|
|
129
|
+
...Array.from(
|
|
130
|
+
document.images,
|
|
131
|
+
(image) => image.complete ? Promise.resolve() : new Promise((resolve) => {
|
|
132
|
+
image.addEventListener("load", () => resolve(), { once: true });
|
|
133
|
+
image.addEventListener("error", () => resolve(), { once: true });
|
|
134
|
+
})
|
|
135
|
+
)
|
|
136
|
+
]),
|
|
137
|
+
new Promise((_, reject) => {
|
|
138
|
+
timer = setTimeout(() => reject(new Error("genui: assets timed out")), timeoutMs);
|
|
139
|
+
})
|
|
140
|
+
]);
|
|
141
|
+
} finally {
|
|
142
|
+
clearTimeout(timer);
|
|
143
|
+
}
|
|
144
|
+
}, limits.timeoutMs);
|
|
145
|
+
const height = await page.evaluate(
|
|
146
|
+
() => Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
|
|
147
|
+
);
|
|
148
|
+
if (height > limits.height)
|
|
149
|
+
throw new RangeError(
|
|
150
|
+
"genui: content exceeds capture height; reduce rowsPerPage or paginate the component"
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
async images(html, settings) {
|
|
155
|
+
checkPages(html);
|
|
156
|
+
return withPage(settings, async (page, limits) => {
|
|
157
|
+
const images = [];
|
|
158
|
+
for (const content of html) {
|
|
159
|
+
await ready(page, content, limits);
|
|
160
|
+
images.push(
|
|
161
|
+
await page.screenshot({ type: "png", fullPage: true, timeout: limits.timeoutMs })
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return images;
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
async pdf(html, settings) {
|
|
168
|
+
checkPages(html);
|
|
169
|
+
return withPage(settings, async (page, limits) => {
|
|
170
|
+
const escapeAttribute = (value) => value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
171
|
+
const pdfDocument = `<!doctype html><html><head><style>@page { size: ${limits.width}px ${limits.height}px; margin: 0 } body { margin: 0 } iframe { display:block; border:0; width:${limits.width}px; height:${limits.height}px; break-after:page } iframe:last-child { break-after:auto }</style></head><body>${html.map((content) => `<iframe sandbox="allow-same-origin" srcdoc="${escapeAttribute(content)}"></iframe>`).join("")}</body></html>`;
|
|
172
|
+
await page.setContent(pdfDocument, { waitUntil: "load", timeout: limits.timeoutMs });
|
|
173
|
+
for (const frame of page.frames().slice(1)) {
|
|
174
|
+
await frame.evaluate(async () => {
|
|
175
|
+
await document.fonts.ready;
|
|
176
|
+
await Promise.all(
|
|
177
|
+
Array.from(document.images, (image) => image.decode().catch(() => {
|
|
178
|
+
}))
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
const height = await frame.evaluate(() => document.documentElement.scrollHeight);
|
|
182
|
+
if (height > limits.height)
|
|
183
|
+
throw new RangeError("genui: content exceeds PDF page height; reduce rowsPerPage");
|
|
184
|
+
}
|
|
185
|
+
return page.pdf({
|
|
186
|
+
width: `${limits.width}px`,
|
|
187
|
+
height: `${limits.height}px`,
|
|
188
|
+
printBackground: true,
|
|
189
|
+
preferCSSPageSize: true
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
196
|
+
0 && (module.exports = {
|
|
197
|
+
createPlaywrightCaptureAdapter
|
|
198
|
+
});
|
|
199
|
+
//# sourceMappingURL=genui-server-playwright.cjs.map
|