yiyan-browser-agent 1.0.29 → 1.0.31
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 +1 -2
- package/src/index.js +20 -11
- package/src/postinstall.js +0 -50
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yiyan-browser-agent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31",
|
|
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,7 +9,6 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "node src/index.js",
|
|
12
|
-
"postinstall": "node src/postinstall.js",
|
|
13
12
|
"debug": "node src/index.js --debug",
|
|
14
13
|
"calibrate": "node src/calibrate.js"
|
|
15
14
|
},
|
package/src/index.js
CHANGED
|
@@ -10,13 +10,14 @@ 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, headless: false, workingDir: null, calibrate: false, help: false };
|
|
13
|
+
const opts = { task: null, interactive: false, debug: false, headless: 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
19
|
else if (a === '--headless') opts.headless = true;
|
|
20
|
+
else if (a === '--show-browser') opts.showBrowser = true;
|
|
20
21
|
else if (a === '--calibrate') opts.calibrate = true;
|
|
21
22
|
else if (a === '-h' || a === '--help') opts.help = true;
|
|
22
23
|
else if (a === '-d' || a === '--dir') opts.workingDir = args[++i];
|
|
@@ -31,19 +32,20 @@ function printHelp() {
|
|
|
31
32
|
\x1b[1mYIYAN AGENT\x1b[0m — AI Coding Agent via Browser
|
|
32
33
|
|
|
33
34
|
\x1b[33mUSAGE\x1b[0m
|
|
34
|
-
yiyan-agent [TASK]
|
|
35
|
-
yiyan-agent
|
|
35
|
+
yiyan-agent [TASK] # Headless mode (no browser window)
|
|
36
|
+
yiyan-agent -i # Interactive mode (shows browser for login)
|
|
36
37
|
|
|
37
38
|
\x1b[33mOPTIONS\x1b[0m
|
|
38
|
-
-i, --interactive
|
|
39
|
-
--
|
|
40
|
-
--debug
|
|
41
|
-
--calibrate
|
|
42
|
-
-h, --help
|
|
39
|
+
-i, --interactive Interactive mode (shows browser)
|
|
40
|
+
--show-browser Show browser window for single task
|
|
41
|
+
--debug Show debug info
|
|
42
|
+
--calibrate Debug DOM selectors
|
|
43
|
+
-h, --help Show help
|
|
43
44
|
|
|
44
45
|
\x1b[33mEXAMPLES\x1b[0m
|
|
45
|
-
yiyan-agent "济宁天气"
|
|
46
|
-
yiyan-agent -i
|
|
46
|
+
yiyan-agent "济宁天气" # Runs headless (fast)
|
|
47
|
+
yiyan-agent -i # Login first time
|
|
48
|
+
yiyan-agent "写个脚本" --show-browser # Watch browser work
|
|
47
49
|
`);
|
|
48
50
|
}
|
|
49
51
|
|
|
@@ -53,7 +55,14 @@ async function main() {
|
|
|
53
55
|
if (opts.help) { printHelp(); process.exit(0); }
|
|
54
56
|
|
|
55
57
|
if (opts.debug) config.DEBUG = true;
|
|
56
|
-
|
|
58
|
+
|
|
59
|
+
// Headless logic: interactive mode shows browser, single task runs headless by default
|
|
60
|
+
// User can override with --show-browser to watch single task
|
|
61
|
+
if (opts.interactive || opts.calibrate || opts.showBrowser) {
|
|
62
|
+
config.HEADLESS = false; // Show browser
|
|
63
|
+
} else {
|
|
64
|
+
config.HEADLESS = true; // Single task: headless by default (faster)
|
|
65
|
+
}
|
|
57
66
|
if (opts.workingDir) {
|
|
58
67
|
const resolved = path.resolve(opts.workingDir);
|
|
59
68
|
if (!fs.existsSync(resolved)) { logger.error(`Dir not found: ${resolved}`); process.exit(1); }
|
package/src/postinstall.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// src/postinstall.js — Runs after `npm install -g yiyan-browser-agent`
|
|
2
|
-
// Automatically downloads the Playwright Chromium browser.
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const { execSync } = require('child_process');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const os = require('os');
|
|
8
|
-
|
|
9
|
-
// Skip in CI environments where a display isn't available
|
|
10
|
-
if (process.env.CI || process.env.SKIP_PLAYWRIGHT_INSTALL) {
|
|
11
|
-
console.log('[yiyan-agent] Skipping Playwright browser install (CI detected).');
|
|
12
|
-
process.exit(0);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
console.log('');
|
|
16
|
-
console.log('╔══════════════════════════════════════════════════╗');
|
|
17
|
-
console.log('║ 🤖 Yiyan Browser Agent (文心一言) — Setup ║');
|
|
18
|
-
console.log('╚══════════════════════════════════════════════════╝');
|
|
19
|
-
console.log('');
|
|
20
|
-
console.log(' Downloading Playwright Chromium browser...');
|
|
21
|
-
console.log(' (This only happens once — ~150 MB)\n');
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
// Use the playwright binary bundled in this package's node_modules
|
|
25
|
-
// On Windows, .bin files have .cmd extension; on Linux/macOS, they're shell scripts
|
|
26
|
-
const isWindows = process.platform === 'win32';
|
|
27
|
-
const playwrightBin = path.join(__dirname, '..', 'node_modules', '.bin',
|
|
28
|
-
isWindows ? 'playwright.cmd' : 'playwright');
|
|
29
|
-
|
|
30
|
-
execSync(`"${playwrightBin}" install chromium`, {
|
|
31
|
-
stdio : 'inherit',
|
|
32
|
-
env : { ...process.env },
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
console.log('');
|
|
36
|
-
console.log(' ✓ Browser installed successfully!');
|
|
37
|
-
console.log('');
|
|
38
|
-
console.log(' Get started:');
|
|
39
|
-
console.log(' yiyan-agent --interactive');
|
|
40
|
-
console.log(' yiyan-agent "build a REST API in Express"');
|
|
41
|
-
console.log('');
|
|
42
|
-
} catch (err) {
|
|
43
|
-
console.warn('');
|
|
44
|
-
console.warn(' ⚠ Could not auto-install Chromium.');
|
|
45
|
-
console.warn(' Run this manually to complete setup:');
|
|
46
|
-
console.warn('');
|
|
47
|
-
console.warn(' npx playwright install chromium');
|
|
48
|
-
console.warn('');
|
|
49
|
-
// Don't exit(1) — don't break the install if browser download fails
|
|
50
|
-
}
|