/**
 * LLM client — picks an adapter based on the provider type.
 */

import { anthropicAdapter } from './anthropic';
import { openaiAdapter } from './openai';
import type { LlmAdapter, LlmCallbacks, LlmRequest, LlmTurnResult } from './types';

export type { LlmAdapter, LlmCallbacks, LlmRequest, LlmTurnResult, LlmTool, StopReason } from './types';

const ADAPTERS: Record<LlmRequest['provider'], LlmAdapter> = {
  anthropic: anthropicAdapter,
  openai: openaiAdapter,
};

export function streamLlm(req: LlmRequest, cb: LlmCallbacks): Promise<LlmTurnResult> {
  const adapter = ADAPTERS[req.provider];
  if (!adapter) throw new Error(`unknown provider: ${req.provider}`);
  return adapter.stream(req, cb);
}
