@midscene/computer 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 +21 -18
- package/dist/es/index.mjs +21 -18
- package/dist/lib/cli.js +21 -18
- package/dist/lib/index.js +21 -18
- package/dist/types/index.d.ts +8 -6
- package/package.json +3 -8
- package/dist/es/mcp-server.mjs +0 -2085
- package/dist/lib/mcp-server.js +0 -2138
- package/dist/types/mcp-server.d.ts +0 -243
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 { execFileSync, execSync, spawn, spawnSync } from "node:child_process";
|
|
7
8
|
import { chmodSync, existsSync, statSync } from "node:fs";
|
|
@@ -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.
|
|
698
|
+
console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618014851.0");
|
|
698
699
|
console.log('[HealthCheck] Taking screenshot...');
|
|
699
700
|
const screenshotTimeout = 15000;
|
|
700
701
|
let timeoutId;
|
|
@@ -1873,7 +1874,7 @@ async function agentForRDPComputer(opts) {
|
|
|
1873
1874
|
await device.connect();
|
|
1874
1875
|
return new ComputerAgent(device, opts);
|
|
1875
1876
|
}
|
|
1876
|
-
function
|
|
1877
|
+
function agent_tools_define_property(obj, key, value) {
|
|
1877
1878
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1878
1879
|
value: value,
|
|
1879
1880
|
enumerable: true,
|
|
@@ -1883,7 +1884,7 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
1883
1884
|
else obj[key] = value;
|
|
1884
1885
|
return obj;
|
|
1885
1886
|
}
|
|
1886
|
-
const
|
|
1887
|
+
const agent_tools_debug = getDebug('agent-tools:computer');
|
|
1887
1888
|
const RDP_SECURITY_PROTOCOLS = [
|
|
1888
1889
|
'auto',
|
|
1889
1890
|
'tls',
|
|
@@ -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,29 +1947,31 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
|
|
|
1949
1947
|
return new ComputerDevice({});
|
|
1950
1948
|
}
|
|
1951
1949
|
async ensureAgent(opts) {
|
|
1952
|
-
|
|
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) {
|
|
1956
|
-
|
|
1955
|
+
agent_tools_debug('Failed to destroy agent during cleanup:', error);
|
|
1957
1956
|
}
|
|
1958
1957
|
this.agent = void 0;
|
|
1959
1958
|
}
|
|
1960
1959
|
if (this.agent) return this.agent;
|
|
1961
1960
|
const reportOptions = this.readCliReportAgentOptions();
|
|
1962
1961
|
if (opts?.mode === 'rdp') {
|
|
1963
|
-
|
|
1962
|
+
agent_tools_debug('Creating RDP Computer agent for host:', opts.host);
|
|
1964
1963
|
const { mode: _mode, ...rdpFields } = opts;
|
|
1965
1964
|
const agent = await agentForRDPComputer({
|
|
1966
1965
|
...rdpFields,
|
|
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;
|
|
1973
1973
|
const headless = opts?.mode === 'local' ? opts.headless : void 0;
|
|
1974
|
-
|
|
1974
|
+
agent_tools_debug('Creating Computer agent with displayId:', displayId || 'primary');
|
|
1975
1975
|
const agentOpts = {
|
|
1976
1976
|
...displayId ? {
|
|
1977
1977
|
displayId
|
|
@@ -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() {
|
|
@@ -2000,9 +2002,10 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
|
|
|
2000
2002
|
try {
|
|
2001
2003
|
await this.agent.destroy?.();
|
|
2002
2004
|
} catch (error) {
|
|
2003
|
-
|
|
2005
|
+
agent_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),
|
|
2048
|
+
super(...args), agent_tools_define_property(this, "lastInitArgsSignature", void 0), agent_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.
|
|
2061
|
+
version: "1.9.8-beta-20260618014851.0",
|
|
2059
2062
|
extraCommands: createReportCliCommands()
|
|
2060
2063
|
}).catch((e)=>{
|
|
2061
2064
|
process.exit(reportCLIError(e));
|
package/dist/es/index.mjs
CHANGED
|
@@ -13,7 +13,8 @@ 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 {
|
|
16
|
+
import { agentBehaviorInitArgShape, extractAgentBehaviorInitArgs, getAgentInitArgsSignature, shouldRebuildAgentForInitArgs } from "@midscene/shared/agent-tools/agent-behavior-init-args";
|
|
17
|
+
import { BaseMidsceneTools } from "@midscene/shared/agent-tools/base-tools";
|
|
17
18
|
import { overrideAIConfig } from "@midscene/shared/env";
|
|
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.
|
|
698
|
+
console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618014851.0");
|
|
698
699
|
console.log('[HealthCheck] Taking screenshot...');
|
|
699
700
|
const screenshotTimeout = 15000;
|
|
700
701
|
let timeoutId;
|
|
@@ -1916,7 +1917,7 @@ async function agentForRDPComputer(opts) {
|
|
|
1916
1917
|
await device.connect();
|
|
1917
1918
|
return new ComputerAgent(device, opts);
|
|
1918
1919
|
}
|
|
1919
|
-
function
|
|
1920
|
+
function agent_tools_define_property(obj, key, value) {
|
|
1920
1921
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1921
1922
|
value: value,
|
|
1922
1923
|
enumerable: true,
|
|
@@ -1926,7 +1927,7 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
1926
1927
|
else obj[key] = value;
|
|
1927
1928
|
return obj;
|
|
1928
1929
|
}
|
|
1929
|
-
const
|
|
1930
|
+
const agent_tools_debug = getDebug('agent-tools:computer');
|
|
1930
1931
|
const RDP_SECURITY_PROTOCOLS = [
|
|
1931
1932
|
'auto',
|
|
1932
1933
|
'tls',
|
|
@@ -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,29 +1990,31 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
|
|
|
1992
1990
|
return new ComputerDevice({});
|
|
1993
1991
|
}
|
|
1994
1992
|
async ensureAgent(opts) {
|
|
1995
|
-
|
|
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) {
|
|
1999
|
-
|
|
1998
|
+
agent_tools_debug('Failed to destroy agent during cleanup:', error);
|
|
2000
1999
|
}
|
|
2001
2000
|
this.agent = void 0;
|
|
2002
2001
|
}
|
|
2003
2002
|
if (this.agent) return this.agent;
|
|
2004
2003
|
const reportOptions = this.readCliReportAgentOptions();
|
|
2005
2004
|
if (opts?.mode === 'rdp') {
|
|
2006
|
-
|
|
2005
|
+
agent_tools_debug('Creating RDP Computer agent for host:', opts.host);
|
|
2007
2006
|
const { mode: _mode, ...rdpFields } = opts;
|
|
2008
2007
|
const agent = await agentForRDPComputer({
|
|
2009
2008
|
...rdpFields,
|
|
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;
|
|
2016
2016
|
const headless = opts?.mode === 'local' ? opts.headless : void 0;
|
|
2017
|
-
|
|
2017
|
+
agent_tools_debug('Creating Computer agent with displayId:', displayId || 'primary');
|
|
2018
2018
|
const agentOpts = {
|
|
2019
2019
|
...displayId ? {
|
|
2020
2020
|
displayId
|
|
@@ -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() {
|
|
@@ -2043,9 +2045,10 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
|
|
|
2043
2045
|
try {
|
|
2044
2046
|
await this.agent.destroy?.();
|
|
2045
2047
|
} catch (error) {
|
|
2046
|
-
|
|
2048
|
+
agent_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),
|
|
2091
|
+
super(...args), agent_tools_define_property(this, "lastInitArgsSignature", void 0), agent_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.
|
|
2102
|
+
const currentVersion = "1.9.8-beta-20260618014851.0";
|
|
2100
2103
|
console.log(`@midscene/computer v${currentVersion}`);
|
|
2101
2104
|
return currentVersion;
|
|
2102
2105
|
}
|
package/dist/lib/cli.js
CHANGED
|
@@ -26,8 +26,9 @@ var __webpack_require__ = {};
|
|
|
26
26
|
var __webpack_exports__ = {};
|
|
27
27
|
const core_namespaceObject = require("@midscene/core");
|
|
28
28
|
const cli_namespaceObject = require("@midscene/shared/cli");
|
|
29
|
+
const agent_behavior_init_args_namespaceObject = require("@midscene/shared/agent-tools/agent-behavior-init-args");
|
|
30
|
+
const base_tools_namespaceObject = require("@midscene/shared/agent-tools/base-tools");
|
|
29
31
|
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
30
|
-
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");
|
|
33
34
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
@@ -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.
|
|
724
|
+
console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618014851.0");
|
|
724
725
|
console.log('[HealthCheck] Taking screenshot...');
|
|
725
726
|
const screenshotTimeout = 15000;
|
|
726
727
|
let timeoutId;
|
|
@@ -1900,7 +1901,7 @@ async function agentForRDPComputer(opts) {
|
|
|
1900
1901
|
await device.connect();
|
|
1901
1902
|
return new ComputerAgent(device, opts);
|
|
1902
1903
|
}
|
|
1903
|
-
function
|
|
1904
|
+
function agent_tools_define_property(obj, key, value) {
|
|
1904
1905
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1905
1906
|
value: value,
|
|
1906
1907
|
enumerable: true,
|
|
@@ -1910,7 +1911,7 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
1910
1911
|
else obj[key] = value;
|
|
1911
1912
|
return obj;
|
|
1912
1913
|
}
|
|
1913
|
-
const
|
|
1914
|
+
const agent_tools_debug = (0, logger_namespaceObject.getDebug)('agent-tools:computer');
|
|
1914
1915
|
const RDP_SECURITY_PROTOCOLS = [
|
|
1915
1916
|
'auto',
|
|
1916
1917
|
'tls',
|
|
@@ -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,29 +1974,31 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
1976
1974
|
return new ComputerDevice({});
|
|
1977
1975
|
}
|
|
1978
1976
|
async ensureAgent(opts) {
|
|
1979
|
-
|
|
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) {
|
|
1983
|
-
|
|
1982
|
+
agent_tools_debug('Failed to destroy agent during cleanup:', error);
|
|
1984
1983
|
}
|
|
1985
1984
|
this.agent = void 0;
|
|
1986
1985
|
}
|
|
1987
1986
|
if (this.agent) return this.agent;
|
|
1988
1987
|
const reportOptions = this.readCliReportAgentOptions();
|
|
1989
1988
|
if (opts?.mode === 'rdp') {
|
|
1990
|
-
|
|
1989
|
+
agent_tools_debug('Creating RDP Computer agent for host:', opts.host);
|
|
1991
1990
|
const { mode: _mode, ...rdpFields } = opts;
|
|
1992
1991
|
const agent = await agentForRDPComputer({
|
|
1993
1992
|
...rdpFields,
|
|
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;
|
|
2000
2000
|
const headless = opts?.mode === 'local' ? opts.headless : void 0;
|
|
2001
|
-
|
|
2001
|
+
agent_tools_debug('Creating Computer agent with displayId:', displayId || 'primary');
|
|
2002
2002
|
const agentOpts = {
|
|
2003
2003
|
...displayId ? {
|
|
2004
2004
|
displayId
|
|
@@ -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() {
|
|
@@ -2027,9 +2029,10 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
2027
2029
|
try {
|
|
2028
2030
|
await this.agent.destroy?.();
|
|
2029
2031
|
} catch (error) {
|
|
2030
|
-
|
|
2032
|
+
agent_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),
|
|
2075
|
+
super(...args), agent_tools_define_property(this, "lastInitArgsSignature", void 0), agent_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.
|
|
2088
|
+
version: "1.9.8-beta-20260618014851.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.
|
|
750
|
+
console.log("[HealthCheck] @midscene/computer v1.9.8-beta-20260618014851.0");
|
|
751
751
|
console.log('[HealthCheck] Taking screenshot...');
|
|
752
752
|
const screenshotTimeout = 15000;
|
|
753
753
|
let timeoutId;
|
|
@@ -1972,8 +1972,9 @@ async function agentForRDPComputer(opts) {
|
|
|
1972
1972
|
return new ComputerAgent(device, opts);
|
|
1973
1973
|
}
|
|
1974
1974
|
const core_namespaceObject = require("@midscene/core");
|
|
1975
|
-
const
|
|
1976
|
-
|
|
1975
|
+
const agent_behavior_init_args_namespaceObject = require("@midscene/shared/agent-tools/agent-behavior-init-args");
|
|
1976
|
+
const base_tools_namespaceObject = require("@midscene/shared/agent-tools/base-tools");
|
|
1977
|
+
function agent_tools_define_property(obj, key, value) {
|
|
1977
1978
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
1978
1979
|
value: value,
|
|
1979
1980
|
enumerable: true,
|
|
@@ -1983,7 +1984,7 @@ function mcp_tools_define_property(obj, key, value) {
|
|
|
1983
1984
|
else obj[key] = value;
|
|
1984
1985
|
return obj;
|
|
1985
1986
|
}
|
|
1986
|
-
const
|
|
1987
|
+
const agent_tools_debug = (0, logger_namespaceObject.getDebug)('agent-tools:computer');
|
|
1987
1988
|
const RDP_SECURITY_PROTOCOLS = [
|
|
1988
1989
|
'auto',
|
|
1989
1990
|
'tls',
|
|
@@ -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,29 +2047,31 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
2049
2047
|
return new ComputerDevice({});
|
|
2050
2048
|
}
|
|
2051
2049
|
async ensureAgent(opts) {
|
|
2052
|
-
|
|
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) {
|
|
2056
|
-
|
|
2055
|
+
agent_tools_debug('Failed to destroy agent during cleanup:', error);
|
|
2057
2056
|
}
|
|
2058
2057
|
this.agent = void 0;
|
|
2059
2058
|
}
|
|
2060
2059
|
if (this.agent) return this.agent;
|
|
2061
2060
|
const reportOptions = this.readCliReportAgentOptions();
|
|
2062
2061
|
if (opts?.mode === 'rdp') {
|
|
2063
|
-
|
|
2062
|
+
agent_tools_debug('Creating RDP Computer agent for host:', opts.host);
|
|
2064
2063
|
const { mode: _mode, ...rdpFields } = opts;
|
|
2065
2064
|
const agent = await agentForRDPComputer({
|
|
2066
2065
|
...rdpFields,
|
|
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;
|
|
2073
2073
|
const headless = opts?.mode === 'local' ? opts.headless : void 0;
|
|
2074
|
-
|
|
2074
|
+
agent_tools_debug('Creating Computer agent with displayId:', displayId || 'primary');
|
|
2075
2075
|
const agentOpts = {
|
|
2076
2076
|
...displayId ? {
|
|
2077
2077
|
displayId
|
|
@@ -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() {
|
|
@@ -2100,9 +2102,10 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
|
|
|
2100
2102
|
try {
|
|
2101
2103
|
await this.agent.destroy?.();
|
|
2102
2104
|
} catch (error) {
|
|
2103
|
-
|
|
2105
|
+
agent_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),
|
|
2148
|
+
super(...args), agent_tools_define_property(this, "lastInitArgsSignature", void 0), agent_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.
|
|
2160
|
+
const currentVersion = "1.9.8-beta-20260618014851.0";
|
|
2158
2161
|
console.log(`@midscene/computer v${currentVersion}`);
|
|
2159
2162
|
return currentVersion;
|
|
2160
2163
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { AbstractInterface } from '@midscene/core/device';
|
|
2
2
|
import { Agent } from '@midscene/core/agent';
|
|
3
|
+
import { AgentBehaviorInitArgs } from '@midscene/shared/agent-tools/agent-behavior-init-args';
|
|
3
4
|
import { AgentOpt } from '@midscene/core/agent';
|
|
4
|
-
import { BaseMidsceneTools } from '@midscene/shared/
|
|
5
|
+
import { BaseMidsceneTools } from '@midscene/shared/agent-tools/base-tools';
|
|
5
6
|
import { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
6
7
|
import { ComputerInputPrimitives } from '@midscene/core/device';
|
|
7
8
|
import type { DeviceAction } from '@midscene/core';
|
|
8
|
-
import { InitArgSpec } from '@midscene/shared/
|
|
9
|
+
import { InitArgSpec } from '@midscene/shared/agent-tools/base-tools';
|
|
9
10
|
import type { InterfaceType } from '@midscene/core';
|
|
10
11
|
import { overrideAIConfig } from '@midscene/shared/env';
|
|
11
12
|
import type { Size } from '@midscene/core';
|
|
12
13
|
import { SpawnOptionsWithoutStdio } from 'node:child_process';
|
|
13
|
-
import type { ToolDefinition } from '@midscene/shared/
|
|
14
|
+
import type { ToolDefinition } from '@midscene/shared/agent-tools/types';
|
|
14
15
|
|
|
15
16
|
declare interface AccessibilityCheckResult {
|
|
16
17
|
hasPermission: boolean;
|
|
@@ -152,7 +153,7 @@ export declare interface ComputerDeviceOpt {
|
|
|
152
153
|
/**
|
|
153
154
|
* Discriminated union describing the two ways `computer_*` tools can spawn an
|
|
154
155
|
* agent. `mode` is filled in by `initArgSpec.adapt` based on whether `host` is
|
|
155
|
-
* set, so callers (CLI/
|
|
156
|
+
* set, so callers (CLI/YAML) never have to provide it explicitly.
|
|
156
157
|
*/
|
|
157
158
|
declare type ComputerInitArgs = ComputerLocalInitArgs | ComputerRDPInitArgs;
|
|
158
159
|
|
|
@@ -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
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/computer",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.8-beta-20260618014851.0",
|
|
4
4
|
"description": "Midscene.js Computer Desktop Automation",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,19 +27,14 @@
|
|
|
27
27
|
"import": "./dist/es/index.mjs",
|
|
28
28
|
"require": "./dist/lib/index.js"
|
|
29
29
|
},
|
|
30
|
-
"./mcp-server": {
|
|
31
|
-
"types": "./dist/types/mcp-server.d.ts",
|
|
32
|
-
"import": "./dist/es/mcp-server.mjs",
|
|
33
|
-
"require": "./dist/lib/mcp-server.js"
|
|
34
|
-
},
|
|
35
30
|
"./package.json": "./package.json"
|
|
36
31
|
},
|
|
37
32
|
"dependencies": {
|
|
38
33
|
"@computer-use/libnut": "^4.2.0",
|
|
39
34
|
"clipboardy": "^4.0.0",
|
|
40
35
|
"screenshot-desktop": "^1.15.3",
|
|
41
|
-
"@midscene/core": "1.9.
|
|
42
|
-
"@midscene/shared": "1.9.
|
|
36
|
+
"@midscene/core": "1.9.8-beta-20260618014851.0",
|
|
37
|
+
"@midscene/shared": "1.9.8-beta-20260618014851.0"
|
|
43
38
|
},
|
|
44
39
|
"optionalDependencies": {
|
|
45
40
|
"node-mac-permissions": "2.5.0"
|