Skip to content

Agent Zero AI framework

fixes - allowed hosts, image get folders, extensions after termination

frdel08693c22f01a
diff --git a/agent.py b/agent.py
index 50d47e4c3..dc985f5f1 100644
--- a/agent.py
+++ b/agent.py
@@ -487,9 +487,10 @@ class Agent:
finally:
# call message_loop_end extensions
- await self.call_extensions(
- "message_loop_end", loop_data=self.loop_data
- )
+ if self.context.task and self.context.task.is_alive(): # don't call extensions post mortem
+ await self.call_extensions(
+ "message_loop_end", loop_data=self.loop_data
+ )
# exceptions outside message loop:
except InterventionException as e:
@@ -503,7 +504,8 @@ class Agent:
finally:
self.context.streaming_agent = None # unset current streamer
# call monologue_end extensions
- await self.call_extensions("monologue_end", loop_data=self.loop_data) # type: ignore
+ if self.context.task and self.context.task.is_alive(): # don't call extensions post mortem
+ await self.call_extensions("monologue_end", loop_data=self.loop_data) # type: ignore
async def prepare_prompt(self, loop_data: LoopData) -> list[BaseMessage]:
self.context.log.set_progress("Building prompt")
diff --git a/python/api/csrf_token.py b/python/api/csrf_token.py
index f4d1d63c0..69082a59b 100644
--- a/python/api/csrf_token.py
+++ b/python/api/csrf_token.py
@@ -70,7 +70,6 @@ class GetCsrfToken(ApiHandler):
)
return {"ok": match, "origin": origin, "allowed_origins": allowed_origins}
-
def get_origin_from_request(self, request: Request):
# get from origin
r = request.headers.get("Origin") or request.environ.get("HTTP_ORIGIN")
@@ -93,7 +92,9 @@ class GetCsrfToken(ApiHandler):
# get the allowed origins from the environment
allowed_origins = [
origin.strip()
- for origin in (dotenv.get_dotenv_value(ALLOWED_ORIGINS_KEY) or "").split(",")
+ for origin in (dotenv.get_dotenv_value(ALLOWED_ORIGINS_KEY) or "").split(
+ ","
+ )
if origin.strip()
]
@@ -114,12 +115,19 @@ class GetCsrfToken(ApiHandler):
return allowed_origins
def get_default_allowed_origins(self) -> list[str]:
- return ["*://localhost:*", "*://127.0.0.1:*", "*://0.0.0.0:*"]
+ return [
+ "*://localhost",
+ "*://localhost:*",
+ "*://127.0.0.1",
+ "*://127.0.0.1:*",
+ "*://0.0.0.0",
+ "*://0.0.0.0:*",
+ ]
def initialize_allowed_origins(self, request: Request):
"""
If A0 is hosted on a server, add the first visit origin to ALLOWED_ORIGINS.
- This simplifies deployment process as users can access their new instance without
+ This simplifies deployment process as users can access their new instance without
additional setup while keeping it secure.
"""
# dotenv value is already set, do nothing
@@ -144,5 +152,3 @@ class GetCsrfToken(ApiHandler):
# if not, add it to the allowed origins
allowed_origins.append(req_origin)
dotenv.save_dotenv_value(ALLOWED_ORIGINS_KEY, ",".join(allowed_origins))
-
-
\ No newline at end of file
diff --git a/python/api/image_get.py b/python/api/image_get.py
index 53b2cb0bd..a009d7f32 100644
--- a/python/api/image_get.py
+++ b/python/api/image_get.py
@@ -28,7 +28,7 @@ class ImageGet(ApiHandler):
in_base = files.is_in_base_dir(files.fix_dev_path(path))
else:
in_base = files.is_in_base_dir(path)
- if not in_base:
+ if not in_base and not files.is_in_dir(path, "/root"):
raise ValueError("Path is outside of allowed directory")
# get file extension and info
diff --git a/python/helpers/files.py b/python/helpers/files.py
index 0ed9cb06d..04a019602 100644
--- a/python/helpers/files.py
+++ b/python/helpers/files.py
@@ -505,12 +505,14 @@ def dirname(path: str):
def is_in_base_dir(path: str):
- # check if the given path is within the base directory
- base_dir = get_base_dir()
- # normalize paths to handle relative paths and symlinks
+ return is_in_dir(path,get_base_dir())
+
+
+def is_in_dir(path:str,dir:str):
+ # check if the given path is within the directory
abs_path = os.path.abspath(path)
- # check if the absolute path starts with the base directory
- return os.path.commonpath([abs_path, base_dir]) == base_dir
+ abs_dir = os.path.abspath(dir)
+ return os.path.commonpath([abs_path, abs_dir]) == abs_dir
def get_subdirectories(
diff --git a/webui/components/sidebar/chats/chats-list.html b/webui/components/sidebar/chats/chats-list.html
index 228060dfa..28d357096 100644
--- a/webui/components/sidebar/chats/chats-list.html
+++ b/webui/components/sidebar/chats/chats-list.html
@@ -129,6 +129,10 @@
margin-right: 8px;
}
+ .chat-container:hover{
+ background-color: var(--color-background-hover);
+ }
+
.device-pointer .chat-container .chat-list-action-btn {
opacity: 0;
visibility: hidden;