mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Add Ralph status dialog and session management improvements (#171)
This commit is contained in:
1 parent
27352ea5cf
commit
86613b1ea4
12 files changed
+1132
-65
No files matched your search
@@ -544,7 +544,7 @@ export const useAbortSession = (
|
||||
attemptAbort();
|
||||
|
||||
if (repoId) {
|
||||
cancelRalphLoop(String(repoId), targetSessionID).catch(() => {})
|
||||
cancelRalphLoop(repoId, targetSessionID).catch(() => {})
|
||||
}
|
||||
|
||||
retryIntervalRef.current = setInterval(() => {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user