// This runs on the server import 'server-only'; import { Agent, run } from '@openai/agents'; import type { RealtimeItem } from '@openai/agents/realtime'; import z from 'zod'; const agent = new Agent({ name: 'Refund Expert', instructions: 'You are a refund expert. You are given a request to process a refund and you need to determine if the request is valid.', model: 'o4-mini', outputType: z.object({ reasong: z.string(), refundApproved: z.boolean(), }), }); export async function handleRefundRequest( request: string, history: RealtimeItem[], ) { const input = ` The user has requested a refund. The request is: ${request} Current conversation history: ${JSON.stringify(history, null, 2)} `.trim(); const result = await run(agent, input); return JSON.stringify(result.finalOutput, null, 2); }