initial 2
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-06-26 09:26:50 +01:00
parent 194330fb47
commit 3b37368e7d
213 changed files with 14688 additions and 1 deletions

View File

@@ -0,0 +1,64 @@
import { handleApi } from "@/lib/api";
import { requireUser } from "@/lib/services/user";
import {
getPromptTemplate,
updatePromptTemplate,
resetPromptTemplate,
previewTemplate,
getTemplateVersions,
restoreTemplateVersion,
} from "@/lib/services/ai-templates";
export async function GET(
_request: Request,
{ params }: { params: Promise<{ key: string }> }
) {
const { key } = await params;
return handleApi(async () => {
const { user } = await requireUser();
const template = await getPromptTemplate(user.id, key);
const versions = await getTemplateVersions(user.id, key);
return { template, versions };
});
}
export async function PATCH(
request: Request,
{ params }: { params: Promise<{ key: string }> }
) {
const { key } = await params;
const body = await request.json();
return handleApi(async () => {
const { user } = await requireUser();
const template = await updatePromptTemplate(user.id, key, body);
return { template };
});
}
export async function POST(
request: Request,
{ params }: { params: Promise<{ key: string }> }
) {
const { key } = await params;
const { searchParams } = new URL(request.url);
const action = searchParams.get("action");
const body = await request.json().catch(() => ({}));
return handleApi(async () => {
const { user } = await requireUser();
if (action === "reset") {
const template = await resetPromptTemplate(user.id, key);
return { template };
}
if (action === "preview") {
const rendered = await previewTemplate(user.id, key, body.body);
return { rendered };
}
if (action === "restore" && body.version) {
const template = await restoreTemplateVersion(user.id, key, body.version);
return { template };
}
throw new Error("Unknown action");
});
}

View File

@@ -0,0 +1,12 @@
import { handleApi } from "@/lib/api";
import { requireUser } from "@/lib/services/user";
import { getPromptTemplates } from "@/lib/services/ai-templates";
import { PLACEHOLDER_DOCS } from "@/lib/ai/prompts/defaults";
export async function GET() {
return handleApi(async () => {
const { user } = await requireUser();
const templates = await getPromptTemplates(user.id);
return { templates, placeholders: PLACEHOLDER_DOCS };
});
}