@midscene/android 1.9.5-beta-20260611051901.0 → 1.9.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.mjs +50 -5
- package/dist/es/index.mjs +49 -4
- package/dist/es/mcp-server.mjs +50 -5
- package/dist/lib/cli.js +50 -5
- package/dist/lib/index.js +49 -4
- package/dist/lib/mcp-server.js +50 -5
- package/package.json +4 -4
package/dist/es/cli.mjs
CHANGED
|
@@ -447,6 +447,45 @@ function __webpack_require__(moduleId) {
|
|
|
447
447
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
448
448
|
})();
|
|
449
449
|
var logger_ = __webpack_require__("@midscene/shared/logger");
|
|
450
|
+
const EMPTY_ADB_SHELL_STDOUT = '<empty>';
|
|
451
|
+
const MAX_RUN_ADB_SHELL_STDOUT = 200;
|
|
452
|
+
function normalizeShellStream(value) {
|
|
453
|
+
if (null == value) return '';
|
|
454
|
+
return String(value);
|
|
455
|
+
}
|
|
456
|
+
function truncateAdbShellStream(output, streamName) {
|
|
457
|
+
if (output.length <= MAX_RUN_ADB_SHELL_STDOUT) return output;
|
|
458
|
+
return `${output.slice(0, MAX_RUN_ADB_SHELL_STDOUT)}
|
|
459
|
+
...[${streamName} truncated, ${output.length - MAX_RUN_ADB_SHELL_STDOUT} more characters]`;
|
|
460
|
+
}
|
|
461
|
+
function buildRunAdbShellPlanningFeedback({ command, stdout }) {
|
|
462
|
+
if ('' === stdout) return;
|
|
463
|
+
const commandText = 'string' == typeof command && command.length > 0 ? `Command: ${command}\n` : '';
|
|
464
|
+
return `${commandText}Stdout:
|
|
465
|
+
${stdout}`;
|
|
466
|
+
}
|
|
467
|
+
function buildAdbShellStderrErrorMessage(command, stdout, stderr) {
|
|
468
|
+
return `RunAdbShell command returned stderr.
|
|
469
|
+
Command: ${command}
|
|
470
|
+
Stderr:
|
|
471
|
+
${truncateAdbShellStream(stderr, 'stderr')}
|
|
472
|
+
Stdout:
|
|
473
|
+
${stdout ? truncateAdbShellStream(stdout, 'stdout') : EMPTY_ADB_SHELL_STDOUT}`;
|
|
474
|
+
}
|
|
475
|
+
function getAdbShellStdoutOrThrow(command, output) {
|
|
476
|
+
if ('string' == typeof output) return output;
|
|
477
|
+
const stdout = normalizeShellStream(output.stdout);
|
|
478
|
+
const stderr = normalizeShellStream(output.stderr);
|
|
479
|
+
if (stderr) throw new Error(buildAdbShellStderrErrorMessage(command, stdout, stderr));
|
|
480
|
+
return stdout;
|
|
481
|
+
}
|
|
482
|
+
async function runAdbShellStdoutOrThrow(adb, command, options = {}) {
|
|
483
|
+
const output = await adb.shell(command, {
|
|
484
|
+
...options,
|
|
485
|
+
outputFormat: adb.EXEC_OUTPUT_FORMAT.FULL
|
|
486
|
+
});
|
|
487
|
+
return getAdbShellStdoutOrThrow(command, output);
|
|
488
|
+
}
|
|
450
489
|
const defaultAppNameMapping = {
|
|
451
490
|
微信: 'com.tencent.mm',
|
|
452
491
|
QQ: 'com.tencent.mobileqq',
|
|
@@ -1782,16 +1821,22 @@ const terminateParamSchema = z.object({
|
|
|
1782
1821
|
const createPlatformActions = (device)=>({
|
|
1783
1822
|
RunAdbShell: defineAction({
|
|
1784
1823
|
name: 'RunAdbShell',
|
|
1785
|
-
description: 'Execute ADB shell command on Android device',
|
|
1824
|
+
description: 'Execute an ADB shell command on the Android device and return the command stdout. Read the returned stdout to decide the next step; the stdout may indicate either success or failure.',
|
|
1786
1825
|
interfaceAlias: 'runAdbShell',
|
|
1787
1826
|
paramSchema: runAdbShellParamSchema,
|
|
1788
1827
|
sample: {
|
|
1789
1828
|
command: 'dumpsys window displays | grep -E "mCurrentFocus"'
|
|
1790
1829
|
},
|
|
1791
|
-
call: async (param)=>{
|
|
1830
|
+
call: async (param, context)=>{
|
|
1792
1831
|
if (!param.command || '' === param.command.trim()) throw new Error('RunAdbShell requires a non-empty command parameter');
|
|
1793
1832
|
const adb = await device.getAdb();
|
|
1794
|
-
|
|
1833
|
+
const stdout = await runAdbShellStdoutOrThrow(adb, param.command);
|
|
1834
|
+
const planningFeedback = buildRunAdbShellPlanningFeedback({
|
|
1835
|
+
command: param.command,
|
|
1836
|
+
stdout
|
|
1837
|
+
});
|
|
1838
|
+
if (planningFeedback && context?.task) context.task.planningFeedback = planningFeedback;
|
|
1839
|
+
return stdout;
|
|
1795
1840
|
}
|
|
1796
1841
|
}),
|
|
1797
1842
|
Launch: defineAction({
|
|
@@ -1861,7 +1906,7 @@ class AndroidAgent extends Agent {
|
|
|
1861
1906
|
async runAdbShell(command, opt) {
|
|
1862
1907
|
if (opt?.timeout !== void 0) {
|
|
1863
1908
|
const adb = await this.interface.getAdb();
|
|
1864
|
-
return await adb
|
|
1909
|
+
return await runAdbShellStdoutOrThrow(adb, command, {
|
|
1865
1910
|
timeout: opt.timeout
|
|
1866
1911
|
});
|
|
1867
1912
|
}
|
|
@@ -1999,7 +2044,7 @@ class AndroidMidsceneTools extends BaseMidsceneTools {
|
|
|
1999
2044
|
const tools = new AndroidMidsceneTools();
|
|
2000
2045
|
runToolsCLI(tools, 'midscene-android', {
|
|
2001
2046
|
stripPrefix: 'android_',
|
|
2002
|
-
version: "1.9.5
|
|
2047
|
+
version: "1.9.5",
|
|
2003
2048
|
extraCommands: createReportCliCommands()
|
|
2004
2049
|
}).catch((e)=>{
|
|
2005
2050
|
process.exit(reportCLIError(e));
|
package/dist/es/index.mjs
CHANGED
|
@@ -449,6 +449,45 @@ var external_node_fs_ = __webpack_require__("node:fs");
|
|
|
449
449
|
var external_node_module_ = __webpack_require__("node:module");
|
|
450
450
|
var external_node_path_ = __webpack_require__("node:path");
|
|
451
451
|
var logger_ = __webpack_require__("@midscene/shared/logger");
|
|
452
|
+
const EMPTY_ADB_SHELL_STDOUT = '<empty>';
|
|
453
|
+
const MAX_RUN_ADB_SHELL_STDOUT = 200;
|
|
454
|
+
function normalizeShellStream(value) {
|
|
455
|
+
if (null == value) return '';
|
|
456
|
+
return String(value);
|
|
457
|
+
}
|
|
458
|
+
function truncateAdbShellStream(output, streamName) {
|
|
459
|
+
if (output.length <= MAX_RUN_ADB_SHELL_STDOUT) return output;
|
|
460
|
+
return `${output.slice(0, MAX_RUN_ADB_SHELL_STDOUT)}
|
|
461
|
+
...[${streamName} truncated, ${output.length - MAX_RUN_ADB_SHELL_STDOUT} more characters]`;
|
|
462
|
+
}
|
|
463
|
+
function buildRunAdbShellPlanningFeedback({ command, stdout }) {
|
|
464
|
+
if ('' === stdout) return;
|
|
465
|
+
const commandText = 'string' == typeof command && command.length > 0 ? `Command: ${command}\n` : '';
|
|
466
|
+
return `${commandText}Stdout:
|
|
467
|
+
${stdout}`;
|
|
468
|
+
}
|
|
469
|
+
function buildAdbShellStderrErrorMessage(command, stdout, stderr) {
|
|
470
|
+
return `RunAdbShell command returned stderr.
|
|
471
|
+
Command: ${command}
|
|
472
|
+
Stderr:
|
|
473
|
+
${truncateAdbShellStream(stderr, 'stderr')}
|
|
474
|
+
Stdout:
|
|
475
|
+
${stdout ? truncateAdbShellStream(stdout, 'stdout') : EMPTY_ADB_SHELL_STDOUT}`;
|
|
476
|
+
}
|
|
477
|
+
function getAdbShellStdoutOrThrow(command, output) {
|
|
478
|
+
if ('string' == typeof output) return output;
|
|
479
|
+
const stdout = normalizeShellStream(output.stdout);
|
|
480
|
+
const stderr = normalizeShellStream(output.stderr);
|
|
481
|
+
if (stderr) throw new Error(buildAdbShellStderrErrorMessage(command, stdout, stderr));
|
|
482
|
+
return stdout;
|
|
483
|
+
}
|
|
484
|
+
async function runAdbShellStdoutOrThrow(adb, command, options = {}) {
|
|
485
|
+
const output = await adb.shell(command, {
|
|
486
|
+
...options,
|
|
487
|
+
outputFormat: adb.EXEC_OUTPUT_FORMAT.FULL
|
|
488
|
+
});
|
|
489
|
+
return getAdbShellStdoutOrThrow(command, output);
|
|
490
|
+
}
|
|
452
491
|
var scrcpy_manager = __webpack_require__("./src/scrcpy-manager.ts");
|
|
453
492
|
function _define_property(obj, key, value) {
|
|
454
493
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -1685,16 +1724,22 @@ const terminateParamSchema = z.object({
|
|
|
1685
1724
|
const createPlatformActions = (device)=>({
|
|
1686
1725
|
RunAdbShell: defineAction({
|
|
1687
1726
|
name: 'RunAdbShell',
|
|
1688
|
-
description: 'Execute ADB shell command on Android device',
|
|
1727
|
+
description: 'Execute an ADB shell command on the Android device and return the command stdout. Read the returned stdout to decide the next step; the stdout may indicate either success or failure.',
|
|
1689
1728
|
interfaceAlias: 'runAdbShell',
|
|
1690
1729
|
paramSchema: runAdbShellParamSchema,
|
|
1691
1730
|
sample: {
|
|
1692
1731
|
command: 'dumpsys window displays | grep -E "mCurrentFocus"'
|
|
1693
1732
|
},
|
|
1694
|
-
call: async (param)=>{
|
|
1733
|
+
call: async (param, context)=>{
|
|
1695
1734
|
if (!param.command || '' === param.command.trim()) throw new Error('RunAdbShell requires a non-empty command parameter');
|
|
1696
1735
|
const adb = await device.getAdb();
|
|
1697
|
-
|
|
1736
|
+
const stdout = await runAdbShellStdoutOrThrow(adb, param.command);
|
|
1737
|
+
const planningFeedback = buildRunAdbShellPlanningFeedback({
|
|
1738
|
+
command: param.command,
|
|
1739
|
+
stdout
|
|
1740
|
+
});
|
|
1741
|
+
if (planningFeedback && context?.task) context.task.planningFeedback = planningFeedback;
|
|
1742
|
+
return stdout;
|
|
1698
1743
|
}
|
|
1699
1744
|
}),
|
|
1700
1745
|
Launch: defineAction({
|
|
@@ -1927,7 +1972,7 @@ class AndroidAgent extends Agent {
|
|
|
1927
1972
|
async runAdbShell(command, opt) {
|
|
1928
1973
|
if (opt?.timeout !== void 0) {
|
|
1929
1974
|
const adb = await this.interface.getAdb();
|
|
1930
|
-
return await adb
|
|
1975
|
+
return await runAdbShellStdoutOrThrow(adb, command, {
|
|
1931
1976
|
timeout: opt.timeout
|
|
1932
1977
|
});
|
|
1933
1978
|
}
|
package/dist/es/mcp-server.mjs
CHANGED
|
@@ -447,6 +447,45 @@ function __webpack_require__(moduleId) {
|
|
|
447
447
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
448
448
|
})();
|
|
449
449
|
var logger_ = __webpack_require__("@midscene/shared/logger");
|
|
450
|
+
const EMPTY_ADB_SHELL_STDOUT = '<empty>';
|
|
451
|
+
const MAX_RUN_ADB_SHELL_STDOUT = 200;
|
|
452
|
+
function normalizeShellStream(value) {
|
|
453
|
+
if (null == value) return '';
|
|
454
|
+
return String(value);
|
|
455
|
+
}
|
|
456
|
+
function truncateAdbShellStream(output, streamName) {
|
|
457
|
+
if (output.length <= MAX_RUN_ADB_SHELL_STDOUT) return output;
|
|
458
|
+
return `${output.slice(0, MAX_RUN_ADB_SHELL_STDOUT)}
|
|
459
|
+
...[${streamName} truncated, ${output.length - MAX_RUN_ADB_SHELL_STDOUT} more characters]`;
|
|
460
|
+
}
|
|
461
|
+
function buildRunAdbShellPlanningFeedback({ command, stdout }) {
|
|
462
|
+
if ('' === stdout) return;
|
|
463
|
+
const commandText = 'string' == typeof command && command.length > 0 ? `Command: ${command}\n` : '';
|
|
464
|
+
return `${commandText}Stdout:
|
|
465
|
+
${stdout}`;
|
|
466
|
+
}
|
|
467
|
+
function buildAdbShellStderrErrorMessage(command, stdout, stderr) {
|
|
468
|
+
return `RunAdbShell command returned stderr.
|
|
469
|
+
Command: ${command}
|
|
470
|
+
Stderr:
|
|
471
|
+
${truncateAdbShellStream(stderr, 'stderr')}
|
|
472
|
+
Stdout:
|
|
473
|
+
${stdout ? truncateAdbShellStream(stdout, 'stdout') : EMPTY_ADB_SHELL_STDOUT}`;
|
|
474
|
+
}
|
|
475
|
+
function getAdbShellStdoutOrThrow(command, output) {
|
|
476
|
+
if ('string' == typeof output) return output;
|
|
477
|
+
const stdout = normalizeShellStream(output.stdout);
|
|
478
|
+
const stderr = normalizeShellStream(output.stderr);
|
|
479
|
+
if (stderr) throw new Error(buildAdbShellStderrErrorMessage(command, stdout, stderr));
|
|
480
|
+
return stdout;
|
|
481
|
+
}
|
|
482
|
+
async function runAdbShellStdoutOrThrow(adb, command, options = {}) {
|
|
483
|
+
const output = await adb.shell(command, {
|
|
484
|
+
...options,
|
|
485
|
+
outputFormat: adb.EXEC_OUTPUT_FORMAT.FULL
|
|
486
|
+
});
|
|
487
|
+
return getAdbShellStdoutOrThrow(command, output);
|
|
488
|
+
}
|
|
450
489
|
const defaultAppNameMapping = {
|
|
451
490
|
微信: 'com.tencent.mm',
|
|
452
491
|
QQ: 'com.tencent.mobileqq',
|
|
@@ -1782,16 +1821,22 @@ const terminateParamSchema = z.object({
|
|
|
1782
1821
|
const createPlatformActions = (device)=>({
|
|
1783
1822
|
RunAdbShell: defineAction({
|
|
1784
1823
|
name: 'RunAdbShell',
|
|
1785
|
-
description: 'Execute ADB shell command on Android device',
|
|
1824
|
+
description: 'Execute an ADB shell command on the Android device and return the command stdout. Read the returned stdout to decide the next step; the stdout may indicate either success or failure.',
|
|
1786
1825
|
interfaceAlias: 'runAdbShell',
|
|
1787
1826
|
paramSchema: runAdbShellParamSchema,
|
|
1788
1827
|
sample: {
|
|
1789
1828
|
command: 'dumpsys window displays | grep -E "mCurrentFocus"'
|
|
1790
1829
|
},
|
|
1791
|
-
call: async (param)=>{
|
|
1830
|
+
call: async (param, context)=>{
|
|
1792
1831
|
if (!param.command || '' === param.command.trim()) throw new Error('RunAdbShell requires a non-empty command parameter');
|
|
1793
1832
|
const adb = await device.getAdb();
|
|
1794
|
-
|
|
1833
|
+
const stdout = await runAdbShellStdoutOrThrow(adb, param.command);
|
|
1834
|
+
const planningFeedback = buildRunAdbShellPlanningFeedback({
|
|
1835
|
+
command: param.command,
|
|
1836
|
+
stdout
|
|
1837
|
+
});
|
|
1838
|
+
if (planningFeedback && context?.task) context.task.planningFeedback = planningFeedback;
|
|
1839
|
+
return stdout;
|
|
1795
1840
|
}
|
|
1796
1841
|
}),
|
|
1797
1842
|
Launch: defineAction({
|
|
@@ -1861,7 +1906,7 @@ class AndroidAgent extends Agent {
|
|
|
1861
1906
|
async runAdbShell(command, opt) {
|
|
1862
1907
|
if (opt?.timeout !== void 0) {
|
|
1863
1908
|
const adb = await this.interface.getAdb();
|
|
1864
|
-
return await adb
|
|
1909
|
+
return await runAdbShellStdoutOrThrow(adb, command, {
|
|
1865
1910
|
timeout: opt.timeout
|
|
1866
1911
|
});
|
|
1867
1912
|
}
|
|
@@ -2003,7 +2048,7 @@ class AndroidMCPServer extends BaseMCPServer {
|
|
|
2003
2048
|
constructor(toolsManager){
|
|
2004
2049
|
super({
|
|
2005
2050
|
name: '@midscene/android-mcp',
|
|
2006
|
-
version: "1.9.5
|
|
2051
|
+
version: "1.9.5",
|
|
2007
2052
|
description: 'Control the Android device using natural language commands'
|
|
2008
2053
|
}, toolsManager);
|
|
2009
2054
|
}
|
package/dist/lib/cli.js
CHANGED
|
@@ -452,6 +452,45 @@ var __webpack_exports__ = {};
|
|
|
452
452
|
const base_tools_namespaceObject = require("@midscene/shared/mcp/base-tools");
|
|
453
453
|
const agent_namespaceObject = require("@midscene/core/agent");
|
|
454
454
|
const utils_namespaceObject = require("@midscene/shared/utils");
|
|
455
|
+
const EMPTY_ADB_SHELL_STDOUT = '<empty>';
|
|
456
|
+
const MAX_RUN_ADB_SHELL_STDOUT = 200;
|
|
457
|
+
function normalizeShellStream(value) {
|
|
458
|
+
if (null == value) return '';
|
|
459
|
+
return String(value);
|
|
460
|
+
}
|
|
461
|
+
function truncateAdbShellStream(output, streamName) {
|
|
462
|
+
if (output.length <= MAX_RUN_ADB_SHELL_STDOUT) return output;
|
|
463
|
+
return `${output.slice(0, MAX_RUN_ADB_SHELL_STDOUT)}
|
|
464
|
+
...[${streamName} truncated, ${output.length - MAX_RUN_ADB_SHELL_STDOUT} more characters]`;
|
|
465
|
+
}
|
|
466
|
+
function buildRunAdbShellPlanningFeedback({ command, stdout }) {
|
|
467
|
+
if ('' === stdout) return;
|
|
468
|
+
const commandText = 'string' == typeof command && command.length > 0 ? `Command: ${command}\n` : '';
|
|
469
|
+
return `${commandText}Stdout:
|
|
470
|
+
${stdout}`;
|
|
471
|
+
}
|
|
472
|
+
function buildAdbShellStderrErrorMessage(command, stdout, stderr) {
|
|
473
|
+
return `RunAdbShell command returned stderr.
|
|
474
|
+
Command: ${command}
|
|
475
|
+
Stderr:
|
|
476
|
+
${truncateAdbShellStream(stderr, 'stderr')}
|
|
477
|
+
Stdout:
|
|
478
|
+
${stdout ? truncateAdbShellStream(stdout, 'stdout') : EMPTY_ADB_SHELL_STDOUT}`;
|
|
479
|
+
}
|
|
480
|
+
function getAdbShellStdoutOrThrow(command, output) {
|
|
481
|
+
if ('string' == typeof output) return output;
|
|
482
|
+
const stdout = normalizeShellStream(output.stdout);
|
|
483
|
+
const stderr = normalizeShellStream(output.stderr);
|
|
484
|
+
if (stderr) throw new Error(buildAdbShellStderrErrorMessage(command, stdout, stderr));
|
|
485
|
+
return stdout;
|
|
486
|
+
}
|
|
487
|
+
async function runAdbShellStdoutOrThrow(adb, command, options = {}) {
|
|
488
|
+
const output = await adb.shell(command, {
|
|
489
|
+
...options,
|
|
490
|
+
outputFormat: adb.EXEC_OUTPUT_FORMAT.FULL
|
|
491
|
+
});
|
|
492
|
+
return getAdbShellStdoutOrThrow(command, output);
|
|
493
|
+
}
|
|
455
494
|
const defaultAppNameMapping = {
|
|
456
495
|
微信: 'com.tencent.mm',
|
|
457
496
|
QQ: 'com.tencent.mobileqq',
|
|
@@ -1797,16 +1836,22 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
1797
1836
|
const createPlatformActions = (device)=>({
|
|
1798
1837
|
RunAdbShell: (0, device_namespaceObject.defineAction)({
|
|
1799
1838
|
name: 'RunAdbShell',
|
|
1800
|
-
description: 'Execute ADB shell command on Android device',
|
|
1839
|
+
description: 'Execute an ADB shell command on the Android device and return the command stdout. Read the returned stdout to decide the next step; the stdout may indicate either success or failure.',
|
|
1801
1840
|
interfaceAlias: 'runAdbShell',
|
|
1802
1841
|
paramSchema: runAdbShellParamSchema,
|
|
1803
1842
|
sample: {
|
|
1804
1843
|
command: 'dumpsys window displays | grep -E "mCurrentFocus"'
|
|
1805
1844
|
},
|
|
1806
|
-
call: async (param)=>{
|
|
1845
|
+
call: async (param, context)=>{
|
|
1807
1846
|
if (!param.command || '' === param.command.trim()) throw new Error('RunAdbShell requires a non-empty command parameter');
|
|
1808
1847
|
const adb = await device.getAdb();
|
|
1809
|
-
|
|
1848
|
+
const stdout = await runAdbShellStdoutOrThrow(adb, param.command);
|
|
1849
|
+
const planningFeedback = buildRunAdbShellPlanningFeedback({
|
|
1850
|
+
command: param.command,
|
|
1851
|
+
stdout
|
|
1852
|
+
});
|
|
1853
|
+
if (planningFeedback && context?.task) context.task.planningFeedback = planningFeedback;
|
|
1854
|
+
return stdout;
|
|
1810
1855
|
}
|
|
1811
1856
|
}),
|
|
1812
1857
|
Launch: (0, device_namespaceObject.defineAction)({
|
|
@@ -1876,7 +1921,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
1876
1921
|
async runAdbShell(command, opt) {
|
|
1877
1922
|
if (opt?.timeout !== void 0) {
|
|
1878
1923
|
const adb = await this.interface.getAdb();
|
|
1879
|
-
return await adb
|
|
1924
|
+
return await runAdbShellStdoutOrThrow(adb, command, {
|
|
1880
1925
|
timeout: opt.timeout
|
|
1881
1926
|
});
|
|
1882
1927
|
}
|
|
@@ -2014,7 +2059,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
2014
2059
|
const tools = new AndroidMidsceneTools();
|
|
2015
2060
|
(0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-android', {
|
|
2016
2061
|
stripPrefix: 'android_',
|
|
2017
|
-
version: "1.9.5
|
|
2062
|
+
version: "1.9.5",
|
|
2018
2063
|
extraCommands: (0, core_namespaceObject.createReportCliCommands)()
|
|
2019
2064
|
}).catch((e)=>{
|
|
2020
2065
|
process.exit((0, cli_namespaceObject.reportCLIError)(e));
|
package/dist/lib/index.js
CHANGED
|
@@ -483,6 +483,45 @@ var __webpack_exports__ = {};
|
|
|
483
483
|
var logger_ = __webpack_require__("@midscene/shared/logger");
|
|
484
484
|
const shared_utils_namespaceObject = require("@midscene/shared/utils");
|
|
485
485
|
const external_appium_adb_namespaceObject = require("appium-adb");
|
|
486
|
+
const EMPTY_ADB_SHELL_STDOUT = '<empty>';
|
|
487
|
+
const MAX_RUN_ADB_SHELL_STDOUT = 200;
|
|
488
|
+
function normalizeShellStream(value) {
|
|
489
|
+
if (null == value) return '';
|
|
490
|
+
return String(value);
|
|
491
|
+
}
|
|
492
|
+
function truncateAdbShellStream(output, streamName) {
|
|
493
|
+
if (output.length <= MAX_RUN_ADB_SHELL_STDOUT) return output;
|
|
494
|
+
return `${output.slice(0, MAX_RUN_ADB_SHELL_STDOUT)}
|
|
495
|
+
...[${streamName} truncated, ${output.length - MAX_RUN_ADB_SHELL_STDOUT} more characters]`;
|
|
496
|
+
}
|
|
497
|
+
function buildRunAdbShellPlanningFeedback({ command, stdout }) {
|
|
498
|
+
if ('' === stdout) return;
|
|
499
|
+
const commandText = 'string' == typeof command && command.length > 0 ? `Command: ${command}\n` : '';
|
|
500
|
+
return `${commandText}Stdout:
|
|
501
|
+
${stdout}`;
|
|
502
|
+
}
|
|
503
|
+
function buildAdbShellStderrErrorMessage(command, stdout, stderr) {
|
|
504
|
+
return `RunAdbShell command returned stderr.
|
|
505
|
+
Command: ${command}
|
|
506
|
+
Stderr:
|
|
507
|
+
${truncateAdbShellStream(stderr, 'stderr')}
|
|
508
|
+
Stdout:
|
|
509
|
+
${stdout ? truncateAdbShellStream(stdout, 'stdout') : EMPTY_ADB_SHELL_STDOUT}`;
|
|
510
|
+
}
|
|
511
|
+
function getAdbShellStdoutOrThrow(command, output) {
|
|
512
|
+
if ('string' == typeof output) return output;
|
|
513
|
+
const stdout = normalizeShellStream(output.stdout);
|
|
514
|
+
const stderr = normalizeShellStream(output.stderr);
|
|
515
|
+
if (stderr) throw new Error(buildAdbShellStderrErrorMessage(command, stdout, stderr));
|
|
516
|
+
return stdout;
|
|
517
|
+
}
|
|
518
|
+
async function runAdbShellStdoutOrThrow(adb, command, options = {}) {
|
|
519
|
+
const output = await adb.shell(command, {
|
|
520
|
+
...options,
|
|
521
|
+
outputFormat: adb.EXEC_OUTPUT_FORMAT.FULL
|
|
522
|
+
});
|
|
523
|
+
return getAdbShellStdoutOrThrow(command, output);
|
|
524
|
+
}
|
|
486
525
|
var scrcpy_manager = __webpack_require__("./src/scrcpy-manager.ts");
|
|
487
526
|
function _define_property(obj, key, value) {
|
|
488
527
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -1719,16 +1758,22 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
1719
1758
|
const createPlatformActions = (device)=>({
|
|
1720
1759
|
RunAdbShell: (0, device_namespaceObject.defineAction)({
|
|
1721
1760
|
name: 'RunAdbShell',
|
|
1722
|
-
description: 'Execute ADB shell command on Android device',
|
|
1761
|
+
description: 'Execute an ADB shell command on the Android device and return the command stdout. Read the returned stdout to decide the next step; the stdout may indicate either success or failure.',
|
|
1723
1762
|
interfaceAlias: 'runAdbShell',
|
|
1724
1763
|
paramSchema: runAdbShellParamSchema,
|
|
1725
1764
|
sample: {
|
|
1726
1765
|
command: 'dumpsys window displays | grep -E "mCurrentFocus"'
|
|
1727
1766
|
},
|
|
1728
|
-
call: async (param)=>{
|
|
1767
|
+
call: async (param, context)=>{
|
|
1729
1768
|
if (!param.command || '' === param.command.trim()) throw new Error('RunAdbShell requires a non-empty command parameter');
|
|
1730
1769
|
const adb = await device.getAdb();
|
|
1731
|
-
|
|
1770
|
+
const stdout = await runAdbShellStdoutOrThrow(adb, param.command);
|
|
1771
|
+
const planningFeedback = buildRunAdbShellPlanningFeedback({
|
|
1772
|
+
command: param.command,
|
|
1773
|
+
stdout
|
|
1774
|
+
});
|
|
1775
|
+
if (planningFeedback && context?.task) context.task.planningFeedback = planningFeedback;
|
|
1776
|
+
return stdout;
|
|
1732
1777
|
}
|
|
1733
1778
|
}),
|
|
1734
1779
|
Launch: (0, device_namespaceObject.defineAction)({
|
|
@@ -1962,7 +2007,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
1962
2007
|
async runAdbShell(command, opt) {
|
|
1963
2008
|
if (opt?.timeout !== void 0) {
|
|
1964
2009
|
const adb = await this.interface.getAdb();
|
|
1965
|
-
return await adb
|
|
2010
|
+
return await runAdbShellStdoutOrThrow(adb, command, {
|
|
1966
2011
|
timeout: opt.timeout
|
|
1967
2012
|
});
|
|
1968
2013
|
}
|
package/dist/lib/mcp-server.js
CHANGED
|
@@ -466,6 +466,45 @@ var __webpack_exports__ = {};
|
|
|
466
466
|
const agent_namespaceObject = require("@midscene/core/agent");
|
|
467
467
|
var logger_ = __webpack_require__("@midscene/shared/logger");
|
|
468
468
|
const utils_namespaceObject = require("@midscene/shared/utils");
|
|
469
|
+
const EMPTY_ADB_SHELL_STDOUT = '<empty>';
|
|
470
|
+
const MAX_RUN_ADB_SHELL_STDOUT = 200;
|
|
471
|
+
function normalizeShellStream(value) {
|
|
472
|
+
if (null == value) return '';
|
|
473
|
+
return String(value);
|
|
474
|
+
}
|
|
475
|
+
function truncateAdbShellStream(output, streamName) {
|
|
476
|
+
if (output.length <= MAX_RUN_ADB_SHELL_STDOUT) return output;
|
|
477
|
+
return `${output.slice(0, MAX_RUN_ADB_SHELL_STDOUT)}
|
|
478
|
+
...[${streamName} truncated, ${output.length - MAX_RUN_ADB_SHELL_STDOUT} more characters]`;
|
|
479
|
+
}
|
|
480
|
+
function buildRunAdbShellPlanningFeedback({ command, stdout }) {
|
|
481
|
+
if ('' === stdout) return;
|
|
482
|
+
const commandText = 'string' == typeof command && command.length > 0 ? `Command: ${command}\n` : '';
|
|
483
|
+
return `${commandText}Stdout:
|
|
484
|
+
${stdout}`;
|
|
485
|
+
}
|
|
486
|
+
function buildAdbShellStderrErrorMessage(command, stdout, stderr) {
|
|
487
|
+
return `RunAdbShell command returned stderr.
|
|
488
|
+
Command: ${command}
|
|
489
|
+
Stderr:
|
|
490
|
+
${truncateAdbShellStream(stderr, 'stderr')}
|
|
491
|
+
Stdout:
|
|
492
|
+
${stdout ? truncateAdbShellStream(stdout, 'stdout') : EMPTY_ADB_SHELL_STDOUT}`;
|
|
493
|
+
}
|
|
494
|
+
function getAdbShellStdoutOrThrow(command, output) {
|
|
495
|
+
if ('string' == typeof output) return output;
|
|
496
|
+
const stdout = normalizeShellStream(output.stdout);
|
|
497
|
+
const stderr = normalizeShellStream(output.stderr);
|
|
498
|
+
if (stderr) throw new Error(buildAdbShellStderrErrorMessage(command, stdout, stderr));
|
|
499
|
+
return stdout;
|
|
500
|
+
}
|
|
501
|
+
async function runAdbShellStdoutOrThrow(adb, command, options = {}) {
|
|
502
|
+
const output = await adb.shell(command, {
|
|
503
|
+
...options,
|
|
504
|
+
outputFormat: adb.EXEC_OUTPUT_FORMAT.FULL
|
|
505
|
+
});
|
|
506
|
+
return getAdbShellStdoutOrThrow(command, output);
|
|
507
|
+
}
|
|
469
508
|
const defaultAppNameMapping = {
|
|
470
509
|
微信: 'com.tencent.mm',
|
|
471
510
|
QQ: 'com.tencent.mobileqq',
|
|
@@ -1812,16 +1851,22 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
1812
1851
|
const createPlatformActions = (device)=>({
|
|
1813
1852
|
RunAdbShell: (0, device_namespaceObject.defineAction)({
|
|
1814
1853
|
name: 'RunAdbShell',
|
|
1815
|
-
description: 'Execute ADB shell command on Android device',
|
|
1854
|
+
description: 'Execute an ADB shell command on the Android device and return the command stdout. Read the returned stdout to decide the next step; the stdout may indicate either success or failure.',
|
|
1816
1855
|
interfaceAlias: 'runAdbShell',
|
|
1817
1856
|
paramSchema: runAdbShellParamSchema,
|
|
1818
1857
|
sample: {
|
|
1819
1858
|
command: 'dumpsys window displays | grep -E "mCurrentFocus"'
|
|
1820
1859
|
},
|
|
1821
|
-
call: async (param)=>{
|
|
1860
|
+
call: async (param, context)=>{
|
|
1822
1861
|
if (!param.command || '' === param.command.trim()) throw new Error('RunAdbShell requires a non-empty command parameter');
|
|
1823
1862
|
const adb = await device.getAdb();
|
|
1824
|
-
|
|
1863
|
+
const stdout = await runAdbShellStdoutOrThrow(adb, param.command);
|
|
1864
|
+
const planningFeedback = buildRunAdbShellPlanningFeedback({
|
|
1865
|
+
command: param.command,
|
|
1866
|
+
stdout
|
|
1867
|
+
});
|
|
1868
|
+
if (planningFeedback && context?.task) context.task.planningFeedback = planningFeedback;
|
|
1869
|
+
return stdout;
|
|
1825
1870
|
}
|
|
1826
1871
|
}),
|
|
1827
1872
|
Launch: (0, device_namespaceObject.defineAction)({
|
|
@@ -1891,7 +1936,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
1891
1936
|
async runAdbShell(command, opt) {
|
|
1892
1937
|
if (opt?.timeout !== void 0) {
|
|
1893
1938
|
const adb = await this.interface.getAdb();
|
|
1894
|
-
return await adb
|
|
1939
|
+
return await runAdbShellStdoutOrThrow(adb, command, {
|
|
1895
1940
|
timeout: opt.timeout
|
|
1896
1941
|
});
|
|
1897
1942
|
}
|
|
@@ -2034,7 +2079,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
2034
2079
|
constructor(toolsManager){
|
|
2035
2080
|
super({
|
|
2036
2081
|
name: '@midscene/android-mcp',
|
|
2037
|
-
version: "1.9.5
|
|
2082
|
+
version: "1.9.5",
|
|
2038
2083
|
description: 'Control the Android device using natural language commands'
|
|
2039
2084
|
}, toolsManager);
|
|
2040
2085
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/android",
|
|
3
|
-
"version": "1.9.5
|
|
3
|
+
"version": "1.9.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/midscene.git",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@yume-chan/stream-extra": "2.1.0",
|
|
47
47
|
"appium-adb": "12.12.1",
|
|
48
48
|
"sharp": "^0.34.3",
|
|
49
|
-
"@midscene/
|
|
50
|
-
"@midscene/
|
|
49
|
+
"@midscene/shared": "1.9.5",
|
|
50
|
+
"@midscene/core": "1.9.5"
|
|
51
51
|
},
|
|
52
52
|
"optionalDependencies": {
|
|
53
53
|
"@ffmpeg-installer/ffmpeg": "^1.1.0"
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"undici": "^6.0.0",
|
|
62
62
|
"vitest": "3.0.5",
|
|
63
63
|
"zod": "^3.25.1",
|
|
64
|
-
"@midscene/playground": "1.9.5
|
|
64
|
+
"@midscene/playground": "1.9.5"
|
|
65
65
|
},
|
|
66
66
|
"license": "MIT",
|
|
67
67
|
"scripts": {
|