yiyan-browser-agent 1.0.17 → 1.0.19

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +43 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yiyan-browser-agent",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
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": {
@@ -39,7 +39,7 @@
39
39
  "license": "MIT",
40
40
  "repository": {
41
41
  "type": "git",
42
- "url": "https://github.com/readfor/yiyan-browser-agent"
42
+ "url": "git+https://github.com/readfor/yiyan-browser-agent.git"
43
43
  },
44
44
  "homepage": "https://github.com/readfor/yiyan-browser-agent#readme"
45
45
  }
package/src/index.js CHANGED
@@ -6,7 +6,8 @@ const path = require('path');
6
6
  const fs = require('fs');
7
7
  const config = require('./config');
8
8
  const logger = require('./logger');
9
- const YiyanAgent = require('./agent');
9
+ const YiyanAgent = require('./agent');
10
+ const BrowserManager = require('./browser-manager');
10
11
 
11
12
  // ─────────────────────────────────────────────
12
13
  // Parse CLI arguments
@@ -150,23 +151,25 @@ async function main() {
150
151
  const agent = new YiyanAgent({ saveLog: opts.saveLog });
151
152
 
152
153
  // ── Graceful shutdown handler ──────────────────────────────────────────────
153
- const shutdown = async (code = 0) => {
154
- logger.info('\nShutting down...');
155
- try { await agent.shutdown(); } catch {}
154
+ const shutdown = async (code = 0, closeBrowser = true) => {
155
+ if (closeBrowser) {
156
+ logger.info('\nShutting down...');
157
+ try { await agent.shutdown(); } catch {}
158
+ }
156
159
  process.exit(code);
157
160
  };
158
161
 
159
- process.on('SIGINT', () => shutdown(0));
160
- process.on('SIGTERM', () => shutdown(0));
162
+ process.on('SIGINT', () => shutdown(0, true));
163
+ process.on('SIGTERM', () => shutdown(0, true));
161
164
  process.on('uncaughtException', async err => {
162
165
  logger.error(`Uncaught error: ${err.message}`);
163
166
  if (config.DEBUG) console.error(err.stack);
164
- await shutdown(1);
167
+ await shutdown(1, true); // Error: close browser
165
168
  });
166
169
  process.on('unhandledRejection', async reason => {
167
170
  logger.error(`Unhandled rejection: ${reason}`);
168
171
  if (config.DEBUG) console.error(reason);
169
- await shutdown(1);
172
+ await shutdown(1, true); // Error: close browser
170
173
  });
171
174
 
172
175
  // ── Calibrate mode ─────────────────────────────────────────────────────────
@@ -198,9 +201,40 @@ async function main() {
198
201
  try {
199
202
  if (opts.interactive) {
200
203
  await agent.runInteractive();
204
+ await shutdown(0, true);
201
205
  } else {
202
206
  const result = await agent.run(opts.task);
203
207
  console.log(JSON.stringify(result, null, 2));
208
+
209
+ // Success: keep process alive for next task (read from stdin)
210
+ if (result.status === 'success') {
211
+ logger.info('Browser kept open. Enter next task or Ctrl+C to exit...');
212
+ const readline = require('readline');
213
+ const rl = readline.createInterface({
214
+ input : process.stdin,
215
+ output : process.stdout,
216
+ });
217
+
218
+ // Wait for next task
219
+ while (true) {
220
+ const nextTask = await new Promise(resolve => rl.question('', resolve));
221
+ const trimmed = nextTask.trim();
222
+
223
+ if (!trimmed) continue;
224
+ if (['exit', 'quit', 'q'].includes(trimmed.toLowerCase())) break;
225
+
226
+ // Run next task with same browser
227
+ agent.conversation = new ConversationManager();
228
+ await BrowserManager.newChat();
229
+ const nextResult = await agent.run(trimmed);
230
+ console.log(JSON.stringify(nextResult, null, 2));
231
+ }
232
+
233
+ rl.close();
234
+ await shutdown(0, true);
235
+ } else {
236
+ await shutdown(0, true); // Error: close browser
237
+ }
204
238
  }
205
239
  } catch (err) {
206
240
  console.log(JSON.stringify({
@@ -209,10 +243,8 @@ async function main() {
209
243
  duration: 0,
210
244
  status: 'error'
211
245
  }, null, 2));
212
- await shutdown(1);
246
+ await shutdown(1, true); // Error: close browser
213
247
  }
214
-
215
- await shutdown(0);
216
248
  }
217
249
 
218
250
  main();