From e9846c1dda4640984ff6af7cdd1c8498f4d72a63 Mon Sep 17 00:00:00 2001 From: Henry Li Date: Fri, 16 Jan 2026 09:13:02 +0800 Subject: [PATCH] refactor: refine folder structure and rename --- .../app/workspace/chats/[thread_id]/page.tsx | 22 +++++++++++++------ .../workspace/threads/[thread_id]/page.tsx | 4 ++-- .../src/components/workspace/input-box.tsx | 12 +++++++++- .../workspace/message-list/message-group.tsx | 9 ++++---- .../message-list/message-list-item.tsx | 6 ++++- .../workspace/message-list/message-list.tsx | 6 ++--- .../components/workspace/recent-chat-list.tsx | 2 +- frontend/src/core/api/hooks.ts | 10 ++++----- .../message-list => core/messages}/utils.ts | 0 frontend/src/core/thread/types.ts | 8 ------- .../src/core/{thread => threads}/index.ts | 0 frontend/src/core/threads/types.ts | 15 +++++++++++++ .../src/core/{thread => threads}/utils.ts | 8 +++---- 13 files changed, 65 insertions(+), 37 deletions(-) rename frontend/src/{components/workspace/message-list => core/messages}/utils.ts (100%) delete mode 100644 frontend/src/core/thread/types.ts rename frontend/src/core/{thread => threads}/index.ts (100%) create mode 100644 frontend/src/core/threads/types.ts rename frontend/src/core/{thread => threads}/utils.ts (71%) diff --git a/frontend/src/app/workspace/chats/[thread_id]/page.tsx b/frontend/src/app/workspace/chats/[thread_id]/page.tsx index c3bc011..47faa64 100644 --- a/frontend/src/app/workspace/chats/[thread_id]/page.tsx +++ b/frontend/src/app/workspace/chats/[thread_id]/page.tsx @@ -17,8 +17,12 @@ import { WorkspaceFooter, } from "@/components/workspace/workspace-container"; import { getLangGraphClient } from "@/core/api"; -import type { MessageThread, MessageThreadState } from "@/core/thread"; -import { titleOfThread } from "@/core/thread/utils"; +import type { + AgentThread, + AgentThreadContext, + AgentThreadState, +} from "@/core/threads"; +import { titleOfThread } from "@/core/threads/utils"; import { uuid } from "@/core/utils/uuid"; const langGraphClient = getLangGraphClient(); @@ -32,6 +36,11 @@ export default function ChatPage() { [threadIdFromPath], ); const [threadId, setThreadId] = useState(null); + const [threadContext, setThreadContext] = useState({ + thread_id: "", + model: "deepseek-v3.2", + thinking_enabled: true, + }); useEffect(() => { if (threadIdFromPath !== "new") { setThreadId(threadIdFromPath); @@ -39,7 +48,7 @@ export default function ChatPage() { setThreadId(uuid()); } }, [threadIdFromPath]); - const thread = useStream({ + const thread = useStream({ client: langGraphClient, assistantId: "lead_agent", threadId: !isNewThread ? threadId : undefined, @@ -74,15 +83,14 @@ export default function ChatPage() { streamSubgraphs: true, streamResumable: true, context: { + ...threadContext, thread_id: threadId!, - model: "deepseek-v3.2", - thinking_enabled: true, }, }, ); void queryClient.invalidateQueries({ queryKey: ["threads", "search"] }); }, - [isNewThread, queryClient, router, thread, threadId], + [isNewThread, queryClient, router, thread, threadContext, threadId], ); const handleStop = useCallback(async () => { await thread.stop(); @@ -93,7 +101,7 @@ export default function ChatPage() { {isNewThread ? "New" - : titleOfThread(thread as unknown as MessageThread)} + : titleOfThread(thread as unknown as AgentThread)} diff --git a/frontend/src/app/workspace/threads/[thread_id]/page.tsx b/frontend/src/app/workspace/threads/[thread_id]/page.tsx index 0b71518..4562f83 100644 --- a/frontend/src/app/workspace/threads/[thread_id]/page.tsx +++ b/frontend/src/app/workspace/threads/[thread_id]/page.tsx @@ -4,13 +4,13 @@ import { useStream } from "@langchain/langgraph-sdk/react"; import { useParams } from "next/navigation"; import { getLangGraphClient } from "@/core/api"; -import type { MessageThreadState } from "@/core/thread"; +import type { AgentThreadState } from "@/core/threads"; const apiClient = getLangGraphClient(); export default function TestPage() { const { thread_id: threadId } = useParams<{ thread_id: string }>(); - const thread = useStream({ + const thread = useStream({ client: apiClient, assistantId: "lead_agent", threadId, diff --git a/frontend/src/components/workspace/input-box.tsx b/frontend/src/components/workspace/input-box.tsx index cf8820a..d8cd5b2 100644 --- a/frontend/src/components/workspace/input-box.tsx +++ b/frontend/src/components/workspace/input-box.tsx @@ -1,9 +1,11 @@ import type { ChatStatus } from "ai"; +import { LightbulbIcon, LightbulbOffIcon } from "lucide-react"; import { useCallback, type ComponentProps } from "react"; import { PromptInput, PromptInputBody, + PromptInputButton, PromptInputFooter, PromptInputSubmit, PromptInputTextarea, @@ -11,6 +13,8 @@ import { } from "@/components/ai-elements/prompt-input"; import { cn } from "@/lib/utils"; +import { Tooltip } from "./tooltip"; + export function InputBox({ className, autoFocus, @@ -57,7 +61,13 @@ export function InputBox({ /> -
+
+ + + + + +
; + thread: UseStream; }) { if (thread.isThreadLoading) { return ; diff --git a/frontend/src/components/workspace/recent-chat-list.tsx b/frontend/src/components/workspace/recent-chat-list.tsx index 65f919a..c69c002 100644 --- a/frontend/src/components/workspace/recent-chat-list.tsx +++ b/frontend/src/components/workspace/recent-chat-list.tsx @@ -21,7 +21,7 @@ import { SidebarMenuItem, } from "@/components/ui/sidebar"; import { useDeleteThread, useThreads } from "@/core/api"; -import { pathOfThread, titleOfThread } from "@/core/thread/utils"; +import { pathOfThread, titleOfThread } from "@/core/threads/utils"; export function RecentChatList() { const router = useRouter(); diff --git a/frontend/src/core/api/hooks.ts b/frontend/src/core/api/hooks.ts index dfaa80c..a24f7be 100644 --- a/frontend/src/core/api/hooks.ts +++ b/frontend/src/core/api/hooks.ts @@ -1,7 +1,7 @@ import type { ThreadsClient } from "@langchain/langgraph-sdk/client"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import type { MessageThread, MessageThreadState } from "../thread"; +import type { AgentThread, AgentThreadState } from "../threads"; import { getLangGraphClient } from "./client"; @@ -13,12 +13,12 @@ export function useThreads( }, ) { const langGraphClient = getLangGraphClient(); - return useQuery({ + return useQuery({ queryKey: ["threads", "search", params], queryFn: async () => { const response = - await langGraphClient.threads.search(params); - return response as MessageThread[]; + await langGraphClient.threads.search(params); + return response as AgentThread[]; }, }); } @@ -36,7 +36,7 @@ export function useDeleteThread() { queryKey: ["threads", "search"], exact: false, }, - (oldData: Array) => { + (oldData: Array) => { return oldData.filter((t) => t.thread_id !== threadId); }, ); diff --git a/frontend/src/components/workspace/message-list/utils.ts b/frontend/src/core/messages/utils.ts similarity index 100% rename from frontend/src/components/workspace/message-list/utils.ts rename to frontend/src/core/messages/utils.ts diff --git a/frontend/src/core/thread/types.ts b/frontend/src/core/thread/types.ts deleted file mode 100644 index e78b514..0000000 --- a/frontend/src/core/thread/types.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { type BaseMessage } from "@langchain/core/messages"; -import type { Thread } from "@langchain/langgraph-sdk"; - -export interface MessageThreadState extends Record { - messages: BaseMessage[]; -} - -export interface MessageThread extends Thread {} diff --git a/frontend/src/core/thread/index.ts b/frontend/src/core/threads/index.ts similarity index 100% rename from frontend/src/core/thread/index.ts rename to frontend/src/core/threads/index.ts diff --git a/frontend/src/core/threads/types.ts b/frontend/src/core/threads/types.ts new file mode 100644 index 0000000..eb59a2a --- /dev/null +++ b/frontend/src/core/threads/types.ts @@ -0,0 +1,15 @@ +import { type BaseMessage } from "@langchain/core/messages"; +import type { Thread } from "@langchain/langgraph-sdk"; + +export interface AgentThreadState extends Record { + title: string; + messages: BaseMessage[]; +} + +export interface AgentThread extends Thread {} + +export interface AgentThreadContext extends Record { + thread_id: string; + model: string; + thinking_enabled: boolean; +} diff --git a/frontend/src/core/thread/utils.ts b/frontend/src/core/threads/utils.ts similarity index 71% rename from frontend/src/core/thread/utils.ts rename to frontend/src/core/threads/utils.ts index 295d78e..bf03e87 100644 --- a/frontend/src/core/thread/utils.ts +++ b/frontend/src/core/threads/utils.ts @@ -1,8 +1,8 @@ import type { BaseMessage } from "@langchain/core/messages"; -import type { MessageThread } from "./types"; +import type { AgentThread } from "./types"; -export function pathOfThread(thread: MessageThread, includeAssistantId = true) { +export function pathOfThread(thread: AgentThread, includeAssistantId = true) { if (includeAssistantId) { return `/workspace/chats/${thread.thread_id}`; } @@ -19,9 +19,9 @@ export function textOfMessage(message: BaseMessage) { return null; } -export function titleOfThread(thread: MessageThread) { +export function titleOfThread(thread: AgentThread) { if (thread.values && "title" in thread.values) { - return thread.values.title as string; + return thread.values.title; } return "Untitled"; }