removed bundles, tests
frdel committed
Nov 19, 2024 at 21:21 UTC
040de30ef2863c57a335c1c408baaf338c8bdf7b
10 files changed
-781
bundle/bundle.py
deleted
-226
@@ -1,226 +0,0 @@
1
-import os
2
-import subprocess
3
-import sys
4
-import site
5
-import shutil
6
-from pathlib import Path
7
-import pathspec
8
-import importlib
9
-import importlib.metadata as metadata
10
-import py7zr
11
-import zipfile
12
-
13
-def get_package_data_folder(package_name):
14
- """Return the package path if it contains data files."""
15
- try:
16
- package = importlib.import_module(package_name)
17
- package_path = os.path.dirname(package.__file__) # type: ignore
18
- if not package_path.endswith("site-packages"):
19
- has_data = any(
20
- file.endswith((".json", ".txt", ".csv", ".yml", ".yaml"))
21
- for root, dirs, files in os.walk(package_path)
22
- for file in files
23
- )
24
- if has_data:
25
- return package_path
26
- except ImportError:
27
- print(f"Warning: Unable to import {package_name}. Skipping data folder discovery for this package.")
28
- return None
29
-
30
-def get_add_data_args():
31
- """Return an array of --add-data arguments for PyInstaller, one per package."""
32
- add_data_args = []
33
- installed_packages = [dist.metadata["Name"] for dist in metadata.distributions()]
34
- for package in installed_packages:
35
- package_data_folder = get_package_data_folder(package)
36
- if package_data_folder:
37
- add_data_args.append(f"--add-data={package_data_folder}{os.pathsep}{package}")
38
- return add_data_args
39
-
40
-def get_site_packages_path():
41
- """Get the path to the site-packages directory of the current environment."""
42
- if hasattr(site, "getsitepackages"):
43
- paths = site.getsitepackages()
44
- else:
45
- paths = [site.getusersitepackages()]
46
- if paths:
47
- return paths[0]
48
- else:
49
- raise RuntimeError("Couldn't determine the site-packages path.")
50
-
51
-def parse_gitignore(gitignore_path):
52
- """Parse .gitignore file and return a PathSpec object."""
53
- if not os.path.exists(gitignore_path):
54
- return pathspec.PathSpec.from_lines("gitwildmatch", [])
55
- with open(gitignore_path, "r") as f:
56
- return pathspec.PathSpec.from_lines("gitwildmatch", f)
57
-
58
-def copy_project_files(src_dir, dst_dir, spec):
59
- """Copy project files respecting .gitignore rules using pathspec."""
60
- src_path = Path(src_dir)
61
- for root, dirs, files in os.walk(src_dir):
62
- rel_root = Path(root).relative_to(src_path)
63
- for file in files:
64
- rel_path = rel_root / file
65
- if not spec.match_file(str(rel_path)):
66
- src_file = src_path / rel_path
67
- dst_file = Path(dst_dir) / rel_path
68
- dst_file.parent.mkdir(parents=True, exist_ok=True)
69
- shutil.copy2(src_file, dst_file)
70
-
71
-def cleanup_directories(bundle_name, build_dir, dist_dir, keep_dist=False):
72
- """Remove build directory and .spec file. Optionally keep dist."""
73
- if not keep_dist and os.path.exists(dist_dir):
74
- shutil.rmtree(dist_dir)
75
- if os.path.exists(build_dir):
76
- shutil.rmtree(build_dir)
77
- spec_file = f"{bundle_name}.spec"
78
- if os.path.exists(spec_file):
79
- os.remove(spec_file)
80
-
81
-def compress_internal_folder(dist_dir, exe_name):
82
- """Compress the _internal folder using zipfile."""
83
- try:
84
- internal_path = Path(dist_dir) / exe_name / "_internal"
85
- archive_path = internal_path.parent / "_internal.zip"
86
-
87
- if not internal_path.exists():
88
- print("Warning: _internal folder not found")
89
- return False
90
-
91
- # Remove existing archive if it exists
92
- if archive_path.exists():
93
- archive_path.unlink()
94
-
95
- print(f"Compressing _internal folder to: {archive_path}")
96
-
97
- # Create the zip archive
98
- with zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_STORED) as archive:
99
- for root, dirs, files in os.walk(internal_path):
100
- for file in files:
101
- file_path = Path(root) / file
102
- archive.write(file_path, arcname=file_path.relative_to(internal_path.parent))
103
-
104
- # Remove the original _internal folder
105
- shutil.rmtree(internal_path)
106
- print("_internal folder compressed and removed successfully")
107
- return True
108
-
109
- except Exception as e:
110
- print(f"Error during _internal compression: {e}")
111
- return False
112
-
113
-def compress_dist_folder(dist_dir, exe_name):
114
- """Compress the dist folder using py7zr library."""
115
- try:
116
- archive_path = Path(dist_dir) / f"{exe_name}.7z"
117
- files_path = Path(dist_dir) / exe_name
118
-
119
-
120
- # Remove existing archive if it exists
121
- if archive_path.exists():
122
- archive_path.unlink()
123
-
124
- print(f"Compressing dist folder to: {archive_path}")
125
-
126
- # Create the 7z archive with maximum compression
127
- with py7zr.SevenZipFile(archive_path, 'w', filters=[{'id': py7zr.FILTER_LZMA2, 'preset': 2}]) as archive:
128
- archive.writeall(files_path, arcname=files_path.name)
129
-
130
- print("Compression completed successfully")
131
- return str(archive_path)
132
-
133
- except Exception as e:
134
- print(f"Error during compression: {e}")
135
- return None
136
-
137
-def build_executable(script_path, exe_name=None, compress=False):
138
- """Run PyInstaller with the correct site-packages path, clean, and additional data."""
139
- try:
140
- # Resolve the absolute path to the script, relative to the current file location (__file__)
141
- bundling_script_dir = Path(__file__).parent.resolve()
142
- script_path = (bundling_script_dir / script_path).resolve()
143
- script_name = script_path.name # run_bundle.py
144
- project_dir = script_path.parent # Folder containing run_bundle.py
145
-
146
- # Define build and dist paths under the /bundle directory (bundling_script_dir)
147
- build_dir = bundling_script_dir / "build"
148
- dist_dir = bundling_script_dir / "dist"
149
-
150
- # Initial cleanup
151
- cleanup_directories(exe_name, build_dir, dist_dir, keep_dist=False)
152
-
153
- site_packages_path = get_site_packages_path()
154
- print(f"Using site-packages path: {site_packages_path}")
155
- print(f"Bundling project from: {project_dir}")
156
- print(f"Build directory: {build_dir}")
157
- print(f"Dist directory: {dist_dir}")
158
-
159
- # Parse .gitignore in the project directory
160
- gitignore_path = project_dir / ".gitignore"
161
- spec = parse_gitignore(gitignore_path)
162
-
163
- # Create a temporary directory for project files inside build
164
- temp_project_dir = build_dir / "temp_project"
165
- os.makedirs(temp_project_dir, exist_ok=True)
166
-
167
- # Copy project files respecting .gitignore
168
- copy_project_files(project_dir, temp_project_dir, spec)
169
-
170
- # Construct the PyInstaller command
171
- pyinstaller_command = [
172
- "pyinstaller",
173
- "--clean",
174
- "--noconfirm",
175
- "--onedir",
176
- f"--paths={site_packages_path}",
177
- f"--workpath={build_dir}", # Specify the build directory under /bundle
178
- f"--distpath={dist_dir}", # Specify the dist directory under /bundle
179
- ]
180
-
181
- # Add data arguments
182
- pyinstaller_command.extend(get_add_data_args())
183
-
184
- # Add custom name if provided
185
- if exe_name:
186
- pyinstaller_command.append(f"--name={exe_name}")
187
- else:
188
- exe_name = os.path.splitext(script_name)[0]
189
-
190
- # Add the script path (in the temp_project directory)
191
- pyinstaller_command.append(os.path.join(temp_project_dir, script_name))
192
-
193
- # Run the PyInstaller command
194
- print("Running PyInstaller...")
195
- subprocess.run(pyinstaller_command, check=True)
196
-
197
- # Post-processing: Create a folder for project files inside dist/
198
- project_files_dir = dist_dir / exe_name / f"{exe_name}-files"
199
- os.makedirs(project_files_dir, exist_ok=True)
200
-
201
- # Copy project files to the dist folder
202
- copy_project_files(temp_project_dir, project_files_dir, spec)
203
-
204
- print(f"PyInstaller finished successfully.")
205
- print(f"Executable created at: '{dist_dir}/{exe_name}'")
206
- print(f"Project files copied to: '{project_files_dir}'")
207
-
208
- # Compress the _internal folder first
209
- # compress_internal_folder(dist_dir, exe_name)
210
-
211
- # Compress the dist folder if requested
212
- if compress:
213
- archive_path = compress_dist_folder(dist_dir, exe_name)
214
- if archive_path:
215
- print(f"Created compressed archive at: {archive_path}")
216
-
217
- # Final cleanup (keeping dist folder)
218
- cleanup_directories(exe_name, build_dir, dist_dir, keep_dist=True)
219
-
220
- except subprocess.CalledProcessError as e:
221
- print(f"Error during PyInstaller execution: {e}")
222
- except Exception as e:
223
- print(f"Error: {e}")
224
-
225
-if __name__ == "__main__":
226
- build_executable("../run_bundle.py", "agent-zero", compress=False)
\ No newline at end of file
bundle/mac_pkg_scripts/postinstall
deleted
-39
@@ -1,39 +0,0 @@
1
-#!/bin/bash
2
-
3
-# Define the source path in the user's Library/Application Support
4
-SOURCE_PATH="$HOME/Library/Application Support/agent-zero/install"
5
-
6
-# Prompt the user to select a folder using an AppleScript dialog
7
-TARGET_FOLDER=$(osascript <<EOT
8
- tell application "System Events"
9
- activate
10
- set chosenFolder to choose folder with prompt "Please select a folder for the installation:"
11
- return POSIX path of chosenFolder
12
- end tell
13
-EOT
14
-)
15
-
16
-# Check if the user selected a folder
17
-if [ -n "$TARGET_FOLDER" ]; then
18
- echo "Installing files to $TARGET_FOLDER"
19
-
20
- # Move the installed files to the selected folder
21
- mv "$SOURCE_PATH"/* "$TARGET_FOLDER"
22
-
23
- # Check if the move operation was successful
24
- if [ $? -eq 0 ]; then
25
- echo "Files successfully moved to $TARGET_FOLDER"
26
-
27
- # Remove the agent-zero folder in Library/Application Support
28
- rm -rf "$SOURCE_PATH"
29
- echo "$SOURCE_PATH folder removed."
30
- else
31
- echo "Error moving files. Exiting."
32
- exit 1
33
- fi
34
-else
35
- echo "No folder selected. Exiting installation."
36
- exit 1
37
-fi
38
-
39
-exit 0
bundle/macos_bundle.sh
deleted
-114
@@ -1,114 +0,0 @@
1
-#!/bin/bash
2
-
3
-set -e
4
-
5
-# 1. Remove conda environment if it exists
6
-echo "Removing conda environment 'az-bundle' if it exists..."
7
-conda env remove -n az-bundle -y || echo "Conda environment 'az-bundle' does not exist."
8
-
9
-# 2. Create new environment with Python 3.12 and activate it
10
-echo "Creating new conda environment 'az-bundle' with Python 3.12..."
11
-conda create -n az-bundle python=3.12 -y
12
-if [ $? -ne 0 ]; then
13
- echo "Error creating conda environment."
14
- exit 1
15
-fi
16
-
17
-echo "Activating conda environment 'az-bundle'..."
18
-source $(conda info --base)/etc/profile.d/conda.sh
19
-conda activate az-bundle
20
-if [ $? -ne 0 ]; then
21
- echo "Error activating conda environment."
22
- exit 1
23
-fi
24
-
25
-# 3. Purge folder ./agent-zero-git (retry mechanism in case of failure)
26
-if [ -d "agent-zero-git" ]; then
27
- echo "Deleting agent-zero-git folder..."
28
- rm -rf agent-zero-git
29
- if [ -d "agent-zero-git" ]; then
30
- echo "Error: Unable to delete agent-zero-git folder, retrying..."
31
- sleep 3
32
- rm -rf agent-zero-git
33
- fi
34
- if [ -d "agent-zero-git" ]; then
35
- echo "Error: Failed to purge agent-zero-git folder after retry."
36
- exit 1
37
- fi
38
-fi
39
-
40
-# 4. Clone the repository (testing branch)
41
-echo "Cloning the repository (testing branch)..."
42
-git clone --branch testing https://github.com/frdel/agent-zero agent-zero-git
43
-if [ $? -ne 0 ]; then
44
- echo "Error cloning the repository."
45
- exit 1
46
-fi
47
-
48
-# 5. Change directory to agent-zero
49
-# cd agent-zero || { echo "Error changing directory"; exit 1; }
50
-
51
-# 6. Install requirements
52
-echo "Installing requirements from requirements.txt..."
53
-pip install -r ./agent-zero-git/requirements.txt
54
-if [ $? -ne 0 ]; then
55
- echo "Error installing requirements."
56
- exit 1
57
-fi
58
-
59
-pip install -r ./agent-zero-git/bundle/requirements.txt
60
-if [ $? -ne 0 ]; then
61
- echo "Error installing requirements."
62
- exit 1
63
-fi
64
-
65
-# 7. Install specific version of pefile
66
-# skip
67
-
68
-# 8. Run bundle.py
69
-echo "Running bundle.py..."
70
-python ./agent-zero-git/bundle/bundle.py
71
-if [ $? -ne 0 ]; then
72
- echo "Error running bundle.py."
73
- exit 1
74
-fi
75
-
76
-# # 9. Move the generated 7z file to the script directory and remove agent-zero folder
77
-# BUNDLE_FILE="bundle/dist/agent-zero.7z"
78
-# if [ -f "$BUNDLE_FILE" ]; then
79
-# SCRIPT_DIR=$(dirname "$0")
80
-# echo "Moving $BUNDLE_FILE to $SCRIPT_DIR..."
81
-# mv "$BUNDLE_FILE" "$SCRIPT_DIR"
82
-# if [ $? -ne 0 ]; then
83
-# echo "Error moving $BUNDLE_FILE to $SCRIPT_DIR."
84
-# exit 1
85
-# fi
86
-# else
87
-# echo "Error: $BUNDLE_FILE not found."
88
-# exit 1
89
-# fi
90
-
91
-# 9. Create macOS package
92
-echo "Creating macOS package..."
93
-pkgbuild --root ./agent-zero-git/bundle/dist/agent-zero \
94
- --identifier frdel.agent-zero \
95
- --install-location "$HOME/Library/Application Support/agent-zero/install" \
96
- --scripts ./agent-zero-git/bundle/mac_pkg_scripts \
97
- --ownership preserve \
98
- agent-zero-preinstalled-mac-m1.pkg
99
-
100
-if [ $? -ne 0 ]; then
101
- echo "Error creating macOS package."
102
- exit 1
103
-fi
104
-
105
-# 10. Remove the agent-zero-git folder
106
-echo "Deleting agent-zero-git folder..."
107
-cd ..
108
-rm -rf agent-zero-git
109
-if [ -d "agent-zero-git" ]; then
110
- echo "Error: Failed to delete agent-zero-git folder."
111
- exit 1
112
-fi
113
-
114
-echo "Script completed."
bundle/requirements.txt
deleted
-3
@@ -1,3 +0,0 @@
1
-pathspec==0.12.1
2
-py7zr==0.22.0
3
-pyinstaller==6.10.0
\ No newline at end of file
bundle/windows_bundle.bat
deleted
-124
@@ -1,124 +0,0 @@
1
-@echo off
2
-setlocal enabledelayedexpansion
3
-
4
-:: Check if conda is recognized
5
-where conda >nul 2>nul
6
-if %errorlevel% neq 0 (
7
- echo Conda not found in PATH. Checking known location...
8
-
9
- set "CONDA_PATH=C:\Users\%USERNAME%\miniconda3"
10
- if exist "!CONDA_PATH!\Scripts\conda.exe" (
11
- echo Found Conda at !CONDA_PATH!
12
- set "PATH=!CONDA_PATH!;!CONDA_PATH!\Scripts;!CONDA_PATH!\Library\bin;%PATH%"
13
- echo Added Conda to PATH
14
- ) else (
15
- echo Conda installation not found at !CONDA_PATH!
16
- echo Please install Conda or add it to PATH manually.
17
- pause
18
- exit /b 1
19
- )
20
-)
21
-
22
-:: Verify conda is now accessible
23
-where conda >nul 2>nul
24
-if %errorlevel% neq 0 (
25
- echo Failed to add Conda to PATH. Please add it manually.
26
- pause
27
- exit /b 1
28
-)
29
-
30
-:: Initialize conda shell (if not done before)
31
-call conda init bash >nul 2>nul
32
-if %errorlevel% neq 0 (
33
- echo Error running 'conda init'. Please check your conda installation.
34
- pause
35
- exit /b 1
36
-)
37
-
38
-:: 1. Remove conda environment if it exists
39
-conda env remove -n az-bundle -y 2>nul
40
-if %errorlevel% neq 0 (
41
- echo Error removing conda environment
42
- pause
43
-)
44
-
45
-:: 2. Create new environment with Python 3.12 and activate it
46
-conda create -n az-bundle python=3.12 -y
47
-if %errorlevel% neq 0 (
48
- echo Error creating conda environment
49
- pause
50
-) else (
51
- call conda.bat activate az-bundle
52
- if %errorlevel% neq 0 (
53
- echo Error activating conda environment
54
- pause
55
- )
56
-)
57
-
58
-:: 3. Purge folder ./agent-zero (retry mechanism in case of failure)
59
-if exist agent-zero-git (
60
- echo Deleting agent-zero-git folder...
61
- rmdir /s /q agent-zero-git
62
- if exist agent-zero-git (
63
- echo Error: Unable to delete agent-zero-git folder, retrying...
64
- timeout /t 3 /nobreak >nul
65
- rmdir /s /q agent-zero-git
66
- )
67
- if exist agent-zero-git (
68
- echo Error: Failed to purge agent-zero-git folder after retry.
69
- pause
70
- )
71
-)
72
-
73
-:: 4. Clone the repository (testing branch)
74
-echo Cloning the repository (testing branch)...
75
-git clone --branch testing https://github.com/frdel/agent-zero agent-zero-git
76
-if %ERRORLEVEL% neq 0 (
77
- echo Error cloning the repository
78
- pause
79
-)
80
-
81
-@REM :: 5. Change directory to agent-zero
82
-@REM cd agent-zero
83
-@REM if %errorlevel% neq 0 (
84
-@REM echo Error changing directory
85
-@REM pause
86
-@REM )
87
-
88
-:: 6. Install requirements
89
-pip install -r ./agent-zero-git/requirements.txt
90
-if %errorlevel% neq 0 (
91
- echo Error installing project requirements
92
- pause
93
-)
94
-
95
-pip install -r ./agent-zero-git/bundle/requirements.txt
96
-if %errorlevel% neq 0 (
97
- echo Error installing bundle requirements
98
- pause
99
-)
100
-
101
-:: 7. Install specific version of pefile
102
-pip install pefile==2023.2.7
103
-if %errorlevel% neq 0 (
104
- echo Error installing pefile
105
- pause
106
-)
107
-
108
-:: 8. Run bundle.py
109
-python ./agent-zero-git/bundle/bundle.py
110
-if %errorlevel% neq 0 (
111
- echo Error running bundle.py
112
- pause
113
-)
114
-
115
-:: 9. Create Windows self-extracting archive with 7-Zip
116
-echo Creating Windows self-extracting archive...
117
-"C:\Program Files\7-Zip\7z.exe" a -sfx"C:\Program Files\7-Zip\7z.sfx" agent-zero-preinstalled-win-x86.exe ".\agent-zero-git\bundle\dist\agent-zero" -mx=7
118
-if %errorlevel% neq 0 (
119
- echo Error creating Windows self-extracting archive.
120
- pause
121
-)
122
-
123
-echo Script completed
124
-pause
docker/run/docker_manager_mac_linux.sh
deleted
-137
@@ -1,137 +0,0 @@
1
-#!/bin/bash
2
-
3
-# Constants
4
-IMAGE_NAME="frdel/agent-zero-run"
5
-DEFAULT_CONTAINER_NAME="agent-zero"
6
-BASE_PORT=50080
7
-
8
-# Global variable for container IDs
9
-container_ids=()
10
-
11
-# Function to list unique containers based on the specified image
12
-list_containers() {
13
- echo
14
- echo "Listing all containers using image '$IMAGE_NAME':"
15
- container_ids=() # Reset global array for each list update
16
- container_list=$(docker ps -a --filter "ancestor=$IMAGE_NAME" --format "{{.ID}} {{.Names}} {{.Ports}}" | sort -u -k2,2)
17
-
18
- if [ -z "$container_list" ]; then
19
- echo "No containers found for image '$IMAGE_NAME'."
20
- return 1
21
- fi
22
-
23
- index=1
24
- printed_ids=()
25
- while IFS= read -r line; do
26
- container_id=$(echo "$line" | awk '{print $1}')
27
- container_name=$(echo "$line" | awk '{print $2}')
28
- ports=$(echo "$line" | awk '{print substr($0, index($0,$3))}')
29
-
30
- # Extract the mapped port using sed
31
- mapped_port=$(echo "$ports" | sed -n 's/.*0.0.0.0:\([0-9]*\)->80.*/\1/p')
32
- container_url="http://localhost:${mapped_port}"
33
-
34
- # Check if this ID has already been printed and mapped_port is valid
35
- if [[ ! " ${printed_ids[@]} " =~ " ${container_id} " ]] && [ -n "$mapped_port" ]; then
36
- printed_ids+=("$container_id")
37
- container_ids+=("$container_id") # Store container ID in global array
38
- printf "%2d. [%s] %s - URL: %s\n" "$index" "$container_id" "$container_name" "$container_url"
39
- index=$((index + 1))
40
- fi
41
- done <<< "$container_list"
42
- return 0
43
-}
44
-
45
-
46
-
47
-# Function to select an action for an existing container
48
-manage_container() {
49
- container_id=$1
50
- while true; do
51
- echo -e "\nSelect an action for container ID: $container_id"
52
- echo "1. Restart"
53
- echo "2. Remove"
54
- echo "3. View Logs"
55
- echo "0. Back"
56
- read -p "Choose an action (0-3): " action
57
- case $action in
58
- 1)
59
- docker restart "$container_id"
60
- echo "Container restarted."
61
- ;;
62
- 2)
63
- docker rm -f "$container_id"
64
- echo "Container removed."
65
- return # Go back to the list screen after removing
66
- ;;
67
- 3)
68
- echo -e "\n--- Logs for container ID: $container_id ---"
69
- docker logs "$container_id"
70
- echo -e "\n--- End of logs ---"
71
- ;;
72
- 0)
73
- return
74
- ;;
75
- *)
76
- echo "Invalid selection. Please choose 0, 1, 2, or 3."
77
- ;;
78
- esac
79
- done
80
-}
81
-
82
-# Function to create a new container
83
-create_container() {
84
- # Generate the default container name
85
- container_count=$(docker ps -a --filter "name=$DEFAULT_CONTAINER_NAME" --format "{{.Names}}" | wc -l)
86
- default_name="$DEFAULT_CONTAINER_NAME-$(($container_count + 1))"
87
-
88
- # Prompt for the container name
89
- read -p "Enter container name or leave empty for '$default_name': " name
90
- name=${name:-"$default_name"}
91
-
92
- # Calculate default port based on the container count
93
- default_port=$((BASE_PORT + container_count + 1))
94
- read -p "Enter web port or leave empty for '$default_port': " web_port
95
- web_port=${web_port:-$default_port}
96
-
97
- # Prompt for the data folder
98
- read -p "Enter data folder or leave empty for '$(pwd)/agent-zero': " data_folder
99
- data_folder=${data_folder:-$(pwd)/agent-zero}
100
-
101
- # Run the container with the specified name, port mapping, and data folder
102
- container_id=$(docker run -d -p "$web_port:80" --name "$name" -v "$data_folder:/a0" "$IMAGE_NAME:latest")
103
- echo -e "\nContainer '$name' created with ID '$container_id', data folder '$data_folder', and web port '$web_port' mapped to port 80."
104
-}
105
-
106
-# Main program loop
107
-echo -e "\nWelcome to Agent Zero Docker Management Script.\n"
108
-while true; do
109
- list_containers
110
- if [ $? -ne 0 ]; then
111
- echo -e "\nNo containers available. Would you like to create a new one? (y/n)"
112
- read -p "> " create_new
113
- if [ "$create_new" == "y" ]; then
114
- create_container
115
- else
116
- exit 0
117
- fi
118
- else
119
- echo -e "\nChoose a container by line number, type 'n' to create a new one, or 'r' to refresh the list:"
120
- read -p "> " choice
121
-
122
- # Refresh the list if the user inputs 'r'
123
- if [ "$choice" == "r" ]; then
124
- continue
125
- fi
126
-
127
- # Match choice to the actual container list
128
- if [[ $choice =~ ^[0-9]+$ ]] && ((choice >= 1 && choice <= ${#container_ids[@]})); then
129
- selected_container_id="${container_ids[$((choice - 1))]}"
130
- manage_container "$selected_container_id"
131
- elif [ "$choice" == "n" ]; then
132
- create_container
133
- else
134
- echo "Invalid choice, please enter a valid line number, 'n' to create a new container, or 'r' to refresh the list."
135
- fi
136
- fi
137
-done
run_bundle.py
deleted
-78
@@ -1,78 +0,0 @@
1
-def post_install():
2
- # if "_internal.zip" exists, unzip and remove
3
- import os
4
- if os.path.exists("_internal.zip"):
5
- import zipfile
6
- print("\nDecompressing internal binaries...\n")
7
- with zipfile.ZipFile("_internal.zip", 'r') as zip_ref:
8
- zip_ref.extractall("_internal")
9
- os.remove("_internal.zip")
10
-
11
-def run_bundle():
12
- print("\nImporting dependencies, this may take a while...\n")
13
-
14
- # dependencies to bundle
15
- import ansio
16
- import bs4
17
- import docker
18
- import duckduckgo_search
19
- import faiss
20
- from flask import Flask
21
- import flask_basicauth
22
- import inputimeout
23
- import langchain.embeddings
24
- import langchain_anthropic
25
- import langchain_community
26
- import langchain_google_genai
27
- import langchain_groq
28
- import langchain_huggingface
29
- import langchain_mistralai
30
- import langchain_ollama
31
- import langchain_openai
32
- import lxml_html_clean
33
- import emoji
34
- from emoji import unicode_codes
35
- import markdown
36
- import newspaper
37
- import paramiko
38
- import pypdf
39
- import dotenv
40
- import sentence_transformers
41
- from tiktoken import model, registry
42
- from tiktoken_ext import openai_public
43
- import unstructured
44
- import unstructured_client
45
- import webcolors
46
-
47
-
48
-
49
- # but do not bundle project files, these are to be imported at runtime
50
-
51
-
52
-
53
- import sys
54
- import os
55
- import importlib.util
56
-
57
- # Add the project_files directory to the Python path
58
- project_files_dir = os.path.join(os.path.dirname(sys.executable), 'agent-zero-files')
59
- sys.path.insert(0, project_files_dir)
60
-
61
- # Dynamically load the 'run_ui' module
62
- module_name = "run_ui"
63
- module_path = os.path.join(project_files_dir, f"{module_name}.py")
64
-
65
- # Load the module at runtime
66
- spec = importlib.util.spec_from_file_location(module_name, module_path)
67
- if spec and spec.loader:
68
- run_ui = importlib.util.module_from_spec(spec)
69
- spec.loader.exec_module(run_ui)
70
-
71
- # Now you can call the function in the dynamically imported module
72
- run_ui.run() # Call the 'run' function from run_ui
73
- else:
74
- raise Exception(f"Could not load {module_name} from {module_path}")
75
-
76
-
77
-# post_install()
78
-run_bundle()
\ No newline at end of file
tests/__init__.py
tests/helpers/__init__.py
tests/helpers/test_json_parse_dirty.py
deleted
-60
@@ -1,60 +0,0 @@
1
-import unittest
2
-from python.helpers.extract_tools import extract_json_object_string
3
-from python.helpers.dirty_json import DirtyJson
4
-from typing import Any
5
-
6
-
7
-def json_parse_dirty(json: str) -> dict[str, Any] | None:
8
- ext_json = extract_json_object_string(json)
9
- if ext_json:
10
- data = DirtyJson.parse_string(ext_json)
11
- if isinstance(data, dict):
12
- return data
13
- return None
14
-
15
-
16
-class TestJsonParseDirty(unittest.TestCase):
17
- def test_valid_json(self):
18
- json_string = '{"key": "value"}'
19
- expected_output = {"key": "value"}
20
- self.assertEqual(json_parse_dirty(json_string), expected_output)
21
-
22
- def test_invalid_json(self):
23
- json_string = 'invalid json'
24
- self.assertIsNone(json_parse_dirty(json_string))
25
-
26
- def test_partial_json(self):
27
- json_string = 'some text before {"key": "value"} some text after'
28
- expected_output = {"key": "value"}
29
- self.assertEqual(json_parse_dirty(json_string), expected_output)
30
-
31
- def test_no_closing_brace(self):
32
- json_string = '{"key": "value"'
33
- expected_output = {"key": "value"}
34
- self.assertEqual(json_parse_dirty(json_string), expected_output)
35
-
36
- def test_no_opening_brace(self):
37
- json_string = '"key": "value"}'
38
- self.assertIsNone(json_parse_dirty(json_string))
39
-
40
- def test_agent_response(self):
41
- json_string = ('{"thoughts": ["The user wants to save the source code of their Hello, World! application to a '
42
- 'file.", "I can use the code_execution_tool with terminal runtime to achieve this."], '
43
- '"tool_name": "code_execution_tool", "tool_args": {"runtime": "terminal", "code": "echo '
44
- '\'print(\'Hello, World!\')\' > hello_world.py"}}')
45
- expected_result = {
46
- "thoughts": [
47
- "The user wants to save the source code of their Hello, World! application to a file.",
48
- "I can use the code_execution_tool with terminal runtime to achieve this."
49
- ],
50
- "tool_name": "code_execution_tool",
51
- "tool_args": {
52
- "runtime": "terminal",
53
- "code": "echo \'print(\'Hello, World!\')\' > hello_world.py"
54
- }
55
- }
56
- self.assertEqual(json_parse_dirty(json_string), expected_result)
57
-
58
-
59
-if __name__ == '__main__':
60
- unittest.main()
\ No newline at end of file