@midscene/computer 1.2.1-beta-20260112081017.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/LICENSE +21 -0
- package/README.md +243 -0
- package/dist/es/index.mjs +438 -0
- package/dist/es/mcp-server.mjs +508 -0
- package/dist/lib/index.js +498 -0
- package/dist/lib/mcp-server.js +559 -0
- package/dist/types/index.d.ts +70 -0
- package/dist/types/mcp-server.d.ts +88 -0
- package/package.json +48 -0
- package/rslib.config.ts +26 -0
- package/src/agent.ts +17 -0
- package/src/device.ts +554 -0
- package/src/index.ts +8 -0
- package/src/mcp-server.ts +65 -0
- package/src/mcp-tools.ts +96 -0
- package/src/types/libnut.d.ts +36 -0
- package/src/utils.ts +51 -0
- package/tests/ai/ai-auto-todo.test.ts +85 -0
- package/tests/ai/ai-shop.test.ts +56 -0
- package/tests/ai/basic.test.ts +46 -0
- package/tests/ai/keyboard.test.ts +66 -0
- package/tests/ai/multi-display.test.ts +76 -0
- package/tests/ai/test-utils.ts +31 -0
- package/tests/ai/web-browser.test.ts +63 -0
- package/tests/unit-test/agent.test.ts +34 -0
- package/tests/unit-test/device.test.ts +53 -0
- package/tsconfig.json +18 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +47 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AbstractInterface } from '@midscene/core/device';
|
|
2
|
+
import { Agent } from '@midscene/core/agent';
|
|
3
|
+
import { BaseMCPServer } from '@midscene/shared/mcp';
|
|
4
|
+
import { BaseMidsceneTools } from '@midscene/shared/mcp';
|
|
5
|
+
import { DeviceAction } from '@midscene/core';
|
|
6
|
+
import { InterfaceType } from '@midscene/core';
|
|
7
|
+
import { LaunchMCPServerOptions } from '@midscene/shared/mcp';
|
|
8
|
+
import { LaunchMCPServerResult } from '@midscene/shared/mcp';
|
|
9
|
+
import { Size } from '@midscene/core';
|
|
10
|
+
import { Tool } from '@midscene/shared/mcp';
|
|
11
|
+
import { ToolDefinition } from '@midscene/shared/mcp';
|
|
12
|
+
|
|
13
|
+
declare class ComputerAgent extends Agent<ComputerDevice> {
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class ComputerDevice implements AbstractInterface {
|
|
17
|
+
interfaceType: InterfaceType;
|
|
18
|
+
private options?;
|
|
19
|
+
private displayId?;
|
|
20
|
+
private description?;
|
|
21
|
+
private destroyed;
|
|
22
|
+
uri?: string;
|
|
23
|
+
constructor(options?: ComputerDeviceOpt);
|
|
24
|
+
describe(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get all available displays
|
|
27
|
+
*/
|
|
28
|
+
static listDisplays(): Promise<DisplayInfo[]>;
|
|
29
|
+
connect(): Promise<void>;
|
|
30
|
+
screenshotBase64(): Promise<string>;
|
|
31
|
+
size(): Promise<Size>;
|
|
32
|
+
actionSpace(): DeviceAction<any>[];
|
|
33
|
+
destroy(): Promise<void>;
|
|
34
|
+
url(): Promise<string>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare interface ComputerDeviceOpt {
|
|
38
|
+
displayId?: string;
|
|
39
|
+
customActions?: DeviceAction<any>[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Computer MCP Server
|
|
44
|
+
* Provides MCP tools for computer desktop automation
|
|
45
|
+
*/
|
|
46
|
+
export declare class ComputerMCPServer extends BaseMCPServer {
|
|
47
|
+
constructor(toolsManager?: ComputerMidsceneTools);
|
|
48
|
+
protected createToolsManager(): ComputerMidsceneTools;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Computer-specific tools manager
|
|
53
|
+
* Extends BaseMidsceneTools to provide desktop automation tools
|
|
54
|
+
*/
|
|
55
|
+
declare class ComputerMidsceneTools extends BaseMidsceneTools<ComputerAgent> {
|
|
56
|
+
protected createTemporaryDevice(): ComputerDevice;
|
|
57
|
+
protected ensureAgent(displayId?: string): Promise<ComputerAgent>;
|
|
58
|
+
/**
|
|
59
|
+
* Provide Computer-specific platform tools
|
|
60
|
+
*/
|
|
61
|
+
protected preparePlatformTools(): ToolDefinition[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare interface DisplayInfo {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
primary?: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Create MCP kit for a specific Computer Agent
|
|
72
|
+
*/
|
|
73
|
+
export declare function mcpKitForAgent(agent: Agent | ComputerAgent): Promise<{
|
|
74
|
+
description: string;
|
|
75
|
+
tools: Tool[];
|
|
76
|
+
}>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Create an MCP server launcher for a specific Computer Agent
|
|
80
|
+
*/
|
|
81
|
+
export declare function mcpServerForAgent(agent: Agent | ComputerAgent): {
|
|
82
|
+
launch(options?: {
|
|
83
|
+
verbose?: boolean;
|
|
84
|
+
}): Promise<LaunchMCPServerResult>;
|
|
85
|
+
launchHttp(options: LaunchMCPServerOptions): Promise<LaunchMCPServerResult>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export { }
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@midscene/computer",
|
|
3
|
+
"version": "1.2.1-beta-20260112081017.0",
|
|
4
|
+
"description": "Midscene.js Computer Desktop Automation",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/web-infra-dev/midscene.git",
|
|
9
|
+
"directory": "packages/computer"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/lib/index.js",
|
|
12
|
+
"module": "./dist/es/index.mjs",
|
|
13
|
+
"types": "./dist/types/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/types/index.d.ts",
|
|
17
|
+
"import": "./dist/es/index.mjs",
|
|
18
|
+
"require": "./dist/lib/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./mcp-server": {
|
|
21
|
+
"types": "./dist/types/mcp-server.d.ts",
|
|
22
|
+
"import": "./dist/es/mcp-server.mjs",
|
|
23
|
+
"require": "./dist/lib/mcp-server.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@computer-use/libnut": "^4.2.0",
|
|
29
|
+
"screenshot-desktop": "^1.15.3",
|
|
30
|
+
"@midscene/core": "1.2.1-beta-20260112081017.0",
|
|
31
|
+
"@midscene/shared": "1.2.1-beta-20260112081017.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@rslib/core": "^0.18.3",
|
|
35
|
+
"@types/node": "^18.0.0",
|
|
36
|
+
"@types/screenshot-desktop": "1.15.0",
|
|
37
|
+
"dotenv": "^16.4.5",
|
|
38
|
+
"tsx": "^4.19.2",
|
|
39
|
+
"typescript": "^5.8.3",
|
|
40
|
+
"vitest": "3.0.5"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "rslib build",
|
|
44
|
+
"dev": "rslib build --watch",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"test:ai": "AI_TEST_TYPE=computer vitest run"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/rslib.config.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineConfig } from '@rslib/core';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
lib: [
|
|
5
|
+
{
|
|
6
|
+
output: { distPath: { root: 'dist/lib' } },
|
|
7
|
+
format: 'cjs',
|
|
8
|
+
syntax: 'es2020',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
output: { distPath: { root: 'dist/es' } },
|
|
12
|
+
dts: {
|
|
13
|
+
bundle: true,
|
|
14
|
+
distPath: 'dist/types',
|
|
15
|
+
},
|
|
16
|
+
format: 'esm',
|
|
17
|
+
syntax: 'es2020',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
source: {
|
|
21
|
+
entry: {
|
|
22
|
+
index: './src/index.ts',
|
|
23
|
+
'mcp-server': './src/mcp-server.ts',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
package/src/agent.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AgentOpt, Agent as PageAgent } from '@midscene/core/agent';
|
|
2
|
+
import { ComputerDevice, type ComputerDeviceOpt } from './device';
|
|
3
|
+
|
|
4
|
+
export type ComputerAgentOpt = AgentOpt & ComputerDeviceOpt;
|
|
5
|
+
|
|
6
|
+
export class ComputerAgent extends PageAgent<ComputerDevice> {}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create an Agent from computer
|
|
10
|
+
*/
|
|
11
|
+
export async function agentFromComputer(
|
|
12
|
+
opts?: ComputerAgentOpt,
|
|
13
|
+
): Promise<ComputerAgent> {
|
|
14
|
+
const device = new ComputerDevice(opts || {});
|
|
15
|
+
await device.connect();
|
|
16
|
+
return new ComputerAgent(device, opts);
|
|
17
|
+
}
|