import OpenAI from 'openai';
import * as dotenv from 'dotenv';
dotenv.config({ path: ['.env.local', '.env'] });

export const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

export async function askAgent(prompt: string) {
  try {
    const response = await openai.chat.completions.create({
      model: 'gpt-5.4',
      service_tier: 'flex',
      messages: [{ role: 'user', content: prompt }],
    });
    return response!.choices![0]!.message!.content;
  } catch (err) {
    console.error('Agent endpoint dummy error:', err instanceof Error ? err.message : err);
    return 'Agent is in dummy mode or encountered an error.';
  }
}
