mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +01:00
- Introduced InMemoryJobStore, InMemoryEventTransport, and InMemoryContentState for improved job management and event handling. - Updated GenerationJobManager to utilize these new implementations, allowing for better separation of concerns and easier maintenance. - Enhanced job metadata handling to support user messages and response IDs for resumable functionality. - Improved cleanup and state management processes to prevent memory leaks and ensure efficient resource usage.
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { request } from 'librechat-data-provider';
|
|
import type { Agents } from 'librechat-data-provider';
|
|
|
|
export interface StreamStatusResponse {
|
|
active: boolean;
|
|
streamId?: string;
|
|
status?: 'running' | 'complete' | 'error' | 'aborted';
|
|
aggregatedContent?: Array<{ type: string; text?: string }>;
|
|
createdAt?: number;
|
|
resumeState?: Agents.ResumeState;
|
|
}
|
|
|
|
/**
|
|
* Query key for stream status
|
|
*/
|
|
export const streamStatusQueryKey = (conversationId: string) => ['streamStatus', conversationId];
|
|
|
|
/**
|
|
* Fetch stream status for a conversation
|
|
*/
|
|
export const fetchStreamStatus = async (conversationId: string): Promise<StreamStatusResponse> => {
|
|
console.log('[fetchStreamStatus] Fetching status for:', conversationId);
|
|
const result = await request.get<StreamStatusResponse>(
|
|
`/api/agents/chat/status/${conversationId}`,
|
|
);
|
|
console.log('[fetchStreamStatus] Result:', result);
|
|
return result;
|
|
};
|
|
|
|
/**
|
|
* React Query hook for checking if a conversation has an active generation stream.
|
|
* Only fetches when conversationId is provided and resumable streams are enabled.
|
|
*/
|
|
export function useStreamStatus(conversationId: string | undefined, enabled = true) {
|
|
return useQuery({
|
|
queryKey: streamStatusQueryKey(conversationId || ''),
|
|
queryFn: () => fetchStreamStatus(conversationId!),
|
|
enabled: !!conversationId && enabled,
|
|
staleTime: 1000, // Consider stale after 1 second
|
|
refetchOnMount: true,
|
|
refetchOnWindowFocus: true,
|
|
retry: false,
|
|
});
|
|
}
|