diff --git a/frontend/src/api/event-service/event-service.api.ts b/frontend/src/api/event-service/event-service.api.ts index 3e7a42666b..7464480d5c 100644 --- a/frontend/src/api/event-service/event-service.api.ts +++ b/frontend/src/api/event-service/event-service.api.ts @@ -5,7 +5,6 @@ import type { ConfirmationResponseRequest, ConfirmationResponseResponse, } from "./event-service.types"; -import { openHands } from "../open-hands-axios"; class EventService { /** @@ -38,11 +37,27 @@ class EventService { return data; } - static async getEventCount(conversationId: string): Promise { - const params = new URLSearchParams(); - params.append("conversation_id__eq", conversationId); - const { data } = await openHands.get( - `/api/v1/events/count?${params.toString()}`, + /** + * Get event count for a V1 conversation + * @param conversationId The conversation ID + * @param conversationUrl The conversation URL (e.g., "http://localhost:54928/api/conversations/...") + * @param sessionApiKey Session API key for authentication (required for V1) + * @returns The event count + */ + static async getEventCount( + conversationId: string, + conversationUrl: string, + sessionApiKey?: string | null, + ): Promise { + // Build the runtime URL using the conversation URL + const runtimeUrl = buildHttpBaseUrl(conversationUrl); + + // Build session headers for authentication + const headers = buildSessionHeaders(sessionApiKey); + + const { data } = await axios.get( + `${runtimeUrl}/api/conversations/${conversationId}/events/count`, + { headers }, ); return data; } diff --git a/frontend/src/contexts/conversation-websocket-context.tsx b/frontend/src/contexts/conversation-websocket-context.tsx index 68c50f9499..8a8a205cd6 100644 --- a/frontend/src/contexts/conversation-websocket-context.tsx +++ b/frontend/src/contexts/conversation-websocket-context.tsx @@ -578,9 +578,13 @@ export function ConversationWebSocketProvider({ removeErrorMessage(); // Clear any previous error messages on successful connection // Fetch expected event count for history loading detection - if (conversationId) { + if (conversationId && conversationUrl) { try { - const count = await EventService.getEventCount(conversationId); + const count = await EventService.getEventCount( + conversationId, + conversationUrl, + sessionApiKey, + ); setExpectedEventCountMain(count); // If no events expected, mark as loaded immediately @@ -618,6 +622,7 @@ export function ConversationWebSocketProvider({ removeErrorMessage, sessionApiKey, conversationId, + conversationUrl, ]); // Separate WebSocket options for planning agent connection @@ -642,10 +647,15 @@ export function ConversationWebSocketProvider({ removeErrorMessage(); // Clear any previous error messages on successful connection // Fetch expected event count for history loading detection - if (planningAgentConversation?.id) { + if ( + planningAgentConversation?.id && + planningAgentConversation.conversation_url + ) { try { const count = await EventService.getEventCount( planningAgentConversation.id, + planningAgentConversation.conversation_url, + planningAgentConversation.session_api_key, ); setExpectedEventCountPlanning(count);