feat(agent-chat): 修复智能体会话归属与历史路由恢复:侧边栏按当前agent过滤会话并携带agent上下文跳转,补充旧线程路径回溯到智能体工作区,防止误入通用问答,并完善输入框记忆按钮显隐与侧边栏展开入口,提升体验一致性。

This commit is contained in:
董宏凯 committed 2026-09-01 13:47:31 +08:00
1 parent 051e66f7d8
commit aeb9a55497
5 files changed
+140 -30

No files matched your search

+37 -18
View File
@@ -3,6 +3,7 @@
import {
BotIcon,
Compass,
PanelLeftOpenIcon,
PanelRightOpenIcon,
PlusSquare,
} from "lucide-react";
@@ -13,6 +14,7 @@ import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } fro
import type { PromptInputMessage } from "@/components/ai-elements/prompt-input";
import { Button } from "@/components/ui/button";
import { useSidebarSafe } from "@/components/ui/sidebar";
import { AgentChatSidebar } from "@/components/workspace/agents/agent-chat-sidebar";
import { AgentDetailPanel } from "@/components/workspace/agents/agent-detail-panel";
import { AgentQuestionChips } from "@/components/workspace/agents/agent-question-chips";
@@ -225,6 +227,7 @@ export default function AgentChatPage({
const { t } = useI18n();
const [showFollowups, setShowFollowups] = useState(false);
const router = useRouter();
const workspaceSidebar = useSidebarSafe();
const { agent_id: agentIdFromPath } = useParams<{
agent_id: string;
@@ -806,6 +809,23 @@ export default function AgentChatPage({
<main className="relative flex size-full min-h-0 min-w-0 flex-col">
{/* Header in normal flow, fixed height. */}
<header className="bg-card/90 border-border/70 flex h-12 shrink-0 items-center gap-2 border-b px-4 backdrop-blur-md">
{/* 工作区左栏收起后,在智能体聊天区左上角提供展开入口。 */}
{showAgentList &&
!isEmbedded &&
workspaceSidebar &&
!workspaceSidebar.open && (
<Button
type="button"
variant="ghost"
size="icon-sm"
onClick={workspaceSidebar.toggleSidebar}
title="展开左侧栏"
aria-label="展开左侧栏"
className="shrink-0 text-muted-foreground hover:text-foreground"
>
<PanelLeftOpenIcon className="size-4" />
</Button>
)}
<div className="flex shrink-0 items-center gap-1.5 rounded-md border px-2 py-1">
<BotIcon className="text-primary h-3.5 w-3.5" />
<span
@@ -881,23 +901,6 @@ export default function AgentChatPage({
开始回答
</Button>
)}
<Tooltip content={t.agents.newChat}>
<Button
size="sm"
variant="secondary"
onClick={() => {
// 嵌入态:保持停留在通用问答右侧,开同一智能体的新对话;
// 非嵌入态:走该智能体的独立新对话页(按当前路由 base)。
router.push(
isEmbedded
? `/page/workspace/chats/new?agent=${agent_id}`
: `${agentChatsBase}/new`,
);
}}
>
<PlusSquare /> {t.agents.newChat}
</Button>
</Tooltip>
{/* 右侧智能体详情面板收起时的「展开」入口:仅收起态显示
(展开态的「收起」按钮在面板右上角)。桌面端专用(lg+),
窄屏面板走抽屉交互;嵌入态面板固定渲染,不显示该开关。 */}
@@ -919,6 +922,23 @@ export default function AgentChatPage({
enabled={tokenUsageEnabled}
messages={displayThread.messages}
/>
<Tooltip content={t.agents.newChat}>
<Button
size="sm"
variant="secondary"
onClick={() => {
// 嵌入态:保持停留在通用问答右侧,开同一智能体的新对话;
// 非嵌入态:走该智能体的独立新对话页(按当前路由 base)。
router.push(
isEmbedded
? `/page/workspace/chats/new?agent=${agent_id}`
: `${agentChatsBase}/new`,
);
}}
>
<PlusSquare /> {t.agents.newChat}
</Button>
</Tooltip>
<ExportTrigger threadId={threadId} />
<ArtifactTrigger />
</div>
@@ -1101,7 +1121,6 @@ export default function AgentChatPage({
onAskQuestion={(text) => handleSubmit({ text, files: [] })}
collapsed={detailCollapsed}
onCollapsedChange={setDetailCollapsed}
showRecentChats={!taskCtxOn}
compactAppearanceActions={compactAppearanceActions}
/>
</div>