@gram-ai/elements 1.9.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 +208 -27
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/buttonVariants.d.ts +1 -1
- 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/index.d.ts +1 -1
- 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 +5 -29
- package/dist/types/plugins.d.ts +57 -0
- package/dist/types/schemas.d.ts +20 -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/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { useElements as useGramElements } from './hooks/useElements';
|
|
|
3
3
|
export { Chat } from './components/Chat';
|
|
4
4
|
export { ToolUI, ToolUISection } from './components/ui/tool-ui';
|
|
5
5
|
export type { ToolUIProps, ToolUISectionProps, ToolStatus, } from './components/ui/tool-ui';
|
|
6
|
-
export type { ElementsConfig, ComposerConfig, AttachmentsConfig, ModalConfig, SidecarConfig, ToolsConfig, ModelConfig, ThemeConfig, WelcomeConfig, Suggestion, Model, ModalTriggerPosition, } from './types';
|
|
6
|
+
export type { ElementsConfig, ComposerConfig, AttachmentsConfig, ModalConfig, SidecarConfig, ToolsConfig, ModelConfig, ThemeConfig, WelcomeConfig, Suggestion, Model, ModalTriggerPosition, ColorScheme, Radius, Density, Variant, } from './types';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +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 {
|
|
4
|
+
import { Plugin } from './plugins';
|
|
5
5
|
export interface ElementsProviderProps {
|
|
6
6
|
/**
|
|
7
7
|
* The children to render.
|
|
@@ -20,6 +20,7 @@ export interface ElementsConfig {
|
|
|
20
20
|
* The system prompt to use for the Elements library.
|
|
21
21
|
*/
|
|
22
22
|
systemPrompt?: string;
|
|
23
|
+
plugins?: Plugin[];
|
|
23
24
|
/**
|
|
24
25
|
* The project slug to use for the Elements library.
|
|
25
26
|
*/
|
|
@@ -268,6 +269,8 @@ export interface ComposerConfig {
|
|
|
268
269
|
/**
|
|
269
270
|
* AttachmentsConfig provides fine-grained control over file attachments.
|
|
270
271
|
* Inspired by OpenAI ChatKit's attachment options.
|
|
272
|
+
*
|
|
273
|
+
* Note: not yet implemented on the Gram side.
|
|
271
274
|
*/
|
|
272
275
|
export interface AttachmentsConfig {
|
|
273
276
|
/**
|
|
@@ -302,16 +305,6 @@ export interface SidecarConfig {
|
|
|
302
305
|
* @default '800px'
|
|
303
306
|
*/
|
|
304
307
|
expandedWidth?: string | number | `${number}%`;
|
|
305
|
-
/**
|
|
306
|
-
* Callback when the pop-out button is clicked.
|
|
307
|
-
* If provided, the pop-out button will be shown.
|
|
308
|
-
*/
|
|
309
|
-
onPopOut?: () => void;
|
|
310
|
-
/**
|
|
311
|
-
* Callback when the collapse button is clicked.
|
|
312
|
-
* If provided, the collapse button will be shown.
|
|
313
|
-
*/
|
|
314
|
-
onCollapse?: () => void;
|
|
315
308
|
}
|
|
316
309
|
export type ElementsContextType = {
|
|
317
310
|
config: ElementsConfig;
|
|
@@ -321,23 +314,6 @@ export type ElementsContextType = {
|
|
|
321
314
|
setIsExpanded: Dispatch<SetStateAction<boolean>>;
|
|
322
315
|
isOpen: boolean;
|
|
323
316
|
setIsOpen: (isOpen: boolean) => void;
|
|
317
|
+
plugins: Plugin[];
|
|
324
318
|
};
|
|
325
|
-
declare const ContentSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
326
|
-
type: z.ZodLiteral<"text">;
|
|
327
|
-
text: z.ZodString;
|
|
328
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
329
|
-
type: z.ZodLiteral<"image">;
|
|
330
|
-
data: z.ZodString;
|
|
331
|
-
}, z.core.$strip>]>;
|
|
332
|
-
export type ToolCallResultContent = z.infer<typeof ContentSchema>;
|
|
333
|
-
export declare const ToolCallResultSchema: z.ZodUnion<[z.ZodObject<{
|
|
334
|
-
content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
335
|
-
type: z.ZodLiteral<"text">;
|
|
336
|
-
text: z.ZodString;
|
|
337
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
338
|
-
type: z.ZodLiteral<"image">;
|
|
339
|
-
data: z.ZodString;
|
|
340
|
-
}, z.core.$strip>]>>;
|
|
341
|
-
}, z.core.$strip>, z.ZodUndefined]>;
|
|
342
|
-
export type ToolCallResult = z.infer<typeof ToolCallResultSchema>;
|
|
343
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const ContentSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
3
|
+
type: z.ZodLiteral<"text">;
|
|
4
|
+
text: z.ZodString;
|
|
5
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
6
|
+
type: z.ZodLiteral<"image">;
|
|
7
|
+
data: z.ZodString;
|
|
8
|
+
}, z.core.$strip>]>;
|
|
9
|
+
export type ToolCallResultContent = z.infer<typeof ContentSchema>;
|
|
10
|
+
export declare const ToolCallResultSchema: z.ZodUnion<[z.ZodObject<{
|
|
11
|
+
content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
12
|
+
type: z.ZodLiteral<"text">;
|
|
13
|
+
text: z.ZodString;
|
|
14
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
15
|
+
type: z.ZodLiteral<"image">;
|
|
16
|
+
data: z.ZodString;
|
|
17
|
+
}, z.core.$strip>]>>;
|
|
18
|
+
}, z.core.$strip>, z.ZodUndefined]>;
|
|
19
|
+
export type ToolCallResult = z.infer<typeof ToolCallResultSchema>;
|
|
20
|
+
export {};
|
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": {
|