/** * Cross-Source Verifier (INT-015) * * Compares the same topic across multiple sources to detect contradictions * and provide confidence scoring based on agreement. Extensible to any * fact-checking use case. * * @example * ```typescript * import { CrossSourceVerifier, verifySources } from 'llm-browser/sdk'; * * // Quick verification of multiple sources * const result = verifySources([ * { url: 'https://gov.example.com/visa', data: { fee: 100, duration: '30 days' } }, * { url: 'https://embassy.example.com/visa', data: { fee: 100, duration: '30 days' } }, * { url: 'https://blog.example.com/visa', data: { fee: 150, duration: '2 weeks' } }, * ]); * * // Check for contradictions * if (result.hasContradictions) { * console.log('Contradictions found:'); * for (const c of result.contradictions) { * console.log(` ${c.field}: ${c.values.join(' vs ')}`); * console.log(` Recommended: ${c.recommendedValue} (confidence: ${c.confidence})`); * } * } * * // Get verified facts * for (const fact of result.verifiedFacts) { * console.log(`${fact.field}: ${fact.value} (${fact.confidence} confidence)`); * } * ``` */ /** * Source credibility levels */ export type SourceCredibility = 'official' | 'authoritative' | 'secondary' | 'unverified'; /** * Agreement levels for facts */ export type AgreementLevel = 'unanimous' | 'majority' | 'contested' | 'conflicting'; /** * Confidence levels for verification */ export type ConfidenceLevel = 'high' | 'medium' | 'low' | 'uncertain'; /** * A data source for verification */ export interface VerificationSource { /** Source URL */ url: string; /** Extracted data from the source */ data: Record; /** Source credibility (official, authoritative, secondary, unverified) */ credibility?: SourceCredibility; /** When the data was extracted */ extractedAt?: number; /** Source language (ISO 639-1) */ language?: string; /** Optional source metadata */ metadata?: Record; } /** * A contradiction detected between sources */ export interface Contradiction { /** Field that has contradicting values */ field: string; /** Different values found across sources */ values: { value: unknown; sources: string[]; }[]; /** Severity of the contradiction */ severity: 'critical' | 'major' | 'minor'; /** Recommended value based on source credibility */ recommendedValue?: unknown; /** Confidence in the recommended value */ confidence: ConfidenceLevel; /** Explanation of the contradiction */ explanation: string; } /** * A verified fact with confidence */ export interface VerifiedFact { /** Field name */ field: string; /** Verified value */ value: unknown; /** Formatted value for display */ valueFormatted: string; /** Agreement level across sources */ agreementLevel: AgreementLevel; /** Confidence in the verification */ confidence: ConfidenceLevel; /** Sources that agree on this value */ agreeingSources: string[]; /** Sources that disagree (if any) */ disagreeingSources: string[]; /** Number of sources that provided this value */ sourceCount: number; } /** * Result of cross-source verification */ export interface VerificationResult { /** Whether verification was successful */ success: boolean; /** Total number of sources analyzed */ sourceCount: number; /** Whether any contradictions were found */ hasContradictions: boolean; /** Number of contradictions found */ contradictionCount: number; /** List of contradictions */ contradictions: Contradiction[]; /** Verified facts with confidence scores */ verifiedFacts: VerifiedFact[]; /** Overall confidence in the verification */ overallConfidence: ConfidenceLevel; /** Summary of the verification */ summary: string; /** Timestamp of verification */ timestamp: number; /** Metadata about the verification */ metadata: { /** Fields analyzed */ fieldsAnalyzed: string[]; /** Official sources count */ officialSources: number; /** Authoritative sources count */ authoritativeSources: number; }; } /** * Options for verification */ export interface VerificationOptions { /** Fields to verify (if empty, verify all) */ fields?: string[]; /** Minimum sources required for verification */ minSources?: number; /** Whether to include uncertain facts */ includeUncertain?: boolean; /** Custom field weights for scoring */ fieldWeights?: Record; /** URL patterns for official sources */ officialPatterns?: RegExp[]; /** URL patterns for authoritative sources */ authoritativePatterns?: RegExp[]; /** Threshold for considering values equivalent (for numeric comparison) */ numericTolerance?: number; } /** * Historical verification record */ export interface VerificationHistoryRecord { /** Unique ID */ id: string; /** Topic/subject being verified */ topic?: string; /** Timestamp */ timestamp: number; /** Number of sources */ sourceCount: number; /** Number of contradictions */ contradictionCount: number; /** Overall confidence */ overallConfidence: ConfidenceLevel; /** Source URLs */ sourceUrls: string[]; } /** * Configuration for the verifier */ export interface CrossSourceVerifierConfig { /** Storage path for persistence */ storagePath?: string; /** Maximum history entries */ maxHistoryEntries?: number; /** Default official URL patterns */ defaultOfficialPatterns?: RegExp[]; /** Default authoritative URL patterns */ defaultAuthoritativePatterns?: RegExp[]; } /** * Cross-Source Verifier * * Compares data from multiple sources to detect contradictions * and provide confidence-scored verified facts. */ export declare class CrossSourceVerifier { private store; private data; private config; private initialized; constructor(config?: CrossSourceVerifierConfig); /** * Initialize the verifier with optional persistence */ initialize(): Promise; /** * Verify data across multiple sources */ verify(sources: VerificationSource[], options?: VerificationOptions): VerificationResult; /** * Get verification history */ getHistory(limit?: number): VerificationHistoryRecord[]; /** * Clear history */ clearHistory(): Promise; /** * Determine source credibility from URL */ private determineCredibility; /** * Collect all fields to analyze */ private collectFields; /** * Recursively collect field paths from an object */ private collectFieldsFromObject; /** * Analyze a single field across sources */ private analyzeField; /** * Get a field value from a nested object */ private getFieldValue; /** * Normalize a value for comparison */ private normalizeValue; /** * Get credibility score for sorting */ private credibilityScore; /** * Determine agreement level from ratio */ private determineAgreementLevel; /** * Create a verified fact */ private createVerifiedFact; /** * Create a contradiction */ private createContradiction; /** * Determine field severity for contradictions */ private determineSeverity; /** * Determine confidence level */ private determineConfidence; /** * Format a value for display */ private formatValue; /** * Generate explanation for a contradiction */ private generateContradictionExplanation; /** * Format a field name for display */ private formatFieldName; /** * Calculate overall confidence */ private calculateOverallConfidence; /** * Get numeric weight for confidence level */ private getConfidenceWeight; /** * Generate verification summary */ private generateSummary; /** * Create an empty result for error cases */ private createEmptyResult; /** * Add verification to history */ private addToHistory; /** * Save data to persistent store */ private save; } /** * Create a new cross-source verifier instance */ export declare function createCrossSourceVerifier(config?: CrossSourceVerifierConfig): CrossSourceVerifier; /** * Get the global verifier instance (singleton) */ export declare function getCrossSourceVerifier(): CrossSourceVerifier; /** * Verify data from multiple sources (convenience function) * Uses the global singleton instance for persistence and history. */ export declare function verifySources(sources: VerificationSource[], options?: VerificationOptions): VerificationResult; /** * Check if sources have any contradictions (convenience function) */ export declare function hasContradictions(sources: VerificationSource[], options?: VerificationOptions): boolean; /** * Get only the contradictions from sources (convenience function) */ export declare function getContradictions(sources: VerificationSource[], options?: VerificationOptions): Contradiction[]; /** * Get high-confidence facts from sources (convenience function) */ export declare function getHighConfidenceFacts(sources: VerificationSource[], options?: VerificationOptions): VerifiedFact[]; //# sourceMappingURL=cross-source-verifier.d.ts.map