1import Anthropic from "@anthropic-ai/sdk";
2const client = new Anthropic();
3
4async function ask(prompt: string) {
5 const reply = await client.messages.create({
6 model: "claude-haiku-5-5", max_tokens: 2000,
7 messages: [{ role: "user", content: prompt }],
8 });
9 return reply.content.flatMap((b) => (b.type === "text" ? [b.text] : [])).join("");
10}
11
12const facts = "Dark mode ships 2 November. Turn it on in Settings, then Appearance.";
13const draft = await ask(`Write a 60-word launch note for our dark mode. <facts>${facts}</facts>`);
14const review = await ask(`<draft>${draft}</draft> Check it against: under 60 words, no jargon, mentions the date. List problems in <review> tags, or reply with only OK.`);
15const final = review.trim() === "OK" ? draft : await ask(`<draft>${draft}</draft> <review>${review}</review> Rewrite the draft to fix every problem.`);