/** * Capture Agent — LLM Healer * * Last-resort recovery: when all deterministic strategies fail, * the healer asks an LLM to analyze the current page state and * produce a bounded selector patch. */ import type { ExecutionOpcode, HealerPatch } from './execution-types.js'; import type { LLMCallResult } from './llm-provider.js'; export interface HealerContext { /** The failed opcode */ failedOpcode: ExecutionOpcode; /** Index in the program */ opcodeIndex: number; /** Serialized AKTree of the current page */ akTreeSerialized: string; /** Current page URL */ currentUrl: string; /** Screenshot buffer (for multimodal models) */ screenshot?: Buffer; /** The 3 opcodes before and after the failed one (for context) */ surroundingOpcodes: ExecutionOpcode[]; /** Error message from the failed attempt */ errorMessage: string; } export interface HealerResult { healed: boolean; patch?: HealerPatch; reason: string; /** Raw LLM usage for this healing attempt */ llmResult?: LLMCallResult; } export interface HealerLLMProvider { /** * Call the LLM with a healing prompt. Returns raw JSON string. * The provider handles model selection, API keys, etc. */ call(prompt: string, screenshot?: Buffer): Promise<{ response: string; llmResult: LLMCallResult; }>; } /** * The LLM Healer — a constrained agent that repairs failed selectors. */ export declare class LLMHealer { private llmProvider; private invocationCount; private maxInvocations; constructor(llmProvider: HealerLLMProvider, options?: { maxInvocations?: number; }); get remainingInvocations(): number; heal(context: HealerContext): Promise; }