From 6feace25293151cfd71c1be716e6e35a690a0098 Mon Sep 17 00:00:00 2001 From: Roy Miloh Date: Wed, 7 Jan 2026 15:49:23 -0300 Subject: [PATCH 1/5] send ongoing agent message only --- src/modules/agents.ts | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/modules/agents.ts b/src/modules/agents.ts index 3b8974c..2bbeb1e 100644 --- a/src/modules/agents.ts +++ b/src/modules/agents.ts @@ -52,7 +52,7 @@ export function createAgentsModule({ }); return axios.post( `${baseURL}/conversations/${conversation.id}/messages`, - message + { ...message, api_version: "v2" } ); }; @@ -62,11 +62,39 @@ export function createAgentsModule({ ) => { const room = `/agent-conversations/${conversationId}`; const socket = getSocket(); + + // Store the promise for initial conversation state + let currentConversation: AgentConversation | undefined; + const conversationPromise = getConversation(conversationId).then((conv) => { + currentConversation = conv; + return conv; + }); + return socket.subscribeToRoom(room, { connect: () => {}, - update_model: ({ data: jsonStr }) => { - const conv = JSON.parse(jsonStr) as AgentConversation; - onUpdate?.(conv); + update_model: async ({ data: jsonStr }) => { + const data = JSON.parse(jsonStr); + + // Check if this is v2 format with _agent_message + if (data._agent_message) { + // Wait for initial conversation to be loaded + await conversationPromise; + const message = data._agent_message as AgentMessage; + + // Update local conversation state + if (currentConversation) { + currentConversation = { + ...currentConversation, + messages: [...(currentConversation.messages || []), message], + }; + onUpdate?.(currentConversation); + } + } else { + // Old format: full conversation object + const conv = data as AgentConversation; + currentConversation = conv; + onUpdate?.(conv); + } }, }); }; From 29cecaeb5d3de706fa4b52a429cabf3fc8bf3947 Mon Sep 17 00:00:00 2001 From: Roy Miloh Date: Thu, 8 Jan 2026 07:58:11 -0300 Subject: [PATCH 2/5] streamed message --- src/modules/agents.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/modules/agents.ts b/src/modules/agents.ts index 2bbeb1e..d3206de 100644 --- a/src/modules/agents.ts +++ b/src/modules/agents.ts @@ -83,9 +83,17 @@ export function createAgentsModule({ // Update local conversation state if (currentConversation) { + const messages = currentConversation.messages || []; + const existingIndex = messages.findIndex((m) => m.id === message.id); + + const updatedMessages = + existingIndex !== -1 + ? messages.map((m, i) => (i === existingIndex ? message : m)) + : [...messages, message]; + currentConversation = { ...currentConversation, - messages: [...(currentConversation.messages || []), message], + messages: updatedMessages, }; onUpdate?.(currentConversation); } From 563ab6cea434d586fe538c02c432bf469816f959 Mon Sep 17 00:00:00 2001 From: Roy Miloh Date: Thu, 8 Jan 2026 08:38:07 -0300 Subject: [PATCH 3/5] stream any message --- src/modules/agents.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/modules/agents.ts b/src/modules/agents.ts index d3206de..bc04018 100644 --- a/src/modules/agents.ts +++ b/src/modules/agents.ts @@ -44,12 +44,6 @@ export function createAgentsModule({ conversation: AgentConversation, message: AgentMessage ) => { - const room = `/agent-conversations/${conversation.id}`; - const socket = getSocket(); - await socket.updateModel(room, { - ...conversation, - messages: [...(conversation.messages || []), message], - }); return axios.post( `${baseURL}/conversations/${conversation.id}/messages`, { ...message, api_version: "v2" } @@ -75,11 +69,10 @@ export function createAgentsModule({ update_model: async ({ data: jsonStr }) => { const data = JSON.parse(jsonStr); - // Check if this is v2 format with _agent_message - if (data._agent_message) { + if (data._message) { // Wait for initial conversation to be loaded await conversationPromise; - const message = data._agent_message as AgentMessage; + const message = data._message as AgentMessage; // Update local conversation state if (currentConversation) { @@ -97,11 +90,6 @@ export function createAgentsModule({ }; onUpdate?.(currentConversation); } - } else { - // Old format: full conversation object - const conv = data as AgentConversation; - currentConversation = conv; - onUpdate?.(conv); } }, }); From fa0ded19c7ef2088e81015a5a61970229c60c468 Mon Sep 17 00:00:00 2001 From: Roy Miloh Date: Thu, 8 Jan 2026 08:47:48 -0300 Subject: [PATCH 4/5] version to qp --- src/modules/agents.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/agents.ts b/src/modules/agents.ts index bc04018..7d83838 100644 --- a/src/modules/agents.ts +++ b/src/modules/agents.ts @@ -45,8 +45,8 @@ export function createAgentsModule({ message: AgentMessage ) => { return axios.post( - `${baseURL}/conversations/${conversation.id}/messages`, - { ...message, api_version: "v2" } + `${baseURL}/conversations/${conversation.id}/messages?api_version=v2`, + message ); }; From b5cfdd10f4b72b6501a6fc048803ade3b07c82a3 Mon Sep 17 00:00:00 2001 From: Roy Miloh Date: Tue, 13 Jan 2026 12:50:50 -0300 Subject: [PATCH 5/5] v2 to path; multi conv --- src/modules/agents.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/modules/agents.ts b/src/modules/agents.ts index 7d83838..9b28764 100644 --- a/src/modules/agents.ts +++ b/src/modules/agents.ts @@ -17,6 +17,9 @@ export function createAgentsModule({ }: AgentsModuleConfig): AgentsModule { const baseURL = `/apps/${appId}/agents`; + // Track active conversations + const currentConversations: Record = {}; + const getConversations = () => { return axios.get(`${baseURL}/conversations`); }; @@ -45,7 +48,7 @@ export function createAgentsModule({ message: AgentMessage ) => { return axios.post( - `${baseURL}/conversations/${conversation.id}/messages?api_version=v2`, + `${baseURL}/conversations/v2/${conversation.id}/messages`, message ); }; @@ -58,9 +61,8 @@ export function createAgentsModule({ const socket = getSocket(); // Store the promise for initial conversation state - let currentConversation: AgentConversation | undefined; const conversationPromise = getConversation(conversationId).then((conv) => { - currentConversation = conv; + currentConversations[conversationId] = conv; return conv; }); @@ -74,7 +76,8 @@ export function createAgentsModule({ await conversationPromise; const message = data._message as AgentMessage; - // Update local conversation state + // Update shared conversation state + const currentConversation = currentConversations[conversationId]; if (currentConversation) { const messages = currentConversation.messages || []; const existingIndex = messages.findIndex((m) => m.id === message.id); @@ -84,11 +87,11 @@ export function createAgentsModule({ ? messages.map((m, i) => (i === existingIndex ? message : m)) : [...messages, message]; - currentConversation = { + currentConversations[conversationId] = { ...currentConversation, messages: updatedMessages, }; - onUpdate?.(currentConversation); + onUpdate?.(currentConversations[conversationId]!); } } },