feat: edit and resubmit messages (#592)
This commit is contained in:
parent
2e479ccce7
commit
64d1aad2bb
12 changed files with 302 additions and 25 deletions
|
|
@ -4,6 +4,10 @@ import { type CoreUserMessage, generateText } from 'ai';
|
|||
import { cookies } from 'next/headers';
|
||||
|
||||
import { customModel } from '@/lib/ai';
|
||||
import {
|
||||
deleteMessagesByChatIdAfterTimestamp,
|
||||
getMessageById,
|
||||
} from '@/lib/db/queries';
|
||||
|
||||
export async function saveModelId(model: string) {
|
||||
const cookieStore = await cookies();
|
||||
|
|
@ -27,3 +31,12 @@ export async function generateTitleFromUserMessage({
|
|||
|
||||
return title;
|
||||
}
|
||||
|
||||
export async function deleteTrailingMessages({ id }: { id: string }) {
|
||||
const [message] = await getMessageById({ id });
|
||||
|
||||
await deleteMessagesByChatIdAfterTimestamp({
|
||||
chatId: message.chatId,
|
||||
timestamp: message.createdAt,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,14 +81,21 @@ export async function POST(request: Request) {
|
|||
await saveChat({ id, userId: session.user.id, title });
|
||||
}
|
||||
|
||||
const userMessageId = generateUUID();
|
||||
|
||||
await saveMessages({
|
||||
messages: [
|
||||
{ ...userMessage, id: generateUUID(), createdAt: new Date(), chatId: id },
|
||||
{ ...userMessage, id: userMessageId, createdAt: new Date(), chatId: id },
|
||||
],
|
||||
});
|
||||
|
||||
const streamingData = new StreamData();
|
||||
|
||||
streamingData.append({
|
||||
type: 'user-message-id',
|
||||
content: userMessageId,
|
||||
});
|
||||
|
||||
const result = streamText({
|
||||
model: customModel(model.apiIdentifier),
|
||||
system: systemPrompt,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue