@midscene/computer 1.9.7 → 1.9.8-beta-20260618091332.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,6 +1,7 @@
1
1
  import { createReportCliCommands, z } from "@midscene/core";
2
2
  import { reportCLIError, runToolsCLI } from "@midscene/shared/cli";
3
3
  import { getDebug } from "@midscene/shared/logger";
4
+ import { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/mcp/agent-behavior-init-args";
4
5
  import { BaseMidsceneTools } from "@midscene/shared/mcp/base-tools";
5
6
  import { Agent } from "@midscene/core/agent";
6
7
  import { execFileSync, execSync, spawn, spawnSync } from "node:child_process";
@@ -694,7 +695,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
694
695
  }
695
696
  async healthCheck() {
696
697
  console.log('[HealthCheck] Starting health check...');
697
- console.log("[HealthCheck] @midscene/computer v1.9.7");
698
+ console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618091332.0");
698
699
  console.log('[HealthCheck] Taking screenshot...');
699
700
  const screenshotTimeout = 15000;
700
701
  let timeoutId;
@@ -1903,7 +1904,8 @@ const computerInitArgShape = {
1903
1904
  ignoreCertificate: z.boolean().optional().describe('Skip TLS certificate validation. Requires host.'),
1904
1905
  securityProtocol: z["enum"](RDP_SECURITY_PROTOCOLS).optional().describe('RDP security protocol negotiation (default auto). Requires host.'),
1905
1906
  desktopWidth: z.number().optional().describe('Remote desktop width in pixels. Requires host.'),
1906
- desktopHeight: z.number().optional().describe('Remote desktop height in pixels. Requires host.')
1907
+ desktopHeight: z.number().optional().describe('Remote desktop height in pixels. Requires host.'),
1908
+ ...agentBehaviorInitArgShape
1907
1909
  };
1908
1910
  function adaptComputerInitArgs(extracted) {
1909
1911
  if (!extracted || 0 === Object.keys(extracted).length) return;
@@ -1919,14 +1921,10 @@ function adaptComputerInitArgs(extracted) {
1919
1921
  return {
1920
1922
  mode: 'local',
1921
1923
  displayId: extracted.displayId,
1922
- headless: extracted.headless
1924
+ headless: extracted.headless,
1925
+ ...extractAgentBehaviorInitArgs(extracted) ?? {}
1923
1926
  };
1924
1927
  }
1925
- function shouldRetargetAgent(opts) {
1926
- if (!opts) return false;
1927
- if ('rdp' === opts.mode) return true;
1928
- return void 0 !== opts.displayId || void 0 !== opts.headless;
1929
- }
1930
1928
  function describeConnectTarget(opts) {
1931
1929
  if (opts?.mode === 'rdp') {
1932
1930
  const target = opts.port ? formatRdpServerAddress(opts.host, opts.port) : formatRdpHost(opts.host);
@@ -1949,7 +1947,8 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
1949
1947
  return new ComputerDevice({});
1950
1948
  }
1951
1949
  async ensureAgent(opts) {
1952
- if (this.agent && shouldRetargetAgent(opts)) {
1950
+ const nextSignature = getAgentInitArgsSignature(opts);
1951
+ if (this.agent && shouldRebuildAgentForInitArgs(this.lastInitArgsSignature, nextSignature)) {
1953
1952
  try {
1954
1953
  await this.agent.destroy?.();
1955
1954
  } catch (error) {
@@ -1967,6 +1966,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
1967
1966
  ...reportOptions ?? {}
1968
1967
  });
1969
1968
  this.agent = agent;
1969
+ this.lastInitArgsSignature = nextSignature;
1970
1970
  return agent;
1971
1971
  }
1972
1972
  const displayId = opts?.mode === 'local' ? opts.displayId : void 0;
@@ -1979,10 +1979,12 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
1979
1979
  ...void 0 !== headless ? {
1980
1980
  headless
1981
1981
  } : {},
1982
+ ...extractAgentBehaviorInitArgs(opts) ?? {},
1982
1983
  ...reportOptions ?? {}
1983
1984
  };
1984
1985
  const agent = await agentFromComputer(Object.keys(agentOpts).length > 0 ? agentOpts : void 0);
1985
1986
  this.agent = agent;
1987
+ this.lastInitArgsSignature = nextSignature;
1986
1988
  return agent;
1987
1989
  }
1988
1990
  preparePlatformTools() {
@@ -2003,6 +2005,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2003
2005
  mcp_tools_debug('Failed to destroy agent during connect:', error);
2004
2006
  }
2005
2007
  this.agent = void 0;
2008
+ this.lastInitArgsSignature = void 0;
2006
2009
  }
2007
2010
  const agent = await this.ensureAgent(initArgs);
2008
2011
  const screenshot = await agent.interface.screenshotBase64();
@@ -2042,7 +2045,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2042
2045
  ];
2043
2046
  }
2044
2047
  constructor(...args){
2045
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
2048
+ super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
2046
2049
  namespace: 'computer',
2047
2050
  shape: computerInitArgShape,
2048
2051
  cli: {
@@ -2055,7 +2058,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2055
2058
  const tools = new ComputerMidsceneTools();
2056
2059
  runToolsCLI(tools, 'midscene-computer', {
2057
2060
  stripPrefix: 'computer_',
2058
- version: "1.9.7",
2061
+ version: "1.9.8-beta-20260618091332.0",
2059
2062
  extraCommands: createReportCliCommands()
2060
2063
  }).catch((e)=>{
2061
2064
  process.exit(reportCLIError(e));
package/dist/es/index.mjs CHANGED
@@ -13,6 +13,7 @@ import { Agent } from "@midscene/core/agent";
13
13
  import { once } from "node:events";
14
14
  import { createInterface } from "node:readline";
15
15
  import { z } from "@midscene/core";
16
+ import { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/mcp/agent-behavior-init-args";
16
17
  import { BaseMidsceneTools } from "@midscene/shared/mcp/base-tools";
17
18
  import { overrideAIConfig } from "@midscene/shared/env";
18
19
  function _define_property(obj, key, value) {
@@ -694,7 +695,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
694
695
  }
695
696
  async healthCheck() {
696
697
  console.log('[HealthCheck] Starting health check...');
697
- console.log("[HealthCheck] @midscene/computer v1.9.7");
698
+ console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618091332.0");
698
699
  console.log('[HealthCheck] Taking screenshot...');
699
700
  const screenshotTimeout = 15000;
700
701
  let timeoutId;
@@ -1946,7 +1947,8 @@ const computerInitArgShape = {
1946
1947
  ignoreCertificate: z.boolean().optional().describe('Skip TLS certificate validation. Requires host.'),
1947
1948
  securityProtocol: z["enum"](RDP_SECURITY_PROTOCOLS).optional().describe('RDP security protocol negotiation (default auto). Requires host.'),
1948
1949
  desktopWidth: z.number().optional().describe('Remote desktop width in pixels. Requires host.'),
1949
- desktopHeight: z.number().optional().describe('Remote desktop height in pixels. Requires host.')
1950
+ desktopHeight: z.number().optional().describe('Remote desktop height in pixels. Requires host.'),
1951
+ ...agentBehaviorInitArgShape
1950
1952
  };
1951
1953
  function adaptComputerInitArgs(extracted) {
1952
1954
  if (!extracted || 0 === Object.keys(extracted).length) return;
@@ -1962,14 +1964,10 @@ function adaptComputerInitArgs(extracted) {
1962
1964
  return {
1963
1965
  mode: 'local',
1964
1966
  displayId: extracted.displayId,
1965
- headless: extracted.headless
1967
+ headless: extracted.headless,
1968
+ ...extractAgentBehaviorInitArgs(extracted) ?? {}
1966
1969
  };
1967
1970
  }
1968
- function shouldRetargetAgent(opts) {
1969
- if (!opts) return false;
1970
- if ('rdp' === opts.mode) return true;
1971
- return void 0 !== opts.displayId || void 0 !== opts.headless;
1972
- }
1973
1971
  function describeConnectTarget(opts) {
1974
1972
  if (opts?.mode === 'rdp') {
1975
1973
  const target = opts.port ? formatRdpServerAddress(opts.host, opts.port) : formatRdpHost(opts.host);
@@ -1992,7 +1990,8 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
1992
1990
  return new ComputerDevice({});
1993
1991
  }
1994
1992
  async ensureAgent(opts) {
1995
- if (this.agent && shouldRetargetAgent(opts)) {
1993
+ const nextSignature = getAgentInitArgsSignature(opts);
1994
+ if (this.agent && shouldRebuildAgentForInitArgs(this.lastInitArgsSignature, nextSignature)) {
1996
1995
  try {
1997
1996
  await this.agent.destroy?.();
1998
1997
  } catch (error) {
@@ -2010,6 +2009,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2010
2009
  ...reportOptions ?? {}
2011
2010
  });
2012
2011
  this.agent = agent;
2012
+ this.lastInitArgsSignature = nextSignature;
2013
2013
  return agent;
2014
2014
  }
2015
2015
  const displayId = opts?.mode === 'local' ? opts.displayId : void 0;
@@ -2022,10 +2022,12 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2022
2022
  ...void 0 !== headless ? {
2023
2023
  headless
2024
2024
  } : {},
2025
+ ...extractAgentBehaviorInitArgs(opts) ?? {},
2025
2026
  ...reportOptions ?? {}
2026
2027
  };
2027
2028
  const agent = await agentFromComputer(Object.keys(agentOpts).length > 0 ? agentOpts : void 0);
2028
2029
  this.agent = agent;
2030
+ this.lastInitArgsSignature = nextSignature;
2029
2031
  return agent;
2030
2032
  }
2031
2033
  preparePlatformTools() {
@@ -2046,6 +2048,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2046
2048
  mcp_tools_debug('Failed to destroy agent during connect:', error);
2047
2049
  }
2048
2050
  this.agent = void 0;
2051
+ this.lastInitArgsSignature = void 0;
2049
2052
  }
2050
2053
  const agent = await this.ensureAgent(initArgs);
2051
2054
  const screenshot = await agent.interface.screenshotBase64();
@@ -2085,7 +2088,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2085
2088
  ];
2086
2089
  }
2087
2090
  constructor(...args){
2088
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
2091
+ super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
2089
2092
  namespace: 'computer',
2090
2093
  shape: computerInitArgShape,
2091
2094
  cli: {
@@ -2096,7 +2099,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2096
2099
  }
2097
2100
  }
2098
2101
  function version() {
2099
- const currentVersion = "1.9.7";
2102
+ const currentVersion = "1.9.8-beta-20260618091332.0";
2100
2103
  console.log(`@midscene/computer v${currentVersion}`);
2101
2104
  return currentVersion;
2102
2105
  }
@@ -14,6 +14,7 @@ import node_assert from "node:assert";
14
14
  import { once } from "node:events";
15
15
  import { createInterface } from "node:readline";
16
16
  import { z } from "@midscene/core";
17
+ import { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/mcp/agent-behavior-init-args";
17
18
  import { BaseMidsceneTools } from "@midscene/shared/mcp/base-tools";
18
19
  function _define_property(obj, key, value) {
19
20
  if (key in obj) Object.defineProperty(obj, key, {
@@ -694,7 +695,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
694
695
  }
695
696
  async healthCheck() {
696
697
  console.log('[HealthCheck] Starting health check...');
697
- console.log("[HealthCheck] @midscene/computer v1.9.7");
698
+ console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618091332.0");
698
699
  console.log('[HealthCheck] Taking screenshot...');
699
700
  const screenshotTimeout = 15000;
700
701
  let timeoutId;
@@ -1903,7 +1904,8 @@ const computerInitArgShape = {
1903
1904
  ignoreCertificate: z.boolean().optional().describe('Skip TLS certificate validation. Requires host.'),
1904
1905
  securityProtocol: z["enum"](RDP_SECURITY_PROTOCOLS).optional().describe('RDP security protocol negotiation (default auto). Requires host.'),
1905
1906
  desktopWidth: z.number().optional().describe('Remote desktop width in pixels. Requires host.'),
1906
- desktopHeight: z.number().optional().describe('Remote desktop height in pixels. Requires host.')
1907
+ desktopHeight: z.number().optional().describe('Remote desktop height in pixels. Requires host.'),
1908
+ ...agentBehaviorInitArgShape
1907
1909
  };
1908
1910
  function adaptComputerInitArgs(extracted) {
1909
1911
  if (!extracted || 0 === Object.keys(extracted).length) return;
@@ -1919,14 +1921,10 @@ function adaptComputerInitArgs(extracted) {
1919
1921
  return {
1920
1922
  mode: 'local',
1921
1923
  displayId: extracted.displayId,
1922
- headless: extracted.headless
1924
+ headless: extracted.headless,
1925
+ ...extractAgentBehaviorInitArgs(extracted) ?? {}
1923
1926
  };
1924
1927
  }
1925
- function shouldRetargetAgent(opts) {
1926
- if (!opts) return false;
1927
- if ('rdp' === opts.mode) return true;
1928
- return void 0 !== opts.displayId || void 0 !== opts.headless;
1929
- }
1930
1928
  function describeConnectTarget(opts) {
1931
1929
  if (opts?.mode === 'rdp') {
1932
1930
  const target = opts.port ? formatRdpServerAddress(opts.host, opts.port) : formatRdpHost(opts.host);
@@ -1949,7 +1947,8 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
1949
1947
  return new ComputerDevice({});
1950
1948
  }
1951
1949
  async ensureAgent(opts) {
1952
- if (this.agent && shouldRetargetAgent(opts)) {
1950
+ const nextSignature = getAgentInitArgsSignature(opts);
1951
+ if (this.agent && shouldRebuildAgentForInitArgs(this.lastInitArgsSignature, nextSignature)) {
1953
1952
  try {
1954
1953
  await this.agent.destroy?.();
1955
1954
  } catch (error) {
@@ -1967,6 +1966,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
1967
1966
  ...reportOptions ?? {}
1968
1967
  });
1969
1968
  this.agent = agent;
1969
+ this.lastInitArgsSignature = nextSignature;
1970
1970
  return agent;
1971
1971
  }
1972
1972
  const displayId = opts?.mode === 'local' ? opts.displayId : void 0;
@@ -1979,10 +1979,12 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
1979
1979
  ...void 0 !== headless ? {
1980
1980
  headless
1981
1981
  } : {},
1982
+ ...extractAgentBehaviorInitArgs(opts) ?? {},
1982
1983
  ...reportOptions ?? {}
1983
1984
  };
1984
1985
  const agent = await agentFromComputer(Object.keys(agentOpts).length > 0 ? agentOpts : void 0);
1985
1986
  this.agent = agent;
1987
+ this.lastInitArgsSignature = nextSignature;
1986
1988
  return agent;
1987
1989
  }
1988
1990
  preparePlatformTools() {
@@ -2003,6 +2005,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2003
2005
  mcp_tools_debug('Failed to destroy agent during connect:', error);
2004
2006
  }
2005
2007
  this.agent = void 0;
2008
+ this.lastInitArgsSignature = void 0;
2006
2009
  }
2007
2010
  const agent = await this.ensureAgent(initArgs);
2008
2011
  const screenshot = await agent.interface.screenshotBase64();
@@ -2042,7 +2045,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
2042
2045
  ];
2043
2046
  }
2044
2047
  constructor(...args){
2045
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
2048
+ super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
2046
2049
  namespace: 'computer',
2047
2050
  shape: computerInitArgShape,
2048
2051
  cli: {
@@ -2059,7 +2062,7 @@ class ComputerMCPServer extends BaseMCPServer {
2059
2062
  constructor(toolsManager){
2060
2063
  super({
2061
2064
  name: '@midscene/computer-mcp',
2062
- version: "1.9.7",
2065
+ version: "1.9.8-beta-20260618091332.0",
2063
2066
  description: 'Control the computer desktop using natural language commands'
2064
2067
  }, toolsManager);
2065
2068
  }
package/dist/lib/cli.js CHANGED
@@ -27,6 +27,7 @@ var __webpack_exports__ = {};
27
27
  const core_namespaceObject = require("@midscene/core");
28
28
  const cli_namespaceObject = require("@midscene/shared/cli");
29
29
  const logger_namespaceObject = require("@midscene/shared/logger");
30
+ const agent_behavior_init_args_namespaceObject = require("@midscene/shared/mcp/agent-behavior-init-args");
30
31
  const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
31
32
  const agent_namespaceObject = require("@midscene/core/agent");
32
33
  const external_node_child_process_namespaceObject = require("node:child_process");
@@ -720,7 +721,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
720
721
  }
721
722
  async healthCheck() {
722
723
  console.log('[HealthCheck] Starting health check...');
723
- console.log("[HealthCheck] @midscene/computer v1.9.7");
724
+ console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618091332.0");
724
725
  console.log('[HealthCheck] Taking screenshot...');
725
726
  const screenshotTimeout = 15000;
726
727
  let timeoutId;
@@ -1930,7 +1931,8 @@ const computerInitArgShape = {
1930
1931
  ignoreCertificate: core_namespaceObject.z.boolean().optional().describe('Skip TLS certificate validation. Requires host.'),
1931
1932
  securityProtocol: core_namespaceObject.z["enum"](RDP_SECURITY_PROTOCOLS).optional().describe('RDP security protocol negotiation (default auto). Requires host.'),
1932
1933
  desktopWidth: core_namespaceObject.z.number().optional().describe('Remote desktop width in pixels. Requires host.'),
1933
- desktopHeight: core_namespaceObject.z.number().optional().describe('Remote desktop height in pixels. Requires host.')
1934
+ desktopHeight: core_namespaceObject.z.number().optional().describe('Remote desktop height in pixels. Requires host.'),
1935
+ ...agent_behavior_init_args_namespaceObject.agentBehaviorInitArgShape
1934
1936
  };
1935
1937
  function adaptComputerInitArgs(extracted) {
1936
1938
  if (!extracted || 0 === Object.keys(extracted).length) return;
@@ -1946,14 +1948,10 @@ function adaptComputerInitArgs(extracted) {
1946
1948
  return {
1947
1949
  mode: 'local',
1948
1950
  displayId: extracted.displayId,
1949
- headless: extracted.headless
1951
+ headless: extracted.headless,
1952
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
1950
1953
  };
1951
1954
  }
1952
- function shouldRetargetAgent(opts) {
1953
- if (!opts) return false;
1954
- if ('rdp' === opts.mode) return true;
1955
- return void 0 !== opts.displayId || void 0 !== opts.headless;
1956
- }
1957
1955
  function describeConnectTarget(opts) {
1958
1956
  if (opts?.mode === 'rdp') {
1959
1957
  const target = opts.port ? formatRdpServerAddress(opts.host, opts.port) : formatRdpHost(opts.host);
@@ -1976,7 +1974,8 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1976
1974
  return new ComputerDevice({});
1977
1975
  }
1978
1976
  async ensureAgent(opts) {
1979
- if (this.agent && shouldRetargetAgent(opts)) {
1977
+ const nextSignature = (0, agent_behavior_init_args_namespaceObject.getAgentInitArgsSignature)(opts);
1978
+ if (this.agent && (0, agent_behavior_init_args_namespaceObject.shouldRebuildAgentForInitArgs)(this.lastInitArgsSignature, nextSignature)) {
1980
1979
  try {
1981
1980
  await this.agent.destroy?.();
1982
1981
  } catch (error) {
@@ -1994,6 +1993,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1994
1993
  ...reportOptions ?? {}
1995
1994
  });
1996
1995
  this.agent = agent;
1996
+ this.lastInitArgsSignature = nextSignature;
1997
1997
  return agent;
1998
1998
  }
1999
1999
  const displayId = opts?.mode === 'local' ? opts.displayId : void 0;
@@ -2006,10 +2006,12 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2006
2006
  ...void 0 !== headless ? {
2007
2007
  headless
2008
2008
  } : {},
2009
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(opts) ?? {},
2009
2010
  ...reportOptions ?? {}
2010
2011
  };
2011
2012
  const agent = await agentFromComputer(Object.keys(agentOpts).length > 0 ? agentOpts : void 0);
2012
2013
  this.agent = agent;
2014
+ this.lastInitArgsSignature = nextSignature;
2013
2015
  return agent;
2014
2016
  }
2015
2017
  preparePlatformTools() {
@@ -2030,6 +2032,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2030
2032
  mcp_tools_debug('Failed to destroy agent during connect:', error);
2031
2033
  }
2032
2034
  this.agent = void 0;
2035
+ this.lastInitArgsSignature = void 0;
2033
2036
  }
2034
2037
  const agent = await this.ensureAgent(initArgs);
2035
2038
  const screenshot = await agent.interface.screenshotBase64();
@@ -2069,7 +2072,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2069
2072
  ];
2070
2073
  }
2071
2074
  constructor(...args){
2072
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
2075
+ super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
2073
2076
  namespace: 'computer',
2074
2077
  shape: computerInitArgShape,
2075
2078
  cli: {
@@ -2082,7 +2085,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2082
2085
  const tools = new ComputerMidsceneTools();
2083
2086
  (0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-computer', {
2084
2087
  stripPrefix: 'computer_',
2085
- version: "1.9.7",
2088
+ version: "1.9.8-beta-20260618091332.0",
2086
2089
  extraCommands: (0, core_namespaceObject.createReportCliCommands)()
2087
2090
  }).catch((e)=>{
2088
2091
  process.exit((0, cli_namespaceObject.reportCLIError)(e));
package/dist/lib/index.js CHANGED
@@ -747,7 +747,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
747
747
  }
748
748
  async healthCheck() {
749
749
  console.log('[HealthCheck] Starting health check...');
750
- console.log("[HealthCheck] @midscene/computer v1.9.7");
750
+ console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618091332.0");
751
751
  console.log('[HealthCheck] Taking screenshot...');
752
752
  const screenshotTimeout = 15000;
753
753
  let timeoutId;
@@ -1972,6 +1972,7 @@ async function agentForRDPComputer(opts) {
1972
1972
  return new ComputerAgent(device, opts);
1973
1973
  }
1974
1974
  const core_namespaceObject = require("@midscene/core");
1975
+ const agent_behavior_init_args_namespaceObject = require("@midscene/shared/mcp/agent-behavior-init-args");
1975
1976
  const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
1976
1977
  function mcp_tools_define_property(obj, key, value) {
1977
1978
  if (key in obj) Object.defineProperty(obj, key, {
@@ -2003,7 +2004,8 @@ const computerInitArgShape = {
2003
2004
  ignoreCertificate: core_namespaceObject.z.boolean().optional().describe('Skip TLS certificate validation. Requires host.'),
2004
2005
  securityProtocol: core_namespaceObject.z["enum"](RDP_SECURITY_PROTOCOLS).optional().describe('RDP security protocol negotiation (default auto). Requires host.'),
2005
2006
  desktopWidth: core_namespaceObject.z.number().optional().describe('Remote desktop width in pixels. Requires host.'),
2006
- desktopHeight: core_namespaceObject.z.number().optional().describe('Remote desktop height in pixels. Requires host.')
2007
+ desktopHeight: core_namespaceObject.z.number().optional().describe('Remote desktop height in pixels. Requires host.'),
2008
+ ...agent_behavior_init_args_namespaceObject.agentBehaviorInitArgShape
2007
2009
  };
2008
2010
  function adaptComputerInitArgs(extracted) {
2009
2011
  if (!extracted || 0 === Object.keys(extracted).length) return;
@@ -2019,14 +2021,10 @@ function adaptComputerInitArgs(extracted) {
2019
2021
  return {
2020
2022
  mode: 'local',
2021
2023
  displayId: extracted.displayId,
2022
- headless: extracted.headless
2024
+ headless: extracted.headless,
2025
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
2023
2026
  };
2024
2027
  }
2025
- function shouldRetargetAgent(opts) {
2026
- if (!opts) return false;
2027
- if ('rdp' === opts.mode) return true;
2028
- return void 0 !== opts.displayId || void 0 !== opts.headless;
2029
- }
2030
2028
  function describeConnectTarget(opts) {
2031
2029
  if (opts?.mode === 'rdp') {
2032
2030
  const target = opts.port ? formatRdpServerAddress(opts.host, opts.port) : formatRdpHost(opts.host);
@@ -2049,7 +2047,8 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2049
2047
  return new ComputerDevice({});
2050
2048
  }
2051
2049
  async ensureAgent(opts) {
2052
- if (this.agent && shouldRetargetAgent(opts)) {
2050
+ const nextSignature = (0, agent_behavior_init_args_namespaceObject.getAgentInitArgsSignature)(opts);
2051
+ if (this.agent && (0, agent_behavior_init_args_namespaceObject.shouldRebuildAgentForInitArgs)(this.lastInitArgsSignature, nextSignature)) {
2053
2052
  try {
2054
2053
  await this.agent.destroy?.();
2055
2054
  } catch (error) {
@@ -2067,6 +2066,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2067
2066
  ...reportOptions ?? {}
2068
2067
  });
2069
2068
  this.agent = agent;
2069
+ this.lastInitArgsSignature = nextSignature;
2070
2070
  return agent;
2071
2071
  }
2072
2072
  const displayId = opts?.mode === 'local' ? opts.displayId : void 0;
@@ -2079,10 +2079,12 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2079
2079
  ...void 0 !== headless ? {
2080
2080
  headless
2081
2081
  } : {},
2082
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(opts) ?? {},
2082
2083
  ...reportOptions ?? {}
2083
2084
  };
2084
2085
  const agent = await agentFromComputer(Object.keys(agentOpts).length > 0 ? agentOpts : void 0);
2085
2086
  this.agent = agent;
2087
+ this.lastInitArgsSignature = nextSignature;
2086
2088
  return agent;
2087
2089
  }
2088
2090
  preparePlatformTools() {
@@ -2103,6 +2105,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2103
2105
  mcp_tools_debug('Failed to destroy agent during connect:', error);
2104
2106
  }
2105
2107
  this.agent = void 0;
2108
+ this.lastInitArgsSignature = void 0;
2106
2109
  }
2107
2110
  const agent = await this.ensureAgent(initArgs);
2108
2111
  const screenshot = await agent.interface.screenshotBase64();
@@ -2142,7 +2145,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2142
2145
  ];
2143
2146
  }
2144
2147
  constructor(...args){
2145
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
2148
+ super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
2146
2149
  namespace: 'computer',
2147
2150
  shape: computerInitArgShape,
2148
2151
  cli: {
@@ -2154,7 +2157,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2154
2157
  }
2155
2158
  const env_namespaceObject = require("@midscene/shared/env");
2156
2159
  function version() {
2157
- const currentVersion = "1.9.7";
2160
+ const currentVersion = "1.9.8-beta-20260618091332.0";
2158
2161
  console.log(`@midscene/computer v${currentVersion}`);
2159
2162
  return currentVersion;
2160
2163
  }
@@ -734,7 +734,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
734
734
  }
735
735
  async healthCheck() {
736
736
  console.log('[HealthCheck] Starting health check...');
737
- console.log("[HealthCheck] @midscene/computer v1.9.7");
737
+ console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618091332.0");
738
738
  console.log('[HealthCheck] Taking screenshot...');
739
739
  const screenshotTimeout = 15000;
740
740
  let timeoutId;
@@ -1915,6 +1915,7 @@ async function agentForRDPComputer(opts) {
1915
1915
  return new ComputerAgent(device, opts);
1916
1916
  }
1917
1917
  const core_namespaceObject = require("@midscene/core");
1918
+ const agent_behavior_init_args_namespaceObject = require("@midscene/shared/mcp/agent-behavior-init-args");
1918
1919
  const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
1919
1920
  function mcp_tools_define_property(obj, key, value) {
1920
1921
  if (key in obj) Object.defineProperty(obj, key, {
@@ -1946,7 +1947,8 @@ const computerInitArgShape = {
1946
1947
  ignoreCertificate: core_namespaceObject.z.boolean().optional().describe('Skip TLS certificate validation. Requires host.'),
1947
1948
  securityProtocol: core_namespaceObject.z["enum"](RDP_SECURITY_PROTOCOLS).optional().describe('RDP security protocol negotiation (default auto). Requires host.'),
1948
1949
  desktopWidth: core_namespaceObject.z.number().optional().describe('Remote desktop width in pixels. Requires host.'),
1949
- desktopHeight: core_namespaceObject.z.number().optional().describe('Remote desktop height in pixels. Requires host.')
1950
+ desktopHeight: core_namespaceObject.z.number().optional().describe('Remote desktop height in pixels. Requires host.'),
1951
+ ...agent_behavior_init_args_namespaceObject.agentBehaviorInitArgShape
1950
1952
  };
1951
1953
  function adaptComputerInitArgs(extracted) {
1952
1954
  if (!extracted || 0 === Object.keys(extracted).length) return;
@@ -1962,14 +1964,10 @@ function adaptComputerInitArgs(extracted) {
1962
1964
  return {
1963
1965
  mode: 'local',
1964
1966
  displayId: extracted.displayId,
1965
- headless: extracted.headless
1967
+ headless: extracted.headless,
1968
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(extracted) ?? {}
1966
1969
  };
1967
1970
  }
1968
- function shouldRetargetAgent(opts) {
1969
- if (!opts) return false;
1970
- if ('rdp' === opts.mode) return true;
1971
- return void 0 !== opts.displayId || void 0 !== opts.headless;
1972
- }
1973
1971
  function describeConnectTarget(opts) {
1974
1972
  if (opts?.mode === 'rdp') {
1975
1973
  const target = opts.port ? formatRdpServerAddress(opts.host, opts.port) : formatRdpHost(opts.host);
@@ -1992,7 +1990,8 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1992
1990
  return new ComputerDevice({});
1993
1991
  }
1994
1992
  async ensureAgent(opts) {
1995
- if (this.agent && shouldRetargetAgent(opts)) {
1993
+ const nextSignature = (0, agent_behavior_init_args_namespaceObject.getAgentInitArgsSignature)(opts);
1994
+ if (this.agent && (0, agent_behavior_init_args_namespaceObject.shouldRebuildAgentForInitArgs)(this.lastInitArgsSignature, nextSignature)) {
1996
1995
  try {
1997
1996
  await this.agent.destroy?.();
1998
1997
  } catch (error) {
@@ -2010,6 +2009,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2010
2009
  ...reportOptions ?? {}
2011
2010
  });
2012
2011
  this.agent = agent;
2012
+ this.lastInitArgsSignature = nextSignature;
2013
2013
  return agent;
2014
2014
  }
2015
2015
  const displayId = opts?.mode === 'local' ? opts.displayId : void 0;
@@ -2022,10 +2022,12 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2022
2022
  ...void 0 !== headless ? {
2023
2023
  headless
2024
2024
  } : {},
2025
+ ...(0, agent_behavior_init_args_namespaceObject.extractAgentBehaviorInitArgs)(opts) ?? {},
2025
2026
  ...reportOptions ?? {}
2026
2027
  };
2027
2028
  const agent = await agentFromComputer(Object.keys(agentOpts).length > 0 ? agentOpts : void 0);
2028
2029
  this.agent = agent;
2030
+ this.lastInitArgsSignature = nextSignature;
2029
2031
  return agent;
2030
2032
  }
2031
2033
  preparePlatformTools() {
@@ -2046,6 +2048,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2046
2048
  mcp_tools_debug('Failed to destroy agent during connect:', error);
2047
2049
  }
2048
2050
  this.agent = void 0;
2051
+ this.lastInitArgsSignature = void 0;
2049
2052
  }
2050
2053
  const agent = await this.ensureAgent(initArgs);
2051
2054
  const screenshot = await agent.interface.screenshotBase64();
@@ -2085,7 +2088,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
2085
2088
  ];
2086
2089
  }
2087
2090
  constructor(...args){
2088
- super(...args), mcp_tools_define_property(this, "initArgSpec", {
2091
+ super(...args), mcp_tools_define_property(this, "lastInitArgsSignature", void 0), mcp_tools_define_property(this, "initArgSpec", {
2089
2092
  namespace: 'computer',
2090
2093
  shape: computerInitArgShape,
2091
2094
  cli: {
@@ -2102,7 +2105,7 @@ class ComputerMCPServer extends mcp_namespaceObject.BaseMCPServer {
2102
2105
  constructor(toolsManager){
2103
2106
  super({
2104
2107
  name: '@midscene/computer-mcp',
2105
- version: "1.9.7",
2108
+ version: "1.9.8-beta-20260618091332.0",
2106
2109
  description: 'Control the computer desktop using natural language commands'
2107
2110
  }, toolsManager);
2108
2111
  }
@@ -1,5 +1,6 @@
1
1
  import { AbstractInterface } from '@midscene/core/device';
2
2
  import { Agent } from '@midscene/core/agent';
3
+ import { AgentBehaviorInitArgs } from '@midscene/shared/mcp/agent-behavior-init-args';
3
4
  import { AgentOpt } from '@midscene/core/agent';
4
5
  import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
5
6
  import { ChildProcessWithoutNullStreams } from 'node:child_process';
@@ -161,13 +162,14 @@ export declare type ComputerInterface = ComputerDevice | RDPDevice;
161
162
  /** Init args for the local desktop agent (macOS/Windows/Linux). */
162
163
  declare type ComputerLocalInitArgs = {
163
164
  mode: 'local';
164
- } & Pick<ComputerDeviceOpt, 'displayId' | 'headless'>;
165
+ } & Pick<ComputerDeviceOpt, 'displayId' | 'headless'> & AgentBehaviorInitArgs;
165
166
 
166
167
  /**
167
168
  * Computer-specific tools manager
168
169
  * Extends BaseMidsceneTools to provide desktop automation tools
169
170
  */
170
171
  export declare class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent, ComputerInitArgs> {
172
+ private lastInitArgsSignature?;
171
173
  protected getCliReportSessionName(): string;
172
174
  protected readonly initArgSpec: InitArgSpec<ComputerInitArgs>;
173
175
  protected createTemporaryDevice(): ComputerDevice;
@@ -181,7 +183,7 @@ export declare class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAge
181
183
  /** Init args for the RDP remote-desktop agent. */
182
184
  declare type ComputerRDPInitArgs = {
183
185
  mode: 'rdp';
184
- } & RDPConnectionConfig;
186
+ } & RDPConnectionConfig & AgentBehaviorInitArgs;
185
187
 
186
188
  export declare function createDefaultRDPBackendClient(): RDPBackendClient;
187
189
 
@@ -1,5 +1,6 @@
1
1
  import { AbstractInterface } from '@midscene/core/device';
2
2
  import { Agent } from '@midscene/core/agent';
3
+ import { AgentBehaviorInitArgs } from '@midscene/shared/mcp/agent-behavior-init-args';
3
4
  import { BaseMCPServer } from '@midscene/shared/mcp';
4
5
  import { BaseMidsceneTools } from '@midscene/shared/mcp/base-tools';
5
6
  import { ComputerInputPrimitives } from '@midscene/core/device';
@@ -113,7 +114,7 @@ declare type ComputerInterface = ComputerDevice | RDPDevice;
113
114
  /** Init args for the local desktop agent (macOS/Windows/Linux). */
114
115
  declare type ComputerLocalInitArgs = {
115
116
  mode: 'local';
116
- } & Pick<ComputerDeviceOpt, 'displayId' | 'headless'>;
117
+ } & Pick<ComputerDeviceOpt, 'displayId' | 'headless'> & AgentBehaviorInitArgs;
117
118
 
118
119
  /**
119
120
  * Computer MCP Server
@@ -129,6 +130,7 @@ export declare class ComputerMCPServer extends BaseMCPServer {
129
130
  * Extends BaseMidsceneTools to provide desktop automation tools
130
131
  */
131
132
  declare class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent, ComputerInitArgs> {
133
+ private lastInitArgsSignature?;
132
134
  protected getCliReportSessionName(): string;
133
135
  protected readonly initArgSpec: InitArgSpec<ComputerInitArgs>;
134
136
  protected createTemporaryDevice(): ComputerDevice;
@@ -142,7 +144,7 @@ declare class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent, Com
142
144
  /** Init args for the RDP remote-desktop agent. */
143
145
  declare type ComputerRDPInitArgs = {
144
146
  mode: 'rdp';
145
- } & RDPConnectionConfig;
147
+ } & RDPConnectionConfig & AgentBehaviorInitArgs;
146
148
 
147
149
  declare interface DisplayInfo {
148
150
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/computer",
3
- "version": "1.9.7",
3
+ "version": "1.9.8-beta-20260618091332.0",
4
4
  "description": "Midscene.js Computer Desktop Automation",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,8 +38,8 @@
38
38
  "@computer-use/libnut": "^4.2.0",
39
39
  "clipboardy": "^4.0.0",
40
40
  "screenshot-desktop": "^1.15.3",
41
- "@midscene/core": "1.9.7",
42
- "@midscene/shared": "1.9.7"
41
+ "@midscene/core": "1.9.8-beta-20260618091332.0",
42
+ "@midscene/shared": "1.9.8-beta-20260618091332.0"
43
43
  },
44
44
  "optionalDependencies": {
45
45
  "node-mac-permissions": "2.5.0"