@gram-ai/elements 1.16.4 → 1.17.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 CHANGED
@@ -4,13 +4,6 @@ Elements is a library built for the agentic age. We provide customizable and ele
4
4
 
5
5
  ## Setup
6
6
 
7
- ### Package Exports
8
-
9
- This package provides two separate exports with different dependencies:
10
-
11
- - **`@gram-ai/elements`** - React UI components (requires React and related dependencies)
12
- - **`@gram-ai/elements/server`** - Server-side handlers (does NOT require React)
13
-
14
7
  ### Frontend Setup
15
8
 
16
9
  First ensure that you have installed the required peer dependencies:
@@ -48,7 +41,16 @@ const app = express()
48
41
 
49
42
  app.use(express.json())
50
43
 
51
- app.post('/chat/completions', handlers.chat)
44
+ app.post('/chat/session', (req, res) =>
45
+ handlers.session(req, res, {
46
+ // The origin from which the token will be used
47
+ embedOrigin: 'http://localhost:3000',
48
+ // A free-form user identifier
49
+ userIdentifier: 'user-123',
50
+ // Token expiration in seconds (max / default 3600)
51
+ expiresAfter: 3600,
52
+ })
53
+ )
52
54
  ```
53
55
 
54
56
  You will need to add an environment variable to your backend and make it available to the process:
@@ -71,8 +73,6 @@ import '@gram-ai/elements/elements.css'
71
73
  const config: ElementsConfig = {
72
74
  projectSlug: 'xxx',
73
75
  mcp: 'https://app.getgram.ai/mcp/{your_slug}',
74
- // Points to your backend endpoint
75
- chatEndpoint: '/chat/completions',
76
76
  variant: 'widget',
77
77
  welcome: {
78
78
  title: 'Hello!',
@@ -95,6 +95,37 @@ export const App = () => {
95
95
  }
96
96
  ```
97
97
 
98
+ ### Custom Session Endpoint
99
+
100
+ By default, Elements expects the session endpoint on your backend to be located at `/chat/session`. If you've mounted your session endpoint at a different path, you can provide a custom `getSession` function in the `ElementsProvider`:
101
+
102
+ ```jsx
103
+ import { GramElementsProvider, Chat, type ElementsConfig, type GetSessionFn } from '@gram-ai/elements'
104
+ import '@gram-ai/elements/elements.css'
105
+
106
+ const config: ElementsConfig = {
107
+ projectSlug: 'xxx',
108
+ mcp: 'https://app.getgram.ai/mcp/{your_slug}',
109
+ // ... other config
110
+ }
111
+
112
+ const customGetSession: GetSessionFn = async () => {
113
+ const response = await fetch('/api/custom-session-endpoint', {
114
+ method: 'POST',
115
+ })
116
+ const data = await response.json()
117
+ return data.client_token
118
+ }
119
+
120
+ export const App = () => {
121
+ return (
122
+ <GramElementsProvider config={config} getSession={customGetSession}>
123
+ <Chat />
124
+ </GramElementsProvider>
125
+ )
126
+ }
127
+ ```
128
+
98
129
  ## Configuration
99
130
 
100
131
  For complete configuration options and TypeScript type definitions, see the [API documentation](./docs/interfaces/ElementsConfig.md).
@@ -108,7 +139,6 @@ import '@gram-ai/elements/elements.css'
108
139
  const config: ElementsConfig = {
109
140
  projectSlug: 'your-project',
110
141
  mcp: 'https://app.getgram.ai/mcp/your-mcp-slug',
111
- chatEndpoint: '/chat/completions',
112
142
  variant: 'widget', // 'widget' | 'sidecar' | 'standalone'
113
143
  welcome: {
114
144
  title: 'Hello!',
@@ -1,2 +1,2 @@
1
1
  import { ElementsProviderProps } from '../types';
2
- export declare const ElementsProvider: ({ children, config, }: ElementsProviderProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const ElementsProvider: (props: ElementsProviderProps) => import("react/jsx-runtime").JSX.Element;