fix(artifact): enhance artifact content loading to include URL for non-write files (#1678)

This commit is contained in:
JeffJiang 2026-04-01 11:38:55 +08:00 committed by GitHub
parent 6ff60f2af1
commit cf43584d24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 4 deletions

View File

@ -83,7 +83,7 @@ export function ArtifactFileDetail({
const isSupportPreview = useMemo(() => {
return language === "html" || language === "markdown";
}, [language]);
const { content } = useArtifactContent({
const { content, url } = useArtifactContent({
threadId,
filepath: filepathFromProps,
enabled: isCodeFile && !isWriteFile,
@ -240,7 +240,9 @@ export function ArtifactFileDetail({
(language === "markdown" || language === "html") && (
<ArtifactFilePreview
content={displayContent}
isWriteFile={isWriteFile}
language={language ?? "text"}
url={url}
/>
)}
{isCodeFile && viewMode === "code" && (
@ -263,10 +265,14 @@ export function ArtifactFileDetail({
export function ArtifactFilePreview({
content,
isWriteFile,
language,
url,
}: {
content: string;
isWriteFile: boolean;
language: string;
url?: string;
}) {
if (language === "markdown") {
return (
@ -286,8 +292,8 @@ export function ArtifactFilePreview({
<iframe
className="size-full"
title="Artifact preview"
srcDoc={content}
sandbox="allow-scripts allow-forms"
{...(isWriteFile ? { srcDoc: content } : url ? { src: url } : {})}
/>
);
}

View File

@ -34,5 +34,10 @@ export function useArtifactContent({
// Cache artifact content for 5 minutes to avoid repeated fetches (especially for .skill ZIP extraction)
staleTime: 5 * 60 * 1000,
});
return { content: isWriteFile ? content : data, isLoading, error };
return {
content: isWriteFile ? content : data?.content,
url: isWriteFile ? undefined : data?.url,
isLoading,
error,
};
}

View File

@ -20,7 +20,7 @@ export async function loadArtifactContent({
const url = urlOfArtifact({ filepath: enhancedFilepath, threadId, isMock });
const response = await fetch(url);
const text = await response.text();
return text;
return { content: text, url };
}
export function loadArtifactContentFromToolCall({