import Anthropic from "@anthropic-ai/sdk";
import OpenAI from "openai";
import { env } from "../env.js";

export function openaiClient() {
  if (!env.OPENAI_API_KEY) throw new Error("OPENAI_API_KEY not set");
  return new OpenAI({ apiKey: env.OPENAI_API_KEY });
}

// xAI (Grok) is OpenAI-compatible at https://api.x.ai/v1
export function xaiClient() {
  if (!env.XAI_API_KEY) throw new Error("XAI_API_KEY not set");
  return new OpenAI({ apiKey: env.XAI_API_KEY, baseURL: "https://api.x.ai/v1" });
}

export function geminiClient() {
  if (!env.GEMINI_API_KEY) throw new Error("GEMINI_API_KEY not set");
  return {
    apiKey: env.GEMINI_API_KEY,
    baseURL: "https://generativelanguage.googleapis.com/v1beta",
  };
}

export function isHermesAgentConfigured() {
  return Boolean(env.HERMES_AGENT_API_KEY);
}

export function hermesAgentClient() {
  if (!env.HERMES_AGENT_API_KEY) throw new Error("HERMES_AGENT_API_KEY not set");
  return new OpenAI({
    apiKey: env.HERMES_AGENT_API_KEY,
    baseURL: env.HERMES_AGENT_API_BASE_URL,
  });
}

export function anthropicClient() {
  if (!env.ANTHROPIC_API_KEY) throw new Error("ANTHROPIC_API_KEY not set");
  return new Anthropic({ apiKey: env.ANTHROPIC_API_KEY });
}
