mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(backend): include path filter in workspace file count
get_file_count() now accepts path parameter to match list_files() filtering, fixing pagination totals when filtering by path prefix. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -157,7 +157,8 @@ class ListWorkspaceFilesTool(BaseTool):
|
||||
include_all_sessions=include_all_sessions,
|
||||
)
|
||||
total = await manager.get_file_count(
|
||||
include_all_sessions=include_all_sessions
|
||||
path=path_prefix,
|
||||
include_all_sessions=include_all_sessions,
|
||||
)
|
||||
|
||||
file_infos = [
|
||||
|
||||
@@ -222,7 +222,7 @@ async def list_files(
|
||||
|
||||
manager = WorkspaceManager(user_id, workspace.id)
|
||||
files = await manager.list_files(path=path, limit=limit, offset=offset)
|
||||
total = await manager.get_file_count()
|
||||
total = await manager.get_file_count(path=path)
|
||||
|
||||
return WorkspaceFileListResponse(
|
||||
files=[_file_to_info(f) for f in files],
|
||||
|
||||
@@ -360,7 +360,11 @@ class WorkspaceManager:
|
||||
resolved_path = self._resolve_path(path)
|
||||
return await workspace_file_exists(self.workspace_id, resolved_path)
|
||||
|
||||
async def get_file_count(self, include_all_sessions: bool = False) -> int:
|
||||
async def get_file_count(
|
||||
self,
|
||||
path: Optional[str] = None,
|
||||
include_all_sessions: bool = False,
|
||||
) -> int:
|
||||
"""
|
||||
Get number of files in workspace.
|
||||
|
||||
@@ -368,6 +372,7 @@ class WorkspaceManager:
|
||||
only counts files in the current session's folder.
|
||||
|
||||
Args:
|
||||
path: Optional path prefix to filter (e.g., "/documents/")
|
||||
include_all_sessions: If True, count all files in workspace.
|
||||
If False (default), only count current session's files.
|
||||
|
||||
@@ -376,10 +381,16 @@ class WorkspaceManager:
|
||||
"""
|
||||
# Determine the effective path prefix (same logic as list_files)
|
||||
if include_all_sessions:
|
||||
path_prefix = None
|
||||
# Use provided path as-is (or None for all files)
|
||||
effective_path = path
|
||||
elif path is not None:
|
||||
# Resolve the provided path with session scoping
|
||||
effective_path = self._resolve_path(path)
|
||||
elif self.session_path:
|
||||
path_prefix = self.session_path
|
||||
# Default to session folder
|
||||
effective_path = self.session_path
|
||||
else:
|
||||
path_prefix = None
|
||||
# No session context, use path as-is
|
||||
effective_path = path
|
||||
|
||||
return await count_workspace_files(self.workspace_id, path_prefix=path_prefix)
|
||||
return await count_workspace_files(self.workspace_id, path_prefix=effective_path)
|
||||
|
||||
Reference in New Issue
Block a user