mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-19 12:24:46 +08:00
feat: set artifacts layout
This commit is contained in:
11
frontend/src/app/workspace/chats/[thread_id]/layout.tsx
Normal file
11
frontend/src/app/workspace/chats/[thread_id]/layout.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { ArtifactsProvider } from "@/components/workspace/artifacts";
|
||||||
|
|
||||||
|
export default function ChatLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return <ArtifactsProvider>{children}</ArtifactsProvider>;
|
||||||
|
}
|
||||||
@@ -1,41 +1,48 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { UseStream } from "@langchain/langgraph-sdk/react";
|
import { FilesIcon, XIcon } from "lucide-react";
|
||||||
import { useParams, useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
import { BreadcrumbItem } from "@/components/ui/breadcrumb";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
ResizableHandle,
|
ResizableHandle,
|
||||||
ResizablePanel,
|
ResizablePanel,
|
||||||
ResizablePanelGroup,
|
ResizablePanelGroup,
|
||||||
} from "@/components/ui/resizable";
|
} from "@/components/ui/resizable";
|
||||||
|
import { useSidebar } from "@/components/ui/sidebar";
|
||||||
import {
|
import {
|
||||||
ArtifactFileDetail,
|
ArtifactFileDetail,
|
||||||
ArtifactsProvider,
|
|
||||||
useArtifacts,
|
useArtifacts,
|
||||||
} from "@/components/workspace/artifacts";
|
} from "@/components/workspace/artifacts";
|
||||||
|
import { FlipDisplay } from "@/components/workspace/flip-display";
|
||||||
import { InputBox } from "@/components/workspace/input-box";
|
import { InputBox } from "@/components/workspace/input-box";
|
||||||
import { MessageList } from "@/components/workspace/messages";
|
import { MessageList } from "@/components/workspace/messages";
|
||||||
import {
|
import { Tooltip } from "@/components/workspace/tooltip";
|
||||||
WorkspaceContainer,
|
|
||||||
WorkspaceBody,
|
|
||||||
WorkspaceHeader,
|
|
||||||
} from "@/components/workspace/workspace-container";
|
|
||||||
import { useLocalSettings } from "@/core/settings";
|
import { useLocalSettings } from "@/core/settings";
|
||||||
import { type AgentThread, type AgentThreadState } from "@/core/threads";
|
import { type AgentThread } from "@/core/threads";
|
||||||
import { useSubmitThread, useThreadStream } from "@/core/threads/hooks";
|
import { useSubmitThread, useThreadStream } from "@/core/threads/hooks";
|
||||||
import { pathOfThread, titleOfThread } from "@/core/threads/utils";
|
import { pathOfThread, titleOfThread } from "@/core/threads/utils";
|
||||||
import { uuid } from "@/core/utils/uuid";
|
import { uuid } from "@/core/utils/uuid";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { ConversationEmptyState } from "@/components/ai-elements/conversation";
|
||||||
|
|
||||||
export default function ChatPage() {
|
export default function ChatPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [settings, setSettings] = useLocalSettings();
|
||||||
|
const { setOpen: setSidebarOpen } = useSidebar();
|
||||||
|
const {
|
||||||
|
open: artifactsOpen,
|
||||||
|
setOpen: setArtifactsOpen,
|
||||||
|
selectedArtifact,
|
||||||
|
} = useArtifacts();
|
||||||
|
|
||||||
const { thread_id: threadIdFromPath } = useParams<{ thread_id: string }>();
|
const { thread_id: threadIdFromPath } = useParams<{ thread_id: string }>();
|
||||||
const isNewThread = useMemo(
|
const isNewThread = useMemo(
|
||||||
() => threadIdFromPath === "new",
|
() => threadIdFromPath === "new",
|
||||||
[threadIdFromPath],
|
[threadIdFromPath],
|
||||||
);
|
);
|
||||||
const [threadId, setThreadId] = useState<string | null>(null);
|
const [threadId, setThreadId] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (threadIdFromPath !== "new") {
|
if (threadIdFromPath !== "new") {
|
||||||
setThreadId(threadIdFromPath);
|
setThreadId(threadIdFromPath);
|
||||||
@@ -43,44 +50,16 @@ export default function ChatPage() {
|
|||||||
setThreadId(uuid());
|
setThreadId(uuid());
|
||||||
}
|
}
|
||||||
}, [threadIdFromPath]);
|
}, [threadIdFromPath]);
|
||||||
|
|
||||||
const thread = useThreadStream({
|
const thread = useThreadStream({
|
||||||
isNewThread,
|
isNewThread,
|
||||||
threadId,
|
threadId,
|
||||||
});
|
});
|
||||||
return (
|
const title = useMemo(
|
||||||
<WorkspaceContainer>
|
() => (isNewThread ? "" : titleOfThread(thread as unknown as AgentThread)),
|
||||||
<WorkspaceHeader>
|
[thread, isNewThread],
|
||||||
<BreadcrumbItem className="hidden md:block">
|
|
||||||
{isNewThread
|
|
||||||
? "New"
|
|
||||||
: titleOfThread(thread as unknown as AgentThread)}
|
|
||||||
</BreadcrumbItem>
|
|
||||||
</WorkspaceHeader>
|
|
||||||
<WorkspaceBody>
|
|
||||||
<ArtifactsProvider>
|
|
||||||
<ThreadDetail
|
|
||||||
threadId={threadId}
|
|
||||||
thread={thread}
|
|
||||||
isNewThread={isNewThread}
|
|
||||||
/>
|
|
||||||
</ArtifactsProvider>
|
|
||||||
</WorkspaceBody>
|
|
||||||
</WorkspaceContainer>
|
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
function ThreadDetail({
|
|
||||||
threadId,
|
|
||||||
thread,
|
|
||||||
isNewThread,
|
|
||||||
}: {
|
|
||||||
threadId?: string | null;
|
|
||||||
thread: UseStream<AgentThreadState>;
|
|
||||||
isNewThread: boolean;
|
|
||||||
}) {
|
|
||||||
const router = useRouter();
|
|
||||||
const [settings, setSettings] = useLocalSettings();
|
|
||||||
const { open, selectedArtifact } = useArtifacts();
|
|
||||||
const handleSubmit = useSubmitThread({
|
const handleSubmit = useSubmitThread({
|
||||||
isNewThread,
|
isNewThread,
|
||||||
threadId,
|
threadId,
|
||||||
@@ -93,34 +72,106 @@ function ThreadDetail({
|
|||||||
const handleStop = useCallback(async () => {
|
const handleStop = useCallback(async () => {
|
||||||
await thread.stop();
|
await thread.stop();
|
||||||
}, [thread]);
|
}, [thread]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResizablePanelGroup orientation="horizontal">
|
<ResizablePanelGroup orientation="horizontal">
|
||||||
<ResizablePanel className="relative" defaultSize={46}>
|
<ResizablePanel
|
||||||
<div className="flex size-full justify-center">
|
className="relative"
|
||||||
<MessageList className="size-full" thread={thread} />
|
defaultSize={artifactsOpen ? 46 : 100}
|
||||||
</div>
|
minSize={30}
|
||||||
<div className="absolute right-0 bottom-0 left-0 flex justify-center px-4">
|
>
|
||||||
<InputBox
|
<div className="relative flex size-full min-h-0 justify-between">
|
||||||
className="w-full max-w-(--container-width-md)"
|
<header className="absolute top-0 right-0 left-0 z-30 flex h-12 shrink-0 items-center px-4 drop-shadow-2xl backdrop-blur">
|
||||||
autoFocus={isNewThread}
|
<div className="flex w-full items-center text-sm font-medium">
|
||||||
status={thread.isLoading ? "streaming" : "ready"}
|
<FlipDisplay
|
||||||
context={settings.context}
|
uniqueKey={title}
|
||||||
onContextChange={(context) => setSettings("context", context)}
|
className="w-fit overflow-hidden text-ellipsis whitespace-nowrap"
|
||||||
onSubmit={handleSubmit}
|
>
|
||||||
onStop={handleStop}
|
{title}
|
||||||
/>
|
</FlipDisplay>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{!artifactsOpen && (
|
||||||
|
<Tooltip content="Show artifacts">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => {
|
||||||
|
setArtifactsOpen(true);
|
||||||
|
setSidebarOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FilesIcon />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<main className="flex min-h-0 grow flex-col">
|
||||||
|
<div className="flex size-full justify-center">
|
||||||
|
<MessageList className="size-full" thread={thread} />
|
||||||
|
</div>
|
||||||
|
<div className="absolute right-0 bottom-0 left-0 flex justify-center px-4">
|
||||||
|
<InputBox
|
||||||
|
className="w-full max-w-(--container-width-md)"
|
||||||
|
autoFocus={isNewThread}
|
||||||
|
status={thread.isLoading ? "streaming" : "ready"}
|
||||||
|
context={settings.context}
|
||||||
|
onContextChange={(context) => setSettings("context", context)}
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
onStop={handleStop}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</ResizablePanel>
|
||||||
|
<ResizableHandle
|
||||||
|
className={cn(
|
||||||
|
"transition-opacity duration-300",
|
||||||
|
!artifactsOpen && "pointer-events-none opacity-0",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<ResizablePanel
|
||||||
|
className={cn(
|
||||||
|
"transition-all duration-300 ease-in-out",
|
||||||
|
!artifactsOpen && "opacity-0",
|
||||||
|
)}
|
||||||
|
defaultSize={artifactsOpen ? 64 : 0}
|
||||||
|
minSize={0}
|
||||||
|
>
|
||||||
|
<div className="absolute top-1 right-1 z-30">
|
||||||
|
<Button
|
||||||
|
size="icon-sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => {
|
||||||
|
setArtifactsOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<XIcon />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"h-full transition-transform duration-300 ease-in-out",
|
||||||
|
artifactsOpen ? "translate-x-0" : "translate-x-full",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{selectedArtifact ? (
|
||||||
|
<ArtifactFileDetail
|
||||||
|
className="size-full"
|
||||||
|
filepath={selectedArtifact}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="flex size-full items-center justify-center">
|
||||||
|
<ConversationEmptyState
|
||||||
|
icon={<FilesIcon />}
|
||||||
|
title="No artifact selected"
|
||||||
|
description="Select an artifact to view its details"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
{open && (
|
|
||||||
<>
|
|
||||||
<ResizableHandle />
|
|
||||||
<ResizablePanel defaultSize={64}>
|
|
||||||
{selectedArtifact && (
|
|
||||||
<ArtifactFileDetail filepath={selectedArtifact} />
|
|
||||||
)}
|
|
||||||
</ResizablePanel>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</ResizablePanelGroup>
|
</ResizablePanelGroup>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export default function WorkspaceLayout({
|
|||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<SidebarProvider
|
<SidebarProvider
|
||||||
|
className="h-screen"
|
||||||
style={
|
style={
|
||||||
{
|
{
|
||||||
"--sidebar-width": "calc(var(--spacing) * 72)",
|
"--sidebar-width": "calc(var(--spacing) * 72)",
|
||||||
|
|||||||
@@ -1,23 +1,22 @@
|
|||||||
import { FileIcon, XIcon } from "lucide-react";
|
import { FileIcon } from "lucide-react";
|
||||||
import { useCallback } from "react";
|
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
import { useArtifacts } from "./context";
|
export function ArtifactFileDetail({
|
||||||
|
className,
|
||||||
export function ArtifactFileDetail({ filepath }: { filepath: string }) {
|
filepath,
|
||||||
const { setOpen } = useArtifacts();
|
}: {
|
||||||
const handleClose = useCallback(() => {
|
className?: string;
|
||||||
setOpen(false);
|
filepath: string;
|
||||||
}, [setOpen]);
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="relative flex size-full items-center justify-center">
|
<div
|
||||||
<div className="absolute top-1 right-1">
|
className={cn(
|
||||||
<Button size="icon-sm" variant="ghost" onClick={handleClose}>
|
"relative flex size-full items-center justify-center",
|
||||||
<XIcon />
|
className,
|
||||||
</Button>
|
)}
|
||||||
</div>
|
>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex size-fit items-center gap-2">
|
||||||
<div>
|
<div>
|
||||||
<FileIcon />
|
<FileIcon />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { createContext, useContext, useState, type ReactNode } from "react";
|
import { createContext, useContext, useState, type ReactNode } from "react";
|
||||||
|
|
||||||
|
import { useSidebar } from "@/components/ui/sidebar";
|
||||||
|
|
||||||
export interface ArtifactsContextType {
|
export interface ArtifactsContextType {
|
||||||
artifacts: string[];
|
artifacts: string[];
|
||||||
selectedArtifact: string | null;
|
selectedArtifact: string | null;
|
||||||
@@ -23,6 +25,7 @@ export function ArtifactsProvider({ children }: ArtifactsProviderProps) {
|
|||||||
const [artifacts, setArtifacts] = useState<string[]>([]);
|
const [artifacts, setArtifacts] = useState<string[]>([]);
|
||||||
const [selectedArtifact, setSelectedArtifact] = useState<string | null>(null);
|
const [selectedArtifact, setSelectedArtifact] = useState<string | null>(null);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const { setOpen: setSidebarOpen } = useSidebar();
|
||||||
|
|
||||||
const addArtifacts = (newArtifacts: string[]) => {
|
const addArtifacts = (newArtifacts: string[]) => {
|
||||||
setArtifacts((prev) => [...prev, ...newArtifacts]);
|
setArtifacts((prev) => [...prev, ...newArtifacts]);
|
||||||
@@ -31,6 +34,7 @@ export function ArtifactsProvider({ children }: ArtifactsProviderProps) {
|
|||||||
const openArtifact = (artifact: string) => {
|
const openArtifact = (artifact: string) => {
|
||||||
setSelectedArtifact(artifact);
|
setSelectedArtifact(artifact);
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
|
setSidebarOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const value: ArtifactsContextType = {
|
const value: ArtifactsContextType = {
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ export function MessageList({
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Conversation
|
<Conversation
|
||||||
className={cn("flex size-full flex-col justify-center pt-2", className)}
|
className={cn("flex size-full flex-col justify-center", className)}
|
||||||
>
|
>
|
||||||
<ConversationContent className="mx-auto w-full max-w-(--container-width-md) gap-10">
|
<ConversationContent className="mx-auto w-full max-w-(--container-width-md) gap-10 pt-12">
|
||||||
{groupMessages(
|
{groupMessages(
|
||||||
thread.messages,
|
thread.messages,
|
||||||
(groupedMessages) => {
|
(groupedMessages) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user