@midscene/android 1.17.8-beta-20261106101231.0 → 1.17.8

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.
@@ -0,0 +1,105 @@
1
+ import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test";
2
+ import { z } from "zod/v4";
3
+ const defineAndroidAgentNode = createAgentTestRunnerNodeDefinition('an Android Agent');
4
+ const nonBlankText = (description)=>z.string().regex(/\S/, 'value must contain a non-whitespace character').describe(description);
5
+ const launchInputSchema = z.strictObject({
6
+ uri: nonBlankText('The app, URL, URI, or package name to launch.')
7
+ });
8
+ const terminateInputSchema = z.strictObject({
9
+ uri: nonBlankText('The package name or app name to terminate.')
10
+ });
11
+ const runAdbShellOptionsInputSchema = z.strictObject({
12
+ timeout: z.number().int().positive().optional().describe('ADB shell command timeout in milliseconds.')
13
+ });
14
+ const runAdbShellInputSchema = z.strictObject({
15
+ command: nonBlankText('The shell command to execute, without an adb shell prefix.'),
16
+ options: runAdbShellOptionsInputSchema.optional()
17
+ });
18
+ const emptyInputSchema = z.strictObject({});
19
+ const launchNode = defineAndroidAgentNode({
20
+ method: 'launch',
21
+ description: 'Launch an application through the current Android Agent.',
22
+ stringInputKey: 'uri',
23
+ inputSchema: launchInputSchema,
24
+ toArgs: (input)=>[
25
+ input.uri
26
+ ],
27
+ toResult: (_output, input)=>({
28
+ summary: `Launched ${input.uri}`
29
+ })
30
+ });
31
+ const terminateNode = defineAndroidAgentNode({
32
+ method: 'terminate',
33
+ description: 'Terminate an application through the current Android Agent.',
34
+ stringInputKey: 'uri',
35
+ inputSchema: terminateInputSchema,
36
+ toArgs: (input)=>[
37
+ input.uri
38
+ ],
39
+ toResult: (_output, input)=>({
40
+ summary: `Terminated ${input.uri}`
41
+ })
42
+ });
43
+ const runAdbShellNode = defineAndroidAgentNode({
44
+ method: 'runAdbShell',
45
+ title: 'Run an ADB shell command',
46
+ description: 'Execute a shell command through the current Android Agent. Pass only the shell command, without the adb shell prefix.',
47
+ stringInputKey: 'command',
48
+ inputSchema: runAdbShellInputSchema,
49
+ toArgs (input, context) {
50
+ context.signal.throwIfAborted();
51
+ if (/^\s*adb(?:\s|$)/i.test(input.command)) throw new TypeError('command must not include an adb or adb shell prefix.');
52
+ return [
53
+ input.command,
54
+ input.options
55
+ ];
56
+ },
57
+ toResult (stdout) {
58
+ if ('string' != typeof stdout) throw new TypeError('runAdbShell() must return stdout as a string.');
59
+ return {
60
+ summary: `Executed ADB shell command (${stdout.length} stdout characters)`,
61
+ data: {
62
+ stdout
63
+ }
64
+ };
65
+ }
66
+ });
67
+ const backNode = defineAndroidAgentNode({
68
+ method: 'back',
69
+ description: 'Trigger the Android system back operation.',
70
+ stringInputKey: false,
71
+ inputSchema: emptyInputSchema,
72
+ toArgs: ()=>[],
73
+ toResult: ()=>({
74
+ summary: 'Triggered Android back'
75
+ })
76
+ });
77
+ const homeNode = defineAndroidAgentNode({
78
+ method: 'home',
79
+ description: 'Trigger the Android system home operation.',
80
+ stringInputKey: false,
81
+ inputSchema: emptyInputSchema,
82
+ toArgs: ()=>[],
83
+ toResult: ()=>({
84
+ summary: 'Triggered Android home'
85
+ })
86
+ });
87
+ const recentAppsNode = defineAndroidAgentNode({
88
+ method: 'recentApps',
89
+ description: 'Trigger the Android system recent apps operation.',
90
+ stringInputKey: false,
91
+ inputSchema: emptyInputSchema,
92
+ toArgs: ()=>[],
93
+ toResult: ()=>({
94
+ summary: 'Triggered Android recentApps'
95
+ })
96
+ });
97
+ const androidAgentTestRunnerNodeDefinitions = [
98
+ launchNode,
99
+ terminateNode,
100
+ runAdbShellNode,
101
+ backNode,
102
+ homeNode,
103
+ recentAppsNode
104
+ ];
105
+ export { androidAgentTestRunnerNodeDefinitions, launchInputSchema, runAdbShellInputSchema, runAdbShellOptionsInputSchema, terminateInputSchema };