新会话默认agent取Agents管理里排第一的Agent,而不是注册表里面的第一个
This commit is contained in:
@@ -31,6 +31,7 @@ export function AgentSelector({
|
||||
const [selected, setSelected] = useState<AgentType | null>(
|
||||
defaultAgentType ?? null
|
||||
)
|
||||
const selectedRef = useRef(selected)
|
||||
const onSelectRef = useRef(onSelect)
|
||||
const onAgentsLoadedRef = useRef(onAgentsLoaded)
|
||||
|
||||
@@ -58,23 +59,19 @@ export function AgentSelector({
|
||||
const visible = sorted.filter((a) => a.enabled)
|
||||
setAgents(visible)
|
||||
onAgentsLoadedRef.current?.(visible)
|
||||
if (defaultAgentType) {
|
||||
const found = visible.find(
|
||||
(a) => a.agent_type === defaultAgentType && a.available
|
||||
)
|
||||
if (found) {
|
||||
setSelected(found.agent_type)
|
||||
} else {
|
||||
const first = visible.find((a) => a.available)
|
||||
if (first) {
|
||||
setSelected(first.agent_type)
|
||||
onSelectRef.current(first.agent_type)
|
||||
}
|
||||
}
|
||||
// Keep current selection if still available; otherwise pick first.
|
||||
const preferred = defaultAgentType ?? selectedRef.current
|
||||
const found = preferred
|
||||
? visible.find((a) => a.agent_type === preferred && a.available)
|
||||
: null
|
||||
if (found) {
|
||||
setSelected(found.agent_type)
|
||||
selectedRef.current = found.agent_type
|
||||
} else {
|
||||
const first = visible.find((a) => a.available)
|
||||
if (first) {
|
||||
setSelected(first.agent_type)
|
||||
selectedRef.current = first.agent_type
|
||||
onSelectRef.current(first.agent_type)
|
||||
}
|
||||
}
|
||||
@@ -119,6 +116,7 @@ export function AgentSelector({
|
||||
|
||||
const handleSelect = (agentType: AgentType) => {
|
||||
setSelected(agentType)
|
||||
selectedRef.current = agentType
|
||||
onSelect(agentType)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 w-full max-w-2xl flex-col gap-4 px-4">
|
||||
<AgentSelector
|
||||
defaultAgentType={selectedAgent}
|
||||
defaultAgentType={
|
||||
conversationId != null ? selectedAgent : undefined
|
||||
}
|
||||
onSelect={handleAgentSelect}
|
||||
onAgentsLoaded={(agents) => {
|
||||
setAgentsLoaded(true)
|
||||
@@ -917,7 +919,9 @@ const ConversationTabView = memo(function ConversationTabView({
|
||||
<div className="flex h-full min-h-0 flex-col">
|
||||
<div className="px-4 pt-3 pb-2">
|
||||
<AgentSelector
|
||||
defaultAgentType={selectedAgent}
|
||||
defaultAgentType={
|
||||
conversationId != null ? selectedAgent : undefined
|
||||
}
|
||||
onSelect={handleAgentSelect}
|
||||
onAgentsLoaded={(agents) => {
|
||||
setAgentsLoaded(true)
|
||||
|
||||
@@ -25,7 +25,6 @@ interface SelectedConversation {
|
||||
}
|
||||
|
||||
interface NewConversationState {
|
||||
agentType: AgentType
|
||||
workingDir: string
|
||||
}
|
||||
|
||||
@@ -44,7 +43,7 @@ interface FolderContextValue {
|
||||
clearSelection: () => void
|
||||
|
||||
newConversation: NewConversationState | null
|
||||
startNewConversation: (agentType: AgentType, workingDir: string) => void
|
||||
startNewConversation: (workingDir: string) => void
|
||||
cancelNewConversation: () => void
|
||||
|
||||
stats: AgentStats | null
|
||||
@@ -205,13 +204,10 @@ export function FolderProvider({
|
||||
setSelectedConversation(null)
|
||||
}, [])
|
||||
|
||||
const startNewConversation = useCallback(
|
||||
(agentType: AgentType, workingDir: string) => {
|
||||
setNewConversation({ agentType, workingDir })
|
||||
setSelectedConversation(null)
|
||||
},
|
||||
[]
|
||||
)
|
||||
const startNewConversation = useCallback((workingDir: string) => {
|
||||
setNewConversation({ workingDir })
|
||||
setSelectedConversation(null)
|
||||
}, [])
|
||||
|
||||
const cancelNewConversation = useCallback(() => {
|
||||
setNewConversation(null)
|
||||
|
||||
@@ -322,7 +322,7 @@ export function TabProvider({ children }: TabProviderProps) {
|
||||
cancelNewConversation()
|
||||
return
|
||||
}
|
||||
startNewConversation(tab.agentType, workingDir)
|
||||
startNewConversation(workingDir)
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -588,7 +588,7 @@ export function TabProvider({ children }: TabProviderProps) {
|
||||
|
||||
setTabs((prev) => [...prev, newTab])
|
||||
setActiveTabId(tabId)
|
||||
startNewConversation(agentType, workingDir)
|
||||
startNewConversation(workingDir)
|
||||
activateConversationPane()
|
||||
},
|
||||
[activateConversationPane, startNewConversation, syncFolderContext, t]
|
||||
|
||||
Reference in New Issue
Block a user