import { NodeType } from '@midscene_spp/shared/constants';
import { ChatCompletionMessageParam } from 'openai/resources';

interface LocateOption {
    prompt?: string;
    deepThink?: boolean;
    cacheable?: boolean;
}
interface ReferenceImage {
    base64: string;
    rect?: Rect;
}
interface DetailedLocateParam extends LocateOption {
    prompt: string;
    referenceImage?: ReferenceImage;
}
interface scrollParam {
    direction: 'down' | 'up' | 'right' | 'left';
    scrollType: 'once' | 'untilBottom' | 'untilTop' | 'untilRight' | 'untilLeft';
    distance?: null | number;
}
interface MidsceneYamlScript {
    target?: MidsceneYamlScriptWebEnv;
    web?: MidsceneYamlScriptWebEnv;
    android?: MidsceneYamlScriptAndroidEnv;
    tasks: MidsceneYamlTask[];
}
interface MidsceneYamlTask {
    name: string;
    flow: MidsceneYamlFlowItem[];
    continueOnError?: boolean;
}
interface MidsceneYamlScriptEnvBase {
    output?: string;
    aiActionContext?: string;
}
interface MidsceneYamlScriptWebEnv extends MidsceneYamlScriptEnvBase {
    serve?: string;
    url: string;
    userAgent?: string;
    acceptInsecureCerts?: boolean;
    viewportWidth?: number;
    viewportHeight?: number;
    viewportScale?: number;
    waitForNetworkIdle?: {
        timeout?: number;
        continueOnNetworkIdleError?: boolean;
    };
    cookie?: string;
    forceSameTabNavigation?: boolean;
    bridgeMode?: false | 'newTabWithUrl' | 'currentTab';
    closeNewTabsAfterDisconnect?: boolean;
}
interface MidsceneYamlScriptAndroidEnv extends MidsceneYamlScriptEnvBase {
    deviceId?: string;
    launch?: string;
}
type MidsceneYamlScriptEnv = MidsceneYamlScriptWebEnv | MidsceneYamlScriptAndroidEnv;
interface MidsceneYamlFlowItemAIAction {
    ai?: string;
    aiAction?: string;
    aiActionProgressTips?: string[];
    cacheable?: boolean;
}
interface MidsceneYamlFlowItemAIAssert {
    aiAssert: string;
}
interface MidsceneYamlFlowItemAIQuery {
    aiQuery: string;
    name?: string;
}
interface MidsceneYamlFlowItemAINumber {
    aiNumber: string;
    name?: string;
}
interface MidsceneYamlFlowItemAINString {
    aiString: string;
    name?: string;
}
interface MidsceneYamlFlowItemAIBoolean {
    aiBoolean: string;
    name?: string;
}
interface MidsceneYamlFlowItemAILocate {
    aiLocate: string;
    name?: string;
}
interface MidsceneYamlFlowItemAIWaitFor {
    aiWaitFor: string;
    timeout?: number;
}
interface MidsceneYamlFlowItemAITap extends LocateOption {
    aiTap: string;
}
interface MidsceneYamlFlowItemAIHover extends LocateOption {
    aiHover: string;
}
interface MidsceneYamlFlowItemAIInput extends LocateOption {
    aiInput: string;
    locate: string;
}
interface MidsceneYamlFlowItemAIKeyboardPress extends LocateOption {
    aiKeyboardPress: string;
    locate?: string;
}
interface MidsceneYamlFlowItemAIScroll extends LocateOption, PlanningActionParamScroll {
    aiScroll: null;
    locate?: string;
}
interface MidsceneYamlFlowItemEvaluateJavaScript {
    javascript: string;
    name?: string;
}
interface MidsceneYamlFlowItemSleep {
    sleep: number;
}
type MidsceneYamlFlowItem = MidsceneYamlFlowItemAIAction | MidsceneYamlFlowItemAIAssert | MidsceneYamlFlowItemAIQuery | MidsceneYamlFlowItemAIWaitFor | MidsceneYamlFlowItemAITap | MidsceneYamlFlowItemAIHover | MidsceneYamlFlowItemAIInput | MidsceneYamlFlowItemAIKeyboardPress | MidsceneYamlFlowItemAIScroll | MidsceneYamlFlowItemSleep;
interface FreeFn {
    name: string;
    fn: () => void;
}
interface ScriptPlayerTaskStatus extends MidsceneYamlTask {
    status: ScriptPlayerStatusValue;
    currentStep?: number;
    totalSteps: number;
    error?: Error;
}
type ScriptPlayerStatusValue = 'init' | 'running' | 'done' | 'error';

interface Point {
    left: number;
    top: number;
}
interface Size {
    width: number;
    height: number;
    dpr?: number;
}
type Rect = Point & Size & {
    zoom?: number;
};
declare abstract class BaseElement {
    abstract id: string;
    abstract indexId?: number;
    abstract attributes: {
        nodeType: NodeType;
        [key: string]: string;
    };
    abstract content: string;
    abstract rect: Rect;
    abstract center: [number, number];
    abstract locator?: string;
    abstract xpaths?: string[];
}
interface ElementTreeNode<ElementType extends BaseElement = BaseElement> {
    node: ElementType | null;
    children: ElementTreeNode<ElementType>[];
}
type AIUsageInfo = Record<string, any> & {
    prompt_tokens: number;
    completion_tokens: number;
    total_tokens: number;
};
/**
 * openai
 *
 */
declare enum AIResponseFormat {
    JSON = "json_object",
    TEXT = "text"
}
type AISingleElementResponseById = {
    id: string;
    reason?: string;
    text?: string;
    xpaths?: string[];
};
type AISingleElementResponseByPosition = {
    position?: {
        x: number;
        y: number;
    };
    bbox?: [number, number, number, number];
    reason: string;
    text: string;
};
type AISingleElementResponse = AISingleElementResponseById;
interface AIElementLocatorResponse {
    elements: {
        id: string;
        reason?: string;
        text?: string;
        xpaths?: string[];
    }[];
    bbox?: [number, number, number, number];
    errors?: string[];
}
interface AIElementCoordinatesResponse {
    bbox: [number, number, number, number];
    errors?: string[];
}
type AIElementResponse = AIElementLocatorResponse | AIElementCoordinatesResponse;
interface AIDataExtractionResponse<DataShape> {
    data: DataShape;
    errors?: string[];
}
interface AISectionLocatorResponse {
    bbox: [number, number, number, number];
    references_bbox?: [number, number, number, number][];
    error?: string;
}
interface AIAssertionResponse {
    pass: boolean;
    thought: string;
}
interface AIDescribeElementResponse {
    description: string;
    error?: string;
}
interface LocatorValidatorOption {
    centerDistanceThreshold?: number;
}
interface LocateValidatorResult {
    pass: boolean;
    rect: Rect;
    center: [number, number];
    centerDistance?: number;
}
interface AgentDescribeElementAtPointResult {
    prompt: string;
    deepThink: boolean;
    verifyResult?: LocateValidatorResult;
}
/**
 * context
 */
declare abstract class UIContext<ElementType extends BaseElement = BaseElement> {
    abstract screenshotBase64: string;
    abstract content: ElementType[];
    abstract tree: ElementTreeNode<ElementType>;
    abstract size: Size;
}
/**
 * insight
 */
type CallAIFn = <T>(messages: ChatCompletionMessageParam[]) => Promise<T>;
interface InsightOptions {
    taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;
    aiVendorFn?: CallAIFn;
}
type EnsureObject<T> = {
    [K in keyof T]: any;
};
type InsightAction = 'locate' | 'extract' | 'assert' | 'describe';
type InsightExtractParam = string | Record<string, string>;
type LocateResultElement = {
    id: string;
    indexId?: number;
    center: [number, number];
    rect: Rect;
    xpaths: string[];
    attributes: {
        nodeType: NodeType;
        [key: string]: string;
    };
};
interface LocateResult {
    element: LocateResultElement | null;
    rect?: Rect;
}
interface InsightTaskInfo {
    durationMs: number;
    formatResponse?: string;
    rawResponse?: string;
    usage?: AIUsageInfo;
    searchArea?: Rect;
    searchAreaRawResponse?: string;
    searchAreaUsage?: AIUsageInfo;
}
interface DumpMeta {
    sdkVersion: string;
    logTime: number;
    model_name: string;
    model_description?: string;
}
interface ReportDumpWithAttributes {
    dumpString: string;
    attributes?: Record<string, any>;
}
interface InsightDump extends DumpMeta {
    type: 'locate' | 'extract' | 'assert';
    logId: string;
    userQuery: {
        element?: string;
        dataDemand?: InsightExtractParam;
        assertion?: string;
    };
    matchedElement: BaseElement[];
    matchedRect?: Rect;
    deepThink?: boolean;
    data: any;
    assertionPass?: boolean;
    assertionThought?: string;
    taskInfo: InsightTaskInfo;
    error?: string;
    output?: any;
}
type PartialInsightDumpFromSDK = Omit<InsightDump, 'sdkVersion' | 'logTime' | 'logId' | 'model_name'>;
type DumpSubscriber = (dump: InsightDump) => Promise<void> | void;
interface LiteUISection {
    name: string;
    description: string;
    sectionCharacteristics: string;
    textIds: string[];
}
type ElementById = (id: string) => BaseElement | null;
type InsightAssertionResponse = AIAssertionResponse & {
    usage?: AIUsageInfo;
};
/**
 * agent
 */
type OnTaskStartTip = (tip: string) => Promise<void> | void;
interface AgentWaitForOpt {
    checkIntervalMs?: number;
    timeoutMs?: number;
}
interface AgentAssertOpt {
    keepRawResponse?: boolean;
}
/**
 * planning
 *
 */
interface PlanningLocateParam extends DetailedLocateParam {
    id?: string;
    bbox?: [number, number, number, number];
}
interface PlanningAction<ParamType = any> {
    thought?: string;
    type: 'Locate' | 'Tap' | 'Drag' | 'Hover' | 'Input' | 'KeyboardPress' | 'Scroll' | 'Error' | 'ExpectedFalsyCondition' | 'Assert' | 'AssertWithoutThrow' | 'Sleep' | 'Finished' | 'AndroidBackButton' | 'AndroidHomeButton' | 'AndroidRecentAppsButton';
    param: ParamType;
    locate?: PlanningLocateParam | null;
}
interface PlanningAIResponse {
    action?: PlanningAction;
    actions?: PlanningAction[];
    more_actions_needed_by_instruction: boolean;
    log: string;
    sleep?: number;
    error?: string;
    usage?: AIUsageInfo;
    rawResponse?: string;
    yamlFlow?: MidsceneYamlFlowItem[];
    yamlString?: string;
}
type PlanningActionParamTap = null;
type PlanningActionParamHover = null;
interface PlanningActionParamInputOrKeyPress {
    value: string;
}
type PlanningActionParamScroll = scrollParam;
interface PlanningActionParamAssert {
    assertion: string;
}
interface PlanningActionParamSleep {
    timeMs: number;
}
interface PlanningActionParamError {
    thought: string;
}
type PlanningActionParamWaitFor = AgentWaitForOpt & {
    assertion: string;
};
/**
 * misc
 */
interface Color {
    name: string;
    hex: string;
}
interface BaseAgentParserOpt {
    selector?: string;
    ignoreMarker?: boolean;
}
interface PuppeteerParserOpt extends BaseAgentParserOpt {
}
interface PlaywrightParserOpt extends BaseAgentParserOpt {
}
interface ExecutionTaskProgressOptions {
    onTaskStart?: (task: ExecutionTask) => Promise<void> | void;
}
interface ExecutionRecorderItem {
    type: 'screenshot';
    ts: number;
    screenshot?: string;
    timing?: string;
}
type ExecutionTaskType = 'Planning' | 'Insight' | 'Action' | 'Assertion';
interface ExecutorContext {
    task: ExecutionTask;
    element?: LocateResultElement | null;
}
interface TaskCacheInfo {
    hit: boolean;
}
interface ExecutionTaskApply<Type extends ExecutionTaskType = any, TaskParam = any, TaskOutput = any, TaskLog = any> {
    type: Type;
    subType?: string;
    param?: TaskParam;
    thought?: string;
    locate?: PlanningLocateParam | null;
    pageContext?: UIContext;
    executor: (param: TaskParam, context: ExecutorContext) => Promise<ExecutionTaskReturn<TaskOutput, TaskLog> | undefined | void> | undefined | void;
}
interface ExecutionTaskReturn<TaskOutput = unknown, TaskLog = unknown> {
    output?: TaskOutput;
    log?: TaskLog;
    recorder?: ExecutionRecorderItem[];
    cache?: TaskCacheInfo;
}
type ExecutionTask<E extends ExecutionTaskApply<any, any, any> = ExecutionTaskApply<any, any, any>> = E & ExecutionTaskReturn<E extends ExecutionTaskApply<any, any, infer TaskOutput, any> ? TaskOutput : unknown, E extends ExecutionTaskApply<any, any, any, infer TaskLog> ? TaskLog : unknown> & {
    status: 'pending' | 'running' | 'finished' | 'failed' | 'cancelled';
    error?: string;
    errorStack?: string;
    timing?: {
        start: number;
        end?: number;
        cost?: number;
        aiCost?: number;
    };
    usage?: AIUsageInfo;
};
interface ExecutionDump extends DumpMeta {
    name: string;
    description?: string;
    tasks: ExecutionTask[];
}
type ExecutionTaskInsightLocateParam = PlanningLocateParam;
interface ExecutionTaskInsightLocateOutput {
    element: LocateResultElement | null;
}
interface ExecutionTaskInsightDumpLog {
    dump?: InsightDump;
}
type ExecutionTaskInsightLocateApply = ExecutionTaskApply<'Insight', ExecutionTaskInsightLocateParam, ExecutionTaskInsightLocateOutput, ExecutionTaskInsightDumpLog>;
type ExecutionTaskInsightLocate = ExecutionTask<ExecutionTaskInsightLocateApply>;
interface ExecutionTaskInsightQueryParam {
    dataDemand: InsightExtractParam;
}
interface ExecutionTaskInsightQueryOutput {
    data: any;
}
type ExecutionTaskInsightQueryApply = ExecutionTaskApply<'Insight', ExecutionTaskInsightQueryParam, any, ExecutionTaskInsightDumpLog>;
type ExecutionTaskInsightQuery = ExecutionTask<ExecutionTaskInsightQueryApply>;
interface ExecutionTaskInsightAssertionParam {
    assertion: string;
}
type ExecutionTaskInsightAssertionApply = ExecutionTaskApply<'Insight', ExecutionTaskInsightAssertionParam, InsightAssertionResponse, ExecutionTaskInsightDumpLog>;
type ExecutionTaskInsightAssertion = ExecutionTask<ExecutionTaskInsightAssertionApply>;
type ExecutionTaskActionApply<ActionParam = any> = ExecutionTaskApply<'Action', ActionParam, void, void>;
type ExecutionTaskAction = ExecutionTask<ExecutionTaskActionApply>;
type ExecutionTaskPlanningApply = ExecutionTaskApply<'Planning', {
    userInstruction: string;
    log?: string;
}, PlanningAIResponse>;
type ExecutionTaskPlanning = ExecutionTask<ExecutionTaskPlanningApply>;
interface GroupedActionDump {
    groupName: string;
    groupDescription?: string;
    executions: ExecutionDump[];
}
type PageType = 'puppeteer' | 'playwright' | 'static' | 'chrome-extension-proxy' | 'android';

export { type PlanningActionParamInputOrKeyPress as $, type AIDescribeElementResponse as A, BaseElement as B, type CallAIFn as C, type DumpSubscriber as D, type ExecutionTask as E, type LocateResultElement as F, type DumpMeta as G, type ReportDumpWithAttributes as H, type InsightAction as I, type InsightDump as J, type PartialInsightDumpFromSDK as K, type LocateResult as L, type MidsceneYamlScript as M, type LiteUISection as N, type ElementById as O, type Point as P, type OnTaskStartTip as Q, type Rect as R, type Size as S, type AgentWaitForOpt as T, UIContext as U, type AgentAssertOpt as V, type PlanningLocateParam as W, type PlanningAction as X, type PlanningAIResponse as Y, type PlanningActionParamTap as Z, type PlanningActionParamHover as _, type ExecutionTaskProgressOptions as a, type PlanningActionParamScroll as a0, type PlanningActionParamAssert as a1, type PlanningActionParamSleep as a2, type PlanningActionParamError as a3, type PlanningActionParamWaitFor as a4, type Color as a5, type BaseAgentParserOpt as a6, type PuppeteerParserOpt as a7, type PlaywrightParserOpt as a8, type ExecutionRecorderItem as a9, type MidsceneYamlScriptWebEnv as aA, type MidsceneYamlScriptAndroidEnv as aB, type MidsceneYamlScriptEnv as aC, type MidsceneYamlFlowItemAIAction as aD, type MidsceneYamlFlowItemAIAssert as aE, type MidsceneYamlFlowItemAIQuery as aF, type MidsceneYamlFlowItemAINumber as aG, type MidsceneYamlFlowItemAINString as aH, type MidsceneYamlFlowItemAIBoolean as aI, type MidsceneYamlFlowItemAILocate as aJ, type MidsceneYamlFlowItemAIWaitFor as aK, type MidsceneYamlFlowItemAITap as aL, type MidsceneYamlFlowItemAIHover as aM, type MidsceneYamlFlowItemAIInput as aN, type MidsceneYamlFlowItemAIKeyboardPress as aO, type MidsceneYamlFlowItemAIScroll as aP, type MidsceneYamlFlowItemEvaluateJavaScript as aQ, type MidsceneYamlFlowItemSleep as aR, type FreeFn as aS, type ScriptPlayerTaskStatus as aT, type ScriptPlayerStatusValue as aU, type ExecutionTaskType as aa, type ExecutorContext as ab, type TaskCacheInfo as ac, type ExecutionTaskReturn as ad, type ExecutionTaskInsightLocateParam as ae, type ExecutionTaskInsightLocateOutput as af, type ExecutionTaskInsightDumpLog as ag, type ExecutionTaskInsightLocateApply as ah, type ExecutionTaskInsightLocate as ai, type ExecutionTaskInsightQueryParam as aj, type ExecutionTaskInsightQueryOutput as ak, type ExecutionTaskInsightQueryApply as al, type ExecutionTaskInsightQuery as am, type ExecutionTaskInsightAssertionParam as an, type ExecutionTaskInsightAssertionApply as ao, type ExecutionTaskInsightAssertion as ap, type ExecutionTaskActionApply as aq, type ExecutionTaskAction as ar, type ExecutionTaskPlanningApply as as, type ExecutionTaskPlanning as at, type GroupedActionDump as au, type PageType as av, type LocateOption as aw, type ReferenceImage as ax, type scrollParam as ay, type MidsceneYamlScriptEnvBase as az, type ExecutionTaskApply as b, type ExecutionDump as c, type InsightTaskInfo as d, type InsightOptions as e, type DetailedLocateParam as f, type InsightAssertionResponse as g, type MidsceneYamlTask as h, type MidsceneYamlFlowItem as i, type ElementTreeNode as j, type AIUsageInfo as k, AIResponseFormat as l, type AISingleElementResponseById as m, type AISingleElementResponseByPosition as n, type AISingleElementResponse as o, type AIElementLocatorResponse as p, type AIElementCoordinatesResponse as q, type AIElementResponse as r, type AIDataExtractionResponse as s, type AISectionLocatorResponse as t, type AIAssertionResponse as u, type LocatorValidatorOption as v, type LocateValidatorResult as w, type AgentDescribeElementAtPointResult as x, type EnsureObject as y, type InsightExtractParam as z };
