autoclaw 1.0.21 → 1.0.23

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/dist/index.js CHANGED
@@ -8,6 +8,8 @@ import * as fs from 'fs';
8
8
  import * as path from 'path';
9
9
  import * as os from 'os';
10
10
  import { fileURLToPath } from 'url';
11
+ import { createInterface } from 'node:readline/promises';
12
+ import { stdin as input, stdout as output } from 'node:process';
11
13
  // Handle Ctrl+C gracefully
12
14
  function handleExit() {
13
15
  console.log(chalk.cyan("\n\nGoodbye! (Interrupted)"));
@@ -345,15 +347,10 @@ async function runChat(queryParts, options) {
345
347
  }
346
348
  }
347
349
  // Main chat loop
350
+ const rl = createInterface({ input, output });
348
351
  try {
349
352
  while (true) {
350
- const { userInput } = await inquirer.prompt([
351
- {
352
- type: 'input',
353
- name: 'userInput',
354
- message: 'You >'
355
- }
356
- ]);
353
+ const userInput = await rl.question(chalk.green('? ') + 'You > ');
357
354
  if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
358
355
  console.log(chalk.cyan("Goodbye!"));
359
356
  break;
@@ -364,12 +361,10 @@ async function runChat(queryParts, options) {
364
361
  }
365
362
  }
366
363
  catch (err) {
367
- // Check for Inquirer interruption error (Ctrl+C often causes this)
368
- if (err.message && (err.message.includes('User force closed') || err.message.includes('Prompt was canceled'))) {
369
- console.log(chalk.cyan("\nGoodbye!"));
370
- process.exit(0);
371
- }
372
- throw err; // Re-throw real errors to be caught by main().catch
364
+ console.error(chalk.red("Error in chat loop:"), err);
365
+ }
366
+ finally {
367
+ rl.close();
373
368
  }
374
369
  }
375
370
  // Global error handler
@@ -29,24 +29,47 @@ export const ScreenshotTool = {
29
29
  },
30
30
  handler: async (args, config) => {
31
31
  let browser;
32
+ const launchOptions = {
33
+ headless: true,
34
+ args: ['--font-render-hinting=none']
35
+ };
32
36
  try {
33
- browser = await chromium.launch({ headless: true });
37
+ // Try to launch system Chrome first as it usually has better font support
38
+ browser = await chromium.launch({ ...launchOptions, channel: 'chrome' });
34
39
  }
35
- catch (error) {
36
- if (error.message.includes("Executable doesn't exist")) {
37
- return "Error: Playwright browsers are not installed. Please run `npx playwright install chromium` to enable this feature.";
40
+ catch (e) {
41
+ // Fallback to bundled Chromium
42
+ try {
43
+ browser = await chromium.launch(launchOptions);
44
+ }
45
+ catch (error) {
46
+ if (error.message.includes("Executable doesn't exist")) {
47
+ return "Error: Playwright browsers are not installed. Please run `npx playwright install chromium` to enable this feature.";
48
+ }
49
+ return `Error launching browser: ${error.message}`;
38
50
  }
39
- return `Error launching browser: ${error.message}`;
40
51
  }
41
52
  const context = await browser.newContext({
42
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
43
- viewport: { width: 1280, height: 720 }
53
+ userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
54
+ viewport: { width: 1280, height: 720 },
55
+ locale: 'zh-CN', // Set locale to Chinese
56
+ deviceScaleFactor: 2 // High DPI
44
57
  });
45
58
  const page = await context.newPage();
46
59
  try {
47
60
  console.log(`Navigating to ${args.url} for screenshot...`);
48
61
  await page.goto(args.url, { waitUntil: 'networkidle', timeout: 30000 });
49
- // Wait a bit for animations etc.
62
+ // Inject CSS to force common Chinese fonts
63
+ await page.addStyleTag({
64
+ content: `
65
+ body, h1, h2, h3, h4, h5, h6, p, span, div, li, a, button, input, textarea {
66
+ font-family: "PingFang SC", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif !important;
67
+ }
68
+ `
69
+ });
70
+ // Wait for fonts to be ready
71
+ await page.evaluate(() => document.fonts.ready);
72
+ // Additional small delay for dynamic content and font rendering
50
73
  await page.waitForTimeout(1000);
51
74
  await page.screenshot({
52
75
  path: args.outputPath,
@@ -58,7 +81,9 @@ export const ScreenshotTool = {
58
81
  return `Error taking screenshot: ${error.message}`;
59
82
  }
60
83
  finally {
61
- await browser.close();
84
+ if (browser) {
85
+ await browser.close();
86
+ }
62
87
  }
63
88
  }
64
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoclaw",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {