route.ts 725 B

1234567891011121314151617181920212223242526272829
  1. import { streamText } from "ai";
  2. import { dashboardCatalog } from "@/lib/render/catalog";
  3. export const maxDuration = 30;
  4. // Use the new catalog.prompt() API
  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. let fullPrompt = prompt;
  10. // Add data context
  11. if (context?.data) {
  12. fullPrompt += `\n\nAVAILABLE DATA:\n${JSON.stringify(context.data, null, 2)}`;
  13. }
  14. const result = streamText({
  15. model: process.env.AI_GATEWAY_MODEL || DEFAULT_MODEL,
  16. system: SYSTEM_PROMPT,
  17. prompt: fullPrompt,
  18. temperature: 0.7,
  19. });
  20. return result.toTextStreamResponse();
  21. }