@@ -52,7 +52,7 @@ export function createAgentsModule({
5252 } ) ;
5353 return axios . post < any , AgentMessage > (
5454 `${ baseURL } /conversations/${ conversation . id } /messages` ,
55- message
55+ { ... message , api_version : "v2" }
5656 ) ;
5757 } ;
5858
@@ -62,11 +62,39 @@ export function createAgentsModule({
6262 ) => {
6363 const room = `/agent-conversations/${ conversationId } ` ;
6464 const socket = getSocket ( ) ;
65+
66+ // Store the promise for initial conversation state
67+ let currentConversation : AgentConversation | undefined ;
68+ const conversationPromise = getConversation ( conversationId ) . then ( ( conv ) => {
69+ currentConversation = conv ;
70+ return conv ;
71+ } ) ;
72+
6573 return socket . subscribeToRoom ( room , {
6674 connect : ( ) => { } ,
67- update_model : ( { data : jsonStr } ) => {
68- const conv = JSON . parse ( jsonStr ) as AgentConversation ;
69- onUpdate ?.( conv ) ;
75+ update_model : async ( { data : jsonStr } ) => {
76+ const data = JSON . parse ( jsonStr ) ;
77+
78+ // Check if this is v2 format with _agent_message
79+ if ( data . _agent_message ) {
80+ // Wait for initial conversation to be loaded
81+ await conversationPromise ;
82+ const message = data . _agent_message as AgentMessage ;
83+
84+ // Update local conversation state
85+ if ( currentConversation ) {
86+ currentConversation = {
87+ ...currentConversation ,
88+ messages : [ ...( currentConversation . messages || [ ] ) , message ] ,
89+ } ;
90+ onUpdate ?.( currentConversation ) ;
91+ }
92+ } else {
93+ // Old format: full conversation object
94+ const conv = data as AgentConversation ;
95+ currentConversation = conv ;
96+ onUpdate ?.( conv ) ;
97+ }
7098 } ,
7199 } ) ;
72100 } ;
0 commit comments