99 lines
3.7 KiB
TypeScript
99 lines
3.7 KiB
TypeScript
"use client";
|
|
|
|
import { Bot, ChevronRight } from "lucide-react";
|
|
import Link from "next/link";
|
|
import { usePathname } from "next/navigation";
|
|
|
|
import {
|
|
SidebarGroup,
|
|
SidebarGroupContent,
|
|
SidebarGroupLabel,
|
|
SidebarMenu,
|
|
SidebarMenuButton,
|
|
SidebarMenuItem,
|
|
} from "@/components/ui/sidebar";
|
|
import { useSidebarAgents } from "@/core/agents";
|
|
import { desensitize } from "@/lib/desensitize";
|
|
|
|
/** 常用智能体最多展示个数(需求 1.2 ②)。 */
|
|
|
|
/** 「更多」跳转目标:智能体管理页(需求 1.3)。 */
|
|
const MORE_HREF = "/page/strategy/agents";
|
|
|
|
/** 打开某个智能体主页(其对话落地页,thread_id=new = 新会话)。 */
|
|
function agentHomeHref(agentId: string): string {
|
|
return `/page/strategy/agents/${agentId}/chats/new`;
|
|
}
|
|
|
|
/**
|
|
* 「常用智能体」侧栏区块(通用问答左栏,全量模式)。
|
|
*
|
|
* 级联兜底取数(需求 1.2 ② / 1.3)——按优先级补足到最多 3 个、去重:
|
|
* 1. 置顶智能体(``is_pinned``,可来自「我的」或「广场」);
|
|
* 2. 不足 3 个 → 用「我的」智能体(``scope="mine"``)补足;
|
|
* 3. 仍不足 → 用「广场」默认推荐(``scope="square"``)补足。
|
|
*
|
|
* 取不到任何智能体时整块隐藏(与 ``RecentChatList`` 的空态约定一致)。
|
|
*/
|
|
export function FrequentAgentsList() {
|
|
const pathname = usePathname();
|
|
const { agents: frequent } = useSidebarAgents();
|
|
|
|
if (frequent.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<SidebarGroup className="px-2 pt-3 mt-2 border-t border-sidebar-border/60">
|
|
<SidebarGroupLabel className="text-muted-foreground/70 px-3 mb-1 text-[10px] font-semibold tracking-[0.12em] uppercase select-none">
|
|
常用智能体
|
|
</SidebarGroupLabel>
|
|
<SidebarGroupContent>
|
|
<SidebarMenu>
|
|
<div className="flex w-full flex-col gap-0.5">
|
|
{frequent.map((agent) => {
|
|
const href = agentHomeHref(agent.id);
|
|
const isActive = pathname === href;
|
|
return (
|
|
<SidebarMenuItem key={agent.id}>
|
|
<SidebarMenuButton
|
|
isActive={isActive}
|
|
asChild
|
|
className={
|
|
"rounded-lg h-7 px-3 text-[13px] text-muted-foreground hover:text-foreground hover:bg-sidebar-accent/60 " +
|
|
"data-[active=true]:bg-white data-[active=true]:text-foreground data-[active=true]:shadow-[0_1px_2px_rgba(15,23,42,0.05)] " +
|
|
"dark:data-[active=true]:bg-slate-700/80 dark:data-[active=true]:text-slate-100 dark:data-[active=true]:shadow-none"
|
|
}
|
|
>
|
|
<Link
|
|
className="flex w-full items-center gap-2 whitespace-nowrap"
|
|
href={href}
|
|
>
|
|
<Bot className="size-3.5 shrink-0 text-muted-foreground/70" />
|
|
<span className="truncate">{desensitize(agent.name)}</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
);
|
|
})}
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton
|
|
asChild
|
|
className="rounded-lg h-7 px-3 text-[12px] text-muted-foreground/70 hover:text-foreground hover:bg-sidebar-accent/60"
|
|
>
|
|
<Link
|
|
className="flex w-full items-center justify-between gap-1"
|
|
href={MORE_HREF}
|
|
>
|
|
<span>更多</span>
|
|
<ChevronRight className="size-3.5 shrink-0" />
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
</div>
|
|
</SidebarMenu>
|
|
</SidebarGroupContent>
|
|
</SidebarGroup>
|
|
);
|
|
}
|