yiyan-browser-agent 1.4.5 → 1.4.7
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/LICENSE +1 -1
- package/README.md +241 -153
- package/package.json +25 -30
- package/src/agent.js +63 -0
- package/src/browser.js +589 -0
- package/src/calibrate.js +178 -0
- package/src/config.js +68 -0
- package/src/index.js +115 -0
- package/src/logger.js +118 -0
- package/src/parser.js +272 -0
- package/src/postinstall.js +26 -0
- package/src/prompt.js +188 -0
- package/src/tools.js +547 -0
- package/dist/cli.d.ts +0 -27
- package/dist/cli.js +0 -857
- package/dist/cli.js.map +0 -1
- package/dist/index.d.ts +0 -73
- package/dist/index.js +0 -666
- package/dist/index.js.map +0 -1
- package/dist/postinstall.d.ts +0 -2
- package/dist/postinstall.js +0 -70
- package/dist/postinstall.js.map +0 -1
- package/dist/types-BhQ78DYf.d.ts +0 -39
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,228 +1,316 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<img src="https://img.shields.io/badge/status-in%20development-orange?style=for-the-badge" alt="Status: In Development"/>
|
|
4
|
+
<img src="https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen?style=for-the-badge" alt="Node.js"/>
|
|
5
|
+
<img src="https://img.shields.io/badge/license-MIT-green?style=for-the-badge" alt="License"/>
|
|
6
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen?style=for-the-badge" alt="PRs Welcome"/>
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
# 🤖 Yiyan Browser Agent (文心一言)
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
- 🔐 Login persistence via Playwright session
|
|
9
|
-
- 🌍 Cross-platform: Windows / Ubuntu / macOS
|
|
10
|
-
- 📦 Auto-download Chromium (~150MB)
|
|
11
|
-
- 🛠️ CLI and Node.js API support
|
|
12
|
-
- 📝 TypeScript support with full type definitions
|
|
10
|
+
**An autonomous AI coding agent that runs entirely for free — no API key required.**
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
It drives a real browser to talk to [Yiyan (文心一言)](https://yiyan.baidu.com), giving you a Claude Code / Cursor-style coding agent powered by Baidu's AI models at zero cost.
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
npm install yiyan-browser-agent
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Chromium will be automatically downloaded after installation.
|
|
14
|
+
[Installation](#-installation) · [Quick Start](#-quick-start) · [Usage](#-usage) · [Configuration](#-configuration) · [Tools](#-available-tools) · [Contributing](#-contributing)
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npx playwright install-deps chromium
|
|
26
|
-
```
|
|
16
|
+
---
|
|
27
17
|
|
|
28
|
-
|
|
18
|
+
> ⚠️ **This project is currently in active development.**
|
|
19
|
+
> Core functionality works, but you may encounter rough edges. Bug reports and contributions are very welcome — see [Contributing](#-contributing).
|
|
29
20
|
|
|
30
|
-
|
|
21
|
+
</div>
|
|
31
22
|
|
|
32
|
-
|
|
23
|
+
---
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
# First time: login to Yiyan
|
|
36
|
-
yiyan-browser-agent login
|
|
25
|
+
## 🧠 How It Works
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
yiyan-browser-agent ask "济宁天气情况"
|
|
27
|
+
Most AI coding agents talk to a paid API. This one doesn't.
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
yiyan-browser-agent ask "什么是 TypeScript?" --verbose
|
|
29
|
+
Instead, it uses **Playwright** to control a real Chromium browser, navigates to `yiyan.baidu.com`, sends your task, waits for the response, and parses it to extract tool calls — all automatically. Your local files and terminal are wired up as tools the AI can use, so it can read code, write files, run commands, and and build complete projects step by step.
|
|
43
30
|
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
```
|
|
32
|
+
Your Terminal
|
|
33
|
+
│
|
|
34
|
+
▼
|
|
35
|
+
Agent Core ← orchestrates the loop
|
|
36
|
+
│
|
|
37
|
+
├──► Browser (Playwright) ← talks to yiyan.baidu.com
|
|
38
|
+
│ │
|
|
39
|
+
│ Yiyan AI (文心一言) ← thinks, decides what tool to use
|
|
40
|
+
│ │
|
|
41
|
+
└──► Tool Executor ← reads/writes files, runs commands
|
|
42
|
+
│
|
|
43
|
+
Your Project
|
|
44
|
+
```
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
yiyan-browser-agent status
|
|
46
|
+
---
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
yiyan-browser-agent reset
|
|
48
|
+
## 📦 Installation
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
yiyan-browser-agent
|
|
50
|
+
```bash
|
|
51
|
+
npm install -g yiyan-browser-agent
|
|
55
52
|
```
|
|
56
53
|
|
|
57
|
-
|
|
54
|
+
> Chromium downloads automatically after install (~150 MB, one time only).
|
|
55
|
+
|
|
56
|
+
**Requirements:** Node.js ≥ 18
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
import { YiyanAgent } from 'yiyan-browser-agent';
|
|
58
|
+
---
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
const agent = new YiyanAgent({
|
|
64
|
-
timeout: 120000, // Timeout in milliseconds (default: 120000)
|
|
65
|
-
});
|
|
60
|
+
## 🚀 Quick Start
|
|
66
61
|
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
**1. First run — log in to Yiyan:**
|
|
63
|
+
```bash
|
|
64
|
+
yiyan-agent --interactive
|
|
65
|
+
```
|
|
66
|
+
A browser window opens. Log in to your Yiyan (文心一言) account, then come back to the terminal and press **Enter**. Your session is saved — you only do this once.
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
**2. Give it a task:**
|
|
69
|
+
```bash
|
|
70
|
+
yiyan-agent "build a REST API in Express with user authentication"
|
|
71
|
+
```
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
**3. Use the short alias `ya` from any project folder:**
|
|
74
|
+
```bash
|
|
75
|
+
cd ~/my-project
|
|
76
|
+
ya "add input validation to all my API routes"
|
|
77
|
+
```
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
const status = agent.status();
|
|
79
|
-
console.log('Logged in:', status.loggedIn);
|
|
80
|
-
console.log('Session path:', status.sessionPath);
|
|
79
|
+
---
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
await agent.reset();
|
|
81
|
+
## 💻 Usage
|
|
84
82
|
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
```
|
|
84
|
+
yiyan-agent [OPTIONS] [TASK]
|
|
85
|
+
|
|
86
|
+
-t, --task <task> Task to run (or just type it as the last argument)
|
|
87
|
+
-i, --interactive Keep browser open, run multiple tasks in a session
|
|
88
|
+
-d, --dir <path> Set working directory (default: current directory)
|
|
89
|
+
--debug Print raw AI responses to the terminal
|
|
90
|
+
--headless Run browser invisibly (requires prior login)
|
|
91
|
+
--save-log Save full session log to ~/.yiyan-agent/logs/
|
|
92
|
+
--calibrate Auto-detect DOM selectors (run if agent breaks)
|
|
93
|
+
-h, --help Show help
|
|
94
|
+
|
|
95
|
+
Aliases:
|
|
96
|
+
ya Short form of yiyan-agent
|
|
87
97
|
```
|
|
88
98
|
|
|
89
|
-
|
|
99
|
+
### Examples
|
|
90
100
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
| `ask "question"` | Send question and get answer |
|
|
95
|
-
| `status` | Check login status |
|
|
96
|
-
| `reset` | Clear saved session |
|
|
97
|
-
| `debug` | Debug mode: output DOM info for troubleshooting |
|
|
101
|
+
```bash
|
|
102
|
+
# Single task — runs and exits
|
|
103
|
+
yiyan-agent "create a Python script that scrapes Hacker News"
|
|
98
104
|
|
|
99
|
-
|
|
105
|
+
# Interactive mode — keeps browser open between tasks
|
|
106
|
+
yiyan-agent --interactive
|
|
100
107
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
| `--timeout <ms>` | Timeout in milliseconds (default: 120000) |
|
|
104
|
-
| `--headful` | Show browser window (for debugging/captcha) |
|
|
105
|
-
| `--verbose` | Show detailed logs |
|
|
106
|
-
| `--help` | Show help message |
|
|
108
|
+
# Run on a specific project
|
|
109
|
+
ya --dir ~/projects/my-app "refactor all callbacks to async/await"
|
|
107
110
|
|
|
108
|
-
|
|
111
|
+
# Debug mode (shows what Yiyan is actually outputting)
|
|
112
|
+
ya --debug "build a calculator"
|
|
109
113
|
|
|
110
|
-
|
|
114
|
+
# Headless mode (faster — browser runs in background)
|
|
115
|
+
ya --headless "write unit tests for utils.js"
|
|
111
116
|
|
|
112
|
-
|
|
117
|
+
# In interactive mode, type 'new' to start a fresh chat:
|
|
118
|
+
❯ Task: new
|
|
119
|
+
```
|
|
113
120
|
|
|
114
|
-
|
|
121
|
+
---
|
|
115
122
|
|
|
116
|
-
|
|
117
|
-
new YiyanAgent(options?: YiyanAgentOptions)
|
|
118
|
-
```
|
|
123
|
+
## ⚙️ Configuration
|
|
119
124
|
|
|
120
|
-
|
|
121
|
-
- `timeout?: number` - Timeout in milliseconds (default: 120000)
|
|
122
|
-
- `profileDir?: string` - Custom session directory
|
|
123
|
-
- `verbose?: boolean` - Enable verbose logging (default: false)
|
|
125
|
+
### Global config — applies everywhere
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
Create `~/.yiyan-agent/config.json`:
|
|
126
128
|
|
|
127
|
-
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"HEADLESS": true,
|
|
132
|
+
"MAX_ITERATIONS": 50,
|
|
133
|
+
"STABLE_DELAY": 3000,
|
|
134
|
+
"DEBUG": false
|
|
135
|
+
}
|
|
136
|
+
```
|
|
128
137
|
|
|
129
|
-
|
|
138
|
+
### Per-project config — overrides global
|
|
130
139
|
|
|
131
|
-
|
|
140
|
+
Drop `yiyan-agent.config.json` in your project root:
|
|
132
141
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"MAX_ITERATIONS": 60,
|
|
145
|
+
"MAX_OUTPUT_LENGTH": 12000
|
|
146
|
+
}
|
|
147
|
+
```
|
|
136
148
|
|
|
137
|
-
|
|
149
|
+
### All settings
|
|
150
|
+
|
|
151
|
+
| Setting | Default | Description |
|
|
152
|
+
|---|---|---|
|
|
153
|
+
| `HEADLESS` | `false` | Hide the browser window |
|
|
154
|
+
| `MAX_ITERATIONS` | `40` | Max agent steps per task before stopping |
|
|
155
|
+
| `RESPONSE_TIMEOUT` | `180000` | Max ms to wait for a response (3 min) |
|
|
156
|
+
| `STABLE_DELAY` | `2500` | Ms of silence that means Yiyan is done |
|
|
157
|
+
| `SEND_DELAY` | `400` | Ms between typing and pressing Enter |
|
|
158
|
+
| `MAX_OUTPUT_LENGTH` | `8000` | Truncate long command outputs sent to AI |
|
|
159
|
+
| `DEBUG` | `false` | Print raw AI responses to terminal |
|
|
160
|
+
| `SESSION_DIR` | `~/.yiyan-agent/session` | Where browser cookies are saved |
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 🛠️ Available Tools
|
|
165
|
+
|
|
166
|
+
The agent can use these tools autonomously to complete your task:
|
|
167
|
+
|
|
168
|
+
| Tool | Description |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `read_file` | Read a file's contents, optionally by line range |
|
|
171
|
+
| `write_file` | Create or overwrite a file (auto-creates directories) |
|
|
172
|
+
| `append_to_file` | Append text to an existing file |
|
|
173
|
+
| `replace_in_file` | Find and replace text in a file (regex supported) |
|
|
174
|
+
| `delete_file` | Permanently delete a file |
|
|
175
|
+
| `list_directory` | List directory contents, optionally recursive |
|
|
176
|
+
| `create_directory` | Create a directory and all parents |
|
|
177
|
+
| `move_file` | Move or rename a file or directory |
|
|
178
|
+
| `copy_file` | Copy a file to a new location |
|
|
179
|
+
| `get_file_info` | Get file metadata (size, line count, dates) |
|
|
180
|
+
| `run_command` | Execute any shell command |
|
|
181
|
+
| `find_files` | Find files by name pattern (e.g. `*.ts`) |
|
|
182
|
+
| `search_in_files` | Search text inside files (like `grep -r`) |
|
|
183
|
+
| `read_url` | Fetch and read the content of a URL |
|
|
184
|
+
| `write_files` | Write multiple files at once (batch scaffold) |
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 📂 Where Data is Stored
|
|
189
|
+
|
|
190
|
+
Everything lives in `~/.yiyan-agent/` in your home directory:
|
|
138
191
|
|
|
139
|
-
|
|
192
|
+
```
|
|
193
|
+
~/.yiyan-agent/
|
|
194
|
+
├── session/ ← Browser cookies (login once, runs forever)
|
|
195
|
+
├── logs/ ← Session logs (only saved with --save-log)
|
|
196
|
+
└── config.json ← Your global settings
|
|
197
|
+
```
|
|
140
198
|
|
|
141
|
-
|
|
199
|
+
---
|
|
142
200
|
|
|
143
|
-
|
|
201
|
+
## 🔧 Troubleshooting
|
|
144
202
|
|
|
145
|
-
|
|
203
|
+
### Agent responds but creates no files
|
|
204
|
+
The browser DOM rendered the AI's response in a way the parser didn't catch. Run with `--debug` to see exactly what's being received:
|
|
205
|
+
```bash
|
|
206
|
+
yiyan-agent --debug "build a calculator"
|
|
207
|
+
```
|
|
146
208
|
|
|
147
|
-
|
|
209
|
+
### Agent stops responding / loops
|
|
210
|
+
Yiyan's UI may have changed. Run the calibration tool — it inspects the live DOM and prints updated selectors:
|
|
211
|
+
```bash
|
|
212
|
+
yiyan-agent --calibrate
|
|
213
|
+
```
|
|
148
214
|
|
|
149
|
-
###
|
|
215
|
+
### Login session expired
|
|
216
|
+
Just run without `--headless` — the browser opens and you log in again:
|
|
217
|
+
```bash
|
|
218
|
+
yiyan-agent --interactive
|
|
219
|
+
```
|
|
150
220
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
| `NETWORK` | Network or connection error |
|
|
156
|
-
| `CAPTCHA` | Captcha detected (use --headful) |
|
|
221
|
+
### Chromium didn't download automatically
|
|
222
|
+
```bash
|
|
223
|
+
npx playwright install chromium
|
|
224
|
+
```
|
|
157
225
|
|
|
158
|
-
|
|
226
|
+
### Response times out on long tasks
|
|
227
|
+
Increase the timeout in your config:
|
|
228
|
+
```json
|
|
229
|
+
{ "RESPONSE_TIMEOUT": 300000, "STABLE_DELAY": 4000 }
|
|
230
|
+
```
|
|
159
231
|
|
|
160
|
-
|
|
161
|
-
2. Launches browser with persistent session context
|
|
162
|
-
3. Navigates to Yiyan chat page
|
|
163
|
-
4. Sends question and waits for response
|
|
164
|
-
5. Extracts response using multiple strategies
|
|
165
|
-
6. Closes browser (session saved for next use)
|
|
232
|
+
---
|
|
166
233
|
|
|
167
|
-
##
|
|
234
|
+
## 🗂️ Project Structure
|
|
168
235
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
236
|
+
```
|
|
237
|
+
yiyan-browser-agent/
|
|
238
|
+
├── src/
|
|
239
|
+
│ ├── index.js ← CLI entry point and argument parsing
|
|
240
|
+
│ ├── agent.js ← Core agent loop (send → wait → parse → execute)
|
|
241
|
+
│ ├── browser.js ← Playwright controller for yiyan.baidu.com
|
|
242
|
+
│ ├── tools.js ← All 15 filesystem and shell tools
|
|
243
|
+
│ ├── parser.js ← Extracts tool calls from AI responses (6 strategies)
|
|
244
|
+
│ ├── prompt.js ← System prompt and conversation history manager
|
|
245
|
+
│ ├── config.js ← Configuration loader (global + per-project)
|
|
246
|
+
│ ├── logger.js ← ANSI-colored terminal output
|
|
247
|
+
│ ├── calibrate.js ← DOM selector inspector / auto-fix tool
|
|
248
|
+
│ └── postinstall.js ← Auto-downloads Chromium after npm install
|
|
249
|
+
├── LICENSE
|
|
250
|
+
├── README.md
|
|
251
|
+
└── package.json
|
|
252
|
+
```
|
|
172
253
|
|
|
173
|
-
|
|
254
|
+
---
|
|
174
255
|
|
|
175
|
-
|
|
176
|
-
|----------|--------|-------|
|
|
177
|
-
| Windows | ✅ | Direct use |
|
|
178
|
-
| Ubuntu | ✅ | Run `npx playwright install-deps chromium` first |
|
|
179
|
-
| macOS | ✅ | Direct use |
|
|
256
|
+
## 🤝 Contributing
|
|
180
257
|
|
|
181
|
-
|
|
258
|
+
Contributions are very welcome — this project is in active development and there's plenty of room to grow.
|
|
182
259
|
|
|
183
|
-
###
|
|
260
|
+
### Setting up locally
|
|
184
261
|
|
|
185
262
|
```bash
|
|
263
|
+
git clone https://github.com/YOUR_USERNAME/yiyan-browser-agent
|
|
264
|
+
cd yiyan-browser-agent
|
|
265
|
+
npm install
|
|
186
266
|
npx playwright install chromium
|
|
187
|
-
|
|
188
|
-
yiyan-browser-agent login --verbose
|
|
267
|
+
node src/index.js --interactive
|
|
189
268
|
```
|
|
190
269
|
|
|
191
|
-
###
|
|
270
|
+
### Areas that need work
|
|
192
271
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
272
|
+
- 🧪 **Tests** — there are currently no automated tests; a test suite would be a great contribution
|
|
273
|
+
- 🎨 **UI selector resilience** — Yiyan updates their UI occasionally; better selector strategies are welcome
|
|
274
|
+
- 🔌 **More tools** — image generation, browser control, database tools, etc.
|
|
275
|
+
- 🌐 **Other AI frontends** — adapting the browser layer to work with other free AI chats
|
|
276
|
+
- 📦 **Windows support** — currently tested on Linux; Windows path handling may need fixes
|
|
277
|
+
- 📝 **Better error messages** — making failures easier to diagnose
|
|
197
278
|
|
|
198
|
-
###
|
|
279
|
+
### How to contribute
|
|
199
280
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
281
|
+
1. Fork the repo
|
|
282
|
+
2. Create a branch: `git checkout -b feature/my-improvement`
|
|
283
|
+
3. Make your changes
|
|
284
|
+
4. Open a Pull Request with a clear description
|
|
204
285
|
|
|
205
|
-
|
|
286
|
+
Please keep PRs focused — one feature or fix per PR makes review much faster.
|
|
206
287
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
288
|
+
### Reporting bugs
|
|
289
|
+
|
|
290
|
+
Open an issue on GitHub with:
|
|
291
|
+
- What you ran
|
|
292
|
+
- What you expected
|
|
293
|
+
- What actually happened
|
|
294
|
+
- Output of `yiyan-agent --debug "your task"` if relevant
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## ⚠️ Disclaimer
|
|
299
|
+
|
|
300
|
+
This project automates a web browser to interact with yiyan.baidu.com. Automating web UIs may violate the terms of service of the website being automated. Use this tool for **personal and development purposes only**. The authors take no responsibility for account suspensions or other consequences of use.
|
|
301
|
+
|
|
302
|
+
---
|
|
211
303
|
|
|
212
|
-
##
|
|
304
|
+
## 📄 License
|
|
213
305
|
|
|
214
|
-
|
|
306
|
+
MIT — see [LICENSE](./LICENSE) for details.
|
|
215
307
|
|
|
216
|
-
|
|
217
|
-
|---------|---------------------|------------------------|
|
|
218
|
-
| Browser | Playwright Chromium | Playwright Chromium |
|
|
219
|
-
| Login | Persistent session | Persistent session |
|
|
220
|
-
| Platform | Win/Ubuntu/macOS | Linux |
|
|
308
|
+
---
|
|
221
309
|
|
|
222
|
-
|
|
310
|
+
<div align="center">
|
|
223
311
|
|
|
224
|
-
|
|
312
|
+
**Built with Playwright · Powered by Yiyan (文心一言) · Free forever**
|
|
225
313
|
|
|
226
|
-
|
|
314
|
+
If this project helped you, consider giving it a ⭐ on GitHub!
|
|
227
315
|
|
|
228
|
-
|
|
316
|
+
</div>
|
package/package.json
CHANGED
|
@@ -1,50 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yiyan-browser-agent",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.4.7",
|
|
4
|
+
"description": "AI coding agent powered by Yiyan (文心一言) via browser automation — no API key needed",
|
|
5
|
+
"main": "src/index.js",
|
|
5
6
|
"bin": {
|
|
6
|
-
"yiyan-
|
|
7
|
+
"yiyan-agent": "src/index.js",
|
|
8
|
+
"ya": "src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node src/index.js",
|
|
12
|
+
"postinstall": "node src/postinstall.js",
|
|
13
|
+
"debug": "node src/index.js --debug",
|
|
14
|
+
"calibrate": "node src/calibrate.js"
|
|
7
15
|
},
|
|
8
|
-
"main": "./dist/index.js",
|
|
9
16
|
"files": [
|
|
10
|
-
"
|
|
17
|
+
"src/",
|
|
11
18
|
"README.md",
|
|
12
19
|
"LICENSE"
|
|
13
20
|
],
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsup",
|
|
16
|
-
"test": "vitest run",
|
|
17
|
-
"test:watch": "vitest",
|
|
18
|
-
"typecheck": "tsc --noEmit",
|
|
19
|
-
"postinstall": "node dist/postinstall.js",
|
|
20
|
-
"prepublishOnly": "npm run build && npm run test"
|
|
21
|
-
},
|
|
22
21
|
"dependencies": {
|
|
23
22
|
"playwright": "^1.45.0"
|
|
24
23
|
},
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"vitest": "^3.2.4",
|
|
28
|
-
"tsup": "^8.0.0",
|
|
29
|
-
"@types/node": "^20.0.0"
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18.0.0"
|
|
30
26
|
},
|
|
31
27
|
"keywords": [
|
|
28
|
+
"ai",
|
|
29
|
+
"agent",
|
|
32
30
|
"yiyan",
|
|
33
|
-
"
|
|
31
|
+
"wenxin",
|
|
34
32
|
"baidu",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"chatbot"
|
|
33
|
+
"browser-automation",
|
|
34
|
+
"coding-agent",
|
|
35
|
+
"cli",
|
|
36
|
+
"llm"
|
|
40
37
|
],
|
|
38
|
+
"author": "readfor",
|
|
41
39
|
"license": "MIT",
|
|
42
40
|
"repository": {
|
|
43
41
|
"type": "git",
|
|
44
|
-
"url": "https://github.com/
|
|
45
|
-
},
|
|
46
|
-
"bugs": {
|
|
47
|
-
"url": "https://github.com/picha/yiyan-browser-agent/issues"
|
|
42
|
+
"url": "git+https://github.com/readfor/yiyan-browser-agent.git"
|
|
48
43
|
},
|
|
49
|
-
"homepage": "https://github.com/
|
|
50
|
-
}
|
|
44
|
+
"homepage": "https://github.com/readfor/yiyan-browser-agent#readme"
|
|
45
|
+
}
|
package/src/agent.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/agent.js — Simple agent, one browser per process
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const config = require('./config');
|
|
5
|
+
const logger = require('./logger');
|
|
6
|
+
const YiyanBrowser = require('./browser');
|
|
7
|
+
|
|
8
|
+
class YiyanAgent {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.browser = new YiyanBrowser();
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async init() {
|
|
15
|
+
await this.browser.launch();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async shutdown() {
|
|
19
|
+
await this.browser.close();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async run(task) {
|
|
23
|
+
const startTime = Date.now();
|
|
24
|
+
|
|
25
|
+
logger.info('Sending task to Yiyan...');
|
|
26
|
+
await this.browser.sendMessage(task);
|
|
27
|
+
|
|
28
|
+
logger.info('Waiting for response...');
|
|
29
|
+
const answer = await this.browser.waitForResponse();
|
|
30
|
+
|
|
31
|
+
const duration = Date.now() - startTime;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
question: task,
|
|
35
|
+
answer: answer || 'No response',
|
|
36
|
+
duration,
|
|
37
|
+
status: answer ? 'success' : 'error'
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async runInteractive() {
|
|
42
|
+
const readline = require('readline');
|
|
43
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
44
|
+
const ask = () => new Promise(resolve => rl.question('', resolve));
|
|
45
|
+
|
|
46
|
+
while (true) {
|
|
47
|
+
const task = (await ask()).trim();
|
|
48
|
+
if (!task) continue;
|
|
49
|
+
if (['exit', 'quit', 'q'].includes(task.toLowerCase())) break;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
await this.browser.newChat();
|
|
53
|
+
const result = await this.run(task);
|
|
54
|
+
console.log(JSON.stringify(result, null, 2));
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.log(JSON.stringify({ question: task, answer: `Error: ${err.message}`, duration: 0, status: 'error' }, null, 2));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
rl.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = YiyanAgent;
|