const DEFAULT_MAX_TOKENS = 2e3;
async function callAnthropicText(opts, apiKey) {
  const { default: Anthropic } = await import("@anthropic-ai/sdk");
  const client = new Anthropic({ apiKey });
  const start = Date.now();
  const response = await client.messages.create(
    {
      model: opts.model,
      max_tokens: opts.maxTokens ?? DEFAULT_MAX_TOKENS,
      messages: [{ role: "user", content: opts.prompt }]
    },
    { signal: opts.signal }
  );
  const block = (response.content ?? []).find((b) => b.type === "text");
  if (!block) throw new Error("anthropic: no text block in response");
  return {
    text: block.text,
    provider: "anthropic",
    model: response.model ?? opts.model,
    latencyMs: Date.now() - start
  };
}
async function callOpenAIText(opts, apiKey) {
  const { default: OpenAI } = await import("openai");
  const client = new OpenAI({ apiKey });
  const start = Date.now();
  const response = await client.chat.completions.create(
    {
      model: opts.model,
      max_completion_tokens: opts.maxTokens ?? DEFAULT_MAX_TOKENS,
      messages: [{ role: "user", content: opts.prompt }]
    },
    { signal: opts.signal }
  );
  const text = response.choices?.[0]?.message?.content;
  if (typeof text !== "string" || text.trim().length === 0) {
    throw new Error("openai: empty content in response");
  }
  return {
    text,
    provider: "openai",
    model: response.model ?? opts.model,
    latencyMs: Date.now() - start
  };
}
async function callGeminiText(opts, apiKey) {
  const { GoogleGenAI } = await import("@google/genai");
  const client = new GoogleGenAI({ apiKey });
  const start = Date.now();
  const response = await client.models.generateContent({
    model: opts.model,
    contents: opts.prompt,
    config: {
      maxOutputTokens: opts.maxTokens ?? DEFAULT_MAX_TOKENS,
      abortSignal: opts.signal
    }
  });
  const text = response.text;
  if (!text || text.trim().length === 0) throw new Error("gemini: empty text in response");
  return {
    text,
    provider: "gemini",
    model: opts.model,
    latencyMs: Date.now() - start
  };
}
async function callGroqText(opts, apiKey) {
  const { default: Groq } = await import("groq-sdk");
  const client = new Groq({ apiKey });
  const start = Date.now();
  const response = await client.chat.completions.create(
    {
      model: opts.model,
      max_completion_tokens: opts.maxTokens ?? DEFAULT_MAX_TOKENS,
      messages: [{ role: "user", content: opts.prompt }]
    },
    { signal: opts.signal }
  );
  const text = response.choices?.[0]?.message?.content;
  if (typeof text !== "string" || text.trim().length === 0) {
    throw new Error("groq: empty content in response");
  }
  return {
    text,
    provider: "groq",
    model: response.model ?? opts.model,
    latencyMs: Date.now() - start
  };
}
const TEXT_ADAPTERS = {
  anthropic: callAnthropicText,
  openai: callOpenAIText,
  gemini: callGeminiText,
  groq: callGroqText
};
export {
  TEXT_ADAPTERS,
  callAnthropicText,
  callGeminiText,
  callGroqText,
  callOpenAIText
};
//# sourceMappingURL=text-adapters.js.map