yiyan-browser-agent 1.0.17 → 1.0.18

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 +1 -1
  2. package/src/index.js +13 -10
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.18",
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": {
package/src/index.js CHANGED
@@ -150,23 +150,25 @@ async function main() {
150
150
  const agent = new YiyanAgent({ saveLog: opts.saveLog });
151
151
 
152
152
  // ── Graceful shutdown handler ──────────────────────────────────────────────
153
- const shutdown = async (code = 0) => {
154
- logger.info('\nShutting down...');
155
- try { await agent.shutdown(); } catch {}
153
+ const shutdown = async (code = 0, closeBrowser = true) => {
154
+ if (closeBrowser) {
155
+ logger.info('\nShutting down...');
156
+ try { await agent.shutdown(); } catch {}
157
+ }
156
158
  process.exit(code);
157
159
  };
158
160
 
159
- process.on('SIGINT', () => shutdown(0));
160
- process.on('SIGTERM', () => shutdown(0));
161
+ process.on('SIGINT', () => shutdown(0, true));
162
+ process.on('SIGTERM', () => shutdown(0, true));
161
163
  process.on('uncaughtException', async err => {
162
164
  logger.error(`Uncaught error: ${err.message}`);
163
165
  if (config.DEBUG) console.error(err.stack);
164
- await shutdown(1);
166
+ await shutdown(1, true); // Error: close browser
165
167
  });
166
168
  process.on('unhandledRejection', async reason => {
167
169
  logger.error(`Unhandled rejection: ${reason}`);
168
170
  if (config.DEBUG) console.error(reason);
169
- await shutdown(1);
171
+ await shutdown(1, true); // Error: close browser
170
172
  });
171
173
 
172
174
  // ── Calibrate mode ─────────────────────────────────────────────────────────
@@ -198,9 +200,12 @@ async function main() {
198
200
  try {
199
201
  if (opts.interactive) {
200
202
  await agent.runInteractive();
203
+ await shutdown(0, true); // Interactive mode exit: close browser
201
204
  } else {
202
205
  const result = await agent.run(opts.task);
203
206
  console.log(JSON.stringify(result, null, 2));
207
+ // Single task mode: keep browser open if success, close on error
208
+ await shutdown(0, result.status === 'error');
204
209
  }
205
210
  } catch (err) {
206
211
  console.log(JSON.stringify({
@@ -209,10 +214,8 @@ async function main() {
209
214
  duration: 0,
210
215
  status: 'error'
211
216
  }, null, 2));
212
- await shutdown(1);
217
+ await shutdown(1, true); // Error: close browser
213
218
  }
214
-
215
- await shutdown(0);
216
219
  }
217
220
 
218
221
  main();