/** * Interaction Pattern Types (OWL-002) * * Types for the InteractionLearner system that learns click, type, and select * patterns as procedural skills. */ import type { PageContext } from './index.js'; /** * Type of interaction action */ export type InteractionType = 'click' | 'double_click' | 'type' | 'select' | 'hover' | 'scroll' | 'key_press' | 'wait' | 'focus' | 'blur'; /** * Selector strategy for finding elements */ export type SelectorStrategy = 'css' | 'xpath' | 'text' | 'aria-label' | 'data-testid' | 'role' | 'placeholder' | 'name' | 'id'; /** * A robust selector with fallbacks */ export interface RobustSelector { /** Primary selector (most specific) */ primary: string; /** Fallback selectors in priority order */ fallbacks: string[]; /** Strategy used for the primary selector */ strategy: SelectorStrategy; /** Confidence in this selector chain (0-1) */ confidence: number; /** Human-readable name for the element */ elementName?: string; /** ARIA role if detected */ role?: string; /** Visible text content */ text?: string; /** Success count for this selector */ successCount: number; /** Failure count for this selector */ failureCount: number; /** Last time this selector worked */ lastWorked?: number; /** Last time this selector failed */ lastFailed?: number; } /** * A single interaction action with metadata */ export interface InteractionAction { /** Type of interaction */ type: InteractionType; /** Selector to find the element (if applicable) */ selector?: RobustSelector; /** Value to input (for type, select) */ value?: string; /** Key to press (for key_press) */ key?: string; /** Delay before action in ms (for wait) */ delayMs?: number; /** Scroll amount in pixels (for scroll) */ scrollPixels?: number; /** Scroll direction (for scroll) */ scrollDirection?: 'up' | 'down' | 'left' | 'right'; /** Modifiers for key/click actions */ modifiers?: Array<'ctrl' | 'shift' | 'alt' | 'meta'>; /** Whether the action was successful */ success: boolean; /** Duration of the action in ms */ durationMs: number; /** Error message if failed */ error?: string; /** Timestamp when action occurred */ timestamp: number; /** Optional screenshot reference */ screenshotRef?: string; } /** * Context about the page where interaction happened */ export interface InteractionPageContext extends PageContext { /** Current focused element selector */ focusedElement?: string; /** Visible modal/dialog selectors */ visibleModals?: string[]; /** Active dropdown selectors */ activeDropdowns?: string[]; /** Form fields detected on page */ formFields?: Array<{ name: string; type: string; selector: string; required?: boolean; label?: string; }>; /** Buttons detected on page */ buttons?: Array<{ text: string; selector: string; type?: 'submit' | 'button' | 'reset'; }>; /** Links detected on page */ links?: Array<{ text: string; href: string; selector: string; }>; } /** * A recorded interaction trajectory */ export interface InteractionTrajectory { /** Unique identifier */ id: string; /** URL where interaction started */ url: string; /** Domain */ domain: string; /** Sequence of interactions */ actions: InteractionAction[]; /** Whether the overall trajectory succeeded */ success: boolean; /** Total duration in ms */ totalDurationMs: number; /** Page context at start */ startContext: InteractionPageContext; /** Page context at end */ endContext?: InteractionPageContext; /** What was the goal of this trajectory */ goal?: string; /** Timestamp */ timestamp: number; /** Optional user feedback */ feedback?: 'positive' | 'negative'; } /** * Preconditions for when an interaction pattern applies */ export interface InteractionPreconditions { /** URL patterns where this works */ urlPatterns?: string[]; /** Domain patterns */ domainPatterns?: string[]; /** Required elements on the page */ requiredElements?: RobustSelector[]; /** Page type (list, form, modal, etc.) */ pageType?: 'list' | 'detail' | 'form' | 'modal' | 'search' | 'login' | 'checkout' | 'unknown'; /** Content hints */ contentHints?: string[]; /** Required state (modal open, dropdown visible, etc.) */ requiredState?: Array<{ type: 'modal_visible' | 'dropdown_open' | 'form_present' | 'logged_in' | 'custom'; selector?: string; value?: string; }>; } /** * A learned interaction pattern */ export interface LearnedInteractionPattern { /** Unique identifier */ id: string; /** Human-readable name */ name: string; /** Description of what this pattern does */ description: string; /** When this pattern applies */ preconditions: InteractionPreconditions; /** The interaction sequence */ actions: InteractionAction[]; /** Dynamic selectors that may change between uses */ dynamicSelectors: Map; /** 64-dimensional embedding for similarity matching */ embedding: number[]; /** Performance metrics */ metrics: { successCount: number; failureCount: number; successRate: number; avgDurationMs: number; lastUsed: number; timesUsed: number; }; /** Source URL where learned */ sourceUrl: string; /** Source domain */ sourceDomain: string; /** When created */ createdAt: number; /** When last updated */ updatedAt: number; /** Tier for progressive loading */ tier: 'essential' | 'domain-specific' | 'advanced'; } /** * Options for recording interactions */ export interface RecordInteractionOptions { /** Goal/purpose of this interaction sequence */ goal?: string; /** Whether to capture screenshots */ captureScreenshots?: boolean; /** Maximum actions to record */ maxActions?: number; /** Timeout for recording session */ timeoutMs?: number; } /** * Options for executing a learned interaction */ export interface ExecuteInteractionOptions { /** Timeout for execution */ timeoutMs?: number; /** Whether to retry failed selectors with fallbacks */ useFallbacks?: boolean; /** Maximum retries per action */ maxRetries?: number; /** Delay between actions in ms */ actionDelayMs?: number; /** Whether to capture screenshots on failure */ screenshotOnFailure?: boolean; /** Custom variable values to substitute */ variables?: Record; } /** * Result of executing an interaction pattern */ export interface InteractionExecutionResult { /** Pattern that was executed */ patternId: string; /** Pattern name */ patternName: string; /** Whether execution succeeded */ success: boolean; /** Total duration */ durationMs: number; /** Results of each action */ actionResults: Array<{ type: InteractionType; selector?: string; success: boolean; durationMs: number; error?: string; retries?: number; }>; /** Number of actions executed */ actionsExecuted: number; /** Total actions in pattern */ totalActions: number; /** Error if failed */ error?: string; /** Final page state */ finalState?: InteractionPageContext; /** Whether any fallback selectors were used */ usedFallbacks: boolean; } /** * Interaction learning event for tracking */ export interface InteractionLearningEvent { type: 'pattern_learned' | 'pattern_updated' | 'pattern_failed' | 'selector_learned' | 'fallback_discovered'; patternId?: string; domain: string; details: Record; timestamp: number; } /** * Configuration for InteractionLearner */ export interface InteractionLearnerConfig { /** Minimum trajectory length to create a pattern */ minTrajectoryLength: number; /** Similarity threshold for merging patterns */ mergeThreshold: number; /** Maximum patterns to store */ maxPatterns: number; /** Whether to auto-discover fallback selectors */ autoDiscoverFallbacks: boolean; /** Confidence threshold for using a pattern */ confidenceThreshold: number; /** Path for storing patterns */ storagePath?: string; } /** * Match result when finding patterns */ export interface InteractionPatternMatch { /** The matched pattern */ pattern: LearnedInteractionPattern; /** Similarity score (0-1) */ similarity: number; /** Whether preconditions are met */ preconditionsMet: boolean; /** Reason for the match */ reason: string; } //# sourceMappingURL=interaction-patterns.d.ts.map