@gram-ai/elements 1.14.0 → 1.16.1
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/LICENSE +661 -0
- package/README.md +1 -32
- package/dist/components/FrontendTools/index.d.ts +4 -0
- package/dist/elements.cjs +20 -24
- package/dist/elements.css +1 -1
- package/dist/elements.js +4639 -5841
- package/dist/index-BqoFmyxX.cjs +60 -0
- package/dist/index-CVZt-xeH.js +14913 -0
- package/dist/index.d.ts +2 -0
- package/dist/lib/tools.d.ts +22 -0
- package/dist/server.cjs +16 -41
- package/dist/server.js +2058 -8569
- package/dist/types/index.d.ts +177 -2
- package/package.json +14 -17
- package/dist/components/assistant-ui/d3-renderer.d.ts +0 -5
- package/dist/index-DxNldiiY.js +0 -6560
- package/dist/index-IZN-i8ZU.cjs +0 -33
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MODELS } from '../lib/models';
|
|
2
|
-
import { ImageMessagePartComponent, ReasoningGroupComponent, ReasoningMessagePartComponent, TextMessagePartComponent, ToolCallMessagePartComponent } from '@assistant-ui/react';
|
|
2
|
+
import { AssistantTool, ImageMessagePartComponent, ReasoningGroupComponent, ReasoningMessagePartComponent, TextMessagePartComponent, ToolCallMessagePartComponent } from '@assistant-ui/react';
|
|
3
3
|
import { ComponentType, Dispatch, PropsWithChildren, SetStateAction, ReactNode } from 'react';
|
|
4
4
|
import { Plugin } from './plugins';
|
|
5
5
|
export interface ElementsProviderProps {
|
|
@@ -15,6 +15,14 @@ export interface ElementsProviderProps {
|
|
|
15
15
|
type ServerUrl = string;
|
|
16
16
|
export declare const VARIANTS: readonly ["widget", "sidecar", "standalone"];
|
|
17
17
|
export type Variant = (typeof VARIANTS)[number];
|
|
18
|
+
/**
|
|
19
|
+
* The top level configuration object for the Elements library.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const config: ElementsConfig = {
|
|
23
|
+
* systemPrompt: 'You are a helpful assistant.',
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
18
26
|
export interface ElementsConfig {
|
|
19
27
|
/**
|
|
20
28
|
* The system prompt to use for the Elements library.
|
|
@@ -26,9 +34,41 @@ export interface ElementsConfig {
|
|
|
26
34
|
* @default import { recommended } from '@gram-ai/elements/plugins'
|
|
27
35
|
*/
|
|
28
36
|
plugins?: Plugin[];
|
|
37
|
+
/**
|
|
38
|
+
* Override the default components used by the Elements library.
|
|
39
|
+
*
|
|
40
|
+
* The available components are:
|
|
41
|
+
* - Composer
|
|
42
|
+
* - UserMessage
|
|
43
|
+
* - EditComposer
|
|
44
|
+
* - AssistantMessage
|
|
45
|
+
* - ThreadWelcome
|
|
46
|
+
* - Text
|
|
47
|
+
* - Image
|
|
48
|
+
* - ToolFallback
|
|
49
|
+
* - Reasoning
|
|
50
|
+
* - ReasoningGroup
|
|
51
|
+
* - ToolGroup
|
|
52
|
+
*
|
|
53
|
+
* To understand how to override these components, please consult the [assistant-ui documentation](https://www.assistant-ui.com/docs).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const config: ElementsConfig = {
|
|
57
|
+
* components: {
|
|
58
|
+
* Composer: CustomComposerComponent,
|
|
59
|
+
* },
|
|
60
|
+
* }
|
|
61
|
+
*/
|
|
29
62
|
components?: ComponentOverrides;
|
|
30
63
|
/**
|
|
31
64
|
* The project slug to use for the Elements library.
|
|
65
|
+
*
|
|
66
|
+
* Your project slug can be found within the Gram dashboard.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const config: ElementsConfig = {
|
|
70
|
+
* projectSlug: 'your-project-slug',
|
|
71
|
+
* }
|
|
32
72
|
*/
|
|
33
73
|
projectSlug: string;
|
|
34
74
|
/**
|
|
@@ -36,10 +76,16 @@ export interface ElementsConfig {
|
|
|
36
76
|
* Can be retrieved from https://app.getgram.ai/{team}/{project}/mcp/{mcp_slug}
|
|
37
77
|
*
|
|
38
78
|
* Note: This config option will likely change in the future
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* const config: ElementsConfig = {
|
|
82
|
+
* mcp: 'https://app.getgram.ai/mcp/your-mcp-slug',
|
|
83
|
+
* }
|
|
39
84
|
*/
|
|
40
85
|
mcp: ServerUrl;
|
|
41
86
|
/**
|
|
42
87
|
* The path of your backend's chat endpoint.
|
|
88
|
+
*
|
|
43
89
|
* @default '/chat/completions'
|
|
44
90
|
*
|
|
45
91
|
* @example
|
|
@@ -51,6 +97,7 @@ export interface ElementsConfig {
|
|
|
51
97
|
/**
|
|
52
98
|
* Custom environment variable overrides for the Elements library.
|
|
53
99
|
* Will be used to override the environment variables for the MCP server.
|
|
100
|
+
*
|
|
54
101
|
* For more documentation on passing through different kinds of environment variables, including bearer tokens, see the [Gram documentation](https://www.speakeasy.com/docs/gram/host-mcp/public-private-servers#pass-through-authentication).
|
|
55
102
|
*/
|
|
56
103
|
environment?: Record<string, unknown>;
|
|
@@ -78,32 +125,112 @@ export interface ElementsConfig {
|
|
|
78
125
|
model?: ModelConfig;
|
|
79
126
|
/**
|
|
80
127
|
* Visual appearance configuration options.
|
|
81
|
-
* Similar to OpenAI ChatKit's ThemeOption
|
|
128
|
+
* Similar to OpenAI ChatKit's ThemeOption.\
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* const config: ElementsConfig = {
|
|
132
|
+
* theme: {
|
|
133
|
+
* colorScheme: 'dark',
|
|
134
|
+
* density: 'compact',
|
|
135
|
+
* radius: 'round',
|
|
136
|
+
* },
|
|
137
|
+
* }
|
|
82
138
|
*/
|
|
83
139
|
theme?: ThemeConfig;
|
|
84
140
|
/**
|
|
85
141
|
* The configuration for the welcome message and initial suggestions.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* const config: ElementsConfig = {
|
|
145
|
+
* welcome: {
|
|
146
|
+
* title: 'Welcome to the chat',
|
|
147
|
+
* subtitle: 'This is a chat with a bot',
|
|
148
|
+
* suggestions: [
|
|
149
|
+
* { title: 'Suggestion 1', label: 'Suggestion 1', action: 'action1' },
|
|
150
|
+
* ],
|
|
151
|
+
* },
|
|
152
|
+
* }
|
|
86
153
|
*/
|
|
87
154
|
welcome: WelcomeConfig;
|
|
88
155
|
/**
|
|
89
156
|
* The configuration for the composer.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* const config: ElementsConfig = {
|
|
160
|
+
* composer: {
|
|
161
|
+
* placeholder: 'Enter your message...',
|
|
162
|
+
* },
|
|
163
|
+
* }
|
|
90
164
|
*/
|
|
91
165
|
composer?: ComposerConfig;
|
|
92
166
|
/**
|
|
93
167
|
* The configuration for the modal window.
|
|
94
168
|
* Does not apply if variant is 'standalone'.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* const config: ElementsConfig = {
|
|
172
|
+
* modal: {
|
|
173
|
+
* title: 'Chat',
|
|
174
|
+
* position: 'bottom-right',
|
|
175
|
+
* },
|
|
176
|
+
* expandable: true,
|
|
177
|
+
* defaultExpanded: false,
|
|
178
|
+
* dimensions: {
|
|
179
|
+
* width: 400,
|
|
180
|
+
* height: 600,
|
|
181
|
+
* },
|
|
182
|
+
* }
|
|
95
183
|
*/
|
|
96
184
|
modal?: ModalConfig;
|
|
97
185
|
/**
|
|
98
186
|
* The configuration for the sidecar panel.
|
|
99
187
|
* Only applies if variant is 'sidecar'.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* const config: ElementsConfig = {
|
|
191
|
+
* sidecar: {
|
|
192
|
+
* title: 'Chat',
|
|
193
|
+
* },
|
|
194
|
+
* expandable: true,
|
|
195
|
+
* defaultExpanded: false,
|
|
196
|
+
* dimensions: {
|
|
197
|
+
* width: 400,
|
|
198
|
+
* height: 600,
|
|
199
|
+
* },
|
|
200
|
+
* }
|
|
100
201
|
*/
|
|
101
202
|
sidecar?: SidecarConfig;
|
|
102
203
|
/**
|
|
103
204
|
* The configuration for the tools.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* const config: ElementsConfig = {
|
|
208
|
+
* tools: {
|
|
209
|
+
* expandToolGroupsByDefault: true,
|
|
210
|
+
* },
|
|
211
|
+
* components: {
|
|
212
|
+
* ToolFallback: CustomToolFallbackComponent,
|
|
213
|
+
* },
|
|
214
|
+
* frontendTools: {
|
|
215
|
+
* fetchUrl: FetchTool,
|
|
216
|
+
* },
|
|
217
|
+
* components: {
|
|
218
|
+
* fetchUrl: FetchToolComponent,
|
|
219
|
+
* },
|
|
220
|
+
* }
|
|
104
221
|
*/
|
|
105
222
|
tools?: ToolsConfig;
|
|
106
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* The LLM model to use for the Elements library.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* const config: ElementsConfig = {
|
|
229
|
+
* model: {
|
|
230
|
+
* defaultModel: 'openai/gpt-4o',
|
|
231
|
+
* },
|
|
232
|
+
* }
|
|
233
|
+
*/
|
|
107
234
|
export type Model = (typeof MODELS)[number];
|
|
108
235
|
/**
|
|
109
236
|
* ModelConfig is used to configure model support in the Elements library.
|
|
@@ -248,6 +375,54 @@ export interface ToolsConfig {
|
|
|
248
375
|
* }
|
|
249
376
|
*/
|
|
250
377
|
components?: Record<string, ToolCallMessagePartComponent | undefined> | undefined;
|
|
378
|
+
/**
|
|
379
|
+
* The frontend tools to use for the Elements library.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```ts
|
|
383
|
+
* import { defineFrontendTool } from '@gram-ai/elements'
|
|
384
|
+
*
|
|
385
|
+
* const FetchTool = defineFrontendTool<{ url: string }, string>(
|
|
386
|
+
* {
|
|
387
|
+
* description: 'Fetch a URL (supports CORS-enabled URLs like httpbin.org)',
|
|
388
|
+
* parameters: z.object({
|
|
389
|
+
* url: z.string().describe('URL to fetch (must support CORS)'),
|
|
390
|
+
* }),
|
|
391
|
+
* execute: async ({ url }) => {
|
|
392
|
+
* const response = await fetch(url as string)
|
|
393
|
+
* const text = await response.text()
|
|
394
|
+
* return text
|
|
395
|
+
* },
|
|
396
|
+
* },
|
|
397
|
+
* 'fetchUrl'
|
|
398
|
+
* )
|
|
399
|
+
* const config: ElementsConfig = {
|
|
400
|
+
* frontendTools: {
|
|
401
|
+
* fetchUrl: FetchTool,
|
|
402
|
+
* },
|
|
403
|
+
* }
|
|
404
|
+
* ```
|
|
405
|
+
*
|
|
406
|
+
* You can also override the default components used by the
|
|
407
|
+
* Elements library for a given tool result.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* import { FetchToolComponent } from './components/FetchToolComponent'
|
|
412
|
+
*
|
|
413
|
+
* const config: ElementsConfig = {
|
|
414
|
+
* tools: {
|
|
415
|
+
* frontendTools: {
|
|
416
|
+
* fetchUrl: FetchTool,
|
|
417
|
+
* },
|
|
418
|
+
* components: {
|
|
419
|
+
* 'fetchUrl': FetchToolComponent, // will override the default component used by the Elements library for the 'fetchUrl' tool
|
|
420
|
+
* },
|
|
421
|
+
* },
|
|
422
|
+
* }
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
frontendTools?: Record<string, AssistantTool>;
|
|
251
426
|
}
|
|
252
427
|
export interface WelcomeConfig {
|
|
253
428
|
/**
|
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.16.1",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -27,25 +27,14 @@
|
|
|
27
27
|
],
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "https://github.com/speakeasy-api/gram
|
|
30
|
+
"url": "https://github.com/speakeasy-api/gram.git"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"scripts": {
|
|
36
|
-
"build": "vite build",
|
|
37
|
-
"lint": "eslint src",
|
|
38
|
-
"analyze": "pnpm dlx vite-bundle-visualizer",
|
|
39
|
-
"storybook": "storybook dev -p 6006",
|
|
40
|
-
"build-storybook": "storybook build",
|
|
41
|
-
"type-check": "tsc --noEmit",
|
|
42
|
-
"docs": "typedoc",
|
|
43
|
-
"docs:watch": "typedoc --watch"
|
|
44
|
-
},
|
|
45
35
|
"keywords": [],
|
|
46
36
|
"author": "Adam Bull <adam@speakeasy.com>",
|
|
47
37
|
"license": "ISC",
|
|
48
|
-
"packageManager": "pnpm@10.18.2",
|
|
49
38
|
"peerDependencies": {
|
|
50
39
|
"@assistant-ui/react": "^0.11.0",
|
|
51
40
|
"@assistant-ui/react-markdown": "^0.11.0",
|
|
@@ -114,7 +103,7 @@
|
|
|
114
103
|
},
|
|
115
104
|
"devDependencies": {
|
|
116
105
|
"@ai-sdk/openai": "^2.0.0-beta.5",
|
|
117
|
-
"@assistant-ui/react": "^0.11.
|
|
106
|
+
"@assistant-ui/react": "^0.11.53",
|
|
118
107
|
"@assistant-ui/react-ai-sdk": "^1.1.16",
|
|
119
108
|
"@assistant-ui/react-markdown": "^0.11.4",
|
|
120
109
|
"@eslint/compat": "^2.0.0",
|
|
@@ -123,7 +112,6 @@
|
|
|
123
112
|
"@storybook/addon-docs": "^10.0.8",
|
|
124
113
|
"@storybook/react-vite": "^10.0.8",
|
|
125
114
|
"@tailwindcss/vite": "^4.1.13",
|
|
126
|
-
"@types/d3": "^7.4.3",
|
|
127
115
|
"@types/lodash.merge": "^4.6.9",
|
|
128
116
|
"@types/node": "^24.10.1",
|
|
129
117
|
"@vitejs/plugin-react": "^5.0.3",
|
|
@@ -141,7 +129,6 @@
|
|
|
141
129
|
"prettier": "^3.7.4",
|
|
142
130
|
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
143
131
|
"remark-gfm": "^4.0.1",
|
|
144
|
-
"semantic-release": "^24.2.0",
|
|
145
132
|
"storybook": "^10.0.8",
|
|
146
133
|
"tailwindcss": "^4.1.13",
|
|
147
134
|
"tw-animate-css": "^1.3.8",
|
|
@@ -151,5 +138,15 @@
|
|
|
151
138
|
"vite": "^7.1.6",
|
|
152
139
|
"vite-plugin-dts": "^4.5.4",
|
|
153
140
|
"zustand": "^5.0.8"
|
|
141
|
+
},
|
|
142
|
+
"scripts": {
|
|
143
|
+
"build": "vite build",
|
|
144
|
+
"lint": "eslint src",
|
|
145
|
+
"analyze": "pnpm dlx vite-bundle-visualizer",
|
|
146
|
+
"storybook": "storybook dev -p 6006",
|
|
147
|
+
"build-storybook": "storybook build",
|
|
148
|
+
"type-check": "tsc --noEmit",
|
|
149
|
+
"docs": "typedoc",
|
|
150
|
+
"docs:watch": "typedoc --watch"
|
|
154
151
|
}
|
|
155
|
-
}
|
|
152
|
+
}
|