mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 22:59:14 +00:00
[feat] Update history API to v2 array format and add comprehensive tests
- Migrate from object-based to array-based history response format - Update /history endpoint to /history_v2 with max_items parameter - Add lazy loading of workflows via /history_v2/:prompt_id endpoint - Implement comprehensive browser tests for history API functionality - Add unit tests for API methods and queue store - Update TaskItemImpl to support history workflow loading - Add proper error handling and edge case coverage - Follow established test patterns for better maintainability This change improves performance by reducing initial payload size and enables on-demand workflow loading for history items.
This commit is contained in:
committed by
Jennifer Weber
parent
c27edb7e94
commit
7649feb47f
@@ -14,6 +14,7 @@ import type {
|
||||
ExecutionSuccessWsMessage,
|
||||
ExtensionsResponse,
|
||||
FeatureFlagsWsMessage,
|
||||
HistoryResponse,
|
||||
HistoryTaskItem,
|
||||
LogsRawResponse,
|
||||
LogsWsMessage,
|
||||
@@ -28,6 +29,7 @@ import type {
|
||||
StatusWsMessage,
|
||||
StatusWsMessageStatus,
|
||||
SystemStats,
|
||||
TaskPrompt,
|
||||
User,
|
||||
UserDataFullInfo
|
||||
} from '@/schemas/apiSchema'
|
||||
@@ -915,13 +917,13 @@ export class ComfyApi extends EventTarget {
|
||||
const data = await res.json()
|
||||
return {
|
||||
// Running action uses a different endpoint for cancelling
|
||||
Running: data.queue_running.map((prompt: Record<number, any>) => ({
|
||||
Running: data.queue_running.map((prompt: TaskPrompt) => ({
|
||||
taskType: 'Running',
|
||||
prompt,
|
||||
// prompt[1] is the prompt id
|
||||
remove: { name: 'Cancel', cb: () => api.interrupt(prompt[1]) }
|
||||
})),
|
||||
Pending: data.queue_pending.map((prompt: Record<number, any>) => ({
|
||||
Pending: data.queue_pending.map((prompt: TaskPrompt) => ({
|
||||
taskType: 'Pending',
|
||||
prompt
|
||||
}))
|
||||
@@ -940,13 +942,17 @@ export class ComfyApi extends EventTarget {
|
||||
max_items: number = 200
|
||||
): Promise<{ History: HistoryTaskItem[] }> {
|
||||
try {
|
||||
const res = await this.fetchApi(`/history?max_items=${max_items}`)
|
||||
const json: Promise<HistoryTaskItem[]> = await res.json()
|
||||
const res = await this.fetchApi(`/history_v2?max_items=${max_items}`)
|
||||
const json: HistoryResponse = await res.json()
|
||||
|
||||
// Extract history data from new format: { history: [{prompt_id: "...", ...}, ...] }
|
||||
return {
|
||||
History: Object.values(json).map((item) => ({
|
||||
...item,
|
||||
taskType: 'History'
|
||||
}))
|
||||
History: json.history.map(
|
||||
(item): HistoryTaskItem => ({
|
||||
...item,
|
||||
taskType: 'History'
|
||||
})
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
@@ -954,6 +960,33 @@ export class ComfyApi extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets workflow data for a specific prompt from history
|
||||
* @param prompt_id The prompt ID to fetch workflow for
|
||||
* @returns Workflow data for the specific prompt
|
||||
*/
|
||||
async getWorkflowFromHistory(
|
||||
prompt_id: string
|
||||
): Promise<ComfyWorkflowJSON | null> {
|
||||
try {
|
||||
const res = await this.fetchApi(`/history_v2/${prompt_id}`)
|
||||
const json = await res.json()
|
||||
|
||||
// The /history_v2/{prompt_id} endpoint returns data for a specific prompt
|
||||
// The response format is: { prompt_id: { prompt: {priority, prompt_id, extra_data}, outputs: {...}, status: {...} } }
|
||||
const historyItem = json[prompt_id]
|
||||
if (!historyItem) return null
|
||||
|
||||
// Extract workflow from the prompt object
|
||||
// prompt.extra_data contains extra_pnginfo.workflow
|
||||
const workflow = historyItem.prompt?.extra_data?.extra_pnginfo?.workflow
|
||||
return workflow || null
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch workflow for prompt ${prompt_id}:`, error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets system & device stats
|
||||
* @returns System stats such as python version, OS, per device info
|
||||
|
||||
@@ -264,15 +264,16 @@ class ComfyList {
|
||||
? item.remove
|
||||
: {
|
||||
name: 'Delete',
|
||||
cb: () => api.deleteItem(this.#type, item.prompt[1])
|
||||
cb: () =>
|
||||
api.deleteItem(this.#type, item.prompt.prompt_id)
|
||||
}
|
||||
return $el('div', { textContent: item.prompt[0] + ': ' }, [
|
||||
return $el('div', { textContent: item.prompt.priority + ': ' }, [
|
||||
$el('button', {
|
||||
textContent: 'Load',
|
||||
onclick: async () => {
|
||||
await app.loadGraphData(
|
||||
// @ts-expect-error fixme ts strict error
|
||||
item.prompt[3].extra_pnginfo.workflow,
|
||||
item.prompt.extra_data.extra_pnginfo.workflow,
|
||||
true,
|
||||
false
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user