File size: 2,409 Bytes
0cfd364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { apiClient } from '@/api/client';
import type { Agent } from '@/types';

export function useAgents(episodeId: string | undefined) {
  return useQuery({
    queryKey: ['episode', episodeId, 'agents'],
    queryFn: () => (episodeId ? apiClient.getAgents(episodeId) : []),
    enabled: !!episodeId,
    refetchInterval: 1000,
  });
}

export function useAgent(episodeId: string | undefined, agentId: string) {
  return useQuery({
    queryKey: ['episode', episodeId, 'agents', agentId],
    queryFn: () =>
      episodeId ? apiClient.getAgent(episodeId, agentId) : null,
    enabled: !!episodeId && !!agentId,
    refetchInterval: 500,
  });
}

export function useUpdateAgent(episodeId: string | undefined) {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: ({
      agentId,
      updates,
    }: {
      agentId: string;
      updates: Partial<Agent>;
    }) =>
      episodeId
        ? apiClient.updateAgent(episodeId, agentId, updates)
        : Promise.reject(new Error('No episode')),
    onSuccess: (_, { agentId }) => {
      queryClient.invalidateQueries({
        queryKey: ['episode', episodeId, 'agents', agentId],
      });
      queryClient.invalidateQueries({
        queryKey: ['episode', episodeId, 'agents'],
      });
    },
  });
}

export function getAgentStatusVariant(
  status: Agent['status']
): 'success' | 'warning' | 'error' | 'info' | 'neutral' {
  switch (status) {
    case 'acting':
      return 'success';
    case 'thinking':
      return 'info';
    case 'waiting':
      return 'warning';
    case 'error':
      return 'error';
    case 'idle':
    default:
      return 'neutral';
  }
}

export function getAgentRoleColor(role: Agent['role']): string {
  switch (role) {
    case 'navigator':
      return 'text-blue-400';
    case 'extractor':
      return 'text-purple-400';
    case 'validator':
      return 'text-green-400';
    case 'coordinator':
      return 'text-orange-400';
    default:
      return 'text-dark-400';
  }
}

export function getAgentRoleIcon(role: Agent['role']): string {
  switch (role) {
    case 'navigator':
      return '🧭';
    case 'extractor':
      return 'πŸ“Š';
    case 'validator':
      return 'βœ…';
    case 'coordinator':
      return '🎯';
    default:
      return 'πŸ€–';
  }
}

export type { Agent };