yiyan-browser-agent 1.0.31 → 1.0.33
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/package.json +2 -1
- package/src/index.js +31 -32
- package/src/postinstall.js +26 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yiyan-browser-agent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.33",
|
|
4
4
|
"description": "AI coding agent powered by Yiyan (文心一言) via browser automation — no API key needed",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "node src/index.js",
|
|
12
|
+
"postinstall": "node src/postinstall.js",
|
|
12
13
|
"debug": "node src/index.js --debug",
|
|
13
14
|
"calibrate": "node src/calibrate.js"
|
|
14
15
|
},
|
package/src/index.js
CHANGED
|
@@ -10,13 +10,12 @@ const YiyanAgent = require('./agent');
|
|
|
10
10
|
|
|
11
11
|
function parseArgs(argv) {
|
|
12
12
|
const args = argv.slice(2);
|
|
13
|
-
const opts = { task: null, interactive: false, debug: false,
|
|
13
|
+
const opts = { task: null, interactive: false, debug: false, showBrowser: false, workingDir: null, calibrate: false, help: false };
|
|
14
14
|
|
|
15
15
|
for (let i = 0; i < args.length; i++) {
|
|
16
16
|
const a = args[i];
|
|
17
17
|
if (a === '-i' || a === '--interactive') opts.interactive = true;
|
|
18
18
|
else if (a === '--debug') opts.debug = true;
|
|
19
|
-
else if (a === '--headless') opts.headless = true;
|
|
20
19
|
else if (a === '--show-browser') opts.showBrowser = true;
|
|
21
20
|
else if (a === '--calibrate') opts.calibrate = true;
|
|
22
21
|
else if (a === '-h' || a === '--help') opts.help = true;
|
|
@@ -29,23 +28,17 @@ function parseArgs(argv) {
|
|
|
29
28
|
|
|
30
29
|
function printHelp() {
|
|
31
30
|
console.log(`
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
yiyan-agent
|
|
36
|
-
yiyan-agent -i
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
-i, --interactive
|
|
40
|
-
--show-browser
|
|
41
|
-
--debug
|
|
42
|
-
--
|
|
43
|
-
-h, --help Show help
|
|
44
|
-
|
|
45
|
-
\x1b[33mEXAMPLES\x1b[0m
|
|
46
|
-
yiyan-agent "济宁天气" # Runs headless (fast)
|
|
47
|
-
yiyan-agent -i # Login first time
|
|
48
|
-
yiyan-agent "写个脚本" --show-browser # Watch browser work
|
|
31
|
+
yiyan-agent — AI Agent via Yiyan Browser
|
|
32
|
+
|
|
33
|
+
USAGE
|
|
34
|
+
yiyan-agent "任务" # 执行任务,只输出JSON
|
|
35
|
+
yiyan-agent -i # 交互模式(用于登录)
|
|
36
|
+
|
|
37
|
+
OPTIONS
|
|
38
|
+
-i, --interactive 交互模式
|
|
39
|
+
--show-browser 显示浏览器
|
|
40
|
+
--debug 调试模式
|
|
41
|
+
-h, --help 帮助
|
|
49
42
|
`);
|
|
50
43
|
}
|
|
51
44
|
|
|
@@ -56,26 +49,30 @@ async function main() {
|
|
|
56
49
|
|
|
57
50
|
if (opts.debug) config.DEBUG = true;
|
|
58
51
|
|
|
59
|
-
// Headless
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
config.HEADLESS = false; // Show browser
|
|
63
|
-
} else {
|
|
64
|
-
config.HEADLESS = true; // Single task: headless by default (faster)
|
|
65
|
-
}
|
|
52
|
+
// Headless: 单任务默认隐藏,交互模式显示
|
|
53
|
+
config.HEADLESS = !(opts.interactive || opts.calibrate || opts.showBrowser);
|
|
54
|
+
|
|
66
55
|
if (opts.workingDir) {
|
|
67
56
|
const resolved = path.resolve(opts.workingDir);
|
|
68
|
-
if (!fs.existsSync(resolved)) {
|
|
57
|
+
if (!fs.existsSync(resolved)) {
|
|
58
|
+
if (opts.interactive) logger.error(`Dir not found: ${resolved}`);
|
|
59
|
+
else console.log(JSON.stringify({ question: '', answer: `Dir not found: ${resolved}`, status: 'error' }));
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
69
62
|
config.WORKING_DIR = resolved;
|
|
70
63
|
}
|
|
71
64
|
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
// 只在交互/调试模式显示日志
|
|
66
|
+
const silent = !opts.interactive && !opts.debug && !opts.calibrate;
|
|
67
|
+
if (!silent) {
|
|
68
|
+
logger.banner();
|
|
69
|
+
logger.info(`Working dir: ${config.WORKING_DIR}`);
|
|
70
|
+
}
|
|
74
71
|
|
|
75
72
|
const agent = new YiyanAgent();
|
|
76
73
|
|
|
77
74
|
const shutdown = async (code = 0) => {
|
|
78
|
-
logger.info('Shutting down...');
|
|
75
|
+
if (!silent) logger.info('Shutting down...');
|
|
79
76
|
try { await agent.shutdown(); } catch {}
|
|
80
77
|
process.exit(code);
|
|
81
78
|
};
|
|
@@ -95,7 +92,8 @@ async function main() {
|
|
|
95
92
|
try {
|
|
96
93
|
await agent.init();
|
|
97
94
|
} catch (err) {
|
|
98
|
-
|
|
95
|
+
if (silent) console.log(JSON.stringify({ question: opts.task || '', answer: `Error: ${err.message}`, status: 'error' }));
|
|
96
|
+
else logger.error(`Failed: ${err.message}`);
|
|
99
97
|
process.exit(1);
|
|
100
98
|
}
|
|
101
99
|
|
|
@@ -104,10 +102,11 @@ async function main() {
|
|
|
104
102
|
await agent.runInteractive();
|
|
105
103
|
} else {
|
|
106
104
|
const result = await agent.run(opts.task);
|
|
105
|
+
// 单任务:只输出JSON
|
|
107
106
|
console.log(JSON.stringify(result, null, 2));
|
|
108
107
|
}
|
|
109
108
|
} catch (err) {
|
|
110
|
-
console.log(JSON.stringify({ question: opts.task || '', answer: `Error: ${err.message}`,
|
|
109
|
+
console.log(JSON.stringify({ question: opts.task || '', answer: `Error: ${err.message}`, status: 'error' }));
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
await shutdown(0);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/postinstall.js — Auto-install Playwright Chromium
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { execSync } = require('child_process');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
|
|
8
|
+
// Skip in CI
|
|
9
|
+
if (process.env.CI || process.env.SKIP_PLAYWRIGHT_INSTALL) {
|
|
10
|
+
console.log('[yiyan-agent] Skipping browser install (CI detected)');
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
console.log('\n[yiyan-agent] Installing Playwright Chromium...\n');
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const isWindows = process.platform === 'win32';
|
|
18
|
+
const playwrightBin = path.join(__dirname, '..', 'node_modules', '.bin',
|
|
19
|
+
isWindows ? 'playwright.cmd' : 'playwright');
|
|
20
|
+
|
|
21
|
+
execSync(`"${playwrightBin}" install chromium`, { stdio: 'inherit' });
|
|
22
|
+
console.log('\n[yiyan-agent] ✓ Browser installed!\n');
|
|
23
|
+
} catch {
|
|
24
|
+
console.warn('\n[yiyan-agent] ⚠ Could not auto-install. Run manually:');
|
|
25
|
+
console.warn(' npx playwright install chromium\n');
|
|
26
|
+
}
|