db5ad86381
* Refactor API fetch calls to use a unified fetch function; enhance chat history loading with new hooks and UI components - Replaced `fetchWithAuth` with a generic `fetch` function across various API modules for consistency. - Updated `useThreadStream` and `useThreadHistory` hooks to manage chat history loading, including loading states and pagination. - Introduced `LoadMoreHistoryIndicator` component for better user experience when loading more chat history. - Enhanced message handling in `MessageList` to accommodate new loading states and history management. - Added support for run messages in the thread context, improving the overall message handling logic. - Updated translations for loading indicators in English and Chinese. * Fix test assertions for run ordering in RunManager tests - Updated assertions in `test_list_by_thread` to reflect correct ordering of runs. - Modified `test_list_by_thread_is_stable_when_timestamps_tie` to ensure stable ordering when timestamps are tied.
43 lines
1.1 KiB
TypeScript
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/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/threads/${encodeURIComponent(threadId)}/runs/${encodeURIComponent(runId)}/feedback`,
|
|
{ method: "DELETE" },
|
|
);
|
|
if (!res.ok && res.status !== 404) {
|
|
throw new Error(`Failed to delete feedback: ${res.status}`);
|
|
}
|
|
}
|