11import { useChat } from "@ai-sdk/vue" ;
2- import { computed , ref , watch } from "vue" ;
2+ import { computed , nextTick , ref , watch } from "vue" ;
33import {
44 AvailableProviders ,
55 AvailableModels ,
@@ -11,7 +11,7 @@ import { notify } from "@beekeeperstudio/plugin";
1111import { z } from "zod" ;
1212import { createProvider } from "@/providers" ;
1313import { useConfigurationStore } from "@/stores/configuration" ;
14- import { isReadQuery } from "@/utils" ;
14+ import { isEmptyUIMessage , isReadQuery } from "@/utils" ;
1515
1616type AIOptions = {
1717 initialMessages : Message [ ] ;
@@ -27,6 +27,9 @@ type SendOptions = {
2727}
2828
2929export function useAI ( options : AIOptions ) {
30+ /** FIXME: Only used because we want to retry automatically after an error.
31+ * REMOVE AFTER V5 UPGRADE. */
32+ const sendOptions = ref < SendOptions > ( ) ;
3033 const pendingToolCallIds = ref < string [ ] > ( [ ] ) ;
3134 const askingPermission = computed ( ( ) => pendingToolCallIds . value . length > 0 ) ;
3235 const followupAfterRejected = ref ( "" ) ;
@@ -90,6 +93,13 @@ export function useAI(options: AIOptions) {
9093 followupAfterRejected . value = "" ;
9194 // fillTitle();
9295 }
96+ } else if ( error . message . includes ( "all messages must have non-empty content" ) ) {
97+ // FIXME we dont need this once we upgrade to AI SDK v5 since we use `convertToModelMessages()`
98+ // See https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response
99+ messages . value = messages . value . filter ( ( m ) => ! isEmptyUIMessage ( m ) ) ;
100+ nextTick ( ) . then ( ( ) => {
101+ retry ( sendOptions . value ! ) ;
102+ } )
93103 }
94104 } ,
95105 onFinish : ( ) => {
@@ -150,6 +160,8 @@ export function useAI(options: AIOptions) {
150160
151161 /** Send a message to the AI */
152162 async function send ( message : string , options : SendOptions ) {
163+ // FIXME: Remove after v5 upgrade
164+ sendOptions . value = options ;
153165 await append (
154166 {
155167 role : "user" ,
@@ -165,6 +177,8 @@ export function useAI(options: AIOptions) {
165177 }
166178
167179 async function retry ( options : SendOptions ) {
180+ // FIXME: Remove after v5 upgrade
181+ sendOptions . value = options ;
168182 await reload ( {
169183 body : {
170184 sendOptions : options ,
0 commit comments