fix(artifact): enhance artifact content loading to include URL for non-write files (#1678)
This commit is contained in:
parent
6ff60f2af1
commit
cf43584d24
|
|
@ -83,7 +83,7 @@ export function ArtifactFileDetail({
|
||||||
const isSupportPreview = useMemo(() => {
|
const isSupportPreview = useMemo(() => {
|
||||||
return language === "html" || language === "markdown";
|
return language === "html" || language === "markdown";
|
||||||
}, [language]);
|
}, [language]);
|
||||||
const { content } = useArtifactContent({
|
const { content, url } = useArtifactContent({
|
||||||
threadId,
|
threadId,
|
||||||
filepath: filepathFromProps,
|
filepath: filepathFromProps,
|
||||||
enabled: isCodeFile && !isWriteFile,
|
enabled: isCodeFile && !isWriteFile,
|
||||||
|
|
@ -240,7 +240,9 @@ export function ArtifactFileDetail({
|
||||||
(language === "markdown" || language === "html") && (
|
(language === "markdown" || language === "html") && (
|
||||||
<ArtifactFilePreview
|
<ArtifactFilePreview
|
||||||
content={displayContent}
|
content={displayContent}
|
||||||
|
isWriteFile={isWriteFile}
|
||||||
language={language ?? "text"}
|
language={language ?? "text"}
|
||||||
|
url={url}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{isCodeFile && viewMode === "code" && (
|
{isCodeFile && viewMode === "code" && (
|
||||||
|
|
@ -263,10 +265,14 @@ export function ArtifactFileDetail({
|
||||||
|
|
||||||
export function ArtifactFilePreview({
|
export function ArtifactFilePreview({
|
||||||
content,
|
content,
|
||||||
|
isWriteFile,
|
||||||
language,
|
language,
|
||||||
|
url,
|
||||||
}: {
|
}: {
|
||||||
content: string;
|
content: string;
|
||||||
|
isWriteFile: boolean;
|
||||||
language: string;
|
language: string;
|
||||||
|
url?: string;
|
||||||
}) {
|
}) {
|
||||||
if (language === "markdown") {
|
if (language === "markdown") {
|
||||||
return (
|
return (
|
||||||
|
|
@ -286,8 +292,8 @@ export function ArtifactFilePreview({
|
||||||
<iframe
|
<iframe
|
||||||
className="size-full"
|
className="size-full"
|
||||||
title="Artifact preview"
|
title="Artifact preview"
|
||||||
srcDoc={content}
|
|
||||||
sandbox="allow-scripts allow-forms"
|
sandbox="allow-scripts allow-forms"
|
||||||
|
{...(isWriteFile ? { srcDoc: content } : url ? { src: url } : {})}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,5 +34,10 @@ export function useArtifactContent({
|
||||||
// Cache artifact content for 5 minutes to avoid repeated fetches (especially for .skill ZIP extraction)
|
// Cache artifact content for 5 minutes to avoid repeated fetches (especially for .skill ZIP extraction)
|
||||||
staleTime: 5 * 60 * 1000,
|
staleTime: 5 * 60 * 1000,
|
||||||
});
|
});
|
||||||
return { content: isWriteFile ? content : data, isLoading, error };
|
return {
|
||||||
|
content: isWriteFile ? content : data?.content,
|
||||||
|
url: isWriteFile ? undefined : data?.url,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ export async function loadArtifactContent({
|
||||||
const url = urlOfArtifact({ filepath: enhancedFilepath, threadId, isMock });
|
const url = urlOfArtifact({ filepath: enhancedFilepath, threadId, isMock });
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
return text;
|
return { content: text, url };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadArtifactContentFromToolCall({
|
export function loadArtifactContentFromToolCall({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue