/ tools / AgentTool / agentColorManager.ts
agentColorManager.ts
 1  import { getAgentColorMap } from '../../bootstrap/state.js'
 2  import type { Theme } from '../../utils/theme.js'
 3  
 4  export type AgentColorName =
 5    | 'red'
 6    | 'blue'
 7    | 'green'
 8    | 'yellow'
 9    | 'purple'
10    | 'orange'
11    | 'pink'
12    | 'cyan'
13  
14  export const AGENT_COLORS: readonly AgentColorName[] = [
15    'red',
16    'blue',
17    'green',
18    'yellow',
19    'purple',
20    'orange',
21    'pink',
22    'cyan',
23  ] as const
24  
25  export const AGENT_COLOR_TO_THEME_COLOR = {
26    red: 'red_FOR_SUBAGENTS_ONLY',
27    blue: 'blue_FOR_SUBAGENTS_ONLY',
28    green: 'green_FOR_SUBAGENTS_ONLY',
29    yellow: 'yellow_FOR_SUBAGENTS_ONLY',
30    purple: 'purple_FOR_SUBAGENTS_ONLY',
31    orange: 'orange_FOR_SUBAGENTS_ONLY',
32    pink: 'pink_FOR_SUBAGENTS_ONLY',
33    cyan: 'cyan_FOR_SUBAGENTS_ONLY',
34  } as const satisfies Record<AgentColorName, keyof Theme>
35  
36  export function getAgentColor(agentType: string): keyof Theme | undefined {
37    if (agentType === 'general-purpose') {
38      return undefined
39    }
40  
41    const agentColorMap = getAgentColorMap()
42  
43    // Check if color already assigned
44    const existingColor = agentColorMap.get(agentType)
45    if (existingColor && AGENT_COLORS.includes(existingColor)) {
46      return AGENT_COLOR_TO_THEME_COLOR[existingColor]
47    }
48  
49    return undefined
50  }
51  
52  export function setAgentColor(
53    agentType: string,
54    color: AgentColorName | undefined,
55  ): void {
56    const agentColorMap = getAgentColorMap()
57  
58    if (!color) {
59      agentColorMap.delete(agentType)
60      return
61    }
62  
63    if (AGENT_COLORS.includes(color)) {
64      agentColorMap.set(agentType, color)
65    }
66  }