feat: support artifact preview

This commit is contained in:
Henry Li
2026-01-17 15:09:44 +08:00
parent ec5bbf6b51
commit 962d8f04ec
16 changed files with 482 additions and 42 deletions

View 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 };
}

View File

@@ -0,0 +1 @@
export * from "./loader";

View 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;
}

View 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" : ""}`;
}