@xiuchang-midscene/shared 2.0.2 → 2.0.3

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.
Files changed (166) hide show
  1. package/dist/es/oss/index.mjs +1 -1
  2. package/dist/lib/oss/index.js +1 -1
  3. package/package.json +1 -1
  4. package/src/oss/index.ts +1 -1
  5. package/dist/es/baseDB.mjs.bak +0 -109
  6. package/dist/es/build/copy-static.mjs.bak +0 -31
  7. package/dist/es/build/rspack-config.mjs.bak +0 -4
  8. package/dist/es/cli/cli-runner.mjs.bak +0 -140
  9. package/dist/es/cli/index.mjs.bak +0 -2
  10. package/dist/es/common.mjs.bak +0 -37
  11. package/dist/es/constants/example-code.mjs.bak +0 -223
  12. package/dist/es/constants/index.mjs.bak +0 -23
  13. package/dist/es/env/basic.mjs.bak +0 -6
  14. package/dist/es/env/constants.mjs.bak +0 -70
  15. package/dist/es/env/global-config-manager.mjs.bak +0 -94
  16. package/dist/es/env/helper.mjs.bak +0 -43
  17. package/dist/es/env/index.mjs.bak +0 -5
  18. package/dist/es/env/init-debug.mjs.bak +0 -18
  19. package/dist/es/env/model-config-manager.mjs.bak +0 -79
  20. package/dist/es/env/parse-model-config.mjs.bak +0 -132
  21. package/dist/es/env/types.mjs.bak +0 -220
  22. package/dist/es/env/utils.mjs.bak +0 -26
  23. package/dist/es/extractor/constants.mjs.bak +0 -2
  24. package/dist/es/extractor/debug.mjs.bak +0 -6
  25. package/dist/es/extractor/dom-util.mjs.bak +0 -92
  26. package/dist/es/extractor/index.mjs.bak +0 -5
  27. package/dist/es/extractor/locator.mjs.bak +0 -250
  28. package/dist/es/extractor/tree.mjs.bak +0 -78
  29. package/dist/es/extractor/util.mjs.bak +0 -245
  30. package/dist/es/extractor/web-extractor.mjs.bak +0 -303
  31. package/dist/es/img/box-select.mjs.bak +0 -824
  32. package/dist/es/img/canvas-fallback.mjs.bak +0 -238
  33. package/dist/es/img/get-photon.mjs.bak +0 -45
  34. package/dist/es/img/get-sharp.mjs.bak +0 -11
  35. package/dist/es/img/index.mjs.bak +0 -4
  36. package/dist/es/img/info.mjs.bak +0 -29
  37. package/dist/es/img/transform.mjs.bak +0 -295
  38. package/dist/es/index.mjs.bak +0 -4
  39. package/dist/es/logger.mjs.bak +0 -64
  40. package/dist/es/mcp/base-server.mjs.bak +0 -281
  41. package/dist/es/mcp/base-tools.mjs.bak +0 -91
  42. package/dist/es/mcp/chrome-path.mjs.bak +0 -35
  43. package/dist/es/mcp/index.mjs.bak +0 -7
  44. package/dist/es/mcp/inject-report-html-plugin.mjs.bak +0 -53
  45. package/dist/es/mcp/launcher-helper.mjs.bak +0 -52
  46. package/dist/es/mcp/tool-generator.mjs.bak +0 -297
  47. package/dist/es/mcp/types.mjs.bak +0 -3
  48. package/dist/es/node/fs.mjs.bak +0 -44
  49. package/dist/es/node/index.mjs.bak +0 -2
  50. package/dist/es/node/port.mjs.bak +0 -24
  51. package/dist/es/oss/demo.mjs.bak +0 -30
  52. package/dist/es/oss/index.mjs.bak +0 -90
  53. package/dist/es/polyfills/async-hooks.mjs.bak +0 -2
  54. package/dist/es/polyfills/index.mjs.bak +0 -1
  55. package/dist/es/types/index.mjs.bak +0 -3
  56. package/dist/es/us-keyboard-layout.mjs.bak +0 -1414
  57. package/dist/es/utils.mjs.bak +0 -72
  58. package/dist/es/zod-schema-utils.mjs.bak +0 -54
  59. package/dist/lib/baseDB.js.bak +0 -149
  60. package/dist/lib/build/copy-static.js.bak +0 -79
  61. package/dist/lib/build/rspack-config.js.bak +0 -38
  62. package/dist/lib/cli/cli-runner.js.bak +0 -196
  63. package/dist/lib/cli/index.js.bak +0 -48
  64. package/dist/lib/common.js.bak +0 -93
  65. package/dist/lib/constants/example-code.js.bak +0 -260
  66. package/dist/lib/constants/index.js.bak +0 -96
  67. package/dist/lib/env/basic.js.bak +0 -40
  68. package/dist/lib/env/constants.js.bak +0 -113
  69. package/dist/lib/env/global-config-manager.js.bak +0 -128
  70. package/dist/lib/env/helper.js.bak +0 -80
  71. package/dist/lib/env/index.js.bak +0 -90
  72. package/dist/lib/env/init-debug.js.bak +0 -52
  73. package/dist/lib/env/model-config-manager.js.bak +0 -113
  74. package/dist/lib/env/parse-model-config.js.bak +0 -178
  75. package/dist/lib/env/types.js.bak +0 -554
  76. package/dist/lib/env/utils.js.bak +0 -72
  77. package/dist/lib/extractor/constants.js.bak +0 -42
  78. package/dist/lib/extractor/debug.js.bak +0 -12
  79. package/dist/lib/extractor/dom-util.js.bak +0 -153
  80. package/dist/lib/extractor/index.js.bak +0 -81
  81. package/dist/lib/extractor/locator.js.bak +0 -296
  82. package/dist/lib/extractor/tree.js.bak +0 -124
  83. package/dist/lib/extractor/util.js.bak +0 -336
  84. package/dist/lib/extractor/web-extractor.js.bak +0 -349
  85. package/dist/lib/img/box-select.js.bak +0 -875
  86. package/dist/lib/img/canvas-fallback.js.bak +0 -305
  87. package/dist/lib/img/get-photon.js.bak +0 -82
  88. package/dist/lib/img/get-sharp.js.bak +0 -45
  89. package/dist/lib/img/index.js.bak +0 -95
  90. package/dist/lib/img/info.js.bak +0 -83
  91. package/dist/lib/img/transform.js.bak +0 -387
  92. package/dist/lib/index.js.bak +0 -47
  93. package/dist/lib/logger.js.bak +0 -114
  94. package/dist/lib/mcp/base-server.js.bak +0 -331
  95. package/dist/lib/mcp/base-tools.js.bak +0 -125
  96. package/dist/lib/mcp/chrome-path.js.bak +0 -72
  97. package/dist/lib/mcp/index.js.bak +0 -100
  98. package/dist/lib/mcp/inject-report-html-plugin.js.bak +0 -98
  99. package/dist/lib/mcp/launcher-helper.js.bak +0 -86
  100. package/dist/lib/mcp/tool-generator.js.bak +0 -334
  101. package/dist/lib/mcp/types.js.bak +0 -40
  102. package/dist/lib/node/fs.js.bak +0 -97
  103. package/dist/lib/node/index.js.bak +0 -65
  104. package/dist/lib/node/port.js.bak +0 -61
  105. package/dist/lib/oss/demo.js.bak +0 -36
  106. package/dist/lib/oss/index.js.bak +0 -138
  107. package/dist/lib/polyfills/async-hooks.js.bak +0 -36
  108. package/dist/lib/polyfills/index.js.bak +0 -58
  109. package/dist/lib/types/index.js.bak +0 -37
  110. package/dist/lib/us-keyboard-layout.js.bak +0 -1457
  111. package/dist/lib/utils.js.bak +0 -148
  112. package/dist/lib/zod-schema-utils.js.bak +0 -97
  113. package/dist/types/baseDB.d.ts.bak +0 -25
  114. package/dist/types/build/copy-static.d.ts.bak +0 -31
  115. package/dist/types/build/rspack-config.d.ts.bak +0 -8
  116. package/dist/types/cli/cli-runner.d.ts.bak +0 -14
  117. package/dist/types/cli/index.d.ts.bak +0 -2
  118. package/dist/types/common.d.ts.bak +0 -12
  119. package/dist/types/constants/example-code.d.ts.bak +0 -2
  120. package/dist/types/constants/index.d.ts.bak +0 -21
  121. package/dist/types/env/basic.d.ts.bak +0 -6
  122. package/dist/types/env/constants.d.ts.bak +0 -40
  123. package/dist/types/env/global-config-manager.d.ts.bak +0 -32
  124. package/dist/types/env/helper.d.ts.bak +0 -4
  125. package/dist/types/env/index.d.ts.bak +0 -4
  126. package/dist/types/env/init-debug.d.ts.bak +0 -1
  127. package/dist/types/env/model-config-manager.d.ts.bak +0 -25
  128. package/dist/types/env/parse-model-config.d.ts.bak +0 -31
  129. package/dist/types/env/types.d.ts.bak +0 -318
  130. package/dist/types/env/utils.d.ts.bak +0 -38
  131. package/dist/types/extractor/constants.d.ts.bak +0 -1
  132. package/dist/types/extractor/debug.d.ts.bak +0 -1
  133. package/dist/types/extractor/dom-util.d.ts.bak +0 -56
  134. package/dist/types/extractor/index.d.ts.bak +0 -32
  135. package/dist/types/extractor/locator.d.ts.bak +0 -9
  136. package/dist/types/extractor/tree.d.ts.bak +0 -6
  137. package/dist/types/extractor/util.d.ts.bak +0 -47
  138. package/dist/types/extractor/web-extractor.d.ts.bak +0 -19
  139. package/dist/types/img/box-select.d.ts.bak +0 -26
  140. package/dist/types/img/canvas-fallback.d.ts.bak +0 -105
  141. package/dist/types/img/get-photon.d.ts.bak +0 -19
  142. package/dist/types/img/get-sharp.d.ts.bak +0 -3
  143. package/dist/types/img/index.d.ts.bak +0 -3
  144. package/dist/types/img/info.d.ts.bak +0 -29
  145. package/dist/types/img/transform.d.ts.bak +0 -107
  146. package/dist/types/index.d.ts.bak +0 -4
  147. package/dist/types/logger.d.ts.bak +0 -5
  148. package/dist/types/mcp/base-server.d.ts.bak +0 -93
  149. package/dist/types/mcp/base-tools.d.ts.bak +0 -79
  150. package/dist/types/mcp/chrome-path.d.ts.bak +0 -2
  151. package/dist/types/mcp/index.d.ts.bak +0 -7
  152. package/dist/types/mcp/inject-report-html-plugin.d.ts.bak +0 -18
  153. package/dist/types/mcp/launcher-helper.d.ts.bak +0 -94
  154. package/dist/types/mcp/tool-generator.d.ts.bak +0 -10
  155. package/dist/types/mcp/types.d.ts.bak +0 -103
  156. package/dist/types/node/fs.d.ts.bak +0 -15
  157. package/dist/types/node/index.d.ts.bak +0 -2
  158. package/dist/types/node/port.d.ts.bak +0 -8
  159. package/dist/types/oss/demo.d.ts.bak +0 -1
  160. package/dist/types/oss/index.d.ts.bak +0 -34
  161. package/dist/types/polyfills/async-hooks.d.ts.bak +0 -6
  162. package/dist/types/polyfills/index.d.ts.bak +0 -4
  163. package/dist/types/types/index.d.ts.bak +0 -34
  164. package/dist/types/us-keyboard-layout.d.ts.bak +0 -32
  165. package/dist/types/utils.d.ts.bak +0 -34
  166. package/dist/types/zod-schema-utils.d.ts.bak +0 -23
@@ -1,98 +0,0 @@
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
- });
@@ -1,86 +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
- createMCPServerLauncher: ()=>createMCPServerLauncher
28
- });
29
- function createMCPServerLauncher(config) {
30
- const { agent, platformName, ToolsManagerClass, MCPServerClass } = config;
31
- function validateAgent() {
32
- const device = agent.interface;
33
- if (!device) throw new Error(`Agent must have an 'interface' property that references the underlying device.
34
- Please ensure your agent instance is properly initialized with a device interface.
35
- Expected: agent.interface to be defined, but got: ${typeof device}
36
- Solution: Check that your agent constructor properly sets the interface property.`);
37
- }
38
- function createToolsManager() {
39
- const toolsManager = new ToolsManagerClass();
40
- toolsManager.agent = agent;
41
- return toolsManager;
42
- }
43
- function logStartupInfo(mode, additionalInfo) {
44
- const device = agent.interface;
45
- console.log(`Starting Midscene ${platformName} MCP Server (${mode})...`);
46
- console.log(`Agent: ${agent.constructor.name}`);
47
- console.log(`Device: ${device.constructor.name}`);
48
- if (additionalInfo?.port !== void 0) console.log(`Port: ${additionalInfo.port}`);
49
- if (additionalInfo?.host) console.log(`Host: ${additionalInfo.host}`);
50
- }
51
- return {
52
- async launch (options = {}) {
53
- const { verbose = true } = options;
54
- validateAgent();
55
- if (verbose) logStartupInfo('stdio');
56
- const toolsManager = createToolsManager();
57
- const server = new MCPServerClass(toolsManager);
58
- const result = await server.launch();
59
- if (verbose) console.log(`${platformName} MCP Server started (stdio mode)`);
60
- return result;
61
- },
62
- async launchHttp (options) {
63
- const { port, host = 'localhost', verbose = true } = options;
64
- validateAgent();
65
- if (verbose) logStartupInfo('HTTP', {
66
- port,
67
- host
68
- });
69
- const toolsManager = createToolsManager();
70
- const server = new MCPServerClass(toolsManager);
71
- const result = await server.launchHttp({
72
- port,
73
- host
74
- });
75
- if (verbose) console.log(`${platformName} MCP Server started on http://${result.host}:${result.port}/mcp`);
76
- return result;
77
- }
78
- };
79
- }
80
- exports.createMCPServerLauncher = __webpack_exports__.createMCPServerLauncher;
81
- for(var __rspack_i in __webpack_exports__)if (-1 === [
82
- "createMCPServerLauncher"
83
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
84
- Object.defineProperty(exports, '__esModule', {
85
- value: true
86
- });
@@ -1,334 +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
- const external_zod_schema_utils_js_namespaceObject = require("../zod-schema-utils.js");
33
- function getErrorMessage(error) {
34
- return error instanceof Error ? error.message : String(error);
35
- }
36
- function describeActionForMCP(action) {
37
- const actionDesc = action.description || `Execute ${action.name} action`;
38
- if (!action.paramSchema) return `${action.name} action, ${actionDesc}`;
39
- const schema = action.paramSchema;
40
- const isZodObjectType = schema._def?.typeName === 'ZodObject';
41
- if (!isZodObjectType || !schema.shape) {
42
- const typeName = (0, external_zod_schema_utils_js_namespaceObject.getZodTypeName)(schema);
43
- const description = (0, external_zod_schema_utils_js_namespaceObject.getZodDescription)(schema);
44
- const paramDesc = description ? `${typeName} - ${description}` : typeName;
45
- return `${action.name} action, ${actionDesc}. Parameter: ${paramDesc}`;
46
- }
47
- const paramDescriptions = [];
48
- for (const [key, field] of Object.entries(schema.shape))if (field && 'object' == typeof field) {
49
- const isFieldOptional = 'function' == typeof field.isOptional && field.isOptional();
50
- const typeName = (0, external_zod_schema_utils_js_namespaceObject.getZodTypeName)(field);
51
- const description = (0, external_zod_schema_utils_js_namespaceObject.getZodDescription)(field);
52
- let paramStr = `${key}${isFieldOptional ? '?' : ''} (${typeName})`;
53
- if (description) paramStr += ` - ${description}`;
54
- paramDescriptions.push(paramStr);
55
- }
56
- if (0 === paramDescriptions.length) return `${action.name} action, ${actionDesc}`;
57
- return `${action.name} action, ${actionDesc}. Parameters: ${paramDescriptions.join('; ')}`;
58
- }
59
- function isZodOptional(value) {
60
- return '_def' in value && value._def?.typeName === 'ZodOptional';
61
- }
62
- function isZodObject(value) {
63
- return '_def' in value && value._def?.typeName === 'ZodObject' && 'shape' in value;
64
- }
65
- function unwrapOptional(value) {
66
- if (isZodOptional(value)) return {
67
- innerValue: value._def.innerType,
68
- isOptional: true
69
- };
70
- return {
71
- innerValue: value,
72
- isOptional: false
73
- };
74
- }
75
- function isLocateField(value) {
76
- if (!isZodObject(value)) return false;
77
- return 'prompt' in value.shape;
78
- }
79
- function makePromptOptional(value, wrapInOptional) {
80
- const newShape = {
81
- ...value.shape
82
- };
83
- newShape.prompt = value.shape.prompt.optional();
84
- let newSchema = external_zod_namespaceObject.z.object(newShape).passthrough();
85
- if (wrapInOptional) newSchema = newSchema.optional();
86
- return newSchema;
87
- }
88
- function transformSchemaField(key, value) {
89
- const { innerValue, isOptional } = unwrapOptional(value);
90
- if (isZodObject(innerValue) && isLocateField(innerValue)) return [
91
- key,
92
- makePromptOptional(innerValue, isOptional)
93
- ];
94
- return [
95
- key,
96
- value
97
- ];
98
- }
99
- function extractActionSchema(paramSchema) {
100
- if (!paramSchema) return {};
101
- const schema = paramSchema;
102
- if (!isZodObject(schema)) return schema;
103
- return Object.fromEntries(Object.entries(schema.shape).map(([key, value])=>transformSchemaField(key, value)));
104
- }
105
- function serializeArgsToDescription(args) {
106
- try {
107
- return Object.entries(args).map(([key, value])=>{
108
- if ('object' == typeof value && null !== value) try {
109
- return `${key}: ${JSON.stringify(value)}`;
110
- } catch {
111
- return `${key}: [object]`;
112
- }
113
- return `${key}: "${value}"`;
114
- }).join(', ');
115
- } catch (error) {
116
- const errorMessage = getErrorMessage(error);
117
- console.error('Error serializing args:', errorMessage);
118
- return `[args serialization failed: ${errorMessage}]`;
119
- }
120
- }
121
- function buildActionInstruction(actionName, args) {
122
- const locatePrompt = args.locate && 'object' == typeof args.locate ? args.locate.prompt : void 0;
123
- switch(actionName){
124
- case 'Tap':
125
- return locatePrompt ? `Tap on "${locatePrompt}"` : 'Tap';
126
- case 'Input':
127
- {
128
- const value = args.value ?? args.content ?? '';
129
- return locatePrompt ? `Input "${value}" into "${locatePrompt}"` : `Input "${value}"`;
130
- }
131
- case 'Scroll':
132
- {
133
- const direction = args.direction ?? 'down';
134
- return locatePrompt ? `Scroll ${direction} on "${locatePrompt}"` : `Scroll ${direction}`;
135
- }
136
- case 'Hover':
137
- return locatePrompt ? `Hover over "${locatePrompt}"` : 'Hover';
138
- case 'KeyboardPress':
139
- {
140
- const key = args.value ?? args.key ?? '';
141
- return `Press key "${key}"`;
142
- }
143
- default:
144
- {
145
- const argsDescription = serializeArgsToDescription(args);
146
- return argsDescription ? `${actionName}: ${argsDescription}` : actionName;
147
- }
148
- }
149
- }
150
- async function captureScreenshotResult(agent, actionName) {
151
- try {
152
- const screenshot = await agent.page?.screenshotBase64();
153
- if (!screenshot) return {
154
- content: [
155
- {
156
- type: 'text',
157
- text: `Action "${actionName}" completed.`
158
- }
159
- ]
160
- };
161
- const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
162
- return {
163
- content: [
164
- {
165
- type: 'text',
166
- text: `Action "${actionName}" completed.`
167
- },
168
- {
169
- type: 'image',
170
- data: body,
171
- mimeType
172
- }
173
- ]
174
- };
175
- } catch (error) {
176
- const errorMessage = getErrorMessage(error);
177
- console.error('Error capturing screenshot:', errorMessage);
178
- return {
179
- content: [
180
- {
181
- type: 'text',
182
- text: `Action "${actionName}" completed (screenshot unavailable: ${errorMessage})`
183
- }
184
- ]
185
- };
186
- }
187
- }
188
- function createErrorResult(message) {
189
- return {
190
- content: [
191
- {
192
- type: 'text',
193
- text: message
194
- }
195
- ],
196
- isError: true
197
- };
198
- }
199
- async function captureFailureResult(agent, actionName, errorMessage) {
200
- const warningText = `Warning: Action "${actionName}" failed: ${errorMessage}. Check the screenshot below for the current page state and decide how to proceed.`;
201
- try {
202
- const screenshot = await agent.page?.screenshotBase64();
203
- if (!screenshot) return {
204
- content: [
205
- {
206
- type: 'text',
207
- text: warningText
208
- }
209
- ]
210
- };
211
- const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
212
- return {
213
- content: [
214
- {
215
- type: 'text',
216
- text: warningText
217
- },
218
- {
219
- type: 'image',
220
- data: body,
221
- mimeType
222
- }
223
- ]
224
- };
225
- } catch {
226
- return {
227
- content: [
228
- {
229
- type: 'text',
230
- text: warningText
231
- }
232
- ]
233
- };
234
- }
235
- }
236
- function generateToolsFromActionSpace(actionSpace, getAgent) {
237
- return actionSpace.map((action)=>{
238
- const schema = extractActionSchema(action.paramSchema);
239
- return {
240
- name: action.name,
241
- description: describeActionForMCP(action),
242
- schema,
243
- handler: async (args)=>{
244
- try {
245
- const agent = await getAgent();
246
- if (agent.aiAction) {
247
- const instruction = buildActionInstruction(action.name, args);
248
- try {
249
- await agent.aiAction(instruction);
250
- } catch (error) {
251
- const errorMessage = getErrorMessage(error);
252
- console.error(`Error executing action "${action.name}":`, errorMessage);
253
- return await captureFailureResult(agent, action.name, errorMessage);
254
- }
255
- }
256
- return await captureScreenshotResult(agent, action.name);
257
- } catch (error) {
258
- const errorMessage = getErrorMessage(error);
259
- console.error(`Error in handler for "${action.name}":`, errorMessage);
260
- return createErrorResult(`Failed to get agent or execute action "${action.name}": ${errorMessage}`);
261
- }
262
- }
263
- };
264
- });
265
- }
266
- function generateCommonTools(getAgent) {
267
- return [
268
- {
269
- name: 'take_screenshot',
270
- description: 'Capture screenshot of current page/screen',
271
- schema: {},
272
- handler: async ()=>{
273
- try {
274
- const agent = await getAgent();
275
- const screenshot = await agent.page?.screenshotBase64();
276
- if (!screenshot) return createErrorResult('Screenshot not available');
277
- const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
278
- return {
279
- content: [
280
- {
281
- type: 'image',
282
- data: body,
283
- mimeType
284
- }
285
- ]
286
- };
287
- } catch (error) {
288
- const errorMessage = getErrorMessage(error);
289
- console.error('Error taking screenshot:', errorMessage);
290
- return createErrorResult(`Failed to capture screenshot: ${errorMessage}`);
291
- }
292
- }
293
- },
294
- {
295
- name: 'act',
296
- description: 'Execute a natural language action. The AI will plan and perform multi-step operations in a single invocation, useful for transient UI interactions (e.g., Spotlight, dropdown menus) that disappear between separate commands.',
297
- schema: {
298
- prompt: external_zod_namespaceObject.z.string().describe('Natural language description of the action to perform, e.g. "press Command+Space, type Safari, press Enter"')
299
- },
300
- handler: async (args)=>{
301
- const prompt = args.prompt;
302
- try {
303
- const agent = await getAgent();
304
- if (!agent.aiAction) return createErrorResult('act is not supported by this agent');
305
- const result = await agent.aiAction(prompt, {
306
- deepThink: false
307
- });
308
- const screenshotResult = await captureScreenshotResult(agent, 'act');
309
- if (result) {
310
- const message = 'string' == typeof result ? result : JSON.stringify(result);
311
- screenshotResult.content.unshift({
312
- type: 'text',
313
- text: `Task finished, message: ${message}`
314
- });
315
- }
316
- return screenshotResult;
317
- } catch (error) {
318
- const errorMessage = getErrorMessage(error);
319
- console.error('Error executing act:', errorMessage);
320
- return createErrorResult(`Failed to execute act: ${errorMessage}`);
321
- }
322
- }
323
- }
324
- ];
325
- }
326
- exports.generateCommonTools = __webpack_exports__.generateCommonTools;
327
- exports.generateToolsFromActionSpace = __webpack_exports__.generateToolsFromActionSpace;
328
- for(var __rspack_i in __webpack_exports__)if (-1 === [
329
- "generateCommonTools",
330
- "generateToolsFromActionSpace"
331
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
332
- Object.defineProperty(exports, '__esModule', {
333
- value: true
334
- });
@@ -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
- });