mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-18 20:14:44 +08:00
feat: support SSE write_file(0
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { useThread } from "@/components/workspace/messages/context";
|
||||
|
||||
import { loadArtifactContent } from "./loader";
|
||||
|
||||
@@ -11,10 +14,37 @@ export function useArtifactContent({
|
||||
threadId: string;
|
||||
enabled?: boolean;
|
||||
}) {
|
||||
const isWriteFile = useMemo(() => {
|
||||
return filepath.startsWith("write-file:");
|
||||
}, [filepath]);
|
||||
const { thread } = useThread();
|
||||
const content = useMemo(() => {
|
||||
if (isWriteFile) {
|
||||
const url = new URL(filepath);
|
||||
const toolCallId = url.searchParams.get("tool_call_id");
|
||||
const messageId = url.searchParams.get("message_id");
|
||||
if (messageId && toolCallId) {
|
||||
const message = thread.messages.find(
|
||||
(message) => message.id === messageId,
|
||||
);
|
||||
if (message?.type === "ai" && message.tool_calls) {
|
||||
const toolCall = message.tool_calls.find(
|
||||
(toolCall) => toolCall.id === toolCallId,
|
||||
);
|
||||
if (toolCall) {
|
||||
return toolCall.args.content;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, [filepath, isWriteFile, thread.messages]);
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: ["artifact", filepath, threadId],
|
||||
queryFn: () => loadArtifactContent({ filepath, threadId }),
|
||||
queryFn: () => {
|
||||
return loadArtifactContent({ filepath, threadId });
|
||||
},
|
||||
enabled,
|
||||
});
|
||||
return { content: data, isLoading, error };
|
||||
return { content: isWriteFile ? content : data, isLoading, error };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user