Skip to content

Commit 90b8027

Browse files
committed
updates
1 parent 97e8744 commit 90b8027

36 files changed

+5396
-853
lines changed

MyApp.ServiceInterface/AdminServices.cs

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -692,110 +692,6 @@ public object Any(MigrateToPostgres request)
692692
return ret;
693693
}
694694

695-
private ComfyAgent GetRequiredAgent(string deviceId)
696-
{
697-
var agent = appData.GetComfyAgent(new(DeviceId:deviceId))
698-
?? Db.Single<ComfyAgent>(x => x.DeviceId == deviceId)
699-
?? throw HttpError.NotFound("Device not found");
700-
return agent;
701-
}
702-
703-
public object Post(InstallPipPackage request)
704-
{
705-
var agent = GetRequiredAgent(request.DeviceId);
706-
agent.RequirePip ??= new();
707-
if (!agent.RequirePip.Contains(request.Package))
708-
{
709-
agent.RequirePip.AddIfNotExists(request.Package);
710-
Db.UpdateOnly(() => new ComfyAgent {
711-
RequirePip = agent.RequirePip,
712-
}, where: x => x.DeviceId == agent.DeviceId);
713-
}
714-
715-
agentEvents.Enqueue(request.DeviceId, new AgentEvent
716-
{
717-
Name = EventMessages.InstallPipPackage,
718-
Args = new() {
719-
["package"] = request.Package,
720-
}
721-
});
722-
return new StringResponse
723-
{
724-
Result = $"Enqueued {request.Package} for {request.DeviceId}"
725-
};
726-
}
727-
728-
public object Post(InstallCustomNode request)
729-
{
730-
var agent = GetRequiredAgent(request.DeviceId);
731-
agent.RequireNodes ??= new();
732-
if (!agent.RequireNodes.Contains(request.RepoUrl))
733-
{
734-
agent.RequireNodes.AddIfNotExists(request.RepoUrl);
735-
Db.UpdateOnly(() => new ComfyAgent {
736-
RequireNodes = agent.RequireNodes,
737-
}, where: x => x.DeviceId == agent.DeviceId);
738-
}
739-
740-
agentEvents.Enqueue(request.DeviceId, new AgentEvent
741-
{
742-
Name = EventMessages.InstallCustomNode,
743-
Args = new() {
744-
["url"] = request.RepoUrl,
745-
}
746-
});
747-
return new StringResponse
748-
{
749-
Result = $"Enqueued {request.RepoUrl} for {request.DeviceId}"
750-
};
751-
}
752-
753-
public object Post(InstallModel request)
754-
{
755-
var agent = GetRequiredAgent(request.DeviceId);
756-
agent.RequireModels ??= new();
757-
var model = $"{request.SaveTo.Trim()} {request.Url.Trim()}";
758-
if (!agent.RequireModels.Contains(model))
759-
{
760-
agent.RequireNodes.AddIfNotExists(model);
761-
Db.UpdateOnly(() => new ComfyAgent {
762-
RequireModels = agent.RequireModels,
763-
}, where: x => x.DeviceId == agent.DeviceId);
764-
}
765-
766-
var url = (!string.IsNullOrEmpty(request.Token) ? request.Token + "@" : "") + request.Url;
767-
agentEvents.Enqueue(request.DeviceId, new AgentEvent
768-
{
769-
Name = EventMessages.DownloadModel,
770-
Args = new() {
771-
["model"] = $"{request.SaveTo} {url}",
772-
}
773-
});
774-
return new StringResponse
775-
{
776-
Result = $"Enqueued {url} > {request.SaveTo} for {request.DeviceId}"
777-
};
778-
}
779-
780-
public object Post(RebootAgent request)
781-
{
782-
var agent = GetRequiredAgent(request.DeviceId);
783-
agentEvents.Enqueue(request.DeviceId, new AgentEvent
784-
{
785-
Name = EventMessages.Reboot,
786-
});
787-
return new StringResponse
788-
{
789-
Result = $"Enqueued reboot for {request.DeviceId}"
790-
};
791-
}
792-
793-
public object Get(GetDeviceStatus request)
794-
{
795-
var agent = GetRequiredAgent(request.DeviceId);
796-
return agent.ConvertTo<GetDeviceStatusResponse>();
797-
}
798-
799695
public object Post(AiChat request)
800696
{
801697
using var dbTasks = appData.OpenAiTaskDb();

MyApp.ServiceInterface/AgentServices.cs

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ public object Post(UpdateComfyAgent request)
5454
return new EmptyResponse();
5555
}
5656

57+
agent.SetLastUpdate();
5758
agent.QueueCount = request.QueueCount;
5859
agent.RunningGenerationIds = request.RunningGenerationIds ?? [];
5960
agent.QueuedGenerationIds = request.QueuedGenerationIds ?? [];
6061
agent.QueuedIds = [..agent.QueuedGenerationIds, ..agent.RunningGenerationIds];
61-
agent.LastUpdate = DateTime.UtcNow;
62-
agent.ModifiedDate = DateTime.UtcNow;
6362
agent.Gpus = request.Gpus ?? agent.Gpus;
6463
agent.RunningGenerationIds = request.RunningGenerationIds ?? [];
6564
agent.QueuedGenerationIds = request.QueuedGenerationIds ?? [];
@@ -68,7 +67,7 @@ public object Post(UpdateComfyAgent request)
6867
{
6968
QueueCount = agent.QueueCount,
7069
Gpus = agent.Gpus,
71-
ModifiedDate = now,
70+
ModifiedDate = agent.ModifiedDate,
7271
LastIp = Request!.UserHostAddress,
7372
}, where: x => x.DeviceId == request.DeviceId);
7473

@@ -107,14 +106,40 @@ public object Any(UpdateComfyAgentStatus request)
107106
return new EmptyResponse();
108107
}
109108

109+
agent.Status = request.Status ?? agent.Status;
110+
agent.Downloading = request.Downloading ?? agent.Downloading;
111+
agent.Downloaded = request.Downloaded ?? agent.Downloaded;
112+
agent.DownloadFailed = request.DownloadFailed ?? agent.DownloadFailed;
113+
agent.Logs = request.Logs ?? agent.Logs;
114+
agent.Error = request.Error ?? agent.Error;
115+
agent.SetLastUpdate(now);
116+
110117
using var db = Db;
111-
db.UpdateOnly(() => new ComfyAgent
118+
if (request.Logs != null)
112119
{
113-
Status = request.Status ?? agent.Status,
114-
Logs = request.Logs ?? agent.Logs,
115-
Error = request.Error ?? agent.Error,
116-
ModifiedDate = now,
117-
}, where: x => x.DeviceId == request.DeviceId);
120+
db.UpdateOnly(() => new ComfyAgent
121+
{
122+
Status = agent.Status,
123+
Downloading = agent.Downloading,
124+
Downloaded = agent.Downloaded,
125+
DownloadFailed = agent.DownloadFailed,
126+
Logs = agent.Logs,
127+
Error = agent.Error,
128+
ModifiedDate = agent.ModifiedDate,
129+
}, where: x => x.DeviceId == request.DeviceId);
130+
}
131+
else
132+
{
133+
db.UpdateOnly(() => new ComfyAgent
134+
{
135+
Status = agent.Status,
136+
Downloading = agent.Downloading,
137+
Downloaded = agent.Downloaded,
138+
DownloadFailed = agent.DownloadFailed,
139+
Error = agent.Error,
140+
ModifiedDate = now,
141+
}, where: x => x.DeviceId == request.DeviceId);
142+
}
118143

119144
return new EmptyResponse();
120145
}
@@ -150,7 +175,7 @@ public async Task<object> Get(GetComfyAgentEvents request)
150175
ret.Results.Add(new AgentEvent { Name = EventMessages.Register });
151176
return ret;
152177
}
153-
agent.ModifiedDate = agent.LastUpdate = DateTime.UtcNow;
178+
agent.SetLastUpdate();
154179

155180
// Return any pending events immediately
156181
var agentEvents = agentManager.GetAgentEvents(agent.DeviceId);
@@ -271,11 +296,13 @@ public async Task<object> Any(RegisterComfyAgent request)
271296
RequireNodes = appData.RequireNodes,
272297
RequireModels = appData.RequireModels,
273298
DevicePool = DateTime.UtcNow,
299+
Settings = new ComfyAgentSettings {
300+
PreserveOutputs = false,
301+
},
274302
};
275303
}
276304

277-
agent.LastUpdate = DateTime.UtcNow;
278-
305+
agent.SetLastUpdate();
279306
agent.Version = request.Version;
280307
agent.ComfyVersion = request.ComfyVersion;
281308
agent.Gpus = request.Gpus;
@@ -286,9 +313,9 @@ public async Task<object> Any(RegisterComfyAgent request)
286313
agent.ApiKey = apiKey.Key;
287314
agent.Enabled = true;
288315
agent.OfflineDate = null;
289-
agent.ModifiedDate = DateTime.UtcNow;
290316
agent.LastIp = Request.UserHostAddress;
291317
agent.LanguageModels = request.LanguageModels;
318+
agent.Downloading = null;
292319
agent.Status = "Registered";
293320
agent.Logs = null;
294321
agent.Error = null;
@@ -298,25 +325,37 @@ public async Task<object> Any(RegisterComfyAgent request)
298325
agent.Checkpoints = sorted(checkpointLoader.GetInput("ckpt_name")?.EnumValues);
299326

300327
if (nodeDefs.TryGetValue("UNETLoader", out var unetLoader))
301-
agent.Unets = sorted(unetLoader.GetInput("unet_name")?.EnumValues);
328+
agent.DiffusionModels = sorted(unetLoader.GetInput("unet_name")?.EnumValues);
302329
if (nodeDefs.TryGetValue("VAELoader", out var vaeLoader))
303-
agent.Vaes = sorted(vaeLoader.GetInput("vae_name")?.EnumValues);
330+
agent.Vae = sorted(vaeLoader.GetInput("vae_name")?.EnumValues);
304331
if (nodeDefs.TryGetValue("CLIPLoader", out var clipLoader))
305-
agent.Clips = sorted(clipLoader.GetInput("clip_name")?.EnumValues);
332+
agent.Clip = sorted(clipLoader.GetInput("clip_name")?.EnumValues);
306333
if (nodeDefs.TryGetValue("CLIPVisionLoader", out var clipVisionLoader))
307-
agent.ClipVisions = sorted(clipVisionLoader.GetInput("clip_name")?.EnumValues);
334+
agent.ClipVision = sorted(clipVisionLoader.GetInput("clip_name")?.EnumValues);
308335
if (nodeDefs.TryGetValue("LoraLoader", out var loraLoader))
309336
agent.Loras = sorted(loraLoader.GetInput("lora_name")?.EnumValues);
310337
if (nodeDefs.TryGetValue("UpscaleModelLoader", out var upscaleLoader))
311-
agent.Upscalers = sorted(upscaleLoader.GetInput("model_name")?.EnumValues);
338+
agent.UpscaleModels = sorted(upscaleLoader.GetInput("model_name")?.EnumValues);
312339
if (nodeDefs.TryGetValue("ControlNetLoader", out var controlNetLoader))
313-
agent.ControlNets = sorted(controlNetLoader.GetInput("control_net_name")?.EnumValues);
340+
agent.Controlnet = sorted(controlNetLoader.GetInput("control_net_name")?.EnumValues);
314341
if (nodeDefs.TryGetValue("StyleModelLoader", out var styleLoader))
315-
agent.Stylers = sorted(styleLoader.GetInput("style_model_name")?.EnumValues);
342+
agent.StyleModels = sorted(styleLoader.GetInput("style_model_name")?.EnumValues);
316343
if (nodeDefs.TryGetValue("PhotoMakerLoader", out var photoMakerLoader))
317-
agent.PhotoMakers = sorted(photoMakerLoader.GetInput("photomaker_model_name")?.EnumValues);
344+
agent.Photomaker = sorted(photoMakerLoader.GetInput("photomaker_model_name")?.EnumValues);
318345
if (nodeDefs.TryGetValue("GLIGENLoader", out var gligenLoader))
319-
agent.Gligens = sorted(gligenLoader.GetInput("gligen_name")?.EnumValues);
346+
agent.Gligen = sorted(gligenLoader.GetInput("gligen_name")?.EnumValues);
347+
348+
//TODO Verify predicted locations
349+
agent.Hypernetworks = sorted(nodeDefs.TryGetValue("HypernetworkLoader", out var hypernetworkLoader)
350+
? hypernetworkLoader.GetInput("hypernetwork_name")?.EnumValues : null);
351+
agent.Diffusers = sorted(nodeDefs.TryGetValue("DiffusersLoader", out var diffusersLoader)
352+
? diffusersLoader.GetInput("model_path")?.EnumValues : null); // diffusers_name?
353+
agent.Embeddings = sorted(nodeDefs.TryGetValue("TextualInversionLoader", out var textualInversionLoader)
354+
? textualInversionLoader.GetInput("textual_inversion_name")?.EnumValues : null);
355+
agent.Configs = sorted(nodeDefs.TryGetValue("ConfigLoader", out var configLoader)
356+
? configLoader.GetInput("config_name")?.EnumValues : null);
357+
agent.VaeApprox = sorted(nodeDefs.TryGetValue("VAEApproxLoader", out var vaeApproxLoader)
358+
? vaeApproxLoader.GetInput("vae_approx_name")?.EnumValues : null);
320359

321360
db.Save(agent);
322361

@@ -353,6 +392,7 @@ public async Task<object> Any(RegisterComfyAgent request)
353392
RequirePip = appData.RequirePip,
354393
RequireNodes = appData.RequireNodes,
355394
RequireModels = appData.RequireModels,
395+
Settings = agent.Settings,
356396
};
357397

358398
return ret;

0 commit comments

Comments
 (0)