Skip to content

Commit f56f641

Browse files
committed
fix chat history query
1 parent 98500a8 commit f56f641

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

apps/sim/hooks/queries/tasks.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,29 @@ export async function fetchChatHistory(
133133
chatId: string,
134134
signal?: AbortSignal
135135
): Promise<TaskChatHistory> {
136-
const response = await fetch(`/api/mothership/chats/${chatId}`, { signal })
136+
const mothershipRes = await fetch(`/api/mothership/chats/${chatId}`, { signal })
137+
138+
if (mothershipRes.ok) {
139+
const { chat } = await mothershipRes.json()
140+
return {
141+
id: chat.id,
142+
title: chat.title,
143+
messages: Array.isArray(chat.messages) ? chat.messages : [],
144+
activeStreamId: chat.conversationId || null,
145+
resources: Array.isArray(chat.resources) ? chat.resources : [],
146+
streamSnapshot: chat.streamSnapshot || null,
147+
}
148+
}
137149

138-
if (!response.ok) {
150+
const copilotRes = await fetch(`/api/copilot/chat?chatId=${encodeURIComponent(chatId)}`, {
151+
signal,
152+
})
153+
154+
if (!copilotRes.ok) {
139155
throw new Error('Failed to load chat')
140156
}
141157

142-
const { chat } = await response.json()
158+
const { chat } = await copilotRes.json()
143159
return {
144160
id: chat.id,
145161
title: chat.title,

0 commit comments

Comments
 (0)