@sqaitech/core 0.30.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -0
  3. package/dist/es/agent/agent.mjs +635 -0
  4. package/dist/es/agent/agent.mjs.map +1 -0
  5. package/dist/es/agent/common.mjs +0 -0
  6. package/dist/es/agent/index.mjs +6 -0
  7. package/dist/es/agent/task-cache.mjs +184 -0
  8. package/dist/es/agent/task-cache.mjs.map +1 -0
  9. package/dist/es/agent/tasks.mjs +663 -0
  10. package/dist/es/agent/tasks.mjs.map +1 -0
  11. package/dist/es/agent/ui-utils.mjs +72 -0
  12. package/dist/es/agent/ui-utils.mjs.map +1 -0
  13. package/dist/es/agent/utils.mjs +162 -0
  14. package/dist/es/agent/utils.mjs.map +1 -0
  15. package/dist/es/ai-model/action-executor.mjs +129 -0
  16. package/dist/es/ai-model/action-executor.mjs.map +1 -0
  17. package/dist/es/ai-model/common.mjs +355 -0
  18. package/dist/es/ai-model/common.mjs.map +1 -0
  19. package/dist/es/ai-model/conversation-history.mjs +58 -0
  20. package/dist/es/ai-model/conversation-history.mjs.map +1 -0
  21. package/dist/es/ai-model/index.mjs +11 -0
  22. package/dist/es/ai-model/inspect.mjs +286 -0
  23. package/dist/es/ai-model/inspect.mjs.map +1 -0
  24. package/dist/es/ai-model/llm-planning.mjs +140 -0
  25. package/dist/es/ai-model/llm-planning.mjs.map +1 -0
  26. package/dist/es/ai-model/prompt/assertion.mjs +31 -0
  27. package/dist/es/ai-model/prompt/assertion.mjs.map +1 -0
  28. package/dist/es/ai-model/prompt/common.mjs +7 -0
  29. package/dist/es/ai-model/prompt/common.mjs.map +1 -0
  30. package/dist/es/ai-model/prompt/describe.mjs +44 -0
  31. package/dist/es/ai-model/prompt/describe.mjs.map +1 -0
  32. package/dist/es/ai-model/prompt/extraction.mjs +129 -0
  33. package/dist/es/ai-model/prompt/extraction.mjs.map +1 -0
  34. package/dist/es/ai-model/prompt/llm-locator.mjs +268 -0
  35. package/dist/es/ai-model/prompt/llm-locator.mjs.map +1 -0
  36. package/dist/es/ai-model/prompt/llm-planning.mjs +367 -0
  37. package/dist/es/ai-model/prompt/llm-planning.mjs.map +1 -0
  38. package/dist/es/ai-model/prompt/llm-section-locator.mjs +41 -0
  39. package/dist/es/ai-model/prompt/llm-section-locator.mjs.map +1 -0
  40. package/dist/es/ai-model/prompt/playwright-generator.mjs +117 -0
  41. package/dist/es/ai-model/prompt/playwright-generator.mjs.map +1 -0
  42. package/dist/es/ai-model/prompt/ui-tars-locator.mjs +34 -0
  43. package/dist/es/ai-model/prompt/ui-tars-locator.mjs.map +1 -0
  44. package/dist/es/ai-model/prompt/ui-tars-planning.mjs +36 -0
  45. package/dist/es/ai-model/prompt/ui-tars-planning.mjs.map +1 -0
  46. package/dist/es/ai-model/prompt/util.mjs +124 -0
  47. package/dist/es/ai-model/prompt/util.mjs.map +1 -0
  48. package/dist/es/ai-model/prompt/yaml-generator.mjs +219 -0
  49. package/dist/es/ai-model/prompt/yaml-generator.mjs.map +1 -0
  50. package/dist/es/ai-model/service-caller/index.mjs +388 -0
  51. package/dist/es/ai-model/service-caller/index.mjs.map +1 -0
  52. package/dist/es/ai-model/ui-tars-planning.mjs +201 -0
  53. package/dist/es/ai-model/ui-tars-planning.mjs.map +1 -0
  54. package/dist/es/device/index.mjs +152 -0
  55. package/dist/es/device/index.mjs.map +1 -0
  56. package/dist/es/image/index.mjs +2 -0
  57. package/dist/es/index.mjs +11 -0
  58. package/dist/es/index.mjs.map +1 -0
  59. package/dist/es/insight/index.mjs +231 -0
  60. package/dist/es/insight/index.mjs.map +1 -0
  61. package/dist/es/insight/utils.mjs +15 -0
  62. package/dist/es/insight/utils.mjs.map +1 -0
  63. package/dist/es/report.mjs +88 -0
  64. package/dist/es/report.mjs.map +1 -0
  65. package/dist/es/tree.mjs +2 -0
  66. package/dist/es/types.mjs +11 -0
  67. package/dist/es/types.mjs.map +1 -0
  68. package/dist/es/utils.mjs +202 -0
  69. package/dist/es/utils.mjs.map +1 -0
  70. package/dist/es/yaml/builder.mjs +13 -0
  71. package/dist/es/yaml/builder.mjs.map +1 -0
  72. package/dist/es/yaml/index.mjs +3 -0
  73. package/dist/es/yaml/player.mjs +372 -0
  74. package/dist/es/yaml/player.mjs.map +1 -0
  75. package/dist/es/yaml/utils.mjs +73 -0
  76. package/dist/es/yaml/utils.mjs.map +1 -0
  77. package/dist/es/yaml.mjs +0 -0
  78. package/dist/lib/agent/agent.js +682 -0
  79. package/dist/lib/agent/agent.js.map +1 -0
  80. package/dist/lib/agent/common.js +5 -0
  81. package/dist/lib/agent/index.js +81 -0
  82. package/dist/lib/agent/index.js.map +1 -0
  83. package/dist/lib/agent/task-cache.js +236 -0
  84. package/dist/lib/agent/task-cache.js.map +1 -0
  85. package/dist/lib/agent/tasks.js +700 -0
  86. package/dist/lib/agent/tasks.js.map +1 -0
  87. package/dist/lib/agent/ui-utils.js +121 -0
  88. package/dist/lib/agent/ui-utils.js.map +1 -0
  89. package/dist/lib/agent/utils.js +233 -0
  90. package/dist/lib/agent/utils.js.map +1 -0
  91. package/dist/lib/ai-model/action-executor.js +163 -0
  92. package/dist/lib/ai-model/action-executor.js.map +1 -0
  93. package/dist/lib/ai-model/common.js +461 -0
  94. package/dist/lib/ai-model/common.js.map +1 -0
  95. package/dist/lib/ai-model/conversation-history.js +92 -0
  96. package/dist/lib/ai-model/conversation-history.js.map +1 -0
  97. package/dist/lib/ai-model/index.js +131 -0
  98. package/dist/lib/ai-model/index.js.map +1 -0
  99. package/dist/lib/ai-model/inspect.js +326 -0
  100. package/dist/lib/ai-model/inspect.js.map +1 -0
  101. package/dist/lib/ai-model/llm-planning.js +174 -0
  102. package/dist/lib/ai-model/llm-planning.js.map +1 -0
  103. package/dist/lib/ai-model/prompt/assertion.js +65 -0
  104. package/dist/lib/ai-model/prompt/assertion.js.map +1 -0
  105. package/dist/lib/ai-model/prompt/common.js +41 -0
  106. package/dist/lib/ai-model/prompt/common.js.map +1 -0
  107. package/dist/lib/ai-model/prompt/describe.js +78 -0
  108. package/dist/lib/ai-model/prompt/describe.js.map +1 -0
  109. package/dist/lib/ai-model/prompt/extraction.js +169 -0
  110. package/dist/lib/ai-model/prompt/extraction.js.map +1 -0
  111. package/dist/lib/ai-model/prompt/llm-locator.js +308 -0
  112. package/dist/lib/ai-model/prompt/llm-locator.js.map +1 -0
  113. package/dist/lib/ai-model/prompt/llm-planning.js +407 -0
  114. package/dist/lib/ai-model/prompt/llm-planning.js.map +1 -0
  115. package/dist/lib/ai-model/prompt/llm-section-locator.js +78 -0
  116. package/dist/lib/ai-model/prompt/llm-section-locator.js.map +1 -0
  117. package/dist/lib/ai-model/prompt/playwright-generator.js +178 -0
  118. package/dist/lib/ai-model/prompt/playwright-generator.js.map +1 -0
  119. package/dist/lib/ai-model/prompt/ui-tars-locator.js +68 -0
  120. package/dist/lib/ai-model/prompt/ui-tars-locator.js.map +1 -0
  121. package/dist/lib/ai-model/prompt/ui-tars-planning.js +73 -0
  122. package/dist/lib/ai-model/prompt/ui-tars-planning.js.map +1 -0
  123. package/dist/lib/ai-model/prompt/util.js +176 -0
  124. package/dist/lib/ai-model/prompt/util.js.map +1 -0
  125. package/dist/lib/ai-model/prompt/yaml-generator.js +280 -0
  126. package/dist/lib/ai-model/prompt/yaml-generator.js.map +1 -0
  127. package/dist/lib/ai-model/service-caller/index.js +468 -0
  128. package/dist/lib/ai-model/service-caller/index.js.map +1 -0
  129. package/dist/lib/ai-model/ui-tars-planning.js +238 -0
  130. package/dist/lib/ai-model/ui-tars-planning.js.map +1 -0
  131. package/dist/lib/device/index.js +255 -0
  132. package/dist/lib/device/index.js.map +1 -0
  133. package/dist/lib/image/index.js +56 -0
  134. package/dist/lib/image/index.js.map +1 -0
  135. package/dist/lib/index.js +103 -0
  136. package/dist/lib/index.js.map +1 -0
  137. package/dist/lib/insight/index.js +265 -0
  138. package/dist/lib/insight/index.js.map +1 -0
  139. package/dist/lib/insight/utils.js +49 -0
  140. package/dist/lib/insight/utils.js.map +1 -0
  141. package/dist/lib/report.js +122 -0
  142. package/dist/lib/report.js.map +1 -0
  143. package/dist/lib/tree.js +44 -0
  144. package/dist/lib/tree.js.map +1 -0
  145. package/dist/lib/types.js +82 -0
  146. package/dist/lib/types.js.map +1 -0
  147. package/dist/lib/utils.js +281 -0
  148. package/dist/lib/utils.js.map +1 -0
  149. package/dist/lib/yaml/builder.js +57 -0
  150. package/dist/lib/yaml/builder.js.map +1 -0
  151. package/dist/lib/yaml/index.js +80 -0
  152. package/dist/lib/yaml/index.js.map +1 -0
  153. package/dist/lib/yaml/player.js +406 -0
  154. package/dist/lib/yaml/player.js.map +1 -0
  155. package/dist/lib/yaml/utils.js +126 -0
  156. package/dist/lib/yaml/utils.js.map +1 -0
  157. package/dist/lib/yaml.js +20 -0
  158. package/dist/lib/yaml.js.map +1 -0
  159. package/dist/types/agent/agent.d.ts +156 -0
  160. package/dist/types/agent/common.d.ts +0 -0
  161. package/dist/types/agent/index.d.ts +9 -0
  162. package/dist/types/agent/task-cache.d.ts +48 -0
  163. package/dist/types/agent/tasks.d.ts +48 -0
  164. package/dist/types/agent/ui-utils.d.ts +7 -0
  165. package/dist/types/agent/utils.d.ts +52 -0
  166. package/dist/types/ai-model/action-executor.d.ts +19 -0
  167. package/dist/types/ai-model/common.d.ts +569 -0
  168. package/dist/types/ai-model/conversation-history.d.ts +18 -0
  169. package/dist/types/ai-model/index.d.ts +13 -0
  170. package/dist/types/ai-model/inspect.d.ts +46 -0
  171. package/dist/types/ai-model/llm-planning.d.ts +11 -0
  172. package/dist/types/ai-model/prompt/assertion.d.ts +2 -0
  173. package/dist/types/ai-model/prompt/common.d.ts +2 -0
  174. package/dist/types/ai-model/prompt/describe.d.ts +1 -0
  175. package/dist/types/ai-model/prompt/extraction.d.ts +4 -0
  176. package/dist/types/ai-model/prompt/llm-locator.d.ts +8 -0
  177. package/dist/types/ai-model/prompt/llm-planning.d.ts +9 -0
  178. package/dist/types/ai-model/prompt/llm-section-locator.d.ts +5 -0
  179. package/dist/types/ai-model/prompt/playwright-generator.d.ts +26 -0
  180. package/dist/types/ai-model/prompt/ui-tars-locator.d.ts +1 -0
  181. package/dist/types/ai-model/prompt/ui-tars-planning.d.ts +2 -0
  182. package/dist/types/ai-model/prompt/util.d.ts +47 -0
  183. package/dist/types/ai-model/prompt/yaml-generator.d.ts +100 -0
  184. package/dist/types/ai-model/service-caller/index.d.ts +26 -0
  185. package/dist/types/ai-model/ui-tars-planning.d.ts +59 -0
  186. package/dist/types/device/index.d.ts +2158 -0
  187. package/dist/types/image/index.d.ts +1 -0
  188. package/dist/types/index.d.ts +12 -0
  189. package/dist/types/insight/index.d.ts +31 -0
  190. package/dist/types/insight/utils.d.ts +2 -0
  191. package/dist/types/report.d.ts +12 -0
  192. package/dist/types/tree.d.ts +1 -0
  193. package/dist/types/types.d.ts +412 -0
  194. package/dist/types/utils.d.ts +40 -0
  195. package/dist/types/yaml/builder.d.ts +2 -0
  196. package/dist/types/yaml/index.d.ts +3 -0
  197. package/dist/types/yaml/player.d.ts +34 -0
  198. package/dist/types/yaml/utils.d.ts +9 -0
  199. package/dist/types/yaml.d.ts +178 -0
  200. package/package.json +124 -0
@@ -0,0 +1,129 @@
1
+ function systemPromptToExtract() {
2
+ return `
3
+ You are a versatile professional in software UI design and testing. Your outstanding contributions will impact the user experience of billions of users.
4
+
5
+ The user will give you a screenshot, the contents of it (optional), and some data requirements in <DATA_DEMAND>. You need to understand the user's requirements and extract the data satisfying the <DATA_DEMAND>.
6
+
7
+ If a key specifies a JSON data type (such as Number, String, Boolean, Object, Array), ensure the returned value strictly matches that data type.
8
+
9
+ If the user provides multiple reference images, please carefully review the reference images with the screenshot and provide the correct answer for <DATA_DEMAND>.
10
+
11
+
12
+ Return in the following JSON format:
13
+ {
14
+ thought: string, // the thinking process of the extraction, less then 300 words
15
+ data: any, // the extracted data. Make sure both the value and scheme meet the DATA_DEMAND. If you want to write some description in this field, use the same language as the DATA_DEMAND.
16
+ errors: [], // string[], error message if any
17
+ }
18
+
19
+ # Example 1
20
+ For example, if the DATA_DEMAND is:
21
+
22
+ <DATA_DEMAND>
23
+ {
24
+ "name": "name shows on the left panel, string",
25
+ "age": "age shows on the right panel, number",
26
+ "isAdmin": "if the user is admin, boolean"
27
+ }
28
+ </DATA_DEMAND>
29
+
30
+ By viewing the screenshot and page contents, you can extract the following data:
31
+
32
+ {
33
+ thought: "According to the screenshot, i can see ...",
34
+ data: {
35
+ name: "John",
36
+ age: 30,
37
+ isAdmin: true
38
+ },
39
+ }
40
+
41
+ # Example 2
42
+ If the DATA_DEMAND is:
43
+
44
+ <DATA_DEMAND>
45
+ the todo items list, string[]
46
+ </DATA_DEMAND>
47
+
48
+ By viewing the screenshot and page contents, you can extract the following data:
49
+
50
+ {
51
+ thought: "According to the screenshot, i can see ...",
52
+ data: ["todo 1", "todo 2", "todo 3"],
53
+ }
54
+
55
+ # Example 3
56
+ If the DATA_DEMAND is:
57
+
58
+ <DATA_DEMAND>
59
+ the page title, string
60
+ </DATA_DEMAND>
61
+
62
+ By viewing the screenshot and page contents, you can extract the following data:
63
+
64
+ {
65
+ thought: "According to the screenshot, i can see ...",
66
+ data: "todo list",
67
+ }
68
+
69
+ # Example 4
70
+ If the DATA_DEMAND is:
71
+
72
+ <DATA_DEMAND>
73
+ {
74
+ "result": "Boolean, is it currently the SMS page?"
75
+ }
76
+ </DATA_DEMAND>
77
+
78
+ By viewing the screenshot and page contents, you can extract the following data:
79
+
80
+ {
81
+ thought: "According to the screenshot, i can see ...",
82
+ data: { result: true },
83
+ }
84
+ `;
85
+ }
86
+ const extractDataQueryPrompt = (pageDescription, dataQuery)=>{
87
+ let dataQueryText = '';
88
+ dataQueryText = 'string' == typeof dataQuery ? dataQuery : JSON.stringify(dataQuery, null, 2);
89
+ return `
90
+ <PageDescription>
91
+ ${pageDescription}
92
+ </PageDescription>
93
+
94
+ <DATA_DEMAND>
95
+ ${dataQueryText}
96
+ </DATA_DEMAND>
97
+ `;
98
+ };
99
+ const extractDataSchema = {
100
+ type: 'json_schema',
101
+ json_schema: {
102
+ name: 'extract_data',
103
+ strict: true,
104
+ schema: {
105
+ type: 'object',
106
+ properties: {
107
+ data: {
108
+ type: 'object',
109
+ description: 'The extracted data'
110
+ },
111
+ errors: {
112
+ type: 'array',
113
+ items: {
114
+ type: 'string'
115
+ },
116
+ description: 'Error messages, if any'
117
+ }
118
+ },
119
+ required: [
120
+ 'data',
121
+ 'errors'
122
+ ],
123
+ additionalProperties: false
124
+ }
125
+ }
126
+ };
127
+ export { extractDataQueryPrompt, extractDataSchema, systemPromptToExtract };
128
+
129
+ //# sourceMappingURL=extraction.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-model\\prompt\\extraction.mjs","sources":["webpack://@sqaitech/core/./src/ai-model/prompt/extraction.ts"],"sourcesContent":["import type { ResponseFormatJSONSchema } from 'openai/resources/index';\r\n\r\nexport function systemPromptToExtract() {\r\n return `\r\nYou are a versatile professional in software UI design and testing. Your outstanding contributions will impact the user experience of billions of users.\r\n\r\nThe user will give you a screenshot, the contents of it (optional), and some data requirements in <DATA_DEMAND>. You need to understand the user's requirements and extract the data satisfying the <DATA_DEMAND>.\r\n\r\nIf a key specifies a JSON data type (such as Number, String, Boolean, Object, Array), ensure the returned value strictly matches that data type.\r\n\r\nIf the user provides multiple reference images, please carefully review the reference images with the screenshot and provide the correct answer for <DATA_DEMAND>.\r\n\r\n\r\nReturn in the following JSON format:\r\n{\r\n thought: string, // the thinking process of the extraction, less then 300 words\r\n data: any, // the extracted data. Make sure both the value and scheme meet the DATA_DEMAND. If you want to write some description in this field, use the same language as the DATA_DEMAND.\r\n errors: [], // string[], error message if any\r\n}\r\n\r\n# Example 1\r\nFor example, if the DATA_DEMAND is:\r\n\r\n<DATA_DEMAND>\r\n{\r\n \"name\": \"name shows on the left panel, string\",\r\n \"age\": \"age shows on the right panel, number\",\r\n \"isAdmin\": \"if the user is admin, boolean\"\r\n}\r\n</DATA_DEMAND>\r\n\r\nBy viewing the screenshot and page contents, you can extract the following data:\r\n\r\n{\r\n thought: \"According to the screenshot, i can see ...\",\r\n data: {\r\n name: \"John\",\r\n age: 30,\r\n isAdmin: true\r\n },\r\n}\r\n\r\n# Example 2\r\nIf the DATA_DEMAND is:\r\n\r\n<DATA_DEMAND>\r\nthe todo items list, string[]\r\n</DATA_DEMAND>\r\n\r\nBy viewing the screenshot and page contents, you can extract the following data:\r\n\r\n{\r\n thought: \"According to the screenshot, i can see ...\",\r\n data: [\"todo 1\", \"todo 2\", \"todo 3\"],\r\n}\r\n\r\n# Example 3\r\nIf the DATA_DEMAND is:\r\n\r\n<DATA_DEMAND>\r\nthe page title, string\r\n</DATA_DEMAND>\r\n\r\nBy viewing the screenshot and page contents, you can extract the following data:\r\n\r\n{\r\n thought: \"According to the screenshot, i can see ...\",\r\n data: \"todo list\",\r\n}\r\n\r\n# Example 4\r\nIf the DATA_DEMAND is:\r\n\r\n<DATA_DEMAND>\r\n{\r\n \"result\": \"Boolean, is it currently the SMS page?\"\r\n}\r\n</DATA_DEMAND>\r\n\r\nBy viewing the screenshot and page contents, you can extract the following data:\r\n\r\n{\r\n thought: \"According to the screenshot, i can see ...\",\r\n data: { result: true },\r\n}\r\n`;\r\n}\r\n\r\nexport const extractDataQueryPrompt = (\r\n pageDescription: string,\r\n dataQuery: string | Record<string, string>,\r\n) => {\r\n let dataQueryText = '';\r\n if (typeof dataQuery === 'string') {\r\n dataQueryText = dataQuery;\r\n } else {\r\n dataQueryText = JSON.stringify(dataQuery, null, 2);\r\n }\r\n\r\n return `\r\n<PageDescription>\r\n${pageDescription}\r\n</PageDescription>\r\n\r\n<DATA_DEMAND>\r\n${dataQueryText}\r\n</DATA_DEMAND>\r\n `;\r\n};\r\n\r\nexport const extractDataSchema: ResponseFormatJSONSchema = {\r\n type: 'json_schema',\r\n json_schema: {\r\n name: 'extract_data',\r\n strict: true,\r\n schema: {\r\n type: 'object',\r\n properties: {\r\n data: {\r\n type: 'object',\r\n description: 'The extracted data',\r\n },\r\n errors: {\r\n type: 'array',\r\n items: {\r\n type: 'string',\r\n },\r\n description: 'Error messages, if any',\r\n },\r\n },\r\n required: ['data', 'errors'],\r\n additionalProperties: false,\r\n },\r\n },\r\n};\r\n"],"names":["systemPromptToExtract","extractDataQueryPrompt","pageDescription","dataQuery","dataQueryText","JSON","extractDataSchema"],"mappings":"AAEO,SAASA;IACd,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFV,CAAC;AACD;AAEO,MAAMC,yBAAyB,CACpCC,iBACAC;IAEA,IAAIC,gBAAgB;IAElBA,gBADE,AAAqB,YAArB,OAAOD,YACOA,YAEAE,KAAK,SAAS,CAACF,WAAW,MAAM;IAGlD,OAAO,CAAC;;AAEV,EAAED,gBAAgB;;;;AAIlB,EAAEE,cAAc;;EAEd,CAAC;AACH;AAEO,MAAME,oBAA8C;IACzD,MAAM;IACN,aAAa;QACX,MAAM;QACN,QAAQ;QACR,QAAQ;YACN,MAAM;YACN,YAAY;gBACV,MAAM;oBACJ,MAAM;oBACN,aAAa;gBACf;gBACA,QAAQ;oBACN,MAAM;oBACN,OAAO;wBACL,MAAM;oBACR;oBACA,aAAa;gBACf;YACF;YACA,UAAU;gBAAC;gBAAQ;aAAS;YAC5B,sBAAsB;QACxB;IACF;AACF"}
@@ -0,0 +1,268 @@
1
+ import { bboxDescription } from "./common.mjs";
2
+ function systemPromptToLocateElement(vlMode) {
3
+ if (vlMode) {
4
+ const bboxComment = bboxDescription(vlMode);
5
+ return `
6
+ ## Role:
7
+ You are an expert in software testing.
8
+
9
+ ## Objective:
10
+ - Identify elements in screenshots and text that match the user's description.
11
+ - Give the coordinates of the element that matches the user's description best in the screenshot.
12
+ - Determine whether the user's description is order-sensitive (e.g., contains phrases like 'the third item in the list', 'the last button', etc.).
13
+
14
+ ## Output Format:
15
+ \`\`\`json
16
+ {
17
+ "bbox": [number, number, number, number], // ${bboxComment}
18
+ "errors"?: string[],
19
+ "isOrderSensitive": boolean // Whether the targetElementDescription is order-sensitive (true/false)
20
+ }
21
+ \`\`\`
22
+
23
+ Fields:
24
+ * \`bbox\` is the bounding box of the element that matches the user's description best in the screenshot
25
+ * \`isOrderSensitive\` is a boolean indicating whether the user's description is order-sensitive (true/false)
26
+ * \`errors\` is an optional array of error messages (if any)
27
+
28
+ Order-sensitive means the description contains phrases like:
29
+ - "the third item in the list"
30
+ - "the last button"
31
+ - "the first input box"
32
+ - "the second row"
33
+
34
+ Not order-sensitive means the description is like:
35
+ - "confirm button"
36
+ - "search box"
37
+ - "password input"
38
+
39
+ For example, when an element is found and the description is order-sensitive:
40
+ \`\`\`json
41
+ {
42
+ "bbox": [100, 100, 200, 200],
43
+ "isOrderSensitive": true,
44
+ "errors": []
45
+ }
46
+ \`\`\`
47
+
48
+ When no element is found and the description is not order-sensitive:
49
+ \`\`\`json
50
+ {
51
+ "bbox": [],
52
+ "isOrderSensitive": false,
53
+ "errors": ["I can see ..., but {some element} is not found"]
54
+ }
55
+ \`\`\`
56
+ `;
57
+ }
58
+ return `
59
+ ## Role:
60
+ You are an expert in software page image (2D) and page element text analysis.
61
+
62
+ ## Objective:
63
+ - Identify elements in screenshots and text that match the user's description.
64
+ - Return JSON data containing the selection reason and element ID.
65
+ - Determine whether the user's description is order-sensitive (e.g., contains phrases like 'the third item in the list', 'the last button', etc.).
66
+
67
+ ## Skills:
68
+ - Image analysis and recognition
69
+ - Multilingual text understanding
70
+ - Software UI design and testing
71
+
72
+ ## Workflow:
73
+ 1. Receive the user's element description, screenshot, and element description information. Note that the text may contain non-English characters (e.g., Chinese), indicating that the application may be non-English.
74
+ 2. Based on the user's description, locate the target element ID in the list of element descriptions and the screenshot.
75
+ 3. Found the required number of elements
76
+ 4. Return JSON data containing the selection reason and element ID.
77
+ 5. Judge whether the user's description is order-sensitive (see below for definition and examples).
78
+
79
+ ## Constraints:
80
+ - Strictly adhere to the specified location when describing the required element; do not select elements from other locations.
81
+ - Elements in the image with NodeType other than "TEXT Node" have been highlighted to identify the element among multiple non-text elements.
82
+ - Accurately identify element information based on the user's description and return the corresponding element ID from the element description information, not extracted from the image.
83
+ - If no elements are found, the "elements" array should be empty.
84
+ - The returned data must conform to the specified JSON format.
85
+ - The returned value id information must use the id from element info (important: **use id not indexId, id is hash content**)
86
+
87
+ ## Order-Sensitive Definition:
88
+ - If the description contains phrases like "the third item in the list", "the last button", "the first input box", "the second row", etc., it is order-sensitive (isOrderSensitive = true).
89
+ - If the description is like "confirm button", "search box", "password input", etc., it is not order-sensitive (isOrderSensitive = false).
90
+
91
+ ## Output Format:
92
+
93
+ Please return the result in JSON format as follows:
94
+
95
+ \`\`\`json
96
+ {
97
+ "elements": [
98
+ // If no matching elements are found, return an empty array []
99
+ {
100
+ "reason": "PLACEHOLDER", // The thought process for finding the element, replace PLACEHOLDER with your thought process
101
+ "text": "PLACEHOLDER", // Replace PLACEHOLDER with the text of elementInfo, if none, leave empty
102
+ "id": "PLACEHOLDER" // Replace PLACEHOLDER with the ID (important: **use id not indexId, id is hash content**) of elementInfo
103
+ }
104
+ // More elements...
105
+ ],
106
+ "isOrderSensitive": true, // or false, depending on the user's description
107
+ "errors": [] // Array of strings containing any error messages
108
+ }
109
+ \`\`\`
110
+
111
+ ## Example:
112
+ Example 1:
113
+ Input Example:
114
+ \`\`\`json
115
+ // Description: "Shopping cart icon in the upper right corner"
116
+ {
117
+ "description": "PLACEHOLDER", // Description of the target element
118
+ "screenshot": "path/screenshot.png",
119
+ "text": '{
120
+ "pageSize": {
121
+ "width": 400, // Width of the page
122
+ "height": 905 // Height of the page
123
+ },
124
+ "elementInfos": [
125
+ {
126
+ "id": "1231", // ID of the element
127
+ "indexId": "0", // Index of the element\u{FF0C}The image is labeled to the left of the element
128
+ "attributes": { // Attributes of the element
129
+ "nodeType": "IMG Node", // Type of element, types include: TEXT Node, IMG Node, BUTTON Node, INPUT Node
130
+ "src": "https://ap-southeast-3.m",
131
+ "class": ".img"
132
+ },
133
+ "content": "", // Text content of the element
134
+ "rect": {
135
+ "left": 280, // Distance from the left side of the page
136
+ "top": 8, // Distance from the top of the page
137
+ "width": 44, // Width of the element
138
+ "height": 44 // Height of the element
139
+ }
140
+ },
141
+ {
142
+ "id": "66551", // ID of the element
143
+ "indexId": "1", // Index of the element,The image is labeled to the left of the element
144
+ "attributes": { // Attributes of the element
145
+ "nodeType": "IMG Node", // Type of element, types include: TEXT Node, IMG Node, BUTTON Node, INPUT Node
146
+ "src": "data:image/png;base64,iVBORw0KGgoAAAANSU...",
147
+ "class": ".icon"
148
+ },
149
+ "content": "", // Text content of the element
150
+ "rect": {
151
+ "left": 350, // Distance from the left side of the page
152
+ "top": 16, // Distance from the top of the page
153
+ "width": 25, // Width of the element
154
+ "height": 25 // Height of the element
155
+ }
156
+ },
157
+ ...
158
+ {
159
+ "id": "12344",
160
+ "indexId": "2", // Index of the element\u{FF0C}The image is labeled to the left of the element
161
+ "attributes": {
162
+ "nodeType": "TEXT Node",
163
+ "class": ".product-name"
164
+ },
165
+ "center": [
166
+ 288,
167
+ 834
168
+ ],
169
+ "content": "Mango Drink",
170
+ "rect": {
171
+ "left": 188,
172
+ "top": 827,
173
+ "width": 199,
174
+ "height": 13
175
+ }
176
+ },
177
+ ...
178
+ ]
179
+ }
180
+ '
181
+ }
182
+ \`\`\`
183
+ Output Example:
184
+ \`\`\`json
185
+ {
186
+ "elements": [
187
+ {
188
+ // Describe the reason for finding this element, replace with actual value in practice
189
+ "reason": "Reason for finding element 4: It is located in the upper right corner, is an image type, and according to the screenshot, it is a shopping cart icon button",
190
+ "text": "",
191
+ // ID(**use id not indexId**) of this element, replace with actual value in practice, **use id not indexId**
192
+ "id": "1231"
193
+ }
194
+ ],
195
+ "isOrderSensitive": true,
196
+ "errors": []
197
+ }
198
+ \`\`\`
199
+
200
+ `;
201
+ }
202
+ const locatorSchema = {
203
+ type: 'json_schema',
204
+ json_schema: {
205
+ name: 'find_elements',
206
+ strict: true,
207
+ schema: {
208
+ type: 'object',
209
+ properties: {
210
+ elements: {
211
+ type: 'array',
212
+ items: {
213
+ type: 'object',
214
+ properties: {
215
+ reason: {
216
+ type: 'string',
217
+ description: 'Reason for finding this element'
218
+ },
219
+ text: {
220
+ type: 'string',
221
+ description: 'Text content of the element'
222
+ },
223
+ id: {
224
+ type: 'string',
225
+ description: 'ID of this element'
226
+ }
227
+ },
228
+ required: [
229
+ 'reason',
230
+ 'text',
231
+ 'id'
232
+ ],
233
+ additionalProperties: false
234
+ },
235
+ description: 'List of found elements'
236
+ },
237
+ isOrderSensitive: {
238
+ type: 'boolean',
239
+ description: "Whether the targetElementDescription is order-sensitive (true/false)"
240
+ },
241
+ errors: {
242
+ type: 'array',
243
+ items: {
244
+ type: 'string'
245
+ },
246
+ description: 'List of error messages, if any'
247
+ }
248
+ },
249
+ required: [
250
+ 'elements',
251
+ 'isOrderSensitive',
252
+ 'errors'
253
+ ],
254
+ additionalProperties: false
255
+ }
256
+ }
257
+ };
258
+ const findElementPrompt = ({ pageDescription, targetElementDescription })=>`
259
+ Here is the item user want to find:
260
+ =====================================
261
+ ${targetElementDescription}
262
+ =====================================
263
+
264
+ ${pageDescription}
265
+ `;
266
+ export { findElementPrompt, locatorSchema, systemPromptToLocateElement };
267
+
268
+ //# sourceMappingURL=llm-locator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-model\\prompt\\llm-locator.mjs","sources":["webpack://@sqaitech/core/./src/ai-model/prompt/llm-locator.ts"],"sourcesContent":["import type { TVlModeTypes } from '@sqaitech/shared/env';\r\nimport type { ResponseFormatJSONSchema } from 'openai/resources/index';\r\nimport { bboxDescription } from './common';\r\nexport function systemPromptToLocateElement(vlMode: TVlModeTypes | undefined) {\r\n if (vlMode) {\r\n const bboxComment = bboxDescription(vlMode);\r\n return `\r\n## Role:\r\nYou are an expert in software testing.\r\n\r\n## Objective:\r\n- Identify elements in screenshots and text that match the user's description.\r\n- Give the coordinates of the element that matches the user's description best in the screenshot.\r\n- Determine whether the user's description is order-sensitive (e.g., contains phrases like 'the third item in the list', 'the last button', etc.).\r\n\r\n## Output Format:\r\n\\`\\`\\`json\r\n{\r\n \"bbox\": [number, number, number, number], // ${bboxComment}\r\n \"errors\"?: string[],\r\n \"isOrderSensitive\": boolean // Whether the targetElementDescription is order-sensitive (true/false)\r\n}\r\n\\`\\`\\`\r\n\r\nFields:\r\n* \\`bbox\\` is the bounding box of the element that matches the user's description best in the screenshot\r\n* \\`isOrderSensitive\\` is a boolean indicating whether the user's description is order-sensitive (true/false)\r\n* \\`errors\\` is an optional array of error messages (if any)\r\n\r\nOrder-sensitive means the description contains phrases like:\r\n- \"the third item in the list\"\r\n- \"the last button\"\r\n- \"the first input box\"\r\n- \"the second row\"\r\n\r\nNot order-sensitive means the description is like:\r\n- \"confirm button\"\r\n- \"search box\"\r\n- \"password input\"\r\n\r\nFor example, when an element is found and the description is order-sensitive:\r\n\\`\\`\\`json\r\n{\r\n \"bbox\": [100, 100, 200, 200],\r\n \"isOrderSensitive\": true,\r\n \"errors\": []\r\n}\r\n\\`\\`\\`\r\n\r\nWhen no element is found and the description is not order-sensitive:\r\n\\`\\`\\`json\r\n{\r\n \"bbox\": [],\r\n \"isOrderSensitive\": false,\r\n \"errors\": [\"I can see ..., but {some element} is not found\"]\r\n}\r\n\\`\\`\\`\r\n`;\r\n }\r\n\r\n return `\r\n## Role:\r\nYou are an expert in software page image (2D) and page element text analysis.\r\n\r\n## Objective:\r\n- Identify elements in screenshots and text that match the user's description.\r\n- Return JSON data containing the selection reason and element ID.\r\n- Determine whether the user's description is order-sensitive (e.g., contains phrases like 'the third item in the list', 'the last button', etc.).\r\n\r\n## Skills:\r\n- Image analysis and recognition\r\n- Multilingual text understanding\r\n- Software UI design and testing\r\n\r\n## Workflow:\r\n1. Receive the user's element description, screenshot, and element description information. Note that the text may contain non-English characters (e.g., Chinese), indicating that the application may be non-English.\r\n2. Based on the user's description, locate the target element ID in the list of element descriptions and the screenshot.\r\n3. Found the required number of elements\r\n4. Return JSON data containing the selection reason and element ID.\r\n5. Judge whether the user's description is order-sensitive (see below for definition and examples).\r\n\r\n## Constraints:\r\n- Strictly adhere to the specified location when describing the required element; do not select elements from other locations.\r\n- Elements in the image with NodeType other than \"TEXT Node\" have been highlighted to identify the element among multiple non-text elements.\r\n- Accurately identify element information based on the user's description and return the corresponding element ID from the element description information, not extracted from the image.\r\n- If no elements are found, the \"elements\" array should be empty.\r\n- The returned data must conform to the specified JSON format.\r\n- The returned value id information must use the id from element info (important: **use id not indexId, id is hash content**)\r\n\r\n## Order-Sensitive Definition:\r\n- If the description contains phrases like \"the third item in the list\", \"the last button\", \"the first input box\", \"the second row\", etc., it is order-sensitive (isOrderSensitive = true).\r\n- If the description is like \"confirm button\", \"search box\", \"password input\", etc., it is not order-sensitive (isOrderSensitive = false).\r\n\r\n## Output Format:\r\n\r\nPlease return the result in JSON format as follows:\r\n\r\n\\`\\`\\`json\r\n{\r\n \"elements\": [\r\n // If no matching elements are found, return an empty array []\r\n {\r\n \"reason\": \"PLACEHOLDER\", // The thought process for finding the element, replace PLACEHOLDER with your thought process\r\n \"text\": \"PLACEHOLDER\", // Replace PLACEHOLDER with the text of elementInfo, if none, leave empty\r\n \"id\": \"PLACEHOLDER\" // Replace PLACEHOLDER with the ID (important: **use id not indexId, id is hash content**) of elementInfo\r\n }\r\n // More elements...\r\n ],\r\n \"isOrderSensitive\": true, // or false, depending on the user's description\r\n \"errors\": [] // Array of strings containing any error messages\r\n}\r\n\\`\\`\\`\r\n\r\n## Example:\r\nExample 1:\r\nInput Example:\r\n\\`\\`\\`json\r\n// Description: \"Shopping cart icon in the upper right corner\"\r\n{\r\n \"description\": \"PLACEHOLDER\", // Description of the target element\r\n \"screenshot\": \"path/screenshot.png\",\r\n \"text\": '{\r\n \"pageSize\": {\r\n \"width\": 400, // Width of the page\r\n \"height\": 905 // Height of the page\r\n },\r\n \"elementInfos\": [\r\n {\r\n \"id\": \"1231\", // ID of the element\r\n \"indexId\": \"0\", // Index of the element,The image is labeled to the left of the element\r\n \"attributes\": { // Attributes of the element\r\n \"nodeType\": \"IMG Node\", // Type of element, types include: TEXT Node, IMG Node, BUTTON Node, INPUT Node\r\n \"src\": \"https://ap-southeast-3.m\",\r\n \"class\": \".img\"\r\n },\r\n \"content\": \"\", // Text content of the element\r\n \"rect\": {\r\n \"left\": 280, // Distance from the left side of the page\r\n \"top\": 8, // Distance from the top of the page\r\n \"width\": 44, // Width of the element\r\n \"height\": 44 // Height of the element\r\n }\r\n },\r\n {\r\n \"id\": \"66551\", // ID of the element\r\n \"indexId\": \"1\", // Index of the element,The image is labeled to the left of the element\r\n \"attributes\": { // Attributes of the element\r\n \"nodeType\": \"IMG Node\", // Type of element, types include: TEXT Node, IMG Node, BUTTON Node, INPUT Node\r\n \"src\": \"data:image/png;base64,iVBORw0KGgoAAAANSU...\",\r\n \"class\": \".icon\"\r\n },\r\n \"content\": \"\", // Text content of the element\r\n \"rect\": {\r\n \"left\": 350, // Distance from the left side of the page\r\n \"top\": 16, // Distance from the top of the page\r\n \"width\": 25, // Width of the element\r\n \"height\": 25 // Height of the element\r\n }\r\n },\r\n ...\r\n {\r\n \"id\": \"12344\",\r\n \"indexId\": \"2\", // Index of the element,The image is labeled to the left of the element\r\n \"attributes\": {\r\n \"nodeType\": \"TEXT Node\",\r\n \"class\": \".product-name\"\r\n },\r\n \"center\": [\r\n 288,\r\n 834\r\n ],\r\n \"content\": \"Mango Drink\",\r\n \"rect\": {\r\n \"left\": 188,\r\n \"top\": 827,\r\n \"width\": 199,\r\n \"height\": 13\r\n }\r\n },\r\n ...\r\n ]\r\n }\r\n '\r\n}\r\n\\`\\`\\`\r\nOutput Example:\r\n\\`\\`\\`json\r\n{\r\n \"elements\": [\r\n {\r\n // Describe the reason for finding this element, replace with actual value in practice\r\n \"reason\": \"Reason for finding element 4: It is located in the upper right corner, is an image type, and according to the screenshot, it is a shopping cart icon button\",\r\n \"text\": \"\",\r\n // ID(**use id not indexId**) of this element, replace with actual value in practice, **use id not indexId**\r\n \"id\": \"1231\"\r\n }\r\n ],\r\n \"isOrderSensitive\": true,\r\n \"errors\": []\r\n}\r\n\\`\\`\\`\r\n \r\n `;\r\n}\r\n\r\nexport const locatorSchema: ResponseFormatJSONSchema = {\r\n type: 'json_schema',\r\n json_schema: {\r\n name: 'find_elements',\r\n strict: true,\r\n schema: {\r\n type: 'object',\r\n properties: {\r\n elements: {\r\n type: 'array',\r\n items: {\r\n type: 'object',\r\n properties: {\r\n reason: {\r\n type: 'string',\r\n description: 'Reason for finding this element',\r\n },\r\n text: {\r\n type: 'string',\r\n description: 'Text content of the element',\r\n },\r\n id: {\r\n type: 'string',\r\n description: 'ID of this element',\r\n },\r\n },\r\n required: ['reason', 'text', 'id'],\r\n additionalProperties: false,\r\n },\r\n description: 'List of found elements',\r\n },\r\n isOrderSensitive: {\r\n type: 'boolean',\r\n description:\r\n 'Whether the targetElementDescription is order-sensitive (true/false)',\r\n },\r\n errors: {\r\n type: 'array',\r\n items: {\r\n type: 'string',\r\n },\r\n description: 'List of error messages, if any',\r\n },\r\n },\r\n required: ['elements', 'isOrderSensitive', 'errors'],\r\n additionalProperties: false,\r\n },\r\n },\r\n};\r\n\r\nexport const findElementPrompt = ({\r\n pageDescription,\r\n targetElementDescription,\r\n}: {\r\n pageDescription: string;\r\n targetElementDescription: string;\r\n}) => `\r\nHere is the item user want to find:\r\n=====================================\r\n${targetElementDescription}\r\n=====================================\r\n\r\n${pageDescription}\r\n `;\r\n"],"names":["systemPromptToLocateElement","vlMode","bboxComment","bboxDescription","locatorSchema","findElementPrompt","pageDescription","targetElementDescription"],"mappings":";AAGO,SAASA,4BAA4BC,MAAgC;IAC1E,IAAIA,QAAQ;QACV,MAAMC,cAAcC,gBAAgBF;QACpC,OAAO,CAAC;;;;;;;;;;;;gDAYoC,EAAEC,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuC9D,CAAC;IACC;IAEA,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8IR,CAAC;AACH;AAEO,MAAME,gBAA0C;IACrD,MAAM;IACN,aAAa;QACX,MAAM;QACN,QAAQ;QACR,QAAQ;YACN,MAAM;YACN,YAAY;gBACV,UAAU;oBACR,MAAM;oBACN,OAAO;wBACL,MAAM;wBACN,YAAY;4BACV,QAAQ;gCACN,MAAM;gCACN,aAAa;4BACf;4BACA,MAAM;gCACJ,MAAM;gCACN,aAAa;4BACf;4BACA,IAAI;gCACF,MAAM;gCACN,aAAa;4BACf;wBACF;wBACA,UAAU;4BAAC;4BAAU;4BAAQ;yBAAK;wBAClC,sBAAsB;oBACxB;oBACA,aAAa;gBACf;gBACA,kBAAkB;oBAChB,MAAM;oBACN,aACE;gBACJ;gBACA,QAAQ;oBACN,MAAM;oBACN,OAAO;wBACL,MAAM;oBACR;oBACA,aAAa;gBACf;YACF;YACA,UAAU;gBAAC;gBAAY;gBAAoB;aAAS;YACpD,sBAAsB;QACxB;IACF;AACF;AAEO,MAAMC,oBAAoB,CAAC,EAChCC,eAAe,EACfC,wBAAwB,EAIzB,GAAK,CAAC;;;AAGP,EAAEA,yBAAyB;;;AAG3B,EAAED,gBAAgB;EAChB,CAAC"}