parent
d3b3449eb8
commit
f2320bf321
14 changed files with 879 additions and 145 deletions
|
|
@ -34,7 +34,7 @@ export async function GET(
|
|||
return new ChatSDKError('unauthorized:chat').toResponse();
|
||||
}
|
||||
|
||||
let chat: Chat;
|
||||
let chat: Chat | null;
|
||||
|
||||
try {
|
||||
chat = await getChatById({ id: chatId });
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import {
|
|||
saveChat,
|
||||
saveMessages,
|
||||
} from '@/lib/db/queries';
|
||||
import { updateChatLastContextById } from '@/lib/db/queries';
|
||||
import { convertToUIMessages, generateUUID } from '@/lib/utils';
|
||||
import { generateTitleFromUserMessage } from '../../actions';
|
||||
import { createDocument } from '@/lib/ai/tools/create-document';
|
||||
|
|
@ -208,6 +209,17 @@ export async function POST(request: Request) {
|
|||
chatId: id,
|
||||
})),
|
||||
});
|
||||
|
||||
if (finalUsage) {
|
||||
try {
|
||||
await updateChatLastContextById({
|
||||
chatId: id,
|
||||
context: finalUsage,
|
||||
});
|
||||
} catch (err) {
|
||||
console.warn('Unable to persist last usage for chat', id, err);
|
||||
}
|
||||
}
|
||||
},
|
||||
onError: () => {
|
||||
return 'Oops, an error occurred!';
|
||||
|
|
@ -251,7 +263,7 @@ export async function DELETE(request: Request) {
|
|||
|
||||
const chat = await getChatById({ id });
|
||||
|
||||
if (chat.userId !== session.user.id) {
|
||||
if (chat?.userId !== session.user.id) {
|
||||
return new ChatSDKError('forbidden:chat').toResponse();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue