mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-11 02:20:08 +00:00
update api.ts to handle prompt formats
This commit is contained in:
committed by
Jennifer Weber
parent
c4c1c8121c
commit
9c65b47a64
@@ -39,9 +39,9 @@ import type {
|
||||
NodeId
|
||||
} from '@/schemas/comfyWorkflowSchema'
|
||||
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
|
||||
import type { NodeExecutionId } from '@/types/nodeIdentification'
|
||||
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
|
||||
import { useToastStore } from '@/stores/toastStore'
|
||||
import type { NodeExecutionId } from '@/types/nodeIdentification'
|
||||
import { WorkflowTemplates } from '@/types/workflowTemplateTypes'
|
||||
|
||||
interface QueuePromptRequestBody {
|
||||
@@ -904,6 +904,28 @@ export class ComfyApi extends EventTarget {
|
||||
return this.getHistory()
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses queue prompt data from array or object format
|
||||
* @param rawPrompt The raw prompt data from the API
|
||||
* @returns Normalized TaskPrompt object
|
||||
*/
|
||||
private parseQueuePrompt(rawPrompt: any): TaskPrompt {
|
||||
if (Array.isArray(rawPrompt)) {
|
||||
// Queue format: [priority, prompt_id, workflow, outputs]
|
||||
const [priority, prompt_id, workflow] = rawPrompt
|
||||
return {
|
||||
priority,
|
||||
prompt_id,
|
||||
extra_data: workflow?.extra_data || {
|
||||
client_id: '',
|
||||
extra_pnginfo: workflow
|
||||
}
|
||||
}
|
||||
}
|
||||
// Already in object format
|
||||
return rawPrompt
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current state of the queue
|
||||
* @returns The currently running and queued items
|
||||
@@ -917,16 +939,17 @@ 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: TaskPrompt) => ({
|
||||
Running: data.queue_running.map((prompt: any) => ({
|
||||
taskType: 'Running',
|
||||
prompt,
|
||||
// prompt[1] is the prompt id
|
||||
// @ts-expect-error - prompt[1] is the prompt id
|
||||
remove: { name: 'Cancel', cb: () => api.interrupt(prompt[1]) }
|
||||
prompt: this.parseQueuePrompt(prompt),
|
||||
remove: {
|
||||
name: 'Cancel',
|
||||
cb: () => api.interrupt(this.parseQueuePrompt(prompt).prompt_id)
|
||||
}
|
||||
})),
|
||||
Pending: data.queue_pending.map((prompt: TaskPrompt) => ({
|
||||
Pending: data.queue_pending.map((prompt: any) => ({
|
||||
taskType: 'Pending',
|
||||
prompt
|
||||
prompt: this.parseQueuePrompt(prompt)
|
||||
}))
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user