myagent-ai 1.16.7 → 1.16.9
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/agents/main_agent.py +1 -0
- package/package.json +1 -1
- package/skills/chromedev_mcp.py +70 -24
package/agents/main_agent.py
CHANGED
package/package.json
CHANGED
package/skills/chromedev_mcp.py
CHANGED
|
@@ -227,56 +227,102 @@ class MCPClient:
|
|
|
227
227
|
|
|
228
228
|
# 4. [v1.16.7] Puppeteer 缓存目录(npx puppeteer install 安装的 Chromium)
|
|
229
229
|
home = os.path.expanduser("~")
|
|
230
|
+
# Puppeteer 标准缓存路径
|
|
230
231
|
puppeteer_cache_dirs = [
|
|
231
232
|
os.path.join(home, ".cache", "puppeteer", "chrome"),
|
|
232
233
|
os.path.join(home, ".cache", "puppeteer"),
|
|
234
|
+
os.path.join(home, ".cache", "ms-playwright"),
|
|
233
235
|
]
|
|
234
236
|
for cache_dir in puppeteer_cache_dirs:
|
|
235
237
|
if os.path.isdir(cache_dir):
|
|
236
238
|
# 查找 chrome / chromium 可执行文件
|
|
237
239
|
for root, dirs, files in os.walk(cache_dir):
|
|
238
240
|
for fname in files:
|
|
239
|
-
if fname in ("chrome", "chromium"):
|
|
241
|
+
if fname in ("chrome", "chromium", "headless_shell"):
|
|
240
242
|
full = os.path.join(root, fname)
|
|
241
243
|
if os.access(full, os.X_OK):
|
|
242
244
|
return full
|
|
243
245
|
|
|
246
|
+
# 5. [v1.16.8] puppeteer browsers install 的标准路径
|
|
247
|
+
# ~/.cache/puppeteer/chrome/{platform-{arch}}/chrome-linux64/chrome
|
|
248
|
+
puppeteer_browsers_dir = os.path.join(
|
|
249
|
+
home, ".cache", "puppeteer", "chrome"
|
|
250
|
+
)
|
|
251
|
+
if os.path.isdir(puppeteer_browsers_dir):
|
|
252
|
+
for entry in os.listdir(puppeteer_browsers_dir):
|
|
253
|
+
entry_path = os.path.join(puppeteer_browsers_dir, entry)
|
|
254
|
+
if os.path.isdir(entry_path):
|
|
255
|
+
# 进入 platform 目录
|
|
256
|
+
for sub in os.listdir(entry_path):
|
|
257
|
+
sub_path = os.path.join(entry_path, sub)
|
|
258
|
+
if os.path.isdir(sub_path):
|
|
259
|
+
for fname in ["chrome", "headless_shell"]:
|
|
260
|
+
full = os.path.join(sub_path, fname)
|
|
261
|
+
if os.path.isfile(full) and os.access(full, os.X_OK):
|
|
262
|
+
return full
|
|
263
|
+
|
|
244
264
|
return None
|
|
245
265
|
|
|
246
266
|
@staticmethod
|
|
247
267
|
def _try_install_chromium() -> bool:
|
|
248
|
-
"""[v1.16.
|
|
249
|
-
|
|
250
|
-
依次尝试: apt install chromium-browser → apt install chromium
|
|
251
|
-
需要当前用户有 sudo 权限(容器环境通常有 root 权限)。
|
|
252
|
-
"""
|
|
253
|
-
import stat
|
|
268
|
+
"""[v1.16.8] 尝试自动安装 Chrome/Chromium。
|
|
254
269
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
270
|
+
安装策略(按优先级):
|
|
271
|
+
1. npx puppeteer install chrome — 下载官方 Chrome,自带所有依赖,最可靠
|
|
272
|
+
2. apt install chromium-browser — 系统包
|
|
273
|
+
3. apt install chromium — 备用包名
|
|
259
274
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
275
|
+
容器环境缺少 libnss3/libatk 等共享库时,apt 安装的 Chromium 会崩溃,
|
|
276
|
+
而 puppeteer 下载的 Chrome 是自包含的,不受影响。
|
|
277
|
+
"""
|
|
278
|
+
# 方法1: puppeteer install chrome(推荐,容器环境最可靠)
|
|
279
|
+
if shutil.which("npx"):
|
|
263
280
|
try:
|
|
264
|
-
logger.info(
|
|
281
|
+
logger.info("正在通过 puppeteer 下载 Chrome...")
|
|
265
282
|
result = subprocess.run(
|
|
266
|
-
["
|
|
267
|
-
capture_output=True, text=True, timeout=
|
|
283
|
+
["npx", "-y", "puppeteer", "browsers", "install", "chrome@stable"],
|
|
284
|
+
capture_output=True, text=True, timeout=300,
|
|
268
285
|
)
|
|
269
286
|
if result.returncode == 0:
|
|
270
|
-
logger.info(
|
|
287
|
+
logger.info("puppeteer install chrome 成功")
|
|
271
288
|
return True
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
289
|
+
# 也尝试旧版命令格式
|
|
290
|
+
result2 = subprocess.run(
|
|
291
|
+
["npx", "-y", "puppeteer", "install"],
|
|
292
|
+
capture_output=True, text=True, timeout=300,
|
|
293
|
+
)
|
|
294
|
+
if result2.returncode == 0:
|
|
295
|
+
logger.info("puppeteer install 成功")
|
|
296
|
+
return True
|
|
297
|
+
logger.warning(
|
|
298
|
+
f"puppeteer install 失败: "
|
|
299
|
+
f"{result.stderr[-300:] if result.stderr else result.stdout[-300:]}"
|
|
300
|
+
)
|
|
276
301
|
except subprocess.TimeoutExpired:
|
|
277
|
-
logger.warning(
|
|
302
|
+
logger.warning("puppeteer install 超时 (5分钟)")
|
|
278
303
|
except Exception as e:
|
|
279
|
-
logger.warning(f"
|
|
304
|
+
logger.warning(f"puppeteer install 异常: {e}")
|
|
305
|
+
|
|
306
|
+
# 方法2: apt install(后备)
|
|
307
|
+
if shutil.which("apt"):
|
|
308
|
+
packages = ["chromium-browser", "chromium"]
|
|
309
|
+
for pkg in packages:
|
|
310
|
+
try:
|
|
311
|
+
logger.info(f"正在 apt install {pkg}...")
|
|
312
|
+
result = subprocess.run(
|
|
313
|
+
["apt", "install", "-y", pkg],
|
|
314
|
+
capture_output=True, text=True, timeout=120,
|
|
315
|
+
)
|
|
316
|
+
if result.returncode == 0:
|
|
317
|
+
logger.info(f"成功安装 {pkg}")
|
|
318
|
+
return True
|
|
319
|
+
else:
|
|
320
|
+
logger.warning(
|
|
321
|
+
f"apt install {pkg} 失败: "
|
|
322
|
+
f"{result.stderr[-300:] if result.stderr else result.stdout[-300:]}"
|
|
323
|
+
)
|
|
324
|
+
except Exception as e:
|
|
325
|
+
logger.warning(f"apt install {pkg} 异常: {e}")
|
|
280
326
|
|
|
281
327
|
return False
|
|
282
328
|
|