@gram-ai/elements 1.10.0 → 1.11.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/elements.cjs +17 -20
- package/dist/elements.css +1 -1
- package/dist/elements.js +1976 -1995
- package/dist/hooks/usePluginComponents.d.ts +9 -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 +3 -0
- package/dist/types/plugins.d.ts +57 -0
- package/package.json +7 -5
|
@@ -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 {};
|
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
|
*/
|
|
@@ -312,5 +314,6 @@ export type ElementsContextType = {
|
|
|
312
314
|
setIsExpanded: Dispatch<SetStateAction<boolean>>;
|
|
313
315
|
isOpen: boolean;
|
|
314
316
|
setIsOpen: (isOpen: boolean) => void;
|
|
317
|
+
plugins: Plugin[];
|
|
315
318
|
};
|
|
316
319
|
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.11.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": {
|