Files
deer-flow/web/src/core/api/hooks.ts
T
JeffJiang 462752b462 feat: RAG Integration (#238)
* feat: add rag provider and retriever

* feat: retriever tool

* feat: add retriever tool to the researcher node

* feat: add rag http apis

* feat: new message input supports resource mentions

* feat: new message input component support resource mentions

* refactor: need_web_search to need_search

* chore: RAG integration docs

* chore: change example api host

* fix: user message color in dark mode

* fix: mentions style

* feat: add local_search_tool to researcher prompt

* chore: research prompt

* fix: ragflow page size and reporter with

* docs: ragflow integration and add acknowledgment projects

* chore: format
2025-05-28 14:13:46 +08:00

68 lines
1.7 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 { getRAGConfig } from "./rag";
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;
}
getRAGConfig()
.then(setProvider)
.catch((e) => {
setProvider(null);
console.error("Failed to get RAG provider", e);
})
.finally(() => {
setLoading(false);
});
}, []);
return { provider, loading };
}