🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
fix: browser_install (#3231)
Puzhen Zhanga1ac02ed86f5
diff --git a/camel/storages/vectordb_storages/oceanbase.py b/camel/storages/vectordb_storages/oceanbase.pyindex 60ec1d0ef..7cfe4b5c1 100644--- a/camel/storages/vectordb_storages/oceanbase.py+++ b/camel/storages/vectordb_storages/oceanbase.py@@ -74,7 +74,6 @@ class OceanBaseStorage(BaseVectorStorage):ObVecClient,)from pyobvector.client.index_param import (- IndexParam,IndexParams,)from pyobvector.schema import VECTORdiff --git a/camel/toolkits/hybrid_browser_toolkit/installer.py b/camel/toolkits/hybrid_browser_toolkit/installer.pynew file mode 100644index 000000000..d3d9c1093--- /dev/null+++ b/camel/toolkits/hybrid_browser_toolkit/installer.py@@ -0,0 +1,203 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========++import os+import platform+import shutil+import subprocess+from typing import Optional, Tuple++from camel.logger import get_logger++logger = get_logger(__name__)+++def find_command(+ cmd_base: str,+ windows_variants: Optional[list] = None,+ unix_variant: Optional[str] = None,+) -> Optional[str]:+ """Find command across platforms."""+ is_windows = platform.system() == 'Windows'++ if is_windows and windows_variants:+ for variant in windows_variants:+ if shutil.which(variant):+ return variant+ else:+ variant = unix_variant or cmd_base+ if shutil.which(variant):+ return variant++ if shutil.which(cmd_base):+ return cmd_base+ return None+++def create_command_not_found_error(+ command: str, error: Optional[Exception] = None+) -> RuntimeError:+ base_msg = f"{command} is not installed or not in PATH. "+ if command in ['npm', 'node']:+ base_msg += (+ f"Please install Node.js{' and npm' if command == 'npm' else ''} "+ f"from https://nodejs.org/ to use the hybrid browser toolkit."+ )+ if not error:+ base_msg += (+ " If already installed, ensure the Node.js installation "+ "directory (e.g., C:\\Program Files\\nodejs on Windows) is "+ "in your system PATH."+ )+ if error:+ base_msg += f" Error details: {error!s}"+ return RuntimeError(base_msg)+++def create_npm_command_error(command: str, error: Exception) -> RuntimeError:+ return RuntimeError(+ f"Failed to run {command}: {error!s}. "+ f"Please ensure npm is properly installed and in PATH."+ )+++async def check_and_install_dependencies(ts_dir: str) -> Tuple[str, str]:+ """Check Node.js/npm and install dependencies if needed.++ Returns:+ Tuple of (npm_cmd, node_cmd) that can be used for running commands+ """+ is_windows = platform.system() == 'Windows'+ use_shell = is_windows++ npm_cmd = find_command('npm', windows_variants=['npm.cmd', 'npm.exe'])+ if not npm_cmd:+ raise create_command_not_found_error('npm')++ try:+ npm_check = subprocess.run(+ [npm_cmd, '--version'],+ capture_output=True,+ text=True,+ shell=use_shell,+ )+ if npm_check.returncode != 0:+ raise RuntimeError(+ f"npm command failed with error: {npm_check.stderr}. "+ "Please ensure Node.js and npm are properly installed."+ )+ except (FileNotFoundError, OSError) as e:+ raise create_command_not_found_error('npm', e)++ node_cmd = find_command('node', windows_variants=['node.exe'])+ if not node_cmd:+ raise create_command_not_found_error('node')++ try:+ node_check = subprocess.run(+ [node_cmd, '--version'],+ capture_output=True,+ text=True,+ shell=use_shell,+ )+ if node_check.returncode != 0:+ raise RuntimeError(+ f"node command failed with error: {node_check.stderr}. "+ "Please ensure Node.js is properly installed."+ )+ except (FileNotFoundError, OSError) as e:+ raise create_command_not_found_error('node', e)++ node_modules_path = os.path.join(ts_dir, 'node_modules')+ if not os.path.exists(node_modules_path):+ logger.warning("Node modules not found. Running npm install...")+ try:+ install_result = subprocess.run(+ [npm_cmd, 'install'],+ cwd=ts_dir,+ capture_output=True,+ text=True,+ shell=use_shell,+ )+ if install_result.returncode != 0:+ logger.error(f"npm install failed: {install_result.stderr}")+ raise RuntimeError(+ f"Failed to install npm dependencies: {install_result.stderr}\n" # noqa:E501+ f"Please run 'npm install' in {ts_dir} manually."+ )+ except (FileNotFoundError, OSError) as e:+ raise create_npm_command_error("npm install", e)+ logger.info("npm dependencies installed successfully")++ dist_dir = os.path.join(ts_dir, 'dist')+ if not os.path.exists(dist_dir) or not os.listdir(dist_dir):+ logger.info("Building TypeScript...")+ try:+ build_result = subprocess.run(+ [npm_cmd, 'run', 'build'],+ cwd=ts_dir,+ capture_output=True,+ text=True,+ shell=use_shell,+ )+ if build_result.returncode != 0:+ logger.error(f"TypeScript build failed: {build_result.stderr}")+ raise RuntimeError(+ f"TypeScript build failed: {build_result.stderr}"+ )+ logger.info("TypeScript build completed successfully")+ except (FileNotFoundError, OSError) as e:+ raise create_npm_command_error("npm run build", e)+ else:+ logger.info("TypeScript already built, skipping build")++ playwright_marker = os.path.join(ts_dir, '.playwright_installed')+ if not os.path.exists(playwright_marker):+ logger.info("Installing Playwright browsers...")+ npx_cmd = find_command('npx', windows_variants=['npx.cmd', 'npx.exe'])+ if not npx_cmd:+ logger.warning(+ "npx not found. Skipping Playwright browser installation. "+ "Users may need to run 'npx playwright install' manually."+ )+ else:+ try:+ playwright_install = subprocess.run(+ [npx_cmd, 'playwright', 'install'],+ cwd=ts_dir,+ capture_output=True,+ text=True,+ shell=use_shell,+ )+ if playwright_install.returncode == 0:+ logger.info("Playwright browsers installed successfully")+ with open(playwright_marker, 'w') as f:+ f.write('installed')+ else:+ logger.warning(+ f"Playwright browser installation failed: "+ f"{playwright_install.stderr}"+ )+ logger.warning(+ "Users may need to run 'npx playwright install' "+ "manually"+ )+ except (FileNotFoundError, OSError) as e:+ logger.warning(+ f"Failed to install Playwright browsers: {e!s}. "+ f"Users may need to run 'npx playwright install' "+ f"manually"+ )++ return npm_cmd, node_cmddiff --git a/camel/toolkits/hybrid_browser_toolkit/ts/package-lock.json b/camel/toolkits/hybrid_browser_toolkit/ts/package-lock.jsonindex 451773c15..59733a091 100644--- a/camel/toolkits/hybrid_browser_toolkit/ts/package-lock.json+++ b/camel/toolkits/hybrid_browser_toolkit/ts/package-lock.json@@ -10,7 +10,6 @@"license": "Apache-2.0","dependencies": {"playwright": "^1.40.0",- "sharp": "^0.32.0","ws": "^8.14.0"},"devDependencies": {@@ -1119,12 +1118,6 @@"sprintf-js": "~1.0.2"}},- "node_modules/b4a": {- "version": "1.6.7",- "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.7.tgz",- "integrity": "sha512-OnAYlL5b7LEkALw87fUVafQw5rVR9RjwGd4KUwNQ6DrrNmaVaUCgLipfVlzrPQ4tWOR9P0IXGNOx50jYCCdSJg==",- "license": "Apache-2.0"- },"node_modules/babel-jest": {"version": "29.7.0","resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz",@@ -1248,109 +1241,6 @@"dev": true,"license": "MIT"},- "node_modules/bare-events": {- "version": "2.6.0",- "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.6.0.tgz",- "integrity": "sha512-EKZ5BTXYExaNqi3I3f9RtEsaI/xBSGjE0XZCZilPzFAV/goswFHuPd9jEZlPIZ/iNZJwDSao9qRiScySz7MbQg==",- "license": "Apache-2.0",- "optional": true- },- "node_modules/bare-fs": {- "version": "4.1.6",- "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.1.6.tgz",- "integrity": "sha512-25RsLF33BqooOEFNdMcEhMpJy8EoR88zSMrnOQOaM3USnOK2VmaJ1uaQEwPA6AQjrv1lXChScosN6CzbwbO9OQ==",- "license": "Apache-2.0",- "optional": true,- "dependencies": {- "bare-events": "^2.5.4",- "bare-path": "^3.0.0",- "bare-stream": "^2.6.4"- },- "engines": {- "bare": ">=1.16.0"- },- "peerDependencies": {- "bare-buffer": "*"- },- "peerDependenciesMeta": {- "bare-buffer": {- "optional": true- }- }- },- "node_modules/bare-os": {- "version": "3.6.1",- "resolved": "https://registry.npmjs.org/bare-os/-/bare-os-3.6.1.tgz",- "integrity": "sha512-uaIjxokhFidJP+bmmvKSgiMzj2sV5GPHaZVAIktcxcpCyBFFWO+YlikVAdhmUo2vYFvFhOXIAlldqV29L8126g==",- "license": "Apache-2.0",- "optional": true,- "engines": {- "bare": ">=1.14.0"- }- },- "node_modules/bare-path": {- "version": "3.0.0",- "resolved": "https://registry.npmjs.org/bare-path/-/bare-path-3.0.0.tgz",- "integrity": "sha512-tyfW2cQcB5NN8Saijrhqn0Zh7AnFNsnczRcuWODH0eYAXBsJ5gVxAUuNr7tsHSC6IZ77cA0SitzT+s47kot8Mw==",- "license": "Apache-2.0",- "optional": true,- "dependencies": {- "bare-os": "^3.0.1"- }- },- "node_modules/bare-stream": {- "version": "2.6.5",- "resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.6.5.tgz",- "integrity": "sha512-jSmxKJNJmHySi6hC42zlZnq00rga4jjxcgNZjY9N5WlOe/iOoGRtdwGsHzQv2RlH2KOYMwGUXhf2zXd32BA9RA==",- "license": "Apache-2.0",- "optional": true,- "dependencies": {- "streamx": "^2.21.0"- },- "peerDependencies": {- "bare-buffer": "*",- "bare-events": "*"- },- "peerDependenciesMeta": {- "bare-buffer": {- "optional": true- },- "bare-events": {- "optional": true- }- }- },- "node_modules/base64-js": {- "version": "1.5.1",- "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",- "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",- "funding": [- {- "type": "github",- "url": "https://github.com/sponsors/feross"- },- {- "type": "patreon",- "url": "https://www.patreon.com/feross"- },- {- "type": "consulting",- "url": "https://feross.org/support"- }- ],- "license": "MIT"- },- "node_modules/bl": {- "version": "4.1.0",- "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",- "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==",- "license": "MIT",- "dependencies": {- "buffer": "^5.5.0",- "inherits": "^2.0.4",- "readable-stream": "^3.4.0"- }- },"node_modules/brace-expansion": {"version": "1.1.12","resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",@@ -1418,30 +1308,6 @@"node-int64": "^0.4.0"}},- "node_modules/buffer": {- "version": "5.7.1",- "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",- "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",- "funding": [- {- "type": "github",- "url": "https://github.com/sponsors/feross"- },- {- "type": "patreon",- "url": "https://www.patreon.com/feross"- },- {- "type": "consulting",- "url": "https://feross.org/support"- }- ],- "license": "MIT",- "dependencies": {- "base64-js": "^1.3.1",- "ieee754": "^1.1.13"- }- },"node_modules/buffer-from": {"version": "1.1.2","resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",@@ -1517,12 +1383,6 @@"node": ">=10"}},- "node_modules/chownr": {- "version": "1.1.4",- "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",- "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==",- "license": "ISC"- },"node_modules/ci-info": {"version": "3.9.0","resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz",@@ -1579,23 +1439,11 @@"dev": true,"license": "MIT"},- "node_modules/color": {- "version": "4.2.3",- "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",- "integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==",- "license": "MIT",- "dependencies": {- "color-convert": "^2.0.1",- "color-string": "^1.9.0"- },- "engines": {- "node": ">=12.5.0"- }- },"node_modules/color-convert": {"version": "2.0.1","resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz","integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",+ "dev": true,"license": "MIT","dependencies": {"color-name": "~1.1.4"@@ -1608,18 +1456,9 @@"version": "1.1.4","resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz","integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",+ "dev": true,"license": "MIT"},- "node_modules/color-string": {- "version": "1.9.1",- "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz",- "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==",- "license": "MIT",- "dependencies": {- "color-name": "^1.0.0",- "simple-swizzle": "^0.2.2"- }- },"node_modules/concat-map": {"version": "0.0.1","resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",@@ -1689,21 +1528,6 @@}}},- "node_modules/decompress-response": {- "version": "6.0.0",- "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz",- "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==",- "license": "MIT",- "dependencies": {- "mimic-response": "^3.1.0"- },- "engines": {- "node": ">=10"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },"node_modules/dedent": {"version": "1.6.0","resolved": "https://registry.npmjs.org/dedent/-/dedent-1.6.0.tgz",@@ -1719,15 +1543,6 @@}}},- "node_modules/deep-extend": {- "version": "0.6.0",- "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",- "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==",- "license": "MIT",- "engines": {- "node": ">=4.0.0"- }- },"node_modules/deepmerge": {"version": "4.3.1","resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz",@@ -1738,15 +1553,6 @@"node": ">=0.10.0"}},- "node_modules/detect-libc": {- "version": "2.0.4",- "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.4.tgz",- "integrity": "sha512-3UDv+G9CsCKO1WKMGw9fwq/SWJYbI0c5Y7LU1AXYoDdbhE2AHQ6N6Nb34sG8Fj7T5APy8qXDCKuuIHd1BR0tVA==",- "license": "Apache-2.0",- "engines": {- "node": ">=8"- }- },"node_modules/detect-newline": {"version": "3.1.0","resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz",@@ -1794,15 +1600,6 @@"dev": true,"license": "MIT"},- "node_modules/end-of-stream": {- "version": "1.4.5",- "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz",- "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==",- "license": "MIT",- "dependencies": {- "once": "^1.4.0"- }- },"node_modules/error-ex": {"version": "1.3.2","resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz",@@ -1880,15 +1677,6 @@"node": ">= 0.8.0"}},- "node_modules/expand-template": {- "version": "2.0.3",- "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz",- "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==",- "license": "(MIT OR WTFPL)",- "engines": {- "node": ">=6"- }- },"node_modules/expect": {"version": "29.7.0","resolved": "https://registry.npmjs.org/expect/-/expect-29.7.0.tgz",@@ -1906,12 +1694,6 @@"node": "^14.15.0 || ^16.10.0 || >=18.0.0"}},- "node_modules/fast-fifo": {- "version": "1.3.2",- "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz",- "integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==",- "license": "MIT"- },"node_modules/fast-json-stable-stringify": {"version": "2.1.0","resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",@@ -1956,12 +1738,6 @@"node": ">=8"}},- "node_modules/fs-constants": {- "version": "1.0.0",- "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",- "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==",- "license": "MIT"- },"node_modules/fs.realpath": {"version": "1.0.0","resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",@@ -2037,12 +1813,6 @@"url": "https://github.com/sponsors/sindresorhus"}},- "node_modules/github-from-package": {- "version": "0.0.0",- "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz",- "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==",- "license": "MIT"- },"node_modules/glob": {"version": "7.2.3","resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",@@ -2112,26 +1882,6 @@"node": ">=10.17.0"}},- "node_modules/ieee754": {- "version": "1.2.1",- "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",- "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",- "funding": [- {- "type": "github",- "url": "https://github.com/sponsors/feross"- },- {- "type": "patreon",- "url": "https://www.patreon.com/feross"- },- {- "type": "consulting",- "url": "https://feross.org/support"- }- ],- "license": "BSD-3-Clause"- },"node_modules/import-local": {"version": "3.2.0","resolved": "https://registry.npmjs.org/import-local/-/import-local-3.2.0.tgz",@@ -2178,12 +1928,7 @@"version": "2.0.4","resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz","integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",- "license": "ISC"- },- "node_modules/ini": {- "version": "1.3.8",- "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",- "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==",+ "dev": true,"license": "ISC"},"node_modules/is-arrayish": {@@ -3113,18 +2858,6 @@"node": ">=6"}},- "node_modules/mimic-response": {- "version": "3.1.0",- "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz",- "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==",- "license": "MIT",- "engines": {- "node": ">=10"- },- "funding": {- "url": "https://github.com/sponsors/sindresorhus"- }- },"node_modules/minimatch": {"version": "3.1.2","resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",@@ -3138,21 +2871,6 @@"node": "*"}},- "node_modules/minimist": {- "version": "1.2.8",- "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",- "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",- "license": "MIT",- "funding": {- "url": "https://github.com/sponsors/ljharb"- }- },- "node_modules/mkdirp-classic": {- "version": "0.5.3",- "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",- "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",- "license": "MIT"- },"node_modules/ms": {"version": "2.1.3","resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",@@ -3160,12 +2878,6 @@"dev": true,"license": "MIT"},- "node_modules/napi-build-utils": {- "version": "2.0.0",- "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-2.0.0.tgz",- "integrity": "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==",- "license": "MIT"- },"node_modules/natural-compare": {"version": "1.4.0","resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",@@ -3173,36 +2885,6 @@"dev": true,"license": "MIT"},- "node_modules/node-abi": {- "version": "3.75.0",- "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.75.0.tgz",- "integrity": "sha512-OhYaY5sDsIka7H7AtijtI9jwGYLyl29eQn/W623DiN/MIv5sUqc4g7BIDThX+gb7di9f6xK02nkp8sdfFWZLTg==",- "license": "MIT",- "dependencies": {- "semver": "^7.3.5"- },- "engines": {- "node": ">=10"- }- },- "node_modules/node-abi/node_modules/semver": {- "version": "7.7.2",- "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",- "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==",- "license": "ISC",- "bin": {- "semver": "bin/semver.js"- },- "engines": {- "node": ">=10"- }- },- "node_modules/node-addon-api": {- "version": "6.1.0",- "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-6.1.0.tgz",- "integrity": "sha512-+eawOlIgy680F0kBzPUNFhMZGtJ1YmqM6l4+Crf4IkImjYrO/mqPwRMh352g23uIaQKFItcQ64I7KMaJxHgAVA==",- "license": "MIT"- },"node_modules/node-int64": {"version": "0.4.0","resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",@@ -3244,6 +2926,7 @@"version": "1.4.0","resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz","integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",+ "dev": true,"license": "ISC","dependencies": {"wrappy": "1"@@ -3463,60 +3146,6 @@"node": "^8.16.0 || ^10.6.0 || >=11.0.0"}},- "node_modules/prebuild-install": {- "version": "7.1.3",- "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz",- "integrity": "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==",- "license": "MIT",- "dependencies": {- "detect-libc": "^2.0.0",- "expand-template": "^2.0.3",- "github-from-package": "0.0.0",- "minimist": "^1.2.3",- "mkdirp-classic": "^0.5.3",- "napi-build-utils": "^2.0.0",- "node-abi": "^3.3.0",- "pump": "^3.0.0",- "rc": "^1.2.7",- "simple-get": "^4.0.0",- "tar-fs": "^2.0.0",- "tunnel-agent": "^0.6.0"- },- "bin": {- "prebuild-install": "bin.js"- },- "engines": {- "node": ">=10"- }- },- "node_modules/prebuild-install/node_modules/tar-fs": {- "version": "2.1.3",- "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.3.tgz",- "integrity": "sha512-090nwYJDmlhwFwEW3QQl+vaNnxsO2yVsd45eTKRBzSzu+hlb1w2K9inVq5b0ngXuLVqQ4ApvsUHHnu/zQNkWAg==",- "license": "MIT",- "dependencies": {- "chownr": "^1.1.1",- "mkdirp-classic": "^0.5.2",- "pump": "^3.0.0",- "tar-stream": "^2.1.4"- }- },- "node_modules/prebuild-install/node_modules/tar-stream": {- "version": "2.2.0",- "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz",- "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==",- "license": "MIT",- "dependencies": {- "bl": "^4.0.3",- "end-of-stream": "^1.4.1",- "fs-constants": "^1.0.0",- "inherits": "^2.0.3",- "readable-stream": "^3.1.1"- },- "engines": {- "node": ">=6"- }- },"node_modules/pretty-format": {"version": "29.7.0","resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz",@@ -3559,16 +3188,6 @@"node": ">= 6"}},- "node_modules/pump": {- "version": "3.0.3",- "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.3.tgz",- "integrity": "sha512-todwxLMY7/heScKmntwQG8CXVkWUOdYxIvY2s0VWAAMh/nd8SoYiRaKjlr7+iCs984f2P8zvrfWcDDYVb73NfA==",- "license": "MIT",- "dependencies": {- "end-of-stream": "^1.1.0",- "once": "^1.3.1"- }- },"node_modules/pure-rand": {"version": "6.1.0","resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.1.0.tgz",@@ -3586,30 +3205,6 @@],"license": "MIT"},- "node_modules/rc": {- "version": "1.2.8",- "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz",- "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==",- "license": "(BSD-2-Clause OR MIT OR Apache-2.0)",- "dependencies": {- "deep-extend": "^0.6.0",- "ini": "~1.3.0",- "minimist": "^1.2.0",- "strip-json-comments": "~2.0.1"- },- "bin": {- "rc": "cli.js"- }- },- "node_modules/rc/node_modules/strip-json-comments": {- "version": "2.0.1",- "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",- "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==",- "license": "MIT",- "engines": {- "node": ">=0.10.0"- }- },"node_modules/react-is": {"version": "18.3.1","resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz",@@ -3617,20 +3212,6 @@"dev": true,"license": "MIT"},- "node_modules/readable-stream": {- "version": "3.6.2",- "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",- "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",- "license": "MIT",- "dependencies": {- "inherits": "^2.0.3",- "string_decoder": "^1.1.1",- "util-deprecate": "^1.0.1"- },- "engines": {- "node": ">= 6"- }- },"node_modules/require-directory": {"version": "2.1.1","resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",@@ -3695,26 +3276,6 @@"node": ">=10"}},- "node_modules/safe-buffer": {- "version": "5.2.1",- "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",- "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",- "funding": [- {- "type": "github",- "url": "https://github.com/sponsors/feross"- },- {- "type": "patreon",- "url": "https://www.patreon.com/feross"- },- {- "type": "consulting",- "url": "https://feross.org/support"- }- ],- "license": "MIT"- },"node_modules/semver": {"version": "6.3.1","resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",@@ -3725,41 +3286,6 @@"semver": "bin/semver.js"}},- "node_modules/sharp": {- "version": "0.32.6",- "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.32.6.tgz",- "integrity": "sha512-KyLTWwgcR9Oe4d9HwCwNM2l7+J0dUQwn/yf7S0EnTtb0eVS4RxO0eUSvxPtzT4F3SY+C4K6fqdv/DO27sJ/v/w==",- "hasInstallScript": true,- "license": "Apache-2.0",- "dependencies": {- "color": "^4.2.3",- "detect-libc": "^2.0.2",- "node-addon-api": "^6.1.0",- "prebuild-install": "^7.1.1",- "semver": "^7.5.4",- "simple-get": "^4.0.1",- "tar-fs": "^3.0.4",- "tunnel-agent": "^0.6.0"- },- "engines": {- "node": ">=14.15.0"- },- "funding": {- "url": "https://opencollective.com/libvips"- }- },- "node_modules/sharp/node_modules/semver": {- "version": "7.7.2",- "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",- "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==",- "license": "ISC",- "bin": {- "semver": "bin/semver.js"- },- "engines": {- "node": ">=10"- }- },"node_modules/shebang-command": {"version": "2.0.0","resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",@@ -3790,66 +3316,6 @@"dev": true,"license": "ISC"},- "node_modules/simple-concat": {- "version": "1.0.1",- "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",- "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==",- "funding": [- {- "type": "github",- "url": "https://github.com/sponsors/feross"- },- {- "type": "patreon",- "url": "https://www.patreon.com/feross"- },- {- "type": "consulting",- "url": "https://feross.org/support"- }- ],- "license": "MIT"- },- "node_modules/simple-get": {- "version": "4.0.1",- "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz",- "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==",- "funding": [- {- "type": "github",- "url": "https://github.com/sponsors/feross"- },- {- "type": "patreon",- "url": "https://www.patreon.com/feross"- },- {- "type": "consulting",- "url": "https://feross.org/support"- }- ],- "license": "MIT",- "dependencies": {- "decompress-response": "^6.0.0",- "once": "^1.3.1",- "simple-concat": "^1.0.0"- }- },- "node_modules/simple-swizzle": {- "version": "0.2.2",- "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",- "integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==",- "license": "MIT",- "dependencies": {- "is-arrayish": "^0.3.1"- }- },- "node_modules/simple-swizzle/node_modules/is-arrayish": {- "version": "0.3.2",- "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz",- "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==",- "license": "MIT"- },"node_modules/sisteransi": {"version": "1.0.5","resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",@@ -3908,28 +3374,6 @@"node": ">=10"}},- "node_modules/streamx": {- "version": "2.22.1",- "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.22.1.tgz",- "integrity": "sha512-znKXEBxfatz2GBNK02kRnCXjV+AA4kjZIUxeWSr3UGirZMJfTE9uiwKHobnbgxWyL/JWro8tTq+vOqAK1/qbSA==",- "license": "MIT",- "dependencies": {- "fast-fifo": "^1.3.2",- "text-decoder": "^1.1.0"- },- "optionalDependencies": {- "bare-events": "^2.2.0"- }- },- "node_modules/string_decoder": {- "version": "1.3.0",- "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",- "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",- "license": "MIT",- "dependencies": {- "safe-buffer": "~5.2.0"- }- },"node_modules/string-length": {"version": "4.0.2","resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz",@@ -4031,31 +3475,6 @@"url": "https://github.com/sponsors/ljharb"}},- "node_modules/tar-fs": {- "version": "3.1.0",- "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.1.0.tgz",- "integrity": "sha512-5Mty5y/sOF1YWj1J6GiBodjlDc05CUR8PKXrsnFAiSG0xA+GHeWLovaZPYUDXkH/1iKRf2+M5+OrRgzC7O9b7w==",- "license": "MIT",- "dependencies": {- "pump": "^3.0.0",- "tar-stream": "^3.1.5"- },- "optionalDependencies": {- "bare-fs": "^4.0.1",- "bare-path": "^3.0.0"- }- },- "node_modules/tar-stream": {- "version": "3.1.7",- "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.7.tgz",- "integrity": "sha512-qJj60CXt7IU1Ffyc3NJMjh6EkuCFej46zUqJ4J7pqYlThyd9bO0XBTmcOIhSzZJVWfsLks0+nle/j538YAW9RQ==",- "license": "MIT",- "dependencies": {- "b4a": "^1.6.4",- "fast-fifo": "^1.2.0",- "streamx": "^2.15.0"- }- },"node_modules/test-exclude": {"version": "6.0.0","resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz",@@ -4071,15 +3490,6 @@"node": ">=8"}},- "node_modules/text-decoder": {- "version": "1.2.3",- "resolved": "https://registry.npmjs.org/text-decoder/-/text-decoder-1.2.3.tgz",- "integrity": "sha512-3/o9z3X0X0fTupwsYvR03pJ/DjWuqqrfwBgTQzdWDiQSm9KitAyz/9WqsT2JQW7KV2m+bC2ol/zqpW37NHxLaA==",- "license": "Apache-2.0",- "dependencies": {- "b4a": "^1.6.4"- }- },"node_modules/tmpl": {"version": "1.0.5","resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",@@ -4100,18 +3510,6 @@"node": ">=8.0"}},- "node_modules/tunnel-agent": {- "version": "0.6.0",- "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",- "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==",- "license": "Apache-2.0",- "dependencies": {- "safe-buffer": "^5.0.1"- },- "engines": {- "node": "*"- }- },"node_modules/type-detect": {"version": "4.0.8","resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",@@ -4187,12 +3585,6 @@"browserslist": ">= 4.21.0"}},- "node_modules/util-deprecate": {- "version": "1.0.2",- "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",- "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",- "license": "MIT"- },"node_modules/v8-to-istanbul": {"version": "9.3.0","resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz",@@ -4256,6 +3648,7 @@"version": "1.0.2","resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz","integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",+ "dev": true,"license": "ISC"},"node_modules/write-file-atomic": {diff --git a/camel/toolkits/hybrid_browser_toolkit/ts/package.json b/camel/toolkits/hybrid_browser_toolkit/ts/package.jsonindex 89287e06a..891181e2c 100644--- a/camel/toolkits/hybrid_browser_toolkit/ts/package.json+++ b/camel/toolkits/hybrid_browser_toolkit/ts/package.json@@ -20,7 +20,6 @@"license": "Apache-2.0","dependencies": {"playwright": "^1.40.0",- "sharp": "^0.32.0","ws": "^8.14.0"},"devDependencies": {diff --git a/camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py b/camel/toolkits/hybrid_browser_toolkit/ws_wrapper.pyindex c07d93630..8d3f72d9a 100644--- a/camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py+++ b/camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py@@ -34,9 +34,42 @@ else:from camel.logger import get_loggerfrom camel.utils.tool_result import ToolResult+from .installer import check_and_install_dependencies+logger = get_logger(__name__)+def _create_memory_aware_error(base_msg: str) -> str:+ import psutil++ mem = psutil.virtual_memory()+ if mem.available < 1024**3:+ return (+ f"{base_msg} "+ f"(likely due to insufficient memory). "+ f"Available memory: {mem.available / 1024**3:.2f}GB "+ f"({mem.percent}% used)"+ )+ return base_msg+++async def _cleanup_process_and_tasks(process, log_reader_task, ts_log_file):+ if process:+ with contextlib.suppress(ProcessLookupError, Exception):+ process.kill()+ with contextlib.suppress(Exception):+ process.wait(timeout=2)++ if log_reader_task and not log_reader_task.done():+ log_reader_task.cancel()+ with contextlib.suppress(asyncio.CancelledError):+ await log_reader_task++ if ts_log_file:+ with contextlib.suppress(Exception):+ ts_log_file.close()++def action_logger(func):"""Decorator to add logging to action methods."""@@ -192,69 +225,14 @@ class WebSocketBrowserWrapper:"""Start the WebSocket server and connect to it."""await self._cleanup_existing_processes()+ npm_cmd, node_cmd = await check_and_install_dependencies(self.ts_dir)+import platformuse_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(- "npm is not installed or not in PATH. "- "Please install Node.js and npm from https://nodejs.org/ "- "to use the hybrid browser toolkit."- )- node_check = subprocess.run(- ['node', '--version'],- capture_output=True,- text=True,- shell=use_shell,- )- if node_check.returncode != 0:- raise RuntimeError(- "node is not installed or not in PATH. "- "Please install Node.js from https://nodejs.org/ "- "to use the hybrid browser toolkit."- )-- node_modules_path = os.path.join(self.ts_dir, 'node_modules')- if not os.path.exists(node_modules_path):- logger.warning("Node modules not found. Running npm install...")- install_result = subprocess.run(- ['npm', 'install'],- 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}")- raise RuntimeError(- f"Failed to install npm dependencies: {install_result.stderr}\n" # noqa:E501- f"Please run 'npm install' in {self.ts_dir} manually."- )- logger.info("npm dependencies installed successfully")-- build_result = subprocess.run(- ['npm', 'run', 'build'],- 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}")- raise RuntimeError(- f"TypeScript build failed: {build_result.stderr}"- )-- # use_shell already defined aboveself.process = subprocess.Popen(- ['node', 'websocket-server.js'],+ [node_cmd, 'websocket-server.js'],cwd=self.ts_dir,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,@@ -286,32 +264,17 @@ class WebSocketBrowserWrapper:server_ready = Falseif not server_ready:- with contextlib.suppress(ProcessLookupError, Exception):- self.process.kill()- with contextlib.suppress(Exception):- self.process.wait(timeout=2)- if self._log_reader_task and not self._log_reader_task.done():- self._log_reader_task.cancel()- with contextlib.suppress(asyncio.CancelledError):- await self._log_reader_task- if getattr(self, 'ts_log_file', None):- with contextlib.suppress(Exception):- self.ts_log_file.close()- self.ts_log_file = None+ await _cleanup_process_and_tasks(+ self.process,+ self._log_reader_task,+ getattr(self, 'ts_log_file', None),+ )+ self.ts_log_file = Noneself.process = None- error_msg = "WebSocket server failed to start within timeout"- import psutil-- mem = psutil.virtual_memory()- if mem.available < 1024**3:- error_msg = (- f"WebSocket server failed to start"- f"(likely due to insufficient memory). "- f"Available memory: {mem.available / 1024**3:.2f}GB "- f"({mem.percent}% used)"- )-+ error_msg = _create_memory_aware_error(+ "WebSocket server failed to start within timeout"+ )raise RuntimeError(error_msg)max_retries = 3@@ -367,35 +330,17 @@ class WebSocketBrowserWrapper:breakif not self.websocket:- with contextlib.suppress(ProcessLookupError, Exception):- self.process.kill()- with contextlib.suppress(Exception):- self.process.wait(timeout=2)- if self._log_reader_task and not self._log_reader_task.done():- self._log_reader_task.cancel()- with contextlib.suppress(asyncio.CancelledError):- await self._log_reader_task- if getattr(self, 'ts_log_file', None):- with contextlib.suppress(Exception):- self.ts_log_file.close()- self.ts_log_file = None+ await _cleanup_process_and_tasks(+ self.process,+ self._log_reader_task,+ getattr(self, 'ts_log_file', None),+ )+ self.ts_log_file = Noneself.process = None- import psutil-- mem = psutil.virtual_memory()-- error_msg = (+ error_msg = _create_memory_aware_error("Failed to connect to WebSocket server after multiple attempts")- if mem.available < 1024**3:- error_msg = (- f"Failed to connect to WebSocket server "- f"(likely due to insufficient memory). "- f"Available memory: {mem.available / 1024**3:.2f}GB "- f"({mem.percent}% used)"- )-raise RuntimeError(error_msg)self._receive_task = asyncio.create_task(self._receive_loop())@@ -601,18 +546,7 @@ class WebSocketBrowserWrapper:async def _ensure_connection(self) -> None:"""Ensure WebSocket connection is alive."""if not self.websocket:- error_msg = "WebSocket not connected"- import psutil-- mem = psutil.virtual_memory()- if mem.available < 1024**3:- error_msg = (- f"WebSocket not connected "- f"(likely due to insufficient memory). "- f"Available memory: {mem.available / 1024**3:.2f}GB "- f"({mem.percent}% used)"- )-+ error_msg = _create_memory_aware_error("WebSocket not connected")raise RuntimeError(error_msg)# Check if connection is still alive@@ -624,18 +558,7 @@ class WebSocketBrowserWrapper:logger.warning(f"WebSocket ping failed: {e}")self.websocket = None- error_msg = "WebSocket connection lost"- import psutil-- mem = psutil.virtual_memory()- if mem.available < 1024**3:- error_msg = (- f"WebSocket connection lost "- f"(likely due to insufficient memory). "- f"Available memory: {mem.available / 1024**3:.2f}GB "- f"({mem.percent}% used)"- )-+ error_msg = _create_memory_aware_error("WebSocket connection lost")raise RuntimeError(error_msg)async def _send_command(diff --git a/hatch_build_npm.py b/hatch_build_npm.pydeleted file mode 100644index d347aa1c7..000000000--- a/hatch_build_npm.py+++ /dev/null@@ -1,304 +0,0 @@-# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========-# Licensed under the Apache License, Version 2.0 (the "License");-# you may not use this file except in compliance with the License.-# You may obtain a copy of the License at-#-# http://www.apache.org/licenses/LICENSE-2.0-#-# Unless required by applicable law or agreed to in writing, software-# distributed under the License is distributed on an "AS IS" BASIS,-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.-# See the License for the specific language governing permissions and-# limitations under the License.-# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========-"""-Hatch build hook for building TypeScript dependencies in-hybrid_browser_toolkit.--This script runs during package building to compile TypeScript code.-It gracefully handles cases where Node.js/npm is not available.-"""--import json-import platform-import re-import subprocess-from pathlib import Path-from typing import Optional, Tuple--from hatchling.builders.hooks.plugin.interface import BuildHookInterface---class NpmBuildHook(BuildHookInterface):- r"""Hatch build hook for TypeScript compilation."""-- PLUGIN_NAME = "npm-build"-- def initialize(self, version, build_data):- r"""Initialize the build hook and run npm build."""- self.build_npm_dependencies()-- def finalize(self, version, build_data, artifact_path):- r"""Finalize the build - ensure TypeScript was built."""- base_dir = Path(self.root)- ts_dir = self._get_ts_directory(base_dir)- dist_dir = ts_dir / "dist"-- if dist_dir.exists():- print(f"TypeScript build artifacts found at: {dist_dir}")- else:- print("Warning: TypeScript build artifacts not found")-- def _get_ts_directory(self, base_dir: Path) -> Path:- r"""Get the TypeScript directory path."""- return (- base_dir / "camel" / "toolkits" / "hybrid_browser_toolkit" / "ts"- )-- def _parse_version(self, version_str: str) -> Tuple[int, int, int]:- r"""Parse version string into major, minor, patch numbers."""- version_str = version_str.strip().lstrip('v')- match = re.match(r'(\d+)\.(\d+)\.(\d+)', version_str)- if match:- 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:- r"""Check if current version meets requirement."""- if required.startswith('>='):- required_version = self._parse_version(required[2:])- current_version = self._parse_version(current)- return current_version >= required_version- elif required.startswith('^'):- required_version = self._parse_version(required[1:])- current_version = self._parse_version(current)- return (- current_version[0] == required_version[0]- and current_version >= required_version- )- return True-- def _get_package_requirements(self, ts_dir: Path) -> Optional[dict]:- r"""Get Node.js/npm version requirements from package.json or- package-lock.json.- """- package_json = ts_dir / "package.json"- package_lock = ts_dir / "package-lock.json"-- try:- if package_json.exists():- with open(package_json, 'r') as f:- data = json.load(f)- if 'engines' in data:- return data['engines']-- if package_lock.exists():- with open(package_lock, 'r') as f:- data = json.load(f)- for pkg_name, pkg_data in data.get('packages', {}).items():- if not pkg_name and 'engines' in pkg_data:- return pkg_data['engines']-- except (json.JSONDecodeError, IOError) as e:- print(f"Warning: Could not read package requirements: {e}")-- return None-- def _check_node_npm_versions(- self, ts_dir: Path- ) -> Tuple[Optional[str], Optional[str], bool]:- r"""Check Node.js and npm versions against requirements."""- node_version = None- npm_version = None- versions_ok = True-- use_shell = platform.system() == "Windows"-- try:- result = subprocess.run(- ["node", "--version"],- check=True,- capture_output=True,- text=True,- timeout=30,- shell=use_shell,- )- node_version = result.stdout.strip()- print(f"Found Node.js version: {node_version}")- except (FileNotFoundError, subprocess.CalledProcessError):- print("Warning: Node.js not found in PATH")- return None, None, False-- try:- result = subprocess.run(- ["npm", "--version"],- check=True,- capture_output=True,- text=True,- timeout=30,- shell=use_shell,- )- npm_version = result.stdout.strip()- print(f"Found npm version: {npm_version}")- except (FileNotFoundError, subprocess.CalledProcessError):- print("Warning: npm not found in PATH")- return node_version, None, False-- requirements = self._get_package_requirements(ts_dir)- if requirements:- if 'node' in requirements:- node_req = requirements['node']- if not self._check_version_requirement(node_version, node_req):- print(- f"Warning: Node.js version {node_version} "- f"does not meet requirement {node_req}"- )- versions_ok = False- else:- print(- f"✓ Node.js version {node_version} meets "- f"requirement {node_req}"- )-- if 'npm' in requirements:- npm_req = requirements['npm']- if not self._check_version_requirement(npm_version, npm_req):- print(- f"Warning: npm version {npm_version} does not "- f"meet requirement {npm_req}"- )- versions_ok = False- else:- print(- f"✓ npm version {npm_version} meets "- f"requirement {npm_req}"- )-- return node_version, npm_version, versions_ok-- 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(- ["npm", "install"],- cwd=ts_dir,- check=True,- text=True,- timeout=300,- shell=use_shell,- )-- print("Building TypeScript...")- subprocess.run(- ["npm", "run", "build"],- cwd=ts_dir,- check=True,- text=True,- timeout=300,- shell=use_shell,- )-- print("Installing Playwright browsers...")- try:- subprocess.run(- ["npx", "playwright", "install"],- cwd=ts_dir,- check=True,- text=True,- timeout=600,- shell=use_shell,- )- print("Playwright browsers installed successfully")- except subprocess.CalledProcessError as e:- print(f"Warning: Playwright browser installation failed: {e}")- print(- "Users will need to run 'npx playwright install' manually"- )- print(" npx playwright install")-- index_js = dist_dir / "index.js"- if index_js.exists():- print("TypeScript build completed successfully")- return True- else:- print(- "Warning: TypeScript build may have failed (index.js "- "not found)"- )- return False-- except subprocess.CalledProcessError as e:- print(f"Warning: TypeScript build failed with error: {e}")- print("Installing without TypeScript support")- print("This may affect hybrid_browser_toolkit functionality")- return False-- except Exception as e:- print(f"Warning: Unexpected error during TypeScript build: {e}")- print("Installing without TypeScript support")- return False-- def _print_manual_instructions(self, ts_dir: Path):- r"""Print manual installation instructions."""- print("Installing without TypeScript support")- print("To use hybrid_browser_toolkit, please install Node.js and run:")- print(f" cd {ts_dir}")- print(" npm install && npm run build")- print(" npx playwright install")-- def build_npm_dependencies(self):- r"""Build TypeScript dependencies during wheel/sdist creation."""- base_dir = Path(self.root)- ts_dir = self._get_ts_directory(base_dir)-- print(f"Checking TypeScript directory: {ts_dir}")-- if not ts_dir.exists():- print("TypeScript directory not found, skipping npm build")- return-- dist_dir = ts_dir / "dist"- if dist_dir.exists() and any(dist_dir.iterdir()):- print(- "TypeScript already built (dist directory exists), "- "skipping build"- )- return-- node_version, npm_version, versions_ok = self._check_node_npm_versions(- ts_dir- )-- if node_version is None or npm_version is None:- print("Warning: npm or node not found in PATH")- self._print_manual_instructions(ts_dir)- return-- if not versions_ok:- print("Warning: Node.js/npm version requirements not met")- print("Continuing anyway, but build may fail")-- self._run_npm_build_process(ts_dir, dist_dir)---def build_npm_dependencies_standalone():- r"""Standalone function for testing purposes."""- hook = NpmBuildHook(None, None)- hook.root = Path(__file__).parent.absolute()- hook.build_npm_dependencies()---if __name__ == "__main__":- print("=" * 60)- print("Running Hatch build hook for TypeScript dependencies")- print("=" * 60)-- build_npm_dependencies_standalone()-- print("=" * 60)- print("Build hook completed")- print("=" * 60)diff --git a/pyproject.toml b/pyproject.tomlindex 32923e44e..70cb29861 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -31,6 +31,7 @@ dependencies = ["psutil>=5.9.8,<6","pillow>=10.1.0,<11.0.0","openai>=1.86.0,<2",+ "websockets>=13.0,<15.1",]@@ -444,7 +445,6 @@ include = ["camel/toolkits/hybrid_browser_toolkit/ts/tsconfig.json","camel/toolkits/hybrid_browser_toolkit/ts/src/**/*","camel/toolkits/hybrid_browser_toolkit/ts/websocket-server.js",- "hatch_build_npm.py",]exclude = ["camel/toolkits/hybrid_browser_toolkit/ts/node_modules/**/*"]@@ -460,11 +460,6 @@ include = []exclude = ["camel/toolkits/hybrid_browser_toolkit/ts/node_modules/**/*"]-[tool.hatch.build.targets.wheel.hooks.custom]-path = "hatch_build_npm.py"--[tool.hatch.build.targets.sdist.hooks.custom]-path = "hatch_build_npm.py"[tool.hatch.metadata]allow-direct-references = truediff --git a/uv.lock b/uv.lockindex b546bdf3e..9b57648ef 100644--- a/uv.lock+++ b/uv.lock@@ -661,6 +661,7 @@ dependencies = [{ name = "psutil" },{ name = "pydantic" },{ name = "tiktoken" },+ { name = "websockets" },][package.optional-dependencies]@@ -1410,6 +1411,7 @@ requires-dist = [{ name = "weaviate-client", marker = "extra == 'all'", specifier = ">=4.15.0" },{ name = "weaviate-client", marker = "extra == 'rag'", specifier = ">=4.15.0" },{ name = "weaviate-client", marker = "extra == 'storage'", specifier = ">=4.15.0" },+ { name = "websockets", specifier = ">=13.0,<15.1" },{ name = "websockets", marker = "extra == 'all'", specifier = ">=13.0,<15.1" },{ name = "websockets", marker = "extra == 'eigent'", specifier = ">=13.0,<15.1" },{ name = "websockets", marker = "extra == 'owl'", specifier = ">=13.0,<15.1" },