@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
package/README.md
CHANGED
|
@@ -109,6 +109,7 @@ The `ElementsConfig` object accepts the following configuration options:
|
|
|
109
109
|
| `chatEndpoint` | `string` | No | ✅ Implemented | `'/chat/completions'` | The path of your backend's chat endpoint |
|
|
110
110
|
| `environment` | `Record<string, unknown>` | No | ✅ Implemented | `undefined` | Custom environment variable overrides for the MCP server. See [Gram documentation](https://www.speakeasy.com/docs/gram/host-mcp/public-private-servers#pass-through-authentication) for pass-through authentication |
|
|
111
111
|
| `variant` | `'widget' \| 'sidecar' \| 'standalone'` | No | ✅ Implemented | `'widget'` | The layout variant for the chat interface. `widget` is a popup modal, `sidecar` is a side panel, `standalone` is a full-page experience |
|
|
112
|
+
| `plugins` | [`Plugin[]`](#plugins) | No | ✅ Implemented | `[]` | Array of plugins to extend rendering capabilities. See [Plugins section](#plugins) for details |
|
|
112
113
|
| `theme` | [`ThemeConfig`](#theme-configuration-themeconfig) | No | ✅ Implemented | `undefined` | Visual appearance configuration options |
|
|
113
114
|
| `welcome` | [`WelcomeConfig`](#welcome-configuration-welcomeconfig) | Yes | ✅ Implemented | - | Configuration for the welcome message and initial suggestions |
|
|
114
115
|
| `composer` | [`ComposerConfig`](#composer-configuration-composerconfig) | No | ✅ Implemented | `undefined` | Configuration for the composer input |
|
|
@@ -240,6 +241,7 @@ const config: ElementsConfig = {
|
|
|
240
241
|
|
|
241
242
|
```typescript
|
|
242
243
|
import { ElementsConfig } from '@gram-ai/elements'
|
|
244
|
+
import { recommended } from '@gram-ai/elements/plugins'
|
|
243
245
|
import { WeatherComponent } from './components/WeatherComponent'
|
|
244
246
|
|
|
245
247
|
const config: ElementsConfig = {
|
|
@@ -248,6 +250,7 @@ const config: ElementsConfig = {
|
|
|
248
250
|
mcp: 'https://app.getgram.ai/mcp/my-mcp-slug',
|
|
249
251
|
chatEndpoint: '/api/chat',
|
|
250
252
|
variant: 'widget',
|
|
253
|
+
plugins: recommended,
|
|
251
254
|
theme: {
|
|
252
255
|
colorScheme: 'system',
|
|
253
256
|
density: 'normal',
|
|
@@ -375,6 +378,106 @@ const config: ElementsConfig = {
|
|
|
375
378
|
}
|
|
376
379
|
```
|
|
377
380
|
|
|
381
|
+
## Plugins
|
|
382
|
+
|
|
383
|
+
Plugins extend the Gram Elements library with custom rendering capabilities for specific content types. They allow you to transform markdown code blocks into rich, interactive visualizations and components.
|
|
384
|
+
|
|
385
|
+
### How Plugins Work
|
|
386
|
+
|
|
387
|
+
When you add a plugin:
|
|
388
|
+
|
|
389
|
+
1. The plugin extends the system prompt with instructions for the LLM
|
|
390
|
+
2. The LLM returns code blocks marked with the plugin's language identifier
|
|
391
|
+
3. The plugin's custom component renders the code block content
|
|
392
|
+
|
|
393
|
+
For example, the built-in chart plugin instructs the LLM to return Vega specifications for visualizations, which are then rendered as interactive charts.
|
|
394
|
+
|
|
395
|
+
### Using Recommended Plugins
|
|
396
|
+
|
|
397
|
+
Gram Elements includes a set of recommended plugins that you can use out of the box:
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
import { GramElementsProvider, Chat, type ElementsConfig } from '@gram-ai/elements'
|
|
401
|
+
import { recommended } from '@gram-ai/elements/plugins'
|
|
402
|
+
import '@gram-ai/elements/elements.css'
|
|
403
|
+
|
|
404
|
+
const config: ElementsConfig = {
|
|
405
|
+
projectSlug: 'my-project',
|
|
406
|
+
mcp: 'https://app.getgram.ai/mcp/my-mcp-slug',
|
|
407
|
+
welcome: {
|
|
408
|
+
title: 'Hello!',
|
|
409
|
+
subtitle: 'How can I help you today?',
|
|
410
|
+
},
|
|
411
|
+
// Add all recommended plugins
|
|
412
|
+
plugins: recommended,
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export const App = () => {
|
|
416
|
+
return (
|
|
417
|
+
<GramElementsProvider config={config}>
|
|
418
|
+
<Chat />
|
|
419
|
+
</GramElementsProvider>
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
#### Available Recommended Plugins
|
|
425
|
+
|
|
426
|
+
- **`chart`** - Renders Vega chart specifications as interactive visualizations
|
|
427
|
+
|
|
428
|
+
### Using Individual Plugins
|
|
429
|
+
|
|
430
|
+
You can also import and use plugins individually:
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
import { chart } from '@gram-ai/elements/plugins'
|
|
434
|
+
|
|
435
|
+
const config: ElementsConfig = {
|
|
436
|
+
// ... other config
|
|
437
|
+
plugins: [chart],
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Using Custom Plugins
|
|
442
|
+
|
|
443
|
+
You can create your own custom plugins to add specialized rendering capabilities:
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
import { GramElementsProvider, Chat, type ElementsConfig } from '@gram-ai/elements'
|
|
447
|
+
import { chart } from '@gram-ai/elements/plugins'
|
|
448
|
+
import { myCustomPlugin } from './plugins/myCustomPlugin'
|
|
449
|
+
import '@gram-ai/elements/elements.css'
|
|
450
|
+
|
|
451
|
+
const config: ElementsConfig = {
|
|
452
|
+
projectSlug: 'my-project',
|
|
453
|
+
mcp: 'https://app.getgram.ai/mcp/my-mcp-slug',
|
|
454
|
+
welcome: {
|
|
455
|
+
title: 'Hello!',
|
|
456
|
+
subtitle: 'How can I help you today?',
|
|
457
|
+
},
|
|
458
|
+
// Combine built-in and custom plugins
|
|
459
|
+
plugins: [chart, myCustomPlugin],
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export const App = () => {
|
|
463
|
+
return (
|
|
464
|
+
<GramElementsProvider config={config}>
|
|
465
|
+
<Chat />
|
|
466
|
+
</GramElementsProvider>
|
|
467
|
+
)
|
|
468
|
+
}
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### Creating Custom Plugins
|
|
472
|
+
|
|
473
|
+
To create your own plugins, see the comprehensive [Plugin Development Guide](./src/plugins/README.md). The guide covers:
|
|
474
|
+
|
|
475
|
+
- Plugin architecture and interface
|
|
476
|
+
- Step-by-step tutorial for creating plugins
|
|
477
|
+
- Best practices and common patterns
|
|
478
|
+
- Real-world examples
|
|
479
|
+
- Troubleshooting tips
|
|
480
|
+
|
|
378
481
|
## Contributing
|
|
379
482
|
|
|
380
483
|
We welcome pull requests to Elements. Please read the contributing guide.
|