/** * Provider-Agnostic LLM Integration for Research Tool * * Supports multiple LLM providers for structured data synthesis: * - Anthropic (Claude) * - OpenAI (GPT-4) * - Ollama (local models) * * Falls back gracefully to regex-only extraction if no provider is available. */ export interface SynthesisSource { url: string; title: string; excerpt: string; sourceType: string; authorityScore: number; regexExtracted?: Record; /** Content freshness score (0-1) based on year mentions */ freshnessScore?: number; /** Most recent year mentioned in the content */ mostRecentYear?: number | null; } export interface SynthesisRequest { /** The research scope/query */ scope: string; /** JSON Schema for the data to extract */ schema: Record; /** Sources to extract from, ordered by authority */ sources: SynthesisSource[]; /** Data already extracted by regex (for comparison/correction) */ regexMergedData?: Record; } export interface SynthesisConflict { field: string; values: unknown[]; resolution: string; } export interface SynthesisResult { /** Extracted data matching the schema */ data: Record; /** Overall confidence score (0-1) */ confidence: number; /** Per-field confidence scores */ fieldConfidences: Record; /** Optional reasoning for the extraction */ reasoning?: string; /** Conflicts detected between sources */ conflicts?: SynthesisConflict[]; /** Which provider was used */ provider: string; /** Token usage for cost tracking */ usage?: { inputTokens: number; outputTokens: number; }; } export interface LLMProviderConfig { /** Override default model */ model?: string; /** Max tokens for response */ maxTokens?: number; /** Temperature (0-1) */ temperature?: number; /** Timeout in ms */ timeoutMs?: number; } /** * Callback for synthesize operations - used to bypass Promise limitations * after browse timeouts where Promise.then() doesn't work reliably. */ export type SynthesizeCallback = (error: Error | null, result: SynthesisResult | null) => void; export interface LLMProvider { /** Provider name (e.g., 'anthropic', 'openai', 'ollama') */ readonly name: string; /** Model being used */ readonly model: string; /** Check if this provider is available (has API key, etc.) */ isAvailable(): boolean; /** * Synthesize structured data from research sources * This is the main method for extraction */ synthesize(request: SynthesisRequest): Promise; /** * Callback-based synthesize - bypasses Promise limitations after browse timeouts. * The callback is invoked directly when synthesis completes, avoiding Promise.then(). */ synthesizeWithCallback?(request: SynthesisRequest, callback: SynthesizeCallback): void; } /** * Get an LLM provider based on available environment variables. * * If LLM_PROVIDER is explicitly set (anthropic, openai, ollama), that provider is used. * Otherwise, auto-detection priority: * 1. ANTHROPIC_API_KEY -> Anthropic (Claude) * 2. OPENAI_API_KEY -> OpenAI (GPT-4) * 3. OLLAMA_BASE_URL -> Ollama (local) * * Returns null if no provider is available (falls back to regex-only). */ export declare function getLLMProvider(config?: LLMProviderConfig): LLMProvider | null; /** * Reset the provider cache (useful for testing) */ export declare function resetLLMProviderCache(): void; /** * Check which LLM providers are available */ export declare function getAvailableProviders(): string[]; /** * Build the synthesis prompt for any provider */ export declare function buildSynthesisPrompt(request: SynthesisRequest): string; /** * Parse and validate LLM response */ export declare function parseSynthesisResponse(response: string, provider: string): Omit; //# sourceMappingURL=llm-provider.d.ts.map