feat(ai): replace hardcoded design kits with dynamic open-design templates and registries

This commit is contained in:
2026-05-15 13:49:16 -07:00
parent 8487acc9e0
commit 895fd8a961
937 changed files with 236485 additions and 266 deletions

View File

@@ -18,6 +18,8 @@
*/
import { NextResponse } from "next/server";
import fs from "fs";
import path from "path";
import { BigQuery } from "@google-cloud/bigquery";
import { toolBrowserConsole, toolBrowserNavigate } from "./browser";
import { requireWorkspacePrincipal } from "@/lib/auth/workspace-auth";
@@ -424,6 +426,8 @@ export async function POST(request: Request) {
return await toolFsWrite(principal, params);
case "fs.edit":
return await toolFsEdit(principal, params);
case "get_design_template":
return await toolGetDesignTemplate(params);
case "apps.templates.scaffold":
return await toolAppsTemplatesScaffold(principal, params);
case "generate_media":
@@ -4614,6 +4618,48 @@ async function toolFsRead(principal: Principal, params: Record<string, any>) {
});
}
async function toolGetDesignTemplate(params: Record<string, unknown>) {
const templateId = String(params.template_id || "").trim();
if (!templateId) {
return NextResponse.json(
{ error: "Missing required parameter 'template_id'" },
{ status: 400 },
);
}
// Prevent directory traversal
if (templateId.includes("..") || templateId.includes("/")) {
return NextResponse.json({ error: "Invalid template_id" }, { status: 400 });
}
const skillPath = path.join(
process.cwd(),
"lib",
"scaffold",
"open-design",
"design-templates",
templateId,
"SKILL.md",
);
try {
if (!fs.existsSync(skillPath)) {
return NextResponse.json(
{ error: `Template '${templateId}' not found or missing SKILL.md` },
{ status: 404 },
);
}
const content = await fs.promises.readFile(skillPath, "utf-8");
return NextResponse.json({ result: { content } });
} catch (err: any) {
return NextResponse.json(
{ error: `Failed to read template: ${err.message}` },
{ status: 500 },
);
}
}
async function toolAppsTemplatesScaffold(
principal: Principal,
params: Record<string, any>,