@@ -1742,20 +1742,30 @@ class ChatStore {
17421742 this . setConversationLoading ( this . activeConversation . id , true ) ;
17431743 this . clearConversationStreaming ( this . activeConversation . id ) ;
17441744
1745+ // Get current content (includes any edits made to the message)
1746+ // This comes from activeMessages which is kept in sync with the database
17451747 const originalContent = messageToContinue . content ;
17461748 const originalThinking = messageToContinue . thinking || '' ;
17471749
1748- // Get conversation context up to and including the message to continue
1749- const conversationContext = this . activeMessages . slice ( 0 , messageIndex + 1 ) ;
1750+ // Get conversation context up to (but not including) the message to continue
1751+ const conversationContext = this . activeMessages . slice ( 0 , messageIndex ) ;
17501752
17511753 // Add a synthetic "continue" prompt to signal continuation
1754+ // We check if original content ends with whitespace to preserve it in the instruction
1755+ const endsWithWhitespace = / \s $ / . test ( originalContent ) ;
1756+ const continueInstruction = endsWithWhitespace
1757+ ? 'Continue your response. Start directly without adding extra spacing.'
1758+ : 'Continue your response from where you left off.' ;
1759+
17521760 const continuePrompt : ApiChatMessageData = {
17531761 role : 'user' ,
1754- content : 'Continue from where you left off.'
1762+ content : continueInstruction
17551763 } ;
17561764
1765+ // Build context: all previous messages + assistant message + synthetic user prompt
1766+ // The user prompt is only sent to the API, not saved to the database
17571767 const contextWithContinue = [
1758- ...conversationContext . slice ( 0 , - 1 ) . map ( ( msg ) => {
1768+ ...conversationContext . map ( ( msg ) => {
17591769 if ( 'id' in msg && 'convId' in msg && 'timestamp' in msg ) {
17601770 return msg as DatabaseMessage & { extra ?: DatabaseMessageExtra [ ] } ;
17611771 }
@@ -1778,6 +1788,8 @@ class ChatStore {
17781788
17791789 onChunk : ( chunk : string ) => {
17801790 appendedContent += chunk ;
1791+ // Preserve originalContent exactly as-is, including any trailing whitespace
1792+ // The concatenation naturally preserves any whitespace at the end of originalContent
17811793 const fullContent = originalContent + appendedContent ;
17821794 this . setConversationStreaming (
17831795 messageToContinue . convId ,
0 commit comments