From e721eadc06926769782fba70fb7440b8d63b565d Mon Sep 17 00:00:00 2001 From: bigboss2063 Date: Wed, 4 Mar 2026 21:09:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(ai):=20add=20=E9=98=BF=E9=87=8C=E4=BA=91?= =?UTF-8?q?=E7=99=BE=E7=82=BC=EF=BC=88Coding=20Plan=EF=BC=89=20provider=20?= =?UTF-8?q?with=20static=20model=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/core/setting/ai/modelSelect.tsx | 19 +++++++++++++++++-- src/app/core/setting/ai/page.tsx | 13 +++++++++---- src/app/core/setting/config.tsx | 20 +++++++++++++++++++- src/lib/ai/utils.ts | 2 ++ 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/app/core/setting/ai/modelSelect.tsx b/src/app/core/setting/ai/modelSelect.tsx index 73c7050c4..8d889fe80 100644 --- a/src/app/core/setting/ai/modelSelect.tsx +++ b/src/app/core/setting/ai/modelSelect.tsx @@ -15,7 +15,7 @@ import { CommandItem, CommandList, } from "@/components/ui/command"; -import { AiConfig } from "../config"; +import { AiConfig, baseAiConfig } from "../config"; import { Store } from "@tauri-apps/plugin-store"; import emitter from "@/lib/emitter"; @@ -56,7 +56,22 @@ export default function ModelSelect( if (requestId !== currentRequestIdRef.current) return if (!models) return - setList(models) + // 如果API返回空列表,尝试使用静态模型列表作为后备 + if (models.length === 0 && model) { + const baseConfig = baseAiConfig.find(c => c.baseURL === model.baseURL) + if (baseConfig?.staticModels?.length) { + setList(baseConfig.staticModels.map(id => ({ + id, + object: 'model' as const, + created: 0, + owned_by: baseConfig.key, + }))) + } else { + setList(models) + } + } else { + setList(models) + } // 如果没有传入aiConfig,则从store中设置model值 if (!aiConfig && setModel) { diff --git a/src/app/core/setting/ai/page.tsx b/src/app/core/setting/ai/page.tsx index 2ceccd71f..108444ab2 100644 --- a/src/app/core/setting/ai/page.tsx +++ b/src/app/core/setting/ai/page.tsx @@ -47,6 +47,11 @@ export default function AiPage() { // 当前选中的AI配置 const currentConfig = userCustomModels.find(model => model.key === selectedAiConfig) + + const getConfigDisplayTitle = (config?: AiConfig) => { + if (!config) return t('selectConfig') + return baseAiConfig.find(item => item.baseURL === config.baseURL)?.title || config.title + } const parseHeadersToKeyValue = (headers: Record = {}) => { return Object.entries(headers).map(([key, value]) => ({ @@ -282,13 +287,13 @@ export default function AiPage() {