Skip to content

Commit fb357f0

Browse files
committed
Ensure task result is always string
1 parent 10c84a0 commit fb357f0

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

web/src/state/chat/reducer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,16 @@ const taskToToolCall = (task: Task): ChatCompletionMessageToolCall => ({
231231

232232
/**
233233
* Converts a Task result to ActionChatMessageContent
234-
* Assumes task.result is always a string
234+
* Ensures task.result is converted to string before adding to content
235235
*/
236236
const taskResultToContent = (task: Task): ActionChatMessageContent => {
237+
const content = typeof task.result === 'string'
238+
? task.result
239+
: JSON.stringify(task.result)
240+
237241
return {
238242
type: 'BLANK',
239-
content: task.result as string,
243+
content,
240244
renderInfo: {
241245
text: '',
242246
code: undefined,

web/src/state/store.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,29 @@ const migrations = {
523523
let newState = {...state}
524524
newState.settings.useTeamMemory = false
525525
return newState
526+
},
527+
59: (state: RootState) => {
528+
let newState = {...state}
529+
// Ensure all tool call responses in chat messages are strings
530+
newState.chat.threads.forEach((thread) => {
531+
thread.messages.forEach((message) => {
532+
if (message.role === 'tool' && message.content && message.content.content !== undefined) {
533+
// If content is not already a string, convert it to string
534+
if (typeof message.content.content !== 'string') {
535+
message.content.content = JSON.stringify(message.content.content)
536+
}
537+
}
538+
})
539+
})
540+
return newState
526541
}
527542
}
528543

529544
const BLACKLIST = ['billing', 'cache', userStateApi.reducerPath, atlasApi.reducerPath]
530545

531546
const persistConfig = {
532547
key: 'root',
533-
version: 57,
548+
version: 59,
534549
storage,
535550
blacklist: BLACKLIST,
536551
// @ts-ignore

0 commit comments

Comments
 (0)