@@ -23,7 +23,11 @@ import { generateElementByPosition } from '@midscene/shared/extractor';
2323import { getDebug } from '@midscene/shared/logger' ;
2424import { assert } from '@midscene/shared/utils' ;
2525import type { TaskCache } from './task-cache' ;
26- import { matchElementFromCache , matchElementFromPlan } from './utils' ;
26+ import {
27+ ifPlanLocateParamIsBbox ,
28+ matchElementFromCache ,
29+ matchElementFromPlan ,
30+ } from './utils' ;
2731
2832const debug = getDebug ( 'agent:task-builder' ) ;
2933
@@ -201,22 +205,33 @@ export class TaskBuilder {
201205
202206 locateFields . forEach ( ( field ) => {
203207 if ( param [ field ] ) {
204- const locatePlan = locatePlanForLocate ( param [ field ] ) ;
205- debug (
206- 'will prepend locate param for field' ,
207- `action.type=${ planType } ` ,
208- `param=${ JSON . stringify ( param [ field ] ) } ` ,
209- `locatePlan=${ JSON . stringify ( locatePlan ) } ` ,
210- ) ;
211- const locateTask = this . createLocateTask (
212- locatePlan ,
213- param [ field ] ,
214- context ,
215- ( result ) => {
216- param [ field ] = result ;
217- } ,
218- ) ;
219- context . tasks . push ( locateTask ) ;
208+ if ( ifPlanLocateParamIsBbox ( param [ field ] ) ) {
209+ debug (
210+ 'plan locate param is bbox, will match element from plan' ,
211+ param [ field ] ,
212+ ) ;
213+ const elementFromPlan = matchElementFromPlan ( param [ field ] ) ;
214+ if ( elementFromPlan ) {
215+ param [ field ] = elementFromPlan ;
216+ }
217+ } else {
218+ const locatePlan = locatePlanForLocate ( param [ field ] ) ;
219+ debug (
220+ 'will prepend locate param for field' ,
221+ `action.type=${ planType } ` ,
222+ `param=${ JSON . stringify ( param [ field ] ) } ` ,
223+ `locatePlan=${ JSON . stringify ( locatePlan ) } ` ,
224+ ) ;
225+ const locateTask = this . createLocateTask (
226+ locatePlan ,
227+ param [ field ] ,
228+ context ,
229+ ( result ) => {
230+ param [ field ] = result ;
231+ } ,
232+ ) ;
233+ context . tasks . push ( locateTask ) ;
234+ }
220235 } else {
221236 assert (
222237 ! requiredLocateFields . includes ( field ) ,
@@ -419,11 +434,7 @@ export class TaskBuilder {
419434 ) ;
420435 const cacheHitFlag = ! ! elementFromCache ;
421436
422- const elementFromPlan =
423- ! userExpectedPathHitFlag && ! cacheHitFlag
424- ? matchElementFromPlan ( param )
425- : undefined ;
426- const planHitFlag = ! ! elementFromPlan ;
437+ const planHitFlag = false ;
427438
428439 let elementFromAiLocate : LocateResultElement | null | undefined ;
429440 if ( ! userExpectedPathHitFlag && ! cacheHitFlag && ! planHitFlag ) {
@@ -446,10 +457,7 @@ export class TaskBuilder {
446457 }
447458
448459 const element =
449- elementFromXpath ||
450- elementFromCache ||
451- elementFromPlan ||
452- elementFromAiLocate ;
460+ elementFromXpath || elementFromCache || elementFromAiLocate ;
453461
454462 let currentCacheEntry : ElementCacheFeature | undefined ;
455463 if (
@@ -526,13 +534,6 @@ export class TaskBuilder {
526534 cacheToSave : currentCacheEntry ,
527535 } ,
528536 } ;
529- } else if ( planHitFlag ) {
530- hitBy = {
531- from : 'Planning' ,
532- context : {
533- rect : elementFromPlan ?. rect ,
534- } ,
535- } ;
536537 }
537538
538539 onResult ?.( element ) ;
0 commit comments