@midscene/harmony 1.9.7 → 1.9.8-beta-20260618014851.0

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/cli.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { createReportCliCommands, z } from "@midscene/core";
2
2
  import { reportCLIError, runToolsCLI } from "@midscene/shared/cli";
3
+ import { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/agent-tools/agent-behavior-init-args";
4
+ import { BaseMidsceneTools } from "@midscene/shared/agent-tools/base-tools";
3
5
  import { getDebug } from "@midscene/shared/logger";
4
- import { BaseMidsceneTools } from "@midscene/shared/mcp/base-tools";
5
6
  import { Agent } from "@midscene/core/agent";
6
7
  import { mergeAndNormalizeAppNameMapping, normalizeForComparison, repeat } from "@midscene/shared/utils";
7
8
  import node_assert from "node:assert";
@@ -975,7 +976,7 @@ async function agentFromHdcDevice(deviceId, opts) {
975
976
  await device.connect();
976
977
  return new HarmonyAgent(device, opts);
977
978
  }
978
- function mcp_tools_define_property(obj, key, value) {
979
+ function agent_tools_define_property(obj, key, value) {
979
980
  if (key in obj) Object.defineProperty(obj, key, {
980
981
  value: value,
981
982
  enumerable: true,
@@ -985,7 +986,17 @@ function mcp_tools_define_property(obj, key, value) {
985
986
  else obj[key] = value;
986
987
  return obj;
987
988
  }
988
- const debug = getDebug('mcp:harmony-tools');
989
+ const debug = getDebug('agent-tools:harmony');
990
+ function adaptHarmonyInitArgs(extracted) {
991
+ if (!extracted) return;
992
+ const initArgs = {
993
+ ...'string' == typeof extracted.deviceId ? {
994
+ deviceId: extracted.deviceId
995
+ } : {},
996
+ ...extractAgentBehaviorInitArgs(extracted) ?? {}
997
+ };
998
+ return Object.keys(initArgs).length > 0 ? initArgs : void 0;
999
+ }
989
1000
  class HarmonyMidsceneTools extends BaseMidsceneTools {
990
1001
  getCliReportSessionName() {
991
1002
  return 'midscene-harmony';
@@ -993,8 +1004,10 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
993
1004
  createTemporaryDevice() {
994
1005
  return new HarmonyDevice('temp-for-action-space', {});
995
1006
  }
996
- async ensureAgent(deviceId) {
997
- if (this.agent && deviceId) {
1007
+ async ensureAgent(initArgs) {
1008
+ const deviceId = initArgs?.deviceId;
1009
+ const nextSignature = getAgentInitArgsSignature(initArgs);
1010
+ if (this.agent && shouldRebuildAgentForInitArgs(this.lastInitArgsSignature, nextSignature)) {
998
1011
  try {
999
1012
  await this.agent.destroy?.();
1000
1013
  } catch (error) {
@@ -1007,9 +1020,11 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
1007
1020
  const reportOptions = this.readCliReportAgentOptions();
1008
1021
  const agent = await agentFromHdcDevice(deviceId, {
1009
1022
  autoDismissKeyboard: false,
1023
+ ...extractAgentBehaviorInitArgs(initArgs) ?? {},
1010
1024
  ...reportOptions ?? {}
1011
1025
  });
1012
1026
  this.agent = agent;
1027
+ this.lastInitArgsSignature = nextSignature;
1013
1028
  return agent;
1014
1029
  }
1015
1030
  preparePlatformTools() {
@@ -1020,7 +1035,8 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
1020
1035
  schema: this.getAgentInitArgSchema(),
1021
1036
  cli: this.getAgentInitArgCliMetadata(),
1022
1037
  handler: async (args)=>{
1023
- const deviceId = this.extractAgentInitParam(args);
1038
+ const initArgs = this.extractAgentInitParam(args);
1039
+ const deviceId = initArgs?.deviceId;
1024
1040
  const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
1025
1041
  this.commitCliReportSession(reportSession);
1026
1042
  if (this.agent) {
@@ -1030,8 +1046,9 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
1030
1046
  debug('Failed to destroy agent during connect:', error);
1031
1047
  }
1032
1048
  this.agent = void 0;
1049
+ this.lastInitArgsSignature = void 0;
1033
1050
  }
1034
- const agent = await this.ensureAgent(deviceId);
1051
+ const agent = await this.ensureAgent(initArgs);
1035
1052
  const screenshot = await agent.page.screenshotBase64();
1036
1053
  return {
1037
1054
  content: [
@@ -1054,22 +1071,23 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
1054
1071
  ];
1055
1072
  }
1056
1073
  constructor(...args){
1057
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
1074
+ super(...args), agent_tools_define_property(this, "lastInitArgsSignature", void 0), agent_tools_define_property(this, "initArgSpec", {
1058
1075
  namespace: 'harmony',
1059
1076
  shape: {
1060
- deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
1077
+ deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
1078
+ ...agentBehaviorInitArgShape
1061
1079
  },
1062
1080
  cli: {
1063
1081
  preferBareKeys: true
1064
1082
  },
1065
- adapt: (extracted)=>extracted?.deviceId
1083
+ adapt: adaptHarmonyInitArgs
1066
1084
  });
1067
1085
  }
1068
1086
  }
1069
1087
  const tools = new HarmonyMidsceneTools();
1070
1088
  runToolsCLI(tools, 'midscene-harmony', {
1071
1089
  stripPrefix: 'harmony_',
1072
- version: "1.9.7",
1090
+ version: "1.9.8-beta-20260618014851.0",
1073
1091
  extraCommands: createReportCliCommands()
1074
1092
  }).catch((e)=>{
1075
1093
  process.exit(reportCLIError(e));
package/dist/es/index.mjs CHANGED
@@ -9,7 +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 { BaseMidsceneTools } from "@midscene/shared/mcp/base-tools";
12
+ import { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/agent-tools/agent-behavior-init-args";
13
+ import { BaseMidsceneTools } from "@midscene/shared/agent-tools/base-tools";
13
14
  import { overrideAIConfig } from "@midscene/shared/env";
14
15
  import node_path from "node:path";
15
16
  import { select as prompts_select } from "@inquirer/prompts";
@@ -980,7 +981,7 @@ async function agentFromHdcDevice(deviceId, opts) {
980
981
  await device.connect();
981
982
  return new HarmonyAgent(device, opts);
982
983
  }
983
- function mcp_tools_define_property(obj, key, value) {
984
+ function agent_tools_define_property(obj, key, value) {
984
985
  if (key in obj) Object.defineProperty(obj, key, {
985
986
  value: value,
986
987
  enumerable: true,
@@ -990,7 +991,17 @@ function mcp_tools_define_property(obj, key, value) {
990
991
  else obj[key] = value;
991
992
  return obj;
992
993
  }
993
- const debug = getDebug('mcp:harmony-tools');
994
+ const debug = getDebug('agent-tools:harmony');
995
+ function adaptHarmonyInitArgs(extracted) {
996
+ if (!extracted) return;
997
+ const initArgs = {
998
+ ...'string' == typeof extracted.deviceId ? {
999
+ deviceId: extracted.deviceId
1000
+ } : {},
1001
+ ...extractAgentBehaviorInitArgs(extracted) ?? {}
1002
+ };
1003
+ return Object.keys(initArgs).length > 0 ? initArgs : void 0;
1004
+ }
994
1005
  class HarmonyMidsceneTools extends BaseMidsceneTools {
995
1006
  getCliReportSessionName() {
996
1007
  return 'midscene-harmony';
@@ -998,8 +1009,10 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
998
1009
  createTemporaryDevice() {
999
1010
  return new HarmonyDevice('temp-for-action-space', {});
1000
1011
  }
1001
- async ensureAgent(deviceId) {
1002
- if (this.agent && deviceId) {
1012
+ async ensureAgent(initArgs) {
1013
+ const deviceId = initArgs?.deviceId;
1014
+ const nextSignature = getAgentInitArgsSignature(initArgs);
1015
+ if (this.agent && shouldRebuildAgentForInitArgs(this.lastInitArgsSignature, nextSignature)) {
1003
1016
  try {
1004
1017
  await this.agent.destroy?.();
1005
1018
  } catch (error) {
@@ -1012,9 +1025,11 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
1012
1025
  const reportOptions = this.readCliReportAgentOptions();
1013
1026
  const agent = await agentFromHdcDevice(deviceId, {
1014
1027
  autoDismissKeyboard: false,
1028
+ ...extractAgentBehaviorInitArgs(initArgs) ?? {},
1015
1029
  ...reportOptions ?? {}
1016
1030
  });
1017
1031
  this.agent = agent;
1032
+ this.lastInitArgsSignature = nextSignature;
1018
1033
  return agent;
1019
1034
  }
1020
1035
  preparePlatformTools() {
@@ -1025,7 +1040,8 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
1025
1040
  schema: this.getAgentInitArgSchema(),
1026
1041
  cli: this.getAgentInitArgCliMetadata(),
1027
1042
  handler: async (args)=>{
1028
- const deviceId = this.extractAgentInitParam(args);
1043
+ const initArgs = this.extractAgentInitParam(args);
1044
+ const deviceId = initArgs?.deviceId;
1029
1045
  const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
1030
1046
  this.commitCliReportSession(reportSession);
1031
1047
  if (this.agent) {
@@ -1035,8 +1051,9 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
1035
1051
  debug('Failed to destroy agent during connect:', error);
1036
1052
  }
1037
1053
  this.agent = void 0;
1054
+ this.lastInitArgsSignature = void 0;
1038
1055
  }
1039
- const agent = await this.ensureAgent(deviceId);
1056
+ const agent = await this.ensureAgent(initArgs);
1040
1057
  const screenshot = await agent.page.screenshotBase64();
1041
1058
  return {
1042
1059
  content: [
@@ -1059,15 +1076,16 @@ class HarmonyMidsceneTools extends BaseMidsceneTools {
1059
1076
  ];
1060
1077
  }
1061
1078
  constructor(...args){
1062
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
1079
+ super(...args), agent_tools_define_property(this, "lastInitArgsSignature", void 0), agent_tools_define_property(this, "initArgSpec", {
1063
1080
  namespace: 'harmony',
1064
1081
  shape: {
1065
- deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
1082
+ deviceId: z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
1083
+ ...agentBehaviorInitArgShape
1066
1084
  },
1067
1085
  cli: {
1068
1086
  preferBareKeys: true
1069
1087
  },
1070
- adapt: (extracted)=>extracted?.deviceId
1088
+ adapt: adaptHarmonyInitArgs
1071
1089
  });
1072
1090
  }
1073
1091
  }
package/dist/lib/cli.js CHANGED
@@ -23,8 +23,9 @@ var __webpack_require__ = {};
23
23
  var __webpack_exports__ = {};
24
24
  const core_namespaceObject = require("@midscene/core");
25
25
  const cli_namespaceObject = require("@midscene/shared/cli");
26
+ const agent_behavior_init_args_namespaceObject = require("@midscene/shared/agent-tools/agent-behavior-init-args");
27
+ const base_tools_namespaceObject = require("@midscene/shared/agent-tools/base-tools");
26
28
  const logger_namespaceObject = require("@midscene/shared/logger");
27
- const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
28
29
  const agent_namespaceObject = require("@midscene/core/agent");
29
30
  const utils_namespaceObject = require("@midscene/shared/utils");
30
31
  const defaultAppNameMapping = {
@@ -1000,7 +1001,7 @@ async function agentFromHdcDevice(deviceId, opts) {
1000
1001
  await device.connect();
1001
1002
  return new HarmonyAgent(device, opts);
1002
1003
  }
1003
- function mcp_tools_define_property(obj, key, value) {
1004
+ function agent_tools_define_property(obj, key, value) {
1004
1005
  if (key in obj) Object.defineProperty(obj, key, {
1005
1006
  value: value,
1006
1007
  enumerable: true,
@@ -1010,7 +1011,17 @@ function mcp_tools_define_property(obj, key, value) {
1010
1011
  else obj[key] = value;
1011
1012
  return obj;
1012
1013
  }
1013
- const debug = (0, logger_namespaceObject.getDebug)('mcp:harmony-tools');
1014
+ const debug = (0, logger_namespaceObject.getDebug)('agent-tools:harmony');
1015
+ function adaptHarmonyInitArgs(extracted) {
1016
+ if (!extracted) return;
1017
+ const initArgs = {
1018
+ ...'string' == typeof extracted.deviceId ? {
1019
+ deviceId: extracted.deviceId
1020
+ } : {},
1021
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
1022
+ };
1023
+ return Object.keys(initArgs).length > 0 ? initArgs : void 0;
1024
+ }
1014
1025
  class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools {
1015
1026
  getCliReportSessionName() {
1016
1027
  return 'midscene-harmony';
@@ -1018,8 +1029,10 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1018
1029
  createTemporaryDevice() {
1019
1030
  return new HarmonyDevice('temp-for-action-space', {});
1020
1031
  }
1021
- async ensureAgent(deviceId) {
1022
- if (this.agent && deviceId) {
1032
+ async ensureAgent(initArgs) {
1033
+ const deviceId = initArgs?.deviceId;
1034
+ const nextSignature = (0, agent_behavior_init_args_namespaceObject.getAgentInitArgsSignature)(initArgs);
1035
+ if (this.agent && (0, agent_behavior_init_args_namespaceObject.shouldRebuildAgentForInitArgs)(this.lastInitArgsSignature, nextSignature)) {
1023
1036
  try {
1024
1037
  await this.agent.destroy?.();
1025
1038
  } catch (error) {
@@ -1032,9 +1045,11 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1032
1045
  const reportOptions = this.readCliReportAgentOptions();
1033
1046
  const agent = await agentFromHdcDevice(deviceId, {
1034
1047
  autoDismissKeyboard: false,
1048
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(initArgs) ?? {},
1035
1049
  ...reportOptions ?? {}
1036
1050
  });
1037
1051
  this.agent = agent;
1052
+ this.lastInitArgsSignature = nextSignature;
1038
1053
  return agent;
1039
1054
  }
1040
1055
  preparePlatformTools() {
@@ -1045,7 +1060,8 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1045
1060
  schema: this.getAgentInitArgSchema(),
1046
1061
  cli: this.getAgentInitArgCliMetadata(),
1047
1062
  handler: async (args)=>{
1048
- const deviceId = this.extractAgentInitParam(args);
1063
+ const initArgs = this.extractAgentInitParam(args);
1064
+ const deviceId = initArgs?.deviceId;
1049
1065
  const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
1050
1066
  this.commitCliReportSession(reportSession);
1051
1067
  if (this.agent) {
@@ -1055,8 +1071,9 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1055
1071
  debug('Failed to destroy agent during connect:', error);
1056
1072
  }
1057
1073
  this.agent = void 0;
1074
+ this.lastInitArgsSignature = void 0;
1058
1075
  }
1059
- const agent = await this.ensureAgent(deviceId);
1076
+ const agent = await this.ensureAgent(initArgs);
1060
1077
  const screenshot = await agent.page.screenshotBase64();
1061
1078
  return {
1062
1079
  content: [
@@ -1079,22 +1096,23 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1079
1096
  ];
1080
1097
  }
1081
1098
  constructor(...args){
1082
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
1099
+ super(...args), agent_tools_define_property(this, "lastInitArgsSignature", void 0), agent_tools_define_property(this, "initArgSpec", {
1083
1100
  namespace: 'harmony',
1084
1101
  shape: {
1085
- deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
1102
+ deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
1103
+ ...agent_behavior_init_args_namespaceObject.agentBehaviorInitArgShape
1086
1104
  },
1087
1105
  cli: {
1088
1106
  preferBareKeys: true
1089
1107
  },
1090
- adapt: (extracted)=>extracted?.deviceId
1108
+ adapt: adaptHarmonyInitArgs
1091
1109
  });
1092
1110
  }
1093
1111
  }
1094
1112
  const tools = new HarmonyMidsceneTools();
1095
1113
  (0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-harmony', {
1096
1114
  stripPrefix: 'harmony_',
1097
- version: "1.9.7",
1115
+ version: "1.9.8-beta-20260618014851.0",
1098
1116
  extraCommands: (0, core_namespaceObject.createReportCliCommands)()
1099
1117
  }).catch((e)=>{
1100
1118
  process.exit((0, cli_namespaceObject.reportCLIError)(e));
package/dist/lib/index.js CHANGED
@@ -1018,8 +1018,9 @@ async function agentFromHdcDevice(deviceId, opts) {
1018
1018
  await device.connect();
1019
1019
  return new HarmonyAgent(device, opts);
1020
1020
  }
1021
- const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
1022
- function mcp_tools_define_property(obj, key, value) {
1021
+ const agent_behavior_init_args_namespaceObject = require("@midscene/shared/agent-tools/agent-behavior-init-args");
1022
+ const base_tools_namespaceObject = require("@midscene/shared/agent-tools/base-tools");
1023
+ function agent_tools_define_property(obj, key, value) {
1023
1024
  if (key in obj) Object.defineProperty(obj, key, {
1024
1025
  value: value,
1025
1026
  enumerable: true,
@@ -1029,7 +1030,17 @@ function mcp_tools_define_property(obj, key, value) {
1029
1030
  else obj[key] = value;
1030
1031
  return obj;
1031
1032
  }
1032
- const debug = (0, logger_namespaceObject.getDebug)('mcp:harmony-tools');
1033
+ const debug = (0, logger_namespaceObject.getDebug)('agent-tools:harmony');
1034
+ function adaptHarmonyInitArgs(extracted) {
1035
+ if (!extracted) return;
1036
+ const initArgs = {
1037
+ ...'string' == typeof extracted.deviceId ? {
1038
+ deviceId: extracted.deviceId
1039
+ } : {},
1040
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
1041
+ };
1042
+ return Object.keys(initArgs).length > 0 ? initArgs : void 0;
1043
+ }
1033
1044
  class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools {
1034
1045
  getCliReportSessionName() {
1035
1046
  return 'midscene-harmony';
@@ -1037,8 +1048,10 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1037
1048
  createTemporaryDevice() {
1038
1049
  return new HarmonyDevice('temp-for-action-space', {});
1039
1050
  }
1040
- async ensureAgent(deviceId) {
1041
- if (this.agent && deviceId) {
1051
+ async ensureAgent(initArgs) {
1052
+ const deviceId = initArgs?.deviceId;
1053
+ const nextSignature = (0, agent_behavior_init_args_namespaceObject.getAgentInitArgsSignature)(initArgs);
1054
+ if (this.agent && (0, agent_behavior_init_args_namespaceObject.shouldRebuildAgentForInitArgs)(this.lastInitArgsSignature, nextSignature)) {
1042
1055
  try {
1043
1056
  await this.agent.destroy?.();
1044
1057
  } catch (error) {
@@ -1051,9 +1064,11 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1051
1064
  const reportOptions = this.readCliReportAgentOptions();
1052
1065
  const agent = await agentFromHdcDevice(deviceId, {
1053
1066
  autoDismissKeyboard: false,
1067
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(initArgs) ?? {},
1054
1068
  ...reportOptions ?? {}
1055
1069
  });
1056
1070
  this.agent = agent;
1071
+ this.lastInitArgsSignature = nextSignature;
1057
1072
  return agent;
1058
1073
  }
1059
1074
  preparePlatformTools() {
@@ -1064,7 +1079,8 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1064
1079
  schema: this.getAgentInitArgSchema(),
1065
1080
  cli: this.getAgentInitArgCliMetadata(),
1066
1081
  handler: async (args)=>{
1067
- const deviceId = this.extractAgentInitParam(args);
1082
+ const initArgs = this.extractAgentInitParam(args);
1083
+ const deviceId = initArgs?.deviceId;
1068
1084
  const reportSession = this.createNewCliReportSession(deviceId ?? 'auto');
1069
1085
  this.commitCliReportSession(reportSession);
1070
1086
  if (this.agent) {
@@ -1074,8 +1090,9 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1074
1090
  debug('Failed to destroy agent during connect:', error);
1075
1091
  }
1076
1092
  this.agent = void 0;
1093
+ this.lastInitArgsSignature = void 0;
1077
1094
  }
1078
- const agent = await this.ensureAgent(deviceId);
1095
+ const agent = await this.ensureAgent(initArgs);
1079
1096
  const screenshot = await agent.page.screenshotBase64();
1080
1097
  return {
1081
1098
  content: [
@@ -1098,15 +1115,16 @@ class HarmonyMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1098
1115
  ];
1099
1116
  }
1100
1117
  constructor(...args){
1101
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
1118
+ super(...args), agent_tools_define_property(this, "lastInitArgsSignature", void 0), agent_tools_define_property(this, "initArgSpec", {
1102
1119
  namespace: 'harmony',
1103
1120
  shape: {
1104
- deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)')
1121
+ deviceId: core_namespaceObject.z.string().optional().describe('HarmonyOS device ID (from hdc list targets)'),
1122
+ ...agent_behavior_init_args_namespaceObject.agentBehaviorInitArgShape
1105
1123
  },
1106
1124
  cli: {
1107
1125
  preferBareKeys: true
1108
1126
  },
1109
- adapt: (extracted)=>extracted?.deviceId
1127
+ adapt: adaptHarmonyInitArgs
1110
1128
  });
1111
1129
  }
1112
1130
  }
@@ -2,20 +2,21 @@ import { AbstractInterface } from '@midscene/core/device';
2
2
  import type { ActionParam } from '@midscene/core';
3
3
  import type { ActionReturn } from '@midscene/core';
4
4
  import { Agent } from '@midscene/core/agent';
5
+ import { AgentBehaviorInitArgs } from '@midscene/shared/agent-tools/agent-behavior-init-args';
5
6
  import { AgentOpt } from '@midscene/core/agent';
6
- import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
7
+ import { BaseMidsceneTools } from '@midscene/shared/agent-tools/base-tools';
7
8
  import { DeviceAction } from '@midscene/core';
8
9
  import type { ElementInfo } from '@midscene/shared/extractor';
9
10
  import { HarmonyDeviceInputOpt as HarmonyDeviceInputOpt_2 } from '@midscene/core/device';
10
11
  import { HarmonyDeviceOpt as HarmonyDeviceOpt_2 } from '@midscene/core/device';
11
- import { InitArgSpec } from '@midscene/shared/mcp/base-tools';
12
+ import { InitArgSpec } from '@midscene/shared/agent-tools/base-tools';
12
13
  import { InterfaceType } from '@midscene/core';
13
14
  import { MobileInputPrimitives } from '@midscene/core/device';
14
15
  import { overrideAIConfig } from '@midscene/shared/env';
15
16
  import { PlaygroundPlatformDescriptor } from '@midscene/playground';
16
17
  import { Point } from '@midscene/core';
17
18
  import { Size } from '@midscene/core';
18
- import type { ToolDefinition } from '@midscene/shared/mcp/types';
19
+ import type { ToolDefinition } from '@midscene/shared/agent-tools/types';
19
20
 
20
21
  declare type ActionArgs<T extends DeviceAction> = [ActionParam<T>] extends [undefined] ? [] : [ActionParam<T>];
21
22
 
@@ -138,11 +139,16 @@ declare type HarmonyDeviceInputOpt = HarmonyDeviceInputOpt_2 & {
138
139
 
139
140
  declare type HarmonyDeviceOpt = HarmonyDeviceOpt_2 & HarmonyDeviceInputOpt;
140
141
 
141
- export declare class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent, string> {
142
+ declare type HarmonyInitArgs = AgentBehaviorInitArgs & {
143
+ deviceId?: string;
144
+ };
145
+
146
+ export declare class HarmonyMidsceneTools extends BaseMidsceneTools<HarmonyAgent, HarmonyInitArgs> {
147
+ private lastInitArgsSignature?;
142
148
  protected getCliReportSessionName(): string;
143
- protected readonly initArgSpec: InitArgSpec<string>;
149
+ protected readonly initArgSpec: InitArgSpec<HarmonyInitArgs>;
144
150
  protected createTemporaryDevice(): HarmonyDevice;
145
- protected ensureAgent(deviceId?: string): Promise<HarmonyAgent>;
151
+ protected ensureAgent(initArgs?: HarmonyInitArgs): Promise<HarmonyAgent>;
146
152
  protected preparePlatformTools(): ToolDefinition[];
147
153
  }
148
154
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/harmony",
3
- "version": "1.9.7",
3
+ "version": "1.9.8-beta-20260618014851.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/midscene.git",
@@ -31,11 +31,6 @@
31
31
  "import": "./dist/es/index.mjs",
32
32
  "require": "./dist/lib/index.js"
33
33
  },
34
- "./mcp-server": {
35
- "types": "./dist/types/mcp-server.d.ts",
36
- "import": "./dist/es/mcp-server.mjs",
37
- "require": "./dist/lib/mcp-server.js"
38
- },
39
34
  "./bin": {
40
35
  "types": "./dist/types/bin.d.ts",
41
36
  "import": "./dist/es/bin.mjs",
@@ -46,9 +41,9 @@
46
41
  "dependencies": {
47
42
  "@inquirer/prompts": "^7.8.6",
48
43
  "open": "10.1.0",
49
- "@midscene/core": "1.9.7",
50
- "@midscene/playground": "1.9.7",
51
- "@midscene/shared": "1.9.7"
44
+ "@midscene/playground": "1.9.8-beta-20260618014851.0",
45
+ "@midscene/core": "1.9.8-beta-20260618014851.0",
46
+ "@midscene/shared": "1.9.8-beta-20260618014851.0"
52
47
  },
53
48
  "devDependencies": {
54
49
  "@rslib/core": "^0.18.3",
package/static/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.7b1abe58.js"></script><script defer src="/static/js/905.8d12588e.js"></script><script defer src="/static/js/index.50e06ed5.js"></script><link href="/static/css/index.1293237f.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
1
+ <!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.7b1abe58.js"></script><script defer src="/static/js/905.8d12588e.js"></script><script defer src="/static/js/index.b4cb2178.js"></script><link href="/static/css/index.1293237f.css" rel="stylesheet"></head><body><div id="root"></div></body></html>