@tscomfy/client 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +76 -2
- package/dist/channel.d.ts +54 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +307 -0
- package/dist/channel.js.map +1 -0
- package/dist/client-error.d.ts +15 -0
- package/dist/client-error.d.ts.map +1 -0
- package/dist/client-error.js +16 -0
- package/dist/client-error.js.map +1 -0
- package/dist/connection.d.ts +33 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +35 -0
- package/dist/connection.js.map +1 -0
- package/dist/event-queue.d.ts +16 -0
- package/dist/event-queue.d.ts.map +1 -0
- package/dist/event-queue.js +66 -0
- package/dist/event-queue.js.map +1 -0
- package/dist/events.d.ts +60 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/files.d.ts +55 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +69 -0
- package/dist/files.js.map +1 -0
- package/dist/frames.d.ts +24 -0
- package/dist/frames.d.ts.map +1 -0
- package/dist/frames.js +71 -0
- package/dist/frames.js.map +1 -0
- package/dist/http.d.ts +28 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +96 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/job.d.ts +59 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +481 -0
- package/dist/job.js.map +1 -0
- package/dist/outcome.d.ts +47 -0
- package/dist/outcome.d.ts.map +1 -0
- package/dist/outcome.js +2 -0
- package/dist/outcome.js.map +1 -0
- package/dist/outputs.d.ts +53 -0
- package/dist/outputs.d.ts.map +1 -0
- package/dist/outputs.js +21 -0
- package/dist/outputs.js.map +1 -0
- package/dist/read-outputs.d.ts +11 -0
- package/dist/read-outputs.d.ts.map +1 -0
- package/dist/read-outputs.js +142 -0
- package/dist/read-outputs.js.map +1 -0
- package/dist/server-errors.d.ts +7 -0
- package/dist/server-errors.d.ts.map +1 -0
- package/dist/server-errors.js +46 -0
- package/dist/server-errors.js.map +1 -0
- package/dist/server.d.ts +30 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -0
- package/dist/timers.d.ts +11 -0
- package/dist/timers.d.ts.map +1 -0
- package/dist/timers.js +38 -0
- package/dist/timers.js.map +1 -0
- package/dist/url.d.ts +14 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +39 -0
- package/dist/url.js.map +1 -0
- package/dist/uuid.d.ts +7 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +13 -0
- package/dist/uuid.js.map +1 -0
- package/package.json +46 -4
- package/src/channel.ts +334 -0
- package/src/client-error.ts +19 -0
- package/src/connection.ts +59 -0
- package/src/event-queue.ts +70 -0
- package/src/events.ts +76 -0
- package/src/files.ts +119 -0
- package/src/frames.ts +87 -0
- package/src/http.ts +113 -0
- package/src/index.ts +53 -0
- package/src/job.ts +562 -0
- package/src/outcome.ts +52 -0
- package/src/outputs.ts +69 -0
- package/src/read-outputs.ts +171 -0
- package/src/server-errors.ts +61 -0
- package/src/server.ts +29 -0
- package/src/timers.ts +35 -0
- package/src/url.ts +41 -0
- package/src/uuid.ts +12 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Events of these types are snapshots: a newer one of a node replaces its unread one. Progress
|
|
3
|
+
* text isn't: each says something different ("Downloading…", "Generating…").
|
|
4
|
+
*/
|
|
5
|
+
const COALESCED = new Set(["progress", "preview"]);
|
|
6
|
+
/**
|
|
7
|
+
* A job's events, for one consumer. Buffered from the start, so none is missed before the
|
|
8
|
+
* consumer starts reading; while it lags, a newer progress or preview of a node replaces the
|
|
9
|
+
* unread one where it stands, so the buffer stays bounded by the number of nodes and keeps its
|
|
10
|
+
* order.
|
|
11
|
+
*/
|
|
12
|
+
export class EventQueue {
|
|
13
|
+
#buffer = [];
|
|
14
|
+
/** `next()` calls waiting for an event, in the order they were made. */
|
|
15
|
+
#waiting = [];
|
|
16
|
+
#ended = false;
|
|
17
|
+
#taken = false;
|
|
18
|
+
/** Adds an event, unless the queue has ended or its consumer stopped. */
|
|
19
|
+
push(event) {
|
|
20
|
+
if (this.#ended)
|
|
21
|
+
return;
|
|
22
|
+
const waiting = this.#waiting.shift();
|
|
23
|
+
if (waiting !== undefined) {
|
|
24
|
+
waiting({ done: false, value: event });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (COALESCED.has(event.type) && "node" in event) {
|
|
28
|
+
const stale = this.#buffer.findIndex((queued) => queued.type === event.type && "node" in queued && queued.node === event.node);
|
|
29
|
+
if (stale !== -1) {
|
|
30
|
+
this.#buffer[stale] = event;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
this.#buffer.push(event);
|
|
35
|
+
}
|
|
36
|
+
/** Ends the queue: the consumer reads what is buffered, then stops. */
|
|
37
|
+
end() {
|
|
38
|
+
this.#ended = true;
|
|
39
|
+
for (const waiting of this.#waiting.splice(0))
|
|
40
|
+
waiting({ done: true, value: undefined });
|
|
41
|
+
}
|
|
42
|
+
[Symbol.asyncIterator]() {
|
|
43
|
+
if (this.#taken)
|
|
44
|
+
throw new TypeError("job.events can be iterated only once");
|
|
45
|
+
this.#taken = true;
|
|
46
|
+
return {
|
|
47
|
+
next: () => {
|
|
48
|
+
const event = this.#buffer.shift();
|
|
49
|
+
if (event !== undefined)
|
|
50
|
+
return Promise.resolve({ done: false, value: event });
|
|
51
|
+
if (this.#ended)
|
|
52
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
this.#waiting.push(resolve);
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
return: () => {
|
|
58
|
+
// The consumer stopped (`break`): drop the buffer and what comes later.
|
|
59
|
+
this.#buffer.length = 0;
|
|
60
|
+
this.end();
|
|
61
|
+
return Promise.resolve({ done: true, value: undefined });
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=event-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-queue.js","sourceRoot":"","sources":["../src/event-queue.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,SAAS,GAAkC,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;AAIlF;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IACZ,OAAO,GAAe,EAAE,CAAC;IAClC,wEAAwE;IAC/D,QAAQ,GAAa,EAAE,CAAC;IACjC,MAAM,GAAG,KAAK,CAAC;IACf,MAAM,GAAG,KAAK,CAAC;IAEf,yEAAyE;IACzE,IAAI,CAAC,KAAe;QAClB,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACvC,OAAO;QACT,CAAC;QACD,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAClC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CACzF,CAAC;YACF,IAAI,KAAK,KAAK,CAAC,CA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I,CAAC,GAAG,EAAE,CAAC;gBACX,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;YAC3D,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { NodeId } from "@tscomfy/core";
|
|
2
|
+
import type { NodeOutput } from "./outputs.ts";
|
|
3
|
+
/** The server started running the job. */
|
|
4
|
+
export interface StartedEvent {
|
|
5
|
+
readonly type: "started";
|
|
6
|
+
}
|
|
7
|
+
/** Nodes whose cached results the run reuses instead of running them. */
|
|
8
|
+
export interface CachedEvent {
|
|
9
|
+
readonly type: "cached";
|
|
10
|
+
readonly nodes: readonly NodeId[];
|
|
11
|
+
}
|
|
12
|
+
/** A node started running. */
|
|
13
|
+
export interface ExecutingEvent {
|
|
14
|
+
readonly type: "executing";
|
|
15
|
+
readonly node: NodeId;
|
|
16
|
+
}
|
|
17
|
+
/** A running node's progress: `value` of `max` (sampler steps, say). */
|
|
18
|
+
export interface ProgressEvent {
|
|
19
|
+
readonly type: "progress";
|
|
20
|
+
readonly node: NodeId;
|
|
21
|
+
readonly value: number;
|
|
22
|
+
readonly max: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A live preview from a running node: a sampler's latent preview (a JPEG at most 512 pixels on a
|
|
26
|
+
* side, sent when the job asks for previews with `previews` in {@link SubmitOptions}, or the
|
|
27
|
+
* server was started with `--preview-method`), or a `SaveImageWebsocket` image (a full-size PNG,
|
|
28
|
+
* always sent).
|
|
29
|
+
*/
|
|
30
|
+
export interface PreviewEvent {
|
|
31
|
+
readonly type: "preview";
|
|
32
|
+
readonly node: NodeId;
|
|
33
|
+
/** `image/jpeg` or `image/png`. */
|
|
34
|
+
readonly mime: string;
|
|
35
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
36
|
+
}
|
|
37
|
+
/** A node finished and reported output (files, text). */
|
|
38
|
+
export interface OutputEvent {
|
|
39
|
+
readonly type: "output";
|
|
40
|
+
readonly node: NodeId;
|
|
41
|
+
readonly output: NodeOutput;
|
|
42
|
+
}
|
|
43
|
+
/** Progress text from a running node (partner nodes report their status this way). */
|
|
44
|
+
export interface TextEvent {
|
|
45
|
+
readonly type: "text";
|
|
46
|
+
readonly node: NodeId;
|
|
47
|
+
readonly text: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A node blocked execution with a message. The run continues without what depends on it; the
|
|
51
|
+
* outcome also lists it, as a `W_NODE_BLOCKED` diagnostic.
|
|
52
|
+
*/
|
|
53
|
+
export interface BlockedEvent {
|
|
54
|
+
readonly type: "blocked";
|
|
55
|
+
readonly node: NodeId;
|
|
56
|
+
readonly message: string;
|
|
57
|
+
}
|
|
58
|
+
/** What a job reports while it runs. Node ids are the prompt's (the builder's) ids. */
|
|
59
|
+
export type JobEvent = StartedEvent | CachedEvent | ExecutingEvent | ProgressEvent | PreviewEvent | OutputEvent | TextEvent | BlockedEvent;
|
|
60
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,0CAA0C;AAC1C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;CAC1B;AAED,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,8BAA8B;AAC9B,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3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"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":""}
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { FileRef, FolderType } from "./outputs.ts";
|
|
2
|
+
import type { Server } from "./server.ts";
|
|
3
|
+
/** A file to upload. */
|
|
4
|
+
export interface UploadSource {
|
|
5
|
+
/** The file name to store it under. */
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly bytes: Uint8Array;
|
|
8
|
+
/** Its media type, such as `image/png`. */
|
|
9
|
+
readonly mime?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Options for {@link uploadFile}. */
|
|
12
|
+
export interface UploadOptions {
|
|
13
|
+
/** A folder under the target directory. */
|
|
14
|
+
readonly subfolder?: string;
|
|
15
|
+
/** The directory: `input` (default), `temp` or `output`. */
|
|
16
|
+
readonly type?: FolderType;
|
|
17
|
+
/** Replace a file of the same name. Otherwise the server keeps both, renaming the new one. */
|
|
18
|
+
readonly overwrite?: boolean;
|
|
19
|
+
readonly signal?: AbortSignal;
|
|
20
|
+
}
|
|
21
|
+
/** An uploaded file, as the server stored it. */
|
|
22
|
+
export interface UploadedFile extends FileRef {
|
|
23
|
+
/**
|
|
24
|
+
* The value a loader node's file input takes (`LoadImage`'s `image`): `subfolder/name`, with
|
|
25
|
+
* ` [temp]` or ` [output]` after it outside the input directory.
|
|
26
|
+
*/
|
|
27
|
+
readonly value: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Uploads a file (an image, video or audio for a loader node) through `/upload/image`. The
|
|
31
|
+
* stored name can differ from `source.name`: without `overwrite`, the server renames a file whose
|
|
32
|
+
* name is taken by different content. Rejects with a {@link ClientError} if the server refuses.
|
|
33
|
+
*/
|
|
34
|
+
export declare function uploadFile(server: Server, source: UploadSource, options?: UploadOptions): Promise<UploadedFile>;
|
|
35
|
+
/** A downloaded file. */
|
|
36
|
+
export interface FileData {
|
|
37
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
38
|
+
/** The server's `Content-Type`; `application/octet-stream` when it sent none. */
|
|
39
|
+
readonly mime: string;
|
|
40
|
+
}
|
|
41
|
+
/** Options for {@link fetchFile}. */
|
|
42
|
+
export interface FetchFileOptions {
|
|
43
|
+
readonly signal?: AbortSignal;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Downloads a file the server has, such as an output, through `/view`. Rejects with a
|
|
47
|
+
* {@link ClientError} if the server doesn't have it.
|
|
48
|
+
*/
|
|
49
|
+
export declare function fetchFile(server: Server, file: FileRef, options?: FetchFileOptions): Promise<FileData>;
|
|
50
|
+
/**
|
|
51
|
+
* The URL `/view` serves a file at, for `<img src>` on a page the server allows (same origin, or
|
|
52
|
+
* `--enable-cors-header`). It carries the server URL's query, so a token in it is in the result.
|
|
53
|
+
*/
|
|
54
|
+
export declare function fileUrl(server: Server, file: FileRef): string;
|
|
55
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,wBAAwB;AACxB,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,8FAA8F;IAC9F,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,iDAAiD;AACjD,MAAM,WAAW,YAAa,SAAQ,OAAO;IAC3C;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CA2BvB;AAED,yBAAyB;AACzB,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IACxC,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,QAAQ,CAAC,CAYnB;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAE7D"}
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ClientError } from "./client-error.js";
|
|
2
|
+
import { readObject, send, unexpected } from "./http.js";
|
|
3
|
+
import { isFolderType } from "./read-outputs.js";
|
|
4
|
+
import { baseUrl, endpoint } from "./url.js";
|
|
5
|
+
/**
|
|
6
|
+
* Uploads a file (an image, video or audio for a loader node) through `/upload/image`. The
|
|
7
|
+
* stored name can differ from `source.name`: without `overwrite`, the server renames a file whose
|
|
8
|
+
* name is taken by different content. Rejects with a {@link ClientError} if the server refuses.
|
|
9
|
+
*/
|
|
10
|
+
export async function uploadFile(server, source, options = {}) {
|
|
11
|
+
const form = new FormData();
|
|
12
|
+
const blob = new Blob([new Uint8Array(source.bytes)], { type: source.mime ?? "" });
|
|
13
|
+
form.append("image", blob, source.name);
|
|
14
|
+
form.append("type", options.type ?? "input");
|
|
15
|
+
if (options.subfolder !== undefined)
|
|
16
|
+
form.append("subfolder", options.subfolder);
|
|
17
|
+
if (options.overwrite === true)
|
|
18
|
+
form.append("overwrite", "true");
|
|
19
|
+
const response = await send(server, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
path: "upload/image",
|
|
22
|
+
body: form,
|
|
23
|
+
signal: options.signal,
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok)
|
|
26
|
+
throw await unexpected(response);
|
|
27
|
+
const answer = await readObject(response);
|
|
28
|
+
const { name, subfolder, type } = answer;
|
|
29
|
+
if (typeof name !== "string" || !isFolderType(type)) {
|
|
30
|
+
throw new ClientError("The server's answer to an upload has no file name or folder");
|
|
31
|
+
}
|
|
32
|
+
const folder = typeof subfolder === "string" ? subfolder : "";
|
|
33
|
+
const path = folder === "" ? name : `${folder}/${name}`;
|
|
34
|
+
return Object.freeze({
|
|
35
|
+
filename: name,
|
|
36
|
+
subfolder: folder,
|
|
37
|
+
type,
|
|
38
|
+
value: type === "input" ? path : `${path} [${type}]`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Downloads a file the server has, such as an output, through `/view`. Rejects with a
|
|
43
|
+
* {@link ClientError} if the server doesn't have it.
|
|
44
|
+
*/
|
|
45
|
+
export async function fetchFile(server, file, options = {}) {
|
|
46
|
+
const response = await send(server, {
|
|
47
|
+
method: "GET",
|
|
48
|
+
path: "view",
|
|
49
|
+
query: viewQuery(file),
|
|
50
|
+
signal: options.signal,
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok)
|
|
53
|
+
throw await unexpected(response);
|
|
54
|
+
return Object.freeze({
|
|
55
|
+
bytes: new Uint8Array(await response.arrayBuffer()),
|
|
56
|
+
mime: response.headers.get("content-type") ?? "application/octet-stream",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The URL `/view` serves a file at, for `<img src>` on a page the server allows (same origin, or
|
|
61
|
+
* `--enable-cors-header`). It carries the server URL's query, so a token in it is in the result.
|
|
62
|
+
*/
|
|
63
|
+
export function fileUrl(server, file) {
|
|
64
|
+
return endpoint(baseUrl(server), "view", viewQuery(file)).href;
|
|
65
|
+
}
|
|
66
|
+
function viewQuery(file) {
|
|
67
|
+
return { filename: file.filename, subfolder: file.subfolder, type: file.type };
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AA+B7C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAc,EACd,MAAoB,EACpB,OAAO,GAAkB,EAAE;IAE3B,MAAM,IAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC5B,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;IACnF,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,OA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CAAC;AAcD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,MAAc,EACd,IAAa,EACb,OAAO,GAAqB,EAAE;IAE9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE;QAClC,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,KAAK,EAAE,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,0BAA0B;KACzE,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,IAAa;IACnD,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACjE,CAAC;AAED,SAAS,SAAS,CAAC,IAAa;IAC9B,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;AACjF,CAAC"}
|
package/dist/frames.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type NodeId } from "@tscomfy/core";
|
|
2
|
+
/** A preview image: binary type 4, which carries the node and prompt it belongs to. */
|
|
3
|
+
export interface PreviewFrame {
|
|
4
|
+
readonly kind: "preview";
|
|
5
|
+
readonly promptId: string;
|
|
6
|
+
readonly node: NodeId;
|
|
7
|
+
readonly mime: string;
|
|
8
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
9
|
+
}
|
|
10
|
+
/** Progress text: binary type 3. Only newer servers say which prompt it belongs to. */
|
|
11
|
+
export interface TextFrame {
|
|
12
|
+
readonly kind: "text";
|
|
13
|
+
readonly promptId: string | undefined;
|
|
14
|
+
readonly node: NodeId;
|
|
15
|
+
readonly text: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Decodes a binary websocket frame: a big-endian `uint32` type, then the payload. Type 1 (a
|
|
19
|
+
* preview without ids) isn't decoded: the client asks for type 4 instead, and an unattributed
|
|
20
|
+
* image can't be given to a job. Unknown types and malformed frames give `undefined`.
|
|
21
|
+
* `textHasPromptId` is the server's `supports_progress_text_metadata` flag.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeFrame(data: ArrayBuffer, textHasPromptId: boolean): PreviewFrame | TextFrame | undefined;
|
|
24
|
+
//# sourceMappingURL=frames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frames.d.ts","sourceRoot":"","sources":["../src/frames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAS,MAAM,eAAe,CAAC;AAGnD,uFAAuF;AACvF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;CACzC;AAED,uFAAuF;AACvF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAKD;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,WAAW,EACjB,eAAe,EAAE,OAAO,GACvB,YAAY,GAAG,SAAS,GAAG,SAAS,CAOtC"}
|
package/dist/frames.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { parse } from "@tscomfy/core";
|
|
2
|
+
import { isObject } from "./http.js";
|
|
3
|
+
const TEXT = 3;
|
|
4
|
+
const PREVIEW_WITH_METADATA = 4;
|
|
5
|
+
/**
|
|
6
|
+
* Decodes a binary websocket frame: a big-endian `uint32` type, then the payload. Type 1 (a
|
|
7
|
+
* preview without ids) isn't decoded: the client asks for type 4 instead, and an unattributed
|
|
8
|
+
* image can't be given to a job. Unknown types and malformed frames give `undefined`.
|
|
9
|
+
* `textHasPromptId` is the server's `supports_progress_text_metadata` flag.
|
|
10
|
+
*/
|
|
11
|
+
export function decodeFrame(data, textHasPromptId) {
|
|
12
|
+
if (data.byteLength < 4)
|
|
13
|
+
return undefined;
|
|
14
|
+
const view = new DataView(data);
|
|
15
|
+
const type = view.getUint32(0);
|
|
16
|
+
if (type === PREVIEW_WITH_METADATA)
|
|
17
|
+
return preview(data, view);
|
|
18
|
+
if (type === TEXT)
|
|
19
|
+
return text(data, view, textHasPromptId);
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
function preview(data, view) {
|
|
23
|
+
const length = readLength(view, 4);
|
|
24
|
+
if (length === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
const metadata = parse(decoder.decode(new Uint8Array(data, 8, length))).value;
|
|
27
|
+
if (!isObject(metadata))
|
|
28
|
+
return undefined;
|
|
29
|
+
const promptId = metadata["prompt_id"];
|
|
30
|
+
const node = metadata["display_node_id"] ?? metadata["node_id"];
|
|
31
|
+
const mime = metadata["image_type"];
|
|
32
|
+
if (typeof promptId !== "string" || typeof node !== "string")
|
|
33
|
+
return undefined;
|
|
34
|
+
return {
|
|
35
|
+
kind: "preview",
|
|
36
|
+
promptId,
|
|
37
|
+
node,
|
|
38
|
+
mime: typeof mime === "string" ? mime : "image/jpeg",
|
|
39
|
+
bytes: new Uint8Array(data.slice(8 + length)),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function text(data, view, hasPromptId) {
|
|
43
|
+
let offset = 4;
|
|
44
|
+
let promptId;
|
|
45
|
+
if (hasPromptId) {
|
|
46
|
+
const length = readLength(view, offset);
|
|
47
|
+
if (length === undefined)
|
|
48
|
+
return undefined;
|
|
49
|
+
promptId = decoder.decode(new Uint8Array(data, offset + 4, length));
|
|
50
|
+
offset += 4 + length;
|
|
51
|
+
}
|
|
52
|
+
const length = readLength(view, offset);
|
|
53
|
+
if (length === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
const node = decoder.decode(new Uint8Array(data, offset + 4, length));
|
|
56
|
+
return {
|
|
57
|
+
kind: "text",
|
|
58
|
+
promptId,
|
|
59
|
+
node,
|
|
60
|
+
text: decoder.decode(new Uint8Array(data, offset + 4 + length)),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** A `uint32` length at `offset` whose bytes fit in the frame after it. */
|
|
64
|
+
function readLength(view, offset) {
|
|
65
|
+
if (view.byteLength < offset + 4)
|
|
66
|
+
return undefined;
|
|
67
|
+
const length = view.getUint32(offset);
|
|
68
|
+
return offset + 4 + length <= view.byteLength ? length : undefined;
|
|
69
|
+
}
|
|
70
|
+
const decoder = new TextDecoder();
|
|
71
|
+
//# sourceMappingURL=frames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frames.js","sourceRoot":"","sources":["../src/frames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAmBrC,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC;;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AAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,MAAM,GAAG,CAAC,GAAG,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type JsonObject, type JsonValue } from "@tscomfy/core";
|
|
2
|
+
import { ClientError } from "./client-error.ts";
|
|
3
|
+
import type { Server } from "./server.ts";
|
|
4
|
+
/** One HTTP request to a server. */
|
|
5
|
+
export interface Request {
|
|
6
|
+
readonly method: "GET" | "POST";
|
|
7
|
+
/** Under the server's path: `prompt`, `api/jobs/<id>`. */
|
|
8
|
+
readonly path: string;
|
|
9
|
+
readonly query?: Readonly<Record<string, string>>;
|
|
10
|
+
readonly body?: string | FormData;
|
|
11
|
+
readonly signal?: AbortSignal | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Sends a request and returns the response, whatever its status. A failure to reach the server
|
|
15
|
+
* is a {@link ClientError}; an aborted signal rejects with the signal's reason, as `fetch` does.
|
|
16
|
+
*/
|
|
17
|
+
export declare function send(server: Server, request: Request): Promise<Response>;
|
|
18
|
+
/** The response's body as JSON, read losslessly (big integers stay exact). */
|
|
19
|
+
export declare function readJson(response: Response): Promise<JsonValue>;
|
|
20
|
+
/** The response's body as a JSON object; anything else is a {@link ClientError}. */
|
|
21
|
+
export declare function readObject(response: Response): Promise<JsonObject>;
|
|
22
|
+
/** A {@link ClientError} for an answer the protocol doesn't expect, with the body's message. */
|
|
23
|
+
export declare function unexpected(response: Response): Promise<ClientError>;
|
|
24
|
+
/** A JSON list. */
|
|
25
|
+
export declare function isList(value: JsonValue | undefined): value is readonly JsonValue[];
|
|
26
|
+
/** A JSON object, not an array or `null`. */
|
|
27
|
+
export declare function isObject(value: JsonValue | undefined):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,6CAA6C;AAC7C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,KAAK,IAAI,UAAU,CAE1E"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { parse } from "@tscomfy/core";
|
|
2
|
+
import { ClientError } from "./client-error.js";
|
|
3
|
+
import { baseUrl, endpoint, shownUrl } from "./url.js";
|
|
4
|
+
/**
|
|
5
|
+
* Sends a request and returns the response, whatever its status. A failure to reach the server
|
|
6
|
+
* is a {@link ClientError}; an aborted signal rejects with the signal's reason, as `fetch` does.
|
|
7
|
+
*/
|
|
8
|
+
export async function send(server, request) {
|
|
9
|
+
const url = endpoint(baseUrl(server), request.path, request.query);
|
|
10
|
+
const headers = new Headers(server.headers);
|
|
11
|
+
if (typeof request.body === "string")
|
|
12
|
+
headers.set("content-type", "application/json");
|
|
13
|
+
const fetcher = server.fetch ?? globalThis.fetch;
|
|
14
|
+
try {
|
|
15
|
+
return await fetcher(url, {
|
|
16
|
+
method: request.method,
|
|
17
|
+
headers,
|
|
18
|
+
body: request.body ?? null,
|
|
19
|
+
signal: request.signal ?? null,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (request.signal?.aborted === true)
|
|
24
|
+
throw request.signal.reason;
|
|
25
|
+
// The runtime's message may quote the URL, query and all.
|
|
26
|
+
const why = describe(error).replaceAll(url.href, shownUrl(url));
|
|
27
|
+
throw new ClientError(`Could not reach ${shownUrl(url)}: ${why}`, { cause: error });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** The response's body as JSON, read losslessly (big integers stay exact). */
|
|
31
|
+
export async function readJson(response) {
|
|
32
|
+
const text = await response.text();
|
|
33
|
+
const { value } = parse(text);
|
|
34
|
+
if (value === undefined) {
|
|
35
|
+
throw new ClientError(`${where(response)} answered with a body that isn't JSON`, {
|
|
36
|
+
status: response.status,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
/** The response's body as a JSON object; anything else is a {@link ClientError}. */
|
|
42
|
+
export async function readObject(response) {
|
|
43
|
+
const value = await readJson(response);
|
|
44
|
+
if (!isObject(value)) {
|
|
45
|
+
throw new ClientError(`${where(response)} answered with JSON that isn't an object`, {
|
|
46
|
+
status: response.status,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
/** A {@link ClientError} for an answer the protocol doesn't expect, with the body's message. */
|
|
52
|
+
export async function unexpected(response) {
|
|
53
|
+
const answer = `${String(response.status)} ${response.statusText}`.trimEnd();
|
|
54
|
+
// Best effort: the status says what went wrong; the body may say why.
|
|
55
|
+
const body = await response.text().catch(() => "");
|
|
56
|
+
const detail = bodyMessage(body);
|
|
57
|
+
return new ClientError(`${where(response)} answered ${answer}${detail === undefined ? "" : `: ${detail}`}`, { status: response.status });
|
|
58
|
+
}
|
|
59
|
+
/** A JSON list. */
|
|
60
|
+
export function isList(value) {
|
|
61
|
+
return Array.isArray(value);
|
|
62
|
+
}
|
|
63
|
+
/** A JSON object, not an array or `null`. */
|
|
64
|
+
export function isObject(value) {
|
|
65
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66
|
+
}
|
|
67
|
+
/** The response's URL without its query, or a fallback when the runtime gives none. */
|
|
68
|
+
function where(response) {
|
|
69
|
+
return URL.canParse(response.url) ? shownUrl(new URL(response.url)) : "The server";
|
|
70
|
+
}
|
|
71
|
+
/** The message of an error body (`{"error": …}`, `{"detail": …}`), at most 200 characters. */
|
|
72
|
+
function bodyMessage(text) {
|
|
73
|
+
const value = parse(text).value;
|
|
74
|
+
if (!isObject(value))
|
|
75
|
+
return undefined;
|
|
76
|
+
const message = value["error"] ?? value["detail"] ?? value["message"];
|
|
77
|
+
const shown = typeof message === "string"
|
|
78
|
+
? message
|
|
79
|
+
: isObject(message) && typeof message["message"] === "string"
|
|
80
|
+
? message["message"]
|
|
81
|
+
: undefined;
|
|
82
|
+
if (shown === undefined)
|
|
83
|
+
return undefined;
|
|
84
|
+
// oxlint-disable-next-line no-control-regex -- control characters are what it removes
|
|
85
|
+
const printable = shown.replaceAll(/[\u0000-\u001f\u007f]/g, " ");
|
|
86
|
+
return printable.length <= 200 ? printable : `${printable.slice(0, 200)}…`;
|
|
87
|
+
}
|
|
88
|
+
/** Why something failed. Node's `fetch` says only "fetch failed"; the reason is in its `cause`. */
|
|
89
|
+
function describe(error) {
|
|
90
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
91
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
92
|
+
if (!(cause instanceof Error) || message.includes(cause.message))
|
|
93
|
+
return message;
|
|
94
|
+
return `${message} (${cause.message})`;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAYvD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,MAAc,EAAE,OAAgB;IACzD,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;IACtF,MAAM,OAAO,GAAG,MAAM,CAAC,KAA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AC,CAAC,CAAC,SAAS,CAAC;IACxE,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IACjF,OAAO,GAAG,OAAO,KAAK,KAAK,CAAC,OAAO,GAAG,CAAC;AACzC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @tscomfy/client
|
|
3
|
+
*
|
|
4
|
+
* Runs tscomfy workflows on a ComfyUI server: `connect` opens a websocket, `submit` queues a
|
|
5
|
+
* workflow and returns a job whose events stream progress, live previews and outputs, and whose
|
|
6
|
+
* outcome the server's record of the job decides. `uploadFile` and `fetchFile` move files.
|
|
7
|
+
* Runtime-agnostic: it uses only `fetch`, `WebSocket` and their companions.
|
|
8
|
+
*/
|
|
9
|
+
export { ClientError } from "./client-error.ts";
|
|
10
|
+
export { type Connection, type ConnectOptions, connect } from "./connection.ts";
|
|
11
|
+
export type { BlockedEvent, CachedEvent, ExecutingEvent, JobEvent, OutputEvent, PreviewEvent, ProgressEvent, StartedEvent, TextEvent, } from "./events.ts";
|
|
12
|
+
export { type FetchFileOptions, fetchFile, type FileData, fileUrl, type UploadedFile, uploadFile, type UploadOptions, type UploadSource, } from "./files.ts";
|
|
13
|
+
export { type Job, type PreviewMethod, submit, type SubmitOptions } from "./job.ts";
|
|
14
|
+
export type { CancelledOutcome, ExecutionError, FailedOutcome, Outcome, RejectedOutcome, SuccessOutcome, } from "./outcome.ts";
|
|
15
|
+
export { type FileKind, type FileRef, type FolderType, type NodeOutput, type NodeRef, type OutputFile, outputFiles, outputOf, type Outputs, } from "./outputs.ts";
|
|
16
|
+
export type { Server } from "./server.ts";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAChF,YAAY,EACV,YAAY,EACZ,WAAW,EACX,cAAc,EACd,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,gBAAgB,EACrB,SAAS,EACT,KAAK,QAAQ,EACb,OAAO,EACP,KAAK,YAAY,EACjB,UAAU,EACV,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,aAAa,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACpF,YAAY,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,OAAO,EACP,eAAe,EACf,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,WAAW,EACX,QAAQ,EACR,KAAK,OAAO,GACb,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @tscomfy/client
|
|
3
|
+
*
|
|
4
|
+
* Runs tscomfy workflows on a ComfyUI server: `connect` opens a websocket, `submit` queues a
|
|
5
|
+
* workflow and returns a job whose events stream progress, live previews and outputs, and whose
|
|
6
|
+
* outcome the server's record of the job decides. `uploadFile` and `fetchFile` move files.
|
|
7
|
+
* Runtime-agnostic: it uses only `fetch`, `WebSocket` and their companions.
|
|
8
|
+
*/
|
|
9
|
+
export { ClientError } from "./client-error.js";
|
|
10
|
+
export { connect } from "./connection.js";
|
|
11
|
+
export { fetchFile, fileUrl, uploadFile, } from "./files.js";
|
|
12
|
+
export { submit } from "./job.js";
|
|
13
|
+
export { outputFiles, outputOf, } from "./outputs.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAwC,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAYhF,OAAO,EAEL,SAAS,EAET,OAAO,EAEP,UAAU,GAGX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAgC,MAAM,EAAsB,MAAM,UAAU,CAAC;AASpF,OAAO,EAOL,WAAW,EACX,QAAQ,GAET,MAAM,cAAc,CAAC"}
|
package/dist/job.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type ApiPrompt, type JsonObject, type Workflow } from "@tscomfy/core";
|
|
2
|
+
import type { Connection } from "./connection.ts";
|
|
3
|
+
import type { JobEvent } from "./events.ts";
|
|
4
|
+
import type { Outcome } from "./outcome.ts";
|
|
5
|
+
import type { NodeRef } from "./outputs.ts";
|
|
6
|
+
/** How the server draws live previews: `auto` is latent2rgb; `taesd` needs its decoder model. */
|
|
7
|
+
export type PreviewMethod = "auto" | "latent2rgb" | "taesd" | "none";
|
|
8
|
+
/** Options for {@link submit}. */
|
|
9
|
+
export interface SubmitOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Live previews for this job (`extra_data.preview_method`). Without it the server's default
|
|
12
|
+
* applies, which is `none` unless it was started with `--preview-method`.
|
|
13
|
+
*/
|
|
14
|
+
readonly previews?: PreviewMethod;
|
|
15
|
+
/** Run only these output nodes (`partial_execution_targets`). */
|
|
16
|
+
readonly targets?: readonly NodeRef[];
|
|
17
|
+
/** Queue ahead of the jobs already waiting. */
|
|
18
|
+
readonly front?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* More `extra_data` for the server, such as `api_key_comfy_org` for partner nodes. The keys the
|
|
21
|
+
* client sets (`client_id`, `preview_method`) are refused.
|
|
22
|
+
*/
|
|
23
|
+
readonly extraData?: JsonObject;
|
|
24
|
+
/**
|
|
25
|
+
* Aborting it cancels the job on the server and rejects the outcome with the signal's reason:
|
|
26
|
+
* `AbortSignal.timeout(600_000)`. There is no default timeout.
|
|
27
|
+
*/
|
|
28
|
+
readonly signal?: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
/** A submitted job. */
|
|
31
|
+
export interface Job {
|
|
32
|
+
/** The prompt id, minted by the client. */
|
|
33
|
+
readonly id: string;
|
|
34
|
+
/**
|
|
35
|
+
* What the job reports while it runs, for one consumer, from the moment it was submitted. Ends
|
|
36
|
+
* when the outcome settles; never throws for the job's failure.
|
|
37
|
+
*/
|
|
38
|
+
readonly events: AsyncIterable<JobEvent>;
|
|
39
|
+
/**
|
|
40
|
+
* How the job ended, as the server's record says. Rejects only with the signal's reason (see
|
|
41
|
+
* {@link SubmitOptions.signal}) or a {@link ClientError}: the server couldn't be reached, the
|
|
42
|
+
* connection was closed, or the server broke the protocol.
|
|
43
|
+
*/
|
|
44
|
+
readonly outcome: Promise<Outcome>;
|
|
45
|
+
/**
|
|
46
|
+
* Asks the server to cancel the job, queued or running. The outcome then settles, normally as
|
|
47
|
+
* `cancelled` (a job that was finishing may still succeed). Rejects with a {@link ClientError}
|
|
48
|
+
* if the server can't be asked.
|
|
49
|
+
*/
|
|
50
|
+
cancel(): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Submits a workflow, or a prompt, to run on the server. A workflow is exported with `toApi`,
|
|
54
|
+
* which validates it and throws a `ValidationError` for errors (D21); a prompt is sent as given.
|
|
55
|
+
* The job is registered under a prompt id the client mints before anything is sent, so no event
|
|
56
|
+
* is missed. Throws a `TypeError` for invalid options or a closed connection.
|
|
57
|
+
*/
|
|
58
|
+
export declare function submit(connection: Connection, input: Workflow | ApiPrompt, options?: SubmitOptions): Job;
|
|
59
|
+
//# sourceMappingURL=job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../src/job.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EAGd,KAAK,UAAU,EAKf,KAAK,QAAQ,EACd,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,KAAK,EAAkB,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAc,OAAO,EAAW,MAAM,cAAc,CAAC;AAOjE,iGAAiG;AACjG,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,GAAG,MAAM,CAAC;AAErE,kCAAkC;AAClC,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC;IAClC,iEAAiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IACtC,+CAA+C;IAC/C,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,uBAAuB;AACvB,MAAM,WAAW,GAAG;IAClB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACzC;;;;OAIG;IACH,QAAQ,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