import type { LLMRequestOptions, LLMResponse, LLMStreamEvent } from './llm-provider.js'; export type LLMProtocolId = 'anthropic-messages' | 'openai-chat'; export type LLMProtocolHandler = ( config: Config, opts: LLMRequestOptions, onEvent: (e: LLMStreamEvent) => void ) => Promise; export interface LLMProtocol { readonly id: LLMProtocolId; readonly handle: LLMProtocolHandler; } export function protocolIdForProvider(provider: string): LLMProtocolId { return provider === 'anthropic' ? 'anthropic-messages' : 'openai-chat'; } export interface LLMProtocolRouter { readonly resolve: (provider: string) => LLMProtocol; readonly ids: () => LLMProtocolId[]; } export function createProtocolRouter( protocols: ReadonlyArray> ): LLMProtocolRouter { const byId = new Map>(); for (const protocol of protocols) byId.set(protocol.id, protocol); return { resolve(provider: string): LLMProtocol { const id = protocolIdForProvider(provider); const protocol = byId.get(id); if (!protocol) throw new Error(`No LLM protocol registered for "${id}" (provider "${provider}")`); return protocol; }, ids: () => [...byId.keys()], }; }