fix(frontend): address static demo PR review comments

This commit is contained in:
foreleven
2026-05-22 22:21:07 +08:00
parent 55a4149be4
commit bf94ae43fa
4 changed files with 92 additions and 7 deletions
@@ -1,8 +1,12 @@
import { isStaticWebsiteOnly } from "@/core/static-mode";
import { DEMO_THREAD_IDS } from "@/core/threads/static-demo";
import { ChatProviders } from "./providers";
export function generateStaticParams() {
if (!isStaticWebsiteOnly()) {
return [];
}
return DEMO_THREAD_IDS.map((thread_id) => ({ thread_id }));
}
@@ -325,11 +325,7 @@ export function ArtifactFilePreview({
<iframe
className="size-full"
title="Artifact preview"
sandbox={
isWriteFile
? "allow-scripts allow-forms"
: "allow-scripts allow-forms allow-same-origin"
}
sandbox="allow-scripts allow-forms"
src={isWriteFile ? undefined : htmlPreviewUrl}
srcDoc={isWriteFile ? content : undefined}
/>
+18 -2
View File
@@ -13,7 +13,10 @@ export function urlOfArtifact({
download?: boolean;
isMock?: boolean;
}) {
if (isMock || isStaticWebsiteOnly()) {
if (isStaticWebsiteOnly()) {
return staticDemoArtifactURL({ filepath, threadId, download });
}
if (isMock) {
return `${getBackendBaseURL()}/mock/api/threads/${threadId}/artifacts${filepath}${download ? "?download=true" : ""}`;
}
return `${getBackendBaseURL()}/api/threads/${threadId}/artifacts${filepath}${download ? "?download=true" : ""}`;
@@ -25,7 +28,20 @@ export function extractArtifactsFromThread(thread: AgentThread) {
export function resolveArtifactURL(absolutePath: string, threadId: string) {
if (isStaticWebsiteOnly()) {
return `${getBackendBaseURL()}/mock/api/threads/${threadId}/artifacts${absolutePath}`;
return staticDemoArtifactURL({ filepath: absolutePath, threadId });
}
return `${getBackendBaseURL()}/api/threads/${threadId}/artifacts${absolutePath}`;
}
function staticDemoArtifactURL({
filepath,
threadId,
download = false,
}: {
filepath: string;
threadId: string;
download?: boolean;
}) {
const demoPath = filepath.replace(/^\/mnt\//, "/");
return `${getBackendBaseURL()}/demo/threads/${threadId}${demoPath}${download ? "?download=true" : ""}`;
}