@midscene/core 0.27.1 → 0.27.2-beta-20250825025215.0

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.
@@ -141,7 +141,7 @@ function trimContextByViewport(execution) {
141
141
  }) : execution.tasks
142
142
  };
143
143
  }
144
- const getMidsceneVersion = ()=>"0.27.1";
144
+ const getMidsceneVersion = ()=>"0.27.2-beta-20250825025215.0";
145
145
  const parsePrompt = (prompt)=>{
146
146
  if ('string' == typeof prompt) return {
147
147
  textPrompt: prompt,
@@ -1 +1 @@
1
- {"version":3,"file":"agent/utils.mjs","sources":["webpack://@midscene/core/./src/agent/utils.ts"],"sourcesContent":["import { elementByPositionWithElementInfo } from '@/ai-model';\nimport type { AbstractPage } from '@/device';\nimport type {\n BaseElement,\n DetailedLocateParam,\n DeviceAction,\n ElementTreeNode,\n ExecutionDump,\n ExecutionTask,\n ExecutorContext,\n LocateOption,\n MidsceneLocationResultType,\n PlanningLocateParam,\n TMultimodalPrompt,\n TUserPrompt,\n UIContext,\n} from '@/index';\nimport { getMidsceneLocationSchema, z } from '@/index';\nimport { sleep, uploadTestInfoToServer } from '@/utils';\nimport { MIDSCENE_REPORT_TAG_NAME, getAIConfig } from '@midscene/shared/env';\nimport type { ElementInfo } from '@midscene/shared/extractor';\nimport {\n generateElementByPosition,\n getNodeFromCacheList,\n} from '@midscene/shared/extractor';\nimport { resizeImgBase64 } from '@midscene/shared/img';\nimport { getDebug } from '@midscene/shared/logger';\nimport { _keyDefinitions } from '@midscene/shared/us-keyboard-layout';\nimport { assert, logMsg, uuid } from '@midscene/shared/utils';\nimport dayjs from 'dayjs';\nimport { debug as cacheDebug } from './task-cache';\nimport type { PageTaskExecutor } from './tasks';\nimport { getKeyCommands } from './ui-utils';\n\nconst debugProfile = getDebug('web:tool:profile');\nconst debugUtils = getDebug('web:tool:utils');\n\nexport async function commonContextParser(\n page: AbstractPage,\n): Promise<UIContext> {\n assert(page, 'page is required');\n\n debugProfile('Getting page URL');\n const url = await page.url();\n debugProfile('URL end');\n\n debugProfile('Uploading test info to server');\n uploadTestInfoToServer({ testUrl: url });\n debugProfile('UploadTestInfoToServer end');\n\n let screenshotBase64 = await page.screenshotBase64();\n assert(screenshotBase64!, 'screenshotBase64 is required');\n\n const size = await page.size();\n debugProfile(`size: ${size.width}x${size.height} dpr: ${size.dpr}`);\n\n if (size.dpr && size.dpr > 1) {\n debugProfile('Resizing screenshot for high DPR display');\n screenshotBase64 = await resizeImgBase64(screenshotBase64, {\n width: size.width,\n height: size.height,\n });\n debugProfile('ResizeImgBase64 end');\n }\n\n return {\n tree: {\n node: null,\n children: [],\n },\n size,\n screenshotBase64: screenshotBase64!,\n url,\n };\n}\n\nexport function getReportFileName(tag = 'web') {\n const reportTagName = getAIConfig(MIDSCENE_REPORT_TAG_NAME);\n const dateTimeInFileName = dayjs().format('YYYY-MM-DD_HH-mm-ss');\n // ensure uniqueness at the same time\n const uniqueId = uuid().substring(0, 8);\n return `${reportTagName || tag}-${dateTimeInFileName}-${uniqueId}`;\n}\n\nexport function printReportMsg(filepath: string) {\n logMsg(`Midscene - report file updated: ${filepath}`);\n}\n\n/**\n * Get the current execution file name\n * @returns The name of the current execution file\n */\nexport function getCurrentExecutionFile(trace?: string): string | false {\n const error = new Error();\n const stackTrace = trace || error.stack;\n const pkgDir = process.cwd() || '';\n if (stackTrace) {\n const stackLines = stackTrace.split('\\n');\n for (const line of stackLines) {\n if (\n line.includes('.spec.') ||\n line.includes('.test.') ||\n line.includes('.ts') ||\n line.includes('.js')\n ) {\n const match = line.match(/(?:at\\s+)?(.*?\\.(?:spec|test)\\.[jt]s)/);\n if (match?.[1]) {\n const targetFileName = match[1]\n .replace(pkgDir, '')\n .trim()\n .replace('at ', '');\n return targetFileName;\n }\n }\n }\n }\n return false;\n}\n\nconst testFileIndex = new Map<string, number>();\n\nexport function generateCacheId(fileName?: string): string {\n let taskFile = fileName || getCurrentExecutionFile();\n if (!taskFile) {\n taskFile = uuid();\n console.warn(\n 'Midscene - using random UUID for cache id. Cache may be invalid.',\n );\n }\n\n if (testFileIndex.has(taskFile)) {\n const currentIndex = testFileIndex.get(taskFile);\n if (currentIndex !== undefined) {\n testFileIndex.set(taskFile, currentIndex + 1);\n }\n } else {\n testFileIndex.set(taskFile, 1);\n }\n return `${taskFile}-${testFileIndex.get(taskFile)}`;\n}\n\nexport function matchElementFromPlan(\n planLocateParam: PlanningLocateParam,\n tree: ElementTreeNode<BaseElement>,\n) {\n if (!planLocateParam) {\n return undefined;\n }\n if (planLocateParam.id) {\n return getNodeFromCacheList(planLocateParam.id);\n }\n\n if (planLocateParam.bbox) {\n const centerPosition = {\n x: Math.floor((planLocateParam.bbox[0] + planLocateParam.bbox[2]) / 2),\n y: Math.floor((planLocateParam.bbox[1] + planLocateParam.bbox[3]) / 2),\n };\n let element = elementByPositionWithElementInfo(tree, centerPosition);\n\n if (!element) {\n element = generateElementByPosition(centerPosition) as BaseElement;\n }\n\n return element;\n }\n\n return undefined;\n}\n\nexport async function matchElementFromCache(\n taskExecutor: PageTaskExecutor,\n xpaths: string[] | undefined,\n cachePrompt: TUserPrompt,\n cacheable: boolean | undefined,\n) {\n try {\n if (\n xpaths?.length &&\n taskExecutor.taskCache?.isCacheResultUsed &&\n cacheable !== false &&\n (taskExecutor.page as any).getElementInfoByXpath\n ) {\n // hit cache, use new id\n for (let i = 0; i < xpaths.length; i++) {\n const element = await (taskExecutor.page as any).getElementInfoByXpath(\n xpaths[i],\n );\n\n if (element?.id) {\n cacheDebug('cache hit, prompt: %s', cachePrompt);\n cacheDebug(\n 'found a new element with same xpath, xpath: %s, id: %s',\n xpaths[i],\n element?.id,\n );\n return element;\n }\n }\n }\n } catch (error) {\n cacheDebug('get element info by xpath error: ', error);\n }\n}\n\nexport function trimContextByViewport(execution: ExecutionDump) {\n function filterVisibleTree(\n node: ElementTreeNode<BaseElement>,\n ): ElementTreeNode<BaseElement> | null {\n if (!node) return null;\n\n // recursively process all children\n const filteredChildren = Array.isArray(node.children)\n ? (node.children\n .map(filterVisibleTree)\n .filter((child) => child !== null) as ElementTreeNode<BaseElement>[])\n : [];\n\n // if the current node is visible, keep it and the filtered children\n if (node.node && node.node.isVisible === true) {\n return {\n ...node,\n children: filteredChildren,\n };\n }\n\n // if the current node is invisible, but has visible children, create an empty node to include these children\n if (filteredChildren.length > 0) {\n return {\n node: null,\n children: filteredChildren,\n };\n }\n\n // if the current node is invisible and has no visible children, return null\n return null;\n }\n\n return {\n ...execution,\n tasks: Array.isArray(execution.tasks)\n ? execution.tasks.map((task: ExecutionTask) => {\n const newTask = { ...task };\n if (task.pageContext?.tree) {\n newTask.pageContext = {\n ...task.pageContext,\n tree: filterVisibleTree(task.pageContext.tree) || {\n node: null,\n children: [],\n },\n };\n }\n return newTask;\n })\n : execution.tasks,\n };\n}\n\ndeclare const __VERSION__: string | undefined;\n\nexport const getMidsceneVersion = (): string => {\n if (typeof __VERSION__ !== 'undefined') {\n return __VERSION__;\n } else if (\n process.env.__VERSION__ &&\n process.env.__VERSION__ !== 'undefined'\n ) {\n return process.env.__VERSION__;\n }\n throw new Error('__VERSION__ inject failed during build');\n};\n\nexport const parsePrompt = (\n prompt: TUserPrompt,\n): {\n textPrompt: string;\n multimodalPrompt?: TMultimodalPrompt;\n} => {\n if (typeof prompt === 'string') {\n return {\n textPrompt: prompt,\n multimodalPrompt: undefined,\n };\n }\n return {\n textPrompt: prompt.prompt,\n multimodalPrompt: prompt.images\n ? {\n images: prompt.images,\n convertHttpImage2Base64: !!prompt.convertHttpImage2Base64,\n }\n : undefined,\n };\n};\n\nexport const commonWebActionsForWebPage = <T extends AbstractPage>(\n page: T,\n): DeviceAction<any>[] => [\n {\n name: 'Tap',\n description: 'Tap the element',\n interfaceAlias: 'aiTap',\n paramSchema: z.object({\n locate: getMidsceneLocationSchema().describe('The element to be tapped'),\n }),\n call: async (param) => {\n const element = param.locate;\n assert(element, 'Element not found, cannot tap');\n await page.mouse.click(element.center[0], element.center[1], {\n button: 'left',\n });\n },\n } as DeviceAction<{\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'RightClick',\n description: 'Right click the element',\n interfaceAlias: 'aiRightClick',\n paramSchema: z.object({\n locate: getMidsceneLocationSchema().describe(\n 'The element to be right clicked',\n ),\n }),\n call: async (param) => {\n const element = param.locate;\n assert(element, 'Element not found, cannot right click');\n await page.mouse.click(element.center[0], element.center[1], {\n button: 'right',\n });\n },\n } as DeviceAction<{\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'Hover',\n description: 'Move the mouse to the element',\n interfaceAlias: 'aiHover',\n paramSchema: z.object({\n locate: getMidsceneLocationSchema().describe('The element to be hovered'),\n }),\n call: async (param) => {\n const element = param.locate;\n assert(element, 'Element not found, cannot hover');\n await page.mouse.move(element.center[0], element.center[1]);\n },\n } as DeviceAction<{\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'Input',\n description:\n 'Replace the input field with a new value. `value` is the final that should be filled in the input box. No matter what modifications are required, just provide the final value to replace the existing input value. Giving a blank string means clear the input field.',\n interfaceAlias: 'aiInput',\n paramSchema: z.object({\n value: z\n .string()\n .describe('The final value that should be filled in the input box'),\n locate: getMidsceneLocationSchema()\n .describe('The input field to be filled')\n .optional(),\n }),\n call: async (param) => {\n const element = param.locate;\n if (element) {\n await page.clearInput(element as unknown as ElementInfo);\n\n if (!param || !param.value) {\n return;\n }\n }\n\n // Note: there is another implementation in AndroidDevicePage, which is more complex\n await page.keyboard.type(param.value);\n },\n } as DeviceAction<{\n value: string;\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'KeyboardPress',\n description:\n 'Press a function key, like \"Enter\", \"Tab\", \"Escape\". Do not use this to type text.',\n interfaceAlias: 'aiKeyboardPress',\n paramSchema: z.object({\n locate: getMidsceneLocationSchema()\n .describe('The element to be clicked before pressing the key')\n .optional(),\n keyName: z.string().describe('The key to be pressed'),\n }),\n call: async (param) => {\n const element = param.locate;\n if (element) {\n await page.mouse.click(element.center[0], element.center[1], {\n button: 'left',\n });\n }\n\n const keys = getKeyCommands(param.keyName);\n await page.keyboard.press(keys as any); // TODO: fix this type error\n },\n } as DeviceAction<{\n keyName: string;\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'Scroll',\n description:\n 'Scroll the page or an element. The direction to scroll, the scroll type, and the distance to scroll. The distance is the number of pixels to scroll. If not specified, use `down` direction, `once` scroll type, and `null` distance.',\n interfaceAlias: 'aiScroll',\n paramSchema: z.object({\n direction: z\n .enum(['down', 'up', 'right', 'left'])\n .default('down')\n .describe('The direction to scroll'),\n scrollType: z\n .enum(['once', 'untilBottom', 'untilTop', 'untilRight', 'untilLeft'])\n .default('once')\n .describe('The scroll type'),\n distance: z\n .number()\n .nullable()\n .optional()\n .describe('The distance in pixels to scroll'),\n locate: getMidsceneLocationSchema()\n .optional()\n .describe('The element to be scrolled'),\n }),\n call: async (param) => {\n const element = param.locate;\n const startingPoint = element\n ? {\n left: element.center[0],\n top: element.center[1],\n }\n : undefined;\n const scrollToEventName = param?.scrollType;\n if (scrollToEventName === 'untilTop') {\n await page.scrollUntilTop(startingPoint);\n } else if (scrollToEventName === 'untilBottom') {\n await page.scrollUntilBottom(startingPoint);\n } else if (scrollToEventName === 'untilRight') {\n await page.scrollUntilRight(startingPoint);\n } else if (scrollToEventName === 'untilLeft') {\n await page.scrollUntilLeft(startingPoint);\n } else if (scrollToEventName === 'once' || !scrollToEventName) {\n if (param?.direction === 'down' || !param || !param.direction) {\n await page.scrollDown(param?.distance || undefined, startingPoint);\n } else if (param.direction === 'up') {\n await page.scrollUp(param.distance || undefined, startingPoint);\n } else if (param.direction === 'left') {\n await page.scrollLeft(param.distance || undefined, startingPoint);\n } else if (param.direction === 'right') {\n await page.scrollRight(param.distance || undefined, startingPoint);\n } else {\n throw new Error(`Unknown scroll direction: ${param.direction}`);\n }\n // until mouse event is done\n await sleep(500);\n } else {\n throw new Error(\n `Unknown scroll event type: ${scrollToEventName}, param: ${JSON.stringify(\n param,\n )}`,\n );\n }\n },\n } as DeviceAction<{\n scrollType:\n | 'once'\n | 'untilBottom'\n | 'untilTop'\n | 'untilRight'\n | 'untilLeft';\n direction: 'up' | 'down';\n distance?: number;\n duration?: number;\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'DragAndDrop',\n description: 'Drag and drop the element',\n paramSchema: z.object({\n from: getMidsceneLocationSchema().describe('The position to be dragged'),\n to: getMidsceneLocationSchema().describe('The position to be dropped'),\n }),\n call: async (param) => {\n const from = param.from;\n const to = param.to;\n assert(from, 'missing \"from\" param for drag and drop');\n assert(to, 'missing \"to\" param for drag and drop');\n await page.mouse.drag(\n {\n x: from.center[0],\n y: from.center[1],\n },\n {\n x: to.center[0],\n y: to.center[1],\n },\n );\n },\n } as DeviceAction<{\n from: MidsceneLocationResultType;\n to: MidsceneLocationResultType;\n }>,\n];\n"],"names":["debugProfile","getDebug","commonContextParser","page","assert","url","uploadTestInfoToServer","screenshotBase64","size","resizeImgBase64","getReportFileName","tag","reportTagName","getAIConfig","MIDSCENE_REPORT_TAG_NAME","dateTimeInFileName","dayjs","uniqueId","uuid","printReportMsg","filepath","logMsg","getCurrentExecutionFile","trace","error","Error","stackTrace","pkgDir","process","stackLines","line","match","targetFileName","testFileIndex","Map","generateCacheId","fileName","taskFile","console","currentIndex","undefined","matchElementFromPlan","planLocateParam","tree","getNodeFromCacheList","centerPosition","Math","element","elementByPositionWithElementInfo","generateElementByPosition","matchElementFromCache","taskExecutor","xpaths","cachePrompt","cacheable","_taskExecutor_taskCache","i","cacheDebug","trimContextByViewport","execution","filterVisibleTree","node","filteredChildren","Array","child","task","_task_pageContext","newTask","getMidsceneVersion","__VERSION__","parsePrompt","prompt","commonWebActionsForWebPage","z","getMidsceneLocationSchema","param","keys","getKeyCommands","startingPoint","scrollToEventName","JSON","sleep","from","to"],"mappings":";;;;;;;;;;;AAkCA,MAAMA,eAAeC,SAAS;AACXA,SAAS;AAErB,eAAeC,oBACpBC,IAAkB;IAElBC,OAAOD,MAAM;IAEbH,aAAa;I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A,IAAAA,MAAO,SAAS,AAAD,MAAM,UAAWA,SAAUA,MAAM,SAAS,EAEtD,IAAIA,AAAoB,SAApBA,MAAM,SAAS,EACxB,MAAMxE,KAAK,QAAQ,CAACwE,MAAM,QAAQ,IAAInC,QAAWsC;yBAC5C,IAAIH,AAAoB,WAApBA,MAAM,SAAS,EACxB,MAAMxE,KAAK,UAAU,CAACwE,MAAM,QAAQ,IAAInC,QAAWsC;yBAC9C,IAAIH,AAAoB,YAApBA,MAAM,SAAS,EACxB,MAAMxE,KAAK,WAAW,CAACwE,MAAM,QAAQ,IAAInC,QAAWsC;yBAEpD,MAAM,IAAIrD,MAAM,CAAC,0BAA0B,EAAEkD,MAAM,SAAS,EAAE;yBAR9D,MAAMxE,KAAK,UAAU,CAACwE,AAAAA,CAAAA,QAAAA,QAAAA,KAAAA,IAAAA,MAAO,QAAQ,AAAD,KAAKnC,QAAWsC;oBAWtD,MAAMG,MAAM;gBACd;YAOF;QACF;QAYA;YACE,MAAM;YACN,aAAa;YACb,aAAaR,EAAE,MAAM,CAAC;gBACpB,MAAMC,4BAA4B,QAAQ,CAAC;gBAC3C,IAAIA,4BAA4B,QAAQ,CAAC;YAC3C;YACA,MAAM,OAAOC;gBACX,MAAMO,OAAOP,MAAM,IAAI;gBACvB,MAAMQ,KAAKR,MAAM,EAAE;gBACnBvE,OAAO8E,MAAM;gBACb9E,OAAO+E,IAAI;gBACX,MAAMhF,KAAK,KAAK,CAAC,IAAI,CACnB;oBACE,GAAG+E,KAAK,MAAM,CAAC,EAAE;oBACjB,GAAGA,KAAK,MAAM,CAAC,EAAE;gBACnB,GACA;oBACE,GAAGC,GAAG,MAAM,CAAC,EAAE;oBACf,GAAGA,GAAG,MAAM,CAAC,EAAE;gBACjB;YAEJ;QACF;KAID"}
1
+ {"version":3,"file":"agent/utils.mjs","sources":["webpack://@midscene/core/./src/agent/utils.ts"],"sourcesContent":["import { elementByPositionWithElementInfo } from '@/ai-model';\nimport type { AbstractPage } from '@/device';\nimport type {\n BaseElement,\n DeviceAction,\n ElementTreeNode,\n ExecutionDump,\n ExecutionTask,\n ExecutorContext,\n MidsceneLocationResultType,\n PlanningLocateParam,\n TMultimodalPrompt,\n TUserPrompt,\n UIContext,\n} from '@/index';\nimport { getMidsceneLocationSchema, z } from '@/index';\nimport { sleep, uploadTestInfoToServer } from '@/utils';\nimport { MIDSCENE_REPORT_TAG_NAME, getAIConfig } from '@midscene/shared/env';\nimport type { ElementInfo } from '@midscene/shared/extractor';\nimport {\n generateElementByPosition,\n getNodeFromCacheList,\n} from '@midscene/shared/extractor';\nimport { resizeImgBase64 } from '@midscene/shared/img';\nimport { getDebug } from '@midscene/shared/logger';\nimport { _keyDefinitions } from '@midscene/shared/us-keyboard-layout';\nimport { assert, logMsg, uuid } from '@midscene/shared/utils';\nimport dayjs from 'dayjs';\nimport { debug as cacheDebug } from './task-cache';\nimport type { PageTaskExecutor } from './tasks';\nimport { getKeyCommands } from './ui-utils';\n\nconst debugProfile = getDebug('web:tool:profile');\nconst debugUtils = getDebug('web:tool:utils');\n\nexport async function commonContextParser(\n page: AbstractPage,\n): Promise<UIContext> {\n assert(page, 'page is required');\n\n debugProfile('Getting page URL');\n const url = await page.url();\n debugProfile('URL end');\n\n debugProfile('Uploading test info to server');\n uploadTestInfoToServer({ testUrl: url });\n debugProfile('UploadTestInfoToServer end');\n\n let screenshotBase64 = await page.screenshotBase64();\n assert(screenshotBase64!, 'screenshotBase64 is required');\n\n const size = await page.size();\n debugProfile(`size: ${size.width}x${size.height} dpr: ${size.dpr}`);\n\n if (size.dpr && size.dpr > 1) {\n debugProfile('Resizing screenshot for high DPR display');\n screenshotBase64 = await resizeImgBase64(screenshotBase64, {\n width: size.width,\n height: size.height,\n });\n debugProfile('ResizeImgBase64 end');\n }\n\n return {\n tree: {\n node: null,\n children: [],\n },\n size,\n screenshotBase64: screenshotBase64!,\n url,\n };\n}\n\nexport function getReportFileName(tag = 'web') {\n const reportTagName = getAIConfig(MIDSCENE_REPORT_TAG_NAME);\n const dateTimeInFileName = dayjs().format('YYYY-MM-DD_HH-mm-ss');\n // ensure uniqueness at the same time\n const uniqueId = uuid().substring(0, 8);\n return `${reportTagName || tag}-${dateTimeInFileName}-${uniqueId}`;\n}\n\nexport function printReportMsg(filepath: string) {\n logMsg(`Midscene - report file updated: ${filepath}`);\n}\n\n/**\n * Get the current execution file name\n * @returns The name of the current execution file\n */\nexport function getCurrentExecutionFile(trace?: string): string | false {\n const error = new Error();\n const stackTrace = trace || error.stack;\n const pkgDir = process.cwd() || '';\n if (stackTrace) {\n const stackLines = stackTrace.split('\\n');\n for (const line of stackLines) {\n if (\n line.includes('.spec.') ||\n line.includes('.test.') ||\n line.includes('.ts') ||\n line.includes('.js')\n ) {\n const match = line.match(/(?:at\\s+)?(.*?\\.(?:spec|test)\\.[jt]s)/);\n if (match?.[1]) {\n const targetFileName = match[1]\n .replace(pkgDir, '')\n .trim()\n .replace('at ', '');\n return targetFileName;\n }\n }\n }\n }\n return false;\n}\n\nconst testFileIndex = new Map<string, number>();\n\nexport function generateCacheId(fileName?: string): string {\n let taskFile = fileName || getCurrentExecutionFile();\n if (!taskFile) {\n taskFile = uuid();\n console.warn(\n 'Midscene - using random UUID for cache id. Cache may be invalid.',\n );\n }\n\n if (testFileIndex.has(taskFile)) {\n const currentIndex = testFileIndex.get(taskFile);\n if (currentIndex !== undefined) {\n testFileIndex.set(taskFile, currentIndex + 1);\n }\n } else {\n testFileIndex.set(taskFile, 1);\n }\n return `${taskFile}-${testFileIndex.get(taskFile)}`;\n}\n\nexport function matchElementFromPlan(\n planLocateParam: PlanningLocateParam,\n tree: ElementTreeNode<BaseElement>,\n) {\n if (!planLocateParam) {\n return undefined;\n }\n if (planLocateParam.id) {\n return getNodeFromCacheList(planLocateParam.id);\n }\n\n if (planLocateParam.bbox) {\n const centerPosition = {\n x: Math.floor((planLocateParam.bbox[0] + planLocateParam.bbox[2]) / 2),\n y: Math.floor((planLocateParam.bbox[1] + planLocateParam.bbox[3]) / 2),\n };\n let element = elementByPositionWithElementInfo(tree, centerPosition);\n\n if (!element) {\n element = generateElementByPosition(centerPosition) as BaseElement;\n }\n\n return element;\n }\n\n return undefined;\n}\n\nexport async function matchElementFromCache(\n taskExecutor: PageTaskExecutor,\n xpaths: string[] | undefined,\n cachePrompt: TUserPrompt,\n cacheable: boolean | undefined,\n) {\n try {\n if (\n xpaths?.length &&\n taskExecutor.taskCache?.isCacheResultUsed &&\n cacheable !== false &&\n (taskExecutor.page as any).getElementInfoByXpath\n ) {\n // hit cache, use new id\n for (let i = 0; i < xpaths.length; i++) {\n const element = await (taskExecutor.page as any).getElementInfoByXpath(\n xpaths[i],\n );\n\n if (element?.id) {\n cacheDebug('cache hit, prompt: %s', cachePrompt);\n cacheDebug(\n 'found a new element with same xpath, xpath: %s, id: %s',\n xpaths[i],\n element?.id,\n );\n return element;\n }\n }\n }\n } catch (error) {\n cacheDebug('get element info by xpath error: ', error);\n }\n}\n\nexport function trimContextByViewport(execution: ExecutionDump) {\n function filterVisibleTree(\n node: ElementTreeNode<BaseElement>,\n ): ElementTreeNode<BaseElement> | null {\n if (!node) return null;\n\n // recursively process all children\n const filteredChildren = Array.isArray(node.children)\n ? (node.children\n .map(filterVisibleTree)\n .filter((child) => child !== null) as ElementTreeNode<BaseElement>[])\n : [];\n\n // if the current node is visible, keep it and the filtered children\n if (node.node && node.node.isVisible === true) {\n return {\n ...node,\n children: filteredChildren,\n };\n }\n\n // if the current node is invisible, but has visible children, create an empty node to include these children\n if (filteredChildren.length > 0) {\n return {\n node: null,\n children: filteredChildren,\n };\n }\n\n // if the current node is invisible and has no visible children, return null\n return null;\n }\n\n return {\n ...execution,\n tasks: Array.isArray(execution.tasks)\n ? execution.tasks.map((task: ExecutionTask) => {\n const newTask = { ...task };\n if (task.pageContext?.tree) {\n newTask.pageContext = {\n ...task.pageContext,\n tree: filterVisibleTree(task.pageContext.tree) || {\n node: null,\n children: [],\n },\n };\n }\n return newTask;\n })\n : execution.tasks,\n };\n}\n\ndeclare const __VERSION__: string | undefined;\n\nexport const getMidsceneVersion = (): string => {\n if (typeof __VERSION__ !== 'undefined') {\n return __VERSION__;\n } else if (\n process.env.__VERSION__ &&\n process.env.__VERSION__ !== 'undefined'\n ) {\n return process.env.__VERSION__;\n }\n throw new Error('__VERSION__ inject failed during build');\n};\n\nexport const parsePrompt = (\n prompt: TUserPrompt,\n): {\n textPrompt: string;\n multimodalPrompt?: TMultimodalPrompt;\n} => {\n if (typeof prompt === 'string') {\n return {\n textPrompt: prompt,\n multimodalPrompt: undefined,\n };\n }\n return {\n textPrompt: prompt.prompt,\n multimodalPrompt: prompt.images\n ? {\n images: prompt.images,\n convertHttpImage2Base64: !!prompt.convertHttpImage2Base64,\n }\n : undefined,\n };\n};\n\nexport const commonWebActionsForWebPage = <T extends AbstractPage>(\n page: T,\n): DeviceAction<any>[] => [\n {\n name: 'Tap',\n description: 'Tap the element',\n interfaceAlias: 'aiTap',\n paramSchema: z.object({\n locate: getMidsceneLocationSchema().describe('The element to be tapped'),\n }),\n call: async (param) => {\n const element = param.locate;\n assert(element, 'Element not found, cannot tap');\n await page.mouse.click(element.center[0], element.center[1], {\n button: 'left',\n });\n },\n } as DeviceAction<{\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'RightClick',\n description: 'Right click the element',\n interfaceAlias: 'aiRightClick',\n paramSchema: z.object({\n locate: getMidsceneLocationSchema().describe(\n 'The element to be right clicked',\n ),\n }),\n call: async (param) => {\n const element = param.locate;\n assert(element, 'Element not found, cannot right click');\n await page.mouse.click(element.center[0], element.center[1], {\n button: 'right',\n });\n },\n } as DeviceAction<{\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'Hover',\n description: 'Move the mouse to the element',\n interfaceAlias: 'aiHover',\n paramSchema: z.object({\n locate: getMidsceneLocationSchema().describe('The element to be hovered'),\n }),\n call: async (param) => {\n const element = param.locate;\n assert(element, 'Element not found, cannot hover');\n await page.mouse.move(element.center[0], element.center[1]);\n },\n } as DeviceAction<{\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'Input',\n description:\n 'Replace the input field with a new value. `value` is the final that should be filled in the input box. No matter what modifications are required, just provide the final value to replace the existing input value. Giving a blank string means clear the input field.',\n interfaceAlias: 'aiInput',\n paramSchema: z.object({\n value: z\n .string()\n .describe('The final value that should be filled in the input box'),\n locate: getMidsceneLocationSchema()\n .describe('The input field to be filled')\n .optional(),\n }),\n call: async (param) => {\n const element = param.locate;\n if (element) {\n await page.clearInput(element as unknown as ElementInfo);\n\n if (!param || !param.value) {\n return;\n }\n }\n\n // Note: there is another implementation in AndroidDevicePage, which is more complex\n await page.keyboard.type(param.value);\n },\n } as DeviceAction<{\n value: string;\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'KeyboardPress',\n description:\n 'Press a function key, like \"Enter\", \"Tab\", \"Escape\". Do not use this to type text.',\n interfaceAlias: 'aiKeyboardPress',\n paramSchema: z.object({\n locate: getMidsceneLocationSchema()\n .describe('The element to be clicked before pressing the key')\n .optional(),\n keyName: z.string().describe('The key to be pressed'),\n }),\n call: async (param) => {\n const element = param.locate;\n if (element) {\n await page.mouse.click(element.center[0], element.center[1], {\n button: 'left',\n });\n }\n\n const keys = getKeyCommands(param.keyName);\n await page.keyboard.press(keys as any); // TODO: fix this type error\n },\n } as DeviceAction<{\n keyName: string;\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'Scroll',\n description:\n 'Scroll the page or an element. The direction to scroll, the scroll type, and the distance to scroll. The distance is the number of pixels to scroll. If not specified, use `down` direction, `once` scroll type, and `null` distance.',\n interfaceAlias: 'aiScroll',\n paramSchema: z.object({\n direction: z\n .enum(['down', 'up', 'right', 'left'])\n .default('down')\n .describe('The direction to scroll'),\n scrollType: z\n .enum(['once', 'untilBottom', 'untilTop', 'untilRight', 'untilLeft'])\n .default('once')\n .describe('The scroll type'),\n distance: z\n .number()\n .nullable()\n .optional()\n .describe('The distance in pixels to scroll'),\n locate: getMidsceneLocationSchema()\n .optional()\n .describe('The element to be scrolled'),\n }),\n call: async (param) => {\n const element = param.locate;\n const startingPoint = element\n ? {\n left: element.center[0],\n top: element.center[1],\n }\n : undefined;\n const scrollToEventName = param?.scrollType;\n if (scrollToEventName === 'untilTop') {\n await page.scrollUntilTop(startingPoint);\n } else if (scrollToEventName === 'untilBottom') {\n await page.scrollUntilBottom(startingPoint);\n } else if (scrollToEventName === 'untilRight') {\n await page.scrollUntilRight(startingPoint);\n } else if (scrollToEventName === 'untilLeft') {\n await page.scrollUntilLeft(startingPoint);\n } else if (scrollToEventName === 'once' || !scrollToEventName) {\n if (param?.direction === 'down' || !param || !param.direction) {\n await page.scrollDown(param?.distance || undefined, startingPoint);\n } else if (param.direction === 'up') {\n await page.scrollUp(param.distance || undefined, startingPoint);\n } else if (param.direction === 'left') {\n await page.scrollLeft(param.distance || undefined, startingPoint);\n } else if (param.direction === 'right') {\n await page.scrollRight(param.distance || undefined, startingPoint);\n } else {\n throw new Error(`Unknown scroll direction: ${param.direction}`);\n }\n // until mouse event is done\n await sleep(500);\n } else {\n throw new Error(\n `Unknown scroll event type: ${scrollToEventName}, param: ${JSON.stringify(\n param,\n )}`,\n );\n }\n },\n } as DeviceAction<{\n scrollType:\n | 'once'\n | 'untilBottom'\n | 'untilTop'\n | 'untilRight'\n | 'untilLeft';\n direction: 'up' | 'down';\n distance?: number;\n duration?: number;\n locate: MidsceneLocationResultType;\n }>,\n {\n name: 'DragAndDrop',\n description: 'Drag and drop the element',\n paramSchema: z.object({\n from: getMidsceneLocationSchema().describe('The position to be dragged'),\n to: getMidsceneLocationSchema().describe('The position to be dropped'),\n }),\n call: async (param) => {\n const from = param.from;\n const to = param.to;\n assert(from, 'missing \"from\" param for drag and drop');\n assert(to, 'missing \"to\" param for drag and drop');\n await page.mouse.drag(\n {\n x: from.center[0],\n y: from.center[1],\n },\n {\n x: to.center[0],\n y: to.center[1],\n },\n );\n },\n } as DeviceAction<{\n from: MidsceneLocationResultType;\n to: MidsceneLocationResultType;\n }>,\n];\n"],"names":["debugProfile","getDebug","commonContextParser","page","assert","url","uploadTestInfoToServer","screenshotBase64","size","resizeImgBase64","getReportFileName","tag","reportTagName","getAIConfig","MIDSCENE_REPORT_TAG_NAME","dateTimeInFileName","dayjs","uniqueId","uuid","printReportMsg","filepath","logMsg","getCurrentExecutionFile","trace","error","Error","stackTrace","pkgDir","process","stackLines","line","match","targetFileName","testFileIndex","Map","generateCacheId","fileName","taskFile","console","currentIndex","undefined","matchElementFromPlan","planLocateParam","tree","getNodeFromCacheList","centerPosition","Math","element","elementByPositionWithElementInfo","generateElementByPosition","matchElementFromCache","taskExecutor","xpaths","cachePrompt","cacheable","_taskExecutor_taskCache","i","cacheDebug","trimContextByViewport","execution","filterVisibleTree","node","filteredChildren","Array","child","task","_task_pageContext","newTask","getMidsceneVersion","__VERSION__","parsePrompt","prompt","commonWebActionsForWebPage","z","getMidsceneLocationSchema","param","keys","getKeyCommands","startingPoint","scrollToEventName","JSON","sleep","from","to"],"mappings":";;;;;;;;;;;AAgCA,MAAMA,eAAeC,SAAS;AACXA,SAAS;AAErB,eAAeC,oBACpBC,IAAkB;IAElBC,OAAOD,MAAM;IAEbH,aAAa;IACb,MAAMK,MAAM,MAAMF,KAAK,GAAG;IAC1BH,aAAa;IAEbA,aAAa;IACbM,uBAAuB;QAAE,SAASD;IAAI;IACtCL,aAAa;IAEb,IAAIO,mBAAmB,MAAMJ,KAAK,gBAAgB;IAClDC,OAAOG,kBAAmB;IAE1B,MAAMC,OAAO,MAAML,KAAK,IAAI;IAC5BH,aAAa,CAAC,MAAM,EAAEQ,KAAK,KAAK,CAAC,CAAC,EAAEA,KAAK,MAAM,CAAC,MAAM,EAAEA,KAAK,GAAG,EAAE;IAElE,IAAIA,KAAK,GAAG,IAAIA,KAAK,GAAG,GAAG,GAAG;QAC5BR,aAAa;QACbO,mBAAmB,MAAME,gBAAgBF,kBAAkB;YACzD,OAAOC,KAAK,KAAK;YACjB,QAAQA,KAAK,MAAM;QACrB;QACAR,aAAa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