From 65b4b973dbd4f649fb3fdd6aab7d43ca10742877 Mon Sep 17 00:00:00 2001 From: Sun Tao <2605127667@qq.com> Date: Thu, 18 Dec 2025 00:23:40 +0800 Subject: [PATCH] update --- src/pages/Setting/Models.tsx | 529 +++++++++++++++++------------------ src/store/authStore.ts | 54 ++-- 2 files changed, 291 insertions(+), 292 deletions(-) diff --git a/src/pages/Setting/Models.tsx b/src/pages/Setting/Models.tsx index eec20bd77..b277c08df 100644 --- a/src/pages/Setting/Models.tsx +++ b/src/pages/Setting/Models.tsx @@ -73,9 +73,9 @@ export default function SettingModels() { INIT_PROVODERS.filter((p) => p.id !== "local").map(() => false) ); const [loading, setLoading] = useState(null); -const [errors, setErrors] = useState< - { apiKey?: string; apiHost?: string; model_type?: string; externalConfig?: string }[] ->(() => + const [errors, setErrors] = useState< + { apiKey?: string; apiHost?: string; model_type?: string; externalConfig?: string }[] + >(() => INIT_PROVODERS.filter((p) => p.id !== "local").map(() => ({ apiKey: "", apiHost: "", @@ -123,14 +123,14 @@ const [errors, setErrors] = useState< model_type: found.model_type ?? "", externalConfig: fi.externalConfig ? fi.externalConfig.map((ec) => { - if ( - found.encrypted_config && - found.encrypted_config[ec.key] !== undefined - ) { - return { ...ec, value: found.encrypted_config[ec.key] }; - } - return ec; - }) + if ( + found.encrypted_config && + found.encrypted_config[ec.key] !== undefined + ) { + return { ...ec, value: found.encrypted_config[ec.key] }; + } + return ec; + }) : undefined, }; } @@ -146,8 +146,8 @@ const [errors, setErrors] = useState< setLocalEndpoint(local.endpoint_url || ""); setLocalPlatform( local.encrypted_config?.model_platform || - local.provider_name || - "ollama" + local.provider_name || + "ollama" ); setLocalType(local.encrypted_config?.model_type || "llama3.2"); setLocalEnabled(local.is_valid ?? true); @@ -216,7 +216,7 @@ const [errors, setErrors] = useState< } console.log(form[idx]); - try { + try { const res = await fetchPost("/model/validate", { model_platform: item.id, model_type: form[idx].model_type, @@ -224,7 +224,7 @@ const [errors, setErrors] = useState< url: form[idx].apiHost, extra_params: external, }); - if (res.is_tool_calls && res.is_valid) { + if (res.is_tool_calls && res.is_valid) { console.log("success"); toast(t("setting.validate-success"), { description: t( @@ -233,27 +233,27 @@ const [errors, setErrors] = useState< closeButton: true, }); } else { - console.log("failed", res.message); - // Surface error inline on API Key input - setErrors((prev) => { - const next = [...prev]; - if (!next[idx]) next[idx] = {} as any; - next[idx].apiKey = getValidateMessage(res); - return next; - }); - return; + console.log("failed", res.message); + // Surface error inline on API Key input + setErrors((prev) => { + const next = [...prev]; + if (!next[idx]) next[idx] = {} as any; + next[idx].apiKey = getValidateMessage(res); + return next; + }); + return; } console.log(res); } catch (e) { - console.log(e); - // Network/exception case: show inline error - setErrors((prev) => { - const next = [...prev]; - if (!next[idx]) next[idx] = {} as any; - next[idx].apiKey = getValidateMessage(e); - return next; - }); - return; + console.log(e); + // Network/exception case: show inline error + setErrors((prev) => { + const next = [...prev]; + if (!next[idx]) next[idx] = {} as any; + next[idx].apiKey = getValidateMessage(e); + return next; + }); + return; } finally { setLoading(null); } @@ -296,14 +296,14 @@ const [errors, setErrors] = useState< prefer: found.prefer ?? false, externalConfig: fi.externalConfig ? fi.externalConfig.map((ec) => { - if ( - found.encrypted_config && - found.encrypted_config[ec.key] !== undefined - ) { - return { ...ec, value: found.encrypted_config[ec.key] }; - } - return ec; - }) + if ( + found.encrypted_config && + found.encrypted_config[ec.key] !== undefined + ) { + return { ...ec, value: found.encrypted_config[ec.key] }; + } + return ec; + }) : undefined, }; } @@ -436,8 +436,8 @@ const [errors, setErrors] = useState< setLocalPrefer(local.prefer ?? false); setLocalPlatform( local.encrypted_config?.model_platform || - local.provider_name || - localPlatform + local.provider_name || + localPlatform ); await handleLocalSwitch(true, local.id); } @@ -583,7 +583,7 @@ const [errors, setErrors] = useState< } }; -// removed bulk reset; only single-provider delete is supported + // removed bulk reset; only single-provider delete is supported const checkHasSearchKey = async () => { const configsRes = await proxyFetchGet("/api/configs"); @@ -630,37 +630,37 @@ const [errors, setErrors] = useState<
{t("setting.eigent-cloud-version")}
- {cloudPrefer ? ( - - ) : ( - - )} + {cloudPrefer ? ( + + ) : ( + + )}
@@ -726,20 +726,22 @@ const [errors, setErrors] = useState< {cloud_model_type === "gpt-4.1-mini" ? t("setting.gpt-4.1-mini") : cloud_model_type === "gpt-4.1" - ? t("setting.gpt-4.1") - : cloud_model_type === "claude-sonnet-4-5" - ? t("setting.claude-sonnet-4-5") - : cloud_model_type === "claude-sonnet-4-20250514" - ? t("setting.claude-sonnet-4") - : cloud_model_type === "claude-3-5-haiku-20241022" - ? t("setting.claude-3.5-haiku") - : cloud_model_type === "gemini-3-pro-preview" - ? t("setting.gemini-3-pro-preview") - : cloud_model_type === "gpt-5" - ? t("setting.gpt-5") - : cloud_model_type === "gpt-5-mini" - ? t("setting.gpt-5-mini") - : t("setting.gemini-2.5-pro")} + ? t("setting.gpt-4.1") + : cloud_model_type === "claude-sonnet-4-5" + ? t("setting.claude-sonnet-4-5") + : cloud_model_type === "claude-sonnet-4-20250514" + ? t("setting.claude-sonnet-4") + : cloud_model_type === "claude-3-5-haiku-20241022" + ? t("setting.claude-3.5-haiku") + : cloud_model_type === "gemini-3-pro-preview" + ? t("setting.gemini-3-pro-preview") + : cloud_model_type === "gpt-5" + ? t("setting.gpt-5") + : cloud_model_type === "gpt-5-mini" + ? t("setting.gpt-5-mini") + : cloud_model_type === "gemini-3-flash-preview" + ? t("setting.gemini-3-flash-preview") + : t("setting.gemini-2.5-pro")} @@ -756,6 +758,7 @@ const [errors, setErrors] = useState< Gemini 2.5 Pro Gemini 2.5 Flash Gemini 3 Pro Preview + Gemini 3 Flash Preview GPT-4.1 mini GPT-4.1 GPT-5 @@ -779,14 +782,14 @@ const [errors, setErrors] = useState<
{/* header */}
-
- - {t("setting.custom-model")} - - - {t("setting.use-your-own-api-keys-or-set-up-a-local-model")} - -
+
+ + {t("setting.custom-model")} + + + {t("setting.use-your-own-api-keys-or-set-up-a-local-model")} + +
- ) : ( - - )} + {form[idx].prefer ? ( + + ) : ( + + )}
- {item.description} -
+ {item.description} +
- {/* API Key Setting */} - : } - onBackIconClick={() => - setShowApiKey((arr) => arr.map((v, i) => (i === idx ? !v : v))) - } - value={form[idx].apiKey} - onChange={(e) => { - const v = e.target.value; - setForm((f) => - f.map((fi, i) => - i === idx ? { ...fi, apiKey: v } : fi - ) - ); - setErrors((errs) => - errs.map((er, i) => - i === idx ? { ...er, apiKey: "" } : er - ) - ); - }} - /> - {/* API Host Setting */} - : } + onBackIconClick={() => + setShowApiKey((arr) => arr.map((v, i) => (i === idx ? !v : v))) + } + value={form[idx].apiKey} + onChange={(e) => { + const v = e.target.value; + setForm((f) => + f.map((fi, i) => + i === idx ? { ...fi, apiKey: v } : fi + ) + ); + setErrors((errs) => + errs.map((er, i) => + i === idx ? { ...er, apiKey: "" } : er + ) + ); + }} + /> + {/* API Host Setting */} + { - const v = e.target.value; - setForm((f) => - f.map((fi, i) => - i === idx ? { ...fi, apiHost: v } : fi - ) - ); - setErrors((errs) => - errs.map((er, i) => - i === idx ? { ...er, apiHost: "" } : er - ) - ); - }} - /> - {/* Model Type Setting */} - { + const v = e.target.value; + setForm((f) => + f.map((fi, i) => + i === idx ? { ...fi, apiHost: v } : fi + ) + ); + setErrors((errs) => + errs.map((er, i) => + i === idx ? { ...er, apiHost: "" } : er + ) + ); + }} + /> + {/* Model Type Setting */} + { - const v = e.target.value; - setForm((f) => - f.map((fi, i) => - i === idx ? { ...fi, model_type: v } : fi - ) - ); - setErrors((errs) => - errs.map((er, i) => - i === idx ? { ...er, model_type: "" } : er - ) - ); - }} - /> - {/* externalConfig render */} + value={form[idx].model_type} + onChange={(e) => { + const v = e.target.value; + setForm((f) => + f.map((fi, i) => + i === idx ? { ...fi, model_type: v } : fi + ) + ); + setErrors((errs) => + errs.map((er, i) => + i === idx ? { ...er, model_type: "" } : er + ) + ); + }} + /> + {/* externalConfig render */} {item.externalConfig && form[idx].externalConfig && form[idx].externalConfig.map((ec, ecIdx) => ( @@ -948,14 +947,14 @@ const [errors, setErrors] = useState< f.map((fi, i) => i === idx ? { - ...fi, - externalConfig: fi.externalConfig?.map( - (eec, i2) => - i2 === ecIdx - ? { ...eec, value: v } - : eec - ), - } + ...fi, + externalConfig: fi.externalConfig?.map( + (eec, i2) => + i2 === ecIdx + ? { ...eec, value: v } + : eec + ), + } : fi ) ); @@ -985,14 +984,14 @@ const [errors, setErrors] = useState< f.map((fi, i) => i === idx ? { - ...fi, - externalConfig: fi.externalConfig?.map( - (eec, i2) => - i2 === ecIdx - ? { ...eec, value: v } - : eec - ), - } + ...fi, + externalConfig: fi.externalConfig?.map( + (eec, i2) => + i2 === ecIdx + ? { ...eec, value: v } + : eec + ), + } : fi ) ); @@ -1002,9 +1001,9 @@ const [errors, setErrors] = useState<
))} - {/* Action Button */} + {/* Action Button */}
- + diff --git a/src/store/authStore.ts b/src/store/authStore.ts index 3bdf08f5d..ca88739b5 100644 --- a/src/store/authStore.ts +++ b/src/store/authStore.ts @@ -4,7 +4,7 @@ import { persist } from 'zustand/middleware'; // type definition type InitState = 'permissions' | 'carousel' | 'done'; type ModelType = 'cloud' | 'local' | 'custom'; -type CloudModelType = 'gemini/gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-3-pro-preview' | 'gpt-4.1-mini' | 'gpt-4.1' | 'claude-sonnet-4-5' | 'claude-sonnet-4-20250514' | 'claude-3-5-haiku-20241022' | 'gpt-5' | 'gpt-5-mini'; +type CloudModelType = 'gemini/gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-3-pro-preview' | 'gemini-3-flash-preview' | 'gpt-4.1-mini' | 'gpt-4.1' | 'claude-sonnet-4-5' | 'claude-sonnet-4-20250514' | 'claude-3-5-haiku-20241022' | 'gpt-5' | 'gpt-5-mini'; // auth info interface interface AuthInfo { @@ -21,7 +21,7 @@ interface AuthState { username: string | null; email: string | null; user_id: number | null; - + // application settings appearance: string; language: string; @@ -29,21 +29,21 @@ interface AuthState { modelType: ModelType; cloud_model_type: CloudModelType; initState: InitState; - + // shared token share_token?: string | null; - + // local proxy value recorded at login localProxyValue?: string | null; - + // worker list data workerListData: { [key: string]: Agent[] }; - - // auth related methods - setAuth: (auth: AuthInfo) => void; - logout: () => void; - setLocalProxyValue: (value: string | null) => void; - + + // auth related methods + setAuth: (auth: AuthInfo) => void; + logout: () => void; + setLocalProxyValue: (value: string | null) => void; + // set related methods setAppearance: (appearance: string) => void; setLanguage: (language: string) => void; @@ -51,7 +51,7 @@ interface AuthState { setModelType: (modelType: ModelType) => void; setCloudModelType: (cloud_model_type: CloudModelType) => void; setIsFirstLaunch: (isFirstLaunch: boolean) => void; - + // worker related methods setWorkerList: (workerList: Agent[]) => void; checkAgentTool: (tool: string) => void; @@ -75,7 +75,7 @@ const authStore = create()( share_token: null, localProxyValue: null, workerListData: {}, - + // auth related methods setAuth: ({ token, username, email, user_id }) => set({ token, username, email, user_id }), @@ -89,25 +89,25 @@ const authStore = create()( initState: 'carousel', localProxyValue: null }), - + // set related methods setAppearance: (appearance) => set({ appearance }), - + setLanguage: (language) => set({ language }), - + setInitState: (initState) => { console.log('set({ initState })', initState); set({ initState }); }, - + setModelType: (modelType) => set({ modelType }), - + setCloudModelType: (cloud_model_type) => set({ cloud_model_type }), - + setIsFirstLaunch: (isFirstLaunch) => set({ isFirstLaunch }), - + setLocalProxyValue: (value) => set({ localProxyValue: value }), - + // worker related methods setWorkerList: (workerList) => { const { email } = get(); @@ -119,15 +119,15 @@ const authStore = create()( } })); }, - + checkAgentTool: (tool) => { const { email } = get(); set((state) => { const currentEmail = email as string; const originalList = state.workerListData[currentEmail] ?? []; - + console.log("tool!!!", tool); - + const updatedList = originalList .map((worker) => { const filteredTools = worker.tools?.filter((t) => t !== tool) ?? []; @@ -135,9 +135,9 @@ const authStore = create()( return { ...worker, tools: filteredTools }; }) .filter((worker) => worker.tools.length > 0); - + console.log("updatedList", updatedList); - + return { ...state, workerListData: { @@ -182,4 +182,4 @@ export const useWorkerList = (): Agent[] => { const { email, workerListData } = getAuthStore(); const workerList = workerListData[email as string]; return workerList ?? EMPTY_LIST; -}; \ No newline at end of file +};