Skip to content

Commit 9915fa6

Browse files
committed
fix typing
1 parent 7689d3f commit 9915fa6

File tree

9 files changed

+263
-117
lines changed

9 files changed

+263
-117
lines changed

src/components/queue/job/useJobErrorReporting.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,34 @@ type JobExecutionError = {
2525
export const extractExecutionError = (
2626
task: TaskItemImpl | null
2727
): JobExecutionError | null => {
28-
const status = (task as TaskItemImpl | null)?.status
29-
const messages = (status as { messages?: unknown[] } | undefined)?.messages
30-
if (!Array.isArray(messages) || !messages.length) return null
31-
const record = messages.find((entry: unknown) => {
32-
return Array.isArray(entry) && entry[0] === 'execution_error'
33-
}) as [string, ExecutionErrorWsMessage?] | undefined
34-
if (!record) return null
35-
const detail = record[1]
36-
const message = String(detail?.exception_message ?? '')
37-
return {
38-
detail,
39-
message
28+
if (!task) return null
29+
30+
// Try detailed executionStatus.messages first (from job detail API)
31+
const messages = task.executionStatus?.messages
32+
if (Array.isArray(messages) && messages.length > 0) {
33+
const record = messages.find(
34+
(entry): entry is [string, ExecutionErrorWsMessage] =>
35+
Array.isArray(entry) && entry[0] === 'execution_error'
36+
)
37+
if (record) {
38+
const detail = record[1]
39+
return {
40+
detail,
41+
message: detail?.exception_message ?? ''
42+
}
43+
}
4044
}
45+
46+
// Fall back to simple errorMessage (from jobs list API)
47+
const errorMessage = task.errorMessage
48+
if (errorMessage) {
49+
return {
50+
detail: undefined,
51+
message: errorMessage
52+
}
53+
}
54+
55+
return null
4156
}
4257

4358
type UseJobErrorReportingOptions = {

src/composables/queue/useJobMenu.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,31 @@ export function useJobMenu(
9191
await queueStore.update()
9292
}
9393

94+
const getExecutionError = (
95+
item: JobListItem | null
96+
): ExecutionErrorWsMessage | undefined => {
97+
const messages = item?.taskRef?.executionStatus?.messages
98+
if (!Array.isArray(messages)) return undefined
99+
const record = messages.find(
100+
(entry): entry is [string, ExecutionErrorWsMessage] =>
101+
Array.isArray(entry) && entry[0] === 'execution_error'
102+
)
103+
return record?.[1]
104+
}
105+
94106
const copyErrorMessage = async () => {
95107
const item = currentMenuItem()
96108
if (!item) return
97-
const msgs = item.taskRef?.status?.messages as any[] | undefined
98-
const err = msgs?.find((m: any) => m?.[0] === 'execution_error')?.[1] as
99-
| ExecutionErrorWsMessage
100-
| undefined
101-
const message = err?.exception_message
109+
// Try detailed error from executionStatus, fall back to errorMessage
110+
const err = getExecutionError(item)
111+
const message = err?.exception_message ?? item.taskRef?.errorMessage
102112
if (message) await copyToClipboard(String(message))
103113
}
104114

105115
const reportError = () => {
106116
const item = currentMenuItem()
107117
if (!item) return
108-
const msgs = item.taskRef?.status?.messages as any[] | undefined
109-
const err = msgs?.find((m: any) => m?.[0] === 'execution_error')?.[1] as
110-
| ExecutionErrorWsMessage
111-
| undefined
118+
const err = getExecutionError(item)
112119
if (err) useDialogService().showExecutionErrorDialog(err)
113120
}
114121

src/composables/queue/useResultGallery.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import { ref, shallowRef } from 'vue'
22

33
import type { JobListItem } from '@/composables/queue/useJobList'
4-
import type { ResultItemImpl, TaskItemImpl } from '@/stores/queueStore'
4+
import type { ResultItemImpl } from '@/stores/queueStore'
55

66
type FetchApi = (url: string) => Promise<Response>
77

8+
/**
9+
* Minimal interface for tasks used by the result gallery.
10+
* This allows the gallery to work with any object that provides these properties,
11+
* without coupling to the full TaskItemImpl class.
12+
*/
13+
interface GalleryTask {
14+
readonly promptId: string
15+
readonly outputsCount?: number
16+
readonly flatOutputs: readonly ResultItemImpl[]
17+
readonly previewOutput?: ResultItemImpl
18+
loadFullOutputs(fetchApi: FetchApi): Promise<GalleryTask>
19+
}
20+
821
const getPreviewableOutputs = (outputs?: readonly ResultItemImpl[]) =>
922
outputs?.filter((o) => o.supportsPreview) ?? []
1023

@@ -18,17 +31,17 @@ const findActiveIndex = (items: ResultItemImpl[], url?: string): number => {
1831
* Manages result gallery state and activation for queue items.
1932
*/
2033
export function useResultGallery(
21-
getFilteredTasks: () => TaskItemImpl[],
34+
getFilteredTasks: () => GalleryTask[],
2235
fetchApi?: FetchApi
2336
) {
2437
const galleryActiveIndex = ref(-1)
2538
const galleryItems = shallowRef<ResultItemImpl[]>([])
2639

27-
const loadedTasksCache = new Map<string, TaskItemImpl>()
40+
const loadedTasksCache = new Map<string, GalleryTask>()
2841
let currentRequestId = 0
2942

3043
const getOutputsForTask = async (
31-
task: TaskItemImpl
44+
task: GalleryTask
3245
): Promise<ResultItemImpl[]> => {
3346
const outputsCount = task.outputsCount ?? 0
3447
const needsLazyLoad = outputsCount > 1 && fetchApi
@@ -54,7 +67,7 @@ export function useResultGallery(
5467

5568
const requestId = ++currentRequestId
5669

57-
const targetTask = item.taskRef as TaskItemImpl | undefined
70+
const targetTask = item.taskRef as GalleryTask | undefined
5871
let targetOutputs: ResultItemImpl[] = []
5972

6073
if (targetTask) {

src/platform/remote/comfyui/jobs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ export {
1111
fetchJobDetail,
1212
fetchQueue
1313
} from './fetchers/fetchJobs'
14-
export type { JobDetail, JobListItem } from './types/jobTypes'
14+
export type { ExecutionStatus, JobDetail, JobListItem } from './types/jobTypes'

src/platform/remote/comfyui/jobs/types/jobTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,4 @@ export type JobStatus = z.infer<typeof zJobStatus>
124124
export type RawJobListItem = z.infer<typeof zRawJobListItem>
125125
export type JobListItem = z.infer<typeof zJobListItem>
126126
export type JobDetail = z.infer<typeof zJobDetail>
127+
export type ExecutionStatus = z.infer<typeof zExecutionStatus>

src/stores/queueStore.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { computed, ref, shallowRef, toRaw, toValue } from 'vue'
44

55
import { reconcileJobs } from '@/platform/remote/comfyui/history/reconciliation'
66
import { extractWorkflow, fetchJobDetail } from '@/platform/remote/comfyui/jobs'
7-
import type { JobListItem } from '@/platform/remote/comfyui/jobs/types/jobTypes'
7+
import type {
8+
ExecutionStatus,
9+
JobListItem
10+
} from '@/platform/remote/comfyui/jobs'
811
import type {
912
ComfyWorkflowJSON,
1013
NodeId
@@ -188,13 +191,16 @@ export class TaskItemImpl {
188191
readonly job: JobListItem
189192
readonly outputs: TaskOutput
190193
readonly flatOutputs: ReadonlyArray<ResultItemImpl>
194+
readonly executionStatus?: ExecutionStatus
191195

192196
constructor(
193197
job: JobListItem,
194198
outputs?: TaskOutput,
195-
flatOutputs?: ReadonlyArray<ResultItemImpl>
199+
flatOutputs?: ReadonlyArray<ResultItemImpl>,
200+
executionStatus?: ExecutionStatus
196201
) {
197202
this.job = job
203+
this.executionStatus = executionStatus
198204
// If no outputs provided but job has preview_output, create synthetic outputs
199205
const effectiveOutputs =
200206
outputs ??
@@ -371,7 +377,7 @@ export class TaskItemImpl {
371377

372378
/**
373379
* Loads full outputs for tasks that only have preview data
374-
* Returns a new TaskItemImpl with full outputs loaded
380+
* Returns a new TaskItemImpl with full outputs and execution status
375381
*/
376382
public async loadFullOutputs(
377383
fetchApi: (url: string) => Promise<Response>
@@ -386,8 +392,13 @@ export class TaskItemImpl {
386392
return this
387393
}
388394

389-
// Create new TaskItemImpl with full outputs
390-
return new TaskItemImpl(this.job, jobDetail.outputs)
395+
// Create new TaskItemImpl with full outputs and execution status
396+
return new TaskItemImpl(
397+
this.job,
398+
jobDetail.outputs,
399+
undefined,
400+
jobDetail.execution_status
401+
)
391402
}
392403

393404
public async loadWorkflow(app: ComfyApp) {

0 commit comments

Comments
 (0)