Initial commit: deerflow-server (frontend-web + offline-backend-20260512)
This commit is contained in:
commit
e7a455f22e
560 files changed
+101331
No files matched your search
@@ -0,0 +1,43 @@
|
||||
"use client";
|
||||
|
||||
import { useParams, usePathname, useSearchParams } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { uuid } from "@/core/utils/uuid";
|
||||
|
||||
export function useThreadChat() {
|
||||
const { thread_id: threadIdFromPath } = useParams<{ thread_id: string }>();
|
||||
const pathname = usePathname();
|
||||
|
||||
const searchParams = useSearchParams();
|
||||
const [threadId, setThreadId] = useState(() => {
|
||||
return threadIdFromPath === "new" ? uuid() : threadIdFromPath;
|
||||
});
|
||||
|
||||
const [isNewThread, setIsNewThread] = useState(
|
||||
() => threadIdFromPath === "new",
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const onNewChatPath =
|
||||
pathname.endsWith("/new") ||
|
||||
(pathname === "/" && threadIdFromPath === "new");
|
||||
if (onNewChatPath) {
|
||||
setIsNewThread(true);
|
||||
setThreadId(uuid());
|
||||
return;
|
||||
}
|
||||
// Guard: after history.replaceState updates the URL from /chats/new to
|
||||
// /chats/{UUID}, Next.js useParams may still return the stale "new" value
|
||||
// because replaceState does not trigger router updates. Avoid propagating
|
||||
// this invalid thread ID to downstream hooks (e.g. useStream), which would
|
||||
// cause a 422 from LangGraph Server.
|
||||
if (threadIdFromPath === "new") {
|
||||
return;
|
||||
}
|
||||
setIsNewThread(false);
|
||||
setThreadId(threadIdFromPath);
|
||||
}, [pathname, threadIdFromPath]);
|
||||
const isMock = searchParams.get("mock") === "true";
|
||||
return { threadId, setThreadId, isNewThread, setIsNewThread, isMock };
|
||||
}
|
||||
Reference in new issue
Block a user