refactor: replace message.content with message.parts (#868)
This commit is contained in:
parent
553a3d825a
commit
47a630fd53
25 changed files with 1311 additions and 311 deletions
|
|
@ -4,9 +4,10 @@ import { notFound } from 'next/navigation';
|
|||
import { auth } from '@/app/(auth)/auth';
|
||||
import { Chat } from '@/components/chat';
|
||||
import { getChatById, getMessagesByChatId } from '@/lib/db/queries';
|
||||
import { convertToUIMessages } from '@/lib/utils';
|
||||
import { DataStreamHandler } from '@/components/data-stream-handler';
|
||||
import { DEFAULT_CHAT_MODEL } from '@/lib/ai/models';
|
||||
import { DBMessage } from '@/lib/db/schema';
|
||||
import { Attachment, UIMessage } from 'ai';
|
||||
|
||||
export default async function Page(props: { params: Promise<{ id: string }> }) {
|
||||
const params = await props.params;
|
||||
|
|
@ -33,6 +34,19 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
|
|||
id,
|
||||
});
|
||||
|
||||
function convertToUIMessages(messages: Array<DBMessage>): Array<UIMessage> {
|
||||
return messages.map((message) => ({
|
||||
id: message.id,
|
||||
parts: message.parts as UIMessage['parts'],
|
||||
role: message.role as UIMessage['role'],
|
||||
// Note: content will soon be deprecated in @ai-sdk/react
|
||||
content: '',
|
||||
createdAt: message.createdAt,
|
||||
experimental_attachments:
|
||||
(message.attachments as Array<Attachment>) ?? [],
|
||||
}));
|
||||
}
|
||||
|
||||
const cookieStore = await cookies();
|
||||
const chatModelFromCookie = cookieStore.get('chat-model');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue