@@ -103,10 +103,29 @@ export function CopilotInterface({
103103 const mergedConfig = {
104104 ...aiConfig ,
105105 onError : ( error : any ) => {
106+
107+ // chatHook.
108+ chatHook ?. setMessages ( ( prevMessages ) => [
109+ ...prevMessages ,
110+ {
111+ role : 'assistant' ,
112+ id : `error-${ Date . now ( ) } ` ,
113+ createdAt : new Date ( ) ,
114+ parts : [
115+ { type : 'text' , text : error . message }
116+ ]
117+ } ,
118+ ] )
119+ // Optionally log the error to console or external service
120+ // e.g., console.error("AI Error:", error);
121+ // If you have a custom error handling function, call it here
122+ // customErrorHandler?.(error)
123+ // For example, if you want to send an error message to the chat:
124+ // This assumes chatHook has a method to send messages
125+ // If not, you can handle it differently based on your chat implementation
126+ // e.g., chatHook?.sendMessage({ text: error.message })
127+ // Or simply log it for now
106128 // console.error("Error in CopilotInterface:", error);
107- chatHook ?. sendMessage ( {
108- text : error . message ,
109- } )
110129 console . log ( error . code , error . message ) ;
111130 } ,
112131 // Add any default AI configuration here
@@ -117,7 +136,6 @@ export function CopilotInterface({
117136 // AI Chat Integration - use internal useChat by default, allow override
118137 const internalChat = useChat ( mergedConfig || { } )
119138 const chatHook = enableAI ? ( useCustomChat || internalChat ) : null
120-
121139 const [ localInput , setLocalInput ] = useState ( "" )
122140 const [ isTyping , setIsTyping ] = useState ( false )
123141
0 commit comments