chore: update to ai sdk v5 beta (#1074)

This commit is contained in:
Jeremy 2025-07-03 02:26:34 -07:00 committed by GitHub
parent 7d8e71383f
commit 4c281fe09d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
54 changed files with 1372 additions and 1060 deletions

View file

@ -1,6 +1,6 @@
'use client';
import type { Attachment, UIMessage } from 'ai';
import type { UIMessage } from 'ai';
import cx from 'classnames';
import type React from 'react';
import {
@ -27,6 +27,7 @@ import { AnimatePresence, motion } from 'framer-motion';
import { ArrowDown } from 'lucide-react';
import { useScrollToBottom } from '@/hooks/use-scroll-to-bottom';
import type { VisibilityType } from './visibility-selector';
import type { Attachment, ChatMessage } from '@/lib/types';
function PureMultimodalInput({
chatId,
@ -38,22 +39,20 @@ function PureMultimodalInput({
setAttachments,
messages,
setMessages,
append,
handleSubmit,
sendMessage,
className,
selectedVisibilityType,
}: {
chatId: string;
input: UseChatHelpers['input'];
setInput: UseChatHelpers['setInput'];
status: UseChatHelpers['status'];
input: string;
setInput: Dispatch<SetStateAction<string>>;
status: UseChatHelpers<ChatMessage>['status'];
stop: () => void;
attachments: Array<Attachment>;
setAttachments: Dispatch<SetStateAction<Array<Attachment>>>;
messages: Array<UIMessage>;
setMessages: UseChatHelpers['setMessages'];
append: UseChatHelpers['append'];
handleSubmit: UseChatHelpers['handleSubmit'];
setMessages: UseChatHelpers<ChatMessage>['setMessages'];
sendMessage: UseChatHelpers<ChatMessage>['sendMessage'];
className?: string;
selectedVisibilityType: VisibilityType;
}) {
@ -112,20 +111,35 @@ function PureMultimodalInput({
const submitForm = useCallback(() => {
window.history.replaceState({}, '', `/chat/${chatId}`);
handleSubmit(undefined, {
experimental_attachments: attachments,
sendMessage({
role: 'user',
parts: [
...attachments.map((attachment) => ({
type: 'file' as const,
url: attachment.url,
name: attachment.name,
mediaType: attachment.contentType,
})),
{
type: 'text',
text: input,
},
],
});
setAttachments([]);
setLocalStorageInput('');
resetHeight();
setInput('');
if (width && width > 768) {
textareaRef.current?.focus();
}
}, [
input,
setInput,
attachments,
handleSubmit,
sendMessage,
setAttachments,
setLocalStorageInput,
width,
@ -224,7 +238,7 @@ function PureMultimodalInput({
attachments.length === 0 &&
uploadQueue.length === 0 && (
<SuggestedActions
append={append}
sendMessage={sendMessage}
chatId={chatId}
selectedVisibilityType={selectedVisibilityType}
/>
@ -328,7 +342,7 @@ function PureAttachmentsButton({
status,
}: {
fileInputRef: React.MutableRefObject<HTMLInputElement | null>;
status: UseChatHelpers['status'];
status: UseChatHelpers<ChatMessage>['status'];
}) {
return (
<Button
@ -353,7 +367,7 @@ function PureStopButton({
setMessages,
}: {
stop: () => void;
setMessages: UseChatHelpers['setMessages'];
setMessages: UseChatHelpers<ChatMessage>['setMessages'];
}) {
return (
<Button