@midscene/core 1.16.0 → 1.16.1

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 (94) hide show
  1. package/dist/es/agent/agent-options.mjs +36 -0
  2. package/dist/es/agent/agent-options.mjs.map +1 -0
  3. package/dist/es/agent/agent-report-manager.mjs +323 -0
  4. package/dist/es/agent/agent-report-manager.mjs.map +1 -0
  5. package/dist/es/agent/agent.mjs +112 -228
  6. package/dist/es/agent/agent.mjs.map +1 -1
  7. package/dist/es/agent/cache-config.mjs +21 -1
  8. package/dist/es/agent/cache-config.mjs.map +1 -1
  9. package/dist/es/agent/tasks.mjs +3 -1
  10. package/dist/es/agent/tasks.mjs.map +1 -1
  11. package/dist/es/agent/utils.mjs +1 -1
  12. package/dist/es/report-generator.mjs +73 -33
  13. package/dist/es/report-generator.mjs.map +1 -1
  14. package/dist/es/report-html-template.mjs +1 -1
  15. package/dist/es/test-runner/engine/document-runtime.mjs +30 -24
  16. package/dist/es/test-runner/engine/document-runtime.mjs.map +1 -1
  17. package/dist/es/test-runner/engine/project-runtime.mjs +17 -11
  18. package/dist/es/test-runner/engine/project-runtime.mjs.map +1 -1
  19. package/dist/es/test-runner/engine/resource-operations.mjs +33 -8
  20. package/dist/es/test-runner/engine/resource-operations.mjs.map +1 -1
  21. package/dist/es/test-runner/engine/run-collected-case.mjs +1 -0
  22. package/dist/es/test-runner/engine/run-collected-case.mjs.map +1 -1
  23. package/dist/es/test-runner/engine/run-workflow-document.mjs +3 -0
  24. package/dist/es/test-runner/engine/run-workflow-document.mjs.map +1 -1
  25. package/dist/es/test-runner/engine/setup-timeout.mjs +37 -0
  26. package/dist/es/test-runner/engine/setup-timeout.mjs.map +1 -0
  27. package/dist/es/utils.mjs +1 -1
  28. package/dist/es/yaml/execution-session.mjs +2 -1
  29. package/dist/es/yaml/execution-session.mjs.map +1 -1
  30. package/dist/es/yaml/legacy-yaml-report.mjs +1 -1
  31. package/dist/es/yaml/legacy-yaml-report.mjs.map +1 -1
  32. package/dist/es/yaml/player.mjs +17 -3
  33. package/dist/es/yaml/player.mjs.map +1 -1
  34. package/dist/lib/agent/agent-options.js +73 -0
  35. package/dist/lib/agent/agent-options.js.map +1 -0
  36. package/dist/lib/agent/agent-report-manager.js +357 -0
  37. package/dist/lib/agent/agent-report-manager.js.map +1 -0
  38. package/dist/lib/agent/agent.js +110 -226
  39. package/dist/lib/agent/agent.js.map +1 -1
  40. package/dist/lib/agent/cache-config.js +23 -0
  41. package/dist/lib/agent/cache-config.js.map +1 -1
  42. package/dist/lib/agent/tasks.js +3 -1
  43. package/dist/lib/agent/tasks.js.map +1 -1
  44. package/dist/lib/agent/utils.js +1 -1
  45. package/dist/lib/report-generator.js +73 -33
  46. package/dist/lib/report-generator.js.map +1 -1
  47. package/dist/lib/report-html-template.js +1 -1
  48. package/dist/lib/test-runner/engine/document-runtime.js +30 -24
  49. package/dist/lib/test-runner/engine/document-runtime.js.map +1 -1
  50. package/dist/lib/test-runner/engine/project-runtime.js +17 -11
  51. package/dist/lib/test-runner/engine/project-runtime.js.map +1 -1
  52. package/dist/lib/test-runner/engine/resource-operations.js +36 -8
  53. package/dist/lib/test-runner/engine/resource-operations.js.map +1 -1
  54. package/dist/lib/test-runner/engine/run-collected-case.js +1 -0
  55. package/dist/lib/test-runner/engine/run-collected-case.js.map +1 -1
  56. package/dist/lib/test-runner/engine/run-workflow-document.js +3 -0
  57. package/dist/lib/test-runner/engine/run-workflow-document.js.map +1 -1
  58. package/dist/lib/test-runner/engine/setup-timeout.js +71 -0
  59. package/dist/lib/test-runner/engine/setup-timeout.js.map +1 -0
  60. package/dist/lib/utils.js +1 -1
  61. package/dist/lib/yaml/execution-session.js +4 -0
  62. package/dist/lib/yaml/execution-session.js.map +1 -1
  63. package/dist/lib/yaml/legacy-yaml-report.js +1 -1
  64. package/dist/lib/yaml/legacy-yaml-report.js.map +1 -1
  65. package/dist/lib/yaml/player.js +16 -2
  66. package/dist/lib/yaml/player.js.map +1 -1
  67. package/dist/types/agent/agent-options.d.ts +4 -0
  68. package/dist/types/agent/agent-options.d.ts.map +1 -0
  69. package/dist/types/agent/agent-report-manager.d.ts +92 -0
  70. package/dist/types/agent/agent-report-manager.d.ts.map +1 -0
  71. package/dist/types/agent/agent.d.ts +31 -24
  72. package/dist/types/agent/agent.d.ts.map +1 -1
  73. package/dist/types/agent/cache-config.d.ts +10 -0
  74. package/dist/types/agent/cache-config.d.ts.map +1 -1
  75. package/dist/types/agent/tasks.d.ts +1 -0
  76. package/dist/types/agent/tasks.d.ts.map +1 -1
  77. package/dist/types/report-generator.d.ts +5 -1
  78. package/dist/types/report-generator.d.ts.map +1 -1
  79. package/dist/types/test-runner/engine/document-runtime.d.ts.map +1 -1
  80. package/dist/types/test-runner/engine/project-runtime.d.ts.map +1 -1
  81. package/dist/types/test-runner/engine/resource-operations.d.ts +5 -0
  82. package/dist/types/test-runner/engine/resource-operations.d.ts.map +1 -1
  83. package/dist/types/test-runner/engine/run-collected-case.d.ts.map +1 -1
  84. package/dist/types/test-runner/engine/run-workflow-document.d.ts.map +1 -1
  85. package/dist/types/test-runner/engine/setup-timeout.d.ts +3 -0
  86. package/dist/types/test-runner/engine/setup-timeout.d.ts.map +1 -0
  87. package/dist/types/test-runner/engine/types.d.ts +7 -0
  88. package/dist/types/test-runner/engine/types.d.ts.map +1 -1
  89. package/dist/types/test-runner/project.d.ts +22 -0
  90. package/dist/types/test-runner/project.d.ts.map +1 -1
  91. package/dist/types/yaml/execution-session.d.ts +2 -0
  92. package/dist/types/yaml/execution-session.d.ts.map +1 -1
  93. package/dist/types/yaml/player.d.ts.map +1 -1
  94. package/package.json +2 -2
@@ -0,0 +1,36 @@
1
+ import { isAgentAIContextKey } from "@midscene/shared/agent-tools/agent-context";
2
+ import { assertReportGenerationOptions } from "../report-generator.mjs";
3
+ function withAgentDefaults(opts) {
4
+ const options = Object.assign({
5
+ generateReport: true,
6
+ persistExecutionDump: false,
7
+ autoPrintReportMsg: true,
8
+ groupName: 'Midscene Report',
9
+ groupDescription: ''
10
+ }, opts || {});
11
+ assertReportGenerationOptions(options);
12
+ return options;
13
+ }
14
+ function normalizeAgentOptions(options, warn) {
15
+ if (void 0 !== options.aiContexts && ('object' != typeof options.aiContexts || null === options.aiContexts || Array.isArray(options.aiContexts))) throw new TypeError('opts.aiContexts must be a plain object');
16
+ for (const [key, value] of Object.entries(options.aiContexts ?? {})){
17
+ if (!isAgentAIContextKey(key)) throw new TypeError(`Unknown Agent context key: ${key}`);
18
+ if (void 0 !== value && 'string' != typeof value) throw new TypeError(`Agent context "${key}" must be a string`);
19
+ }
20
+ const deprecatedAiActContextOption = void 0 !== options.aiActContext ? 'aiActContext' : void 0 !== options.aiActionContext ? 'aiActionContext' : void 0;
21
+ if (deprecatedAiActContextOption) warn(`Agent option "${deprecatedAiActContextOption}" is deprecated; use "aiContexts.aiAct" instead. When both are provided, "aiContexts.aiAct" takes precedence.`);
22
+ const normalizedAIContexts = {
23
+ ...options.aiContexts
24
+ };
25
+ const resolvedAiActContext = normalizedAIContexts.aiAct ?? options.aiActContext ?? options.aiActionContext;
26
+ if (void 0 !== resolvedAiActContext) {
27
+ normalizedAIContexts.aiAct = resolvedAiActContext;
28
+ options.aiActContext = resolvedAiActContext;
29
+ options.aiActionContext = resolvedAiActContext;
30
+ }
31
+ options.aiContexts = normalizedAIContexts;
32
+ if (options.modelConfig && ('object' != typeof options.modelConfig || Array.isArray(options.modelConfig))) throw new Error(`opts.modelConfig must be a plain object map of env keys to values, but got ${typeof options.modelConfig}`);
33
+ }
34
+ export { normalizeAgentOptions, withAgentDefaults };
35
+
36
+ //# sourceMappingURL=agent-options.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent/agent-options.mjs","sources":["../../../src/agent/agent-options.ts"],"sourcesContent":["import { isAgentAIContextKey } from '@midscene/shared/agent-tools/agent-context';\nimport { assertReportGenerationOptions } from '../report-generator';\nimport type { AgentAIContexts, AgentOpt } from '../types';\n\nexport function withAgentDefaults(opts?: AgentOpt): AgentOpt {\n const options = Object.assign(\n {\n generateReport: true,\n persistExecutionDump: false,\n autoPrintReportMsg: true,\n groupName: 'Midscene Report',\n groupDescription: '',\n },\n opts || {},\n );\n assertReportGenerationOptions(options);\n return options;\n}\n\nexport function normalizeAgentOptions(\n options: AgentOpt,\n warn: (message: string) => void,\n): void {\n if (\n options.aiContexts !== undefined &&\n (typeof options.aiContexts !== 'object' ||\n options.aiContexts === null ||\n Array.isArray(options.aiContexts))\n ) {\n throw new TypeError('opts.aiContexts must be a plain object');\n }\n\n for (const [key, value] of Object.entries(options.aiContexts ?? {})) {\n if (!isAgentAIContextKey(key)) {\n throw new TypeError(`Unknown Agent context key: ${key}`);\n }\n if (value !== undefined && typeof value !== 'string') {\n throw new TypeError(`Agent context \"${key}\" must be a string`);\n }\n }\n\n const deprecatedAiActContextOption =\n options.aiActContext !== undefined\n ? 'aiActContext'\n : options.aiActionContext !== undefined\n ? 'aiActionContext'\n : undefined;\n if (deprecatedAiActContextOption) {\n warn(\n `Agent option \"${deprecatedAiActContextOption}\" is deprecated; use \"aiContexts.aiAct\" instead. When both are provided, \"aiContexts.aiAct\" takes precedence.`,\n );\n }\n\n const normalizedAIContexts: AgentAIContexts = { ...options.aiContexts };\n const resolvedAiActContext =\n normalizedAIContexts.aiAct ??\n options.aiActContext ??\n options.aiActionContext;\n if (resolvedAiActContext !== undefined) {\n normalizedAIContexts.aiAct = resolvedAiActContext;\n options.aiActContext = resolvedAiActContext;\n options.aiActionContext = resolvedAiActContext;\n }\n options.aiContexts = normalizedAIContexts;\n\n if (\n options.modelConfig &&\n (typeof options.modelConfig !== 'object' ||\n Array.isArray(options.modelConfig))\n ) {\n throw new Error(\n `opts.modelConfig must be a plain object map of env keys to values, but got ${typeof options.modelConfig}`,\n );\n }\n}\n"],"names":["withAgentDefaults","opts","options","Object","assertReportGenerationOptions","normalizeAgentOptions","warn","undefined","Array","TypeError","key","value","isAgentAIContextKey","deprecatedAiActCont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GAAGY;IAErB,IACEZ,QAAQ,WAAW,IAClB,CAA+B,YAA/B,OAAOA,QAAQ,WAAW,IACzBM,MAAM,OAAO,CAACN,QAAQ,WAAW,IAEnC,MAAM,IAAIc,MACR,CAAC,2EAA2E,EAAE,OAAOd,QAAQ,WAAW,EAAE;AAGhH"}
@@ -0,0 +1,323 @@
1
+ import { getDebug } from "@midscene/shared/logger";
2
+ import { assert, ifInBrowser, uuid } from "@midscene/shared/utils";
3
+ import { IS_REPORT_BUILD } from "../constants.mjs";
4
+ import { generateTestRunReportScriptTag } from "../dump/html-utils.mjs";
5
+ import { ReportGenerator } from "../report-generator.mjs";
6
+ import { WorkflowError } from "../test-runner/errors.mjs";
7
+ import { buildAgentTestRunReportDump } from "../test-runner/reporting/agent-report.mjs";
8
+ import { executionRecordsToReportInput } from "../test-runner/reporting/execution-record.mjs";
9
+ import { ReportActionDump } from "../types.mjs";
10
+ import { getVersion, reportHTMLContent } from "../utils.mjs";
11
+ import { getReportFileName } from "./utils.mjs";
12
+ function _define_property(obj, key, value) {
13
+ if (key in obj) Object.defineProperty(obj, key, {
14
+ value: value,
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true
18
+ });
19
+ else obj[key] = value;
20
+ return obj;
21
+ }
22
+ const warn = getDebug('agent', {
23
+ console: true
24
+ });
25
+ class AgentReportManager {
26
+ get opts() {
27
+ return this.context.getOptions();
28
+ }
29
+ get dump() {
30
+ return this.reportState.dump;
31
+ }
32
+ set dump(value) {
33
+ this.reportState.dump = value;
34
+ }
35
+ get reportFile() {
36
+ return this.reportState.file;
37
+ }
38
+ set reportFile(value) {
39
+ this.reportState.file = value;
40
+ }
41
+ get reportFileName() {
42
+ return this.reportState.fileName;
43
+ }
44
+ set reportFileName(value) {
45
+ this.reportState.fileName = value;
46
+ }
47
+ _prepareForTestRunner() {
48
+ this.reportState.generator.enableSourceSnapshots?.();
49
+ }
50
+ async _createReportSource(scopeId, executionIds) {
51
+ return this.reportState.generator.createSourceSnapshot?.(scopeId, executionIds);
52
+ }
53
+ async _writeYamlExecutionReport(record) {
54
+ const report = this.reportState;
55
+ const existingIndex = report.yamlRecords.findIndex((entry)=>entry.runId === record.runId);
56
+ const recordIndex = existingIndex < 0 ? report.yamlRecords.length : existingIndex;
57
+ report.yamlRecords[recordIndex] = record;
58
+ try {
59
+ const path = await report.generator.writeRunnerReport?.(this.buildYamlReportInput(), report.yamlScopeId, this.getReportMeta());
60
+ report.file = path ?? report.file;
61
+ return path;
62
+ } catch (error) {
63
+ report.yamlRecords[recordIndex] = Object.freeze({
64
+ ...record,
65
+ status: 'failed',
66
+ reportError: error
67
+ });
68
+ throw error;
69
+ }
70
+ }
71
+ buildYamlReportInput() {
72
+ const scopedRecords = this.reportState.yamlRecords.map((entry)=>({
73
+ ...entry,
74
+ ...entry.execution ? {
75
+ execution: {
76
+ document: {
77
+ ...entry.execution.document,
78
+ reportScopeId: this.reportState.yamlScopeId
79
+ },
80
+ cases: entry.execution.cases.map((outcome)=>({
81
+ ...outcome,
82
+ ...outcome.run ? {
83
+ run: {
84
+ ...outcome.run,
85
+ reportScopeId: this.reportState.yamlScopeId
86
+ }
87
+ } : {},
88
+ ...outcome.attempts ? {
89
+ attempts: outcome.attempts.map((attempt)=>({
90
+ ...attempt,
91
+ reportScopeId: this.reportState.yamlScopeId
92
+ }))
93
+ } : {}
94
+ }))
95
+ }
96
+ } : {}
97
+ }));
98
+ return executionRecordsToReportInput(scopedRecords, {
99
+ runId: this.reportState.yamlScopeId
100
+ });
101
+ }
102
+ createEmptyDump() {
103
+ return new ReportActionDump({
104
+ sdkVersion: getVersion(),
105
+ groupName: this.opts.groupName,
106
+ groupDescription: this.opts.groupDescription,
107
+ executions: [],
108
+ modelBriefs: [],
109
+ deviceType: this.context.getDeviceType()
110
+ });
111
+ }
112
+ createReportState(fileName, reuseExistingReport = false) {
113
+ return {
114
+ dump: this.createEmptyDump(),
115
+ fileName,
116
+ generator: ReportGenerator.create(fileName, {
117
+ generateReport: this.opts.generateReport,
118
+ persistExecutionDump: this.opts.persistExecutionDump,
119
+ outputFormat: this.opts.outputFormat,
120
+ autoPrintReportMsg: this.opts.autoPrintReportMsg,
121
+ reuseExistingReport
122
+ }),
123
+ executionIndexByRunner: new WeakMap(),
124
+ yamlScopeId: uuid(),
125
+ yamlRecords: [],
126
+ activeOperations: new Set()
127
+ };
128
+ }
129
+ clearDumpInMemory(report = this.reportState) {
130
+ report.dump = this.createEmptyDump();
131
+ report.executionIndexByRunner = new WeakMap();
132
+ report.lastExecution = void 0;
133
+ report.yamlRecords.length = 0;
134
+ }
135
+ assertReportIdle() {
136
+ assert(!this.reportState.activeOperations.size && !this.context.isExternallyBusy(), 'Cannot reset or finalize a report while the Agent is executing. Await the active operation first.');
137
+ }
138
+ assertReportWritable() {
139
+ const report = this.reportState;
140
+ assert(!this.context.isDestroyed(), 'Cannot execute using a destroyed Agent.');
141
+ assert(!this.reportReset, 'Report reset is in progress. Await resetDump() first.');
142
+ assert(!report.finalization, 'The report has been finalized. Call and await resetDump() before executing again.');
143
+ return report;
144
+ }
145
+ async withReportOperation(operation) {
146
+ const report = this.assertReportWritable();
147
+ const pending = Promise.resolve().then(operation);
148
+ report.activeOperations.add(pending);
149
+ try {
150
+ return await pending;
151
+ } finally{
152
+ report.activeOperations.delete(pending);
153
+ }
154
+ }
155
+ async resetDump() {
156
+ assert(!this.context.isDestroyed(), 'Cannot reset a report using a destroyed Agent.');
157
+ if (this.reportReset) return this.reportReset;
158
+ this.assertReportIdle();
159
+ this.reportReset = (async ()=>{
160
+ try {
161
+ await this.finalizeReport();
162
+ } catch (error) {
163
+ warn(`Failed to finalize previous report; resetting dump: ${String(error)}`);
164
+ }
165
+ assert(!this.context.isDestroyed(), 'Cannot reset a report using a destroyed Agent.');
166
+ const fileName = getReportFileName(this.opts.testId || this.context.getDeviceType() || 'web');
167
+ this.reportState = this.createReportState(fileName);
168
+ return this.dump;
169
+ })();
170
+ try {
171
+ return await this.reportReset;
172
+ } finally{
173
+ this.reportReset = void 0;
174
+ }
175
+ }
176
+ async finalizeReport() {
177
+ const report = this.reportState;
178
+ if (!report.finalization) {
179
+ this.assertReportIdle();
180
+ report.finalization = (async ()=>{
181
+ await report.generator.flush();
182
+ const path = await report.generator.finalize();
183
+ report.file = path;
184
+ this.clearDumpInMemory(report);
185
+ return path;
186
+ })();
187
+ }
188
+ return report.finalization;
189
+ }
190
+ appendExecutionDump(execution, runner) {
191
+ assert(!this.reportState.finalization, 'Cannot append to a finalized report. Await resetDump() first.');
192
+ const currentDump = this.dump;
193
+ if (runner) {
194
+ const existingIndex = this.reportState.executionIndexByRunner.get(runner);
195
+ if (void 0 !== existingIndex) {
196
+ currentDump.executions[existingIndex] = execution;
197
+ return;
198
+ }
199
+ currentDump.executions.push(execution);
200
+ this.reportState.executionIndexByRunner.set(runner, currentDump.executions.length - 1);
201
+ return;
202
+ }
203
+ currentDump.executions.push(execution);
204
+ }
205
+ dumpDataString(opt) {
206
+ this.dump.groupName = this.opts.groupName;
207
+ this.dump.groupDescription = this.opts.groupDescription;
208
+ if (ifInBrowser || opt?.inlineScreenshots) return this.dump.serializeWithInlineScreenshots();
209
+ return this.dump.serialize();
210
+ }
211
+ reportHTMLString(getDumpString) {
212
+ if (IS_REPORT_BUILD) return '';
213
+ const dumpString = getDumpString();
214
+ if (!this.reportState.yamlRecords.length) return reportHTMLContent(dumpString);
215
+ const reportId = this.reportState.yamlScopeId;
216
+ const runnerDump = buildAgentTestRunReportDump(this.buildYamlReportInput(), this.dump, {
217
+ reportId,
218
+ scopeId: this.reportState.yamlScopeId,
219
+ sourcePath: this.reportFile ?? '<inline-agent-report>'
220
+ });
221
+ return `${reportHTMLContent({
222
+ dumpString,
223
+ attributes: {
224
+ 'data-group-id': reportId,
225
+ 'data-report-id': reportId
226
+ }
227
+ })}\n${generateTestRunReportScriptTag(runnerDump)}`;
228
+ }
229
+ writeOutActionDumps(executionDump) {
230
+ const report = this.reportState;
231
+ if (report.finalization) {
232
+ if (executionDump) throw new WorkflowError('Cannot append to a finalized report. Await resetDump() first.', {
233
+ code: 'REPORT_FINALIZED'
234
+ });
235
+ return;
236
+ }
237
+ const exec = executionDump || report.lastExecution;
238
+ if (exec) {
239
+ report.lastExecution = exec;
240
+ report.generator.onExecutionUpdate(exec, this.getReportMeta(), this.opts.reportAttributes);
241
+ }
242
+ report.file = report.generator.getReportPath();
243
+ }
244
+ async flushReport() {
245
+ if (this.reportReset) await this.reportReset;
246
+ const report = this.reportState;
247
+ if (report.finalization) return report.finalization;
248
+ this.writeOutActionDumps();
249
+ await report.generator.flush();
250
+ return report.lastExecution ? report.file ?? void 0 : void 0;
251
+ }
252
+ getReportMeta() {
253
+ return {
254
+ groupName: this.dump.groupName,
255
+ groupDescription: this.dump.groupDescription,
256
+ sdkVersion: this.dump.sdkVersion,
257
+ modelBriefs: this.dump.modelBriefs,
258
+ deviceType: this.dump.deviceType
259
+ };
260
+ }
261
+ get onDumpUpdate() {
262
+ return this.dumpUpdateListeners[0];
263
+ }
264
+ set onDumpUpdate(callback) {
265
+ this.dumpUpdateListeners = [];
266
+ if (callback) this.dumpUpdateListeners.push(callback);
267
+ }
268
+ addDumpUpdateListener(listener) {
269
+ this.dumpUpdateListeners.push(listener);
270
+ return ()=>{
271
+ this.removeDumpUpdateListener(listener);
272
+ };
273
+ }
274
+ removeDumpUpdateListener(listener) {
275
+ const index = this.dumpUpdateListeners.indexOf(listener);
276
+ if (index > -1) this.dumpUpdateListeners.splice(index, 1);
277
+ }
278
+ clearDumpUpdateListeners() {
279
+ this.dumpUpdateListeners = [];
280
+ }
281
+ notifyDumpUpdateListeners(executionDump) {
282
+ const dumpString = this.dumpDataString();
283
+ for (const listener of this.dumpUpdateListeners)try {
284
+ listener(dumpString, executionDump);
285
+ } catch (error) {
286
+ console.error('Error in onDumpUpdate listener', error);
287
+ }
288
+ }
289
+ bindRunner(runner) {
290
+ this.reportByRunner.set(runner, this.reportState);
291
+ }
292
+ assertRunnerCurrent(runner) {
293
+ const report = this.reportByRunner.get(runner);
294
+ assert(report === this.reportState && !report.finalization, 'Cannot write a late execution update into a different or finalized report.');
295
+ }
296
+ async flushPendingWrites() {
297
+ await this.reportState.generator.flush();
298
+ }
299
+ async waitForOperations() {
300
+ while(this.reportState.activeOperations.size)await Promise.allSettled([
301
+ ...this.reportState.activeOperations
302
+ ]);
303
+ }
304
+ async waitForReset() {
305
+ if (this.reportReset) await this.reportReset.catch(()=>{});
306
+ }
307
+ constructor(context){
308
+ _define_property(this, "context", void 0);
309
+ _define_property(this, "reportState", void 0);
310
+ _define_property(this, "reportReset", void 0);
311
+ _define_property(this, "reportByRunner", void 0);
312
+ _define_property(this, "dumpUpdateListeners", void 0);
313
+ this.context = context;
314
+ this.reportByRunner = new WeakMap();
315
+ this.dumpUpdateListeners = [];
316
+ const opts = this.opts;
317
+ const fileName = opts.reportFileName ?? getReportFileName(opts.testId || context.getDeviceType() || 'web');
318
+ this.reportState = this.createReportState(fileName, opts.reportAttributes?.['data-group-id'] === fileName);
319
+ }
320
+ }
321
+ export { AgentReportManager };
322
+
323
+ //# sourceMappingURL=agent-report-manager.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent/agent-report-manager.mjs","sources":["../../../src/agent/agent-report-manager.ts"],"sourcesContent":["import { getDebug } from '@midscene/shared/logger';\nimport { assert, ifInBrowser, uuid } from '@midscene/shared/utils';\nimport { IS_REPORT_BUILD } from '../constants';\nimport { generateTestRunReportScriptTag } from '../dump/html-utils';\nimport { type IReportGenerator, ReportGenerator } from '../report-generator';\nimport type { TaskRunner } from '../task-runner';\nimport { WorkflowError } from '../test-runner/errors';\nimport type { WorkflowExecutionRecord } from '../test-runner/execution-record';\nimport { buildAgentTestRunReportDump } from '../test-runner/reporting/agent-report';\nimport { executionRecordsToReportInput } from '../test-runner/reporting/execution-record';\nimport {\n type AgentOpt,\n type ExecutionDump,\n ReportActionDump,\n type ReportMeta,\n} from '../types';\nimport { getVersion, reportHTMLContent } from '../utils';\nimport { getReportFileName } from './utils';\n\nconst warn = getDebug('agent', { console: true });\n\ntype ReportOptions = Pick<\n AgentOpt,\n | 'groupName'\n | 'groupDescription'\n | 'generateReport'\n | 'persistExecutionDump'\n | 'outputFormat'\n | 'autoPrintReportMsg'\n | 'reportAttributes'\n | 'reportFileName'\n | 'testId'\n>;\n\ninterface AgentReportContext {\n getOptions(): ReportOptions;\n getDeviceType(): ReportActionDump['deviceType'];\n isDestroyed(): boolean;\n isExternallyBusy(): boolean;\n}\n\ninterface AgentReportState {\n dump: ReportActionDump;\n file?: string | null;\n fileName?: string;\n generator: IReportGenerator;\n finalization?: Promise<string | undefined>;\n lastExecution?: ExecutionDump;\n executionIndexByRunner: WeakMap<TaskRunner, number>;\n yamlScopeId: string;\n yamlRecords: WorkflowExecutionRecord[];\n activeOperations: Set<Promise<unknown>>;\n}\n\n/** Owns report state and persistence; execution and device ownership stay with Agent. */\nexport class AgentReportManager {\n private reportState: AgentReportState;\n private reportReset?: Promise<ReportActionDump>;\n private readonly reportByRunner = new WeakMap<TaskRunner, AgentReportState>();\n private dumpUpdateListeners: Array<\n (dump: string, executionDump?: ExecutionDump) => void\n > = [];\n\n constructor(private readonly context: AgentReportContext) {\n const opts = this.opts;\n const fileName =\n opts.reportFileName ??\n getReportFileName(opts.testId || context.getDeviceType() || 'web');\n this.reportState = this.createReportState(\n fileName,\n opts.reportAttributes?.['data-group-id'] === fileName,\n );\n }\n\n private get opts(): ReportOptions {\n return this.context.getOptions();\n }\n\n get dump(): ReportActionDump {\n return this.reportState.dump;\n }\n set dump(value: ReportActionDump) {\n this.reportState.dump = value;\n }\n\n get reportFile(): string | null | undefined {\n return this.reportState.file;\n }\n set reportFile(value: string | null | undefined) {\n this.reportState.file = value;\n }\n\n get reportFileName(): string | undefined {\n return this.reportState.fileName;\n }\n set reportFileName(value: string | undefined) {\n this.reportState.fileName = value;\n }\n\n /** @internal Runner snapshots retain immutable data and shared image files. */\n _prepareForTestRunner(): void {\n this.reportState.generator.enableSourceSnapshots?.();\n }\n async _createReportSource(scopeId: string, executionIds?: readonly string[]) {\n return this.reportState.generator.createSourceSnapshot?.(\n scopeId,\n executionIds,\n );\n }\n\n /** @internal The Agent owns one report stream across root YAML invocations. */\n async _writeYamlExecutionReport(\n record: WorkflowExecutionRecord,\n ): Promise<string | undefined> {\n const report = this.reportState;\n const existingIndex = report.yamlRecords.findIndex(\n (entry) => entry.runId === record.runId,\n );\n const recordIndex =\n existingIndex < 0 ? report.yamlRecords.length : existingIndex;\n report.yamlRecords[recordIndex] = record;\n try {\n const path = await report.generator.writeRunnerReport?.(\n this.buildYamlReportInput(),\n report.yamlScopeId,\n this.getReportMeta(),\n );\n report.file = path ?? report.file;\n return path;\n } catch (error) {\n report.yamlRecords[recordIndex] = Object.freeze({\n ...record,\n status: 'failed',\n reportError: error,\n });\n throw error;\n }\n }\n\n private buildYamlReportInput() {\n const scopedRecords = this.reportState.yamlRecords.map((entry) => ({\n ...entry,\n ...(entry.execution\n ? {\n execution: {\n document: {\n ...entry.execution.document,\n reportScopeId: this.reportState.yamlScopeId,\n },\n cases: entry.execution.cases.map((outcome) => ({\n ...outcome,\n ...(outcome.run\n ? {\n run: {\n ...outcome.run,\n reportScopeId: this.reportState.yamlScopeId,\n },\n }\n : {}),\n ...(outcome.attempts\n ? {\n attempts: outcome.attempts.map((attempt) => ({\n ...attempt,\n reportScopeId: this.reportState.yamlScopeId,\n })),\n }\n : {}),\n })),\n },\n }\n : {}),\n }));\n return executionRecordsToReportInput(scopedRecords, {\n runId: this.reportState.yamlScopeId,\n });\n }\n\n private createEmptyDump(): ReportActionDump {\n return new ReportActionDump({\n sdkVersion: getVersion(),\n groupName: this.opts.groupName!,\n groupDescription: this.opts.groupDescription,\n executions: [],\n modelBriefs: [],\n deviceType: this.context.getDeviceType(),\n });\n }\n\n private createReportState(\n fileName: string,\n reuseExistingReport = false,\n ): AgentReportState {\n return {\n dump: this.createEmptyDump(),\n fileName,\n generator: ReportGenerator.create(fileName, {\n generateReport: this.opts.generateReport,\n persistExecutionDump: this.opts.persistExecutionDump,\n outputFormat: this.opts.outputFormat,\n autoPrintReportMsg: this.opts.autoPrintReportMsg,\n reuseExistingReport,\n }),\n executionIndexByRunner: new WeakMap(),\n yamlScopeId: uuid(),\n yamlRecords: [],\n activeOperations: new Set(),\n };\n }\n\n private clearDumpInMemory(report = this.reportState): void {\n report.dump = this.createEmptyDump();\n report.executionIndexByRunner = new WeakMap();\n report.lastExecution = undefined;\n report.yamlRecords.length = 0;\n }\n\n private assertReportIdle(): void {\n assert(\n !this.reportState.activeOperations.size &&\n !this.context.isExternallyBusy(),\n 'Cannot reset or finalize a report while the Agent is executing. Await the active operation first.',\n );\n }\n\n assertReportWritable(): AgentReportState {\n const report = this.reportState;\n assert(\n !this.context.isDestroyed(),\n 'Cannot execute using a destroyed Agent.',\n );\n assert(\n !this.reportReset,\n 'Report reset is in progress. Await resetDump() first.',\n );\n assert(\n !report.finalization,\n 'The report has been finalized. Call and await resetDump() before executing again.',\n );\n return report;\n }\n\n async withReportOperation<T>(operation: () => Promise<T>): Promise<T> {\n const report = this.assertReportWritable();\n const pending = Promise.resolve().then(operation);\n report.activeOperations.add(pending);\n try {\n return await pending;\n } finally {\n report.activeOperations.delete(pending);\n }\n }\n\n /**\n * Finalize the preceding report and reset execution records for a new report.\n * Historical artifacts are retained; this Agent and its device stay connected.\n * Await this method before executing again. Concurrent resets share one reset.\n */\n async resetDump(): Promise<ReportActionDump> {\n assert(\n !this.context.isDestroyed(),\n 'Cannot reset a report using a destroyed Agent.',\n );\n if (this.reportReset) return this.reportReset;\n this.assertReportIdle();\n this.reportReset = (async () => {\n try {\n await this.finalizeReport();\n } catch (error) {\n // Failure belongs to the preceding report, not to the next write queue.\n warn(\n `Failed to finalize previous report; resetting dump: ${String(error)}`,\n );\n }\n assert(\n !this.context.isDestroyed(),\n 'Cannot reset a report using a destroyed Agent.',\n );\n const fileName = getReportFileName(\n this.opts.testId || this.context.getDeviceType() || 'web',\n );\n this.reportState = this.createReportState(fileName);\n return this.dump;\n })();\n try {\n return await this.reportReset;\n } finally {\n this.reportReset = undefined;\n }\n }\n\n /**\n * Seal the current report and release its in-memory records without\n * disconnecting the device. Export in-memory data before calling this method.\n * Repeated calls return the same result and never rewrite published artifacts.\n */\n async finalizeReport(): Promise<string | undefined> {\n const report = this.reportState;\n if (!report.finalization) {\n this.assertReportIdle();\n report.finalization = (async () => {\n await report.generator.flush();\n const path = await report.generator.finalize();\n report.file = path;\n this.clearDumpInMemory(report);\n return path;\n })();\n }\n return report.finalization;\n }\n\n appendExecutionDump(execution: ExecutionDump, runner?: TaskRunner) {\n assert(\n !this.reportState.finalization,\n 'Cannot append to a finalized report. Await resetDump() first.',\n );\n const currentDump = this.dump;\n if (runner) {\n const existingIndex = this.reportState.executionIndexByRunner.get(runner);\n if (existingIndex !== undefined) {\n currentDump.executions[existingIndex] = execution;\n return;\n }\n currentDump.executions.push(execution);\n this.reportState.executionIndexByRunner.set(\n runner,\n currentDump.executions.length - 1,\n );\n return;\n }\n currentDump.executions.push(execution);\n }\n\n dumpDataString(opt?: { inlineScreenshots?: boolean }) {\n // update dump info\n this.dump.groupName = this.opts.groupName!;\n this.dump.groupDescription = this.opts.groupDescription;\n // In browser environment, use inline screenshots since file system is not available\n if (ifInBrowser || opt?.inlineScreenshots) {\n return this.dump.serializeWithInlineScreenshots();\n }\n return this.dump.serialize();\n }\n\n reportHTMLString(getDumpString: () => string) {\n // Short-circuit at the call site because JavaScript evaluates function\n // arguments first. This avoids serializing the dump (including inline\n // screenshots) when the Report Viewer build does not need report HTML.\n if (IS_REPORT_BUILD) {\n return '';\n }\n\n // dumpDataString() handles browser environment with inline screenshots\n const dumpString = getDumpString();\n if (!this.reportState.yamlRecords.length)\n return reportHTMLContent(dumpString);\n\n // Browser exports have no file writer, so the execution record must own\n // the hierarchy independently of whether file report generation is enabled.\n const reportId = this.reportState.yamlScopeId;\n const runnerDump = buildAgentTestRunReportDump(\n this.buildYamlReportInput(),\n this.dump,\n {\n reportId,\n scopeId: this.reportState.yamlScopeId,\n sourcePath: this.reportFile ?? '<inline-agent-report>',\n },\n );\n return `${reportHTMLContent({\n dumpString,\n attributes: { 'data-group-id': reportId, 'data-report-id': reportId },\n })}\\n${generateTestRunReportScriptTag(runnerDump)}`;\n }\n\n writeOutActionDumps(executionDump?: ExecutionDump) {\n const report = this.reportState;\n if (report.finalization) {\n if (executionDump) {\n throw new WorkflowError(\n 'Cannot append to a finalized report. Await resetDump() first.',\n {\n code: 'REPORT_FINALIZED',\n },\n );\n }\n return;\n }\n const exec = executionDump || report.lastExecution;\n if (exec) {\n report.lastExecution = exec;\n report.generator.onExecutionUpdate(\n exec,\n this.getReportMeta(),\n this.opts.reportAttributes,\n );\n }\n report.file = report.generator.getReportPath();\n }\n\n /** Persist current report data without disposing this Agent or its device. */\n async flushReport(): Promise<string | undefined> {\n if (this.reportReset) await this.reportReset;\n const report = this.reportState;\n if (report.finalization) return report.finalization;\n this.writeOutActionDumps();\n await report.generator.flush();\n return report.lastExecution ? (report.file ?? undefined) : undefined;\n }\n\n private getReportMeta(): ReportMeta {\n return {\n groupName: this.dump.groupName,\n groupDescription: this.dump.groupDescription,\n sdkVersion: this.dump.sdkVersion,\n modelBriefs: this.dump.modelBriefs,\n deviceType: this.dump.deviceType,\n };\n }\n\n get onDumpUpdate():\n | ((dump: string, executionDump?: ExecutionDump) => void)\n | undefined {\n return this.dumpUpdateListeners[0];\n }\n\n set onDumpUpdate(callback:\n | ((dump: string, executionDump?: ExecutionDump) => void)\n | undefined) {\n // Clear existing listeners\n this.dumpUpdateListeners = [];\n // Add callback to array if provided\n if (callback) {\n this.dumpUpdateListeners.push(callback);\n }\n }\n\n addDumpUpdateListener(\n listener: (dump: string, executionDump?: ExecutionDump) => void,\n ): () => void {\n this.dumpUpdateListeners.push(listener);\n\n // Return remove function\n return () => {\n this.removeDumpUpdateListener(listener);\n };\n }\n\n /**\n * Remove a dump update listener\n * @param listener The listener function to remove\n */\n removeDumpUpdateListener(\n listener: (dump: string, executionDump?: ExecutionDump) => void,\n ): void {\n const index = this.dumpUpdateListeners.indexOf(listener);\n if (index > -1) {\n this.dumpUpdateListeners.splice(index, 1);\n }\n }\n\n /**\n * Clear all dump update listeners\n */\n clearDumpUpdateListeners(): void {\n this.dumpUpdateListeners = [];\n }\n\n notifyDumpUpdateListeners(executionDump?: ExecutionDump) {\n const dumpString = this.dumpDataString();\n for (const listener of this.dumpUpdateListeners) {\n try {\n listener(dumpString, executionDump);\n } catch (error) {\n console.error('Error in onDumpUpdate listener', error);\n }\n }\n }\n\n bindRunner(runner: TaskRunner): void {\n this.reportByRunner.set(runner, this.reportState);\n }\n\n assertRunnerCurrent(runner: TaskRunner): void {\n const report = this.reportByRunner.get(runner);\n assert(\n report === this.reportState && !report.finalization,\n 'Cannot write a late execution update into a different or finalized report.',\n );\n }\n\n async flushPendingWrites(): Promise<void> {\n await this.reportState.generator.flush();\n }\n\n async waitForOperations(): Promise<void> {\n while (this.reportState.activeOperations.size) {\n await Promise.allSettled([...this.reportState.activeOperations]);\n }\n }\n\n async waitForReset(): Promise<void> {\n if (this.reportReset) await this.reportReset.catch(() => {});\n }\n}\n"],"names":["warn","getDebug","AgentReportManager","value","scopeId","executionIds","record","report","existingIndex","entry","recordIndex","path","error","Object","scopedRecords","outcome","attempt","executionRecordsToReportInput","ReportActionDump","getVersion","fileName","reuseExistingReport","ReportGenerator","WeakMap","uuid","Set","undefined","assert","operation","pending","Promise","String","getReportFileName","execution","runner","currentDump","opt","ifInBrowser","getDumpString","IS_REPORT_BUILD","dumpString","reportHTMLContent","reportId","runnerDump","buildAgentTestRunReportDump","generateTestRunReportScriptTag","executionDump","WorkflowError","exec","callback","listener","index","console","context","opts"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,MAAMA,OAAOC,SAAS,SAAS;IAAE,SAAS;AAAK;AAoCxC,MAAMC;IAmBX,IAAY,OAAsB;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU;IAChC;IAEA,IAA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