Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

chore: browser windows compatibility (#3130)

Puzhen Zhangb2d7d4619267
diff --git a/camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py b/camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py
index c7592dc5d..c07d93630 100644
--- a/camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py
+++ b/camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py
@@ -192,10 +192,14 @@ class WebSocketBrowserWrapper:
"""Start the WebSocket server and connect to it."""
await self._cleanup_existing_processes()
+ import platform
+
+ use_shell = platform.system() == 'Windows'
npm_check = subprocess.run(
['npm', '--version'],
capture_output=True,
text=True,
+ shell=use_shell,
)
if npm_check.returncode != 0:
raise RuntimeError(
@@ -208,6 +212,7 @@ class WebSocketBrowserWrapper:
['node', '--version'],
capture_output=True,
text=True,
+ shell=use_shell,
)
if node_check.returncode != 0:
raise RuntimeError(
@@ -224,6 +229,7 @@ class WebSocketBrowserWrapper:
cwd=self.ts_dir,
capture_output=True,
text=True,
+ shell=use_shell,
)
if install_result.returncode != 0:
logger.error(f"npm install failed: {install_result.stderr}")
@@ -238,6 +244,7 @@ class WebSocketBrowserWrapper:
cwd=self.ts_dir,
capture_output=True,
text=True,
+ shell=use_shell,
)
if build_result.returncode != 0:
logger.error(f"TypeScript build failed: {build_result.stderr}")
@@ -245,13 +252,16 @@ class WebSocketBrowserWrapper:
f"TypeScript build failed: {build_result.stderr}"
)
+ # use_shell already defined above
self.process = subprocess.Popen(
['node', 'websocket-server.js'],
cwd=self.ts_dir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
+ encoding='utf-8',
bufsize=1,
+ shell=use_shell,
)
self._server_ready_future = asyncio.get_running_loop().create_future()
diff --git a/hatch_build_npm.py b/hatch_build_npm.py
index ba304e9f1..d347aa1c7 100644
--- a/hatch_build_npm.py
+++ b/hatch_build_npm.py
@@ -20,6 +20,7 @@ It gracefully handles cases where Node.js/npm is not available.
"""
import json
+import platform
import re
import subprocess
from pathlib import Path
@@ -59,7 +60,8 @@ class NpmBuildHook(BuildHookInterface):
version_str = version_str.strip().lstrip('v')
match = re.match(r'(\d+)\.(\d+)\.(\d+)', version_str)
if match:
- return tuple(map(int, match.groups()))
+ groups = match.groups()
+ return (int(groups[0]), int(groups[1]), int(groups[2]))
return (0, 0, 0)
def _check_version_requirement(self, current: str, required: str) -> bool:
@@ -111,6 +113,8 @@ class NpmBuildHook(BuildHookInterface):
npm_version = None
versions_ok = True
+ use_shell = platform.system() == "Windows"
+
try:
result = subprocess.run(
["node", "--version"],
@@ -118,6 +122,7 @@ class NpmBuildHook(BuildHookInterface):
capture_output=True,
text=True,
timeout=30,
+ shell=use_shell,
)
node_version = result.stdout.strip()
print(f"Found Node.js version: {node_version}")
@@ -132,6 +137,7 @@ class NpmBuildHook(BuildHookInterface):
capture_output=True,
text=True,
timeout=30,
+ shell=use_shell,
)
npm_version = result.stdout.strip()
print(f"Found npm version: {npm_version}")
@@ -173,6 +179,8 @@ class NpmBuildHook(BuildHookInterface):
def _run_npm_build_process(self, ts_dir: Path, dist_dir: Path) -> bool:
r"""Run the npm build process."""
+ use_shell = platform.system() == "Windows"
+
try:
print("Installing npm dependencies...")
subprocess.run(
@@ -181,6 +189,7 @@ class NpmBuildHook(BuildHookInterface):
check=True,
text=True,
timeout=300,
+ shell=use_shell,
)
print("Building TypeScript...")
@@ -190,6 +199,7 @@ class NpmBuildHook(BuildHookInterface):
check=True,
text=True,
timeout=300,
+ shell=use_shell,
)
print("Installing Playwright browsers...")
@@ -200,6 +210,7 @@ class NpmBuildHook(BuildHookInterface):
check=True,
text=True,
timeout=600,
+ shell=use_shell,
)
print("Playwright browsers installed successfully")
except subprocess.CalledProcessError as e: