@@ -29,16 +29,15 @@ public class ComfyClient : InferenceClientBase
2929 private readonly IComfyApi comfyApi ;
3030 private bool isDisposed ;
3131
32- private readonly JsonSerializerOptions jsonSerializerOptions =
33- new ( )
32+ private readonly JsonSerializerOptions jsonSerializerOptions = new ( )
33+ {
34+ PropertyNamingPolicy = JsonNamingPolicies . SnakeCaseLower ,
35+ Converters =
3436 {
35- PropertyNamingPolicy = JsonNamingPolicies . SnakeCaseLower ,
36- Converters =
37- {
38- new NodeConnectionBaseJsonConverter ( ) ,
39- new OneOfJsonConverter < string , StringNodeConnection > ( )
40- }
41- } ;
37+ new NodeConnectionBaseJsonConverter ( ) ,
38+ new OneOfJsonConverter < string , StringNodeConnection > ( ) ,
39+ } ,
40+ } ;
4241
4342 // ReSharper disable once MemberCanBePrivate.Global
4443 public string ClientId { get ; } = Guid . NewGuid ( ) . ToString ( ) ;
@@ -111,20 +110,20 @@ public ComfyClient(IApiFactory apiFactory, Uri baseAddress)
111110 {
112111 Scheme = "ws" ,
113112 Path = "/ws" ,
114- Query = $ "clientId={ ClientId } "
113+ Query = $ "clientId={ ClientId } ",
115114 } . Uri ;
116115
117116 webSocketClient = new WebsocketClient ( wsUri )
118117 {
119118 Name = nameof ( ComfyClient ) ,
120- ReconnectTimeout = TimeSpan . FromSeconds ( 30 )
119+ ReconnectTimeout = TimeSpan . FromSeconds ( 30 ) ,
121120 } ;
122121
123- webSocketClient . DisconnectionHappened . Subscribe (
124- info => Logger . Info ( "Websocket Disconnected, ({Type})" , info . Type )
122+ webSocketClient . DisconnectionHappened . Subscribe ( info =>
123+ Logger . Info ( "Websocket Disconnected, ({Type})" , info . Type )
125124 ) ;
126- webSocketClient . ReconnectionHappened . Subscribe (
127- info => Logger . Info ( "Websocket Reconnected, ({Type})" , info . Type )
125+ webSocketClient . ReconnectionHappened . Subscribe ( info =>
126+ Logger . Info ( "Websocket Reconnected, ({Type})" , info . Type )
128127 ) ;
129128
130129 webSocketClient . MessageReceived . Subscribe ( OnMessageReceived ) ;
@@ -287,7 +286,7 @@ private void HandleBinaryMessage(byte[] data)
287286 Array.Reverse(typeBytes);
288287 }*/
289288
290- PreviewImageReceived ? . Invoke ( this , new ComfyWebSocketImageData { ImageBytes = data [ 8 ..] , } ) ;
289+ PreviewImageReceived ? . Invoke ( this , new ComfyWebSocketImageData { ImageBytes = data [ 8 ..] } ) ;
291290 }
292291
293292 public override async Task ConnectAsync ( CancellationToken cancellationToken = default )
@@ -326,21 +325,23 @@ public override async Task CloseAsync(CancellationToken cancellationToken = defa
326325 await webSocketClient . Stop ( WebSocketCloseStatus . NormalClosure , string . Empty ) . ConfigureAwait ( false ) ;
327326 }
328327
329- public async Task < ComfyTask > QueuePromptAsync (
330- Dictionary < string , ComfyNode > nodes ,
331- CancellationToken cancellationToken = default
332- )
333- {
334- var request = new ComfyPromptRequest { ClientId = ClientId , Prompt = nodes } ;
328+ public async Task < ComfyTask > QueuePromptAsync (
329+ Dictionary < string , ComfyNode > nodes ,
330+ CancellationToken cancellationToken = default
331+ )
332+ {
333+ var request = new ComfyPromptRequest { ClientId = ClientId , Prompt = nodes } ;
335334
336- var result = await comfyApi . PostPrompt ( request , cancellationToken ) . ConfigureAwait ( false ) ;
335+ var result = await comfyApi . PostPrompt ( request , cancellationToken ) . ConfigureAwait ( false ) ;
337336
338- var task = new ComfyTask ( result . PromptId ) ;
339- PromptTasks . TryAdd ( result . PromptId , task ) ;
340- currentPromptTask = task ;
337+ // Add task to dictionary and set it as the current task
338+ var task = new ComfyTask ( result . PromptId ) ;
339+ PromptTasks . TryAdd ( result . PromptId , task ) ;
340+ currentPromptTask = task ;
341+
342+ return task ;
343+ }
341344
342- return task ;
343- }
344345 public async Task InterruptPromptAsync ( CancellationToken cancellationToken = default )
345346 {
346347 await comfyApi . PostInterrupt ( cancellationToken ) . ConfigureAwait ( false ) ;
0 commit comments