@gram-ai/elements 1.20.1 → 1.20.2

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.
@@ -173,6 +173,10 @@ const ElementsProviderWithApproval = ({
173
173
  // but runtime is created using transport. The ref gets populated after runtime creation.
174
174
  const runtimeRef = useRef<ReturnType<typeof useChatRuntime> | null>(null)
175
175
 
176
+ // Generate a stable chat ID for server-side persistence (when history is disabled)
177
+ // When history is enabled, the thread adapter manages chat IDs instead
178
+ const chatIdRef = useRef<string | null>(null)
179
+
176
180
  // Create chat transport configuration
177
181
  const transport = useMemo<ChatTransport<UIMessage>>(
178
182
  () => ({
@@ -183,18 +187,29 @@ const ElementsProviderWithApproval = ({
183
187
  throw new Error('Session is loading')
184
188
  }
185
189
 
190
+ // Generate chat ID on first message if not already set
191
+ if (!chatIdRef.current) {
192
+ chatIdRef.current = crypto.randomUUID()
193
+ }
194
+
186
195
  const context = runtimeRef.current?.thread.getModelContext()
187
196
  const frontendTools = toAISDKTools(
188
197
  getEnabledTools(context?.tools ?? {})
189
198
  )
190
199
 
200
+ // Include Gram-Chat-ID header for chat persistence
201
+ const headersWithChatId = {
202
+ ...auth.headers,
203
+ 'Gram-Chat-ID': chatIdRef.current,
204
+ }
205
+
191
206
  // Create OpenRouter model (only needed when not using custom model)
192
207
  const openRouterModel = usingCustomModel
193
208
  ? null
194
209
  : createOpenRouter({
195
210
  baseURL: apiUrl,
196
211
  apiKey: 'unused, but must be set',
197
- headers: auth.headers,
212
+ headers: headersWithChatId,
198
213
  })
199
214
 
200
215
  if (config.languageModel) {