Files
local-cal/src/app/api/ai-summary/route.ts
Dmytro Stanchiev 824768ce93 Add RRuleDisplay component and clean up unused imports
- Create new RRuleDisplay component for better recurrence rule formatting
- Replace Badge with RRuleDisplay in EventCard for improved UX
- Remove unused imports across multiple files (CalendarEvent, Badge, Card components)
- Remove unused catch parameter in ai-event route
2025-08-22 13:35:13 -04:00

46 lines
1.2 KiB
TypeScript

import { NextResponse } from "next/server";
export async function POST(request: Request) {
try {
const { events } = await request.json();
if (!events || !Array.isArray(events)) {
return NextResponse.json(
{ error: "Invalid events array" },
{ status: 400 },
);
}
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`, // Server-side only
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "@preset/i-cal-editor-summarize", // FREE model
messages: [
{
role: "system",
content: `You summarize a list of events in natural language. Include date, time, and title. Be concise.`,
},
{ role: "user", content: JSON.stringify(events) },
],
temperature: 0.4,
// max_tokens: 300,
}),
});
const data = await res.json();
const summary =
data?.choices?.[0]?.message?.content || "No summary generated.";
return NextResponse.json({ summary });
} catch (error) {
console.error(error);
return NextResponse.json(
{ error: "Failed to summarize events" },
{ status: 500 },
);
}
}