@midscene/core 1.12.4-beta-20260904065253.0 → 1.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/agent/agent.mjs +72 -25
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/index.mjs +2 -1
- package/dist/es/agent/insight.mjs +26 -10
- package/dist/es/agent/insight.mjs.map +1 -1
- package/dist/es/agent/prompt-context.mjs +12 -7
- package/dist/es/agent/prompt-context.mjs.map +1 -1
- package/dist/es/agent/run-gherkin-scenario.mjs +1 -1
- package/dist/es/agent/run-gherkin-scenario.mjs.map +1 -1
- package/dist/es/agent/tasks.mjs +2 -1
- package/dist/es/agent/tasks.mjs.map +1 -1
- package/dist/es/agent/test-runner-nodes.mjs +274 -0
- package/dist/es/agent/test-runner-nodes.mjs.map +1 -0
- package/dist/es/agent/utils.mjs +1 -1
- package/dist/es/ai-model/prompt/insight/user-prompt.mjs +1 -1
- package/dist/es/ai-model/prompt/insight/user-prompt.mjs.map +1 -1
- package/dist/es/ai-model/workflows/insight/extraction.mjs +3 -1
- package/dist/es/ai-model/workflows/insight/extraction.mjs.map +1 -1
- package/dist/es/ai-model/workflows/planning/custom-planning.mjs +3 -3
- package/dist/es/ai-model/workflows/planning/custom-planning.mjs.map +1 -1
- package/dist/es/ai-model/workflows/planning/standard-planning.mjs +1 -1
- package/dist/es/ai-model/workflows/planning/standard-planning.mjs.map +1 -1
- package/dist/es/report-html-template.mjs +1 -1
- package/dist/es/types.mjs.map +1 -1
- package/dist/es/utils.mjs +1 -1
- package/dist/es/yaml/player.mjs +0 -5
- package/dist/es/yaml/player.mjs.map +1 -1
- package/dist/es/yaml.mjs.map +1 -1
- package/dist/lib/agent/agent.js +72 -25
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/index.js +57 -8
- package/dist/lib/agent/insight.js +26 -10
- package/dist/lib/agent/insight.js.map +1 -1
- package/dist/lib/agent/prompt-context.js +16 -8
- package/dist/lib/agent/prompt-context.js.map +1 -1
- package/dist/lib/agent/run-gherkin-scenario.js +1 -1
- package/dist/lib/agent/run-gherkin-scenario.js.map +1 -1
- package/dist/lib/agent/tasks.js +2 -1
- package/dist/lib/agent/tasks.js.map +1 -1
- package/dist/lib/agent/test-runner-nodes.js +353 -0
- package/dist/lib/agent/test-runner-nodes.js.map +1 -0
- package/dist/lib/agent/utils.js +1 -1
- package/dist/lib/ai-model/prompt/insight/user-prompt.js +1 -1
- package/dist/lib/ai-model/prompt/insight/user-prompt.js.map +1 -1
- package/dist/lib/ai-model/workflows/insight/extraction.js +3 -1
- package/dist/lib/ai-model/workflows/insight/extraction.js.map +1 -1
- package/dist/lib/ai-model/workflows/planning/custom-planning.js +3 -3
- package/dist/lib/ai-model/workflows/planning/custom-planning.js.map +1 -1
- package/dist/lib/ai-model/workflows/planning/standard-planning.js +1 -1
- package/dist/lib/ai-model/workflows/planning/standard-planning.js.map +1 -1
- package/dist/lib/report-html-template.js +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/yaml/player.js +0 -5
- package/dist/lib/yaml/player.js.map +1 -1
- package/dist/lib/yaml.js.map +1 -1
- package/dist/types/agent/agent.d.ts +26 -3
- package/dist/types/agent/index.d.ts +3 -1
- package/dist/types/agent/insight.d.ts +5 -1
- package/dist/types/agent/prompt-context.d.ts +2 -0
- package/dist/types/agent/run-gherkin-scenario.d.ts +1 -0
- package/dist/types/agent/test-runner-nodes.d.ts +192 -0
- package/dist/types/types.d.ts +28 -0
- package/dist/types/yaml.d.ts +12 -4
- package/package.json +10 -2
package/dist/es/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sources":["../../src/types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { SerializedError } from '@midscene/shared/agent-tools/error-formatter';\nimport type { NodeType } from '@midscene/shared/constants';\nimport type { CreateOpenAIClientFn, TModelConfig } from '@midscene/shared/env';\nimport type {\n BaseElement,\n LocateResultElement,\n Rect,\n Size,\n} from '@midscene/shared/types';\nimport type { z } from 'zod';\nimport type { TUserPrompt } from './common';\nimport type { ScreenshotItem } from './screenshot-item';\nimport type {\n DetailedLocateParam,\n MidsceneYamlFlowItem,\n ServiceExtractOption,\n} from './yaml';\n\nexport type {\n ElementTreeNode,\n BaseElement,\n Rect,\n Size,\n Point,\n} from '@midscene/shared/types';\nexport type { SerializedError } from '@midscene/shared/agent-tools/error-formatter';\nexport * from './yaml';\n\nexport { ServiceError } from './errors';\nexport {\n ExecutionDump,\n ReportActionDump,\n GroupedActionDump,\n} from './dump/report-action-dump';\n\nexport type AIUsageInfo = Record<string, any> & {\n prompt_tokens: number | undefined;\n completion_tokens: number | undefined;\n total_tokens: number | undefined;\n cached_input: number | undefined;\n time_cost: number | undefined;\n model_name: string | undefined;\n model_description: string | undefined;\n /**\n * Raw top-level `.model` value returned by the model service response.\n */\n response_model_name: string | undefined;\n /**\n * Semantic intent of the model call, such as default, planning, or insight.\n */\n intent: string | undefined;\n /**\n * Config slot where the model config was resolved from. For example, a\n * planning call may use the default slot when no planning model is configured.\n */\n slot: string | undefined;\n request_id: string | undefined;\n};\n\nexport type { LocateResultElement };\n\nexport type AISingleElementResponseByPosition = {\n position?: {\n x: number;\n y: number;\n };\n bbox?: [number, number, number, number];\n reason: string;\n text: string;\n};\n\nexport type LocateResultPoint = [number, number];\nexport type Bbox = [number, number, number, number];\nexport type LocateResultBbox = Bbox;\nexport type PixelBbox = Bbox;\n\nexport interface AIElementLocateResponse {\n bbox?: LocateResultBbox;\n point?: LocateResultPoint;\n error?: string;\n}\n\nexport interface AIDataExtractionResponse<DataDemand> {\n data: DataDemand;\n errors?: string[];\n thought?: string;\n}\n\nexport interface AISectionLocatorResponse {\n bbox?: LocateResultBbox;\n point?: LocateResultPoint;\n references_bbox?: LocateResultBbox[];\n references_point?: LocateResultPoint[];\n error?: string;\n}\n\nexport interface AIAssertionResponse {\n pass: boolean;\n thought: string;\n}\n\nexport interface AIDescribeElementResponse {\n description: string;\n error?: string;\n}\n\nexport interface LocatorValidatorOption {\n centerDistanceThreshold?: number;\n}\n\nexport interface LocateValidatorResult {\n pass: boolean;\n rect: Rect;\n center: [number, number];\n centerDistance?: number;\n includedInRect?: boolean;\n}\n\nexport interface AgentDescribeElementAtPointResult {\n prompt: string;\n deepLocate: boolean;\n deepDescribe: boolean;\n verifyResult?: LocateValidatorResult;\n success: boolean;\n error?: string;\n failureStage?: 'describe' | 'verify';\n}\n\n/**\n * context\n */\n\nexport interface UiNode {\n type: string;\n attrs: Record<string, string | undefined>;\n bounds: Rect;\n children: UiNode[];\n}\n\nexport interface UITreeSnapshot {\n platform: 'android';\n capturedAt: number;\n root: UiNode;\n}\n\nexport abstract class UIContext {\n /**\n * screenshot of the current UI state. which size is shotSize(be shrunk by screenshotShrinkFactor),\n */\n abstract screenshot: ScreenshotItem;\n\n /**\n * Optional sequence of screenshots captured over a short time window, in\n * temporal order (earliest first, latest last). When present with more than\n * one frame, extract/assert flows submit all frames to the model so it can\n * observe transient UI (toasts, carousels, auto-hiding controls). The last\n * frame is the same state as {@link screenshot}.\n */\n abstract screenshotSequence?: ScreenshotItem[];\n\n /**\n * screenshot size after shrinking\n */\n abstract shotSize: Size;\n\n /**\n * The ratio for converting shrunk screenshot coordinates to logical coordinates.\n *\n * Example:\n * - Physical screen width: 3000px, dpr=6\n * - Logical width: 500px\n * - User-defined screenshotShrinkFactor: 2\n * - Actual shrunk screenshot width: 3000 / 2 = 1500px\n * - shrunkShotToLogicalRatio: dpr / screenshotShrinkFactor = 6 / 2 = 3\n * - To map back to logical coordinates: 1500 / shrunkShotToLogicalRatio = 500px\n */\n abstract shrunkShotToLogicalRatio: number;\n\n abstract _isFrozen?: boolean;\n\n // @deprecated - backward compatibility for aiLocate\n abstract deprecatedDpr?: number;\n}\n\nexport type EnsureObject<T> = { [K in keyof T]: any };\n\nexport type ServiceAction = 'locate' | 'extract' | 'assert' | 'describe';\n\nexport type ServiceExtractParam = string | Record<string, string>;\n\nexport type ElementCacheFeature = Record<string, unknown>;\n\nexport interface LocateResult {\n element: LocateResultElement | null;\n rect?: Rect;\n}\n\nexport type ThinkingLevel = 'off' | 'medium' | 'high';\n\nexport type AiActEffort = 'fast' | 'balance' | 'deepThink';\n\nexport type DeepThinkOption = 'unset' | true | false;\n\nexport interface ServiceTaskInfo {\n durationMs: number;\n formatResponse?: unknown;\n /**\n * Adapter-extracted content used by Midscene for parsing. This is not the\n * full provider response or choices[0].message.\n */\n rawResponse?: unknown;\n rawChoiceMessage?: unknown;\n usage?: AIUsageInfo;\n searchArea?: Rect;\n /**\n * Adapter-extracted content from the search-area model call. This is not the\n * full provider response or choices[0].message.\n */\n searchAreaRawResponse?: string;\n searchAreaRawChoiceMessage?: unknown;\n searchAreaUsage?: AIUsageInfo;\n reasoning_content?: string;\n}\n\nexport interface DumpMeta {\n logTime: number;\n}\n\nexport type ReportAttributes = Record<\n string,\n string | number | boolean | null | undefined\n>;\n\nexport interface ReportDumpWithAttributes {\n dumpString: string;\n attributes?: ReportAttributes;\n}\n\nexport interface ServiceDump extends DumpMeta {\n type: 'locate' | 'extract' | 'assert';\n logId: string;\n userQuery: {\n element?: TUserPrompt;\n dataDemand?: ServiceExtractParam;\n assertion?: TUserPrompt;\n };\n matchedElement?: LocateResultElement[];\n matchedRect?: Rect;\n deepLocate?: boolean;\n data: any;\n assertionPass?: boolean;\n assertionThought?: string;\n taskInfo: ServiceTaskInfo;\n error?: string;\n output?: any;\n}\n\nexport type PartialServiceDumpFromSDK = Omit<\n ServiceDump,\n 'logTime' | 'logId' | 'model_name'\n>;\n\nexport interface ServiceResultBase {\n dump: ServiceDump;\n}\n\nexport type LocateResultWithDump = LocateResult & ServiceResultBase;\n\nexport interface ServiceExtractResult<T> extends ServiceResultBase {\n data: T;\n thought?: string;\n usage?: AIUsageInfo;\n reasoning_content?: string;\n}\n\n// intermediate variables to optimize the return value by AI\nexport interface LiteUISection {\n name: string;\n description: string;\n sectionCharacteristics: string;\n textIds: string[];\n}\n\nexport type ElementById = (id: string) => BaseElement | null;\n\nexport type ServiceAssertionResponse = AIAssertionResponse & {\n usage?: AIUsageInfo;\n};\n\n/**\n * agent\n */\n\nexport type OnTaskStartTip = (tip: string) => Promise<void> | void;\n\nexport interface AgentWaitForOpt extends ServiceExtractOption {\n checkIntervalMs?: number;\n timeoutMs?: number;\n}\n\nexport interface AgentAssertOpt {\n keepRawResponse?: boolean;\n context?: string;\n abortSignal?: AbortSignal;\n}\n\nexport interface AgentAssertResult {\n pass: boolean;\n thought?: string;\n message?: string;\n}\n\nexport type QueryOptions = ServiceExtractOption;\nexport type AssertOptions = AgentAssertOpt & ServiceExtractOption;\n\n/** Options for fixed observations, which never read the live DOM. */\nexport type ObservationQueryOptions = Omit<QueryOptions, 'domIncluded'> & {\n domIncluded?: never;\n};\n\n/** Assertion options for fixed observations, which never read the live DOM. */\nexport type ObservationAssertOptions = Omit<AssertOptions, 'domIncluded'> & {\n domIncluded?: never;\n};\n\n/** Read-only AI operations supported by both live Agents and UI observations. */\nexport interface InsightAPI<\n QueryOpt extends QueryOptions = QueryOptions,\n AssertOpt extends AssertOptions = AssertOptions,\n> {\n aiQuery<ReturnType = any>(\n demand: ServiceExtractParam,\n options?: QueryOpt,\n ): Promise<ReturnType>;\n aiBoolean(prompt: TUserPrompt, options?: QueryOpt): Promise<boolean>;\n aiNumber(prompt: TUserPrompt, options?: QueryOpt): Promise<number>;\n aiString(prompt: TUserPrompt, options?: QueryOpt): Promise<string>;\n aiAsk(prompt: TUserPrompt, options?: QueryOpt): Promise<string>;\n aiAssert(\n assertion: TUserPrompt,\n message?: string,\n options?: AssertOpt,\n ): Promise<AgentAssertResult | undefined>;\n}\n\n/**\n * planning\n *\n */\n\ntype PlanningActionBase = {\n thought?: string;\n log?: string; // a brief preamble to the user explaining what you’re about to do\n type: string;\n};\n\nexport type PlanningAction<ParamType = undefined> = PlanningActionBase &\n ([ParamType] extends [undefined] ? { param?: any } : { param: ParamType });\n\nexport type SubGoalStatus = 'pending' | 'running' | 'finished';\n\nexport interface SubGoal {\n index: number;\n status: SubGoalStatus;\n description: string;\n logs?: string[];\n}\n\nexport interface RawResponsePlanningAIResponse {\n action: PlanningAction | null;\n thought?: string;\n log: string;\n memory?: string;\n error?: string;\n finalizeMessage?: string;\n finalizeSuccess?: boolean;\n updateSubGoals?: SubGoal[];\n markFinishedIndexes?: number[];\n}\n\nexport interface PlanningAIResponse\n extends Omit<RawResponsePlanningAIResponse, 'action'> {\n actions?: PlanningAction[];\n usage?: AIUsageInfo;\n /**\n * Adapter-extracted content used by Midscene for parsing. This is not the\n * full provider response or choices[0].message.\n */\n rawResponse?: string;\n rawChoiceMessage?: unknown;\n yamlFlow?: MidsceneYamlFlowItem[];\n yamlString?: string;\n error?: string;\n reasoning_content?: string;\n shouldContinuePlanning: boolean;\n output?: string; // Output message from <complete> tag (same as finalizeMessage)\n}\n\nexport interface PlanningActionParamSleep {\n timeMs: number;\n}\n\nexport interface PlanningActionParamError {\n thought: string;\n}\n\nexport type PlanningActionParamWaitFor = AgentWaitForOpt & {};\n\nexport interface LongPressParam {\n duration?: number;\n}\n\nexport interface PullParam {\n direction: 'up' | 'down';\n distance?: number;\n duration?: number;\n}\n/**\n * misc\n */\n\nexport interface Color {\n name: string;\n hex: string;\n}\n\nexport interface BaseAgentParserOpt {\n selector?: string;\n}\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface PuppeteerParserOpt extends BaseAgentParserOpt {}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface PlaywrightParserOpt extends BaseAgentParserOpt {}\n\n/*\naction\n*/\nexport interface ExecutionTaskProgressOptions {\n onTaskStart?: (task: ExecutionTask) => Promise<void> | void;\n}\n\n/**\n * Generic agent progress bus.\n *\n * Progress notifications are a single, generic stream the agent broadcasts as\n * it works. Each event is a thin envelope: a `scope` naming the producer, a\n * `phase` within that producer's lifecycle, a monotonic `sequence`, and a\n * structured, presentation-free `data` payload. The bus knows nothing about any\n * particular producer's payload - consumers narrow by `scope`. `aiAct` is the\n * first producer (\"pilot\") on this bus; others (queries, waits, ...) can be\n * added without touching the bus, the listener API, or the renderer core.\n */\nexport interface AgentProgressEvent<\n TScope extends string = string,\n TData = unknown,\n TPhase extends string = string,\n> {\n scope: TScope;\n phase: TPhase;\n sequence: number;\n data: TData;\n}\n\nexport type AgentProgressListener<\n TScope extends string = string,\n TData = unknown,\n TPhase extends string = string,\n> = (event: AgentProgressEvent<TScope, TData, TPhase>) => Promise<void> | void;\n\n// --- aiAct: the first producer on the generic progress bus ---\n\nexport type AiActProgressPhase =\n | 'start'\n | 'plan_thinking'\n | 'plan_planned'\n | 'plan_action'\n | 'plan_failed'\n | 'action_running'\n | 'action_done'\n | 'action_failed'\n | 'complete'\n | 'failed';\n\nexport interface AiActProgressAction {\n name: string;\n target?: string;\n point?: [number, number];\n bbox?: [number, number, number, number];\n /**\n * Structured, compacted summary of the action params for actions that are\n * not described by a point/bbox (e.g. `Sleep` -> `{ timeMs }`). This is data,\n * never a pre-formatted display string; consumers decide how to render it.\n */\n param?: unknown;\n}\n\n/**\n * Structured payload carried by aiAct progress events. The producer only\n * reports *what happened* as data: the action involved, the raw text the model\n * produced, timings and errors. It never assembles human-readable log lines or\n * truncates strings for display - that belongs to whichever layer consumes the\n * stream (e.g. the CLI verbose renderer).\n */\nexport interface AiActProgressData {\n /** Original user instruction, present on the `start` phase. */\n prompt?: string;\n planIndex?: number;\n planLimit?: number;\n /** Latest screenshot, present on `plan_thinking`. */\n screenshot?: ScreenshotItem;\n /** Structured action descriptor, present on the `*action*` phases. */\n action?: AiActProgressAction;\n /**\n * Raw, untruncated semantic text produced by the model. Consumers choose\n * which field to surface and how to format/truncate it.\n */\n thought?: string;\n log?: string;\n output?: string;\n /** Wall-clock cost of an action, present on `action_done`/`action_failed`. */\n durationMs?: number;\n error?: string;\n}\n\nexport const aiActProgressScope = 'aiAct';\n\nexport interface ExecutionRecorderItem {\n type: 'screenshot';\n ts: number;\n screenshot?: ScreenshotItem;\n description?: string;\n timing?: string;\n}\n\nexport interface RecordToReportScreenshot {\n /**\n * PNG/JPEG data URI, or raw PNG base64 body.\n */\n base64: string;\n description?: string;\n}\n\nexport interface RecordToReportOptions {\n content?: string;\n /**\n * @deprecated Use `screenshots: [{ base64 }]` instead.\n */\n screenshotBase64?: string;\n /**\n * Custom screenshots to display under a single report entry.\n */\n screenshots?: RecordToReportScreenshot[];\n}\n\nexport type ExecutionTaskType = 'Planning' | 'Insight' | 'Action Space' | 'Log';\n\nexport interface ExecutorContext {\n task: ExecutionTask;\n element?: LocateResultElement | null;\n uiContext?: UIContext;\n}\n\nexport interface ExecutionTaskApply<\n Type extends ExecutionTaskType = any,\n TaskParam = any,\n TaskOutput = any,\n TaskLog = any,\n> {\n type: Type;\n subType?: string;\n param?: TaskParam;\n thought?: string;\n uiContext?: UIContext;\n executor: (\n context: ExecutorContext,\n ) => // biome-ignore lint/suspicious/noConfusingVoidType: void is intentionally allowed as some executors may not return a value\n | Promise<ExecutionTaskReturn<TaskOutput, TaskLog> | undefined | void>\n | undefined\n | void;\n}\n\nexport interface ExecutionTaskHitBy {\n from: string;\n context: Record<string, any>;\n}\n\nexport interface ExecutionTaskReturn<TaskOutput = unknown, TaskLog = unknown> {\n output?: TaskOutput;\n log?: TaskLog;\n recorder?: ExecutionRecorderItem[];\n hitBy?: ExecutionTaskHitBy;\n}\n\nexport type ExecutionTask<\n E extends ExecutionTaskApply<any, any, any> = ExecutionTaskApply<\n any,\n any,\n any\n >,\n> = E &\n ExecutionTaskReturn<\n E extends ExecutionTaskApply<any, any, infer TaskOutput, any>\n ? TaskOutput\n : unknown,\n E extends ExecutionTaskApply<any, any, any, infer TaskLog>\n ? TaskLog\n : unknown\n > & {\n taskId: string;\n status: 'pending' | 'running' | 'finished' | 'failed' | 'cancelled';\n /**\n * Optional feedback produced by a task for the next planning round.\n * This is execution metadata, not part of the action return value.\n */\n planningFeedback?: string;\n /**\n * A bounded diagnostic DTO created when the task executor throws. Arbitrary\n * upstream payloads are intentionally omitted; use this field for structured\n * diagnostics or errorMessage/errorStack for the common display path.\n */\n error?: SerializedError;\n errorMessage?: string;\n errorStack?: string;\n timing?: {\n start: number;\n getUiContextStart?: number;\n getUiContextEnd?: number;\n callAiStart?: number;\n callAiEnd?: number;\n beforeInvokeActionHookStart?: number;\n beforeInvokeActionHookEnd?: number;\n callActionStart?: number;\n callActionEnd?: number;\n afterInvokeActionHookStart?: number;\n afterInvokeActionHookEnd?: number;\n captureAfterCallingSnapshotStart?: number;\n captureAfterCallingSnapshotEnd?: number;\n end?: number;\n cost?: number;\n };\n usage?: AIUsageInfo;\n /**\n * Pixel rect of the deepLocate first-stage search area in screenshot\n * coordinates. Used by reports to explain the crop/zoom area that the\n * final locate ran against.\n */\n searchArea?: Rect;\n searchAreaUsage?: AIUsageInfo;\n reasoning_content?: string;\n };\n\nexport interface IExecutionDump extends DumpMeta {\n /** Stable unique identifier for this execution run */\n id?: string;\n name: string;\n description?: string;\n tasks: ExecutionTask[];\n aiActContext?: string;\n}\n\n/*\ntask - service-locate\n*/\nexport interface ExecutionTaskInsightLocateOutput {\n element: LocateResultElement | null;\n}\n\nexport type ExecutionTaskInsightDump = ServiceDump;\n\nexport type ExecutionTaskInsightLocateApply = ExecutionTaskApply<\n 'Insight',\n DetailedLocateParam,\n ExecutionTaskInsightLocateOutput,\n ExecutionTaskInsightDump\n>;\n\nexport type ExecutionTaskInsightLocate =\n ExecutionTask<ExecutionTaskInsightLocateApply>;\n\n/*\ntask - service-query\n*/\nexport interface ExecutionTaskInsightQueryParam {\n dataDemand: ServiceExtractParam;\n domIncluded?: boolean | 'visible-only';\n context?: string;\n}\n\nexport interface ExecutionTaskInsightQueryOutput {\n data: any;\n}\n\nexport type ExecutionTaskInsightQueryApply = ExecutionTaskApply<\n 'Insight',\n ExecutionTaskInsightQueryParam,\n any,\n ExecutionTaskInsightDump\n>;\n\nexport type ExecutionTaskInsightQuery =\n ExecutionTask<ExecutionTaskInsightQueryApply>;\n\n/*\ntask - assertion\n*/\nexport interface ExecutionTaskInsightAssertionParam {\n assertion: string;\n}\n\nexport type ExecutionTaskInsightAssertionApply = ExecutionTaskApply<\n 'Insight',\n ExecutionTaskInsightAssertionParam,\n ServiceAssertionResponse,\n ExecutionTaskInsightDump\n>;\n\nexport type ExecutionTaskInsightAssertion =\n ExecutionTask<ExecutionTaskInsightAssertionApply>;\n\n/*\ntask - action (i.e. interact) \n*/\nexport type ExecutionTaskActionApply<ActionParam = any> = ExecutionTaskApply<\n 'Action Space',\n ActionParam,\n void,\n void\n>;\n\nexport type ExecutionTaskAction = ExecutionTask<ExecutionTaskActionApply>;\n\n/*\ntask - Log\n*/\n\nexport type ExecutionTaskLogApply<\n LogParam = {\n content: string;\n },\n> = ExecutionTaskApply<'Log', LogParam, void, void>;\n\nexport type ExecutionTaskLog = ExecutionTask<ExecutionTaskLogApply>;\n\n/*\ntask - planning\n*/\n\nexport interface ExecutionTaskPlanningParam {\n userInstruction: TUserPrompt;\n userInstructionDisplay?: string;\n replanningCycleLimit?: number;\n aiActContext?: string;\n imagesIncludeCount?: number;\n effort?: AiActEffort;\n subGoalStatus?: string;\n memoriesStatus?: string;\n}\n\nexport type ExecutionTaskPlanningApply = ExecutionTaskApply<\n 'Planning',\n ExecutionTaskPlanningParam,\n PlanningAIResponse\n>;\n\nexport type ExecutionTaskPlanning = ExecutionTask<ExecutionTaskPlanningApply>;\n\n/*\ntask - planning-locate\n*/\nexport interface ExecutionTaskPlanningLocateOutput {\n element: LocateResultElement | null;\n}\n\nexport type ExecutionTaskPlanningDump = ServiceDump;\n\nexport type ExecutionTaskPlanningLocateApply = ExecutionTaskApply<\n 'Planning',\n DetailedLocateParam,\n ExecutionTaskPlanningLocateOutput,\n ExecutionTaskPlanningDump\n>;\n\nexport type ExecutionTaskPlanningLocate =\n ExecutionTask<ExecutionTaskPlanningLocateApply>;\n\n/*\nHow a report file stores screenshots:\n- `inline`: base64 image script tags embedded in the single HTML file\n- `directory`: external PNG files under a sibling `screenshots/` dir\n*/\nexport type ScreenshotMode = 'inline' | 'directory';\n\n/*\nReport metadata - extracted from ReportActionDump for per-execution writes\n*/\nexport interface ReportMeta {\n groupName: string;\n groupDescription?: string;\n sdkVersion: string;\n modelBriefs: ModelBrief[];\n deviceType?: string;\n}\n\n// Backward-compatible aliases for existing external consumers.\nexport type GroupMeta = ReportMeta;\n\n/*\nReport dump\n*/\nexport interface IReportActionDump {\n sdkVersion: string;\n groupName: string;\n groupDescription?: string;\n modelBriefs: ModelBrief[];\n executions: IExecutionDump[];\n deviceType?: string;\n}\n\n// Backward-compatible aliases for existing external consumers.\nexport type IGroupedActionDump = IReportActionDump;\n\nexport interface ModelBrief {\n /**\n * The intent/category of the model call, for example \"planning\" or \"insight\".\n */\n intent?: string;\n\n /**\n * The model name returned by usage metadata, for example \"gpt-4o\".\n */\n name?: string;\n\n /**\n * Optional human-readable model description, for example \"qwen2.5-vl mode\".\n */\n modelDescription?: string;\n}\n\nexport type InterfaceType =\n | 'puppeteer'\n | 'playwright'\n | 'static'\n | 'chrome-extension-proxy'\n | 'android'\n | string;\n\nexport interface StreamingCodeGenerationOptions {\n /** Whether to enable streaming output */\n stream?: boolean;\n /** Callback function to handle streaming chunks */\n onChunk?: StreamingCallback;\n /** Callback function to handle streaming completion */\n onComplete?: (finalCode: string) => void;\n /** Callback function to handle streaming errors */\n onError?: (error: Error) => void;\n}\n\nexport type StreamingCallback = (chunk: CodeGenerationChunk) => void;\n\nexport interface CodeGenerationChunk {\n /** The incremental content chunk */\n content: string;\n /** The reasoning content */\n reasoning_content: string;\n /** The accumulated content so far */\n accumulated: string;\n /** Whether this is the final chunk */\n isComplete: boolean;\n /** Token usage information if available */\n usage?: AIUsageInfo;\n}\n\nexport interface StreamingAIResponse {\n /** The final accumulated content */\n content: string;\n /** Token usage information */\n usage?: AIUsageInfo;\n /** Whether the response was streamed */\n isStreamed: boolean;\n}\n\nexport interface DeviceAction<TParam = any, TReturn = any> {\n name: string;\n description?: string;\n interfaceAlias?: string;\n paramSchema?: z.ZodType<TParam>;\n call: (\n param: TParam,\n context?: ExecutorContext,\n ) => Promise<TReturn> | TReturn;\n delayBeforeRunner?: number;\n delayAfterRunner?: number;\n /**\n * An example param object for this action.\n * Locate fields with { prompt } may be resolved to internal pixel bboxes when needed.\n */\n sample?: { [K in keyof TParam]?: any };\n}\n\n/**\n * Type utilities for extracting types from DeviceAction definitions\n */\n\n/**\n * Extract parameter type from a DeviceAction\n */\nexport type ActionParam<Action extends DeviceAction<any, any>> =\n Action extends DeviceAction<infer P, any> ? P : never;\n\n/**\n * Extract return type from a DeviceAction\n */\nexport type ActionReturn<Action extends DeviceAction<any, any>> =\n Action extends DeviceAction<any, infer R> ? R : never;\n\n/**\n * Web-specific types\n */\nexport interface WebElementInfo extends BaseElement {\n id: string;\n attributes: {\n nodeType: NodeType;\n [key: string]: string;\n };\n}\n\n/**\n * Agent\n */\n\nexport type CacheConfig = {\n strategy?: 'read-only' | 'read-write' | 'write-only';\n id: string;\n /**\n * Optional cache directory path.\n * When set, cache files are written to this directory instead of\n * `<MIDSCENE_RUN_DIR>/cache`.\n */\n cacheDir?: string;\n};\n\nexport type Cache =\n | false // No read, no write\n | true // Will throw error at runtime - deprecated\n | CacheConfig; // Object configuration (requires explicit id)\n\nexport interface AgentOpt {\n // @deprecated Use `reportFileName` and `cache.id` instead.\n testId?: string;\n // @deprecated\n cacheId?: string; // Keep backward compatibility, but marked as deprecated\n groupName?: string;\n groupDescription?: string;\n /* if auto generate report, default true */\n generateReport?: boolean;\n /* if persist per-execution dump files next to the report, default false */\n persistExecutionDump?: boolean;\n /* if auto print report msg, default true */\n autoPrintReportMsg?: boolean;\n\n /**\n * Use directory-based report format with separate image files.\n *\n * When enabled:\n * - Screenshots are saved as PNG files in a `screenshots/` subdirectory\n * - Report is generated as `index.html` with relative image paths\n * - Reduces memory usage and report file size\n *\n * IMPORTANT: 'html-and-external-assets' reports must be served via HTTP server\n * (e.g., `npx serve ./report-dir`). The file:// protocol will not\n * work due to browser CORS restrictions.\n *\n * @default 'single-html'\n */\n outputFormat?: 'single-html' | 'html-and-external-assets';\n\n onTaskStartTip?: OnTaskStartTip;\n aiActContext?: string;\n aiActionContext?: string;\n /* custom report file name */\n reportFileName?: string;\n reportAttributes?: ReportAttributes;\n modelConfig?: TModelConfig;\n cache?: Cache;\n /**\n * Maximum number of replanning cycles for aiAct.\n * Defaults are resolved by the active model adapter: 20 for standard planning,\n * 40 for UI-TARS, and 100 for Auto-GLM.\n * If omitted, the agent will also read `MIDSCENE_REPLANNING_CYCLE_LIMIT` for backward compatibility.\n */\n replanningCycleLimit?: number;\n\n /**\n * Wait time in milliseconds after each action execution.\n * This allows the UI to settle and stabilize before the next action.\n * Defaults to 300ms when not provided.\n */\n waitAfterAction?: number;\n\n /**\n * When set to true, Midscene will use the target device's formatted local\n * time instead of the runtime system time. The target interface must implement\n * getDeviceLocalTimeString to provide device-local wall-clock time.\n * Default: false\n */\n useDeviceTime?: boolean;\n\n /**\n * Custom screenshot shrink factor to reduce AI token usage.\n * When set, the screenshot will be scaled down by this factor from the physical resolution.\n *\n * Example:\n * - Physical screen width: 3000px, dpr=6\n * - Logical width: 500px\n * - screenshotShrinkFactor: 2\n * - Actual shrunk screenshot width: 3000 / 2 = 1500px\n * - AI analyzes the 1500px screenshot\n * - Coordinates are transformed back to logical (500px) before actions execute\n *\n * Benefits:\n * - Reduces token usage for high-resolution screenshots\n * - Maintains accuracy by scaling coordinates appropriately\n *\n * Must be >= 1 (shrinking only, enlarging is not supported).\n *\n * @default 1 (no shrinking, uses original physical screenshot)\n */\n screenshotShrinkFactor?: number;\n\n /**\n * Custom OpenAI client factory function\n *\n * If provided, this function will be called to create OpenAI client instances\n * for each AI call, allowing you to:\n * - Wrap clients with observability tools (langsmith, langfuse)\n * - Use custom OpenAI-compatible clients\n * - Apply different configurations based on intent\n *\n * @param config - Resolved model configuration\n * @returns OpenAI client instance (original or wrapped)\n *\n * @example\n * ```typescript\n * createOpenAIClient: async (openai, opts) => {\n * // Wrap with langsmith for planning tasks\n * if (opts.baseURL?.includes('planning')) {\n * return wrapOpenAI(openai, { metadata: { task: 'planning' } });\n * }\n *\n * return openai;\n * }\n * ```\n */\n createOpenAIClient?: CreateOpenAIClientFn;\n\n /**\n * Called once per LLM call as soon as its usage is available, with the raw\n * {@link AIUsageInfo} (token counts, model name, intent, request id, etc.).\n *\n * Use this for real-time, per-spec cost observability — e.g. push each call\n * to Langfuse without waiting for the run to finish. For aggregated totals,\n * read `agent.metrics` instead.\n */\n onLLMUsage?: (usage: AIUsageInfo) => void;\n}\n\nexport type TestStatus =\n | 'passed'\n | 'failed'\n | 'timedOut'\n | 'skipped'\n | 'interrupted';\n\nexport interface ReportFileAttributes {\n testDuration: number;\n testStatus: TestStatus;\n testTitle: string;\n testId: string;\n testDescription: string;\n}\n\ntype SkippedReportFileAttributes = Omit<ReportFileAttributes, 'testStatus'> & {\n testStatus: 'skipped';\n};\n\nexport type ReportFileWithAttributes =\n | {\n reportFilePath: string;\n reportAttributes: ReportFileAttributes;\n }\n | {\n reportFilePath?: undefined;\n reportAttributes: SkippedReportFileAttributes;\n };\n"],"names":["UIContext","aiActProgressScope"],"mappings":";;;AAmJO,MAAeA;AAqCtB;AAuVO,MAAMC,qBAAqB"}
|
|
1
|
+
{"version":3,"file":"types.mjs","sources":["../../src/types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { AgentAIContexts } from '@midscene/shared/agent-tools/agent-context';\nimport type { SerializedError } from '@midscene/shared/agent-tools/error-formatter';\nimport type { NodeType } from '@midscene/shared/constants';\nimport type { CreateOpenAIClientFn, TModelConfig } from '@midscene/shared/env';\nimport type {\n BaseElement,\n LocateResultElement,\n Rect,\n Size,\n} from '@midscene/shared/types';\nimport type { z } from 'zod';\nimport type { TUserPrompt } from './common';\nimport type { ScreenshotItem } from './screenshot-item';\nimport type {\n DetailedLocateParam,\n MidsceneYamlFlowItem,\n ServiceExtractOption,\n} from './yaml';\n\nexport type {\n ElementTreeNode,\n BaseElement,\n Rect,\n Size,\n Point,\n} from '@midscene/shared/types';\nexport type { SerializedError } from '@midscene/shared/agent-tools/error-formatter';\nexport type {\n AgentAIContextKey,\n AgentAIContexts,\n AiApiName,\n} from '@midscene/shared/agent-tools/agent-context';\nexport * from './yaml';\n\nexport { ServiceError } from './errors';\nexport {\n ExecutionDump,\n ReportActionDump,\n GroupedActionDump,\n} from './dump/report-action-dump';\n\nexport type AIUsageInfo = Record<string, any> & {\n prompt_tokens: number | undefined;\n completion_tokens: number | undefined;\n total_tokens: number | undefined;\n cached_input: number | undefined;\n time_cost: number | undefined;\n model_name: string | undefined;\n model_description: string | undefined;\n /**\n * Raw top-level `.model` value returned by the model service response.\n */\n response_model_name: string | undefined;\n /**\n * Semantic intent of the model call, such as default, planning, or insight.\n */\n intent: string | undefined;\n /**\n * Config slot where the model config was resolved from. For example, a\n * planning call may use the default slot when no planning model is configured.\n */\n slot: string | undefined;\n request_id: string | undefined;\n};\n\nexport type { LocateResultElement };\n\nexport type AISingleElementResponseByPosition = {\n position?: {\n x: number;\n y: number;\n };\n bbox?: [number, number, number, number];\n reason: string;\n text: string;\n};\n\nexport type LocateResultPoint = [number, number];\nexport type Bbox = [number, number, number, number];\nexport type LocateResultBbox = Bbox;\nexport type PixelBbox = Bbox;\n\nexport interface AIElementLocateResponse {\n bbox?: LocateResultBbox;\n point?: LocateResultPoint;\n error?: string;\n}\n\nexport interface AIDataExtractionResponse<DataDemand> {\n data: DataDemand;\n errors?: string[];\n thought?: string;\n}\n\nexport interface AISectionLocatorResponse {\n bbox?: LocateResultBbox;\n point?: LocateResultPoint;\n references_bbox?: LocateResultBbox[];\n references_point?: LocateResultPoint[];\n error?: string;\n}\n\nexport interface AIAssertionResponse {\n pass: boolean;\n thought: string;\n}\n\nexport interface AIDescribeElementResponse {\n description: string;\n error?: string;\n}\n\nexport interface LocatorValidatorOption {\n centerDistanceThreshold?: number;\n}\n\nexport interface LocateValidatorResult {\n pass: boolean;\n rect: Rect;\n center: [number, number];\n centerDistance?: number;\n includedInRect?: boolean;\n}\n\nexport interface AgentDescribeElementAtPointResult {\n prompt: string;\n deepLocate: boolean;\n deepDescribe: boolean;\n verifyResult?: LocateValidatorResult;\n success: boolean;\n error?: string;\n failureStage?: 'describe' | 'verify';\n}\n\n/**\n * context\n */\n\nexport interface UiNode {\n type: string;\n attrs: Record<string, string | undefined>;\n bounds: Rect;\n children: UiNode[];\n}\n\nexport interface UITreeSnapshot {\n platform: 'android';\n capturedAt: number;\n root: UiNode;\n}\n\nexport abstract class UIContext {\n /**\n * screenshot of the current UI state. which size is shotSize(be shrunk by screenshotShrinkFactor),\n */\n abstract screenshot: ScreenshotItem;\n\n /**\n * Optional sequence of screenshots captured over a short time window, in\n * temporal order (earliest first, latest last). When present with more than\n * one frame, extract/assert flows submit all frames to the model so it can\n * observe transient UI (toasts, carousels, auto-hiding controls). The last\n * frame is the same state as {@link screenshot}.\n */\n abstract screenshotSequence?: ScreenshotItem[];\n\n /**\n * screenshot size after shrinking\n */\n abstract shotSize: Size;\n\n /**\n * The ratio for converting shrunk screenshot coordinates to logical coordinates.\n *\n * Example:\n * - Physical screen width: 3000px, dpr=6\n * - Logical width: 500px\n * - User-defined screenshotShrinkFactor: 2\n * - Actual shrunk screenshot width: 3000 / 2 = 1500px\n * - shrunkShotToLogicalRatio: dpr / screenshotShrinkFactor = 6 / 2 = 3\n * - To map back to logical coordinates: 1500 / shrunkShotToLogicalRatio = 500px\n */\n abstract shrunkShotToLogicalRatio: number;\n\n abstract _isFrozen?: boolean;\n\n // @deprecated - backward compatibility for aiLocate\n abstract deprecatedDpr?: number;\n}\n\nexport type EnsureObject<T> = { [K in keyof T]: any };\n\nexport type ServiceAction = 'locate' | 'extract' | 'assert' | 'describe';\n\nexport type ServiceExtractParam = string | Record<string, string>;\n\nexport type ElementCacheFeature = Record<string, unknown>;\n\nexport interface LocateResult {\n element: LocateResultElement | null;\n rect?: Rect;\n}\n\nexport type ThinkingLevel = 'off' | 'medium' | 'high';\n\nexport type AiActEffort = 'fast' | 'balance' | 'deepThink';\n\nexport type DeepThinkOption = 'unset' | true | false;\n\nexport interface ServiceTaskInfo {\n durationMs: number;\n formatResponse?: unknown;\n /**\n * Adapter-extracted content used by Midscene for parsing. This is not the\n * full provider response or choices[0].message.\n */\n rawResponse?: unknown;\n rawChoiceMessage?: unknown;\n usage?: AIUsageInfo;\n searchArea?: Rect;\n /**\n * Adapter-extracted content from the search-area model call. This is not the\n * full provider response or choices[0].message.\n */\n searchAreaRawResponse?: string;\n searchAreaRawChoiceMessage?: unknown;\n searchAreaUsage?: AIUsageInfo;\n reasoning_content?: string;\n}\n\nexport interface DumpMeta {\n logTime: number;\n}\n\nexport type ReportAttributes = Record<\n string,\n string | number | boolean | null | undefined\n>;\n\nexport interface ReportDumpWithAttributes {\n dumpString: string;\n attributes?: ReportAttributes;\n}\n\nexport interface ServiceDump extends DumpMeta {\n type: 'locate' | 'extract' | 'assert';\n logId: string;\n userQuery: {\n element?: TUserPrompt;\n dataDemand?: ServiceExtractParam;\n assertion?: TUserPrompt;\n };\n matchedElement?: LocateResultElement[];\n matchedRect?: Rect;\n deepLocate?: boolean;\n data: any;\n assertionPass?: boolean;\n assertionThought?: string;\n taskInfo: ServiceTaskInfo;\n error?: string;\n output?: any;\n}\n\nexport type PartialServiceDumpFromSDK = Omit<\n ServiceDump,\n 'logTime' | 'logId' | 'model_name'\n>;\n\nexport interface ServiceResultBase {\n dump: ServiceDump;\n}\n\nexport type LocateResultWithDump = LocateResult & ServiceResultBase;\n\nexport interface ServiceExtractResult<T> extends ServiceResultBase {\n data: T;\n thought?: string;\n usage?: AIUsageInfo;\n reasoning_content?: string;\n}\n\n// intermediate variables to optimize the return value by AI\nexport interface LiteUISection {\n name: string;\n description: string;\n sectionCharacteristics: string;\n textIds: string[];\n}\n\nexport type ElementById = (id: string) => BaseElement | null;\n\nexport type ServiceAssertionResponse = AIAssertionResponse & {\n usage?: AIUsageInfo;\n};\n\n/**\n * agent\n */\n\nexport type OnTaskStartTip = (tip: string) => Promise<void> | void;\n\nexport interface AgentWaitForOpt extends ServiceExtractOption {\n checkIntervalMs?: number;\n timeoutMs?: number;\n}\n\nexport interface AgentAssertOpt {\n keepRawResponse?: boolean;\n /**\n * Additional facts, decision rules, constraints, or output requirements for\n * this assertion. It overrides `aiContexts.aiAssert` and\n * `aiContexts.default`;\n * `''` disables inherited user context for this call.\n */\n context?: string;\n abortSignal?: AbortSignal;\n}\n\nexport interface AgentAssertResult {\n pass: boolean;\n thought?: string;\n message?: string;\n}\n\nexport type QueryOptions = ServiceExtractOption;\nexport type AssertOptions = AgentAssertOpt & ServiceExtractOption;\n\n/** Options for fixed observations, which never read the live DOM. */\nexport type ObservationQueryOptions = Omit<QueryOptions, 'domIncluded'> & {\n domIncluded?: never;\n};\n\n/** Assertion options for fixed observations, which never read the live DOM. */\nexport type ObservationAssertOptions = Omit<AssertOptions, 'domIncluded'> & {\n domIncluded?: never;\n};\n\n/** Read-only AI operations supported by both live Agents and UI observations. */\nexport interface InsightAPI<\n QueryOpt extends QueryOptions = QueryOptions,\n AssertOpt extends AssertOptions = AssertOptions,\n> {\n aiQuery<ReturnType = any>(\n demand: ServiceExtractParam,\n options?: QueryOpt,\n ): Promise<ReturnType>;\n aiBoolean(prompt: TUserPrompt, options?: QueryOpt): Promise<boolean>;\n aiNumber(prompt: TUserPrompt, options?: QueryOpt): Promise<number>;\n aiString(prompt: TUserPrompt, options?: QueryOpt): Promise<string>;\n aiAsk(prompt: TUserPrompt, options?: QueryOpt): Promise<string>;\n aiAssert(\n assertion: TUserPrompt,\n message?: string,\n options?: AssertOpt,\n ): Promise<AgentAssertResult | undefined>;\n}\n\n/**\n * planning\n *\n */\n\ntype PlanningActionBase = {\n thought?: string;\n log?: string; // a brief preamble to the user explaining what you’re about to do\n type: string;\n};\n\nexport type PlanningAction<ParamType = undefined> = PlanningActionBase &\n ([ParamType] extends [undefined] ? { param?: any } : { param: ParamType });\n\nexport type SubGoalStatus = 'pending' | 'running' | 'finished';\n\nexport interface SubGoal {\n index: number;\n status: SubGoalStatus;\n description: string;\n logs?: string[];\n}\n\nexport interface RawResponsePlanningAIResponse {\n action: PlanningAction | null;\n thought?: string;\n log: string;\n memory?: string;\n error?: string;\n finalizeMessage?: string;\n finalizeSuccess?: boolean;\n updateSubGoals?: SubGoal[];\n markFinishedIndexes?: number[];\n}\n\nexport interface PlanningAIResponse\n extends Omit<RawResponsePlanningAIResponse, 'action'> {\n actions?: PlanningAction[];\n usage?: AIUsageInfo;\n /**\n * Adapter-extracted content used by Midscene for parsing. This is not the\n * full provider response or choices[0].message.\n */\n rawResponse?: string;\n rawChoiceMessage?: unknown;\n yamlFlow?: MidsceneYamlFlowItem[];\n yamlString?: string;\n error?: string;\n reasoning_content?: string;\n shouldContinuePlanning: boolean;\n output?: string; // Output message from <complete> tag (same as finalizeMessage)\n}\n\nexport interface PlanningActionParamSleep {\n timeMs: number;\n}\n\nexport interface PlanningActionParamError {\n thought: string;\n}\n\nexport type PlanningActionParamWaitFor = AgentWaitForOpt & {};\n\nexport interface LongPressParam {\n duration?: number;\n}\n\nexport interface PullParam {\n direction: 'up' | 'down';\n distance?: number;\n duration?: number;\n}\n/**\n * misc\n */\n\nexport interface Color {\n name: string;\n hex: string;\n}\n\nexport interface BaseAgentParserOpt {\n selector?: string;\n}\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface PuppeteerParserOpt extends BaseAgentParserOpt {}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface PlaywrightParserOpt extends BaseAgentParserOpt {}\n\n/*\naction\n*/\nexport interface ExecutionTaskProgressOptions {\n onTaskStart?: (task: ExecutionTask) => Promise<void> | void;\n}\n\n/**\n * Generic agent progress bus.\n *\n * Progress notifications are a single, generic stream the agent broadcasts as\n * it works. Each event is a thin envelope: a `scope` naming the producer, a\n * `phase` within that producer's lifecycle, a monotonic `sequence`, and a\n * structured, presentation-free `data` payload. The bus knows nothing about any\n * particular producer's payload - consumers narrow by `scope`. `aiAct` is the\n * first producer (\"pilot\") on this bus; others (queries, waits, ...) can be\n * added without touching the bus, the listener API, or the renderer core.\n */\nexport interface AgentProgressEvent<\n TScope extends string = string,\n TData = unknown,\n TPhase extends string = string,\n> {\n scope: TScope;\n phase: TPhase;\n sequence: number;\n data: TData;\n}\n\nexport type AgentProgressListener<\n TScope extends string = string,\n TData = unknown,\n TPhase extends string = string,\n> = (event: AgentProgressEvent<TScope, TData, TPhase>) => Promise<void> | void;\n\n// --- aiAct: the first producer on the generic progress bus ---\n\nexport type AiActProgressPhase =\n | 'start'\n | 'plan_thinking'\n | 'plan_planned'\n | 'plan_action'\n | 'plan_failed'\n | 'action_running'\n | 'action_done'\n | 'action_failed'\n | 'complete'\n | 'failed';\n\nexport interface AiActProgressAction {\n name: string;\n target?: string;\n point?: [number, number];\n bbox?: [number, number, number, number];\n /**\n * Structured, compacted summary of the action params for actions that are\n * not described by a point/bbox (e.g. `Sleep` -> `{ timeMs }`). This is data,\n * never a pre-formatted display string; consumers decide how to render it.\n */\n param?: unknown;\n}\n\n/**\n * Structured payload carried by aiAct progress events. The producer only\n * reports *what happened* as data: the action involved, the raw text the model\n * produced, timings and errors. It never assembles human-readable log lines or\n * truncates strings for display - that belongs to whichever layer consumes the\n * stream (e.g. the CLI verbose renderer).\n */\nexport interface AiActProgressData {\n /** Original user instruction, present on the `start` phase. */\n prompt?: string;\n planIndex?: number;\n planLimit?: number;\n /** Latest screenshot, present on `plan_thinking`. */\n screenshot?: ScreenshotItem;\n /** Structured action descriptor, present on the `*action*` phases. */\n action?: AiActProgressAction;\n /**\n * Raw, untruncated semantic text produced by the model. Consumers choose\n * which field to surface and how to format/truncate it.\n */\n thought?: string;\n log?: string;\n output?: string;\n /** Wall-clock cost of an action, present on `action_done`/`action_failed`. */\n durationMs?: number;\n error?: string;\n}\n\nexport const aiActProgressScope = 'aiAct';\n\nexport interface ExecutionRecorderItem {\n type: 'screenshot';\n ts: number;\n screenshot?: ScreenshotItem;\n description?: string;\n timing?: string;\n}\n\nexport interface RecordToReportScreenshot {\n /**\n * PNG/JPEG data URI, or raw PNG base64 body.\n */\n base64: string;\n description?: string;\n}\n\nexport interface RecordToReportOptions {\n content?: string;\n /**\n * @deprecated Use `screenshots: [{ base64 }]` instead.\n */\n screenshotBase64?: string;\n /**\n * Custom screenshots to display under a single report entry.\n */\n screenshots?: RecordToReportScreenshot[];\n}\n\nexport type ExecutionTaskType = 'Planning' | 'Insight' | 'Action Space' | 'Log';\n\nexport interface ExecutorContext {\n task: ExecutionTask;\n element?: LocateResultElement | null;\n uiContext?: UIContext;\n}\n\nexport interface ExecutionTaskApply<\n Type extends ExecutionTaskType = any,\n TaskParam = any,\n TaskOutput = any,\n TaskLog = any,\n> {\n type: Type;\n subType?: string;\n param?: TaskParam;\n thought?: string;\n uiContext?: UIContext;\n executor: (\n context: ExecutorContext,\n ) => // biome-ignore lint/suspicious/noConfusingVoidType: void is intentionally allowed as some executors may not return a value\n | Promise<ExecutionTaskReturn<TaskOutput, TaskLog> | undefined | void>\n | undefined\n | void;\n}\n\nexport interface ExecutionTaskHitBy {\n from: string;\n context: Record<string, any>;\n}\n\nexport interface ExecutionTaskReturn<TaskOutput = unknown, TaskLog = unknown> {\n output?: TaskOutput;\n log?: TaskLog;\n recorder?: ExecutionRecorderItem[];\n hitBy?: ExecutionTaskHitBy;\n}\n\nexport type ExecutionTask<\n E extends ExecutionTaskApply<any, any, any> = ExecutionTaskApply<\n any,\n any,\n any\n >,\n> = E &\n ExecutionTaskReturn<\n E extends ExecutionTaskApply<any, any, infer TaskOutput, any>\n ? TaskOutput\n : unknown,\n E extends ExecutionTaskApply<any, any, any, infer TaskLog>\n ? TaskLog\n : unknown\n > & {\n taskId: string;\n status: 'pending' | 'running' | 'finished' | 'failed' | 'cancelled';\n /**\n * Optional feedback produced by a task for the next planning round.\n * This is execution metadata, not part of the action return value.\n */\n planningFeedback?: string;\n /**\n * A bounded diagnostic DTO created when the task executor throws. Arbitrary\n * upstream payloads are intentionally omitted; use this field for structured\n * diagnostics or errorMessage/errorStack for the common display path.\n */\n error?: SerializedError;\n errorMessage?: string;\n errorStack?: string;\n timing?: {\n start: number;\n getUiContextStart?: number;\n getUiContextEnd?: number;\n callAiStart?: number;\n callAiEnd?: number;\n beforeInvokeActionHookStart?: number;\n beforeInvokeActionHookEnd?: number;\n callActionStart?: number;\n callActionEnd?: number;\n afterInvokeActionHookStart?: number;\n afterInvokeActionHookEnd?: number;\n captureAfterCallingSnapshotStart?: number;\n captureAfterCallingSnapshotEnd?: number;\n end?: number;\n cost?: number;\n };\n usage?: AIUsageInfo;\n /**\n * Pixel rect of the deepLocate first-stage search area in screenshot\n * coordinates. Used by reports to explain the crop/zoom area that the\n * final locate ran against.\n */\n searchArea?: Rect;\n searchAreaUsage?: AIUsageInfo;\n reasoning_content?: string;\n };\n\nexport interface IExecutionDump extends DumpMeta {\n /** Stable unique identifier for this execution run */\n id?: string;\n name: string;\n description?: string;\n tasks: ExecutionTask[];\n aiActContext?: string;\n}\n\n/*\ntask - service-locate\n*/\nexport interface ExecutionTaskInsightLocateOutput {\n element: LocateResultElement | null;\n}\n\nexport type ExecutionTaskInsightDump = ServiceDump;\n\nexport type ExecutionTaskInsightLocateApply = ExecutionTaskApply<\n 'Insight',\n DetailedLocateParam,\n ExecutionTaskInsightLocateOutput,\n ExecutionTaskInsightDump\n>;\n\nexport type ExecutionTaskInsightLocate =\n ExecutionTask<ExecutionTaskInsightLocateApply>;\n\n/*\ntask - service-query\n*/\nexport interface ExecutionTaskInsightQueryParam {\n dataDemand: ServiceExtractParam;\n domIncluded?: boolean | 'visible-only';\n context?: string;\n}\n\nexport interface ExecutionTaskInsightQueryOutput {\n data: any;\n}\n\nexport type ExecutionTaskInsightQueryApply = ExecutionTaskApply<\n 'Insight',\n ExecutionTaskInsightQueryParam,\n any,\n ExecutionTaskInsightDump\n>;\n\nexport type ExecutionTaskInsightQuery =\n ExecutionTask<ExecutionTaskInsightQueryApply>;\n\n/*\ntask - assertion\n*/\nexport interface ExecutionTaskInsightAssertionParam {\n assertion: string;\n}\n\nexport type ExecutionTaskInsightAssertionApply = ExecutionTaskApply<\n 'Insight',\n ExecutionTaskInsightAssertionParam,\n ServiceAssertionResponse,\n ExecutionTaskInsightDump\n>;\n\nexport type ExecutionTaskInsightAssertion =\n ExecutionTask<ExecutionTaskInsightAssertionApply>;\n\n/*\ntask - action (i.e. interact) \n*/\nexport type ExecutionTaskActionApply<ActionParam = any> = ExecutionTaskApply<\n 'Action Space',\n ActionParam,\n void,\n void\n>;\n\nexport type ExecutionTaskAction = ExecutionTask<ExecutionTaskActionApply>;\n\n/*\ntask - Log\n*/\n\nexport type ExecutionTaskLogApply<\n LogParam = {\n content: string;\n },\n> = ExecutionTaskApply<'Log', LogParam, void, void>;\n\nexport type ExecutionTaskLog = ExecutionTask<ExecutionTaskLogApply>;\n\n/*\ntask - planning\n*/\n\nexport interface ExecutionTaskPlanningParam {\n userInstruction: TUserPrompt;\n userInstructionDisplay?: string;\n replanningCycleLimit?: number;\n aiActContext?: string;\n imagesIncludeCount?: number;\n effort?: AiActEffort;\n subGoalStatus?: string;\n memoriesStatus?: string;\n}\n\nexport type ExecutionTaskPlanningApply = ExecutionTaskApply<\n 'Planning',\n ExecutionTaskPlanningParam,\n PlanningAIResponse\n>;\n\nexport type ExecutionTaskPlanning = ExecutionTask<ExecutionTaskPlanningApply>;\n\n/*\ntask - planning-locate\n*/\nexport interface ExecutionTaskPlanningLocateOutput {\n element: LocateResultElement | null;\n}\n\nexport type ExecutionTaskPlanningDump = ServiceDump;\n\nexport type ExecutionTaskPlanningLocateApply = ExecutionTaskApply<\n 'Planning',\n DetailedLocateParam,\n ExecutionTaskPlanningLocateOutput,\n ExecutionTaskPlanningDump\n>;\n\nexport type ExecutionTaskPlanningLocate =\n ExecutionTask<ExecutionTaskPlanningLocateApply>;\n\n/*\nHow a report file stores screenshots:\n- `inline`: base64 image script tags embedded in the single HTML file\n- `directory`: external PNG files under a sibling `screenshots/` dir\n*/\nexport type ScreenshotMode = 'inline' | 'directory';\n\n/*\nReport metadata - extracted from ReportActionDump for per-execution writes\n*/\nexport interface ReportMeta {\n groupName: string;\n groupDescription?: string;\n sdkVersion: string;\n modelBriefs: ModelBrief[];\n deviceType?: string;\n}\n\n// Backward-compatible aliases for existing external consumers.\nexport type GroupMeta = ReportMeta;\n\n/*\nReport dump\n*/\nexport interface IReportActionDump {\n sdkVersion: string;\n groupName: string;\n groupDescription?: string;\n modelBriefs: ModelBrief[];\n executions: IExecutionDump[];\n deviceType?: string;\n}\n\n// Backward-compatible aliases for existing external consumers.\nexport type IGroupedActionDump = IReportActionDump;\n\nexport interface ModelBrief {\n /**\n * The intent/category of the model call, for example \"planning\" or \"insight\".\n */\n intent?: string;\n\n /**\n * The model name returned by usage metadata, for example \"gpt-4o\".\n */\n name?: string;\n\n /**\n * Optional human-readable model description, for example \"qwen2.5-vl mode\".\n */\n modelDescription?: string;\n}\n\nexport type InterfaceType =\n | 'puppeteer'\n | 'playwright'\n | 'static'\n | 'chrome-extension-proxy'\n | 'android'\n | string;\n\nexport interface StreamingCodeGenerationOptions {\n /** Whether to enable streaming output */\n stream?: boolean;\n /** Callback function to handle streaming chunks */\n onChunk?: StreamingCallback;\n /** Callback function to handle streaming completion */\n onComplete?: (finalCode: string) => void;\n /** Callback function to handle streaming errors */\n onError?: (error: Error) => void;\n}\n\nexport type StreamingCallback = (chunk: CodeGenerationChunk) => void;\n\nexport interface CodeGenerationChunk {\n /** The incremental content chunk */\n content: string;\n /** The reasoning content */\n reasoning_content: string;\n /** The accumulated content so far */\n accumulated: string;\n /** Whether this is the final chunk */\n isComplete: boolean;\n /** Token usage information if available */\n usage?: AIUsageInfo;\n}\n\nexport interface StreamingAIResponse {\n /** The final accumulated content */\n content: string;\n /** Token usage information */\n usage?: AIUsageInfo;\n /** Whether the response was streamed */\n isStreamed: boolean;\n}\n\nexport interface DeviceAction<TParam = any, TReturn = any> {\n name: string;\n description?: string;\n interfaceAlias?: string;\n paramSchema?: z.ZodType<TParam>;\n call: (\n param: TParam,\n context?: ExecutorContext,\n ) => Promise<TReturn> | TReturn;\n delayBeforeRunner?: number;\n delayAfterRunner?: number;\n /**\n * An example param object for this action.\n * Locate fields with { prompt } may be resolved to internal pixel bboxes when needed.\n */\n sample?: { [K in keyof TParam]?: any };\n}\n\n/**\n * Type utilities for extracting types from DeviceAction definitions\n */\n\n/**\n * Extract parameter type from a DeviceAction\n */\nexport type ActionParam<Action extends DeviceAction<any, any>> =\n Action extends DeviceAction<infer P, any> ? P : never;\n\n/**\n * Extract return type from a DeviceAction\n */\nexport type ActionReturn<Action extends DeviceAction<any, any>> =\n Action extends DeviceAction<any, infer R> ? R : never;\n\n/**\n * Web-specific types\n */\nexport interface WebElementInfo extends BaseElement {\n id: string;\n attributes: {\n nodeType: NodeType;\n [key: string]: string;\n };\n}\n\n/**\n * Agent\n */\n\nexport type CacheConfig = {\n strategy?: 'read-only' | 'read-write' | 'write-only';\n id: string;\n /**\n * Optional cache directory path.\n * When set, cache files are written to this directory instead of\n * `<MIDSCENE_RUN_DIR>/cache`.\n */\n cacheDir?: string;\n};\n\nexport type Cache =\n | false // No read, no write\n | true // Will throw error at runtime - deprecated\n | CacheConfig; // Object configuration (requires explicit id)\n\nexport interface AgentOpt {\n // @deprecated Use `reportFileName` and `cache.id` instead.\n testId?: string;\n // @deprecated\n cacheId?: string; // Keep backward compatibility, but marked as deprecated\n groupName?: string;\n groupDescription?: string;\n /* if auto generate report, default true */\n generateReport?: boolean;\n /* if persist per-execution dump files next to the report, default false */\n persistExecutionDump?: boolean;\n /* if auto print report msg, default true */\n autoPrintReportMsg?: boolean;\n\n /**\n * Use directory-based report format with separate image files.\n *\n * When enabled:\n * - Screenshots are saved as PNG files in a `screenshots/` subdirectory\n * - Report is generated as `index.html` with relative image paths\n * - Reduces memory usage and report file size\n *\n * IMPORTANT: 'html-and-external-assets' reports must be served via HTTP server\n * (e.g., `npx serve ./report-dir`). The file:// protocol will not\n * work due to browser CORS restrictions.\n *\n * @default 'single-html'\n */\n outputFormat?: 'single-html' | 'html-and-external-assets';\n\n onTaskStartTip?: OnTaskStartTip;\n /**\n * Agent-level AI guidance containing business facts, rules, constraints, or\n * output requirements. `aiContexts.default` is a shared fallback used only\n * when neither the call nor the matching API key provides a context.\n *\n * A per-call `options.context` overrides the matching API context, which\n * overrides `aiContexts.default`. An empty string explicitly clears\n * inherited user context for that scope. These layers are not automatically\n * merged.\n */\n aiContexts?: AgentAIContexts;\n /**\n * Compatibility alias for `aiContexts.aiAct`. `aiContexts.aiAct` takes\n * precedence when both are provided.\n * @deprecated Use `aiContexts.aiAct` instead.\n */\n aiActContext?: string;\n /**\n * Older compatibility alias for `aiContexts.aiAct`.\n * @deprecated Use `aiContexts.aiAct` instead.\n */\n aiActionContext?: string;\n /* custom report file name */\n reportFileName?: string;\n reportAttributes?: ReportAttributes;\n modelConfig?: TModelConfig;\n cache?: Cache;\n /**\n * Maximum number of replanning cycles for aiAct.\n * Defaults are resolved by the active model adapter: 20 for standard planning,\n * 40 for UI-TARS, and 100 for Auto-GLM.\n * If omitted, the agent will also read `MIDSCENE_REPLANNING_CYCLE_LIMIT` for backward compatibility.\n */\n replanningCycleLimit?: number;\n\n /**\n * Wait time in milliseconds after each action execution.\n * This allows the UI to settle and stabilize before the next action.\n * Defaults to 300ms when not provided.\n */\n waitAfterAction?: number;\n\n /**\n * When set to true, Midscene will use the target device's formatted local\n * time instead of the runtime system time. The target interface must implement\n * getDeviceLocalTimeString to provide device-local wall-clock time.\n * Default: false\n */\n useDeviceTime?: boolean;\n\n /**\n * Custom screenshot shrink factor to reduce AI token usage.\n * When set, the screenshot will be scaled down by this factor from the physical resolution.\n *\n * Example:\n * - Physical screen width: 3000px, dpr=6\n * - Logical width: 500px\n * - screenshotShrinkFactor: 2\n * - Actual shrunk screenshot width: 3000 / 2 = 1500px\n * - AI analyzes the 1500px screenshot\n * - Coordinates are transformed back to logical (500px) before actions execute\n *\n * Benefits:\n * - Reduces token usage for high-resolution screenshots\n * - Maintains accuracy by scaling coordinates appropriately\n *\n * Must be >= 1 (shrinking only, enlarging is not supported).\n *\n * @default 1 (no shrinking, uses original physical screenshot)\n */\n screenshotShrinkFactor?: number;\n\n /**\n * Custom OpenAI client factory function\n *\n * If provided, this function will be called to create OpenAI client instances\n * for each AI call, allowing you to:\n * - Wrap clients with observability tools (langsmith, langfuse)\n * - Use custom OpenAI-compatible clients\n * - Apply different configurations based on intent\n *\n * @param config - Resolved model configuration\n * @returns OpenAI client instance (original or wrapped)\n *\n * @example\n * ```typescript\n * createOpenAIClient: async (openai, opts) => {\n * // Wrap with langsmith for planning tasks\n * if (opts.baseURL?.includes('planning')) {\n * return wrapOpenAI(openai, { metadata: { task: 'planning' } });\n * }\n *\n * return openai;\n * }\n * ```\n */\n createOpenAIClient?: CreateOpenAIClientFn;\n\n /**\n * Called once per LLM call as soon as its usage is available, with the raw\n * {@link AIUsageInfo} (token counts, model name, intent, request id, etc.).\n *\n * Use this for real-time, per-spec cost observability — e.g. push each call\n * to Langfuse without waiting for the run to finish. For aggregated totals,\n * read `agent.metrics` instead.\n */\n onLLMUsage?: (usage: AIUsageInfo) => void;\n}\n\nexport type TestStatus =\n | 'passed'\n | 'failed'\n | 'timedOut'\n | 'skipped'\n | 'interrupted';\n\nexport interface ReportFileAttributes {\n testDuration: number;\n testStatus: TestStatus;\n testTitle: string;\n testId: string;\n testDescription: string;\n}\n\ntype SkippedReportFileAttributes = Omit<ReportFileAttributes, 'testStatus'> & {\n testStatus: 'skipped';\n};\n\nexport type ReportFileWithAttributes =\n | {\n reportFilePath: string;\n reportAttributes: ReportFileAttributes;\n }\n | {\n reportFilePath?: undefined;\n reportAttributes: SkippedReportFileAttributes;\n };\n"],"names":["UIContext","aiActProgressScope"],"mappings":";;;AAyJO,MAAeA;AAqCtB;AA6VO,MAAMC,qBAAqB"}
|
package/dist/es/utils.mjs
CHANGED
|
@@ -184,7 +184,7 @@ function stringifyDumpData(data, indents) {
|
|
|
184
184
|
return JSON.stringify(data, replacerForPageObject, indents);
|
|
185
185
|
}
|
|
186
186
|
function getVersion() {
|
|
187
|
-
return "1.12.4
|
|
187
|
+
return "1.12.4";
|
|
188
188
|
}
|
|
189
189
|
function debugLog(...message) {
|
|
190
190
|
const debugMode = process.env[MIDSCENE_DEBUG_MODE];
|
package/dist/es/yaml/player.mjs
CHANGED
|
@@ -448,11 +448,6 @@ class ScriptPlayer {
|
|
|
448
448
|
this.failedReportExecutionInCurrentStep = false;
|
|
449
449
|
this.scriptPath = scriptPath;
|
|
450
450
|
this.result = {};
|
|
451
|
-
const resolvedAiActContext = script.agent?.aiActContext ?? script.agent?.aiActionContext;
|
|
452
|
-
if (void 0 !== resolvedAiActContext && script.agent) {
|
|
453
|
-
if (void 0 === script.agent.aiActContext && void 0 !== script.agent.aiActionContext) console.warn('agent.aiActionContext is deprecated, please use agent.aiActContext instead. The legacy name is still accepted for backward compatibility.');
|
|
454
|
-
script.agent.aiActContext = resolvedAiActContext;
|
|
455
|
-
}
|
|
456
451
|
this.target = script.target || script.web || script.android || script.ios || script.computer || script.config;
|
|
457
452
|
if (ifInBrowser || ifInWorker) {
|
|
458
453
|
this.output = void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yaml/player.mjs","sources":["../../../src/yaml/player.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { basename, dirname, join, resolve } from 'node:path';\nimport { assert, ifInBrowser, ifInWorker } from '@midscene/shared/utils';\nimport { type ZodTypeAny, z } from 'zod';\n\n// previous defined yaml flow, as a helper\ninterface MidsceneYamlFlowItemAIInput extends LocateOption {\n // previous version\n // aiInput: string; // value to input\n // locate: TUserPrompt; // where to input\n aiInput: TUserPrompt | undefined; // where to input\n value: string | number; // value to input\n mode?: 'replace' | 'clear' | 'typeOnly';\n autoDismissKeyboard?: boolean;\n keyboardTypeDelay?: number;\n inputStrategy?: InputStrategy;\n}\n\ninterface MidsceneYamlFlowItemAIKeyboardPress extends LocateOption {\n // previous version\n // aiKeyboardPress: string;\n // locate?: TUserPrompt; // where to press, optional\n aiKeyboardPress: TUserPrompt | undefined; // where to press\n keyName: string; // key to press\n}\n\ninterface MidsceneYamlFlowItemAIScroll extends LocateOption, ScrollParam {\n // previous version\n // aiScroll: null;\n // locate?: TUserPrompt; // which area to scroll, optional\n aiScroll: TUserPrompt | undefined; // which area to scroll\n}\n\ntype RuntimeYamlFlowItem =\n | MidsceneYamlFlowItem\n | MidsceneYamlFlowItemAIInput\n | MidsceneYamlFlowItemAIKeyboardPress\n | MidsceneYamlFlowItemAIScroll;\n\nimport type { Agent } from '@/agent/agent';\nimport type { TUserPrompt } from '@/common';\nimport type { InputStrategy } from '@/device';\nimport { deriveCaseStatus } from '@/dump/task-status';\nimport type {\n DeviceAction,\n FreeFn,\n LocateOption,\n MidsceneYamlFlowItem,\n MidsceneYamlFlowItemAIAction,\n MidsceneYamlFlowItemAIAssert,\n MidsceneYamlFlowItemAIWaitFor,\n MidsceneYamlFlowItemEvaluateJavaScript,\n MidsceneYamlFlowItemLogScreenshot,\n MidsceneYamlFlowItemRunGherkinScenario,\n MidsceneYamlFlowItemSleep,\n MidsceneYamlScript,\n MidsceneYamlScriptEnv,\n ScriptPlayerStatusValue,\n ScriptPlayerTaskStatus,\n ScrollParam,\n} from '@/types';\nimport { getMidsceneRunSubDir } from '@midscene/shared/common';\nimport { getDebug } from '@midscene/shared/logger';\nimport { runFreeFnCleanup } from './cleanup';\nimport {\n buildDetailedLocateParam,\n buildDetailedLocateParamAndRestParams,\n} from './utils';\n\nconst debug = getDebug('yaml-player');\n\nconst aiTaskHandlerMap = {\n aiQuery: 'aiQuery',\n aiNumber: 'aiNumber',\n aiString: 'aiString',\n aiBoolean: 'aiBoolean',\n aiAsk: 'aiAsk',\n aiLocate: 'aiLocate',\n} as const;\n\ntype AISimpleTaskKey = keyof typeof aiTaskHandlerMap;\n\nconst isStringParamSchema = (schema?: ZodTypeAny): boolean => {\n if (!schema) {\n return false;\n }\n\n const schemaDef = (schema as any)?._def;\n if (!schemaDef?.typeName) {\n return false;\n }\n\n switch (schemaDef.typeName) {\n case z.ZodFirstPartyTypeKind.ZodString:\n case z.ZodFirstPartyTypeKind.ZodEnum:\n case z.ZodFirstPartyTypeKind.ZodNativeEnum:\n return true;\n case z.ZodFirstPartyTypeKind.ZodLiteral:\n return typeof schemaDef.value === 'string';\n case z.ZodFirstPartyTypeKind.ZodOptional:\n case z.ZodFirstPartyTypeKind.ZodNullable:\n case z.ZodFirstPartyTypeKind.ZodDefault:\n return isStringParamSchema(schemaDef.innerType);\n case z.ZodFirstPartyTypeKind.ZodEffects:\n return isStringParamSchema(schemaDef.schema);\n case z.ZodFirstPartyTypeKind.ZodPipeline:\n return isStringParamSchema(schemaDef.out);\n case z.ZodFirstPartyTypeKind.ZodUnion: {\n const options = schemaDef.options as ZodTypeAny[] | undefined;\n return Array.isArray(options)\n ? options.every((option) => isStringParamSchema(option))\n : false;\n }\n default:\n return false;\n }\n};\n\nconst buildShortcutActionParam = (\n actionName: string,\n interfaceAlias: string | undefined,\n value: string,\n) => {\n if (actionName === 'Launch' || interfaceAlias === 'launch') {\n return { uri: value };\n }\n\n if (actionName === 'Terminate' || interfaceAlias === 'terminate') {\n return { uri: value };\n }\n\n if (\n actionName === 'RunAdbShell' ||\n interfaceAlias === 'runAdbShell' ||\n actionName === 'RunHdcShell' ||\n interfaceAlias === 'runHdcShell'\n ) {\n return { command: value };\n }\n\n return undefined;\n};\nexport class ScriptPlayer<T extends MidsceneYamlScriptEnv> {\n public currentTaskIndex?: number;\n public taskStatusList: ScriptPlayerTaskStatus[] = [];\n public status: ScriptPlayerStatusValue = 'init';\n public reportFile?: string | null;\n public result: Record<string, any>;\n private unnamedResultIndex = 0;\n public output?: string | null;\n public unstableLogContent?: string | null;\n public errorInSetup?: Error;\n private interfaceAgent: Agent | null = null;\n public agentStatusTip?: string;\n public target?: MidsceneYamlScriptEnv;\n private actionSpace: DeviceAction[] = [];\n private scriptPath?: string;\n private failedReportExecutionInCurrentStep = false;\n constructor(\n private script: MidsceneYamlScript,\n private setupAgent: (platform: T) => Promise<{\n agent: Agent;\n freeFn: FreeFn[];\n }>,\n public onTaskStatusChange?: (taskStatus: ScriptPlayerTaskStatus) => void,\n scriptPath?: string,\n ) {\n this.scriptPath = scriptPath;\n this.result = {};\n const resolvedAiActContext =\n script.agent?.aiActContext ?? script.agent?.aiActionContext;\n\n if (resolvedAiActContext !== undefined && script.agent) {\n if (\n script.agent.aiActContext === undefined &&\n script.agent.aiActionContext !== undefined\n ) {\n console.warn(\n 'agent.aiActionContext is deprecated, please use agent.aiActContext instead. The legacy name is still accepted for backward compatibility.',\n );\n }\n\n script.agent.aiActContext = resolvedAiActContext;\n }\n\n this.target =\n script.target ||\n script.web ||\n script.android ||\n script.ios ||\n script.computer ||\n script.config;\n\n if (ifInBrowser || ifInWorker) {\n this.output = undefined;\n debug('output is undefined in browser or worker');\n } else if (this.target?.output) {\n this.output = resolve(process.cwd(), this.target.output);\n debug('setting output by config.output', this.output);\n } else {\n const scriptName = this.scriptPath\n ? basename(this.scriptPath, '.yaml').replace(/\\.(ya?ml)$/i, '')\n : 'script';\n this.output = join(\n getMidsceneRunSubDir('output'),\n `${scriptName}-${Date.now()}.json`,\n );\n debug('setting output by script path', this.output);\n }\n\n if (ifInBrowser || ifInWorker) {\n this.unstableLogContent = undefined;\n } else if (typeof this.target?.unstableLogContent === 'string') {\n this.unstableLogContent = resolve(\n process.cwd(),\n this.target.unstableLogContent,\n );\n } else if (this.target?.unstableLogContent === true) {\n this.unstableLogContent = join(\n getMidsceneRunSubDir('output'),\n 'unstableLogContent.json',\n );\n }\n\n this.taskStatusList = (script.tasks || []).map((task, taskIndex) => ({\n ...task,\n index: taskIndex,\n status: 'init',\n totalSteps: task.flow?.length || 0,\n }));\n }\n\n private setResult(key: string | undefined, value: any) {\n const keyToUse = key || this.unnamedResultIndex++;\n if (this.result[keyToUse]) {\n console.warn(`result key ${keyToUse} already exists, will overwrite`);\n }\n this.result[keyToUse] = value;\n\n return this.flushResult();\n }\n\n private setPlayerStatus(status: ScriptPlayerStatusValue, error?: Error) {\n this.status = status;\n this.errorInSetup = error;\n }\n\n private notifyCurrentTaskStatusChange(taskIndex?: number) {\n const taskIndexToNotify =\n typeof taskIndex === 'number' ? taskIndex : this.currentTaskIndex;\n\n if (typeof taskIndexToNotify !== 'number') {\n return;\n }\n\n const taskStatus = this.taskStatusList[taskIndexToNotify];\n if (this.onTaskStatusChange) {\n this.onTaskStatusChange(taskStatus);\n }\n }\n\n private async setTaskStatus(\n index: number,\n statusValue: ScriptPlayerStatusValue,\n error?: Error,\n ) {\n this.taskStatusList[index].status = statusValue;\n if (error) {\n this.taskStatusList[index].error = error;\n }\n\n this.notifyCurrentTaskStatusChange(index);\n }\n\n private setTaskIndex(taskIndex: number) {\n this.currentTaskIndex = taskIndex;\n }\n\n private flushResult() {\n if (this.output) {\n const output = resolve(process.cwd(), this.output);\n const outputDir = dirname(output);\n if (!existsSync(outputDir)) {\n mkdirSync(outputDir, { recursive: true });\n }\n writeFileSync(output, JSON.stringify(this.result || {}, undefined, 2));\n }\n }\n\n private flushUnstableLogContent() {\n if (this.unstableLogContent) {\n const content = this.interfaceAgent?._unstableLogContent();\n const filePath = resolve(process.cwd(), this.unstableLogContent);\n const outputDir = dirname(filePath);\n if (!existsSync(outputDir)) {\n mkdirSync(outputDir, { recursive: true });\n }\n writeFileSync(filePath, JSON.stringify(content, null, 2));\n }\n }\n\n async playTask(taskStatus: ScriptPlayerTaskStatus, agent: Agent) {\n const { flow } = taskStatus;\n assert(flow, 'missing flow in task');\n\n for (const flowItemIndex in flow) {\n const currentStep = Number.parseInt(flowItemIndex, 10);\n taskStatus.currentStep = currentStep;\n const flowItem = flow[flowItemIndex] as RuntimeYamlFlowItem;\n const flowItemRecord = flowItem as Record<string, unknown>;\n const executionCountBeforeStep = agent.dump?.executions?.length ?? 0;\n this.failedReportExecutionInCurrentStep = false;\n\n try {\n await this.playFlowItem(agent, flowItem, flowItemRecord, flowItemIndex);\n } catch (error) {\n this.failedReportExecutionInCurrentStep =\n this.hasFailedReportExecutionSince(agent, executionCountBeforeStep);\n throw error;\n }\n }\n this.reportFile = agent.reportFile;\n await this.flushUnstableLogContent();\n }\n\n private hasFailedReportExecutionSince(\n agent: Agent,\n executionCountBefore: number,\n ) {\n const executions = (agent.dump?.executions ?? []).slice(\n executionCountBefore,\n );\n return deriveCaseStatus(executions) === 'failed';\n }\n\n private async playFlowItem(\n agent: Agent,\n flowItem: RuntimeYamlFlowItem,\n flowItemRecord: Record<string, unknown>,\n flowItemIndex: string,\n ) {\n // Skip Finalize action from cache - it's a planning-only marker\n if ('Finalize' in flowItemRecord) {\n return;\n }\n\n debug(\n `playing step ${flowItemIndex}, flowItem=${JSON.stringify(flowItem)}`,\n );\n const simpleAIKey = (\n Object.keys(aiTaskHandlerMap) as AISimpleTaskKey[]\n ).find((key) => Object.prototype.hasOwnProperty.call(flowItemRecord, key));\n if (\n 'aiAct' in (flowItem as MidsceneYamlFlowItemAIAction) ||\n 'aiAction' in (flowItem as MidsceneYamlFlowItemAIAction) ||\n 'ai' in (flowItem as MidsceneYamlFlowItemAIAction)\n ) {\n const actionTask = flowItem as MidsceneYamlFlowItemAIAction;\n const { aiAct, aiAction, ai, instruction, ...actionOptions } =\n actionTask as any;\n const actionPrompt = aiAct ?? aiAction ?? ai;\n let promptForAI: TUserPrompt | undefined;\n\n if (typeof instruction === 'string' && instruction) {\n promptForAI = instruction;\n } else if (\n instruction &&\n typeof instruction === 'object' &&\n typeof (instruction as { prompt?: unknown }).prompt === 'string' &&\n (instruction as { prompt?: string }).prompt\n ) {\n promptForAI = instruction as TUserPrompt;\n } else if (\n actionPrompt &&\n typeof actionPrompt === 'object' &&\n typeof (actionPrompt as { prompt?: unknown }).prompt === 'string' &&\n (actionPrompt as { prompt?: string }).prompt\n ) {\n promptForAI = actionPrompt as TUserPrompt;\n } else if (typeof actionPrompt === 'string' && actionPrompt) {\n promptForAI = actionPrompt;\n }\n\n assert(promptForAI, 'missing prompt for ai (aiAct)');\n await agent.aiAct(promptForAI, actionOptions);\n } else if (\n 'runGherkinScenario' in\n (flowItem as MidsceneYamlFlowItemRunGherkinScenario)\n ) {\n const gherkinScenarioTask =\n flowItem as MidsceneYamlFlowItemRunGherkinScenario;\n const { runGherkinScenario } = gherkinScenarioTask;\n assert(runGherkinScenario, 'missing scenario for runGherkinScenario');\n await agent.runGherkinScenario(runGherkinScenario, {\n cacheable: false,\n });\n } else if ('aiAssert' in (flowItem as MidsceneYamlFlowItemAIAssert)) {\n const assertTask = flowItem as MidsceneYamlFlowItemAIAssert;\n const {\n aiAssert: prompt,\n errorMessage: msg,\n name,\n ...restOpts\n } = assertTask;\n assert(prompt, 'missing prompt for aiAssert');\n assert(\n !Object.prototype.hasOwnProperty.call(assertTask, 'observe'),\n '`observe` is not supported in YAML aiAssert. Use agent.startObserving() from code instead.',\n );\n\n const result = await agent.aiAssert(prompt, msg, {\n ...restOpts,\n keepRawResponse: true,\n });\n const pass = result?.pass;\n const thought = result?.thought;\n const message = result?.message;\n\n this.setResult(name, { pass, thought, message });\n\n if (!pass) {\n throw new Error(message);\n }\n } else if (simpleAIKey) {\n const {\n [simpleAIKey]: prompt,\n name,\n ...options\n } = flowItem as Record<string, any>;\n assert(prompt, `missing prompt for ${simpleAIKey}`);\n assert(\n !Object.prototype.hasOwnProperty.call(flowItem, 'observe'),\n '`observe` is not supported in YAML flow items. Use agent.startObserving() from code instead.',\n );\n\n const agentMethod = (agent as any)[aiTaskHandlerMap[simpleAIKey]];\n assert(\n typeof agentMethod === 'function',\n `missing agent method for ${simpleAIKey}`,\n );\n const aiResult = await agentMethod.call(agent, prompt, options);\n this.setResult(name, aiResult);\n } else if ('aiWaitFor' in (flowItem as MidsceneYamlFlowItemAIWaitFor)) {\n const waitForTask = flowItem as MidsceneYamlFlowItemAIWaitFor;\n const { aiWaitFor, timeout, ...restWaitForOpts } = waitForTask;\n const prompt = aiWaitFor;\n assert(prompt, 'missing prompt for aiWaitFor');\n const waitForOptions = {\n ...restWaitForOpts,\n ...(timeout !== undefined ? { timeout, timeoutMs: timeout } : {}),\n };\n await agent.aiWaitFor(prompt, waitForOptions);\n } else if ('sleep' in flowItem) {\n const sleepTask = flowItem as unknown as MidsceneYamlFlowItemSleep;\n const ms = sleepTask.sleep;\n let msNumber = ms;\n if (typeof ms === 'string') {\n msNumber = Number.parseInt(ms, 10);\n }\n assert(\n msNumber && msNumber > 0,\n `ms for sleep must be greater than 0, but got ${ms}`,\n );\n await new Promise((resolve) => setTimeout(resolve, msNumber));\n } else if ('javascript' in flowItem) {\n const evaluateJavaScriptTask =\n flowItem as unknown as MidsceneYamlFlowItemEvaluateJavaScript;\n\n const result = await agent.evaluateJavaScript(\n evaluateJavaScriptTask.javascript,\n );\n this.setResult(evaluateJavaScriptTask.name, result);\n } else if (\n 'logScreenshot' in (flowItem as MidsceneYamlFlowItemLogScreenshot) ||\n 'recordToReport' in (flowItem as MidsceneYamlFlowItemLogScreenshot)\n ) {\n const recordTask = flowItem as MidsceneYamlFlowItemLogScreenshot;\n const title =\n recordTask.recordToReport ?? recordTask.logScreenshot ?? 'untitled';\n const content = recordTask.content || '';\n await agent.recordToReport(title, { content });\n } else if ('aiInput' in flowItem) {\n // may be input empty string ''\n const {\n aiInput,\n value: rawValue,\n ...inputTask\n } = flowItem as unknown as MidsceneYamlFlowItemAIInput;\n\n // Compatibility with previous version:\n // Old format: { aiInput: string (value), locate: TUserPrompt }\n // New format - 1: { aiInput: TUserPrompt, value: string | number }\n // New format - 2: { aiInput: undefined, locate: TUserPrompt, value: string | number }\n let locatePrompt: TUserPrompt | undefined;\n let value: string | number | undefined;\n if ((inputTask as any).locate) {\n // Old format - aiInput is the value, locate is the prompt\n // Keep backward compatibility: empty string is treated as no value\n value = (aiInput as string | number) || rawValue;\n locatePrompt = (inputTask as any).locate;\n } else {\n // New format - aiInput is the prompt, value is the value\n locatePrompt = aiInput || '';\n value = rawValue;\n }\n\n // Convert value to string for Input action\n await agent.callActionInActionSpace('Input', {\n ...inputTask,\n ...(value !== undefined ? { value: String(value) } : {}),\n ...(locatePrompt\n ? { locate: buildDetailedLocateParam(locatePrompt, inputTask) }\n : {}),\n });\n } else if ('aiKeyboardPress' in flowItem) {\n const { aiKeyboardPress, ...keyboardPressTask } =\n flowItem as unknown as MidsceneYamlFlowItemAIKeyboardPress;\n\n // Compatibility with previous version:\n // Old format: { aiKeyboardPress: string (key), locate?: TUserPrompt }\n // New format - 1: { aiKeyboardPress: TUserPrompt, keyName: string }\n // New format - 2: { aiKeyboardPress: , locate?: TUserPrompt, keyName: string }\n let locatePrompt: TUserPrompt | undefined;\n let keyName: string | undefined;\n if ((keyboardPressTask as any).locate) {\n // Old format - aiKeyboardPress is the key, locate is the prompt\n keyName = aiKeyboardPress as string;\n locatePrompt = (keyboardPressTask as any).locate;\n } else if (keyboardPressTask.keyName) {\n // New format - aiKeyboardPress is the prompt, key is the key\n keyName = keyboardPressTask.keyName;\n locatePrompt = aiKeyboardPress;\n } else {\n keyName = aiKeyboardPress as string;\n }\n\n await agent.callActionInActionSpace('KeyboardPress', {\n ...keyboardPressTask,\n ...(keyName ? { keyName } : {}),\n ...(locatePrompt\n ? {\n locate: buildDetailedLocateParam(locatePrompt, keyboardPressTask),\n }\n : {}),\n });\n } else if ('aiScroll' in flowItem) {\n const { aiScroll, ...scrollTask } =\n flowItem as unknown as MidsceneYamlFlowItemAIScroll;\n\n // Compatibility with previous version:\n // Old format: { aiScroll: null, locate?: TUserPrompt, direction, scrollType, distance? }\n // New format - 1: { aiScroll: TUserPrompt, direction, scrollType, distance? }\n // New format - 2: { aiScroll: undefined, locate: TUserPrompt, direction, scrollType, distance? }\n const { locate, ...scrollOptions } = scrollTask as any;\n const locatePrompt: TUserPrompt | undefined =\n locate ?? aiScroll ?? undefined;\n\n await agent.aiScroll(locatePrompt, scrollOptions);\n } else if ('aiTap' in flowItem) {\n const { aiTap, prompt, locate, ...tapOptions } = flowItem as any;\n\n let locatePrompt: TUserPrompt;\n let opts = tapOptions;\n // Support both formats:\n // 1. { aiTap: null, locate: { prompt, images, ... } } (locate as sibling key)\n // 2. { aiTap: { locate: { prompt, images, ... } } } (locate nested in aiTap)\n const locateObj =\n locate ??\n (typeof aiTap === 'object' && aiTap !== null\n ? aiTap.locate\n : undefined);\n\n if (typeof aiTap === 'string' && aiTap) {\n // User YAML: aiTap: 'search input box'\n locatePrompt = aiTap;\n } else if (typeof locateObj === 'object' && locateObj?.prompt) {\n // buildYamlFlowFromPlans: { aiTap: '', locate: { prompt, deepLocate, cacheable } }\n const { prompt: lp, ...locateOpts } = locateObj;\n locatePrompt = lp;\n opts = { ...locateOpts, ...tapOptions };\n } else {\n // User YAML: aiTap: { prompt: '...' } or aiTap: null + prompt: '...'\n locatePrompt = aiTap?.prompt || prompt || locateObj;\n }\n\n assert(locatePrompt, 'missing prompt for aiTap');\n await agent.aiTap(locatePrompt, opts);\n } else {\n // generic action, find the action in actionSpace\n\n /* for aiRightClick, the parameters are a flattened data for the 'locate', these are all valid data\n\n - aiRightClick: 'search input box'\n - aiRightClick: 'search input box'\n deepLocate: true\n cacheable: false\n - aiRightClick:\n prompt: 'search input box'\n - aiRightClick:\n prompt: 'search input box'\n deepLocate: true\n cacheable: false\n */\n\n const actionSpace = this.actionSpace;\n let locatePromptShortcut: string | undefined;\n let actionParamForMatchedAction: unknown;\n const matchedAction = actionSpace.find((action) => {\n const actionInterfaceAlias = action.interfaceAlias;\n if (\n actionInterfaceAlias &&\n Object.prototype.hasOwnProperty.call(flowItem, actionInterfaceAlias)\n ) {\n actionParamForMatchedAction =\n flowItem[actionInterfaceAlias as keyof typeof flowItem];\n if (typeof actionParamForMatchedAction === 'string') {\n locatePromptShortcut = actionParamForMatchedAction;\n }\n return true;\n }\n\n const keyOfActionInActionSpace = action.name;\n if (\n Object.prototype.hasOwnProperty.call(\n flowItem,\n keyOfActionInActionSpace,\n )\n ) {\n actionParamForMatchedAction =\n flowItem[keyOfActionInActionSpace as keyof typeof flowItem];\n if (typeof actionParamForMatchedAction === 'string') {\n locatePromptShortcut = actionParamForMatchedAction;\n }\n return true;\n }\n\n return false;\n });\n\n assert(\n matchedAction,\n `unknown flowItem in yaml: ${JSON.stringify(flowItem)}`,\n );\n\n const schemaIsStringParam = isStringParamSchema(\n matchedAction.paramSchema,\n );\n let stringParamToCall: string | undefined;\n const resultName = (flowItem as any).name;\n const timeout = (flowItem as any).timeout;\n const hasRunAdbShellAlias = Object.prototype.hasOwnProperty.call(\n flowItem,\n 'runAdbShell',\n );\n\n if (\n hasRunAdbShellAlias &&\n typeof actionParamForMatchedAction === 'string' &&\n typeof timeout === 'number' &&\n typeof (agent as any).runAdbShell === 'function'\n ) {\n const result = await (agent as any).runAdbShell(\n actionParamForMatchedAction,\n { timeout },\n );\n if (result !== undefined) {\n this.setResult(resultName, result);\n }\n return;\n }\n\n const specialActionParamToCall =\n typeof actionParamForMatchedAction === 'string'\n ? buildShortcutActionParam(\n matchedAction.name,\n matchedAction.interfaceAlias,\n actionParamForMatchedAction,\n )\n : undefined;\n if (specialActionParamToCall) {\n debug(\n `matchedAction: ${matchedAction.name}`,\n `flowParams: ${JSON.stringify(specialActionParamToCall)}`,\n );\n const result = await agent.callActionInActionSpace(\n matchedAction.name,\n specialActionParamToCall,\n );\n\n if (result !== undefined) {\n this.setResult(resultName, result);\n }\n } else if (\n typeof actionParamForMatchedAction === 'string' &&\n schemaIsStringParam\n ) {\n if (matchedAction.paramSchema) {\n const parseResult = matchedAction.paramSchema.safeParse(\n actionParamForMatchedAction,\n );\n if (parseResult.success && typeof parseResult.data === 'string') {\n stringParamToCall = parseResult.data;\n } else if (!parseResult.success) {\n debug(\n `parse failed for action ${matchedAction.name} with string param`,\n parseResult.error,\n );\n stringParamToCall = actionParamForMatchedAction;\n }\n } else {\n stringParamToCall = actionParamForMatchedAction;\n }\n\n if (stringParamToCall !== undefined) {\n debug(\n `matchedAction: ${matchedAction.name}`,\n `flowParams: ${JSON.stringify(stringParamToCall)}`,\n );\n const result = await agent.callActionInActionSpace(\n matchedAction.name,\n stringParamToCall,\n );\n\n // Store result if there's a name property in flowItem\n const resultName = (flowItem as any).name;\n if (result !== undefined) {\n this.setResult(resultName, result);\n }\n }\n } else {\n // Determine the source for parameter extraction:\n // - If we have a locatePromptShortcut, use the flowItem (for actions like aiTap with prompt)\n // - Otherwise, use actionParamForMatchedAction (for actions like runWdaRequest with structured params)\n const sourceForParams =\n locatePromptShortcut &&\n typeof actionParamForMatchedAction === 'string'\n ? { ...flowItem, prompt: locatePromptShortcut }\n : typeof actionParamForMatchedAction === 'object' &&\n actionParamForMatchedAction !== null\n ? actionParamForMatchedAction\n : flowItem;\n\n const { locateParam, restParams } =\n buildDetailedLocateParamAndRestParams(\n locatePromptShortcut || '',\n sourceForParams as LocateOption,\n [\n matchedAction.name,\n matchedAction.interfaceAlias || '_never_mind_',\n ],\n );\n\n const flowParams = {\n ...restParams,\n locate: locateParam,\n };\n\n debug(\n `matchedAction: ${matchedAction.name}`,\n `flowParams: ${JSON.stringify(flowParams, null, 2)}`,\n );\n const result = await agent.callActionInActionSpace(\n matchedAction.name,\n flowParams,\n );\n\n // Store result if there's a name property in flowItem\n const resultName = (flowItem as any).name;\n if (result !== undefined) {\n this.setResult(resultName, result);\n }\n }\n }\n }\n\n async run() {\n const { target, web, android, ios, harmony, computer, tasks } = this.script;\n const webEnv = web || target;\n const androidEnv = android;\n const iosEnv = ios;\n const harmonyEnv = harmony;\n const computerEnv = computer;\n const platform =\n webEnv || androidEnv || iosEnv || harmonyEnv || computerEnv;\n\n this.setPlayerStatus('running');\n\n let agent: Agent | null = null;\n let freeFn: FreeFn[] = [];\n try {\n const { agent: newAgent, freeFn: newFreeFn } = await this.setupAgent(\n platform as T,\n );\n this.actionSpace = await newAgent.getActionSpace();\n agent = newAgent;\n const originalOnTaskStartTip = agent.onTaskStartTip;\n agent.onTaskStartTip = (tip) => {\n if (this.status === 'running') {\n this.agentStatusTip = tip;\n }\n originalOnTaskStartTip?.(tip);\n };\n freeFn = [\n ...(newFreeFn || []),\n {\n name: 'restore-agent-onTaskStartTip',\n fn: () => {\n if (agent) {\n agent.onTaskStartTip = originalOnTaskStartTip;\n }\n },\n },\n ];\n } catch (e) {\n this.setPlayerStatus('error', e as Error);\n return;\n }\n this.interfaceAgent = agent;\n\n let taskIndex = 0;\n this.setPlayerStatus('running');\n let errorFlag = false;\n while (taskIndex < tasks.length) {\n const taskStatus = this.taskStatusList[taskIndex];\n this.setTaskStatus(taskIndex, 'running' as any);\n this.setTaskIndex(taskIndex);\n this.failedReportExecutionInCurrentStep = false;\n\n try {\n await this.playTask(taskStatus, this.interfaceAgent);\n this.setTaskStatus(taskIndex, 'done' as any);\n } catch (e) {\n this.setTaskStatus(taskIndex, 'error' as any, e as Error);\n const recordErrorToReport = (agent as any).recordErrorToReport;\n if (\n !this.failedReportExecutionInCurrentStep &&\n typeof recordErrorToReport === 'function'\n ) {\n try {\n await recordErrorToReport.call(\n agent,\n `YAML task failed - ${taskStatus.name}`,\n {\n error: e as Error,\n content: `Step ${taskStatus.currentStep ?? 0} failed while running YAML task \"${taskStatus.name}\".`,\n },\n );\n } catch (reportError) {\n debug('failed to record yaml error to report', reportError);\n }\n }\n\n if (taskStatus.continueOnError) {\n // nothing more to do\n } else {\n this.reportFile = agent.reportFile;\n errorFlag = true;\n break;\n }\n }\n this.reportFile = agent?.reportFile;\n taskIndex++;\n }\n\n if (errorFlag) {\n this.setPlayerStatus('error');\n } else {\n this.setPlayerStatus('done');\n }\n this.agentStatusTip = '';\n\n await runFreeFnCleanup(freeFn);\n }\n}\n"],"names":["debug","getDebug","aiTaskHandlerMap","isStringParamSchema","schema","schemaDef","z","options","Array","option","buildShortcutActionParam","actionName","interfaceAlias","value","ScriptPlayer","key","keyToUse","console","status","error","taskIndex","taskIndexToNotify","taskStatus","index","statusValue","output","resolve","process","outputDir","dirname","existsSync","mkdirSync","writeFileSync","JSON","undefined","content","filePath","agent","flow","assert","flowItemIndex","currentStep","Number","flowItem","flowItemRecord","executionCountBeforeStep","executionCountBefore","executions","deriveCaseStatus","simpleAIKey","Object","actionTask","aiAct","aiAction","ai","instruction","actionOptions","actionPrompt","promptForAI","gherkinScenarioTask","runGherkinScenario","assertTask","prompt","msg","name","restOpts","result","pass","thought","message","Error","agentMethod","aiResult","waitForTask","aiWaitFor","timeout","restWaitForOpts","waitForOptions","sleepTask","ms","msNumber","Promise","setTimeout","evaluateJavaScriptTask","recordTask","title","aiInput","rawValue","inputTask","locatePrompt","String","buildDetailedLocateParam","aiKeyboardPress","keyboardPressTask","keyName","aiScroll","scrollTask","locate","scrollOptions","aiTap","tapOptions","opts","locateObj","lp","locateOpts","actionSpace","locatePromptShortcut","actionParamForMatchedAction","matchedAction","action","actionInterfaceAlias","keyOfActionInActionSpace","schemaIsStringParam","stringParamToCall","resultName","hasRunAdbShellAlias","specialActionParamToCall","parseResult","sourceForParams","locateParam","restParams","buildDetailedLocateParamAndRestParams","flowParams","target","web","android","ios","harmony","computer","tasks","webEnv","androidEnv","iosEnv","harmonyEnv","computerEnv","platform","freeFn","newAgent","newFreeFn","originalOnTaskStartTip","tip","e","errorFlag","recordErrorToReport","reportError","runFreeFnCleanup","script","setupAgent","onTaskStatusChange","scriptPath","resolvedAiActContext","ifInBrowser","ifInWorker","scriptName","basename","join","getMidsceneRunSubDir","Date","task"],"mappings":";;;;;;;;;;;;;;;;;;;AAqEA,MAAMA,QAAQC,SAAS;AAEvB,MAAMC,mBAAmB;IACvB,SAAS;IACT,UAAU;IACV,UAAU;IACV,WAAW;IACX,OAAO;IACP,UAAU;AACZ;AAIA,MAAMC,sBAAsB,CAACC;IAC3B,IAAI,CAACA,QACH,OAAO;IAGT,MAAMC,YAAaD,QAAgB;IACnC,IAAI,CAAC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MAAM,EAAE,QAAQ;YAC9B,IAAI,CAAC,MAAM,GAAG0B,2BAAQC,QAAQ,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM;YACvD3B,MAAM,mCAAmC,IAAI,CAAC,MAAM;QACtD,OAAO;YACL,MAAMyJ,aAAa,IAAI,CAAC,UAAU,GAC9BC,SAAS,IAAI,CAAC,UAAU,EAAE,SAAS,OAAO,CAAC,eAAe,MAC1D;YACJ,IAAI,CAAC,MAAM,GAAGC,KACZC,qBAAqB,WACrB,GAAGH,WAAW,CAAC,EAAEI,KAAK,GAAG,GAAG,KAAK,CAAC;YAEpC7J,MAAM,iCAAiC,IAAI,CAAC,MAAM;QACpD;QAEA,IAAIuJ,eAAeC,YACjB,IAAI,CAAC,kBAAkB,GAAGtH;aACrB,IAAI,AAA2C,YAA3C,OAAO,IAAI,CAAC,MAAM,EAAE,oBAC7B,IAAI,CAAC,kBAAkB,GAAGR,2BACxBC,QAAQ,GAAG,IACX,IAAI,CAAC,MAAM,CAAC,kBAAkB;aAE3B,IAAI,IAAI,CAAC,MAAM,EAAE,uBAAuB,MAC7C,IAAI,CAAC,kBAAkB,GAAGgI,KACxBC,qBAAqB,WACrB;QAIJ,IAAI,CAAC,cAAc,GAAIV,AAAAA,CAAAA,OAAO,KAAK,IAAI,EAAC,EAAG,GAAG,CAAC,CAACY,MAAM1I,YAAe;gBACnE,GAAG0I,IAAI;gBACP,OAAO1I;gBACP,QAAQ;gBACR,YAAY0I,KAAK,IAAI,EAAE,UAAU;YACnC;IACF;AAmoBF"}
|
|
1
|
+
{"version":3,"file":"yaml/player.mjs","sources":["../../../src/yaml/player.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { basename, dirname, join, resolve } from 'node:path';\nimport { assert, ifInBrowser, ifInWorker } from '@midscene/shared/utils';\nimport { type ZodTypeAny, z } from 'zod';\n\n// previous defined yaml flow, as a helper\ninterface MidsceneYamlFlowItemAIInput extends LocateOption {\n // previous version\n // aiInput: string; // value to input\n // locate: TUserPrompt; // where to input\n aiInput: TUserPrompt | undefined; // where to input\n value: string | number; // value to input\n mode?: 'replace' | 'clear' | 'typeOnly';\n autoDismissKeyboard?: boolean;\n keyboardTypeDelay?: number;\n inputStrategy?: InputStrategy;\n}\n\ninterface MidsceneYamlFlowItemAIKeyboardPress extends LocateOption {\n // previous version\n // aiKeyboardPress: string;\n // locate?: TUserPrompt; // where to press, optional\n aiKeyboardPress: TUserPrompt | undefined; // where to press\n keyName: string; // key to press\n}\n\ninterface MidsceneYamlFlowItemAIScroll extends LocateOption, ScrollParam {\n // previous version\n // aiScroll: null;\n // locate?: TUserPrompt; // which area to scroll, optional\n aiScroll: TUserPrompt | undefined; // which area to scroll\n}\n\ntype RuntimeYamlFlowItem =\n | MidsceneYamlFlowItem\n | MidsceneYamlFlowItemAIInput\n | MidsceneYamlFlowItemAIKeyboardPress\n | MidsceneYamlFlowItemAIScroll;\n\nimport type { Agent } from '@/agent/agent';\nimport type { TUserPrompt } from '@/common';\nimport type { InputStrategy } from '@/device';\nimport { deriveCaseStatus } from '@/dump/task-status';\nimport type {\n DeviceAction,\n FreeFn,\n LocateOption,\n MidsceneYamlFlowItem,\n MidsceneYamlFlowItemAIAction,\n MidsceneYamlFlowItemAIAssert,\n MidsceneYamlFlowItemAIWaitFor,\n MidsceneYamlFlowItemEvaluateJavaScript,\n MidsceneYamlFlowItemLogScreenshot,\n MidsceneYamlFlowItemRunGherkinScenario,\n MidsceneYamlFlowItemSleep,\n MidsceneYamlScript,\n MidsceneYamlScriptEnv,\n ScriptPlayerStatusValue,\n ScriptPlayerTaskStatus,\n ScrollParam,\n} from '@/types';\nimport { getMidsceneRunSubDir } from '@midscene/shared/common';\nimport { getDebug } from '@midscene/shared/logger';\nimport { runFreeFnCleanup } from './cleanup';\nimport {\n buildDetailedLocateParam,\n buildDetailedLocateParamAndRestParams,\n} from './utils';\n\nconst debug = getDebug('yaml-player');\n\nconst aiTaskHandlerMap = {\n aiQuery: 'aiQuery',\n aiNumber: 'aiNumber',\n aiString: 'aiString',\n aiBoolean: 'aiBoolean',\n aiAsk: 'aiAsk',\n aiLocate: 'aiLocate',\n} as const;\n\ntype AISimpleTaskKey = keyof typeof aiTaskHandlerMap;\n\nconst isStringParamSchema = (schema?: ZodTypeAny): boolean => {\n if (!schema) {\n return false;\n }\n\n const schemaDef = (schema as any)?._def;\n if (!schemaDef?.typeName) {\n return false;\n }\n\n switch (schemaDef.typeName) {\n case z.ZodFirstPartyTypeKind.ZodString:\n case z.ZodFirstPartyTypeKind.ZodEnum:\n case z.ZodFirstPartyTypeKind.ZodNativeEnum:\n return true;\n case z.ZodFirstPartyTypeKind.ZodLiteral:\n return typeof schemaDef.value === 'string';\n case z.ZodFirstPartyTypeKind.ZodOptional:\n case z.ZodFirstPartyTypeKind.ZodNullable:\n case z.ZodFirstPartyTypeKind.ZodDefault:\n return isStringParamSchema(schemaDef.innerType);\n case z.ZodFirstPartyTypeKind.ZodEffects:\n return isStringParamSchema(schemaDef.schema);\n case z.ZodFirstPartyTypeKind.ZodPipeline:\n return isStringParamSchema(schemaDef.out);\n case z.ZodFirstPartyTypeKind.ZodUnion: {\n const options = schemaDef.options as ZodTypeAny[] | undefined;\n return Array.isArray(options)\n ? options.every((option) => isStringParamSchema(option))\n : false;\n }\n default:\n return false;\n }\n};\n\nconst buildShortcutActionParam = (\n actionName: string,\n interfaceAlias: string | undefined,\n value: string,\n) => {\n if (actionName === 'Launch' || interfaceAlias === 'launch') {\n return { uri: value };\n }\n\n if (actionName === 'Terminate' || interfaceAlias === 'terminate') {\n return { uri: value };\n }\n\n if (\n actionName === 'RunAdbShell' ||\n interfaceAlias === 'runAdbShell' ||\n actionName === 'RunHdcShell' ||\n interfaceAlias === 'runHdcShell'\n ) {\n return { command: value };\n }\n\n return undefined;\n};\nexport class ScriptPlayer<T extends MidsceneYamlScriptEnv> {\n public currentTaskIndex?: number;\n public taskStatusList: ScriptPlayerTaskStatus[] = [];\n public status: ScriptPlayerStatusValue = 'init';\n public reportFile?: string | null;\n public result: Record<string, any>;\n private unnamedResultIndex = 0;\n public output?: string | null;\n public unstableLogContent?: string | null;\n public errorInSetup?: Error;\n private interfaceAgent: Agent | null = null;\n public agentStatusTip?: string;\n public target?: MidsceneYamlScriptEnv;\n private actionSpace: DeviceAction[] = [];\n private scriptPath?: string;\n private failedReportExecutionInCurrentStep = false;\n constructor(\n private script: MidsceneYamlScript,\n private setupAgent: (platform: T) => Promise<{\n agent: Agent;\n freeFn: FreeFn[];\n }>,\n public onTaskStatusChange?: (taskStatus: ScriptPlayerTaskStatus) => void,\n scriptPath?: string,\n ) {\n this.scriptPath = scriptPath;\n this.result = {};\n\n this.target =\n script.target ||\n script.web ||\n script.android ||\n script.ios ||\n script.computer ||\n script.config;\n\n if (ifInBrowser || ifInWorker) {\n this.output = undefined;\n debug('output is undefined in browser or worker');\n } else if (this.target?.output) {\n this.output = resolve(process.cwd(), this.target.output);\n debug('setting output by config.output', this.output);\n } else {\n const scriptName = this.scriptPath\n ? basename(this.scriptPath, '.yaml').replace(/\\.(ya?ml)$/i, '')\n : 'script';\n this.output = join(\n getMidsceneRunSubDir('output'),\n `${scriptName}-${Date.now()}.json`,\n );\n debug('setting output by script path', this.output);\n }\n\n if (ifInBrowser || ifInWorker) {\n this.unstableLogContent = undefined;\n } else if (typeof this.target?.unstableLogContent === 'string') {\n this.unstableLogContent = resolve(\n process.cwd(),\n this.target.unstableLogContent,\n );\n } else if (this.target?.unstableLogContent === true) {\n this.unstableLogContent = join(\n getMidsceneRunSubDir('output'),\n 'unstableLogContent.json',\n );\n }\n\n this.taskStatusList = (script.tasks || []).map((task, taskIndex) => ({\n ...task,\n index: taskIndex,\n status: 'init',\n totalSteps: task.flow?.length || 0,\n }));\n }\n\n private setResult(key: string | undefined, value: any) {\n const keyToUse = key || this.unnamedResultIndex++;\n if (this.result[keyToUse]) {\n console.warn(`result key ${keyToUse} already exists, will overwrite`);\n }\n this.result[keyToUse] = value;\n\n return this.flushResult();\n }\n\n private setPlayerStatus(status: ScriptPlayerStatusValue, error?: Error) {\n this.status = status;\n this.errorInSetup = error;\n }\n\n private notifyCurrentTaskStatusChange(taskIndex?: number) {\n const taskIndexToNotify =\n typeof taskIndex === 'number' ? taskIndex : this.currentTaskIndex;\n\n if (typeof taskIndexToNotify !== 'number') {\n return;\n }\n\n const taskStatus = this.taskStatusList[taskIndexToNotify];\n if (this.onTaskStatusChange) {\n this.onTaskStatusChange(taskStatus);\n }\n }\n\n private async setTaskStatus(\n index: number,\n statusValue: ScriptPlayerStatusValue,\n error?: Error,\n ) {\n this.taskStatusList[index].status = statusValue;\n if (error) {\n this.taskStatusList[index].error = error;\n }\n\n this.notifyCurrentTaskStatusChange(index);\n }\n\n private setTaskIndex(taskIndex: number) {\n this.currentTaskIndex = taskIndex;\n }\n\n private flushResult() {\n if (this.output) {\n const output = resolve(process.cwd(), this.output);\n const outputDir = dirname(output);\n if (!existsSync(outputDir)) {\n mkdirSync(outputDir, { recursive: true });\n }\n writeFileSync(output, JSON.stringify(this.result || {}, undefined, 2));\n }\n }\n\n private flushUnstableLogContent() {\n if (this.unstableLogContent) {\n const content = this.interfaceAgent?._unstableLogContent();\n const filePath = resolve(process.cwd(), this.unstableLogContent);\n const outputDir = dirname(filePath);\n if (!existsSync(outputDir)) {\n mkdirSync(outputDir, { recursive: true });\n }\n writeFileSync(filePath, JSON.stringify(content, null, 2));\n }\n }\n\n async playTask(taskStatus: ScriptPlayerTaskStatus, agent: Agent) {\n const { flow } = taskStatus;\n assert(flow, 'missing flow in task');\n\n for (const flowItemIndex in flow) {\n const currentStep = Number.parseInt(flowItemIndex, 10);\n taskStatus.currentStep = currentStep;\n const flowItem = flow[flowItemIndex] as RuntimeYamlFlowItem;\n const flowItemRecord = flowItem as Record<string, unknown>;\n const executionCountBeforeStep = agent.dump?.executions?.length ?? 0;\n this.failedReportExecutionInCurrentStep = false;\n\n try {\n await this.playFlowItem(agent, flowItem, flowItemRecord, flowItemIndex);\n } catch (error) {\n this.failedReportExecutionInCurrentStep =\n this.hasFailedReportExecutionSince(agent, executionCountBeforeStep);\n throw error;\n }\n }\n this.reportFile = agent.reportFile;\n await this.flushUnstableLogContent();\n }\n\n private hasFailedReportExecutionSince(\n agent: Agent,\n executionCountBefore: number,\n ) {\n const executions = (agent.dump?.executions ?? []).slice(\n executionCountBefore,\n );\n return deriveCaseStatus(executions) === 'failed';\n }\n\n private async playFlowItem(\n agent: Agent,\n flowItem: RuntimeYamlFlowItem,\n flowItemRecord: Record<string, unknown>,\n flowItemIndex: string,\n ) {\n // Skip Finalize action from cache - it's a planning-only marker\n if ('Finalize' in flowItemRecord) {\n return;\n }\n\n debug(\n `playing step ${flowItemIndex}, flowItem=${JSON.stringify(flowItem)}`,\n );\n const simpleAIKey = (\n Object.keys(aiTaskHandlerMap) as AISimpleTaskKey[]\n ).find((key) => Object.prototype.hasOwnProperty.call(flowItemRecord, key));\n if (\n 'aiAct' in (flowItem as MidsceneYamlFlowItemAIAction) ||\n 'aiAction' in (flowItem as MidsceneYamlFlowItemAIAction) ||\n 'ai' in (flowItem as MidsceneYamlFlowItemAIAction)\n ) {\n const actionTask = flowItem as MidsceneYamlFlowItemAIAction;\n const { aiAct, aiAction, ai, instruction, ...actionOptions } =\n actionTask as any;\n const actionPrompt = aiAct ?? aiAction ?? ai;\n let promptForAI: TUserPrompt | undefined;\n\n if (typeof instruction === 'string' && instruction) {\n promptForAI = instruction;\n } else if (\n instruction &&\n typeof instruction === 'object' &&\n typeof (instruction as { prompt?: unknown }).prompt === 'string' &&\n (instruction as { prompt?: string }).prompt\n ) {\n promptForAI = instruction as TUserPrompt;\n } else if (\n actionPrompt &&\n typeof actionPrompt === 'object' &&\n typeof (actionPrompt as { prompt?: unknown }).prompt === 'string' &&\n (actionPrompt as { prompt?: string }).prompt\n ) {\n promptForAI = actionPrompt as TUserPrompt;\n } else if (typeof actionPrompt === 'string' && actionPrompt) {\n promptForAI = actionPrompt;\n }\n\n assert(promptForAI, 'missing prompt for ai (aiAct)');\n await agent.aiAct(promptForAI, actionOptions);\n } else if (\n 'runGherkinScenario' in\n (flowItem as MidsceneYamlFlowItemRunGherkinScenario)\n ) {\n const gherkinScenarioTask =\n flowItem as MidsceneYamlFlowItemRunGherkinScenario;\n const { runGherkinScenario } = gherkinScenarioTask;\n assert(runGherkinScenario, 'missing scenario for runGherkinScenario');\n await agent.runGherkinScenario(runGherkinScenario, {\n cacheable: false,\n });\n } else if ('aiAssert' in (flowItem as MidsceneYamlFlowItemAIAssert)) {\n const assertTask = flowItem as MidsceneYamlFlowItemAIAssert;\n const {\n aiAssert: prompt,\n errorMessage: msg,\n name,\n ...restOpts\n } = assertTask;\n assert(prompt, 'missing prompt for aiAssert');\n assert(\n !Object.prototype.hasOwnProperty.call(assertTask, 'observe'),\n '`observe` is not supported in YAML aiAssert. Use agent.startObserving() from code instead.',\n );\n\n const result = await agent.aiAssert(prompt, msg, {\n ...restOpts,\n keepRawResponse: true,\n });\n const pass = result?.pass;\n const thought = result?.thought;\n const message = result?.message;\n\n this.setResult(name, { pass, thought, message });\n\n if (!pass) {\n throw new Error(message);\n }\n } else if (simpleAIKey) {\n const {\n [simpleAIKey]: prompt,\n name,\n ...options\n } = flowItem as Record<string, any>;\n assert(prompt, `missing prompt for ${simpleAIKey}`);\n assert(\n !Object.prototype.hasOwnProperty.call(flowItem, 'observe'),\n '`observe` is not supported in YAML flow items. Use agent.startObserving() from code instead.',\n );\n\n const agentMethod = (agent as any)[aiTaskHandlerMap[simpleAIKey]];\n assert(\n typeof agentMethod === 'function',\n `missing agent method for ${simpleAIKey}`,\n );\n const aiResult = await agentMethod.call(agent, prompt, options);\n this.setResult(name, aiResult);\n } else if ('aiWaitFor' in (flowItem as MidsceneYamlFlowItemAIWaitFor)) {\n const waitForTask = flowItem as MidsceneYamlFlowItemAIWaitFor;\n const { aiWaitFor, timeout, ...restWaitForOpts } = waitForTask;\n const prompt = aiWaitFor;\n assert(prompt, 'missing prompt for aiWaitFor');\n const waitForOptions = {\n ...restWaitForOpts,\n ...(timeout !== undefined ? { timeout, timeoutMs: timeout } : {}),\n };\n await agent.aiWaitFor(prompt, waitForOptions);\n } else if ('sleep' in flowItem) {\n const sleepTask = flowItem as unknown as MidsceneYamlFlowItemSleep;\n const ms = sleepTask.sleep;\n let msNumber = ms;\n if (typeof ms === 'string') {\n msNumber = Number.parseInt(ms, 10);\n }\n assert(\n msNumber && msNumber > 0,\n `ms for sleep must be greater than 0, but got ${ms}`,\n );\n await new Promise((resolve) => setTimeout(resolve, msNumber));\n } else if ('javascript' in flowItem) {\n const evaluateJavaScriptTask =\n flowItem as unknown as MidsceneYamlFlowItemEvaluateJavaScript;\n\n const result = await agent.evaluateJavaScript(\n evaluateJavaScriptTask.javascript,\n );\n this.setResult(evaluateJavaScriptTask.name, result);\n } else if (\n 'logScreenshot' in (flowItem as MidsceneYamlFlowItemLogScreenshot) ||\n 'recordToReport' in (flowItem as MidsceneYamlFlowItemLogScreenshot)\n ) {\n const recordTask = flowItem as MidsceneYamlFlowItemLogScreenshot;\n const title =\n recordTask.recordToReport ?? recordTask.logScreenshot ?? 'untitled';\n const content = recordTask.content || '';\n await agent.recordToReport(title, { content });\n } else if ('aiInput' in flowItem) {\n // may be input empty string ''\n const {\n aiInput,\n value: rawValue,\n ...inputTask\n } = flowItem as unknown as MidsceneYamlFlowItemAIInput;\n\n // Compatibility with previous version:\n // Old format: { aiInput: string (value), locate: TUserPrompt }\n // New format - 1: { aiInput: TUserPrompt, value: string | number }\n // New format - 2: { aiInput: undefined, locate: TUserPrompt, value: string | number }\n let locatePrompt: TUserPrompt | undefined;\n let value: string | number | undefined;\n if ((inputTask as any).locate) {\n // Old format - aiInput is the value, locate is the prompt\n // Keep backward compatibility: empty string is treated as no value\n value = (aiInput as string | number) || rawValue;\n locatePrompt = (inputTask as any).locate;\n } else {\n // New format - aiInput is the prompt, value is the value\n locatePrompt = aiInput || '';\n value = rawValue;\n }\n\n // Convert value to string for Input action\n await agent.callActionInActionSpace('Input', {\n ...inputTask,\n ...(value !== undefined ? { value: String(value) } : {}),\n ...(locatePrompt\n ? { locate: buildDetailedLocateParam(locatePrompt, inputTask) }\n : {}),\n });\n } else if ('aiKeyboardPress' in flowItem) {\n const { aiKeyboardPress, ...keyboardPressTask } =\n flowItem as unknown as MidsceneYamlFlowItemAIKeyboardPress;\n\n // Compatibility with previous version:\n // Old format: { aiKeyboardPress: string (key), locate?: TUserPrompt }\n // New format - 1: { aiKeyboardPress: TUserPrompt, keyName: string }\n // New format - 2: { aiKeyboardPress: , locate?: TUserPrompt, keyName: string }\n let locatePrompt: TUserPrompt | undefined;\n let keyName: string | undefined;\n if ((keyboardPressTask as any).locate) {\n // Old format - aiKeyboardPress is the key, locate is the prompt\n keyName = aiKeyboardPress as string;\n locatePrompt = (keyboardPressTask as any).locate;\n } else if (keyboardPressTask.keyName) {\n // New format - aiKeyboardPress is the prompt, key is the key\n keyName = keyboardPressTask.keyName;\n locatePrompt = aiKeyboardPress;\n } else {\n keyName = aiKeyboardPress as string;\n }\n\n await agent.callActionInActionSpace('KeyboardPress', {\n ...keyboardPressTask,\n ...(keyName ? { keyName } : {}),\n ...(locatePrompt\n ? {\n locate: buildDetailedLocateParam(locatePrompt, keyboardPressTask),\n }\n : {}),\n });\n } else if ('aiScroll' in flowItem) {\n const { aiScroll, ...scrollTask } =\n flowItem as unknown as MidsceneYamlFlowItemAIScroll;\n\n // Compatibility with previous version:\n // Old format: { aiScroll: null, locate?: TUserPrompt, direction, scrollType, distance? }\n // New format - 1: { aiScroll: TUserPrompt, direction, scrollType, distance? }\n // New format - 2: { aiScroll: undefined, locate: TUserPrompt, direction, scrollType, distance? }\n const { locate, ...scrollOptions } = scrollTask as any;\n const locatePrompt: TUserPrompt | undefined =\n locate ?? aiScroll ?? undefined;\n\n await agent.aiScroll(locatePrompt, scrollOptions);\n } else if ('aiTap' in flowItem) {\n const { aiTap, prompt, locate, ...tapOptions } = flowItem as any;\n\n let locatePrompt: TUserPrompt;\n let opts = tapOptions;\n // Support both formats:\n // 1. { aiTap: null, locate: { prompt, images, ... } } (locate as sibling key)\n // 2. { aiTap: { locate: { prompt, images, ... } } } (locate nested in aiTap)\n const locateObj =\n locate ??\n (typeof aiTap === 'object' && aiTap !== null\n ? aiTap.locate\n : undefined);\n\n if (typeof aiTap === 'string' && aiTap) {\n // User YAML: aiTap: 'search input box'\n locatePrompt = aiTap;\n } else if (typeof locateObj === 'object' && locateObj?.prompt) {\n // buildYamlFlowFromPlans: { aiTap: '', locate: { prompt, deepLocate, cacheable } }\n const { prompt: lp, ...locateOpts } = locateObj;\n locatePrompt = lp;\n opts = { ...locateOpts, ...tapOptions };\n } else {\n // User YAML: aiTap: { prompt: '...' } or aiTap: null + prompt: '...'\n locatePrompt = aiTap?.prompt || prompt || locateObj;\n }\n\n assert(locatePrompt, 'missing prompt for aiTap');\n await agent.aiTap(locatePrompt, opts);\n } else {\n // generic action, find the action in actionSpace\n\n /* for aiRightClick, the parameters are a flattened data for the 'locate', these are all valid data\n\n - aiRightClick: 'search input box'\n - aiRightClick: 'search input box'\n deepLocate: true\n cacheable: false\n - aiRightClick:\n prompt: 'search input box'\n - aiRightClick:\n prompt: 'search input box'\n deepLocate: true\n cacheable: false\n */\n\n const actionSpace = this.actionSpace;\n let locatePromptShortcut: string | undefined;\n let actionParamForMatchedAction: unknown;\n const matchedAction = actionSpace.find((action) => {\n const actionInterfaceAlias = action.interfaceAlias;\n if (\n actionInterfaceAlias &&\n Object.prototype.hasOwnProperty.call(flowItem, actionInterfaceAlias)\n ) {\n actionParamForMatchedAction =\n flowItem[actionInterfaceAlias as keyof typeof flowItem];\n if (typeof actionParamForMatchedAction === 'string') {\n locatePromptShortcut = actionParamForMatchedAction;\n }\n return true;\n }\n\n const keyOfActionInActionSpace = action.name;\n if (\n Object.prototype.hasOwnProperty.call(\n flowItem,\n keyOfActionInActionSpace,\n )\n ) {\n actionParamForMatchedAction =\n flowItem[keyOfActionInActionSpace as keyof typeof flowItem];\n if (typeof actionParamForMatchedAction === 'string') {\n locatePromptShortcut = actionParamForMatchedAction;\n }\n return true;\n }\n\n return false;\n });\n\n assert(\n matchedAction,\n `unknown flowItem in yaml: ${JSON.stringify(flowItem)}`,\n );\n\n const schemaIsStringParam = isStringParamSchema(\n matchedAction.paramSchema,\n );\n let stringParamToCall: string | undefined;\n const resultName = (flowItem as any).name;\n const timeout = (flowItem as any).timeout;\n const hasRunAdbShellAlias = Object.prototype.hasOwnProperty.call(\n flowItem,\n 'runAdbShell',\n );\n\n if (\n hasRunAdbShellAlias &&\n typeof actionParamForMatchedAction === 'string' &&\n typeof timeout === 'number' &&\n typeof (agent as any).runAdbShell === 'function'\n ) {\n const result = await (agent as any).runAdbShell(\n actionParamForMatchedAction,\n { timeout },\n );\n if (result !== undefined) {\n this.setResult(resultName, result);\n }\n return;\n }\n\n const specialActionParamToCall =\n typeof actionParamForMatchedAction === 'string'\n ? buildShortcutActionParam(\n matchedAction.name,\n matchedAction.interfaceAlias,\n actionParamForMatchedAction,\n )\n : undefined;\n if (specialActionParamToCall) {\n debug(\n `matchedAction: ${matchedAction.name}`,\n `flowParams: ${JSON.stringify(specialActionParamToCall)}`,\n );\n const result = await agent.callActionInActionSpace(\n matchedAction.name,\n specialActionParamToCall,\n );\n\n if (result !== undefined) {\n this.setResult(resultName, result);\n }\n } else if (\n typeof actionParamForMatchedAction === 'string' &&\n schemaIsStringParam\n ) {\n if (matchedAction.paramSchema) {\n const parseResult = matchedAction.paramSchema.safeParse(\n actionParamForMatchedAction,\n );\n if (parseResult.success && typeof parseResult.data === 'string') {\n stringParamToCall = parseResult.data;\n } else if (!parseResult.success) {\n debug(\n `parse failed for action ${matchedAction.name} with string param`,\n parseResult.error,\n );\n stringParamToCall = actionParamForMatchedAction;\n }\n } else {\n stringParamToCall = actionParamForMatchedAction;\n }\n\n if (stringParamToCall !== undefined) {\n debug(\n `matchedAction: ${matchedAction.name}`,\n `flowParams: ${JSON.stringify(stringParamToCall)}`,\n );\n const result = await agent.callActionInActionSpace(\n matchedAction.name,\n stringParamToCall,\n );\n\n // Store result if there's a name property in flowItem\n const resultName = (flowItem as any).name;\n if (result !== undefined) {\n this.setResult(resultName, result);\n }\n }\n } else {\n // Determine the source for parameter extraction:\n // - If we have a locatePromptShortcut, use the flowItem (for actions like aiTap with prompt)\n // - Otherwise, use actionParamForMatchedAction (for actions like runWdaRequest with structured params)\n const sourceForParams =\n locatePromptShortcut &&\n typeof actionParamForMatchedAction === 'string'\n ? { ...flowItem, prompt: locatePromptShortcut }\n : typeof actionParamForMatchedAction === 'object' &&\n actionParamForMatchedAction !== null\n ? actionParamForMatchedAction\n : flowItem;\n\n const { locateParam, restParams } =\n buildDetailedLocateParamAndRestParams(\n locatePromptShortcut || '',\n sourceForParams as LocateOption,\n [\n matchedAction.name,\n matchedAction.interfaceAlias || '_never_mind_',\n ],\n );\n\n const flowParams = {\n ...restParams,\n locate: locateParam,\n };\n\n debug(\n `matchedAction: ${matchedAction.name}`,\n `flowParams: ${JSON.stringify(flowParams, null, 2)}`,\n );\n const result = await agent.callActionInActionSpace(\n matchedAction.name,\n flowParams,\n );\n\n // Store result if there's a name property in flowItem\n const resultName = (flowItem as any).name;\n if (result !== undefined) {\n this.setResult(resultName, result);\n }\n }\n }\n }\n\n async run() {\n const { target, web, android, ios, harmony, computer, tasks } = this.script;\n const webEnv = web || target;\n const androidEnv = android;\n const iosEnv = ios;\n const harmonyEnv = harmony;\n const computerEnv = computer;\n const platform =\n webEnv || androidEnv || iosEnv || harmonyEnv || computerEnv;\n\n this.setPlayerStatus('running');\n\n let agent: Agent | null = null;\n let freeFn: FreeFn[] = [];\n try {\n const { agent: newAgent, freeFn: newFreeFn } = await this.setupAgent(\n platform as T,\n );\n this.actionSpace = await newAgent.getActionSpace();\n agent = newAgent;\n const originalOnTaskStartTip = agent.onTaskStartTip;\n agent.onTaskStartTip = (tip) => {\n if (this.status === 'running') {\n this.agentStatusTip = tip;\n }\n originalOnTaskStartTip?.(tip);\n };\n freeFn = [\n ...(newFreeFn || []),\n {\n name: 'restore-agent-onTaskStartTip',\n fn: () => {\n if (agent) {\n agent.onTaskStartTip = originalOnTaskStartTip;\n }\n },\n },\n ];\n } catch (e) {\n this.setPlayerStatus('error', e as Error);\n return;\n }\n this.interfaceAgent = agent;\n\n let taskIndex = 0;\n this.setPlayerStatus('running');\n let errorFlag = false;\n while (taskIndex < tasks.length) {\n const taskStatus = this.taskStatusList[taskIndex];\n this.setTaskStatus(taskIndex, 'running' as any);\n this.setTaskIndex(taskIndex);\n this.failedReportExecutionInCurrentStep = false;\n\n try {\n await this.playTask(taskStatus, this.interfaceAgent);\n this.setTaskStatus(taskIndex, 'done' as any);\n } catch (e) {\n this.setTaskStatus(taskIndex, 'error' as any, e as Error);\n const recordErrorToReport = (agent as any).recordErrorToReport;\n if (\n !this.failedReportExecutionInCurrentStep &&\n typeof recordErrorToReport === 'function'\n ) {\n try {\n await recordErrorToReport.call(\n agent,\n `YAML task failed - ${taskStatus.name}`,\n {\n error: e as Error,\n content: `Step ${taskStatus.currentStep ?? 0} failed while running YAML task \"${taskStatus.name}\".`,\n },\n );\n } catch (reportError) {\n debug('failed to record yaml error to report', reportError);\n }\n }\n\n if (taskStatus.continueOnError) {\n // nothing more to do\n } else {\n this.reportFile = agent.reportFile;\n errorFlag = true;\n break;\n }\n }\n this.reportFile = agent?.reportFile;\n taskIndex++;\n }\n\n if (errorFlag) {\n this.setPlayerStatus('error');\n } else {\n this.setPlayerStatus('done');\n }\n this.agentStatusTip = '';\n\n await runFreeFnCleanup(freeFn);\n }\n}\n"],"names":["debug","getDebug","aiTaskHandlerMap","isStringParamSchema","schema","schemaDef","z","options","Array","option","buildShortcutActionParam","actionName","interfaceAlias","value","ScriptPlayer","key","keyToUse","console","status","error","taskIndex","taskIndexToNotify","taskStatus","index","statusValue","output","resolve","process","outputDir","dirname","existsSync","mkdirSync","writeFileSync","JSON","undefined","content","filePath","agent","flow","assert","flowItemIndex","currentStep","Number","flowItem","flowItemRecord","executionCountBeforeStep","executionCountBefore","executions","deriveCaseStatus","simpleAIKey","Object","actionTask","aiAct","aiAction","ai","instruction","actionOptions","actionPrompt","promptForAI","gherkinScenarioTask","runGherkinScenario","assertTask","prompt","msg","name","restOpts","result","pass","thought","message","Error","agentMethod","aiResult","waitForTask","aiWaitFor","timeout","restWaitForOpts","waitForOptions","sleepTask","ms","msNumber","Promise","setTimeout","evaluateJavaScriptTask","recordTask","title","aiInput","rawValue","inputTask","locatePrompt","String","buildDetailedLocateParam","aiKeyboardPress","keyboardPressTask","keyName","aiScroll","scrollTask","locate","scrollOptions","aiTap","tapOptions","opts","locateObj","lp","locateOpts","actionSpace","locatePromptShortcut","actionParamForMatchedAction","matchedAction","action","actionInterfaceAlias","keyOfActionInActionSpace","schemaIsStringParam","stringParamToCall","resultName","hasRunAdbShellAlias","specialActionParamToCall","parseResult","sourceForParams","locateParam","restParams","buildDetailedLocateParamAndRestParams","flowParams","target","web","android","ios","harmony","computer","tasks","webEnv","androidEnv","iosEnv","harmonyEnv","computerEnv","platform","freeFn","newAgent","newFreeFn","originalOnTaskStartTip","tip","e","errorFlag","recordErrorToReport","reportError","runFreeFnCleanup","script","setupAgent","onTaskStatusChange","scriptPath","ifInBrowser","ifInWorker","scriptName","basename","join","getMidsceneRunSubDir","Date","task"],"mappings":";;;;;;;;;;;;;;;;;;;AAqEA,MAAMA,QAAQC,SAAS;AAEvB,MAAMC,mBAAmB;IACvB,SAAS;IACT,UAAU;IACV,UAAU;IACV,WAAW;IACX,OAAO;IACP,UAAU;AACZ;AAIA,MAAMC,sBAAsB,CAACC;IAC3B,IAAI,CAACA,QACH,OAAO;IAGT,MAAMC,YAAaD,QAAgB;IACnC,IAAI,CAACC,WAAW,UACd,OAAO;IAGT,OAAQA,UAAU,QAAQ;QACxB,KAAKC,EAAE,qBAAqB,CAAC,SAAS;QACtC,KAAKA,EAAE,qBAAqB,CAAC,OAAO;QACpC,KAAKA,EAAE,qBAAqB,CAAC,aAAa;Y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B,GAAGrH;aACrB,IAAI,AAA2C,YAA3C,OAAO,IAAI,CAAC,MAAM,EAAE,oBAC7B,IAAI,CAAC,kBAAkB,GAAGR,2BACxBC,QAAQ,GAAG,IACX,IAAI,CAAC,MAAM,CAAC,kBAAkB;aAE3B,IAAI,IAAI,CAAC,MAAM,EAAE,uBAAuB,MAC7C,IAAI,CAAC,kBAAkB,GAAG+H,KACxBC,qBAAqB,WACrB;QAIJ,IAAI,CAAC,cAAc,GAAIT,AAAAA,CAAAA,OAAO,KAAK,IAAI,EAAC,EAAG,GAAG,CAAC,CAACW,MAAMzI,YAAe;gBACnE,GAAGyI,IAAI;gBACP,OAAOzI;gBACP,QAAQ;gBACR,YAAYyI,KAAK,IAAI,EAAE,UAAU;YACnC;IACF;AAmoBF"}
|
package/dist/es/yaml.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yaml.mjs","sources":["../../src/yaml.ts"],"sourcesContent":["import type { TMultimodalPrompt, TUserPrompt } from './common';\nimport type {\n AndroidDeviceOpt,\n HarmonyDeviceOpt,\n IOSDeviceOpt,\n} from './device';\nimport type { AgentOpt, LocateResultElement, Rect } from './types';\nimport type { UIContext } from './types';\n\nexport interface LocateOption extends Partial<TMultimodalPrompt> {\n prompt?: TUserPrompt;\n /** Additional context for this AI request. */\n context?: string;\n deepLocate?: boolean; // only available in vl model\n /** @deprecated Use `deepLocate` instead. Kept for backward compatibility. */\n deepThink?: boolean; // alias for deepLocate\n cacheable?: boolean; // user can set this param to false to disable the cache for a single agent api\n xpath?: string; // only available in web\n uiContext?: UIContext;\n fileChooserAccept?: string | string[]; // file path(s) to upload when tapping triggers a file chooser\n}\n\nexport interface ServiceExtractOption {\n /** Additional context for this AI request. */\n context?: string;\n domIncluded?: boolean | 'visible-only';\n screenshotIncluded?: boolean;\n [key: string]: unknown;\n}\n\nexport interface DetailedLocateParam\n extends Omit<\n LocateOption,\n 'context' | 'deepThink' | keyof TMultimodalPrompt\n > {\n prompt: TUserPrompt;\n /** Original prompt text used for user-facing reports. */\n promptDisplay?: string;\n /** Per-call business context used for user-facing reports. */\n context?: string;\n}\n\nexport type ScrollType =\n | 'singleAction'\n | 'scrollToBottom'\n | 'scrollToTop'\n | 'scrollToRight'\n | 'scrollToLeft'\n // Legacy aliases kept for backward compatibility\n | 'once'\n | 'untilBottom'\n | 'untilTop'\n | 'untilRight'\n | 'untilLeft';\n\nexport type ActionScrollParam = {\n direction?: 'down' | 'up' | 'right' | 'left';\n scrollType?: ScrollType;\n distance?: number | null;\n locate?: LocateResultElement;\n};\n\nexport type ScrollParam = Omit<ActionScrollParam, 'locate'>;\n\nexport interface MidsceneYamlScript {\n // @deprecated\n target?: MidsceneYamlScriptWebEnv;\n\n page?: MidsceneYamlScriptWebEnv;\n browser?: MidsceneYamlScriptWebEnv;\n web?: MidsceneYamlScriptWebEnv;\n android?: MidsceneYamlScriptAndroidEnv;\n ios?: MidsceneYamlScriptIOSEnv;\n harmony?: MidsceneYamlScriptHarmonyEnv;\n computer?: MidsceneYamlScriptComputerEnv;\n\n interface?: MidsceneYamlScriptEnvGeneralInterface;\n config?: MidsceneYamlScriptConfig;\n agent?: MidsceneYamlScriptAgentOpt;\n\n tasks: MidsceneYamlTask[];\n}\n\nexport interface MidsceneYamlTask {\n name: string;\n flow: MidsceneYamlFlowItem[];\n continueOnError?: boolean;\n}\n\n/**\n * Agent configuration options that can be specified in YAML scripts.\n *\n * This type includes serializable fields from AgentOpt, excluding non-serializable\n * fields like functions and complex objects. All fields are optional.\n *\n * @remarks\n * - testId is deprecated; prefer reportFileName and cache.id\n * - These settings apply to all platforms (Web, Android, iOS, Generic Interface)\n * - modelConfig is configured through environment variables, not in YAML\n *\n * @example\n * ```yaml\n * agent:\n * reportFileName: \"checkout-report\"\n * groupName: \"E2E Test Suite\"\n * generateReport: true\n * replanningCycleLimit: 30\n * cache:\n * id: \"checkout-cache\"\n * strategy: \"read-write\"\n * ```\n */\nexport type MidsceneYamlScriptAgentOpt = Pick<\n AgentOpt,\n | 'testId' // deprecated, kept for backward compatibility\n | 'groupName'\n | 'groupDescription'\n | 'generateReport'\n | 'persistExecutionDump'\n | 'autoPrintReportMsg'\n | 'reportFileName'\n | 'replanningCycleLimit'\n | 'aiActContext'\n | 'aiActionContext'\n | 'cache'\n | 'screenshotShrinkFactor'\n>;\n\nexport interface MidsceneYamlScriptConfig {\n output?: string;\n unstableLogContent?: boolean | string;\n}\n\nexport interface MidsceneYamlScriptEnvGeneralInterface {\n // this will work as `const {...} = import('...'); const interface = new ...(param)`\n module: string;\n export?: string;\n param?: Record<string, any>;\n}\n\nexport interface MidsceneYamlScriptWebEnv\n extends MidsceneYamlScriptConfig,\n MidsceneYamlScriptAgentOpt {\n mode?: 'page' | 'browser';\n\n // for web only\n serve?: string;\n url: string;\n\n // puppeteer only\n userAgent?: string;\n acceptInsecureCerts?: boolean;\n viewportWidth?: number;\n viewportHeight?: number;\n deviceScaleFactor?: number;\n waitForNetworkIdle?: {\n timeout?: number;\n continueOnNetworkIdleError?: boolean; // should continue if failed to wait for network idle, true for default\n };\n cookie?: string;\n\n /**\n * Extra HTTP headers sent with every request (Puppeteer only, not supported\n * in bridge mode). Useful when the server validates custom request headers.\n *\n * Header values must be strings. Quote values that YAML would otherwise parse\n * as a boolean or number (e.g. `true`, `false`, `123`), such as `\"true\"`.\n *\n * @example\n * ```yaml\n * web:\n * url: https://example.com\n * extraHTTPHeaders:\n * X-Custom-Token: my-token\n * Accept-Language: en-US\n * ```\n */\n extraHTTPHeaders?: Record<string, string>;\n\n forceSameTabNavigation?: boolean; // if limit the new tab to the current page, true for default in yaml script\n autoFollowNewPage?: boolean; // if use BrowserAgent to follow newly opened pages, false for default\n\n /**\n * Chrome download directory (Puppeteer only, not supported in bridge mode).\n *\n * Relative paths are resolved from the current working directory.\n *\n * @example\n * ```yaml\n * web:\n * url: https://example.com\n * downloadPath: ./downloads\n * ```\n */\n downloadPath?: string;\n\n /**\n * Custom Chrome launch arguments (Puppeteer only, not supported in bridge mode).\n *\n * Allows passing custom command-line arguments to Chrome/Chromium when launching the browser.\n * This is useful for testing scenarios that require specific browser configurations.\n *\n * ⚠️ Security Warning: Some arguments (e.g., --no-sandbox, --disable-web-security) may\n * reduce browser security. Use only in controlled testing environments.\n *\n * @example\n * ```yaml\n * web:\n * url: https://example.com\n * chromeArgs:\n * - '--disable-features=ThirdPartyCookiePhaseout'\n * - '--disable-features=SameSiteByDefaultCookies'\n * - '--window-size=1920,1080'\n * ```\n */\n chromeArgs?: string[];\n\n // bridge mode config\n bridgeMode?: false | 'newTabWithUrl' | 'currentTab';\n closeNewTabsAfterDisconnect?: boolean;\n\n /**\n * CDP (Chrome DevTools Protocol) endpoint URL.\n * When specified, connects to an existing Chrome browser via CDP instead of launching a new one.\n *\n * @example\n * ```yaml\n * web:\n * url: https://example.com\n * cdpEndpoint: ws://localhost:9222/devtools/browser/xxxx\n * ```\n */\n cdpEndpoint?: string;\n}\n\nexport interface MidsceneYamlScriptAndroidEnv\n extends MidsceneYamlScriptConfig,\n Omit<AndroidDeviceOpt, 'customActions'> {\n // The Android device ID to connect to, optional, will use the first device if not specified\n deviceId?: string;\n\n // The URL or app package to launch, optional, will use the current screen if not specified\n launch?: string;\n}\n\nexport interface MidsceneYamlScriptIOSEnv\n extends MidsceneYamlScriptConfig,\n Omit<IOSDeviceOpt, 'customActions'> {\n // The URL or app bundle ID to launch, optional, will use the current screen if not specified\n launch?: string;\n}\n\nexport interface MidsceneYamlScriptHarmonyEnv\n extends MidsceneYamlScriptConfig,\n Omit<HarmonyDeviceOpt, 'customActions'> {\n // The HarmonyOS device ID to connect to, optional, will use the first device if not specified\n deviceId?: string;\n\n // The bundle name, bundle/Ability target, or mapped app name to launch, optional,\n // will use the current screen if not specified\n launch?: string;\n\n // Custom mapping of app names to bundle names or explicit bundle/Ability targets;\n // user-provided mappings take precedence over defaults\n appNameMapping?: Record<string, string>;\n}\n\nexport interface MidsceneYamlScriptComputerEnv\n extends MidsceneYamlScriptConfig {\n // The display ID to use, optional, will use the primary display if not specified\n displayId?: string;\n}\n\nexport type MidsceneYamlScriptEnv =\n | MidsceneYamlScriptWebEnv\n | MidsceneYamlScriptAndroidEnv\n | MidsceneYamlScriptIOSEnv\n | MidsceneYamlScriptHarmonyEnv\n | MidsceneYamlScriptComputerEnv;\n\n/** Target sections that can be supplied as batch-wide YAML overrides. */\nexport type MidsceneYamlTargetKey = Exclude<\n keyof MidsceneYamlScript,\n 'config' | 'agent' | 'tasks'\n>;\n\nconst midsceneYamlTargetKeyMap = {\n target: true,\n page: true,\n browser: true,\n web: true,\n android: true,\n ios: true,\n harmony: true,\n computer: true,\n interface: true,\n} as const satisfies Record<MidsceneYamlTargetKey, true>;\n\nexport const midsceneYamlTargetKeys = Object.keys(\n midsceneYamlTargetKeyMap,\n) as MidsceneYamlTargetKey[];\n\n/**\n * Partial target settings applied to every script in a YAML batch.\n *\n * Batch settings are deep-merged over each script's target section, so every\n * nested target field is optional here even when a standalone script requires\n * it.\n */\nexport type MidsceneYamlTargetConfig = {\n [Target in MidsceneYamlTargetKey]?: Partial<\n NonNullable<MidsceneYamlScript[Target]>\n >;\n};\n\nexport interface MidsceneYamlFlowItemAIAction {\n // defined as aiAction for backward compatibility\n aiAction?: TUserPrompt | null;\n ai?: TUserPrompt | null; // this is the shortcut for aiAct\n aiAct?: TUserPrompt | null;\n instruction?: TUserPrompt;\n aiActionProgressTips?: string[];\n cacheable?: boolean;\n [key: string]: unknown;\n}\n\nexport interface MidsceneYamlFlowItemAIAssert extends ServiceExtractOption {\n aiAssert: string;\n errorMessage?: string;\n name?: string;\n}\n\nexport interface MidsceneYamlFlowItemAIWaitFor extends ServiceExtractOption {\n aiWaitFor: string;\n timeout?: number;\n}\n\nexport interface MidsceneYamlFlowItemRunGherkinScenario {\n runGherkinScenario: string;\n}\n\nexport interface MidsceneYamlFlowItemEvaluateJavaScript {\n javascript: string;\n name?: string;\n}\n\nexport interface MidsceneYamlFlowItemSleep {\n sleep: number;\n}\n\nexport interface MidsceneYamlFlowItemLogScreenshot {\n logScreenshot?: string; // optional, the title of the screenshot\n recordToReport?: string; // preferred key for record title\n content?: string;\n}\n\nexport type MidsceneYamlFlowItem =\n | MidsceneYamlFlowItemAIAction\n | MidsceneYamlFlowItemAIAssert\n | MidsceneYamlFlowItemAIWaitFor\n | MidsceneYamlFlowItemRunGherkinScenario\n | MidsceneYamlFlowItemEvaluateJavaScript\n | MidsceneYamlFlowItemSleep\n | MidsceneYamlFlowItemLogScreenshot;\n\nexport interface FreeFn {\n name: string;\n fn: () => void | Promise<void>;\n}\n\nexport interface ScriptPlayerTaskStatus extends MidsceneYamlTask {\n status: ScriptPlayerStatusValue;\n currentStep?: number;\n totalSteps: number;\n error?: Error;\n}\n\nexport type ScriptPlayerStatusValue = 'init' | 'running' | 'done' | 'error';\n\n// Index YAML file types for batch execution\nexport interface MidsceneYamlConfig extends MidsceneYamlTargetConfig {\n /** @deprecated Use `web`, `page`, or `browser` instead. */\n target?: Partial<MidsceneYamlScriptWebEnv>;\n concurrent?: number;\n continueOnError?: boolean;\n /**\n * Number of times to retry a failed yaml file before marking it as failed.\n * A value of 2 means each failing case is re-executed up to 2 extra times\n * (3 attempts in total). Only the cases that failed in the previous attempt\n * are retried. Defaults to 0 (no retry).\n */\n retry?: number;\n summary?: string;\n /**\n * Share one BrowserContext and Page across Puppeteer Web yaml files. This is\n * not supported by bridge mode or non-Web targets.\n */\n shareBrowserContext?: boolean;\n /**\n * A setup yaml file that runs before the main `files`. A setup failure aborts\n * the whole batch and the main files are marked as not executed. Puppeteer\n * Web setup requires `shareBrowserContext: true` to pass browser state to the\n * main files. Other targets run setup without browser-context sharing.\n */\n setup?: string;\n files: string[];\n headed?: boolean;\n keepWindow?: boolean;\n dotenvOverride?: boolean;\n dotenvDebug?: boolean;\n}\n\nexport interface MidsceneYamlConfigOutput {\n format?: 'json';\n path?: string;\n}\n\nexport type MidsceneYamlConfigResultType =\n | 'success'\n | 'failed'\n | 'partialFailed'\n | 'notExecuted';\n\nexport interface MidsceneYamlConfigAttempt {\n attempt: number;\n success: boolean;\n output?: string | null;\n report?: string | null;\n error?: string;\n duration?: number;\n resultType?: MidsceneYamlConfigResultType;\n}\n\nexport interface MidsceneYamlConfigResult {\n file: string;\n success: boolean;\n executed: boolean;\n output?: string | null;\n report?: string | null;\n retryReport?: string | null;\n attempts?: MidsceneYamlConfigAttempt[];\n error?: string;\n duration?: number;\n /**\n * Type of result:\n * - 'success': All tasks completed successfully\n * - 'failed': Execution failed (player error)\n * - 'partialFailed': Some tasks failed but execution continued (continueOnError)\n * - 'notExecuted': Not executed due to previous failures\n */\n resultType?: MidsceneYamlConfigResultType;\n}\n"],"names":["midsceneYamlTargetKeyMap","midsceneYamlTargetKeys","Object"],"mappings":"AA8RA,MAAMA,2BAA2B;IAC/B,QAAQ;IACR,MAAM;IACN,SAAS;IACT,KAAK;IACL,SAAS;IACT,KAAK;IACL,SAAS;IACT,UAAU;IACV,WAAW;AACb;AAEO,MAAMC,yBAAyBC,OAAO,IAAI,CAC/CF"}
|
|
1
|
+
{"version":3,"file":"yaml.mjs","sources":["../../src/yaml.ts"],"sourcesContent":["import type { TMultimodalPrompt, TUserPrompt } from './common';\nimport type {\n AndroidDeviceOpt,\n HarmonyDeviceOpt,\n IOSDeviceOpt,\n} from './device';\nimport type { AgentOpt, LocateResultElement, Rect } from './types';\nimport type { UIContext } from './types';\n\nexport interface LocateOption extends Partial<TMultimodalPrompt> {\n prompt?: TUserPrompt;\n /**\n * Additional facts, rules, or constraints for this AI call. It overrides\n * the matching API context and `aiContexts.default`; `''` disables inherited\n * user context for this call.\n */\n context?: string;\n deepLocate?: boolean; // only available in vl model\n /** @deprecated Use `deepLocate` instead. Kept for backward compatibility. */\n deepThink?: boolean; // alias for deepLocate\n cacheable?: boolean; // user can set this param to false to disable the cache for a single agent api\n xpath?: string; // only available in web\n uiContext?: UIContext;\n fileChooserAccept?: string | string[]; // file path(s) to upload when tapping triggers a file chooser\n}\n\nexport interface ServiceExtractOption {\n /**\n * Additional facts, decision rules, constraints, or output requirements for\n * this AI call. It overrides the matching API context and\n * `aiContexts.default`; `''` disables inherited user context for this call.\n */\n context?: string;\n domIncluded?: boolean | 'visible-only';\n screenshotIncluded?: boolean;\n [key: string]: unknown;\n}\n\nexport interface DetailedLocateParam\n extends Omit<\n LocateOption,\n 'context' | 'deepThink' | keyof TMultimodalPrompt\n > {\n prompt: TUserPrompt;\n /** Original prompt text used for user-facing reports. */\n promptDisplay?: string;\n /** Per-call AI guidance recorded in user-facing reports. */\n context?: string;\n}\n\nexport type ScrollType =\n | 'singleAction'\n | 'scrollToBottom'\n | 'scrollToTop'\n | 'scrollToRight'\n | 'scrollToLeft'\n // Legacy aliases kept for backward compatibility\n | 'once'\n | 'untilBottom'\n | 'untilTop'\n | 'untilRight'\n | 'untilLeft';\n\nexport type ActionScrollParam = {\n direction?: 'down' | 'up' | 'right' | 'left';\n scrollType?: ScrollType;\n distance?: number | null;\n locate?: LocateResultElement;\n};\n\nexport type ScrollParam = Omit<ActionScrollParam, 'locate'>;\n\nexport interface MidsceneYamlScript {\n // @deprecated\n target?: MidsceneYamlScriptWebEnv;\n\n page?: MidsceneYamlScriptWebEnv;\n browser?: MidsceneYamlScriptWebEnv;\n web?: MidsceneYamlScriptWebEnv;\n android?: MidsceneYamlScriptAndroidEnv;\n ios?: MidsceneYamlScriptIOSEnv;\n harmony?: MidsceneYamlScriptHarmonyEnv;\n computer?: MidsceneYamlScriptComputerEnv;\n\n interface?: MidsceneYamlScriptEnvGeneralInterface;\n config?: MidsceneYamlScriptConfig;\n agent?: MidsceneYamlScriptAgentOpt;\n\n tasks: MidsceneYamlTask[];\n}\n\nexport interface MidsceneYamlTask {\n name: string;\n flow: MidsceneYamlFlowItem[];\n continueOnError?: boolean;\n}\n\n/**\n * Agent configuration options that can be specified in YAML scripts.\n *\n * This type includes serializable fields from AgentOpt, excluding non-serializable\n * fields like functions and complex objects. All fields are optional.\n *\n * @remarks\n * - testId is deprecated; prefer reportFileName and cache.id\n * - These settings apply to all platforms (Web, Android, iOS, Generic Interface)\n * - modelConfig is configured through environment variables, not in YAML\n *\n * @example\n * ```yaml\n * agent:\n * reportFileName: \"checkout-report\"\n * groupName: \"E2E Test Suite\"\n * generateReport: true\n * replanningCycleLimit: 30\n * cache:\n * id: \"checkout-cache\"\n * strategy: \"read-write\"\n * ```\n */\nexport type MidsceneYamlScriptAgentOpt = Pick<\n AgentOpt,\n | 'testId' // deprecated, kept for backward compatibility\n | 'groupName'\n | 'groupDescription'\n | 'generateReport'\n | 'persistExecutionDump'\n | 'autoPrintReportMsg'\n | 'reportFileName'\n | 'replanningCycleLimit'\n | 'aiContexts'\n | 'aiActContext'\n | 'aiActionContext'\n | 'cache'\n | 'screenshotShrinkFactor'\n>;\n\nexport interface MidsceneYamlScriptConfig {\n output?: string;\n unstableLogContent?: boolean | string;\n}\n\nexport interface MidsceneYamlScriptEnvGeneralInterface {\n // this will work as `const {...} = import('...'); const interface = new ...(param)`\n module: string;\n export?: string;\n param?: Record<string, any>;\n}\n\nexport interface MidsceneYamlScriptWebEnv\n extends MidsceneYamlScriptConfig,\n MidsceneYamlScriptAgentOpt {\n mode?: 'page' | 'browser';\n\n // for web only\n serve?: string;\n url: string;\n\n // puppeteer only\n userAgent?: string;\n acceptInsecureCerts?: boolean;\n viewportWidth?: number;\n viewportHeight?: number;\n deviceScaleFactor?: number;\n waitForNetworkIdle?: {\n timeout?: number;\n continueOnNetworkIdleError?: boolean; // should continue if failed to wait for network idle, true for default\n };\n cookie?: string;\n\n /**\n * Extra HTTP headers sent with every request (Puppeteer only, not supported\n * in bridge mode). Useful when the server validates custom request headers.\n *\n * Header values must be strings. Quote values that YAML would otherwise parse\n * as a boolean or number (e.g. `true`, `false`, `123`), such as `\"true\"`.\n *\n * @example\n * ```yaml\n * web:\n * url: https://example.com\n * extraHTTPHeaders:\n * X-Custom-Token: my-token\n * Accept-Language: en-US\n * ```\n */\n extraHTTPHeaders?: Record<string, string>;\n\n forceSameTabNavigation?: boolean; // if limit the new tab to the current page, true for default in yaml script\n autoFollowNewPage?: boolean; // if use BrowserAgent to follow newly opened pages, false for default\n\n /**\n * Chrome download directory (Puppeteer only, not supported in bridge mode).\n *\n * Relative paths are resolved from the current working directory.\n *\n * @example\n * ```yaml\n * web:\n * url: https://example.com\n * downloadPath: ./downloads\n * ```\n */\n downloadPath?: string;\n\n /**\n * Custom Chrome launch arguments (Puppeteer only, not supported in bridge mode).\n *\n * Allows passing custom command-line arguments to Chrome/Chromium when launching the browser.\n * This is useful for testing scenarios that require specific browser configurations.\n *\n * ⚠️ Security Warning: Some arguments (e.g., --no-sandbox, --disable-web-security) may\n * reduce browser security. Use only in controlled testing environments.\n *\n * @example\n * ```yaml\n * web:\n * url: https://example.com\n * chromeArgs:\n * - '--disable-features=ThirdPartyCookiePhaseout'\n * - '--disable-features=SameSiteByDefaultCookies'\n * - '--window-size=1920,1080'\n * ```\n */\n chromeArgs?: string[];\n\n // bridge mode config\n bridgeMode?: false | 'newTabWithUrl' | 'currentTab';\n closeNewTabsAfterDisconnect?: boolean;\n\n /**\n * CDP (Chrome DevTools Protocol) endpoint URL.\n * When specified, connects to an existing Chrome browser via CDP instead of launching a new one.\n *\n * @example\n * ```yaml\n * web:\n * url: https://example.com\n * cdpEndpoint: ws://localhost:9222/devtools/browser/xxxx\n * ```\n */\n cdpEndpoint?: string;\n}\n\nexport interface MidsceneYamlScriptAndroidEnv\n extends MidsceneYamlScriptConfig,\n Omit<AndroidDeviceOpt, 'customActions'> {\n // The Android device ID to connect to, optional, will use the first device if not specified\n deviceId?: string;\n\n // The URL or app package to launch, optional, will use the current screen if not specified\n launch?: string;\n}\n\nexport interface MidsceneYamlScriptIOSEnv\n extends MidsceneYamlScriptConfig,\n Omit<IOSDeviceOpt, 'customActions'> {\n // The URL or app bundle ID to launch, optional, will use the current screen if not specified\n launch?: string;\n}\n\nexport interface MidsceneYamlScriptHarmonyEnv\n extends MidsceneYamlScriptConfig,\n Omit<HarmonyDeviceOpt, 'customActions'> {\n // The HarmonyOS device ID to connect to, optional, will use the first device if not specified\n deviceId?: string;\n\n // The bundle name, bundle/Ability target, or mapped app name to launch, optional,\n // will use the current screen if not specified\n launch?: string;\n\n // Custom mapping of app names to bundle names or explicit bundle/Ability targets;\n // user-provided mappings take precedence over defaults\n appNameMapping?: Record<string, string>;\n}\n\nexport interface MidsceneYamlScriptComputerEnv\n extends MidsceneYamlScriptConfig {\n // The display ID to use, optional, will use the primary display if not specified\n displayId?: string;\n}\n\nexport type MidsceneYamlScriptEnv =\n | MidsceneYamlScriptWebEnv\n | MidsceneYamlScriptAndroidEnv\n | MidsceneYamlScriptIOSEnv\n | MidsceneYamlScriptHarmonyEnv\n | MidsceneYamlScriptComputerEnv;\n\n/** Target sections that can be supplied as batch-wide YAML overrides. */\nexport type MidsceneYamlTargetKey = Exclude<\n keyof MidsceneYamlScript,\n 'config' | 'agent' | 'tasks'\n>;\n\nconst midsceneYamlTargetKeyMap = {\n target: true,\n page: true,\n browser: true,\n web: true,\n android: true,\n ios: true,\n harmony: true,\n computer: true,\n interface: true,\n} as const satisfies Record<MidsceneYamlTargetKey, true>;\n\nexport const midsceneYamlTargetKeys = Object.keys(\n midsceneYamlTargetKeyMap,\n) as MidsceneYamlTargetKey[];\n\n/**\n * Partial target settings applied to every script in a YAML batch.\n *\n * Batch settings are deep-merged over each script's target section, so every\n * nested target field is optional here even when a standalone script requires\n * it.\n */\nexport type MidsceneYamlTargetConfig = {\n [Target in MidsceneYamlTargetKey]?: Partial<\n NonNullable<MidsceneYamlScript[Target]>\n >;\n};\n\nexport interface MidsceneYamlFlowItemAIAction {\n // defined as aiAction for backward compatibility\n aiAction?: TUserPrompt | null;\n ai?: TUserPrompt | null; // this is the shortcut for aiAct\n aiAct?: TUserPrompt | null;\n instruction?: TUserPrompt;\n aiActionProgressTips?: string[];\n cacheable?: boolean;\n [key: string]: unknown;\n}\n\nexport interface MidsceneYamlFlowItemAIAssert extends ServiceExtractOption {\n aiAssert: string;\n errorMessage?: string;\n name?: string;\n}\n\nexport interface MidsceneYamlFlowItemAIWaitFor extends ServiceExtractOption {\n aiWaitFor: string;\n timeout?: number;\n}\n\nexport interface MidsceneYamlFlowItemRunGherkinScenario {\n runGherkinScenario: string;\n}\n\nexport interface MidsceneYamlFlowItemEvaluateJavaScript {\n javascript: string;\n name?: string;\n}\n\nexport interface MidsceneYamlFlowItemSleep {\n sleep: number;\n}\n\nexport interface MidsceneYamlFlowItemLogScreenshot {\n logScreenshot?: string; // optional, the title of the screenshot\n recordToReport?: string; // preferred key for record title\n content?: string;\n}\n\nexport type MidsceneYamlFlowItem =\n | MidsceneYamlFlowItemAIAction\n | MidsceneYamlFlowItemAIAssert\n | MidsceneYamlFlowItemAIWaitFor\n | MidsceneYamlFlowItemRunGherkinScenario\n | MidsceneYamlFlowItemEvaluateJavaScript\n | MidsceneYamlFlowItemSleep\n | MidsceneYamlFlowItemLogScreenshot;\n\nexport interface FreeFn {\n name: string;\n fn: () => void | Promise<void>;\n}\n\nexport interface ScriptPlayerTaskStatus extends MidsceneYamlTask {\n status: ScriptPlayerStatusValue;\n currentStep?: number;\n totalSteps: number;\n error?: Error;\n}\n\nexport type ScriptPlayerStatusValue = 'init' | 'running' | 'done' | 'error';\n\n// Index YAML file types for batch execution\nexport interface MidsceneYamlConfig extends MidsceneYamlTargetConfig {\n /** @deprecated Use `web`, `page`, or `browser` instead. */\n target?: Partial<MidsceneYamlScriptWebEnv>;\n concurrent?: number;\n continueOnError?: boolean;\n /**\n * Number of times to retry a failed yaml file before marking it as failed.\n * A value of 2 means each failing case is re-executed up to 2 extra times\n * (3 attempts in total). Only the cases that failed in the previous attempt\n * are retried. Defaults to 0 (no retry).\n */\n retry?: number;\n summary?: string;\n /**\n * Share one BrowserContext and Page across Puppeteer Web yaml files. This is\n * not supported by bridge mode or non-Web targets.\n */\n shareBrowserContext?: boolean;\n /**\n * A setup yaml file that runs before the main `files`. A setup failure aborts\n * the whole batch and the main files are marked as not executed. Puppeteer\n * Web setup requires `shareBrowserContext: true` to pass browser state to the\n * main files. Other targets run setup without browser-context sharing.\n */\n setup?: string;\n files: string[];\n headed?: boolean;\n keepWindow?: boolean;\n dotenvOverride?: boolean;\n dotenvDebug?: boolean;\n}\n\nexport interface MidsceneYamlConfigOutput {\n format?: 'json';\n path?: string;\n}\n\nexport type MidsceneYamlConfigResultType =\n | 'success'\n | 'failed'\n | 'partialFailed'\n | 'notExecuted';\n\nexport interface MidsceneYamlConfigAttempt {\n attempt: number;\n success: boolean;\n output?: string | null;\n report?: string | null;\n error?: string;\n duration?: number;\n resultType?: MidsceneYamlConfigResultType;\n}\n\nexport interface MidsceneYamlConfigResult {\n file: string;\n success: boolean;\n executed: boolean;\n output?: string | null;\n report?: string | null;\n retryReport?: string | null;\n attempts?: MidsceneYamlConfigAttempt[];\n error?: string;\n duration?: number;\n /**\n * Type of result:\n * - 'success': All tasks completed successfully\n * - 'failed': Execution failed (player error)\n * - 'partialFailed': Some tasks failed but execution continued (continueOnError)\n * - 'notExecuted': Not executed due to previous failures\n */\n resultType?: MidsceneYamlConfigResultType;\n}\n"],"names":["midsceneYamlTargetKeyMap","midsceneYamlTargetKeys","Object"],"mappings":"AAuSA,MAAMA,2BAA2B;IAC/B,QAAQ;IACR,MAAM;IACN,SAAS;IACT,KAAK;IACL,SAAS;IACT,KAAK;IACL,SAAS;IACT,UAAU;IACV,WAAW;AACb;AAEO,MAAMC,yBAAyBC,OAAO,IAAI,CAC/CF"}
|