Save to db on final ai state update (#429)
Co-authored-by: jb-dev1 <10735400+jb-dev1@users.noreply.github.com>
This commit is contained in:
parent
2a6bf4b00b
commit
124efca9a1
1 changed files with 22 additions and 23 deletions
|
|
@ -517,12 +517,14 @@ export const AI = createAI<AIState, UIState>({
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSetAIState: async ({ state }) => {
|
onSetAIState: async ({ state, done }) => {
|
||||||
'use server'
|
'use server'
|
||||||
|
|
||||||
const session = await auth()
|
if (!done) return
|
||||||
|
|
||||||
|
const session = await auth()
|
||||||
|
if (!session || !session.user) return
|
||||||
|
|
||||||
if (session && session.user) {
|
|
||||||
const { chatId, messages } = state
|
const { chatId, messages } = state
|
||||||
|
|
||||||
const createdAt = new Date()
|
const createdAt = new Date()
|
||||||
|
|
@ -542,9 +544,6 @@ export const AI = createAI<AIState, UIState>({
|
||||||
}
|
}
|
||||||
|
|
||||||
await saveChat(chat)
|
await saveChat(chat)
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue