import { eq } from 'drizzle-orm' import { z } from 'zod' const schema = z.object({ name: z.string().min(1).optional(), type: z.enum(['openai-compatible', 'anthropic', 'google']).optional(), baseUrl: z.string().optional(), // 不传或传空字符串表示保留原有密钥 apiKey: z.string().optional() }) export default defineEventHandler(async (event) => { const id = param(event) const body = await readJson(event, schema) const patch: Partial = {} if (body.name !== undefined) patch.name = body.name if (body.type !== undefined) patch.type = body.type if (body.baseUrl !== undefined) patch.baseUrl = body.baseUrl.trim() if (body.apiKey) patch.apiKeyEnc = encryptSecret(body.apiKey.trim()) useDb().update(tables.providers).set(patch).where(eq(tables.providers.id, id)).run() return { ok: true } })