@midscene/shared 1.0.1-beta-20251208031856.0 → 1.0.1-beta-20251208070218.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/mcp/base-server.mjs +9 -0
- package/dist/es/mcp/index.mjs +1 -0
- package/dist/es/mcp/inject-report-html-plugin.mjs +42 -0
- package/dist/lib/mcp/base-server.js +9 -0
- package/dist/lib/mcp/index.js +7 -0
- package/dist/lib/mcp/inject-report-html-plugin.js +87 -0
- package/dist/types/mcp/index.d.ts +1 -0
- package/dist/types/mcp/inject-report-html-plugin.d.ts +18 -0
- package/dist/types/mcp/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/mcp/base-server.ts +13 -0
- package/src/mcp/index.ts +1 -0
- package/src/mcp/inject-report-html-plugin.ts +98 -0
- package/src/mcp/types.ts +2 -1
|
@@ -56,6 +56,15 @@ class BaseMCPServer {
|
|
|
56
56
|
this.toolsManager?.closeBrowser?.().catch(console.error);
|
|
57
57
|
}
|
|
58
58
|
async launch() {
|
|
59
|
+
console.log = (...args)=>{
|
|
60
|
+
console.error('[LOG]', ...args);
|
|
61
|
+
};
|
|
62
|
+
console.info = (...args)=>{
|
|
63
|
+
console.error('[INFO]', ...args);
|
|
64
|
+
};
|
|
65
|
+
console.debug = (...args)=>{
|
|
66
|
+
console.error('[DEBUG]', ...args);
|
|
67
|
+
};
|
|
59
68
|
await this.initializeToolsManager();
|
|
60
69
|
const transport = new StdioServerTransport();
|
|
61
70
|
try {
|
package/dist/es/mcp/index.mjs
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
const MAGIC_STRING = 'REPLACE_ME_WITH_REPORT_HTML';
|
|
4
|
+
const REPLACED_MARK = '/*REPORT_HTML_REPLACED*/';
|
|
5
|
+
const REG_EXP_FOR_REPLACE = /\/\*REPORT_HTML_REPLACED\*\/.*/;
|
|
6
|
+
function injectReportHtmlFromCore(packageDir) {
|
|
7
|
+
return {
|
|
8
|
+
name: 'inject-report-html-from-core',
|
|
9
|
+
setup (api) {
|
|
10
|
+
api.onAfterBuild(()=>{
|
|
11
|
+
const coreUtilsPath = node_path.resolve(packageDir, '..', 'core', 'dist', 'lib', 'utils.js');
|
|
12
|
+
if (!node_fs.existsSync(coreUtilsPath)) return void console.warn('[inject-report-html] @midscene/core dist not found, skipping');
|
|
13
|
+
const coreContent = node_fs.readFileSync(coreUtilsPath, 'utf-8');
|
|
14
|
+
if (!coreContent.includes(REPLACED_MARK)) return void console.warn('[inject-report-html] HTML not found in core dist. Ensure report builds first.');
|
|
15
|
+
const match = coreContent.match(/\/\*REPORT_HTML_REPLACED\*\/(".*?")/);
|
|
16
|
+
if (!match?.[1]) return void console.warn('[inject-report-html] Failed to extract HTML from core');
|
|
17
|
+
const finalContent = `${REPLACED_MARK}${match[1]}`;
|
|
18
|
+
const distDir = node_path.join(packageDir, 'dist');
|
|
19
|
+
if (!node_fs.existsSync(distDir)) return;
|
|
20
|
+
const jsFiles = node_fs.readdirSync(distDir).filter((f)=>f.endsWith('.js'));
|
|
21
|
+
let injectedCount = 0;
|
|
22
|
+
for (const file of jsFiles){
|
|
23
|
+
const filePath = node_path.join(distDir, file);
|
|
24
|
+
const content = node_fs.readFileSync(filePath, 'utf-8');
|
|
25
|
+
if (content.includes(REPLACED_MARK)) {
|
|
26
|
+
if (REG_EXP_FOR_REPLACE.test(content)) {
|
|
27
|
+
node_fs.writeFileSync(filePath, content.replace(REG_EXP_FOR_REPLACE, ()=>finalContent));
|
|
28
|
+
console.log(`[inject-report-html] Updated: ${file}`);
|
|
29
|
+
injectedCount++;
|
|
30
|
+
}
|
|
31
|
+
} else if (content.includes(`'${MAGIC_STRING}'`)) {
|
|
32
|
+
node_fs.writeFileSync(filePath, content.replace(`'${MAGIC_STRING}'`, ()=>finalContent));
|
|
33
|
+
console.log(`[inject-report-html] Injected: ${file}`);
|
|
34
|
+
injectedCount++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (injectedCount > 0) console.log(`[inject-report-html] Completed: ${injectedCount} file(s)`);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export { injectReportHtmlFromCore };
|
|
@@ -86,6 +86,15 @@ class BaseMCPServer {
|
|
|
86
86
|
this.toolsManager?.closeBrowser?.().catch(console.error);
|
|
87
87
|
}
|
|
88
88
|
async launch() {
|
|
89
|
+
console.log = (...args)=>{
|
|
90
|
+
console.error('[LOG]', ...args);
|
|
91
|
+
};
|
|
92
|
+
console.info = (...args)=>{
|
|
93
|
+
console.error('[INFO]', ...args);
|
|
94
|
+
};
|
|
95
|
+
console.debug = (...args)=>{
|
|
96
|
+
console.error('[DEBUG]', ...args);
|
|
97
|
+
};
|
|
89
98
|
await this.initializeToolsManager();
|
|
90
99
|
const transport = new stdio_js_namespaceObject.StdioServerTransport();
|
|
91
100
|
try {
|
package/dist/lib/mcp/index.js
CHANGED
|
@@ -6,6 +6,9 @@ var __webpack_modules__ = {
|
|
|
6
6
|
"./base-tools" (module) {
|
|
7
7
|
module.exports = require("./base-tools.js");
|
|
8
8
|
},
|
|
9
|
+
"./inject-report-html-plugin" (module) {
|
|
10
|
+
module.exports = require("./inject-report-html-plugin.js");
|
|
11
|
+
},
|
|
9
12
|
"./tool-generator" (module) {
|
|
10
13
|
module.exports = require("./tool-generator.js");
|
|
11
14
|
},
|
|
@@ -72,6 +75,10 @@ var __webpack_exports__ = {};
|
|
|
72
75
|
var __rspack_reexport = {};
|
|
73
76
|
for(const __rspack_import_key in _types__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_3[__rspack_import_key];
|
|
74
77
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
78
|
+
var _inject_report_html_plugin__rspack_import_4 = __webpack_require__("./inject-report-html-plugin");
|
|
79
|
+
var __rspack_reexport = {};
|
|
80
|
+
for(const __rspack_import_key in _inject_report_html_plugin__rspack_import_4)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_inject_report_html_plugin__rspack_import_4[__rspack_import_key];
|
|
81
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
75
82
|
})();
|
|
76
83
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
77
84
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
injectReportHtmlFromCore: ()=>injectReportHtmlFromCore
|
|
37
|
+
});
|
|
38
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
39
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
40
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
41
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
42
|
+
const MAGIC_STRING = 'REPLACE_ME_WITH_REPORT_HTML';
|
|
43
|
+
const REPLACED_MARK = '/*REPORT_HTML_REPLACED*/';
|
|
44
|
+
const REG_EXP_FOR_REPLACE = /\/\*REPORT_HTML_REPLACED\*\/.*/;
|
|
45
|
+
function injectReportHtmlFromCore(packageDir) {
|
|
46
|
+
return {
|
|
47
|
+
name: 'inject-report-html-from-core',
|
|
48
|
+
setup (api) {
|
|
49
|
+
api.onAfterBuild(()=>{
|
|
50
|
+
const coreUtilsPath = external_node_path_default().resolve(packageDir, '..', 'core', 'dist', 'lib', 'utils.js');
|
|
51
|
+
if (!external_node_fs_default().existsSync(coreUtilsPath)) return void console.warn('[inject-report-html] @midscene/core dist not found, skipping');
|
|
52
|
+
const coreContent = external_node_fs_default().readFileSync(coreUtilsPath, 'utf-8');
|
|
53
|
+
if (!coreContent.includes(REPLACED_MARK)) return void console.warn('[inject-report-html] HTML not found in core dist. Ensure report builds first.');
|
|
54
|
+
const match = coreContent.match(/\/\*REPORT_HTML_REPLACED\*\/(".*?")/);
|
|
55
|
+
if (!match?.[1]) return void console.warn('[inject-report-html] Failed to extract HTML from core');
|
|
56
|
+
const finalContent = `${REPLACED_MARK}${match[1]}`;
|
|
57
|
+
const distDir = external_node_path_default().join(packageDir, 'dist');
|
|
58
|
+
if (!external_node_fs_default().existsSync(distDir)) return;
|
|
59
|
+
const jsFiles = external_node_fs_default().readdirSync(distDir).filter((f)=>f.endsWith('.js'));
|
|
60
|
+
let injectedCount = 0;
|
|
61
|
+
for (const file of jsFiles){
|
|
62
|
+
const filePath = external_node_path_default().join(distDir, file);
|
|
63
|
+
const content = external_node_fs_default().readFileSync(filePath, 'utf-8');
|
|
64
|
+
if (content.includes(REPLACED_MARK)) {
|
|
65
|
+
if (REG_EXP_FOR_REPLACE.test(content)) {
|
|
66
|
+
external_node_fs_default().writeFileSync(filePath, content.replace(REG_EXP_FOR_REPLACE, ()=>finalContent));
|
|
67
|
+
console.log(`[inject-report-html] Updated: ${file}`);
|
|
68
|
+
injectedCount++;
|
|
69
|
+
}
|
|
70
|
+
} else if (content.includes(`'${MAGIC_STRING}'`)) {
|
|
71
|
+
external_node_fs_default().writeFileSync(filePath, content.replace(`'${MAGIC_STRING}'`, ()=>finalContent));
|
|
72
|
+
console.log(`[inject-report-html] Injected: ${file}`);
|
|
73
|
+
injectedCount++;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (injectedCount > 0) console.log(`[inject-report-html] Completed: ${injectedCount} file(s)`);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
exports.injectReportHtmlFromCore = __webpack_exports__.injectReportHtmlFromCore;
|
|
82
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
83
|
+
"injectReportHtmlFromCore"
|
|
84
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
85
|
+
Object.defineProperty(exports, '__esModule', {
|
|
86
|
+
value: true
|
|
87
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
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 {};
|
|
@@ -61,12 +61,13 @@ export interface ToolDefinition<T = Record<string, unknown>> {
|
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Action space item definition
|
|
64
|
+
* Note: Intentionally no index signature to maintain compatibility with DeviceAction
|
|
64
65
|
*/
|
|
65
66
|
export interface ActionSpaceItem {
|
|
66
67
|
name: string;
|
|
67
68
|
description?: string;
|
|
68
69
|
args?: Record<string, unknown>;
|
|
69
|
-
|
|
70
|
+
paramSchema?: z.ZodTypeAny;
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
73
|
* Base agent interface
|
package/package.json
CHANGED
package/src/mcp/base-server.ts
CHANGED
|
@@ -114,6 +114,19 @@ export abstract class BaseMCPServer {
|
|
|
114
114
|
* Initialize and launch the MCP server with stdio transport
|
|
115
115
|
*/
|
|
116
116
|
public async launch(): Promise<void> {
|
|
117
|
+
// Hijack stdout-based console methods to stderr for stdio mode
|
|
118
|
+
// This prevents them from breaking MCP JSON-RPC protocol on stdout
|
|
119
|
+
// Note: console.warn and console.error already output to stderr
|
|
120
|
+
console.log = (...args: unknown[]) => {
|
|
121
|
+
console.error('[LOG]', ...args);
|
|
122
|
+
};
|
|
123
|
+
console.info = (...args: unknown[]) => {
|
|
124
|
+
console.error('[INFO]', ...args);
|
|
125
|
+
};
|
|
126
|
+
console.debug = (...args: unknown[]) => {
|
|
127
|
+
console.error('[DEBUG]', ...args);
|
|
128
|
+
};
|
|
129
|
+
|
|
117
130
|
await this.initializeToolsManager();
|
|
118
131
|
|
|
119
132
|
const transport = new StdioServerTransport();
|
package/src/mcp/index.ts
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const MAGIC_STRING = 'REPLACE_ME_WITH_REPORT_HTML';
|
|
5
|
+
const REPLACED_MARK = '/*REPORT_HTML_REPLACED*/';
|
|
6
|
+
const REG_EXP_FOR_REPLACE = /\/\*REPORT_HTML_REPLACED\*\/.*/;
|
|
7
|
+
|
|
8
|
+
interface RslibPluginApi {
|
|
9
|
+
onAfterBuild: (callback: () => void) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Rslib plugin to inject report HTML from @midscene/core dist into MCP bundle.
|
|
14
|
+
* This runs after build and reads the already-injected HTML from core.
|
|
15
|
+
*
|
|
16
|
+
* Prerequisites:
|
|
17
|
+
* - @midscene/report must be in devDependencies to ensure correct build order
|
|
18
|
+
* - @midscene/core dist must exist with injected HTML
|
|
19
|
+
*
|
|
20
|
+
* @param packageDir - The directory of the MCP package (use __dirname)
|
|
21
|
+
*/
|
|
22
|
+
export function injectReportHtmlFromCore(packageDir: string) {
|
|
23
|
+
return {
|
|
24
|
+
name: 'inject-report-html-from-core',
|
|
25
|
+
setup(api: RslibPluginApi) {
|
|
26
|
+
api.onAfterBuild(() => {
|
|
27
|
+
const coreUtilsPath = path.resolve(
|
|
28
|
+
packageDir,
|
|
29
|
+
'..',
|
|
30
|
+
'core',
|
|
31
|
+
'dist',
|
|
32
|
+
'lib',
|
|
33
|
+
'utils.js',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (!fs.existsSync(coreUtilsPath)) {
|
|
37
|
+
console.warn(
|
|
38
|
+
'[inject-report-html] @midscene/core dist not found, skipping',
|
|
39
|
+
);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const coreContent = fs.readFileSync(coreUtilsPath, 'utf-8');
|
|
44
|
+
if (!coreContent.includes(REPLACED_MARK)) {
|
|
45
|
+
console.warn(
|
|
46
|
+
'[inject-report-html] HTML not found in core dist. Ensure report builds first.',
|
|
47
|
+
);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const match = coreContent.match(/\/\*REPORT_HTML_REPLACED\*\/(".*?")/);
|
|
52
|
+
if (!match?.[1]) {
|
|
53
|
+
console.warn('[inject-report-html] Failed to extract HTML from core');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const finalContent = `${REPLACED_MARK}${match[1]}`;
|
|
58
|
+
const distDir = path.join(packageDir, 'dist');
|
|
59
|
+
|
|
60
|
+
if (!fs.existsSync(distDir)) return;
|
|
61
|
+
|
|
62
|
+
const jsFiles = fs
|
|
63
|
+
.readdirSync(distDir)
|
|
64
|
+
.filter((f) => f.endsWith('.js'));
|
|
65
|
+
let injectedCount = 0;
|
|
66
|
+
|
|
67
|
+
for (const file of jsFiles) {
|
|
68
|
+
const filePath = path.join(distDir, file);
|
|
69
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
70
|
+
|
|
71
|
+
if (content.includes(REPLACED_MARK)) {
|
|
72
|
+
if (REG_EXP_FOR_REPLACE.test(content)) {
|
|
73
|
+
fs.writeFileSync(
|
|
74
|
+
filePath,
|
|
75
|
+
content.replace(REG_EXP_FOR_REPLACE, () => finalContent),
|
|
76
|
+
);
|
|
77
|
+
console.log(`[inject-report-html] Updated: ${file}`);
|
|
78
|
+
injectedCount++;
|
|
79
|
+
}
|
|
80
|
+
} else if (content.includes(`'${MAGIC_STRING}'`)) {
|
|
81
|
+
fs.writeFileSync(
|
|
82
|
+
filePath,
|
|
83
|
+
content.replace(`'${MAGIC_STRING}'`, () => finalContent),
|
|
84
|
+
);
|
|
85
|
+
console.log(`[inject-report-html] Injected: ${file}`);
|
|
86
|
+
injectedCount++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (injectedCount > 0) {
|
|
91
|
+
console.log(
|
|
92
|
+
`[inject-report-html] Completed: ${injectedCount} file(s)`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
package/src/mcp/types.ts
CHANGED
|
@@ -60,12 +60,13 @@ export interface ToolDefinition<T = Record<string, unknown>> {
|
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Action space item definition
|
|
63
|
+
* Note: Intentionally no index signature to maintain compatibility with DeviceAction
|
|
63
64
|
*/
|
|
64
65
|
export interface ActionSpaceItem {
|
|
65
66
|
name: string;
|
|
66
67
|
description?: string;
|
|
67
68
|
args?: Record<string, unknown>;
|
|
68
|
-
|
|
69
|
+
paramSchema?: z.ZodTypeAny;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
/**
|