fix(agent): 调整agent显示样式

This commit is contained in:
sophie committed 2026-07-13 18:11:48 +08:00
1 parent b2fa2688a3
commit 42de6c02d3
3 files changed
+84 -26

No files matched your search

+48 -5
View File
@@ -86,9 +86,23 @@ def list_directory_member_agents(agent_id: int, *, active_only: bool = False) ->
return query.all() return query.all()
def serialize_directory_member(agent: Agent) -> dict[str, Any]: def serialize_directory_member(
"""Serialize one member Agent for Admin and Dify runtime metadata.""" agent: Agent,
return { *,
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, 'id': agent.id,
'name': agent.name, 'name': agent.name,
'description': agent.description, 'description': agent.description,
@@ -97,12 +111,41 @@ def serialize_directory_member(agent: Agent) -> dict[str, Any]:
'dify_app_id': agent.dify_app_id, 'dify_app_id': agent.dify_app_id,
'category': agent.category, 'category': agent.category,
'sub_category': agent.sub_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.""" """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 [ 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) for agent in list_directory_member_agents(agent_id, active_only=active_only)
if agent.id not in visited
] ]
@@ -24,7 +24,7 @@ const props = withDefaults(defineProps<{
activeAgentId: null, activeAgentId: null,
compact: false, compact: false,
showSearch: true, showSearch: true,
defaultExpanded: true, defaultExpanded: false,
}); });
const emit = defineEmits<{ const emit = defineEmits<{
@@ -64,7 +64,7 @@ const matchesQuery = (agent: AgentWithCategory, query: string) => {
const filteredAgents = computed(() => { const filteredAgents = computed(() => {
const q = searchQuery.value.trim(); const q = searchQuery.value.trim();
return props.agents.filter((agent) => { 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); return matchesQuery(agent, q);
}); });
}); });
@@ -134,18 +134,29 @@ const onSelect = (agent: AgentWithCategory) => {
/** /**
* 统一 Agent 行的激活/默认样式类。 * 统一 Agent 行的激活/默认样式类。
* 核心逻辑:选中态用浅蓝底 + 品牌色文字,比实心 brand-600 更轻,与侧栏历史选中风格一致。
* @param active - 是否为当前选中项 * @param active - 是否为当前选中项
* @param dense - 是否为目录成员等更紧凑的行 * @param dense - 是否为目录成员等更紧凑的行
*/ */
const agentRowClass = (active: boolean, dense = false) => { const agentRowClass = (active: boolean, dense = false) => {
const base = dense 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-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-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-colors duration-150';
if (active) { 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'
);
</script> </script>
<template> <template>
@@ -170,12 +181,16 @@ const agentRowClass = (active: boolean, dense = false) => {
<div <div
v-for="agent in aggregateAgents" v-for="agent in aggregateAgents"
:key="agent.id" :key="agent.id"
class="overflow-hidden rounded-2xl border border-subtle bg-surface shadow-sm" class="overflow-hidden rounded-2xl border transition-all duration-150"
:class="aggregateCardClass(isActiveAgent(agent))"
> >
<div class="flex min-w-0 items-stretch"> <div class="flex min-w-0 items-stretch">
<button <button
type="button" type="button"
class="flex w-7 shrink-0 items-center justify-center text-muted transition-colors hover:bg-surface-soft hover:text-brand-600" class="flex w-7 shrink-0 items-center justify-center transition-colors"
:class="isActiveAgent(agent)
? 'text-brand-600 hover:bg-brand-100/60'
: 'text-muted hover:bg-surface-soft hover:text-brand-600'"
:title="isDirectoryCollapsed(agent.id) ? t('chat.expandAgents') : t('chat.collapseAgents')" :title="isDirectoryCollapsed(agent.id) ? t('chat.expandAgents') : t('chat.collapseAgents')"
@click.stop="toggleDirectory(agent.id)" @click.stop="toggleDirectory(agent.id)"
> >
@@ -189,7 +204,7 @@ const agentRowClass = (active: boolean, dense = false) => {
type="button" type="button"
class="flex min-w-0 flex-1 items-center gap-1.5 py-1.5 pr-2.5 text-left transition-colors" class="flex min-w-0 flex-1 items-center gap-1.5 py-1.5 pr-2.5 text-left transition-colors"
:class="isActiveAgent(agent) :class="isActiveAgent(agent)
? 'cursor-default bg-brand-50/80' ? 'cursor-default bg-brand-50 text-brand-700'
: 'hover:bg-surface-soft/80'" : 'hover:bg-surface-soft/80'"
:aria-current="isActiveAgent(agent) ? 'page' : undefined" :aria-current="isActiveAgent(agent) ? 'page' : undefined"
@click="onSelect(agent)" @click="onSelect(agent)"
@@ -197,44 +212,41 @@ const agentRowClass = (active: boolean, dense = false) => {
<span <span
class="flex h-5 w-5 shrink-0 items-center justify-center rounded-md" class="flex h-5 w-5 shrink-0 items-center justify-center rounded-md"
:class="isActiveAgent(agent) :class="isActiveAgent(agent)
? 'bg-brand-100 text-brand-600 dark:bg-brand-900/40 dark:text-brand-300' ? 'bg-brand-100 text-brand-600'
: 'bg-surface-strong text-brand-500'" : 'bg-surface-strong text-brand-500'"
> >
<FolderTree class="h-3 w-3" /> <FolderTree class="h-3 w-3" />
</span> </span>
<span <span
class="min-w-0 truncate text-xs font-semibold tracking-tight" class="min-w-0 truncate text-xs font-semibold tracking-tight"
:class="isActiveAgent(agent) ? 'text-brand-700 dark:text-brand-300' : 'text-primary'" :class="isActiveAgent(agent) ? 'text-brand-700' : 'text-primary'"
> >
{{ agent.name }} {{ agent.name }}
</span> </span>
<span <span
v-if="visibleDirectoryMembers(agent).length" v-if="visibleDirectoryMembers(agent).length"
class="ml-auto shrink-0 rounded px-1 py-px text-[10px] font-medium tabular-nums text-muted" class="ml-auto shrink-0 rounded px-1 py-px text-[10px] font-medium tabular-nums"
:class="isActiveAgent(agent) ? 'text-brand-500' : 'text-muted'"
> >
{{ visibleDirectoryMembers(agent).length }} {{ visibleDirectoryMembers(agent).length }}
</span> </span>
</button> </button>
</div> </div>
<div <div v-show="!isDirectoryCollapsed(agent.id)" class="border-t border-subtle bg-surface-soft/40 px-2 py-2">
v-show="!isDirectoryCollapsed(agent.id)"
class="border-t border-subtle bg-surface-soft/40 px-2 py-2"
>
<div class="grid grid-cols-2 gap-1"> <div class="grid grid-cols-2 gap-1">
<button <template
v-for="member in visibleDirectoryMembers(agent)" v-for="member in visibleDirectoryMembers(agent)"
:key="`${agent.id}-${member.id}`" :key="`${agent.id}-${member.id}`"
>
<button
type="button" type="button"
:class="agentRowClass(isActiveAgent(member), true)" :class="agentRowClass(isActiveAgent(member), true)"
:title="member.name" :title="member.name"
:aria-current="isActiveAgent(member) ? 'page' : undefined" :aria-current="isActiveAgent(member) ? 'page' : undefined"
@click="onSelect(member)" @click="onSelect(member)"
> >
<span <span v-if="isActiveAgent(member)" class="absolute inset-y-1 left-0 w-0.5 rounded-full bg-brand-500" />
v-if="isActiveAgent(member)"
class="absolute inset-y-1 left-0 w-0.5 rounded-full bg-brand-500"
/>
<div <div
v-if="member.icon_url" v-if="member.icon_url"
class="h-5 w-5 shrink-0 rounded-md bg-contain bg-center bg-no-repeat ring-1 ring-black/5" class="h-5 w-5 shrink-0 rounded-md bg-contain bg-center bg-no-repeat ring-1 ring-black/5"
@@ -248,6 +260,7 @@ const agentRowClass = (active: boolean, dense = false) => {
</div> </div>
<span class="min-w-0 truncate leading-tight">{{ member.name }}</span> <span class="min-w-0 truncate leading-tight">{{ member.name }}</span>
</button> </button>
</template>
</div> </div>
</div> </div>
</div> </div>
@@ -27,6 +27,8 @@ export interface AgentDirectoryMemberRef extends AgentCategoryFields {
description?: string | null; description?: string | null;
agent_code?: string | null; agent_code?: string | null;
dify_app_id?: string | null; dify_app_id?: string | null;
is_aggregate?: boolean;
directory_members?: AgentDirectoryMemberRef[];
} }
export interface AgentCategorySubGroup<T extends AgentWithCategory = AgentWithCategory> { export interface AgentCategorySubGroup<T extends AgentWithCategory = AgentWithCategory> {