From 77491f280126a1efe780e8ebb17016c24ab4746b Mon Sep 17 00:00:00 2001 From: rayhpeng Date: Fri, 10 Apr 2026 18:28:26 +0800 Subject: [PATCH] feat(feedback): add frontend feedback API client Adds upsertFeedback and deleteFeedback API functions backed by fetchWithAuth, targeting the /api/threads/{id}/runs/{id}/feedback endpoint. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/core/api/feedback.ts | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 frontend/src/core/api/feedback.ts diff --git a/frontend/src/core/api/feedback.ts b/frontend/src/core/api/feedback.ts new file mode 100644 index 000000000..5af3f02c8 --- /dev/null +++ b/frontend/src/core/api/feedback.ts @@ -0,0 +1,42 @@ +import { getBackendBaseURL } from "../config"; + +import { fetchWithAuth } from "./fetcher"; + +export interface FeedbackData { + feedback_id: string; + rating: number; + comment: string | null; +} + +export async function upsertFeedback( + threadId: string, + runId: string, + rating: number, + comment?: string, +): Promise { + const res = await fetchWithAuth( + `${getBackendBaseURL()}/api/threads/${encodeURIComponent(threadId)}/runs/${encodeURIComponent(runId)}/feedback`, + { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ rating, comment: comment ?? null }), + }, + ); + if (!res.ok) { + throw new Error(`Failed to submit feedback: ${res.status}`); + } + return res.json(); +} + +export async function deleteFeedback( + threadId: string, + runId: string, +): Promise { + const res = await fetchWithAuth( + `${getBackendBaseURL()}/api/threads/${encodeURIComponent(threadId)}/runs/${encodeURIComponent(runId)}/feedback`, + { method: "DELETE" }, + ); + if (!res.ok && res.status !== 404) { + throw new Error(`Failed to delete feedback: ${res.status}`); + } +}