Skip to content

Commit 07f41f9

Browse files
committed
fix(copilot): preserve stream_id on conflict + propagate chat model from update-messages
1 parent b1b23b8 commit 07f41f9

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

apps/sim/app/api/copilot/chat/update-messages/route.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,14 @@ export const POST = withRouteHandler(async (req: NextRequest) => {
8787
updateData.config = config
8888
}
8989

90-
await db.update(copilotChats).set(updateData).where(eq(copilotChats.id, chatId))
91-
await replaceCopilotChatMessages(chatId, normalizedMessages)
90+
const [updated] = await db
91+
.update(copilotChats)
92+
.set(updateData)
93+
.where(eq(copilotChats.id, chatId))
94+
.returning({ model: copilotChats.model })
95+
await replaceCopilotChatMessages(chatId, normalizedMessages, {
96+
chatModel: updated?.model ?? null,
97+
})
9298

9399
logger.info(`[${tracker.requestId}] Successfully updated chat`, {
94100
chatId,

apps/sim/lib/copilot/chat/messages-dual-write.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export async function appendCopilotChatMessages(
4646
content: sql`excluded.content`,
4747
role: sql`excluded.role`,
4848
model: sql`COALESCE(excluded.model, ${copilotChatMessages.model})`,
49+
streamId: sql`COALESCE(excluded.stream_id, ${copilotChatMessages.streamId})`,
4950
updatedAt: sql`now()`,
5051
},
5152
})

0 commit comments

Comments
 (0)