@@ -364,7 +364,9 @@ export default function ChatPage() {
364364
365365 const fetchIntegrations = useCallback ( async ( ) => {
366366 try {
367- const res = await fetch ( "/api/settings/integrations" , { method : "POST" } )
367+ const res = await fetch ( "/api/settings/integrations" , {
368+ method : "POST"
369+ } )
368370 if ( ! res . ok ) throw new Error ( "Failed to fetch integrations" )
369371 const data = await res . json ( )
370372 setIntegrations ( data . integrations || [ ] )
@@ -614,24 +616,12 @@ export default function ChatPage() {
614616 if ( textareaRef . current ) textareaRef . current . style . height = "auto"
615617
616618 try {
617- const messagesToSend = updatedMessages . slice ( - 20 ) . map ( ( msg ) => {
618- let content = msg . content
619- if ( msg . replyToId ) {
620- const originalMsg = updatedMessages . find (
621- ( m ) => m . id === msg . replyToId
622- )
623- if ( originalMsg ) {
624- content = `<reply_to id="${ originalMsg . id } ">${ originalMsg . content } </reply_to>\n${ msg . content } `
625- }
626- }
627- return { id : msg . id , role : msg . role , content : content }
628- } )
629-
630619 const response = await fetch ( "/api/chat/message" , {
631620 method : "POST" ,
632621 headers : { "Content-Type" : "application/json" } ,
633622 body : JSON . stringify ( {
634- messages : messagesToSend
623+ // The server only needs the new user message to save it, then it fetches its own history.
624+ messages : [ newUserMessage ]
635625 } ) ,
636626 signal : abortControllerRef . current . signal
637627 } )
@@ -658,7 +648,8 @@ export default function ChatPage() {
658648 role : "assistant" ,
659649 content : "" ,
660650 timestamp : new Date ( ) . toISOString ( ) ,
661- tools : [ ]
651+ tools : [ ] ,
652+ turn_steps : [ ] // --- ADDED --- Initialize turn_steps for the new message
662653 }
663654 ] )
664655
@@ -708,6 +699,19 @@ export default function ChatPage() {
708699 setDisplayedMessages ( ( prev ) =>
709700 prev . map ( ( msg ) => {
710701 if ( msg . id === assistantMessageId ) {
702+ // --- CHANGED --- Handle the final 'done' event with parsed data
703+ if ( parsed . done ) {
704+ return {
705+ ...msg ,
706+ content :
707+ parsed . final_content ||
708+ msg . content , // Replace content with clean version
709+ turn_steps :
710+ parsed . turn_steps ||
711+ msg . turn_steps // Populate turn_steps
712+ }
713+ }
714+ // For intermediate chunks, just append the token
711715 return {
712716 ...msg ,
713717 content :
@@ -1801,9 +1805,7 @@ export default function ChatPage() {
18011805 role = { msg . role }
18021806 content = { msg . content }
18031807 tools = { msg . tools || [ ] }
1804- thoughts = { msg . thoughts || [ ] }
1805- tool_calls = { msg . tool_calls || [ ] }
1806- tool_results = { msg . tool_results || [ ] }
1808+ turn_steps = { msg . turn_steps || [ ] } // --- CHANGED --- Pass turn_steps instead of old props
18071809 onReply = { handleReply }
18081810 message = { msg }
18091811 allMessages = { displayedMessages }
0 commit comments