From 49aa55425776384b59ec83f4dba8316f598db1ff Mon Sep 17 00:00:00 2001 From: Ionite Date: Thu, 11 Apr 2024 15:22:01 -0400 Subject: [PATCH 01/19] Fix settings env var conflict --- .../Models/Settings/Settings.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/StabilityMatrix.Core/Models/Settings/Settings.cs b/StabilityMatrix.Core/Models/Settings/Settings.cs index 01e22fd2..ff65f104 100644 --- a/StabilityMatrix.Core/Models/Settings/Settings.cs +++ b/StabilityMatrix.Core/Models/Settings/Settings.cs @@ -118,10 +118,22 @@ public class Settings public Dictionary? UserEnvironmentVariables { get; set; } [JsonIgnore] - public IReadOnlyDictionary EnvironmentVariables => - DefaultEnvironmentVariables - .Concat(UserEnvironmentVariables ?? []) - .ToDictionary(x => x.Key, x => x.Value); + public IReadOnlyDictionary EnvironmentVariables + { + get + { + if (UserEnvironmentVariables is null || UserEnvironmentVariables.Count == 0) + { + return DefaultEnvironmentVariables; + } + + return DefaultEnvironmentVariables + .Concat(UserEnvironmentVariables) + .GroupBy(pair => pair.Key) + // User variables override default variables with the same key + .ToDictionary(grouping => grouping.Key, grouping => grouping.Last().Value); + } + } public HashSet? InstalledModelHashes { get; set; } = new(); From e41b4195dc90de7738ff2dfeada3e04409547b2b Mon Sep 17 00:00:00 2001 From: Ionite Date: Thu, 11 Apr 2024 15:24:01 -0400 Subject: [PATCH 02/19] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 546b1b81..c644343d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to Stability Matrix will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html). +## v2.10.1 +### Fixed +- Fixed package launch not working when environment variable `SETUPTOOLS_USE_DISTUTILS` is set due to conflict with a default environment variable. User environment variables will now correctly override any default environment variables. + ## v2.10.0 ### Added - Added Reference-Only mode for Inference ControlNet, used for guiding the sampler with an image without a pretrained model. Part of the latent and attention layers will be connected to the reference image, similar to Image to Image or Inpainting. From ef25d5b944aacfc1b507c272bbde97620befbee0 Mon Sep 17 00:00:00 2001 From: JT Date: Fri, 12 Apr 2024 18:26:05 -0700 Subject: [PATCH 03/19] Fix Inference teaching tip showing more often & fix `--launch-package` argument not working --- CHANGELOG.md | 5 +++ .../Inference/PromptCardViewModel.cs | 4 ++ .../ViewModels/PackageManagerViewModel.cs | 45 ++++++++++++++++--- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 546b1b81..ecc12f07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to Stability Matrix will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html). +## v2.10.1 +### Fixed +- Fixed [#584](https://github.com/LykosAI/StabilityMatrix/issues/584) - `--launch-package` argument not working +- Fixed [#581](https://github.com/LykosAI/StabilityMatrix/issues/581) - Inference teaching tip showing more often than it should + ## v2.10.0 ### Added - Added Reference-Only mode for Inference ControlNet, used for guiding the sampler with an image without a pretrained model. Part of the latent and attention layers will be connected to the reference image, similar to Image to Image or Inpainting. diff --git a/StabilityMatrix.Avalonia/ViewModels/Inference/PromptCardViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Inference/PromptCardViewModel.cs index 919e4e30..cbae5b9c 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Inference/PromptCardViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Inference/PromptCardViewModel.cs @@ -104,6 +104,10 @@ public partial class PromptCardViewModel : LoadableViewModelBase, IParametersLoa if (!settingsManager.Settings.SeenTeachingTips.Contains(TeachingTip.InferencePromptHelpButtonTip)) { IsHelpButtonTeachingTipOpen = true; + settingsManager.Transaction(settings => + { + settings.SeenTeachingTips.Add(TeachingTip.InferencePromptHelpButtonTip); + }); } } diff --git a/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs index 9d59df05..faf3e63f 100644 --- a/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs @@ -42,6 +42,7 @@ public partial class PackageManagerViewModel : PageViewModelBase private readonly INotificationService notificationService; private readonly INavigationService packageNavigationService; private readonly ILogger logger; + private readonly RunningPackageService runningPackageService; public override string Title => Resources.Label_Packages; public override IconSource IconSource => new SymbolIconSource { Symbol = Symbol.Box, IsFilled = true }; @@ -69,7 +70,8 @@ public partial class PackageManagerViewModel : PageViewModelBase ServiceManager dialogFactory, INotificationService notificationService, INavigationService packageNavigationService, - ILogger logger + ILogger logger, + RunningPackageService runningPackageService ) { this.settingsManager = settingsManager; @@ -77,6 +79,7 @@ public partial class PackageManagerViewModel : PageViewModelBase this.notificationService = notificationService; this.packageNavigationService = packageNavigationService; this.logger = logger; + this.runningPackageService = runningPackageService; EventManager.Instance.InstalledPackagesChanged += OnInstalledPackagesChanged; EventManager.Instance.OneClickInstallFinished += OnOneClickInstallFinished; @@ -118,15 +121,39 @@ public partial class PackageManagerViewModel : PageViewModelBase unknownInstalledPackages.Edit(s => s.Load(packages)); } + protected override async Task OnInitialLoadedAsync() + { + if (string.IsNullOrWhiteSpace(Program.Args.LaunchPackageName)) + { + await base.OnInitialLoadedAsync(); + return; + } + + await LoadPackages(); + + var package = Packages.FirstOrDefault(x => x.DisplayName == Program.Args.LaunchPackageName); + if (package is not null) + { + await runningPackageService.StartPackage(package); + return; + } + + package = Packages.FirstOrDefault(x => x.Id.ToString() == Program.Args.LaunchPackageName); + if (package is null) + { + await base.OnInitialLoadedAsync(); + return; + } + + await runningPackageService.StartPackage(package); + } + public override async Task OnLoadedAsync() { if (Design.IsDesignMode || !settingsManager.IsLibraryDirSet) return; - installedPackages.EditDiff(settingsManager.Settings.InstalledPackages, InstalledPackage.Comparer); - - var currentUnknown = await Task.Run(IndexUnknownPackages); - unknownInstalledPackages.Edit(s => s.Load(currentUnknown)); + await LoadPackages(); timer.Start(); } @@ -142,6 +169,14 @@ public partial class PackageManagerViewModel : PageViewModelBase NavigateToSubPage(typeof(PackageInstallBrowserViewModel)); } + private async Task LoadPackages() + { + installedPackages.EditDiff(settingsManager.Settings.InstalledPackages, InstalledPackage.Comparer); + + var currentUnknown = await Task.Run(IndexUnknownPackages); + unknownInstalledPackages.Edit(s => s.Load(currentUnknown)); + } + private async Task CheckPackagesForUpdates() { foreach (var package in PackageCards) From 90e815a4213a9764a1baead229a1372c932ef6ea Mon Sep 17 00:00:00 2001 From: Ionite Date: Fri, 12 Apr 2024 22:36:51 -0400 Subject: [PATCH 04/19] Fix auth header added to all lykosauthapi routes --- .../Api/TokenAuthHeaderHandler.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/StabilityMatrix.Core/Api/TokenAuthHeaderHandler.cs b/StabilityMatrix.Core/Api/TokenAuthHeaderHandler.cs index 25cdaa6f..3efe6847 100644 --- a/StabilityMatrix.Core/Api/TokenAuthHeaderHandler.cs +++ b/StabilityMatrix.Core/Api/TokenAuthHeaderHandler.cs @@ -22,8 +22,7 @@ public class TokenAuthHeaderHandler : DelegatingHandler .HandleResult( r => r.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden - && r.RequestMessage?.Headers.Authorization - is { Scheme: "Bearer", Parameter: not null } + && r.RequestMessage?.Headers.Authorization is { Scheme: "Bearer", Parameter: not null } ) .RetryAsync( async (result, _) => @@ -35,9 +34,7 @@ public class TokenAuthHeaderHandler : DelegatingHandler "Refreshing access token for status ({StatusCode})", result.Result.StatusCode ); - var (newToken, _) = await tokenProvider - .RefreshTokensAsync() - .ConfigureAwait(false); + var (newToken, _) = await tokenProvider.RefreshTokensAsync().ConfigureAwait(false); Logger.Info( "Access token refreshed: {OldToken} -> {NewToken}", @@ -46,10 +43,6 @@ public class TokenAuthHeaderHandler : DelegatingHandler ); } ); - - // InnerHandler must be left as null when using DI, but must be assigned a value when - // using RestService.For - // InnerHandler = new HttpClientHandler(); } protected override Task SendAsync( @@ -59,9 +52,17 @@ public class TokenAuthHeaderHandler : DelegatingHandler { return policy.ExecuteAsync(async () => { - var accessToken = await tokenProvider.GetAccessTokenAsync().ConfigureAwait(false); + // Only add if Authorization is already set to Bearer and access token is not empty + // this allows some routes to not use the access token + if (request.Headers.Authorization is { Scheme: "Bearer" }) + { + var accessToken = await tokenProvider.GetAccessTokenAsync().ConfigureAwait(false); - request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); + if (!string.IsNullOrWhiteSpace(accessToken)) + { + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); + } + } return await base.SendAsync(request, cancellationToken).ConfigureAwait(false); }); From d3b37229dae439f36288ff790f56f7ce780f4f08 Mon Sep 17 00:00:00 2001 From: Ionite Date: Fri, 12 Apr 2024 22:38:32 -0400 Subject: [PATCH 05/19] Fix token refresh when access token is empty --- StabilityMatrix.Core/Api/TokenAuthHeaderHandler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/StabilityMatrix.Core/Api/TokenAuthHeaderHandler.cs b/StabilityMatrix.Core/Api/TokenAuthHeaderHandler.cs index 3efe6847..b042d6b7 100644 --- a/StabilityMatrix.Core/Api/TokenAuthHeaderHandler.cs +++ b/StabilityMatrix.Core/Api/TokenAuthHeaderHandler.cs @@ -22,7 +22,8 @@ public class TokenAuthHeaderHandler : DelegatingHandler .HandleResult( r => r.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden - && r.RequestMessage?.Headers.Authorization is { Scheme: "Bearer", Parameter: not null } + && r.RequestMessage?.Headers.Authorization is { Scheme: "Bearer", Parameter: { } param } + && !string.IsNullOrWhiteSpace(param) ) .RetryAsync( async (result, _) => From a75908e4ef2495ffb7c007bec1ddcb43e0133104 Mon Sep 17 00:00:00 2001 From: Ionite Date: Fri, 12 Apr 2024 22:47:54 -0400 Subject: [PATCH 06/19] Improve login error message --- .../ViewModels/Dialogs/LykosLoginViewModel.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/LykosLoginViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/LykosLoginViewModel.cs index 471d052b..7dd14a8b 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/LykosLoginViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/LykosLoginViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Net; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -90,7 +91,15 @@ public partial class LykosLoginViewModel : TaskDialogViewModelBase } catch (ApiException e) { - LoginError = new AppException("Failed to login", $"{e.StatusCode} - {e.Message}"); + LoginError = e.StatusCode switch + { + HttpStatusCode.Unauthorized + => new AppException( + "Incorrect email or password", + "Please try again or reset your password" + ), + _ => new AppException("Failed to login", $"{e.StatusCode} - {e.Message}") + }; } } From 01cc2f89a7930d2aaa472392689926347b32d9ae Mon Sep 17 00:00:00 2001 From: Ionite Date: Fri, 12 Apr 2024 22:48:16 -0400 Subject: [PATCH 07/19] Add LykosLoginDialog max width --- StabilityMatrix.Avalonia/Views/Dialogs/LykosLoginDialog.axaml | 1 + 1 file changed, 1 insertion(+) diff --git a/StabilityMatrix.Avalonia/Views/Dialogs/LykosLoginDialog.axaml b/StabilityMatrix.Avalonia/Views/Dialogs/LykosLoginDialog.axaml index 98ab8228..0f0de8a5 100644 --- a/StabilityMatrix.Avalonia/Views/Dialogs/LykosLoginDialog.axaml +++ b/StabilityMatrix.Avalonia/Views/Dialogs/LykosLoginDialog.axaml @@ -14,6 +14,7 @@ xmlns:mdxaml="https://github.com/whistyun/Markdown.Avalonia.Tight" xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia" Focusable="True" + MaxWidth="400" d:DataContext="{x:Static mocks:DesignData.LykosLoginViewModel}" d:DesignHeight="350" d:DesignWidth="400" From 128ef132293371c25c343a6a7b9432a631ac5481 Mon Sep 17 00:00:00 2001 From: Ionite Date: Fri, 12 Apr 2024 22:50:40 -0400 Subject: [PATCH 08/19] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c644343d..163fed1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2 ## v2.10.1 ### Fixed - Fixed package launch not working when environment variable `SETUPTOOLS_USE_DISTUTILS` is set due to conflict with a default environment variable. User environment variables will now correctly override any default environment variables. +- Fixed "No refresh token found" error when failing to login with Lykos account in some cases. ## v2.10.0 ### Added From 64c55ec3799efe8b83196d4eb946d1c9b22c646c Mon Sep 17 00:00:00 2001 From: Ionite Date: Fri, 12 Apr 2024 22:52:02 -0400 Subject: [PATCH 09/19] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 163fed1f..76a4992d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html). ## v2.10.1 +### Changed +- Improved error message when logging in with a Lykos account fails due to incorrect email or password. ### Fixed - Fixed package launch not working when environment variable `SETUPTOOLS_USE_DISTUTILS` is set due to conflict with a default environment variable. User environment variables will now correctly override any default environment variables. - Fixed "No refresh token found" error when failing to login with Lykos account in some cases. From 68a9968794b2b3f6480a77ad4f05def4478a4112 Mon Sep 17 00:00:00 2001 From: JT Date: Fri, 12 Apr 2024 20:21:18 -0700 Subject: [PATCH 10/19] twoway? --- StabilityMatrix.Avalonia/Controls/Inference/PromptCard.axaml | 2 +- .../ViewModels/Inference/PromptCardViewModel.cs | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/StabilityMatrix.Avalonia/Controls/Inference/PromptCard.axaml b/StabilityMatrix.Avalonia/Controls/Inference/PromptCard.axaml index 12423e48..7539cbde 100644 --- a/StabilityMatrix.Avalonia/Controls/Inference/PromptCard.axaml +++ b/StabilityMatrix.Avalonia/Controls/Inference/PromptCard.axaml @@ -72,7 +72,7 @@ + IsOpen="{Binding IsHelpButtonTeachingTipOpen, Mode=TwoWay}"/>