Skip to content

Commit b5cfdd1

Browse files
committed
v2 to path; multi conv
1 parent fa0ded1 commit b5cfdd1

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/modules/agents.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export function createAgentsModule({
1717
}: AgentsModuleConfig): AgentsModule {
1818
const baseURL = `/apps/${appId}/agents`;
1919

20+
// Track active conversations
21+
const currentConversations: Record<string, AgentConversation | undefined> = {};
22+
2023
const getConversations = () => {
2124
return axios.get<any, AgentConversation[]>(`${baseURL}/conversations`);
2225
};
@@ -45,7 +48,7 @@ export function createAgentsModule({
4548
message: AgentMessage
4649
) => {
4750
return axios.post<any, AgentMessage>(
48-
`${baseURL}/conversations/${conversation.id}/messages?api_version=v2`,
51+
`${baseURL}/conversations/v2/${conversation.id}/messages`,
4952
message
5053
);
5154
};
@@ -58,9 +61,8 @@ export function createAgentsModule({
5861
const socket = getSocket();
5962

6063
// Store the promise for initial conversation state
61-
let currentConversation: AgentConversation | undefined;
6264
const conversationPromise = getConversation(conversationId).then((conv) => {
63-
currentConversation = conv;
65+
currentConversations[conversationId] = conv;
6466
return conv;
6567
});
6668

@@ -74,7 +76,8 @@ export function createAgentsModule({
7476
await conversationPromise;
7577
const message = data._message as AgentMessage;
7678

77-
// Update local conversation state
79+
// Update shared conversation state
80+
const currentConversation = currentConversations[conversationId];
7881
if (currentConversation) {
7982
const messages = currentConversation.messages || [];
8083
const existingIndex = messages.findIndex((m) => m.id === message.id);
@@ -84,11 +87,11 @@ export function createAgentsModule({
8487
? messages.map((m, i) => (i === existingIndex ? message : m))
8588
: [...messages, message];
8689

87-
currentConversation = {
90+
currentConversations[conversationId] = {
8891
...currentConversation,
8992
messages: updatedMessages,
9093
};
91-
onUpdate?.(currentConversation);
94+
onUpdate?.(currentConversations[conversationId]!);
9295
}
9396
}
9497
},

0 commit comments

Comments
 (0)