优化 API 配置:一个弹窗完成接口、Key 与模型选择

- 去掉预设供应商,直接选择接口类型并填写 Base URL、API Key
- 可在保存前从接口拉取模型,搜索并勾选多个;也可手动输入模型名
- 适配中转站:漏写 /v1(Gemini 为 /v1beta)时自动补全,同时发送 Bearer 与官方鉴权头
- 保存时服务端同步连接下的模型列表;编辑时不填 Key 也可拉取
- 单模型测试与参数设置;手机端布局优化

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jocay
2026-10-18 02:23:09 +08:00
parent a472a86069
commit 283f40892a
10 changed files with 409 additions and 250 deletions
@@ -0,0 +1,27 @@
import { eq } from 'drizzle-orm'
import { z } from 'zod'
const schema = z.object({
type: z.enum(['openai-compatible', 'anthropic', 'google']),
baseUrl: z.string().default(''),
apiKey: z.string().default(''),
/** 编辑已有连接且未重新填写 Key 时,使用已保存的 Key */
providerId: z.string().optional()
})
/** 用(可能尚未保存的)连接配置拉取模型列表 */
export default defineEventHandler(async (event) => {
const body = await readJson(event, schema)
let apiKey = body.apiKey.trim()
if (!apiKey && body.providerId) {
const p = useDb().select().from(tables.providers).where(eq(tables.providers.id, body.providerId)).get()
if (p) apiKey = decryptSecret(p.apiKeyEnc)
}
if (!apiKey) throw createError({ statusCode: 400, message: '请先填写 API Key' })
try {
return await listRemoteModels(body.type, body.baseUrl, apiKey)
}
catch (err) {
throw createError({ statusCode: 502, message: `拉取模型列表失败:${describeError(err)}` })
}
})