πŸ“„ File detail

tools/AgentTool/agentColorManager.ts

🧩 .tsπŸ“ 67 linesπŸ’Ύ 1,499 bytesπŸ“ text
← Back to All Files

🎯 Use case

This module implements the β€œAgentTool” tool (Agent) β€” something the model can call at runtime alongside other agent tools. On the API surface it exposes AgentColorName, AGENT_COLORS, AGENT_COLOR_TO_THEME_COLOR, getAgentColor, and setAgentColor β€” mainly types, interfaces, or factory objects. It composes internal code from bootstrap and utils (relative imports).

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

import { getAgentColorMap } from '../../bootstrap/state.js' import type { Theme } from '../../utils/theme.js' export type AgentColorName = | 'red'

πŸ“€ Exports (heuristic)

  • AgentColorName
  • AGENT_COLORS
  • AGENT_COLOR_TO_THEME_COLOR
  • getAgentColor
  • setAgentColor

πŸ–₯️ Source preview

import { getAgentColorMap } from '../../bootstrap/state.js'
import type { Theme } from '../../utils/theme.js'

export type AgentColorName =
  | 'red'
  | 'blue'
  | 'green'
  | 'yellow'
  | 'purple'
  | 'orange'
  | 'pink'
  | 'cyan'

export const AGENT_COLORS: readonly AgentColorName[] = [
  'red',
  'blue',
  'green',
  'yellow',
  'purple',
  'orange',
  'pink',
  'cyan',
] as const

export const AGENT_COLOR_TO_THEME_COLOR = {
  red: 'red_FOR_SUBAGENTS_ONLY',
  blue: 'blue_FOR_SUBAGENTS_ONLY',
  green: 'green_FOR_SUBAGENTS_ONLY',
  yellow: 'yellow_FOR_SUBAGENTS_ONLY',
  purple: 'purple_FOR_SUBAGENTS_ONLY',
  orange: 'orange_FOR_SUBAGENTS_ONLY',
  pink: 'pink_FOR_SUBAGENTS_ONLY',
  cyan: 'cyan_FOR_SUBAGENTS_ONLY',
} as const satisfies Record<AgentColorName, keyof Theme>

export function getAgentColor(agentType: string): keyof Theme | undefined {
  if (agentType === 'general-purpose') {
    return undefined
  }

  const agentColorMap = getAgentColorMap()

  // Check if color already assigned
  const existingColor = agentColorMap.get(agentType)
  if (existingColor && AGENT_COLORS.includes(existingColor)) {
    return AGENT_COLOR_TO_THEME_COLOR[existingColor]
  }

  return undefined
}

export function setAgentColor(
  agentType: string,
  color: AgentColorName | undefined,
): void {
  const agentColorMap = getAgentColorMap()

  if (!color) {
    agentColorMap.delete(agentType)
    return
  }

  if (AGENT_COLORS.includes(color)) {
    agentColorMap.set(agentType, color)
  }
}