1- import type {
2- Attachment ,
3- ChatRequestOptions ,
4- CreateMessage ,
5- Message ,
6- } from 'ai' ;
1+ import type { Attachment , Message } from 'ai' ;
72import { formatDistance } from 'date-fns' ;
83import { AnimatePresence , motion } from 'framer-motion' ;
94import {
@@ -31,6 +26,7 @@ import { codeArtifact } from '@/artifacts/code/client';
3126import { sheetArtifact } from '@/artifacts/sheet/client' ;
3227import { textArtifact } from '@/artifacts/text/client' ;
3328import equal from 'fast-deep-equal' ;
29+ import { UseChatHelpers } from '@ai-sdk/react' ;
3430
3531export const artifactDefinitions = [
3632 textArtifact ,
@@ -60,7 +56,7 @@ function PureArtifact({
6056 input,
6157 setInput,
6258 handleSubmit,
63- isLoading ,
59+ status ,
6460 stop,
6561 attachments,
6662 setAttachments,
@@ -73,27 +69,17 @@ function PureArtifact({
7369} : {
7470 chatId : string ;
7571 input : string ;
76- setInput : ( input : string ) => void ;
77- isLoading : boolean ;
78- stop : ( ) => void ;
72+ setInput : UseChatHelpers [ 'setInput' ] ;
73+ status : UseChatHelpers [ 'status' ] ;
74+ stop : UseChatHelpers [ 'stop' ] ;
7975 attachments : Array < Attachment > ;
8076 setAttachments : Dispatch < SetStateAction < Array < Attachment > > > ;
8177 messages : Array < Message > ;
8278 setMessages : Dispatch < SetStateAction < Array < Message > > > ;
8379 votes : Array < Vote > | undefined ;
84- append : (
85- message : Message | CreateMessage ,
86- chatRequestOptions ?: ChatRequestOptions ,
87- ) => Promise < string | null | undefined > ;
88- handleSubmit : (
89- event ?: {
90- preventDefault ?: ( ) => void ;
91- } ,
92- chatRequestOptions ?: ChatRequestOptions ,
93- ) => void ;
94- reload : (
95- chatRequestOptions ?: ChatRequestOptions ,
96- ) => Promise < string | null | undefined > ;
80+ append : UseChatHelpers [ 'append' ] ;
81+ handleSubmit : UseChatHelpers [ 'handleSubmit' ] ;
82+ reload : UseChatHelpers [ 'reload' ] ;
9783 isReadonly : boolean ;
9884} ) {
9985 const { artifact, setArtifact, metadata, setMetadata } = useArtifact ( ) ;
@@ -269,6 +255,7 @@ function PureArtifact({
269255 < AnimatePresence >
270256 { artifact . isVisible && (
271257 < motion . div
258+ data-testid = "artifact"
272259 className = "flex flex-row h-dvh w-dvw fixed top-0 left-0 z-50 bg-transparent"
273260 initial = { { opacity : 1 } }
274261 animate = { { opacity : 1 } }
@@ -325,7 +312,7 @@ function PureArtifact({
325312 < div className = "flex flex-col h-full justify-between items-center gap-4" >
326313 < ArtifactMessages
327314 chatId = { chatId }
328- isLoading = { isLoading }
315+ status = { status }
329316 votes = { votes }
330317 messages = { messages }
331318 setMessages = { setMessages }
@@ -340,7 +327,7 @@ function PureArtifact({
340327 input = { input }
341328 setInput = { setInput }
342329 handleSubmit = { handleSubmit }
343- isLoading = { isLoading }
330+ status = { status }
344331 stop = { stop }
345332 attachments = { attachments }
346333 setAttachments = { setAttachments }
@@ -486,7 +473,7 @@ function PureArtifact({
486473 isToolbarVisible = { isToolbarVisible }
487474 setIsToolbarVisible = { setIsToolbarVisible }
488475 append = { append }
489- isLoading = { isLoading }
476+ status = { status }
490477 stop = { stop }
491478 setMessages = { setMessages }
492479 artifactKind = { artifact . kind }
@@ -512,7 +499,7 @@ function PureArtifact({
512499}
513500
514501export const Artifact = memo ( PureArtifact , ( prevProps , nextProps ) => {
515- if ( prevProps . isLoading !== nextProps . isLoading ) return false ;
502+ if ( prevProps . status !== nextProps . status ) return false ;
516503 if ( ! equal ( prevProps . votes , nextProps . votes ) ) return false ;
517504 if ( prevProps . input !== nextProps . input ) return false ;
518505 if ( ! equal ( prevProps . messages , nextProps . messages . length ) ) return false ;
0 commit comments