From d6b416f5e7d2391241cf065f00353ad031c65f0e Mon Sep 17 00:00:00 2001 From: sp mac bookpro 2605 Date: Fri, 29 May 2026 14:18:42 +0800 Subject: [PATCH] refactor(chat): derive model options from agent detail --- src/pages/ChatPage.tsx | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/pages/ChatPage.tsx b/src/pages/ChatPage.tsx index d86e8e8..4771226 100644 --- a/src/pages/ChatPage.tsx +++ b/src/pages/ChatPage.tsx @@ -6,14 +6,12 @@ import ReactMarkdown from 'react-markdown'; import { Agent, AgentAPI, - AgentAllowedLLMResponse, BranchInfo, ChatAPI, ChatAttachment, ChatAttachmentsAPI, ChatMessage, ImageAPI, - LLMProviderAPI, ModelOverrides, RetrievedSnippet, SessionAPI, @@ -32,8 +30,8 @@ interface StreamingState { toolCalls: ToolCallTrace[]; } -const parseAllowedModels = (payload?: Pick | null) => - String(payload?.model || '') +const parseAgentModels = (value?: string) => + String(value || '') .split(',') .map((item) => item.trim()) .filter(Boolean); @@ -58,7 +56,6 @@ export default function ChatPage() { const [paramsDrawerOpen, setParamsDrawerOpen] = useState(false); const [tplDrawerOpen, setTplDrawerOpen] = useState(false); const [overrides, setOverrides] = useState({}); - const [allowedModels, setAllowedModels] = useState([]); const [attachments, setAttachments] = useState([]); const [imageUrls, setImageUrls] = useState([]); const [uploadingAtt, setUploadingAtt] = useState(false); @@ -111,16 +108,6 @@ export default function ChatPage() { } }; - const loadAllowedModels = async (agentId: string) => { - try { - const result = await LLMProviderAPI.allowedModels(agentId); - setAllowedModels(parseAllowedModels(result)); - } catch (e: any) { - setAllowedModels([]); - msg.error('加载智能体模型失败:' + (e?.message ?? e)); - } - }; - const loadMessages = async () => { if (!id || !sessionId) return; const his = await ChatAPI.history(id, sessionId); @@ -147,12 +134,10 @@ export default function ChatPage() { if (!id) { setAgent(null); setMessages([]); - setAllowedModels([]); setOverrides({}); return () => abortRef.current?.abort(); } loadAgent(); - loadAllowedModels(id); setOverrides({}); return () => abortRef.current?.abort(); // eslint-disable-next-line react-hooks/exhaustive-deps @@ -413,17 +398,18 @@ export default function ChatPage() { const isImageUrl = (url: string) => url?.startsWith('http') || url?.startsWith('/'); const agentModel = agent?.model || ''; - const modelOptions = allowedModels.map((modelName) => ({ + const agentModels = parseAgentModels(agentModel); + const modelOptions = agentModels.map((modelName) => ({ value: modelName, label: modelName })); const activeModelValue = overrides.model || ''; - const defaultModelLabel = allowedModels.length > 0 ? allowedModels.join(', ') : agentModel || '默认模型'; + const defaultModelLabel = agentModel || '默认模型'; const selectedModelKey = activeModelValue || '__default__'; const modelSelectOptions = [ { value: '__default__', - label: `跟随默认 · ${defaultModelLabel}` + label: defaultModelLabel }, ...modelOptions ];