mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat(servers): run Manager automation on linked servers
This commit is contained in:
1 parent
c591c15743
commit
a9bdb8358f
131 files changed
+6568
-949
No files matched your search
@@ -6,17 +6,20 @@ import {
|
||||
resumeSessionGoal,
|
||||
startSessionGoal,
|
||||
} from '@/api/sessionGoals'
|
||||
import { useOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
|
||||
import { serverScopedKey } from '@/lib/serverScope'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { SESSION_GOAL_POLL_INTERVAL_MS, type SessionGoal, type StartSessionGoalRequest } from '@opencode-manager/shared/schemas'
|
||||
|
||||
function sessionGoalQueryKey(sessionId: string) {
|
||||
return ['session-goal', sessionId] as const
|
||||
function sessionGoalQueryKey(sessionId: string, serverId: string) {
|
||||
return serverScopedKey(['session-goal', sessionId], serverId)
|
||||
}
|
||||
|
||||
export function useSessionGoal(sessionId: string, options: { enabled?: boolean } = {}) {
|
||||
const serverId = useOpenCodeServerId()
|
||||
return useQuery({
|
||||
queryKey: sessionGoalQueryKey(sessionId),
|
||||
queryFn: () => getLatestSessionGoal(sessionId),
|
||||
queryKey: sessionGoalQueryKey(sessionId, serverId),
|
||||
queryFn: () => getLatestSessionGoal(sessionId, serverId),
|
||||
enabled: options.enabled ?? true,
|
||||
refetchInterval: (query) => (query.state.data?.status === 'active' ? SESSION_GOAL_POLL_INTERVAL_MS : false),
|
||||
})
|
||||
@@ -30,7 +33,7 @@ function useGoalMutation<TInput>(
|
||||
return useMutation({
|
||||
mutationFn,
|
||||
onSuccess: (goal: SessionGoal) => {
|
||||
queryClient.setQueryData(sessionGoalQueryKey(goal.sessionId), goal)
|
||||
queryClient.setQueryData(sessionGoalQueryKey(goal.sessionId, goal.serverId), goal)
|
||||
},
|
||||
onError: (error: unknown) => {
|
||||
showToast.error(error instanceof Error ? error.message : errorMessage)
|
||||
@@ -39,7 +42,11 @@ function useGoalMutation<TInput>(
|
||||
}
|
||||
|
||||
export function useStartSessionGoal() {
|
||||
return useGoalMutation((input: StartSessionGoalRequest) => startSessionGoal(input), 'Failed to start goal')
|
||||
const serverId = useOpenCodeServerId()
|
||||
return useGoalMutation(
|
||||
(input: StartSessionGoalRequest) => startSessionGoal({ ...input, serverId }),
|
||||
'Failed to start goal',
|
||||
)
|
||||
}
|
||||
|
||||
export function usePauseSessionGoal() {
|
||||
|
||||
Reference in new issue
Block a user