Skip to content

Agent Zero AI framework

v0.8.1 release

frdelc161529e9035
diff --git a/agent.py b/agent.py
index 2deb7b965..c5775d131 100644
--- a/agent.py
+++ b/agent.py
@@ -618,6 +618,10 @@ class Agent:
await self.hist_add_user_message(msg, intervention=True)
raise InterventionException(msg)
+ async def wait_if_paused(self):
+ while self.context.paused:
+ await asyncio.sleep(0.1)
+
async def process_tools(self, msg: str):
# search for tool usage requests in agent message
tool_request = extract_tools.json_parse_dirty(msg)
diff --git a/docker/run/fs/exe/initialize.sh b/docker/run/fs/exe/initialize.sh
index 271c7512d..549515e2a 100644
--- a/docker/run/fs/exe/initialize.sh
+++ b/docker/run/fs/exe/initialize.sh
@@ -21,7 +21,7 @@ apt-get update > /dev/null 2>&1 &
/usr/sbin/sshd -D &
# Start searxng server in background
-su - searxng -c "bash /exe/run_searxng.sh" &
+su - searxng -c "bash /exe/run_searxng.sh \"$@\"" &
# Start A0 and restart on exit
bash /exe/run_A0.sh "$@"
diff --git a/docker/run/fs/exe/run_A0.sh b/docker/run/fs/exe/run_A0.sh
index ac499e693..7631b4a41 100644
--- a/docker/run/fs/exe/run_A0.sh
+++ b/docker/run/fs/exe/run_A0.sh
@@ -1,38 +1,13 @@
#!/bin/bash
-# Paths
-SOURCE_DIR="/git/agent-zero"
-TARGET_DIR="/a0"
-
-
-function setup_venv() {
- . "/ins/setup_venv.sh" "$@"
-}
-
-function clone_and_install() {
- # Copy repository files if run_ui.py is missing in /a0 (if the volume is mounted)
- if [ ! -f "$TARGET_DIR/run_ui.py" ]; then
-
- echo "Cloning and installing A0..."
- . "/ins/install_A0.sh" "$@"
-
- echo "Copying files from $SOURCE_DIR to $TARGET_DIR..."
- cp -rn --no-preserve=ownership,mode "$SOURCE_DIR/." "$TARGET_DIR"
-
- fi
-}
-
-# setup and preload A0
-setup_venv
-clone_and_install
-python /a0/prepare.py --dockerized=true
-python /a0/preload.py --dockerized=true
-
# Loop to restart the Python script when it finishes
while true; do
- setup_venv
- clone_repo
+ . "/ins/setup_venv.sh" "$@"
+ . "/ins/copy_A0.sh" "$@"
+
+ python /a0/prepare.py --dockerized=true
+ python /a0/preload.py --dockerized=true
echo "Starting A0..."
python /a0/run_ui.py \
diff --git a/docker/run/fs/ins/copy_A0.sh b/docker/run/fs/ins/copy_A0.sh
new file mode 100644
index 000000000..cbdc5c750
--- /dev/null
+++ b/docker/run/fs/ins/copy_A0.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# Paths
+SOURCE_DIR="/git/agent-zero"
+TARGET_DIR="/a0"
+
+# Copy repository files if run_ui.py is missing in /a0 (if the volume is mounted)
+if [ ! -f "$TARGET_DIR/run_ui.py" ]; then
+ echo "Copying files from $SOURCE_DIR to $TARGET_DIR..."
+ cp -rn --no-preserve=ownership,mode "$SOURCE_DIR/." "$TARGET_DIR"
+fi
\ No newline at end of file
diff --git a/models.py b/models.py
index 28819603b..4887f33cf 100644
--- a/models.py
+++ b/models.py
@@ -46,9 +46,9 @@ class ModelType(Enum):
class ModelProvider(Enum):
ANTHROPIC = "Anthropic"
DEEPSEEK = "DeepSeek"
- HUGGINGFACE = "HuggingFace"
GOOGLE = "Google"
GROQ = "Groq"
+ HUGGINGFACE = "HuggingFace"
LMSTUDIO = "LM Studio"
MISTRALAI = "Mistral AI"
OLLAMA = "Ollama"
diff --git a/prompts/default/agent.system.main.tips.md b/prompts/default/agent.system.main.tips.md
index 41c580f81..f69ef9206 100644
--- a/prompts/default/agent.system.main.tips.md
+++ b/prompts/default/agent.system.main.tips.md
@@ -4,7 +4,11 @@
reason step-by-step execute tasks
avoid repetition ensure progress
never assume success
-memory refers to knowledge_tool and memorize_tool not own knowledge
+memory refers to knowledge_tool and memory tools not own knowledge
+
+## Files
+save files in /root
+don't use spaces in file names
## Instruments
diff --git a/prompts/default/agent.system.tool.browser.md b/prompts/default/agent.system.tool.browser.md
index 029de8c5f..022ad9130 100644
--- a/prompts/default/agent.system.tool.browser.md
+++ b/prompts/default/agent.system.tool.browser.md
@@ -1,18 +1,32 @@
### browser_agent:
+
subordinate agent controls playwright browser
message argument talks to agent give clear instructions credentials task based
reset argument spawns new agent
do not reset if iterating
be precise descriptive like: open google login and end task, log in using ... and end task
+when following up start: considering open pages
dont use phrase wait for instructions use end task
+usage:
```json
{
"thoughts": ["I need to log in to..."],
"tool_name": "browser_agent",
"tool_args": {
"message": "Open and log me into...",
+ "reset": "true"
+ }
+}
+```
+
+```json
+{
+ "thoughts": ["I need to log in to..."],
+ "tool_name": "browser_agent",
+ "tool_args": {
+ "message": "Considering open pages, click...",
"reset": "false"
}
}
-```
\ No newline at end of file
+```
diff --git a/prompts/default/agent.system.tool.response.md b/prompts/default/agent.system.tool.response.md
index 666a0ef6b..ca0ddc76b 100644
--- a/prompts/default/agent.system.tool.response.md
+++ b/prompts/default/agent.system.tool.response.md
@@ -2,9 +2,7 @@
final answer to user
ends task processing use only when done or no task active
put result in text arg
-use memory for guidance
-online sources for current info
-verify memory with online
+always write full file paths
usage:
~~~json
{
diff --git a/prompts/default/browser_agent.system.md b/prompts/default/browser_agent.system.md
index 776c1483a..e9f3d7633 100644
--- a/prompts/default/browser_agent.system.md
+++ b/prompts/default/browser_agent.system.md
@@ -2,4 +2,6 @@
do not overdo task
when told go to website open website and stop
do not interact unless told to
-waiting for instructions means ending task as done
\ No newline at end of file
+waiting for instructions means ending task as done
+accept any cookies do not go to cokkie settings
+in page_summary respond with one paragraph of main content plus brief overview of page elements
\ No newline at end of file
diff --git a/python/api/chat_export.py b/python/api/chat_export.py
index c54586635..2817a4ea8 100644
--- a/python/api/chat_export.py
+++ b/python/api/chat_export.py
@@ -1,10 +1,9 @@
-from python.helpers.api import ApiHandler
-from flask import Request, Response
+from python.helpers.api import ApiHandler, Input, Output, Request, Response
from python.helpers import persist_chat
class ExportChat(ApiHandler):
- async def process(self, input: dict, request: Request) -> dict | Response:
+ async def process(self, input: Input, request: Request) -> Output:
ctxid = input.get("ctxid", "")
if not ctxid:
raise Exception("No context id provided")
diff --git a/python/api/chat_load.py b/python/api/chat_load.py
index 9d3e4b48f..3991212a7 100644
--- a/python/api/chat_load.py
+++ b/python/api/chat_load.py
@@ -1,10 +1,10 @@
-from python.helpers.api import ApiHandler
-from flask import Request, Response
+from python.helpers.api import ApiHandler, Input, Output, Request, Response
+
from python.helpers import persist_chat
class LoadChats(ApiHandler):
- async def process(self, input: dict, request: Request) -> dict | Response:
+ async def process(self, input: Input, request: Request) -> Output:
chats = input.get("chats", [])
if not chats:
raise Exception("No chats provided")
diff --git a/python/api/chat_remove.py b/python/api/chat_remove.py
index 92482849c..da98d4362 100644
--- a/python/api/chat_remove.py
+++ b/python/api/chat_remove.py
@@ -1,12 +1,12 @@
-from python.helpers.api import ApiHandler
-from flask import Request, Response
+from python.helpers.api import ApiHandler, Input, Output, Request, Response
+
from agent import AgentContext
from python.helpers import persist_chat
class RemoveChat(ApiHandler):
- async def process(self, input: dict, request: Request) -> dict | Response:
+ async def process(self, input: Input, request: Request) -> Output:
ctxid = input.get("context", "")
# context instance - get or create
diff --git a/python/api/chat_reset.py b/python/api/chat_reset.py
index 5f2417127..99032c549 100644
--- a/python/api/chat_reset.py
+++ b/python/api/chat_reset.py
@@ -1,10 +1,11 @@
-from python.helpers.api import ApiHandler
-from flask import Request, Response
+from python.helpers.api import ApiHandler, Input, Output, Request, Response
+
from python.helpers import persist_chat
+
class Reset(ApiHandler):
- async def process(self, input: dict, request: Request) -> dict | Response:
+ async def process(self, input: Input, request: Request) -> Output:
ctxid = input.get("context", "")
# context instance - get or create
diff --git a/python/api/ctx_window_get.py b/python/api/ctx_window_get.py
index 22e4edbd9..a8e20db94 100644
--- a/python/api/ctx_window_get.py
+++ b/python/api/ctx_window_get.py
@@ -1,10 +1,10 @@
+from python.helpers.api import ApiHandler, Input, Output, Request, Response
+
from python.helpers import tokens
-from python.helpers.api import ApiHandler
-from flask import Request, Response
class GetCtxWindow(ApiHandler):
- async def process(self, input: dict, request: Request) -> dict | Response:
+ async def process(self, input: Input, request: Request) -> Output:
ctxid = input.get("context", [])
context = self.get_context(ctxid)
agent = context.streaming_agent or context.agent0
diff --git a/python/api/delete_work_dir_file.py b/python/api/delete_work_dir_file.py
index 4b190df55..2808f9106 100644
--- a/python/api/delete_work_dir_file.py
+++ b/python/api/delete_work_dir_file.py
@@ -1,22 +1,31 @@
-from python.helpers.api import ApiHandler
-from flask import Request, Response
+from python.helpers.api import ApiHandler, Input, Output, Request, Response
+
from python.helpers.file_browser import FileBrowser
-from python.helpers import files
+from python.helpers import files, runtime
+from python.api import get_work_dir_files
class DeleteWorkDirFile(ApiHandler):
- async def process(self, input: dict, request: Request) -> dict | Response:
- file_path = input.get('path', '')
- current_path = input.get('currentPath', '')
-
- browser = FileBrowser()
-
- if browser.delete_file(file_path):
+ async def process(self, input: Input, request: Request) -> Output:
+ file_path = input.get("path", "")
+ if not file_path.startswith("/"):
+ file_path = f"/{file_path}"
+
+ current_path = input.get("currentPath", "")
+
+ # browser = FileBrowser()
+ res = await runtime.call_development_function(delete_file, file_path)
+
+ if res:
# Get updated file list
- result = browser.get_files(current_path)
- return {
- "data": result
- }
+ # result = browser.get_files(current_path)
+ result = await runtime.call_development_function(get_work_dir_files.get_files, current_path)
+ return {"data": result}
else:
- raise Exception("File not found or could not be deleted")
\ No newline at end of file
+ raise Exception("File not found or could not be deleted")
+
+
+async def delete_file(file_path: str):
+ browser = FileBrowser()
+ return browser.delete_file(file_path)
diff --git a/python/api/download_work_dir_file.py b/python/api/download_work_dir_file.py
index 52498c5f2..2961745c0 100644
--- a/python/api/download_work_dir_file.py
+++ b/python/api/download_work_dir_file.py
@@ -1,29 +1,64 @@
-from python.helpers.api import ApiHandler
-from flask import Request, Response, send_file
+import base64
+from io import BytesIO
-from python.helpers.file_browser import FileBrowser
-from python.helpers import files
+from python.helpers.api import ApiHandler, Input, Output, Request, Response
+from flask import send_file
+
+from python.helpers import files, runtime
+from python.api import file_info
import os
-class DownloadWorkDirFile(ApiHandler):
- async def process(self, input: dict, request: Request) -> dict | Response:
- file_path = request.args.get("path", "")
+class DownloadFile(ApiHandler):
+ async def process(self, input: Input, request: Request) -> Output:
+ file_path = request.args.get("path", input.get("path", ""))
if not file_path:
raise ValueError("No file path provided")
+ if not file_path.startswith("/"):
+ file_path = f"/{file_path}"
+
+ file = await runtime.call_development_function(
+ file_info.get_file_info, file_path
+ )
+
+ if not file["exists"]:
+ raise Exception(f"File {file_path} not found")
+
+ if file["is_dir"]:
+ zip_file = await runtime.call_development_function(files.zip_dir, file["abs_path"])
+ if runtime.is_development():
+ b64 = await runtime.call_development_function(fetch_file, zip_file)
+ file_data = BytesIO(base64.b64decode(b64))
+ return send_file(
+ file_data,
+ as_attachment=True,
+ download_name=os.path.basename(zip_file),
+ )
+ else:
+ return send_file(
+ zip_file,
+ as_attachment=True,
+ download_name=f"{os.path.basename(file_path)}.zip",
+ )
+ elif file["is_file"]:
+ if runtime.is_development():
+ b64 = await runtime.call_development_function(fetch_file, file["abs_path"])
+ file_data = BytesIO(base64.b64decode(b64))
+ return send_file(
+ file_data,
+ as_attachment=True,
+ download_name=os.path.basename(file_path),
+ )
+ else:
+ return send_file(
+ file["abs_path"],
+ as_attachment=True,
+ download_name=os.path.basename(file["file_name"]),
+ )
+ raise Exception(f"File {file_path} not found")
+
- browser = FileBrowser()
-
- full_path = browser.get_full_path(file_path, True)
- if os.path.isdir(full_path):
- zip_file = browser.zip_dir(full_path)
- return send_file(
- zip_file,
- as_attachment=True,
- download_name=f"{os.path.basename(file_path)}.zip",
- )
- if full_path:
- return send_file(
- full_path, as_attachment=True, download_name=os.path.basename(file_path)
- )
- raise Exception("File not found")
+async def fetch_file(path):
+ with open(path, "rb") as file:
+ file_content = file.read()
+ return base64.b64encode(file_content).decode("utf-8")
diff --git a/python/api/file_info.py b/python/api/file_info.py
new file mode 100644
index 000000000..6f52db4f6
--- /dev/null
+++ b/python/api/file_info.py
@@ -0,0 +1,51 @@
+import os
+from python.helpers.api import ApiHandler, Input, Output, Request, Response
+from python.helpers import files, runtime
+from typing import TypedDict
+
+class FileInfoApi(ApiHandler):
+ async def process(self, input: Input, request: Request) -> Output:
+ path = input.get("path", "")
+ info = await runtime.call_development_function(get_file_info, path)
+ return info
+
+class FileInfo(TypedDict):
+ input_path: str
+ abs_path: str
+ exists: bool
+ is_dir: bool
+ is_file: bool
+ is_link: bool
+ size: int
+ modified: float
+ created: float
+ permissions: int
+ dir_path: str
+ file_name: str
+ file_ext: str
+ message: str
+
+async def get_file_info(path: str) -> FileInfo:
+ abs_path = files.get_abs_path(path)
+ exists = os.path.exists(abs_path)
+ message = ""
+
+ if not exists:
+ message = f"File {path} not found."
+
+ return {
+ "input_path": path,
+ "abs_path": abs_path,
+ "exists": exists,
+ "is_dir": os.path.isdir(abs_path) if exists else False,
+ "is_file": os.path.isfile(abs_path) if exists else False,
+ "is_link": os.path.islink(abs_path) if exists else False,
+ "size": os.path.getsize(abs_path) if exists else 0,
+ "modified": os.path.getmtime(abs_path) if exists else 0,
+ "created": os.path.getctime(abs_path) if exists else 0,
+ "permissions": os.stat(abs_path).st_mode if exists else 0,
+ "dir_path": os.path.dirname(abs_path),
+ "file_name": os.path.basename(abs_path),
+ "file_ext": os.path.splitext(abs_path)[1],
+ "message": message
+ }
\ No newline at end of file
diff --git a/python/api/get_work_dir_files.py b/python/api/get_work_dir_files.py
index 836332fde..6d93e67f9 100644
--- a/python/api/get_work_dir_files.py
+++ b/python/api/get_work_dir_files.py
@@ -9,11 +9,18 @@ class GetWorkDirFiles(ApiHandler):
async def process(self, input: dict, request: Request) -> dict | Response:
current_path = request.args.get("path", "")
if current_path == "$WORK_DIR":
- if runtime.is_development():
- current_path = "work_dir"
- else:
- current_path = "root"
- browser = FileBrowser()
- result = browser.get_files(current_path)
+ # if runtime.is_development():
+ # current_path = "work_dir"
+ # else:
+ # current_path = "root"
+ current_path = "root"
+
+ # browser = FileBrowser()
+ # result = browser.get_files(current_path)
+ result = await runtime.call_development_function(get_files, current_path)
return {"data": result}
+
+async def get_files(path):
+ browser = FileBrowser()
+ return browser.get_files(path)
\ No newline at end of file
diff --git a/python/api/health.py b/python/api/health.py
index 9fe81f56b..c2055fef8 100644
--- a/python/api/health.py
+++ b/python/api/health.py
@@ -1,10 +1,17 @@
from python.helpers.api import ApiHandler
from flask import Request, Response
+from python.helpers import errors
from python.helpers import git
class HealthCheck(ApiHandler):
async def process(self, input: dict, request: Request) -> dict | Response:
- gitinfo = git.get_git_info()
- return {"gitinfo": gitinfo}
+ gitinfo = None
+ error = None
+ try:
+ gitinfo = git.get_git_info()
+ except Exception as e:
+ error = errors.error_text(e)
+
+ return {"gitinfo": gitinfo, "error": error}
diff --git a/python/api/upload_work_dir_files.py b/python/api/upload_work_dir_files.py
index eb6d0b940..74035b02d 100644
--- a/python/api/upload_work_dir_files.py
+++ b/python/api/upload_work_dir_files.py
@@ -1,33 +1,66 @@
+import base64
+from werkzeug.datastructures import FileStorage
from python.helpers.api import ApiHandler
from flask import Request, Response, send_file
from python.helpers.file_browser import FileBrowser
-from python.helpers import files
+from python.helpers import files, runtime
+from python.api import get_work_dir_files
import os
-
-
class UploadWorkDirFiles(ApiHandler):
async def process(self, input: dict, request: Request) -> dict | Response:
if "files[]" not in request.files:
raise Exception("No files uploaded")
- current_path = request.form.get('path', '')
- uploaded_files = request.files.getlist("files[]")
-
- browser = FileBrowser()
-
- successful, failed = browser.save_files(uploaded_files, current_path)
-
+ current_path = request.form.get("path", "")
+ uploaded_files = request.files.getlist("files[]")
+
+ # browser = FileBrowser()
+ # successful, failed = browser.save_files(uploaded_files, current_path)
+
+ successful, failed = await upload_files(uploaded_files, current_path)
+
if not successful and failed:
raise Exception("All uploads failed")
-
- result = browser.get_files(current_path)
-
+
+ # result = browser.get_files(current_path)
+ result = await runtime.call_development_function(get_work_dir_files.get_files, current_path)
+
return {
- "message": "Files uploaded successfully" if not failed else "Some files failed to upload",
+ "message": (
+ "Files uploaded successfully"
+ if not failed
+ else "Some files failed to upload"
+ ),
"data": result,
"successful": successful,
- "failed": failed
- }
\ No newline at end of file
+ "failed": failed,
+ }
+
+
+async def upload_files(uploaded_files: list[FileStorage], current_path: str):
+ if runtime.is_development():
+ successful = []
+ failed = []
+ for file in uploaded_files:
+ file_content = file.stream.read()
+ base64_content = base64.b64encode(file_content).decode("utf-8")
+ if await runtime.call_development_function(
+ upload_file, current_path, file.filename, base64_content
+ ):
+ successful.append(file.filename)
+ else:
+ failed.append(file.filename)
+ else:
+ browser = FileBrowser()
+ successful, failed = browser.save_files(uploaded_files, current_path)
+
+ return successful, failed
+
+
+async def upload_file(current_path: str, filename: str, base64_content: str):
+ browser = FileBrowser()
+ return browser.save_file_b64(current_path, filename, base64_content)
+
diff --git a/python/helpers/api.py b/python/helpers/api.py
index c7133eba3..b3dd6fce5 100644
--- a/python/helpers/api.py
+++ b/python/helpers/api.py
@@ -1,6 +1,8 @@
from abc import abstractmethod
import json
import threading
+from typing import Union, TypedDict, Dict, Any
+from attr import dataclass
from flask import Request, Response, jsonify, Flask
from agent import AgentContext
from initialize import initialize
@@ -9,6 +11,8 @@ from python.helpers.errors import format_error
from werkzeug.serving import make_server
+Input = dict
+Output = Union[Dict[str, Any], Response, TypedDict]
class ApiHandler:
@@ -17,7 +21,7 @@ class ApiHandler:
self.thread_lock = thread_lock
@abstractmethod
- async def process(self, input: dict, request: Request) -> dict | Response:
+ async def process(self, input: Input, request: Request) -> Output:
pass
async def handle_request(self, request: Request) -> Response:
@@ -31,12 +35,14 @@ class ApiHandler:
# process via handler
output = await self.process(input, request)
- # return output based on type
+ # return output based on type
if isinstance(output, Response):
return output
else:
response_json = json.dumps(output)
- return Response(response=response_json, status=200, mimetype="application/json")
+ return Response(
+ response=response_json, status=200, mimetype="application/json"
+ )
# return exceptions with 500
except Exception as e:
@@ -44,8 +50,6 @@ class ApiHandler:
PrintStyle.error(error)
return Response(response=error, status=500, mimetype="text/plain")
-
-
# get context to run agent zero in
def get_context(self, ctxid: str):
with self.thread_lock:
@@ -57,4 +61,4 @@ class ApiHandler:
got = AgentContext.get(ctxid)
if got:
return got
- return AgentContext(config=initialize(), id=ctxid)
\ No newline at end of file
+ return AgentContext(config=initialize(), id=ctxid)
diff --git a/python/helpers/browser_use.py b/python/helpers/browser_use.py
index 4a110f392..5c1800d2e 100644
--- a/python/helpers/browser_use.py
+++ b/python/helpers/browser_use.py
@@ -1,3 +1,4 @@
from python.helpers import dotenv
dotenv.save_dotenv_value("ANONYMIZED_TELEMETRY", "false")
-import browser_use
\ No newline at end of file
+import browser_use
+import browser_use.utils
\ No newline at end of file
diff --git a/python/helpers/defer.py b/python/helpers/defer.py
index 0b681d6f1..02605e4e4 100644
--- a/python/helpers/defer.py
+++ b/python/helpers/defer.py
@@ -1,12 +1,11 @@
import asyncio
from dataclasses import dataclass
import threading
-from concurrent.futures import Future, ThreadPoolExecutor
-from typing import Any, Callable, Optional, Coroutine, TypeVar, Union, Awaitable
+from concurrent.futures import Future
+from typing import Any, Callable, Optional, Coroutine, TypeVar, Awaitable
T = TypeVar("T")
-
class EventLoopThread:
_instances = {}
_lock = threading.Lock()
@@ -155,7 +154,7 @@ class DeferredTask:
return self._future and not self._future.done() # type: ignore
def restart(self, terminate_thread: bool = False) -> None:
- self.kill()
+ self.kill(terminate_thread=terminate_thread)
self._start_task()
def add_child_task(
diff --git a/python/helpers/file_browser.py b/python/helpers/file_browser.py
index 41fdd5bed..11f587ab6 100644
--- a/python/helpers/file_browser.py
+++ b/python/helpers/file_browser.py
@@ -2,6 +2,7 @@ import os
from pathlib import Path
import shutil
import tempfile
+import base64
from typing import Dict, List, Tuple, Optional, Any
import zipfile
from werkzeug.utils import secure_filename
@@ -20,10 +21,11 @@ class FileBrowser:
MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB
def __init__(self):
- if runtime.is_development():
- base_dir = files.get_base_dir()
- else:
- base_dir = "/"
+ # if runtime.is_development():
+ # base_dir = files.get_base_dir()
+ # else:
+ # base_dir = "/"
+ base_dir = "/"
self.base_dir = Path(base_dir)
def _check_file_size(self, file) -> bool:
@@ -35,6 +37,22 @@ class FileBrowser:
except (AttributeError, IOError):
return False
+ def save_file_b64(self, current_path: str, filename:str, base64_content: str):
+ try:
+ # Resolve the target directory path
+ target_file = (self.base_dir / current_path / filename).resolve()
+ if not str(target_file).startswith(str(self.base_dir)):
+ raise ValueError("Invalid target directory")
+
+ os.makedirs(target_file.parent, exist_ok=True)
+ # Save file
+ with open(target_file, "wb") as file:
+ file.write(base64.b64decode(base64_content))
+ return True
+ except Exception as e:
+ PrintStyle.error(f"Error saving file {filename}: {e}")
+ return False
+
def save_files(self, files: List, current_path: str = "") -> Tuple[List[str], List[str]]:
"""Save uploaded files and return successful and failed filenames"""
successful = []
@@ -176,17 +194,4 @@ class FileBrowser:
for file_type, extensions in self.ALLOWED_EXTENSIONS.items():
if ext in extensions:
return file_type
- return 'unknown'
-
- def zip_dir(self, dir_path: str):
- full_path = self.get_full_path(dir_path, allow_dir=True)
- zip_file_path = tempfile.NamedTemporaryFile(suffix='.zip', delete=False).name
- base_name = os.path.basename(full_path)
- with zipfile.ZipFile(zip_file_path, "w", compression=zipfile.ZIP_DEFLATED) as zip:
- for root, _, files in os.walk(full_path):
- for file in files:
- file_path = os.path.join(root, file)
- rel_path = os.path.relpath(file_path, full_path)
- zip.write(file_path, os.path.join(base_name, rel_path))
- return zip_file_path
-
\ No newline at end of file
+ return 'unknown'
\ No newline at end of file
diff --git a/python/helpers/files.py b/python/helpers/files.py
index 41f8ca10a..91bdd0566 100644
--- a/python/helpers/files.py
+++ b/python/helpers/files.py
@@ -3,6 +3,9 @@ import json
import os, re
import re
+import shutil
+import tempfile
+import zipfile
def parse_file(_relative_path, _backup_dirs=None, _encoding="utf-8", **kwargs):
@@ -50,6 +53,7 @@ def replace_placeholders_text(_content: str, **kwargs):
_content = _content.replace(placeholder, strval)
return _content
+
def replace_placeholders_json(_content: str, **kwargs):
# Replace placeholders with values from kwargs
for key, value in kwargs.items():
@@ -58,6 +62,7 @@ def replace_placeholders_json(_content: str, **kwargs):
_content = _content.replace(placeholder, strval)
return _content
+
def replace_placeholders_dict(_content: dict, **kwargs):
def replace_value(value):
if isinstance(value, str):
@@ -162,18 +167,26 @@ def write_file(relative_path: str, content: str, encoding: str = "utf-8"):
with open(abs_path, "w", encoding=encoding) as f:
f.write(content)
+
def write_file_bin(relative_path: str, content: bytes):
abs_path = get_abs_path(relative_path)
os.makedirs(os.path.dirname(abs_path), exist_ok=True)
with open(abs_path, "wb") as f:
f.write(content)
+
def delete_file(relative_path: str):
abs_path = get_abs_path(relative_path)
if os.path.exists(abs_path):
os.remove(abs_path)
+def delete_dir(relative_path: str):
+ abs_path = get_abs_path(relative_path)
+ if os.path.exists(abs_path):
+ shutil.rmtree(abs_path)
+
+
def list_files(relative_path: str, filter: str = "*"):
abs_path = get_abs_path(relative_path)
if not os.path.exists(abs_path):
@@ -181,6 +194,11 @@ def list_files(relative_path: str, filter: str = "*"):
return [file for file in os.listdir(abs_path) if fnmatch(file, filter)]
+def make_dirs(relative_path: str):
+ abs_path = get_abs_path(relative_path)
+ os.makedirs(os.path.dirname(abs_path), exist_ok=True)
+
+
def get_abs_path(*relative_paths):
return os.path.join(get_base_dir(), *relative_paths)
@@ -207,3 +225,23 @@ def get_subdirectories(relative_path: str, include: str = "*", exclude=None):
and fnmatch(subdir, include)
and (exclude is None or not fnmatch(subdir, exclude))
]
+
+
+def zip_dir(dir_path: str):
+ full_path = get_abs_path(dir_path)
+ zip_file_path = tempfile.NamedTemporaryFile(suffix=".zip", delete=False).name
+ base_name = os.path.basename(full_path)
+ with zipfile.ZipFile(zip_file_path, "w", compression=zipfile.ZIP_DEFLATED) as zip:
+ for root, _, files in os.walk(full_path):
+ for file in files:
+ file_path = os.path.join(root, file)
+ rel_path = os.path.relpath(file_path, full_path)
+ zip.write(file_path, os.path.join(base_name, rel_path))
+ return zip_file_path
+
+
+def move_file(relative_path: str, new_path: str):
+ abs_path = get_abs_path(relative_path)
+ new_abs_path = get_abs_path(new_path)
+ os.makedirs(os.path.dirname(new_abs_path), exist_ok=True)
+ os.rename(abs_path, new_abs_path)
diff --git a/python/helpers/git.py b/python/helpers/git.py
index 21dba1fac..0e112f4a7 100644
--- a/python/helpers/git.py
+++ b/python/helpers/git.py
@@ -30,6 +30,8 @@ def get_git_info():
tag_split = tag.split('-')
if len(tag_split) >= 3:
short_tag = "-".join(tag_split[:-1])
+ else:
+ short_tag = tag
except:
tag = ""
diff --git a/python/helpers/persist_chat.py b/python/helpers/persist_chat.py
index dffe8a390..d92f269b9 100644
--- a/python/helpers/persist_chat.py
+++ b/python/helpers/persist_chat.py
@@ -1,7 +1,7 @@
from collections import OrderedDict
from typing import Any
import uuid
-from agent import Agent, AgentConfig, AgentContext, HumanMessage, AIMessage
+from agent import Agent, AgentConfig, AgentContext
from python.helpers import files, history
import json
from initialize import initialize
@@ -10,27 +10,53 @@ from python.helpers.log import Log, LogItem
CHATS_FOLDER = "tmp/chats"
LOG_SIZE = 1000
+CHAT_FILE_NAME = "chat.json"
+def get_chat_folder_path(ctxid: str):
+ return files.get_abs_path(CHATS_FOLDER, ctxid)
+
def save_tmp_chat(context: AgentContext):
- relative_path = _get_file_path(context.id)
+ path = _get_chat_file_path(context.id)
+ files.make_dirs(path)
data = _serialize_context(context)
js = _safe_json_serialize(data, ensure_ascii=False)
- files.write_file(relative_path, js)
+ files.write_file(path, js)
def load_tmp_chats():
- json_files = files.list_files("tmp/chats", "*.json")
+ _convert_v080_chats()
+ folders = files.list_files("tmp/chats/", "*")
+ json_files = []
+ for folder in folders:
+ json_files.append(_get_chat_file_path(folder))
+
ctxids = []
for file in json_files:
- path = files.get_abs_path(CHATS_FOLDER, file)
- js = files.read_file(path)
- data = json.loads(js)
- ctx = _deserialize_context(data)
- ctxids.append(ctx.id)
+ try:
+ js = files.read_file(file)
+ data = json.loads(js)
+ ctx = _deserialize_context(data)
+ ctxids.append(ctx.id)
+ except Exception as e:
+ print(f"Error loading chat {file}: {e}")
return ctxids
+def _get_chat_file_path(ctxid: str):
+ return files.get_abs_path(CHATS_FOLDER, ctxid, CHAT_FILE_NAME)
+
+
+def _convert_v080_chats():
+ json_files = files.list_files("tmp/chats", "*.json")
+ for file in json_files:
+ path = files.get_abs_path(CHATS_FOLDER, file)
+ name = file.rstrip(".json")
+ fold = files.get_abs_path(CHATS_FOLDER, name)
+ new = _get_chat_file_path(name)
+ files.move_file(path, new)
+
+
def load_json_chats(jsons: list[str]):
ctxids = []
for js in jsons:
@@ -49,11 +75,8 @@ def export_json_chat(context: AgentContext):
def remove_chat(ctxid):
- files.delete_file(_get_file_path(ctxid))
-
+ files.delete_dir(get_chat_folder_path(ctxid))
-def _get_file_path(ctxid: str):
- return f"{CHATS_FOLDER}/{ctxid}.json"
def _serialize_context(context: AgentContext):
@@ -174,7 +197,7 @@ def _deserialize_log(data: dict[str, Any]) -> "Log":
log.logs.append(
LogItem(
log=log, # restore the log reference
- no=i, #item_data["no"],
+ no=i, # item_data["no"],
type=item_data["type"],
heading=item_data.get("heading", ""),
content=item_data.get("content", ""),
diff --git a/python/helpers/rag.py b/python/helpers/rag.py
new file mode 100644
index 000000000..0667fdc05
--- /dev/null
+++ b/python/helpers/rag.py
@@ -0,0 +1,60 @@
+from typing import List
+
+from langchain_core.documents import Document
+from python.helpers import files
+
+from langchain_community.document_loaders import (
+ CSVLoader,
+ JSONLoader,
+ PyPDFLoader,
+ TextLoader,
+ UnstructuredHTMLLoader,
+ UnstructuredMarkdownLoader,
+)
+
+# def extract_file(path: str) -> List[Document]:
+# pass # TODO finish implementing
+
+def extract_text(content: bytes, chunk_size: int = 128) -> List[str]:
+ result = []
+
+ def is_binary_chunk(chunk: bytes) -> bool:
+ # Check for high concentration of control chars
+ try:
+ text = chunk.decode("utf-8", errors="ignore")
+ control_chars = sum(1 for c in text if ord(c) < 32 and c not in "\n\r\t")
+ return control_chars / len(text) > 0.3
+ except UnicodeDecodeError:
+ return True
+
+ # Process the content in overlapping chunks to handle boundaries
+ pos = 0
+ while pos < len(content):
+ # Get current chunk with overlap
+ chunk_end = min(pos + chunk_size, len(content))
+
+ # Add overlap to catch word boundaries, unless at end of content
+ if chunk_end < len(content):
+ # Look ahead for next newline or space to avoid splitting words
+ for i in range(chunk_end, min(chunk_end + 100, len(content))):
+ if content[i : i + 1] in [b" ", b"\n", b"\r"]:
+ chunk_end = i + 1
+ break
+
+ chunk = content[pos:chunk_end]
+
+ if is_binary_chunk(chunk):
+ if not result or result[-1] != "[BINARY]":
+ result.append("[BINARY]")
+ else:
+ try:
+ text = chunk.decode("utf-8", errors="ignore").strip()
+ if text: # Only add non-empty text chunks
+ result.append(text)
+ except UnicodeDecodeError:
+ if not result or result[-1] != "[BINARY]":
+ result.append("[BINARY]")
+
+ pos = chunk_end
+
+ return result
diff --git a/python/helpers/runtime.py b/python/helpers/runtime.py
index 7ff2d0e8a..6709c6fdf 100644
--- a/python/helpers/runtime.py
+++ b/python/helpers/runtime.py
@@ -1,8 +1,11 @@
import argparse
import inspect
-from typing import Any, Callable
+from typing import TypeVar, Callable, Awaitable, Union, overload, cast
from python.helpers import dotenv, rfc, settings
+T = TypeVar('T')
+R = TypeVar('R')
+
parser = argparse.ArgumentParser()
args = {}
dockerman = None
@@ -52,11 +55,17 @@ def get_local_url():
return "host.docker.internal"
return "127.0.0.1"
-async def call_development_function(func: Callable, *args, **kwargs):
+@overload
+async def call_development_function(func: Callable[..., Awaitable[T]], *args, **kwargs) -> T: ...
+
+@overload
+async def call_development_function(func: Callable[..., T], *args, **kwargs) -> T: ...
+
+async def call_development_function(func: Union[Callable[..., T], Callable[..., Awaitable[T]]], *args, **kwargs) -> T:
if is_development():
url = _get_rfc_url()
password = _get_rfc_password()
- return await rfc.call_rfc(
+ result = await rfc.call_rfc(
url=url,
password=password,
module=func.__module__,
@@ -64,11 +73,12 @@ async def call_development_function(func: Callable, *args, **kwargs):
args=list(args),
kwargs=kwargs,
)
+ return cast(T, result)
else:
if inspect.iscoroutinefunction(func):
return await func(*args, **kwargs)
else:
- return func(*args, **kwargs)
+ return func(*args, **kwargs) # type: ignore
async def handle_rfc(rfc_call: rfc.RFCCall):
diff --git a/python/helpers/settings.py b/python/helpers/settings.py
index 6995cf484..8aaaefe78 100644
--- a/python/helpers/settings.py
+++ b/python/helpers/settings.py
@@ -381,7 +381,7 @@ def convert_out(settings: Settings) -> SettingsOutput:
{
"id": "browser_model_provider",
"title": "Web Browser model provider",
- "description": "Select provider for web browser model used by browser-use framework",
+ "description": "Select provider for web browser model used by <a href='https://github.com/browser-use/browser-use' target='_blank'>browser-use</a> framework",
"type": "select",
"value": settings["browser_model_provider"],
"options": [{"value": p.name, "label": p.value} for p in ModelProvider],
@@ -433,28 +433,28 @@ def convert_out(settings: Settings) -> SettingsOutput:
browser_model_section: SettingsSection = {
"id": "browser_model",
"title": "Web Browser Model",
- "description": "Settings for the web browser model used by browser-use framework.",
+ "description": "Settings for the web browser model. Agent Zero uses <a href='https://github.com/browser-use/browser-use' target='_blank'>browser-use</a> agentic framework to handle web interactions.",
"fields": browser_model_fields,
}
- # Memory settings section
- memory_fields: list[SettingsField] = []
- memory_fields.append(
- {
- "id": "memory_settings",
- "title": "Memory Settings",
- "description": "<settings for memory>",
- "type": "text",
- "value": "",
- }
- )
+ # # Memory settings section
+ # memory_fields: list[SettingsField] = []
+ # memory_fields.append(
+ # {
+ # "id": "memory_settings",
+ # "title": "Memory Settings",
+ # "description": "<settings for memory>",
+ # "type": "text",
+ # "value": "",
+ # }
+ # )
- memory_section: SettingsSection = {
- "id": "memory",
- "title": "Memory Settings",
- "description": "<settings for memory management here>",
- "fields": memory_fields,
- }
+ # memory_section: SettingsSection = {
+ # "id": "memory",
+ # "title": "Memory Settings",
+ # "description": "<settings for memory management here>",
+ # "fields": memory_fields,
+ # }
# basic auth section
auth_fields: list[SettingsField] = []
@@ -728,7 +728,7 @@ def convert_out(settings: Settings) -> SettingsOutput:
util_model_section,
embed_model_section,
browser_model_section,
- memory_section,
+ # memory_section,
stt_section,
api_keys_section,
auth_section,
diff --git a/python/helpers/strings.py b/python/helpers/strings.py
index 6fded50a5..3cab75980 100644
--- a/python/helpers/strings.py
+++ b/python/helpers/strings.py
@@ -2,6 +2,8 @@ import re
import sys
import time
+from python.helpers import files
+
def calculate_valid_match_lengths(first: bytes | str, second: bytes | str,
deviation_threshold: int = 5,
deviation_reset: int = 5,
@@ -113,4 +115,4 @@ def dict_to_text(d: dict) -> str:
parts.append(f"{value}")
parts.append("") # Add empty line between entries
- return "\n".join(parts).rstrip() # rstrip to remove trailing newline
+ return "\n".join(parts).rstrip() # rstrip to remove trailing newline
\ No newline at end of file
diff --git a/python/helpers/vector_db.py b/python/helpers/vector_db.py
new file mode 100644
index 000000000..c1bc1095b
--- /dev/null
+++ b/python/helpers/vector_db.py
@@ -0,0 +1,116 @@
+from typing import Any, List, Sequence
+import uuid
+from langchain_community.vectorstores import FAISS
+import faiss
+from langchain_core.documents import Document
+from langchain.storage import InMemoryByteStore
+from langchain_community.docstore.in_memory import InMemoryDocstore
+from langchain_community.vectorstores.utils import (
+ DistanceStrategy,
+)
+from langchain.embeddings import CacheBackedEmbeddings
+
+from agent import Agent
+
+
+class MyFaiss(FAISS):
+ # override aget_by_ids
+ def get_by_ids(self, ids: Sequence[str], /) -> List[Document]:
+ # return all self.docstore._dict[id] in ids
+ return [self.docstore._dict[id] for id in (ids if isinstance(ids, list) else [ids]) if id in self.docstore._dict] # type: ignore
+
+ async def aget_by_ids(self, ids: Sequence[str], /) -> List[Document]:
+ return self.get_by_ids(ids)
+
+
+class VectorDB:
+ def __init__(self, agent: Agent):
+ self.agent = agent
+ self.store = InMemoryByteStore()
+ self.model = agent.get_embedding_model()
+
+ self.embedder = CacheBackedEmbeddings.from_bytes_store(
+ self.model,
+ self.store,
+ namespace=getattr(
+ self.model,
+ "model",
+ getattr(self.model, "model_name", "default"),
+ ),
+ )
+
+ self.index = faiss.IndexFlatIP(len(self.embedder.embed_query("example")))
+
+ self.db = MyFaiss(
+ embedding_function=self.embedder,
+ index=self.index,
+ docstore=InMemoryDocstore(),
+ index_to_docstore_id={},
+ distance_strategy=DistanceStrategy.COSINE,
+ # normalize_L2=True,
+ relevance_score_fn=cosine_normalizer,
+ )
+
+ async def search_similarity_threshold(
+ self, query: str, limit: int, threshold: float, filter: str = ""
+ ):
+ comparator = get_comparator(filter) if filter else None
+
+ # rate limiter
+ await self.agent.rate_limiter(
+ model_config=self.agent.config.embeddings_model, input=query
+ )
+
+ return await self.db.asearch(
+ query,
+ search_type="similarity_score_threshold",
+ k=limit,
+ score_threshold=threshold,
+ filter=comparator,
+ )
+
+ async def insert_documents(self, docs: list[Document]):
+ ids = [str(uuid.uuid4()) for _ in range(len(docs))]
+
+ if ids:
+ for doc, id in zip(docs, ids):
+ doc.metadata["id"] = id # add ids to documents metadata
+
+ # rate limiter
+ docs_txt = "".join(format_docs_plain(docs))
+ await self.agent.rate_limiter(
+ model_config=self.agent.config.embeddings_model, input=docs_txt
+ )
+
+ self.db.add_documents(documents=docs, ids=ids)
+ return ids
+
+
+def format_docs_plain(docs: list[Document]) -> list[str]:
+ result = []
+ for doc in docs:
+ text = ""
+ for k, v in doc.metadata.items():
+ text += f"{k}: {v}\n"
+ text += f"Content: {doc.page_content}"
+ result.append(text)
+ return result
+
+
+def cosine_normalizer(val: float) -> float:
+ res = (1 + val) / 2
+ res = max(
+ 0, min(1, res)
+ ) # float precision can cause values like 1.0000000596046448
+ return res
+
+
+def get_comparator(condition: str):
+ def comparator(data: dict[str, Any]):
+ try:
+ return eval(condition, {}, data)
+ except Exception as e:
+ # PrintStyle.error(f"Error evaluating condition: {e}")
+ return False
+
+ return comparator
diff --git a/python/tools/browser_agent.py b/python/tools/browser_agent.py
index 2bd3747eb..64d326c22 100644
--- a/python/tools/browser_agent.py
+++ b/python/tools/browser_agent.py
@@ -5,7 +5,7 @@ from agent import Agent
import models
from python.helpers.tool import Tool, Response
-from python.helpers import dirty_json, files, rfc_exchange, defer, strings
+from python.helpers import dirty_json, files, rfc_exchange, defer, strings, persist_chat
from python.helpers.print_style import PrintStyle
from python.helpers.browser_use import browser_use
from pydantic import BaseModel
@@ -57,9 +57,7 @@ class State:
thread_name="BrowserAgent" + self.agent.context.id
)
if self.agent.context.task:
- self.agent.context.task.add_child_task(
- self.task, terminate_thread=True
- )
+ self.agent.context.task.add_child_task(self.task, terminate_thread=True)
self.task.start_task(self._run_task, task)
return self.task
@@ -114,7 +112,7 @@ class State:
self.use_agent = browser_use.Agent(
task=task,
browser_context=self.context,
- llm=self.agent.get_utility_model(),
+ llm=model,
use_vision=self.agent.config.browser_model.vision,
system_prompt_class=CustomSystemPrompt,
controller=controller,
@@ -172,15 +170,28 @@ class BrowserAgent(Tool):
await self.prepare_state()
result = {}
+ agent = self.agent
ua = self.state.use_agent
page = await self.state.get_page()
+ ctx = self.state.context
if ua and page:
try:
async def _get_update():
+
+ await agent.wait_if_paused()
+
log = []
+ # dom_service = browser_use.DomService(page)
+ # dom_state = await browser_use.utils.time_execution_sync('get_clickable_elements')(
+ # dom_service.get_clickable_elements
+ # )()
+ # elements = dom_state.element_tree
+ # selector_map = dom_state.selector_map
+ # el_text = elements.clickable_elements_to_string()
+
for message in ua.message_manager.get_messages():
if message.type == "system":
continue
@@ -202,7 +213,13 @@ class BrowserAgent(Tool):
log.append("FW:" + part)
result["log"] = log
- path = files.get_abs_path("tmp/browser", f"{self.guid}.png")
+ path = files.get_abs_path(
+ persist_chat.get_chat_folder_path(agent.context.id),
+ "browser",
+ "screenshots",
+ f"{self.guid}.png",
+ )
+ files.make_dirs(path)
await page.screenshot(path=path, full_page=False, timeout=3000)
result["screenshot"] = f"img://{path}&t={str(time.time())}"
diff --git a/python/tools/memory_save.py b/python/tools/memory_save.py
index be2b86cca..b2ae1bbdf 100644
--- a/python/tools/memory_save.py
+++ b/python/tools/memory_save.py
@@ -14,7 +14,7 @@ class MemorySave(Tool):
metadata = {"area": area, **kwargs}
db = await Memory.get(self.agent)
- id = db.insert_text(text, metadata)
+ id = await db.insert_text(text, metadata)
result = self.agent.read_prompt("fw.memory_saved.md", memory_id=id)
return Response(message=result, break_loop=False)
diff --git a/run_ui.py b/run_ui.py
index 6758c1226..bf297ee81 100644
--- a/run_ui.py
+++ b/run_ui.py
@@ -46,13 +46,20 @@ def requires_auth(f):
@app.route("/", methods=["GET"])
@requires_auth
async def serve_index():
- gitinfo = git.get_git_info()
+ gitinfo = None
+ try:
+ gitinfo = git.get_git_info()
+ except Exception as e:
+ gitinfo = {
+ "version": "unknown",
+ "commit_time": "unknown",
+ }
return files.read_file(
"./webui/index.html",
version_no=gitinfo["version"],
version_time=gitinfo["commit_time"],
)
-
+
def run():
PrintStyle().print("Initializing framework...")
@@ -66,15 +73,22 @@ def run():
pass # Override to suppress request logging
# Get configuration from environment
- port = runtime.get_arg("port") or int(dotenv.get_dotenv_value("WEB_UI_PORT", 0)) or 5000
- host = runtime.get_arg("host") or dotenv.get_dotenv_value("WEB_UI_HOST") or "localhost"
- use_cloudflare = (runtime.get_arg("cloudflare_tunnel")
- or dotenv.get_dotenv_value("USE_CLOUDFLARE", "false").lower()) == "true"
-
+ port = (
+ runtime.get_arg("port")
+ or int(dotenv.get_dotenv_value("WEB_UI_PORT", 0))
+ or 5000
+ )
+ host = (
+ runtime.get_arg("host") or dotenv.get_dotenv_value("WEB_UI_HOST") or "localhost"
+ )
+ use_cloudflare = (
+ runtime.get_arg("cloudflare_tunnel")
+ or dotenv.get_dotenv_value("USE_CLOUDFLARE", "false").lower()
+ ) == "true"
tunnel = None
- try:
+ try:
# Initialize and start Cloudflare tunnel if enabled
if use_cloudflare and port:
try:
@@ -95,26 +109,34 @@ def run():
def register_api_handler(app, handler: type[ApiHandler]):
name = handler.__module__.split(".")[-1]
instance = handler(app, lock)
+
@requires_auth
async def handle_request():
return await instance.handle_request(request=request)
+
app.add_url_rule(
f"/{name}",
f"/{name}",
handle_request,
methods=["POST", "GET"],
)
-
+
# initialize and register API handlers
handlers = load_classes_from_folder("python/api", "*.py", ApiHandler)
for handler in handlers:
register_api_handler(app, handler)
-
+
try:
- server = make_server(host=host, port=port, app=app, request_handler=NoRequestLoggingWSGIRequestHandler, threaded=True)
+ server = make_server(
+ host=host,
+ port=port,
+ app=app,
+ request_handler=NoRequestLoggingWSGIRequestHandler,
+ threaded=True,
+ )
process.set_server(server)
server.log_startup()
- server.serve_forever()
+ server.serve_forever()
# Run Flask app
# app.run(
# request_handler=NoRequestLoggingWSGIRequestHandler, port=port, host=host
diff --git a/web_test.py b/web_test.py
deleted file mode 100644
index fdabf0dfb..000000000
--- a/web_test.py
+++ /dev/null
@@ -1,84 +0,0 @@
-from browser_use import Agent, Browser, BrowserConfig, Controller, ActionResult
-from pydantic import BaseModel
-import asyncio
-
-import playwright
-import models
-from python.helpers import dotenv, files
-from playwright.async_api import async_playwright
-
-
-async def main():
-
- dotenv.load_dotenv()
- model = models.get_openai_chat("gpt-4o-mini")
-
- # Initialize controller first
- controller = Controller()
-
- # @controller.action("Ask user for information")
- # def ask_human(question: str, display_question: bool) -> str:
- # return input(f"\n{question}\nInput: ")
-
- class DoneResult(BaseModel):
- title: str
- response: str
- what_do_i_see: str
-
- # we overwrite done() in this example to demonstrate the validator
- @controller.registry.action("Done with task", param_model=DoneResult)
- async def done(params: DoneResult):
- result = ActionResult(is_done=True, extracted_content=params.model_dump_json())
- print(result)
- return result
-
- browser = Browser(
- config=BrowserConfig(
- headless=False,
- disable_security=True,
- )
- )
-
- # Await the coroutine to get the browser context
- context = await browser.new_context()
-
- async with context:
-
- # Add init script to the context - this will be applied to all new pages
- pw_context = context.session.context # type: ignore
- js_override = files.get_abs_path("lib/browser/init_override.js")
- await pw_context.add_init_script(path=js_override) # type: ignore
-
- agent = Agent(
- task="Go to weather.com",
- llm=model,
- browser=browser,
- browser_context=context,
- use_vision=True,
- controller=controller,
- )
-
- result = await agent.run()
- for out in result.model_outputs():
- print("-------------")
- print(out.current_state.memory)
- print(out.current_state.next_goal)
- print("-------------")
-
-
- agent = Agent(
- task="Search for berlin and tell me the temperature",
- llm=model,
- browser=browser,
- browser_context=context,
- use_vision=True,
- controller=controller,
- )
-
- result = await agent.run()
- # page = await agent.browser_context.get_current_page()
- print(result)
-
-
-asyncio.run(main())
-
diff --git a/webui/index.css b/webui/index.css
index 247e93026..95b355f2c 100644
--- a/webui/index.css
+++ b/webui/index.css
@@ -1806,6 +1806,24 @@ input:checked + .slider:before {
}
}
+/* Link styling */
+a {
+ color: inherit;
+ /* text-decoration: none; */
+}
+
+a:visited {
+ color: inherit;
+}
+
+a:hover {
+ color: inherit;
+}
+
+a:active {
+ color: inherit;
+}
+
/* Light mode class */
.light-mode {
--color-background: var(--color-background-light);
@@ -2069,6 +2087,11 @@ input:checked + .slider:before {
opacity: 0.6;
}
+.path-link{
+ margin-left: 0.1em;
+ margin-right: 0.1em;
+}
+
/* Alpine cloak to prevent FOUC */
[x-cloak] {
display: none !important;
diff --git a/webui/index.html b/webui/index.html
index 5a2a574f3..635b0c4d2 100644
--- a/webui/index.html
+++ b/webui/index.html
@@ -5,7 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Agent Zero</title>
- <link rel="icon" type="image/svg+xml" href="public/darkSymbol.svg">
+ <link rel="icon" type="image/svg+xml" href="public/favicon.svg">
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="css/toast.css">
<link rel="stylesheet" href="css/settings.css">
@@ -451,13 +451,13 @@
<template x-for="(section, sectionIndex) in settings.sections" :key="sectionIndex">
<div :id="'section' + (sectionIndex + 1)" class="section">
<div class="section-title" x-text="section.title"></div>
- <div class="section-description" x-text="section.description"></div>
+ <div class="section-description" x-html="section.description"></div>
<template x-for="(field, fieldIndex) in section.fields" :key="fieldIndex">
<div :class="{'field': true, 'field-full': field.type === 'textarea'}">
<div class="field-label">
<div class="field-title" x-text="field.title"></div>
- <div class="field-description" x-text="field.description"></div>
+ <div class="field-description" x-html="field.description"></div>
</div>
<div class="field-control">
@@ -767,7 +767,7 @@
class="dragdrop-overlay">
<img src="public/dragndrop.svg" alt="Drop files" class="dragdrop-icon">
<div class="dragdrop-text">Drop files to attach them to your message</div>
- <div class="dragdrop-subtext">Supported formats: Images (JPG, PNG, BMP) and Documents (PDF, TXT, CSV, HTML, JSON, MD)</div>
+ <div class="dragdrop-subtext"></div>
</div>
</body>
diff --git a/webui/index.js b/webui/index.js
index 47035fb0f..524ffbb3f 100644
--- a/webui/index.js
+++ b/webui/index.js
@@ -802,6 +802,7 @@ function toast(text, type = 'info', timeout = 5000) {
updateAndShowToast();
}
}
+window.toast = toast
function hideToast() {
const toast = document.getElementById('toast');
diff --git a/webui/js/file_browser.js b/webui/js/file_browser.js
index 21a842537..585aac0ff 100644
--- a/webui/js/file_browser.js
+++ b/webui/js/file_browser.js
@@ -1,252 +1,286 @@
const fileBrowserModalProxy = {
- isOpen: false,
- isLoading: false,
-
- browser: {
- title: "File Browser",
- currentPath: "",
- entries: [],
- parentPath: "",
- sortBy: "name",
- sortDirection: "asc"
- },
-
- // Initialize navigation history
- history: [],
-
- async openModal() {
- const modalEl = document.getElementById('fileBrowserModal');
- const modalAD = Alpine.$data(modalEl);
-
- modalAD.isOpen = true;
- modalAD.isLoading = true;
- modalAD.history = []; // reset history when opening modal
-
- // Initialize currentPath to root if it's empty
- if (!modalAD.browser.currentPath) {
- modalAD.browser.currentPath = "$WORK_DIR";
- }
-
- await modalAD.fetchFiles(modalAD.browser.currentPath);
- },
-
- isArchive(filename) {
- const archiveExts = ['zip', 'tar', 'gz', 'rar', '7z'];
- const ext = filename.split('.').pop().toLowerCase();
- return archiveExts.includes(ext);
- },
-
- async fetchFiles(path = "") {
- this.isLoading = true;
- try {
- const response = await fetch(`/get_work_dir_files?path=${encodeURIComponent(path)}`);
-
- if (response.ok) {
- const data = await response.json();
- this.browser.entries = data.data.entries;
- this.browser.currentPath = data.data.current_path;
- this.browser.parentPath = data.data.parent_path;
- } else {
- console.error('Error fetching files:', await response.text());
- this.browser.entries = [];
- }
- } catch (error) {
- window.toastFetchError("Error fetching files", error)
- this.browser.entries = [];
- } finally {
- this.isLoading = false;
- }
- },
-
- async navigateToFolder(path) {
- // Push current path to history before navigating
- if (this.browser.currentPath !== path) {
- this.history.push(this.browser.currentPath);
- }
- await this.fetchFiles(path);
- },
-
- async navigateUp() {
- if (this.browser.parentPath !== "") {
- // Push current path to history before navigating up
- this.history.push(this.browser.currentPath);
- await this.fetchFiles(this.browser.parentPath);
- }
- },
-
- sortFiles(entries) {
- return [...entries].sort((a, b) => {
- // Folders always come first
- if (a.is_dir !== b.is_dir) {
- return a.is_dir ? -1 : 1;
- }
-
- const direction = this.browser.sortDirection === 'asc' ? 1 : -1;
- switch (this.browser.sortBy) {
- case 'name':
- return direction * a.name.localeCompare(b.name);
- case 'size':
- return direction * (a.size - b.size);
- case 'date':
- return direction * (new Date(a.modified) - new Date(b.modified));
- default:
- return 0;
- }
- });
- },
-
- toggleSort(column) {
- if (this.browser.sortBy === column) {
- this.browser.sortDirection = this.browser.sortDirection === 'asc' ? 'desc' : 'asc';
- } else {
- this.browser.sortBy = column;
- this.browser.sortDirection = 'asc';
- }
- },
+ isOpen: false,
+ isLoading: false,
+
+ browser: {
+ title: "File Browser",
+ currentPath: "",
+ entries: [],
+ parentPath: "",
+ sortBy: "name",
+ sortDirection: "asc",
+ },
+
+ // Initialize navigation history
+ history: [],
+
+ async openModal(path) {
+ const modalEl = document.getElementById("fileBrowserModal");
+ const modalAD = Alpine.$data(modalEl);
+
+ modalAD.isOpen = true;
+ modalAD.isLoading = true;
+ modalAD.history = []; // reset history when opening modal
+
+ // Initialize currentPath to root if it's empty
+ if (path) modalAD.browser.currentPath = path;
+ else if (!modalAD.browser.currentPath)
+ modalAD.browser.currentPath = "$WORK_DIR";
+
+ await modalAD.fetchFiles(modalAD.browser.currentPath);
+ },
+
+ isArchive(filename) {
+ const archiveExts = ["zip", "tar", "gz", "rar", "7z"];
+ const ext = filename.split(".").pop().toLowerCase();
+ return archiveExts.includes(ext);
+ },
+
+ async fetchFiles(path = "") {
+ this.isLoading = true;
+ try {
+ const response = await fetch(
+ `/get_work_dir_files?path=${encodeURIComponent(path)}`
+ );
+
+ if (response.ok) {
+ const data = await response.json();
+ this.browser.entries = data.data.entries;
+ this.browser.currentPath = data.data.current_path;
+ this.browser.parentPath = data.data.parent_path;
+ } else {
+ console.error("Error fetching files:", await response.text());
+ this.browser.entries = [];
+ }
+ } catch (error) {
+ window.toastFetchError("Error fetching files", error);
+ this.browser.entries = [];
+ } finally {
+ this.isLoading = false;
+ }
+ },
- async deleteFile(file) {
- if (!confirm(`Are you sure you want to delete ${file.name}?`)) {
- return;
- }
+ async navigateToFolder(path) {
+ // Push current path to history before navigating
+ if (this.browser.currentPath !== path) {
+ this.history.push(this.browser.currentPath);
+ }
+ await this.fetchFiles(path);
+ },
+
+ async navigateUp() {
+ if (this.browser.parentPath !== "") {
+ // Push current path to history before navigating up
+ this.history.push(this.browser.currentPath);
+ await this.fetchFiles(this.browser.parentPath);
+ }
+ },
+
+ sortFiles(entries) {
+ return [...entries].sort((a, b) => {
+ // Folders always come first
+ if (a.is_dir !== b.is_dir) {
+ return a.is_dir ? -1 : 1;
+ }
+
+ const direction = this.browser.sortDirection === "asc" ? 1 : -1;
+ switch (this.browser.sortBy) {
+ case "name":
+ return direction * a.name.localeCompare(b.name);
+ case "size":
+ return direction * (a.size - b.size);
+ case "date":
+ return direction * (new Date(a.modified) - new Date(b.modified));
+ default:
+ return 0;
+ }
+ });
+ },
+
+ toggleSort(column) {
+ if (this.browser.sortBy === column) {
+ this.browser.sortDirection =
+ this.browser.sortDirection === "asc" ? "desc" : "asc";
+ } else {
+ this.browser.sortBy = column;
+ this.browser.sortDirection = "asc";
+ }
+ },
- try {
- const response = await fetch('/delete_work_dir_file', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- path: file.path,
- currentPath: this.browser.currentPath
- })
- });
-
- if (response.ok) {
- const data = await response.json();
- this.browser.entries = this.browser.entries.filter(entry => entry.path !== file.path);
- alert('File deleted successfully.');
- } else {
- alert(`Error deleting file: ${await response.text()}`);
- }
- } catch (error) {
- window.toastFetchError("Error deleting file", error)
- alert('Error deleting file');
- }
- },
+ async deleteFile(file) {
+ if (!confirm(`Are you sure you want to delete ${file.name}?`)) {
+ return;
+ }
- async handleFileUpload(event) {
- try {
- const files = event.target.files;
- if (!files.length) return;
-
- const formData = new FormData();
- formData.append('path', this.browser.currentPath);
-
- for (let i = 0; i < files.length; i++) {
- const ext = files[i].name.split('.').pop().toLowerCase();
- if (!['zip', 'tar', 'gz', 'rar', '7z'].includes(ext)) {
- if (files[i].size > 100 * 1024 * 1024) { // 100MB
- alert(`File ${files[i].name} exceeds the maximum allowed size of 100MB.`);
- continue;
- }
- }
- formData.append('files[]', files[i]);
- }
-
- // Proceed with upload after validation
- const response = await fetch('/upload_work_dir_files', {
- method: 'POST',
- body: formData
- });
-
- if (response.ok) {
- const data = await response.json();
- // Update the file list with new data
- this.browser.entries = data.data.entries.map(entry => ({
- ...entry,
- uploadStatus: data.failed.includes(entry.name) ? 'failed' : 'success'
- }));
- this.browser.currentPath = data.data.current_path;
- this.browser.parentPath = data.data.parent_path;
-
- // Show success message
- if (data.failed && data.failed.length > 0) {
- const failedFiles = data.failed.map(file => `${file.name}: ${file.error}`).join('\n');
- alert(`Some files failed to upload:\n${failedFiles}`);
- }
- } else {
-
- alert(data.message);
- }
-
- } catch (error) {
- window.toastFetchError("Error uploading files", error)
- alert('Error uploading files');
+ try {
+ const response = await fetch("/delete_work_dir_file", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ path: file.path,
+ currentPath: this.browser.currentPath,
+ }),
+ });
+
+ if (response.ok) {
+ const data = await response.json();
+ this.browser.entries = this.browser.entries.filter(
+ (entry) => entry.path !== file.path
+ );
+ alert("File deleted successfully.");
+ } else {
+ alert(`Error deleting file: ${await response.text()}`);
+ }
+ } catch (error) {
+ window.toastFetchError("Error deleting file", error);
+ alert("Error deleting file");
+ }
+ },
+
+ async handleFileUpload(event) {
+ try {
+ const files = event.target.files;
+ if (!files.length) return;
+
+ const formData = new FormData();
+ formData.append("path", this.browser.currentPath);
+
+ for (let i = 0; i < files.length; i++) {
+ const ext = files[i].name.split(".").pop().toLowerCase();
+ if (!["zip", "tar", "gz", "rar", "7z"].includes(ext)) {
+ if (files[i].size > 100 * 1024 * 1024) {
+ // 100MB
+ alert(
+ `File ${files[i].name} exceeds the maximum allowed size of 100MB.`
+ );
+ continue;
+ }
}
- },
-
- async downloadFile(file) {
-
- try {
-
- const downloadUrl = `/download_work_dir_file?path=${encodeURIComponent(file.path)}`;
-
- const response = await fetch(downloadUrl)
-
-
- if (!response.ok) {
- throw new Error('Network response was not ok');
- }
-
- const blob = await response.blob();
-
- const link = document.createElement('a');
- link.href = window.URL.createObjectURL(blob);
- link.download = file.name;
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- window.URL.revokeObjectURL(link.href);
-
- } catch (error) {
- window.toastFetchError("Error downloading file", error)
- alert('Error downloading file');
+ formData.append("files[]", files[i]);
+ }
+
+ // Proceed with upload after validation
+ const response = await fetch("/upload_work_dir_files", {
+ method: "POST",
+ body: formData,
+ });
+
+ if (response.ok) {
+ const data = await response.json();
+ // Update the file list with new data
+ this.browser.entries = data.data.entries.map((entry) => ({
+ ...entry,
+ uploadStatus: data.failed.includes(entry.name) ? "failed" : "success",
+ }));
+ this.browser.currentPath = data.data.current_path;
+ this.browser.parentPath = data.data.parent_path;
+
+ // Show success message
+ if (data.failed && data.failed.length > 0) {
+ const failedFiles = data.failed
+ .map((file) => `${file.name}: ${file.error}`)
+ .join("\n");
+ alert(`Some files failed to upload:\n${failedFiles}`);
}
- },
-
- // Helper Functions
- formatFileSize(size) {
- if (size === 0) return '0 Bytes';
- const k = 1024;
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
- const i = Math.floor(Math.log(size) / Math.log(k));
- return parseFloat((size / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
- },
-
- formatDate(dateString) {
- const options = { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' };
- return new Date(dateString).toLocaleDateString(undefined, options);
- },
-
- handleClose() {
- this.isOpen = false;
+ } else {
+ alert(data.message);
+ }
+ } catch (error) {
+ window.toastFetchError("Error uploading files", error);
+ alert("Error uploading files");
}
+ },
+
+ async downloadFile(file) {
+ try {
+ const downloadUrl = `/download_work_dir_file?path=${encodeURIComponent(
+ file.path
+ )}`;
+
+ const response = await fetch(downloadUrl);
+
+ if (!response.ok) {
+ throw new Error("Network response was not ok");
+ }
+
+ const blob = await response.blob();
+
+ const link = document.createElement("a");
+ link.href = window.URL.createObjectURL(blob);
+ link.download = file.name;
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ window.URL.revokeObjectURL(link.href);
+ } catch (error) {
+ window.toastFetchError("Error downloading file", error);
+ alert("Error downloading file");
+ }
+ },
+
+ // Helper Functions
+ formatFileSize(size) {
+ if (size === 0) return "0 Bytes";
+ const k = 1024;
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
+ const i = Math.floor(Math.log(size) / Math.log(k));
+ return parseFloat((size / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
+ },
+
+ formatDate(dateString) {
+ const options = {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ hour: "2-digit",
+ minute: "2-digit",
+ };
+ return new Date(dateString).toLocaleDateString(undefined, options);
+ },
+
+ handleClose() {
+ this.isOpen = false;
+ },
};
// Wait for Alpine to be ready
-document.addEventListener('alpine:init', () => {
- Alpine.data('fileBrowserModalProxy', () => ({
- init() {
- Object.assign(this, fileBrowserModalProxy);
- // Ensure immediate file fetch when modal opens
- this.$watch('isOpen', async (value) => {
- if (value) {
- await this.fetchFiles(this.browser.currentPath);
- }
- });
+document.addEventListener("alpine:init", () => {
+ Alpine.data("fileBrowserModalProxy", () => ({
+ init() {
+ Object.assign(this, fileBrowserModalProxy);
+ // Ensure immediate file fetch when modal opens
+ this.$watch("isOpen", async (value) => {
+ if (value) {
+ await this.fetchFiles(this.browser.currentPath);
}
- }));
+ });
+ },
+ }));
});
// Keep the global assignment for backward compatibility
window.fileBrowserModalProxy = fileBrowserModalProxy;
+
+openFileLink = async function (path) {
+ try {
+ const resp = await window.sendJsonData("/file_info", { path });
+ if (!resp.exists) {
+ window.toast("File does not exist.", "error");
+ return;
+ }
+
+ if (resp.is_dir) {
+ fileBrowserModalProxy.openModal(resp.abs_path);
+ } else {
+ fileBrowserModalProxy.downloadFile({
+ path: resp.abs_path,
+ name: resp.file_name,
+ });
+ }
+ } catch (e) {
+ window.toastFetchError("Error opening file", e);
+ }
+};
+window.openFileLink = openFileLink;
diff --git a/webui/js/messages.js b/webui/js/messages.js
index ef12d0d48..3b1eb7314 100644
--- a/webui/js/messages.js
+++ b/webui/js/messages.js
@@ -103,7 +103,7 @@ export function _drawMessage(
preElement.style.wordBreak = "break-word";
const spanElement = document.createElement("span");
- spanElement.innerHTML = escapeHTML(content);
+ spanElement.innerHTML = convertHTML(content);
// Add click handler for small screens
spanElement.addEventListener("click", () => {
@@ -117,9 +117,7 @@ export function _drawMessage(
// Render LaTeX math within the span
if (window.renderMathInElement && latex) {
renderMathInElement(spanElement, {
- delimiters: [
- { left: "$", right: "$", display: true }
- ],
+ delimiters: [{ left: "$", right: "$", display: true }],
throwOnError: false,
});
}
@@ -143,11 +141,10 @@ export function drawMessageDefault(
temp,
kvps = null
) {
- const messageContent = convertImageTags(content); // Convert image tags
_drawMessage(
messageContainer,
heading,
- messageContent,
+ content,
temp,
false,
kvps,
@@ -171,11 +168,10 @@ export function drawMessageAgent(
delete kvpsFlat["tool_args"];
}
- const messageContent = convertImageTags(content); // Convert image tags
_drawMessage(
messageContainer,
heading,
- messageContent,
+ content,
temp,
false,
kvpsFlat,
@@ -194,11 +190,10 @@ export function drawMessageResponse(
temp,
kvps = null
) {
- const messageContent = convertImageTags(content); // Convert image tags
_drawMessage(
messageContainer,
heading,
- messageContent,
+ content,
temp,
true,
null,
@@ -217,7 +212,6 @@ export function drawMessageDelegation(
temp,
kvps = null
) {
- const messageContent = convertImageTags(content); // Convert image tags
_drawMessage(
messageContainer,
heading,
@@ -251,10 +245,10 @@ export function drawMessageUser(
if (content && content.trim().length > 0) {
const textDiv = document.createElement("div");
textDiv.classList.add("message-text");
-
+
// Create a span for the content
const spanElement = document.createElement("span");
- spanElement.textContent = content;
+ spanElement.innerHTML = convertHTML(content);
textDiv.appendChild(spanElement);
// Add click handler
@@ -336,7 +330,6 @@ export function drawMessageTool(
temp,
kvps = null
) {
- const messageContent = convertImageTags(content); // Convert image tags
_drawMessage(
messageContainer,
heading,
@@ -358,8 +351,7 @@ export function drawMessageCodeExe(
temp,
kvps = null
) {
- const messageContent = convertImageTags(content); // Convert image tags
- _drawMessage(messageContainer, heading, messageContent, temp, true, null, [
+ _drawMessage(messageContainer, heading, content, temp, true, null, [
"message-ai",
"message-code-exe",
]);
@@ -374,11 +366,10 @@ export function drawMessageBrowser(
temp,
kvps = null
) {
- const messageContent = convertImageTags(content); // Convert image tags
_drawMessage(
messageContainer,
heading,
- messageContent,
+ content,
temp,
true,
kvps,
@@ -397,8 +388,7 @@ export function drawMessageAgentPlain(
temp,
kvps = null
) {
- const messageContent = convertImageTags(content); // Convert image tags
- _drawMessage(messageContainer, heading, messageContent, temp, false, kvps, [
+ _drawMessage(messageContainer, heading, content, temp, false, kvps, [
...classes,
]);
messageContainer.classList.add("center-container");
@@ -434,11 +424,10 @@ export function drawMessageUtil(
temp,
kvps = null
) {
- const messageContent = convertImageTags(content); // Convert image tags
_drawMessage(
messageContainer,
heading,
- messageContent,
+ content,
temp,
false,
kvps,
@@ -536,7 +525,7 @@ function drawKvps(container, kvps, latex) {
pre.classList.add("kvps-val");
// if (row.classList.contains("msg-thoughts")) {
const span = document.createElement("span");
- span.innerHTML = escapeHTML(value);
+ span.innerHTML = convertHTML(value);
pre.appendChild(span);
td.appendChild(pre);
addCopyButtonToElement(row);
@@ -548,9 +537,7 @@ function drawKvps(container, kvps, latex) {
if (window.renderMathInElement && latex) {
renderMathInElement(span, {
- delimiters: [
- { left: "$", right: "$", display: true }
- ],
+ delimiters: [{ left: "$", right: "$", display: true }],
throwOnError: false,
});
}
@@ -608,11 +595,16 @@ async function copyText(text, element) {
}
}
-function escapeHTML(str) {
- if (typeof str !== "string") {
- return str;
- }
+function convertHTML(str) {
+ if (typeof str !== "string") str = JSON.stringify(str, null, 2);
+
+ let result = escapeHTML(str);
+ result = convertPathsToLinks(result);
+ result = convertImageTags(result);
+ return result;
+}
+function escapeHTML(str) {
const escapeChars = {
"&": "&amp;",
"<": "&lt;",
@@ -622,3 +614,27 @@ function escapeHTML(str) {
};
return str.replace(/[&<>'"]/g, (char) => escapeChars[char]);
}
+
+function convertPathsToLinks(str) {
+ function generateLinks(match,...args) {
+ const parts = match.split("/");
+
+ if (!parts[0]) parts.shift();
+ let conc = "";
+ let html = "";
+ for (let part of parts) {
+ conc += "/" + part;
+ html += `/<a href="#" class="path-link" onclick="openFileLink('${conc}');">${part}</a>`;
+ }
+ return html;
+ }
+
+ const prefix = `(?:[ \`'"\\n]|&#39;|&quot;)`; // Use a non-capturing group for OR logic
+ const folder = `[a-zA-Z0-9_\\/\\.]`; // Characters allowed in folder names
+ const file = `[a-zA-Z0-9_\\/]`; // Characters allowed in file names
+ const suffix = `(?<!\\.)`
+
+ const regex = new RegExp(`(?<=${prefix})\\/${folder}*${file}${suffix}`, 'g');
+
+ return str.replace(regex, generateLinks);
+}
diff --git a/webui/js/settings.js b/webui/js/settings.js
index 9dbd2a3d9..4a192da3a 100644
--- a/webui/js/settings.js
+++ b/webui/js/settings.js
@@ -15,7 +15,7 @@ const settingsModalProxy = {
const settings = {
- "title": "Settings page",
+ "title": "Settings",
"buttons": [
{
"id": "save",
diff --git a/webui/public/favicon.svg b/webui/public/favicon.svg
new file mode 100644
index 000000000..95bb36465
--- /dev/null
+++ b/webui/public/favicon.svg
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg width="100%" height="100%" viewBox="0 0 960 960" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
+ <g transform="matrix(1.13341,0,0,1.13341,-36.9503,-43.0342)">
+ <path d="M878.621,178.762C878.621,101.597 815.973,38.95 738.808,38.95L173.394,38.95C96.23,38.95 33.582,101.597 33.582,178.762L33.582,744.176C33.582,821.34 96.23,883.988 173.394,883.988L738.808,883.988C815.973,883.988 878.621,821.34 878.621,744.176L878.621,178.762Z" style="fill:rgb(1,4,26);"/>
+ </g>
+ <g transform="matrix(1.03321,0,0,1.03321,-15.9385,-15.938)">
+ <path d="M717.77,788.27C638.99,652.89 559.87,516.92 479.15,378.22C399.29,516.59 320.58,652.95 241.99,789.12L120,789.12C239.91,581.87 479.49,170.89 479.49,170.89C479.49,170.89 720.12,580.92 840,788.27L717.77,788.27Z" style="fill:white;fill-rule:nonzero;"/>
+ </g>
+ <g transform="matrix(1.03321,0,0,1.03321,-15.9385,-15.938)">
+ <path d="M633.08,788.85L323.54,788.85C344.15,753.01 364.09,718.33 383.88,683.93L574.1,683.93C593.38,718.23 612.57,752.36 633.08,788.85Z" style="fill:white;fill-rule:nonzero;"/>
+ </g>
+</svg>
diff --git a/work_dir/.gitkeep b/work_dir/.gitkeep
deleted file mode 100644
index e69de29bb..000000000