@assistant-ui/react-generative-ui 0.0.6 → 0.0.7
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/JSONGenerativeUI.client.d.ts +4 -1
- package/dist/JSONGenerativeUI.client.d.ts.map +1 -1
- package/dist/JSONGenerativeUI.client.js +9 -2
- package/dist/JSONGenerativeUI.client.js.map +1 -1
- package/dist/JSONGenerativeUI.shared.d.ts +8 -0
- package/dist/JSONGenerativeUI.shared.d.ts.map +1 -1
- package/dist/JSONGenerativeUI.shared.js.map +1 -1
- package/dist/actionRegistry.d.ts +41 -0
- package/dist/actionRegistry.d.ts.map +1 -0
- package/dist/actionRegistry.js +41 -0
- package/dist/actionRegistry.js.map +1 -0
- package/dist/buildPresentParameters.js +10 -1
- package/dist/buildPresentParameters.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +5 -2
- package/dist/index.server.d.ts +12 -0
- package/dist/index.server.js +10 -0
- package/dist/index.shared.d.ts +11 -0
- package/dist/index.shared.js +9 -0
- package/dist/ir.d.ts +115 -0
- package/dist/ir.d.ts.map +1 -0
- package/dist/ir.js +149 -0
- package/dist/ir.js.map +1 -0
- package/dist/renderGenerativeUI.d.ts +5 -4
- package/dist/renderGenerativeUI.d.ts.map +1 -1
- package/dist/renderGenerativeUI.js +18 -45
- package/dist/renderGenerativeUI.js.map +1 -1
- package/dist/types.d.ts +34 -30
- package/dist/types.d.ts.map +1 -1
- package/dist/vocabulary/alert.d.ts +34 -0
- package/dist/vocabulary/alert.d.ts.map +1 -0
- package/dist/vocabulary/alert.js +49 -0
- package/dist/vocabulary/alert.js.map +1 -0
- package/dist/vocabulary/data.d.ts +53 -0
- package/dist/vocabulary/data.d.ts.map +1 -0
- package/dist/vocabulary/data.js +63 -0
- package/dist/vocabulary/data.js.map +1 -0
- package/dist/vocabulary/fact.d.ts +20 -0
- package/dist/vocabulary/fact.d.ts.map +1 -0
- package/dist/vocabulary/fact.js +24 -0
- package/dist/vocabulary/fact.js.map +1 -0
- package/dist/vocabulary/index.d.ts +16 -0
- package/dist/vocabulary/index.d.ts.map +1 -0
- package/dist/vocabulary/index.js +30 -0
- package/dist/vocabulary/index.js.map +1 -0
- package/dist/vocabulary/interactive.d.ts +81 -0
- package/dist/vocabulary/interactive.d.ts.map +1 -0
- package/dist/vocabulary/interactive.js +123 -0
- package/dist/vocabulary/interactive.js.map +1 -0
- package/dist/vocabulary/layout.d.ts +78 -0
- package/dist/vocabulary/layout.d.ts.map +1 -0
- package/dist/vocabulary/layout.js +72 -0
- package/dist/vocabulary/layout.js.map +1 -0
- package/dist/vocabulary/media.d.ts +34 -0
- package/dist/vocabulary/media.d.ts.map +1 -0
- package/dist/vocabulary/media.js +32 -0
- package/dist/vocabulary/media.js.map +1 -0
- package/dist/vocabulary/text.d.ts +74 -0
- package/dist/vocabulary/text.d.ts.map +1 -0
- package/dist/vocabulary/text.js +48 -0
- package/dist/vocabulary/text.js.map +1 -0
- package/package.json +12 -12
- package/src/JSONGenerativeUI.client.tsx +10 -2
- package/src/JSONGenerativeUI.shared.ts +8 -0
- package/src/actionRegistry.test.ts +90 -0
- package/src/actionRegistry.ts +96 -0
- package/src/buildPresentParameters.ts +23 -7
- package/src/index.server.ts +2 -0
- package/src/index.shared.ts +58 -0
- package/src/index.ts +2 -26
- package/src/ir.test.ts +203 -0
- package/src/ir.ts +253 -0
- package/src/renderGenerativeUI.test.tsx +53 -0
- package/src/renderGenerativeUI.tsx +49 -82
- package/src/types.ts +57 -42
- package/src/vocabulary/alert.test.tsx +66 -0
- package/src/vocabulary/alert.tsx +47 -0
- package/src/vocabulary/data.test.tsx +67 -0
- package/src/vocabulary/data.tsx +86 -0
- package/src/vocabulary/fact.test.tsx +15 -0
- package/src/vocabulary/fact.tsx +22 -0
- package/src/vocabulary/index.test.ts +56 -0
- package/src/vocabulary/index.ts +27 -0
- package/src/vocabulary/interactive.dispatch.test.tsx +110 -0
- package/src/vocabulary/interactive.test.tsx +108 -0
- package/src/vocabulary/interactive.tsx +165 -0
- package/src/vocabulary/layout.test.tsx +61 -0
- package/src/vocabulary/layout.tsx +76 -0
- package/src/vocabulary/media.test.tsx +53 -0
- package/src/vocabulary/media.tsx +37 -0
- package/src/vocabulary/text.test.tsx +73 -0
- package/src/vocabulary/text.tsx +59 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
3
|
+
import { renderGenerativeUI } from "../renderGenerativeUI";
|
|
4
|
+
import { textVocabulary } from "./text";
|
|
5
|
+
|
|
6
|
+
const render = (node: unknown) =>
|
|
7
|
+
renderToStaticMarkup(<>{renderGenerativeUI(node, textVocabulary)}</>);
|
|
8
|
+
|
|
9
|
+
describe("textVocabulary", () => {
|
|
10
|
+
it("Header renders an h2 with the text and a size hook", () => {
|
|
11
|
+
expect(render({ $type: "Header", text: "Title", size: "xl" })).toBe(
|
|
12
|
+
'<h2 data-aui="header" data-aui-size="xl">Title</h2>',
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("Header defaults size to lg when omitted", () => {
|
|
17
|
+
expect(render({ $type: "Header", text: "Title" })).toBe(
|
|
18
|
+
'<h2 data-aui="header" data-aui-size="lg">Title</h2>',
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("Text renders a span with size/weight/color hooks and the value", () => {
|
|
23
|
+
expect(
|
|
24
|
+
render({
|
|
25
|
+
$type: "Text",
|
|
26
|
+
value: "hi",
|
|
27
|
+
size: "sm",
|
|
28
|
+
weight: "bold",
|
|
29
|
+
color: "secondary",
|
|
30
|
+
}),
|
|
31
|
+
).toBe(
|
|
32
|
+
'<span data-aui="text" data-aui-size="sm" data-aui-weight="bold" data-aui-color="secondary">hi</span>',
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("Text defaults size to md and leaves weight/color undefined", () => {
|
|
37
|
+
expect(render({ $type: "Text", value: "hi" })).toBe(
|
|
38
|
+
'<span data-aui="text" data-aui-size="md">hi</span>',
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("Text renders partial value while streaming (streamProperties: true)", () => {
|
|
43
|
+
expect(
|
|
44
|
+
renderToStaticMarkup(
|
|
45
|
+
<>
|
|
46
|
+
{renderGenerativeUI(
|
|
47
|
+
{ $type: "Text", value: "partial" },
|
|
48
|
+
textVocabulary,
|
|
49
|
+
{ status: "streaming" },
|
|
50
|
+
)}
|
|
51
|
+
</>,
|
|
52
|
+
),
|
|
53
|
+
).toBe('<span data-aui="text" data-aui-size="md">partial</span>');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("Text renders nested children (span-in-span, valid HTML)", () => {
|
|
57
|
+
expect(
|
|
58
|
+
render({
|
|
59
|
+
$type: "Text",
|
|
60
|
+
value: "before",
|
|
61
|
+
children: { $type: "Text", value: "after" },
|
|
62
|
+
}),
|
|
63
|
+
).toBe(
|
|
64
|
+
'<span data-aui="text" data-aui-size="md">before<span data-aui="text" data-aui-size="md">after</span></span>',
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("Caption renders a p with the value", () => {
|
|
69
|
+
expect(render({ $type: "Caption", value: "muted note" })).toBe(
|
|
70
|
+
'<p data-aui="caption">muted note</p>',
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { GenerativeUILibrary } from "../types";
|
|
3
|
+
import { COLORS, TEXT_SIZES, WEIGHTS } from "../ir";
|
|
4
|
+
|
|
5
|
+
export const textVocabulary = {
|
|
6
|
+
Header: {
|
|
7
|
+
description: "A section heading. Renders as a bold title.",
|
|
8
|
+
properties: z.object({
|
|
9
|
+
text: z.string().describe("The heading text."),
|
|
10
|
+
size: z
|
|
11
|
+
.enum(TEXT_SIZES)
|
|
12
|
+
.optional()
|
|
13
|
+
.describe("Heading size; defaults to `lg`."),
|
|
14
|
+
}),
|
|
15
|
+
render: ({ text, size, children }) => (
|
|
16
|
+
<h2 data-aui="header" data-aui-size={size ?? "lg"}>
|
|
17
|
+
{text}
|
|
18
|
+
{children}
|
|
19
|
+
</h2>
|
|
20
|
+
),
|
|
21
|
+
},
|
|
22
|
+
Text: {
|
|
23
|
+
description: "A run of text. Use for paragraphs, labels, or inline copy.",
|
|
24
|
+
properties: z.object({
|
|
25
|
+
value: z.string().describe("The text content."),
|
|
26
|
+
size: z
|
|
27
|
+
.enum(TEXT_SIZES)
|
|
28
|
+
.optional()
|
|
29
|
+
.describe("Text size; defaults to `md`."),
|
|
30
|
+
weight: z.enum(WEIGHTS).optional().describe("Font weight."),
|
|
31
|
+
color: z.enum(COLORS).optional().describe("Foreground color token."),
|
|
32
|
+
}),
|
|
33
|
+
streamProperties: true,
|
|
34
|
+
render: ({ value, size, weight, color, children }) => (
|
|
35
|
+
<span
|
|
36
|
+
data-aui="text"
|
|
37
|
+
data-aui-size={size ?? "md"}
|
|
38
|
+
data-aui-weight={weight}
|
|
39
|
+
data-aui-color={color}
|
|
40
|
+
>
|
|
41
|
+
{value}
|
|
42
|
+
{children}
|
|
43
|
+
</span>
|
|
44
|
+
),
|
|
45
|
+
},
|
|
46
|
+
Caption: {
|
|
47
|
+
description: "Secondary, de-emphasized text under a primary element.",
|
|
48
|
+
properties: z.object({
|
|
49
|
+
value: z.string().describe("The caption text."),
|
|
50
|
+
}),
|
|
51
|
+
streamProperties: true,
|
|
52
|
+
render: ({ value, children }) => (
|
|
53
|
+
<p data-aui="caption">
|
|
54
|
+
{value}
|
|
55
|
+
{children}
|
|
56
|
+
</p>
|
|
57
|
+
),
|
|
58
|
+
},
|
|
59
|
+
} satisfies GenerativeUILibrary;
|