mirror of
https://github.com/vercel-labs/json-render.git
synced 2026-10-20 06:19:57 +08:00
* add react-email workspace dependencies * add react-email package * add react-email example with Vercel Invite, Stripe Welcome and Nike Receipt * add render tests for react-email package * fix missing style prop on stripe-welcome logo Image * add react email documentation * add json render react email skill * fix @internal/react-state alias in vitest config Pre-existing issue: vitest could not resolve @internal/react-state, causing 6 test suites in packages/react and packages/react-pdf to fail. * fix PR review feedback - fix tsconfig: remove rootDir, expand include for test imports - fix render tests: add non-null assertions for noUncheckedIndexedAccess - fix dev script: add portless to match other examples - fix .env.example: correct comment from video to email generation - fix docs: add blank line before heading in installation page * merge latest * fix: update tsconfig extends from @repo to @internal/typescript-config * fixes * fixes --------- Co-authored-by: WManzoli <willmanzoli@gmail.com> Co-authored-by: Chris Tate <chris@ctate.dev>
35 lines
862 B
TypeScript
35 lines
862 B
TypeScript
import { streamText } from "ai";
|
|
import { buildUserPrompt, type Spec } from "@json-render/core";
|
|
import { emailCatalog } from "@/lib/catalog";
|
|
|
|
export const maxDuration = 60;
|
|
|
|
const SYSTEM_PROMPT = emailCatalog.prompt();
|
|
|
|
const DEFAULT_MODEL = "anthropic/claude-haiku-4.5";
|
|
|
|
export async function POST(req: Request) {
|
|
const { prompt, startingSpec } = (await req.json()) as {
|
|
prompt: string;
|
|
startingSpec?: Spec | null;
|
|
};
|
|
|
|
if (!prompt || typeof prompt !== "string") {
|
|
return Response.json({ error: "prompt is required" }, { status: 400 });
|
|
}
|
|
|
|
const userPrompt = buildUserPrompt({
|
|
prompt,
|
|
currentSpec: startingSpec,
|
|
});
|
|
|
|
const result = streamText({
|
|
model: process.env.AI_GATEWAY_MODEL ?? DEFAULT_MODEL,
|
|
system: SYSTEM_PROMPT,
|
|
prompt: userPrompt,
|
|
temperature: 0.7,
|
|
});
|
|
|
|
return result.toTextStreamResponse();
|
|
}
|