mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-21 02:13:49 +00:00
Improved the assistants page with categories for assistant plugins (#1211)
This commit is contained in:
1 parent
ef059ffd15
commit
1db0f85898
74 files changed
+3392
-380
No files matched your search
@@ -0,0 +1,71 @@
|
||||
namespace AIStudio.Tools.PluginSystem;
|
||||
|
||||
/// <summary>
|
||||
/// One category of assistants, as the assistants page groups them: a category of AI Studio, or a
|
||||
/// custom category a plugin names itself.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Two rules decide when two categories are the same. CORE belongs to configuration and language
|
||||
/// plugins; an assistant plugin which names it nevertheless appears under "General", so CORE becomes
|
||||
/// COMMON. Custom categories come in the language of their authors, so two plugins may well spell one
|
||||
/// category differently: their names are compared without regard to case.
|
||||
/// </remarks>
|
||||
public sealed record AssistantCategoryKey
|
||||
{
|
||||
/// <param name="category">The category of AI Studio.</param>
|
||||
/// <param name="customName">The name of the custom category, when the category is CUSTOM.</param>
|
||||
public AssistantCategoryKey(PluginCategory category, string customName = "")
|
||||
{
|
||||
this.Category = category is PluginCategory.CORE ? PluginCategory.COMMON : category;
|
||||
this.CustomName = this.Category is PluginCategory.CUSTOM ? customName.Trim() : string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The category of AI Studio, never CORE.
|
||||
/// </summary>
|
||||
public PluginCategory Category { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the custom category, or an empty string for any other category.
|
||||
/// </summary>
|
||||
public string CustomName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the category as the user reads it: localized for a category of AI Studio, as the
|
||||
/// plugin wrote it for a custom one.
|
||||
/// </summary>
|
||||
public string Name => this.Category is PluginCategory.CUSTOM ? this.CustomName : this.Category.Name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the categories a plugin names, its custom ones included.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// CUSTOM stands for all names of CUSTOM_CATEGORIES. Each category appears once, also when a plugin
|
||||
/// names CORE and COMMON at the same time.
|
||||
/// </remarks>
|
||||
/// <param name="plugin">The plugin in question.</param>
|
||||
/// <returns>The categories of the plugin, in the order the plugin names them.</returns>
|
||||
public static IReadOnlyList<AssistantCategoryKey> AllOf(IPluginMetadata plugin) => AllOf(plugin.Categories, plugin.CustomCategories);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the categories which CATEGORIES and CUSTOM_CATEGORIES name together.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For categories which are not loaded yet, e.g., those of a model answer. See the overload for a plugin.
|
||||
/// </remarks>
|
||||
/// <param name="categories">The categories of AI Studio.</param>
|
||||
/// <param name="customCategories">The names of the custom categories.</param>
|
||||
/// <returns>The categories, each once, in the order they are named.</returns>
|
||||
public static IReadOnlyList<AssistantCategoryKey> AllOf(IEnumerable<PluginCategory> categories, IEnumerable<string> customCategories) => categories
|
||||
.SelectMany(category => category is PluginCategory.CUSTOM
|
||||
? customCategories.Select(name => new AssistantCategoryKey(PluginCategory.CUSTOM, name))
|
||||
: [new AssistantCategoryKey(category)])
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(AssistantCategoryKey? other) => other is not null && this.Category == other.Category && string.Equals(this.CustomName, other.CustomName, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode() => HashCode.Combine(this.Category, StringComparer.OrdinalIgnoreCase.GetHashCode(this.CustomName));
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace AIStudio.Tools.PluginSystem.Assistants;
|
||||
|
||||
/// <summary>
|
||||
/// One section of the assistants page, with the assistant plugins it shows.
|
||||
/// </summary>
|
||||
/// <param name="Category">The category of the section.</param>
|
||||
/// <param name="Assistants">The assistant plugins of this category, sorted by their title.</param>
|
||||
/// <typeparam name="TPlugin">The type of the plugins.</typeparam>
|
||||
public sealed record AssistantPageSection<TPlugin>(AssistantCategoryKey Category, IReadOnlyList<TPlugin> Assistants);
|
||||
@@ -0,0 +1,163 @@
|
||||
using AIStudio.Settings.DataModel;
|
||||
|
||||
namespace AIStudio.Tools.PluginSystem.Assistants;
|
||||
|
||||
/// <summary>
|
||||
/// Decides which sections the assistants page shows and in which order.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The built-in assistants and the assistant plugins share one set of categories, see
|
||||
/// AssistantCategoryKey. The page shows the sections of its built-in assistants first, in
|
||||
/// the order users know: "General", "Business", "Learning & Reflecting", and "Software Development".
|
||||
/// The categories which only plugins name follow, the ones of AI Studio before the custom ones, each
|
||||
/// group sorted by its name. "AI Studio Development" comes last, since it concerns the development of
|
||||
/// AI Studio itself.
|
||||
/// </remarks>
|
||||
public static class AssistantPageSections
|
||||
{
|
||||
/// <summary>
|
||||
/// The groups of sections, in the order of the page.
|
||||
/// </summary>
|
||||
private enum PageGroup
|
||||
{
|
||||
LEADING,
|
||||
OTHER,
|
||||
CUSTOM,
|
||||
TRAILING,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A plugin in one of its categories.
|
||||
/// </summary>
|
||||
/// <param name="Category">One category of the plugin.</param>
|
||||
/// <param name="Plugin">The plugin.</param>
|
||||
/// <typeparam name="TPlugin">The type of the plugin.</typeparam>
|
||||
private sealed record SectionMember<TPlugin>(AssistantCategoryKey Category, TPlugin Plugin);
|
||||
|
||||
/// <summary>
|
||||
/// The categories of the built-in assistants, which lead the page, in their order.
|
||||
/// </summary>
|
||||
public static readonly IReadOnlyList<AssistantCategoryKey> LEADING_CATEGORIES =
|
||||
[
|
||||
new(PluginCategory.COMMON),
|
||||
new(PluginCategory.BUSINESS),
|
||||
new(PluginCategory.EDUCATION),
|
||||
new(PluginCategory.SOFTWARE_DEVELOPMENT),
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// The category of the built-in assistants which ends the page.
|
||||
/// </summary>
|
||||
public static readonly AssistantCategoryKey TRAILING_CATEGORY = new(PluginCategory.AI_STUDIO_DEVELOPMENT);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the page shows a section of this category for its built-in assistants anyway.
|
||||
/// </summary>
|
||||
/// <param name="category">The category in question.</param>
|
||||
/// <returns>True for the categories of the built-in assistants.</returns>
|
||||
public static bool IsBuiltIn(AssistantCategoryKey category) => LEADING_CATEGORIES.Contains(category) || category == TRAILING_CATEGORY;
|
||||
|
||||
/// <summary>
|
||||
/// Compares two categories by their place on the assistants page.
|
||||
/// </summary>
|
||||
/// <param name="left">The first category.</param>
|
||||
/// <param name="right">The second category.</param>
|
||||
/// <returns>Less than zero when the first category comes first, zero when both are the same, otherwise more than zero.</returns>
|
||||
public static int Compare(AssistantCategoryKey left, AssistantCategoryKey right)
|
||||
{
|
||||
var byGroup = Group(left).CompareTo(Group(right));
|
||||
if (byGroup != 0)
|
||||
return byGroup;
|
||||
|
||||
var leftIndex = IndexOfLeading(left);
|
||||
if (leftIndex >= 0)
|
||||
return leftIndex.CompareTo(IndexOfLeading(right));
|
||||
|
||||
return NameComparer.Compare(left.Name, right.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects the categories the settings dialog of the assistants page offers, in the order of the page.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The dialog offers the categories the page shows right now, so that every switch changes something
|
||||
/// the user sees, and every category the user hid, so that each one can come back. Categories your
|
||||
/// organization disabled are missing: no switch of the user brings them back.
|
||||
/// </remarks>
|
||||
/// <param name="shownCategories">The categories which show at least one assistant right now.</param>
|
||||
/// <param name="app">The app settings which hold the categories your organization disabled.</param>
|
||||
/// <param name="page">The settings of the assistants page, which hold the categories the user hid.</param>
|
||||
/// <returns>The categories for the dialog, each once.</returns>
|
||||
public static IReadOnlyList<AssistantCategoryKey> SelectForSettings(IEnumerable<AssistantCategoryKey> shownCategories, DataApp app, DataAssistantsPage page)
|
||||
{
|
||||
var hiddenCategories = page.HiddenCategories
|
||||
.Select(category => new AssistantCategoryKey(category))
|
||||
.Concat(page.HiddenCustomCategories.Select(name => new AssistantCategoryKey(PluginCategory.CUSTOM, name)));
|
||||
|
||||
return shownCategories
|
||||
.Concat(hiddenCategories)
|
||||
.Distinct()
|
||||
.Where(category => !app.IsAssistantCategoryDisabled(category))
|
||||
.Order(Comparer<AssistantCategoryKey>.Create(Compare))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Groups the assistant plugins into the sections of the assistants page.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A plugin appears in each of its categories, but only once per section. The sections come in the
|
||||
/// order of the page, and their plugins sorted by title.
|
||||
/// </remarks>
|
||||
/// <param name="plugins">The assistant plugins to show.</param>
|
||||
/// <param name="titleOf">Gets the title under which a plugin appears.</param>
|
||||
/// <typeparam name="TPlugin">The type of the plugins.</typeparam>
|
||||
/// <returns>One section per category any of the plugins names.</returns>
|
||||
public static IReadOnlyList<AssistantPageSection<TPlugin>> Build<TPlugin>(IEnumerable<TPlugin> plugins, Func<TPlugin, string> titleOf) where TPlugin : IPluginMetadata
|
||||
{
|
||||
var titleComparer = NameComparer;
|
||||
return plugins
|
||||
.SelectMany(plugin => AssistantCategoryKey.AllOf(plugin).Select(category => new SectionMember<TPlugin>(category, plugin)))
|
||||
.GroupBy(member => member.Category)
|
||||
.Order(Comparer<IGrouping<AssistantCategoryKey, SectionMember<TPlugin>>>.Create((left, right) => Compare(left.Key, right.Key)))
|
||||
.Select(group => new AssistantPageSection<TPlugin>(group.Key, group.Select(member => member.Plugin).OrderBy(titleOf, titleComparer).ToList()))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <param name="sections">The sections of the assistants page.</param>
|
||||
/// <typeparam name="TPlugin">The type of the plugins.</typeparam>
|
||||
extension<TPlugin>(IReadOnlyList<AssistantPageSection<TPlugin>> sections)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the assistant plugins of one category.
|
||||
/// </summary>
|
||||
/// <param name="category">The category in question.</param>
|
||||
/// <returns>The plugins of the category, or none when no plugin names it.</returns>
|
||||
public IReadOnlyList<TPlugin> PluginsOf(AssistantCategoryKey category) => sections.FirstOrDefault(section => section.Category == category)?.Assistants ?? [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares names the way the user reads them: in the culture of the active language, without regard to case.
|
||||
/// </summary>
|
||||
private static StringComparer NameComparer => StringComparer.Create(I18N.I.Culture, ignoreCase: true);
|
||||
|
||||
private static int IndexOfLeading(AssistantCategoryKey category)
|
||||
{
|
||||
for (var index = 0; index < LEADING_CATEGORIES.Count; index++)
|
||||
if (LEADING_CATEGORIES[index] == category)
|
||||
return index;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static PageGroup Group(AssistantCategoryKey category)
|
||||
{
|
||||
if (IndexOfLeading(category) >= 0)
|
||||
return PageGroup.LEADING;
|
||||
|
||||
if (category == TRAILING_CATEGORY)
|
||||
return PageGroup.TRAILING;
|
||||
|
||||
return category.Category is PluginCategory.CUSTOM ? PageGroup.CUSTOM : PageGroup.OTHER;
|
||||
}
|
||||
}
|
||||
+15
-2
@@ -35,7 +35,7 @@ public static class DirectChatLauncherLuaWriter
|
||||
private const string FALLBACK_AUTHOR = "MindWork AI - Assistant Builder";
|
||||
private const string FALLBACK_SUPPORT_CONTACT = "mailto:info@mindwork.ai";
|
||||
private const string FALLBACK_SOURCE_URL = "https://github.com/MindWorkAI/AI-Studio";
|
||||
private const string FALLBACK_CATEGORY = nameof(PluginCategory.CORE);
|
||||
private const string FALLBACK_CATEGORY = nameof(PluginCategory.COMMON);
|
||||
private const string FALLBACK_TARGET_GROUP = nameof(PluginTargetGroup.EVERYONE);
|
||||
|
||||
//
|
||||
@@ -141,10 +141,23 @@ public static class DirectChatLauncherLuaWriter
|
||||
builder.AppendLineLF($"SOURCE_URL = \"{Escape(ValueOrFallback(plugin.SourceURL, FALLBACK_SOURCE_URL))}\"");
|
||||
builder.AppendLineLF();
|
||||
|
||||
//
|
||||
// CUSTOM needs its names, and the loader refuses it without them. A defective launcher which
|
||||
// lost its names thus keeps its other categories, or falls back like any other:
|
||||
//
|
||||
var customCategories = plugin.CustomCategories.Where(name => !string.IsNullOrWhiteSpace(name)).ToList();
|
||||
var categories = customCategories.Count > 0 ? plugin.Categories : plugin.Categories.Where(category => category is not PluginCategory.CUSTOM).ToList();
|
||||
builder.AppendLineLF("-- The categories for the plugin:");
|
||||
builder.AppendLineLF($"CATEGORIES = {WriteEnumList(plugin.Categories, FALLBACK_CATEGORY)}");
|
||||
builder.AppendLineLF($"CATEGORIES = {WriteEnumList(categories, FALLBACK_CATEGORY)}");
|
||||
builder.AppendLineLF();
|
||||
|
||||
if (customCategories.Count > 0 && categories.Contains(PluginCategory.CUSTOM))
|
||||
{
|
||||
builder.AppendLineLF("-- The names of the custom categories for the plugin:");
|
||||
builder.AppendLineLF($"CUSTOM_CATEGORIES = {WriteStringList(customCategories, string.Empty)}");
|
||||
builder.AppendLineLF();
|
||||
}
|
||||
|
||||
builder.AppendLineLF("-- The target groups for the plugin:");
|
||||
builder.AppendLineLF($"TARGET_GROUPS = {WriteEnumList(plugin.TargetGroups, FALLBACK_TARGET_GROUP)}");
|
||||
builder.AppendLineLF();
|
||||
|
||||
+3
-2
@@ -15,16 +15,17 @@ namespace AIStudio.Tools.PluginSystem.Assistants;
|
||||
/// <param name="SupportContact">Where users turn with questions about this plugin.</param>
|
||||
/// <param name="SourceURL">Where the plugin comes from.</param>
|
||||
/// <param name="Categories">The categories this plugin belongs to.</param>
|
||||
/// <param name="CustomCategories">The names of the custom categories, when the categories contain CUSTOM.</param>
|
||||
/// <param name="TargetGroups">The target groups this plugin is meant for.</param>
|
||||
/// <param name="IsMaintained">Whether the plugin is still maintained.</param>
|
||||
/// <param name="DeprecationMessage">What users are told when the plugin is deprecated.</param>
|
||||
/// <param name="IsAssistantBuilderGenerated">Whether the Assistant Builder created this plugin.</param>
|
||||
public sealed record DirectChatLauncherPluginMetadata(Guid Id, string Version, DateTimeOffset? LastChanged, IReadOnlyList<string> Authors, string SupportContact, string SourceURL,
|
||||
IReadOnlyList<PluginCategory> Categories, IReadOnlyList<PluginTargetGroup> TargetGroups, bool IsMaintained, string DeprecationMessage, bool IsAssistantBuilderGenerated)
|
||||
IReadOnlyList<PluginCategory> Categories, IReadOnlyList<string> CustomCategories, IReadOnlyList<PluginTargetGroup> TargetGroups, bool IsMaintained, string DeprecationMessage, bool IsAssistantBuilderGenerated)
|
||||
{
|
||||
/// <summary>
|
||||
/// Takes the metadata of an installed launcher for the case where one is edited.
|
||||
/// </summary>
|
||||
public static DirectChatLauncherPluginMetadata FromPlugin(PluginAssistants plugin) => new(plugin.Id, plugin.Version.ToString(), plugin.LastChanged, plugin.Authors,
|
||||
plugin.SupportContact, plugin.SourceURL, plugin.Categories, plugin.TargetGroups, plugin.IsMaintained, plugin.DeprecationMessage, plugin.IsAssistantBuilderGenerated);
|
||||
plugin.SupportContact, plugin.SourceURL, plugin.Categories, plugin.CustomCategories, plugin.TargetGroups, plugin.IsMaintained, plugin.DeprecationMessage, plugin.IsAssistantBuilderGenerated);
|
||||
}
|
||||
@@ -61,7 +61,15 @@ public interface IPluginMetadata
|
||||
/// The categories of this plugin.
|
||||
/// </summary>
|
||||
public PluginCategory[] Categories { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The names of the categories this plugin names itself, when its categories contain CUSTOM.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// These names come in the language of the plugin's authors, so AI Studio shows them as they are.
|
||||
/// </remarks>
|
||||
public string[] CustomCategories { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The target groups of this plugin.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Globalization;
|
||||
|
||||
using AIStudio.Settings;
|
||||
|
||||
using Lua;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
@@ -74,7 +76,10 @@ public abstract partial class PluginBase : IPluginMetadata, IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
public PluginCategory[] Categories { get; } = [];
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public string[] CustomCategories { get; } = [];
|
||||
|
||||
/// <inheritdoc />
|
||||
public PluginTargetGroup[] TargetGroups { get; } = [];
|
||||
|
||||
@@ -168,10 +173,16 @@ public abstract partial class PluginBase : IPluginMetadata, IDisposable
|
||||
issues.Add(issue);
|
||||
|
||||
if(this.TryInitCategories(out issue, out var categories))
|
||||
{
|
||||
this.Categories = categories;
|
||||
if(this.TryInitCustomCategories(categories, out issue, out var customCategories))
|
||||
this.CustomCategories = customCategories;
|
||||
else
|
||||
issues.Add(issue);
|
||||
}
|
||||
else if(this is not NoPlugin)
|
||||
issues.Add(issue);
|
||||
|
||||
|
||||
if(this.TryInitTargetGroups(out issue, out var targetGroups))
|
||||
this.TargetGroups = targetGroups;
|
||||
else if(this is not NoPlugin)
|
||||
@@ -432,10 +443,14 @@ public abstract partial class PluginBase : IPluginMetadata, IDisposable
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Only the names of categories count. Enum.TryParse would also take a number such as "1", or
|
||||
// "BUSINESS, SCIENCE" as a combination of both, and turn them into some category nobody named:
|
||||
//
|
||||
var categoryList = new List<PluginCategory>();
|
||||
foreach(var luaCategory in categoriesTable.GetArraySpan())
|
||||
if(luaCategory.TryRead<string>(out var categoryName))
|
||||
if(Enum.TryParse<PluginCategory>(categoryName, out var category) && category != PluginCategory.NONE)
|
||||
if(PluginCategory.TryParseName(categoryName, out var category) && category != PluginCategory.NONE)
|
||||
categoryList.Add(category);
|
||||
|
||||
categories = categoryList.ToArray();
|
||||
@@ -444,7 +459,79 @@ public abstract partial class PluginBase : IPluginMetadata, IDisposable
|
||||
message = string.Format(TB("The table CATEGORIES is empty. At least one category is necessary. Valid categories are: {0}."), CommonTools.GetAllEnumValues(PluginCategory.NONE));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
message = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to read the names of the categories the plugin names itself.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The table CUSTOM_CATEGORIES belongs to the category CUSTOM, in both directions: CUSTOM without
|
||||
/// a name could not be shown anywhere, and names without CUSTOM would be a category the plugin did
|
||||
/// not declare. Either way, the plugin is invalid, so that its authors notice it right away.
|
||||
/// Names are trimmed, and a name which differs from an earlier one only in its case is dropped,
|
||||
/// because both would end up under the same heading anyway.
|
||||
/// </remarks>
|
||||
/// <param name="categories">The categories the plugin declared in CATEGORIES.</param>
|
||||
/// <param name="message">The error message, when the names could not be read.</param>
|
||||
/// <param name="customCategories">The read names, or an empty array without CUSTOM.</param>
|
||||
/// <returns>True, when the names could be read successfully.</returns>
|
||||
private bool TryInitCustomCategories(PluginCategory[] categories, out string message, out string[] customCategories)
|
||||
{
|
||||
customCategories = [];
|
||||
var isCustomDeclared = categories.Contains(PluginCategory.CUSTOM);
|
||||
var customCategoriesValue = this.State.Environment["CUSTOM_CATEGORIES"];
|
||||
if (customCategoriesValue.Type is LuaValueType.Nil)
|
||||
{
|
||||
if (isCustomDeclared)
|
||||
{
|
||||
message = TB("The category CUSTOM requires the table CUSTOM_CATEGORIES with at least one name.");
|
||||
return false;
|
||||
}
|
||||
|
||||
message = string.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!customCategoriesValue.TryRead<LuaTable>(out var customCategoriesTable))
|
||||
{
|
||||
message = TB("The table CUSTOM_CATEGORIES is using an invalid syntax. It must be a table of names.");
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// We read the table by its length rather than by GetArraySpan: the span may hold empty slots
|
||||
// beyond the last entry, which would read as names which are no text:
|
||||
//
|
||||
var names = new List<string>();
|
||||
for (var index = 1; index <= customCategoriesTable.ArrayLength; index++)
|
||||
{
|
||||
if (!customCategoriesTable[index].TryRead<string>(out var name) || string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
message = TB("The table CUSTOM_CATEGORIES contains an empty name or a value which is not a text.");
|
||||
return false;
|
||||
}
|
||||
|
||||
name = name.Trim();
|
||||
if (!names.Contains(name, StringComparer.OrdinalIgnoreCase))
|
||||
names.Add(name);
|
||||
}
|
||||
|
||||
if (isCustomDeclared && names.Count == 0)
|
||||
{
|
||||
message = TB("The category CUSTOM requires the table CUSTOM_CATEGORIES with at least one name.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isCustomDeclared && names.Count > 0)
|
||||
{
|
||||
message = TB("The table CUSTOM_CATEGORIES requires the category CUSTOM in the table CATEGORIES.");
|
||||
return false;
|
||||
}
|
||||
|
||||
customCategories = names.ToArray();
|
||||
message = string.Empty;
|
||||
return true;
|
||||
}
|
||||
@@ -464,10 +551,11 @@ public abstract partial class PluginBase : IPluginMetadata, IDisposable
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only the names of target groups count, as for the categories:
|
||||
var targetGroupList = new List<PluginTargetGroup>();
|
||||
foreach(var luaTargetGroup in targetGroupsTable.GetArraySpan())
|
||||
if(luaTargetGroup.TryRead<string>(out var targetGroupName))
|
||||
if(Enum.TryParse<PluginTargetGroup>(targetGroupName, out var targetGroup) && targetGroup != PluginTargetGroup.NONE)
|
||||
if(PluginTargetGroup.TryParseName(targetGroupName, out var targetGroup) && targetGroup != PluginTargetGroup.NONE)
|
||||
targetGroupList.Add(targetGroup);
|
||||
|
||||
targetGroups = targetGroupList.ToArray();
|
||||
|
||||
@@ -30,4 +30,26 @@ public enum PluginCategory
|
||||
FICTION,
|
||||
WRITING,
|
||||
CONTENT_CREATION,
|
||||
|
||||
/// <summary>
|
||||
/// Assistants for everyday tasks, which the assistants page shows under "General".
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// CORE stays the category of configuration and language plugins. An assistant plugin which
|
||||
/// names CORE nevertheless appears under "General" as well.
|
||||
/// </remarks>
|
||||
COMMON,
|
||||
|
||||
/// <summary>
|
||||
/// Assistants which help to develop AI Studio itself, e.g., its localization.
|
||||
/// </summary>
|
||||
AI_STUDIO_DEVELOPMENT,
|
||||
|
||||
/// <summary>
|
||||
/// A category the plugin names itself, see CUSTOM_CATEGORIES.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Plugins name such categories in the language of their authors, so AI Studio cannot translate them.
|
||||
/// </remarks>
|
||||
CUSTOM,
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public static class PluginCategoryExtensions
|
||||
PluginCategory.UTILITY => TB("Utility"),
|
||||
PluginCategory.SOFTWARE_DEVELOPMENT => TB("Software Development"),
|
||||
PluginCategory.GAMING => TB("Gaming"),
|
||||
PluginCategory.EDUCATION => TB("Education"),
|
||||
PluginCategory.EDUCATION => TB("Learning & Reflecting"),
|
||||
PluginCategory.ENTERTAINMENT => TB("Entertainment"),
|
||||
PluginCategory.SOCIAL => TB("Social"),
|
||||
PluginCategory.SHOPPING => TB("Shopping"),
|
||||
@@ -36,6 +36,10 @@ public static class PluginCategoryExtensions
|
||||
PluginCategory.FICTION => TB("Fiction"),
|
||||
PluginCategory.WRITING => TB("Writing"),
|
||||
PluginCategory.CONTENT_CREATION => TB("Content Creation"),
|
||||
|
||||
PluginCategory.COMMON => TB("General"),
|
||||
PluginCategory.AI_STUDIO_DEVELOPMENT => TB("AI Studio Development"),
|
||||
PluginCategory.CUSTOM => TB("Custom category"),
|
||||
|
||||
_ => TB("Unknown plugin category"),
|
||||
};
|
||||
|
||||
@@ -334,6 +334,14 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
|
||||
// Config: hide some assistants?
|
||||
ManagedConfiguration.TryProcessConfiguration(x => x.App, x => x.HiddenAssistants, this.Id, settingsTable, dryRun);
|
||||
|
||||
// Config: disable some categories of assistants, built-in ones and plugins alike?
|
||||
ManagedConfiguration.TryProcessConfiguration(x => x.App, x => x.DisabledAssistantCategories, this.Id, settingsTable, dryRun);
|
||||
ManagedConfiguration.TryProcessConfiguration(x => x.App, x => x.DisabledCustomAssistantCategories, this.Id, settingsTable, dryRun);
|
||||
|
||||
// Config: what happens to the assistants of categories users collapsed or hid?
|
||||
ManagedConfiguration.TryProcessConfiguration(x => x.AssistantsPage, x => x.CollapsedCategoryAssistants, this.Id, settingsTable, dryRun);
|
||||
ManagedConfiguration.TryProcessConfiguration(x => x.AssistantsPage, x => x.HiddenCategoryAssistants, this.Id, settingsTable, dryRun);
|
||||
|
||||
// Config: prohibit some providers?
|
||||
ManagedConfiguration.TryProcessConfiguration(x => x.App, x => x.ProhibitedProviders, this.Id, settingsTable, dryRun);
|
||||
|
||||
|
||||
@@ -131,6 +131,32 @@ public static partial class PluginFactory
|
||||
return wasConfigurationChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether your organization deployed this assistant plugin itself.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Rules of your organization which keep plugins of others away, e.g., disabled categories, never
|
||||
/// apply to its own plugins. Two things prove that a plugin is one of them: it is stored below the
|
||||
/// directory of a configuration plugin, or it declares DEPLOYED_USING_CONFIG_SERVER and your
|
||||
/// organization approved exactly its code, e.g., when an MDM solution rolls it out. The declaration
|
||||
/// alone proves nothing, because any plugin from the internet can make it. The approval alone does
|
||||
/// not either: it states that a plugin is safe, not that the organization wants it.
|
||||
/// </remarks>
|
||||
/// <param name="plugin">The assistant plugin in question.</param>
|
||||
/// <param name="approvals">The approvals of your organization, i.e., DataAssistantPluginAudit.EnterpriseApprovedPlugins.</param>
|
||||
/// <returns>True when your organization deployed the plugin itself.</returns>
|
||||
public static bool IsAssistantDeployedByOrganization(PluginAssistants plugin, IEnumerable<DataAssistantPluginEnterpriseApproval> approvals)
|
||||
{
|
||||
if (IsOrganizationConfigurationPath(plugin.PluginPath))
|
||||
return true;
|
||||
|
||||
if (!plugin.IsManagedByConfigServer)
|
||||
return false;
|
||||
|
||||
var pluginHash = NormalizeAssistantHash(plugin.ComputeAuditHash());
|
||||
return pluginHash.Length > 0 && approvals.Any(approval => string.Equals(NormalizeAssistantHash(approval.PluginHash), pluginHash, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
private static bool IsOrganizationDefaultActivation(Dictionary<string, DataAssistantPluginEnterpriseApproval> approvalsByHash, string pluginHash)
|
||||
=> approvalsByHash.TryGetValue(pluginHash, out var approval) && approval is { Activate: true, AllowUserOverride: true };
|
||||
|
||||
|
||||
@@ -37,6 +37,9 @@ public sealed class PluginMetadata(PluginBase plugin, string localPath, bool isM
|
||||
/// <inheritdoc />
|
||||
public PluginCategory[] Categories { get; } = plugin.Categories;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string[] CustomCategories { get; } = plugin.CustomCategories;
|
||||
|
||||
/// <inheritdoc />
|
||||
public PluginTargetGroup[] TargetGroups { get; } = plugin.TargetGroups;
|
||||
|
||||
|
||||
Reference in new issue
Block a user