From 42de6c02d3678e666756cfb83469217cdb8706c2 Mon Sep 17 00:00:00 2001 From: sophie Date: Mon, 13 Jul 2026 18:11:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(agent):=20=E8=B0=83=E6=95=B4agent=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/agent_directory.py | 53 +++++++++-- .../shared/components/AgentCategoryList.vue | 89 +++++++++++-------- .../src/shared/utils/agent-category.utils.ts | 2 + 3 files changed, 101 insertions(+), 43 deletions(-) diff --git a/backend/app/services/agent_directory.py b/backend/app/services/agent_directory.py index 9484067e..4701101b 100644 --- a/backend/app/services/agent_directory.py +++ b/backend/app/services/agent_directory.py @@ -86,9 +86,23 @@ def list_directory_member_agents(agent_id: int, *, active_only: bool = False) -> return query.all() -def serialize_directory_member(agent: Agent) -> dict[str, Any]: - """Serialize one member Agent for Admin and Dify runtime metadata.""" - return { +def serialize_directory_member( + agent: Agent, + *, + active_only: bool = False, + max_depth: int = 0, + visited_ids: set[int] | None = None, +) -> dict[str, Any]: + """ + Serialize one member Agent for Admin, user navigation, and Dify metadata. + + Args: + active_only: True 时只展开启用中的子应用。 + max_depth: 允许向下展开的聚合层级,避免用户列表中聚合子应用丢失展开能力。 + visited_ids: 已访问 Agent ID,用于防止循环配置导致递归。 + """ + is_aggregate = bool(getattr(agent, 'is_aggregate', False)) + payload = { 'id': agent.id, 'name': agent.name, 'description': agent.description, @@ -97,12 +111,41 @@ def serialize_directory_member(agent: Agent) -> dict[str, Any]: 'dify_app_id': agent.dify_app_id, 'category': agent.category, 'sub_category': agent.sub_category, + 'sort_order': int(getattr(agent, 'sort_order', 0) or 0), + 'is_aggregate': is_aggregate, } + if is_aggregate and max_depth > 0: + next_visited = set(visited_ids or set()) + if agent.id not in next_visited: + next_visited.add(agent.id) + payload['directory_members'] = serialize_directory_members( + agent.id, + active_only=active_only, + max_depth=max_depth - 1, + visited_ids=next_visited, + ) + return payload -def serialize_directory_members(agent_id: int, *, active_only: bool = False) -> list[dict[str, Any]]: +def serialize_directory_members( + agent_id: int, + *, + active_only: bool = False, + max_depth: int = 0, + visited_ids: set[int] | None = None, +) -> list[dict[str, Any]]: """Serialize configured member Agents for a directory Agent.""" + visited = set(visited_ids or set()) + if agent_id in visited: + return [] + visited.add(agent_id) return [ - serialize_directory_member(agent) + serialize_directory_member( + agent, + active_only=active_only, + max_depth=max_depth, + visited_ids=visited, + ) for agent in list_directory_member_agents(agent_id, active_only=active_only) + if agent.id not in visited ] diff --git a/frontend/src/shared/components/AgentCategoryList.vue b/frontend/src/shared/components/AgentCategoryList.vue index 4f4dd4a1..7b324596 100644 --- a/frontend/src/shared/components/AgentCategoryList.vue +++ b/frontend/src/shared/components/AgentCategoryList.vue @@ -24,7 +24,7 @@ const props = withDefaults(defineProps<{ activeAgentId: null, compact: false, showSearch: true, - defaultExpanded: true, + defaultExpanded: false, }); const emit = defineEmits<{ @@ -64,7 +64,7 @@ const matchesQuery = (agent: AgentWithCategory, query: string) => { const filteredAgents = computed(() => { const q = searchQuery.value.trim(); return props.agents.filter((agent) => { - if (directoryMemberIds.value.has(agent.id)) return false; + if (directoryMemberIds.value.has(agent.id) && !isAggregateAgent(agent)) return false; return matchesQuery(agent, q); }); }); @@ -134,18 +134,29 @@ const onSelect = (agent: AgentWithCategory) => { /** * 统一 Agent 行的激活/默认样式类。 + * 核心逻辑:选中态用浅蓝底 + 品牌色文字,比实心 brand-600 更轻,与侧栏历史选中风格一致。 * @param active - 是否为当前选中项 * @param dense - 是否为目录成员等更紧凑的行 */ const agentRowClass = (active: boolean, dense = false) => { const base = dense - ? 'group relative flex w-full min-w-0 items-center gap-2 rounded-lg px-2 py-1.5 text-left text-[11px] font-medium transition-all duration-150' - : 'group relative flex w-full min-w-0 items-center gap-2 rounded-xl px-2.5 py-2 text-left text-xs font-medium transition-all duration-150'; + ? 'group relative flex w-full min-w-0 items-center gap-2 rounded-lg px-2 py-1.5 text-left text-[11px] font-medium transition-colors duration-150' + : 'group relative flex w-full min-w-0 items-center gap-2 rounded-xl px-2.5 py-2 text-left text-xs font-medium transition-colors duration-150'; if (active) { - return `${base} cursor-default bg-brand-50 text-brand-700 shadow-sm ring-1 ring-brand-100/80 dark:bg-brand-900/25 dark:text-brand-300 dark:ring-brand-800/40`; + return `${base} cursor-default bg-brand-50 text-brand-700`; } - return `${base} text-secondary hover:bg-surface hover:text-primary hover:shadow-sm`; + return `${base} text-secondary hover:bg-surface hover:text-primary`; }; + +/** + * 聚合应用作为一级入口时选中态需要更强,避免与浅色未选中卡片混在一起。 + * 核心逻辑:浅蓝底 + 浅品牌描边表达选中,不用实心深蓝。 + */ +const aggregateCardClass = (active: boolean) => ( + active + ? 'border-brand-200 bg-brand-50 text-brand-700' + : 'border-subtle bg-surface' +); diff --git a/frontend/src/shared/utils/agent-category.utils.ts b/frontend/src/shared/utils/agent-category.utils.ts index 7754bcba..2b30d73a 100644 --- a/frontend/src/shared/utils/agent-category.utils.ts +++ b/frontend/src/shared/utils/agent-category.utils.ts @@ -27,6 +27,8 @@ export interface AgentDirectoryMemberRef extends AgentCategoryFields { description?: string | null; agent_code?: string | null; dify_app_id?: string | null; + is_aggregate?: boolean; + directory_members?: AgentDirectoryMemberRef[]; } export interface AgentCategorySubGroup {