/**
 * Provider dispatcher.
 *
 * One function that turns a `(flavor, request)` into a `PiStreamEvent`
 * AsyncIterable. The session loop only knows this entry point — provider
 * choice happens here based on the sub-provider's `flavor` field.
 */
import type { PiApiFlavor } from '../sub-providers.js';
import type { PiStreamRequest, PiStreamEvent } from './types.js';
import { streamGoogle } from './stream-google.js';
import { streamOpenAICompletions } from './stream-openai-completions.js';
import { streamAnthropic } from './stream-anthropic.js';

export function streamProvider(flavor: PiApiFlavor, req: PiStreamRequest): AsyncIterable<PiStreamEvent> {
  switch (flavor) {
    case 'google-gemini':
      return streamGoogle(req);
    case 'openai-completions':
      return streamOpenAICompletions(req);
    case 'anthropic-messages':
      return streamAnthropic(req);
  }
}
