@gram-ai/elements 1.10.0 → 1.12.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 +103 -0
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/buttonVariants.d.ts +1 -1
- package/dist/elements.cjs +19 -22
- package/dist/elements.css +1 -1
- package/dist/elements.js +2791 -2680
- package/dist/hooks/useDensity.d.ts +45 -36
- package/dist/hooks/useExpanded.d.ts +1 -0
- package/dist/hooks/usePluginComponents.d.ts +9 -0
- package/dist/lib/humanize.d.ts +1 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/plugins/chart/component.d.ts +3 -0
- package/dist/plugins/chart/index.d.ts +5 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/types/index.d.ts +36 -34
- package/dist/types/plugins.d.ts +57 -0
- package/package.json +7 -5
|
@@ -3,61 +3,70 @@
|
|
|
3
3
|
*/
|
|
4
4
|
declare const densityClasses: {
|
|
5
5
|
readonly compact: {
|
|
6
|
-
readonly 'p-
|
|
6
|
+
readonly 'p-xs': "p-1";
|
|
7
|
+
readonly 'p-sm': "p-1.5";
|
|
7
8
|
readonly 'p-md': "p-2";
|
|
8
|
-
readonly 'p-lg': "p-
|
|
9
|
-
readonly 'p-xl': "p-
|
|
10
|
-
readonly 'px-
|
|
11
|
-
readonly 'px-
|
|
12
|
-
readonly 'px-
|
|
13
|
-
readonly 'px-
|
|
14
|
-
readonly '
|
|
15
|
-
readonly 'py-
|
|
16
|
-
readonly 'py-
|
|
9
|
+
readonly 'p-lg': "p-2.5";
|
|
10
|
+
readonly 'p-xl': "p-3";
|
|
11
|
+
readonly 'px-xs': "px-1";
|
|
12
|
+
readonly 'px-sm': "px-1.5";
|
|
13
|
+
readonly 'px-md': "px-2";
|
|
14
|
+
readonly 'px-lg': "px-2.5";
|
|
15
|
+
readonly 'px-xl': "px-3";
|
|
16
|
+
readonly 'py-xs': "py-1";
|
|
17
|
+
readonly 'py-sm': "py-1.5";
|
|
18
|
+
readonly 'py-md': "py-2";
|
|
19
|
+
readonly 'py-lg': "py-2.5";
|
|
17
20
|
readonly 'py-xl': "py-3";
|
|
18
21
|
readonly 'gap-sm': "gap-1";
|
|
19
|
-
readonly 'gap-md': "gap-
|
|
20
|
-
readonly 'gap-lg': "gap-
|
|
21
|
-
readonly 'gap-xl': "gap-
|
|
22
|
+
readonly 'gap-md': "gap-1.5";
|
|
23
|
+
readonly 'gap-lg': "gap-2";
|
|
24
|
+
readonly 'gap-xl': "gap-2.5";
|
|
22
25
|
readonly 'h-header': "h-10";
|
|
23
|
-
readonly 'h-input': "min-h-
|
|
26
|
+
readonly 'h-input': "min-h-10";
|
|
24
27
|
readonly 'text-base': "text-sm";
|
|
25
28
|
readonly 'text-title': "text-xl";
|
|
26
29
|
readonly 'text-subtitle': "text-sm";
|
|
27
30
|
};
|
|
28
31
|
readonly normal: {
|
|
32
|
+
readonly 'p-xs': "p-1";
|
|
29
33
|
readonly 'p-sm': "p-2";
|
|
30
|
-
readonly 'p-md': "p-
|
|
31
|
-
readonly 'p-lg': "p-
|
|
32
|
-
readonly 'p-xl': "p-
|
|
33
|
-
readonly 'px-
|
|
34
|
-
readonly 'px-
|
|
35
|
-
readonly 'px-
|
|
36
|
-
readonly 'px-
|
|
37
|
-
readonly '
|
|
38
|
-
readonly 'py-
|
|
39
|
-
readonly 'py-
|
|
40
|
-
readonly 'py-
|
|
41
|
-
readonly '
|
|
34
|
+
readonly 'p-md': "p-3";
|
|
35
|
+
readonly 'p-lg': "p-4";
|
|
36
|
+
readonly 'p-xl': "p-6";
|
|
37
|
+
readonly 'px-xs': "px-1";
|
|
38
|
+
readonly 'px-sm': "px-2";
|
|
39
|
+
readonly 'px-md': "px-3";
|
|
40
|
+
readonly 'px-lg': "px-4";
|
|
41
|
+
readonly 'px-xl': "px-6";
|
|
42
|
+
readonly 'py-xs': "py-1";
|
|
43
|
+
readonly 'py-sm': "py-2";
|
|
44
|
+
readonly 'py-md': "py-3";
|
|
45
|
+
readonly 'py-lg': "py-4";
|
|
46
|
+
readonly 'py-xl': "py-6";
|
|
47
|
+
readonly 'gap-sm': "gap-1.5";
|
|
42
48
|
readonly 'gap-md': "gap-2";
|
|
43
49
|
readonly 'gap-lg': "gap-3";
|
|
44
|
-
readonly 'gap-xl': "gap-
|
|
50
|
+
readonly 'gap-xl': "gap-4";
|
|
45
51
|
readonly 'h-header': "h-12";
|
|
46
|
-
readonly 'h-input': "min-h-
|
|
52
|
+
readonly 'h-input': "min-h-12";
|
|
47
53
|
readonly 'text-base': "text-base";
|
|
48
54
|
readonly 'text-title': "text-2xl";
|
|
49
55
|
readonly 'text-subtitle': "text-base";
|
|
50
56
|
};
|
|
51
57
|
readonly spacious: {
|
|
58
|
+
readonly 'p-xs': "p-2";
|
|
52
59
|
readonly 'p-sm': "p-3";
|
|
53
|
-
readonly 'p-md': "p-
|
|
54
|
-
readonly 'p-lg': "p-
|
|
60
|
+
readonly 'p-md': "p-4";
|
|
61
|
+
readonly 'p-lg': "p-6";
|
|
55
62
|
readonly 'p-xl': "p-10";
|
|
56
|
-
readonly 'px-
|
|
57
|
-
readonly 'px-
|
|
58
|
-
readonly 'px-
|
|
63
|
+
readonly 'px-xs': "px-2";
|
|
64
|
+
readonly 'px-sm': "px-3";
|
|
65
|
+
readonly 'px-md': "px-4";
|
|
66
|
+
readonly 'px-lg': "px-6";
|
|
59
67
|
readonly 'px-xl': "px-10";
|
|
60
|
-
readonly 'py-
|
|
68
|
+
readonly 'py-xs': "py-2";
|
|
69
|
+
readonly 'py-sm': "py-3";
|
|
61
70
|
readonly 'py-md': "py-4";
|
|
62
71
|
readonly 'py-lg': "py-6";
|
|
63
72
|
readonly 'py-xl': "py-10";
|
|
@@ -66,7 +75,7 @@ declare const densityClasses: {
|
|
|
66
75
|
readonly 'gap-lg': "gap-4";
|
|
67
76
|
readonly 'gap-xl': "gap-6";
|
|
68
77
|
readonly 'h-header': "h-14";
|
|
69
|
-
readonly 'h-input': "min-h-
|
|
78
|
+
readonly 'h-input': "min-h-16";
|
|
70
79
|
readonly 'text-base': "text-lg";
|
|
71
80
|
readonly 'text-title': "text-3xl";
|
|
72
81
|
readonly 'text-subtitle': "text-lg";
|
|
@@ -77,5 +86,5 @@ type DensityToken = keyof (typeof densityClasses)['normal'];
|
|
|
77
86
|
* Hook to get density classes based on theme config
|
|
78
87
|
* Use: const d = useDensity(); then d('p-md') returns the appropriate padding class
|
|
79
88
|
*/
|
|
80
|
-
export declare const useDensity: () => (token: DensityToken) => "p-1" | "p-2" | "p-
|
|
89
|
+
export declare const useDensity: () => (token: DensityToken) => "p-1" | "p-1.5" | "p-2" | "p-2.5" | "p-3" | "px-1" | "px-1.5" | "px-2" | "px-2.5" | "px-3" | "py-1" | "py-1.5" | "py-2" | "py-2.5" | "py-3" | "gap-1" | "gap-1.5" | "gap-2" | "gap-2.5" | "h-10" | "min-h-10" | "text-sm" | "text-xl" | "p-4" | "p-6" | "px-4" | "px-6" | "py-4" | "py-6" | "gap-3" | "gap-4" | "h-12" | "min-h-12" | "text-base" | "text-2xl" | "p-10" | "px-10" | "py-10" | "gap-6" | "h-14" | "min-h-16" | "text-lg" | "text-3xl";
|
|
81
90
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CodeHeaderProps, SyntaxHighlighterProps } from '@assistant-ui/react-markdown';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
import { Plugin } from '../types/plugins';
|
|
4
|
+
type ComponentsByLanguage = Record<string, {
|
|
5
|
+
CodeHeader?: ComponentType<CodeHeaderProps> | undefined;
|
|
6
|
+
SyntaxHighlighter?: ComponentType<SyntaxHighlighterProps> | undefined;
|
|
7
|
+
}> | undefined;
|
|
8
|
+
export declare function useComponentsByLanguage(plugins: Plugin[]): ComponentsByLanguage;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function humanizeToolName(toolName: string): string;
|
package/dist/lib/utils.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MODELS } from '../lib/models';
|
|
2
2
|
import { ToolCallMessagePartComponent } from '@assistant-ui/react';
|
|
3
3
|
import { Dispatch, SetStateAction, ReactNode } from 'react';
|
|
4
|
+
import { Plugin } from './plugins';
|
|
4
5
|
export interface ElementsProviderProps {
|
|
5
6
|
/**
|
|
6
7
|
* The children to render.
|
|
@@ -19,6 +20,7 @@ export interface ElementsConfig {
|
|
|
19
20
|
* The system prompt to use for the Elements library.
|
|
20
21
|
*/
|
|
21
22
|
systemPrompt?: string;
|
|
23
|
+
plugins?: Plugin[];
|
|
22
24
|
/**
|
|
23
25
|
* The project slug to use for the Elements library.
|
|
24
26
|
*/
|
|
@@ -168,6 +170,11 @@ export interface ThemeConfig {
|
|
|
168
170
|
* }
|
|
169
171
|
*/
|
|
170
172
|
export interface ToolsConfig {
|
|
173
|
+
/**
|
|
174
|
+
* Whether individual tool calls within a group should be expanded by default.
|
|
175
|
+
* @default false
|
|
176
|
+
*/
|
|
177
|
+
expandToolGroupsByDefault?: boolean;
|
|
171
178
|
/**
|
|
172
179
|
* `components` can be used to override the default components used by the
|
|
173
180
|
* Elements library for a given tool result.
|
|
@@ -204,13 +211,34 @@ export interface Suggestion {
|
|
|
204
211
|
label: string;
|
|
205
212
|
action: string;
|
|
206
213
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
214
|
+
interface ExpandableDimensions {
|
|
215
|
+
default: {
|
|
216
|
+
width: number | string;
|
|
217
|
+
height: number | string;
|
|
218
|
+
maxHeight?: number | string;
|
|
219
|
+
};
|
|
220
|
+
expanded?: {
|
|
221
|
+
width: number | string;
|
|
222
|
+
height: number | string;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
interface ExpandedConfig {
|
|
226
|
+
/**
|
|
227
|
+
* Whether the modal can be expanded to full screen.
|
|
228
|
+
*/
|
|
229
|
+
expandable?: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Whether the modal should be expanded by default.
|
|
232
|
+
* @default false
|
|
233
|
+
*/
|
|
234
|
+
defaultExpanded?: boolean;
|
|
235
|
+
/**
|
|
236
|
+
* The dimensions for the modal window.
|
|
237
|
+
*/
|
|
238
|
+
dimensions?: ExpandableDimensions;
|
|
239
|
+
}
|
|
212
240
|
export type ModalTriggerPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
213
|
-
export interface ModalConfig {
|
|
241
|
+
export interface ModalConfig extends ExpandedConfig {
|
|
214
242
|
/**
|
|
215
243
|
* Whether to open the modal window by default.
|
|
216
244
|
*/
|
|
@@ -231,23 +259,6 @@ export interface ModalConfig {
|
|
|
231
259
|
* Receives the current state of the modal window.
|
|
232
260
|
*/
|
|
233
261
|
icon?: (state: 'open' | 'closed' | undefined) => ReactNode;
|
|
234
|
-
/**
|
|
235
|
-
* Whether the modal can be expanded to full screen.
|
|
236
|
-
*/
|
|
237
|
-
expandable?: boolean;
|
|
238
|
-
/**
|
|
239
|
-
* The dimensions for the modal window.
|
|
240
|
-
*/
|
|
241
|
-
dimensions?: {
|
|
242
|
-
/**
|
|
243
|
-
* The default dimensions for the modal window.
|
|
244
|
-
*/
|
|
245
|
-
default: ModalDimension;
|
|
246
|
-
/**
|
|
247
|
-
* The expanded dimensions for the modal window.
|
|
248
|
-
*/
|
|
249
|
-
expanded?: Pick<ModalDimension, 'width' | 'height'>;
|
|
250
|
-
};
|
|
251
262
|
}
|
|
252
263
|
export interface ComposerConfig {
|
|
253
264
|
/**
|
|
@@ -287,22 +298,12 @@ export interface AttachmentsConfig {
|
|
|
287
298
|
*/
|
|
288
299
|
maxSize?: number;
|
|
289
300
|
}
|
|
290
|
-
export interface SidecarConfig {
|
|
301
|
+
export interface SidecarConfig extends ExpandedConfig {
|
|
291
302
|
/**
|
|
292
303
|
* The title displayed in the sidecar header.
|
|
293
304
|
* @default 'Chat'
|
|
294
305
|
*/
|
|
295
306
|
title?: string;
|
|
296
|
-
/**
|
|
297
|
-
* The width of the sidecar panel.
|
|
298
|
-
* @default '400px'
|
|
299
|
-
*/
|
|
300
|
-
width?: string | number | `${number}%`;
|
|
301
|
-
/**
|
|
302
|
-
* The width of the sidecar panel when expanded.
|
|
303
|
-
* @default '800px'
|
|
304
|
-
*/
|
|
305
|
-
expandedWidth?: string | number | `${number}%`;
|
|
306
307
|
}
|
|
307
308
|
export type ElementsContextType = {
|
|
308
309
|
config: ElementsConfig;
|
|
@@ -312,5 +313,6 @@ export type ElementsContextType = {
|
|
|
312
313
|
setIsExpanded: Dispatch<SetStateAction<boolean>>;
|
|
313
314
|
isOpen: boolean;
|
|
314
315
|
setIsOpen: (isOpen: boolean) => void;
|
|
316
|
+
plugins: Plugin[];
|
|
315
317
|
};
|
|
316
318
|
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CodeHeaderProps, SyntaxHighlighterProps } from '@assistant-ui/react-markdown';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* A plugin enables addition of custom rendering capabilities to the Elements library.
|
|
5
|
+
* For example, a plugin could provide a custom renderer for a specific language such as
|
|
6
|
+
* D3.js or Mermaid.
|
|
7
|
+
*
|
|
8
|
+
* The general flow of a plugin is:
|
|
9
|
+
* 1. Plugin extends the system prompt with a custom prompt instructing the LLM to return code fences marked with the specified language / format
|
|
10
|
+
* 2. The LLM returns a code fence marked with the specified language / format
|
|
11
|
+
* 3. The code fence is rendered using the custom renderer
|
|
12
|
+
*/
|
|
13
|
+
export interface Plugin {
|
|
14
|
+
/**
|
|
15
|
+
* Any prompt that the plugin may need to add to the system prompt.
|
|
16
|
+
* Will be appended to the built-in system prompt.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```
|
|
20
|
+
* If the user asks for a chart, use D3 to render it.
|
|
21
|
+
* Return only a d3 code block. The code will execute in a sandboxed environment where:
|
|
22
|
+
* - \`d3\` is the D3 library
|
|
23
|
+
* - \`container\` is the DOM element to render into (use \`d3.select(container)\` NOT \`d3.select('body')\`)
|
|
24
|
+
* The code should be wrapped in a \`\`\`d3
|
|
25
|
+
* \`\`\` block.
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
prompt: string;
|
|
29
|
+
/**
|
|
30
|
+
* The language identifier for the syntax highlighter
|
|
31
|
+
* e.g mermaid or d3
|
|
32
|
+
*
|
|
33
|
+
* Does not need to be an official language identifier, can be any string. The important part is that the
|
|
34
|
+
* prompt adequately instructs the LLM to return code fences marked with the specified language / format
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```
|
|
38
|
+
* d3
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
language: string;
|
|
42
|
+
/**
|
|
43
|
+
* The component to use for the syntax highlighter.
|
|
44
|
+
*/
|
|
45
|
+
Component: ComponentType<SyntaxHighlighterProps>;
|
|
46
|
+
/**
|
|
47
|
+
* The component to use for the code header.
|
|
48
|
+
* Will be rendered above the code block.
|
|
49
|
+
* @default () => null
|
|
50
|
+
*/
|
|
51
|
+
Header?: ComponentType<CodeHeaderProps> | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Whether to override existing plugins with the same language.
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
overrideExisting?: boolean;
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@gram-ai/elements",
|
|
3
3
|
"description": "Gram Elements is a library of UI primitives for building chat-like experiences for MCP Servers.",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.12.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"import": "./dist/server.js",
|
|
16
16
|
"require": "./dist/server.cjs"
|
|
17
17
|
},
|
|
18
|
+
"./plugins": {
|
|
19
|
+
"types": "./dist/plugins.d.ts",
|
|
20
|
+
"import": "./dist/plugins.js",
|
|
21
|
+
"require": "./dist/plugins.cjs"
|
|
22
|
+
},
|
|
18
23
|
"./elements.css": "./dist/elements.css"
|
|
19
24
|
},
|
|
20
25
|
"files": [
|
|
@@ -44,7 +49,6 @@
|
|
|
44
49
|
"@assistant-ui/react-markdown": "^0.11.0",
|
|
45
50
|
"@types/react": ">=18 <20",
|
|
46
51
|
"@types/react-dom": ">=18 <20",
|
|
47
|
-
"d3": "^7.9.0",
|
|
48
52
|
"motion": "^12.0.0",
|
|
49
53
|
"react": ">=18 <20",
|
|
50
54
|
"react-dom": ">=18 <20",
|
|
@@ -78,9 +82,6 @@
|
|
|
78
82
|
},
|
|
79
83
|
"zustand": {
|
|
80
84
|
"optional": true
|
|
81
|
-
},
|
|
82
|
-
"d3": {
|
|
83
|
-
"optional": true
|
|
84
85
|
}
|
|
85
86
|
},
|
|
86
87
|
"dependencies": {
|
|
@@ -99,6 +100,7 @@
|
|
|
99
100
|
"lucide-react": "^0.544.0",
|
|
100
101
|
"tailwind-merge": "^3.3.1",
|
|
101
102
|
"tw-shimmer": "^0.4.0",
|
|
103
|
+
"vega": "^6.2.0",
|
|
102
104
|
"zod": "^4.1.13"
|
|
103
105
|
},
|
|
104
106
|
"devDependencies": {
|