Add Ralph status dialog and session management improvements (#171)

This commit is contained in:
Chris Scott authored and GitHub committed 2026-03-24 20:25:09 -04:00
1 parent 27352ea5cf
commit 86613b1ea4
12 files changed
+1132 -65

No files matched your search

+1 -1
View File
@@ -544,7 +544,7 @@ export const useAbortSession = (
attemptAbort();
if (repoId) {
cancelRalphLoop(String(repoId), targetSessionID).catch(() => {})
cancelRalphLoop(repoId, targetSessionID).catch(() => {})
}
retryIntervalRef.current = setInterval(() => {
+48
View File
@@ -0,0 +1,48 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { getRalphStatus, cancelRalphLoop } from '@/api/memory'
import { showToast } from '@/lib/toast'
export function useRalphStatus(repoId: number | undefined, open: boolean) {
const queryClient = useQueryClient()
const { data, isLoading, error } = useQuery({
queryKey: ['ralph-status', repoId],
queryFn: () => getRalphStatus(repoId!),
enabled: open && !!repoId,
staleTime: 0,
refetchInterval: ({ state }) => {
const loops = state.data?.loops ?? []
return loops.some(l => l.active) ? 5000 : false
},
})
const cancelMutation = useMutation({
mutationFn: ({ sessionId }: { sessionId: string }) =>
cancelRalphLoop(repoId!, sessionId),
onSuccess: (result) => {
if (result.cancelled) {
queryClient.invalidateQueries({ queryKey: ['ralph-status', repoId] })
} else {
showToast.error('Ralph loop is no longer active')
}
},
onError: () => {
showToast.error('Unable to cancel the Ralph loop. Please try again.')
},
})
const pendingSessionId = cancelMutation.isPending ? (cancelMutation.variables?.sessionId ?? null) : null
return { data, isLoading, error, cancelMutation, pendingSessionId }
}
export function useRalphActiveCount(repoId: number | undefined, enabled: boolean) {
const { data } = useQuery({
queryKey: ['ralph-status', repoId],
queryFn: () => getRalphStatus(repoId!),
enabled: enabled && !!repoId,
staleTime: 0,
refetchInterval: 10000,
})
return data?.loops.filter(l => l.active).length ?? 0
}