mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-10 09:21:25 +08:00
feat: add agent filter counts (#17984)
This commit is contained in:
@@ -681,6 +681,18 @@ _COMPILATION_TEMPLATE_GROUP_CATEGORY = "compilation_template_group"
|
||||
@login_required
|
||||
@add_tenant_id_to_kwargs
|
||||
def list_agents(tenant_id):
|
||||
if request.args.get("type") == "filter":
|
||||
tenants = TenantService.get_joined_tenants_by_user_id(tenant_id)
|
||||
joined_tenant_ids = list({member["tenant_id"] for member in tenants} | {tenant_id})
|
||||
owners = UserCanvasService.get_owner_filter(joined_tenant_ids, tenant_id)
|
||||
categories = UserCanvasService.get_category_filter(joined_tenant_ids, tenant_id)
|
||||
return get_json_result(
|
||||
data={
|
||||
"filter": {"owner": owners, "canvas_category": categories},
|
||||
"total": sum(owner["count"] for owner in owners),
|
||||
}
|
||||
)
|
||||
|
||||
keywords = request.args.get("keywords", "")
|
||||
canvas_category_list = [item for item in request.args.get("canvas_category", "").strip().split(",") if item]
|
||||
canvas_type = request.args.get("canvas_type")
|
||||
@@ -707,6 +719,7 @@ def list_agents(tenant_id):
|
||||
effective_owner_ids = list(requested_owner_ids)
|
||||
else:
|
||||
effective_owner_ids = list(authorized_owner_ids)
|
||||
include_template_groups = tenant_id in effective_owner_ids
|
||||
|
||||
# Groups-only: when ``compilation_template_group`` is the only selected
|
||||
# category, return just the caller's template groups (no agents) via
|
||||
@@ -715,11 +728,12 @@ def list_agents(tenant_id):
|
||||
if canvas_category_list == [_COMPILATION_TEMPLATE_GROUP_CATEGORY]:
|
||||
from api.db.services.compilation_template_group_service import CompilationTemplateGroupService
|
||||
|
||||
try:
|
||||
groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc)
|
||||
except Exception:
|
||||
logging.exception("list_agents: compilation template group list failed for tenant=%s", tenant_id)
|
||||
groups = []
|
||||
groups = []
|
||||
if include_template_groups:
|
||||
try:
|
||||
groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc)
|
||||
except Exception:
|
||||
logging.exception("list_agents: compilation template group list failed for tenant=%s", tenant_id)
|
||||
for group in groups:
|
||||
group["type"] = _COMPILATION_TEMPLATE_GROUP_CATEGORY
|
||||
total = len(groups)
|
||||
@@ -758,11 +772,12 @@ def list_agents(tenant_id):
|
||||
)
|
||||
# Groups are owner-only (no team sharing), so they're scoped to the
|
||||
# caller. Keyword filters the group name; scope is left unfiltered.
|
||||
try:
|
||||
groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc)
|
||||
except Exception:
|
||||
logging.exception("list_agents: compilation template group merge failed for tenant=%s", tenant_id)
|
||||
groups = []
|
||||
groups = []
|
||||
if include_template_groups:
|
||||
try:
|
||||
groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc)
|
||||
except Exception:
|
||||
logging.exception("list_agents: compilation template group merge failed for tenant=%s", tenant_id)
|
||||
|
||||
items: list[dict] = []
|
||||
for agent in agents:
|
||||
@@ -802,11 +817,12 @@ def list_agents(tenant_id):
|
||||
tags,
|
||||
canvas_type,
|
||||
)
|
||||
try:
|
||||
groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc)
|
||||
except Exception:
|
||||
logging.exception("list_agents: compilation template group mixed failed for tenant=%s", tenant_id)
|
||||
groups = []
|
||||
groups = []
|
||||
if include_template_groups:
|
||||
try:
|
||||
groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc)
|
||||
except Exception:
|
||||
logging.exception("list_agents: compilation template group mixed failed for tenant=%s", tenant_id)
|
||||
|
||||
items = []
|
||||
for agent in agents:
|
||||
|
||||
Reference in New Issue
Block a user