@gram-ai/elements 1.13.10 → 1.15.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.
@@ -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.13.10",
5
+ "version": "1.15.0",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
8
8
  ".": {
@@ -38,7 +38,9 @@
38
38
  "analyze": "pnpm dlx vite-bundle-visualizer",
39
39
  "storybook": "storybook dev -p 6006",
40
40
  "build-storybook": "storybook build",
41
- "type-check": "tsc --noEmit"
41
+ "type-check": "tsc --noEmit",
42
+ "docs": "typedoc",
43
+ "docs:watch": "typedoc --watch"
42
44
  },
43
45
  "keywords": [],
44
46
  "author": "Adam Bull <adam@speakeasy.com>",
@@ -53,9 +55,9 @@
53
55
  "react": ">=18 <20",
54
56
  "react-dom": ">=18 <20",
55
57
  "remark-gfm": "^4.0.0",
58
+ "shiki": "^3.20.0",
56
59
  "vega": "^6.2.0",
57
- "zustand": "^5.0.0",
58
- "shiki": "^3.20.0"
60
+ "zustand": "^5.0.0"
59
61
  },
60
62
  "peerDependenciesMeta": {
61
63
  "@assistant-ui/react": {
@@ -112,7 +114,7 @@
112
114
  },
113
115
  "devDependencies": {
114
116
  "@ai-sdk/openai": "^2.0.0-beta.5",
115
- "@assistant-ui/react": "^0.11.37",
117
+ "@assistant-ui/react": "^0.11.53",
116
118
  "@assistant-ui/react-ai-sdk": "^1.1.16",
117
119
  "@assistant-ui/react-markdown": "^0.11.4",
118
120
  "@eslint/compat": "^2.0.0",
@@ -143,6 +145,8 @@
143
145
  "storybook": "^10.0.8",
144
146
  "tailwindcss": "^4.1.13",
145
147
  "tw-animate-css": "^1.3.8",
148
+ "typedoc": "^0.28.15",
149
+ "typedoc-plugin-markdown": "^4.9.0",
146
150
  "typescript-eslint": "^8.48.1",
147
151
  "vite": "^7.1.6",
148
152
  "vite-plugin-dts": "^4.5.4",