This commit is contained in:
Timothy Jaeryang Baek
2026-01-24 03:25:29 +04:00
parent 6c76983999
commit b7e9992d78
3 changed files with 11 additions and 17 deletions
+4 -3
View File
@@ -297,12 +297,13 @@ async def delete_prompt_by_id(
@router.get("/id/{prompt_id}/history", response_model=list[PromptHistoryResponse]) @router.get("/id/{prompt_id}/history", response_model=list[PromptHistoryResponse])
async def get_prompt_history( async def get_prompt_history(
prompt_id: str, prompt_id: str,
limit: int = 50, page: int = 0,
offset: int = 0,
user=Depends(get_verified_user), user=Depends(get_verified_user),
db: Session = Depends(get_session), db: Session = Depends(get_session),
): ):
"""Get version history for a prompt.""" """Get version history for a prompt."""
PAGE_SIZE = 20
prompt = Prompts.get_prompt_by_id(prompt_id, db=db) prompt = Prompts.get_prompt_by_id(prompt_id, db=db)
if not prompt: if not prompt:
@@ -323,7 +324,7 @@ async def get_prompt_history(
) )
history = PromptHistories.get_history_by_prompt_id( history = PromptHistories.get_history_by_prompt_id(
prompt.id, limit=limit, offset=offset, db=db prompt.id, limit=PAGE_SIZE, offset=page * PAGE_SIZE, db=db
) )
return history return history
+2 -3
View File
@@ -312,13 +312,12 @@ export const deletePromptById = async (token: string, promptId: string) => {
export const getPromptHistory = async ( export const getPromptHistory = async (
token: string, token: string,
promptId: string, promptId: string,
limit: number = 50, page: number = 0
offset: number = 0
): Promise<PromptHistoryItem[]> => { ): Promise<PromptHistoryItem[]> => {
let error = null; let error = null;
const res = await fetch( const res = await fetch(
`${WEBUI_API_BASE_URL}/prompts/id/${promptId}/history?limit=${limit}&offset=${offset}`, `${WEBUI_API_BASE_URL}/prompts/id/${promptId}/history?page=${page}`,
{ {
method: 'GET', method: 'GET',
headers: { headers: {
@@ -49,10 +49,9 @@
let history: any[] = []; let history: any[] = [];
let historyLoading = false; let historyLoading = false;
let selectedHistoryEntry: any = null; let selectedHistoryEntry: any = null;
let historyOffset = 0; let historyPage = 0;
let historyHasMore = true; let historyHasMore = true;
let contentCopied = false; let contentCopied = false;
const HISTORY_PAGE_SIZE = 20;
$: if (!edit && !hasManualEdit) { $: if (!edit && !hasManualEdit) {
command = name !== '' ? slugify(name) : ''; command = name !== '' ? slugify(name) : '';
@@ -109,17 +108,12 @@
historyLoading = true; historyLoading = true;
if (reset) { if (reset) {
historyOffset = 0; historyPage = 0;
historyHasMore = true; historyHasMore = true;
} }
try { try {
const newEntries = await getPromptHistory( const newEntries = await getPromptHistory(localStorage.token, prompt.id, historyPage);
localStorage.token,
prompt.id,
HISTORY_PAGE_SIZE,
historyOffset
);
if (reset) { if (reset) {
history = newEntries; history = newEntries;
@@ -127,8 +121,8 @@
history = [...history, ...newEntries]; history = [...history, ...newEntries];
} }
historyHasMore = newEntries.length === HISTORY_PAGE_SIZE; historyHasMore = newEntries.length > 0;
historyOffset += newEntries.length; historyPage = historyPage + 1;
} catch (error) { } catch (error) {
console.error('Failed to load history:', error); console.error('Failed to load history:', error);
if (reset) { if (reset) {