{"version":3,"file":"ai-model/prompt/llm-section-locator.mjs","sources":["../../../../src/ai-model/prompt/llm-section-locator.ts"],"sourcesContent":["import { getPreferredLanguage } from '@midscene/shared/env';\nimport type { LocateResultPromptSpec } from '../shared/model-locate-result';\nimport { formatLocateExampleValue } from './locate-param-example';\n\nexport function systemPromptToLocateSection(\n  promptSpec: LocateResultPromptSpec,\n) {\n  const preferredLanguage = getPreferredLanguage();\n  const resultKey = promptSpec.resultKey;\n  const exampleValueText = formatLocateExampleValue(\n    promptSpec.exampleValues[0],\n  );\n  const resultJsonProperty = `\"${resultKey}\": ${promptSpec.resultValueSchema},  // ${promptSpec.resultValueDescription}`;\n  const resultValueType = promptSpec.resultValueSchema;\n  const resultFieldDescription = `${promptSpec.resultNoun} of the section containing the target element`;\n  const referenceFieldDescription = `Optional array of ${promptSpec.resultNounPlural} of reference elements`;\n  return `\n## Role:\nYou are an AI assistant that helps identify UI elements.\n\n## Objective:\n- Find a section containing the target element\n- If the description mentions reference elements, also locate sections containing those references\n\n## Output Format:\n\\`\\`\\`json\n{\n  ${resultJsonProperty}\n  \"references_${resultKey}\"?: [\n    ${resultValueType},\n    ...\n  ],\n  \"error\"?: string\n}\n\\`\\`\\`\n\nFields:\n* \\`${resultKey}\\` - ${resultFieldDescription}\n* \\`references_${resultKey}\\` - ${referenceFieldDescription}\n* \\`error\\` - Optional error message if the section cannot be found. Use ${preferredLanguage}.\n\nExample:\nIf the description is \"delete button on the second row with title 'Peter'\", return:\n\\`\\`\\`json\n{\n  \"${resultKey}\": ${exampleValueText},\n  \"references_${resultKey}\": [${exampleValueText}]\n}\n\\`\\`\\`\n`;\n}\n\nexport const sectionLocatorInstruction = (sectionDescription: string) =>\n  `Find section containing: ${sectionDescription}`;\n"],"names":["systemPromptToLocateSection","promptSpec","preferredLanguage","getPreferredLanguage","resultKey","exampleValueText","formatLocateExampleValue","resultJsonProperty","resultValueType","resultFieldDescription","referenceFieldDescription","sectionLocatorInstruction","sectionDescription"],"mappings":";;AAIO,SAASA,4BACdC,UAAkC;IAElC,MAAMC,oBAAoBC;IAC1B,MAAMC,YAAYH,WAAW,SAAS;IACtC,MAAMI,mBAAmBC,yBACvBL,WAAW,aAAa,CAAC,EAAE;IAE7B,MAAMM,qBAAqB,CAAC,CAAC,EAAEH,UAAU,GAAG,EAAEH,WAAW,iBAAiB,CAAC,MAAM,EAAEA,WAAW,sBAAsB,EAAE;IACtH,MAAMO,kBAAkBP,WAAW,iBAAiB;IACpD,MAAMQ,yBAAyB,GAAGR,WAAW,UAAU,CAAC,6CAA6C,CAAC;IACtG,MAAMS,4BAA4B,CAAC,kBAAkB,EAAET,WAAW,gBAAgB,CAAC,sBAAsB,CAAC;IAC1G,OAAO,CAAC;;;;;;;;;;;EAWR,EAAEM,mBAAmB;cACT,EAAEH,UAAU;IACtB,EAAEI,gBAAgB;;;;;;;;IAQlB,EAAEJ,UAAU,KAAK,EAAEK,uBAAuB;eAC/B,EAAEL,UAAU,KAAK,EAAEM,0BAA0B;yEACa,EAAER,kBAAkB;;;;;;GAM1F,EAAEE,UAAU,GAAG,EAAEC,iBAAiB;cACvB,EAAED,UAAU,IAAI,EAAEC,iBAAiB;;;AAGjD,CAAC;AACD;AAEO,MAAMM,4BAA4B,CAACC,qBACxC,CAAC,yBAAyB,EAAEA,oBAAoB"}