/** * Field-Level Change Tracker (INT-014) * * Tracks specific field changes in structured content with: * - Before/after diff output for each field * - Severity classification (breaking, major, minor, cosmetic) * - Field categorization (fee, deadline, requirement, contact, etc.) * - Multi-language support for field name matching * - Change history tracking with persistence * * @example * ```typescript * import { FieldLevelChangeTracker } from 'llm-browser/sdk'; * * const tracker = new FieldLevelChangeTracker(); * * // Track changes between two data snapshots * const changes = tracker.trackChanges(oldData, newData, { * url: 'https://gov.example.com/visa', * category: 'visa_requirements', * }); * * // Filter for breaking changes only * const breakingChanges = changes.changes.filter(c => c.severity === 'breaking'); * ``` */ /** * Severity levels for field changes * - breaking: Changes that invalidate existing processes (fee increase, new requirement) * - major: Significant changes that affect planning (timeline change, document change) * - minor: Changes that are informational (contact update, hours change) * - cosmetic: Non-functional changes (formatting, typo fixes) */ export type ChangeSeverity = 'breaking' | 'major' | 'minor' | 'cosmetic'; /** * Categories of fields that can change */ export type FieldCategory = 'fee' | 'deadline' | 'requirement' | 'document' | 'timeline' | 'contact' | 'hours' | 'location' | 'eligibility' | 'procedure' | 'form' | 'appointment' | 'status' | 'other'; /** * Type of change detected */ export type ChangeType = 'added' | 'removed' | 'modified' | 'increased' | 'decreased'; /** * A single field change with before/after values */ export interface FieldChange { /** Field path (e.g., "fees.application_fee", "requirements[0]") */ fieldPath: string; /** Human-readable field name */ fieldName: string; /** Category of the field */ category: FieldCategory; /** Type of change */ changeType: ChangeType; /** Severity of the change */ severity: ChangeSeverity; /** Previous value (undefined if added) */ oldValue?: unknown; /** New value (undefined if removed) */ newValue?: unknown; /** Formatted old value for display */ oldValueFormatted?: string; /** Formatted new value for display */ newValueFormatted?: string; /** Description of the change */ description: string; /** Impact description for user understanding */ impact?: string; /** Percentage change for numeric values */ percentageChange?: number; } /** * Result of tracking changes between two snapshots */ export interface ChangeTrackingResult { /** Whether any changes were detected */ hasChanges: boolean; /** Total number of changes */ totalChanges: number; /** Changes by severity */ changesBySeverity: Record; /** Changes by category */ changesByCategory: Record; /** All detected changes */ changes: FieldChange[]; /** Breaking changes only (convenience accessor) */ breakingChanges: FieldChange[]; /** Summary of all changes */ summary: string; /** Timestamp when changes were detected */ timestamp: number; /** Source URL if provided */ url?: string; /** Content category if provided */ contentCategory?: string; } /** * Options for tracking changes */ export interface TrackingOptions { /** Source URL for the content */ url?: string; /** Content category for better classification */ category?: string; /** Language for field name detection */ language?: string; /** Custom field mappings */ customFieldMappings?: Record; /** Fields to ignore */ ignoreFields?: string[]; /** Only track these fields */ onlyFields?: string[]; /** Treat array reordering as a change */ trackArrayOrder?: boolean; } /** * A historical change record */ export interface ChangeHistoryRecord { /** Unique ID for this record */ id: string; /** Source URL */ url: string; /** When the change was detected */ timestamp: number; /** Summary of changes */ summary: string; /** Number of changes by severity */ severityCounts: Record; /** The actual changes */ changes: FieldChange[]; } /** * Configuration for the tracker */ export interface FieldLevelChangeTrackerConfig { /** Storage path for persistence */ storagePath?: string; /** Maximum history entries per URL */ maxHistoryPerUrl?: number; } /** * Field-Level Change Tracker * * Tracks changes in structured data with field-level granularity, * severity classification, and change history. */ export declare class FieldLevelChangeTracker { private store; private data; private config; private initialized; constructor(config?: FieldLevelChangeTrackerConfig); /** * Initialize the tracker with optional persistence */ initialize(): Promise; /** * Track changes between two data snapshots * * @param oldData - Previous data snapshot * @param newData - Current data snapshot * @param options - Tracking options * @returns Change tracking result with all detected changes */ trackChanges(oldData: Record, newData: Record, options?: TrackingOptions): ChangeTrackingResult; /** * Compare two values and detect changes */ private compareObjects; /** * Compare arrays and detect changes */ private compareArrays; /** * Create a FieldChange object */ private createChange; /** * Detect the category of a field based on its name and value */ private detectCategory; /** * Detect the type of change (modified, increased, decreased) */ private detectChangeType; /** * Extract days from a duration string */ private extractDays; /** * Calculate percentage change for numeric values */ private calculatePercentageChange; /** * Format a field name for display */ private formatFieldName; /** * Format a value for display */ private formatValue; /** * Generate a description for the change */ private generateDescription; /** * Generate impact description based on severity */ private generateImpact; /** * Generate a summary of all changes */ private generateSummary; /** * Check if a value is a plain object */ private isObject; /** * Check if two values are equal using deep comparison * (key order insensitive for objects) */ private valuesEqual; /** * Add a change record to history */ private addToHistory; /** * Get change history for a URL * * @param url - URL to get history for * @param limit - Maximum records to return * @returns Array of change history records */ getHistory(url: string, limit?: number): Promise; /** * Get all URLs with change history */ getTrackedUrls(): Promise; /** * Clear history for a URL */ clearHistory(url: string): Promise; /** * Clear all history */ clearAllHistory(): Promise; /** * Get statistics across all tracked URLs */ getStatistics(): Promise<{ totalUrls: number; totalRecords: number; changesBySeverity: Record; changesByCategory: Record; recentChanges: ChangeHistoryRecord[]; }>; /** * Save data to persistent storage */ private save; /** * Flush pending writes */ flush(): Promise; } /** * Create a new FieldLevelChangeTracker */ export declare function createFieldLevelChangeTracker(config?: FieldLevelChangeTrackerConfig): FieldLevelChangeTracker; /** * Get the global FieldLevelChangeTracker instance */ export declare function getFieldLevelChangeTracker(config?: FieldLevelChangeTrackerConfig): FieldLevelChangeTracker; /** * Track changes between two data snapshots (convenience function) * Uses the global singleton instance for persistence and history. */ export declare function trackFieldChanges(oldData: Record, newData: Record, options?: TrackingOptions): ChangeTrackingResult; /** * Get breaking changes only (convenience function) */ export declare function getBreakingChanges(oldData: Record, newData: Record, options?: TrackingOptions): FieldChange[]; /** * Check if there are any breaking changes (convenience function) */ export declare function hasBreakingChanges(oldData: Record, newData: Record, options?: TrackingOptions): boolean; //# sourceMappingURL=field-level-change-tracker.d.ts.map