@midscene/shared 1.7.5-beta-20260421030751.0 → 1.7.5
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/cli/cli-args.mjs +95 -0
- package/dist/es/cli/cli-error.mjs +24 -0
- package/dist/es/cli/cli-runner.mjs +10 -40
- package/dist/es/cli/index.mjs +4 -2
- package/dist/es/constants/index.mjs +3 -2
- package/dist/es/key-alias-utils.mjs +19 -0
- package/dist/es/mcp/base-tools.mjs +45 -2
- package/dist/es/mcp/index.mjs +1 -0
- package/dist/es/mcp/init-arg-utils.mjs +38 -0
- package/dist/es/mcp/tool-generator.mjs +29 -11
- package/dist/lib/cli/cli-args.js +138 -0
- package/dist/lib/cli/cli-error.js +61 -0
- package/dist/lib/cli/cli-runner.js +19 -46
- package/dist/lib/cli/index.js +8 -3
- package/dist/lib/constants/index.js +5 -1
- package/dist/lib/key-alias-utils.js +62 -0
- package/dist/lib/mcp/base-tools.js +45 -2
- package/dist/lib/mcp/index.js +19 -12
- package/dist/lib/mcp/init-arg-utils.js +78 -0
- package/dist/lib/mcp/tool-generator.js +29 -11
- package/dist/types/cli/cli-args.d.ts +8 -0
- package/dist/types/cli/cli-error.d.ts +5 -0
- package/dist/types/cli/cli-runner.d.ts +4 -7
- package/dist/types/cli/index.d.ts +3 -1
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/key-alias-utils.d.ts +9 -0
- package/dist/types/mcp/base-tools.d.ts +65 -5
- package/dist/types/mcp/index.d.ts +1 -0
- package/dist/types/mcp/init-arg-utils.d.ts +13 -0
- package/dist/types/mcp/tool-generator.d.ts +3 -3
- package/dist/types/mcp/types.d.ts +8 -0
- package/package.json +1 -1
- package/src/cli/cli-args.ts +173 -0
- package/src/cli/cli-error.ts +24 -0
- package/src/cli/cli-runner.ts +37 -56
- package/src/cli/index.ts +3 -7
- package/src/constants/index.ts +2 -0
- package/src/key-alias-utils.ts +23 -0
- package/src/mcp/base-tools.ts +164 -9
- package/src/mcp/index.ts +1 -0
- package/src/mcp/init-arg-utils.ts +105 -0
- package/src/mcp/tool-generator.ts +47 -10
- package/src/mcp/types.ts +10 -0
|
@@ -33,10 +33,11 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
CLIError: ()=>CLIError,
|
|
37
|
-
parseCliArgs: ()=>parseCliArgs,
|
|
38
|
-
parseValue: ()=>parseValue,
|
|
36
|
+
CLIError: ()=>external_cli_error_js_namespaceObject.CLIError,
|
|
37
|
+
parseCliArgs: ()=>external_cli_args_js_namespaceObject.parseCliArgs,
|
|
38
|
+
parseValue: ()=>external_cli_args_js_namespaceObject.parseValue,
|
|
39
39
|
runToolsCLI: ()=>runToolsCLI,
|
|
40
|
+
reportCLIError: ()=>external_cli_error_js_namespaceObject.reportCLIError,
|
|
40
41
|
removePrefix: ()=>removePrefix
|
|
41
42
|
});
|
|
42
43
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
@@ -45,44 +46,9 @@ const external_node_path_namespaceObject = require("node:path");
|
|
|
45
46
|
const external_dotenv_namespaceObject = require("dotenv");
|
|
46
47
|
var external_dotenv_default = /*#__PURE__*/ __webpack_require__.n(external_dotenv_namespaceObject);
|
|
47
48
|
const external_logger_js_namespaceObject = require("../logger.js");
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
value: value,
|
|
51
|
-
enumerable: true,
|
|
52
|
-
configurable: true,
|
|
53
|
-
writable: true
|
|
54
|
-
});
|
|
55
|
-
else obj[key] = value;
|
|
56
|
-
return obj;
|
|
57
|
-
}
|
|
49
|
+
const external_cli_args_js_namespaceObject = require("./cli-args.js");
|
|
50
|
+
const external_cli_error_js_namespaceObject = require("./cli-error.js");
|
|
58
51
|
const debug = (0, external_logger_js_namespaceObject.getDebug)('cli-runner');
|
|
59
|
-
class CLIError extends Error {
|
|
60
|
-
constructor(message, exitCode = 1){
|
|
61
|
-
super(message), _define_property(this, "exitCode", void 0), this.exitCode = exitCode;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function parseValue(raw) {
|
|
65
|
-
if (raw.startsWith('{') || raw.startsWith('[')) try {
|
|
66
|
-
return JSON.parse(raw);
|
|
67
|
-
} catch {}
|
|
68
|
-
if (/^-?\d+(\.\d+)?$/.test(raw)) return Number(raw);
|
|
69
|
-
return raw;
|
|
70
|
-
}
|
|
71
|
-
function parseCliArgs(args) {
|
|
72
|
-
const result = {};
|
|
73
|
-
for(let i = 0; i < args.length; i++){
|
|
74
|
-
const arg = args[i];
|
|
75
|
-
if (!arg.startsWith('--')) continue;
|
|
76
|
-
const body = arg.slice(2);
|
|
77
|
-
const eqIdx = body.indexOf('=');
|
|
78
|
-
if (eqIdx >= 0) result[body.slice(0, eqIdx)] = parseValue(body.slice(eqIdx + 1));
|
|
79
|
-
else if (args[i + 1] && !args[i + 1].startsWith('--')) {
|
|
80
|
-
i++;
|
|
81
|
-
result[body] = parseValue(args[i]);
|
|
82
|
-
} else result[body] = true;
|
|
83
|
-
}
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
52
|
function outputContentItem(item, isError) {
|
|
87
53
|
switch(item.type){
|
|
88
54
|
case 'text':
|
|
@@ -114,10 +80,13 @@ function printCommandHelp(scriptName, cmd) {
|
|
|
114
80
|
console.log(def.description);
|
|
115
81
|
const schemaEntries = Object.entries(def.schema);
|
|
116
82
|
if (schemaEntries.length > 0) {
|
|
83
|
+
const optionWidth = Math.max(22, ...schemaEntries.map(([key])=>(0, external_cli_args_js_namespaceObject.getCliOptionDisplay)(key, def.cli?.options?.[key]).label.length));
|
|
117
84
|
console.log('\nOptions:');
|
|
118
85
|
for (const [key, zodType] of schemaEntries){
|
|
86
|
+
const { label, aliases } = (0, external_cli_args_js_namespaceObject.getCliOptionDisplay)(key, def.cli?.options?.[key]);
|
|
119
87
|
const desc = zodType.description ?? '';
|
|
120
|
-
|
|
88
|
+
const aliasText = aliases.length > 0 ? ` (aliases: ${aliases.join(', ')})` : '';
|
|
89
|
+
console.log(` ${label.padEnd(optionWidth)} ${desc}${aliasText}`);
|
|
121
90
|
}
|
|
122
91
|
}
|
|
123
92
|
}
|
|
@@ -167,7 +136,7 @@ async function runToolsCLI(tools, scriptName, options) {
|
|
|
167
136
|
return;
|
|
168
137
|
}
|
|
169
138
|
if ('--version' === commandName || '-v' === commandName || 'version' === commandName.toLowerCase()) {
|
|
170
|
-
if (!cliVersion) throw new CLIError('Failed to determine CLI version');
|
|
139
|
+
if (!cliVersion) throw new external_cli_error_js_namespaceObject.CLIError('Failed to determine CLI version');
|
|
171
140
|
printVersion(scriptName, cliVersion);
|
|
172
141
|
return;
|
|
173
142
|
}
|
|
@@ -176,31 +145,35 @@ async function runToolsCLI(tools, scriptName, options) {
|
|
|
176
145
|
debug('unknown command: %s', commandName);
|
|
177
146
|
console.error(`Unknown command: ${commandName}`);
|
|
178
147
|
printHelp(scriptName, commands, cliVersion);
|
|
179
|
-
throw new CLIError(`Unknown command: ${commandName}`);
|
|
148
|
+
throw new external_cli_error_js_namespaceObject.CLIError(`Unknown command: ${commandName}`);
|
|
180
149
|
}
|
|
181
|
-
const parsedArgs = parseCliArgs(restArgs);
|
|
182
|
-
debug('command: %s, args: %s', match.name, JSON.stringify(parsedArgs));
|
|
150
|
+
const parsedArgs = (0, external_cli_args_js_namespaceObject.parseCliArgs)(restArgs);
|
|
183
151
|
if (true === parsedArgs.help) {
|
|
184
152
|
debug('showing command help for: %s', match.name);
|
|
185
153
|
printCommandHelp(scriptName, match);
|
|
186
154
|
return;
|
|
187
155
|
}
|
|
156
|
+
const cliValidationError = (0, external_cli_args_js_namespaceObject.formatCliValidationError)(scriptName, match.name, match.def, parsedArgs);
|
|
157
|
+
if (cliValidationError) throw new external_cli_error_js_namespaceObject.CLIError(cliValidationError);
|
|
158
|
+
debug('command: %s, args: %s', match.name, JSON.stringify(parsedArgs));
|
|
188
159
|
const result = await match.def.handler(parsedArgs);
|
|
189
160
|
debug('command %s completed, isError: %s', match.name, result.isError ?? false);
|
|
190
161
|
outputResult(result);
|
|
191
162
|
await tools.destroy();
|
|
192
|
-
if (result.isError) throw new CLIError('Command failed', 1);
|
|
163
|
+
if (result.isError) throw new external_cli_error_js_namespaceObject.CLIError('Command failed', 1);
|
|
193
164
|
}
|
|
194
165
|
exports.CLIError = __webpack_exports__.CLIError;
|
|
195
166
|
exports.parseCliArgs = __webpack_exports__.parseCliArgs;
|
|
196
167
|
exports.parseValue = __webpack_exports__.parseValue;
|
|
197
168
|
exports.removePrefix = __webpack_exports__.removePrefix;
|
|
169
|
+
exports.reportCLIError = __webpack_exports__.reportCLIError;
|
|
198
170
|
exports.runToolsCLI = __webpack_exports__.runToolsCLI;
|
|
199
171
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
200
172
|
"CLIError",
|
|
201
173
|
"parseCliArgs",
|
|
202
174
|
"parseValue",
|
|
203
175
|
"removePrefix",
|
|
176
|
+
"reportCLIError",
|
|
204
177
|
"runToolsCLI"
|
|
205
178
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
206
179
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/lib/cli/index.js
CHANGED
|
@@ -24,23 +24,28 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
CLIError: ()=>
|
|
28
|
-
parseCliArgs: ()=>
|
|
29
|
-
parseValue: ()=>
|
|
27
|
+
CLIError: ()=>external_cli_error_js_namespaceObject.CLIError,
|
|
28
|
+
parseCliArgs: ()=>external_cli_args_js_namespaceObject.parseCliArgs,
|
|
29
|
+
parseValue: ()=>external_cli_args_js_namespaceObject.parseValue,
|
|
30
30
|
runToolsCLI: ()=>external_cli_runner_js_namespaceObject.runToolsCLI,
|
|
31
|
+
reportCLIError: ()=>external_cli_error_js_namespaceObject.reportCLIError,
|
|
31
32
|
removePrefix: ()=>external_cli_runner_js_namespaceObject.removePrefix
|
|
32
33
|
});
|
|
34
|
+
const external_cli_error_js_namespaceObject = require("./cli-error.js");
|
|
35
|
+
const external_cli_args_js_namespaceObject = require("./cli-args.js");
|
|
33
36
|
const external_cli_runner_js_namespaceObject = require("./cli-runner.js");
|
|
34
37
|
exports.CLIError = __webpack_exports__.CLIError;
|
|
35
38
|
exports.parseCliArgs = __webpack_exports__.parseCliArgs;
|
|
36
39
|
exports.parseValue = __webpack_exports__.parseValue;
|
|
37
40
|
exports.removePrefix = __webpack_exports__.removePrefix;
|
|
41
|
+
exports.reportCLIError = __webpack_exports__.reportCLIError;
|
|
38
42
|
exports.runToolsCLI = __webpack_exports__.runToolsCLI;
|
|
39
43
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
40
44
|
"CLIError",
|
|
41
45
|
"parseCliArgs",
|
|
42
46
|
"parseValue",
|
|
43
47
|
"removePrefix",
|
|
48
|
+
"reportCLIError",
|
|
44
49
|
"runToolsCLI"
|
|
45
50
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
46
51
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -35,6 +35,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
35
35
|
YAML_EXAMPLE_CODE: ()=>external_example_code_js_namespaceObject.YAML_EXAMPLE_CODE,
|
|
36
36
|
CONTAINER_MINI_HEIGHT: ()=>CONTAINER_MINI_HEIGHT,
|
|
37
37
|
SCRCPY_VIDEO_STREAM_TIMEOUT_MS: ()=>SCRCPY_VIDEO_STREAM_TIMEOUT_MS,
|
|
38
|
+
SCRCPY_ADB_CONNECT_TIMEOUT_MS: ()=>SCRCPY_ADB_CONNECT_TIMEOUT_MS,
|
|
38
39
|
SCRCPY_START_TIMEOUT_MS: ()=>SCRCPY_START_TIMEOUT_MS,
|
|
39
40
|
PLAYGROUND_SERVER_PORT: ()=>PLAYGROUND_SERVER_PORT,
|
|
40
41
|
DEFAULT_WDA_PORT: ()=>DEFAULT_WDA_PORT,
|
|
@@ -60,10 +61,11 @@ var constants_NodeType = /*#__PURE__*/ function(NodeType) {
|
|
|
60
61
|
}({});
|
|
61
62
|
const PLAYGROUND_SERVER_PORT = 5800;
|
|
62
63
|
const SCRCPY_SERVER_PORT = 5700;
|
|
64
|
+
const SCRCPY_ADB_CONNECT_TIMEOUT_MS = 10000;
|
|
63
65
|
const SCRCPY_PUSH_TIMEOUT_MS = 10000;
|
|
64
66
|
const SCRCPY_START_TIMEOUT_MS = 15000;
|
|
65
67
|
const SCRCPY_VIDEO_STREAM_TIMEOUT_MS = 15000;
|
|
66
|
-
const SCRCPY_PREVIEW_METADATA_TIMEOUT_MS = SCRCPY_PUSH_TIMEOUT_MS + SCRCPY_START_TIMEOUT_MS + SCRCPY_VIDEO_STREAM_TIMEOUT_MS + 5000;
|
|
68
|
+
const SCRCPY_PREVIEW_METADATA_TIMEOUT_MS = SCRCPY_ADB_CONNECT_TIMEOUT_MS + SCRCPY_PUSH_TIMEOUT_MS + SCRCPY_START_TIMEOUT_MS + SCRCPY_VIDEO_STREAM_TIMEOUT_MS + 5000;
|
|
67
69
|
const WEBDRIVER_ELEMENT_ID_KEY = 'element-6066-11e4-a52e-4f735466cecf';
|
|
68
70
|
const DEFAULT_WDA_PORT = 8100;
|
|
69
71
|
const DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT = 5000;
|
|
@@ -78,6 +80,7 @@ exports.DEFAULT_WDA_PORT = __webpack_exports__.DEFAULT_WDA_PORT;
|
|
|
78
80
|
exports.NodeType = __webpack_exports__.NodeType;
|
|
79
81
|
exports.PLAYGROUND_SERVER_PORT = __webpack_exports__.PLAYGROUND_SERVER_PORT;
|
|
80
82
|
exports.PLAYWRIGHT_EXAMPLE_CODE = __webpack_exports__.PLAYWRIGHT_EXAMPLE_CODE;
|
|
83
|
+
exports.SCRCPY_ADB_CONNECT_TIMEOUT_MS = __webpack_exports__.SCRCPY_ADB_CONNECT_TIMEOUT_MS;
|
|
81
84
|
exports.SCRCPY_PREVIEW_METADATA_TIMEOUT_MS = __webpack_exports__.SCRCPY_PREVIEW_METADATA_TIMEOUT_MS;
|
|
82
85
|
exports.SCRCPY_PUSH_TIMEOUT_MS = __webpack_exports__.SCRCPY_PUSH_TIMEOUT_MS;
|
|
83
86
|
exports.SCRCPY_SERVER_PORT = __webpack_exports__.SCRCPY_SERVER_PORT;
|
|
@@ -97,6 +100,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
97
100
|
"NodeType",
|
|
98
101
|
"PLAYGROUND_SERVER_PORT",
|
|
99
102
|
"PLAYWRIGHT_EXAMPLE_CODE",
|
|
103
|
+
"SCRCPY_ADB_CONNECT_TIMEOUT_MS",
|
|
100
104
|
"SCRCPY_PREVIEW_METADATA_TIMEOUT_MS",
|
|
101
105
|
"SCRCPY_PUSH_TIMEOUT_MS",
|
|
102
106
|
"SCRCPY_SERVER_PORT",
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
camelToKebab: ()=>camelToKebab,
|
|
28
|
+
getKeyAliases: ()=>getKeyAliases,
|
|
29
|
+
isRecord: ()=>isRecord,
|
|
30
|
+
kebabToCamel: ()=>kebabToCamel
|
|
31
|
+
});
|
|
32
|
+
function kebabToCamel(str) {
|
|
33
|
+
return str.replace(/-([a-z])/g, (_, letter)=>letter.toUpperCase());
|
|
34
|
+
}
|
|
35
|
+
function camelToKebab(str) {
|
|
36
|
+
return str.replace(/[A-Z]/g, (letter)=>`-${letter.toLowerCase()}`).replace(/^-/, '');
|
|
37
|
+
}
|
|
38
|
+
function getKeyAliases(key) {
|
|
39
|
+
return [
|
|
40
|
+
...new Set([
|
|
41
|
+
key,
|
|
42
|
+
kebabToCamel(key),
|
|
43
|
+
camelToKebab(key)
|
|
44
|
+
])
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
function isRecord(value) {
|
|
48
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
49
|
+
}
|
|
50
|
+
exports.camelToKebab = __webpack_exports__.camelToKebab;
|
|
51
|
+
exports.getKeyAliases = __webpack_exports__.getKeyAliases;
|
|
52
|
+
exports.isRecord = __webpack_exports__.isRecord;
|
|
53
|
+
exports.kebabToCamel = __webpack_exports__.kebabToCamel;
|
|
54
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
55
|
+
"camelToKebab",
|
|
56
|
+
"getKeyAliases",
|
|
57
|
+
"isRecord",
|
|
58
|
+
"kebabToCamel"
|
|
59
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
60
|
+
Object.defineProperty(exports, '__esModule', {
|
|
61
|
+
value: true
|
|
62
|
+
});
|
|
@@ -28,6 +28,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
});
|
|
29
29
|
const img_namespaceObject = require("@midscene/shared/img");
|
|
30
30
|
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
31
|
+
const external_key_alias_utils_js_namespaceObject = require("../key-alias-utils.js");
|
|
32
|
+
const external_init_arg_utils_js_namespaceObject = require("./init-arg-utils.js");
|
|
31
33
|
const external_tool_generator_js_namespaceObject = require("./tool-generator.js");
|
|
32
34
|
function _define_property(obj, key, value) {
|
|
33
35
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -41,6 +43,47 @@ function _define_property(obj, key, value) {
|
|
|
41
43
|
}
|
|
42
44
|
const debug = (0, logger_namespaceObject.getDebug)('mcp:base-tools');
|
|
43
45
|
class BaseMidsceneTools {
|
|
46
|
+
getInitArgKeys() {
|
|
47
|
+
return this.initArgSpec ? Object.keys(this.initArgSpec.shape) : [];
|
|
48
|
+
}
|
|
49
|
+
extractAgentInitParam(args) {
|
|
50
|
+
if (!this.initArgSpec) return;
|
|
51
|
+
const extracted = (0, external_init_arg_utils_js_namespaceObject.extractNamespacedArgs)(args, this.initArgSpec.namespace, this.getInitArgKeys());
|
|
52
|
+
if (this.initArgSpec.adapt) return this.initArgSpec.adapt(extracted);
|
|
53
|
+
return extracted;
|
|
54
|
+
}
|
|
55
|
+
sanitizeToolArgs(args) {
|
|
56
|
+
if (!this.initArgSpec) return args;
|
|
57
|
+
return (0, external_init_arg_utils_js_namespaceObject.sanitizeNamespacedArgs)(args, this.initArgSpec.namespace, this.getInitArgKeys());
|
|
58
|
+
}
|
|
59
|
+
getAgentInitArgSchema() {
|
|
60
|
+
if (!this.initArgSpec) return {};
|
|
61
|
+
return (0, external_init_arg_utils_js_namespaceObject.createNamespacedInitArgSchema)(this.initArgSpec.namespace, this.initArgSpec.shape);
|
|
62
|
+
}
|
|
63
|
+
getAgentInitArgCliMetadata() {
|
|
64
|
+
if (!this.initArgSpec?.cli) return;
|
|
65
|
+
const options = Object.fromEntries(this.getInitArgKeys().map((key)=>{
|
|
66
|
+
const canonicalKey = `${this.initArgSpec.namespace}.${key}`;
|
|
67
|
+
const preferredName = this.initArgSpec.cli?.preferredNames?.[key] ?? (this.initArgSpec.cli?.preferBareKeys ? (0, external_key_alias_utils_js_namespaceObject.camelToKebab)(key) : canonicalKey);
|
|
68
|
+
const acceptedNames = new Set([
|
|
69
|
+
preferredName,
|
|
70
|
+
...this.initArgSpec.cli?.preferBareKeys ? (0, external_key_alias_utils_js_namespaceObject.getKeyAliases)(key) : (0, external_key_alias_utils_js_namespaceObject.getKeyAliases)(canonicalKey)
|
|
71
|
+
]);
|
|
72
|
+
acceptedNames.delete(preferredName);
|
|
73
|
+
return [
|
|
74
|
+
canonicalKey,
|
|
75
|
+
{
|
|
76
|
+
preferredName,
|
|
77
|
+
aliases: [
|
|
78
|
+
...acceptedNames
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
}));
|
|
83
|
+
return {
|
|
84
|
+
options
|
|
85
|
+
};
|
|
86
|
+
}
|
|
44
87
|
preparePlatformTools() {
|
|
45
88
|
return [];
|
|
46
89
|
}
|
|
@@ -58,8 +101,8 @@ class BaseMidsceneTools {
|
|
|
58
101
|
await tempDevice.destroy?.();
|
|
59
102
|
debug('Action space from temporary device:', actionSpace.map((a)=>a.name).join(', '));
|
|
60
103
|
}
|
|
61
|
-
const actionTools = (0, external_tool_generator_js_namespaceObject.generateToolsFromActionSpace)(actionSpace, ()=>this.ensureAgent());
|
|
62
|
-
const commonTools = (0, external_tool_generator_js_namespaceObject.generateCommonTools)(()=>this.ensureAgent());
|
|
104
|
+
const actionTools = (0, external_tool_generator_js_namespaceObject.generateToolsFromActionSpace)(actionSpace, (args = {})=>this.ensureAgent(this.extractAgentInitParam(args)), (args = {})=>this.sanitizeToolArgs(args), this.getAgentInitArgSchema(), this.getAgentInitArgCliMetadata());
|
|
105
|
+
const commonTools = (0, external_tool_generator_js_namespaceObject.generateCommonTools)((args = {})=>this.ensureAgent(this.extractAgentInitParam(args)), this.getAgentInitArgSchema(), this.getAgentInitArgCliMetadata());
|
|
63
106
|
this.toolDefinitions.push(...actionTools, ...commonTools);
|
|
64
107
|
debug('Total tools prepared:', this.toolDefinitions.length);
|
|
65
108
|
}
|
package/dist/lib/mcp/index.js
CHANGED
|
@@ -12,6 +12,9 @@ var __webpack_modules__ = {
|
|
|
12
12
|
"./error-formatter" (module) {
|
|
13
13
|
module.exports = require("./error-formatter.js");
|
|
14
14
|
},
|
|
15
|
+
"./init-arg-utils" (module) {
|
|
16
|
+
module.exports = require("./init-arg-utils.js");
|
|
17
|
+
},
|
|
15
18
|
"./inject-report-html-plugin" (module) {
|
|
16
19
|
module.exports = require("./inject-report-html-plugin.js");
|
|
17
20
|
},
|
|
@@ -76,29 +79,33 @@ var __webpack_exports__ = {};
|
|
|
76
79
|
var __rspack_reexport = {};
|
|
77
80
|
for(const __rspack_import_key in _base_tools__rspack_import_1)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_base_tools__rspack_import_1[__rspack_import_key];
|
|
78
81
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
79
|
-
var
|
|
82
|
+
var _init_arg_utils__rspack_import_2 = __webpack_require__("./init-arg-utils");
|
|
83
|
+
var __rspack_reexport = {};
|
|
84
|
+
for(const __rspack_import_key in _init_arg_utils__rspack_import_2)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_init_arg_utils__rspack_import_2[__rspack_import_key];
|
|
85
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
86
|
+
var _error_formatter__rspack_import_3 = __webpack_require__("./error-formatter");
|
|
80
87
|
var __rspack_reexport = {};
|
|
81
|
-
for(const __rspack_import_key in
|
|
88
|
+
for(const __rspack_import_key in _error_formatter__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_error_formatter__rspack_import_3[__rspack_import_key];
|
|
82
89
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
83
|
-
var
|
|
90
|
+
var _tool_generator__rspack_import_4 = __webpack_require__("./tool-generator");
|
|
84
91
|
var __rspack_reexport = {};
|
|
85
|
-
for(const __rspack_import_key in
|
|
92
|
+
for(const __rspack_import_key in _tool_generator__rspack_import_4)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_tool_generator__rspack_import_4[__rspack_import_key];
|
|
86
93
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
87
|
-
var
|
|
94
|
+
var _types__rspack_import_5 = __webpack_require__("./types");
|
|
88
95
|
var __rspack_reexport = {};
|
|
89
|
-
for(const __rspack_import_key in
|
|
96
|
+
for(const __rspack_import_key in _types__rspack_import_5)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_5[__rspack_import_key];
|
|
90
97
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
91
|
-
var
|
|
98
|
+
var _inject_report_html_plugin__rspack_import_6 = __webpack_require__("./inject-report-html-plugin");
|
|
92
99
|
var __rspack_reexport = {};
|
|
93
|
-
for(const __rspack_import_key in
|
|
100
|
+
for(const __rspack_import_key in _inject_report_html_plugin__rspack_import_6)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_inject_report_html_plugin__rspack_import_6[__rspack_import_key];
|
|
94
101
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
95
|
-
var
|
|
102
|
+
var _launcher_helper__rspack_import_7 = __webpack_require__("./launcher-helper");
|
|
96
103
|
var __rspack_reexport = {};
|
|
97
|
-
for(const __rspack_import_key in
|
|
104
|
+
for(const __rspack_import_key in _launcher_helper__rspack_import_7)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_launcher_helper__rspack_import_7[__rspack_import_key];
|
|
98
105
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
99
|
-
var
|
|
106
|
+
var _chrome_path__rspack_import_8 = __webpack_require__("./chrome-path");
|
|
100
107
|
var __rspack_reexport = {};
|
|
101
|
-
for(const __rspack_import_key in
|
|
108
|
+
for(const __rspack_import_key in _chrome_path__rspack_import_8)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_chrome_path__rspack_import_8[__rspack_import_key];
|
|
102
109
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
103
110
|
})();
|
|
104
111
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
createNamespacedInitArgSchema: ()=>createNamespacedInitArgSchema,
|
|
28
|
+
extractNamespacedArgs: ()=>extractNamespacedArgs,
|
|
29
|
+
sanitizeNamespacedArgs: ()=>sanitizeNamespacedArgs
|
|
30
|
+
});
|
|
31
|
+
const external_key_alias_utils_js_namespaceObject = require("../key-alias-utils.js");
|
|
32
|
+
function readAliasedValue(args, key) {
|
|
33
|
+
for (const alias of (0, external_key_alias_utils_js_namespaceObject.getKeyAliases)(key))if (alias in args) return args[alias];
|
|
34
|
+
}
|
|
35
|
+
function readNamespacedArg(args, namespace, key) {
|
|
36
|
+
const namespacedArgs = readAliasedValue(args, namespace);
|
|
37
|
+
if ((0, external_key_alias_utils_js_namespaceObject.isRecord)(namespacedArgs)) {
|
|
38
|
+
const nestedValue = readAliasedValue(namespacedArgs, key);
|
|
39
|
+
if (void 0 !== nestedValue) return nestedValue;
|
|
40
|
+
}
|
|
41
|
+
const dottedValue = readAliasedValue(args, `${namespace}.${key}`);
|
|
42
|
+
if (void 0 !== dottedValue) return dottedValue;
|
|
43
|
+
const directValue = readAliasedValue(args, key);
|
|
44
|
+
if (void 0 !== directValue) return directValue;
|
|
45
|
+
}
|
|
46
|
+
function extractNamespacedArgs(args, namespace, keys) {
|
|
47
|
+
const extracted = {};
|
|
48
|
+
for (const key of keys){
|
|
49
|
+
const value = readNamespacedArg(args, namespace, key);
|
|
50
|
+
if (void 0 !== value) extracted[key] = value;
|
|
51
|
+
}
|
|
52
|
+
return Object.keys(extracted).length > 0 ? extracted : void 0;
|
|
53
|
+
}
|
|
54
|
+
function sanitizeNamespacedArgs(args, namespace, keys) {
|
|
55
|
+
const excludedKeys = new Set((0, external_key_alias_utils_js_namespaceObject.getKeyAliases)(namespace));
|
|
56
|
+
for (const key of keys){
|
|
57
|
+
for (const alias of (0, external_key_alias_utils_js_namespaceObject.getKeyAliases)(key))excludedKeys.add(alias);
|
|
58
|
+
for (const alias of (0, external_key_alias_utils_js_namespaceObject.getKeyAliases)(`${namespace}.${key}`))excludedKeys.add(alias);
|
|
59
|
+
}
|
|
60
|
+
return Object.fromEntries(Object.entries(args).filter(([key])=>!excludedKeys.has(key)));
|
|
61
|
+
}
|
|
62
|
+
function createNamespacedInitArgSchema(namespace, shape) {
|
|
63
|
+
return Object.fromEntries(Object.entries(shape).map(([key, value])=>[
|
|
64
|
+
`${namespace}.${key}`,
|
|
65
|
+
value
|
|
66
|
+
]));
|
|
67
|
+
}
|
|
68
|
+
exports.createNamespacedInitArgSchema = __webpack_exports__.createNamespacedInitArgSchema;
|
|
69
|
+
exports.extractNamespacedArgs = __webpack_exports__.extractNamespacedArgs;
|
|
70
|
+
exports.sanitizeNamespacedArgs = __webpack_exports__.sanitizeNamespacedArgs;
|
|
71
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
72
|
+
"createNamespacedInitArgSchema",
|
|
73
|
+
"extractNamespacedArgs",
|
|
74
|
+
"sanitizeNamespacedArgs"
|
|
75
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
76
|
+
Object.defineProperty(exports, '__esModule', {
|
|
77
|
+
value: true
|
|
78
|
+
});
|
|
@@ -306,17 +306,30 @@ async function captureFailureResult(agent, actionName, errorMessage) {
|
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
|
-
function
|
|
309
|
+
function mergeToolCliMetadata(base, extra) {
|
|
310
|
+
const options = {
|
|
311
|
+
...base?.options ?? {},
|
|
312
|
+
...extra?.options ?? {}
|
|
313
|
+
};
|
|
314
|
+
return Object.keys(options).length > 0 ? {
|
|
315
|
+
options
|
|
316
|
+
} : void 0;
|
|
317
|
+
}
|
|
318
|
+
function generateToolsFromActionSpace(actionSpace, getAgent, sanitizeArgs = (args)=>args, initArgSchema = {}, initArgCliMetadata) {
|
|
310
319
|
return actionSpace.map((action)=>{
|
|
311
|
-
const schema =
|
|
320
|
+
const schema = {
|
|
321
|
+
...extractActionSchema(action.paramSchema),
|
|
322
|
+
...initArgSchema
|
|
323
|
+
};
|
|
312
324
|
return {
|
|
313
325
|
name: action.name,
|
|
314
326
|
description: describeActionForMCP(action),
|
|
315
327
|
schema,
|
|
328
|
+
cli: initArgCliMetadata,
|
|
316
329
|
handler: async (args)=>{
|
|
317
330
|
try {
|
|
318
|
-
const agent = await getAgent();
|
|
319
|
-
const normalizedArgs = normalizeActionArgs(args, action.paramSchema);
|
|
331
|
+
const agent = await getAgent(args);
|
|
332
|
+
const normalizedArgs = normalizeActionArgs(sanitizeArgs(args), action.paramSchema);
|
|
320
333
|
let actionResult;
|
|
321
334
|
try {
|
|
322
335
|
actionResult = await executeAction(agent, action.name, normalizedArgs);
|
|
@@ -335,15 +348,18 @@ function generateToolsFromActionSpace(actionSpace, getAgent) {
|
|
|
335
348
|
};
|
|
336
349
|
});
|
|
337
350
|
}
|
|
338
|
-
function generateCommonTools(getAgent) {
|
|
351
|
+
function generateCommonTools(getAgent, initArgSchema = {}, initArgCliMetadata) {
|
|
339
352
|
return [
|
|
340
353
|
{
|
|
341
354
|
name: 'take_screenshot',
|
|
342
355
|
description: 'Capture screenshot of current page/screen',
|
|
343
|
-
schema: {
|
|
344
|
-
|
|
356
|
+
schema: {
|
|
357
|
+
...initArgSchema
|
|
358
|
+
},
|
|
359
|
+
cli: initArgCliMetadata,
|
|
360
|
+
handler: async (args = {})=>{
|
|
345
361
|
try {
|
|
346
|
-
const agent = await getAgent();
|
|
362
|
+
const agent = await getAgent(args);
|
|
347
363
|
const screenshot = await agent.page?.screenshotBase64();
|
|
348
364
|
if (!screenshot) return createErrorResult('Screenshot not available');
|
|
349
365
|
const { mimeType, body } = (0, img_namespaceObject.parseBase64)(screenshot);
|
|
@@ -367,12 +383,14 @@ function generateCommonTools(getAgent) {
|
|
|
367
383
|
name: 'act',
|
|
368
384
|
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.',
|
|
369
385
|
schema: {
|
|
370
|
-
prompt: external_zod_namespaceObject.z.string().describe('Natural language description of the action to perform, e.g. "press Command+Space, type Safari, press Enter"')
|
|
386
|
+
prompt: external_zod_namespaceObject.z.string().describe('Natural language description of the action to perform, e.g. "press Command+Space, type Safari, press Enter"'),
|
|
387
|
+
...initArgSchema
|
|
371
388
|
},
|
|
372
|
-
|
|
389
|
+
cli: mergeToolCliMetadata(void 0, initArgCliMetadata),
|
|
390
|
+
handler: async (args = {})=>{
|
|
373
391
|
const prompt = args.prompt;
|
|
374
392
|
try {
|
|
375
|
-
const agent = await getAgent();
|
|
393
|
+
const agent = await getAgent(args);
|
|
376
394
|
if (!agent.aiAction) return createErrorResult('act is not supported by this agent');
|
|
377
395
|
const result = await agent.aiAction(prompt, {
|
|
378
396
|
deepThink: false
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolCliOption, ToolDefinition } from '../mcp/types';
|
|
2
|
+
export declare function parseValue(raw: string): unknown;
|
|
3
|
+
export declare function parseCliArgs(args: string[]): Record<string, unknown>;
|
|
4
|
+
export declare function getCliOptionDisplay(key: string, cliOption?: ToolCliOption): {
|
|
5
|
+
label: string;
|
|
6
|
+
aliases: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare function formatCliValidationError(scriptName: string, commandName: string, def: ToolDefinition, rawArgs: Record<string, unknown>): string | undefined;
|
|
@@ -12,11 +12,8 @@ export interface CLIRunnerOptions {
|
|
|
12
12
|
version?: string;
|
|
13
13
|
extraCommands?: CLIExtraCommand[];
|
|
14
14
|
}
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
constructor(message: string, exitCode?: number);
|
|
18
|
-
}
|
|
19
|
-
export declare function parseValue(raw: string): unknown;
|
|
20
|
-
export declare function parseCliArgs(args: string[]): Record<string, unknown>;
|
|
15
|
+
export { parseCliArgs, parseValue } from './cli-args';
|
|
16
|
+
export { CLIError, reportCLIError } from './cli-error';
|
|
21
17
|
export declare function removePrefix(name: string, prefix?: string): string;
|
|
22
|
-
|
|
18
|
+
type AnyMidsceneTools = BaseMidsceneTools<any, any>;
|
|
19
|
+
export declare function runToolsCLI(tools: AnyMidsceneTools, scriptName: string, options?: CLIRunnerOptions): Promise<void>;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CLIError, reportCLIError } from './cli-error';
|
|
2
|
+
export { parseCliArgs, parseValue } from './cli-args';
|
|
3
|
+
export { runToolsCLI, removePrefix } from './cli-runner';
|
|
2
4
|
export type { CLIRunnerOptions, CLIExtraCommand } from './cli-runner';
|
|
@@ -13,6 +13,7 @@ export declare enum NodeType {
|
|
|
13
13
|
}
|
|
14
14
|
export declare const PLAYGROUND_SERVER_PORT = 5800;
|
|
15
15
|
export declare const SCRCPY_SERVER_PORT = 5700;
|
|
16
|
+
export declare const SCRCPY_ADB_CONNECT_TIMEOUT_MS = 10000;
|
|
16
17
|
export declare const SCRCPY_PUSH_TIMEOUT_MS = 10000;
|
|
17
18
|
export declare const SCRCPY_START_TIMEOUT_MS = 15000;
|
|
18
19
|
export declare const SCRCPY_VIDEO_STREAM_TIMEOUT_MS = 15000;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal-only helpers for CLI/MCP argument key aliasing.
|
|
3
|
+
* Not re-exported from the package entry point — keep consumers within
|
|
4
|
+
* `cli/` and `mcp/`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function kebabToCamel(str: string): string;
|
|
7
|
+
export declare function camelToKebab(str: string): string;
|
|
8
|
+
export declare function getKeyAliases(key: string): string[];
|
|
9
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|