Files
deer-flow/frontend/src/app/workspace/chats/[thread_id]/page.tsx

376 lines
13 KiB
TypeScript
Raw Normal View History

2026-01-16 09:15:04 +08:00
"use client";
2026-01-17 11:02:33 +08:00
import { FilesIcon, XIcon } from "lucide-react";
2026-01-31 22:31:25 +08:00
import { useParams, useRouter, useSearchParams } from "next/navigation";
2026-01-16 09:15:04 +08:00
import { useCallback, useEffect, useMemo, useState } from "react";
2026-01-17 15:09:44 +08:00
import { ConversationEmptyState } from "@/components/ai-elements/conversation";
import { usePromptInputController } from "@/components/ai-elements/prompt-input";
2026-01-17 11:02:33 +08:00
import { Button } from "@/components/ui/button";
2026-01-17 00:02:03 +08:00
import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
} from "@/components/ui/resizable";
2026-01-17 11:02:33 +08:00
import { useSidebar } from "@/components/ui/sidebar";
2026-01-17 00:02:03 +08:00
import {
2026-01-17 00:05:19 +08:00
ArtifactFileDetail,
ArtifactFileList,
2026-01-17 00:02:03 +08:00
useArtifacts,
2026-01-17 00:05:19 +08:00
} from "@/components/workspace/artifacts";
2026-01-16 09:15:04 +08:00
import { InputBox } from "@/components/workspace/input-box";
2026-01-17 00:05:19 +08:00
import { MessageList } from "@/components/workspace/messages";
2026-01-18 17:13:15 +08:00
import { ThreadContext } from "@/components/workspace/messages/context";
2026-01-17 17:37:12 +08:00
import { ThreadTitle } from "@/components/workspace/thread-title";
2026-01-22 00:26:11 +08:00
import { TodoList } from "@/components/workspace/todo-list";
2026-01-17 11:02:33 +08:00
import { Tooltip } from "@/components/workspace/tooltip";
2026-01-17 19:46:02 +08:00
import { Welcome } from "@/components/workspace/welcome";
2026-01-20 14:06:47 +08:00
import { useI18n } from "@/core/i18n/hooks";
2026-01-31 11:08:27 +08:00
import { useNotification } from "@/core/notification/hooks";
2026-01-16 09:55:02 +08:00
import { useLocalSettings } from "@/core/settings";
fix(frontend): no half-finished citations, correct state when SSE ends Citations: - In shouldShowCitationLoading, treat any unreplaced [cite-N] in cleanContent as show-loading (no body). Fixes Ultra and other modes when refs arrive before the <citations> block in the stream. - Single rule: hasUnreplacedCitationRefs(cleanContent) => true forces loading; then isLoading && hasCitationsBlock(rawContent) for streaming indicator. SSE end state: - When stream finishes, SDK may set isLoading=false before client state has the final message content, so UI stayed wrong until refresh. - Store onFinish(state) as finalState in chat page; clear when stream starts. - Pass messagesOverride={finalState.messages} to MessageList when not loading so the list uses server-complete messages right after SSE ends (no refresh). Chore: - Stop tracking .githooks/pre-commit; add .githooks/ to .gitignore (local only). Co-authored-by: Cursor <cursoragent@cursor.com> --- fix(前端): 杜绝半成品引用,SSE 结束时展示正确状态 引用: - shouldShowCitationLoading 中只要 cleanContent 仍含未替换的 [cite-N] 就 只显示加载、不渲染正文,解决流式时引用块未到就出现 [cite-1] 的问题。 - 规则:hasUnreplacedCitationRefs(cleanContent) 为真则一律显示加载; 此外 isLoading && hasCitationsBlock 用于流式时显示「正在整理引用」。 SSE 结束状态: - 流结束时 SDK 可能先置 isLoading=false,客户端 messages 尚未包含 最终内容,导致需刷新才显示正确。 - 在对话页保存 onFinish(state) 为 finalState,流开始时清空。 - 非加载时向 MessageList 传入 messagesOverride={finalState.messages}, 列表在 SSE 结束后立即用服务端完整消息渲染,无需刷新。 杂项: - 取消跟踪 .githooks/pre-commit,.gitignore 增加 .githooks/(仅本地)。
2026-02-09 15:15:20 +08:00
import { type AgentThread, type AgentThreadState } from "@/core/threads";
2026-01-16 19:51:39 +08:00
import { useSubmitThread, useThreadStream } from "@/core/threads/hooks";
fix(frontend): no half-finished citations, correct state when SSE ends Citations: - In shouldShowCitationLoading, treat any unreplaced [cite-N] in cleanContent as show-loading (no body). Fixes Ultra and other modes when refs arrive before the <citations> block in the stream. - Single rule: hasUnreplacedCitationRefs(cleanContent) => true forces loading; then isLoading && hasCitationsBlock(rawContent) for streaming indicator. SSE end state: - When stream finishes, SDK may set isLoading=false before client state has the final message content, so UI stayed wrong until refresh. - Store onFinish(state) as finalState in chat page; clear when stream starts. - Pass messagesOverride={finalState.messages} to MessageList when not loading so the list uses server-complete messages right after SSE ends (no refresh). Chore: - Stop tracking .githooks/pre-commit; add .githooks/ to .gitignore (local only). Co-authored-by: Cursor <cursoragent@cursor.com> --- fix(前端): 杜绝半成品引用,SSE 结束时展示正确状态 引用: - shouldShowCitationLoading 中只要 cleanContent 仍含未替换的 [cite-N] 就 只显示加载、不渲染正文,解决流式时引用块未到就出现 [cite-1] 的问题。 - 规则:hasUnreplacedCitationRefs(cleanContent) 为真则一律显示加载; 此外 isLoading && hasCitationsBlock 用于流式时显示「正在整理引用」。 SSE 结束状态: - 流结束时 SDK 可能先置 isLoading=false,客户端 messages 尚未包含 最终内容,导致需刷新才显示正确。 - 在对话页保存 onFinish(state) 为 finalState,流开始时清空。 - 非加载时向 MessageList 传入 messagesOverride={finalState.messages}, 列表在 SSE 结束后立即用服务端完整消息渲染,无需刷新。 杂项: - 取消跟踪 .githooks/pre-commit,.gitignore 增加 .githooks/(仅本地)。
2026-02-09 15:15:20 +08:00
import type { Message } from "@langchain/langgraph-sdk";
2026-01-31 20:22:15 +08:00
import {
pathOfThread,
textOfMessage,
titleOfThread,
} from "@/core/threads/utils";
2026-01-16 09:15:04 +08:00
import { uuid } from "@/core/utils/uuid";
2026-01-24 18:01:27 +08:00
import { env } from "@/env";
2026-01-17 11:02:33 +08:00
import { cn } from "@/lib/utils";
2026-01-16 09:15:04 +08:00
export default function ChatPage() {
2026-01-20 14:06:47 +08:00
const { t } = useI18n();
2026-01-17 11:02:33 +08:00
const router = useRouter();
const [settings, setSettings] = useLocalSettings();
const { setOpen: setSidebarOpen } = useSidebar();
const {
artifacts,
2026-01-17 11:02:33 +08:00
open: artifactsOpen,
setOpen: setArtifactsOpen,
setArtifacts,
2026-01-24 23:51:11 +08:00
select: selectArtifact,
2026-01-17 11:02:33 +08:00
selectedArtifact,
} = useArtifacts();
2026-01-16 09:15:04 +08:00
const { thread_id: threadIdFromPath } = useParams<{ thread_id: string }>();
2026-01-31 22:31:25 +08:00
const searchParams = useSearchParams();
const promptInputController = usePromptInputController();
2026-01-31 22:31:25 +08:00
const inputInitialValue = useMemo(() => {
if (threadIdFromPath !== "new" || searchParams.get("mode") !== "skill") {
return undefined;
}
return t.inputBox.createSkillPrompt;
}, [threadIdFromPath, searchParams, t.inputBox.createSkillPrompt]);
useEffect(() => {
if (inputInitialValue) {
setTimeout(() => {
promptInputController.textInput.setInput(inputInitialValue);
2026-01-31 22:31:25 +08:00
const textarea = document.querySelector("textarea");
if (textarea) {
textarea.focus();
textarea.selectionStart = textarea.value.length;
textarea.selectionEnd = textarea.value.length;
}
}, 100);
}
}, [inputInitialValue, promptInputController.textInput]);
2026-01-16 09:15:04 +08:00
const isNewThread = useMemo(
() => threadIdFromPath === "new",
[threadIdFromPath],
);
const [threadId, setThreadId] = useState<string | null>(null);
useEffect(() => {
if (threadIdFromPath !== "new") {
setThreadId(threadIdFromPath);
} else {
setThreadId(uuid());
}
}, [threadIdFromPath]);
2026-01-17 11:02:33 +08:00
2026-01-31 11:08:27 +08:00
const { showNotification } = useNotification();
fix(frontend): no half-finished citations, correct state when SSE ends Citations: - In shouldShowCitationLoading, treat any unreplaced [cite-N] in cleanContent as show-loading (no body). Fixes Ultra and other modes when refs arrive before the <citations> block in the stream. - Single rule: hasUnreplacedCitationRefs(cleanContent) => true forces loading; then isLoading && hasCitationsBlock(rawContent) for streaming indicator. SSE end state: - When stream finishes, SDK may set isLoading=false before client state has the final message content, so UI stayed wrong until refresh. - Store onFinish(state) as finalState in chat page; clear when stream starts. - Pass messagesOverride={finalState.messages} to MessageList when not loading so the list uses server-complete messages right after SSE ends (no refresh). Chore: - Stop tracking .githooks/pre-commit; add .githooks/ to .gitignore (local only). Co-authored-by: Cursor <cursoragent@cursor.com> --- fix(前端): 杜绝半成品引用,SSE 结束时展示正确状态 引用: - shouldShowCitationLoading 中只要 cleanContent 仍含未替换的 [cite-N] 就 只显示加载、不渲染正文,解决流式时引用块未到就出现 [cite-1] 的问题。 - 规则:hasUnreplacedCitationRefs(cleanContent) 为真则一律显示加载; 此外 isLoading && hasCitationsBlock 用于流式时显示「正在整理引用」。 SSE 结束状态: - 流结束时 SDK 可能先置 isLoading=false,客户端 messages 尚未包含 最终内容,导致需刷新才显示正确。 - 在对话页保存 onFinish(state) 为 finalState,流开始时清空。 - 非加载时向 MessageList 传入 messagesOverride={finalState.messages}, 列表在 SSE 结束后立即用服务端完整消息渲染,无需刷新。 杂项: - 取消跟踪 .githooks/pre-commit,.gitignore 增加 .githooks/(仅本地)。
2026-02-09 15:15:20 +08:00
const [finalState, setFinalState] = useState<AgentThreadState | null>(null);
2026-01-16 14:03:34 +08:00
const thread = useThreadStream({
isNewThread,
threadId,
2026-01-31 11:08:27 +08:00
onFinish: (state) => {
fix(frontend): no half-finished citations, correct state when SSE ends Citations: - In shouldShowCitationLoading, treat any unreplaced [cite-N] in cleanContent as show-loading (no body). Fixes Ultra and other modes when refs arrive before the <citations> block in the stream. - Single rule: hasUnreplacedCitationRefs(cleanContent) => true forces loading; then isLoading && hasCitationsBlock(rawContent) for streaming indicator. SSE end state: - When stream finishes, SDK may set isLoading=false before client state has the final message content, so UI stayed wrong until refresh. - Store onFinish(state) as finalState in chat page; clear when stream starts. - Pass messagesOverride={finalState.messages} to MessageList when not loading so the list uses server-complete messages right after SSE ends (no refresh). Chore: - Stop tracking .githooks/pre-commit; add .githooks/ to .gitignore (local only). Co-authored-by: Cursor <cursoragent@cursor.com> --- fix(前端): 杜绝半成品引用,SSE 结束时展示正确状态 引用: - shouldShowCitationLoading 中只要 cleanContent 仍含未替换的 [cite-N] 就 只显示加载、不渲染正文,解决流式时引用块未到就出现 [cite-1] 的问题。 - 规则:hasUnreplacedCitationRefs(cleanContent) 为真则一律显示加载; 此外 isLoading && hasCitationsBlock 用于流式时显示「正在整理引用」。 SSE 结束状态: - 流结束时 SDK 可能先置 isLoading=false,客户端 messages 尚未包含 最终内容,导致需刷新才显示正确。 - 在对话页保存 onFinish(state) 为 finalState,流开始时清空。 - 非加载时向 MessageList 传入 messagesOverride={finalState.messages}, 列表在 SSE 结束后立即用服务端完整消息渲染,无需刷新。 杂项: - 取消跟踪 .githooks/pre-commit,.gitignore 增加 .githooks/(仅本地)。
2026-02-09 15:15:20 +08:00
setFinalState(state);
2026-01-31 11:08:27 +08:00
if (document.hidden || !document.hasFocus()) {
2026-01-31 20:22:15 +08:00
let body = "Conversation finished";
const lastMessage = state.messages[state.messages.length - 1];
if (lastMessage) {
const textContent = textOfMessage(lastMessage);
if (textContent) {
if (textContent.length > 200) {
body = textContent.substring(0, 200) + "...";
} else {
body = textContent;
}
}
}
2026-01-31 11:08:27 +08:00
showNotification(state.title, {
2026-01-31 20:22:15 +08:00
body,
2026-01-31 11:08:27 +08:00
});
}
},
2026-01-16 09:15:04 +08:00
});
fix(frontend): no half-finished citations, correct state when SSE ends Citations: - In shouldShowCitationLoading, treat any unreplaced [cite-N] in cleanContent as show-loading (no body). Fixes Ultra and other modes when refs arrive before the <citations> block in the stream. - Single rule: hasUnreplacedCitationRefs(cleanContent) => true forces loading; then isLoading && hasCitationsBlock(rawContent) for streaming indicator. SSE end state: - When stream finishes, SDK may set isLoading=false before client state has the final message content, so UI stayed wrong until refresh. - Store onFinish(state) as finalState in chat page; clear when stream starts. - Pass messagesOverride={finalState.messages} to MessageList when not loading so the list uses server-complete messages right after SSE ends (no refresh). Chore: - Stop tracking .githooks/pre-commit; add .githooks/ to .gitignore (local only). Co-authored-by: Cursor <cursoragent@cursor.com> --- fix(前端): 杜绝半成品引用,SSE 结束时展示正确状态 引用: - shouldShowCitationLoading 中只要 cleanContent 仍含未替换的 [cite-N] 就 只显示加载、不渲染正文,解决流式时引用块未到就出现 [cite-1] 的问题。 - 规则:hasUnreplacedCitationRefs(cleanContent) 为真则一律显示加载; 此外 isLoading && hasCitationsBlock 用于流式时显示「正在整理引用」。 SSE 结束状态: - 流结束时 SDK 可能先置 isLoading=false,客户端 messages 尚未包含 最终内容,导致需刷新才显示正确。 - 在对话页保存 onFinish(state) 为 finalState,流开始时清空。 - 非加载时向 MessageList 传入 messagesOverride={finalState.messages}, 列表在 SSE 结束后立即用服务端完整消息渲染,无需刷新。 杂项: - 取消跟踪 .githooks/pre-commit,.gitignore 增加 .githooks/(仅本地)。
2026-02-09 15:15:20 +08:00
useEffect(() => {
if (thread.isLoading) setFinalState(null);
}, [thread.isLoading]);
2026-01-31 11:08:27 +08:00
2026-01-17 15:48:43 +08:00
const title = useMemo(() => {
let result = isNewThread
? ""
: titleOfThread(thread as unknown as AgentThread);
if (result === "Untitled") {
result = "";
}
return result;
}, [thread, isNewThread]);
2026-01-17 00:02:03 +08:00
2026-02-02 09:05:24 +08:00
useEffect(() => {
const pageTitle = isNewThread
? t.pages.newChat
: thread.values?.title && thread.values.title !== "Untitled"
? thread.values.title
: t.pages.untitled;
if (thread.isThreadLoading) {
document.title = `Loading... - ${t.pages.appName}`;
} else {
document.title = `${pageTitle} - ${t.pages.appName}`;
}
}, [
isNewThread,
t.pages.newChat,
t.pages.untitled,
t.pages.appName,
thread.values.title,
thread.isThreadLoading,
]);
2026-01-24 23:59:41 +08:00
const [autoSelectFirstArtifact, setAutoSelectFirstArtifact] = useState(true);
useEffect(() => {
setArtifacts(thread.values.artifacts);
2026-01-24 23:59:41 +08:00
if (
env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true" &&
autoSelectFirstArtifact
) {
2026-01-24 23:51:11 +08:00
if (thread?.values?.artifacts?.length > 0) {
2026-01-24 23:59:41 +08:00
setAutoSelectFirstArtifact(false);
2026-01-24 23:51:11 +08:00
selectArtifact(thread.values.artifacts[0]!);
}
}
2026-01-24 23:59:41 +08:00
}, [
autoSelectFirstArtifact,
selectArtifact,
setArtifacts,
thread.values.artifacts,
]);
2026-01-25 21:57:57 +08:00
const artifactPanelOpen = useMemo(() => {
if (env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true") {
return artifactsOpen && artifacts?.length > 0;
}
return artifactsOpen;
}, [artifactsOpen, artifacts]);
const [todoListCollapsed, setTodoListCollapsed] = useState(true);
2026-01-22 00:26:11 +08:00
2026-01-16 19:51:39 +08:00
const handleSubmit = useSubmitThread({
isNewThread,
threadId,
thread,
threadContext: {
...settings.context,
thinking_enabled: settings.context.mode !== "flash",
2026-02-07 16:14:48 +08:00
is_plan_mode:
settings.context.mode === "pro" || settings.context.mode === "ultra",
2026-02-06 15:42:53 +08:00
subagent_enabled: settings.context.mode === "ultra",
},
2026-01-16 19:51:39 +08:00
afterSubmit() {
router.push(pathOfThread(threadId!));
2026-01-16 09:15:04 +08:00
},
2026-01-16 19:51:39 +08:00
});
2026-01-16 09:15:04 +08:00
const handleStop = useCallback(async () => {
await thread.stop();
}, [thread]);
2026-01-17 11:02:33 +08:00
2026-01-18 17:13:15 +08:00
if (!threadId) {
return null;
}
2026-01-16 09:15:04 +08:00
return (
2026-01-18 17:13:15 +08:00
<ThreadContext.Provider value={{ threadId, thread }}>
<ResizablePanelGroup orientation="horizontal">
<ResizablePanel
className="relative"
2026-01-25 21:57:57 +08:00
defaultSize={artifactPanelOpen ? 46 : 100}
minSize={artifactPanelOpen ? 30 : 100}
2026-01-18 17:13:15 +08:00
>
<div className="relative flex size-full min-h-0 justify-between">
2026-01-21 10:31:54 +08:00
<header
className={cn(
"absolute top-0 right-0 left-0 z-30 flex h-12 shrink-0 items-center px-4",
isNewThread
? "bg-background/0 backdrop-blur-none"
2026-01-27 13:15:49 +08:00
: "bg-background/80 shadow-xs backdrop-blur",
2026-01-21 10:31:54 +08:00
)}
>
2026-01-18 17:13:15 +08:00
<div className="flex w-full items-center text-sm font-medium">
{title !== "Untitled" && (
<ThreadTitle threadId={threadId} threadTitle={title} />
)}
</div>
<div>
{artifacts?.length > 0 && !artifactsOpen && (
2026-01-18 17:13:15 +08:00
<Tooltip content="Show artifacts of this conversation">
<Button
className="text-muted-foreground hover:text-foreground"
2026-01-18 17:13:15 +08:00
variant="ghost"
onClick={() => {
setArtifactsOpen(true);
setSidebarOpen(false);
}}
>
<FilesIcon />
2026-01-20 14:06:47 +08:00
{t.common.artifacts}
2026-01-18 17:13:15 +08:00
</Button>
</Tooltip>
)}
2026-01-18 17:13:15 +08:00
</div>
</header>
2026-02-02 10:02:31 +08:00
<main className="flex min-h-0 max-w-full grow flex-col">
2026-01-18 17:13:15 +08:00
<div className="flex size-full justify-center">
<MessageList
2026-01-27 13:15:49 +08:00
className={cn("size-full", !isNewThread && "pt-10")}
2026-01-18 17:13:15 +08:00
threadId={threadId}
thread={thread}
fix(frontend): no half-finished citations, correct state when SSE ends Citations: - In shouldShowCitationLoading, treat any unreplaced [cite-N] in cleanContent as show-loading (no body). Fixes Ultra and other modes when refs arrive before the <citations> block in the stream. - Single rule: hasUnreplacedCitationRefs(cleanContent) => true forces loading; then isLoading && hasCitationsBlock(rawContent) for streaming indicator. SSE end state: - When stream finishes, SDK may set isLoading=false before client state has the final message content, so UI stayed wrong until refresh. - Store onFinish(state) as finalState in chat page; clear when stream starts. - Pass messagesOverride={finalState.messages} to MessageList when not loading so the list uses server-complete messages right after SSE ends (no refresh). Chore: - Stop tracking .githooks/pre-commit; add .githooks/ to .gitignore (local only). Co-authored-by: Cursor <cursoragent@cursor.com> --- fix(前端): 杜绝半成品引用,SSE 结束时展示正确状态 引用: - shouldShowCitationLoading 中只要 cleanContent 仍含未替换的 [cite-N] 就 只显示加载、不渲染正文,解决流式时引用块未到就出现 [cite-1] 的问题。 - 规则:hasUnreplacedCitationRefs(cleanContent) 为真则一律显示加载; 此外 isLoading && hasCitationsBlock 用于流式时显示「正在整理引用」。 SSE 结束状态: - 流结束时 SDK 可能先置 isLoading=false,客户端 messages 尚未包含 最终内容,导致需刷新才显示正确。 - 在对话页保存 onFinish(state) 为 finalState,流开始时清空。 - 非加载时向 MessageList 传入 messagesOverride={finalState.messages}, 列表在 SSE 结束后立即用服务端完整消息渲染,无需刷新。 杂项: - 取消跟踪 .githooks/pre-commit,.gitignore 增加 .githooks/(仅本地)。
2026-02-09 15:15:20 +08:00
messagesOverride={
!thread.isLoading && finalState?.messages
? (finalState.messages as Message[])
: undefined
}
2026-01-22 00:26:11 +08:00
paddingBottom={todoListCollapsed ? 160 : 280}
2026-01-18 17:13:15 +08:00
/>
</div>
<div className="absolute right-0 bottom-0 left-0 z-30 flex justify-center px-4">
2026-01-17 19:46:02 +08:00
<div
className={cn(
2026-01-18 17:13:15 +08:00
"relative w-full",
2026-02-06 09:39:20 +08:00
isNewThread && "-translate-y-[calc(50vh-96px)]",
2026-01-18 17:13:15 +08:00
isNewThread
? "max-w-(--container-width-sm)"
: "max-w-(--container-width-md)",
2026-01-17 19:46:02 +08:00
)}
>
2026-01-22 09:41:01 +08:00
<div className="absolute -top-4 right-0 left-0 z-0">
2026-01-22 11:42:25 +08:00
<div className="absolute right-0 bottom-0 left-0">
2026-01-22 09:41:01 +08:00
<TodoList
className="bg-background/5"
todos={thread.values.todos ?? []}
collapsed={todoListCollapsed}
hidden={
!thread.values.todos ||
thread.values.todos.length === 0
}
onToggle={() =>
setTodoListCollapsed(!todoListCollapsed)
}
/>
</div>
</div>
2026-01-18 17:13:15 +08:00
<InputBox
2026-01-22 00:26:11 +08:00
className={cn("bg-background/5 w-full -translate-y-4")}
2026-01-22 14:28:10 +08:00
isNewThread={isNewThread}
2026-01-18 17:13:15 +08:00
autoFocus={isNewThread}
status={thread.isLoading ? "streaming" : "ready"}
context={settings.context}
2026-02-09 00:41:25 +08:00
extraHeader={
isNewThread && <Welcome mode={settings.context.mode} />
}
2026-01-24 18:01:27 +08:00
disabled={env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true"}
2026-01-18 17:13:15 +08:00
onContextChange={(context) =>
setSettings("context", context)
}
onSubmit={handleSubmit}
onStop={handleStop}
/>
2026-01-24 18:01:27 +08:00
{env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY === "true" && (
2026-02-02 16:40:43 +08:00
<div className="text-muted-foreground/67 w-full translate-y-12 text-center text-xs">
2026-01-24 18:01:27 +08:00
{t.common.notAvailableInDemoMode}
</div>
)}
2026-01-17 19:46:02 +08:00
</div>
</div>
2026-01-18 17:13:15 +08:00
</main>
</div>
</ResizablePanel>
<ResizableHandle
2026-01-17 11:02:33 +08:00
className={cn(
2026-01-21 08:50:15 +08:00
"opacity-33 hover:opacity-100",
2026-01-25 21:57:57 +08:00
!artifactPanelOpen && "pointer-events-none opacity-0",
2026-01-17 11:02:33 +08:00
)}
2026-01-18 17:13:15 +08:00
/>
<ResizablePanel
className={cn(
"transition-all duration-300 ease-in-out",
!artifactsOpen && "opacity-0",
)}
2026-01-25 21:57:57 +08:00
defaultSize={artifactPanelOpen ? 64 : 0}
2026-01-18 17:13:15 +08:00
minSize={0}
2026-01-25 21:57:57 +08:00
maxSize={artifactPanelOpen ? undefined : 0}
2026-01-17 11:02:33 +08:00
>
2026-01-18 17:13:15 +08:00
<div
className={cn(
2026-01-21 08:50:15 +08:00
"h-full p-4 transition-transform duration-300 ease-in-out",
2026-01-25 21:57:57 +08:00
artifactPanelOpen ? "translate-x-0" : "translate-x-full",
2026-01-18 17:13:15 +08:00
)}
>
{selectedArtifact ? (
<ArtifactFileDetail
className="size-full"
filepath={selectedArtifact}
threadId={threadId}
/>
) : (
<div className="relative flex size-full justify-center">
<div className="absolute top-1 right-1 z-30">
<Button
size="icon-sm"
variant="ghost"
onClick={() => {
setArtifactsOpen(false);
}}
>
<XIcon />
</Button>
</div>
2026-01-18 17:13:15 +08:00
{thread.values.artifacts?.length === 0 ? (
<ConversationEmptyState
icon={<FilesIcon />}
title="No artifact selected"
description="Select an artifact to view its details"
/>
) : (
<div className="flex size-full max-w-(--container-width-sm) flex-col justify-center p-4 pt-8">
<header className="shrink-0">
<h2 className="text-lg font-medium">Artifacts</h2>
</header>
<main className="min-h-0 grow">
<ArtifactFileList
className="max-w-(--container-width-sm) p-4 pt-12"
files={thread.values.artifacts ?? []}
threadId={threadId}
/>
</main>
</div>
)}
</div>
)}
</div>
</ResizablePanel>
</ResizablePanelGroup>
</ThreadContext.Provider>
2026-01-16 09:15:04 +08:00
);
}