/** * Core type definitions for react-native-agentkit */ // ─── Element Info ──────────────────────────────────────────────────────────── export interface ElementPosition { x: number; y: number; width: number; height: number; } export interface ElementState { disabled: boolean; selected: boolean; checked?: boolean; expanded?: boolean; busy?: boolean; } export type ElementType = | 'button' | 'input' | 'text' | 'image' | 'scroll' | 'switch' | 'slider' | 'link' | 'header' | 'list' | 'list-item' | 'tab' | 'modal' | 'view' | 'unknown'; export type ActionType = | 'tap' | 'longPress' | 'type' | 'clear' | 'scroll' | 'toggle' | 'setValue' | 'swipe' | 'focus' | 'blur'; export interface ElementInfo { /** Unique identifier (testID, accessibilityLabel, or auto-generated) */ id: string; /** Type of UI element */ type: ElementType; /** Human-readable label */ label: string; /** Current text content or value */ value?: string; /** Placeholder text (for inputs) */ placeholder?: string; /** Current element state */ state: ElementState; /** Layout position and size on screen */ position: ElementPosition; /** IDs of child elements */ children: string[]; /** ID of parent element */ parent?: string; /** Available actions for this element */ actions: ActionType[]; /** Raw accessibility role from React Native */ accessibilityRole?: string; /** Additional accessibility hint */ accessibilityHint?: string; } // ─── Commands ──────────────────────────────────────────────────────────────── export type CommandName = | 'list' | 'tap' | 'longPress' | 'type' | 'clear' | 'scroll' | 'toggle' | 'setValue' | 'swipe' | 'read' | 'state' | 'back' | 'wait' | 'find' | 'ping'; export interface Command { /** Unique request ID for correlation */ id?: string; /** Command name */ cmd: CommandName; /** Target element ID or text to find */ target?: string; /** Text to type (for 'type' command) */ text?: string; /** Scroll direction */ direction?: 'up' | 'down' | 'left' | 'right'; /** Scroll amount in pixels */ amount?: number; /** Timeout in milliseconds (for 'wait' command) */ timeout?: number; /** Filter by element type (for 'list' and 'find') */ filterType?: ElementType; /** Filter by text content (for 'find') */ filterText?: string; /** Value to set (for 'setValue' command) */ value?: number; } export interface CommandResponse { /** Whether the command succeeded */ success: boolean; /** The command that was executed */ command: CommandName; /** Request ID if provided */ id?: string; /** Target element ID if applicable */ target?: string; /** Command-specific result data */ result: Record; /** Current screen state (element list) — included for state-changing commands */ screenState?: ScreenState; /** Error message if command failed */ error?: string; /** Timestamp of response */ timestamp: number; } export interface ScreenState { /** All interactive elements currently on screen */ elements: ElementInfo[]; /** Total element count */ count: number; /** Screen dimensions */ screen: { width: number; height: number }; } // ─── Configuration ─────────────────────────────────────────────────────────── export interface AgentKitConfig { /** WebSocket server port (default: 8347) */ port: number; /** Enable debug logging (default: false) */ debug: boolean; /** Element scan interval in ms (default: 1000) */ scanInterval: number; /** Include non-interactive elements in scans (default: false) */ includeNonInteractive: boolean; /** Auto-include screen state in command responses (default: true) */ includeScreenState: boolean; /** Cloud relay server URL for production usage (e.g. "ws://relay.example.com:8347") */ relayUrl?: string; /** Channel ID for relay pairing (default: "default") */ channelId: string; /** Shared secret for relay channel authentication (optional in dev, recommended for production) */ channelSecret?: string; } export const DEFAULT_CONFIG: AgentKitConfig = { port: 8347, debug: false, scanInterval: 1000, includeNonInteractive: false, includeScreenState: true, channelId: 'default', }; // ─── Events ────────────────────────────────────────────────────────────────── export type BridgeEventType = | 'connected' | 'disconnected' | 'command' | 'screenChange' | 'error'; export interface BridgeEvent { type: BridgeEventType; data?: unknown; timestamp: number; } // ─── Internal types ────────────────────────────────────────────────────────── export interface RegisteredElement { info: ElementInfo; /** React ref to the native component */ ref: React.RefObject; /** Handlers for programmatic actions */ handlers: ElementHandlers; /** How this element was registered: introspection scan or manual hook */ source: 'introspected' | 'manual'; } export interface ElementHandlers { onPress?: () => void; onLongPress?: () => void; onChangeText?: (text: string) => void; onValueChange?: (value: any) => void; onSwipe?: (direction: 'left' | 'right' | 'up' | 'down') => void; scrollTo?: (options: { x?: number; y?: number; animated?: boolean }) => void; }