@midscene/computer 1.8.0 → 1.8.1-beta-20260513084557.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/lib/index.js CHANGED
@@ -464,7 +464,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
464
464
  }
465
465
  async healthCheck() {
466
466
  console.log('[HealthCheck] Starting health check...');
467
- console.log("[HealthCheck] @midscene/computer v1.8.0");
467
+ console.log("[HealthCheck] @midscene/computer v1.8.1-beta-20260513084557.0");
468
468
  console.log('[HealthCheck] Taking screenshot...');
469
469
  const screenshotTimeout = 15000;
470
470
  let timeoutId;
@@ -1551,10 +1551,61 @@ function mcp_tools_define_property(obj, key, value) {
1551
1551
  return obj;
1552
1552
  }
1553
1553
  const mcp_tools_debug = (0, logger_namespaceObject.getDebug)('mcp:computer-tools');
1554
+ const RDP_SECURITY_PROTOCOLS = [
1555
+ 'auto',
1556
+ 'tls',
1557
+ 'nla',
1558
+ 'rdp'
1559
+ ];
1554
1560
  const computerInitArgShape = {
1555
- displayId: core_namespaceObject.z.string().optional().describe('Display ID (from computer_list_displays)'),
1556
- headless: core_namespaceObject.z.boolean().optional().describe('Start virtual display via Xvfb (Linux only)')
1561
+ displayId: core_namespaceObject.z.string().optional().describe('Display ID for local mode (from computer_list_displays). Ignored when host is set.'),
1562
+ headless: core_namespaceObject.z.boolean().optional().describe('Start virtual display via Xvfb (Linux local mode only). Ignored when host is set.'),
1563
+ host: core_namespaceObject.z.string().optional().describe('RDP host (FQDN or IP). Set this to switch into RDP mode.'),
1564
+ port: core_namespaceObject.z.number().optional().describe('RDP port (default 3389). Requires host.'),
1565
+ username: core_namespaceObject.z.string().optional().describe('RDP username. Requires host.'),
1566
+ password: core_namespaceObject.z.string().optional().describe('RDP password. Requires host. Prefer setting via environment or a secrets manager.'),
1567
+ domain: core_namespaceObject.z.string().optional().describe('RDP domain. Requires host.'),
1568
+ adminSession: core_namespaceObject.z.boolean().optional().describe('Attach to the RDP admin/console session. Requires host.'),
1569
+ ignoreCertificate: core_namespaceObject.z.boolean().optional().describe('Skip TLS certificate validation. Requires host.'),
1570
+ securityProtocol: core_namespaceObject.z["enum"](RDP_SECURITY_PROTOCOLS).optional().describe('RDP security protocol negotiation (default auto). Requires host.'),
1571
+ desktopWidth: core_namespaceObject.z.number().optional().describe('Remote desktop width in pixels. Requires host.'),
1572
+ desktopHeight: core_namespaceObject.z.number().optional().describe('Remote desktop height in pixels. Requires host.')
1557
1573
  };
1574
+ function adaptComputerInitArgs(extracted) {
1575
+ if (!extracted || 0 === Object.keys(extracted).length) return;
1576
+ if (extracted.host) {
1577
+ const { displayId: _d, headless: _h, ...rdpFields } = extracted;
1578
+ return {
1579
+ mode: 'rdp',
1580
+ ...rdpFields,
1581
+ host: extracted.host
1582
+ };
1583
+ }
1584
+ return {
1585
+ mode: 'local',
1586
+ displayId: extracted.displayId,
1587
+ headless: extracted.headless
1588
+ };
1589
+ }
1590
+ function shouldRetargetAgent(opts) {
1591
+ if (!opts) return false;
1592
+ if ('rdp' === opts.mode) return true;
1593
+ return void 0 !== opts.displayId || void 0 !== opts.headless;
1594
+ }
1595
+ function describeConnectTarget(opts) {
1596
+ if (opts?.mode === 'rdp') {
1597
+ const portSuffix = opts.port ? `:${opts.port}` : '';
1598
+ const userSuffix = opts.username ? ` as ${opts.username}` : '';
1599
+ return ` via RDP (${opts.host}${portSuffix}${userSuffix})`;
1600
+ }
1601
+ if (opts?.mode === 'local' && opts.displayId) return ` (Display: ${opts.displayId})`;
1602
+ return ' (Primary display)';
1603
+ }
1604
+ function getCliReportSessionTarget(opts) {
1605
+ if (opts?.mode === 'rdp') return `rdp:${opts.host}`;
1606
+ if (opts?.mode === 'local' && opts.displayId) return opts.displayId;
1607
+ return 'primary';
1608
+ }
1558
1609
  class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools {
1559
1610
  getCliReportSessionName() {
1560
1611
  return 'midscene-computer';
@@ -1563,9 +1614,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1563
1614
  return new ComputerDevice({});
1564
1615
  }
1565
1616
  async ensureAgent(opts) {
1566
- const displayId = opts?.displayId;
1567
- const headless = opts?.headless;
1568
- if (this.agent && (void 0 !== displayId || void 0 !== headless)) {
1617
+ if (this.agent && shouldRetargetAgent(opts)) {
1569
1618
  try {
1570
1619
  await this.agent.destroy?.();
1571
1620
  } catch (error) {
@@ -1574,8 +1623,20 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1574
1623
  this.agent = void 0;
1575
1624
  }
1576
1625
  if (this.agent) return this.agent;
1577
- mcp_tools_debug('Creating Computer agent with displayId:', displayId || 'primary');
1578
1626
  const reportOptions = this.readCliReportAgentOptions();
1627
+ if (opts?.mode === 'rdp') {
1628
+ mcp_tools_debug('Creating RDP Computer agent for host:', opts.host);
1629
+ const { mode: _mode, ...rdpFields } = opts;
1630
+ const agent = await agentForRDPComputer({
1631
+ ...rdpFields,
1632
+ ...reportOptions ?? {}
1633
+ });
1634
+ this.agent = agent;
1635
+ return agent;
1636
+ }
1637
+ const displayId = opts?.mode === 'local' ? opts.displayId : void 0;
1638
+ const headless = opts?.mode === 'local' ? opts.headless : void 0;
1639
+ mcp_tools_debug('Creating Computer agent with displayId:', displayId || 'primary');
1579
1640
  const agentOpts = {
1580
1641
  ...displayId ? {
1581
1642
  displayId
@@ -1593,12 +1654,12 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1593
1654
  return [
1594
1655
  {
1595
1656
  name: 'computer_connect',
1596
- description: 'Connect to computer desktop. Provide displayId to connect to a specific display (use computer_list_displays to get available IDs). If not provided, uses the primary display.',
1657
+ description: "Connect to a computer desktop. Default (local) mode controls the local machine; pass displayId to target a specific local display (see computer_list_displays). Pass host to switch to RDP mode and connect to a remote Windows desktop via the RDP helper binary. RDP-related options (port/username/password/domain/securityProtocol/ignoreCertificate/adminSession/desktopWidth/desktopHeight) only take effect when host is set.",
1597
1658
  schema: this.getAgentInitArgSchema(),
1598
1659
  cli: this.getAgentInitArgCliMetadata(),
1599
1660
  handler: async (args)=>{
1600
1661
  const initArgs = this.extractAgentInitParam(args);
1601
- const reportSession = this.createNewCliReportSession(initArgs?.displayId ?? 'primary');
1662
+ const reportSession = this.createNewCliReportSession(getCliReportSessionTarget(initArgs));
1602
1663
  this.commitCliReportSession(reportSession);
1603
1664
  if (this.agent) {
1604
1665
  try {
@@ -1614,7 +1675,7 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1614
1675
  content: [
1615
1676
  {
1616
1677
  type: 'text',
1617
- text: `Connected to computer${initArgs?.displayId ? ` (Display: ${initArgs.displayId})` : ' (Primary display)'}`
1678
+ text: `Connected to computer${describeConnectTarget(initArgs)}`
1618
1679
  },
1619
1680
  ...this.buildScreenshotContent(screenshot)
1620
1681
  ]
@@ -1652,13 +1713,13 @@ class ComputerMidsceneTools extends base_tools_namespaceObject.BaseMidsceneTools
1652
1713
  cli: {
1653
1714
  preferBareKeys: true
1654
1715
  },
1655
- adapt: (extracted)=>extracted
1716
+ adapt: (extracted)=>adaptComputerInitArgs(extracted)
1656
1717
  });
1657
1718
  }
1658
1719
  }
1659
1720
  const env_namespaceObject = require("@midscene/shared/env");
1660
1721
  function version() {
1661
- const currentVersion = "1.8.0";
1722
+ const currentVersion = "1.8.1-beta-20260513084557.0";
1662
1723
  console.log(`@midscene/computer v${currentVersion}`);
1663
1724
  return currentVersion;
1664
1725
  }