From 18393b55d1710b61200112ed45f2711468082728 Mon Sep 17 00:00:00 2001 From: rayhpeng Date: Fri, 10 Apr 2026 18:28:36 +0800 Subject: [PATCH] feat(feedback): wire feedback data into message rendering for history echo Adds useThreadFeedback hook that fetches run-level feedback from the messages API and builds a runId->FeedbackData map. MessageList now calls this hook and passes feedback and runId to each MessageListItem so previously-submitted thumbs are pre-filled when revisiting a thread. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/core/threads/hooks.ts | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/frontend/src/core/threads/hooks.ts b/frontend/src/core/threads/hooks.ts index 33424aeee..63f69c243 100644 --- a/frontend/src/core/threads/hooks.ts +++ b/frontend/src/core/threads/hooks.ts @@ -678,3 +678,37 @@ export function useRenameThread() { }, }); } + +export function useThreadFeedback(threadId: string | null | undefined) { + return useQuery({ + queryKey: ["thread-feedback", threadId], + queryFn: async () => { + if (!threadId) return {}; + const res = await fetchWithAuth( + `${getBackendBaseURL()}/api/threads/${encodeURIComponent(threadId)}/messages?limit=200`, + ); + if (!res.ok) return {}; + const messages: Array<{ + run_id: string; + event_type: string; + feedback?: { + feedback_id: string; + rating: number; + comment: string | null; + } | null; + }> = await res.json(); + const feedbackMap: Record< + string, + { feedback_id: string; rating: number; comment: string | null } + > = {}; + for (const msg of messages) { + if (msg.feedback && msg.run_id) { + feedbackMap[msg.run_id] = msg.feedback; + } + } + return feedbackMap; + }, + enabled: !!threadId, + staleTime: 30_000, + }); +}