Skip to content

Commit 39f086c

Browse files
ric-yuclaude
andcommitted
[feat] Add Jobs API infrastructure (PR 1 of 3)
Adds Jobs API types, fetchers, and new API methods without breaking existing code. This is the foundation for migrating from legacy /history and /queue endpoints to the unified /jobs endpoint. New files: - src/platform/remote/comfyui/jobs/types/jobTypes.ts - Zod schemas for Jobs API - src/platform/remote/comfyui/jobs/fetchers/fetchJobs.ts - Fetchers for /jobs endpoint - src/platform/remote/comfyui/jobs/index.ts - Barrel exports - tests-ui/tests/platform/remote/comfyui/jobs/fetchers/fetchJobs.test.ts API additions (non-breaking): - api.getQueueFromJobsApi() - Queue from /jobs endpoint - api.getHistoryFromJobsApi() - History from /jobs endpoint - api.getJobDetail() - Full job details including workflow and outputs Part of Jobs API migration. See docs/JOBS_API_MIGRATION_PLAN.md for details. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent d225667 commit 39f086c

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

src/scripts/api.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
4747
import type { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
4848
import type { AuthHeader } from '@/types/authTypes'
4949
import type { NodeExecutionId } from '@/types/nodeIdentification'
50-
import { fetchHistory } from '@/platform/remote/comfyui/history'
50+
import { fetchHistory as fetchHistoryLegacy } from '@/platform/remote/comfyui/history'
51+
import {
52+
fetchHistory as fetchHistoryFromJobsApi,
53+
fetchQueue as fetchQueueFromJobsApi,
54+
type JobListItem
55+
} from '@/platform/remote/comfyui/jobs'
5156

5257
interface QueuePromptRequestBody {
5358
client_id: string
@@ -930,7 +935,7 @@ export class ComfyApi extends EventTarget {
930935
options?: { offset?: number }
931936
): Promise<{ History: HistoryTaskItem[] }> {
932937
try {
933-
return await fetchHistory(
938+
return await fetchHistoryLegacy(
934939
this.fetchApi.bind(this),
935940
max_items,
936941
options?.offset
@@ -1284,6 +1289,48 @@ export class ComfyApi extends EventTarget {
12841289
getServerFeatures(): Record<string, unknown> {
12851290
return { ...this.serverFeatureFlags }
12861291
}
1292+
1293+
// ============================================================================
1294+
// Jobs API Methods (new unified /jobs endpoint)
1295+
// ============================================================================
1296+
1297+
/**
1298+
* Gets queue from the unified Jobs API (/jobs endpoint)
1299+
* @returns Running and pending jobs with synthetic priorities
1300+
*/
1301+
async getQueueFromJobsApi(): Promise<{
1302+
Running: JobListItem[]
1303+
Pending: JobListItem[]
1304+
}> {
1305+
try {
1306+
return await fetchQueueFromJobsApi(this.fetchApi.bind(this))
1307+
} catch (error) {
1308+
console.error(error)
1309+
return { Running: [], Pending: [] }
1310+
}
1311+
}
1312+
1313+
/**
1314+
* Gets history from the unified Jobs API (/jobs endpoint)
1315+
* @param maxItems Maximum number of items to fetch
1316+
* @param offset Offset for pagination
1317+
* @returns Array of completed jobs with synthetic priorities
1318+
*/
1319+
async getHistoryFromJobsApi(
1320+
maxItems: number = 200,
1321+
offset: number = 0
1322+
): Promise<JobListItem[]> {
1323+
try {
1324+
return await fetchHistoryFromJobsApi(
1325+
this.fetchApi.bind(this),
1326+
maxItems,
1327+
offset
1328+
)
1329+
} catch (error) {
1330+
console.error(error)
1331+
return []
1332+
}
1333+
}
12871334
}
12881335

12891336
export const api = new ComfyApi()

0 commit comments

Comments
 (0)