1- import { elementByPositionWithElementInfo } from '@/ai-model' ;
21import type { TMultimodalPrompt , TUserPrompt } from '@/ai-model/common' ;
32import type { AbstractInterface } from '@/device' ;
43import type {
5- BaseElement ,
64 ElementCacheFeature ,
7- ElementTreeNode ,
8- ExecutionDump ,
9- ExecutionTask ,
10- ExecutorContext ,
115 LocateResultElement ,
126 PlanningLocateParam ,
137 UIContext ,
148} from '@/types' ;
159import { uploadTestInfoToServer } from '@/utils' ;
16- import { NodeType } from '@midscene/shared/constants' ;
1710import {
1811 MIDSCENE_REPORT_TAG_NAME ,
1912 globalConfigManager ,
2013} from '@midscene/shared/env' ;
21- import {
22- generateElementByPosition ,
23- getNodeFromCacheList ,
24- } from '@midscene/shared/extractor' ;
14+ import { generateElementByPosition } from '@midscene/shared/extractor' ;
2515import { getDebug } from '@midscene/shared/logger' ;
2616import { _keyDefinitions } from '@midscene/shared/us-keyboard-layout' ;
2717import { assert , logMsg , uuid } from '@midscene/shared/utils' ;
@@ -55,10 +45,6 @@ export async function commonContextParser(
5545 debugProfile ( `size: ${ size . width } x${ size . height } dpr: ${ size . dpr } ` ) ;
5646
5747 return {
58- tree : {
59- node : null ,
60- children : [ ] ,
61- } ,
6248 size,
6349 screenshotBase64 : screenshotBase64 ! ,
6450 } ;
@@ -133,26 +119,18 @@ export function generateCacheId(fileName?: string): string {
133119
134120export function matchElementFromPlan (
135121 planLocateParam : PlanningLocateParam ,
136- tree : ElementTreeNode < BaseElement > ,
137- ) {
122+ ) : LocateResultElement | undefined {
138123 if ( ! planLocateParam ) {
139124 return undefined ;
140125 }
141- if ( planLocateParam . id ) {
142- return getNodeFromCacheList ( planLocateParam . id ) ;
143- }
144126
145127 if ( planLocateParam . bbox ) {
146128 const centerPosition = {
147129 x : Math . floor ( ( planLocateParam . bbox [ 0 ] + planLocateParam . bbox [ 2 ] ) / 2 ) ,
148130 y : Math . floor ( ( planLocateParam . bbox [ 1 ] + planLocateParam . bbox [ 3 ] ) / 2 ) ,
149131 } ;
150- let element = elementByPositionWithElementInfo ( tree , centerPosition ) ;
151-
152- if ( ! element ) {
153- element = generateElementByPosition ( centerPosition ) as BaseElement ;
154- }
155132
133+ const element = generateElementByPosition ( centerPosition ) ;
156134 return element ;
157135 }
158136
@@ -198,10 +176,6 @@ export async function matchElementFromCache(
198176 Math . round ( rect . top + rect . height / 2 ) ,
199177 ] ,
200178 rect,
201- xpaths : [ ] ,
202- attributes : {
203- nodeType : NodeType . POSITION ,
204- } ,
205179 } ;
206180
207181 cacheDebug ( 'cache hit, prompt: %s' , cachePrompt ) ;
@@ -212,59 +186,6 @@ export async function matchElementFromCache(
212186 }
213187}
214188
215- export function trimContextByViewport ( execution : ExecutionDump ) {
216- function filterVisibleTree (
217- node : ElementTreeNode < BaseElement > ,
218- ) : ElementTreeNode < BaseElement > | null {
219- if ( ! node ) return null ;
220-
221- // recursively process all children
222- const filteredChildren = Array . isArray ( node . children )
223- ? ( node . children
224- . map ( filterVisibleTree )
225- . filter ( ( child ) => child !== null ) as ElementTreeNode < BaseElement > [ ] )
226- : [ ] ;
227-
228- // if the current node is visible, keep it and the filtered children
229- if ( node . node && node . node . isVisible === true ) {
230- return {
231- ...node ,
232- children : filteredChildren ,
233- } ;
234- }
235-
236- // if the current node is invisible, but has visible children, create an empty node to include these children
237- if ( filteredChildren . length > 0 ) {
238- return {
239- node : null ,
240- children : filteredChildren ,
241- } ;
242- }
243-
244- // if the current node is invisible and has no visible children, return null
245- return null ;
246- }
247-
248- return {
249- ...execution ,
250- tasks : Array . isArray ( execution . tasks )
251- ? execution . tasks . map ( ( task : ExecutionTask ) => {
252- const newTask = { ...task } ;
253- if ( task . uiContext ?. tree ) {
254- newTask . uiContext = {
255- ...task . uiContext ,
256- tree : filterVisibleTree ( task . uiContext . tree ) || {
257- node : null ,
258- children : [ ] ,
259- } ,
260- } ;
261- }
262- return newTask ;
263- } )
264- : execution . tasks ,
265- } ;
266- }
267-
268189declare const __VERSION__ : string | undefined ;
269190
270191export const getMidsceneVersion = ( ) : string => {
0 commit comments