{"version":3,"file":"ai-model/prompt/llm-locator.mjs","sources":["../../../../src/ai-model/prompt/llm-locator.ts"],"sourcesContent":["import { getPreferredLanguage } from '@midscene/shared/env';\nimport type { LocateResultPromptSpec } from '../shared/model-locate-result';\nimport { locateGroundingRules } from './locate-grounding-rules';\nimport { formatLocateExampleValue } from './locate-param-example';\n\nexport function systemPromptToLocateElement(\n  promptSpec: LocateResultPromptSpec,\n) {\n  const preferredLanguage = getPreferredLanguage();\n  const resultKey = promptSpec.resultKey;\n  const exampleValueText = formatLocateExampleValue(\n    promptSpec.exampleValues[0],\n  );\n  const resultFieldDescription = `the ${promptSpec.resultNoun} of the element that matches the user's description`;\n  return `\n## Role:\nYou are an AI assistant that helps identify UI elements.\n\n## Objective:\n- Identify elements in screenshots that match the user's description.\n- Provide the coordinates of the element that matches the user's description.\n\n${locateGroundingRules()}\n\n## Output Format:\n\\`\\`\\`json\n{\n  \"${resultKey}\": ${promptSpec.resultValueSchema},  // ${promptSpec.resultValueDescription}\n  \"errors\"?: string[]\n}\n\\`\\`\\`\n\nFields:\n* \\`${resultKey}\\` is ${resultFieldDescription}\n* \\`errors\\` is an optional array of error messages (if any)\n\nFor example, when an element is found:\n\\`\\`\\`json\n{\n  \"${resultKey}\": ${exampleValueText},\n  \"errors\": []\n}\n\\`\\`\\`\n\nWhen no element is found:\n\\`\\`\\`json\n{\n  \"${resultKey}\": [],\n  \"errors\": [\"I can see ..., but {some element} is not found. Use ${preferredLanguage}.\"]\n}\n\\`\\`\\`\n`;\n}\n\nexport const findElementPrompt = (targetElementDescription: string) =>\n  `Find: ${targetElementDescription}`;\n"],"names":["systemPromptToLocateElement","promptSpec","preferredLanguage","getPreferredLanguage","resultKey","exampleValueText","formatLocateExampleValue","resultFieldDescription","locateGroundingRules","findElementPrompt","targetElementDescription"],"mappings":";;;AAKO,SAASA,4BACdC,UAAkC;IAElC,MAAMC,oBAAoBC;IAC1B,MAAMC,YAAYH,WAAW,SAAS;IACtC,MAAMI,mBAAmBC,yBACvBL,WAAW,aAAa,CAAC,EAAE;IAE7B,MAAMM,yBAAyB,CAAC,IAAI,EAAEN,WAAW,UAAU,CAAC,mDAAmD,CAAC;IAChH,OAAO,CAAC;;;;;;;;AAQV,EAAEO,uBAAuB;;;;;GAKtB,EAAEJ,UAAU,GAAG,EAAEH,WAAW,iBAAiB,CAAC,MAAM,EAAEA,WAAW,sBAAsB,CAAC;;;;;;IAMvF,EAAEG,UAAU,MAAM,EAAEG,uBAAuB;;;;;;GAM5C,EAAEH,UAAU,GAAG,EAAEC,iBAAiB;;;;;;;;GAQlC,EAAED,UAAU;kEACmD,EAAEF,kBAAkB;;;AAGtF,CAAC;AACD;AAEO,MAAMO,oBAAoB,CAACC,2BAChC,CAAC,MAAM,EAAEA,0BAA0B"}