19fa1e97c3
* feat: implement backend logic * feat: implement api/config endpoint * rename the symbol * feat: re-implement configuration at client-side * feat: add client-side of deep thinking * fix backend bug * feat: add reasoning block * docs: update readme * fix: translate into English * fix: change icon to lightbulb * feat: ignore more bad cases * feat: adjust thinking layout, and implement auto scrolling * docs: add comments --------- Co-authored-by: Henry Li <henry1943@163.com>
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
import { env } from "~/env";
|
|
|
|
import { useReplay } from "../replay";
|
|
|
|
import { fetchReplayTitle } from "./chat";
|
|
import { getConfig } from "./config";
|
|
|
|
export function useReplayMetadata() {
|
|
const { isReplay } = useReplay();
|
|
const [title, setTitle] = useState<string | null>(null);
|
|
const isLoading = useRef(false);
|
|
const [error, setError] = useState<boolean>(false);
|
|
useEffect(() => {
|
|
if (!isReplay) {
|
|
return;
|
|
}
|
|
if (title || isLoading.current) {
|
|
return;
|
|
}
|
|
isLoading.current = true;
|
|
fetchReplayTitle()
|
|
.then((title) => {
|
|
setError(false);
|
|
setTitle(title ?? null);
|
|
if (title) {
|
|
document.title = `${title} - DeerFlow`;
|
|
}
|
|
})
|
|
.catch(() => {
|
|
setError(true);
|
|
setTitle("Error: the replay is not available.");
|
|
document.title = "DeerFlow";
|
|
})
|
|
.finally(() => {
|
|
isLoading.current = false;
|
|
});
|
|
}, [isLoading, isReplay, title]);
|
|
return { title, isLoading, hasError: error };
|
|
}
|
|
|
|
export function useRAGProvider() {
|
|
const [loading, setLoading] = useState(true);
|
|
const [provider, setProvider] = useState<string | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY) {
|
|
setLoading(false);
|
|
return;
|
|
}
|
|
setProvider(getConfig().rag.provider);
|
|
setLoading(false);
|
|
}, []);
|
|
|
|
return { provider, loading };
|
|
}
|