This commit is contained in:
Timothy Jaeryang Baek
2026-06-29 01:32:05 -05:00
parent 9df25b6932
commit 00924fbf79
2 changed files with 33 additions and 5 deletions
+5 -1
View File
@@ -246,7 +246,9 @@ export const getModelChats = async (
startDate: number | null = null,
endDate: number | null = null,
skip: number = 0,
limit: number = 50
limit: number = 50,
orderBy: string | null = null,
direction: string | null = null
) => {
let error = null;
@@ -255,6 +257,8 @@ export const getModelChats = async (
if (endDate) searchParams.append('end_date', endDate.toString());
if (skip) searchParams.append('skip', skip.toString());
if (limit) searchParams.append('limit', limit.toString());
if (orderBy) searchParams.append('order_by', orderBy);
if (direction) searchParams.append('direction', direction);
const res = await fetch(
`${WEBUI_API_BASE_URL}/analytics/models/${encodeURIComponent(modelId)}/chats?${searchParams.toString()}`,
@@ -17,6 +17,7 @@
const i18n = getContext('i18n');
type Tab = 'overview' | 'chats';
type ChatSortKey = 'title' | 'updated_at' | 'user_name';
let selectedTab: Tab = 'overview';
// Overview tab state
@@ -41,6 +42,8 @@
}> = [];
let chatListLoading = false;
let allChatsLoaded = false;
let chatOrderBy: ChatSortKey = 'updated_at';
let chatDirection: 'asc' | 'desc' = 'desc';
const PAGE_SIZE = 50;
const close = () => {
@@ -48,6 +51,8 @@
selectedTab = 'overview';
chatList = [];
allChatsLoaded = false;
chatOrderBy = 'updated_at';
chatDirection = 'desc';
history = [];
tags = [];
onClose();
@@ -88,7 +93,9 @@
startDate,
endDate,
0,
PAGE_SIZE
PAGE_SIZE,
chatOrderBy,
chatDirection
);
const chats = res?.chats ?? [];
chatList = chats.map((c: any) => ({
@@ -98,7 +105,7 @@
user_id: c.user_id,
user_name: c.user_name
}));
allChatsLoaded = chats.length < PAGE_SIZE;
allChatsLoaded = chatList.length >= (res?.total ?? chats.length);
} catch (err) {
console.error('Failed to load chats:', err);
chatList = [];
@@ -118,7 +125,9 @@
startDate,
endDate,
skip,
PAGE_SIZE
PAGE_SIZE,
chatOrderBy,
chatDirection
);
const chats = res?.chats ?? [];
const newChats = chats.map((c: any) => ({
@@ -131,13 +140,23 @@
const existingIds = new Set(chatList.map((c) => c.id));
const uniqueNewChats = newChats.filter((c) => !existingIds.has(c.id));
chatList = [...chatList, ...uniqueNewChats];
allChatsLoaded = chats.length < PAGE_SIZE;
allChatsLoaded = chatList.length >= (res?.total ?? chatList.length);
} catch (err) {
console.error('Failed to load more chats:', err);
}
chatListLoading = false;
};
const setChatSort = (key: ChatSortKey) => {
if (chatOrderBy === key) {
chatDirection = chatDirection === 'asc' ? 'desc' : 'asc';
} else {
chatOrderBy = key;
chatDirection = key === 'updated_at' ? 'desc' : 'asc';
}
loadChats();
};
const selectTab = (tab: Tab) => {
selectedTab = tab;
if (tab === 'chats' && chatList.length === 0) {
@@ -150,6 +169,8 @@
selectedTab = 'overview';
chatList = [];
allChatsLoaded = false;
chatOrderBy = 'updated_at';
chatDirection = 'desc';
selectedRange = '30d';
loadOverview(30);
}
@@ -251,6 +272,9 @@
allLoaded={allChatsLoaded}
showUserInfo={true}
shareUrl={true}
orderBy={chatOrderBy}
direction={chatDirection}
onSort={setChatSort}
onLoadMore={loadMoreChats}
onChatClick={() => (show = false)}
/>