We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d89c04d commit 864711cCopy full SHA for 864711c
1 file changed
docs/ai-chat/patterns/persistence-and-replay.mdx
@@ -142,7 +142,13 @@ export const myChat = chat.agent({
142
// See lifecycle-hooks for the full upsert pattern + rationale:
143
// /ai-chat/lifecycle-hooks#hydratemessages
144
if (upsertIncomingMessage(stored, { trigger, incomingMessages })) {
145
- await db.chat.update({ where: { id: chatId }, data: { messages: stored } });
+ // Upsert, not update: head-start first turns run without a preload
146
+ // to create the row.
147
+ await db.chat.upsert({
148
+ where: { id: chatId },
149
+ create: { id: chatId, messages: stored },
150
+ update: { messages: stored },
151
+ });
152
}
153
154
return stored;
0 commit comments