mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-20 04:44:46 +08:00
feat: support artifact preview
This commit is contained in:
20
frontend/src/core/artifacts/hooks.ts
Normal file
20
frontend/src/core/artifacts/hooks.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { loadArtifactContent } from "./loader";
|
||||
|
||||
export function useArtifactContent({
|
||||
filepath,
|
||||
threadId,
|
||||
enabled,
|
||||
}: {
|
||||
filepath: string;
|
||||
threadId: string;
|
||||
enabled?: boolean;
|
||||
}) {
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: ["artifact", filepath, threadId],
|
||||
queryFn: () => loadArtifactContent({ filepath, threadId }),
|
||||
enabled,
|
||||
});
|
||||
return { content: data, isLoading, error };
|
||||
}
|
||||
1
frontend/src/core/artifacts/index.ts
Normal file
1
frontend/src/core/artifacts/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./loader";
|
||||
14
frontend/src/core/artifacts/loader.ts
Normal file
14
frontend/src/core/artifacts/loader.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { urlOfArtifact } from "./utils";
|
||||
|
||||
export async function loadArtifactContent({
|
||||
filepath,
|
||||
threadId,
|
||||
}: {
|
||||
filepath: string;
|
||||
threadId: string;
|
||||
}) {
|
||||
const url = urlOfArtifact({ filepath, threadId });
|
||||
const response = await fetch(url);
|
||||
const text = await response.text();
|
||||
return text;
|
||||
}
|
||||
11
frontend/src/core/artifacts/utils.ts
Normal file
11
frontend/src/core/artifacts/utils.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export function urlOfArtifact({
|
||||
filepath,
|
||||
threadId,
|
||||
download = false,
|
||||
}: {
|
||||
filepath: string;
|
||||
threadId: string;
|
||||
download?: boolean;
|
||||
}) {
|
||||
return `http://localhost:8000/api/threads/${threadId}/artifacts${filepath}${download ? "?download=true" : ""}`;
|
||||
}
|
||||
Reference in New Issue
Block a user