You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
import { defineWrappedResponseHandler } from "#server/utils/handler";
|
|
import { R } from "#server/utils/response";
|
|
import { requireAdmin } from "#server/utils/admin-guard";
|
|
import { createSystemProvider } from "#server/service/llm";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
await requireAdmin(event);
|
|
|
|
const body = await readBody(event);
|
|
const { name, slug, baseUrl, parseMode, apiKey, status, description } = body as {
|
|
name: string;
|
|
slug: string;
|
|
baseUrl?: string;
|
|
parseMode: string;
|
|
apiKey?: string;
|
|
status?: string;
|
|
description?: string;
|
|
};
|
|
|
|
if (!name || !slug || !parseMode) {
|
|
return R.error("参数无效:name、slug、parseMode 必填", null);
|
|
}
|
|
|
|
if (!["openai", "anthropic"].includes(parseMode)) {
|
|
return R.error("parseMode 仅支持 openai 或 anthropic", null);
|
|
}
|
|
|
|
const result = await createSystemProvider({
|
|
name,
|
|
slug,
|
|
baseUrl,
|
|
parseMode: parseMode as "openai" | "anthropic",
|
|
apiKey,
|
|
status: status as "active" | "inactive" | undefined,
|
|
description,
|
|
});
|
|
|
|
return R.success({ id: result.id });
|
|
});
|
|
|