@gram-ai/elements 1.18.6 → 1.18.7
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/dist/elements.cjs +21 -21
- package/dist/elements.cjs.map +1 -1
- package/dist/elements.css +1 -1
- package/dist/elements.js +1388 -1371
- package/dist/elements.js.map +1 -1
- package/package.json +1 -1
- package/src/components/assistant-ui/reasoning.tsx +2 -2
- package/src/contexts/ElementsProvider.tsx +33 -2
package/package.json
CHANGED
|
@@ -11,10 +11,10 @@ import {
|
|
|
11
11
|
} from 'react'
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
|
-
useScrollLock,
|
|
15
14
|
useAssistantState,
|
|
16
|
-
|
|
15
|
+
useScrollLock,
|
|
17
16
|
type ReasoningGroupComponent,
|
|
17
|
+
type ReasoningMessagePartComponent,
|
|
18
18
|
} from '@assistant-ui/react'
|
|
19
19
|
|
|
20
20
|
import { MarkdownText } from '@/components/assistant-ui/markdown-text'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FrontendTools } from '@/components/FrontendTools'
|
|
2
2
|
import { useMCPTools } from '@/hooks/useMCPTools'
|
|
3
3
|
import { useToolApproval } from '@/hooks/useToolApproval'
|
|
4
|
+
import { getApiUrl } from '@/lib/api'
|
|
4
5
|
import { MODELS } from '@/lib/models'
|
|
5
6
|
import {
|
|
6
7
|
clearFrontendToolApprovalConfig,
|
|
@@ -40,7 +41,6 @@ import {
|
|
|
40
41
|
import { useAuth } from '../hooks/useAuth'
|
|
41
42
|
import { ElementsContext } from './contexts'
|
|
42
43
|
import { ToolApprovalProvider } from './ToolApprovalContext'
|
|
43
|
-
import { getApiUrl } from '@/lib/api'
|
|
44
44
|
|
|
45
45
|
export interface ElementsProviderProps {
|
|
46
46
|
children: ReactNode
|
|
@@ -63,6 +63,33 @@ function mergeInternalSystemPromptWith(
|
|
|
63
63
|
${plugins.map((plugin) => `- ${plugin.language}: ${plugin.prompt}`).join('\n')}`
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Cleans messages before sending to the model to work around an AI SDK bug.
|
|
68
|
+
* Strips callProviderMetadata from all parts (AI SDK bug #9731)
|
|
69
|
+
*/
|
|
70
|
+
function cleanMessagesForModel(messages: UIMessage[]): UIMessage[] {
|
|
71
|
+
return messages.map((message) => {
|
|
72
|
+
const partsArray = message.parts
|
|
73
|
+
if (!Array.isArray(partsArray)) {
|
|
74
|
+
return message
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Process each part: strip providerOptions/providerMetadata and filter reasoning
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
const cleanedParts = partsArray.map((part: any) => {
|
|
80
|
+
// Strip providerOptions and providerMetadata from all remaining parts
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-vars
|
|
82
|
+
const { callProviderMetadata, ...cleanPart } = part
|
|
83
|
+
return cleanPart
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
...message,
|
|
88
|
+
parts: cleanedParts,
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
66
93
|
const ElementsProviderWithApproval = ({
|
|
67
94
|
children,
|
|
68
95
|
config,
|
|
@@ -180,10 +207,14 @@ const ElementsProviderWithApproval = ({
|
|
|
180
207
|
: openRouterModel!.chat(model)
|
|
181
208
|
|
|
182
209
|
try {
|
|
210
|
+
// This works around AI SDK bug where these fields cause validation failures
|
|
211
|
+
const cleanedMessages = cleanMessagesForModel(messages)
|
|
212
|
+
const modelMessages = convertToModelMessages(cleanedMessages)
|
|
213
|
+
|
|
183
214
|
const result = streamText({
|
|
184
215
|
system: systemPrompt,
|
|
185
216
|
model: modelToUse,
|
|
186
|
-
messages:
|
|
217
|
+
messages: modelMessages,
|
|
187
218
|
tools,
|
|
188
219
|
stopWhen: stepCountIs(10),
|
|
189
220
|
experimental_transform: smoothStream({ delayInMs: 15 }),
|