Improved the assistants page with categories for assistant plugins (#1211)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-20 11:47:59 +01:00
1 parent ef059ffd15
commit 1db0f85898
74 files changed
+3392 -380

No files matched your search

@@ -1,31 +1,72 @@
using AIStudio.Components;
using AIStudio.Agents.AssistantAudit;
using AIStudio.Dialogs.Settings;
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.PluginSystem.Assistants;
using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components;
using DialogOptions = AIStudio.Dialogs.DialogOptions;
namespace AIStudio.Pages;
public partial class Assistants : MSGComponentBase
{
private static readonly AssistantCategoryKey COMMON = new(PluginCategory.COMMON);
private static readonly AssistantCategoryKey BUSINESS = new(PluginCategory.BUSINESS);
private static readonly AssistantCategoryKey EDUCATION = new(PluginCategory.EDUCATION);
private static readonly AssistantCategoryKey SOFTWARE_DEVELOPMENT = new(PluginCategory.SOFTWARE_DEVELOPMENT);
private readonly AssistantCategoryRegistry categoryRegistry = new();
private bool isAutoAuditing;
[Inject]
private AssistantPluginAuditService AssistantPluginAuditService { get; init; } = null!;
[Inject]
private NavigationManager NavigationManager { get; init; } = null!;
private IDialogService DialogService { get; init; } = null!;
[Inject]
private DirectChatService DirectChatService { get; init; } = null!;
protected override async Task OnInitializedAsync()
{
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED, Event.PLUGINS_RELOADED ]);
this.categoryRegistry.ShowsAnyCategoryChanged += this.StateHasChanged;
await base.OnInitializedAsync();
}
/// <inheritdoc />
protected override void DisposeResources()
{
this.categoryRegistry.ShowsAnyCategoryChanged -= this.StateHasChanged;
base.DisposeResources();
}
/// <summary>
/// Gets whether the user hid every category the page would show, so that it shows none.
/// </summary>
/// <remarks>
/// Without a hint, the page would look broken. When your organization hid or disabled every
/// assistant instead, the gear brings nothing back, so we keep quiet then.
/// </remarks>
private bool HidesEveryCategory
{
get
{
var page = this.SettingsManager.ConfigurationData.AssistantsPage;
return this.categoryRegistry.ShowsAnyCategory is false && (page.HiddenCategories.Count > 0 || page.HiddenCustomCategories.Count > 0);
}
}
private async Task OpenSettingsDialogAsync()
{
var categories = AssistantPageSections.SelectForSettings(this.categoryRegistry.ShownCategories, this.SettingsManager.ConfigurationData.App, this.SettingsManager.ConfigurationData.AssistantsPage);
var dialogParameters = new DialogParameters<SettingsDialogAssistantsPage>
{
{ x => x.Categories, categories },
};
await this.DialogService.ShowAsync<SettingsDialogAssistantsPage>(T("Assistant Settings"), dialogParameters, DialogOptions.FULLSCREEN);
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
@@ -34,9 +75,18 @@ public partial class Assistants : MSGComponentBase
private IReadOnlyCollection<PluginAssistants> AssistantPlugins =>
PluginFactory.RunningPlugins.OfType<PluginAssistants>()
.Where(plugin => this.SettingsManager.IsPluginEnabled(plugin))
.Where(plugin => this.SettingsManager.IsAssistantPluginAvailable(plugin))
.ToList();
/// <summary>
/// Groups the enabled assistant plugins into the sections of the page.
/// </summary>
/// <remarks>
/// The page asks for the sections once per rendering, so that the plugins and their order stay the
/// same within one rendering.
/// </remarks>
private IReadOnlyList<AssistantPageSection<PluginAssistants>> CreateSections() => AssistantPageSections.Build(this.AssistantPlugins, plugin => plugin.AssistantTitle);
private async Task TryAutoAuditAssistantsAsync()
{
if (this.isAutoAuditing || !this.SettingsManager.ConfigurationData.AssistantPluginAudit.AutomaticallyAuditAssistants)
@@ -88,29 +138,6 @@ public partial class Assistants : MSGComponentBase
audits.Add(audit);
}
private async Task StartAssistantPluginAsync(PluginAssistants assistantPlugin)
{
var securityState = PluginAssistantSecurityResolver.Resolve(this.SettingsManager, assistantPlugin);
if (!securityState.CanStartAssistant)
return;
if (!assistantPlugin.StartsChatDirectly)
{
this.NavigationManager.NavigateTo($"{Routes.ASSISTANT_DYNAMIC}?assistantId={assistantPlugin.Id}");
return;
}
var result = await this.DirectChatService.TryCreateAssistantChatAsync(assistantPlugin);
if (result.Request is null)
{
await this.MessageBus.SendError(new(AppIcons.ERROR, result.ErrorMessage));
return;
}
MessageBus.INSTANCE.DeferMessage(this, Event.SEND_TO_CHAT, result.Request);
this.NavigationManager.NavigateTo(Routes.CHAT);
}
protected override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
{
if (triggeredEvent is Event.PLUGINS_RELOADED)