@ui-tars-test/cli 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +231 -0
- package/bin/index.js +13 -0
- package/dist/337.js +1396 -0
- package/dist/337.js.LICENSE.txt +14 -0
- package/dist/337.js.map +1 -0
- package/dist/337.mjs +1395 -0
- package/dist/337.mjs.LICENSE.txt +14 -0
- package/dist/337.mjs.map +1 -0
- package/dist/597.js +19 -0
- package/dist/597.mjs +18 -0
- package/dist/663.js +98 -0
- package/dist/663.js.map +1 -0
- package/dist/663.mjs +97 -0
- package/dist/663.mjs.map +1 -0
- package/dist/760.js +2957 -0
- package/dist/760.js.map +1 -0
- package/dist/760.mjs +2956 -0
- package/dist/760.mjs.map +1 -0
- package/dist/940.js +1013 -0
- package/dist/940.js.map +1 -0
- package/dist/940.mjs +1011 -0
- package/dist/940.mjs.map +1 -0
- package/dist/955.js +317 -0
- package/dist/955.js.map +1 -0
- package/dist/955.mjs +317 -0
- package/dist/955.mjs.map +1 -0
- package/dist/bundle/index.js +299060 -0
- package/dist/cli/commands.js +75 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/commands.mjs +41 -0
- package/dist/cli/commands.mjs.map +1 -0
- package/dist/cli/start.js +447 -0
- package/dist/cli/start.js.map +1 -0
- package/dist/cli/start.mjs +396 -0
- package/dist/cli/start.mjs.map +1 -0
- package/dist/gui-agent-macos +0 -0
- package/dist/index.js +14 -0
- package/dist/index.js.LICENSE.txt +471 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.LICENSE.txt +471 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src/cli/commands.d.ts +2 -0
- package/dist/src/cli/commands.d.ts.map +1 -0
- package/dist/src/cli/start.d.ts +11 -0
- package/dist/src/cli/start.d.ts.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
9
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: definition[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
run: ()=>run
|
|
32
|
+
});
|
|
33
|
+
const external_commander_namespaceObject = require("commander");
|
|
34
|
+
const external_package_json_namespaceObject = require("../../package.json");
|
|
35
|
+
const external_start_js_namespaceObject = require("./start.js");
|
|
36
|
+
const run = ()=>{
|
|
37
|
+
external_commander_namespaceObject.program.name('gui-agent').description('CLI for GUI Agent automation').usage('<command> [options]').version(`GUI Agent CLI v${external_package_json_namespaceObject.version} \u{1F680}`, '-v, --version', 'Display the version number');
|
|
38
|
+
external_commander_namespaceObject.program.command('run').description('Run GUI Agent automation').option('-p, --presets <url>', 'Load model configuration from preset URL').option('-t, --target <target>', 'Target automation type (computer, browser, android)').option('-q, --query <query>', 'Instruction to execute (optional, will prompt if not provided)').option('-c, --config <path>', 'Path to configuration file').option('-o, --output <dir>', 'Directory to store execution results').option('--tasks <file>', "Path to tasks JSON file containing a list of {taskId, query}. Use 'demo' to run built-in sample tasks").action(async (options)=>{
|
|
39
|
+
try {
|
|
40
|
+
await (0, external_start_js_namespaceObject.start)(options);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error('Failed to run');
|
|
43
|
+
console.error(err);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
external_commander_namespaceObject.program.command('reset').description('Reset stored configuration (API keys, model settings, etc.)').option('-c, --config <path>', 'Reset specific configuration file (default: ~/.gui-agent-cli.json)').action(async (options)=>{
|
|
48
|
+
try {
|
|
49
|
+
await (0, external_start_js_namespaceObject.resetConfig)(options.config);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.error('Failed to reset configuration');
|
|
52
|
+
console.error(err);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (process.argv.length <= 2) {
|
|
57
|
+
external_commander_namespaceObject.program.outputHelp();
|
|
58
|
+
console.log('\nExamples:');
|
|
59
|
+
console.log(' gui-agent run # Run with interactive prompts');
|
|
60
|
+
console.log(' gui-agent run -t android # Run with Android automation');
|
|
61
|
+
console.log(' gui-agent run -q "open calculator" # Run with specific instruction');
|
|
62
|
+
console.log(' gui-agent reset # Reset all configuration');
|
|
63
|
+
console.log(' gui-agent reset -c custom.json # Reset specific config file');
|
|
64
|
+
}
|
|
65
|
+
external_commander_namespaceObject.program.parse();
|
|
66
|
+
};
|
|
67
|
+
exports.run = __webpack_exports__.run;
|
|
68
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
69
|
+
"run"
|
|
70
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
71
|
+
Object.defineProperty(exports, '__esModule', {
|
|
72
|
+
value: true
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli/commands.js","sources":["webpack://@gui-agent/cli/webpack/runtime/define_property_getters","webpack://@gui-agent/cli/webpack/runtime/has_own_property","webpack://@gui-agent/cli/webpack/runtime/make_namespace_object","webpack://@gui-agent/cli/./src/cli/commands.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { program } from 'commander';\n\nimport { version } from '../../package.json';\nimport { CliOptions, start, resetConfig } from './start';\n\nexport const run = () => {\n program\n .name('gui-agent')\n .description('CLI for GUI Agent automation')\n .usage('<command> [options]')\n .version(`GUI Agent CLI v${version} 🚀`, '-v, --version', 'Display the version number');\n\n program\n .command('run')\n .description('Run GUI Agent automation')\n .option('-p, --presets <url>', 'Load model configuration from preset URL')\n .option('-t, --target <target>', 'Target automation type (computer, browser, android)')\n .option('-q, --query <query>', 'Instruction to execute (optional, will prompt if not provided)')\n .option('-c, --config <path>', 'Path to configuration file')\n .option('-o, --output <dir>', 'Directory to store execution results')\n .option(\n '--tasks <file>',\n \"Path to tasks JSON file containing a list of {taskId, query}. Use 'demo' to run built-in sample tasks\",\n )\n .action(async (options: CliOptions) => {\n try {\n await start(options);\n } catch (err) {\n console.error('Failed to run');\n console.error(err);\n process.exit(1);\n }\n });\n\n program\n .command('reset')\n .description('Reset stored configuration (API keys, model settings, etc.)')\n .option(\n '-c, --config <path>',\n 'Reset specific configuration file (default: ~/.gui-agent-cli.json)',\n )\n .action(async (options) => {\n try {\n await resetConfig(options.config);\n } catch (err) {\n console.error('Failed to reset configuration');\n console.error(err);\n process.exit(1);\n }\n });\n\n // Show help if no command provided\n if (process.argv.length <= 2) {\n program.outputHelp();\n console.log('\\nExamples:');\n console.log(' gui-agent run # Run with interactive prompts');\n console.log(' gui-agent run -t android # Run with Android automation');\n console.log(' gui-agent run -q \"open calculator\" # Run with specific instruction');\n console.log(' gui-agent reset # Reset all configuration');\n console.log(' gui-agent reset -c custom.json # Reset specific config file');\n }\n\n program.parse();\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","run","program","version","options","start","err","console","process","resetConfig"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;ACGO,MAAMI,MAAM;IACjBC,mCAAAA,OAAAA,CAAAA,IACO,CAAC,aACL,WAAW,CAAC,gCACZ,KAAK,CAAC,uBACN,OAAO,CAAC,CAAC,eAAe,EAAEC,sCAAAA,OAAOA,CAAC,UAAG,CAAC,EAAE,iBAAiB;IAE5DD,mCAAAA,OAAAA,CAAAA,OACU,CAAC,OACR,WAAW,CAAC,4BACZ,MAAM,CAAC,uBAAuB,4CAC9B,MAAM,CAAC,yBAAyB,uDAChC,MAAM,CAAC,uBAAuB,kEAC9B,MAAM,CAAC,uBAAuB,8BAC9B,MAAM,CAAC,sBAAsB,wCAC7B,MAAM,CACL,kBACA,yGAED,MAAM,CAAC,OAAOE;QACb,IAAI;YACF,MAAMC,AAAAA,IAAAA,kCAAAA,KAAAA,AAAAA,EAAMD;QACd,EAAE,OAAOE,KAAK;YACZC,QAAQ,KAAK,CAAC;YACdA,QAAQ,KAAK,CAACD;YACdE,QAAQ,IAAI,CAAC;QACf;IACF;IAEFN,mCAAAA,OAAAA,CAAAA,OACU,CAAC,SACR,WAAW,CAAC,+DACZ,MAAM,CACL,uBACA,sEAED,MAAM,CAAC,OAAOE;QACb,IAAI;YACF,MAAMK,AAAAA,IAAAA,kCAAAA,WAAAA,AAAAA,EAAYL,QAAQ,MAAM;QAClC,EAAE,OAAOE,KAAK;YACZC,QAAQ,KAAK,CAAC;YACdA,QAAQ,KAAK,CAACD;YACdE,QAAQ,IAAI,CAAC;QACf;IACF;IAGF,IAAIA,QAAQ,IAAI,CAAC,MAAM,IAAI,GAAG;QAC5BN,mCAAAA,OAAAA,CAAAA,UAAkB;QAClBK,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;IACd;IAEAL,mCAAAA,OAAAA,CAAAA,KAAa;AACf"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { program } from "commander";
|
|
6
|
+
import { version } from "../../package.json";
|
|
7
|
+
import { resetConfig, start } from "./start.mjs";
|
|
8
|
+
const run = ()=>{
|
|
9
|
+
program.name('gui-agent').description('CLI for GUI Agent automation').usage('<command> [options]').version(`GUI Agent CLI v${version} \u{1F680}`, '-v, --version', 'Display the version number');
|
|
10
|
+
program.command('run').description('Run GUI Agent automation').option('-p, --presets <url>', 'Load model configuration from preset URL').option('-t, --target <target>', 'Target automation type (computer, browser, android)').option('-q, --query <query>', 'Instruction to execute (optional, will prompt if not provided)').option('-c, --config <path>', 'Path to configuration file').option('-o, --output <dir>', 'Directory to store execution results').option('--tasks <file>', "Path to tasks JSON file containing a list of {taskId, query}. Use 'demo' to run built-in sample tasks").action(async (options)=>{
|
|
11
|
+
try {
|
|
12
|
+
await start(options);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error('Failed to run');
|
|
15
|
+
console.error(err);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
program.command('reset').description('Reset stored configuration (API keys, model settings, etc.)').option('-c, --config <path>', 'Reset specific configuration file (default: ~/.gui-agent-cli.json)').action(async (options)=>{
|
|
20
|
+
try {
|
|
21
|
+
await resetConfig(options.config);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error('Failed to reset configuration');
|
|
24
|
+
console.error(err);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (process.argv.length <= 2) {
|
|
29
|
+
program.outputHelp();
|
|
30
|
+
console.log('\nExamples:');
|
|
31
|
+
console.log(' gui-agent run # Run with interactive prompts');
|
|
32
|
+
console.log(' gui-agent run -t android # Run with Android automation');
|
|
33
|
+
console.log(' gui-agent run -q "open calculator" # Run with specific instruction');
|
|
34
|
+
console.log(' gui-agent reset # Reset all configuration');
|
|
35
|
+
console.log(' gui-agent reset -c custom.json # Reset specific config file');
|
|
36
|
+
}
|
|
37
|
+
program.parse();
|
|
38
|
+
};
|
|
39
|
+
export { run };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=commands.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli/commands.mjs","sources":["webpack://@gui-agent/cli/./src/cli/commands.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { program } from 'commander';\n\nimport { version } from '../../package.json';\nimport { CliOptions, start, resetConfig } from './start';\n\nexport const run = () => {\n program\n .name('gui-agent')\n .description('CLI for GUI Agent automation')\n .usage('<command> [options]')\n .version(`GUI Agent CLI v${version} 🚀`, '-v, --version', 'Display the version number');\n\n program\n .command('run')\n .description('Run GUI Agent automation')\n .option('-p, --presets <url>', 'Load model configuration from preset URL')\n .option('-t, --target <target>', 'Target automation type (computer, browser, android)')\n .option('-q, --query <query>', 'Instruction to execute (optional, will prompt if not provided)')\n .option('-c, --config <path>', 'Path to configuration file')\n .option('-o, --output <dir>', 'Directory to store execution results')\n .option(\n '--tasks <file>',\n \"Path to tasks JSON file containing a list of {taskId, query}. Use 'demo' to run built-in sample tasks\",\n )\n .action(async (options: CliOptions) => {\n try {\n await start(options);\n } catch (err) {\n console.error('Failed to run');\n console.error(err);\n process.exit(1);\n }\n });\n\n program\n .command('reset')\n .description('Reset stored configuration (API keys, model settings, etc.)')\n .option(\n '-c, --config <path>',\n 'Reset specific configuration file (default: ~/.gui-agent-cli.json)',\n )\n .action(async (options) => {\n try {\n await resetConfig(options.config);\n } catch (err) {\n console.error('Failed to reset configuration');\n console.error(err);\n process.exit(1);\n }\n });\n\n // Show help if no command provided\n if (process.argv.length <= 2) {\n program.outputHelp();\n console.log('\\nExamples:');\n console.log(' gui-agent run # Run with interactive prompts');\n console.log(' gui-agent run -t android # Run with Android automation');\n console.log(' gui-agent run -q \"open calculator\" # Run with specific instruction');\n console.log(' gui-agent reset # Reset all configuration');\n console.log(' gui-agent reset -c custom.json # Reset specific config file');\n }\n\n program.parse();\n};\n"],"names":["run","program","version","options","start","err","console","process","resetConfig"],"mappings":";;;;;;;AASO,MAAMA,MAAM;IACjBC,QAAAA,IACO,CAAC,aACL,WAAW,CAAC,gCACZ,KAAK,CAAC,uBACN,OAAO,CAAC,CAAC,eAAe,EAAEC,QAAQ,UAAG,CAAC,EAAE,iBAAiB;IAE5DD,QAAAA,OACU,CAAC,OACR,WAAW,CAAC,4BACZ,MAAM,CAAC,uBAAuB,4CAC9B,MAAM,CAAC,yBAAyB,uDAChC,MAAM,CAAC,uBAAuB,kEAC9B,MAAM,CAAC,uBAAuB,8BAC9B,MAAM,CAAC,sBAAsB,wCAC7B,MAAM,CACL,kBACA,yGAED,MAAM,CAAC,OAAOE;QACb,IAAI;YACF,MAAMC,MAAMD;QACd,EAAE,OAAOE,KAAK;YACZC,QAAQ,KAAK,CAAC;YACdA,QAAQ,KAAK,CAACD;YACdE,QAAQ,IAAI,CAAC;QACf;IACF;IAEFN,QAAAA,OACU,CAAC,SACR,WAAW,CAAC,+DACZ,MAAM,CACL,uBACA,sEAED,MAAM,CAAC,OAAOE;QACb,IAAI;YACF,MAAMK,YAAYL,QAAQ,MAAM;QAClC,EAAE,OAAOE,KAAK;YACZC,QAAQ,KAAK,CAAC;YACdA,QAAQ,KAAK,CAACD;YACdE,QAAQ,IAAI,CAAC;QACf;IACF;IAGF,IAAIA,QAAQ,IAAI,CAAC,MAAM,IAAI,GAAG;QAC5BN,QAAQ,UAAU;QAClBK,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;QACZA,QAAQ,GAAG,CAAC;IACd;IAEAL,QAAQ,KAAK;AACf"}
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.n = (module)=>{
|
|
9
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
10
|
+
__webpack_require__.d(getter, {
|
|
11
|
+
a: getter
|
|
12
|
+
});
|
|
13
|
+
return getter;
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
(()=>{
|
|
17
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
18
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: definition[key]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.r = (exports1)=>{
|
|
29
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
+
value: 'Module'
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __webpack_exports__ = {};
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
start: ()=>start,
|
|
41
|
+
resetConfig: ()=>resetConfig
|
|
42
|
+
});
|
|
43
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
44
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
45
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
46
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
47
|
+
const external_node_os_namespaceObject = require("node:os");
|
|
48
|
+
var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
|
|
49
|
+
const external_node_fetch_namespaceObject = require("node-fetch");
|
|
50
|
+
var external_node_fetch_default = /*#__PURE__*/ __webpack_require__.n(external_node_fetch_namespaceObject);
|
|
51
|
+
const agent_sdk_namespaceObject = require("@gui-agent/agent-sdk");
|
|
52
|
+
const prompts_namespaceObject = require("@clack/prompts");
|
|
53
|
+
const external_js_yaml_namespaceObject = require("js-yaml");
|
|
54
|
+
var external_js_yaml_default = /*#__PURE__*/ __webpack_require__.n(external_js_yaml_namespaceObject);
|
|
55
|
+
const operator_nutjs_namespaceObject = require("@gui-agent/operator-nutjs");
|
|
56
|
+
const operator_adb_namespaceObject = require("@gui-agent/operator-adb");
|
|
57
|
+
const operator_browser_namespaceObject = require("@gui-agent/operator-browser");
|
|
58
|
+
const start = async (options)=>{
|
|
59
|
+
const CONFIG_PATH = options.config || external_node_path_default().join(external_node_os_default().homedir(), '.gui-agent-cli.json');
|
|
60
|
+
let config = {
|
|
61
|
+
baseURL: '',
|
|
62
|
+
apiKey: '',
|
|
63
|
+
model: '',
|
|
64
|
+
provider: 'openai',
|
|
65
|
+
useResponsesApi: false,
|
|
66
|
+
maxLoopCount: 1000
|
|
67
|
+
};
|
|
68
|
+
if (options.presets) {
|
|
69
|
+
const response = await external_node_fetch_default()(options.presets);
|
|
70
|
+
if (!response.ok) throw new Error(`Failed to fetch preset: ${response.status}`);
|
|
71
|
+
const yamlText = await response.text();
|
|
72
|
+
const preset = external_js_yaml_default().load(yamlText);
|
|
73
|
+
config.apiKey = null == preset ? void 0 : preset.vlmApiKey;
|
|
74
|
+
config.baseURL = null == preset ? void 0 : preset.vlmBaseUrl;
|
|
75
|
+
config.model = null == preset ? void 0 : preset.vlmModelName;
|
|
76
|
+
config.useResponsesApi = (null == preset ? void 0 : preset.useResponsesApi) ?? false;
|
|
77
|
+
} else if (external_node_fs_default().existsSync(CONFIG_PATH)) try {
|
|
78
|
+
config = JSON.parse(external_node_fs_default().readFileSync(CONFIG_PATH, 'utf-8'));
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.warn('read config file failed', error);
|
|
81
|
+
}
|
|
82
|
+
if (!config.baseURL || !config.apiKey || !config.model) {
|
|
83
|
+
const configAnswers = await prompts_namespaceObject.group({
|
|
84
|
+
provider: ()=>prompts_namespaceObject.select({
|
|
85
|
+
message: 'Select model provider:',
|
|
86
|
+
options: [
|
|
87
|
+
{
|
|
88
|
+
value: 'volcengine',
|
|
89
|
+
label: 'VolcEngine'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
value: 'anthropic',
|
|
93
|
+
label: 'Anthropic Claude'
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
value: 'openai',
|
|
97
|
+
label: 'OpenAI'
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
value: 'lm-studio',
|
|
101
|
+
label: 'LM Studio'
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
value: 'deepseek',
|
|
105
|
+
label: 'DeepSeek'
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
value: 'ollama',
|
|
109
|
+
label: 'Ollama'
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
}),
|
|
113
|
+
baseURL: ()=>prompts_namespaceObject.text({
|
|
114
|
+
message: 'please input vlm model baseURL:'
|
|
115
|
+
}),
|
|
116
|
+
apiKey: ()=>prompts_namespaceObject.text({
|
|
117
|
+
message: 'please input vlm model apiKey:'
|
|
118
|
+
}),
|
|
119
|
+
model: ()=>prompts_namespaceObject.text({
|
|
120
|
+
message: 'please input vlm model name:'
|
|
121
|
+
})
|
|
122
|
+
}, {
|
|
123
|
+
onCancel: ()=>{
|
|
124
|
+
prompts_namespaceObject.cancel('operation cancelled');
|
|
125
|
+
process.exit(0);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
config = {
|
|
129
|
+
...config,
|
|
130
|
+
...configAnswers
|
|
131
|
+
};
|
|
132
|
+
try {
|
|
133
|
+
external_node_fs_default().writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
134
|
+
console.log('model config file saved to:', CONFIG_PATH);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error('save model config file failed', error);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const maskedKey = config.apiKey ? `${config.apiKey.slice(0, 6)}...${config.apiKey.slice(-4)}` : '(empty)';
|
|
141
|
+
console.log('[CLI] Loaded model config:');
|
|
142
|
+
console.log(` provider: ${config.provider}`);
|
|
143
|
+
console.log(` baseURL: ${config.baseURL}`);
|
|
144
|
+
console.log(` model: ${config.model}`);
|
|
145
|
+
console.log(` apiKey: ${maskedKey}`);
|
|
146
|
+
console.log(` useResponsesApi: ${Boolean(config.useResponsesApi)}`);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
console.warn('[CLI] Failed to print model config diagnostics:', e);
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
if (config.baseURL) {
|
|
152
|
+
let parsed = null;
|
|
153
|
+
try {
|
|
154
|
+
parsed = new URL(config.baseURL);
|
|
155
|
+
} catch (_) {
|
|
156
|
+
console.warn('[CLI] Warning: baseURL is not a valid URL:', config.baseURL);
|
|
157
|
+
}
|
|
158
|
+
if (parsed) {
|
|
159
|
+
const endsWithV1 = /\/v1\/?$/.test(parsed.pathname);
|
|
160
|
+
if (!endsWithV1) console.warn('[CLI] Hint: OpenAI-compatible endpoints typically end with "/v1" (e.g. https://host/v1).');
|
|
161
|
+
if ('https:' !== parsed.protocol) console.warn('[CLI] Hint: use HTTPS for most providers. Current:', parsed.protocol);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} catch (e) {
|
|
165
|
+
console.warn('[CLI] baseURL validation failed:', e);
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
if ('openai' === config.provider && config.baseURL && config.model) {
|
|
169
|
+
const url = new URL(config.baseURL.replace(/\/$/, ''));
|
|
170
|
+
url.pathname = url.pathname.replace(/\/$/, '') + '/chat/completions';
|
|
171
|
+
console.log('[CLI] Preflight: POST', url.toString());
|
|
172
|
+
const controller = new AbortController();
|
|
173
|
+
const timeout = setTimeout(()=>controller.abort(), 16000);
|
|
174
|
+
const resp = await external_node_fetch_default()(url.toString(), {
|
|
175
|
+
method: 'POST',
|
|
176
|
+
headers: {
|
|
177
|
+
'Content-Type': 'application/json',
|
|
178
|
+
Authorization: `Bearer ${config.apiKey}`
|
|
179
|
+
},
|
|
180
|
+
body: JSON.stringify({
|
|
181
|
+
model: config.model,
|
|
182
|
+
messages: [
|
|
183
|
+
{
|
|
184
|
+
role: 'user',
|
|
185
|
+
content: 'ping'
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
stream: false
|
|
189
|
+
}),
|
|
190
|
+
signal: controller.signal
|
|
191
|
+
});
|
|
192
|
+
clearTimeout(timeout);
|
|
193
|
+
const text = await resp.text();
|
|
194
|
+
if (resp.ok) try {
|
|
195
|
+
const json = JSON.parse(text);
|
|
196
|
+
const hasChoices = Array.isArray(null == json ? void 0 : json.choices) && json.choices.length > 0;
|
|
197
|
+
console.log('[CLI] Preflight ok. choices[0] exists:', hasChoices);
|
|
198
|
+
if (!hasChoices) console.warn('[CLI] Preflight: response does not contain choices[]. Service may not implement Chat Completions.');
|
|
199
|
+
} catch (_) {
|
|
200
|
+
console.warn('[CLI] Preflight ok but response is not JSON:', text.slice(0, 200));
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
console.warn('[CLI] Preflight failed:', resp.status, resp.statusText);
|
|
204
|
+
console.warn('[CLI] Preflight response body:', text.slice(0, 500));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
} catch (e) {
|
|
208
|
+
if ((null == e ? void 0 : e.name) === 'AbortError') console.warn('[CLI] Preflight check timed out (16s). Proceeding without preflight.');
|
|
209
|
+
else console.warn('[CLI] Preflight check error:', e);
|
|
210
|
+
}
|
|
211
|
+
let targetOperator = null;
|
|
212
|
+
const targetType = options.target || await prompts_namespaceObject.select({
|
|
213
|
+
message: 'Please select your operator target:',
|
|
214
|
+
options: [
|
|
215
|
+
{
|
|
216
|
+
value: 'computer',
|
|
217
|
+
label: 'computer (Desktop automation)'
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
value: 'android',
|
|
221
|
+
label: 'android (Android automation)'
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
value: 'browser',
|
|
225
|
+
label: 'browser (Web automation)'
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
});
|
|
229
|
+
switch(targetType){
|
|
230
|
+
case 'android':
|
|
231
|
+
console.log('Initializing ADB operator...');
|
|
232
|
+
targetOperator = new operator_adb_namespaceObject.AdbOperator();
|
|
233
|
+
break;
|
|
234
|
+
case 'browser':
|
|
235
|
+
targetOperator = new operator_browser_namespaceObject.BrowserOperator({
|
|
236
|
+
browserType: 'chrome',
|
|
237
|
+
browser: null
|
|
238
|
+
});
|
|
239
|
+
break;
|
|
240
|
+
case 'computer':
|
|
241
|
+
default:
|
|
242
|
+
targetOperator = new operator_nutjs_namespaceObject.NutJSOperator();
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
const useTasksFile = Boolean(options.tasks);
|
|
246
|
+
const answers = useTasksFile ? {
|
|
247
|
+
instruction: ''
|
|
248
|
+
} : options.query ? {
|
|
249
|
+
instruction: options.query
|
|
250
|
+
} : await prompts_namespaceObject.group({
|
|
251
|
+
instruction: ()=>prompts_namespaceObject.text({
|
|
252
|
+
message: 'Input your instruction'
|
|
253
|
+
})
|
|
254
|
+
}, {
|
|
255
|
+
onCancel: ()=>{
|
|
256
|
+
prompts_namespaceObject.cancel("\u64CD\u4F5C\u5DF2\u53D6\u6D88");
|
|
257
|
+
process.exit(0);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
const abortController = new AbortController();
|
|
261
|
+
process.on('SIGINT', ()=>{
|
|
262
|
+
abortController.abort();
|
|
263
|
+
});
|
|
264
|
+
const systemPrompts = [
|
|
265
|
+
"You are provided with a task description, a history of previous actions, and corresponding screenshots. Your goal is to perform the next action to complete the task. Please note that if performing the same action multiple times results in a static screen with no changes, you should attempt a modified or alternative action.",
|
|
266
|
+
'## Function Definition\n\n- You have access to the following functions:\n{"type": "function", "name": "call_user", "parameters": {"type": "object", "properties": {"content": {"type": "string", "description": "Message or information displayed to the user to request their input, feedback, or guidance."}}, "required": []}, "description": "This function is used to interact with the user by displaying a message and requesting their input, feedback, or guidance."}\n{"type": "function", "name": "click", "parameters": {"type": "object", "properties": {"point": {"type": "string", "description": "Click coordinates. The format is: <point>x y</point>"}}, "required": ["point"]}, "description": "Mouse left single click action."}\n{"type": "function", "name": "drag", "parameters": {"type": "object", "properties": {"start_point": {"type": "string", "description": "Drag start point. The format is: <point>x y</point>"}, "end_point": {"type": "string", "description": "Drag end point. The format is: <point>x y</point>"}}, "required": ["start_point", "end_point"]}, "description": "Mouse left button drag action."}\n{"type": "function", "name": "finished", "parameters": {"type": "object", "properties": {"content": {"type": "string", "description": "Provide the final answer or response to complete the task."}}, "required": []}, "description": "This function is used to indicate the completion of a task by providing the final answer or response."}\n{"type": "function", "name": "hotkey", "parameters": {"type": "object", "properties": {"key": {"type": "string", "description": "Hotkeys you want to press. Split keys with a space and use lowercase."}}, "required": ["key"]}, "description": "Press hotkey."}\n{"type": "function", "function": {"name": "infeasible", "parameters": {"type": "object", "properties": {"content": {"type": "string", "description": "Message or information displayed to the user to explain why the current task is infeasible."}}, "required": ["content"]}, "description": "This function is used to indicate that the current task is infeasible thus agent ends the task."}\n{"type": "function", "name": "left_double", "parameters": {"type": "object", "properties": {"point": {"type": "string", "description": "Click coordinates. The format is: <point>x y</point>"}}, "required": ["point"]}, "description": "Mouse left double click action."}\n{"type": "function", "name": "right_single", "parameters": {"type": "object", "properties": {"point": {"type": "string", "description": "Click coordinates. The format is: <point>x y</point>"}}, "required": ["point"]}, "description": "Mouse right single click action."}\n{"type": "function", "name": "scroll", "parameters": {"type": "object", "properties": {"point": {"type": "string", "description": "Scroll start position. If not specified, default to execute on the current mouse position. The format is: <point>x y</point>"}, "direction": {"type": "string", "description": "Scroll direction.", "enum": ["up", "down", "left", "right"]}}, "required": ["direction", "point"]}, "description": "Scroll action."}\n{"type": "function", "name": "type", "parameters": {"type": "object", "properties": {"content": {"type": "string", "description": "Type content. If you want to submit your input, use \\n at the end of content."}}, "required": ["content"]}, "description": "Type content."}\n{"type": "function", "name": "wait", "parameters": {"type": "object", "properties": {"time": {"type": "integer", "description": "Wait time in seconds."}}, "required": []}, "description": "Wait for a while."}\n\n- To call a function, use the following structure without any suffix:\n\n<think_never_used_51bce0c785ca2f68081bfa7d91973934> reasoning process </think_never_used_51bce0c785ca2f68081bfa7d91973934>\n<seed:tool_call_never_used_51bce0c785ca2f68081bfa7d91973934><function_never_used_51bce0c785ca2f68081bfa7d91973934=example_function_name><parameter_never_used_51bce0c785ca2f68081bfa7d91973934=example_parameter_1>value_1</parameter_never_used_51bce0c785ca2f68081bfa7d91973934><parameter_never_used_51bce0c785ca2f68081bfa7d91973934=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter_never_used_51bce0c785ca2f68081bfa7d91973934></function_never_used_51bce0c785ca2f68081bfa7d91973934></seed:tool_call_never_used_51bce0c785ca2f68081bfa7d91973934>\n\n## Important Notes\n- Function calls must begin with <function_never_used_51bce0c785ca2f68081bfa7d91973934= and end with </function_never_used_51bce0c785ca2f68081bfa7d91973934>.\n- All required parameters must be explicitly provided.\n\n## Additional Notes\n- You can execute multiple actions within a single tool call. For example:\n<seed:tool_call_never_used_51bce0c785ca2f68081bfa7d91973934><function_never_used_51bce0c785ca2f68081bfa7d91973934=example_function_1><parameter_never_used_51bce0c785ca2f68081bfa7d91973934=example_parameter_1>value_1</parameter_never_used_51bce0c785ca2f68081bfa7d91973934><parameter_never_used_51bce0c785ca2f68081bfa7d91973934=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter_never_used_51bce0c785ca2f68081bfa7d91973934></function_never_used_51bce0c785ca2f68081bfa7d91973934><function_never_used_51bce0c785ca2f68081bfa7d91973934=example_function_2><parameter_never_used_51bce0c785ca2f68081bfa7d91973934=example_parameter_3>value_4</parameter_never_used_51bce0c785ca2f68081bfa7d91973934></function_never_used_51bce0c785ca2f68081bfa7d91973934></seed:tool_call_never_used_51bce0c785ca2f68081bfa7d91973934>\n- 当你判断任务请求是无法执行的时候,你应该调用Infeasible工具结束任务并解释原因。\n 判断标准:当一个请求符合以下任何一条标准时,应被归类为“无法执行”。\n 1. 技术/物理层面的矛盾: 指令本身包含逻辑上或物理上无法实现的要求。\n 2. 工具/功能错配: 指令要求在一个软件中执行另一个软件的功能,或者执行该软件根本不具备的功能。\n 3. 超出操作边界/范围: 指令要求执行的操作超出了当前用户会话、权限或应用程序的逻辑边界,涉及未告知的隐私信息或者未授权的操作。\n 4. 依赖隐性知识或外部条件: 任务的完成依赖于Agent无法获取的外部硬件、物理环境、未声明的插件/扩展、或特定的文件/数据。\n\n 输出指令:\n 如果请求被判断为“无法执行”,你应该向用户解释为什么这个任务超出了你的能力范围(例如,指出它需要直接操作某个硬件),并尽可能提供一个指导性的替代方案,让用户可以自己完成该任务。\n 你应该非常非常谨慎地使用Infeasible工具,因为它会直接结束任务并降低用户体验。所以非必要的时候,你不应该调用Infeasible工具,尽量以finish工具结束任务并向用户提示原因就好。'
|
|
267
|
+
];
|
|
268
|
+
const guiAgent = new agent_sdk_namespaceObject.GUIAgent({
|
|
269
|
+
model: {
|
|
270
|
+
id: config.model,
|
|
271
|
+
provider: config.provider,
|
|
272
|
+
baseURL: config.baseURL,
|
|
273
|
+
apiKey: config.apiKey
|
|
274
|
+
},
|
|
275
|
+
operator: targetOperator,
|
|
276
|
+
systemPrompt: systemPrompts.join('\n\n')
|
|
277
|
+
});
|
|
278
|
+
if (useTasksFile) {
|
|
279
|
+
const demoDir = external_node_path_default().resolve(external_node_path_default().join(__dirname, '..', '..', 'demo'));
|
|
280
|
+
const tasksPath = 'demo' === options.tasks ? external_node_path_default().join(demoDir, 'tasks.json') : external_node_path_default().resolve(options.tasks);
|
|
281
|
+
try {
|
|
282
|
+
const dirOfTasks = external_node_path_default().dirname(tasksPath);
|
|
283
|
+
external_node_fs_default().mkdirSync(dirOfTasks, {
|
|
284
|
+
recursive: true
|
|
285
|
+
});
|
|
286
|
+
if (!external_node_fs_default().existsSync(tasksPath)) {
|
|
287
|
+
const sample = [
|
|
288
|
+
{
|
|
289
|
+
taskId: 'task-1',
|
|
290
|
+
query: 'Open Chrome and go to github.com'
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
taskId: 'task-2',
|
|
294
|
+
query: "Search for 'GUI Agent automation' on Google"
|
|
295
|
+
}
|
|
296
|
+
];
|
|
297
|
+
external_node_fs_default().writeFileSync(tasksPath, JSON.stringify(sample, null, 2));
|
|
298
|
+
console.log(`[CLI] Sample tasks.json created: ${tasksPath}`);
|
|
299
|
+
}
|
|
300
|
+
} catch (e) {
|
|
301
|
+
console.warn('[CLI] Failed to prepare tasks file directory', e);
|
|
302
|
+
}
|
|
303
|
+
let tasks = [];
|
|
304
|
+
try {
|
|
305
|
+
const raw = external_node_fs_default().readFileSync(tasksPath, 'utf-8');
|
|
306
|
+
const parsed = JSON.parse(raw);
|
|
307
|
+
if (Array.isArray(parsed)) tasks = parsed;
|
|
308
|
+
else console.warn('[CLI] tasks file is not an array');
|
|
309
|
+
} catch (e) {
|
|
310
|
+
console.error('[CLI] Failed to read tasks file', e);
|
|
311
|
+
process.exit(1);
|
|
312
|
+
}
|
|
313
|
+
const targetOutputDir = options.output ? external_node_path_default().resolve(options.output) : 'demo' === options.tasks ? external_node_path_default().join(demoDir, 'results') : external_node_path_default().join(external_node_os_default().homedir(), '.gui-agent-results');
|
|
314
|
+
console.log(`[CLI] Output directory (resolved): ${targetOutputDir}`);
|
|
315
|
+
external_node_fs_default().mkdirSync(targetOutputDir, {
|
|
316
|
+
recursive: true
|
|
317
|
+
});
|
|
318
|
+
for (const task of tasks)try {
|
|
319
|
+
const resultEvent = await guiAgent.run(task.query);
|
|
320
|
+
const eventStream = guiAgent.getEventStream();
|
|
321
|
+
const allEvents = eventStream.getEvents();
|
|
322
|
+
const runStartEvents = allEvents.filter((e)=>'agent_run_start' === e.type);
|
|
323
|
+
const lastRunStart = runStartEvents[runStartEvents.length - 1];
|
|
324
|
+
const startIndex = allEvents.findIndex((e)=>e.id === (null == lastRunStart ? void 0 : lastRunStart.id));
|
|
325
|
+
const endIndex = allEvents.findIndex((e, idx)=>idx > startIndex && 'agent_run_end' === e.type);
|
|
326
|
+
const rangeEvents = startIndex >= 0 ? endIndex >= 0 ? allEvents.slice(startIndex, endIndex + 1) : allEvents.slice(startIndex) : allEvents;
|
|
327
|
+
const envEvents = rangeEvents.filter((e)=>'environment_input' === e.type);
|
|
328
|
+
const screenshotEvents = envEvents.filter((e)=>e.metadata && 'screenshot' === e.metadata.type);
|
|
329
|
+
const lastScreenshot = screenshotEvents.length > 0 ? screenshotEvents[screenshotEvents.length - 1] : null;
|
|
330
|
+
let resultPicPath = '';
|
|
331
|
+
if (lastScreenshot && Array.isArray(lastScreenshot.content)) {
|
|
332
|
+
var _imgPart_image_url;
|
|
333
|
+
const imgPart = lastScreenshot.content.find((c)=>'image_url' === c.type && c.image_url && c.image_url.url);
|
|
334
|
+
const dataUri = null == imgPart ? void 0 : null == (_imgPart_image_url = imgPart.image_url) ? void 0 : _imgPart_image_url.url;
|
|
335
|
+
if (dataUri && 'string' == typeof dataUri && dataUri.startsWith('data:')) {
|
|
336
|
+
const commaIndex = dataUri.indexOf(',');
|
|
337
|
+
const base64Data = commaIndex >= 0 ? dataUri.substring(commaIndex + 1) : dataUri;
|
|
338
|
+
const buffer = Buffer.from(base64Data, 'base64');
|
|
339
|
+
resultPicPath = external_node_path_default().join(targetOutputDir, `${task.taskId}.png`);
|
|
340
|
+
external_node_fs_default().writeFileSync(resultPicPath, buffer);
|
|
341
|
+
console.log(`[CLI] Screenshot saved: ${resultPicPath}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (!resultPicPath) console.log('[CLI] No screenshot captured; resultPic will be empty.');
|
|
345
|
+
const finalAnswer = (null == resultEvent ? void 0 : resultEvent.content) ?? '';
|
|
346
|
+
const report = {
|
|
347
|
+
taskId: task.taskId,
|
|
348
|
+
resultPic: resultPicPath,
|
|
349
|
+
finalAnswer
|
|
350
|
+
};
|
|
351
|
+
const reportPath = external_node_path_default().join(targetOutputDir, `${task.taskId}.json`);
|
|
352
|
+
external_node_fs_default().writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
|
353
|
+
console.log(`Result saved: ${reportPath}`);
|
|
354
|
+
console.log(`[CLI] Report JSON path: ${reportPath}`);
|
|
355
|
+
} catch (taskErr) {
|
|
356
|
+
console.error(`[CLI] Task failed: ${task.taskId}`, taskErr);
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
let resultEvent;
|
|
361
|
+
try {
|
|
362
|
+
console.log('[CLI] Starting GUIAgent run with instruction:', answers.instruction || options.query);
|
|
363
|
+
resultEvent = await guiAgent.run(answers.instruction);
|
|
364
|
+
console.log('[CLI] GUIAgent run completed.');
|
|
365
|
+
} catch (err) {
|
|
366
|
+
var _err_response, _err_response1;
|
|
367
|
+
console.error('[CLI] GUIAgent run failed.');
|
|
368
|
+
const errMsg = (null == err ? void 0 : err.message) || String(err);
|
|
369
|
+
console.error('[CLI] Error message:', errMsg);
|
|
370
|
+
if (null == err ? void 0 : err.status) console.error('[CLI] HTTP status:', err.status);
|
|
371
|
+
if (null == err ? void 0 : err.code) console.error('[CLI] Error code:', err.code);
|
|
372
|
+
const respData = (null == err ? void 0 : null == (_err_response = err.response) ? void 0 : _err_response.data) || (null == err ? void 0 : null == (_err_response1 = err.response) ? void 0 : _err_response1.body) || (null == err ? void 0 : err.data);
|
|
373
|
+
if (respData) try {
|
|
374
|
+
const text = 'string' == typeof respData ? respData : JSON.stringify(respData);
|
|
375
|
+
console.error('[CLI] Response body:', text.slice(0, 500));
|
|
376
|
+
} catch (_) {
|
|
377
|
+
console.error('[CLI] Response body: [unprintable]');
|
|
378
|
+
}
|
|
379
|
+
throw err;
|
|
380
|
+
}
|
|
381
|
+
try {
|
|
382
|
+
const eventStream = guiAgent.getEventStream();
|
|
383
|
+
const allEvents = eventStream.getEvents();
|
|
384
|
+
const runStartEvents = allEvents.filter((e)=>'agent_run_start' === e.type);
|
|
385
|
+
const sessionId = runStartEvents.length > 0 ? runStartEvents[runStartEvents.length - 1].sessionId : `${Date.now()}`;
|
|
386
|
+
const envEvents = allEvents.filter((e)=>'environment_input' === e.type);
|
|
387
|
+
const screenshotEvents = envEvents.filter((e)=>e.metadata && 'screenshot' === e.metadata.type);
|
|
388
|
+
const lastScreenshot = screenshotEvents.length > 0 ? screenshotEvents[screenshotEvents.length - 1] : null;
|
|
389
|
+
const targetOutputDir = options.output ? external_node_path_default().resolve(options.output) : external_node_path_default().join(external_node_os_default().homedir(), '.gui-agent-results');
|
|
390
|
+
console.log(`[CLI] Output directory (resolved): ${targetOutputDir}`);
|
|
391
|
+
external_node_fs_default().mkdirSync(targetOutputDir, {
|
|
392
|
+
recursive: true
|
|
393
|
+
});
|
|
394
|
+
console.log(`[CLI] TaskId/SessionId: ${sessionId}`);
|
|
395
|
+
let resultPicPath = '';
|
|
396
|
+
if (lastScreenshot && Array.isArray(lastScreenshot.content)) {
|
|
397
|
+
var _imgPart_image_url1;
|
|
398
|
+
const imgPart = lastScreenshot.content.find((c)=>'image_url' === c.type && c.image_url && c.image_url.url);
|
|
399
|
+
const dataUri = null == imgPart ? void 0 : null == (_imgPart_image_url1 = imgPart.image_url) ? void 0 : _imgPart_image_url1.url;
|
|
400
|
+
if (dataUri && 'string' == typeof dataUri && dataUri.startsWith('data:')) {
|
|
401
|
+
const commaIndex = dataUri.indexOf(',');
|
|
402
|
+
const base64Data = commaIndex >= 0 ? dataUri.substring(commaIndex + 1) : dataUri;
|
|
403
|
+
const buffer = Buffer.from(base64Data, 'base64');
|
|
404
|
+
resultPicPath = external_node_path_default().join(targetOutputDir, `${sessionId}.png`);
|
|
405
|
+
external_node_fs_default().writeFileSync(resultPicPath, buffer);
|
|
406
|
+
console.log(`[CLI] Screenshot saved: ${resultPicPath}`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (!resultPicPath) console.log('[CLI] No screenshot captured; resultPic will be empty.');
|
|
410
|
+
const finalAnswer = (null == resultEvent ? void 0 : resultEvent.content) ?? '';
|
|
411
|
+
const report = {
|
|
412
|
+
taskId: sessionId,
|
|
413
|
+
resultPic: resultPicPath,
|
|
414
|
+
finalAnswer
|
|
415
|
+
};
|
|
416
|
+
const reportPath = external_node_path_default().join(targetOutputDir, `${sessionId}.json`);
|
|
417
|
+
external_node_fs_default().writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
|
418
|
+
console.log(`Result saved: ${reportPath}`);
|
|
419
|
+
console.log(`[CLI] Report JSON path: ${reportPath}`);
|
|
420
|
+
} catch (err) {
|
|
421
|
+
console.warn('Failed to generate result report:', err);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const resetConfig = async (configPath)=>{
|
|
425
|
+
const CONFIG_PATH = configPath || external_node_path_default().join(external_node_os_default().homedir(), '.gui-agent-cli.json');
|
|
426
|
+
try {
|
|
427
|
+
if (external_node_fs_default().existsSync(CONFIG_PATH)) {
|
|
428
|
+
external_node_fs_default().unlinkSync(CONFIG_PATH);
|
|
429
|
+
console.log(`\u{2713} Configuration file removed: ${CONFIG_PATH}`);
|
|
430
|
+
} else console.log(`No configuration file found at: ${CONFIG_PATH}`);
|
|
431
|
+
console.log('Configuration has been reset. The next time you run gui-agent, you will be prompted to configure your settings again.');
|
|
432
|
+
} catch (error) {
|
|
433
|
+
console.error('Failed to reset configuration:', error);
|
|
434
|
+
process.exit(1);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
exports.resetConfig = __webpack_exports__.resetConfig;
|
|
438
|
+
exports.start = __webpack_exports__.start;
|
|
439
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
440
|
+
"resetConfig",
|
|
441
|
+
"start"
|
|
442
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
443
|
+
Object.defineProperty(exports, '__esModule', {
|
|
444
|
+
value: true
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
//# sourceMappingURL=start.js.map
|