agent.ts 762 B

1234567891011121314151617181920212223
  1. const defaults: Record<string, string> = {
  2. ask: "var(--icon-agent-ask-base)",
  3. build: "var(--icon-agent-build-base)",
  4. docs: "var(--icon-agent-docs-base)",
  5. plan: "var(--icon-agent-plan-base)",
  6. }
  7. export function agentColor(name: string, custom?: string) {
  8. if (custom) return custom
  9. return defaults[name] ?? defaults[name.toLowerCase()]
  10. }
  11. export function messageAgentColor(
  12. list: readonly { role: string; agent?: string }[] | undefined,
  13. agents: readonly { name: string; color?: string }[],
  14. ) {
  15. if (!list) return undefined
  16. for (let i = list.length - 1; i >= 0; i--) {
  17. const item = list[i]
  18. if (item.role !== "user" || !item.agent) continue
  19. return agentColor(item.agent, agents.find((agent) => agent.name === item.agent)?.color)
  20. }
  21. }