新会话默认agent取Agents管理里排第一的Agent,而不是注册表里面的第一个

This commit is contained in:
xintaofei
2026-03-23 15:06:30 +08:00
parent 06bcb12329
commit 30f35e3bcb
4 changed files with 24 additions and 26 deletions

View File

@@ -31,6 +31,7 @@ export function AgentSelector({
const [selected, setSelected] = useState<AgentType | null>( const [selected, setSelected] = useState<AgentType | null>(
defaultAgentType ?? null defaultAgentType ?? null
) )
const selectedRef = useRef(selected)
const onSelectRef = useRef(onSelect) const onSelectRef = useRef(onSelect)
const onAgentsLoadedRef = useRef(onAgentsLoaded) const onAgentsLoadedRef = useRef(onAgentsLoaded)
@@ -58,23 +59,19 @@ export function AgentSelector({
const visible = sorted.filter((a) => a.enabled) const visible = sorted.filter((a) => a.enabled)
setAgents(visible) setAgents(visible)
onAgentsLoadedRef.current?.(visible) onAgentsLoadedRef.current?.(visible)
if (defaultAgentType) { // Keep current selection if still available; otherwise pick first.
const found = visible.find( const preferred = defaultAgentType ?? selectedRef.current
(a) => a.agent_type === defaultAgentType && a.available const found = preferred
) ? visible.find((a) => a.agent_type === preferred && a.available)
: null
if (found) { if (found) {
setSelected(found.agent_type) setSelected(found.agent_type)
selectedRef.current = found.agent_type
} else { } else {
const first = visible.find((a) => a.available) const first = visible.find((a) => a.available)
if (first) { if (first) {
setSelected(first.agent_type) setSelected(first.agent_type)
onSelectRef.current(first.agent_type) selectedRef.current = first.agent_type
}
}
} else {
const first = visible.find((a) => a.available)
if (first) {
setSelected(first.agent_type)
onSelectRef.current(first.agent_type) onSelectRef.current(first.agent_type)
} }
} }
@@ -119,6 +116,7 @@ export function AgentSelector({
const handleSelect = (agentType: AgentType) => { const handleSelect = (agentType: AgentType) => {
setSelected(agentType) setSelected(agentType)
selectedRef.current = agentType
onSelect(agentType) onSelect(agentType)
} }

View File

@@ -866,7 +866,9 @@ const ConversationTabView = memo(function ConversationTabView({
<div className="flex h-full min-h-0 flex-col items-center justify-center"> <div className="flex h-full min-h-0 flex-col items-center justify-center">
<div className="flex w-full max-w-2xl flex-col gap-4 px-4"> <div className="flex w-full max-w-2xl flex-col gap-4 px-4">
<AgentSelector <AgentSelector
defaultAgentType={selectedAgent} defaultAgentType={
conversationId != null ? selectedAgent : undefined
}
onSelect={handleAgentSelect} onSelect={handleAgentSelect}
onAgentsLoaded={(agents) => { onAgentsLoaded={(agents) => {
setAgentsLoaded(true) setAgentsLoaded(true)
@@ -917,7 +919,9 @@ const ConversationTabView = memo(function ConversationTabView({
<div className="flex h-full min-h-0 flex-col"> <div className="flex h-full min-h-0 flex-col">
<div className="px-4 pt-3 pb-2"> <div className="px-4 pt-3 pb-2">
<AgentSelector <AgentSelector
defaultAgentType={selectedAgent} defaultAgentType={
conversationId != null ? selectedAgent : undefined
}
onSelect={handleAgentSelect} onSelect={handleAgentSelect}
onAgentsLoaded={(agents) => { onAgentsLoaded={(agents) => {
setAgentsLoaded(true) setAgentsLoaded(true)

View File

@@ -25,7 +25,6 @@ interface SelectedConversation {
} }
interface NewConversationState { interface NewConversationState {
agentType: AgentType
workingDir: string workingDir: string
} }
@@ -44,7 +43,7 @@ interface FolderContextValue {
clearSelection: () => void clearSelection: () => void
newConversation: NewConversationState | null newConversation: NewConversationState | null
startNewConversation: (agentType: AgentType, workingDir: string) => void startNewConversation: (workingDir: string) => void
cancelNewConversation: () => void cancelNewConversation: () => void
stats: AgentStats | null stats: AgentStats | null
@@ -205,13 +204,10 @@ export function FolderProvider({
setSelectedConversation(null) setSelectedConversation(null)
}, []) }, [])
const startNewConversation = useCallback( const startNewConversation = useCallback((workingDir: string) => {
(agentType: AgentType, workingDir: string) => { setNewConversation({ workingDir })
setNewConversation({ agentType, workingDir })
setSelectedConversation(null) setSelectedConversation(null)
}, }, [])
[]
)
const cancelNewConversation = useCallback(() => { const cancelNewConversation = useCallback(() => {
setNewConversation(null) setNewConversation(null)

View File

@@ -322,7 +322,7 @@ export function TabProvider({ children }: TabProviderProps) {
cancelNewConversation() cancelNewConversation()
return return
} }
startNewConversation(tab.agentType, workingDir) startNewConversation(workingDir)
} }
}, },
[ [
@@ -588,7 +588,7 @@ export function TabProvider({ children }: TabProviderProps) {
setTabs((prev) => [...prev, newTab]) setTabs((prev) => [...prev, newTab])
setActiveTabId(tabId) setActiveTabId(tabId)
startNewConversation(agentType, workingDir) startNewConversation(workingDir)
activateConversationPane() activateConversationPane()
}, },
[activateConversationPane, startNewConversation, syncFolderContext, t] [activateConversationPane, startNewConversation, syncFolderContext, t]