@midscene/computer 1.5.7-beta-20260323114150.0 → 1.5.7
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 +7 -76
- package/dist/es/index.mjs +7 -76
- package/dist/es/mcp-server.mjs +7 -76
- package/dist/lib/cli.js +6 -75
- package/dist/lib/index.js +6 -75
- package/dist/lib/mcp-server.js +6 -75
- package/dist/types/index.d.ts +0 -6
- package/dist/types/mcp-server.d.ts +0 -6
- package/package.json +3 -3
package/dist/es/cli.mjs
CHANGED
|
@@ -4,15 +4,13 @@ import { getDebug } from "@midscene/shared/logger";
|
|
|
4
4
|
import { BaseMidsceneTools } from "@midscene/shared/mcp";
|
|
5
5
|
import { Agent } from "@midscene/core/agent";
|
|
6
6
|
import node_assert from "node:assert";
|
|
7
|
-
import {
|
|
8
|
-
import { existsSync, promises } from "node:fs";
|
|
7
|
+
import { execSync, spawn } from "node:child_process";
|
|
9
8
|
import { createRequire } from "node:module";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
9
|
import { actionHoverParamSchema, defineAction, defineActionClearInput, defineActionDoubleClick, defineActionDragAndDrop, defineActionKeyboardPress, defineActionRightClick, defineActionScroll, defineActionTap } from "@midscene/core/device";
|
|
13
10
|
import { sleep } from "@midscene/core/utils";
|
|
14
11
|
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
15
12
|
import screenshot_desktop from "screenshot-desktop";
|
|
13
|
+
import { existsSync } from "node:fs";
|
|
16
14
|
const debugXvfb = getDebug('computer:xvfb');
|
|
17
15
|
function checkXvfbInstalled() {
|
|
18
16
|
try {
|
|
@@ -301,7 +299,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
301
299
|
}
|
|
302
300
|
async healthCheck() {
|
|
303
301
|
console.log('[HealthCheck] Starting health check...');
|
|
304
|
-
console.log("[HealthCheck] @midscene/computer v1.5.7
|
|
302
|
+
console.log("[HealthCheck] @midscene/computer v1.5.7");
|
|
305
303
|
console.log('[HealthCheck] Taking screenshot...');
|
|
306
304
|
const screenshotTimeout = 15000;
|
|
307
305
|
let timeoutId;
|
|
@@ -378,76 +376,9 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
378
376
|
debugDevice('Screenshot options', options);
|
|
379
377
|
const buffer = await screenshot_desktop(options);
|
|
380
378
|
return createImgBase64ByFormat('png', buffer.toString('base64'));
|
|
381
|
-
} catch (
|
|
382
|
-
debugDevice(`Screenshot failed: ${
|
|
383
|
-
|
|
384
|
-
debugDevice('Trying PowerShell fallback for screenshot...');
|
|
385
|
-
try {
|
|
386
|
-
const buffer = await this.screenshotViaWindowsPowerShell();
|
|
387
|
-
return createImgBase64ByFormat('png', buffer.toString('base64'));
|
|
388
|
-
} catch (fallbackError) {
|
|
389
|
-
debugDevice(`PowerShell fallback also failed: ${fallbackError}`);
|
|
390
|
-
throw new Error(`Failed to take screenshot. Primary error: ${primaryError}. Fallback error: ${fallbackError}`);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
throw new Error(`Failed to take screenshot: ${primaryError}`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
async screenshotViaWindowsPowerShell() {
|
|
397
|
-
const tmpFile = join(tmpdir(), `midscene-screenshot-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.png`);
|
|
398
|
-
const safeDisplayId = this.displayId ? this.displayId.replace(/[^a-zA-Z0-9\\.\-_:]/g, '') : void 0;
|
|
399
|
-
const screenSelector = safeDisplayId ? `$screen = [System.Windows.Forms.Screen]::AllScreens | Where-Object { $_.DeviceName -eq "${safeDisplayId}" }
|
|
400
|
-
if (-not $screen) { $screen = [System.Windows.Forms.Screen]::PrimaryScreen }` : '$screen = [System.Windows.Forms.Screen]::PrimaryScreen';
|
|
401
|
-
const psScript = [
|
|
402
|
-
"Add-Type -TypeDefinition @'",
|
|
403
|
-
'using System;',
|
|
404
|
-
'using System.Runtime.InteropServices;',
|
|
405
|
-
'public static class MidsceneDpi {',
|
|
406
|
-
' [DllImport("user32.dll", SetLastError = true)]',
|
|
407
|
-
' public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);',
|
|
408
|
-
'',
|
|
409
|
-
' [DllImport("user32.dll")]',
|
|
410
|
-
' public static extern bool SetProcessDPIAware();',
|
|
411
|
-
'}',
|
|
412
|
-
"'@",
|
|
413
|
-
'$perMonitorAwareV2 = [IntPtr](-4)',
|
|
414
|
-
'try {',
|
|
415
|
-
' if (-not [MidsceneDpi]::SetProcessDpiAwarenessContext($perMonitorAwareV2)) {',
|
|
416
|
-
' [void][MidsceneDpi]::SetProcessDPIAware()',
|
|
417
|
-
' }',
|
|
418
|
-
'} catch {',
|
|
419
|
-
' try { [void][MidsceneDpi]::SetProcessDPIAware() } catch {}',
|
|
420
|
-
'}',
|
|
421
|
-
'Add-Type -AssemblyName System.Windows.Forms',
|
|
422
|
-
'Add-Type -AssemblyName System.Drawing',
|
|
423
|
-
screenSelector,
|
|
424
|
-
'$bounds = $screen.Bounds',
|
|
425
|
-
'$bmp = New-Object System.Drawing.Bitmap($bounds.Width, $bounds.Height)',
|
|
426
|
-
'$g = [System.Drawing.Graphics]::FromImage($bmp)',
|
|
427
|
-
'$g.CopyFromScreen($bounds.Location, [System.Drawing.Point]::Empty, $bounds.Size)',
|
|
428
|
-
`$bmp.Save("${tmpFile}", [System.Drawing.Imaging.ImageFormat]::Png)`,
|
|
429
|
-
'$g.Dispose()',
|
|
430
|
-
'$bmp.Dispose()'
|
|
431
|
-
].join('\n');
|
|
432
|
-
const encodedScript = Buffer.from(psScript, 'utf16le').toString('base64');
|
|
433
|
-
await new Promise((resolve, reject)=>{
|
|
434
|
-
execFile('powershell.exe', [
|
|
435
|
-
'-NoProfile',
|
|
436
|
-
'-NonInteractive',
|
|
437
|
-
'-EncodedCommand',
|
|
438
|
-
encodedScript
|
|
439
|
-
], {
|
|
440
|
-
windowsHide: true,
|
|
441
|
-
timeout: 30000
|
|
442
|
-
}, (err, _stdout, stderr)=>{
|
|
443
|
-
if (err) reject(new Error(`PowerShell screenshot failed: ${stderr || err.message}`));
|
|
444
|
-
else resolve();
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
try {
|
|
448
|
-
return await promises.readFile(tmpFile);
|
|
449
|
-
} finally{
|
|
450
|
-
await promises.unlink(tmpFile).catch((err)=>debugDevice(`Failed to delete temp screenshot file: ${err}`));
|
|
379
|
+
} catch (error) {
|
|
380
|
+
debugDevice(`Screenshot failed: ${error}`);
|
|
381
|
+
throw new Error(`Failed to take screenshot: ${error}`);
|
|
451
382
|
}
|
|
452
383
|
}
|
|
453
384
|
async size() {
|
|
@@ -850,7 +781,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
|
|
|
850
781
|
const tools = new ComputerMidsceneTools();
|
|
851
782
|
runToolsCLI(tools, 'midscene-computer', {
|
|
852
783
|
stripPrefix: 'computer_',
|
|
853
|
-
version: "1.5.7
|
|
784
|
+
version: "1.5.7"
|
|
854
785
|
}).catch((e)=>{
|
|
855
786
|
if (!(e instanceof CLIError)) console.error(e);
|
|
856
787
|
process.exit(e instanceof CLIError ? e.exitCode : 1);
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import node_assert from "node:assert";
|
|
2
|
-
import {
|
|
3
|
-
import { existsSync, promises } from "node:fs";
|
|
2
|
+
import { execSync, spawn } from "node:child_process";
|
|
4
3
|
import { createRequire } from "node:module";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { join } from "node:path";
|
|
7
4
|
import { getMidsceneLocationSchema, z } from "@midscene/core";
|
|
8
5
|
import { actionHoverParamSchema, defineAction, defineActionClearInput, defineActionDoubleClick, defineActionDragAndDrop, defineActionKeyboardPress, defineActionRightClick, defineActionScroll, defineActionTap } from "@midscene/core/device";
|
|
9
6
|
import { sleep } from "@midscene/core/utils";
|
|
10
7
|
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
11
8
|
import { getDebug } from "@midscene/shared/logger";
|
|
12
9
|
import screenshot_desktop from "screenshot-desktop";
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
13
11
|
import { Agent } from "@midscene/core/agent";
|
|
14
12
|
import { BaseMidsceneTools } from "@midscene/shared/mcp";
|
|
15
13
|
import { overrideAIConfig } from "@midscene/shared/env";
|
|
@@ -301,7 +299,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
301
299
|
}
|
|
302
300
|
async healthCheck() {
|
|
303
301
|
console.log('[HealthCheck] Starting health check...');
|
|
304
|
-
console.log("[HealthCheck] @midscene/computer v1.5.7
|
|
302
|
+
console.log("[HealthCheck] @midscene/computer v1.5.7");
|
|
305
303
|
console.log('[HealthCheck] Taking screenshot...');
|
|
306
304
|
const screenshotTimeout = 15000;
|
|
307
305
|
let timeoutId;
|
|
@@ -378,76 +376,9 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
378
376
|
debugDevice('Screenshot options', options);
|
|
379
377
|
const buffer = await screenshot_desktop(options);
|
|
380
378
|
return createImgBase64ByFormat('png', buffer.toString('base64'));
|
|
381
|
-
} catch (
|
|
382
|
-
debugDevice(`Screenshot failed: ${
|
|
383
|
-
|
|
384
|
-
debugDevice('Trying PowerShell fallback for screenshot...');
|
|
385
|
-
try {
|
|
386
|
-
const buffer = await this.screenshotViaWindowsPowerShell();
|
|
387
|
-
return createImgBase64ByFormat('png', buffer.toString('base64'));
|
|
388
|
-
} catch (fallbackError) {
|
|
389
|
-
debugDevice(`PowerShell fallback also failed: ${fallbackError}`);
|
|
390
|
-
throw new Error(`Failed to take screenshot. Primary error: ${primaryError}. Fallback error: ${fallbackError}`);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
throw new Error(`Failed to take screenshot: ${primaryError}`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
async screenshotViaWindowsPowerShell() {
|
|
397
|
-
const tmpFile = join(tmpdir(), `midscene-screenshot-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.png`);
|
|
398
|
-
const safeDisplayId = this.displayId ? this.displayId.replace(/[^a-zA-Z0-9\\.\-_:]/g, '') : void 0;
|
|
399
|
-
const screenSelector = safeDisplayId ? `$screen = [System.Windows.Forms.Screen]::AllScreens | Where-Object { $_.DeviceName -eq "${safeDisplayId}" }
|
|
400
|
-
if (-not $screen) { $screen = [System.Windows.Forms.Screen]::PrimaryScreen }` : '$screen = [System.Windows.Forms.Screen]::PrimaryScreen';
|
|
401
|
-
const psScript = [
|
|
402
|
-
"Add-Type -TypeDefinition @'",
|
|
403
|
-
'using System;',
|
|
404
|
-
'using System.Runtime.InteropServices;',
|
|
405
|
-
'public static class MidsceneDpi {',
|
|
406
|
-
' [DllImport("user32.dll", SetLastError = true)]',
|
|
407
|
-
' public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);',
|
|
408
|
-
'',
|
|
409
|
-
' [DllImport("user32.dll")]',
|
|
410
|
-
' public static extern bool SetProcessDPIAware();',
|
|
411
|
-
'}',
|
|
412
|
-
"'@",
|
|
413
|
-
'$perMonitorAwareV2 = [IntPtr](-4)',
|
|
414
|
-
'try {',
|
|
415
|
-
' if (-not [MidsceneDpi]::SetProcessDpiAwarenessContext($perMonitorAwareV2)) {',
|
|
416
|
-
' [void][MidsceneDpi]::SetProcessDPIAware()',
|
|
417
|
-
' }',
|
|
418
|
-
'} catch {',
|
|
419
|
-
' try { [void][MidsceneDpi]::SetProcessDPIAware() } catch {}',
|
|
420
|
-
'}',
|
|
421
|
-
'Add-Type -AssemblyName System.Windows.Forms',
|
|
422
|
-
'Add-Type -AssemblyName System.Drawing',
|
|
423
|
-
screenSelector,
|
|
424
|
-
'$bounds = $screen.Bounds',
|
|
425
|
-
'$bmp = New-Object System.Drawing.Bitmap($bounds.Width, $bounds.Height)',
|
|
426
|
-
'$g = [System.Drawing.Graphics]::FromImage($bmp)',
|
|
427
|
-
'$g.CopyFromScreen($bounds.Location, [System.Drawing.Point]::Empty, $bounds.Size)',
|
|
428
|
-
`$bmp.Save("${tmpFile}", [System.Drawing.Imaging.ImageFormat]::Png)`,
|
|
429
|
-
'$g.Dispose()',
|
|
430
|
-
'$bmp.Dispose()'
|
|
431
|
-
].join('\n');
|
|
432
|
-
const encodedScript = Buffer.from(psScript, 'utf16le').toString('base64');
|
|
433
|
-
await new Promise((resolve, reject)=>{
|
|
434
|
-
execFile('powershell.exe', [
|
|
435
|
-
'-NoProfile',
|
|
436
|
-
'-NonInteractive',
|
|
437
|
-
'-EncodedCommand',
|
|
438
|
-
encodedScript
|
|
439
|
-
], {
|
|
440
|
-
windowsHide: true,
|
|
441
|
-
timeout: 30000
|
|
442
|
-
}, (err, _stdout, stderr)=>{
|
|
443
|
-
if (err) reject(new Error(`PowerShell screenshot failed: ${stderr || err.message}`));
|
|
444
|
-
else resolve();
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
try {
|
|
448
|
-
return await promises.readFile(tmpFile);
|
|
449
|
-
} finally{
|
|
450
|
-
await promises.unlink(tmpFile).catch((err)=>debugDevice(`Failed to delete temp screenshot file: ${err}`));
|
|
379
|
+
} catch (error) {
|
|
380
|
+
debugDevice(`Screenshot failed: ${error}`);
|
|
381
|
+
throw new Error(`Failed to take screenshot: ${error}`);
|
|
451
382
|
}
|
|
452
383
|
}
|
|
453
384
|
async size() {
|
|
@@ -848,7 +779,7 @@ class ComputerMidsceneTools extends BaseMidsceneTools {
|
|
|
848
779
|
}
|
|
849
780
|
}
|
|
850
781
|
function version() {
|
|
851
|
-
const currentVersion = "1.5.7
|
|
782
|
+
const currentVersion = "1.5.7";
|
|
852
783
|
console.log(`@midscene/computer v${currentVersion}`);
|
|
853
784
|
return currentVersion;
|
|
854
785
|
}
|
package/dist/es/mcp-server.mjs
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { BaseMCPServer, BaseMidsceneTools, createMCPServerLauncher } from "@midscene/shared/mcp";
|
|
2
2
|
import { Agent } from "@midscene/core/agent";
|
|
3
3
|
import node_assert from "node:assert";
|
|
4
|
-
import {
|
|
5
|
-
import { existsSync, promises } from "node:fs";
|
|
4
|
+
import { execSync, spawn } from "node:child_process";
|
|
6
5
|
import { createRequire } from "node:module";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { join } from "node:path";
|
|
9
6
|
import { getMidsceneLocationSchema, z } from "@midscene/core";
|
|
10
7
|
import { actionHoverParamSchema, defineAction, defineActionClearInput, defineActionDoubleClick, defineActionDragAndDrop, defineActionKeyboardPress, defineActionRightClick, defineActionScroll, defineActionTap } from "@midscene/core/device";
|
|
11
8
|
import { sleep } from "@midscene/core/utils";
|
|
12
9
|
import { createImgBase64ByFormat } from "@midscene/shared/img";
|
|
13
10
|
import { getDebug } from "@midscene/shared/logger";
|
|
14
11
|
import screenshot_desktop from "screenshot-desktop";
|
|
12
|
+
import { existsSync } from "node:fs";
|
|
15
13
|
const debugXvfb = getDebug('computer:xvfb');
|
|
16
14
|
function checkXvfbInstalled() {
|
|
17
15
|
try {
|
|
@@ -300,7 +298,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
300
298
|
}
|
|
301
299
|
async healthCheck() {
|
|
302
300
|
console.log('[HealthCheck] Starting health check...');
|
|
303
|
-
console.log("[HealthCheck] @midscene/computer v1.5.7
|
|
301
|
+
console.log("[HealthCheck] @midscene/computer v1.5.7");
|
|
304
302
|
console.log('[HealthCheck] Taking screenshot...');
|
|
305
303
|
const screenshotTimeout = 15000;
|
|
306
304
|
let timeoutId;
|
|
@@ -377,76 +375,9 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
377
375
|
debugDevice('Screenshot options', options);
|
|
378
376
|
const buffer = await screenshot_desktop(options);
|
|
379
377
|
return createImgBase64ByFormat('png', buffer.toString('base64'));
|
|
380
|
-
} catch (
|
|
381
|
-
debugDevice(`Screenshot failed: ${
|
|
382
|
-
|
|
383
|
-
debugDevice('Trying PowerShell fallback for screenshot...');
|
|
384
|
-
try {
|
|
385
|
-
const buffer = await this.screenshotViaWindowsPowerShell();
|
|
386
|
-
return createImgBase64ByFormat('png', buffer.toString('base64'));
|
|
387
|
-
} catch (fallbackError) {
|
|
388
|
-
debugDevice(`PowerShell fallback also failed: ${fallbackError}`);
|
|
389
|
-
throw new Error(`Failed to take screenshot. Primary error: ${primaryError}. Fallback error: ${fallbackError}`);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
throw new Error(`Failed to take screenshot: ${primaryError}`);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
async screenshotViaWindowsPowerShell() {
|
|
396
|
-
const tmpFile = join(tmpdir(), `midscene-screenshot-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.png`);
|
|
397
|
-
const safeDisplayId = this.displayId ? this.displayId.replace(/[^a-zA-Z0-9\\.\-_:]/g, '') : void 0;
|
|
398
|
-
const screenSelector = safeDisplayId ? `$screen = [System.Windows.Forms.Screen]::AllScreens | Where-Object { $_.DeviceName -eq "${safeDisplayId}" }
|
|
399
|
-
if (-not $screen) { $screen = [System.Windows.Forms.Screen]::PrimaryScreen }` : '$screen = [System.Windows.Forms.Screen]::PrimaryScreen';
|
|
400
|
-
const psScript = [
|
|
401
|
-
"Add-Type -TypeDefinition @'",
|
|
402
|
-
'using System;',
|
|
403
|
-
'using System.Runtime.InteropServices;',
|
|
404
|
-
'public static class MidsceneDpi {',
|
|
405
|
-
' [DllImport("user32.dll", SetLastError = true)]',
|
|
406
|
-
' public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);',
|
|
407
|
-
'',
|
|
408
|
-
' [DllImport("user32.dll")]',
|
|
409
|
-
' public static extern bool SetProcessDPIAware();',
|
|
410
|
-
'}',
|
|
411
|
-
"'@",
|
|
412
|
-
'$perMonitorAwareV2 = [IntPtr](-4)',
|
|
413
|
-
'try {',
|
|
414
|
-
' if (-not [MidsceneDpi]::SetProcessDpiAwarenessContext($perMonitorAwareV2)) {',
|
|
415
|
-
' [void][MidsceneDpi]::SetProcessDPIAware()',
|
|
416
|
-
' }',
|
|
417
|
-
'} catch {',
|
|
418
|
-
' try { [void][MidsceneDpi]::SetProcessDPIAware() } catch {}',
|
|
419
|
-
'}',
|
|
420
|
-
'Add-Type -AssemblyName System.Windows.Forms',
|
|
421
|
-
'Add-Type -AssemblyName System.Drawing',
|
|
422
|
-
screenSelector,
|
|
423
|
-
'$bounds = $screen.Bounds',
|
|
424
|
-
'$bmp = New-Object System.Drawing.Bitmap($bounds.Width, $bounds.Height)',
|
|
425
|
-
'$g = [System.Drawing.Graphics]::FromImage($bmp)',
|
|
426
|
-
'$g.CopyFromScreen($bounds.Location, [System.Drawing.Point]::Empty, $bounds.Size)',
|
|
427
|
-
`$bmp.Save("${tmpFile}", [System.Drawing.Imaging.ImageFormat]::Png)`,
|
|
428
|
-
'$g.Dispose()',
|
|
429
|
-
'$bmp.Dispose()'
|
|
430
|
-
].join('\n');
|
|
431
|
-
const encodedScript = Buffer.from(psScript, 'utf16le').toString('base64');
|
|
432
|
-
await new Promise((resolve, reject)=>{
|
|
433
|
-
execFile('powershell.exe', [
|
|
434
|
-
'-NoProfile',
|
|
435
|
-
'-NonInteractive',
|
|
436
|
-
'-EncodedCommand',
|
|
437
|
-
encodedScript
|
|
438
|
-
], {
|
|
439
|
-
windowsHide: true,
|
|
440
|
-
timeout: 30000
|
|
441
|
-
}, (err, _stdout, stderr)=>{
|
|
442
|
-
if (err) reject(new Error(`PowerShell screenshot failed: ${stderr || err.message}`));
|
|
443
|
-
else resolve();
|
|
444
|
-
});
|
|
445
|
-
});
|
|
446
|
-
try {
|
|
447
|
-
return await promises.readFile(tmpFile);
|
|
448
|
-
} finally{
|
|
449
|
-
await promises.unlink(tmpFile).catch((err)=>debugDevice(`Failed to delete temp screenshot file: ${err}`));
|
|
378
|
+
} catch (error) {
|
|
379
|
+
debugDevice(`Screenshot failed: ${error}`);
|
|
380
|
+
throw new Error(`Failed to take screenshot: ${error}`);
|
|
450
381
|
}
|
|
451
382
|
}
|
|
452
383
|
async size() {
|
|
@@ -853,7 +784,7 @@ class ComputerMCPServer extends BaseMCPServer {
|
|
|
853
784
|
constructor(toolsManager){
|
|
854
785
|
super({
|
|
855
786
|
name: '@midscene/computer-mcp',
|
|
856
|
-
version: "1.5.7
|
|
787
|
+
version: "1.5.7",
|
|
857
788
|
description: 'Control the computer desktop using natural language commands'
|
|
858
789
|
}, toolsManager);
|
|
859
790
|
}
|
package/dist/lib/cli.js
CHANGED
|
@@ -32,15 +32,13 @@ const agent_namespaceObject = require("@midscene/core/agent");
|
|
|
32
32
|
const external_node_assert_namespaceObject = require("node:assert");
|
|
33
33
|
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
34
34
|
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
35
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
36
35
|
const external_node_module_namespaceObject = require("node:module");
|
|
37
|
-
const external_node_os_namespaceObject = require("node:os");
|
|
38
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
39
36
|
const device_namespaceObject = require("@midscene/core/device");
|
|
40
37
|
const utils_namespaceObject = require("@midscene/core/utils");
|
|
41
38
|
const img_namespaceObject = require("@midscene/shared/img");
|
|
42
39
|
const external_screenshot_desktop_namespaceObject = require("screenshot-desktop");
|
|
43
40
|
var external_screenshot_desktop_default = /*#__PURE__*/ __webpack_require__.n(external_screenshot_desktop_namespaceObject);
|
|
41
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
44
42
|
const debugXvfb = (0, logger_namespaceObject.getDebug)('computer:xvfb');
|
|
45
43
|
function checkXvfbInstalled() {
|
|
46
44
|
try {
|
|
@@ -329,7 +327,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
329
327
|
}
|
|
330
328
|
async healthCheck() {
|
|
331
329
|
console.log('[HealthCheck] Starting health check...');
|
|
332
|
-
console.log("[HealthCheck] @midscene/computer v1.5.7
|
|
330
|
+
console.log("[HealthCheck] @midscene/computer v1.5.7");
|
|
333
331
|
console.log('[HealthCheck] Taking screenshot...');
|
|
334
332
|
const screenshotTimeout = 15000;
|
|
335
333
|
let timeoutId;
|
|
@@ -406,76 +404,9 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
406
404
|
debugDevice('Screenshot options', options);
|
|
407
405
|
const buffer = await external_screenshot_desktop_default()(options);
|
|
408
406
|
return (0, img_namespaceObject.createImgBase64ByFormat)('png', buffer.toString('base64'));
|
|
409
|
-
} catch (
|
|
410
|
-
debugDevice(`Screenshot failed: ${
|
|
411
|
-
|
|
412
|
-
debugDevice('Trying PowerShell fallback for screenshot...');
|
|
413
|
-
try {
|
|
414
|
-
const buffer = await this.screenshotViaWindowsPowerShell();
|
|
415
|
-
return (0, img_namespaceObject.createImgBase64ByFormat)('png', buffer.toString('base64'));
|
|
416
|
-
} catch (fallbackError) {
|
|
417
|
-
debugDevice(`PowerShell fallback also failed: ${fallbackError}`);
|
|
418
|
-
throw new Error(`Failed to take screenshot. Primary error: ${primaryError}. Fallback error: ${fallbackError}`);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
throw new Error(`Failed to take screenshot: ${primaryError}`);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
async screenshotViaWindowsPowerShell() {
|
|
425
|
-
const tmpFile = (0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), `midscene-screenshot-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.png`);
|
|
426
|
-
const safeDisplayId = this.displayId ? this.displayId.replace(/[^a-zA-Z0-9\\.\-_:]/g, '') : void 0;
|
|
427
|
-
const screenSelector = safeDisplayId ? `$screen = [System.Windows.Forms.Screen]::AllScreens | Where-Object { $_.DeviceName -eq "${safeDisplayId}" }
|
|
428
|
-
if (-not $screen) { $screen = [System.Windows.Forms.Screen]::PrimaryScreen }` : '$screen = [System.Windows.Forms.Screen]::PrimaryScreen';
|
|
429
|
-
const psScript = [
|
|
430
|
-
"Add-Type -TypeDefinition @'",
|
|
431
|
-
'using System;',
|
|
432
|
-
'using System.Runtime.InteropServices;',
|
|
433
|
-
'public static class MidsceneDpi {',
|
|
434
|
-
' [DllImport("user32.dll", SetLastError = true)]',
|
|
435
|
-
' public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);',
|
|
436
|
-
'',
|
|
437
|
-
' [DllImport("user32.dll")]',
|
|
438
|
-
' public static extern bool SetProcessDPIAware();',
|
|
439
|
-
'}',
|
|
440
|
-
"'@",
|
|
441
|
-
'$perMonitorAwareV2 = [IntPtr](-4)',
|
|
442
|
-
'try {',
|
|
443
|
-
' if (-not [MidsceneDpi]::SetProcessDpiAwarenessContext($perMonitorAwareV2)) {',
|
|
444
|
-
' [void][MidsceneDpi]::SetProcessDPIAware()',
|
|
445
|
-
' }',
|
|
446
|
-
'} catch {',
|
|
447
|
-
' try { [void][MidsceneDpi]::SetProcessDPIAware() } catch {}',
|
|
448
|
-
'}',
|
|
449
|
-
'Add-Type -AssemblyName System.Windows.Forms',
|
|
450
|
-
'Add-Type -AssemblyName System.Drawing',
|
|
451
|
-
screenSelector,
|
|
452
|
-
'$bounds = $screen.Bounds',
|
|
453
|
-
'$bmp = New-Object System.Drawing.Bitmap($bounds.Width, $bounds.Height)',
|
|
454
|
-
'$g = [System.Drawing.Graphics]::FromImage($bmp)',
|
|
455
|
-
'$g.CopyFromScreen($bounds.Location, [System.Drawing.Point]::Empty, $bounds.Size)',
|
|
456
|
-
`$bmp.Save("${tmpFile}", [System.Drawing.Imaging.ImageFormat]::Png)`,
|
|
457
|
-
'$g.Dispose()',
|
|
458
|
-
'$bmp.Dispose()'
|
|
459
|
-
].join('\n');
|
|
460
|
-
const encodedScript = Buffer.from(psScript, 'utf16le').toString('base64');
|
|
461
|
-
await new Promise((resolve, reject)=>{
|
|
462
|
-
(0, external_node_child_process_namespaceObject.execFile)('powershell.exe', [
|
|
463
|
-
'-NoProfile',
|
|
464
|
-
'-NonInteractive',
|
|
465
|
-
'-EncodedCommand',
|
|
466
|
-
encodedScript
|
|
467
|
-
], {
|
|
468
|
-
windowsHide: true,
|
|
469
|
-
timeout: 30000
|
|
470
|
-
}, (err, _stdout, stderr)=>{
|
|
471
|
-
if (err) reject(new Error(`PowerShell screenshot failed: ${stderr || err.message}`));
|
|
472
|
-
else resolve();
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
try {
|
|
476
|
-
return await external_node_fs_namespaceObject.promises.readFile(tmpFile);
|
|
477
|
-
} finally{
|
|
478
|
-
await external_node_fs_namespaceObject.promises.unlink(tmpFile).catch((err)=>debugDevice(`Failed to delete temp screenshot file: ${err}`));
|
|
407
|
+
} catch (error) {
|
|
408
|
+
debugDevice(`Screenshot failed: ${error}`);
|
|
409
|
+
throw new Error(`Failed to take screenshot: ${error}`);
|
|
479
410
|
}
|
|
480
411
|
}
|
|
481
412
|
async size() {
|
|
@@ -878,7 +809,7 @@ class ComputerMidsceneTools extends mcp_namespaceObject.BaseMidsceneTools {
|
|
|
878
809
|
const tools = new ComputerMidsceneTools();
|
|
879
810
|
(0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-computer', {
|
|
880
811
|
stripPrefix: 'computer_',
|
|
881
|
-
version: "1.5.7
|
|
812
|
+
version: "1.5.7"
|
|
882
813
|
}).catch((e)=>{
|
|
883
814
|
if (!(e instanceof cli_namespaceObject.CLIError)) console.error(e);
|
|
884
815
|
process.exit(e instanceof cli_namespaceObject.CLIError ? e.exitCode : 1);
|
package/dist/lib/index.js
CHANGED
|
@@ -51,10 +51,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
51
51
|
const external_node_assert_namespaceObject = require("node:assert");
|
|
52
52
|
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
53
53
|
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
54
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
55
54
|
const external_node_module_namespaceObject = require("node:module");
|
|
56
|
-
const external_node_os_namespaceObject = require("node:os");
|
|
57
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
58
55
|
const core_namespaceObject = require("@midscene/core");
|
|
59
56
|
const device_namespaceObject = require("@midscene/core/device");
|
|
60
57
|
const utils_namespaceObject = require("@midscene/core/utils");
|
|
@@ -62,6 +59,7 @@ const img_namespaceObject = require("@midscene/shared/img");
|
|
|
62
59
|
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
63
60
|
const external_screenshot_desktop_namespaceObject = require("screenshot-desktop");
|
|
64
61
|
var external_screenshot_desktop_default = /*#__PURE__*/ __webpack_require__.n(external_screenshot_desktop_namespaceObject);
|
|
62
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
65
63
|
const debugXvfb = (0, logger_namespaceObject.getDebug)('computer:xvfb');
|
|
66
64
|
function checkXvfbInstalled() {
|
|
67
65
|
try {
|
|
@@ -350,7 +348,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
350
348
|
}
|
|
351
349
|
async healthCheck() {
|
|
352
350
|
console.log('[HealthCheck] Starting health check...');
|
|
353
|
-
console.log("[HealthCheck] @midscene/computer v1.5.7
|
|
351
|
+
console.log("[HealthCheck] @midscene/computer v1.5.7");
|
|
354
352
|
console.log('[HealthCheck] Taking screenshot...');
|
|
355
353
|
const screenshotTimeout = 15000;
|
|
356
354
|
let timeoutId;
|
|
@@ -427,76 +425,9 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
427
425
|
debugDevice('Screenshot options', options);
|
|
428
426
|
const buffer = await external_screenshot_desktop_default()(options);
|
|
429
427
|
return (0, img_namespaceObject.createImgBase64ByFormat)('png', buffer.toString('base64'));
|
|
430
|
-
} catch (
|
|
431
|
-
debugDevice(`Screenshot failed: ${
|
|
432
|
-
|
|
433
|
-
debugDevice('Trying PowerShell fallback for screenshot...');
|
|
434
|
-
try {
|
|
435
|
-
const buffer = await this.screenshotViaWindowsPowerShell();
|
|
436
|
-
return (0, img_namespaceObject.createImgBase64ByFormat)('png', buffer.toString('base64'));
|
|
437
|
-
} catch (fallbackError) {
|
|
438
|
-
debugDevice(`PowerShell fallback also failed: ${fallbackError}`);
|
|
439
|
-
throw new Error(`Failed to take screenshot. Primary error: ${primaryError}. Fallback error: ${fallbackError}`);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
throw new Error(`Failed to take screenshot: ${primaryError}`);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
async screenshotViaWindowsPowerShell() {
|
|
446
|
-
const tmpFile = (0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), `midscene-screenshot-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.png`);
|
|
447
|
-
const safeDisplayId = this.displayId ? this.displayId.replace(/[^a-zA-Z0-9\\.\-_:]/g, '') : void 0;
|
|
448
|
-
const screenSelector = safeDisplayId ? `$screen = [System.Windows.Forms.Screen]::AllScreens | Where-Object { $_.DeviceName -eq "${safeDisplayId}" }
|
|
449
|
-
if (-not $screen) { $screen = [System.Windows.Forms.Screen]::PrimaryScreen }` : '$screen = [System.Windows.Forms.Screen]::PrimaryScreen';
|
|
450
|
-
const psScript = [
|
|
451
|
-
"Add-Type -TypeDefinition @'",
|
|
452
|
-
'using System;',
|
|
453
|
-
'using System.Runtime.InteropServices;',
|
|
454
|
-
'public static class MidsceneDpi {',
|
|
455
|
-
' [DllImport("user32.dll", SetLastError = true)]',
|
|
456
|
-
' public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);',
|
|
457
|
-
'',
|
|
458
|
-
' [DllImport("user32.dll")]',
|
|
459
|
-
' public static extern bool SetProcessDPIAware();',
|
|
460
|
-
'}',
|
|
461
|
-
"'@",
|
|
462
|
-
'$perMonitorAwareV2 = [IntPtr](-4)',
|
|
463
|
-
'try {',
|
|
464
|
-
' if (-not [MidsceneDpi]::SetProcessDpiAwarenessContext($perMonitorAwareV2)) {',
|
|
465
|
-
' [void][MidsceneDpi]::SetProcessDPIAware()',
|
|
466
|
-
' }',
|
|
467
|
-
'} catch {',
|
|
468
|
-
' try { [void][MidsceneDpi]::SetProcessDPIAware() } catch {}',
|
|
469
|
-
'}',
|
|
470
|
-
'Add-Type -AssemblyName System.Windows.Forms',
|
|
471
|
-
'Add-Type -AssemblyName System.Drawing',
|
|
472
|
-
screenSelector,
|
|
473
|
-
'$bounds = $screen.Bounds',
|
|
474
|
-
'$bmp = New-Object System.Drawing.Bitmap($bounds.Width, $bounds.Height)',
|
|
475
|
-
'$g = [System.Drawing.Graphics]::FromImage($bmp)',
|
|
476
|
-
'$g.CopyFromScreen($bounds.Location, [System.Drawing.Point]::Empty, $bounds.Size)',
|
|
477
|
-
`$bmp.Save("${tmpFile}", [System.Drawing.Imaging.ImageFormat]::Png)`,
|
|
478
|
-
'$g.Dispose()',
|
|
479
|
-
'$bmp.Dispose()'
|
|
480
|
-
].join('\n');
|
|
481
|
-
const encodedScript = Buffer.from(psScript, 'utf16le').toString('base64');
|
|
482
|
-
await new Promise((resolve, reject)=>{
|
|
483
|
-
(0, external_node_child_process_namespaceObject.execFile)('powershell.exe', [
|
|
484
|
-
'-NoProfile',
|
|
485
|
-
'-NonInteractive',
|
|
486
|
-
'-EncodedCommand',
|
|
487
|
-
encodedScript
|
|
488
|
-
], {
|
|
489
|
-
windowsHide: true,
|
|
490
|
-
timeout: 30000
|
|
491
|
-
}, (err, _stdout, stderr)=>{
|
|
492
|
-
if (err) reject(new Error(`PowerShell screenshot failed: ${stderr || err.message}`));
|
|
493
|
-
else resolve();
|
|
494
|
-
});
|
|
495
|
-
});
|
|
496
|
-
try {
|
|
497
|
-
return await external_node_fs_namespaceObject.promises.readFile(tmpFile);
|
|
498
|
-
} finally{
|
|
499
|
-
await external_node_fs_namespaceObject.promises.unlink(tmpFile).catch((err)=>debugDevice(`Failed to delete temp screenshot file: ${err}`));
|
|
428
|
+
} catch (error) {
|
|
429
|
+
debugDevice(`Screenshot failed: ${error}`);
|
|
430
|
+
throw new Error(`Failed to take screenshot: ${error}`);
|
|
500
431
|
}
|
|
501
432
|
}
|
|
502
433
|
async size() {
|
|
@@ -900,7 +831,7 @@ class ComputerMidsceneTools extends mcp_namespaceObject.BaseMidsceneTools {
|
|
|
900
831
|
}
|
|
901
832
|
const env_namespaceObject = require("@midscene/shared/env");
|
|
902
833
|
function version() {
|
|
903
|
-
const currentVersion = "1.5.7
|
|
834
|
+
const currentVersion = "1.5.7";
|
|
904
835
|
console.log(`@midscene/computer v${currentVersion}`);
|
|
905
836
|
return currentVersion;
|
|
906
837
|
}
|
package/dist/lib/mcp-server.js
CHANGED
|
@@ -45,10 +45,7 @@ const agent_namespaceObject = require("@midscene/core/agent");
|
|
|
45
45
|
const external_node_assert_namespaceObject = require("node:assert");
|
|
46
46
|
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
47
47
|
const external_node_child_process_namespaceObject = require("node:child_process");
|
|
48
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
49
48
|
const external_node_module_namespaceObject = require("node:module");
|
|
50
|
-
const external_node_os_namespaceObject = require("node:os");
|
|
51
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
52
49
|
const core_namespaceObject = require("@midscene/core");
|
|
53
50
|
const device_namespaceObject = require("@midscene/core/device");
|
|
54
51
|
const utils_namespaceObject = require("@midscene/core/utils");
|
|
@@ -56,6 +53,7 @@ const img_namespaceObject = require("@midscene/shared/img");
|
|
|
56
53
|
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
57
54
|
const external_screenshot_desktop_namespaceObject = require("screenshot-desktop");
|
|
58
55
|
var external_screenshot_desktop_default = /*#__PURE__*/ __webpack_require__.n(external_screenshot_desktop_namespaceObject);
|
|
56
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
59
57
|
const debugXvfb = (0, logger_namespaceObject.getDebug)('computer:xvfb');
|
|
60
58
|
function checkXvfbInstalled() {
|
|
61
59
|
try {
|
|
@@ -344,7 +342,7 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
344
342
|
}
|
|
345
343
|
async healthCheck() {
|
|
346
344
|
console.log('[HealthCheck] Starting health check...');
|
|
347
|
-
console.log("[HealthCheck] @midscene/computer v1.5.7
|
|
345
|
+
console.log("[HealthCheck] @midscene/computer v1.5.7");
|
|
348
346
|
console.log('[HealthCheck] Taking screenshot...');
|
|
349
347
|
const screenshotTimeout = 15000;
|
|
350
348
|
let timeoutId;
|
|
@@ -421,76 +419,9 @@ Available Displays: ${displays.length > 0 ? displays.map((d)=>d.name).join(', ')
|
|
|
421
419
|
debugDevice('Screenshot options', options);
|
|
422
420
|
const buffer = await external_screenshot_desktop_default()(options);
|
|
423
421
|
return (0, img_namespaceObject.createImgBase64ByFormat)('png', buffer.toString('base64'));
|
|
424
|
-
} catch (
|
|
425
|
-
debugDevice(`Screenshot failed: ${
|
|
426
|
-
|
|
427
|
-
debugDevice('Trying PowerShell fallback for screenshot...');
|
|
428
|
-
try {
|
|
429
|
-
const buffer = await this.screenshotViaWindowsPowerShell();
|
|
430
|
-
return (0, img_namespaceObject.createImgBase64ByFormat)('png', buffer.toString('base64'));
|
|
431
|
-
} catch (fallbackError) {
|
|
432
|
-
debugDevice(`PowerShell fallback also failed: ${fallbackError}`);
|
|
433
|
-
throw new Error(`Failed to take screenshot. Primary error: ${primaryError}. Fallback error: ${fallbackError}`);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
throw new Error(`Failed to take screenshot: ${primaryError}`);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
async screenshotViaWindowsPowerShell() {
|
|
440
|
-
const tmpFile = (0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), `midscene-screenshot-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.png`);
|
|
441
|
-
const safeDisplayId = this.displayId ? this.displayId.replace(/[^a-zA-Z0-9\\.\-_:]/g, '') : void 0;
|
|
442
|
-
const screenSelector = safeDisplayId ? `$screen = [System.Windows.Forms.Screen]::AllScreens | Where-Object { $_.DeviceName -eq "${safeDisplayId}" }
|
|
443
|
-
if (-not $screen) { $screen = [System.Windows.Forms.Screen]::PrimaryScreen }` : '$screen = [System.Windows.Forms.Screen]::PrimaryScreen';
|
|
444
|
-
const psScript = [
|
|
445
|
-
"Add-Type -TypeDefinition @'",
|
|
446
|
-
'using System;',
|
|
447
|
-
'using System.Runtime.InteropServices;',
|
|
448
|
-
'public static class MidsceneDpi {',
|
|
449
|
-
' [DllImport("user32.dll", SetLastError = true)]',
|
|
450
|
-
' public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);',
|
|
451
|
-
'',
|
|
452
|
-
' [DllImport("user32.dll")]',
|
|
453
|
-
' public static extern bool SetProcessDPIAware();',
|
|
454
|
-
'}',
|
|
455
|
-
"'@",
|
|
456
|
-
'$perMonitorAwareV2 = [IntPtr](-4)',
|
|
457
|
-
'try {',
|
|
458
|
-
' if (-not [MidsceneDpi]::SetProcessDpiAwarenessContext($perMonitorAwareV2)) {',
|
|
459
|
-
' [void][MidsceneDpi]::SetProcessDPIAware()',
|
|
460
|
-
' }',
|
|
461
|
-
'} catch {',
|
|
462
|
-
' try { [void][MidsceneDpi]::SetProcessDPIAware() } catch {}',
|
|
463
|
-
'}',
|
|
464
|
-
'Add-Type -AssemblyName System.Windows.Forms',
|
|
465
|
-
'Add-Type -AssemblyName System.Drawing',
|
|
466
|
-
screenSelector,
|
|
467
|
-
'$bounds = $screen.Bounds',
|
|
468
|
-
'$bmp = New-Object System.Drawing.Bitmap($bounds.Width, $bounds.Height)',
|
|
469
|
-
'$g = [System.Drawing.Graphics]::FromImage($bmp)',
|
|
470
|
-
'$g.CopyFromScreen($bounds.Location, [System.Drawing.Point]::Empty, $bounds.Size)',
|
|
471
|
-
`$bmp.Save("${tmpFile}", [System.Drawing.Imaging.ImageFormat]::Png)`,
|
|
472
|
-
'$g.Dispose()',
|
|
473
|
-
'$bmp.Dispose()'
|
|
474
|
-
].join('\n');
|
|
475
|
-
const encodedScript = Buffer.from(psScript, 'utf16le').toString('base64');
|
|
476
|
-
await new Promise((resolve, reject)=>{
|
|
477
|
-
(0, external_node_child_process_namespaceObject.execFile)('powershell.exe', [
|
|
478
|
-
'-NoProfile',
|
|
479
|
-
'-NonInteractive',
|
|
480
|
-
'-EncodedCommand',
|
|
481
|
-
encodedScript
|
|
482
|
-
], {
|
|
483
|
-
windowsHide: true,
|
|
484
|
-
timeout: 30000
|
|
485
|
-
}, (err, _stdout, stderr)=>{
|
|
486
|
-
if (err) reject(new Error(`PowerShell screenshot failed: ${stderr || err.message}`));
|
|
487
|
-
else resolve();
|
|
488
|
-
});
|
|
489
|
-
});
|
|
490
|
-
try {
|
|
491
|
-
return await external_node_fs_namespaceObject.promises.readFile(tmpFile);
|
|
492
|
-
} finally{
|
|
493
|
-
await external_node_fs_namespaceObject.promises.unlink(tmpFile).catch((err)=>debugDevice(`Failed to delete temp screenshot file: ${err}`));
|
|
422
|
+
} catch (error) {
|
|
423
|
+
debugDevice(`Screenshot failed: ${error}`);
|
|
424
|
+
throw new Error(`Failed to take screenshot: ${error}`);
|
|
494
425
|
}
|
|
495
426
|
}
|
|
496
427
|
async size() {
|
|
@@ -897,7 +828,7 @@ class ComputerMCPServer extends mcp_namespaceObject.BaseMCPServer {
|
|
|
897
828
|
constructor(toolsManager){
|
|
898
829
|
super({
|
|
899
830
|
name: '@midscene/computer-mcp',
|
|
900
|
-
version: "1.5.7
|
|
831
|
+
version: "1.5.7",
|
|
901
832
|
description: 'Control the computer desktop using natural language commands'
|
|
902
833
|
}, toolsManager);
|
|
903
834
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -70,12 +70,6 @@ export declare class ComputerDevice implements AbstractInterface {
|
|
|
70
70
|
*/
|
|
71
71
|
private isRunningAsAdmin;
|
|
72
72
|
screenshotBase64(): Promise<string>;
|
|
73
|
-
/**
|
|
74
|
-
* Windows-specific screenshot fallback using PowerShell and System.Drawing.
|
|
75
|
-
* Used when screenshot-desktop's screenCapture.exe cannot be executed
|
|
76
|
-
* (e.g. blocked by security policies in environments like Claude Code).
|
|
77
|
-
*/
|
|
78
|
-
private screenshotViaWindowsPowerShell;
|
|
79
73
|
size(): Promise<Size>;
|
|
80
74
|
/**
|
|
81
75
|
* Type text via clipboard (paste)
|
|
@@ -41,12 +41,6 @@ declare class ComputerDevice implements AbstractInterface {
|
|
|
41
41
|
*/
|
|
42
42
|
private isRunningAsAdmin;
|
|
43
43
|
screenshotBase64(): Promise<string>;
|
|
44
|
-
/**
|
|
45
|
-
* Windows-specific screenshot fallback using PowerShell and System.Drawing.
|
|
46
|
-
* Used when screenshot-desktop's screenCapture.exe cannot be executed
|
|
47
|
-
* (e.g. blocked by security policies in environments like Claude Code).
|
|
48
|
-
*/
|
|
49
|
-
private screenshotViaWindowsPowerShell;
|
|
50
44
|
size(): Promise<Size>;
|
|
51
45
|
/**
|
|
52
46
|
* Type text via clipboard (paste)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/computer",
|
|
3
|
-
"version": "1.5.7
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "Midscene.js Computer Desktop Automation",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"@computer-use/libnut": "^4.2.0",
|
|
37
37
|
"clipboardy": "^4.0.0",
|
|
38
38
|
"screenshot-desktop": "^1.15.3",
|
|
39
|
-
"@midscene/
|
|
40
|
-
"@midscene/
|
|
39
|
+
"@midscene/core": "1.5.7",
|
|
40
|
+
"@midscene/shared": "1.5.7"
|
|
41
41
|
},
|
|
42
42
|
"optionalDependencies": {
|
|
43
43
|
"node-mac-permissions": "2.5.0"
|