mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
fix(frontend): fix fetching the number of events on the front end (v1 conversations) (#11987)
This commit is contained in:
parent
5daada17fd
commit
d772dd65a5
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user