@gram-ai/elements 1.22.5 → 1.23.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/dist/components/Chat/stories/Plugins.stories.d.ts +6 -0
- package/dist/components/Chat/stories/Tools.stories.d.ts +15 -0
- package/dist/components/assistant-ui/connection-status-indicator.d.ts +16 -0
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/buttonVariants.d.ts +1 -1
- package/dist/components/ui/generative-ui.d.ts +13 -0
- package/dist/contexts/ConnectionStatusContext.d.ts +27 -0
- package/dist/contexts/ToolExecutionContext.d.ts +21 -0
- package/dist/elements.cjs +1 -1
- package/dist/elements.css +1 -1
- package/dist/elements.js +2 -2
- package/dist/{index-Dip7A_UI.cjs → index-CVYyyxfm.cjs} +43 -43
- package/dist/index-CVYyyxfm.cjs.map +1 -0
- package/dist/index-Co05S1C8.cjs +251 -0
- package/dist/index-Co05S1C8.cjs.map +1 -0
- package/dist/{index-D_ZJq5T1.js → index-D-QXb5EF.js} +10930 -10799
- package/dist/index-D-QXb5EF.js.map +1 -0
- package/dist/{index-BdXdd2ZM.js → index-vM3v0unX.js} +8442 -7926
- package/dist/index-vM3v0unX.js.map +1 -0
- package/dist/lib/generative-ui.d.ts +9 -0
- package/dist/plugins/components/PluginLoadingState.d.ts +11 -0
- package/dist/plugins/components/index.d.ts +1 -0
- package/dist/plugins/generative-ui/component.d.ts +3 -0
- package/dist/plugins/generative-ui/index.d.ts +6 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.js +3 -2
- package/dist/{profiler-CTZ-4zgJ.js → profiler-D8-vgPGn.js} +2 -2
- package/dist/{profiler-CTZ-4zgJ.js.map → profiler-D8-vgPGn.js.map} +1 -1
- package/dist/{profiler-Cucmmy3i.cjs → profiler-Dshm-O8k.cjs} +2 -2
- package/dist/{profiler-Cucmmy3i.cjs.map → profiler-Dshm-O8k.cjs.map} +1 -1
- package/dist/{startRecording-4CwQzWU_.cjs → startRecording-2p7-xVUh.cjs} +2 -2
- package/dist/{startRecording-4CwQzWU_.cjs.map → startRecording-2p7-xVUh.cjs.map} +1 -1
- package/dist/{startRecording-DnSD-PJG.js → startRecording-DnWeZRhl.js} +2 -2
- package/dist/{startRecording-DnSD-PJG.js.map → startRecording-DnWeZRhl.js.map} +1 -1
- package/package.json +7 -2
- package/src/components/Chat/stories/Plugins.stories.tsx +116 -0
- package/src/components/Chat/stories/Tools.stories.tsx +122 -0
- package/src/components/assistant-ui/connection-status-indicator.tsx +134 -0
- package/src/components/assistant-ui/thread.tsx +3 -1
- package/src/components/ui/generative-ui.tsx +437 -0
- package/src/contexts/ConnectionStatusContext.tsx +158 -0
- package/src/contexts/ElementsProvider.tsx +133 -25
- package/src/contexts/ToolExecutionContext.tsx +101 -0
- package/src/lib/generative-ui.ts +18 -0
- package/src/plugins/chart/component.tsx +8 -8
- package/src/plugins/components/PluginLoadingState.tsx +35 -0
- package/src/plugins/components/index.ts +1 -0
- package/src/plugins/generative-ui/component.tsx +56 -0
- package/src/plugins/generative-ui/index.ts +153 -0
- package/src/plugins/index.ts +3 -1
- package/dist/index-BdXdd2ZM.js.map +0 -1
- package/dist/index-CNVoovK7.cjs +0 -111
- package/dist/index-CNVoovK7.cjs.map +0 -1
- package/dist/index-D_ZJq5T1.js.map +0 -1
- package/dist/index-Dip7A_UI.cjs.map +0 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Plugin } from '@/types/plugins'
|
|
2
|
+
import { GenerativeUIRenderer } from './component'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This plugin renders json-render UI trees as dynamic widgets.
|
|
6
|
+
* Use the language identifier 'ui' or 'json-render' in code blocks.
|
|
7
|
+
*/
|
|
8
|
+
export const generativeUI: Plugin = {
|
|
9
|
+
language: 'ui',
|
|
10
|
+
prompt: `WHEN TO USE UI VISUALIZATION:
|
|
11
|
+
Proactively render tool results and structured data as visual UI components whenever it would improve comprehension. Use the 'ui' code block format for:
|
|
12
|
+
- Tool results that return structured data (lists, objects, metrics)
|
|
13
|
+
- Data that benefits from visual hierarchy (dashboards, summaries)
|
|
14
|
+
- Information with multiple related fields (user profiles, order details)
|
|
15
|
+
- Anything with numbers, statuses, or progress that can be visualized
|
|
16
|
+
- Results that would otherwise be displayed as raw JSON or verbose text
|
|
17
|
+
|
|
18
|
+
Do NOT use UI for: simple text responses, single values, error messages, or when the user explicitly asks for raw data.
|
|
19
|
+
|
|
20
|
+
To render UI, output a json-render specification in a code block with the language identifier 'ui'.
|
|
21
|
+
|
|
22
|
+
CRITICAL JSON REQUIREMENTS:
|
|
23
|
+
- The code block MUST contain ONLY valid, parseable JSON
|
|
24
|
+
- NO comments (no // or /* */ anywhere)
|
|
25
|
+
- NO trailing commas
|
|
26
|
+
- Use double quotes for all strings and keys
|
|
27
|
+
- The JSON must start with { and end with }
|
|
28
|
+
|
|
29
|
+
AVAILABLE COMPONENTS:
|
|
30
|
+
|
|
31
|
+
Card - Container with optional title
|
|
32
|
+
props: { title?: string }
|
|
33
|
+
children: any components
|
|
34
|
+
|
|
35
|
+
Grid - Multi-column layout
|
|
36
|
+
props: { columns?: number } (default: 2)
|
|
37
|
+
children: any components
|
|
38
|
+
|
|
39
|
+
Stack - Vertical or horizontal flex layout
|
|
40
|
+
props: { direction?: "vertical" | "horizontal" } (default: "vertical")
|
|
41
|
+
children: any components
|
|
42
|
+
|
|
43
|
+
Metric - Displays a label and formatted value
|
|
44
|
+
props: { label: string, value: number, format?: "currency" | "percent" | "number" }
|
|
45
|
+
|
|
46
|
+
Table - Data table
|
|
47
|
+
props: { headers: string[], rows: any[][] }
|
|
48
|
+
|
|
49
|
+
Text - Text with variants
|
|
50
|
+
props: { content: string, variant?: "heading" | "body" | "caption" | "code" }
|
|
51
|
+
|
|
52
|
+
Badge - Status badge
|
|
53
|
+
props: { content: string, variant?: "default" | "success" | "warning" | "error" }
|
|
54
|
+
|
|
55
|
+
Progress - Progress bar
|
|
56
|
+
props: { value: number, max?: number, label?: string }
|
|
57
|
+
|
|
58
|
+
List - Bullet or numbered list
|
|
59
|
+
props: { items: string[], ordered?: boolean }
|
|
60
|
+
|
|
61
|
+
Divider - Horizontal line separator
|
|
62
|
+
|
|
63
|
+
ActionButton - Interactive button that triggers a tool call
|
|
64
|
+
props: {
|
|
65
|
+
label: string, // Button text
|
|
66
|
+
action: string, // Tool name to invoke when clicked
|
|
67
|
+
args?: object, // Arguments to pass to the tool
|
|
68
|
+
variant?: "default" | "secondary" | "outline" | "destructive"
|
|
69
|
+
}
|
|
70
|
+
NOTE: Only use ActionButton with tools you know are available
|
|
71
|
+
|
|
72
|
+
STRUCTURE:
|
|
73
|
+
Every UI spec is a tree with:
|
|
74
|
+
- "type": component name (required)
|
|
75
|
+
- "props": component properties (optional)
|
|
76
|
+
- "children": array of child components (optional)
|
|
77
|
+
|
|
78
|
+
EXAMPLE - DASHBOARD:
|
|
79
|
+
{
|
|
80
|
+
"type": "Card",
|
|
81
|
+
"props": { "title": "Sales Overview" },
|
|
82
|
+
"children": [
|
|
83
|
+
{
|
|
84
|
+
"type": "Grid",
|
|
85
|
+
"props": { "columns": 3 },
|
|
86
|
+
"children": [
|
|
87
|
+
{ "type": "Metric", "props": { "label": "Revenue", "value": 125000, "format": "currency" } },
|
|
88
|
+
{ "type": "Metric", "props": { "label": "Growth", "value": 0.15, "format": "percent" } },
|
|
89
|
+
{ "type": "Metric", "props": { "label": "Orders", "value": 1420, "format": "number" } }
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
{ "type": "Divider" },
|
|
93
|
+
{ "type": "Progress", "props": { "label": "Q1 Target", "value": 75, "max": 100 } }
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
EXAMPLE - TABLE:
|
|
98
|
+
{
|
|
99
|
+
"type": "Card",
|
|
100
|
+
"props": { "title": "Users" },
|
|
101
|
+
"children": [
|
|
102
|
+
{
|
|
103
|
+
"type": "Table",
|
|
104
|
+
"props": {
|
|
105
|
+
"headers": ["Name", "Email", "Status"],
|
|
106
|
+
"rows": [
|
|
107
|
+
["Alice", "alice@example.com", "Active"],
|
|
108
|
+
["Bob", "bob@example.com", "Pending"]
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
EXAMPLE - WITH ACTIONS:
|
|
116
|
+
{
|
|
117
|
+
"type": "Card",
|
|
118
|
+
"props": { "title": "Pending Request #123" },
|
|
119
|
+
"children": [
|
|
120
|
+
{ "type": "Text", "props": { "variant": "body" }, "children": [{ "type": "Text", "props": {}, "children": [] }] },
|
|
121
|
+
{
|
|
122
|
+
"type": "Stack",
|
|
123
|
+
"props": { "direction": "horizontal" },
|
|
124
|
+
"children": [
|
|
125
|
+
{ "type": "ActionButton", "props": { "label": "Approve", "action": "approve_request", "args": { "id": 123 } } },
|
|
126
|
+
{ "type": "ActionButton", "props": { "label": "Reject", "action": "reject_request", "args": { "id": 123 }, "variant": "destructive" } }
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
STYLE GUIDELINES:
|
|
133
|
+
- Prefer spacious, breathable layouts with adequate visual hierarchy
|
|
134
|
+
- Use Grid with 2-3 columns max for metrics; avoid cramming too many items
|
|
135
|
+
- Group related content in Cards with clear titles
|
|
136
|
+
- Use Dividers to separate logical sections
|
|
137
|
+
- Balance information density: show what matters, hide the noise
|
|
138
|
+
- For dashboards, lead with the most important metrics at the top
|
|
139
|
+
|
|
140
|
+
CONTENT GUIDELINES:
|
|
141
|
+
- Outside the code block, provide context and insights about the data
|
|
142
|
+
- Do not describe technical implementation details
|
|
143
|
+
- Focus on what the data means, not how it's displayed
|
|
144
|
+
|
|
145
|
+
ACTION RESULT HANDLING:
|
|
146
|
+
When you receive a message starting with "[Action completed]" or "[Action failed]", the user clicked an action button and the tool has already been executed. Provide a brief, friendly acknowledgment of what happened. Keep your response concise - one sentence is usually enough. Do not re-execute the action or ask if they want to do something they just did.
|
|
147
|
+
|
|
148
|
+
Examples:
|
|
149
|
+
- "[Action completed] approve_request: Request #123 approved" → "Done! Request #123 has been approved."
|
|
150
|
+
- "[Action failed] delete_task: Permission denied" → "I couldn't delete that task - looks like you don't have permission."`,
|
|
151
|
+
Component: GenerativeUIRenderer,
|
|
152
|
+
Header: undefined,
|
|
153
|
+
}
|
package/src/plugins/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from '@/types/plugins'
|
|
2
2
|
import { chart } from './chart'
|
|
3
|
+
import { generativeUI } from './generative-ui'
|
|
3
4
|
|
|
4
|
-
export const recommended: Plugin[] = [chart]
|
|
5
|
+
export const recommended: Plugin[] = [chart, generativeUI]
|
|
5
6
|
export { chart } from './chart'
|
|
7
|
+
export { generativeUI } from './generative-ui'
|
|
6
8
|
|
|
7
9
|
export type { Plugin } from '@/types/plugins'
|