@midscene/test 1.12.6-beta-20260910093036.0 → 1.12.6

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 (44) hide show
  1. package/dist/es/1~891.mjs +19 -39
  2. package/dist/es/1~891.mjs.map +1 -1
  3. package/dist/es/cli/index.mjs +26 -44
  4. package/dist/es/cli/index.mjs.map +1 -1
  5. package/dist/es/index.mjs +0 -3
  6. package/dist/es/index.mjs.map +1 -1
  7. package/dist/es/midscene/index.mjs +43 -32
  8. package/dist/es/midscene/index.mjs.map +1 -1
  9. package/dist/es/test-cli.mjs +37 -49
  10. package/dist/es/test-cli.mjs.map +1 -1
  11. package/dist/lib/0~458.js +19 -39
  12. package/dist/lib/0~458.js.map +1 -1
  13. package/dist/lib/cli/index.js +26 -44
  14. package/dist/lib/cli/index.js.map +1 -1
  15. package/dist/lib/index.js +0 -3
  16. package/dist/lib/index.js.map +1 -1
  17. package/dist/lib/midscene/index.js +253 -262
  18. package/dist/lib/midscene/index.js.map +1 -1
  19. package/dist/lib/test-cli.js +37 -49
  20. package/dist/lib/test-cli.js.map +1 -1
  21. package/dist/types/cli/index.d.ts +12 -13
  22. package/dist/types/index.d.ts +1 -7
  23. package/dist/types/midscene/index.d.ts +21 -21
  24. package/package.json +8 -48
  25. package/dist/es/android/index.mjs +0 -182
  26. package/dist/es/android/index.mjs.map +0 -1
  27. package/dist/es/harmony/index.mjs +0 -182
  28. package/dist/es/harmony/index.mjs.map +0 -1
  29. package/dist/es/ios/index.mjs +0 -182
  30. package/dist/es/ios/index.mjs.map +0 -1
  31. package/dist/es/playwright/index.mjs +0 -366
  32. package/dist/es/playwright/index.mjs.map +0 -1
  33. package/dist/lib/android/index.js +0 -255
  34. package/dist/lib/android/index.js.map +0 -1
  35. package/dist/lib/harmony/index.js +0 -252
  36. package/dist/lib/harmony/index.js.map +0 -1
  37. package/dist/lib/ios/index.js +0 -255
  38. package/dist/lib/ios/index.js.map +0 -1
  39. package/dist/lib/playwright/index.js +0 -412
  40. package/dist/lib/playwright/index.js.map +0 -1
  41. package/dist/types/android/index.d.ts +0 -140
  42. package/dist/types/harmony/index.d.ts +0 -137
  43. package/dist/types/ios/index.d.ts +0 -143
  44. package/dist/types/playwright/index.d.ts +0 -229
@@ -1,73 +1,5 @@
1
1
  "use strict";
2
- var __webpack_modules__ = {
3
- "./src/errors.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
4
- __webpack_require__.d(__webpack_exports__, {
5
- h2: ()=>NodeExecutionError,
6
- ww: ()=>NodeDefinitionError
7
- });
8
- function _define_property(obj, key, value) {
9
- if (key in obj) Object.defineProperty(obj, key, {
10
- value: value,
11
- enumerable: true,
12
- configurable: true,
13
- writable: true
14
- });
15
- else obj[key] = value;
16
- return obj;
17
- }
18
- class WorkflowError extends Error {
19
- toJSON() {
20
- return {
21
- name: this.name,
22
- message: this.message,
23
- code: this.code,
24
- ...void 0 === this.details ? {} : {
25
- details: this.details
26
- }
27
- };
28
- }
29
- constructor(message, options = {}){
30
- super(message, {
31
- cause: options.cause
32
- }), _define_property(this, "code", void 0), _define_property(this, "details", void 0);
33
- this.name = new.target.name;
34
- this.code = options.code ?? 'WORKFLOW_ERROR';
35
- this.details = options.details;
36
- }
37
- }
38
- class NodeDefinitionError extends WorkflowError {
39
- constructor(message, details){
40
- super(message, {
41
- code: 'NODE_DEFINITION_ERROR',
42
- details
43
- });
44
- }
45
- }
46
- class NodeExecutionError extends WorkflowError {
47
- constructor(node, cause){
48
- const causeMessage = cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');
49
- super(`Node "${node}" failed: ${causeMessage}`, {
50
- code: 'NODE_EXECUTION_ERROR',
51
- details: {
52
- node
53
- },
54
- cause
55
- }), _define_property(this, "node", void 0);
56
- this.node = node;
57
- }
58
- }
59
- }
60
- };
61
- var __webpack_module_cache__ = {};
62
- function __webpack_require__(moduleId) {
63
- var cachedModule = __webpack_module_cache__[moduleId];
64
- if (void 0 !== cachedModule) return cachedModule.exports;
65
- var module = __webpack_module_cache__[moduleId] = {
66
- exports: {}
67
- };
68
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
69
- return module.exports;
70
- }
2
+ var __webpack_require__ = {};
71
3
  (()=>{
72
4
  __webpack_require__.d = (exports1, definition)=>{
73
5
  for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
@@ -90,212 +22,271 @@ function __webpack_require__(moduleId) {
90
22
  };
91
23
  })();
92
24
  var __webpack_exports__ = {};
93
- (()=>{
94
- __webpack_require__.r(__webpack_exports__);
95
- __webpack_require__.d(__webpack_exports__, {
96
- createAgentTestRunnerNodes: ()=>createAgentTestRunnerNodes,
97
- aiActOptionsInputSchema: ()=>test_runner_namespaceObject.aiActOptionsInputSchema,
98
- aiTapInputSchema: ()=>test_runner_namespaceObject.aiTapInputSchema,
99
- reportScreenshotInputSchema: ()=>test_runner_namespaceObject.reportScreenshotInputSchema,
100
- insightInputSchema: ()=>test_runner_namespaceObject.insightInputSchema,
101
- locateOptionsInputSchema: ()=>test_runner_namespaceObject.locateOptionsInputSchema,
102
- structuredUserPromptInputSchema: ()=>test_runner_namespaceObject.structuredUserPromptInputSchema,
103
- waitInputSchema: ()=>waitInputSchema,
104
- promptImageInputSchema: ()=>test_runner_namespaceObject.promptImageInputSchema,
105
- aiAssertInputSchema: ()=>test_runner_namespaceObject.aiAssertInputSchema,
106
- createMidsceneNodes: ()=>createMidsceneNodes,
107
- recordToReportInputSchema: ()=>test_runner_namespaceObject.recordToReportInputSchema,
108
- recordToReportOptionsInputSchema: ()=>test_runner_namespaceObject.recordToReportOptionsInputSchema,
109
- userPromptInputSchema: ()=>test_runner_namespaceObject.userPromptInputSchema,
110
- aiAssertOptionsInputSchema: ()=>test_runner_namespaceObject.aiAssertOptionsInputSchema,
111
- aiActInputSchema: ()=>test_runner_namespaceObject.aiActInputSchema,
112
- insightOptionsInputSchema: ()=>test_runner_namespaceObject.insightOptionsInputSchema
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ createAgentTestRunnerNodes: ()=>createAgentTestRunnerNodes,
28
+ aiActOptionsInputSchema: ()=>test_namespaceObject.aiActOptionsInputSchema,
29
+ aiTapInputSchema: ()=>test_namespaceObject.aiTapInputSchema,
30
+ reportScreenshotInputSchema: ()=>test_namespaceObject.reportScreenshotInputSchema,
31
+ insightInputSchema: ()=>test_namespaceObject.insightInputSchema,
32
+ locateOptionsInputSchema: ()=>test_namespaceObject.locateOptionsInputSchema,
33
+ structuredUserPromptInputSchema: ()=>test_namespaceObject.structuredUserPromptInputSchema,
34
+ waitInputSchema: ()=>waitInputSchema,
35
+ promptImageInputSchema: ()=>test_namespaceObject.promptImageInputSchema,
36
+ aiAssertInputSchema: ()=>test_namespaceObject.aiAssertInputSchema,
37
+ createMidsceneNodes: ()=>createMidsceneNodes,
38
+ recordToReportInputSchema: ()=>test_namespaceObject.recordToReportInputSchema,
39
+ recordToReportOptionsInputSchema: ()=>test_namespaceObject.recordToReportOptionsInputSchema,
40
+ userPromptInputSchema: ()=>test_namespaceObject.userPromptInputSchema,
41
+ aiAssertOptionsInputSchema: ()=>test_namespaceObject.aiAssertOptionsInputSchema,
42
+ aiActInputSchema: ()=>test_namespaceObject.aiActInputSchema,
43
+ insightOptionsInputSchema: ()=>test_namespaceObject.insightOptionsInputSchema
44
+ });
45
+ const test_namespaceObject = require("@midscene/core/agent/test");
46
+ const logger_namespaceObject = require("@midscene/shared/logger");
47
+ const v4_namespaceObject = require("zod/v4");
48
+ function _define_property(obj, key, value) {
49
+ if (key in obj) Object.defineProperty(obj, key, {
50
+ value: value,
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true
113
54
  });
114
- const test_runner_namespaceObject = require("@midscene/core/agent/test-runner");
115
- const logger_namespaceObject = require("@midscene/shared/logger");
116
- const v4_namespaceObject = require("zod/v4");
117
- var errors = __webpack_require__("./src/errors.ts");
118
- const validateOptionalText = (value, field, node)=>{
119
- if (void 0 !== value && ('string' != typeof value || 0 === value.trim().length)) throw new errors.ww(`Node "${node}" ${field} must be a non-empty string.`, {
120
- node,
121
- field
122
- });
123
- };
124
- const validateInputSchema = (schema, node)=>{
125
- if (void 0 === schema) return;
126
- if (!(schema instanceof v4_namespaceObject.z.ZodObject)) throw new errors.ww(`Node "${node}" inputSchema must be a Zod object schema.`, {
127
- node,
128
- field: 'inputSchema'
129
- });
130
- if ('$' in schema.shape) throw new errors.ww(`Node "${node}" inputSchema must not declare "$" as an input property.`, {
131
- node,
132
- field: 'inputSchema.$'
133
- });
134
- };
135
- const validateDefinition = (options)=>{
136
- if (!options || 'object' != typeof options) throw new errors.ww('Node definition must be an object.');
137
- if ('string' != typeof options.name || 0 === options.name.trim().length) throw new errors.ww('Node name must be a non-empty string.');
138
- validateOptionalText(options.title, 'title', options.name);
139
- validateOptionalText(options.description, "description", options.name);
140
- if (void 0 !== options.stringInputKey && false !== options.stringInputKey && ('string' != typeof options.stringInputKey || 0 === options.stringInputKey.trim().length)) throw new errors.ww(`Node "${options.name}" stringInputKey must be a non-empty string or false.`, {
141
- node: options.name,
142
- field: 'stringInputKey'
143
- });
144
- validateInputSchema(options.inputSchema, options.name);
145
- if ('string' == typeof options.stringInputKey && options.inputSchema instanceof v4_namespaceObject.z.ZodObject && !(options.stringInputKey in options.inputSchema.shape)) throw new errors.ww(`Node "${options.name}" stringInputKey must reference a field in inputSchema.`, {
146
- node: options.name,
147
- field: 'stringInputKey'
148
- });
149
- if ('function' != typeof options.execute) throw new errors.ww(`Node "${options.name}" must provide an execute function.`, {
150
- node: options.name
55
+ else obj[key] = value;
56
+ return obj;
57
+ }
58
+ class WorkflowError extends Error {
59
+ toJSON() {
60
+ return {
61
+ name: this.name,
62
+ message: this.message,
63
+ code: this.code,
64
+ ...void 0 === this.details ? {} : {
65
+ details: this.details
66
+ }
67
+ };
68
+ }
69
+ constructor(message, options = {}){
70
+ super(message, {
71
+ cause: options.cause
72
+ }), _define_property(this, "code", void 0), _define_property(this, "details", void 0);
73
+ this.name = new.target.name;
74
+ this.code = options.code ?? 'WORKFLOW_ERROR';
75
+ this.details = options.details;
76
+ }
77
+ }
78
+ class NodeDefinitionError extends WorkflowError {
79
+ constructor(message, details){
80
+ super(message, {
81
+ code: 'NODE_DEFINITION_ERROR',
82
+ details
151
83
  });
152
- };
153
- function defineNode(options) {
154
- validateDefinition(options);
155
- return options;
156
84
  }
157
- const waitInputSchema = v4_namespaceObject.z.strictObject({
158
- duration: v4_namespaceObject.z.number().positive().describe('How long to wait.'),
159
- unit: v4_namespaceObject.z["enum"]([
160
- 'ms',
161
- 's',
162
- 'min'
163
- ]).default('ms').describe('Duration unit: milliseconds, seconds, or minutes.')
85
+ }
86
+ class NodeExecutionError extends WorkflowError {
87
+ constructor(node, cause){
88
+ const causeMessage = cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');
89
+ super(`Node "${node}" failed: ${causeMessage}`, {
90
+ code: 'NODE_EXECUTION_ERROR',
91
+ details: {
92
+ node
93
+ },
94
+ cause
95
+ }), _define_property(this, "node", void 0);
96
+ this.node = node;
97
+ }
98
+ }
99
+ const validateOptionalText = (value, field, node)=>{
100
+ if (void 0 !== value && ('string' != typeof value || 0 === value.trim().length)) throw new NodeDefinitionError(`Node "${node}" ${field} must be a non-empty string.`, {
101
+ node,
102
+ field
164
103
  });
165
- const waitFor = async (durationMs, signal)=>{
166
- if (signal.aborted) throw signal.reason ?? new Error('Wait aborted.');
167
- await new Promise((resolve, reject)=>{
168
- const timeout = setTimeout(()=>{
169
- signal.removeEventListener('abort', abort);
170
- resolve();
171
- }, durationMs);
172
- const abort = ()=>{
173
- clearTimeout(timeout);
174
- reject(signal.reason ?? new Error('Wait aborted.'));
175
- };
176
- signal.addEventListener('abort', abort, {
177
- once: true
178
- });
104
+ };
105
+ const validateInputSchema = (schema, node)=>{
106
+ if (void 0 === schema) return;
107
+ if (!(schema instanceof v4_namespaceObject.z.ZodObject)) throw new NodeDefinitionError(`Node "${node}" inputSchema must be a Zod object schema.`, {
108
+ node,
109
+ field: 'inputSchema'
110
+ });
111
+ if ('$' in schema.shape) throw new NodeDefinitionError(`Node "${node}" inputSchema must not declare "$" as an input property.`, {
112
+ node,
113
+ field: 'inputSchema.$'
114
+ });
115
+ };
116
+ const validateDefinition = (options)=>{
117
+ if (!options || 'object' != typeof options) throw new NodeDefinitionError('Node definition must be an object.');
118
+ if ('string' != typeof options.name || 0 === options.name.trim().length) throw new NodeDefinitionError('Node name must be a non-empty string.');
119
+ validateOptionalText(options.title, 'title', options.name);
120
+ validateOptionalText(options.description, "description", options.name);
121
+ if (void 0 !== options.stringInputKey && false !== options.stringInputKey && ('string' != typeof options.stringInputKey || 0 === options.stringInputKey.trim().length)) throw new NodeDefinitionError(`Node "${options.name}" stringInputKey must be a non-empty string or false.`, {
122
+ node: options.name,
123
+ field: 'stringInputKey'
124
+ });
125
+ validateInputSchema(options.inputSchema, options.name);
126
+ if ('string' == typeof options.stringInputKey && options.inputSchema instanceof v4_namespaceObject.z.ZodObject && !(options.stringInputKey in options.inputSchema.shape)) throw new NodeDefinitionError(`Node "${options.name}" stringInputKey must reference a field in inputSchema.`, {
127
+ node: options.name,
128
+ field: 'stringInputKey'
129
+ });
130
+ if ('function' != typeof options.execute) throw new NodeDefinitionError(`Node "${options.name}" must provide an execute function.`, {
131
+ node: options.name
132
+ });
133
+ };
134
+ function defineNode(options) {
135
+ validateDefinition(options);
136
+ return options;
137
+ }
138
+ const waitInputSchema = v4_namespaceObject.z.strictObject({
139
+ duration: v4_namespaceObject.z.number().positive().describe('How long to wait.'),
140
+ unit: v4_namespaceObject.z["enum"]([
141
+ 'ms',
142
+ 's',
143
+ 'min'
144
+ ]).default('ms').describe('Duration unit: milliseconds, seconds, or minutes.')
145
+ });
146
+ const waitFor = async (durationMs, signal)=>{
147
+ if (signal.aborted) throw signal.reason ?? new Error('Wait aborted.');
148
+ await new Promise((resolve, reject)=>{
149
+ const timeout = setTimeout(()=>{
150
+ signal.removeEventListener('abort', abort);
151
+ resolve();
152
+ }, durationMs);
153
+ const abort = ()=>{
154
+ clearTimeout(timeout);
155
+ reject(signal.reason ?? new Error('Wait aborted.'));
156
+ };
157
+ signal.addEventListener('abort', abort, {
158
+ once: true
179
159
  });
180
- };
181
- const createAgentTestRunnerNodes = (definitions, getAgent)=>{
182
- const activeAgentCalls = new WeakMap();
183
- const runAgentCall = async (node, ctx, agent, call, captureExecutions = true)=>{
184
- const scopeId = 'case' === ctx.scope ? ctx.case.runId : ctx.document.documentRunId;
185
- const activeCall = activeAgentCalls.get(agent);
186
- if (activeCall) throw new errors.h2(node, new Error(`The same Agent instance cannot execute overlapping Midscene Test Steps. Active scope: ${activeCall.scopeId} (${activeCall.node}); requested scope: ${scopeId} (${node}).`));
187
- activeAgentCalls.set(agent, {
188
- scopeId,
189
- node
190
- });
191
- let removeListener;
192
- let sawExecutionWithoutId = false;
193
- const stopListening = ()=>{
194
- const remove = removeListener;
195
- removeListener = void 0;
196
- remove?.();
197
- };
198
- const stopListeningOnAbort = ()=>stopListening();
160
+ });
161
+ };
162
+ const createAgentTestRunnerNodes = (definitions, getAgent)=>{
163
+ const activeAgentCalls = new WeakMap();
164
+ const runAgentCall = async (node, execution, agent, call, captureExecutions = true)=>{
165
+ execution.signal.throwIfAborted();
166
+ const scopeId = 'case' === execution.scope ? execution.case.runId : execution.document.documentRunId;
167
+ const activeCall = activeAgentCalls.get(agent);
168
+ if (activeCall) throw new NodeExecutionError(node, new Error(`The same Agent instance cannot execute overlapping Midscene Test Steps. Active scope: ${activeCall.scopeId} (${activeCall.node}); requested scope: ${scopeId} (${node}).`));
169
+ const currentCall = {
170
+ scopeId,
171
+ node
172
+ };
173
+ activeAgentCalls.set(agent, currentCall);
174
+ const releaseCall = ()=>{
175
+ if (activeAgentCalls.get(agent) === currentCall) activeAgentCalls.delete(agent);
176
+ };
177
+ let removeListener;
178
+ let sawExecutionWithoutId = false;
179
+ const stopListening = ()=>{
180
+ const remove = removeListener;
181
+ removeListener = void 0;
182
+ remove?.();
183
+ };
184
+ const stopListeningOnAbort = ()=>{
199
185
  try {
200
- if (captureExecutions && agent.addDumpUpdateListener) {
201
- removeListener = agent.addDumpUpdateListener((_dump, execution)=>{
202
- if (!execution) return;
203
- if (!execution.id) {
204
- sawExecutionWithoutId = true;
205
- return;
206
- }
207
- ctx.report.addTrace({
208
- type: 'midscene-execution',
209
- executionId: execution.id
210
- });
211
- });
212
- if (ctx.signal.aborted) stopListening();
213
- else ctx.signal.addEventListener('abort', stopListeningOnAbort, {
214
- once: true
215
- });
216
- }
217
- return await call();
186
+ stopListening();
218
187
  } finally{
219
- ctx.signal.removeEventListener('abort', stopListeningOnAbort);
220
- try {
221
- stopListening();
222
- } finally{
223
- activeAgentCalls.delete(agent);
224
- }
225
- if (sawExecutionWithoutId) warnReportTrace(`Skipped a report trace without a stable execution id for ${node} in scope ${scopeId}.`);
188
+ releaseCall();
226
189
  }
227
190
  };
228
- return definitions.map((definition)=>defineNode({
229
- name: definition.name,
230
- ...void 0 === definition.title ? {} : {
231
- title: definition.title
232
- },
233
- ...void 0 === definition.description ? {} : {
234
- description: definition.description
235
- },
236
- ...void 0 === definition.stringInputKey ? {} : {
237
- stringInputKey: definition.stringInputKey
238
- },
239
- inputSchema: definition.inputSchema,
240
- async execute (ctx) {
241
- const agent = await getAgent(ctx);
242
- const call = async ()=>definition.execute(agent, ctx.input, {
243
- signal: ctx.signal
244
- });
245
- if ('object' != typeof agent || null === agent) return call();
246
- return runAgentCall(definition.name, ctx, agent, call);
247
- }
248
- }));
249
- };
250
- const warnReportTrace = (0, logger_namespaceObject.getDebug)('test-runner:report-trace', {
251
- console: true
252
- });
253
- function createMidsceneNodes(options) {
254
- if (!options || 'object' != typeof options) throw new errors.ww('createMidsceneNodes() options must be an object.');
255
- if ('function' != typeof options.agentProvider?.getAgent && 'function' != typeof options.getAgent) throw new errors.ww('createMidsceneNodes() requires getAgent or agentProvider.getAgent.');
256
- if (!options.agentClass || 'function' != typeof options.agentClass.getTestRunnerNodeDefinitions) throw new errors.ww('createMidsceneNodes() requires agentClass.getTestRunnerNodeDefinitions().');
257
- const registeredAgentScopes = new Set();
258
- const getExecutionId = (ctx)=>'case' === ctx.scope ? ctx.case.runId : ctx.document.documentRunId;
259
- const getAgent = async (ctx)=>{
260
- if (!options.agentProvider) return options.getAgent(ctx);
261
- const runId = getExecutionId(ctx);
262
- if (options.agentProvider.releaseAgent && !registeredAgentScopes.has(runId)) {
263
- registeredAgentScopes.add(runId);
264
- ctx.onTeardown(async ()=>{
265
- try {
266
- const released = await options.agentProvider.releaseAgent(runId);
267
- return released?.reportPath ? {
268
- reportPaths: [
269
- released.reportPath
270
- ]
271
- } : void 0;
272
- } finally{
273
- registeredAgentScopes.delete(runId);
191
+ execution.signal.addEventListener('abort', stopListeningOnAbort, {
192
+ once: true
193
+ });
194
+ try {
195
+ if (captureExecutions && agent.addDumpUpdateListener) {
196
+ removeListener = agent.addDumpUpdateListener((_dump, executionRef)=>{
197
+ if (!executionRef) return;
198
+ if (!executionRef.id) {
199
+ sawExecutionWithoutId = true;
200
+ return;
274
201
  }
202
+ execution.report.addTrace({
203
+ type: 'midscene-execution',
204
+ executionId: executionRef.id
205
+ });
275
206
  });
207
+ if (execution.signal.aborted) stopListening();
276
208
  }
277
- return options.agentProvider.getAgent(runId, ctx);
278
- };
279
- const agentDefinitions = options.agentClass.getTestRunnerNodeDefinitions();
280
- return [
281
- ...createAgentTestRunnerNodes(agentDefinitions, getAgent),
282
- defineNode({
283
- name: 'wait',
284
- description: 'Wait for a fixed duration while honoring cancellation.',
285
- stringInputKey: false,
286
- inputSchema: waitInputSchema,
287
- async execute (ctx) {
288
- const multiplier = 'min' === ctx.input.unit ? 60000 : 's' === ctx.input.unit ? 1000 : 1;
289
- const durationMs = ctx.input.duration * multiplier;
290
- await waitFor(durationMs, ctx.signal);
291
- return {
292
- summary: `Waited ${durationMs}ms`
293
- };
209
+ return await call();
210
+ } finally{
211
+ execution.signal.removeEventListener('abort', stopListeningOnAbort);
212
+ try {
213
+ stopListening();
214
+ } finally{
215
+ releaseCall();
216
+ }
217
+ if (sawExecutionWithoutId) warnReportTrace(`Skipped a report trace without a stable execution id for ${node} in scope ${scopeId}.`);
218
+ }
219
+ };
220
+ return definitions.map((definition)=>defineNode({
221
+ name: definition.name,
222
+ ...void 0 === definition.title ? {} : {
223
+ title: definition.title
224
+ },
225
+ ...void 0 === definition.description ? {} : {
226
+ description: definition.description
227
+ },
228
+ ...void 0 === definition.stringInputKey ? {} : {
229
+ stringInputKey: definition.stringInputKey
230
+ },
231
+ inputSchema: definition.inputSchema,
232
+ async execute (execution) {
233
+ const agent = await getAgent(execution);
234
+ const call = async ()=>definition.execute(agent, execution.input, {
235
+ signal: execution.signal
236
+ });
237
+ if ('object' != typeof agent || null === agent) return call();
238
+ return runAgentCall(definition.name, execution, agent, call);
239
+ }
240
+ }));
241
+ };
242
+ const warnReportTrace = (0, logger_namespaceObject.getDebug)('test-runner:report-trace', {
243
+ console: true
244
+ });
245
+ function createMidsceneNodes(options) {
246
+ if (!options || 'object' != typeof options) throw new NodeDefinitionError('createMidsceneNodes() options must be an object.');
247
+ if ('function' != typeof options.agentProvider?.getAgent && 'function' != typeof options.getAgent) throw new NodeDefinitionError('createMidsceneNodes() requires getAgent or agentProvider.getAgent.');
248
+ if (!options.agentClass || 'function' != typeof options.agentClass.getTestRunnerNodeDefinitions) throw new NodeDefinitionError('createMidsceneNodes() requires agentClass.getTestRunnerNodeDefinitions().');
249
+ const registeredAgentScopes = new Set();
250
+ const getExecutionId = (execution)=>'case' === execution.scope ? execution.case.runId : execution.document.documentRunId;
251
+ const getAgent = async (execution)=>{
252
+ if (!options.agentProvider) return options.getAgent(execution);
253
+ const runId = getExecutionId(execution);
254
+ if (options.agentProvider.releaseAgent && !registeredAgentScopes.has(runId)) {
255
+ registeredAgentScopes.add(runId);
256
+ execution.onTeardown(async ()=>{
257
+ try {
258
+ const released = await options.agentProvider.releaseAgent(runId);
259
+ return released?.reportPath ? {
260
+ reportPaths: [
261
+ released.reportPath
262
+ ]
263
+ } : void 0;
264
+ } finally{
265
+ registeredAgentScopes.delete(runId);
294
266
  }
295
- })
296
- ];
297
- }
298
- })();
267
+ });
268
+ }
269
+ return options.agentProvider.getAgent(runId, execution);
270
+ };
271
+ const agentDefinitions = options.agentClass.getTestRunnerNodeDefinitions();
272
+ return [
273
+ ...createAgentTestRunnerNodes(agentDefinitions, getAgent),
274
+ defineNode({
275
+ name: 'wait',
276
+ description: 'Wait for a fixed duration while honoring cancellation.',
277
+ stringInputKey: false,
278
+ inputSchema: waitInputSchema,
279
+ async execute (execution) {
280
+ const multiplier = 'min' === execution.input.unit ? 60000 : 's' === execution.input.unit ? 1000 : 1;
281
+ const durationMs = execution.input.duration * multiplier;
282
+ await waitFor(durationMs, execution.signal);
283
+ return {
284
+ summary: `Waited ${durationMs}ms`
285
+ };
286
+ }
287
+ })
288
+ ];
289
+ }
299
290
  exports.aiActInputSchema = __webpack_exports__.aiActInputSchema;
300
291
  exports.aiActOptionsInputSchema = __webpack_exports__.aiActOptionsInputSchema;
301
292
  exports.aiAssertInputSchema = __webpack_exports__.aiAssertInputSchema;