99 DropdownMenuTrigger ,
1010} from '@/components/ui/dropdown-menu'
1111import { useAgents } from '@/hooks/useOpenCode'
12+ import { getAgentStyleVars } from '@/lib/agent-colors'
1213
1314interface AgentQuickSelectProps {
1415 opcodeUrl : string | null | undefined
@@ -19,33 +20,33 @@ interface AgentQuickSelectProps {
1920 disabled ?: boolean
2021}
2122
22- const getAgentStyles = ( agent : string ) => {
23- const lowerAgent = agent . toLowerCase ( )
24- if ( lowerAgent === 'plan' ) {
25- return {
26- color : 'text-yellow-600 dark:text-yellow-500' ,
27- bg : 'bg-yellow-500/20 border-yellow-400 hover:bg-yellow-500/30 hover:border-yellow-300' ,
28- shadow : 'shadow-yellow-500/20 hover:shadow-yellow-500/30' ,
29- }
30- }
31- if ( lowerAgent === 'build' ) {
32- return {
33- color : 'text-green-600 dark:text-green-500' ,
34- bg : 'bg-green-500/20 border-green-400 hover:bg-green-500/30 hover:border-green-300' ,
35- shadow : 'shadow-green-500/20 hover:shadow-green-500/30' ,
36- }
37- }
38- return {
39- color : 'text-blue-600 dark:text-blue-500' ,
40- bg : 'bg-blue-500/20 border-blue-400 hover:bg-blue-500/30 hover:border-blue-300' ,
41- shadow : 'shadow-blue-500/20 hover:shadow-blue-500/30' ,
42- }
23+ interface AgentInfo {
24+ name : string
25+ color ?: string
26+ description ?: string
27+ mode ?: string
28+ hidden ?: boolean
29+ }
30+
31+ const findAgentColor = ( agents : AgentInfo [ ] , agentName : string ) : string | undefined => {
32+ return agents . find ( a => a . name . toLowerCase ( ) === agentName . toLowerCase ( ) ) ?. color
4333}
4434
45- const bashStyles = {
46- color : 'text-purple-700 dark:text-purple-300' ,
47- bg : 'bg-purple-500/20 border-purple-400' ,
48- shadow : 'shadow-purple-500/20 hover:shadow-purple-500/30' ,
35+ const bashStyleVars : Record < string , string > = {
36+ '--agent-color-light' : '#a753ae' ,
37+ '--agent-color-dark' : '#edb2f1' ,
38+ '--agent-bg-light' : 'rgba(167, 83, 174, 0.2)' ,
39+ '--agent-bg-dark' : 'rgba(237, 178, 241, 0.2)' ,
40+ '--agent-bg-hover-light' : 'rgba(167, 83, 174, 0.3)' ,
41+ '--agent-bg-hover-dark' : 'rgba(237, 178, 241, 0.3)' ,
42+ '--agent-border-light' : 'rgba(167, 83, 174, 0.6)' ,
43+ '--agent-border-dark' : 'rgba(237, 178, 241, 0.6)' ,
44+ '--agent-border-hover-light' : 'rgba(167, 83, 174, 0.5)' ,
45+ '--agent-border-hover-dark' : 'rgba(237, 178, 241, 0.5)' ,
46+ '--agent-shadow-light' : 'rgba(167, 83, 174, 0.2)' ,
47+ '--agent-shadow-dark' : 'rgba(237, 178, 241, 0.2)' ,
48+ '--agent-shadow-hover-light' : 'rgba(167, 83, 174, 0.3)' ,
49+ '--agent-shadow-hover-dark' : 'rgba(237, 178, 241, 0.3)' ,
4950}
5051
5152export function AgentQuickSelect ( {
@@ -66,60 +67,52 @@ export function AgentQuickSelect({
6667 )
6768 } , [ agents ] )
6869
69- const handleToggle = ( ) => {
70- if ( primaryAgents . length === 0 ) return
71-
72- const currentIndex = primaryAgents . findIndex (
73- ( a ) => a . name . toLowerCase ( ) === currentAgent . toLowerCase ( )
74- )
75- const nextIndex = ( currentIndex + 1 ) % primaryAgents . length
76- onAgentChange ( primaryAgents [ nextIndex ] . name )
77- }
78-
7970 const handleSelect = ( agentName : string ) => {
8071 onAgentChange ( agentName )
8172 }
8273
83- const styles = isBashMode ? bashStyles : getAgentStyles ( currentAgent )
74+ const styleVars = isBashMode
75+ ? bashStyleVars
76+ : getAgentStyleVars ( currentAgent , findAgentColor ( agents , currentAgent ) )
8477 const displayName = isBashMode ? 'Bash' : capitalize ( currentAgent )
8578
8679 const buttonContent = (
8780 < button
8881 data-toggle-mode
89- onClick = { primaryAgents . length <= 2 ? handleToggle : undefined }
9082 disabled = { disabled }
91- className = { `px-2 md:px-3.5 py-1 h-[36px] rounded-lg text-sm font-medium border min-w-[48px] max-w-[80px] md:max-w-[100px] flex items-center justify-center transition-all duration-200 active:scale-95 hover:scale-105 shadow-md ${ styles . bg } ${ styles . color } ${ styles . shadow } ` }
83+ style = { styleVars as React . CSSProperties }
84+ className = "px-2 md:px-3.5 py-1 h-[36px] rounded-lg text-sm font-medium border min-w-[56px] max-w-[80px] md:max-w-[100px] flex-shrink-0 flex items-center justify-center transition-all duration-200 active:scale-95 hover:scale-105 shadow-md text-[var(--agent-color-light)] dark:text-[var(--agent-color-dark)] bg-[var(--agent-bg-light)] dark:bg-[var(--agent-bg-dark)] border-[var(--agent-border-light)] dark:border-[var(--agent-border-dark)] hover:bg-[var(--agent-bg-hover-light)] dark:hover:bg-[var(--agent-bg-hover-dark)] hover:border-[var(--agent-border-hover-light)] dark:hover:border-[var(--agent-border-hover-dark)] shadow-[var(--agent-shadow-light)] dark:shadow-[var(--agent-shadow-dark)] hover:shadow-[var(--agent-shadow-hover-light)] dark:hover:shadow-[var(--agent-shadow-hover-dark)]"
9285 >
9386 < span className = "truncate" > { displayName } </ span >
9487 </ button >
9588 )
9689
97- if ( primaryAgents . length <= 2 ) {
98- return buttonContent
99- }
100-
10190 return (
10291 < DropdownMenu >
10392 < DropdownMenuTrigger asChild disabled = { disabled } >
10493 { buttonContent }
10594 </ DropdownMenuTrigger >
106- < DropdownMenuContent align = "start" className = "w-48 " >
95+ < DropdownMenuContent align = "start" className = "w-64 " >
10796 { primaryAgents . map ( ( agent ) => {
108- const agentStyles = getAgentStyles ( agent . name )
97+ const apiColor = agent . color
98+ const itemStyleVars = getAgentStyleVars ( agent . name , apiColor )
10999 const isSelected = agent . name . toLowerCase ( ) === currentAgent . toLowerCase ( )
110100
111101 return (
112102 < DropdownMenuItem
113103 key = { agent . name }
114104 onClick = { ( ) => handleSelect ( agent . name ) }
115- className = "flex items-center justify-between"
105+ className = "group flex items-center justify-between"
116106 >
117- < div className = "flex flex-col" >
118- < span className = { `font-medium ${ agentStyles . color } ` } >
107+ < div className = "flex flex-col min-w-0" >
108+ < span
109+ className = "font-medium"
110+ style = { { color : itemStyleVars [ '--agent-color-light' ] } }
111+ >
119112 { capitalize ( agent . name ) }
120113 </ span >
121114 { agent . description && (
122- < span className = "text-xs text-muted-foreground truncate max-w-[160px] " >
115+ < span className = "text-xs text-muted-foreground line-clamp-2 group-hover:line-clamp-none " >
123116 { agent . description }
124117 </ span >
125118 ) }
0 commit comments