Skip to content

Agent Zero AI framework

Macos bundler .pkg

frdela300abc67a99
diff --git a/.gitignore b/.gitignore
index d4a3d35ae..5d9433b52 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,7 +10,9 @@
.venv/
# ignore all folders under /bundle
-/bundle/*/
+bundle/*/
+# except some
+!bundle/mac_pkg_scripts
# Ignore all contents of the directory "work_dir"
work_dir/*
diff --git a/bundle/bundle.py b/bundle/bundle.py
index f58b69fed..f83866d6a 100644
--- a/bundle/bundle.py
+++ b/bundle/bundle.py
@@ -7,7 +7,8 @@ from pathlib import Path
import pathspec
import importlib
import importlib.metadata as metadata
-import py7zr # New import for 7z compression
+import py7zr
+import zipfile
def get_package_data_folder(package_name):
"""Return the package path if it contains data files."""
@@ -77,6 +78,38 @@ def cleanup_directories(bundle_name, build_dir, dist_dir, keep_dist=False):
if os.path.exists(spec_file):
os.remove(spec_file)
+def compress_internal_folder(dist_dir, exe_name):
+ """Compress the _internal folder using zipfile."""
+ try:
+ internal_path = Path(dist_dir) / exe_name / "_internal"
+ archive_path = internal_path.parent / "_internal.zip"
+
+ if not internal_path.exists():
+ print("Warning: _internal folder not found")
+ return False
+
+ # Remove existing archive if it exists
+ if archive_path.exists():
+ archive_path.unlink()
+
+ print(f"Compressing _internal folder to: {archive_path}")
+
+ # Create the zip archive
+ with zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_STORED) as archive:
+ for root, dirs, files in os.walk(internal_path):
+ for file in files:
+ file_path = Path(root) / file
+ archive.write(file_path, arcname=file_path.relative_to(internal_path.parent))
+
+ # Remove the original _internal folder
+ shutil.rmtree(internal_path)
+ print("_internal folder compressed and removed successfully")
+ return True
+
+ except Exception as e:
+ print(f"Error during _internal compression: {e}")
+ return False
+
def compress_dist_folder(dist_dir, exe_name):
"""Compress the dist folder using py7zr library."""
try:
@@ -91,8 +124,8 @@ def compress_dist_folder(dist_dir, exe_name):
print(f"Compressing dist folder to: {archive_path}")
# Create the 7z archive with maximum compression
- with py7zr.SevenZipFile(archive_path, 'w', filters=[{'id': py7zr.FILTER_LZMA2, 'preset': 9}]) as archive:
- archive.writeall(files_path, arcname=dist_dir.name)
+ with py7zr.SevenZipFile(archive_path, 'w', filters=[{'id': py7zr.FILTER_LZMA2, 'preset': 2}]) as archive:
+ archive.writeall(files_path, arcname=files_path.name)
print("Compression completed successfully")
return str(archive_path)
@@ -172,6 +205,9 @@ def build_executable(script_path, exe_name=None, compress=False):
print(f"Executable created at: '{dist_dir}/{exe_name}'")
print(f"Project files copied to: '{project_files_dir}'")
+ # Compress the _internal folder first
+ # compress_internal_folder(dist_dir, exe_name)
+
# Compress the dist folder if requested
if compress:
archive_path = compress_dist_folder(dist_dir, exe_name)
@@ -187,4 +223,4 @@ def build_executable(script_path, exe_name=None, compress=False):
print(f"Error: {e}")
if __name__ == "__main__":
- build_executable("../run_bundle.py", "agent-zero", compress=True)
\ No newline at end of file
+ build_executable("../run_bundle.py", "agent-zero", compress=False)
\ No newline at end of file
diff --git a/bundle/mac_pkg_scripts/postinstall b/bundle/mac_pkg_scripts/postinstall
new file mode 100755
index 000000000..09d53b312
--- /dev/null
+++ b/bundle/mac_pkg_scripts/postinstall
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Prompt the user to select a folder using an AppleScript dialog
+TARGET_FOLDER=$(osascript <<EOT
+ tell application "System Events"
+ activate
+ set chosenFolder to choose folder with prompt "Please select a folder for the installation:"
+ return POSIX path of chosenFolder
+ end tell
+EOT
+)
+
+# Check if the user selected a folder
+if [ -n "$TARGET_FOLDER" ]; then
+ echo "Installing files to $TARGET_FOLDER"
+
+ # Move the installed files to the selected folder
+ mv /tmp/agent-zero/* "$TARGET_FOLDER"
+
+ # Check if the move operation was successful
+ if [ $? -eq 0 ]; then
+ echo "Files successfully moved to $TARGET_FOLDER"
+
+ # Remove the /tmp/agent-zero folder
+ rm -rf /tmp/agent-zero
+ echo "/tmp/agent-zero folder removed."
+ else
+ echo "Error moving files. Exiting."
+ exit 1
+ fi
+else
+ echo "No folder selected. Exiting installation."
+ exit 1
+fi
+
+exit 0
\ No newline at end of file
diff --git a/bundle/macos_bundle.sh b/bundle/macos_bundle.sh
index 3c1432751..fde05c6a1 100755
--- a/bundle/macos_bundle.sh
+++ b/bundle/macos_bundle.sh
@@ -38,8 +38,8 @@ if [ -d "agent-zero" ]; then
fi
# 4. Clone the repository (development branch)
-echo "Cloning the repository (testing branch)..."
-git clone --branch testing https://github.com/frdel/agent-zero agent-zero
+echo "Cloning the repository (development branch)..."
+git clone --branch development https://github.com/frdel/agent-zero agent-zero
if [ $? -ne 0 ]; then
echo "Error cloning the repository."
exit 1
@@ -67,18 +67,30 @@ if [ $? -ne 0 ]; then
exit 1
fi
-# 9. Move the generated 7z file to the script directory and remove agent-zero folder
-BUNDLE_FILE="bundle/dist/agent-zero.7z"
-if [ -f "$BUNDLE_FILE" ]; then
- SCRIPT_DIR=$(dirname "$0")
- echo "Moving $BUNDLE_FILE to $SCRIPT_DIR..."
- mv "$BUNDLE_FILE" "$SCRIPT_DIR"
- if [ $? -ne 0 ]; then
- echo "Error moving $BUNDLE_FILE to $SCRIPT_DIR."
- exit 1
- fi
-else
- echo "Error: $BUNDLE_FILE not found."
+# # 9. Move the generated 7z file to the script directory and remove agent-zero folder
+# BUNDLE_FILE="bundle/dist/agent-zero.7z"
+# if [ -f "$BUNDLE_FILE" ]; then
+# SCRIPT_DIR=$(dirname "$0")
+# echo "Moving $BUNDLE_FILE to $SCRIPT_DIR..."
+# mv "$BUNDLE_FILE" "$SCRIPT_DIR"
+# if [ $? -ne 0 ]; then
+# echo "Error moving $BUNDLE_FILE to $SCRIPT_DIR."
+# exit 1
+# fi
+# else
+# echo "Error: $BUNDLE_FILE not found."
+# exit 1
+# fi
+
+# 9. Create macOS package
+echo "Creating macOS package..."
+pkgbuild --root ./dist/agent-zero \
+ --identifier frdel.agent-zero \
+ --install-location /tmp/agent-zero \
+ --scripts ./mac_pkg_scripts \
+ agent-zero-preinstalled-mac-m1.pkg
+if [ $? -ne 0 ]; then
+ echo "Error creating macOS package."
exit 1
fi
diff --git a/run_bundle.py b/run_bundle.py
index 1292ffacb..97a6e9e14 100644
--- a/run_bundle.py
+++ b/run_bundle.py
@@ -1,64 +1,78 @@
-print("\nImporting dependencies, this may take a while...\n")
+def post_install():
+ # if "_internal.zip" exists, unzip and remove
+ import os
+ if os.path.exists("_internal.zip"):
+ import zipfile
+ print("\nDecompressing internal binaries...\n")
+ with zipfile.ZipFile("_internal.zip", 'r') as zip_ref:
+ zip_ref.extractall("_internal")
+ os.remove("_internal.zip")
+
+def run_bundle():
+ print("\nImporting dependencies, this may take a while...\n")
+
+ # dependencies to bundle
+ import ansio
+ import bs4
+ import docker
+ import duckduckgo_search
+ import faiss
+ from flask import Flask
+ import flask_basicauth
+ import inputimeout
+ import langchain.embeddings
+ import langchain_anthropic
+ import langchain_community
+ import langchain_google_genai
+ import langchain_groq
+ import langchain_huggingface
+ import langchain_mistralai
+ import langchain_ollama
+ import langchain_openai
+ import lxml_html_clean
+ import emoji
+ from emoji import unicode_codes
+ import markdown
+ import newspaper
+ import paramiko
+ import pypdf
+ import dotenv
+ import sentence_transformers
+ from tiktoken import model, registry
+ from tiktoken_ext import openai_public
+ import unstructured
+ import unstructured_client
+ import webcolors
-# dependencies to bundle
-import ansio
-import bs4
-import docker
-import duckduckgo_search
-import faiss
-from flask import Flask
-import flask_basicauth
-import inputimeout
-import langchain.embeddings
-import langchain_anthropic
-import langchain_community
-import langchain_google_genai
-import langchain_groq
-import langchain_huggingface
-import langchain_mistralai
-import langchain_ollama
-import langchain_openai
-import lxml_html_clean
-import emoji
-from emoji import unicode_codes
-import markdown
-import newspaper
-import paramiko
-import pypdf
-import dotenv
-import sentence_transformers
-from tiktoken import model, registry
-from tiktoken_ext import openai_public
-import unstructured
-import unstructured_client
-import webcolors
+ # but do not bundle project files, these are to be imported at runtime
-# but do not bundle project files, these are to be imported at runtime
+ import sys
+ import os
+ import importlib.util
+ # Add the project_files directory to the Python path
+ project_files_dir = os.path.join(os.path.dirname(sys.executable), 'agent-zero-files')
+ sys.path.insert(0, project_files_dir)
-import sys
-import os
-import importlib.util
+ # Dynamically load the 'run_ui' module
+ module_name = "run_ui"
+ module_path = os.path.join(project_files_dir, f"{module_name}.py")
-# Add the project_files directory to the Python path
-project_files_dir = os.path.join(os.path.dirname(sys.executable), 'agent-zero-files')
-sys.path.insert(0, project_files_dir)
+ # Load the module at runtime
+ spec = importlib.util.spec_from_file_location(module_name, module_path)
+ if spec and spec.loader:
+ run_ui = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(run_ui)
-# Dynamically load the 'run_ui' module
-module_name = "run_ui"
-module_path = os.path.join(project_files_dir, f"{module_name}.py")
+ # Now you can call the function in the dynamically imported module
+ run_ui.run() # Call the 'run' function from run_ui
+ else:
+ raise Exception(f"Could not load {module_name} from {module_path}")
-# Load the module at runtime
-spec = importlib.util.spec_from_file_location(module_name, module_path)
-if spec and spec.loader:
- run_ui = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(run_ui)
- # Now you can call the function in the dynamically imported module
- run_ui.run() # Call the 'run' function from run_ui
-else:
- raise Exception(f"Could not load {module_name} from {module_path}")
\ No newline at end of file
+# post_install()
+run_bundle()
\ No newline at end of file