{"version":3,"file":"common/cache-helper.mjs","sources":["../../../src/common/cache-helper.ts"],"sourcesContent":["import type { ElementCacheFeature, Point, Rect } from '@midscene/core';\nimport { AiJudgeOrderSensitive } from '@midscene/core/ai-model';\nimport type { ModelRuntime } from '@midscene/core/ai-model';\nimport type { DebugFunction } from '@midscene/shared/logger';\n\n// Shared type for web element cache feature\nexport type WebElementCacheFeature = ElementCacheFeature & {\n  xpaths?: string[];\n};\n\n// Shared function to sanitize xpaths\nexport const sanitizeXpaths = (xpaths: unknown): string[] => {\n  if (!Array.isArray(xpaths)) {\n    return [];\n  }\n\n  return xpaths.filter(\n    (xpath): xpath is string => typeof xpath === 'string' && xpath.length > 0,\n  );\n};\n\n// Cache feature extraction options interface\nexport interface CacheFeatureOptions {\n  targetDescription?: string;\n  modelRuntime?: ModelRuntime;\n}\n\n// Shared logic for judging isOrderSensitive\nexport async function judgeOrderSensitive(\n  options: CacheFeatureOptions | undefined,\n  debug: DebugFunction,\n): Promise<boolean> {\n  if (!options?.targetDescription || !options?.modelRuntime) {\n    return false;\n  }\n  try {\n    const judgeResult = await AiJudgeOrderSensitive(\n      options.targetDescription,\n      options.modelRuntime,\n    );\n    debug(\n      'judged isOrderSensitive=%s for description: %s',\n      judgeResult.isOrderSensitive,\n      options.targetDescription,\n    );\n    return judgeResult.isOrderSensitive;\n  } catch (error) {\n    debug('Failed to judge isOrderSensitive: %O', error);\n    return false;\n  }\n}\n\n// Shared logic to build Rect from elementInfo\nexport function buildRectFromElementInfo(elementInfo: {\n  rect: { left: number; top: number; width: number; height: number };\n}): Rect {\n  const matchedRect: Rect = {\n    left: elementInfo.rect.left,\n    top: elementInfo.rect.top,\n    width: elementInfo.rect.width,\n    height: elementInfo.rect.height,\n  };\n  return matchedRect;\n}\n"],"names":["sanitizeXpaths","xpaths","Array","xpath","judgeOrderSensitive","options","debug","judgeResult","AiJudgeOrderSensitive","error","buildRectFromElementInfo","elementInfo","matchedRect"],"mappings":";AAWO,MAAMA,iBAAiB,CAACC;IAC7B,IAAI,CAACC,MAAM,OAAO,CAACD,SACjB,OAAO,EAAE;IAGX,OAAOA,OAAO,MAAM,CAClB,CAACE,QAA2B,AAAiB,YAAjB,OAAOA,SAAsBA,MAAM,MAAM,GAAG;AAE5E;AASO,eAAeC,oBACpBC,OAAwC,EACxCC,KAAoB;IAEpB,IAAI,CAACD,SAAS,qBAAqB,CAACA,SAAS,cAC3C,OAAO;IAET,IAAI;QACF,MAAME,cAAc,MAAMC,sBACxBH,QAAQ,iBAAiB,EACzBA,QAAQ,YAAY;QAEtBC,MACE,kDACAC,YAAY,gBAAgB,EAC5BF,QAAQ,iBAAiB;QAE3B,OAAOE,YAAY,gBAAgB;IACrC,EAAE,OAAOE,OAAO;QACdH,MAAM,wCAAwCG;QAC9C,OAAO;IACT;AACF;AAGO,SAASC,yBAAyBC,WAExC;IACC,MAAMC,cAAoB;QACxB,MAAMD,YAAY,IAAI,CAAC,IAAI;QAC3B,KAAKA,YAAY,IAAI,CAAC,GAAG;QACzB,OAAOA,YAAY,IAAI,CAAC,KAAK;QAC7B,QAAQA,YAAY,IAAI,CAAC,MAAM;IACjC;IACA,OAAOC;AACT"}