Skip to content

Commit 1272c97

Browse files
committed
feat: Add full support for ComfyUI v0.6.0+ Jobs API with new JobsFeature and types, and implement WebSocket delivery for encrypted images in the multi-workflow pool.
1 parent 935d5cf commit 1272c97

35 files changed

Lines changed: 1253 additions & 41 deletions

CHANGELOG.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,69 @@
11
# Changelog
22

3+
## 1.8.0
4+
5+
### Added
6+
7+
- **ComfyUI v0.6.0 Compatibility** – Full support for the new unified Jobs API
8+
- New `JobsFeature` accessible via `api.ext.jobs`
9+
- `getJobs(options?)` – List all jobs with filtering, sorting, and pagination
10+
- `getJob(jobId)` – Get single job details with full outputs
11+
- Convenience methods: `getRunningJobs()`, `getPendingJobs()`, `getCompletedJobs()`, `getFailedJobs()`
12+
- `getExecutionDuration(job)` – Calculate job execution time
13+
14+
**New Types:**
15+
16+
- `JobStatus` enum – `PENDING`, `IN_PROGRESS`, `COMPLETED`, `FAILED`
17+
- `Job` interface – Unified job representation with status, timing, outputs, and workflow data
18+
- `JobsListResponse` – Paginated job list response
19+
- `JobsListOptions` – Query options for filtering and pagination
20+
- `JobOutputPreview` – Preview output metadata for list views
21+
- `JobExecutionError` – Error details for failed jobs
22+
- `JobWorkflow` – Workflow data in detailed job responses
23+
24+
**Example Usage:**
25+
26+
```typescript
27+
import { ComfyApi, JobStatus } from "comfyui-node";
28+
29+
const api = new ComfyApi("http://localhost:8188");
30+
await api.init();
31+
32+
// Check if Jobs API is supported (requires ComfyUI v0.6.0+)
33+
const supported = await api.ext.jobs.checkSupported();
34+
35+
if (supported) {
36+
// List recent completed jobs
37+
const { jobs, pagination } = await api.ext.jobs.getJobs({
38+
status: JobStatus.COMPLETED,
39+
limit: 10,
40+
sort_order: "desc"
41+
});
42+
43+
// Get specific job with full details
44+
const job = await api.ext.jobs.getJob("prompt-id-here");
45+
if (job && job.status === JobStatus.COMPLETED) {
46+
console.log(`Duration: ${api.ext.jobs.getExecutionDuration(job)}ms`);
47+
}
48+
}
49+
```
50+
51+
**Files Changed:**
52+
53+
- `src/types/api.ts` – Added Jobs API type definitions
54+
- `src/features/jobs.ts` – New JobsFeature module
55+
- `src/client.ts` – Registered JobsFeature in ext namespace
56+
- `src/index.ts` – Exported Jobs API types and feature
57+
58+
**Backward Compatibility:**
59+
60+
- All existing APIs remain unchanged
61+
- Legacy `/queue` and `/history` endpoints still work
62+
- Jobs API is optional and gracefully degrades on older ComfyUI versions
63+
364
## 1.7.0
465

66+
567
### Added
668

769
- **Per-Job Priority Overrides for MultiWorkflowPool** – Dynamic client selection based on workflow type

dist/client.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ModelFeature } from "./features/model.js";
1313
import { TerminalFeature } from "./features/terminal.js";
1414
import { MiscFeature } from "./features/misc.js";
1515
import { FeatureFlagsFeature } from "./features/feature-flags.js";
16+
import { JobsFeature } from "./features/jobs.js";
1617
import { WorkflowJob, WorkflowResult } from "./workflow.js";
1718
/**
1819
* Connection state of the WebSocket client.
@@ -104,6 +105,8 @@ export declare class ComfyApi extends TypedEventTarget<TComfyAPIEventMap> {
104105
readonly misc: MiscFeature;
105106
/** Server advertised feature flags */
106107
readonly featureFlags: FeatureFlagsFeature;
108+
/** Unified Jobs API (ComfyUI v0.6.0+) */
109+
readonly jobs: JobsFeature;
107110
};
108111
/** Helper type guard shaping expected feature API */
109112
private asFeature;

dist/client.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/client.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/features/jobs.d.ts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { ComfyApi } from "../client.js";
2+
import { Job, JobsListOptions, JobsListResponse, JobStatus } from "../types/api.js";
3+
import { FeatureBase } from "./base.js";
4+
/**
5+
* Jobs API feature for unified job management (ComfyUI v0.6.0+).
6+
*
7+
* Provides access to the unified `/api/jobs` endpoints which offer:
8+
* - Consistent job representation across all states (pending, in_progress, completed, failed)
9+
* - Filtering by status and workflow ID
10+
* - Sorting by creation time or execution duration
11+
* - Pagination support
12+
* - Summary fields for efficient list views
13+
*
14+
* @example
15+
* ```typescript
16+
* const api = new ComfyApi("http://localhost:8188");
17+
* await api.init();
18+
*
19+
* // List recent completed jobs
20+
* const { jobs, pagination } = await api.ext.jobs.getJobs({
21+
* status: JobStatus.COMPLETED,
22+
* limit: 10,
23+
* sort_order: "desc"
24+
* });
25+
*
26+
* // Get specific job details
27+
* const job = await api.ext.jobs.getJob("prompt-id-here");
28+
* ```
29+
*
30+
* @since ComfyUI v0.6.0
31+
*/
32+
export declare class JobsFeature extends FeatureBase {
33+
constructor(client: ComfyApi);
34+
/**
35+
* Check if the Jobs API is supported by the connected ComfyUI server.
36+
* The Jobs API was introduced in ComfyUI v0.6.0.
37+
*
38+
* @returns Promise resolving to true if supported, false otherwise
39+
*/
40+
checkSupported(): Promise<boolean>;
41+
/**
42+
* List all jobs with optional filtering, sorting, and pagination.
43+
*
44+
* @param options - Query options for filtering and pagination
45+
* @returns Promise resolving to jobs list with pagination info
46+
*
47+
* @example
48+
* ```typescript
49+
* // Get all pending and in-progress jobs
50+
* const { jobs } = await api.ext.jobs.getJobs({
51+
* status: [JobStatus.PENDING, JobStatus.IN_PROGRESS]
52+
* });
53+
*
54+
* // Get paginated completed jobs sorted by execution time
55+
* const { jobs, pagination } = await api.ext.jobs.getJobs({
56+
* status: JobStatus.COMPLETED,
57+
* sort_by: "execution_duration",
58+
* sort_order: "desc",
59+
* limit: 20,
60+
* offset: 0
61+
* });
62+
*
63+
* // Iterate through pages
64+
* while (pagination.has_more) {
65+
* const next = await api.ext.jobs.getJobs({
66+
* limit: 20,
67+
* offset: pagination.offset + jobs.length
68+
* });
69+
* // process next.jobs...
70+
* }
71+
* ```
72+
*/
73+
getJobs(options?: JobsListOptions): Promise<JobsListResponse>;
74+
/**
75+
* Get a single job by its ID with full details including outputs.
76+
*
77+
* @param jobId - The job/prompt ID to retrieve
78+
* @returns Promise resolving to the job details, or null if not found
79+
*
80+
* @example
81+
* ```typescript
82+
* const job = await api.ext.jobs.getJob("abc-123-def");
83+
* if (job) {
84+
* console.log(`Job ${job.id}: ${job.status}`);
85+
* if (job.status === JobStatus.COMPLETED) {
86+
* console.log(`Outputs: ${job.outputs_count}`);
87+
* console.log(`Duration: ${job.execution_end_time - job.execution_start_time}ms`);
88+
* }
89+
* }
90+
* ```
91+
*/
92+
getJob(jobId: string): Promise<Job | null>;
93+
/**
94+
* Get jobs filtered by a specific status.
95+
* Convenience method that wraps getJobs().
96+
*
97+
* @param status - The status to filter by
98+
* @param limit - Maximum number of jobs to return (default 100)
99+
* @returns Promise resolving to array of jobs
100+
*/
101+
getJobsByStatus(status: JobStatus, limit?: number): Promise<Job[]>;
102+
/**
103+
* Get currently running jobs.
104+
* Convenience method for getJobsByStatus(JobStatus.IN_PROGRESS).
105+
*/
106+
getRunningJobs(): Promise<Job[]>;
107+
/**
108+
* Get pending (queued) jobs.
109+
* Convenience method for getJobsByStatus(JobStatus.PENDING).
110+
*/
111+
getPendingJobs(): Promise<Job[]>;
112+
/**
113+
* Get recently completed jobs.
114+
*
115+
* @param limit - Maximum number of jobs to return (default 20)
116+
*/
117+
getCompletedJobs(limit?: number): Promise<Job[]>;
118+
/**
119+
* Get recently failed jobs.
120+
*
121+
* @param limit - Maximum number of jobs to return (default 20)
122+
*/
123+
getFailedJobs(limit?: number): Promise<Job[]>;
124+
/**
125+
* Calculate execution duration for a completed job.
126+
*
127+
* @param job - The job to calculate duration for
128+
* @returns Duration in milliseconds, or null if times are not available
129+
*/
130+
getExecutionDuration(job: Job): number | null;
131+
}
132+
//# sourceMappingURL=jobs.d.ts.map

0 commit comments

Comments
 (0)