import { SDKConfig, HealthStatus, WindowInfo, ElementQueryParams, ElementResponse, ElementInfo, MoveResult, ClickParams, ClickResult, IdleMotionParams, IdleMotionStatus, StopResult, Point, MoveOptions, TypeOptions, TypeResult, ScrollResult, ScrollDetectResult, ElementVisibilityResult, FlashResult, ViewportInset, InspectResponse, RefreshByRuntimeIdResponse, CacheConfigRequest, CacheStatsResponse, FindFromElementRequest, FindFromElementResponse, HoverMouseParams, DragMouseParams, ScreenshotCaptureRequest, ScreenshotCaptureResponse, FindImageRequest, FindImageResponse, SaveElementImageRequest, SaveElementImageResponse, Rect, HumanMonitorStatus, HumanMonitorStartOptions } from './types'; export declare class HttpClient { private client; private maxRetries; private retryDelayMs; /** * 发送请求前的拦截钩子(可选)。 * * 由上层(Flow)注册,用于在每次 HTTP 请求前插入检查逻辑。 * 典型用途:人介入检查点 —— 若检测到人正在操作,挂起直到人离开再放行。 * * - 钩子返回的 Promise resolve 后请求才会发出 * - 钩子抛错则请求中止(错误向上传播) * - 钩子为 null 时无副作用 */ private preRequestHook; /** * 注册请求前拦截钩子。传 null 清除。 */ setPreRequestHook(hook: (() => Promise) | null): void; constructor(config: SDKConfig); /** * 判断错误是否为可重试的瞬态网络错误 */ private isRetryableError; /** * 带自动重试的请求执行器 * * 重试期间保留原始错误(供 isRetryableError 判断); * 最终失败时经 handleError 转换为简短的 SDKError 抛出, * 避免应用层面对一大堆 axios config/堆栈。 */ private requestWithRetry; private logHttpTrace; health(): Promise; listWindows(): Promise; find(params: ElementQueryParams): Promise; moveMouse(target: Point, options?: MoveOptions): Promise; clickMouse(params: ClickParams): Promise; startIdleMotion(params: IdleMotionParams): Promise; stopIdleMotion(): Promise; getIdleMotionStatus(): Promise; /** * 返回 HTTP 基础 URL,供 Flow 构造 SSE 连接地址。 * axios baseURL 末尾可能带或不带斜杠,此方法保证返回不带尾部斜杠。 */ getBaseUrl(): string; /** * 启动人介入监控(POST /api/human-monitor/start) */ startHumanMonitor(options?: HumanMonitorStartOptions): Promise<{ success: boolean; error?: string; }>; /** * 停止人介入监控(POST /api/human-monitor/stop) */ stopHumanMonitor(): Promise<{ success: boolean; error?: string; }>; /** * 查询人介入监控状态(GET /api/human-monitor/status) * 用于断线重连校准和调试。 */ getHumanMonitorStatus(): Promise; scrollMouse(params: { window?: string; element: string; delta?: number; times?: number; wait?: string; waitMode?: string; timeout?: number; autoScrollAmount?: boolean; scrollAmountRatio?: number; scrollToCenter?: boolean; centerAdjustTimes?: number; scrollInterval?: number; autoScrollDelay?: number; minScrollRatio?: number; centerSnapThreshold?: number; viewportInset?: ViewportInset; smoothStepDelta?: number; }): Promise; /** * 滚动边界检测:滚动一次,检测是否到底/到顶 * @param params.delta - 滚动方向,正=向上滚,负=向下滚,默认 -120(向下) * @param params.rollback - 检测后是否反向滚动抵消,默认 false */ scrollDetect(params: { window?: string; container: string; controlTypes?: string[]; direction?: 'up' | 'down'; exclude?: string[]; rollback?: boolean; scrollDelayMs?: number; }): Promise; typeText(text: string, options?: TypeOptions, window?: string, element?: string, runtimeId?: string): Promise; hoverMouse(params: HoverMouseParams): Promise<{ success: boolean; hoverPoint: Point | null; error: string | null; }>; dragMouse(params: DragMouseParams): Promise<{ success: boolean; sourcePoint: Point | null; targetPoint: Point | null; durationMs: number; error: string | null; }>; /** * 在指定屏幕坐标点击(移动 + 点击一步完成) * @param params 坐标点击参数 */ clickAtCoordinate(params: { x: number; y: number; window?: string; options?: { humanize?: boolean; duration?: number; button?: 'left' | 'right'; pauseBefore?: number; pauseAfter?: number; /** 是否在点击位置显示圆点标记(点击留痕) */ showDot?: boolean; /** 圆点显示持续时间(ms),默认 3000 */ dotDuration?: number; /** 点击前闪烁高亮的矩形框(图像元素传 matchRect) */ flashRect?: Rect; /** 闪烁框持续时间(ms),默认 1000 */ flashDuration?: number; }; }): Promise<{ success: boolean; clickPoint: Point; error: string | null; }>; /** * 在指定屏幕坐标悬停(移动 + 停留,不点击) * 供 ImageElement 等无 xpath 元素使用 * @param params 坐标悬停参数 */ hoverAtCoordinate(params: { x: number; y: number; window?: string; options?: { humanize?: boolean; /** 移动持续时间(ms),默认 500 */ duration?: number; /** 悬停停留时间(ms),默认 500 */ hoverDuration?: number; }; }): Promise<{ success: boolean; hoverPoint: Point; error: string | null; }>; /** * 在指定屏幕矩形区域显示高亮闪烁(供 ImageElement.flash 使用) * @param rect 屏幕坐标矩形 * @param duration 闪烁持续时间(ms),默认 1000 */ highlightRect(rect: Rect, duration?: number): Promise<{ success: boolean; error: string | null; }>; /** * 检查指定窗口是否存在(不激活窗口,无副作用) * @param windowSelector 窗口选择器 XPath * @returns 窗口是否存在 */ existsWindow(windowSelector: string): Promise; /** * 激活指定窗口(使其成为前台窗口) * @param windowSelector 窗口选择器 XPath * @returns 激活结果 */ activateWindow(windowSelector: string): Promise<{ success: boolean; error?: string; windowInfo?: WindowInfo; }>; /** * 激活窗口并使指定元素获得焦点 * @param windowSelector 窗口选择器 XPath * @param xpath 元素 XPath * @returns 操作结果 */ focusElement(windowSelector: string, xpath: string): Promise<{ success: boolean; error?: string; }>; /** * 获取所有匹配元素 * @param params 查询参数 * @returns 所有匹配的元素列表 */ findAll(params: ElementQueryParams): Promise<{ found: boolean; elements: { findSelector: string; info: ElementInfo; }[]; total: number; error?: string; }>; /** * 获取元素可视区域位置信息 * @param windowSelector 窗口选择器 XPath * @param elementXPath 元素 XPath * @param containerXPath 可选的滚动容器 XPath,用于计算元素在容器内的可见矩形 * @returns 元素可视区域位置信息 */ getElementVisibility(windowSelector: string, elementXPath: string, containerXPath?: string, runtimeId?: string): Promise; /** * 在元素位置显示高亮闪烁(绿色边框 + 标签) * @param windowSelector 窗口选择器 XPath * @param elementXPath 元素 XPath * @param timeout 闪烁持续时间(ms),默认 1000 * @returns 闪烁结果 */ flashElement(windowSelector: string, elementXPath: string, timeout?: number, runtimeId?: string): Promise; /** * 执行快捷键组合(推荐方法名) * @param keys 快捷键字符串,如 "Ctrl+C", "Alt+F4" */ shortcut(keys: string): Promise<{ success: boolean; error?: string; }>; /** * 执行快捷键组合(向后兼容别名) * @deprecated 请使用 shortcut() 代替 * @param keys 快捷键字符串,如 "Ctrl+C", "Alt+F4" */ executeShortcut(keys: string): Promise<{ success: boolean; error?: string; }>; /** * 执行单个按键 * @param key 按键名称,如 "Enter", "Tab", "Escape" */ executeKey(key: string): Promise<{ success: boolean; error?: string; }>; /** * 检查元素是否支持指定操作 * @param windowSelector 窗口选择器 XPath * @param elementXPath 元素 XPath * @param patternName UIA Pattern 名称 */ supportsPattern(windowSelector: string, elementXPath: string, patternName: string): Promise; /** * 遍历元素下的所有子元素,提取层级/控件类型/name/Text/rect/相对xpath * @param windowSelector 窗口选择器 XPath * @param elementXPath 目标元素 XPath * @param format 返回格式:'json'(默认)、'txt' 或 'text' * @returns InspectResponse(带 filter 方法) */ inspectElement(windowSelector: string, elementXPath: string, format?: 'json' | 'txt' | 'text', runtimeId?: string): Promise; /** * Compass 导航:找到基准元素后逐步 TreeWalker 导航 * @param windowSelector 窗口选择器 XPath * @param baseXPath 基准元素 XPath * @param steps 导航步骤列表 * @returns 导航结果 */ navigateElement(windowSelector: string, baseXPath: string, steps: import('./types').NavigateStep[], runtimeId?: string): Promise; /** * 通过 runtimeId 刷新元素信息(从缓存获取最新属性) */ refreshByRuntimeId(windowSelector: string, runtimeId: string): Promise; /** * 从 RuntimeId 缓存元素查找子元素 */ findFromElement(params: FindFromElementRequest): Promise; /** * 设置全局缓存 TTL */ setCacheConfig(config: CacheConfigRequest): Promise; /** * 获取缓存统计 */ getCacheStats(): Promise; /** * 清除所有缓存 */ clearElementCache(): Promise; /** * 截取指定屏幕区域 */ captureScreenshot(params: ScreenshotCaptureRequest): Promise; /** * 截取全屏 */ captureDesktopScreenshot(): Promise; /** * 通过模板图像在屏幕上查找匹配位置 */ findImage(params: FindImageRequest): Promise; /** * 对 base64 图像按掩码百分比裁剪,返回裁剪后的 base64 */ cropImage(params: { imageBase64: string; top?: string; right?: string; bottom?: string; left?: string; }): Promise<{ success: boolean; base64?: string; cropOffset?: { x: number; y: number; }; error?: string; }>; /** * 对比两张截图的变化率(0.0=完全相同,1.0=完全不同) */ compareImages(params: { image1Base64: string; image2Base64: string; }): Promise<{ success: boolean; changeRate?: number; error?: string; }>; /** * 截图 + 模板匹配 + 画红框标注,返回标注后的 base64 PNG */ visualizeImage(params: { templateBase64: string; precision?: number; algorithm?: string; region?: { x: number; y: number; width: number; height: number; }; strokeWidth?: number; }): Promise<{ success: boolean; base64?: string; matches: Array<{ x: number; y: number; width: number; height: number; confidence: number; }>; width?: number; height?: number; error?: string; }>; /** * 滚动中图像匹配:server 端原子操作(滚动 + 截图 + 匹配),单次 HTTP 调用 */ scrollFind(params: { templateBase64: string; scrollContainer: string; windowSelector: string; algorithm?: string; precision?: number; direction?: string; scrollDelta?: number; scrollIntervalMs?: number; maxScrolls?: number; sampleRegion?: { x: number; y: number; width: number; height: number; }; timeoutMs?: number; scrollEndDetection?: { mode?: 'scrollbar' | 'bottomChangeRate'; bottomChangeThreshold?: number; scrollbarWidth?: number; sampleRatio?: number; consecutiveFrames?: number; saveDebugFrames?: boolean; historyDepth?: number; dynamicPixelEps?: number; minDynamicRatio?: number; }; scrollInset?: { top?: string; right?: string; bottom?: string; left?: string; }; scrollFindThreading?: { scrollIntervalMinMs?: number; scrollIntervalMaxMs?: number; matchIntervalMs?: number; cursorMoveDurationMs?: number; cursorMotionMode?: 'reading' | 'off' | 'random'; cursorMoveIntervalMs?: number; cursorHorizontalRatio?: number; }; }): Promise<{ success: boolean; found: boolean; match?: { x: number; y: number; width: number; height: number; confidence: number; }; scrolled: number; scrolledToEnd: boolean; elapsedMs: number; error?: string; }>; /** * 截取区域并保存到文件 */ saveElementImage(params: SaveElementImageRequest): Promise; handleError(error: unknown, endpoint?: string): never; }