chore: update to ai sdk v5 beta (#1074)
This commit is contained in:
parent
7d8e71383f
commit
4c281fe09d
54 changed files with 1372 additions and 1060 deletions
|
|
@ -6,8 +6,7 @@ import { Chat } from '@/components/chat';
|
|||
import { getChatById, getMessagesByChatId } from '@/lib/db/queries';
|
||||
import { DataStreamHandler } from '@/components/data-stream-handler';
|
||||
import { DEFAULT_CHAT_MODEL } from '@/lib/ai/models';
|
||||
import type { DBMessage } from '@/lib/db/schema';
|
||||
import type { Attachment, UIMessage } from 'ai';
|
||||
import { convertToUIMessages } from '@/lib/utils';
|
||||
|
||||
export default async function Page(props: { params: Promise<{ id: string }> }) {
|
||||
const params = await props.params;
|
||||
|
|
@ -38,18 +37,7 @@ 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 uiMessages = convertToUIMessages(messagesFromDb);
|
||||
|
||||
const cookieStore = await cookies();
|
||||
const chatModelFromCookie = cookieStore.get('chat-model');
|
||||
|
|
@ -59,14 +47,14 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
|
|||
<>
|
||||
<Chat
|
||||
id={chat.id}
|
||||
initialMessages={convertToUIMessages(messagesFromDb)}
|
||||
initialMessages={uiMessages}
|
||||
initialChatModel={DEFAULT_CHAT_MODEL}
|
||||
initialVisibilityType={chat.visibility}
|
||||
isReadonly={session?.user?.id !== chat.userId}
|
||||
session={session}
|
||||
autoResume={true}
|
||||
/>
|
||||
<DataStreamHandler id={id} />
|
||||
<DataStreamHandler />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -75,14 +63,14 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
|
|||
<>
|
||||
<Chat
|
||||
id={chat.id}
|
||||
initialMessages={convertToUIMessages(messagesFromDb)}
|
||||
initialMessages={uiMessages}
|
||||
initialChatModel={chatModelFromCookie.value}
|
||||
initialVisibilityType={chat.visibility}
|
||||
isReadonly={session?.user?.id !== chat.userId}
|
||||
session={session}
|
||||
autoResume={true}
|
||||
/>
|
||||
<DataStreamHandler id={id} />
|
||||
<DataStreamHandler />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue