21 lines
1.1 KiB
TypeScript
21 lines
1.1 KiB
TypeScript
import { z } from "zod";
|
|
import { auth } from "@/app/(auth)/auth";
|
|
import { resolveAgentWorkflowComposerSelections } from "@/lib/agents/workflow-composer";
|
|
import { AGENT_WORKFLOW_UI_CONFIG_KEY, normalizeAgentWorkflowUiConfig } from "@/lib/agents/workflow-ui-config";
|
|
import { getSystemSetting } from "@/lib/db/queries";
|
|
|
|
const selectionsSchema = z.record(z.string().max(160), z.string().max(8192))
|
|
.refine((selections) => Object.keys(selections).length <= 100);
|
|
|
|
export async function POST(request: Request) {
|
|
const session = await auth();
|
|
if (!session?.user?.id) return Response.json({ error: "请先登录" }, { status: 401 });
|
|
|
|
const selections = selectionsSchema.safeParse(await request.json().catch(() => null));
|
|
if (!selections.success) return Response.json({ error: "风格模板选择无效" }, { status: 400 });
|
|
|
|
const setting = await getSystemSetting({ key: AGENT_WORKFLOW_UI_CONFIG_KEY });
|
|
const config = normalizeAgentWorkflowUiConfig(setting?.value);
|
|
return Response.json({ selections: resolveAgentWorkflowComposerSelections({ config, selections: selections.data }) });
|
|
}
|