Files
ZY-Agent/frontend/src/core/api/feedback.ts
T
1445043649 190c1dc3c8 feat(frontend): migrate API calls to /api/v1 (Stage 1 PR5)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 20:07:20 +08:00

43 lines
1.1 KiB
TypeScript

import { getBackendBaseURL } from "../config";
import { fetch } 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<FeedbackData> {
const res = await fetch(
`${getBackendBaseURL()}/api/v1/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<void> {
const res = await fetch(
`${getBackendBaseURL()}/api/v1/threads/${encodeURIComponent(threadId)}/runs/${encodeURIComponent(runId)}/feedback`,
{ method: "DELETE" },
);
if (!res.ok && res.status !== 404) {
throw new Error(`Failed to delete feedback: ${res.status}`);
}
}