lumiverse-spindle-types 0.6.6 → 0.6.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lumiverse-spindle-types",
3
- "version": "0.6.6",
3
+ "version": "0.6.8",
4
4
  "types": "./src/index.ts",
5
5
  "keywords": [
6
6
  "lumiverse",
package/src/api.ts CHANGED
@@ -727,6 +727,11 @@ export interface ImageGenProviderDTO {
727
727
  modelListStyle: "static" | "dynamic" | "google";
728
728
  staticModels?: Array<{ id: string; label: string }>;
729
729
  defaultUrl: string;
730
+ /** Present only when the provider supports Lumiverse's WebSocket preview/status stream. */
731
+ websocketPreviewStreaming?: {
732
+ previews: true;
733
+ status: true;
734
+ };
730
735
  };
731
736
  }
732
737
 
@@ -761,6 +766,47 @@ export interface ImageGenResultDTO {
761
766
  imageUrl?: string;
762
767
  }
763
768
 
769
+ /** Input for {@link SpindleAPI.imageGen.generateStream}. */
770
+ export interface ImageGenStreamRequestDTO extends ImageGenRequestDTO {
771
+ /** Abort the upstream generation and close its WebSocket stream. */
772
+ signal?: AbortSignal;
773
+ }
774
+
775
+ /** A progress/status update received from the provider WebSocket. */
776
+ export interface ImageGenStreamStatusDTO {
777
+ type: "status";
778
+ /** Current step when the provider reports numerical progress. */
779
+ step?: number;
780
+ /** Total steps when the provider reports numerical progress. */
781
+ totalSteps?: number;
782
+ /** Current workflow node, when supplied by the provider. */
783
+ nodeId?: string;
784
+ }
785
+
786
+ /** A preview image received from the provider WebSocket. */
787
+ export interface ImageGenStreamPreviewDTO {
788
+ type: "preview";
789
+ /** Preview image as a base64 data URL. */
790
+ imageDataUrl: string;
791
+ /** Status reported with this preview, when available. */
792
+ step?: number;
793
+ totalSteps?: number;
794
+ nodeId?: string;
795
+ }
796
+
797
+ /** Terminal success event for an image generation stream. */
798
+ export interface ImageGenStreamDoneDTO {
799
+ type: "done";
800
+ /** Final image and its persisted asset identifiers. */
801
+ result: ImageGenResultDTO;
802
+ }
803
+
804
+ /** Events yielded by {@link SpindleAPI.imageGen.generateStream}. */
805
+ export type ImageGenStreamEventDTO =
806
+ | ImageGenStreamStatusDTO
807
+ | ImageGenStreamPreviewDTO
808
+ | ImageGenStreamDoneDTO;
809
+
764
810
  // ─── Image DTOs ─────────────────────────────────────────────────────────
765
811
 
766
812
  export type ImageSpecificityDTO = "full" | "sm" | "lg";
@@ -3384,6 +3430,12 @@ export type WorkerToHost =
3384
3430
  | { type: "macros_resolve"; requestId: string; template: string; chatId?: string; characterId?: string; userId?: string; commit?: boolean }
3385
3431
  // ─── Image Generation (gated: "image_gen") ──────────────────────────
3386
3432
  | { type: "image_gen_generate"; requestId: string; input: ImageGenRequestDTO }
3433
+ /**
3434
+ * Start a WebSocket-backed image stream. Only providers that advertise
3435
+ * `websocketPreviewStreaming` accept this request.
3436
+ */
3437
+ | { type: "image_gen_generate_stream"; requestId: string; input: Omit<ImageGenStreamRequestDTO, "signal"> }
3438
+ | { type: "image_gen_cancel_stream"; requestId: string }
3387
3439
  | { type: "image_gen_providers"; requestId: string; userId?: string }
3388
3440
  | { type: "image_gen_connections_list"; requestId: string; userId?: string }
3389
3441
  | { type: "image_gen_connections_get"; requestId: string; connectionId: string; userId?: string }
@@ -3622,4 +3674,6 @@ export type HostToWorker =
3622
3674
  * `request_generation_stream`. Mutually exclusive with the `done`
3623
3675
  * chunk in `generation_stream_chunk`. Aborts surface here too.
3624
3676
  */
3625
- | { type: "generation_stream_error"; requestId: string; error: string };
3677
+ | { type: "generation_stream_error"; requestId: string; error: string }
3678
+ | { type: "image_gen_stream_chunk"; requestId: string; event: ImageGenStreamEventDTO }
3679
+ | { type: "image_gen_stream_error"; requestId: string; error: string };
package/src/index.ts CHANGED
@@ -155,9 +155,14 @@ export type {
155
155
  ImageGenConnectionDTO,
156
156
  ImageGenParameterSchemaDTO,
157
157
  ImageGenProviderDTO,
158
- ImageGenRequestDTO,
159
- ImageGenResultDTO,
160
- ImageGetOptionsDTO,
158
+ ImageGenRequestDTO,
159
+ ImageGenResultDTO,
160
+ ImageGenStreamRequestDTO,
161
+ ImageGenStreamStatusDTO,
162
+ ImageGenStreamPreviewDTO,
163
+ ImageGenStreamDoneDTO,
164
+ ImageGenStreamEventDTO,
165
+ ImageGetOptionsDTO,
161
166
  ImageDTO,
162
167
  ImageListOptionsDTO,
163
168
  ImageSpecificityDTO,
@@ -70,6 +70,8 @@ import type {
70
70
  ChatMemoryResultDTO,
71
71
  ImageGenRequestDTO,
72
72
  ImageGenResultDTO,
73
+ ImageGenStreamRequestDTO,
74
+ ImageGenStreamEventDTO,
73
75
  ImageGenConnectionDTO,
74
76
  ImageGenProviderDTO,
75
77
  ImageGetOptionsDTO,
@@ -800,6 +802,16 @@ export interface SpindleAPI {
800
802
  * Returns the image as a base64 data URL.
801
803
  */
802
804
  generate(input: ImageGenRequestDTO): Promise<ImageGenResultDTO>;
805
+ /**
806
+ * Generate through a provider that supports WebSocket preview images and
807
+ * status updates (currently SwarmUI and ComfyUI). The terminal `done`
808
+ * event carries the same result as {@link generate}. Breaking from the
809
+ * iterator or aborting `input.signal` cancels the upstream generation.
810
+ *
811
+ * Throws if the selected provider does not advertise
812
+ * `websocketPreviewStreaming` in {@link getProviders}.
813
+ */
814
+ generateStream(input: ImageGenStreamRequestDTO): AsyncGenerator<ImageGenStreamEventDTO, void, void>;
803
815
  /**
804
816
  * List available image generation providers with their capability schemas.
805
817
  * The schemas describe supported parameters, models, and features.
@@ -0,0 +1,44 @@
1
+ import type {
2
+ HostToWorker,
3
+ ImageGenStreamEventDTO,
4
+ SpindleAPI,
5
+ WorkerToHost,
6
+ } from "lumiverse-spindle-types";
7
+
8
+ declare const spindle: SpindleAPI;
9
+
10
+ async function consumePreviews(): Promise<void> {
11
+ const stream = spindle.imageGen.generateStream({
12
+ connection_id: "swarm-connection",
13
+ prompt: "A quiet observatory under a starry sky",
14
+ });
15
+
16
+ for await (const event of stream) {
17
+ if (event.type === "preview") {
18
+ const preview: string = event.imageDataUrl;
19
+ void preview;
20
+ } else if (event.type === "status") {
21
+ const step: number | undefined = event.step;
22
+ void step;
23
+ } else {
24
+ const finalImage: string = event.result.imageDataUrl;
25
+ void finalImage;
26
+ }
27
+ }
28
+ }
29
+
30
+ const event: ImageGenStreamEventDTO = { type: "status", step: 2, totalSteps: 20 };
31
+ const startStream: WorkerToHost = {
32
+ type: "image_gen_generate_stream",
33
+ requestId: "request-1",
34
+ input: { prompt: "A quiet observatory under a starry sky" },
35
+ };
36
+ const preview: HostToWorker = {
37
+ type: "image_gen_stream_chunk",
38
+ requestId: "request-1",
39
+ event: { type: "preview", imageDataUrl: "data:image/png;base64,preview" },
40
+ };
41
+ void event;
42
+ void startStream;
43
+ void preview;
44
+ void consumePreviews;
@@ -5,5 +5,5 @@
5
5
  "outDir": "./.consumer-dist",
6
6
  "declaration": false
7
7
  },
8
- "include": ["test/loom-block-editor-consumer.ts", "test/bound-generation-consumer.ts", "test/interceptor-consumer.ts", "test/host-runtime-contract-consumer.ts"]
8
+ "include": ["test/loom-block-editor-consumer.ts", "test/bound-generation-consumer.ts", "test/interceptor-consumer.ts", "test/host-runtime-contract-consumer.ts", "test/image-gen-stream-consumer.ts"]
9
9
  }