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

+56 -69
View File
@@ -1,88 +1,75 @@
@attribute [Route(Routes.ASSISTANTS)]
@using AIStudio.Dialogs.Settings
@using AIStudio.Settings.DataModel
@using AIStudio.Tools.PluginSystem
@using AIStudio.Tools.PluginSystem.Assistants
@inherits MSGComponentBase
<div class="inner-scrolling-context">
<MudText Typo="Typo.h3" Class="mb-2 mr-3">
@T("Assistants")
</MudText>
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-2" StretchItems="StretchItems.Start">
<MudText Typo="Typo.h3">
@T("Assistants")
</MudText>
<MudTooltip Text="@T("Open the assistant settings")" Placement="Placement.Bottom">
<MudIconButton Icon="@AppIcons.SETTINGS" Color="Color.Default" OnClick="@this.OpenSettingsDialogAsync"/>
</MudTooltip>
</MudStack>
<InnerScrolling>
@{ var sections = this.CreateSections(); }
<AssistantCategoryBlock Title="@T("General")" HeaderClass="mb-2 mr-3">
<AssistantBlock TSettings="SettingsDialogTextSummarizer" Component="Components.TEXT_SUMMARIZER_ASSISTANT" Name="@T("Text Summarizer")" Description="@TA("Use an LLM to summarize a given text.")" Icon="@AppIcons.ASSISTANT_TEXT_SUMMARIZER" Link="@Routes.ASSISTANT_SUMMARIZER"/>
<AssistantBlock TSettings="SettingsDialogTranslation" Component="Components.TRANSLATION_ASSISTANT" Name="@T("Translation")" Description="@T("Translate text into another language.")" Icon="@AppIcons.TRANSLATION" Link="@Routes.ASSISTANT_TRANSLATION"/>
<AssistantBlock TSettings="SettingsDialogGrammarSpelling" Component="Components.GRAMMAR_SPELLING_ASSISTANT" Name="@T("Grammar & Spelling")" Description="@T("Check grammar and spelling of a given text.")" Icon="@AppIcons.ASSISTANT_GRAMMAR_SPELLING" Link="@Routes.ASSISTANT_GRAMMAR_SPELLING"/>
<AssistantBlock TSettings="SettingsDialogRewrite" Component="Components.REWRITE_ASSISTANT" Name="@T("Rewrite & Improve")" Description="@T("Rewrite and improve a given text for a chosen style.")" Icon="@AppIcons.ASSISTANT_REWRITE" Link="@Routes.ASSISTANT_REWRITE"/>
<AssistantBlock TSettings="SettingsDialogPromptOptimizer" Component="Components.PROMPT_OPTIMIZER_ASSISTANT" Name="@T("Prompt Optimizer")" Description="@TA("Optimize your prompt using a structured guideline.")" Icon="@AppIcons.ASSISTANT_PROMPT_OPTIMIZER" Link="@Routes.ASSISTANT_PROMPT_OPTIMIZER"/>
<AssistantBlock TSettings="SettingsDialogSynonyms" Component="Components.SYNONYMS_ASSISTANT" Name="@T("Synonyms")" Description="@TA("Find synonyms for a given word or phrase.")" Icon="@AppIcons.ASSISTANT_SYNONYMS" Link="@Routes.ASSISTANT_SYNONYMS"/>
<AssistantBlock TSettings="SettingsDialogModelComparison" Component="Components.MODEL_COMPARISON_ASSISTANT" Name="@T("Model Comparison")" Description="@TA("Compare two models in a blind test for how much their answers vary and how useful they are.")" Icon="@AppIcons.ASSISTANT_MODEL_COMPARISON" Link="@Routes.ASSISTANT_MODEL_COMPARISON"/>
<AssistantBlock TSettings="SettingsDialogAssistantBuilder" Component="Components.META_ASSISTANT" RequiredPreviewFeature="PreviewFeatures.PRE_META_ASSISTANT_V1" Name="@T("Assistant Builder")" Description="@TA("Generate your own assistants.")" Icon="@AppIcons.ASSISTANT_BUILDER" Link="@Routes.ASSISTANT_META_ASSISTANT"/>
</AssistantCategoryBlock>
@if (this.AssistantPlugins.Count > 0)
@if (this.HidesEveryCategory)
{
<AssistantCategoryBlock Title="@T("Installed Assistants")">
@foreach (var assistantPlugin in this.AssistantPlugins)
{
var securityState = PluginAssistantSecurityResolver.Resolve(this.SettingsManager, assistantPlugin);
var launchLink = assistantPlugin.StartsChatDirectly ? string.Empty : $"{Routes.ASSISTANT_DYNAMIC}?assistantId={assistantPlugin.Id}";
var availablePlugin = PluginFactory.AvailablePlugins.OfType<IAvailablePlugin>().FirstOrDefault(plugin => plugin.Id == assistantPlugin.Id);
<AssistantBlock TSettings="NoSettingsPanel"
Component="Components.DYNAMIC_ASSISTANT"
Name="@T(assistantPlugin.AssistantTitle)"
Description="@T(assistantPlugin.Description)"
Icon="@AppIcons.ASSISTANT_PLUGIN"
Disabled="@(!securityState.CanStartAssistant)"
AssistantSessionInstanceId="@assistantPlugin.Id.ToString()"
Link="@launchLink"
OnClick="@(() => this.StartAssistantPluginAsync(assistantPlugin))">
<AdditionalActions>
<DirectChatLauncherSettingsAction Plugin="@assistantPlugin" />
@if (availablePlugin is not null)
{
<PluginDeleteAction Plugin="@availablePlugin" />
}
</AdditionalActions>
<SecurityBadge>
<AssistantPluginSecurityCard Plugin="@assistantPlugin" Compact="@true" />
</SecurityBadge>
</AssistantBlock>
}
</AssistantCategoryBlock>
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined" Class="mb-3">
@TA("You hid all categories. You can show them again in the assistant settings, which the gear next to the heading opens.")
</MudAlert>
}
<AssistantCategoryBlock Title="@T("Business")">
<AssistantBlock TSettings="SettingsDialogWritingEMails" Component="Components.EMAIL_ASSISTANT" Name="@T("E-Mail")" Description="@TA("Generate an e-mail for a given context.")" Icon="@AppIcons.ASSISTANT_EMAIL" Link="@Routes.ASSISTANT_EMAIL"/>
<AssistantBlock TSettings="SettingsDialogSWOTAnalysis" Component="Components.SWOT_ANALYSIS_ASSISTANT" Name="@T("SWOT Analysis")" Description="@T("Identify strengths, weaknesses, opportunities, threats, and practical next steps from provided information.")" Icon="@AppIcons.ASSISTANT_SWOT_ANALYSIS" Link="@Routes.ASSISTANT_SWOT_ANALYSIS"/>
<AssistantBlock TSettings="NoSettingsPanel" Component="Components.DOCUMENT_ANALYSIS_ASSISTANT" Name="@T("Document Analysis")" Description="@TA("Analyze a document regarding defined rules and extract key information.")" Icon="@AppIcons.ASSISTANT_DOCUMENT_ANALYSIS" Link="@Routes.ASSISTANT_DOCUMENT_ANALYSIS"/>
<AssistantBlock TSettings="SettingsDialogBatchProcessing" Component="Components.BATCH_PROCESSING_ASSISTANT" Name="@T("Batch Processing")" Description="@T("Process all documents of a folder in one batch run and collect the results.")" Icon="@AppIcons.ASSISTANT_BATCH_PROCESSING" Link="@Routes.ASSISTANT_BATCH_PROCESSING"/>
<AssistantBlock TSettings="SettingsDialogMyTasks" Component="Components.MY_TASKS_ASSISTANT" Name="@T("My Tasks")" Description="@TA("Analyze a text or an email for tasks you need to complete.")" Icon="@AppIcons.ASSISTANT_MY_TASKS" Link="@Routes.ASSISTANT_MY_TASKS"/>
<AssistantBlock TSettings="SettingsDialogAgenda" Component="Components.AGENDA_ASSISTANT" Name="@T("Agenda Planner")" Description="@TA("Generate an agenda for a given meeting, seminar, etc.")" Icon="@AppIcons.ASSISTANT_AGENDA" Link="@Routes.ASSISTANT_AGENDA"/>
<AssistantBlock TSettings="SettingsDialogJobPostings" Component="Components.JOB_POSTING_ASSISTANT" Name="@T("Job Posting")" Description="@TA("Generate a job posting for a given job description.")" Icon="@AppIcons.ASSISTANT_JOB_POSTING" Link="@Routes.ASSISTANT_JOB_POSTING"/>
<AssistantBlock TSettings="SettingsDialogLegalCheck" Component="Components.LEGAL_CHECK_ASSISTANT" Name="@T("Legal Check")" Description="@TA("Ask a question about a legal document.")" Icon="@AppIcons.ASSISTANT_LEGAL_CHECK" Link="@Routes.ASSISTANT_LEGAL_CHECK"/>
<AssistantBlock TSettings="SettingsDialogIconFinder" Component="Components.ICON_FINDER_ASSISTANT" Name="@T("Icon Finder")" Description="@TA("Use an LLM to find an icon for a given context.")" Icon="@AppIcons.ASSISTANT_ICON_FINDER" Link="@Routes.ASSISTANT_ICON_FINDER"/>
<AssistantBlock TSettings="SettingsDialogSlideBuilder" Component="Components.SLIDE_BUILDER_ASSISTANT" Name="@T("Slide Assistant")" Description="@TA("Turn texts and documents into slides, also as a PowerPoint file in the design of your template.")" Icon="@AppIcons.ASSISTANT_SLIDES" Link="@Routes.ASSISTANT_SLIDE_BUILDER"/>
<AssistantBlock TSettings="SettingsDialogVisualBriefing" Component="Components.VISUAL_BRIEFING_ASSISTANT" RequiredPreviewFeature="Components.VISUAL_BRIEFING_ASSISTANT.RequiredPreviewFeature" Name="@T("Visual Briefing Assistant")" Description="@TA("Turn documents, data, images, audio, and video into an audience-ready interactive briefing.")" Icon="@AppIcons.ASSISTANT_VISUAL_BRIEFING" Link="@Routes.ASSISTANT_VISUAL_BRIEFING" />
</AssistantCategoryBlock>
<CascadingValue Value="@this.categoryRegistry" IsFixed="@true">
<AssistantCategoryBlock Category="@COMMON" Plugins="@sections.PluginsOf(COMMON)" HeaderClass="mb-2 mr-3">
<AssistantBlock TSettings="SettingsDialogTextSummarizer" Component="Components.TEXT_SUMMARIZER_ASSISTANT" Name="@T("Text Summarizer")" Description="@TA("Use an LLM to summarize a given text.")" Icon="@AppIcons.ASSISTANT_TEXT_SUMMARIZER" Link="@Routes.ASSISTANT_SUMMARIZER"/>
<AssistantBlock TSettings="SettingsDialogTranslation" Component="Components.TRANSLATION_ASSISTANT" Name="@T("Translation")" Description="@T("Translate text into another language.")" Icon="@AppIcons.TRANSLATION" Link="@Routes.ASSISTANT_TRANSLATION"/>
<AssistantBlock TSettings="SettingsDialogGrammarSpelling" Component="Components.GRAMMAR_SPELLING_ASSISTANT" Name="@T("Grammar & Spelling")" Description="@T("Check grammar and spelling of a given text.")" Icon="@AppIcons.ASSISTANT_GRAMMAR_SPELLING" Link="@Routes.ASSISTANT_GRAMMAR_SPELLING"/>
<AssistantBlock TSettings="SettingsDialogRewrite" Component="Components.REWRITE_ASSISTANT" Name="@T("Rewrite & Improve")" Description="@T("Rewrite and improve a given text for a chosen style.")" Icon="@AppIcons.ASSISTANT_REWRITE" Link="@Routes.ASSISTANT_REWRITE"/>
<AssistantBlock TSettings="SettingsDialogPromptOptimizer" Component="Components.PROMPT_OPTIMIZER_ASSISTANT" Name="@T("Prompt Optimizer")" Description="@TA("Optimize your prompt using a structured guideline.")" Icon="@AppIcons.ASSISTANT_PROMPT_OPTIMIZER" Link="@Routes.ASSISTANT_PROMPT_OPTIMIZER"/>
<AssistantBlock TSettings="SettingsDialogSynonyms" Component="Components.SYNONYMS_ASSISTANT" Name="@T("Synonyms")" Description="@TA("Find synonyms for a given word or phrase.")" Icon="@AppIcons.ASSISTANT_SYNONYMS" Link="@Routes.ASSISTANT_SYNONYMS"/>
<AssistantBlock TSettings="SettingsDialogModelComparison" Component="Components.MODEL_COMPARISON_ASSISTANT" Name="@T("Model Comparison")" Description="@TA("Compare two models in a blind test for how much their answers vary and how useful they are.")" Icon="@AppIcons.ASSISTANT_MODEL_COMPARISON" Link="@Routes.ASSISTANT_MODEL_COMPARISON"/>
<AssistantBlock TSettings="SettingsDialogAssistantBuilder" Component="Components.META_ASSISTANT" RequiredPreviewFeature="PreviewFeatures.PRE_META_ASSISTANT_V1" Name="@T("Assistant Builder")" Description="@TA("Generate your own assistants.")" Icon="@AppIcons.ASSISTANT_BUILDER" Link="@Routes.ASSISTANT_META_ASSISTANT"/>
</AssistantCategoryBlock>
<AssistantCategoryBlock Title="@T("Learning & Reflecting")">
<AssistantBlock TSettings="SettingsDialogAssistantBias" Component="Components.BIAS_DAY_ASSISTANT" Name="@T("Bias of the Day")" Description="@TA("Learn about one cognitive bias every day.")" Icon="@AppIcons.ASSISTANT_BIAS_OF_THE_DAY" Link="@Routes.ASSISTANT_BIAS"/>
<AssistantBlock TSettings="SettingsDialogBeyondFactsLab" Component="Components.BEYOND_FACTS_LAB_ASSISTANT" RequiredPreviewFeature="Components.BEYOND_FACTS_LAB_ASSISTANT.RequiredPreviewFeature" Name="@T("BeyondFacts Lab")" Description="@TA("Prepare step by step for a challenging appearance as a researcher, e.g., a panel discussion or an interview.")" Icon="@AppIcons.ASSISTANT_BEYOND_FACTS_LAB" Link="@Routes.ASSISTANT_BEYOND_FACTS_LAB"/>
</AssistantCategoryBlock>
<AssistantCategoryBlock Category="@BUSINESS" Plugins="@sections.PluginsOf(BUSINESS)">
<AssistantBlock TSettings="SettingsDialogWritingEMails" Component="Components.EMAIL_ASSISTANT" Name="@T("E-Mail")" Description="@TA("Generate an e-mail for a given context.")" Icon="@AppIcons.ASSISTANT_EMAIL" Link="@Routes.ASSISTANT_EMAIL"/>
<AssistantBlock TSettings="SettingsDialogSWOTAnalysis" Component="Components.SWOT_ANALYSIS_ASSISTANT" Name="@T("SWOT Analysis")" Description="@T("Identify strengths, weaknesses, opportunities, threats, and practical next steps from provided information.")" Icon="@AppIcons.ASSISTANT_SWOT_ANALYSIS" Link="@Routes.ASSISTANT_SWOT_ANALYSIS"/>
<AssistantBlock TSettings="NoSettingsPanel" Component="Components.DOCUMENT_ANALYSIS_ASSISTANT" Name="@T("Document Analysis")" Description="@TA("Analyze a document regarding defined rules and extract key information.")" Icon="@AppIcons.ASSISTANT_DOCUMENT_ANALYSIS" Link="@Routes.ASSISTANT_DOCUMENT_ANALYSIS"/>
<AssistantBlock TSettings="SettingsDialogBatchProcessing" Component="Components.BATCH_PROCESSING_ASSISTANT" Name="@T("Batch Processing")" Description="@T("Process all documents of a folder in one batch run and collect the results.")" Icon="@AppIcons.ASSISTANT_BATCH_PROCESSING" Link="@Routes.ASSISTANT_BATCH_PROCESSING"/>
<AssistantBlock TSettings="SettingsDialogMyTasks" Component="Components.MY_TASKS_ASSISTANT" Name="@T("My Tasks")" Description="@TA("Analyze a text or an email for tasks you need to complete.")" Icon="@AppIcons.ASSISTANT_MY_TASKS" Link="@Routes.ASSISTANT_MY_TASKS"/>
<AssistantBlock TSettings="SettingsDialogAgenda" Component="Components.AGENDA_ASSISTANT" Name="@T("Agenda Planner")" Description="@TA("Generate an agenda for a given meeting, seminar, etc.")" Icon="@AppIcons.ASSISTANT_AGENDA" Link="@Routes.ASSISTANT_AGENDA"/>
<AssistantBlock TSettings="SettingsDialogJobPostings" Component="Components.JOB_POSTING_ASSISTANT" Name="@T("Job Posting")" Description="@TA("Generate a job posting for a given job description.")" Icon="@AppIcons.ASSISTANT_JOB_POSTING" Link="@Routes.ASSISTANT_JOB_POSTING"/>
<AssistantBlock TSettings="SettingsDialogLegalCheck" Component="Components.LEGAL_CHECK_ASSISTANT" Name="@T("Legal Check")" Description="@TA("Ask a question about a legal document.")" Icon="@AppIcons.ASSISTANT_LEGAL_CHECK" Link="@Routes.ASSISTANT_LEGAL_CHECK"/>
<AssistantBlock TSettings="SettingsDialogIconFinder" Component="Components.ICON_FINDER_ASSISTANT" Name="@T("Icon Finder")" Description="@TA("Use an LLM to find an icon for a given context.")" Icon="@AppIcons.ASSISTANT_ICON_FINDER" Link="@Routes.ASSISTANT_ICON_FINDER"/>
<AssistantBlock TSettings="SettingsDialogSlideBuilder" Component="Components.SLIDE_BUILDER_ASSISTANT" Name="@T("Slide Assistant")" Description="@TA("Turn texts and documents into slides, also as a PowerPoint file in the design of your template.")" Icon="@AppIcons.ASSISTANT_SLIDES" Link="@Routes.ASSISTANT_SLIDE_BUILDER"/>
<AssistantBlock TSettings="SettingsDialogVisualBriefing" Component="Components.VISUAL_BRIEFING_ASSISTANT" RequiredPreviewFeature="Components.VISUAL_BRIEFING_ASSISTANT.RequiredPreviewFeature" Name="@T("Visual Briefing Assistant")" Description="@TA("Turn documents, data, images, audio, and video into an audience-ready interactive briefing.")" Icon="@AppIcons.ASSISTANT_VISUAL_BRIEFING" Link="@Routes.ASSISTANT_VISUAL_BRIEFING" />
</AssistantCategoryBlock>
<AssistantCategoryBlock Title="@T("Software Engineering")">
<AssistantBlock TSettings="SettingsDialogCoding" Component="Components.CODING_ASSISTANT" Name="@T("Coding")" Description="@TA("Get coding and debugging support from an LLM.")" Icon="@AppIcons.ASSISTANT_CODING" Link="@Routes.ASSISTANT_CODING"/>
<AssistantBlock TSettings="SettingsDialogERIServer" Component="Components.ERI_ASSISTANT" RequiredPreviewFeature="PreviewFeatures.PRE_RAG_2024" Name="@T("ERI Server")" Description="@TA("Generate an ERI server to integrate business systems.")" Icon="@AppIcons.ERI" Link="@Routes.ASSISTANT_ERI"/>
</AssistantCategoryBlock>
<AssistantCategoryBlock Category="@EDUCATION" Plugins="@sections.PluginsOf(EDUCATION)">
<AssistantBlock TSettings="SettingsDialogAssistantBias" Component="Components.BIAS_DAY_ASSISTANT" Name="@T("Bias of the Day")" Description="@TA("Learn about one cognitive bias every day.")" Icon="@AppIcons.ASSISTANT_BIAS_OF_THE_DAY" Link="@Routes.ASSISTANT_BIAS"/>
<AssistantBlock TSettings="SettingsDialogBeyondFactsLab" Component="Components.BEYOND_FACTS_LAB_ASSISTANT" RequiredPreviewFeature="Components.BEYOND_FACTS_LAB_ASSISTANT.RequiredPreviewFeature" Name="@T("BeyondFacts Lab")" Description="@TA("Prepare step by step for a challenging appearance as a researcher, e.g., a panel discussion or an interview.")" Icon="@AppIcons.ASSISTANT_BEYOND_FACTS_LAB" Link="@Routes.ASSISTANT_BEYOND_FACTS_LAB"/>
</AssistantCategoryBlock>
<AssistantCategoryBlock Title="@T("AI Studio Development")">
<AssistantBlock TSettings="SettingsDialogI18N" Component="Components.I18N_ASSISTANT" Name="@T("Localization")" Description="@T("Translate AI Studio text content into other languages")" Icon="@AppIcons.ASSISTANT_LOCALIZATION" Link="@Routes.ASSISTANT_AI_STUDIO_I18N"/>
<AssistantBlock TSettings="NoSettingsPanel" Component="Components.LOG_VIEWER_ASSISTANT" Name="@T("Log Viewer")" Description="@T("View and filter AI Studio log files.")" Icon="@AppIcons.ASSISTANT_LOG_VIEWER" Link="@Routes.ASSISTANT_LOG_VIEWER"/>
</AssistantCategoryBlock>
<AssistantCategoryBlock Category="@SOFTWARE_DEVELOPMENT" Plugins="@sections.PluginsOf(SOFTWARE_DEVELOPMENT)">
<AssistantBlock TSettings="SettingsDialogCoding" Component="Components.CODING_ASSISTANT" Name="@T("Coding")" Description="@TA("Get coding and debugging support from an LLM.")" Icon="@AppIcons.ASSISTANT_CODING" Link="@Routes.ASSISTANT_CODING"/>
<AssistantBlock TSettings="SettingsDialogERIServer" Component="Components.ERI_ASSISTANT" RequiredPreviewFeature="PreviewFeatures.PRE_RAG_2024" Name="@T("ERI Server")" Description="@TA("Generate an ERI server to integrate business systems.")" Icon="@AppIcons.ERI" Link="@Routes.ASSISTANT_ERI"/>
</AssistantCategoryBlock>
@foreach (var section in sections.Where(section => !AssistantPageSections.IsBuiltIn(section.Category)))
{
<AssistantCategoryBlock @key="@section.Category" Category="@section.Category" Plugins="@section.Assistants"/>
}
<AssistantCategoryBlock Category="@AssistantPageSections.TRAILING_CATEGORY" Plugins="@sections.PluginsOf(AssistantPageSections.TRAILING_CATEGORY)">
<AssistantBlock TSettings="SettingsDialogI18N" Component="Components.I18N_ASSISTANT" Name="@T("Localization")" Description="@T("Translate AI Studio text content into other languages")" Icon="@AppIcons.ASSISTANT_LOCALIZATION" Link="@Routes.ASSISTANT_AI_STUDIO_I18N"/>
<AssistantBlock TSettings="NoSettingsPanel" Component="Components.LOG_VIEWER_ASSISTANT" Name="@T("Log Viewer")" Description="@T("View and filter AI Studio log files.")" Icon="@AppIcons.ASSISTANT_LOG_VIEWER" Link="@Routes.ASSISTANT_LOG_VIEWER"/>
</AssistantCategoryBlock>
</CascadingValue>
</InnerScrolling>
</div>
@@ -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)
+1 -1
View File
@@ -108,7 +108,7 @@
@* A model plugin runs like a configuration plugin, without anybody switching it on: *@
@if (context is { IsInternal: false, Type: not (PluginType.CONFIGURATION or PluginType.MODEL) })
{
var isEnabled = this.SettingsManager.IsPluginEnabled(context);
var isEnabled = this.IsPluginWorking(context);
var activationSwitchDisabled = this.IsActivationSwitchDisabled(context, isEnabled);
<MudTooltip Text="@this.GetActivationTooltip(context, isEnabled)">
<MudSwitch T="bool" Value="@isEnabled" ValueChanged="@(_ => this.PluginActivationStateChanged(context))" Disabled="@activationSwitchDisabled"/>
+30 -4
View File
@@ -57,7 +57,7 @@ public partial class Plugins : MSGComponentBase
if (pluginMeta.IsInternal)
return GROUP_INTERNAL;
return this.SettingsManager.IsPluginEnabled(pluginMeta)
return this.IsPluginWorking(pluginMeta)
? GROUP_ENABLED
: GROUP_DISABLED;
}
@@ -82,7 +82,7 @@ public partial class Plugins : MSGComponentBase
// activation is decided live, but it would leave the settings in a state which claims the
// opposite of what the user sees:
//
if (PluginFactory.IsAssistantActivationEnforced(pluginMeta.Id))
if (PluginFactory.IsAssistantActivationEnforced(pluginMeta.Id) || this.IsDisabledByItsCategories(pluginMeta))
return;
if (this.SettingsManager.IsPluginEnabled(pluginMeta))
@@ -172,10 +172,28 @@ public partial class Plugins : MSGComponentBase
return dialogResult is not null && !dialogResult.Canceled;
}
/// <summary>
/// Whether your organization disabled this assistant plugin through its categories.
/// </summary>
private bool IsDisabledByItsCategories(IPluginMetadata pluginMeta) =>
pluginMeta.Type is PluginType.ASSISTANT &&
this.TryGetAssistantPlugin(pluginMeta.Id) is { } assistantPlugin &&
this.SettingsManager.IsDisabledByItsCategories(assistantPlugin);
/// <summary>
/// Whether a plugin works: it is enabled, and your organization did not disable it through its categories.
/// </summary>
/// <remarks>
/// The switch shows this instead of the stored activation. The activation stays stored, so the plugin
/// works again as soon as your organization enables one of its categories again.
/// </remarks>
private bool IsPluginWorking(IPluginMetadata pluginMeta) => this.SettingsManager.IsPluginEnabled(pluginMeta) && !this.IsDisabledByItsCategories(pluginMeta);
private bool IsActivationSwitchDisabled(IPluginMetadata pluginMeta, bool isEnabled)
{
// An assistant plugin your organization requires to stay enabled has no switch to offer:
if (PluginFactory.IsAssistantActivationEnforced(pluginMeta.Id))
// An assistant plugin your organization requires to stay enabled, or disabled through its
// categories, has no switch to offer:
if (PluginFactory.IsAssistantActivationEnforced(pluginMeta.Id) || this.IsDisabledByItsCategories(pluginMeta))
return true;
if (isEnabled || pluginMeta.Type is not PluginType.ASSISTANT)
@@ -194,6 +212,14 @@ public partial class Plugins : MSGComponentBase
if (PluginFactory.IsAssistantActivationEnforced(pluginMeta.Id))
return this.TA("Your organization requires this assistant to stay enabled");
if (this.IsDisabledByItsCategories(pluginMeta))
{
var categoryNames = AssistantCategoryKey.AllOf(pluginMeta).Select(category => category.Name).ToList();
return categoryNames.Count == 1
? string.Format(TA("Your organization disabled the category '{0}' of this assistant"), categoryNames[0])
: string.Format(TA("Your organization disabled all categories of this assistant: {0}"), string.Join(", ", categoryNames));
}
if (isEnabled)
return this.T("Disable plugin");