mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-25 16:42:16 +03:00
Adds `.safeParse()` to cli-tools/apply and cli-tools/config POST handlers to satisfy the check:route-validation:t06 CI gate. Regenerates all 41 locale translations of CLAUDE.md to clear the i18n strict-drift check failure.
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { requireCliToolsAuth } from "@/lib/api/requireCliToolsAuth";
|
|
import { generateConfig, generateAllConfigs } from "@/lib/cli-helper/config-generator";
|
|
|
|
const generateConfigSchema = z.object({
|
|
toolId: z.string().min(1),
|
|
baseUrl: z.string().optional(),
|
|
apiKey: z.string().min(1),
|
|
model: z.string().optional(),
|
|
});
|
|
|
|
// GET /api/cli-tools/config - List generated configs for all tools
|
|
export async function GET(request: Request) {
|
|
const authError = await requireCliToolsAuth(request);
|
|
if (authError) return authError;
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const baseUrl = searchParams.get("baseUrl") || "http://localhost:20128/v1";
|
|
const apiKey = searchParams.get("apiKey") || "";
|
|
|
|
if (!apiKey) {
|
|
return NextResponse.json({ error: "API key is required" }, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
const results = await generateAllConfigs({ baseUrl, apiKey });
|
|
return NextResponse.json({ configs: results });
|
|
} catch (error) {
|
|
console.log("Error generating configs:", error);
|
|
return NextResponse.json({ error: "Failed to generate configs" }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
// POST /api/cli-tools/config - Generate config for a specific tool
|
|
export async function POST(request: Request) {
|
|
const authError = await requireCliToolsAuth(request);
|
|
if (authError) return authError;
|
|
|
|
try {
|
|
const parsed = generateConfigSchema.safeParse(await request.json());
|
|
if (!parsed.success) {
|
|
return NextResponse.json(
|
|
{ error: parsed.error.issues[0]?.message ?? "Invalid request" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
const { toolId, baseUrl, apiKey, model } = parsed.data;
|
|
|
|
const result = await generateConfig(toolId, {
|
|
baseUrl: baseUrl || "http://localhost:20128/v1",
|
|
apiKey,
|
|
model,
|
|
});
|
|
|
|
if (!result.success) {
|
|
return NextResponse.json({ error: result.error }, { status: 400 });
|
|
}
|
|
|
|
return NextResponse.json({
|
|
configPath: result.configPath,
|
|
content: result.content,
|
|
});
|
|
} catch (error) {
|
|
console.log("Error generating config:", error);
|
|
return NextResponse.json({ error: "Failed to generate config" }, { status: 500 });
|
|
}
|
|
}
|