@midscene/harmony 1.12.4-beta-20260904041024.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/bin.mjs +105 -0
- package/dist/es/cli.mjs +106 -1
- package/dist/es/index.mjs +106 -1
- package/dist/es/test-runner.mjs +100 -0
- package/dist/lib/bin.js +1331 -1207
- package/dist/lib/cli.js +1259 -1135
- package/dist/lib/index.js +1448 -1309
- package/dist/lib/test-runner.js +143 -0
- package/dist/types/index.d.ts +24 -0
- package/dist/types/test-runner.d.ts +24 -0
- package/package.json +11 -6
- package/static/index.html +1 -1
- package/static/static/js/{226.9d4ca7e4.js → 415.bee53531.js} +55 -32
- package/static/static/js/415.bee53531.js.map +1 -0
- package/static/static/js/index.7d684402.js +855 -0
- package/static/static/js/index.7d684402.js.map +1 -0
- package/static/static/js/226.9d4ca7e4.js.map +0 -1
- package/static/static/js/index.c725ff6d.js +0 -858
- package/static/static/js/index.c725ff6d.js.map +0 -1
- /package/static/static/js/{226.9d4ca7e4.js.LICENSE.txt → 415.bee53531.js.LICENSE.txt} +0 -0
- /package/static/static/js/{index.c725ff6d.js.LICENSE.txt → index.7d684402.js.LICENSE.txt} +0 -0
package/dist/es/bin.mjs
CHANGED
|
@@ -14,6 +14,8 @@ import { getTmpFile, sleep } from "@midscene/core/utils";
|
|
|
14
14
|
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
15
15
|
import { execFile } from "node:child_process";
|
|
16
16
|
import { promisify } from "node:util";
|
|
17
|
+
import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test-runner";
|
|
18
|
+
import { z as v4_z } from "zod/v4";
|
|
17
19
|
const defaultAppNameMapping = {
|
|
18
20
|
设置: 'com.huawei.hmos.settings',
|
|
19
21
|
Settings: 'com.huawei.hmos.settings',
|
|
@@ -1004,6 +1006,103 @@ const createPlatformActions = (device)=>({
|
|
|
1004
1006
|
}
|
|
1005
1007
|
})
|
|
1006
1008
|
});
|
|
1009
|
+
const defineHarmonyAgentNode = createAgentTestRunnerNodeDefinition('a Harmony Agent');
|
|
1010
|
+
const nonBlankText = (description)=>v4_z.string().regex(/\S/, 'value must contain a non-whitespace character').describe(description);
|
|
1011
|
+
const launchInputSchema = v4_z.strictObject({
|
|
1012
|
+
uri: nonBlankText('The app, URL, URI, bundle name, or bundle/Ability target to launch.')
|
|
1013
|
+
});
|
|
1014
|
+
const terminateInputSchema = v4_z.strictObject({
|
|
1015
|
+
uri: nonBlankText('The bundle name or app name to terminate.')
|
|
1016
|
+
});
|
|
1017
|
+
const runHdcShellInputSchema = v4_z.strictObject({
|
|
1018
|
+
command: nonBlankText('The shell command to execute, without an hdc shell prefix.')
|
|
1019
|
+
});
|
|
1020
|
+
const emptyInputSchema = v4_z.strictObject({});
|
|
1021
|
+
const launchNode = defineHarmonyAgentNode({
|
|
1022
|
+
method: 'launch',
|
|
1023
|
+
description: 'Launch an application through the current Harmony Agent.',
|
|
1024
|
+
stringInputKey: 'uri',
|
|
1025
|
+
inputSchema: launchInputSchema,
|
|
1026
|
+
toArgs: (input)=>[
|
|
1027
|
+
input.uri
|
|
1028
|
+
],
|
|
1029
|
+
toResult: (_output, input)=>({
|
|
1030
|
+
summary: `Launched ${input.uri}`
|
|
1031
|
+
})
|
|
1032
|
+
});
|
|
1033
|
+
const terminateNode = defineHarmonyAgentNode({
|
|
1034
|
+
method: 'terminate',
|
|
1035
|
+
description: 'Terminate an application through the current Harmony Agent.',
|
|
1036
|
+
stringInputKey: 'uri',
|
|
1037
|
+
inputSchema: terminateInputSchema,
|
|
1038
|
+
toArgs: (input)=>[
|
|
1039
|
+
input.uri
|
|
1040
|
+
],
|
|
1041
|
+
toResult: (_output, input)=>({
|
|
1042
|
+
summary: `Terminated ${input.uri}`
|
|
1043
|
+
})
|
|
1044
|
+
});
|
|
1045
|
+
const runHdcShellNode = defineHarmonyAgentNode({
|
|
1046
|
+
method: 'runHdcShell',
|
|
1047
|
+
title: 'Run an HDC shell command',
|
|
1048
|
+
description: 'Execute a shell command through the current Harmony Agent. Pass only the shell command, without the hdc shell prefix.',
|
|
1049
|
+
stringInputKey: 'command',
|
|
1050
|
+
inputSchema: runHdcShellInputSchema,
|
|
1051
|
+
toArgs (input, context) {
|
|
1052
|
+
context.signal.throwIfAborted();
|
|
1053
|
+
if (/^\s*hdc(?:\s|$)/i.test(input.command)) throw new TypeError('command must not include an hdc or hdc shell prefix.');
|
|
1054
|
+
return [
|
|
1055
|
+
input.command
|
|
1056
|
+
];
|
|
1057
|
+
},
|
|
1058
|
+
toResult (stdout) {
|
|
1059
|
+
if ('string' != typeof stdout) throw new TypeError('runHdcShell() must return stdout as a string.');
|
|
1060
|
+
return {
|
|
1061
|
+
summary: `Executed HDC shell command (${stdout.length} stdout characters)`,
|
|
1062
|
+
data: {
|
|
1063
|
+
stdout
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
const backNode = defineHarmonyAgentNode({
|
|
1069
|
+
method: 'back',
|
|
1070
|
+
description: 'Trigger the Harmony system back operation.',
|
|
1071
|
+
stringInputKey: false,
|
|
1072
|
+
inputSchema: emptyInputSchema,
|
|
1073
|
+
toArgs: ()=>[],
|
|
1074
|
+
toResult: ()=>({
|
|
1075
|
+
summary: 'Triggered Harmony back'
|
|
1076
|
+
})
|
|
1077
|
+
});
|
|
1078
|
+
const homeNode = defineHarmonyAgentNode({
|
|
1079
|
+
method: 'home',
|
|
1080
|
+
description: 'Trigger the Harmony system home operation.',
|
|
1081
|
+
stringInputKey: false,
|
|
1082
|
+
inputSchema: emptyInputSchema,
|
|
1083
|
+
toArgs: ()=>[],
|
|
1084
|
+
toResult: ()=>({
|
|
1085
|
+
summary: 'Triggered Harmony home'
|
|
1086
|
+
})
|
|
1087
|
+
});
|
|
1088
|
+
const recentAppsNode = defineHarmonyAgentNode({
|
|
1089
|
+
method: 'recentApps',
|
|
1090
|
+
description: 'Trigger the Harmony system recent apps operation.',
|
|
1091
|
+
stringInputKey: false,
|
|
1092
|
+
inputSchema: emptyInputSchema,
|
|
1093
|
+
toArgs: ()=>[],
|
|
1094
|
+
toResult: ()=>({
|
|
1095
|
+
summary: 'Triggered Harmony recentApps'
|
|
1096
|
+
})
|
|
1097
|
+
});
|
|
1098
|
+
const harmonyAgentTestRunnerNodeDefinitions = [
|
|
1099
|
+
launchNode,
|
|
1100
|
+
terminateNode,
|
|
1101
|
+
runHdcShellNode,
|
|
1102
|
+
backNode,
|
|
1103
|
+
homeNode,
|
|
1104
|
+
recentAppsNode
|
|
1105
|
+
];
|
|
1007
1106
|
const debugUtils = getDebug('harmony:utils');
|
|
1008
1107
|
async function utils_getConnectedDevices(hdcPath, options = {}) {
|
|
1009
1108
|
try {
|
|
@@ -1036,6 +1135,12 @@ function agent_define_property(obj, key, value) {
|
|
|
1036
1135
|
}
|
|
1037
1136
|
getDebug('harmony:agent');
|
|
1038
1137
|
class HarmonyAgent extends Agent {
|
|
1138
|
+
static getTestRunnerNodeDefinitions() {
|
|
1139
|
+
return [
|
|
1140
|
+
...Agent.getTestRunnerNodeDefinitions(),
|
|
1141
|
+
...harmonyAgentTestRunnerNodeDefinitions
|
|
1142
|
+
];
|
|
1143
|
+
}
|
|
1039
1144
|
async launch(uri) {
|
|
1040
1145
|
const action = this.wrapActionInActionSpace('Launch');
|
|
1041
1146
|
return action({
|
package/dist/es/cli.mjs
CHANGED
|
@@ -12,6 +12,8 @@ import { getTmpFile, sleep } from "@midscene/core/utils";
|
|
|
12
12
|
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
13
13
|
import { execFile } from "node:child_process";
|
|
14
14
|
import { promisify } from "node:util";
|
|
15
|
+
import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test-runner";
|
|
16
|
+
import { z as v4_z } from "zod/v4";
|
|
15
17
|
const defaultAppNameMapping = {
|
|
16
18
|
设置: 'com.huawei.hmos.settings',
|
|
17
19
|
Settings: 'com.huawei.hmos.settings',
|
|
@@ -1002,6 +1004,103 @@ const createPlatformActions = (device)=>({
|
|
|
1002
1004
|
}
|
|
1003
1005
|
})
|
|
1004
1006
|
});
|
|
1007
|
+
const defineHarmonyAgentNode = createAgentTestRunnerNodeDefinition('a Harmony Agent');
|
|
1008
|
+
const nonBlankText = (description)=>v4_z.string().regex(/\S/, 'value must contain a non-whitespace character').describe(description);
|
|
1009
|
+
const launchInputSchema = v4_z.strictObject({
|
|
1010
|
+
uri: nonBlankText('The app, URL, URI, bundle name, or bundle/Ability target to launch.')
|
|
1011
|
+
});
|
|
1012
|
+
const terminateInputSchema = v4_z.strictObject({
|
|
1013
|
+
uri: nonBlankText('The bundle name or app name to terminate.')
|
|
1014
|
+
});
|
|
1015
|
+
const runHdcShellInputSchema = v4_z.strictObject({
|
|
1016
|
+
command: nonBlankText('The shell command to execute, without an hdc shell prefix.')
|
|
1017
|
+
});
|
|
1018
|
+
const emptyInputSchema = v4_z.strictObject({});
|
|
1019
|
+
const launchNode = defineHarmonyAgentNode({
|
|
1020
|
+
method: 'launch',
|
|
1021
|
+
description: 'Launch an application through the current Harmony Agent.',
|
|
1022
|
+
stringInputKey: 'uri',
|
|
1023
|
+
inputSchema: launchInputSchema,
|
|
1024
|
+
toArgs: (input)=>[
|
|
1025
|
+
input.uri
|
|
1026
|
+
],
|
|
1027
|
+
toResult: (_output, input)=>({
|
|
1028
|
+
summary: `Launched ${input.uri}`
|
|
1029
|
+
})
|
|
1030
|
+
});
|
|
1031
|
+
const terminateNode = defineHarmonyAgentNode({
|
|
1032
|
+
method: 'terminate',
|
|
1033
|
+
description: 'Terminate an application through the current Harmony Agent.',
|
|
1034
|
+
stringInputKey: 'uri',
|
|
1035
|
+
inputSchema: terminateInputSchema,
|
|
1036
|
+
toArgs: (input)=>[
|
|
1037
|
+
input.uri
|
|
1038
|
+
],
|
|
1039
|
+
toResult: (_output, input)=>({
|
|
1040
|
+
summary: `Terminated ${input.uri}`
|
|
1041
|
+
})
|
|
1042
|
+
});
|
|
1043
|
+
const runHdcShellNode = defineHarmonyAgentNode({
|
|
1044
|
+
method: 'runHdcShell',
|
|
1045
|
+
title: 'Run an HDC shell command',
|
|
1046
|
+
description: 'Execute a shell command through the current Harmony Agent. Pass only the shell command, without the hdc shell prefix.',
|
|
1047
|
+
stringInputKey: 'command',
|
|
1048
|
+
inputSchema: runHdcShellInputSchema,
|
|
1049
|
+
toArgs (input, context) {
|
|
1050
|
+
context.signal.throwIfAborted();
|
|
1051
|
+
if (/^\s*hdc(?:\s|$)/i.test(input.command)) throw new TypeError('command must not include an hdc or hdc shell prefix.');
|
|
1052
|
+
return [
|
|
1053
|
+
input.command
|
|
1054
|
+
];
|
|
1055
|
+
},
|
|
1056
|
+
toResult (stdout) {
|
|
1057
|
+
if ('string' != typeof stdout) throw new TypeError('runHdcShell() must return stdout as a string.');
|
|
1058
|
+
return {
|
|
1059
|
+
summary: `Executed HDC shell command (${stdout.length} stdout characters)`,
|
|
1060
|
+
data: {
|
|
1061
|
+
stdout
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
const backNode = defineHarmonyAgentNode({
|
|
1067
|
+
method: 'back',
|
|
1068
|
+
description: 'Trigger the Harmony system back operation.',
|
|
1069
|
+
stringInputKey: false,
|
|
1070
|
+
inputSchema: emptyInputSchema,
|
|
1071
|
+
toArgs: ()=>[],
|
|
1072
|
+
toResult: ()=>({
|
|
1073
|
+
summary: 'Triggered Harmony back'
|
|
1074
|
+
})
|
|
1075
|
+
});
|
|
1076
|
+
const homeNode = defineHarmonyAgentNode({
|
|
1077
|
+
method: 'home',
|
|
1078
|
+
description: 'Trigger the Harmony system home operation.',
|
|
1079
|
+
stringInputKey: false,
|
|
1080
|
+
inputSchema: emptyInputSchema,
|
|
1081
|
+
toArgs: ()=>[],
|
|
1082
|
+
toResult: ()=>({
|
|
1083
|
+
summary: 'Triggered Harmony home'
|
|
1084
|
+
})
|
|
1085
|
+
});
|
|
1086
|
+
const recentAppsNode = defineHarmonyAgentNode({
|
|
1087
|
+
method: 'recentApps',
|
|
1088
|
+
description: 'Trigger the Harmony system recent apps operation.',
|
|
1089
|
+
stringInputKey: false,
|
|
1090
|
+
inputSchema: emptyInputSchema,
|
|
1091
|
+
toArgs: ()=>[],
|
|
1092
|
+
toResult: ()=>({
|
|
1093
|
+
summary: 'Triggered Harmony recentApps'
|
|
1094
|
+
})
|
|
1095
|
+
});
|
|
1096
|
+
const harmonyAgentTestRunnerNodeDefinitions = [
|
|
1097
|
+
launchNode,
|
|
1098
|
+
terminateNode,
|
|
1099
|
+
runHdcShellNode,
|
|
1100
|
+
backNode,
|
|
1101
|
+
homeNode,
|
|
1102
|
+
recentAppsNode
|
|
1103
|
+
];
|
|
1005
1104
|
const debugUtils = getDebug('harmony:utils');
|
|
1006
1105
|
async function getConnectedDevices(hdcPath, options = {}) {
|
|
1007
1106
|
try {
|
|
@@ -1034,6 +1133,12 @@ function agent_define_property(obj, key, value) {
|
|
|
1034
1133
|
}
|
|
1035
1134
|
const debugAgent = getDebug('harmony:agent');
|
|
1036
1135
|
class HarmonyAgent extends Agent {
|
|
1136
|
+
static getTestRunnerNodeDefinitions() {
|
|
1137
|
+
return [
|
|
1138
|
+
...Agent.getTestRunnerNodeDefinitions(),
|
|
1139
|
+
...harmonyAgentTestRunnerNodeDefinitions
|
|
1140
|
+
];
|
|
1141
|
+
}
|
|
1037
1142
|
async launch(uri) {
|
|
1038
1143
|
const action = this.wrapActionInActionSpace('Launch');
|
|
1039
1144
|
return action({
|
|
@@ -1187,7 +1292,7 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
|
|
|
1187
1292
|
const tools = new HarmonyMidsceneTools();
|
|
1188
1293
|
runToolsCLI(tools, 'midscene-harmony', {
|
|
1189
1294
|
stripPrefix: 'harmony_',
|
|
1190
|
-
version: "1.12.4
|
|
1295
|
+
version: "1.12.4",
|
|
1191
1296
|
extraCommands: createReportCliCommands()
|
|
1192
1297
|
}).catch((e)=>{
|
|
1193
1298
|
process.exit(reportCLIError(e));
|
package/dist/es/index.mjs
CHANGED
|
@@ -9,6 +9,8 @@ import { mergeAndNormalizeAppNameMapping, normalizeForComparison, repeat } from
|
|
|
9
9
|
import { execFile } from "node:child_process";
|
|
10
10
|
import { promisify } from "node:util";
|
|
11
11
|
import { Agent } from "@midscene/core/agent";
|
|
12
|
+
import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test-runner";
|
|
13
|
+
import { z as v4_z } from "zod/v4";
|
|
12
14
|
import { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/agent-tools/agent-behavior-init-args";
|
|
13
15
|
import { BaseMidsceneTools } from "@midscene/shared/agent-tools/base-tools";
|
|
14
16
|
import { overrideAIConfig } from "@midscene/shared/env";
|
|
@@ -1007,6 +1009,103 @@ const defaultAppNameMapping = {
|
|
|
1007
1009
|
百度: 'com.baidu.baiduapp',
|
|
1008
1010
|
携程: 'com.ctrip.harmonynext'
|
|
1009
1011
|
};
|
|
1012
|
+
const defineHarmonyAgentNode = createAgentTestRunnerNodeDefinition('a Harmony Agent');
|
|
1013
|
+
const nonBlankText = (description)=>v4_z.string().regex(/\S/, 'value must contain a non-whitespace character').describe(description);
|
|
1014
|
+
const launchInputSchema = v4_z.strictObject({
|
|
1015
|
+
uri: nonBlankText('The app, URL, URI, bundle name, or bundle/Ability target to launch.')
|
|
1016
|
+
});
|
|
1017
|
+
const terminateInputSchema = v4_z.strictObject({
|
|
1018
|
+
uri: nonBlankText('The bundle name or app name to terminate.')
|
|
1019
|
+
});
|
|
1020
|
+
const runHdcShellInputSchema = v4_z.strictObject({
|
|
1021
|
+
command: nonBlankText('The shell command to execute, without an hdc shell prefix.')
|
|
1022
|
+
});
|
|
1023
|
+
const emptyInputSchema = v4_z.strictObject({});
|
|
1024
|
+
const launchNode = defineHarmonyAgentNode({
|
|
1025
|
+
method: 'launch',
|
|
1026
|
+
description: 'Launch an application through the current Harmony Agent.',
|
|
1027
|
+
stringInputKey: 'uri',
|
|
1028
|
+
inputSchema: launchInputSchema,
|
|
1029
|
+
toArgs: (input)=>[
|
|
1030
|
+
input.uri
|
|
1031
|
+
],
|
|
1032
|
+
toResult: (_output, input)=>({
|
|
1033
|
+
summary: `Launched ${input.uri}`
|
|
1034
|
+
})
|
|
1035
|
+
});
|
|
1036
|
+
const terminateNode = defineHarmonyAgentNode({
|
|
1037
|
+
method: 'terminate',
|
|
1038
|
+
description: 'Terminate an application through the current Harmony Agent.',
|
|
1039
|
+
stringInputKey: 'uri',
|
|
1040
|
+
inputSchema: terminateInputSchema,
|
|
1041
|
+
toArgs: (input)=>[
|
|
1042
|
+
input.uri
|
|
1043
|
+
],
|
|
1044
|
+
toResult: (_output, input)=>({
|
|
1045
|
+
summary: `Terminated ${input.uri}`
|
|
1046
|
+
})
|
|
1047
|
+
});
|
|
1048
|
+
const runHdcShellNode = defineHarmonyAgentNode({
|
|
1049
|
+
method: 'runHdcShell',
|
|
1050
|
+
title: 'Run an HDC shell command',
|
|
1051
|
+
description: 'Execute a shell command through the current Harmony Agent. Pass only the shell command, without the hdc shell prefix.',
|
|
1052
|
+
stringInputKey: 'command',
|
|
1053
|
+
inputSchema: runHdcShellInputSchema,
|
|
1054
|
+
toArgs (input, context) {
|
|
1055
|
+
context.signal.throwIfAborted();
|
|
1056
|
+
if (/^\s*hdc(?:\s|$)/i.test(input.command)) throw new TypeError('command must not include an hdc or hdc shell prefix.');
|
|
1057
|
+
return [
|
|
1058
|
+
input.command
|
|
1059
|
+
];
|
|
1060
|
+
},
|
|
1061
|
+
toResult (stdout) {
|
|
1062
|
+
if ('string' != typeof stdout) throw new TypeError('runHdcShell() must return stdout as a string.');
|
|
1063
|
+
return {
|
|
1064
|
+
summary: `Executed HDC shell command (${stdout.length} stdout characters)`,
|
|
1065
|
+
data: {
|
|
1066
|
+
stdout
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
const backNode = defineHarmonyAgentNode({
|
|
1072
|
+
method: 'back',
|
|
1073
|
+
description: 'Trigger the Harmony system back operation.',
|
|
1074
|
+
stringInputKey: false,
|
|
1075
|
+
inputSchema: emptyInputSchema,
|
|
1076
|
+
toArgs: ()=>[],
|
|
1077
|
+
toResult: ()=>({
|
|
1078
|
+
summary: 'Triggered Harmony back'
|
|
1079
|
+
})
|
|
1080
|
+
});
|
|
1081
|
+
const homeNode = defineHarmonyAgentNode({
|
|
1082
|
+
method: 'home',
|
|
1083
|
+
description: 'Trigger the Harmony system home operation.',
|
|
1084
|
+
stringInputKey: false,
|
|
1085
|
+
inputSchema: emptyInputSchema,
|
|
1086
|
+
toArgs: ()=>[],
|
|
1087
|
+
toResult: ()=>({
|
|
1088
|
+
summary: 'Triggered Harmony home'
|
|
1089
|
+
})
|
|
1090
|
+
});
|
|
1091
|
+
const recentAppsNode = defineHarmonyAgentNode({
|
|
1092
|
+
method: 'recentApps',
|
|
1093
|
+
description: 'Trigger the Harmony system recent apps operation.',
|
|
1094
|
+
stringInputKey: false,
|
|
1095
|
+
inputSchema: emptyInputSchema,
|
|
1096
|
+
toArgs: ()=>[],
|
|
1097
|
+
toResult: ()=>({
|
|
1098
|
+
summary: 'Triggered Harmony recentApps'
|
|
1099
|
+
})
|
|
1100
|
+
});
|
|
1101
|
+
const harmonyAgentTestRunnerNodeDefinitions = [
|
|
1102
|
+
launchNode,
|
|
1103
|
+
terminateNode,
|
|
1104
|
+
runHdcShellNode,
|
|
1105
|
+
backNode,
|
|
1106
|
+
homeNode,
|
|
1107
|
+
recentAppsNode
|
|
1108
|
+
];
|
|
1010
1109
|
const debugUtils = getDebug('harmony:utils');
|
|
1011
1110
|
async function getConnectedDevices(hdcPath, options = {}) {
|
|
1012
1111
|
try {
|
|
@@ -1039,6 +1138,12 @@ function agent_define_property(obj, key, value) {
|
|
|
1039
1138
|
}
|
|
1040
1139
|
const debugAgent = getDebug('harmony:agent');
|
|
1041
1140
|
class HarmonyAgent extends Agent {
|
|
1141
|
+
static getTestRunnerNodeDefinitions() {
|
|
1142
|
+
return [
|
|
1143
|
+
...Agent.getTestRunnerNodeDefinitions(),
|
|
1144
|
+
...harmonyAgentTestRunnerNodeDefinitions
|
|
1145
|
+
];
|
|
1146
|
+
}
|
|
1042
1147
|
async launch(uri) {
|
|
1043
1148
|
const action = this.wrapActionInActionSpace('Launch');
|
|
1044
1149
|
return action({
|
|
@@ -1367,4 +1472,4 @@ const harmonyPlaygroundPlatform = definePlaygroundPlatform({
|
|
|
1367
1472
|
};
|
|
1368
1473
|
}
|
|
1369
1474
|
});
|
|
1370
|
-
export { HarmonyAgent, HarmonyDevice, HarmonyMidsceneTools, agentFromHdcDevice, getConnectedDevices, harmonyPlaygroundPlatform, overrideAIConfig };
|
|
1475
|
+
export { HarmonyAgent, HarmonyDevice, HarmonyMidsceneTools, agentFromHdcDevice, getConnectedDevices, harmonyAgentTestRunnerNodeDefinitions, harmonyPlaygroundPlatform, launchInputSchema, overrideAIConfig, runHdcShellInputSchema, terminateInputSchema };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test-runner";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
const defineHarmonyAgentNode = createAgentTestRunnerNodeDefinition('a Harmony 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, bundle name, or bundle/Ability target to launch.')
|
|
7
|
+
});
|
|
8
|
+
const terminateInputSchema = z.strictObject({
|
|
9
|
+
uri: nonBlankText('The bundle name or app name to terminate.')
|
|
10
|
+
});
|
|
11
|
+
const runHdcShellInputSchema = z.strictObject({
|
|
12
|
+
command: nonBlankText('The shell command to execute, without an hdc shell prefix.')
|
|
13
|
+
});
|
|
14
|
+
const emptyInputSchema = z.strictObject({});
|
|
15
|
+
const launchNode = defineHarmonyAgentNode({
|
|
16
|
+
method: 'launch',
|
|
17
|
+
description: 'Launch an application through the current Harmony Agent.',
|
|
18
|
+
stringInputKey: 'uri',
|
|
19
|
+
inputSchema: launchInputSchema,
|
|
20
|
+
toArgs: (input)=>[
|
|
21
|
+
input.uri
|
|
22
|
+
],
|
|
23
|
+
toResult: (_output, input)=>({
|
|
24
|
+
summary: `Launched ${input.uri}`
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
const terminateNode = defineHarmonyAgentNode({
|
|
28
|
+
method: 'terminate',
|
|
29
|
+
description: 'Terminate an application through the current Harmony Agent.',
|
|
30
|
+
stringInputKey: 'uri',
|
|
31
|
+
inputSchema: terminateInputSchema,
|
|
32
|
+
toArgs: (input)=>[
|
|
33
|
+
input.uri
|
|
34
|
+
],
|
|
35
|
+
toResult: (_output, input)=>({
|
|
36
|
+
summary: `Terminated ${input.uri}`
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
const runHdcShellNode = defineHarmonyAgentNode({
|
|
40
|
+
method: 'runHdcShell',
|
|
41
|
+
title: 'Run an HDC shell command',
|
|
42
|
+
description: 'Execute a shell command through the current Harmony Agent. Pass only the shell command, without the hdc shell prefix.',
|
|
43
|
+
stringInputKey: 'command',
|
|
44
|
+
inputSchema: runHdcShellInputSchema,
|
|
45
|
+
toArgs (input, context) {
|
|
46
|
+
context.signal.throwIfAborted();
|
|
47
|
+
if (/^\s*hdc(?:\s|$)/i.test(input.command)) throw new TypeError('command must not include an hdc or hdc shell prefix.');
|
|
48
|
+
return [
|
|
49
|
+
input.command
|
|
50
|
+
];
|
|
51
|
+
},
|
|
52
|
+
toResult (stdout) {
|
|
53
|
+
if ('string' != typeof stdout) throw new TypeError('runHdcShell() must return stdout as a string.');
|
|
54
|
+
return {
|
|
55
|
+
summary: `Executed HDC shell command (${stdout.length} stdout characters)`,
|
|
56
|
+
data: {
|
|
57
|
+
stdout
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const backNode = defineHarmonyAgentNode({
|
|
63
|
+
method: 'back',
|
|
64
|
+
description: 'Trigger the Harmony system back operation.',
|
|
65
|
+
stringInputKey: false,
|
|
66
|
+
inputSchema: emptyInputSchema,
|
|
67
|
+
toArgs: ()=>[],
|
|
68
|
+
toResult: ()=>({
|
|
69
|
+
summary: 'Triggered Harmony back'
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
const homeNode = defineHarmonyAgentNode({
|
|
73
|
+
method: 'home',
|
|
74
|
+
description: 'Trigger the Harmony system home operation.',
|
|
75
|
+
stringInputKey: false,
|
|
76
|
+
inputSchema: emptyInputSchema,
|
|
77
|
+
toArgs: ()=>[],
|
|
78
|
+
toResult: ()=>({
|
|
79
|
+
summary: 'Triggered Harmony home'
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
const recentAppsNode = defineHarmonyAgentNode({
|
|
83
|
+
method: 'recentApps',
|
|
84
|
+
description: 'Trigger the Harmony system recent apps operation.',
|
|
85
|
+
stringInputKey: false,
|
|
86
|
+
inputSchema: emptyInputSchema,
|
|
87
|
+
toArgs: ()=>[],
|
|
88
|
+
toResult: ()=>({
|
|
89
|
+
summary: 'Triggered Harmony recentApps'
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
const harmonyAgentTestRunnerNodeDefinitions = [
|
|
93
|
+
launchNode,
|
|
94
|
+
terminateNode,
|
|
95
|
+
runHdcShellNode,
|
|
96
|
+
backNode,
|
|
97
|
+
homeNode,
|
|
98
|
+
recentAppsNode
|
|
99
|
+
];
|
|
100
|
+
export { harmonyAgentTestRunnerNodeDefinitions, launchInputSchema, runHdcShellInputSchema, terminateInputSchema };
|