route.ts 666 B

123456789101112131415161718192021222324252627
  1. import { streamText } from "ai";
  2. import { buildUserPrompt } from "@json-render/core";
  3. import { dashboardCatalog } from "@/lib/render/catalog";
  4. export const maxDuration = 30;
  5. const SYSTEM_PROMPT = dashboardCatalog.prompt();
  6. const DEFAULT_MODEL = "anthropic/claude-haiku-4.5";
  7. export async function POST(req: Request) {
  8. const { prompt, context } = await req.json();
  9. const userPrompt = buildUserPrompt({
  10. prompt,
  11. state: context?.state,
  12. });
  13. const result = streamText({
  14. model: process.env.AI_GATEWAY_MODEL || DEFAULT_MODEL,
  15. system: SYSTEM_PROMPT,
  16. prompt: userPrompt,
  17. temperature: 0.7,
  18. });
  19. return result.toTextStreamResponse();
  20. }