@@ -4,12 +4,14 @@ import {
44 findEmptyMessages ,
55 findEmptyMessageByIndex ,
66 findMessageByIndexNeedingThinking ,
7+ findMessagesWithEmptyTextParts ,
78 findMessagesWithOrphanThinking ,
89 findMessagesWithThinkingBlocks ,
910 findMessagesWithThinkingOnly ,
1011 injectTextPart ,
1112 prependThinkingPart ,
1213 readParts ,
14+ replaceEmptyTextParts ,
1315 stripThinkingParts ,
1416} from "./storage"
1517import type { MessageData } from "./types"
@@ -222,28 +224,48 @@ async function recoverEmptyContentMessage(
222224) : Promise < boolean > {
223225 const targetIndex = extractMessageIndex ( error )
224226 const failedID = failedAssistantMsg . info ?. id
227+ let anySuccess = false
228+
229+ const messagesWithEmptyText = findMessagesWithEmptyTextParts ( sessionID )
230+ for ( const messageID of messagesWithEmptyText ) {
231+ if ( replaceEmptyTextParts ( messageID , PLACEHOLDER_TEXT ) ) {
232+ anySuccess = true
233+ }
234+ }
225235
226236 const thinkingOnlyIDs = findMessagesWithThinkingOnly ( sessionID )
227237 for ( const messageID of thinkingOnlyIDs ) {
228- injectTextPart ( sessionID , messageID , PLACEHOLDER_TEXT )
238+ if ( injectTextPart ( sessionID , messageID , PLACEHOLDER_TEXT ) ) {
239+ anySuccess = true
240+ }
229241 }
230242
231243 if ( targetIndex !== null ) {
232244 const targetMessageID = findEmptyMessageByIndex ( sessionID , targetIndex )
233245 if ( targetMessageID ) {
234- return injectTextPart ( sessionID , targetMessageID , PLACEHOLDER_TEXT )
246+ if ( replaceEmptyTextParts ( targetMessageID , PLACEHOLDER_TEXT ) ) {
247+ return true
248+ }
249+ if ( injectTextPart ( sessionID , targetMessageID , PLACEHOLDER_TEXT ) ) {
250+ return true
251+ }
235252 }
236253 }
237254
238255 if ( failedID ) {
256+ if ( replaceEmptyTextParts ( failedID , PLACEHOLDER_TEXT ) ) {
257+ return true
258+ }
239259 if ( injectTextPart ( sessionID , failedID , PLACEHOLDER_TEXT ) ) {
240260 return true
241261 }
242262 }
243263
244264 const emptyMessageIDs = findEmptyMessages ( sessionID )
245- let anySuccess = thinkingOnlyIDs . length > 0
246265 for ( const messageID of emptyMessageIDs ) {
266+ if ( replaceEmptyTextParts ( messageID , PLACEHOLDER_TEXT ) ) {
267+ anySuccess = true
268+ }
247269 if ( injectTextPart ( sessionID , messageID , PLACEHOLDER_TEXT ) ) {
248270 anySuccess = true
249271 }
0 commit comments