fix(frontend): fix fetching the number of events on the front end (v1 conversations) (#11987)

This commit is contained in:
Hiep Le 2025-12-12 22:10:22 +07:00 committed by GitHub
parent 5daada17fd
commit d772dd65a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 9 deletions

View File

@ -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<number> {
const params = new URLSearchParams();
params.append("conversation_id__eq", conversationId);
const { data } = await openHands.get<number>(
`/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<number> {
// 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<number>(
`${runtimeUrl}/api/conversations/${conversationId}/events/count`,
{ headers },
);
return data;
}

View File

@ -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);