mirror of
https://git.mirrors.martin98.com/https://github.com/bytedance/deer-flow
synced 2025-08-20 10:19:13 +08:00
feat: add openResearch and closeResearch
This commit is contained in:
parent
fa7d38db4b
commit
2dad50a95f
@ -16,6 +16,7 @@ import {
|
|||||||
} from "~/components/ui/card";
|
} from "~/components/ui/card";
|
||||||
import type { Message, Option } from "~/core/messages";
|
import type { Message, Option } from "~/core/messages";
|
||||||
import {
|
import {
|
||||||
|
closeResearch,
|
||||||
openResearch,
|
openResearch,
|
||||||
useMessage,
|
useMessage,
|
||||||
useResearchTitle,
|
useResearchTitle,
|
||||||
@ -209,7 +210,7 @@ function MessageListItem({
|
|||||||
className={cn(
|
className={cn(
|
||||||
`flex w-fit max-w-[85%] flex-col rounded-2xl px-4 py-3 shadow`,
|
`flex w-fit max-w-[85%] flex-col rounded-2xl px-4 py-3 shadow`,
|
||||||
message.role === "user" &&
|
message.role === "user" &&
|
||||||
"text-primary-foreground bg-brand rounded-ee-none",
|
"text-primary-foreground bg-brand rounded-ee-none",
|
||||||
message.role === "assistant" && "bg-card rounded-es-none",
|
message.role === "assistant" && "bg-card rounded-es-none",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
@ -245,7 +246,7 @@ function MessageListItem({
|
|||||||
const title = useResearchTitle(researchId);
|
const title = useResearchTitle(researchId);
|
||||||
const handleOpen = useCallback(() => {
|
const handleOpen = useCallback(() => {
|
||||||
if (openResearchId === researchId) {
|
if (openResearchId === researchId) {
|
||||||
openResearch(null);
|
closeResearch();
|
||||||
} else {
|
} else {
|
||||||
openResearch(researchId);
|
openResearch(researchId);
|
||||||
}
|
}
|
||||||
@ -318,11 +319,10 @@ function PlanCard({
|
|||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>
|
<CardTitle>
|
||||||
<Markdown animate>
|
<Markdown animate>
|
||||||
{`### ${
|
{`### ${plan.title !== undefined && plan.title !== ""
|
||||||
plan.title !== undefined && plan.title !== ""
|
? plan.title
|
||||||
? plan.title
|
: "Deep Research"
|
||||||
: "Deep Research"
|
}`}
|
||||||
}`}
|
|
||||||
</Markdown>
|
</Markdown>
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import { Button } from "~/components/ui/button";
|
|||||||
import { Card } from "~/components/ui/card";
|
import { Card } from "~/components/ui/card";
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs";
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs";
|
||||||
import { useReplay } from "~/core/replay";
|
import { useReplay } from "~/core/replay";
|
||||||
import { listenToPodcast, openResearch, useStore } from "~/core/store";
|
import { closeResearch, listenToPodcast, useStore } from "~/core/store";
|
||||||
import { cn } from "~/lib/utils";
|
import { cn } from "~/lib/utils";
|
||||||
|
|
||||||
import { ResearchActivitiesBlock } from "./research-activities-block";
|
import { ResearchActivitiesBlock } from "./research-activities-block";
|
||||||
@ -102,9 +102,7 @@ export function ResearchBlock({
|
|||||||
className="text-gray-400"
|
className="text-gray-400"
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => {
|
onClick={() => { closeResearch(); }}
|
||||||
openResearch(null);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<X />
|
<X />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -28,7 +28,9 @@ export const useStore = create<{
|
|||||||
appendMessage: (message: Message) => void;
|
appendMessage: (message: Message) => void;
|
||||||
updateMessage: (message: Message) => void;
|
updateMessage: (message: Message) => void;
|
||||||
updateMessages: (messages: Message[]) => void;
|
updateMessages: (messages: Message[]) => void;
|
||||||
setOngoingResearchId: (value: string | null) => void;
|
openResearch: (researchId: string | null) => void;
|
||||||
|
closeResearch: () => void;
|
||||||
|
setOngoingResearch: (researchId: string | null) => void;
|
||||||
}>((set) => ({
|
}>((set) => ({
|
||||||
responding: false,
|
responding: false,
|
||||||
threadId: THREAD_ID,
|
threadId: THREAD_ID,
|
||||||
@ -57,8 +59,14 @@ export const useStore = create<{
|
|||||||
return { messages: newMessages };
|
return { messages: newMessages };
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setOngoingResearchId(value: string | null) {
|
openResearch(researchId: string | null) {
|
||||||
set({ ongoingResearchId: value });
|
set({ openResearchId: researchId });
|
||||||
|
},
|
||||||
|
closeResearch() {
|
||||||
|
set({ openResearchId: null });
|
||||||
|
},
|
||||||
|
setOngoingResearch(researchId: string | null) {
|
||||||
|
set({ ongoingResearchId: researchId });
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -133,7 +141,7 @@ export async function sendMessage(
|
|||||||
useStore.getState().updateMessage(message);
|
useStore.getState().updateMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
useStore.getState().setOngoingResearchId(null);
|
useStore.getState().setOngoingResearch(null);
|
||||||
} finally {
|
} finally {
|
||||||
setResponding(false);
|
setResponding(false);
|
||||||
}
|
}
|
||||||
@ -191,7 +199,7 @@ function updateMessage(message: Message) {
|
|||||||
message.agent === "reporter" &&
|
message.agent === "reporter" &&
|
||||||
!message.isStreaming
|
!message.isStreaming
|
||||||
) {
|
) {
|
||||||
useStore.getState().setOngoingResearchId(null);
|
useStore.getState().setOngoingResearch(null);
|
||||||
}
|
}
|
||||||
useStore.getState().updateMessage(message);
|
useStore.getState().updateMessage(message);
|
||||||
}
|
}
|
||||||
@ -248,9 +256,11 @@ function appendResearchActivity(message: Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function openResearch(researchId: string | null) {
|
export function openResearch(researchId: string | null) {
|
||||||
useStore.setState({
|
useStore.getState().openResearch(researchId);
|
||||||
openResearchId: researchId,
|
}
|
||||||
});
|
|
||||||
|
export function closeResearch() {
|
||||||
|
useStore.getState().closeResearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listenToPodcast(researchId: string) {
|
export async function listenToPodcast(researchId: string) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user