Files
deer-flow/web/src/app/chat/components/research-report-block.tsx
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

73 lines
2.0 KiB
TypeScript

// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
// SPDX-License-Identifier: MIT
import { useCallback, useRef } from "react";
import { LoadingAnimation } from "~/components/deer-flow/loading-animation";
import { Markdown } from "~/components/deer-flow/markdown";
import ReportEditor from "~/components/editor";
import { useReplay } from "~/core/replay";
import { useMessage, useStore } from "~/core/store";
import { cn } from "~/lib/utils";
export function ResearchReportBlock({
className,
messageId,
editing,
}: {
className?: string;
researchId: string;
messageId: string;
editing: boolean;
}) {
const message = useMessage(messageId);
const { isReplay } = useReplay();
const handleMarkdownChange = useCallback(
(markdown: string) => {
if (message) {
message.content = markdown;
useStore.setState({
messages: new Map(useStore.getState().messages).set(
message.id,
message,
),
});
}
},
[message],
);
const contentRef = useRef<HTMLDivElement>(null);
const isCompleted = message?.isStreaming === false && message?.content !== "";
// TODO: scroll to top when completed, but it's not working
// useEffect(() => {
// if (isCompleted && contentRef.current) {
// setTimeout(() => {
// contentRef
// .current!.closest("[data-radix-scroll-area-viewport]")
// ?.scrollTo({
// top: 0,
// behavior: "smooth",
// });
// }, 500);
// }
// }, [isCompleted]);
return (
<div ref={contentRef} className={cn("w-full pt-4 pb-8", className)}>
{!isReplay && isCompleted && editing ? (
<ReportEditor
content={message?.content}
onMarkdownChange={handleMarkdownChange}
/>
) : (
<>
<Markdown animated checkLinkCredibility>
{message?.content}
</Markdown>
{message?.isStreaming && <LoadingAnimation className="my-12" />}
</>
)}
</div>
);
}