@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,253 @@
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
+ executionToMarkdown: ()=>executionToMarkdown,
28
+ reportToMarkdown: ()=>reportToMarkdown
29
+ });
30
+ const external_node_path_namespaceObject = require("node:path");
31
+ const ui_utils_js_namespaceObject = require("./agent/ui-utils.js");
32
+ const external_screenshot_item_js_namespaceObject = require("./screenshot-item.js");
33
+ const screenshot_store_js_namespaceObject = require("./dump/screenshot-store.js");
34
+ function toExecutionDump(execution) {
35
+ if (!execution || 'object' != typeof execution) throw new Error('executionToMarkdown: execution is required');
36
+ if (!Array.isArray(execution.tasks)) throw new Error('executionToMarkdown: execution.tasks must be an array');
37
+ if (!execution.name) throw new Error('executionToMarkdown: execution.name is required');
38
+ return execution;
39
+ }
40
+ function toReportDump(report) {
41
+ if (!report || 'object' != typeof report) throw new Error('reportToMarkdown: report is required');
42
+ if (!Array.isArray(report.executions)) throw new Error('reportToMarkdown: report.executions must be an array');
43
+ return report;
44
+ }
45
+ function formatTime(ts) {
46
+ if ('number' != typeof ts || Number.isNaN(ts)) return 'N/A';
47
+ return new Date(ts).toISOString();
48
+ }
49
+ function resolveTaskTiming(task) {
50
+ const timing = task.timing;
51
+ if (!timing) return {};
52
+ const start = timing.start ?? timing.callAiStart ?? timing.callActionStart;
53
+ const end = timing.end ?? timing.callAiEnd ?? timing.callActionEnd ?? timing.captureAfterCallingSnapshotEnd;
54
+ const cost = timing.cost ?? ('number' == typeof start && 'number' == typeof end ? end - start : void 0);
55
+ return {
56
+ start,
57
+ end,
58
+ cost
59
+ };
60
+ }
61
+ function safeTaskParam(task) {
62
+ const readable = (0, ui_utils_js_namespaceObject.paramStr)(task);
63
+ if (readable) return readable;
64
+ if ('Insight' === task.type) return (0, ui_utils_js_namespaceObject.extractInsightParam)(task.param).content;
65
+ return '';
66
+ }
67
+ function formatSize(size) {
68
+ if (!size || 'number' != typeof size.width || 'number' != typeof size.height || Number.isNaN(size.width) || Number.isNaN(size.height)) return;
69
+ return `${size.width} x ${size.height}`;
70
+ }
71
+ function extractLocateCenter(task) {
72
+ const outputCenter = task.output?.element?.center;
73
+ if (Array.isArray(outputCenter) && outputCenter.length >= 2 && 'number' == typeof outputCenter[0] && 'number' == typeof outputCenter[1]) return [
74
+ outputCenter[0],
75
+ outputCenter[1]
76
+ ];
77
+ const paramLocateCenter = task.param?.locate?.center;
78
+ if (Array.isArray(paramLocateCenter) && paramLocateCenter.length >= 2 && 'number' == typeof paramLocateCenter[0] && 'number' == typeof paramLocateCenter[1]) return [
79
+ paramLocateCenter[0],
80
+ paramLocateCenter[1]
81
+ ];
82
+ const paramCenter = task.param?.center;
83
+ if (Array.isArray(paramCenter) && paramCenter.length >= 2 && 'number' == typeof paramCenter[0] && 'number' == typeof paramCenter[1]) return [
84
+ paramCenter[0],
85
+ paramCenter[1]
86
+ ];
87
+ }
88
+ function tryExtractBase64(screenshot) {
89
+ if (!screenshot || 'object' != typeof screenshot) return;
90
+ const s = screenshot;
91
+ if ('string' == typeof s.base64 && s.base64.length > 0) return s.base64;
92
+ }
93
+ function screenshotAttachment(screenshot, screenshotBaseDir, executionIndex, taskIndex) {
94
+ if (screenshot instanceof external_screenshot_item_js_namespaceObject.ScreenshotItem) {
95
+ const ext = screenshot.extension;
96
+ const suggestedFileName = `execution-${executionIndex + 1}-task-${taskIndex + 1}-${screenshot.id}.${ext}`;
97
+ const filePath = `${screenshotBaseDir}/${suggestedFileName}`;
98
+ return {
99
+ markdown: `\n![task-${taskIndex + 1}](${filePath})`,
100
+ attachment: {
101
+ id: screenshot.id,
102
+ suggestedFileName,
103
+ filePath,
104
+ mimeType: `image/${'jpeg' === ext ? 'jpeg' : 'png'}`,
105
+ executionIndex,
106
+ taskIndex,
107
+ base64Data: tryExtractBase64(screenshot)
108
+ }
109
+ };
110
+ }
111
+ const ref = (0, screenshot_store_js_namespaceObject.normalizeScreenshotRef)(screenshot);
112
+ if (ref) {
113
+ const ext = 'image/jpeg' === ref.mimeType ? 'jpeg' : 'png';
114
+ const suggestedFileName = `execution-${executionIndex + 1}-task-${taskIndex + 1}-${ref.id}.${ext}`;
115
+ const filePath = ref.path || `${screenshotBaseDir}/${suggestedFileName}`;
116
+ return {
117
+ markdown: `\n![task-${taskIndex + 1}](${filePath})`,
118
+ attachment: {
119
+ id: ref.id,
120
+ suggestedFileName,
121
+ filePath,
122
+ mimeType: ref.mimeType,
123
+ executionIndex,
124
+ taskIndex,
125
+ base64Data: tryExtractBase64(screenshot)
126
+ }
127
+ };
128
+ }
129
+ const base64 = tryExtractBase64(screenshot);
130
+ if (base64) {
131
+ const ext = base64.startsWith('data:image/jpeg') ? 'jpeg' : 'png';
132
+ const id = `restored-${executionIndex + 1}-${taskIndex + 1}`;
133
+ const suggestedFileName = `execution-${executionIndex + 1}-task-${taskIndex + 1}-${id}.${ext}`;
134
+ const filePath = `${screenshotBaseDir}/${suggestedFileName}`;
135
+ return {
136
+ markdown: `\n![task-${taskIndex + 1}](${filePath})`,
137
+ attachment: {
138
+ id,
139
+ suggestedFileName,
140
+ filePath,
141
+ mimeType: `image/${ext}`,
142
+ executionIndex,
143
+ taskIndex,
144
+ base64Data: base64
145
+ }
146
+ };
147
+ }
148
+ throw new Error(`executionToMarkdown: missing screenshot for execution #${executionIndex + 1} task #${taskIndex + 1}`);
149
+ }
150
+ function recorderMarkdownSection(recorder, screenshotBaseDir, executionIndex, taskIndex) {
151
+ if (!recorder?.length) return {
152
+ lines: [],
153
+ attachments: []
154
+ };
155
+ const lines = [
156
+ '',
157
+ '### Recorder'
158
+ ];
159
+ const attachments = [];
160
+ recorder.forEach((item, recorderIndex)=>{
161
+ lines.push(`- #${recorderIndex + 1} type=${item.type}, ts=${formatTime(item.ts)}, timing=${item.timing || 'N/A'}`);
162
+ if (!item.screenshot) return;
163
+ const imageResult = screenshotAttachment(item.screenshot, screenshotBaseDir, executionIndex, taskIndex);
164
+ lines.push(imageResult.markdown);
165
+ attachments.push(imageResult.attachment);
166
+ });
167
+ return {
168
+ lines,
169
+ attachments
170
+ };
171
+ }
172
+ function renderExecution(executionRaw, executionIndex, options) {
173
+ const execution = toExecutionDump(executionRaw);
174
+ const screenshotBaseDir = options?.screenshotBaseDir ?? './screenshots';
175
+ const lines = [];
176
+ const attachments = [];
177
+ lines.push(`# ${execution.name}`);
178
+ if (execution.description) lines.push('', execution.description);
179
+ lines.push('', `- Execution start: ${formatTime(execution.logTime)}`);
180
+ lines.push(`- Task count: ${execution.tasks.length}`);
181
+ execution.tasks.forEach((task, taskIndex)=>{
182
+ const title = (0, ui_utils_js_namespaceObject.typeStr)(task);
183
+ const detail = safeTaskParam(task);
184
+ const time = resolveTaskTiming(task);
185
+ lines.push('', `## ${taskIndex + 1}. ${title}${detail ? ` - ${detail}` : ''}`);
186
+ lines.push(`- Status: ${task.status || 'unknown'}`);
187
+ lines.push(`- Start: ${formatTime(time.start)}`);
188
+ lines.push(`- End: ${formatTime(time.end)}`);
189
+ lines.push(`- Cost(ms): ${'number' == typeof time.cost ? time.cost : 'N/A'}`);
190
+ lines.push(`- Screen size: ${formatSize(task.uiContext?.shotSize) || 'N/A'}`);
191
+ if ('Locate' === task.subType) {
192
+ const locateCenter = extractLocateCenter(task);
193
+ if (locateCenter) lines.push(`- Locate center: (${locateCenter[0]}, ${locateCenter[1]})`);
194
+ }
195
+ if (task.errorMessage) lines.push(`- Error: ${task.errorMessage}`);
196
+ if (task.uiContext?.screenshot) {
197
+ const imageResult = screenshotAttachment(task.uiContext.screenshot, screenshotBaseDir, executionIndex, taskIndex);
198
+ lines.push(imageResult.markdown);
199
+ attachments.push(imageResult.attachment);
200
+ }
201
+ const recorderSection = recorderMarkdownSection(task.recorder, screenshotBaseDir, executionIndex, taskIndex);
202
+ if (recorderSection.lines.length) {
203
+ lines.push(...recorderSection.lines);
204
+ attachments.push(...recorderSection.attachments);
205
+ }
206
+ });
207
+ return {
208
+ markdown: lines.join('\n'),
209
+ attachments
210
+ };
211
+ }
212
+ function reportFileName(execution, executionIndex) {
213
+ const safeName = execution.name.trim().replace(/\s+/g, '-').replace(/[^a-zA-Z0-9-_]/g, '') || `execution-${executionIndex + 1}`;
214
+ return `${executionIndex + 1}-${(0, external_node_path_namespaceObject.basename)(safeName)}.md`;
215
+ }
216
+ function executionToMarkdown(execution, options) {
217
+ return renderExecution(execution, 0, options);
218
+ }
219
+ function reportToMarkdown(report) {
220
+ const reportDump = toReportDump(report);
221
+ const executionResults = reportDump.executions.map((execution, index)=>{
222
+ const rendered = renderExecution(execution, index);
223
+ return {
224
+ executionIndex: index,
225
+ executionName: execution.name,
226
+ markdown: rendered.markdown,
227
+ attachments: rendered.attachments,
228
+ suggestedFileName: reportFileName(execution, index)
229
+ };
230
+ });
231
+ const attachments = executionResults.flatMap((item)=>item.attachments);
232
+ const header = [
233
+ `# ${reportDump.groupName}`,
234
+ reportDump.groupDescription ? `\n${reportDump.groupDescription}` : '',
235
+ `\n- SDK Version: ${reportDump.sdkVersion}`,
236
+ `- Execution count: ${reportDump.executions.length}`,
237
+ '\n## Suggested execution markdown files',
238
+ ...executionResults.map((item)=>`- ${item.suggestedFileName} (${item.executionName})`)
239
+ ].filter(Boolean).join('\n');
240
+ return {
241
+ markdown: `${header}\n\n${executionResults.map((item)=>item.markdown).join('\n\n---\n\n')}`,
242
+ attachments
243
+ };
244
+ }
245
+ exports.executionToMarkdown = __webpack_exports__.executionToMarkdown;
246
+ exports.reportToMarkdown = __webpack_exports__.reportToMarkdown;
247
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
248
+ "executionToMarkdown",
249
+ "reportToMarkdown"
250
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
251
+ Object.defineProperty(exports, '__esModule', {
252
+ value: true
253
+ });
@@ -0,0 +1,333 @@
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
+ splitReportHtmlByExecution: ()=>splitReportHtmlByExecution,
28
+ ReportMergingTool: ()=>ReportMergingTool,
29
+ isDirectoryModeReport: ()=>isDirectoryModeReport,
30
+ dedupeExecutionsKeepLatest: ()=>dedupeExecutionsKeepLatest,
31
+ collectDedupedExecutions: ()=>collectDedupedExecutions
32
+ });
33
+ const external_node_fs_namespaceObject = require("node:fs");
34
+ const external_node_path_namespaceObject = require("node:path");
35
+ const common_namespaceObject = require("@godscene/shared/common");
36
+ const utils_namespaceObject = require("@godscene/shared/utils");
37
+ const index_js_namespaceObject = require("./agent/index.js");
38
+ const html_utils_js_namespaceObject = require("./dump/html-utils.js");
39
+ const screenshot_store_js_namespaceObject = require("./dump/screenshot-store.js");
40
+ const external_types_js_namespaceObject = require("./types.js");
41
+ const external_utils_js_namespaceObject = require("./utils.js");
42
+ function _define_property(obj, key, value) {
43
+ if (key in obj) Object.defineProperty(obj, key, {
44
+ value: value,
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true
48
+ });
49
+ else obj[key] = value;
50
+ return obj;
51
+ }
52
+ function isDirectoryModeReport(reportFilePath) {
53
+ const reportDir = external_node_path_namespaceObject.dirname(reportFilePath);
54
+ return 'index.html' === external_node_path_namespaceObject.basename(reportFilePath) && (0, external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(reportDir, 'screenshots'));
55
+ }
56
+ function dedupeExecutionsKeepLatest(executions) {
57
+ let noIdCounter = 0;
58
+ const deduped = new Map();
59
+ for (const exec of executions){
60
+ const key = exec.id || `__no_id_${noIdCounter++}`;
61
+ deduped.set(key, exec);
62
+ }
63
+ return Array.from(deduped.values());
64
+ }
65
+ function peekReportSdkVersion(reportFilePath) {
66
+ try {
67
+ const dump = (0, html_utils_js_namespaceObject.extractLastDumpScriptSync)(reportFilePath);
68
+ if (!dump) return;
69
+ const match = dump.match(/"sdkVersion"\s*:\s*"([^"]+)"/);
70
+ return match?.[1];
71
+ } catch {
72
+ return;
73
+ }
74
+ }
75
+ const warnedMismatchedVersions = new Set();
76
+ class ReportMergingTool {
77
+ createEmptyDumpString(groupName, groupDescription) {
78
+ return new external_types_js_namespaceObject.ReportActionDump({
79
+ sdkVersion: '',
80
+ groupName,
81
+ groupDescription,
82
+ modelBriefs: [],
83
+ executions: []
84
+ }).serialize();
85
+ }
86
+ append(reportInfo) {
87
+ if (reportInfo.reportFilePath) {
88
+ const sourceVersion = peekReportSdkVersion(reportInfo.reportFilePath);
89
+ const currentVersion = (0, external_utils_js_namespaceObject.getVersion)();
90
+ if (sourceVersion && currentVersion && sourceVersion !== currentVersion && !warnedMismatchedVersions.has(sourceVersion)) {
91
+ warnedMismatchedVersions.add(sourceVersion);
92
+ (0, utils_namespaceObject.logMsg)(`[@godscene/core] ReportMergingTool version mismatch: source report was written by @godscene/core@${sourceVersion} but the merger is @godscene/core@${currentVersion}. This commonly means @godscene/core and the device package (e.g. @godscene/android) resolve to different versions in node_modules. Merged output may silently drop intermediate steps. Align the versions and reinstall (rm -rf node_modules package-lock.json && npm install).`);
93
+ }
94
+ }
95
+ this.reportInfos.push(reportInfo);
96
+ }
97
+ clear() {
98
+ this.reportInfos = [];
99
+ }
100
+ mergeDumpScripts(contents) {
101
+ const unescaped = contents.map((c)=>(0, utils_namespaceObject.antiEscapeScriptTag)(c)).filter((c)=>c.length > 0);
102
+ if (0 === unescaped.length) return '';
103
+ if (1 === unescaped.length) return unescaped[0];
104
+ const base = external_types_js_namespaceObject.ReportActionDump.fromSerializedString(unescaped[0]);
105
+ const allExecutions = [
106
+ ...base.executions
107
+ ];
108
+ for(let i = 1; i < unescaped.length; i++){
109
+ const other = external_types_js_namespaceObject.ReportActionDump.fromSerializedString(unescaped[i]);
110
+ allExecutions.push(...other.executions);
111
+ }
112
+ base.executions = dedupeExecutionsKeepLatest(allExecutions);
113
+ return base.serialize();
114
+ }
115
+ mergeReports(reportFileName = 'AUTO', opts) {
116
+ const { rmOriginalReports = false, overwrite = false } = opts ?? {};
117
+ if (0 === this.reportInfos.length) {
118
+ (0, utils_namespaceObject.logMsg)('No reports to merge');
119
+ return null;
120
+ }
121
+ const targetDir = (0, common_namespaceObject.getMidsceneRunSubDir)('report');
122
+ const hasDirectoryModeReport = this.reportInfos.some((info)=>{
123
+ const reportFilePath = info.reportFilePath;
124
+ return Boolean(reportFilePath && isDirectoryModeReport(reportFilePath));
125
+ });
126
+ const resolvedName = 'AUTO' === reportFileName ? (0, index_js_namespaceObject.getReportFileName)('merged-report') : reportFileName;
127
+ const outputFilePath = hasDirectoryModeReport ? external_node_path_namespaceObject.resolve(targetDir, resolvedName, 'index.html') : external_node_path_namespaceObject.resolve(targetDir, `${resolvedName}.html`);
128
+ if ('AUTO' !== reportFileName && (0, external_node_fs_namespaceObject.existsSync)(outputFilePath)) {
129
+ if (!overwrite) throw new Error(`Report file already exists: ${outputFilePath}\nSet overwrite to true to overwrite this file.`);
130
+ if (hasDirectoryModeReport) (0, external_node_fs_namespaceObject.rmSync)(external_node_path_namespaceObject.dirname(outputFilePath), {
131
+ recursive: true,
132
+ force: true
133
+ });
134
+ else (0, external_node_fs_namespaceObject.unlinkSync)(outputFilePath);
135
+ }
136
+ if (hasDirectoryModeReport) (0, external_node_fs_namespaceObject.mkdirSync)(external_node_path_namespaceObject.dirname(outputFilePath), {
137
+ recursive: true
138
+ });
139
+ (0, utils_namespaceObject.logMsg)(`Start merging ${this.reportInfos.length} reports...\nCreating template file...`);
140
+ try {
141
+ const htmlEndTag = '</html>';
142
+ const tpl = (0, external_utils_js_namespaceObject.getReportTpl)();
143
+ const htmlEndIdx = tpl.lastIndexOf(htmlEndTag);
144
+ const tplWithoutClose = -1 !== htmlEndIdx ? tpl.slice(0, htmlEndIdx) : tpl;
145
+ (0, external_node_fs_namespaceObject.appendFileSync)(outputFilePath, tplWithoutClose);
146
+ if (hasDirectoryModeReport) (0, external_node_fs_namespaceObject.appendFileSync)(outputFilePath, (0, html_utils_js_namespaceObject.getBaseUrlFixScript)());
147
+ for(let i = 0; i < this.reportInfos.length; i++){
148
+ const reportInfo = this.reportInfos[i];
149
+ (0, utils_namespaceObject.logMsg)(`Processing report ${i + 1}/${this.reportInfos.length}`);
150
+ const { reportAttributes } = reportInfo;
151
+ let dumpString = this.createEmptyDumpString(reportAttributes.testTitle, reportAttributes.testDescription);
152
+ let mergedGroupId = `merged-group-${i}`;
153
+ if (reportInfo.reportFilePath) {
154
+ if (isDirectoryModeReport(reportInfo.reportFilePath)) {
155
+ const reportDir = external_node_path_namespaceObject.dirname(reportInfo.reportFilePath);
156
+ const screenshotsDir = external_node_path_namespaceObject.join(reportDir, 'screenshots');
157
+ const mergedScreenshotsDir = external_node_path_namespaceObject.join(external_node_path_namespaceObject.dirname(outputFilePath), 'screenshots');
158
+ (0, external_node_fs_namespaceObject.mkdirSync)(mergedScreenshotsDir, {
159
+ recursive: true
160
+ });
161
+ for (const file of (0, external_node_fs_namespaceObject.readdirSync)(screenshotsDir)){
162
+ const src = external_node_path_namespaceObject.join(screenshotsDir, file);
163
+ const dest = external_node_path_namespaceObject.join(mergedScreenshotsDir, file);
164
+ (0, external_node_fs_namespaceObject.copyFileSync)(src, dest);
165
+ }
166
+ } else (0, html_utils_js_namespaceObject.streamImageScriptsToFile)(reportInfo.reportFilePath, outputFilePath);
167
+ const allDumps = (0, html_utils_js_namespaceObject.extractAllDumpScriptsSync)(reportInfo.reportFilePath).filter((d)=>d.openTag.includes('data-group-id'));
168
+ const groupIdMatch = allDumps[0]?.openTag.match(/data-group-id="([^"]+)"/);
169
+ if (groupIdMatch) mergedGroupId = decodeURIComponent(groupIdMatch[1]);
170
+ const extractedDumpString = allDumps.length > 0 ? this.mergeDumpScripts(allDumps.map((d)=>d.content)) : (0, html_utils_js_namespaceObject.extractLastDumpScriptSync)(reportInfo.reportFilePath);
171
+ if (extractedDumpString) dumpString = extractedDumpString;
172
+ }
173
+ const reportHtmlStr = `${(0, external_utils_js_namespaceObject.reportHTMLContent)({
174
+ dumpString,
175
+ attributes: {
176
+ 'data-group-id': mergedGroupId,
177
+ playwright_test_duration: reportAttributes.testDuration,
178
+ playwright_test_status: reportAttributes.testStatus,
179
+ playwright_test_title: reportAttributes.testTitle,
180
+ playwright_test_id: reportAttributes.testId,
181
+ playwright_test_description: reportAttributes.testDescription,
182
+ is_merged: true
183
+ }
184
+ }, void 0, void 0, false)}\n`;
185
+ (0, external_node_fs_namespaceObject.appendFileSync)(outputFilePath, reportHtmlStr);
186
+ }
187
+ (0, external_node_fs_namespaceObject.appendFileSync)(outputFilePath, `${htmlEndTag}\n`);
188
+ (0, utils_namespaceObject.logMsg)(`Successfully merged new report: ${outputFilePath}`);
189
+ if (rmOriginalReports) {
190
+ for (const info of this.reportInfos)if (info.reportFilePath) try {
191
+ if (isDirectoryModeReport(info.reportFilePath)) {
192
+ const reportDir = external_node_path_namespaceObject.dirname(info.reportFilePath);
193
+ (0, external_node_fs_namespaceObject.rmSync)(reportDir, {
194
+ recursive: true,
195
+ force: true
196
+ });
197
+ } else (0, external_node_fs_namespaceObject.unlinkSync)(info.reportFilePath);
198
+ } catch (error) {
199
+ (0, utils_namespaceObject.logMsg)(`Error deleting report ${info.reportFilePath}: ${error}`);
200
+ }
201
+ (0, utils_namespaceObject.logMsg)(`Removed ${this.reportInfos.length} original reports`);
202
+ }
203
+ return outputFilePath;
204
+ } catch (error) {
205
+ (0, utils_namespaceObject.logMsg)(`Error in mergeReports: ${error}`);
206
+ throw error;
207
+ }
208
+ }
209
+ constructor(){
210
+ _define_property(this, "reportInfos", []);
211
+ }
212
+ }
213
+ function collectDedupedExecutions(htmlPath) {
214
+ let baseDump = null;
215
+ let executionSerial = 0;
216
+ const latestSerialByExecutionId = new Map();
217
+ (0, html_utils_js_namespaceObject.streamDumpScriptsSync)(htmlPath, (dumpScript)=>{
218
+ if (!dumpScript.openTag.includes('data-group-id')) return false;
219
+ const groupedDump = external_types_js_namespaceObject.ReportActionDump.fromSerializedString((0, utils_namespaceObject.antiEscapeScriptTag)(dumpScript.content));
220
+ for (const execution of groupedDump.executions){
221
+ executionSerial += 1;
222
+ if (execution.id) latestSerialByExecutionId.set(execution.id, executionSerial);
223
+ }
224
+ return false;
225
+ });
226
+ const executions = [];
227
+ executionSerial = 0;
228
+ (0, html_utils_js_namespaceObject.streamDumpScriptsSync)(htmlPath, (dumpScript)=>{
229
+ if (!dumpScript.openTag.includes('data-group-id')) return false;
230
+ const groupedDump = external_types_js_namespaceObject.ReportActionDump.fromSerializedString((0, utils_namespaceObject.antiEscapeScriptTag)(dumpScript.content));
231
+ if (!baseDump) baseDump = groupedDump;
232
+ for (const execution of groupedDump.executions){
233
+ executionSerial += 1;
234
+ if (!execution.id || latestSerialByExecutionId.get(execution.id) === executionSerial) executions.push(execution);
235
+ }
236
+ return false;
237
+ });
238
+ if (!baseDump) throw new Error(`No report dump scripts found in ${htmlPath}`);
239
+ return {
240
+ baseDump,
241
+ executions
242
+ };
243
+ }
244
+ function extensionByMimeType(mimeType) {
245
+ if ('image/png' === mimeType) return 'png';
246
+ if ('image/jpeg' === mimeType) return 'jpeg';
247
+ throw new Error(`Unsupported screenshot mime type: ${mimeType}`);
248
+ }
249
+ function externalizeScreenshotsInExecution(execution, opts) {
250
+ const visit = (node)=>{
251
+ if (Array.isArray(node)) {
252
+ for (const item of node)visit(item);
253
+ return;
254
+ }
255
+ if ('object' != typeof node || null === node) return;
256
+ const ref = (0, screenshot_store_js_namespaceObject.normalizeScreenshotRef)(node);
257
+ if (ref) {
258
+ const ext = extensionByMimeType(ref.mimeType);
259
+ const fileName = `${ref.id}.${ext}`;
260
+ const relativePath = `./screenshots/${fileName}`;
261
+ const absolutePath = external_node_path_namespaceObject.join(opts.screenshotsDir, fileName);
262
+ if (!opts.writtenFiles.has(fileName)) {
263
+ const resolved = (0, screenshot_store_js_namespaceObject.resolveScreenshotSource)(ref, {
264
+ reportPath: opts.htmlPath
265
+ });
266
+ if ('data-uri' === resolved.type) {
267
+ const rawBase64 = resolved.dataUri.replace(/^data:image\/[a-zA-Z+]+;base64,/, '');
268
+ (0, external_node_fs_namespaceObject.writeFileSync)(absolutePath, Buffer.from(rawBase64, 'base64'));
269
+ } else (0, external_node_fs_namespaceObject.copyFileSync)(resolved.filePath, absolutePath);
270
+ opts.writtenFiles.add(fileName);
271
+ }
272
+ ref.storage = 'file';
273
+ ref.path = relativePath;
274
+ return;
275
+ }
276
+ for (const value of Object.values(node))visit(value);
277
+ };
278
+ visit(execution);
279
+ }
280
+ function splitReportHtmlByExecution(options) {
281
+ const { htmlPath, outputDir } = options;
282
+ const screenshotsDir = external_node_path_namespaceObject.join(outputDir, 'screenshots');
283
+ (0, external_node_fs_namespaceObject.mkdirSync)(outputDir, {
284
+ recursive: true
285
+ });
286
+ (0, external_node_fs_namespaceObject.mkdirSync)(screenshotsDir, {
287
+ recursive: true
288
+ });
289
+ const executionJsonFiles = [];
290
+ const writtenScreenshotFiles = new Set();
291
+ const { baseDump, executions } = collectDedupedExecutions(htmlPath);
292
+ let fileIndex = 0;
293
+ for (const execution of executions){
294
+ fileIndex += 1;
295
+ externalizeScreenshotsInExecution(execution, {
296
+ htmlPath,
297
+ screenshotsDir,
298
+ writtenFiles: writtenScreenshotFiles
299
+ });
300
+ const singleExecutionDump = new external_types_js_namespaceObject.ReportActionDump({
301
+ sdkVersion: baseDump.sdkVersion,
302
+ groupName: baseDump.groupName,
303
+ groupDescription: baseDump.groupDescription,
304
+ modelBriefs: baseDump.modelBriefs,
305
+ deviceType: baseDump.deviceType,
306
+ executions: [
307
+ execution
308
+ ]
309
+ });
310
+ const jsonFilePath = external_node_path_namespaceObject.join(outputDir, `${fileIndex}.execution.json`);
311
+ (0, external_node_fs_namespaceObject.writeFileSync)(jsonFilePath, singleExecutionDump.serialize(2), 'utf-8');
312
+ executionJsonFiles.push(jsonFilePath);
313
+ }
314
+ return {
315
+ executionJsonFiles,
316
+ screenshotFiles: Array.from(writtenScreenshotFiles).sort().map((fileName)=>external_node_path_namespaceObject.join(screenshotsDir, fileName))
317
+ };
318
+ }
319
+ exports.ReportMergingTool = __webpack_exports__.ReportMergingTool;
320
+ exports.collectDedupedExecutions = __webpack_exports__.collectDedupedExecutions;
321
+ exports.dedupeExecutionsKeepLatest = __webpack_exports__.dedupeExecutionsKeepLatest;
322
+ exports.isDirectoryModeReport = __webpack_exports__.isDirectoryModeReport;
323
+ exports.splitReportHtmlByExecution = __webpack_exports__.splitReportHtmlByExecution;
324
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
325
+ "ReportMergingTool",
326
+ "collectDedupedExecutions",
327
+ "dedupeExecutionsKeepLatest",
328
+ "isDirectoryModeReport",
329
+ "splitReportHtmlByExecution"
330
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
331
+ Object.defineProperty(exports, '__esModule', {
332
+ value: true
333
+ });