fix(front): stabilize artifact paths during streaming (#4094)

This commit is contained in:
Huixin615
2026-07-12 09:00:12 +08:00
committed by GitHub
parent 88b0484898
commit 7bdf9412cc
3 changed files with 19 additions and 2 deletions
@@ -691,6 +691,8 @@ export function MessageList({
return <MessageListSkeleton />;
}
const artifactPaths = extractArtifactsFromThread(thread);
return (
<>
<Conversation
@@ -731,7 +733,7 @@ export function MessageList({
groupIndex === groupedMessages.length - 1
}
threadId={threadId}
artifactPaths={extractArtifactsFromThread(thread)}
artifactPaths={artifactPaths}
runId={
group.type === "assistant"
? (msg as { run_id?: string }).run_id
+3 -1
View File
@@ -2,6 +2,8 @@ import { getBackendBaseURL } from "../config";
import { isStaticWebsiteOnly } from "../static-mode";
import type { AgentThreadState } from "../threads";
const EMPTY_ARTIFACT_PATHS: readonly string[] = [];
export function urlOfArtifact({
filepath,
threadId,
@@ -25,7 +27,7 @@ export function urlOfArtifact({
export function extractArtifactsFromThread(thread: {
values: Pick<AgentThreadState, "artifacts">;
}) {
return thread.values.artifacts ?? [];
return thread.values.artifacts ?? EMPTY_ARTIFACT_PATHS;
}
export function resolveArtifactURL(absolutePath: string, threadId: string) {
@@ -74,6 +74,19 @@ describe("artifact URL helpers", () => {
).toBe("/demo/threads/thread-1/user-data/outputs/style.css");
});
test("returns stable artifact path references", async () => {
const { extractArtifactsFromThread } = await loadFreshArtifactUtils();
const threadWithoutArtifacts = { values: {} };
const artifacts = ["/mnt/user-data/outputs/chart.png"];
expect(extractArtifactsFromThread(threadWithoutArtifacts)).toBe(
extractArtifactsFromThread(threadWithoutArtifacts),
);
expect(extractArtifactsFromThread({ values: { artifacts } })).toBe(
artifacts,
);
});
test("resolves a relative message image when it uniquely matches an artifact", async () => {
const { resolveMessageImageURL } = await loadFreshArtifactUtils();
const artifacts = [