@godscene/core 1.7.11

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 (189) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -0
  3. package/dist/es/agent/agent.mjs +767 -0
  4. package/dist/es/agent/common.mjs +0 -0
  5. package/dist/es/agent/execution-session.mjs +39 -0
  6. package/dist/es/agent/index.mjs +6 -0
  7. package/dist/es/agent/task-builder.mjs +343 -0
  8. package/dist/es/agent/task-cache.mjs +212 -0
  9. package/dist/es/agent/tasks.mjs +428 -0
  10. package/dist/es/agent/ui-utils.mjs +101 -0
  11. package/dist/es/agent/utils.mjs +167 -0
  12. package/dist/es/ai-model/auto-glm/actions.mjs +237 -0
  13. package/dist/es/ai-model/auto-glm/index.mjs +6 -0
  14. package/dist/es/ai-model/auto-glm/parser.mjs +237 -0
  15. package/dist/es/ai-model/auto-glm/planning.mjs +69 -0
  16. package/dist/es/ai-model/auto-glm/prompt.mjs +220 -0
  17. package/dist/es/ai-model/auto-glm/util.mjs +7 -0
  18. package/dist/es/ai-model/connectivity.mjs +136 -0
  19. package/dist/es/ai-model/conversation-history.mjs +193 -0
  20. package/dist/es/ai-model/index.mjs +12 -0
  21. package/dist/es/ai-model/inspect.mjs +395 -0
  22. package/dist/es/ai-model/llm-planning.mjs +231 -0
  23. package/dist/es/ai-model/prompt/common.mjs +5 -0
  24. package/dist/es/ai-model/prompt/describe.mjs +64 -0
  25. package/dist/es/ai-model/prompt/extraction.mjs +129 -0
  26. package/dist/es/ai-model/prompt/llm-locator.mjs +49 -0
  27. package/dist/es/ai-model/prompt/llm-planning.mjs +584 -0
  28. package/dist/es/ai-model/prompt/llm-section-locator.mjs +42 -0
  29. package/dist/es/ai-model/prompt/order-sensitive-judge.mjs +33 -0
  30. package/dist/es/ai-model/prompt/playwright-generator.mjs +115 -0
  31. package/dist/es/ai-model/prompt/ui-tars-planning.mjs +34 -0
  32. package/dist/es/ai-model/prompt/util.mjs +57 -0
  33. package/dist/es/ai-model/prompt/yaml-generator.mjs +201 -0
  34. package/dist/es/ai-model/service-caller/codex-app-server.mjs +573 -0
  35. package/dist/es/ai-model/service-caller/image-detail.mjs +4 -0
  36. package/dist/es/ai-model/service-caller/index.mjs +648 -0
  37. package/dist/es/ai-model/service-caller/request-timeout.mjs +47 -0
  38. package/dist/es/ai-model/ui-tars-planning.mjs +247 -0
  39. package/dist/es/common.mjs +382 -0
  40. package/dist/es/device/device-options.mjs +0 -0
  41. package/dist/es/device/index.mjs +340 -0
  42. package/dist/es/dump/html-utils.mjs +290 -0
  43. package/dist/es/dump/index.mjs +3 -0
  44. package/dist/es/dump/screenshot-restoration.mjs +30 -0
  45. package/dist/es/dump/screenshot-store.mjs +125 -0
  46. package/dist/es/index.mjs +17 -0
  47. package/dist/es/report-cli.mjs +149 -0
  48. package/dist/es/report-generator.mjs +203 -0
  49. package/dist/es/report-markdown.mjs +216 -0
  50. package/dist/es/report.mjs +287 -0
  51. package/dist/es/screenshot-item.mjs +120 -0
  52. package/dist/es/service/index.mjs +272 -0
  53. package/dist/es/service/utils.mjs +13 -0
  54. package/dist/es/skill/index.mjs +35 -0
  55. package/dist/es/task-runner.mjs +261 -0
  56. package/dist/es/task-timing.mjs +10 -0
  57. package/dist/es/tree.mjs +11 -0
  58. package/dist/es/types.mjs +202 -0
  59. package/dist/es/utils.mjs +232 -0
  60. package/dist/es/yaml/builder.mjs +11 -0
  61. package/dist/es/yaml/index.mjs +4 -0
  62. package/dist/es/yaml/player.mjs +425 -0
  63. package/dist/es/yaml/utils.mjs +100 -0
  64. package/dist/es/yaml.mjs +0 -0
  65. package/dist/lib/agent/agent.js +815 -0
  66. package/dist/lib/agent/common.js +5 -0
  67. package/dist/lib/agent/execution-session.js +73 -0
  68. package/dist/lib/agent/index.js +76 -0
  69. package/dist/lib/agent/task-builder.js +380 -0
  70. package/dist/lib/agent/task-cache.js +264 -0
  71. package/dist/lib/agent/tasks.js +471 -0
  72. package/dist/lib/agent/ui-utils.js +153 -0
  73. package/dist/lib/agent/utils.js +238 -0
  74. package/dist/lib/ai-model/auto-glm/actions.js +271 -0
  75. package/dist/lib/ai-model/auto-glm/index.js +64 -0
  76. package/dist/lib/ai-model/auto-glm/parser.js +280 -0
  77. package/dist/lib/ai-model/auto-glm/planning.js +103 -0
  78. package/dist/lib/ai-model/auto-glm/prompt.js +257 -0
  79. package/dist/lib/ai-model/auto-glm/util.js +44 -0
  80. package/dist/lib/ai-model/connectivity.js +180 -0
  81. package/dist/lib/ai-model/conversation-history.js +227 -0
  82. package/dist/lib/ai-model/index.js +127 -0
  83. package/dist/lib/ai-model/inspect.js +441 -0
  84. package/dist/lib/ai-model/llm-planning.js +268 -0
  85. package/dist/lib/ai-model/prompt/common.js +39 -0
  86. package/dist/lib/ai-model/prompt/describe.js +98 -0
  87. package/dist/lib/ai-model/prompt/extraction.js +169 -0
  88. package/dist/lib/ai-model/prompt/llm-locator.js +86 -0
  89. package/dist/lib/ai-model/prompt/llm-planning.js +621 -0
  90. package/dist/lib/ai-model/prompt/llm-section-locator.js +79 -0
  91. package/dist/lib/ai-model/prompt/order-sensitive-judge.js +70 -0
  92. package/dist/lib/ai-model/prompt/playwright-generator.js +176 -0
  93. package/dist/lib/ai-model/prompt/ui-tars-planning.js +71 -0
  94. package/dist/lib/ai-model/prompt/util.js +103 -0
  95. package/dist/lib/ai-model/prompt/yaml-generator.js +262 -0
  96. package/dist/lib/ai-model/service-caller/codex-app-server.js +622 -0
  97. package/dist/lib/ai-model/service-caller/image-detail.js +38 -0
  98. package/dist/lib/ai-model/service-caller/index.js +716 -0
  99. package/dist/lib/ai-model/service-caller/request-timeout.js +93 -0
  100. package/dist/lib/ai-model/ui-tars-planning.js +281 -0
  101. package/dist/lib/common.js +491 -0
  102. package/dist/lib/device/device-options.js +18 -0
  103. package/dist/lib/device/index.js +467 -0
  104. package/dist/lib/dump/html-utils.js +366 -0
  105. package/dist/lib/dump/index.js +58 -0
  106. package/dist/lib/dump/screenshot-restoration.js +64 -0
  107. package/dist/lib/dump/screenshot-store.js +165 -0
  108. package/dist/lib/index.js +184 -0
  109. package/dist/lib/report-cli.js +189 -0
  110. package/dist/lib/report-generator.js +244 -0
  111. package/dist/lib/report-markdown.js +253 -0
  112. package/dist/lib/report.js +333 -0
  113. package/dist/lib/screenshot-item.js +154 -0
  114. package/dist/lib/service/index.js +306 -0
  115. package/dist/lib/service/utils.js +47 -0
  116. package/dist/lib/skill/index.js +69 -0
  117. package/dist/lib/task-runner.js +298 -0
  118. package/dist/lib/task-timing.js +44 -0
  119. package/dist/lib/tree.js +51 -0
  120. package/dist/lib/types.js +298 -0
  121. package/dist/lib/utils.js +314 -0
  122. package/dist/lib/yaml/builder.js +55 -0
  123. package/dist/lib/yaml/index.js +79 -0
  124. package/dist/lib/yaml/player.js +459 -0
  125. package/dist/lib/yaml/utils.js +153 -0
  126. package/dist/lib/yaml.js +18 -0
  127. package/dist/types/agent/agent.d.ts +220 -0
  128. package/dist/types/agent/common.d.ts +0 -0
  129. package/dist/types/agent/execution-session.d.ts +36 -0
  130. package/dist/types/agent/index.d.ts +9 -0
  131. package/dist/types/agent/task-builder.d.ts +34 -0
  132. package/dist/types/agent/task-cache.d.ts +49 -0
  133. package/dist/types/agent/tasks.d.ts +70 -0
  134. package/dist/types/agent/ui-utils.d.ts +14 -0
  135. package/dist/types/agent/utils.d.ts +25 -0
  136. package/dist/types/ai-model/auto-glm/actions.d.ts +78 -0
  137. package/dist/types/ai-model/auto-glm/index.d.ts +6 -0
  138. package/dist/types/ai-model/auto-glm/parser.d.ts +18 -0
  139. package/dist/types/ai-model/auto-glm/planning.d.ts +12 -0
  140. package/dist/types/ai-model/auto-glm/prompt.d.ts +27 -0
  141. package/dist/types/ai-model/auto-glm/util.d.ts +13 -0
  142. package/dist/types/ai-model/connectivity.d.ts +20 -0
  143. package/dist/types/ai-model/conversation-history.d.ts +105 -0
  144. package/dist/types/ai-model/index.d.ts +16 -0
  145. package/dist/types/ai-model/inspect.d.ts +67 -0
  146. package/dist/types/ai-model/llm-planning.d.ts +19 -0
  147. package/dist/types/ai-model/prompt/common.d.ts +2 -0
  148. package/dist/types/ai-model/prompt/describe.d.ts +1 -0
  149. package/dist/types/ai-model/prompt/extraction.d.ts +7 -0
  150. package/dist/types/ai-model/prompt/llm-locator.d.ts +3 -0
  151. package/dist/types/ai-model/prompt/llm-planning.d.ts +10 -0
  152. package/dist/types/ai-model/prompt/llm-section-locator.d.ts +3 -0
  153. package/dist/types/ai-model/prompt/order-sensitive-judge.d.ts +2 -0
  154. package/dist/types/ai-model/prompt/playwright-generator.d.ts +26 -0
  155. package/dist/types/ai-model/prompt/ui-tars-planning.d.ts +2 -0
  156. package/dist/types/ai-model/prompt/util.d.ts +33 -0
  157. package/dist/types/ai-model/prompt/yaml-generator.d.ts +102 -0
  158. package/dist/types/ai-model/service-caller/codex-app-server.d.ts +42 -0
  159. package/dist/types/ai-model/service-caller/image-detail.d.ts +2 -0
  160. package/dist/types/ai-model/service-caller/index.d.ts +60 -0
  161. package/dist/types/ai-model/service-caller/request-timeout.d.ts +32 -0
  162. package/dist/types/ai-model/ui-tars-planning.d.ts +72 -0
  163. package/dist/types/common.d.ts +288 -0
  164. package/dist/types/device/device-options.d.ts +155 -0
  165. package/dist/types/device/index.d.ts +2565 -0
  166. package/dist/types/dump/html-utils.d.ts +75 -0
  167. package/dist/types/dump/index.d.ts +5 -0
  168. package/dist/types/dump/screenshot-restoration.d.ts +8 -0
  169. package/dist/types/dump/screenshot-store.d.ts +49 -0
  170. package/dist/types/index.d.ts +21 -0
  171. package/dist/types/report-cli.d.ts +36 -0
  172. package/dist/types/report-generator.d.ts +88 -0
  173. package/dist/types/report-markdown.d.ts +24 -0
  174. package/dist/types/report.d.ts +52 -0
  175. package/dist/types/screenshot-item.d.ts +67 -0
  176. package/dist/types/service/index.d.ts +24 -0
  177. package/dist/types/service/utils.d.ts +2 -0
  178. package/dist/types/skill/index.d.ts +25 -0
  179. package/dist/types/task-runner.d.ts +50 -0
  180. package/dist/types/task-timing.d.ts +8 -0
  181. package/dist/types/tree.d.ts +4 -0
  182. package/dist/types/types.d.ts +684 -0
  183. package/dist/types/utils.d.ts +45 -0
  184. package/dist/types/yaml/builder.d.ts +2 -0
  185. package/dist/types/yaml/index.d.ts +4 -0
  186. package/dist/types/yaml/player.d.ts +34 -0
  187. package/dist/types/yaml/utils.d.ts +9 -0
  188. package/dist/types/yaml.d.ts +215 -0
  189. package/package.json +130 -0
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ sectionLocatorInstruction: ()=>sectionLocatorInstruction,
28
+ systemPromptToLocateSection: ()=>systemPromptToLocateSection
29
+ });
30
+ const env_namespaceObject = require("@godscene/shared/env");
31
+ const external_common_js_namespaceObject = require("./common.js");
32
+ function systemPromptToLocateSection(modelFamily) {
33
+ const preferredLanguage = (0, env_namespaceObject.getPreferredLanguage)();
34
+ const bboxFormat = (0, external_common_js_namespaceObject.bboxDescription)(modelFamily);
35
+ return `
36
+ ## Role:
37
+ You are an AI assistant that helps identify UI elements.
38
+
39
+ ## Objective:
40
+ - Find a section containing the target element
41
+ - If the description mentions reference elements, also locate sections containing those references
42
+
43
+ ## Output Format:
44
+ \`\`\`json
45
+ {
46
+ "bbox": [number, number, number, number], // ${bboxFormat}
47
+ "references_bbox"?: [
48
+ [number, number, number, number],
49
+ ...
50
+ ],
51
+ "error"?: string
52
+ }
53
+ \`\`\`
54
+
55
+ Fields:
56
+ * \`bbox\` - Bounding box of the section containing the target element
57
+ * \`references_bbox\` - Optional array of bounding boxes for reference elements
58
+ * \`error\` - Optional error message if the section cannot be found. Use ${preferredLanguage}.
59
+
60
+ Example:
61
+ If the description is "delete button on the second row with title 'Peter'", return:
62
+ \`\`\`json
63
+ {
64
+ "bbox": [100, 100, 200, 200],
65
+ "references_bbox": [[100, 100, 200, 200]]
66
+ }
67
+ \`\`\`
68
+ `;
69
+ }
70
+ const sectionLocatorInstruction = (sectionDescription)=>`Find section containing: ${sectionDescription}`;
71
+ exports.sectionLocatorInstruction = __webpack_exports__.sectionLocatorInstruction;
72
+ exports.systemPromptToLocateSection = __webpack_exports__.systemPromptToLocateSection;
73
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
74
+ "sectionLocatorInstruction",
75
+ "systemPromptToLocateSection"
76
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
77
+ Object.defineProperty(exports, '__esModule', {
78
+ value: true
79
+ });
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ orderSensitiveJudgePrompt: ()=>orderSensitiveJudgePrompt,
28
+ systemPromptToJudgeOrderSensitive: ()=>systemPromptToJudgeOrderSensitive
29
+ });
30
+ function systemPromptToJudgeOrderSensitive() {
31
+ return `
32
+ ## Role:
33
+ You are an AI assistant that analyzes UI element descriptions.
34
+
35
+ ## Objective:
36
+ Determine whether a given element description is order-sensitive.
37
+
38
+ Order-sensitive descriptions contain phrases that specify position or sequence, such as:
39
+ - "the first button"
40
+ - "the second item"
41
+ - "the third row"
42
+ - "the last input"
43
+ - "the 5th element"
44
+
45
+ Order-insensitive descriptions do not specify position:
46
+ - "login button"
47
+ - "search input"
48
+ - "submit button"
49
+ - "user avatar"
50
+
51
+ ## Output Format:
52
+ \`\`\`json
53
+ {
54
+ "isOrderSensitive": boolean
55
+ }
56
+ \`\`\`
57
+
58
+ Return true if the description is order-sensitive, false otherwise.
59
+ `;
60
+ }
61
+ const orderSensitiveJudgePrompt = (description)=>`Analyze this element description: "${description}"`;
62
+ exports.orderSensitiveJudgePrompt = __webpack_exports__.orderSensitiveJudgePrompt;
63
+ exports.systemPromptToJudgeOrderSensitive = __webpack_exports__.systemPromptToJudgeOrderSensitive;
64
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
65
+ "orderSensitiveJudgePrompt",
66
+ "systemPromptToJudgeOrderSensitive"
67
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
68
+ Object.defineProperty(exports, '__esModule', {
69
+ value: true
70
+ });
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ createEventCounts: ()=>external_yaml_generator_js_namespaceObject.createEventCounts,
28
+ filterEventsByType: ()=>external_yaml_generator_js_namespaceObject.filterEventsByType,
29
+ generatePlaywrightTest: ()=>generatePlaywrightTest,
30
+ generatePlaywrightTestStream: ()=>generatePlaywrightTestStream,
31
+ validateEvents: ()=>external_yaml_generator_js_namespaceObject.validateEvents,
32
+ createMessageContent: ()=>external_yaml_generator_js_namespaceObject.createMessageContent,
33
+ getScreenshotsForLLM: ()=>external_yaml_generator_js_namespaceObject.getScreenshotsForLLM,
34
+ extractInputDescriptions: ()=>external_yaml_generator_js_namespaceObject.extractInputDescriptions,
35
+ prepareEventSummary: ()=>external_yaml_generator_js_namespaceObject.prepareEventSummary,
36
+ processEventsForLLM: ()=>external_yaml_generator_js_namespaceObject.processEventsForLLM
37
+ });
38
+ const constants_namespaceObject = require("@godscene/shared/constants");
39
+ const external_index_js_namespaceObject = require("../index.js");
40
+ const external_yaml_generator_js_namespaceObject = require("./yaml-generator.js");
41
+ const generatePlaywrightTest = async (events, options, modelConfig)=>{
42
+ (0, external_yaml_generator_js_namespaceObject.validateEvents)(events);
43
+ const summary = (0, external_yaml_generator_js_namespaceObject.prepareEventSummary)(events, {
44
+ testName: options.testName,
45
+ maxScreenshots: options.maxScreenshots || 3
46
+ });
47
+ const playwrightSummary = {
48
+ ...summary,
49
+ waitForNetworkIdle: false !== options.waitForNetworkIdle,
50
+ waitForNetworkIdleTimeout: options.waitForNetworkIdleTimeout || 2000,
51
+ viewportSize: options.viewportSize || {
52
+ width: 1280,
53
+ height: 800
54
+ }
55
+ };
56
+ const screenshots = (0, external_yaml_generator_js_namespaceObject.getScreenshotsForLLM)(events, options.maxScreenshots || 3);
57
+ const promptText = `Generate a Playwright test using @godscene/web/playwright that reproduces this recorded browser session. The test should be based on the following events and follow the structure of the example provided. Make the test descriptive with appropriate assertions and validations.
58
+
59
+ Event Summary:
60
+ ${JSON.stringify(playwrightSummary, null, 2)}
61
+
62
+ Generated code should:
63
+ 1. Import required dependencies
64
+ 2. Set up the test with proper configuration
65
+ 3. Include a beforeEach hook to navigate to the starting URL
66
+ 4. Implement a test that uses Midscene AI methods (aiTap, aiInput, aiAssert, etc.)
67
+ 5. Include appropriate assertions and validations
68
+ 6. Follow best practices for Playwright tests
69
+ 7. Be ready to execute without further modification
70
+
71
+ Important: Return ONLY the raw Playwright test code. Do NOT wrap the response in markdown code blocks (no \`\`\`typescript, \`\`\`javascript or \`\`\`). Start directly with the code content.`;
72
+ const messageContent = (0, external_yaml_generator_js_namespaceObject.createMessageContent)(promptText, screenshots, false !== options.includeScreenshots);
73
+ const systemPrompt = `You are an expert test automation engineer specializing in Playwright and Midscene.
74
+ Your task is to generate a complete, executable Playwright test using @godscene/web/playwright that reproduces a recorded browser session.
75
+
76
+ ${constants_namespaceObject.PLAYWRIGHT_EXAMPLE_CODE}`;
77
+ const prompt = [
78
+ {
79
+ role: 'system',
80
+ content: systemPrompt
81
+ },
82
+ {
83
+ role: 'user',
84
+ content: messageContent
85
+ }
86
+ ];
87
+ const response = await (0, external_index_js_namespaceObject.callAIWithStringResponse)(prompt, modelConfig);
88
+ if (response?.content && 'string' == typeof response.content) return response.content;
89
+ throw new Error('Failed to generate Playwright test code');
90
+ };
91
+ const generatePlaywrightTestStream = async (events, options, modelConfig)=>{
92
+ (0, external_yaml_generator_js_namespaceObject.validateEvents)(events);
93
+ const summary = (0, external_yaml_generator_js_namespaceObject.prepareEventSummary)(events, {
94
+ testName: options.testName,
95
+ maxScreenshots: options.maxScreenshots || 3
96
+ });
97
+ const playwrightSummary = {
98
+ ...summary,
99
+ waitForNetworkIdle: false !== options.waitForNetworkIdle,
100
+ waitForNetworkIdleTimeout: options.waitForNetworkIdleTimeout || 2000,
101
+ viewportSize: options.viewportSize || {
102
+ width: 1280,
103
+ height: 800
104
+ }
105
+ };
106
+ const screenshots = (0, external_yaml_generator_js_namespaceObject.getScreenshotsForLLM)(events, options.maxScreenshots || 3);
107
+ const promptText = `Generate a Playwright test using @godscene/web/playwright that reproduces this recorded browser session. The test should be based on the following events and follow the structure of the example provided. Make the test descriptive with appropriate assertions and validations.
108
+
109
+ Event Summary:
110
+ ${JSON.stringify(playwrightSummary, null, 2)}
111
+
112
+ Generated code should:
113
+ 1. Import required dependencies
114
+ 2. Set up the test with proper configuration
115
+ 3. Include a beforeEach hook to navigate to the starting URL
116
+ 4. Implement a test that uses Midscene AI methods (aiTap, aiInput, aiAssert, etc.)
117
+ 5. Include appropriate assertions and validations
118
+ 6. Follow best practices for Playwright tests
119
+ 7. Be ready to execute without further modification
120
+ 8. can't wrap this test code in markdown code block
121
+
122
+ Important: Return ONLY the raw Playwright test code. Do NOT wrap the response in markdown code blocks (no \`\`\`typescript, \`\`\`javascript or \`\`\`). Start directly with the code content.`;
123
+ const messageContent = (0, external_yaml_generator_js_namespaceObject.createMessageContent)(promptText, screenshots, false !== options.includeScreenshots);
124
+ const systemPrompt = `You are an expert test automation engineer specializing in Playwright and Midscene.
125
+ Your task is to generate a complete, executable Playwright test using @godscene/web/playwright that reproduces a recorded browser session.
126
+
127
+ ${constants_namespaceObject.PLAYWRIGHT_EXAMPLE_CODE}`;
128
+ const prompt = [
129
+ {
130
+ role: 'system',
131
+ content: systemPrompt
132
+ },
133
+ {
134
+ role: 'user',
135
+ content: messageContent
136
+ }
137
+ ];
138
+ if (options.stream && options.onChunk) return await (0, external_index_js_namespaceObject.callAI)(prompt, modelConfig, {
139
+ stream: true,
140
+ onChunk: options.onChunk
141
+ });
142
+ {
143
+ const response = await (0, external_index_js_namespaceObject.callAIWithStringResponse)(prompt, modelConfig);
144
+ if (response?.content && 'string' == typeof response.content) return {
145
+ content: response.content,
146
+ usage: response.usage,
147
+ isStreamed: false
148
+ };
149
+ throw new Error('Failed to generate Playwright test code');
150
+ }
151
+ };
152
+ exports.createEventCounts = __webpack_exports__.createEventCounts;
153
+ exports.createMessageContent = __webpack_exports__.createMessageContent;
154
+ exports.extractInputDescriptions = __webpack_exports__.extractInputDescriptions;
155
+ exports.filterEventsByType = __webpack_exports__.filterEventsByType;
156
+ exports.generatePlaywrightTest = __webpack_exports__.generatePlaywrightTest;
157
+ exports.generatePlaywrightTestStream = __webpack_exports__.generatePlaywrightTestStream;
158
+ exports.getScreenshotsForLLM = __webpack_exports__.getScreenshotsForLLM;
159
+ exports.prepareEventSummary = __webpack_exports__.prepareEventSummary;
160
+ exports.processEventsForLLM = __webpack_exports__.processEventsForLLM;
161
+ exports.validateEvents = __webpack_exports__.validateEvents;
162
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
163
+ "createEventCounts",
164
+ "createMessageContent",
165
+ "extractInputDescriptions",
166
+ "filterEventsByType",
167
+ "generatePlaywrightTest",
168
+ "generatePlaywrightTestStream",
169
+ "getScreenshotsForLLM",
170
+ "prepareEventSummary",
171
+ "processEventsForLLM",
172
+ "validateEvents"
173
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
174
+ Object.defineProperty(exports, '__esModule', {
175
+ value: true
176
+ });
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ getUiTarsPlanningPrompt: ()=>getUiTarsPlanningPrompt,
28
+ getSummary: ()=>getSummary
29
+ });
30
+ const env_namespaceObject = require("@godscene/shared/env");
31
+ function getUiTarsPlanningPrompt() {
32
+ const preferredLanguage = (0, env_namespaceObject.getPreferredLanguage)();
33
+ return `
34
+ You are a GUI agent. You are given a task and your action history, with screenshots. You need to perform the next action to complete the task.
35
+
36
+ ## Output Format
37
+ \`\`\`
38
+ Thought: ...
39
+ Action: ...
40
+ \`\`\`
41
+
42
+ ## Action Space
43
+
44
+ click(start_box='[x1, y1, x2, y2]')
45
+ left_double(start_box='[x1, y1, x2, y2]')
46
+ right_single(start_box='[x1, y1, x2, y2]')
47
+ drag(start_box='[x1, y1, x2, y2]', end_box='[x3, y3, x4, y4]')
48
+ hotkey(key='')
49
+ type(content='xxx') # Use escape characters \\', \\\", and \\n in content part to ensure we can parse the content in normal python string format. If you want to submit your input, use \\n at the end of content.
50
+ scroll(start_box='[x1, y1, x2, y2]', direction='down or up or right or left')
51
+ wait() #Sleep for 5s and take a screenshot to check for any changes.
52
+ finished(content='xxx') # Use escape characters \\', \\", and \\n in content part to ensure we can parse the content in normal python string format.
53
+
54
+
55
+ ## Note
56
+ - Use ${preferredLanguage} in \`Thought\` part.
57
+ - Write a small plan and finally summarize your next action (with its target element) in one sentence in \`Thought\` part.
58
+
59
+ ## User Instruction
60
+ `;
61
+ }
62
+ const getSummary = (prediction)=>prediction.replace(/Reflection:[\s\S]*?(?=Action_Summary:|Action:|$)/g, '').trim();
63
+ exports.getSummary = __webpack_exports__.getSummary;
64
+ exports.getUiTarsPlanningPrompt = __webpack_exports__.getUiTarsPlanningPrompt;
65
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
66
+ "getSummary",
67
+ "getUiTarsPlanningPrompt"
68
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
69
+ Object.defineProperty(exports, '__esModule', {
70
+ value: true
71
+ });
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ distance: ()=>distance,
28
+ distanceThreshold: ()=>distanceThreshold,
29
+ extractXMLTag: ()=>extractXMLTag,
30
+ parseMarkFinishedIndexes: ()=>parseMarkFinishedIndexes,
31
+ parseSubGoalsFromXML: ()=>parseSubGoalsFromXML
32
+ });
33
+ function extractXMLTag(xmlString, tagName) {
34
+ const lowerXmlString = xmlString.toLowerCase();
35
+ const lowerTagName = tagName.toLowerCase();
36
+ const closeTag = `</${lowerTagName}>`;
37
+ const openTag = `<${lowerTagName}>`;
38
+ const lastCloseIndex = lowerXmlString.lastIndexOf(closeTag);
39
+ if (-1 === lastCloseIndex) {
40
+ const lastOpenIndex = lowerXmlString.lastIndexOf(openTag);
41
+ if (-1 === lastOpenIndex) return;
42
+ const contentStart = lastOpenIndex + openTag.length;
43
+ const remaining = xmlString.substring(contentStart);
44
+ const nextTagIndex = remaining.indexOf('<');
45
+ const content = -1 === nextTagIndex ? remaining : remaining.substring(0, nextTagIndex);
46
+ return content.trim();
47
+ }
48
+ const searchArea = lowerXmlString.substring(0, lastCloseIndex);
49
+ const lastOpenIndex = searchArea.lastIndexOf(openTag);
50
+ if (-1 === lastOpenIndex) return;
51
+ const contentStart = lastOpenIndex + openTag.length;
52
+ const contentEnd = lastCloseIndex;
53
+ const content = xmlString.substring(contentStart, contentEnd);
54
+ return content.trim();
55
+ }
56
+ function parseSubGoalsFromXML(xmlContent) {
57
+ const subGoals = [];
58
+ const regex = /<sub-goal\s+index="(\d+)"\s+status="(pending|finished)"(?:\s*\/>|>([\s\S]*?)<\/sub-goal>)/gi;
59
+ let match;
60
+ match = regex.exec(xmlContent);
61
+ while(null !== match){
62
+ const index = Number.parseInt(match[1], 10);
63
+ const status = match[2];
64
+ const description = match[3]?.trim() || '';
65
+ subGoals.push({
66
+ index,
67
+ status,
68
+ description
69
+ });
70
+ match = regex.exec(xmlContent);
71
+ }
72
+ return subGoals;
73
+ }
74
+ function parseMarkFinishedIndexes(xmlContent) {
75
+ const indexes = [];
76
+ const regex = /<sub-goal\s+index="(\d+)"\s+status="finished"\s*\/>/gi;
77
+ let match;
78
+ match = regex.exec(xmlContent);
79
+ while(null !== match){
80
+ indexes.push(Number.parseInt(match[1], 10));
81
+ match = regex.exec(xmlContent);
82
+ }
83
+ return indexes;
84
+ }
85
+ const distanceThreshold = 16;
86
+ function distance(point1, point2) {
87
+ return Math.sqrt((point1.x - point2.x) ** 2 + (point1.y - point2.y) ** 2);
88
+ }
89
+ exports.distance = __webpack_exports__.distance;
90
+ exports.distanceThreshold = __webpack_exports__.distanceThreshold;
91
+ exports.extractXMLTag = __webpack_exports__.extractXMLTag;
92
+ exports.parseMarkFinishedIndexes = __webpack_exports__.parseMarkFinishedIndexes;
93
+ exports.parseSubGoalsFromXML = __webpack_exports__.parseSubGoalsFromXML;
94
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
95
+ "distance",
96
+ "distanceThreshold",
97
+ "extractXMLTag",
98
+ "parseMarkFinishedIndexes",
99
+ "parseSubGoalsFromXML"
100
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
101
+ Object.defineProperty(exports, '__esModule', {
102
+ value: true
103
+ });