autoclaw 1.0.26 → 1.0.28
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/README.md +4 -4
- package/dist/tools/screenshot.js +70 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -156,18 +156,18 @@ Built-in utility to provide the agent with the current system time, ensuring acc
|
|
|
156
156
|
## Docker Support
|
|
157
157
|
|
|
158
158
|
### Chinese Font Issues in Screenshots
|
|
159
|
-
When running AutoClaw inside a Docker container (especially Alpine or Debian Slim), screenshots of Chinese websites may display text as square boxes ("tofu") due to missing fonts.
|
|
159
|
+
When running AutoClaw inside a Docker container (especially Alpine or Debian Slim), screenshots of Chinese websites may display text as square boxes ("tofu") due to missing fonts. Emojis (e.g., 🔥) may also appear as squares.
|
|
160
160
|
|
|
161
|
-
**Solution:** Install CJK (Chinese/Japanese/Korean) fonts in your container.
|
|
161
|
+
**Solution:** Install CJK (Chinese/Japanese/Korean) and Emoji fonts in your container.
|
|
162
162
|
|
|
163
163
|
**For Debian/Ubuntu:**
|
|
164
164
|
```bash
|
|
165
|
-
apt-get update && apt-get install -y fonts-noto-cjk fonts-wqy-zenhei
|
|
165
|
+
apt-get update && apt-get install -y fonts-noto-cjk fonts-wqy-zenhei fonts-noto-color-emoji
|
|
166
166
|
```
|
|
167
167
|
|
|
168
168
|
**For Alpine Linux:**
|
|
169
169
|
```bash
|
|
170
|
-
apk add font-noto-cjk
|
|
170
|
+
apk add font-noto-cjk font-noto-emoji
|
|
171
171
|
```
|
|
172
172
|
|
|
173
173
|
## License
|
package/dist/tools/screenshot.js
CHANGED
|
@@ -1,28 +1,79 @@
|
|
|
1
1
|
import { chromium } from 'playwright';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as os from 'os';
|
|
4
|
-
// Helper to check for common CJK font paths on Linux
|
|
4
|
+
// Helper to check for common CJK and Emoji font paths on Linux
|
|
5
5
|
const checkLinuxFonts = () => {
|
|
6
6
|
if (os.platform() !== 'linux')
|
|
7
|
-
return true;
|
|
7
|
+
return { cjk: true, emoji: true };
|
|
8
8
|
// Check for specific font files rather than just directories
|
|
9
|
-
const
|
|
9
|
+
const commonCJKFontFiles = [
|
|
10
10
|
'/usr/share/fonts/noto/NotoSansCJK-Regular.ttc', // Alpine / Some Debian
|
|
11
11
|
'/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc', // Debian / Ubuntu
|
|
12
12
|
'/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc', // ZenHei
|
|
13
13
|
'/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc' // Arch
|
|
14
14
|
];
|
|
15
|
-
|
|
15
|
+
const commonEmojiFontFiles = [
|
|
16
|
+
'/usr/share/fonts/noto/NotoColorEmoji.ttf',
|
|
17
|
+
'/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf',
|
|
18
|
+
'/usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf'
|
|
19
|
+
];
|
|
20
|
+
const hasCJK = commonCJKFontFiles.some(path => fs.existsSync(path));
|
|
21
|
+
const hasEmoji = commonEmojiFontFiles.some(path => fs.existsSync(path));
|
|
22
|
+
// Also check if fc-list finds fonts (if available) - secondary check
|
|
16
23
|
try {
|
|
17
24
|
const child_process = require('child_process');
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
const cjkOutput = child_process.execSync('fc-list :lang=zh', { stdio: 'pipe' }).toString();
|
|
26
|
+
const emojiOutput = child_process.execSync('fc-list :family=Emoji', { stdio: 'pipe' }).toString(); // Approximate check
|
|
27
|
+
return {
|
|
28
|
+
cjk: hasCJK || cjkOutput.length > 0,
|
|
29
|
+
emoji: hasEmoji || emojiOutput.length > 0
|
|
30
|
+
};
|
|
21
31
|
}
|
|
22
32
|
catch (e) {
|
|
23
33
|
// fc-list might not be installed or failed, fall back to file check
|
|
34
|
+
return { cjk: hasCJK, emoji: hasEmoji };
|
|
24
35
|
}
|
|
25
|
-
|
|
36
|
+
};
|
|
37
|
+
const installFonts = (missing) => {
|
|
38
|
+
const child_process = require('child_process');
|
|
39
|
+
try {
|
|
40
|
+
let installCmd = '';
|
|
41
|
+
if (fs.existsSync('/etc/alpine-release')) {
|
|
42
|
+
// Alpine
|
|
43
|
+
const pkgs = [];
|
|
44
|
+
if (!missing.cjk)
|
|
45
|
+
pkgs.push('font-noto-cjk');
|
|
46
|
+
if (!missing.emoji)
|
|
47
|
+
pkgs.push('font-noto-emoji');
|
|
48
|
+
if (pkgs.length > 0) {
|
|
49
|
+
installCmd = `apk add --no-cache ${pkgs.join(' ')}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (fs.existsSync('/etc/debian_version')) {
|
|
53
|
+
// Debian/Ubuntu
|
|
54
|
+
const pkgs = [];
|
|
55
|
+
if (!missing.cjk)
|
|
56
|
+
pkgs.push('fonts-noto-cjk', 'fonts-wqy-zenhei');
|
|
57
|
+
if (!missing.emoji)
|
|
58
|
+
pkgs.push('fonts-noto-color-emoji');
|
|
59
|
+
if (pkgs.length > 0) {
|
|
60
|
+
// apt-get update is often needed first in clean containers
|
|
61
|
+
installCmd = `apt-get update && apt-get install -y ${pkgs.join(' ')}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (installCmd) {
|
|
65
|
+
console.log(`Creating font environment... (${installCmd})`);
|
|
66
|
+
console.log("This may take a few moments...");
|
|
67
|
+
child_process.execSync(installCmd, { stdio: 'inherit' });
|
|
68
|
+
console.log('✅ Fonts installed successfully.');
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
console.warn(`⚠️ Failed to auto-install fonts: ${e.message}`);
|
|
74
|
+
console.warn('Please install them manually to fix "tofu" characters.');
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
26
77
|
};
|
|
27
78
|
export const ScreenshotTool = {
|
|
28
79
|
name: "Screenshot Tool",
|
|
@@ -45,7 +96,7 @@ export const ScreenshotTool = {
|
|
|
45
96
|
},
|
|
46
97
|
fullPage: {
|
|
47
98
|
type: "boolean",
|
|
48
|
-
description: "If true, takes a screenshot of the full scrollable page
|
|
99
|
+
description: "If true (default), takes a screenshot of the full scrollable page. Set to false for viewport only."
|
|
49
100
|
}
|
|
50
101
|
},
|
|
51
102
|
required: ["url", "outputPath"]
|
|
@@ -54,9 +105,12 @@ export const ScreenshotTool = {
|
|
|
54
105
|
},
|
|
55
106
|
handler: async (args, config) => {
|
|
56
107
|
// Check for fonts on Linux to prevent "tofu" characters
|
|
57
|
-
if (os.platform() === 'linux'
|
|
58
|
-
|
|
59
|
-
|
|
108
|
+
if (os.platform() === 'linux') {
|
|
109
|
+
const fonts = checkLinuxFonts();
|
|
110
|
+
if (!fonts.cjk || !fonts.emoji) {
|
|
111
|
+
console.log("Missing fonts detected. Attempting to fix environment...");
|
|
112
|
+
installFonts(fonts);
|
|
113
|
+
}
|
|
60
114
|
}
|
|
61
115
|
let browser;
|
|
62
116
|
const launchOptions = {
|
|
@@ -91,12 +145,12 @@ export const ScreenshotTool = {
|
|
|
91
145
|
await page.goto(args.url, { waitUntil: 'networkidle', timeout: 30000 });
|
|
92
146
|
// Inject CSS to force common Chinese fonts
|
|
93
147
|
// Note: For Docker environments (Alpine/Debian), ensure fonts are installed.
|
|
94
|
-
// Alpine: apk add font-noto-cjk
|
|
95
|
-
// Debian/Ubuntu: apt-get install fonts-noto-cjk fonts-wqy-zenhei
|
|
148
|
+
// Alpine: apk add font-noto-cjk font-noto-emoji
|
|
149
|
+
// Debian/Ubuntu: apt-get install fonts-noto-cjk fonts-wqy-zenhei fonts-noto-color-emoji
|
|
96
150
|
await page.addStyleTag({
|
|
97
151
|
content: `
|
|
98
152
|
body, h1, h2, h3, h4, h5, h6, p, span, div, li, a, button, input, textarea {
|
|
99
|
-
font-family: "PingFang SC", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif !important;
|
|
153
|
+
font-family: "PingFang SC", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", "Noto Sans CJK SC", "Noto Sans SC", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif !important;
|
|
100
154
|
}
|
|
101
155
|
`
|
|
102
156
|
});
|
|
@@ -106,7 +160,7 @@ export const ScreenshotTool = {
|
|
|
106
160
|
await page.waitForTimeout(1000);
|
|
107
161
|
await page.screenshot({
|
|
108
162
|
path: args.outputPath,
|
|
109
|
-
fullPage: args.fullPage
|
|
163
|
+
fullPage: args.fullPage !== false // Default to true if undefined
|
|
110
164
|
});
|
|
111
165
|
return `Successfully captured screenshot of ${args.url} and saved to ${args.outputPath}`;
|
|
112
166
|
}
|