re-voice/site/red-team-shadow-dossiers/services/roastClient.ts

24 lines
709 B
TypeScript

export interface RoastResponse {
text: string;
}
/**
* Client calls a server-side endpoint.
* IMPORTANT: Do not put model API keys in the browser bundle.
* Codex/server should implement POST /api/roast.
*/
export const generateRoast = async (content: string): Promise<string> => {
const resp = await fetch('/api/roast', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content })
});
if (!resp.ok) {
return 'Roast endpoint unavailable. (Server has not implemented /api/roast yet.)';
}
const data = (await resp.json().catch(() => null)) as RoastResponse | null;
if (!data?.text) return 'No output returned.';
return data.text;
};