@midscene/shared 1.0.1-beta-20251208071759.0 → 1.0.1-beta-20251208085324.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/node/fs.mjs +1 -1
- package/dist/lib/baseDB.js +2 -2
- package/dist/lib/build/copy-static.js +2 -2
- package/dist/lib/build/rspack-config.js +2 -2
- package/dist/lib/common.js +2 -2
- package/dist/lib/constants/example-code.js +2 -2
- package/dist/lib/constants/index.js +2 -2
- package/dist/lib/env/basic.js +2 -2
- package/dist/lib/env/constants.js +2 -2
- package/dist/lib/env/global-config-manager.js +2 -2
- package/dist/lib/env/helper.js +2 -2
- package/dist/lib/env/index.js +6 -6
- package/dist/lib/env/init-debug.js +2 -2
- package/dist/lib/env/model-config-manager.js +2 -2
- package/dist/lib/env/parse-model-config.js +2 -2
- package/dist/lib/env/types.js +2 -2
- package/dist/lib/env/utils.js +2 -2
- package/dist/lib/extractor/constants.js +2 -2
- package/dist/lib/extractor/debug.js +1 -1
- package/dist/lib/extractor/dom-util.js +2 -2
- package/dist/lib/extractor/index.js +2 -2
- package/dist/lib/extractor/locator.js +2 -2
- package/dist/lib/extractor/tree.js +2 -2
- package/dist/lib/extractor/util.js +2 -2
- package/dist/lib/extractor/web-extractor.js +2 -2
- package/dist/lib/img/box-select.js +2 -2
- package/dist/lib/img/draw-box.js +2 -2
- package/dist/lib/img/get-jimp.js +2 -2
- package/dist/lib/img/get-photon.js +2 -2
- package/dist/lib/img/get-sharp.js +2 -2
- package/dist/lib/img/index.js +2 -2
- package/dist/lib/img/info.js +2 -2
- package/dist/lib/img/transform.js +2 -2
- package/dist/lib/index.js +2 -2
- package/dist/lib/logger.js +2 -2
- package/dist/lib/node/fs.js +3 -3
- package/dist/lib/node/index.js +2 -2
- package/dist/lib/polyfills/async-hooks.js +2 -2
- package/dist/lib/polyfills/index.js +2 -2
- package/dist/lib/types/index.js +2 -2
- package/dist/lib/us-keyboard-layout.js +2 -2
- package/dist/lib/utils.js +2 -2
- package/package.json +3 -17
- package/dist/es/mcp/base-server.mjs +0 -250
- package/dist/es/mcp/base-tools.mjs +0 -84
- package/dist/es/mcp/index.mjs +0 -5
- package/dist/es/mcp/inject-report-html-plugin.mjs +0 -53
- package/dist/es/mcp/tool-generator.mjs +0 -215
- package/dist/es/mcp/types.mjs +0 -3
- package/dist/lib/mcp/base-server.js +0 -290
- package/dist/lib/mcp/base-tools.js +0 -118
- package/dist/lib/mcp/index.js +0 -86
- package/dist/lib/mcp/inject-report-html-plugin.js +0 -98
- package/dist/lib/mcp/tool-generator.js +0 -252
- package/dist/lib/mcp/types.js +0 -40
- package/dist/types/mcp/base-server.d.ts +0 -77
- package/dist/types/mcp/base-tools.d.ts +0 -51
- package/dist/types/mcp/index.d.ts +0 -5
- package/dist/types/mcp/inject-report-html-plugin.d.ts +0 -18
- package/dist/types/mcp/tool-generator.d.ts +0 -11
- package/dist/types/mcp/types.d.ts +0 -99
- package/src/mcp/base-server.ts +0 -432
- package/src/mcp/base-tools.ts +0 -190
- package/src/mcp/index.ts +0 -5
- package/src/mcp/inject-report-html-plugin.ts +0 -119
- package/src/mcp/tool-generator.ts +0 -311
- package/src/mcp/types.ts +0 -107
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
generateToolsFromActionSpace: ()=>generateToolsFromActionSpace,
|
|
28
|
-
generateCommonTools: ()=>generateCommonTools
|
|
29
|
-
});
|
|
30
|
-
const img_namespaceObject = require("@midscene/shared/img");
|
|
31
|
-
const external_zod_namespaceObject = require("zod");
|
|
32
|
-
function getErrorMessage(error) {
|
|
33
|
-
return error instanceof Error ? error.message : String(error);
|
|
34
|
-
}
|
|
35
|
-
function isZodOptional(value) {
|
|
36
|
-
return '_def' in value && value._def?.typeName === 'ZodOptional';
|
|
37
|
-
}
|
|
38
|
-
function isZodObject(value) {
|
|
39
|
-
return '_def' in value && value._def?.typeName === 'ZodObject' && 'shape' in value;
|
|
40
|
-
}
|
|
41
|
-
function unwrapOptional(value) {
|
|
42
|
-
if (isZodOptional(value)) return {
|
|
43
|
-
innerValue: value._def.innerType,
|
|
44
|
-
isOptional: true
|
|
45
|
-
};
|
|
46
|
-
return {
|
|
47
|
-
innerValue: value,
|
|
48
|
-
isOptional: false
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function isLocateField(value) {
|
|
52
|
-
if (!isZodObject(value)) return false;
|
|
53
|
-
return 'prompt' in value.shape;
|
|
54
|
-
}
|
|
55
|
-
function makePromptOptional(value, wrapInOptional) {
|
|
56
|
-
const newShape = {
|
|
57
|
-
...value.shape
|
|
58
|
-
};
|
|
59
|
-
newShape.prompt = value.shape.prompt.optional();
|
|
60
|
-
let newSchema = external_zod_namespaceObject.z.object(newShape).passthrough();
|
|
61
|
-
if (wrapInOptional) newSchema = newSchema.optional();
|
|
62
|
-
return newSchema;
|
|
63
|
-
}
|
|
64
|
-
function transformSchemaField(key, value) {
|
|
65
|
-
const { innerValue, isOptional } = unwrapOptional(value);
|
|
66
|
-
if (isZodObject(innerValue) && isLocateField(innerValue)) return [
|
|
67
|
-
key,
|
|
68
|
-
makePromptOptional(innerValue, isOptional)
|
|
69
|
-
];
|
|
70
|
-
return [
|
|
71
|
-
key,
|
|
72
|
-
value
|
|
73
|
-
];
|
|
74
|
-
}
|
|
75
|
-
function extractActionSchema(paramSchema) {
|
|
76
|
-
if (!paramSchema) return {};
|
|
77
|
-
const schema = paramSchema;
|
|
78
|
-
if (!isZodObject(schema)) return schema;
|
|
79
|
-
return Object.fromEntries(Object.entries(schema.shape).map(([key, value])=>transformSchemaField(key, value)));
|
|
80
|
-
}
|
|
81
|
-
function serializeArgsToDescription(args) {
|
|
82
|
-
try {
|
|
83
|
-
return Object.entries(args).map(([key, value])=>{
|
|
84
|
-
if ('object' == typeof value && null !== value) try {
|
|
85
|
-
return `${key}: ${JSON.stringify(value)}`;
|
|
86
|
-
} catch {
|
|
87
|
-
return `${key}: [object]`;
|
|
88
|
-
}
|
|
89
|
-
return `${key}: "${value}"`;
|
|
90
|
-
}).join(', ');
|
|
91
|
-
} catch (error) {
|
|
92
|
-
const errorMessage = getErrorMessage(error);
|
|
93
|
-
console.error('Error serializing args:', errorMessage);
|
|
94
|
-
return `[args serialization failed: ${errorMessage}]`;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function buildActionInstruction(actionName, args) {
|
|
98
|
-
const argsDescription = serializeArgsToDescription(args);
|
|
99
|
-
return argsDescription ? `Use the action "${actionName}" with ${argsDescription}` : `Use the action "${actionName}"`;
|
|
100
|
-
}
|
|
101
|
-
async function captureScreenshotResult(agent, actionName) {
|
|
102
|
-
try {
|
|
103
|
-
const screenshot = await agent.page?.screenshotBase64();
|
|
104
|
-
if (!screenshot) return {
|
|
105
|
-
content: [
|
|
106
|
-
{
|
|
107
|
-
type: 'text',
|
|
108
|
-
text: `Action "${actionName}" completed.`
|
|
109
|
-
}
|
|
110
|
-
]
|
|
111
|
-
};
|
|
112
|
-
const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
|
|
113
|
-
return {
|
|
114
|
-
content: [
|
|
115
|
-
{
|
|
116
|
-
type: 'text',
|
|
117
|
-
text: `Action "${actionName}" completed.`
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
type: 'image',
|
|
121
|
-
data: body,
|
|
122
|
-
mimeType
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
};
|
|
126
|
-
} catch (error) {
|
|
127
|
-
const errorMessage = getErrorMessage(error);
|
|
128
|
-
console.error('Error capturing screenshot:', errorMessage);
|
|
129
|
-
return {
|
|
130
|
-
content: [
|
|
131
|
-
{
|
|
132
|
-
type: 'text',
|
|
133
|
-
text: `Action "${actionName}" completed (screenshot unavailable: ${errorMessage})`
|
|
134
|
-
}
|
|
135
|
-
]
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function createErrorResult(message) {
|
|
140
|
-
return {
|
|
141
|
-
content: [
|
|
142
|
-
{
|
|
143
|
-
type: 'text',
|
|
144
|
-
text: message
|
|
145
|
-
}
|
|
146
|
-
],
|
|
147
|
-
isError: true
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
function generateToolsFromActionSpace(actionSpace, getAgent) {
|
|
151
|
-
return actionSpace.map((action)=>{
|
|
152
|
-
const schema = extractActionSchema(action.paramSchema);
|
|
153
|
-
return {
|
|
154
|
-
name: action.name,
|
|
155
|
-
description: action.description || `Execute ${action.name} action`,
|
|
156
|
-
schema,
|
|
157
|
-
handler: async (args)=>{
|
|
158
|
-
try {
|
|
159
|
-
const agent = await getAgent();
|
|
160
|
-
if (agent.aiAction) {
|
|
161
|
-
const instruction = buildActionInstruction(action.name, args);
|
|
162
|
-
try {
|
|
163
|
-
await agent.aiAction(instruction);
|
|
164
|
-
} catch (error) {
|
|
165
|
-
const errorMessage = getErrorMessage(error);
|
|
166
|
-
console.error(`Error executing action "${action.name}":`, errorMessage);
|
|
167
|
-
return createErrorResult(`Failed to execute action "${action.name}": ${errorMessage}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return await captureScreenshotResult(agent, action.name);
|
|
171
|
-
} catch (error) {
|
|
172
|
-
const errorMessage = getErrorMessage(error);
|
|
173
|
-
console.error(`Error in handler for "${action.name}":`, errorMessage);
|
|
174
|
-
return createErrorResult(`Failed to get agent or execute action "${action.name}": ${errorMessage}`);
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
autoDestroy: true
|
|
178
|
-
};
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
function generateCommonTools(getAgent) {
|
|
182
|
-
return [
|
|
183
|
-
{
|
|
184
|
-
name: 'take_screenshot',
|
|
185
|
-
description: 'Capture screenshot of current page/screen',
|
|
186
|
-
schema: {},
|
|
187
|
-
handler: async ()=>{
|
|
188
|
-
try {
|
|
189
|
-
const agent = await getAgent();
|
|
190
|
-
const screenshot = await agent.page?.screenshotBase64();
|
|
191
|
-
if (!screenshot) return createErrorResult('Screenshot not available');
|
|
192
|
-
const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
|
|
193
|
-
return {
|
|
194
|
-
content: [
|
|
195
|
-
{
|
|
196
|
-
type: 'image',
|
|
197
|
-
data: body,
|
|
198
|
-
mimeType
|
|
199
|
-
}
|
|
200
|
-
]
|
|
201
|
-
};
|
|
202
|
-
} catch (error) {
|
|
203
|
-
const errorMessage = getErrorMessage(error);
|
|
204
|
-
console.error('Error taking screenshot:', errorMessage);
|
|
205
|
-
return createErrorResult(`Failed to capture screenshot: ${errorMessage}`);
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
autoDestroy: true
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
name: 'wait_for',
|
|
212
|
-
description: 'Wait until condition becomes true',
|
|
213
|
-
schema: {
|
|
214
|
-
assertion: external_zod_namespaceObject.z.string().describe('Condition to wait for'),
|
|
215
|
-
timeoutMs: external_zod_namespaceObject.z.number().optional().default(15000),
|
|
216
|
-
checkIntervalMs: external_zod_namespaceObject.z.number().optional().default(3000)
|
|
217
|
-
},
|
|
218
|
-
handler: async (args)=>{
|
|
219
|
-
try {
|
|
220
|
-
const agent = await getAgent();
|
|
221
|
-
const { assertion, timeoutMs, checkIntervalMs } = args;
|
|
222
|
-
if (agent.aiWaitFor) await agent.aiWaitFor(assertion, {
|
|
223
|
-
timeoutMs,
|
|
224
|
-
checkIntervalMs
|
|
225
|
-
});
|
|
226
|
-
return {
|
|
227
|
-
content: [
|
|
228
|
-
{
|
|
229
|
-
type: 'text',
|
|
230
|
-
text: `Condition met: "${assertion}"`
|
|
231
|
-
}
|
|
232
|
-
]
|
|
233
|
-
};
|
|
234
|
-
} catch (error) {
|
|
235
|
-
const errorMessage = getErrorMessage(error);
|
|
236
|
-
console.error('Error in wait_for:', errorMessage);
|
|
237
|
-
return createErrorResult(`Wait condition failed: ${errorMessage}`);
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
autoDestroy: true
|
|
241
|
-
}
|
|
242
|
-
];
|
|
243
|
-
}
|
|
244
|
-
exports.generateCommonTools = __webpack_exports__.generateCommonTools;
|
|
245
|
-
exports.generateToolsFromActionSpace = __webpack_exports__.generateToolsFromActionSpace;
|
|
246
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
247
|
-
"generateCommonTools",
|
|
248
|
-
"generateToolsFromActionSpace"
|
|
249
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
250
|
-
Object.defineProperty(exports, '__esModule', {
|
|
251
|
-
value: true
|
|
252
|
-
});
|
package/dist/lib/mcp/types.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
defaultAppLoadingCheckIntervalMs: ()=>defaultAppLoadingCheckIntervalMs,
|
|
28
|
-
defaultAppLoadingTimeoutMs: ()=>defaultAppLoadingTimeoutMs
|
|
29
|
-
});
|
|
30
|
-
const defaultAppLoadingTimeoutMs = 10000;
|
|
31
|
-
const defaultAppLoadingCheckIntervalMs = 2000;
|
|
32
|
-
exports.defaultAppLoadingCheckIntervalMs = __webpack_exports__.defaultAppLoadingCheckIntervalMs;
|
|
33
|
-
exports.defaultAppLoadingTimeoutMs = __webpack_exports__.defaultAppLoadingTimeoutMs;
|
|
34
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
35
|
-
"defaultAppLoadingCheckIntervalMs",
|
|
36
|
-
"defaultAppLoadingTimeoutMs"
|
|
37
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
38
|
-
Object.defineProperty(exports, '__esModule', {
|
|
39
|
-
value: true
|
|
40
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { ParseArgsConfig } from 'node:util';
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import type { IMidsceneTools } from './types';
|
|
4
|
-
export interface BaseMCPServerConfig {
|
|
5
|
-
name: string;
|
|
6
|
-
version: string;
|
|
7
|
-
description: string;
|
|
8
|
-
}
|
|
9
|
-
export interface HttpLaunchOptions {
|
|
10
|
-
port: number;
|
|
11
|
-
host?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* CLI argument configuration for MCP servers
|
|
15
|
-
*/
|
|
16
|
-
export declare const CLI_ARGS_CONFIG: ParseArgsConfig['options'];
|
|
17
|
-
export interface CLIArgs {
|
|
18
|
-
mode?: string;
|
|
19
|
-
port?: string;
|
|
20
|
-
host?: string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Launch an MCP server based on CLI arguments
|
|
24
|
-
* Shared helper to reduce duplication across platform CLI entry points
|
|
25
|
-
*/
|
|
26
|
-
export declare function launchMCPServer(server: BaseMCPServer, args: CLIArgs): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Base MCP Server class with programmatic launch() API
|
|
29
|
-
* Each platform extends this to provide their own tools manager
|
|
30
|
-
*/
|
|
31
|
-
export declare abstract class BaseMCPServer {
|
|
32
|
-
protected mcpServer: McpServer;
|
|
33
|
-
protected toolsManager?: IMidsceneTools;
|
|
34
|
-
protected config: BaseMCPServerConfig;
|
|
35
|
-
constructor(config: BaseMCPServerConfig);
|
|
36
|
-
/**
|
|
37
|
-
* Platform-specific: create tools manager instance
|
|
38
|
-
*/
|
|
39
|
-
protected abstract createToolsManager(): IMidsceneTools;
|
|
40
|
-
/**
|
|
41
|
-
* Initialize tools manager and attach to MCP server
|
|
42
|
-
*/
|
|
43
|
-
private initializeToolsManager;
|
|
44
|
-
/**
|
|
45
|
-
* Perform cleanup on shutdown
|
|
46
|
-
*/
|
|
47
|
-
private performCleanup;
|
|
48
|
-
/**
|
|
49
|
-
* Initialize and launch the MCP server with stdio transport
|
|
50
|
-
*/
|
|
51
|
-
launch(): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* Launch MCP server with HTTP transport
|
|
54
|
-
* Supports stateful sessions for web applications and service integration
|
|
55
|
-
*/
|
|
56
|
-
launchHttp(options: HttpLaunchOptions): Promise<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Create a new HTTP session with transport
|
|
59
|
-
*/
|
|
60
|
-
private createHttpSession;
|
|
61
|
-
/**
|
|
62
|
-
* Start periodic session cleanup for inactive sessions
|
|
63
|
-
*/
|
|
64
|
-
private startSessionCleanup;
|
|
65
|
-
/**
|
|
66
|
-
* Setup shutdown handlers for HTTP server
|
|
67
|
-
*/
|
|
68
|
-
private setupHttpShutdownHandlers;
|
|
69
|
-
/**
|
|
70
|
-
* Get the underlying MCP server instance
|
|
71
|
-
*/
|
|
72
|
-
getServer(): McpServer;
|
|
73
|
-
/**
|
|
74
|
-
* Get the tools manager instance
|
|
75
|
-
*/
|
|
76
|
-
getToolsManager(): IMidsceneTools | undefined;
|
|
77
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import type { BaseAgent, BaseDevice, IMidsceneTools, ToolDefinition } from './types';
|
|
3
|
-
export declare abstract class BaseMidsceneTools implements IMidsceneTools {
|
|
4
|
-
protected mcpServer?: McpServer;
|
|
5
|
-
protected agent?: BaseAgent;
|
|
6
|
-
protected toolDefinitions: ToolDefinition[];
|
|
7
|
-
/**
|
|
8
|
-
* Ensure agent is initialized and ready for use.
|
|
9
|
-
* Must be implemented by subclasses to create platform-specific agent.
|
|
10
|
-
* @param initParam Optional initialization parameter (platform-specific, e.g., URL, device ID)
|
|
11
|
-
* @returns Promise resolving to initialized agent instance
|
|
12
|
-
* @throws Error if agent initialization fails
|
|
13
|
-
*/
|
|
14
|
-
protected abstract ensureAgent(initParam?: string): Promise<BaseAgent>;
|
|
15
|
-
/**
|
|
16
|
-
* Optional: prepare platform-specific tools (e.g., device connection)
|
|
17
|
-
*/
|
|
18
|
-
protected preparePlatformTools(): ToolDefinition[];
|
|
19
|
-
/**
|
|
20
|
-
* Must be implemented by subclasses to create a temporary device instance
|
|
21
|
-
* This allows getting real actionSpace without connecting to device
|
|
22
|
-
*/
|
|
23
|
-
protected abstract createTemporaryDevice(): BaseDevice;
|
|
24
|
-
/**
|
|
25
|
-
* Initialize all tools by querying actionSpace
|
|
26
|
-
* Uses two-layer fallback strategy:
|
|
27
|
-
* 1. Try to get actionSpace from connected agent (if available)
|
|
28
|
-
* 2. Create temporary device instance to read actionSpace (always succeeds)
|
|
29
|
-
*/
|
|
30
|
-
initTools(): Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Attach to MCP server and register all tools
|
|
33
|
-
*/
|
|
34
|
-
attachToServer(server: McpServer): void;
|
|
35
|
-
/**
|
|
36
|
-
* Wrapper for auto-destroy behavior
|
|
37
|
-
*/
|
|
38
|
-
private toolWithAutoDestroy;
|
|
39
|
-
/**
|
|
40
|
-
* Cleanup method - destroy agent and release resources
|
|
41
|
-
*/
|
|
42
|
-
closeBrowser(): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Helper: Convert base64 screenshot to image content array
|
|
45
|
-
*/
|
|
46
|
-
protected buildScreenshotContent(screenshot: string): {
|
|
47
|
-
type: "image";
|
|
48
|
-
data: string;
|
|
49
|
-
mimeType: string;
|
|
50
|
-
}[];
|
|
51
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
interface RslibPluginApi {
|
|
2
|
-
onAfterBuild: (callback: () => void) => void;
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Rslib plugin to inject report HTML from @midscene/core dist into MCP bundle.
|
|
6
|
-
* This runs after build and reads the already-injected HTML from core.
|
|
7
|
-
*
|
|
8
|
-
* Prerequisites:
|
|
9
|
-
* - @midscene/report must be in devDependencies to ensure correct build order
|
|
10
|
-
* - @midscene/core dist must exist with injected HTML
|
|
11
|
-
*
|
|
12
|
-
* @param packageDir - The directory of the MCP package (use __dirname)
|
|
13
|
-
*/
|
|
14
|
-
export declare function injectReportHtmlFromCore(packageDir: string): {
|
|
15
|
-
name: string;
|
|
16
|
-
setup(api: RslibPluginApi): void;
|
|
17
|
-
};
|
|
18
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ActionSpaceItem, BaseAgent, ToolDefinition } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Converts DeviceAction from actionSpace into MCP ToolDefinition
|
|
4
|
-
* This is the core logic that removes need for hardcoded tool definitions
|
|
5
|
-
*/
|
|
6
|
-
export declare function generateToolsFromActionSpace(actionSpace: ActionSpaceItem[], getAgent: () => Promise<BaseAgent>): ToolDefinition[];
|
|
7
|
-
/**
|
|
8
|
-
* Generate common tools (screenshot, waitFor)
|
|
9
|
-
* SIMPLIFIED: Only keep essential helper tools, removed assert
|
|
10
|
-
*/
|
|
11
|
-
export declare function generateCommonTools(getAgent: () => Promise<BaseAgent>): ToolDefinition[];
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import type { z } from 'zod';
|
|
3
|
-
/**
|
|
4
|
-
* Default timeout constants for app loading verification
|
|
5
|
-
*/
|
|
6
|
-
export declare const defaultAppLoadingTimeoutMs = 10000;
|
|
7
|
-
export declare const defaultAppLoadingCheckIntervalMs = 2000;
|
|
8
|
-
/**
|
|
9
|
-
* Content item types for tool results (MCP compatible)
|
|
10
|
-
*/
|
|
11
|
-
export type ToolResultContent = {
|
|
12
|
-
type: 'text';
|
|
13
|
-
text: string;
|
|
14
|
-
} | {
|
|
15
|
-
type: 'image';
|
|
16
|
-
data: string;
|
|
17
|
-
mimeType: string;
|
|
18
|
-
} | {
|
|
19
|
-
type: 'audio';
|
|
20
|
-
data: string;
|
|
21
|
-
mimeType: string;
|
|
22
|
-
} | {
|
|
23
|
-
type: 'resource';
|
|
24
|
-
resource: {
|
|
25
|
-
text: string;
|
|
26
|
-
uri: string;
|
|
27
|
-
mimeType?: string;
|
|
28
|
-
} | {
|
|
29
|
-
uri: string;
|
|
30
|
-
blob: string;
|
|
31
|
-
mimeType?: string;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Result type for tool execution (MCP compatible)
|
|
36
|
-
*/
|
|
37
|
-
export interface ToolResult {
|
|
38
|
-
[x: string]: unknown;
|
|
39
|
-
content: ToolResultContent[];
|
|
40
|
-
isError?: boolean;
|
|
41
|
-
_meta?: Record<string, unknown>;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Tool handler function type
|
|
45
|
-
* Takes parsed arguments and returns a tool result
|
|
46
|
-
*/
|
|
47
|
-
export type ToolHandler<T = Record<string, unknown>> = (args: T) => Promise<ToolResult>;
|
|
48
|
-
/**
|
|
49
|
-
* Tool schema type using Zod
|
|
50
|
-
*/
|
|
51
|
-
export type ToolSchema = Record<string, z.ZodTypeAny>;
|
|
52
|
-
/**
|
|
53
|
-
* Tool definition for MCP server
|
|
54
|
-
*/
|
|
55
|
-
export interface ToolDefinition<T = Record<string, unknown>> {
|
|
56
|
-
name: string;
|
|
57
|
-
description: string;
|
|
58
|
-
schema: ToolSchema;
|
|
59
|
-
handler: ToolHandler<T>;
|
|
60
|
-
autoDestroy?: boolean;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Action space item definition
|
|
64
|
-
* Note: Intentionally no index signature to maintain compatibility with DeviceAction
|
|
65
|
-
*/
|
|
66
|
-
export interface ActionSpaceItem {
|
|
67
|
-
name: string;
|
|
68
|
-
description?: string;
|
|
69
|
-
args?: Record<string, unknown>;
|
|
70
|
-
paramSchema?: z.ZodTypeAny;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Base agent interface
|
|
74
|
-
* Represents a platform-specific agent (Android, iOS, Web)
|
|
75
|
-
*/
|
|
76
|
-
export interface BaseAgent {
|
|
77
|
-
getActionSpace(): Promise<ActionSpaceItem[]>;
|
|
78
|
-
destroy?(): Promise<void>;
|
|
79
|
-
page?: {
|
|
80
|
-
screenshotBase64(): Promise<string>;
|
|
81
|
-
};
|
|
82
|
-
aiAction?: (description: string, params?: Record<string, unknown>) => Promise<void>;
|
|
83
|
-
aiWaitFor?: (assertion: string, options: Record<string, unknown>) => Promise<void>;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Base device interface for temporary device instances
|
|
87
|
-
*/
|
|
88
|
-
export interface BaseDevice {
|
|
89
|
-
actionSpace(): ActionSpaceItem[];
|
|
90
|
-
destroy?(): Promise<void>;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Interface for platform-specific MCP tools manager
|
|
94
|
-
*/
|
|
95
|
-
export interface IMidsceneTools {
|
|
96
|
-
attachToServer(server: McpServer): void;
|
|
97
|
-
initTools(): Promise<void>;
|
|
98
|
-
closeBrowser?(): Promise<void>;
|
|
99
|
-
}
|