新会话默认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)
|
||||
|
||||
Reference in New Issue
Block a user