Agent Zero AI framework
git+docker improvements
frdel020c16ef8636
diff --git a/docker/run/Dockerfile b/docker/run/Dockerfileindex 0ea5db3d0..73bea5c89 100644--- a/docker/run/Dockerfile+++ b/docker/run/Dockerfile@@ -1,12 +1,14 @@# Use the latest slim version of DebianFROM debian:bookworm-slim+# Check if the argument is provided, else throw an error+ARG BRANCH+RUN if [ -z "$BRANCH" ]; then echo "ERROR: BRANCH is not set!" >&2; exit 1; fi+# Update and install necessary packagesRUN apt-get update && apt-get install -y \python3 \python3-pip \- python3-dev \- python3-babel \python3-venv \nodejs \npm \@@ -15,13 +17,8 @@ RUN apt-get update && apt-get install -y \curl \wget \git \- build-essential \ffmpeg-# Cleanup package list-RUN rm -rf /var/lib/apt/lists/*-RUN apt-get clean-# Set up SSHRUN mkdir /var/run/sshd && \echo 'root:toor' | chpasswd && \@@ -33,12 +30,16 @@ COPY ./fs/ /# install additional softwareRUN bash /ins/install_searxng.sh-# install a0 with caching-RUN bash /ins/install_A0.sh+# install A0+RUN bash /ins/install_A0.sh $BRANCH-# cleanup repo and install a0 without caching, this speeds up builds-ARG CACHE_DATE=unknown-RUN echo "cache buster $CACHE_DATE" && bash /ins/install_A02.sh+# cleanup repo and install A0 without caching, this speeds up builds+ARG CACHE_DATE=none+RUN echo "cache buster $CACHE_DATE" && bash /ins/install_A02.sh $BRANCH++# Cleanup package list+RUN rm -rf /var/lib/apt/lists/*+RUN apt-get clean# Expose ports# EXPOSE 22diff --git a/docker/run/build.txt b/docker/run/build.txtindex 94c8817b2..46627cabc 100644--- a/docker/run/build.txt+++ b/docker/run/build.txt@@ -1,7 +1,18 @@# local image with smart cache-docker build -t agent-zero-run:local --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) .+docker build -t agent-zero-run:local --build-arg BRANCH=development --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) .++# local image without cache+docker build -t agent-zero-run:local --build-arg BRANCH=development --no-cache .++# dockerhub push:-# dockerhub push with and without cachingdocker login-docker buildx build --platform linux/amd64,linux/arm64 -t frdel/agent-zero-run:testing --push --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) .-docker buildx build --platform linux/amd64,linux/arm64 -t frdel/agent-zero-run:testing --push --no-cache .\ No newline at end of file++# development:+docker buildx build --build-arg BRANCH=development -t frdel/agent-zero-run:development --platform linux/amd64,linux/arm64 --push --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) .++# testing:+docker buildx build --build-arg BRANCH=testing -t frdel/agent-zero-run:testing --platform linux/amd64,linux/arm64 --push --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) .++# main+docker buildx build --build-arg BRANCH=testing -t frdel/agent-zero-run:testing --platform linux/amd64,linux/arm64 --push --no-cache .diff --git a/docker/run/fs/exe/node_eval.js b/docker/run/fs/exe/node_eval.jsindex 18bb773c1..aab45b11e 100644--- a/docker/run/fs/exe/node_eval.js+++ b/docker/run/fs/exe/node_eval.js@@ -2,11 +2,29 @@const vm = require('vm');const path = require('path');+const Module = require('module');-// Create a comprehensive context with all important global objects+// Enhance `require` to search CWD first, then globally+function customRequire(moduleName) {+ try {+ // Try resolving from CWD's node_modules+ const cwdPath = path.resolve(process.cwd(), 'node_modules', moduleName);+ return require(cwdPath);+ } catch (cwdErr) {+ try {+ // Try resolving as a global module+ return require(moduleName);+ } catch (globalErr) {+ console.error(`Cannot find module: ${moduleName}`);+ throw globalErr;+ }+ }+}++// Create the VM contextconst context = vm.createContext({...global,- require: require,+ require: customRequire, // Use the custom require__filename: path.join(process.cwd(), 'eval.js'),__dirname: process.cwd(),module: { exports: {} },@@ -19,10 +37,12 @@ const context = vm.createContext({setImmediate: setImmediate,clearTimeout: clearTimeout,clearInterval: clearInterval,- clearImmediate: clearImmediate+ clearImmediate: clearImmediate,});+// Retrieve the code from the command-line argumentconst code = process.argv[2];+const wrappedCode = `(async function() {try {@@ -38,4 +58,4 @@ vm.runInContext(wrappedCode, context, {filename: 'eval.js',lineOffset: -2,columnOffset: 0,-}).catch(console.error);\ No newline at end of file+}).catch(console.error);diff --git a/docker/run/fs/ins/install_A0.sh b/docker/run/fs/ins/install_A0.shindex 931cd7511..cd96a8416 100644--- a/docker/run/fs/ins/install_A0.sh+++ b/docker/run/fs/ins/install_A0.sh@@ -1,9 +1,16 @@#!/bin/bash-BRANCH="development"+# branch from parameter+if [ -z "$1" ]; then+ echo "Error: Branch parameter is empty. Please provide a valid branch name."+ exit 1+fi+BRANCH="$1"+git clone -b "$BRANCH" "https://github.com/frdel/agent-zero" "/git/agent-zero"+# Create and activate Python virtual environmentpython3 -m venv /opt/venvsource /opt/venv/bin/activatediff --git a/docker/run/fs/ins/install_A02.sh b/docker/run/fs/ins/install_A02.shindex 5118ad5fb..9dab41592 100644--- a/docker/run/fs/ins/install_A02.sh+++ b/docker/run/fs/ins/install_A02.sh@@ -4,7 +4,7 @@rm -rf /git/agent-zero# run the original install script again-bash /ins/install_A0.sh+bash /ins/install_A0.sh "$@"# remove python packages cachesource /opt/venv/bin/activatediff --git a/docker/run/fs/ins/install_searxng2.sh b/docker/run/fs/ins/install_searxng2.shindex a75ffc5fe..33fdf0c10 100644--- a/docker/run/fs/ins/install_searxng2.sh+++ b/docker/run/fs/ins/install_searxng2.sh@@ -28,3 +28,6 @@ pip install -U pyyaml# jump to SearXNG's working tree and install SearXNG into virtualenvcd "/usr/local/searxng/searxng-src"pip install --use-pep517 --no-build-isolation -e .++# cleanup cache+pip cache purge\ No newline at end of filediff --git a/python/helpers/git.py b/python/helpers/git.pynew file mode 100644index 000000000..21dba1fac--- /dev/null+++ b/python/helpers/git.py@@ -0,0 +1,48 @@+from git import Repo+from datetime import datetime+import os+from python.helpers import files++def get_git_info():+ # Get the current working directory (assuming the repo is in the same folder as the script)+ repo_path = files.get_base_dir()++ # Open the Git repository+ repo = Repo(repo_path)++ # Ensure the repository is not bare+ if repo.bare:+ raise ValueError(f"Repository at {repo_path} is bare and cannot be used.")++ # Get the current branch name+ branch = repo.active_branch.name if repo.head.is_detached is False else ""++ # Get the latest commit hash+ commit_hash = repo.head.commit.hexsha++ # Get the commit date (ISO 8601 format)+ commit_time = datetime.fromtimestamp(repo.head.commit.committed_date).strftime('%y-%m-%d %H:%M')++ # Get the latest tag description (if available)+ short_tag = ""+ try:+ tag = repo.git.describe(tags=True)+ tag_split = tag.split('-')+ if len(tag_split) >= 3:+ short_tag = "-".join(tag_split[:-1])+ except:+ tag = ""++ version = branch[0].upper() + " " + ( short_tag or commit_hash[:7] )++ # Create the dictionary with collected information+ git_info = {+ "branch": branch,+ "commit_hash": commit_hash,+ "commit_time": commit_time,+ "tag": tag,+ "short_tag": short_tag,+ "version": version+ }++ return git_info\ No newline at end of filediff --git a/python/helpers/persist_chat.py b/python/helpers/persist_chat.pyindex 76d43b5eb..3939337a7 100644--- a/python/helpers/persist_chat.py+++ b/python/helpers/persist_chat.py@@ -165,7 +165,7 @@ def _deserialize_history(history: list[dict[str, Any]]):def _deserialize_log(data: dict[str, Any]) -> "Log":log = Log()log.guid = data.get("guid", str(uuid.uuid4()))- log.progress = data.get("progress", "")+ log.progress = "" #data.get("progress", "")log.progress_no = data.get("progress_no", 0)# Deserialize the list of LogItem objectsdiff --git a/requirements.txt b/requirements.txtindex efba293af..a3633c1b6 100644--- a/requirements.txt+++ b/requirements.txt@@ -5,6 +5,7 @@ duckduckgo-search==6.1.12faiss-cpu==1.8.0.post1flask[async]==3.0.3flask-basicauth==0.2.0+GitPython==3.1.43inputimeout==1.0.4langchain-anthropic==0.1.19langchain-community==0.2.7diff --git a/run_ui.py b/run_ui.pyindex fd65ae964..4843af478 100644--- a/run_ui.py+++ b/run_ui.py@@ -8,7 +8,7 @@ from flask import Flask, request, jsonify, Responsefrom flask_basicauth import BasicAuthfrom agent import AgentContextfrom initialize import initialize-from python.helpers import files+from python.helpers import files, gitfrom python.helpers.files import get_abs_pathfrom python.helpers.print_style import PrintStylefrom python.helpers.dotenv import load_dotenv@@ -48,12 +48,9 @@ def requires_auth(f):async def decorated(*args, **kwargs):user = dotenv.get_dotenv_value("AUTH_LOGIN")password = dotenv.get_dotenv_value("AUTH_PASSWORD")- if user and password:+ if user and password:auth = request.authorization- if not auth or not (- auth.username == user- and auth.password == password- ):+ if not auth or not (auth.username == user and auth.password == password):return Response("Could not verify your access level for that URL.\n""You have to login with proper credentials",@@ -87,6 +84,8 @@ async def upload_file():ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "txt", "pdf", "csv", "html", "json", "md"}++def allowed_file(filename):return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS@@ -131,17 +130,20 @@ async def browse_work_dir():)-# handle default address, show demo html page from ./test_form.html+# handle default address, load index@app.route("/", methods=["GET"])@requires_auth-async def test_form():- return Path(get_abs_path("./webui/index.html")).read_text()+async def serve_index():+ gitinfo = git.get_git_info()+ return files.read_file("./webui/index.html", version_no=gitinfo["version"])# simple health check, just return OK to see the server is running@app.route("/ok", methods=["GET", "POST"])async def health_check():- return "OK"+ gitinfo = git.get_git_info()+ return jsonify({"ok": True, "gitinfo": gitinfo})+# send message to agent (async UI)@app.route("/msg", methods=["POST"])@@ -530,7 +532,7 @@ async def transcribe():"message": str(e),}PrintStyle.error(str(e))-+# respond with jsonreturn jsonify(response)@@ -550,7 +552,7 @@ async def handle_rfc():"ok": True,"result": result,}-+return jsonify(response)except Exception as e:response = {diff --git a/webui/index.html b/webui/index.htmlindex 70ec50c1d..9ca4e3a1b 100644--- a/webui/index.html+++ b/webui/index.html@@ -159,7 +159,7 @@</div><!-- Version Info --><div class="version-info">- <span id="a0version">Agent Zero 0.7.2<br>built on 2024-11-04</span>+ <span id="a0version">Version {{version_no}} {{version_time}}</span></div></div></div>