11import { useEffect , useState } from 'react' ;
2- import { styled } from 'styled-components' ;
2+ import { styled , useTheme } from 'styled-components' ;
33import { Row , Column } from '../Row' ;
4- import { FaPencil , FaPlus , FaTrash } from 'react-icons/fa6' ;
4+ import { FaPencil , FaPlus , FaTrash , FaStar } from 'react-icons/fa6' ;
55import { IconButton } from '../IconButton/IconButton' ;
66import { ModelSelect } from './ModelSelect' ;
7- import type { AIAgent , MCPServer } from './types' ;
7+ import type { AIAgent } from './types' ;
88import {
99 Dialog ,
1010 DialogTitle ,
@@ -17,9 +17,6 @@ import { Button } from '../Button';
1717import { SkeletonButton } from '../SkeletonButton' ;
1818import { useSettings } from '../../helpers/AppSettings' ;
1919import { Checkbox , CheckboxLabel } from '../forms/Checkbox' ;
20- import { generateObject } from 'ai' ;
21- import { createOpenRouter } from '@openrouter/ai-sdk-provider' ;
22- import { z } from 'zod' ;
2320
2421// Helper function to generate a unique ID
2522const generateId = ( ) => {
@@ -86,6 +83,10 @@ export const useAIAgentConfig = () => {
8683 'atomic.ai.autoAgentSelect' ,
8784 true ,
8885 ) ;
86+ const [ defaultAgentId , setDefaultAgentId ] = useLocalStorage < string > (
87+ 'atomic.ai.defaultAgentId' ,
88+ agents [ 0 ] ?. id || '' ,
89+ ) ;
8990
9091 // Save agents to settings
9192 const saveAgents = ( newAgents : AIAgent [ ] ) => {
@@ -97,57 +98,11 @@ export const useAIAgentConfig = () => {
9798 autoAgentSelectEnabled,
9899 setAutoAgentSelectEnabled,
99100 saveAgents,
101+ defaultAgentId,
102+ setDefaultAgentId,
100103 } ;
101104} ;
102105
103- function agentToText ( agent : AIAgent , mcpServers : MCPServer [ ] ) {
104- return `ID: ${ agent . id } Name: ${ agent . name } Description: ${ agent . description } Tools: ${ agent . availableTools . map ( t => mcpServers . find ( s => s . id === t ) ?. name ) . join ( ', ' ) } ` ;
105- }
106-
107- export const useAutoAgentSelect = ( ) => {
108- const { mcpServers, openRouterApiKey } = useSettings ( ) ;
109- const { agents } = useAIAgentConfig ( ) ;
110-
111- const openrouter = createOpenRouter ( {
112- apiKey : openRouterApiKey ,
113- compatibility : 'strict' ,
114- } ) ;
115-
116- const basePrompt = `You are a tool that determines what agent to use to answer the users question.
117- These are the agents to choose from
118-
119- ${ agents . map ( agent => agentToText ( agent , mcpServers ) ) . join ( '\n' ) }
120-
121- Answer with only the ID of the agent you pick
122-
123- User question: ` ;
124-
125- const pickAgent = async ( question : string ) : Promise < AIAgent > => {
126- const prompt = basePrompt + question . trim ( ) ;
127-
128- const { object } = await generateObject ( {
129- // model: openrouter('google/gemma-3-27b-it:free'),
130- model : openrouter ( 'google/gemini-2.0-flash-lite-preview-02-05:free' ) ,
131- schemaName : 'Agent' ,
132- schemaDescription : 'The agent to use for the question.' ,
133- schema : z . object ( {
134- agentId : z . string ( ) ,
135- } ) ,
136- prompt,
137- } ) ;
138-
139- const agent = agents . find ( a => a . id === object . agentId ) ;
140-
141- if ( ! agent ) {
142- throw new Error ( 'Agent not found' ) ;
143- }
144-
145- return agent ;
146- } ;
147-
148- return pickAgent ;
149- } ;
150-
151106export const AgentConfig = ( {
152107 open,
153108 onOpenChange,
@@ -159,10 +114,12 @@ export const AgentConfig = ({
159114 autoAgentSelectEnabled,
160115 setAutoAgentSelectEnabled,
161116 saveAgents,
117+ defaultAgentId,
118+ setDefaultAgentId,
162119 } = useAIAgentConfig ( ) ;
163120 const [ editingAgent , setEditingAgent ] = useState < AIAgent | null > ( null ) ;
164121 const [ isCreating , setIsCreating ] = useState ( false ) ;
165-
122+ const theme = useTheme ( ) ;
166123 const [ dialogProps , show , close , isOpen ] = useDialog ( {
167124 bindShow : onOpenChange ,
168125 } ) ;
@@ -262,7 +219,29 @@ export const AgentConfig = ({
262219 onClick = { ( ) => onSelectAgent ( agent ) }
263220 >
264221 < Column >
265- < AgentName > { agent . name } </ AgentName >
222+ < Row gap = '0.2ch' center >
223+ < IconButton
224+ onClick = { e => {
225+ e . stopPropagation ( ) ;
226+ setDefaultAgentId ( agent . id ) ;
227+ } }
228+ title = {
229+ defaultAgentId === agent . id
230+ ? 'Default agent'
231+ : 'Set as default'
232+ }
233+ edgeAlign = 'start'
234+ >
235+ < FaStar
236+ color = {
237+ defaultAgentId === agent . id
238+ ? theme . colors . main
239+ : theme . colors . bg2
240+ }
241+ />
242+ </ IconButton >
243+ < AgentName > { agent . name } </ AgentName >
244+ </ Row >
266245 < AgentDescription > { agent . description } </ AgentDescription >
267246 </ Column >
268247 < Row gap = '0.5rem' >
0 commit comments