@midscene/shared 1.0.1-beta-20251208033501.0 → 1.0.1-beta-20251208071759.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.
@@ -2,3 +2,4 @@ export * from "./base-server.mjs";
2
2
  export * from "./base-tools.mjs";
3
3
  export * from "./tool-generator.mjs";
4
4
  export * from "./types.mjs";
5
+ export * from "./inject-report-html-plugin.mjs";
@@ -0,0 +1,53 @@
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 markerIndex = coreContent.indexOf(REPLACED_MARK);
16
+ const jsonStart = markerIndex + REPLACED_MARK.length;
17
+ let jsonEnd = jsonStart;
18
+ if ('"' === coreContent[jsonStart]) {
19
+ jsonEnd = jsonStart + 1;
20
+ while(jsonEnd < coreContent.length)if ('\\' === coreContent[jsonEnd]) jsonEnd += 2;
21
+ else if ('"' === coreContent[jsonEnd]) {
22
+ jsonEnd += 1;
23
+ break;
24
+ } else jsonEnd += 1;
25
+ }
26
+ const jsonString = coreContent.slice(jsonStart, jsonEnd);
27
+ if (!jsonString || jsonString.length < 10) return void console.warn('[inject-report-html] Failed to extract HTML from core');
28
+ const finalContent = `${REPLACED_MARK}${jsonString}`;
29
+ const distDir = node_path.join(packageDir, 'dist');
30
+ if (!node_fs.existsSync(distDir)) return;
31
+ const jsFiles = node_fs.readdirSync(distDir).filter((f)=>f.endsWith('.js'));
32
+ let injectedCount = 0;
33
+ for (const file of jsFiles){
34
+ const filePath = node_path.join(distDir, file);
35
+ const content = node_fs.readFileSync(filePath, 'utf-8');
36
+ if (content.includes(REPLACED_MARK)) {
37
+ if (REG_EXP_FOR_REPLACE.test(content)) {
38
+ node_fs.writeFileSync(filePath, content.replace(REG_EXP_FOR_REPLACE, ()=>finalContent));
39
+ console.log(`[inject-report-html] Updated: ${file}`);
40
+ injectedCount++;
41
+ }
42
+ } else if (content.includes(`'${MAGIC_STRING}'`)) {
43
+ node_fs.writeFileSync(filePath, content.replace(`'${MAGIC_STRING}'`, ()=>finalContent));
44
+ console.log(`[inject-report-html] Injected: ${file}`);
45
+ injectedCount++;
46
+ }
47
+ }
48
+ if (injectedCount > 0) console.log(`[inject-report-html] Completed: ${injectedCount} file(s)`);
49
+ });
50
+ }
51
+ };
52
+ }
53
+ export { injectReportHtmlFromCore };
@@ -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,98 @@
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 markerIndex = coreContent.indexOf(REPLACED_MARK);
55
+ const jsonStart = markerIndex + REPLACED_MARK.length;
56
+ let jsonEnd = jsonStart;
57
+ if ('"' === coreContent[jsonStart]) {
58
+ jsonEnd = jsonStart + 1;
59
+ while(jsonEnd < coreContent.length)if ('\\' === coreContent[jsonEnd]) jsonEnd += 2;
60
+ else if ('"' === coreContent[jsonEnd]) {
61
+ jsonEnd += 1;
62
+ break;
63
+ } else jsonEnd += 1;
64
+ }
65
+ const jsonString = coreContent.slice(jsonStart, jsonEnd);
66
+ if (!jsonString || jsonString.length < 10) return void console.warn('[inject-report-html] Failed to extract HTML from core');
67
+ const finalContent = `${REPLACED_MARK}${jsonString}`;
68
+ const distDir = external_node_path_default().join(packageDir, 'dist');
69
+ if (!external_node_fs_default().existsSync(distDir)) return;
70
+ const jsFiles = external_node_fs_default().readdirSync(distDir).filter((f)=>f.endsWith('.js'));
71
+ let injectedCount = 0;
72
+ for (const file of jsFiles){
73
+ const filePath = external_node_path_default().join(distDir, file);
74
+ const content = external_node_fs_default().readFileSync(filePath, 'utf-8');
75
+ if (content.includes(REPLACED_MARK)) {
76
+ if (REG_EXP_FOR_REPLACE.test(content)) {
77
+ external_node_fs_default().writeFileSync(filePath, content.replace(REG_EXP_FOR_REPLACE, ()=>finalContent));
78
+ console.log(`[inject-report-html] Updated: ${file}`);
79
+ injectedCount++;
80
+ }
81
+ } else if (content.includes(`'${MAGIC_STRING}'`)) {
82
+ external_node_fs_default().writeFileSync(filePath, content.replace(`'${MAGIC_STRING}'`, ()=>finalContent));
83
+ console.log(`[inject-report-html] Injected: ${file}`);
84
+ injectedCount++;
85
+ }
86
+ }
87
+ if (injectedCount > 0) console.log(`[inject-report-html] Completed: ${injectedCount} file(s)`);
88
+ });
89
+ }
90
+ };
91
+ }
92
+ exports.injectReportHtmlFromCore = __webpack_exports__.injectReportHtmlFromCore;
93
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
94
+ "injectReportHtmlFromCore"
95
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
96
+ Object.defineProperty(exports, '__esModule', {
97
+ value: true
98
+ });
@@ -2,3 +2,4 @@ export * from './base-server';
2
2
  export * from './base-tools';
3
3
  export * from './tool-generator';
4
4
  export * from './types';
5
+ export * from './inject-report-html-plugin';
@@ -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
- [key: string]: unknown;
70
+ paramSchema?: z.ZodTypeAny;
70
71
  }
71
72
  /**
72
73
  * Base agent interface
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.0.1-beta-20251208033501.0",
3
+ "version": "1.0.1-beta-20251208071759.0",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
package/src/mcp/index.ts CHANGED
@@ -2,3 +2,4 @@ export * from './base-server';
2
2
  export * from './base-tools';
3
3
  export * from './tool-generator';
4
4
  export * from './types';
5
+ export * from './inject-report-html-plugin';
@@ -0,0 +1,119 @@
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
+ // Extract the JSON string after the marker
52
+ // JSON strings can contain escaped quotes, so we need to properly parse it
53
+ const markerIndex = coreContent.indexOf(REPLACED_MARK);
54
+ const jsonStart = markerIndex + REPLACED_MARK.length;
55
+
56
+ // Find the end of the JSON string by tracking quote escaping
57
+ let jsonEnd = jsonStart;
58
+ if (coreContent[jsonStart] === '"') {
59
+ jsonEnd = jsonStart + 1;
60
+ while (jsonEnd < coreContent.length) {
61
+ if (coreContent[jsonEnd] === '\\') {
62
+ jsonEnd += 2; // Skip escaped character
63
+ } else if (coreContent[jsonEnd] === '"') {
64
+ jsonEnd += 1; // Include closing quote
65
+ break;
66
+ } else {
67
+ jsonEnd += 1;
68
+ }
69
+ }
70
+ }
71
+
72
+ const jsonString = coreContent.slice(jsonStart, jsonEnd);
73
+ if (!jsonString || jsonString.length < 10) {
74
+ console.warn('[inject-report-html] Failed to extract HTML from core');
75
+ return;
76
+ }
77
+
78
+ const finalContent = `${REPLACED_MARK}${jsonString}`;
79
+ const distDir = path.join(packageDir, 'dist');
80
+
81
+ if (!fs.existsSync(distDir)) return;
82
+
83
+ const jsFiles = fs
84
+ .readdirSync(distDir)
85
+ .filter((f) => f.endsWith('.js'));
86
+ let injectedCount = 0;
87
+
88
+ for (const file of jsFiles) {
89
+ const filePath = path.join(distDir, file);
90
+ const content = fs.readFileSync(filePath, 'utf-8');
91
+
92
+ if (content.includes(REPLACED_MARK)) {
93
+ if (REG_EXP_FOR_REPLACE.test(content)) {
94
+ fs.writeFileSync(
95
+ filePath,
96
+ content.replace(REG_EXP_FOR_REPLACE, () => finalContent),
97
+ );
98
+ console.log(`[inject-report-html] Updated: ${file}`);
99
+ injectedCount++;
100
+ }
101
+ } else if (content.includes(`'${MAGIC_STRING}'`)) {
102
+ fs.writeFileSync(
103
+ filePath,
104
+ content.replace(`'${MAGIC_STRING}'`, () => finalContent),
105
+ );
106
+ console.log(`[inject-report-html] Injected: ${file}`);
107
+ injectedCount++;
108
+ }
109
+ }
110
+
111
+ if (injectedCount > 0) {
112
+ console.log(
113
+ `[inject-report-html] Completed: ${injectedCount} file(s)`,
114
+ );
115
+ }
116
+ });
117
+ },
118
+ };
119
+ }
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
- [key: string]: unknown;
69
+ paramSchema?: z.ZodTypeAny;
69
70
  }
70
71
 
71
72
  /**