@midscene/test 1.12.4-beta-20260903111111.0 → 1.12.4
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.
- package/dist/es/android/index.mjs +50 -106
- package/dist/es/android/index.mjs.map +1 -1
- package/dist/es/cli/index.mjs +99 -149
- package/dist/es/cli/index.mjs.map +1 -1
- package/dist/es/harmony/index.mjs +119 -0
- package/dist/es/harmony/index.mjs.map +1 -0
- package/dist/es/index.mjs +36 -87
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/ios/index.mjs +51 -101
- package/dist/es/ios/index.mjs.map +1 -1
- package/dist/es/midscene/index.mjs +37 -235
- package/dist/es/midscene/index.mjs.map +1 -1
- package/dist/es/playwright/index.mjs +14 -10
- package/dist/es/playwright/index.mjs.map +1 -1
- package/dist/es/test-cli.mjs +102 -150
- package/dist/es/test-cli.mjs.map +1 -1
- package/dist/lib/android/index.js +151 -178
- package/dist/lib/android/index.js.map +1 -1
- package/dist/lib/cli/index.js +99 -149
- package/dist/lib/cli/index.js.map +1 -1
- package/dist/lib/harmony/index.js +188 -0
- package/dist/lib/harmony/index.js.map +1 -0
- package/dist/lib/index.js +37 -100
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/ios/index.js +152 -173
- package/dist/lib/ios/index.js.map +1 -1
- package/dist/lib/midscene/index.js +264 -412
- package/dist/lib/midscene/index.js.map +1 -1
- package/dist/lib/playwright/index.js +14 -10
- package/dist/lib/playwright/index.js.map +1 -1
- package/dist/lib/test-cli.js +102 -150
- package/dist/lib/test-cli.js.map +1 -1
- package/dist/types/android/index.d.ts +27 -101
- package/dist/types/cli/index.d.ts +9 -32
- package/dist/types/harmony/index.d.ts +124 -0
- package/dist/types/index.d.ts +18 -45
- package/dist/types/ios/index.d.ts +28 -107
- package/dist/types/midscene/index.d.ts +54 -153
- package/dist/types/playwright/index.d.ts +9 -63
- package/package.json +25 -6
|
@@ -1,5 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./src/errors.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
4
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
5
|
+
ww: ()=>NodeDefinitionError
|
|
6
|
+
});
|
|
7
|
+
function _define_property(obj, key, value) {
|
|
8
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
9
|
+
value: value,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true
|
|
13
|
+
});
|
|
14
|
+
else obj[key] = value;
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
class WorkflowError extends Error {
|
|
18
|
+
toJSON() {
|
|
19
|
+
return {
|
|
20
|
+
name: this.name,
|
|
21
|
+
message: this.message,
|
|
22
|
+
code: this.code,
|
|
23
|
+
...void 0 === this.details ? {} : {
|
|
24
|
+
details: this.details
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
constructor(message, options = {}){
|
|
29
|
+
super(message, {
|
|
30
|
+
cause: options.cause
|
|
31
|
+
}), _define_property(this, "code", void 0), _define_property(this, "details", void 0);
|
|
32
|
+
this.name = new.target.name;
|
|
33
|
+
this.code = options.code ?? 'WORKFLOW_ERROR';
|
|
34
|
+
this.details = options.details;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class NodeDefinitionError extends WorkflowError {
|
|
38
|
+
constructor(message, details){
|
|
39
|
+
super(message, {
|
|
40
|
+
code: 'NODE_DEFINITION_ERROR',
|
|
41
|
+
details
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"./src/midscene/index.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
47
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
48
|
+
createAgentTestRunnerNodes: ()=>createAgentTestRunnerNodes
|
|
49
|
+
});
|
|
50
|
+
require("@midscene/core/agent/test-runner");
|
|
51
|
+
const v4_namespaceObject = require("zod/v4");
|
|
52
|
+
var errors = __webpack_require__("./src/errors.ts");
|
|
53
|
+
const validateOptionalText = (value, field, node)=>{
|
|
54
|
+
if (void 0 !== value && ('string' != typeof value || 0 === value.trim().length)) throw new errors.ww(`Node "${node}" ${field} must be a non-empty string.`, {
|
|
55
|
+
node,
|
|
56
|
+
field
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
const validateInputSchema = (schema, node)=>{
|
|
60
|
+
if (void 0 === schema) return;
|
|
61
|
+
if (!(schema instanceof v4_namespaceObject.z.ZodObject)) throw new errors.ww(`Node "${node}" inputSchema must be a Zod object schema.`, {
|
|
62
|
+
node,
|
|
63
|
+
field: 'inputSchema'
|
|
64
|
+
});
|
|
65
|
+
if ('$' in schema.shape) throw new errors.ww(`Node "${node}" inputSchema must not declare "$" as an input property.`, {
|
|
66
|
+
node,
|
|
67
|
+
field: 'inputSchema.$'
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const validateDefinition = (options)=>{
|
|
71
|
+
if (!options || 'object' != typeof options) throw new errors.ww('Node definition must be an object.');
|
|
72
|
+
if ('string' != typeof options.name || 0 === options.name.trim().length) throw new errors.ww('Node name must be a non-empty string.');
|
|
73
|
+
validateOptionalText(options.title, 'title', options.name);
|
|
74
|
+
validateOptionalText(options.description, "description", options.name);
|
|
75
|
+
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.`, {
|
|
76
|
+
node: options.name,
|
|
77
|
+
field: 'stringInputKey'
|
|
78
|
+
});
|
|
79
|
+
validateInputSchema(options.inputSchema, options.name);
|
|
80
|
+
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.`, {
|
|
81
|
+
node: options.name,
|
|
82
|
+
field: 'stringInputKey'
|
|
83
|
+
});
|
|
84
|
+
if ('function' != typeof options.execute) throw new errors.ww(`Node "${options.name}" must provide an execute function.`, {
|
|
85
|
+
node: options.name
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
function define_node_defineNode(options) {
|
|
89
|
+
validateDefinition(options);
|
|
90
|
+
return options;
|
|
91
|
+
}
|
|
92
|
+
const nonBlankPrompt = (description)=>v4_namespaceObject.z.string().regex(/\S/, 'prompt must contain a non-whitespace character').describe(description);
|
|
93
|
+
v4_namespaceObject.z.strictObject({
|
|
94
|
+
duration: v4_namespaceObject.z.number().positive().describe('How long to wait.'),
|
|
95
|
+
unit: v4_namespaceObject.z["enum"]([
|
|
96
|
+
'ms',
|
|
97
|
+
's',
|
|
98
|
+
'min'
|
|
99
|
+
]).default('ms').describe('Duration unit: milliseconds, seconds, or minutes.')
|
|
100
|
+
});
|
|
101
|
+
v4_namespaceObject.z.strictObject({
|
|
102
|
+
prompt: nonBlankPrompt('A self-contained task, including allowed tools and success conditions.')
|
|
103
|
+
});
|
|
104
|
+
const createAgentTestRunnerNodes = (definitions, getAgent)=>definitions.map((definition)=>define_node_defineNode({
|
|
105
|
+
name: definition.name,
|
|
106
|
+
...void 0 === definition.title ? {} : {
|
|
107
|
+
title: definition.title
|
|
108
|
+
},
|
|
109
|
+
...void 0 === definition.description ? {} : {
|
|
110
|
+
description: definition.description
|
|
111
|
+
},
|
|
112
|
+
...void 0 === definition.stringInputKey ? {} : {
|
|
113
|
+
stringInputKey: definition.stringInputKey
|
|
114
|
+
},
|
|
115
|
+
inputSchema: definition.inputSchema,
|
|
116
|
+
async execute (ctx) {
|
|
117
|
+
const agent = await getAgent(ctx);
|
|
118
|
+
return definition.execute(agent, ctx.input, {
|
|
119
|
+
signal: ctx.signal
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var __webpack_module_cache__ = {};
|
|
126
|
+
function __webpack_require__(moduleId) {
|
|
127
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
128
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
129
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
130
|
+
exports: {}
|
|
131
|
+
};
|
|
132
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
133
|
+
return module.exports;
|
|
134
|
+
}
|
|
3
135
|
(()=>{
|
|
4
136
|
__webpack_require__.d = (exports1, definition)=>{
|
|
5
137
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -22,193 +154,34 @@ var __webpack_require__ = {};
|
|
|
22
154
|
};
|
|
23
155
|
})();
|
|
24
156
|
var __webpack_exports__ = {};
|
|
25
|
-
|
|
26
|
-
__webpack_require__.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function _define_property(obj, key, value) {
|
|
34
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
35
|
-
value: value,
|
|
36
|
-
enumerable: true,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true
|
|
157
|
+
(()=>{
|
|
158
|
+
__webpack_require__.r(__webpack_exports__);
|
|
159
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
160
|
+
createAndroidNodes: ()=>createAndroidNodes,
|
|
161
|
+
terminateInputSchema: ()=>test_runner_namespaceObject.terminateInputSchema,
|
|
162
|
+
runAdbShellInputSchema: ()=>test_runner_namespaceObject.runAdbShellInputSchema,
|
|
163
|
+
runAdbShellOptionsInputSchema: ()=>test_runner_namespaceObject.runAdbShellOptionsInputSchema,
|
|
164
|
+
launchInputSchema: ()=>test_runner_namespaceObject.launchInputSchema
|
|
39
165
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
message: this.message,
|
|
48
|
-
code: this.code,
|
|
49
|
-
...void 0 === this.details ? {} : {
|
|
50
|
-
details: this.details
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
constructor(message, options = {}){
|
|
55
|
-
super(message, {
|
|
56
|
-
cause: options.cause
|
|
57
|
-
}), _define_property(this, "code", void 0), _define_property(this, "details", void 0);
|
|
58
|
-
this.name = new.target.name;
|
|
59
|
-
this.code = options.code ?? 'WORKFLOW_ERROR';
|
|
60
|
-
this.details = options.details;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
class NodeDefinitionError extends WorkflowError {
|
|
64
|
-
constructor(message, details){
|
|
65
|
-
super(message, {
|
|
66
|
-
code: 'NODE_DEFINITION_ERROR',
|
|
67
|
-
details
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
class NodeExecutionError extends WorkflowError {
|
|
72
|
-
constructor(node, cause){
|
|
73
|
-
const causeMessage = cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');
|
|
74
|
-
super(`Node "${node}" failed: ${causeMessage}`, {
|
|
75
|
-
code: 'NODE_EXECUTION_ERROR',
|
|
76
|
-
details: {
|
|
77
|
-
node
|
|
78
|
-
},
|
|
79
|
-
cause
|
|
80
|
-
}), _define_property(this, "node", void 0);
|
|
81
|
-
this.node = node;
|
|
166
|
+
const test_runner_namespaceObject = require("@midscene/android/test-runner");
|
|
167
|
+
var errors = __webpack_require__("./src/errors.ts");
|
|
168
|
+
var midscene = __webpack_require__("./src/midscene/index.ts");
|
|
169
|
+
function createAndroidNodes(options) {
|
|
170
|
+
if (!options || 'object' != typeof options) throw new errors.ww('createAndroidNodes() options must be an object.');
|
|
171
|
+
if ('function' != typeof options.getAgent) throw new errors.ww('createAndroidNodes() requires getAgent().');
|
|
172
|
+
return (0, midscene.createAgentTestRunnerNodes)(test_runner_namespaceObject.androidAgentTestRunnerNodeDefinitions, options.getAgent);
|
|
82
173
|
}
|
|
83
|
-
}
|
|
84
|
-
const validateOptionalText = (value, field, node)=>{
|
|
85
|
-
if (void 0 !== value && ('string' != typeof value || 0 === value.trim().length)) throw new NodeDefinitionError(`Node "${node}" ${field} must be a non-empty string.`, {
|
|
86
|
-
node,
|
|
87
|
-
field
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
const validateInputSchema = (schema, node)=>{
|
|
91
|
-
if (void 0 === schema) return;
|
|
92
|
-
if (!(schema instanceof v4_namespaceObject.z.ZodObject)) throw new NodeDefinitionError(`Node "${node}" inputSchema must be a Zod object schema.`, {
|
|
93
|
-
node,
|
|
94
|
-
field: 'inputSchema'
|
|
95
|
-
});
|
|
96
|
-
if ('$' in schema.shape) throw new NodeDefinitionError(`Node "${node}" inputSchema must not declare "$" as an input property.`, {
|
|
97
|
-
node,
|
|
98
|
-
field: 'inputSchema.$'
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
const validateDefinition = (options)=>{
|
|
102
|
-
if (!options || 'object' != typeof options) throw new NodeDefinitionError('Node definition must be an object.');
|
|
103
|
-
if ('string' != typeof options.name || 0 === options.name.trim().length) throw new NodeDefinitionError('Node name must be a non-empty string.');
|
|
104
|
-
validateOptionalText(options.title, 'title', options.name);
|
|
105
|
-
validateOptionalText(options.description, "description", options.name);
|
|
106
|
-
validateInputSchema(options.inputSchema, options.name);
|
|
107
|
-
if ('function' != typeof options.execute) throw new NodeDefinitionError(`Node "${options.name}" must provide an execute function.`, {
|
|
108
|
-
node: options.name
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
function defineNode(options) {
|
|
112
|
-
validateDefinition(options);
|
|
113
|
-
return options;
|
|
114
|
-
}
|
|
115
|
-
const lifecycleInputSchema = (operation, description)=>v4_namespaceObject.z.strictObject({
|
|
116
|
-
prompt: v4_namespaceObject.z.string().regex(/\S/, 'prompt must contain a non-whitespace character').optional().describe(`String shorthand for the app to ${operation}.`),
|
|
117
|
-
uri: v4_namespaceObject.z.string().regex(/\S/, 'uri must contain a non-whitespace character').optional().describe(description)
|
|
118
|
-
}).superRefine((input, ctx)=>{
|
|
119
|
-
if (void 0 === input.prompt === (void 0 === input.uri)) ctx.addIssue({
|
|
120
|
-
code: 'custom',
|
|
121
|
-
message: 'exactly one of prompt and uri is required'
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
const launchInputSchema = lifecycleInputSchema('launch', 'The app, URL, URI, package name, or bundle identifier to launch.');
|
|
125
|
-
const terminateInputSchema = lifecycleInputSchema('terminate', 'The package name, bundle identifier, or app name to terminate.');
|
|
126
|
-
const requireLifecycleMethod = (agent, method, agentName)=>{
|
|
127
|
-
if ('object' != typeof agent || null === agent || 'function' != typeof agent[method]) throw new NodeExecutionError(method, new TypeError(`getAgent() must return ${agentName} with ${method}().`));
|
|
128
|
-
return agent[method];
|
|
129
|
-
};
|
|
130
|
-
const createLaunchNode = (getAgent, agentName = 'an Agent')=>defineNode({
|
|
131
|
-
name: 'launch',
|
|
132
|
-
description: 'Launch an app, URL, or URI through the current Midscene Agent. This Node does not install or manage applications.',
|
|
133
|
-
inputSchema: launchInputSchema,
|
|
134
|
-
async execute (ctx) {
|
|
135
|
-
const uri = ctx.input.uri ?? ctx.input.prompt;
|
|
136
|
-
const agent = await getAgent(ctx);
|
|
137
|
-
const launch = requireLifecycleMethod(agent, 'launch', agentName);
|
|
138
|
-
await launch.call(agent, uri);
|
|
139
|
-
return {
|
|
140
|
-
summary: `Launched ${uri}`
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
const createTerminateNode = (getAgent, agentName)=>defineNode({
|
|
145
|
-
name: 'terminate',
|
|
146
|
-
description: 'Terminate an application through the current Midscene Agent. This Node does not uninstall the application or clear its data.',
|
|
147
|
-
inputSchema: terminateInputSchema,
|
|
148
|
-
async execute (ctx) {
|
|
149
|
-
const uri = ctx.input.uri ?? ctx.input.prompt;
|
|
150
|
-
const agent = await getAgent(ctx);
|
|
151
|
-
const terminate = requireLifecycleMethod(agent, 'terminate', agentName);
|
|
152
|
-
await terminate.call(agent, uri);
|
|
153
|
-
return {
|
|
154
|
-
summary: `Terminated ${uri}`
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
const createDeviceLifecycleNodes = (getAgent, agentName)=>[
|
|
159
|
-
createLaunchNode(getAgent, agentName),
|
|
160
|
-
createTerminateNode(getAgent, agentName)
|
|
161
|
-
];
|
|
162
|
-
const runAdbShellInputSchema = v4_namespaceObject.z.strictObject({
|
|
163
|
-
prompt: v4_namespaceObject.z.string().regex(/\S/).optional().describe('String shorthand for the ADB shell command.'),
|
|
164
|
-
command: v4_namespaceObject.z.string().regex(/\S/).optional().describe('The shell command, without an adb shell prefix.'),
|
|
165
|
-
timeoutMs: v4_namespaceObject.z.number().int().positive().optional().describe('ADB shell command timeout in milliseconds.')
|
|
166
|
-
}).superRefine((input, ctx)=>{
|
|
167
|
-
if (void 0 === input.prompt === (void 0 === input.command)) ctx.addIssue({
|
|
168
|
-
code: 'custom',
|
|
169
|
-
message: 'exactly one of prompt and command is required'
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
function createAndroidNodes(options) {
|
|
173
|
-
if (!options || 'object' != typeof options) throw new NodeDefinitionError('createAndroidNodes() options must be an object.');
|
|
174
|
-
if ('function' != typeof options.getAgent) throw new NodeDefinitionError('createAndroidNodes() requires getAgent().');
|
|
175
|
-
return [
|
|
176
|
-
...createDeviceLifecycleNodes(options.getAgent, 'an Android Agent'),
|
|
177
|
-
defineNode({
|
|
178
|
-
name: 'runAdbShell',
|
|
179
|
-
title: 'Run an ADB shell command',
|
|
180
|
-
description: 'Execute a shell command through the current Android Agent. Pass only the shell command, without the adb shell prefix.',
|
|
181
|
-
inputSchema: runAdbShellInputSchema,
|
|
182
|
-
async execute (ctx) {
|
|
183
|
-
if (ctx.signal.aborted) throw ctx.signal.reason ?? new Error('runAdbShell aborted.');
|
|
184
|
-
const command = ctx.input.command ?? ctx.input.prompt;
|
|
185
|
-
if (/^\s*adb(?:\s|$)/i.test(command)) throw new NodeExecutionError('runAdbShell', new TypeError('command must not include an adb or adb shell prefix.'));
|
|
186
|
-
const agent = await options.getAgent(ctx);
|
|
187
|
-
if ('function' != typeof agent?.runAdbShell) throw new NodeExecutionError('runAdbShell', new TypeError('getAgent() must return an Android Agent with runAdbShell().'));
|
|
188
|
-
const stdout = await agent.runAdbShell(command, {
|
|
189
|
-
...void 0 === ctx.input.timeoutMs ? {} : {
|
|
190
|
-
timeout: ctx.input.timeoutMs
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
if ('string' != typeof stdout) throw new NodeExecutionError('runAdbShell', new TypeError('runAdbShell() must return stdout as a string.'));
|
|
194
|
-
return {
|
|
195
|
-
summary: `Executed ADB shell command (${stdout.length} stdout characters)`,
|
|
196
|
-
data: {
|
|
197
|
-
stdout
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
})
|
|
202
|
-
];
|
|
203
|
-
}
|
|
174
|
+
})();
|
|
204
175
|
exports.createAndroidNodes = __webpack_exports__.createAndroidNodes;
|
|
205
176
|
exports.launchInputSchema = __webpack_exports__.launchInputSchema;
|
|
206
177
|
exports.runAdbShellInputSchema = __webpack_exports__.runAdbShellInputSchema;
|
|
178
|
+
exports.runAdbShellOptionsInputSchema = __webpack_exports__.runAdbShellOptionsInputSchema;
|
|
207
179
|
exports.terminateInputSchema = __webpack_exports__.terminateInputSchema;
|
|
208
180
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
209
181
|
"createAndroidNodes",
|
|
210
182
|
"launchInputSchema",
|
|
211
183
|
"runAdbShellInputSchema",
|
|
184
|
+
"runAdbShellOptionsInputSchema",
|
|
212
185
|
"terminateInputSchema"
|
|
213
186
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
214
187
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android/index.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/errors.ts","../../../src/node/define-node.ts","../../../src/device/lifecycle.ts","../../../src/android/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { z } from 'zod/v4';\n\nexport interface WorkflowErrorOptions {\n code?: string;\n details?: unknown;\n cause?: unknown;\n}\n\nexport class WorkflowError extends Error {\n readonly code: string;\n readonly details?: unknown;\n\n constructor(message: string, options: WorkflowErrorOptions = {}) {\n super(message, { cause: options.cause });\n this.name = new.target.name;\n this.code = options.code ?? 'WORKFLOW_ERROR';\n this.details = options.details;\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n code: this.code,\n ...(this.details === undefined ? {} : { details: this.details }),\n };\n }\n}\n\nexport class WorkflowParseError extends WorkflowError {\n constructor(message: string, details?: unknown, cause?: unknown) {\n super(message, { code: 'WORKFLOW_PARSE_ERROR', details, cause });\n }\n}\n\nexport class NodeDefinitionError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_DEFINITION_ERROR', details });\n }\n}\n\nexport class DuplicateNodeError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is already registered.`, {\n code: 'DUPLICATE_NODE',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeNotFoundError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is not registered.`, {\n code: 'NODE_NOT_FOUND',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeInputValidationError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_INPUT_VALIDATION_ERROR', details });\n }\n\n static fromZod(node: string, error: z.ZodError): NodeInputValidationError {\n const issues = error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n const firstIssue = issues[0];\n const path = firstIssue?.path || '<root>';\n const message = firstIssue?.message ?? 'invalid input';\n return new NodeInputValidationError(\n `Node \"${node}\" input validation failed at \"${path}\": ${message}`,\n { node, issues },\n );\n }\n}\n\nexport class StepTimeoutError extends WorkflowError {\n readonly timeoutMs: number;\n readonly node?: string;\n\n constructor(timeoutMs: number, node?: string) {\n super(\n node\n ? `Node \"${node}\" timed out after ${timeoutMs}ms.`\n : `Step timed out after ${timeoutMs}ms.`,\n {\n code: 'STEP_TIMEOUT',\n details: { timeoutMs, ...(node === undefined ? {} : { node }) },\n },\n );\n this.timeoutMs = timeoutMs;\n this.node = node;\n }\n}\n\nexport class NodeExecutionError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string, cause: unknown) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Node \"${node}\" failed: ${causeMessage}`, {\n code: 'NODE_EXECUTION_ERROR',\n details: { node },\n cause,\n });\n this.node = node;\n }\n}\n\nexport class WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class ProjectSetupError extends WorkflowError {\n constructor(cause: unknown, details: { projectName: string }) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" setup failed: ${causeMessage}`, {\n code: 'PROJECT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class ProjectTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { projectName: string; registrationIndex: number },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" teardown failed: ${causeMessage}`, {\n code: 'PROJECT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class NodeScopeTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n scope: 'case' | 'document';\n scopeId: string;\n node: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(\n `${details.scope === 'case' ? 'Case attempt' : 'Workflow document'} node teardown failed for \"${details.node}\": ${causeMessage}`,\n { code: 'NODE_SCOPE_TEARDOWN_ERROR', details, cause },\n );\n }\n}\n\nexport class FatalDeviceError extends WorkflowError {\n constructor(message: string, cause?: unknown) {\n super(message, { code: 'FATAL_DEVICE_ERROR', cause });\n }\n}\n\nexport const isFatalDeviceError = (error: unknown): boolean => {\n if (error instanceof FatalDeviceError) return true;\n if (error instanceof WorkflowError && error.code === 'FATAL_DEVICE_ERROR') {\n return true;\n }\n if (\n error instanceof Error &&\n /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(\n error.message,\n )\n ) {\n return true;\n }\n return error instanceof Error && error.cause !== undefined\n ? isFatalDeviceError(error.cause)\n : false;\n};\n\nexport class CaseExecutionError extends WorkflowError {\n readonly result: import('./engine/types').CaseRunResult;\n\n constructor(result: import('./engine/types').CaseRunResult) {\n super(`Case \"${result.name}\" failed.`, {\n code: 'CASE_EXECUTION_FAILED',\n details: { caseId: result.caseId, runId: result.runId },\n });\n this.result = result;\n }\n}\n\nexport class WorkflowDocumentExecutionError extends WorkflowError {\n readonly result: import('./engine/types').WorkflowDocumentRunResult;\n\n constructor(result: import('./engine/types').WorkflowDocumentRunResult) {\n super(`Workflow document \"${result.sourcePath}\" failed.`, {\n code: 'WORKFLOW_DOCUMENT_EXECUTION_FAILED',\n details: {\n documentId: result.documentId,\n documentRunId: result.documentRunId,\n },\n });\n this.result = result;\n }\n}\n\nexport function normalizeNodeExecutionError(\n error: unknown,\n node: string,\n): WorkflowError {\n return error instanceof WorkflowError\n ? error\n : new NodeExecutionError(node, error);\n}\n","import { z } from 'zod/v4';\nimport { NodeDefinitionError } from '../errors';\nimport type {\n DefineNodeOptions,\n DefineNodeWithSchemaOptions,\n NodeDefinition,\n NodeDefinitionWithSchema,\n NodeInputSchema,\n} from './types';\n\nconst validateOptionalText = (\n value: unknown,\n field: 'title' | 'description',\n node: string,\n): void => {\n if (\n value !== undefined &&\n (typeof value !== 'string' || value.trim().length === 0)\n ) {\n throw new NodeDefinitionError(\n `Node \"${node}\" ${field} must be a non-empty string.`,\n { node, field },\n );\n }\n};\n\nconst validateInputSchema = (schema: unknown, node: string): void => {\n if (schema === undefined) return;\n if (!(schema instanceof z.ZodObject)) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must be a Zod object schema.`,\n { node, field: 'inputSchema' },\n );\n }\n if ('$' in schema.shape) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must not declare \"$\" as an input property.`,\n { node, field: 'inputSchema.$' },\n );\n }\n};\n\nconst validateDefinition = (options: {\n name: string;\n title?: unknown;\n description?: unknown;\n inputSchema?: unknown;\n execute: unknown;\n}): void => {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError('Node definition must be an object.');\n }\n\n if (typeof options.name !== 'string' || options.name.trim().length === 0) {\n throw new NodeDefinitionError('Node name must be a non-empty string.');\n }\n\n validateOptionalText(options.title, 'title', options.name);\n validateOptionalText(options.description, 'description', options.name);\n validateInputSchema(options.inputSchema, options.name);\n\n if (typeof options.execute !== 'function') {\n throw new NodeDefinitionError(\n `Node \"${options.name}\" must provide an execute function.`,\n { node: options.name },\n );\n }\n};\n\nexport function defineNode<\n TSchema extends NodeInputSchema,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeWithSchemaOptions<TSchema, TData, TContext>,\n): NodeDefinitionWithSchema<TSchema, TData, TContext>;\n\nexport function defineNode<\n TInput = unknown,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeOptions<TInput, TData, TContext>,\n): NodeDefinition<TInput, TData, TContext>;\n\nexport function defineNode(\n options: DefineNodeOptions<any, any, any>,\n): NodeDefinition<any, any, any> {\n validateDefinition(options);\n return options;\n}\n","import { z } from 'zod/v4';\nimport type { Awaitable } from '../engine/types';\nimport { NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\ntype NodeContext<TContext> = NodeExecutionContext<unknown, TContext>;\ntype AgentGetter<TContext> = (ctx: NodeContext<TContext>) => Awaitable<unknown>;\ntype LifecycleMethod = 'launch' | 'terminate';\n\n/** Device capabilities required by Android and iOS lifecycle Nodes. */\nexport interface DeviceLifecycleAgent {\n launch(uri: string): Promise<void>;\n terminate(uri: string): Promise<void>;\n}\n\nconst lifecycleInputSchema = (\n operation: LifecycleMethod,\n description: string,\n) =>\n z\n .strictObject({\n prompt: z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .optional()\n .describe(`String shorthand for the app to ${operation}.`),\n uri: z\n .string()\n .regex(/\\S/, 'uri must contain a non-whitespace character')\n .optional()\n .describe(description),\n })\n .superRefine((input, ctx) => {\n if ((input.prompt === undefined) === (input.uri === undefined)) {\n ctx.addIssue({\n code: 'custom',\n message: 'exactly one of prompt and uri is required',\n });\n }\n });\n\n/** Input schema for the device launch Node. */\nexport const launchInputSchema = lifecycleInputSchema(\n 'launch',\n 'The app, URL, URI, package name, or bundle identifier to launch.',\n);\n\n/** Input schema for the device terminate Node. */\nexport const terminateInputSchema = lifecycleInputSchema(\n 'terminate',\n 'The package name, bundle identifier, or app name to terminate.',\n);\n\nexport type LaunchNodeInput = z.infer<typeof launchInputSchema>;\nexport type TerminateNodeInput = z.infer<typeof terminateInputSchema>;\n\nconst requireLifecycleMethod = (\n agent: unknown,\n method: LifecycleMethod,\n agentName: string,\n): DeviceLifecycleAgent[LifecycleMethod] => {\n if (\n typeof agent !== 'object' ||\n agent === null ||\n typeof (agent as Record<LifecycleMethod, unknown>)[method] !== 'function'\n ) {\n throw new NodeExecutionError(\n method,\n new TypeError(`getAgent() must return ${agentName} with ${method}().`),\n );\n }\n return (agent as DeviceLifecycleAgent)[method];\n};\n\nexport const createLaunchNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName = 'an Agent',\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof launchInputSchema, unknown, TContext>({\n name: 'launch',\n description:\n 'Launch an app, URL, or URI through the current Midscene Agent. This Node does not install or manage applications.',\n inputSchema: launchInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const launch = requireLifecycleMethod(agent, 'launch', agentName);\n await launch.call(agent, uri);\n return { summary: `Launched ${uri}` };\n },\n });\n\nconst createTerminateNode = <TContext>(\n getAgent: AgentGetter<TContext>,\n agentName: string,\n): NodeDefinition<any, any, TContext> =>\n defineNode<typeof terminateInputSchema, unknown, TContext>({\n name: 'terminate',\n description:\n 'Terminate an application through the current Midscene Agent. This Node does not uninstall the application or clear its data.',\n inputSchema: terminateInputSchema,\n async execute(ctx) {\n const uri = ctx.input.uri ?? ctx.input.prompt!;\n const agent = await getAgent(ctx);\n const terminate = requireLifecycleMethod(agent, 'terminate', agentName);\n await terminate.call(agent, uri);\n return { summary: `Terminated ${uri}` };\n },\n });\n\nexport const createDeviceLifecycleNodes = <TContext>(\n getAgent: (ctx: NodeContext<TContext>) => Awaitable<DeviceLifecycleAgent>,\n agentName: string,\n): readonly NodeDefinition<any, any, TContext>[] => [\n createLaunchNode(getAgent, agentName),\n createTerminateNode(getAgent, agentName),\n];\n","import { z } from 'zod/v4';\nimport {\n type DeviceLifecycleAgent,\n createDeviceLifecycleNodes,\n} from '../device/lifecycle';\nexport type {\n LaunchNodeInput,\n TerminateNodeInput,\n} from '../device/lifecycle';\nexport { launchInputSchema, terminateInputSchema } from '../device/lifecycle';\nimport type { Awaitable } from '../engine/types';\nimport { NodeDefinitionError, NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\ntype NodeContext<TContext> = NodeExecutionContext<unknown, TContext>;\n\n/** Minimal Android Agent capability required by the preset Node. */\nexport interface AndroidRunnerAgent extends DeviceLifecycleAgent {\n /** Execute a command in the connected Android device shell. */\n runAdbShell(command: string, options?: { timeout?: number }): Promise<string>;\n}\n\n/** Dependencies used by the Android preset Nodes. */\nexport interface CreateAndroidNodesOptions<TContext> {\n /** Return the Android Agent associated with the current workflow. */\n getAgent(ctx: NodeContext<TContext>): Awaitable<AndroidRunnerAgent>;\n}\n\n/** Input schema for the Android runAdbShell Node. */\nexport const runAdbShellInputSchema = z\n .strictObject({\n prompt: z\n .string()\n .regex(/\\S/)\n .optional()\n .describe('String shorthand for the ADB shell command.'),\n command: z\n .string()\n .regex(/\\S/)\n .optional()\n .describe('The shell command, without an adb shell prefix.'),\n timeoutMs: z\n .number()\n .int()\n .positive()\n .optional()\n .describe('ADB shell command timeout in milliseconds.'),\n })\n .superRefine((input, ctx) => {\n if ((input.prompt === undefined) === (input.command === undefined)) {\n ctx.addIssue({\n code: 'custom',\n message: 'exactly one of prompt and command is required',\n });\n }\n });\n\n/** Validated input accepted by the Android runAdbShell Node. */\nexport type RunAdbShellNodeInput = z.infer<typeof runAdbShellInputSchema>;\n\n/** Create the P0 Android preset Nodes for an injected Android Agent. */\nexport function createAndroidNodes<TContext>(\n options: CreateAndroidNodesOptions<TContext>,\n): readonly NodeDefinition<any, any, TContext>[] {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError(\n 'createAndroidNodes() options must be an object.',\n );\n }\n if (typeof options.getAgent !== 'function') {\n throw new NodeDefinitionError('createAndroidNodes() requires getAgent().');\n }\n\n return [\n ...createDeviceLifecycleNodes(options.getAgent, 'an Android Agent'),\n defineNode<typeof runAdbShellInputSchema, { stdout: string }, TContext>({\n name: 'runAdbShell',\n title: 'Run an ADB shell command',\n description:\n 'Execute a shell command through the current Android Agent. Pass only the shell command, without the adb shell prefix.',\n inputSchema: runAdbShellInputSchema,\n async execute(ctx) {\n if (ctx.signal.aborted) {\n throw ctx.signal.reason ?? new Error('runAdbShell aborted.');\n }\n const command = ctx.input.command ?? ctx.input.prompt!;\n if (/^\\s*adb(?:\\s|$)/i.test(command)) {\n throw new NodeExecutionError(\n 'runAdbShell',\n new TypeError(\n 'command must not include an adb or adb shell prefix.',\n ),\n );\n }\n const agent = await options.getAgent(ctx);\n if (typeof agent?.runAdbShell !== 'function') {\n throw new NodeExecutionError(\n 'runAdbShell',\n new TypeError(\n 'getAgent() must return an Android Agent with runAdbShell().',\n ),\n );\n }\n const stdout = await agent.runAdbShell(command, {\n ...(ctx.input.timeoutMs === undefined\n ? {}\n : { timeout: ctx.input.timeoutMs }),\n });\n if (typeof stdout !== 'string') {\n throw new NodeExecutionError(\n 'runAdbShell',\n new TypeError('runAdbShell() must return stdout as a string.'),\n );\n }\n return {\n summary: `Executed ADB shell command (${stdout.length} stdout characters)`,\n data: { stdout },\n };\n },\n }),\n ];\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","WorkflowError","Error","undefined","message","options","NodeDefinitionError","details","NodeExecutionError","node","cause","causeMessage","String","validateOptionalText","value","field","validateInputSchema","schema","z","validateDefinition","defineNode","lifecycleInputSchema","operation","description","input","ctx","launchInputSchema","terminateInputSchema","requireLifecycleMethod","agent","method","agentName","TypeError","createLaunchNode","getAgent","uri","launch","createTerminateNode","terminate","createDeviceLifecycleNodes","runAdbShellInputSchema","createAndroidNodes","command","stdout"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAAC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IAAI,QAAQ,CAAC;QACX,MAAM;QACN,SAAS;IACX;AAEJ;AAMK,SAASgB,mBACdpC,OAA4C;IAE5C,IAAI,CAACA,WAAW,AAAmB,YAAnB,OAAOA,SACrB,MAAM,IAAIC,oBACR;IAGJ,IAAI,AAA4B,cAA5B,OAAOD,QAAQ,QAAQ,EACzB,MAAM,IAAIC,oBAAoB;IAGhC,OAAO;WACFiC,2BAA2BlC,QAAQ,QAAQ,EAAE;QAChDe,WAAwE;YACtE,MAAM;YACN,OAAO;YACP,aACE;YACF,aAAaoB;YACb,MAAM,SAAQf,GAAG;gBACf,IAAIA,IAAI,MAAM,CAAC,OAAO,EACpB,MAAMA,IAAI,MAAM,CAAC,MAAM,IAAI,IAAIvB,MAAM;gBAEvC,MAAMwC,UAAUjB,IAAI,KAAK,CAAC,OAAO,IAAIA,IAAI,KAAK,CAAC,MAAM;gBACrD,IAAI,mBAAmB,IAAI,CAACiB,UAC1B,MAAM,IAAIlC,mBACR,eACA,IAAIwB,UACF;gBAIN,MAAMH,QAAQ,MAAMxB,QAAQ,QAAQ,CAACoB;gBACrC,IAAI,AAA8B,cAA9B,OAAOI,OAAO,aAChB,MAAM,IAAIrB,mBACR,eACA,IAAIwB,UACF;gBAIN,MAAMW,SAAS,MAAMd,MAAM,WAAW,CAACa,SAAS;oBAC9C,GAAIjB,AAAwBtB,WAAxBsB,IAAI,KAAK,CAAC,SAAS,GACnB,CAAC,IACD;wBAAE,SAASA,IAAI,KAAK,CAAC,SAAS;oBAAC,CAAC;gBACtC;gBACA,IAAI,AAAkB,YAAlB,OAAOkB,QACT,MAAM,IAAInC,mBACR,eACA,IAAIwB,UAAU;gBAGlB,OAAO;oBACL,SAAS,CAAC,4BAA4B,EAAEW,OAAO,MAAM,CAAC,mBAAmB,CAAC;oBAC1E,MAAM;wBAAEA;oBAAO;gBACjB;YACF;QACF;KACD;AACH"}
|
|
1
|
+
{"version":3,"file":"android/index.js","sources":["../../../src/errors.ts","../../../src/node/define-node.ts","../../../src/midscene/index.ts","webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../src/android/index.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\nexport interface WorkflowErrorOptions {\n code?: string;\n details?: unknown;\n cause?: unknown;\n}\n\nexport class WorkflowError extends Error {\n readonly code: string;\n readonly details?: unknown;\n\n constructor(message: string, options: WorkflowErrorOptions = {}) {\n super(message, { cause: options.cause });\n this.name = new.target.name;\n this.code = options.code ?? 'WORKFLOW_ERROR';\n this.details = options.details;\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n code: this.code,\n ...(this.details === undefined ? {} : { details: this.details }),\n };\n }\n}\n\nexport class WorkflowParseError extends WorkflowError {\n constructor(message: string, details?: unknown, cause?: unknown) {\n super(message, { code: 'WORKFLOW_PARSE_ERROR', details, cause });\n }\n}\n\nexport class NodeDefinitionError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_DEFINITION_ERROR', details });\n }\n}\n\nexport class DuplicateNodeError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is already registered.`, {\n code: 'DUPLICATE_NODE',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeNotFoundError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is not registered.`, {\n code: 'NODE_NOT_FOUND',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeInputValidationError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_INPUT_VALIDATION_ERROR', details });\n }\n\n static fromZod(node: string, error: z.ZodError): NodeInputValidationError {\n const issues = error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n const firstIssue = issues[0];\n const path = firstIssue?.path || '<root>';\n const message = firstIssue?.message ?? 'invalid input';\n return new NodeInputValidationError(\n `Node \"${node}\" input validation failed at \"${path}\": ${message}`,\n { node, issues },\n );\n }\n}\n\nexport class StepTimeoutError extends WorkflowError {\n readonly timeoutMs: number;\n readonly node?: string;\n\n constructor(timeoutMs: number, node?: string) {\n super(\n node\n ? `Node \"${node}\" timed out after ${timeoutMs}ms.`\n : `Step timed out after ${timeoutMs}ms.`,\n {\n code: 'STEP_TIMEOUT',\n details: { timeoutMs, ...(node === undefined ? {} : { node }) },\n },\n );\n this.timeoutMs = timeoutMs;\n this.node = node;\n }\n}\n\nexport class NodeExecutionError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string, cause: unknown) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Node \"${node}\" failed: ${causeMessage}`, {\n code: 'NODE_EXECUTION_ERROR',\n details: { node },\n cause,\n });\n this.node = node;\n }\n}\n\nexport class WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class ProjectSetupError extends WorkflowError {\n constructor(cause: unknown, details: { projectName: string }) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" setup failed: ${causeMessage}`, {\n code: 'PROJECT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class ProjectTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { projectName: string; registrationIndex: number },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" teardown failed: ${causeMessage}`, {\n code: 'PROJECT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class NodeScopeTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n scope: 'case' | 'document';\n scopeId: string;\n node: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(\n `${details.scope === 'case' ? 'Case attempt' : 'Workflow document'} node teardown failed for \"${details.node}\": ${causeMessage}`,\n { code: 'NODE_SCOPE_TEARDOWN_ERROR', details, cause },\n );\n }\n}\n\nexport class FatalDeviceError extends WorkflowError {\n constructor(message: string, cause?: unknown) {\n super(message, { code: 'FATAL_DEVICE_ERROR', cause });\n }\n}\n\nexport const isFatalDeviceError = (error: unknown): boolean => {\n if (error instanceof FatalDeviceError) return true;\n if (error instanceof WorkflowError && error.code === 'FATAL_DEVICE_ERROR') {\n return true;\n }\n if (\n error instanceof Error &&\n /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(\n error.message,\n )\n ) {\n return true;\n }\n return error instanceof Error && error.cause !== undefined\n ? isFatalDeviceError(error.cause)\n : false;\n};\n\nexport class CaseExecutionError extends WorkflowError {\n readonly result: import('./engine/types').CaseRunResult;\n\n constructor(result: import('./engine/types').CaseRunResult) {\n super(`Case \"${result.name}\" failed.`, {\n code: 'CASE_EXECUTION_FAILED',\n details: { caseId: result.caseId, runId: result.runId },\n });\n this.result = result;\n }\n}\n\nexport class WorkflowDocumentExecutionError extends WorkflowError {\n readonly result: import('./engine/types').WorkflowDocumentRunResult;\n\n constructor(result: import('./engine/types').WorkflowDocumentRunResult) {\n super(`Workflow document \"${result.sourcePath}\" failed.`, {\n code: 'WORKFLOW_DOCUMENT_EXECUTION_FAILED',\n details: {\n documentId: result.documentId,\n documentRunId: result.documentRunId,\n },\n });\n this.result = result;\n }\n}\n\nexport function normalizeNodeExecutionError(\n error: unknown,\n node: string,\n): WorkflowError {\n return error instanceof WorkflowError\n ? error\n : new NodeExecutionError(node, error);\n}\n","import { z } from 'zod/v4';\nimport { NodeDefinitionError } from '../errors';\nimport type {\n DefineNodeOptions,\n DefineNodeWithSchemaOptions,\n NodeDefinition,\n NodeDefinitionWithSchema,\n NodeInputSchema,\n} from './types';\n\nconst validateOptionalText = (\n value: unknown,\n field: 'title' | 'description',\n node: string,\n): void => {\n if (\n value !== undefined &&\n (typeof value !== 'string' || value.trim().length === 0)\n ) {\n throw new NodeDefinitionError(\n `Node \"${node}\" ${field} must be a non-empty string.`,\n { node, field },\n );\n }\n};\n\nconst validateInputSchema = (schema: unknown, node: string): void => {\n if (schema === undefined) return;\n if (!(schema instanceof z.ZodObject)) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must be a Zod object schema.`,\n { node, field: 'inputSchema' },\n );\n }\n if ('$' in schema.shape) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must not declare \"$\" as an input property.`,\n { node, field: 'inputSchema.$' },\n );\n }\n};\n\nconst validateDefinition = (options: {\n name: string;\n title?: unknown;\n description?: unknown;\n stringInputKey?: unknown;\n inputSchema?: unknown;\n execute: unknown;\n}): void => {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError('Node definition must be an object.');\n }\n\n if (typeof options.name !== 'string' || options.name.trim().length === 0) {\n throw new NodeDefinitionError('Node name must be a non-empty string.');\n }\n\n validateOptionalText(options.title, 'title', options.name);\n validateOptionalText(options.description, 'description', options.name);\n if (\n options.stringInputKey !== undefined &&\n options.stringInputKey !== false &&\n (typeof options.stringInputKey !== 'string' ||\n options.stringInputKey.trim().length === 0)\n ) {\n throw new NodeDefinitionError(\n `Node \"${options.name}\" stringInputKey must be a non-empty string or false.`,\n { node: options.name, field: 'stringInputKey' },\n );\n }\n validateInputSchema(options.inputSchema, options.name);\n\n if (\n typeof options.stringInputKey === 'string' &&\n options.inputSchema instanceof z.ZodObject &&\n !(options.stringInputKey in options.inputSchema.shape)\n ) {\n throw new NodeDefinitionError(\n `Node \"${options.name}\" stringInputKey must reference a field in inputSchema.`,\n { node: options.name, field: 'stringInputKey' },\n );\n }\n\n if (typeof options.execute !== 'function') {\n throw new NodeDefinitionError(\n `Node \"${options.name}\" must provide an execute function.`,\n { node: options.name },\n );\n }\n};\n\nexport function defineNode<\n TSchema extends NodeInputSchema,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeWithSchemaOptions<TSchema, TData, TContext>,\n): NodeDefinitionWithSchema<TSchema, TData, TContext>;\n\nexport function defineNode<\n TInput = unknown,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeOptions<TInput, TData, TContext>,\n): NodeDefinition<TInput, TData, TContext>;\n\nexport function defineNode(\n options: DefineNodeOptions<any, any, any>,\n): NodeDefinition<any, any, any> {\n validateDefinition(options);\n return options;\n}\n","import {\n type AgentTestRunnerNodeDefinition,\n type AgentTestRunnerNodeProvider,\n type CommonAgentTestRunnerApi,\n aiActInputSchema,\n aiActOptionsInputSchema,\n aiAssertInputSchema,\n aiAssertOptionsInputSchema,\n aiTapInputSchema,\n insightInputSchema,\n insightOptionsInputSchema,\n locateOptionsInputSchema,\n promptImageInputSchema,\n recordToReportInputSchema,\n recordToReportOptionsInputSchema,\n reportScreenshotInputSchema,\n structuredUserPromptInputSchema,\n userPromptInputSchema,\n} from '@midscene/core/agent/test-runner';\nimport { z } from 'zod/v4';\nimport type { Awaitable } from '../engine/types';\nimport { NodeDefinitionError, NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type {\n NodeDefinition,\n NodeExecutionContext,\n NodeResult,\n} from '../node/types';\n\nexport type MidsceneUIAgent = CommonAgentTestRunnerApi;\n\nexport {\n aiActInputSchema,\n aiActOptionsInputSchema,\n aiAssertInputSchema,\n aiAssertOptionsInputSchema,\n aiTapInputSchema,\n insightInputSchema,\n insightOptionsInputSchema,\n locateOptionsInputSchema,\n promptImageInputSchema,\n recordToReportInputSchema,\n recordToReportOptionsInputSchema,\n reportScreenshotInputSchema,\n structuredUserPromptInputSchema,\n userPromptInputSchema,\n};\n\nexport interface AgentProvider<TContext> {\n getAgent(\n runId: string,\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n // biome-ignore lint/suspicious/noConfusingVoidType: providers without a report intentionally return void.\n releaseAgent?(runId: string): Awaitable<AgentReleaseResult | void>;\n dispose?(): Awaitable<void>;\n}\n\nexport interface AgentReleaseResult {\n /** Absolute path to the finalized report for this Agent scope. */\n reportPath?: string;\n}\n\nexport interface AgentExecutorInput<TContext> {\n prompt: string;\n context: TContext;\n signal: AbortSignal;\n execution:\n | { scope: 'case'; runId: string }\n | { scope: 'document'; runId: string };\n}\n\nexport interface AgentExecutor<TContext> {\n // biome-ignore lint/suspicious/noConfusingVoidType: executors may perform side effects without returning a summary.\n execute(input: AgentExecutorInput<TContext>): Awaitable<NodeResult | void>;\n}\n\nconst nonBlankPrompt = (description: string) =>\n z\n .string()\n .regex(/\\S/, 'prompt must contain a non-whitespace character')\n .describe(description);\n\nexport const waitInputSchema = z.strictObject({\n duration: z.number().positive().describe('How long to wait.'),\n unit: z\n .enum(['ms', 's', 'min'])\n .default('ms')\n .describe('Duration unit: milliseconds, seconds, or minutes.'),\n});\n\nexport const agentInputSchema = z.strictObject({\n prompt: nonBlankPrompt(\n 'A self-contained task, including allowed tools and success conditions.',\n ),\n});\n\nexport type AiActNodeInput = z.infer<typeof aiActInputSchema>;\nexport type AiAssertNodeInput = z.infer<typeof aiAssertInputSchema>;\nexport type AiTapNodeInput = z.infer<typeof aiTapInputSchema>;\nexport type InsightNodeInput = z.infer<typeof insightInputSchema>;\nexport type RecordToReportNodeInput = z.infer<typeof recordToReportInputSchema>;\nexport type WaitNodeInput = z.infer<typeof waitInputSchema>;\nexport type AgentNodeInput = z.infer<typeof agentInputSchema>;\n\nexport interface CreateMidsceneNodesOptions<TContext> {\n getAgent?(\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n agentProvider?: AgentProvider<TContext>;\n /** Agent class that declares the Agent-backed Nodes to register. */\n agentClass: AgentTestRunnerNodeProvider;\n agentExecutor?: AgentExecutor<TContext>;\n}\n\nconst waitFor = async (durationMs: number, signal: AbortSignal) => {\n if (signal.aborted) {\n throw signal.reason ?? new Error('Wait aborted.');\n }\n await new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n signal.removeEventListener('abort', abort);\n resolve();\n }, durationMs);\n const abort = () => {\n clearTimeout(timeout);\n reject(signal.reason ?? new Error('Wait aborted.'));\n };\n signal.addEventListener('abort', abort, { once: true });\n });\n};\n\n/** Adapt Agent-owned descriptions to executable Test Runner Nodes. */\nexport const createAgentTestRunnerNodes = <TContext>(\n definitions: readonly AgentTestRunnerNodeDefinition[],\n getAgent: (\n ctx: NodeExecutionContext<unknown, TContext>,\n ) => Awaitable<unknown>,\n): readonly NodeDefinition<any, any, TContext>[] =>\n definitions.map((definition) =>\n defineNode({\n name: definition.name,\n ...(definition.title === undefined ? {} : { title: definition.title }),\n ...(definition.description === undefined\n ? {}\n : { description: definition.description }),\n ...(definition.stringInputKey === undefined\n ? {}\n : { stringInputKey: definition.stringInputKey }),\n inputSchema: definition.inputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n return definition.execute(agent, ctx.input, {\n signal: ctx.signal,\n });\n },\n }),\n );\n\nexport function createMidsceneNodes<TContext>(\n options: CreateMidsceneNodesOptions<TContext>,\n): readonly NodeDefinition<any, any, TContext>[] {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() options must be an object.',\n );\n }\n if (\n typeof options.agentProvider?.getAgent !== 'function' &&\n typeof options.getAgent !== 'function'\n ) {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() requires getAgent or agentProvider.getAgent.',\n );\n }\n if (\n !options.agentClass ||\n typeof options.agentClass.getTestRunnerNodeDefinitions !== 'function'\n ) {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() requires agentClass.getTestRunnerNodeDefinitions().',\n );\n }\n\n const registeredAgentScopes = new Set<string>();\n const getExecutionId = (ctx: NodeExecutionContext<unknown, TContext>) =>\n ctx.scope === 'case' ? ctx.case.runId : ctx.document.documentRunId;\n const getAgent = async (\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Promise<MidsceneUIAgent> => {\n if (!options.agentProvider) return options.getAgent!(ctx);\n const runId = getExecutionId(ctx);\n if (\n options.agentProvider.releaseAgent &&\n !registeredAgentScopes.has(runId)\n ) {\n registeredAgentScopes.add(runId);\n ctx.onTeardown(async () => {\n try {\n const released = await options.agentProvider!.releaseAgent!(runId);\n return released?.reportPath\n ? { reportPaths: [released.reportPath] }\n : undefined;\n } finally {\n registeredAgentScopes.delete(runId);\n }\n });\n }\n return options.agentProvider.getAgent(runId, ctx);\n };\n\n const agentDefinitions = options.agentClass.getTestRunnerNodeDefinitions();\n\n return [\n ...createAgentTestRunnerNodes(agentDefinitions, getAgent),\n defineNode<typeof waitInputSchema, unknown, TContext>({\n name: 'wait',\n description: 'Wait for a fixed duration while honoring cancellation.',\n stringInputKey: false,\n inputSchema: waitInputSchema,\n async execute(ctx) {\n const multiplier =\n ctx.input.unit === 'min'\n ? 60_000\n : ctx.input.unit === 's'\n ? 1_000\n : 1;\n const durationMs = ctx.input.duration * multiplier;\n await waitFor(durationMs, ctx.signal);\n return { summary: `Waited ${durationMs}ms` };\n },\n }),\n defineNode<typeof agentInputSchema, unknown, TContext>({\n name: 'agent',\n description:\n 'Execute one self-contained natural-language task with an injected Agent executor.',\n stringInputKey: 'prompt',\n inputSchema: agentInputSchema,\n async execute(ctx) {\n if (!options.agentExecutor) {\n throw new NodeExecutionError(\n 'agent',\n new TypeError('createMidsceneNodes() requires an agentExecutor.'),\n );\n }\n const execution =\n ctx.scope === 'case'\n ? { scope: 'case' as const, runId: ctx.case.runId }\n : {\n scope: 'document' as const,\n runId: ctx.document.documentRunId,\n };\n const result = await options.agentExecutor.execute({\n prompt: ctx.input.prompt,\n context: ctx.context,\n signal: ctx.signal,\n execution,\n });\n return result ?? { summary: 'Agent task completed.' };\n },\n }),\n ];\n}\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { AndroidAgent } from '@midscene/android';\nimport {\n androidAgentTestRunnerNodeDefinitions,\n launchInputSchema,\n runAdbShellInputSchema,\n runAdbShellOptionsInputSchema,\n terminateInputSchema,\n} from '@midscene/android/test-runner';\nexport type {\n LaunchNodeInput,\n RunAdbShellNodeInput,\n TerminateNodeInput,\n} from '@midscene/android/test-runner';\nimport type { Awaitable } from '../engine/types';\nimport { NodeDefinitionError } from '../errors';\nimport { createAgentTestRunnerNodes } from '../midscene';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\nexport {\n launchInputSchema,\n runAdbShellInputSchema,\n runAdbShellOptionsInputSchema,\n terminateInputSchema,\n};\n\nexport type AndroidRunnerAgent = Pick<\n AndroidAgent,\n 'launch' | 'terminate' | 'runAdbShell' | 'back' | 'home' | 'recentApps'\n>;\n\nexport interface CreateAndroidNodesOptions<TContext> {\n getAgent(\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<AndroidRunnerAgent>;\n}\n\nexport function createAndroidNodes<TContext>(\n options: CreateAndroidNodesOptions<TContext>,\n): readonly NodeDefinition<any, any, TContext>[] {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError(\n 'createAndroidNodes() options must be an object.',\n );\n }\n if (typeof options.getAgent !== 'function') {\n throw new NodeDefinitionError('createAndroidNodes() requires getAgent().');\n }\n\n return createAgentTestRunnerNodes(\n androidAgentTestRunnerNodeDefinitions,\n options.getAgent,\n );\n}\n"],"names":["WorkflowError","Error","undefined","message","options","NodeDefinitionError","details","validateOptionalText","value","field","node","validateInputSchema","schema","z","validateDefinition","defineNode","nonBlankPrompt","description","createAgentTestRunnerNodes","definitions","getAgent","definition","ctx","agent","__webpack_require__","key","Object","obj","prop","Symbol","createAndroidNodes","androidAgentTestRunnerNod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