Start the plugin system (#372)
Some checks are pending
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (linux-arm64) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions

This commit is contained in:
Thorsten Sommer 2025-03-29 18:40:17 +01:00 committed by GitHub
parent 3f8f399cd9
commit b632854cd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
36 changed files with 705 additions and 233 deletions

View File

@ -228,18 +228,20 @@ else
<HeaderContent>
<MudTh>Name</MudTh>
<MudTh>Type</MudTh>
<MudTh Style="text-align: left;">Actions</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.EmbeddingName</MudTd>
<MudTd>@context.EmbeddingType</MudTd>
<MudTd Style="text-align: left;">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" Class="ma-2" OnClick="() => this.EditEmbedding(context)">
<MudTd>
<MudStack Row="true" Class="mb-2 mt-2" Wrap="Wrap.Wrap">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" OnClick="() => this.EditEmbedding(context)">
Edit
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" Class="ma-2" OnClick="() => this.DeleteEmbedding(context)">
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="() => this.DeleteEmbedding(context)">
Delete
</MudButton>
</MudStack>
</MudTd>
</RowTemplate>
</MudTable>
@ -274,17 +276,19 @@ else
</ColGroup>
<HeaderContent>
<MudTh>Name</MudTh>
<MudTh Style="text-align: left;">Actions</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.Name</MudTd>
<MudTd Style="text-align: left;">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" Class="ma-2" OnClick="() => this.EditRetrievalProcess(context)">
<MudTd>
<MudStack Row="true" Class="mb-2 mt-2" Wrap="Wrap.Wrap">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" OnClick="() => this.EditRetrievalProcess(context)">
Edit
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" Class="ma-2" OnClick="() => this.DeleteRetrievalProcess(context)">
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="() => this.DeleteRetrievalProcess(context)">
Delete
</MudButton>
</MudStack>
</MudTd>
</RowTemplate>
</MudTable>

View File

@ -1,4 +1,4 @@
<MudTooltip Placement="Placement.Bottom" Arrow="@true">
<MudTooltip Placement="Placement.Bottom" Arrow="@true" Class="@this.Classes">
<ChildContent>
<MudChip T="string" Icon="@Icons.Material.Filled.FirstPage" Color="Color.Error" Class="mb-3">
Alpha

View File

@ -2,4 +2,10 @@ using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
public partial class PreviewAlpha : ComponentBase;
public partial class PreviewAlpha : ComponentBase
{
[Parameter]
public bool ApplyInnerScrollingFix { get; set; }
private string Classes => this.ApplyInnerScrollingFix ? "InnerScrollingFix" : string.Empty;
}

View File

@ -1,4 +1,4 @@
<MudTooltip Placement="Placement.Bottom" Arrow="@true">
<MudTooltip Placement="Placement.Bottom" Arrow="@true" Class="@this.Classes">
<ChildContent>
<MudChip T="string" Icon="@Icons.Material.Filled.HourglassTop" Color="Color.Info" Class="mb-3">
Beta

View File

@ -2,4 +2,10 @@ using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
public partial class PreviewBeta : ComponentBase;
public partial class PreviewBeta : ComponentBase
{
[Parameter]
public bool ApplyInnerScrollingFix { get; set; }
private string Classes => this.ApplyInnerScrollingFix ? "InnerScrollingFix" : string.Empty;
}

View File

@ -1,4 +1,4 @@
<MudTooltip Placement="Placement.Bottom" Arrow="@true">
<MudTooltip Placement="Placement.Bottom" Arrow="@true" Class="@this.Classes">
<ChildContent>
<MudChip T="string" Icon="@Icons.Material.Filled.Science" Color="Color.Error" Class="mb-3">
Experimental

View File

@ -2,4 +2,10 @@ using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
public partial class PreviewExperimental : ComponentBase;
public partial class PreviewExperimental : ComponentBase
{
[Parameter]
public bool ApplyInnerScrollingFix { get; set; }
private string Classes => this.ApplyInnerScrollingFix ? "InnerScrollingFix" : string.Empty;
}

View File

@ -1,4 +1,4 @@
<MudTooltip Placement="Placement.Bottom" Arrow="@true">
<MudTooltip Placement="Placement.Bottom" Arrow="@true" Class="@this.Classes">
<ChildContent>
<MudChip T="string" Icon="@Icons.Material.Filled.HourglassBottom" Color="Color.Error" Class="mb-3">
Prototype

View File

@ -2,4 +2,10 @@ using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
public partial class PreviewPrototype : ComponentBase;
public partial class PreviewPrototype : ComponentBase
{
[Parameter]
public bool ApplyInnerScrollingFix { get; set; }
private string Classes => this.ApplyInnerScrollingFix ? "InnerScrollingFix" : string.Empty;
}

View File

@ -1,4 +1,4 @@
<MudTooltip Placement="Placement.Bottom" Arrow="@true">
<MudTooltip Placement="Placement.Bottom" Arrow="@true" Class="@this.Classes">
<ChildContent>
<MudChip T="string" Icon="@Icons.Material.Filled.VerifiedUser" Color="Color.Success" Class="mb-3">
Release Candidate

View File

@ -2,4 +2,10 @@ using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
public partial class PreviewReleaseCandidate : ComponentBase;
public partial class PreviewReleaseCandidate : ComponentBase
{
[Parameter]
public bool ApplyInnerScrollingFix { get; set; }
private string Classes => this.ApplyInnerScrollingFix ? "InnerScrollingFix" : string.Empty;
}

View File

@ -36,7 +36,7 @@
<MudTh>Name</MudTh>
<MudTh>Provider</MudTh>
<MudTh>Model</MudTh>
<MudTh Style="text-align: left;">Actions</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.Num</MudTd>
@ -44,16 +44,18 @@
<MudTd>@context.UsedLLMProvider</MudTd>
<MudTd>@this.GetEmbeddingProviderModelName(context)</MudTd>
<MudTd Style="text-align: left;">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.OpenInBrowser" Class="ma-2" Href="@context.UsedLLMProvider.GetDashboardURL()" Target="_blank" Disabled="@(!context.UsedLLMProvider.HasDashboard())">
<MudTd>
<MudStack Row="true" Class="mb-2 mt-2" Wrap="Wrap.Wrap">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@context.UsedLLMProvider.GetDashboardURL()" Target="_blank" Disabled="@(!context.UsedLLMProvider.HasDashboard())">
Open Dashboard
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" Class="ma-2" OnClick="() => this.EditEmbeddingProvider(context)">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" OnClick="() => this.EditEmbeddingProvider(context)">
Edit
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" Class="ma-2" OnClick="() => this.DeleteEmbeddingProvider(context)">
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="() => this.DeleteEmbeddingProvider(context)">
Delete
</MudButton>
</MudStack>
</MudTd>
</RowTemplate>
</MudTable>

View File

@ -23,18 +23,20 @@
<HeaderContent>
<MudTh>#</MudTh>
<MudTh>Profile Name</MudTh>
<MudTh Style="text-align: left;">Actions</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.Num</MudTd>
<MudTd>@context.Name</MudTd>
<MudTd Style="text-align: left;">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" Class="ma-2" OnClick="() => this.EditProfile(context)">
<MudTd>
<MudStack Row="true" Class="mb-2 mt-2" Wrap="Wrap.Wrap">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" OnClick="() => this.EditProfile(context)">
Edit
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" Class="ma-2" OnClick="() => this.DeleteProfile(context)">
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="() => this.DeleteProfile(context)">
Delete
</MudButton>
</MudStack>
</MudTd>
</RowTemplate>
</MudTable>

View File

@ -24,7 +24,7 @@
<MudTh>Instance Name</MudTh>
<MudTh>Provider</MudTh>
<MudTh>Model</MudTh>
<MudTh Style="text-align: left;">Actions</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.Num</MudTd>
@ -44,16 +44,18 @@
@("as selected by provider")
}
</MudTd>
<MudTd Style="text-align: left;">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.OpenInBrowser" Class="ma-2" Href="@context.UsedLLMProvider.GetDashboardURL()" Target="_blank" Disabled="@(!context.UsedLLMProvider.HasDashboard())">
<MudTd>
<MudStack Row="true" Class="mb-2 mt-2" Wrap="Wrap.Wrap">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.OpenInBrowser" Href="@context.UsedLLMProvider.GetDashboardURL()" Target="_blank" Disabled="@(!context.UsedLLMProvider.HasDashboard())">
Open Dashboard
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" Class="ma-2" OnClick="() => this.EditLLMProvider(context)">
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" OnClick="() => this.EditLLMProvider(context)">
Edit
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" Class="ma-2" OnClick="() => this.DeleteLLMProvider(context)">
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="() => this.DeleteLLMProvider(context)">
Delete
</MudButton>
</MudStack>
</MudTd>
</RowTemplate>
</MudTable>

View File

@ -29,7 +29,7 @@
<MudTh>Name</MudTh>
<MudTh>Type</MudTh>
<MudTh>Embedding</MudTh>
<MudTh Style="text-align: left;">Actions</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.Num</MudTd>
@ -37,14 +37,16 @@
<MudTd>@context.Type.GetDisplayName()</MudTd>
<MudTd>@this.GetEmbeddingName(context)</MudTd>
<MudTd Style="text-align: left;">
<MudIconButton Variant="Variant.Filled" Color="Color.Info" Icon="@Icons.Material.Filled.Info" Class="ma-2" OnClick="() => this.ShowInformation(context)"/>
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" Class="ma-2" OnClick="() => this.EditDataSource(context)">
<MudTd>
<MudStack Row="true" Class="mb-2 mt-2" Wrap="Wrap.Wrap">
<MudIconButton Variant="Variant.Filled" Color="Color.Info" Icon="@Icons.Material.Filled.Info" OnClick="() => this.ShowInformation(context)"/>
<MudButton Variant="Variant.Filled" Color="Color.Info" StartIcon="@Icons.Material.Filled.Edit" OnClick="() => this.EditDataSource(context)">
Edit
</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" Class="ma-2" OnClick="() => this.DeleteDataSource(context)">
<MudButton Variant="Variant.Filled" Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="() => this.DeleteDataSource(context)">
Delete
</MudButton>
</MudStack>
</MudTd>
</RowTemplate>
</MudTable>

View File

@ -82,9 +82,20 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDis
// Ensure that all settings are loaded:
await this.SettingsManager.LoadSettings();
//
// We cannot process the plugins before the settings are loaded,
// and we know our data directory.
//
if(PreviewFeatures.PRE_PLUGINS_2025.IsEnabled(this.SettingsManager))
{
// Ensure that all internal plugins are present:
await PluginFactory.EnsureInternalPlugins();
// Load (but not start) all plugins, without waiting for them:
var pluginLoadingTimeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
_ = PluginFactory.LoadAll(pluginLoadingTimeout.Token);
}
// Register this component with the message bus:
this.MessageBus.RegisterComponent(this);
this.MessageBus.ApplyFilters(this, [], [ Event.UPDATE_AVAILABLE, Event.USER_SEARCH_FOR_UPDATE, Event.CONFIGURATION_CHANGED, Event.COLOR_THEME_CHANGED ]);
@ -106,33 +117,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDis
private void LoadNavItems()
{
var palette = this.ColorTheme.GetCurrentPalette(this.SettingsManager);
var isWriterModePreviewEnabled = PreviewFeatures.PRE_WRITER_MODE_2024.IsEnabled(this.SettingsManager);
if (!isWriterModePreviewEnabled)
{
this.navItems = new List<NavBarItem>
{
new("Home", Icons.Material.Filled.Home, palette.DarkLighten, palette.GrayLight, Routes.HOME, true),
new("Chat", Icons.Material.Filled.Chat, palette.DarkLighten, palette.GrayLight, Routes.CHAT, false),
new("Assistants", Icons.Material.Filled.Apps, palette.DarkLighten, palette.GrayLight, Routes.ASSISTANTS, false),
new("Supporters", Icons.Material.Filled.Favorite, palette.Error.Value, "#801a00", Routes.SUPPORTERS, false),
new("About", Icons.Material.Filled.Info, palette.DarkLighten, palette.GrayLight, Routes.ABOUT, false),
new("Settings", Icons.Material.Filled.Settings, palette.DarkLighten, palette.GrayLight, Routes.SETTINGS, false),
};
}
else
{
this.navItems = new List<NavBarItem>
{
new("Home", Icons.Material.Filled.Home, palette.DarkLighten, palette.GrayLight, Routes.HOME, true),
new("Chat", Icons.Material.Filled.Chat, palette.DarkLighten, palette.GrayLight, Routes.CHAT, false),
new("Assistants", Icons.Material.Filled.Apps, palette.DarkLighten, palette.GrayLight, Routes.ASSISTANTS, false),
new("Writer", Icons.Material.Filled.Create, palette.DarkLighten, palette.GrayLight, Routes.WRITER, false),
new("Supporters", Icons.Material.Filled.Favorite, palette.Error.Value, "#801a00", Routes.SUPPORTERS, false),
new("About", Icons.Material.Filled.Info, palette.DarkLighten, palette.GrayLight, Routes.ABOUT, false),
new("Settings", Icons.Material.Filled.Settings, palette.DarkLighten, palette.GrayLight, Routes.SETTINGS, false),
};
}
this.navItems = new List<NavBarItem>(this.GetNavItems());
}
#endregion
@ -186,6 +171,25 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, IDis
#endregion
private IEnumerable<NavBarItem> GetNavItems()
{
var palette = this.ColorTheme.GetCurrentPalette(this.SettingsManager);
yield return new("Home", Icons.Material.Filled.Home, palette.DarkLighten, palette.GrayLight, Routes.HOME, true);
yield return new("Chat", Icons.Material.Filled.Chat, palette.DarkLighten, palette.GrayLight, Routes.CHAT, false);
yield return new("Assistants", Icons.Material.Filled.Apps, palette.DarkLighten, palette.GrayLight, Routes.ASSISTANTS, false);
if (PreviewFeatures.PRE_WRITER_MODE_2024.IsEnabled(this.SettingsManager))
yield return new("Writer", Icons.Material.Filled.Create, palette.DarkLighten, palette.GrayLight, Routes.WRITER, false);
if (PreviewFeatures.PRE_PLUGINS_2025.IsEnabled(this.SettingsManager))
yield return new("Plugins", Icons.Material.TwoTone.Extension, palette.DarkLighten, palette.GrayLight, Routes.PLUGINS, false);
yield return new("Supporters", Icons.Material.Filled.Favorite, palette.Error.Value, "#801a00", Routes.SUPPORTERS, false);
yield return new("About", Icons.Material.Filled.Info, palette.DarkLighten, palette.GrayLight, Routes.ABOUT, false);
yield return new("Settings", Icons.Material.Filled.Settings, palette.DarkLighten, palette.GrayLight, Routes.SETTINGS, false);
}
private async Task DismissUpdate()
{
this.userDismissedUpdate = true;

View File

@ -0,0 +1,77 @@
@using AIStudio.Tools.PluginSystem
@attribute [Route(Routes.PLUGINS)]
<div class="inner-scrolling-context">
<MudText Typo="Typo.h3" Class="mb-2">
Plugins
</MudText>
<PreviewExperimental ApplyInnerScrollingFix="true"/>
<InnerScrolling>
<MudTable Items="@PluginFactory.AvailablePlugins" Hover="@true" GroupBy="@this.groupConfig" Class="border-dashed border rounded-lg">
<ColGroup>
<col style="width: 2em;" />
<col style="width: 2.1em; "/>
<col/>
<col style="width: 12em;"/>
</ColGroup>
<HeaderContent>
<MudTh colspan="2">Plugins</MudTh>
<MudTh>Actions</MudTh>
</HeaderContent>
<GroupHeaderTemplate>
<MudTh Class="mud-table-cell-custom-group" colspan="3">
@switch (context.Key)
{
case GROUP_ENABLED:
<MudText Typo="Typo.h6" Class="mb-2">
Enabled Plugins
</MudText>
break;
case GROUP_DISABLED:
<MudText Typo="Typo.h6" Class="mb-2">
Disabled Plugins
</MudText>
break;
case GROUP_INTERNAL:
<MudText Typo="Typo.h6" Class="mb-2">
Internal Plugins
</MudText>
break;
}
</MudTh>
</GroupHeaderTemplate>
<RowTemplate>
<MudTd>
<MudAvatar Size="Size.Medium" Style="width: 2em; height: 2em;" Class="align-content-stretch">
<div class="plugin-icon-container">
@((MarkupString)context.IconSVG)
</div>
</MudAvatar>
</MudTd>
<MudTd>
<MudStack Spacing="0">
<MudText Typo="Typo.h6" Class="mb-0 pb-0 gap-0">
@context.Name
</MudText>
<MudText Typo="Typo.body1">
@context.Description
</MudText>
</MudStack>
</MudTd>
<MudTd>
@if (!context.IsInternal)
{
var isEnabled = this.SettingsManager.IsPluginEnabled(context);
<MudTooltip Text="@(isEnabled ? "Disable plugin" : "Enable plugin")">
<MudSwitch T="bool" Value="@isEnabled" ValueChanged="@(_ => this.PluginActivationStateChanged(context))"/>
</MudTooltip>
}
</MudTd>
</RowTemplate>
</MudTable>
</InnerScrolling>
</div>

View File

@ -0,0 +1,56 @@
using AIStudio.Settings;
using AIStudio.Tools.PluginSystem;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Pages;
public partial class Plugins : ComponentBase
{
private const string GROUP_ENABLED = "Enabled";
private const string GROUP_DISABLED = "Disabled";
private const string GROUP_INTERNAL = "Internal";
[Inject]
private MessageBus MessageBus { get; init; } = null!;
[Inject]
private SettingsManager SettingsManager { get; init; } = null!;
private TableGroupDefinition<IPluginMetadata> groupConfig = null!;
#region Overrides of ComponentBase
protected override async Task OnInitializedAsync()
{
this.groupConfig = new TableGroupDefinition<IPluginMetadata>
{
Expandable = true,
IsInitiallyExpanded = true,
Selector = pluginMeta =>
{
if (pluginMeta.IsInternal)
return GROUP_INTERNAL;
return this.SettingsManager.IsPluginEnabled(pluginMeta)
? GROUP_ENABLED
: GROUP_DISABLED;
}
};
await base.OnInitializedAsync();
}
#endregion
private async Task PluginActivationStateChanged(IPluginMetadata pluginMeta)
{
if (this.SettingsManager.IsPluginEnabled(pluginMeta))
this.SettingsManager.ConfigurationData.EnabledPlugins.Remove(pluginMeta.Id);
else
this.SettingsManager.ConfigurationData.EnabledPlugins.Add(pluginMeta.Id);
await this.SettingsManager.StoreSettings();
await this.MessageBus.SendMessage<bool>(this, Event.CONFIGURATION_CHANGED);
}
}

View File

@ -2,11 +2,10 @@
@inherits MSGComponentBase
<div class="inner-scrolling-context">
<MudText Typo="Typo.h3" Class="mb-2 mr-3">
<MudText Typo="Typo.h3" Class="mb-2">
Writer
</MudText>
<PreviewExperimental/>
<PreviewExperimental ApplyInnerScrollingFix="true"/>
<ProviderSelection @bind-ProviderSettings="@this.providerSettings"/>
<InnerScrolling>

View File

@ -0,0 +1,11 @@
SVG = [[<svg viewBox="0 0 600 600" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2">
<path style="fill:none" d="M0 0h600v600H0z"/>
<clipPath id="a">
<path d="M0 0h600v600H0z"/>
</clipPath>
<g clip-path="url(#a)">
<path d="M17.467 200C58.688 83.529 169.851 0 300.369 0S542.05 83.529 583.271 200c11.072 31.284 17.098 64.944 17.098 100s-6.026 68.716-17.098 100C542.05 516.471 430.887 600 300.369 600S58.688 516.471 17.467 400C6.395 368.716.369 335.056.369 300s6.026-68.716 17.098-100Z"/>
<path d="M583.271 200c11.072 31.284 17.098 64.944 17.098 100s-6.026 68.716-17.098 100C542.05 516.471 430.887 600 300.369 600S58.688 516.471 17.467 400C6.395 368.716.369 335.056.369 300s6.026-68.716 17.098-100h565.804Z" style="fill:#d00"/>
<path d="M583.271 400C542.05 516.471 430.887 600 300.369 600S58.688 516.471 17.467 400h565.804Z" style="fill:#ffce00"/>
</g>
</svg>]]

View File

@ -1,6 +1,12 @@
require("contentHome")
require("icon")
-- The ID for this plugin:
ID = "43065dbc-78d0-45b7-92be-f14c2926e2dc"
-- The icon for the plugin:
ICON_SVG = SVG
-- The name of the plugin:
NAME = "MindWork AI Studio - German / Deutsch"
@ -32,7 +38,7 @@ TARGET_GROUPS = { "EVERYONE" }
IS_MAINTAINED = true
-- When the plugin is deprecated, this message will be shown to users:
DEPRECATION_MESSAGE = nil
DEPRECATION_MESSAGE = ""
UI_TEXT_CONTENT = {
HOME = CONTENT_HOME,

View File

@ -0,0 +1,12 @@
SVG = [[<svg viewBox="0 0 650 650" style="fill-rule:evenodd;clip-rule:evenodd">
<path style="fill:none" d="M0 0h650v650H0z"/>
<clipPath id="a">
<path d="M0 0h650v650H0z"/>
</clipPath>
<g clip-path="url(#a)">
<path d="M208.018 21.723C244.323 7.694 283.77 0 325 0c44.15 0 86.256 8.823 124.649 24.8a319.796 319.796 0 0 1 9.251 4.02A324.269 324.269 0 0 1 494 47.402 326.269 326.269 0 0 1 532.582 75c33.111 27.531 60.675 61.509 80.757 100a322.631 322.631 0 0 1 32.831 100 326.842 326.842 0 0 1 3.83 50c0 17.002-1.308 33.7-3.83 50a322.631 322.631 0 0 1-32.831 100c-20.082 38.491-47.646 72.469-80.757 100-56.319 46.827-128.686 75-207.582 75-78.896 0-151.263-28.173-207.582-75-33.111-27.531-60.675-61.509-80.757-100A322.631 322.631 0 0 1 3.83 375a325.032 325.032 0 0 1-2.881-25A328.869 328.869 0 0 1 0 325c0-17.002 1.308-33.7 3.83-50a322.493 322.493 0 0 1 31.196-96.822 323.44 323.44 0 0 1 8.553-15.752C62.893 129.089 87.96 99.493 117.418 75A325.476 325.476 0 0 1 191.1 28.82a324.203 324.203 0 0 1 16.918-7.097Z" style="fill:#b31942;fill-rule:nonzero"/>
<path d="M0 75h1235m0 100H0m0 100h1235m0 100H0m0 100h1235m0 100H0" style="fill-rule:nonzero;stroke:#fff;stroke-width:50px"/>
<path d="M208.018 21.723C244.323 7.694 283.77 0 325 0c44.15 0 86.256 8.823 124.649 24.8a319.796 319.796 0 0 1 9.251 4.02A324.269 324.269 0 0 1 494 47.402V350H.949A328.869 328.869 0 0 1 0 325c0-17.002 1.308-33.7 3.83-50a322.493 322.493 0 0 1 31.196-96.822 323.44 323.44 0 0 1 8.553-15.752C62.893 129.089 87.96 99.493 117.418 75A325.476 325.476 0 0 1 191.1 28.82a324.203 324.203 0 0 1 16.918-7.097Z" style="fill:#0a3161;fill-rule:nonzero"/>
<path d="M30.895 186.613A317.843 317.843 0 0 1 36.661 175a323.44 323.44 0 0 1 6.918-12.574l2.078 6.394h14.531l-11.756 8.541 4.49 13.819-11.755-8.541-11.756 8.541 1.484-4.567ZM41.167 225l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L41.167 225ZM41.167 295l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L41.167 295ZM82.333 120l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L82.333 120ZM82.333 190l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L82.333 190ZM82.333 260l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L82.333 260ZM123.5 85l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L123.5 85ZM123.5 155l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L123.5 155ZM123.5 225l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L123.5 225ZM123.5 295l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L123.5 295ZM164.667 50l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L164.667 50ZM164.667 120l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L164.667 120ZM164.667 190l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L164.667 190ZM164.667 260l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L164.667 260ZM198.568 37.361l-10.096-7.336c.874-.405 1.75-.807 2.628-1.205h10.243l1.66-5.111a334.886 334.886 0 0 1 5.015-1.986l2.306 7.097h14.53l-11.755 8.541 4.49 13.819-11.756-8.541-11.755 8.541 4.49-13.819ZM205.833 85l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L205.833 85ZM205.833 155l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L205.833 155ZM205.833 225l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L205.833 225ZM205.833 295l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L205.833 295ZM247 50l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L247 50ZM247 120l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L247 120ZM247 190l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L247 190ZM247 260l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L247 260ZM288.167 15l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L288.167 15ZM288.167 85l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L288.167 85ZM288.167 155l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L288.167 155ZM288.167 225l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L288.167 225ZM288.167 295l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L288.167 295ZM329.333 50l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L329.333 50ZM329.333 120l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L329.333 120ZM329.333 190l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L329.333 190ZM329.333 260l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L329.333 260ZM370.5 15l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L370.5 15ZM370.5 85l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L370.5 85ZM370.5 155l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L370.5 155ZM370.5 225l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L370.5 225ZM370.5 295l11.756 36.18-30.777-22.36h38.042l-30.777 22.36L370.5 295ZM411.667 50l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L411.667 50ZM411.667 120l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L411.667 120ZM411.667 190l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L411.667 190ZM411.667 260l11.755 36.18-30.776-22.36h38.042l-30.777 22.36L411.667 260ZM448.343 28.82l1.306-4.02a319.796 319.796 0 0 1 7.405 3.19l.27.83h1.576a320.481 320.481 0 0 1 7.869 3.695l-6.67 4.846 4.49 13.819-11.756-8.541-11.755 8.541 4.49-13.819-11.756-8.541h14.531ZM452.833 85l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L452.833 85ZM452.833 155l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L452.833 155ZM452.833 225l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L452.833 225ZM452.833 295l11.756 36.18-30.777-22.36h38.042l-30.776 22.36L452.833 295Z" style="fill:#fff;fill-rule:nonzero"/>
</g>
</svg>]]

View File

@ -1,8 +1,12 @@
require("contentHome")
require("icon")
-- The ID for this plugin:
ID = "97dfb1ba-50c4-4440-8dfa-6575daf543c8"
-- The icon for the plugin:
ICON_SVG = SVG
-- The name of the plugin:
NAME = "MindWork AI Studio - US English"
@ -34,7 +38,7 @@ TARGET_GROUPS = { "EVERYONE" }
IS_MAINTAINED = true
-- When the plugin is deprecated, this message will be shown to users:
DEPRECATION_MESSAGE = nil
DEPRECATION_MESSAGE = ""
UI_TEXT_CONTENT = {
HOME = CONTENT_HOME,

View File

@ -9,6 +9,7 @@ public sealed partial class Routes
public const string SETTINGS = "/settings";
public const string SUPPORTERS = "/supporters";
public const string WRITER = "/writer";
public const string PLUGINS = "/plugins";
// ReSharper disable InconsistentNaming
public const string ASSISTANT_TRANSLATION = "/assistant/translation";

View File

@ -36,6 +36,11 @@ public sealed class Data
/// </summary>
public List<Profile> Profiles { get; init; } = [];
/// <summary>
/// List of enabled plugins.
/// </summary>
public List<Guid> EnabledPlugins { get; set; } = [];
/// <summary>
/// The next provider number to use.
/// </summary>

View File

@ -4,6 +4,7 @@ using System.Text.Json.Serialization;
using AIStudio.Provider;
using AIStudio.Settings.DataModel;
using AIStudio.Tools.PluginSystem;
// ReSharper disable NotAccessedPositionalProperty.Local
@ -142,6 +143,8 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
return minimumLevel;
}
public bool IsPluginEnabled(IPluginMetadata plugin) => this.ConfigurationData.EnabledPlugins.Contains(plugin.Id);
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
public Provider GetPreselectedProvider(Tools.Components component, string? currentProviderId = null, bool usePreselectionBeforeCurrentProvider = false)
{

View File

@ -0,0 +1,74 @@
namespace AIStudio.Tools.PluginSystem;
public interface IPluginMetadata
{
/// <summary>
/// The icon of this plugin.
/// </summary>
public string IconSVG { get; }
/// <summary>
/// The type of this plugin.
/// </summary>
public PluginType Type { get; }
/// <summary>
/// The ID of this plugin.
/// </summary>
public Guid Id { get; }
/// <summary>
/// The name of this plugin.
/// </summary>
public string Name { get; }
/// <summary>
/// The description of this plugin.
/// </summary>
public string Description { get; }
/// <summary>
/// The version of this plugin.
/// </summary>
public PluginVersion Version { get; }
/// <summary>
/// The authors of this plugin.
/// </summary>
public string[] Authors { get; }
/// <summary>
/// The support contact for this plugin.
/// </summary>
public string SupportContact { get; }
/// <summary>
/// The source URL of this plugin.
/// </summary>
public string SourceURL { get; }
/// <summary>
/// The categories of this plugin.
/// </summary>
public PluginCategory[] Categories { get; }
/// <summary>
/// The target groups of this plugin.
/// </summary>
public PluginTargetGroup[] TargetGroups { get; }
/// <summary>
/// True, when the plugin is maintained.
/// </summary>
public bool IsMaintained { get; }
/// <summary>
/// The message that should be displayed when the plugin is deprecated.
/// </summary>
public string DeprecationMessage { get; }
/// <summary>
/// True, when the plugin is AI Studio internal.
/// </summary>
public bool IsInternal { get; }
}

View File

@ -6,4 +6,4 @@ namespace AIStudio.Tools.PluginSystem;
/// Represents a plugin that could not be loaded.
/// </summary>
/// <param name="parsingError">The error message that occurred while parsing the plugin.</param>
public sealed class NoPlugin(string parsingError) : PluginBase(string.Empty, LuaState.Create(), PluginType.NONE, parsingError);
public sealed class NoPlugin(string parsingError) : PluginBase(false, LuaState.Create(), PluginType.NONE, parsingError);

View File

@ -0,0 +1,45 @@
namespace AIStudio.Tools.PluginSystem;
public abstract partial class PluginBase
{
private const string DEFAULT_ICON_SVG =
"""
<svg height="1.5em" width="1.5em" viewBox="0 0 24 24" fill="#1f1f1f"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M19 13h-2V7h-6V5c0-.28-.22-.5-.5-.5s-.5.22-.5.5v2H4l.01 2.12C5.76 9.8 7 11.51 7 13.5c0 1.99-1.25 3.7-3 4.38V20h2.12c.68-1.75 2.39-3 4.38-3 1.99 0 3.7 1.25 4.38 3H17v-6h2c.28 0 .5-.22.5-.5s-.22-.5-.5-.5z" opacity=".3"/><path d="M19 11V7c0-1.1-.9-2-2-2h-4c0-1.38-1.12-2.5-2.5-2.5S8 3.62 8 5H4c-1.1 0-1.99.9-1.99 2v3.8h.29c1.49 0 2.7 1.21 2.7 2.7s-1.21 2.7-2.7 2.7H2V20c0 1.1.9 2 2 2h3.8v-.3c0-1.49 1.21-2.7 2.7-2.7s2.7 1.21 2.7 2.7v.3H17c1.1 0 2-.9 2-2v-4c1.38 0 2.5-1.12 2.5-2.5S20.38 11 19 11zm0 3h-2v6h-2.12c-.68-1.75-2.39-3-4.38-3-1.99 0-3.7 1.25-4.38 3H4v-2.12c1.75-.68 3-2.39 3-4.38 0-1.99-1.24-3.7-2.99-4.38L4 7h6V5c0-.28.22-.5.5-.5s.5.22.5.5v2h6v6h2c.28 0 .5.22.5.5s-.22.5-.5.5z"/></svg>
""";
#region Initialization-related methods
/// <summary>
/// Tries to initialize the icon of the plugin.
/// </summary>
/// <remarks>
/// When no icon is specified, the default icon will be used.
/// </remarks>
/// <param name="message">The error message, when the icon could not be read.</param>
/// <param name="iconSVG">The read icon as SVG.</param>
/// <returns>True, when the icon could be read successfully.</returns>
// ReSharper disable once OutParameterValueIsAlwaysDiscarded.Local
// ReSharper disable once UnusedMethodReturnValue.Local
private bool TryInitIconSVG(out string message, out string iconSVG)
{
if (!this.state.Environment["ICON_SVG"].TryRead(out iconSVG))
{
iconSVG = DEFAULT_ICON_SVG;
message = "The field ICON_SVG does not exist or is not a valid string.";
return true;
}
if (string.IsNullOrWhiteSpace(iconSVG))
{
iconSVG = DEFAULT_ICON_SVG;
message = "The field ICON_SVG is empty. The icon must be a non-empty string.";
return true;
}
message = string.Empty;
return true;
}
#endregion
}

View File

@ -1,5 +1,4 @@
using Lua;
using Lua.Standard;
// ReSharper disable MemberCanBePrivate.Global
namespace AIStudio.Tools.PluginSystem;
@ -7,72 +6,54 @@ namespace AIStudio.Tools.PluginSystem;
/// <summary>
/// Represents the base of any AI Studio plugin.
/// </summary>
public abstract class PluginBase
public abstract partial class PluginBase : IPluginMetadata
{
private readonly IReadOnlyCollection<string> baseIssues;
protected readonly LuaState state;
protected readonly List<string> pluginIssues = [];
/// <summary>
/// The type of this plugin.
/// </summary>
/// <inheritdoc />
public string IconSVG { get; }
/// <inheritdoc />
public PluginType Type { get; }
/// <summary>
/// The ID of this plugin.
/// </summary>
/// <inheritdoc />
public Guid Id { get; }
/// <summary>
/// The name of this plugin.
/// </summary>
/// <inheritdoc />
public string Name { get; } = string.Empty;
/// <summary>
/// The description of this plugin.
/// </summary>
/// <inheritdoc />
public string Description { get; } = string.Empty;
/// <summary>
/// The version of this plugin.
/// </summary>
/// <inheritdoc />
public PluginVersion Version { get; }
/// <summary>
/// The authors of this plugin.
/// </summary>
/// <inheritdoc />
public string[] Authors { get; } = [];
/// <summary>
/// The support contact for this plugin.
/// </summary>
/// <inheritdoc />
public string SupportContact { get; } = string.Empty;
/// <summary>
/// The source URL of this plugin.
/// </summary>
/// <inheritdoc />
public string SourceURL { get; } = string.Empty;
/// <summary>
/// The categories of this plugin.
/// </summary>
/// <inheritdoc />
public PluginCategory[] Categories { get; } = [];
/// <summary>
/// The target groups of this plugin.
/// </summary>
/// <inheritdoc />
public PluginTargetGroup[] TargetGroups { get; } = [];
/// <summary>
/// True, when the plugin is maintained.
/// </summary>
/// <inheritdoc />
public bool IsMaintained { get; }
/// <summary>
/// The message that should be displayed when the plugin is deprecated.
/// </summary>
public string? DeprecationMessage { get; }
/// <inheritdoc />
public string DeprecationMessage { get; } = string.Empty;
/// <inheritdoc />
public bool IsInternal { get; }
/// <summary>
/// The issues that occurred during the initialization of this plugin.
@ -88,31 +69,24 @@ public abstract class PluginBase
/// </remarks>
public bool IsValid => this is not NoPlugin && this.baseIssues.Count == 0 && this.pluginIssues.Count == 0;
protected PluginBase(string path, LuaState state, PluginType type, string parseError = "")
protected PluginBase(bool isInternal, LuaState state, PluginType type, string parseError = "")
{
this.state = state;
this.Type = type;
// For security reasons, we don't want to allow the plugin to load modules:
this.state.ModuleLoader = new NoModuleLoader();
// Add some useful libraries:
this.state.OpenModuleLibrary();
this.state.OpenStringLibrary();
this.state.OpenTableLibrary();
this.state.OpenMathLibrary();
this.state.OpenBitwiseLibrary();
this.state.OpenCoroutineLibrary();
// Add the module loader so that the plugin can load other Lua modules:
this.state.ModuleLoader = new PluginLoader(path);
var issues = new List<string>();
if(!string.IsNullOrWhiteSpace(parseError))
issues.Add(parseError);
// Notice: when no icon is specified, the default icon will be used.
this.TryInitIconSVG(out _, out var iconSVG);
this.IconSVG = iconSVG;
if(this.TryInitId(out var issue, out var id))
{
this.Id = id;
this.IsInternal = isInternal;
}
else if(this is not NoPlugin)
issues.Add(issue);
@ -456,12 +430,12 @@ public abstract class PluginBase
/// <param name="message">The error message, when the deprecation message could not be read.</param>
/// <param name="deprecationMessage">The read deprecation message.</param>
/// <returns>True, when the deprecation message could be read successfully.</returns>
private bool TryInitDeprecationMessage(out string message, out string? deprecationMessage)
private bool TryInitDeprecationMessage(out string message, out string deprecationMessage)
{
if (!this.state.Environment["DEPRECATION_MESSAGE"].TryRead(out deprecationMessage))
{
deprecationMessage = null;
message = "The field DEPRECATION_MESSAGE does not exist, is not a valid string. This field is optional: use nil to indicate that the plugin is not deprecated.";
deprecationMessage = string.Empty;
message = "The field DEPRECATION_MESSAGE does not exist, is not a valid string. This message is optional: use an empty string to indicate that the plugin is not deprecated.";
return false;
}

View File

@ -0,0 +1,79 @@
using System.Reflection;
using Microsoft.Extensions.FileProviders;
namespace AIStudio.Tools.PluginSystem;
public static partial class PluginFactory
{
public static async Task EnsureInternalPlugins()
{
LOG.LogInformation("Start ensuring internal plugins.");
foreach (var plugin in Enum.GetValues<InternalPlugin>())
{
LOG.LogInformation($"Ensure plugin: {plugin}");
await EnsurePlugin(plugin);
}
}
private static async Task EnsurePlugin(InternalPlugin plugin)
{
try
{
#if DEBUG
var basePath = Path.Join(Environment.CurrentDirectory, "Plugins");
var resourceFileProvider = new PhysicalFileProvider(basePath);
#else
var resourceFileProvider = new ManifestEmbeddedFileProvider(Assembly.GetAssembly(type: typeof(Program))!, "Plugins");
#endif
var metaData = plugin.MetaData();
var mainResourcePath = $"{metaData.ResourcePath}/plugin.lua";
var resourceInfo = resourceFileProvider.GetFileInfo(mainResourcePath);
if(!resourceInfo.Exists)
{
LOG.LogError($"The plugin {plugin} does not exist. This should not happen, since the plugin is an integral part of AI Studio.");
return;
}
// Ensure that the additional resources exist:
foreach (var content in resourceFileProvider.GetDirectoryContents(metaData.ResourcePath))
{
if(content.IsDirectory)
{
LOG.LogError("The plugin contains a directory. This is not allowed.");
continue;
}
await CopyInternalPluginFile(content, metaData);
}
}
catch
{
LOG.LogError($"Was not able to ensure the plugin: {plugin}");
}
}
private static async Task CopyInternalPluginFile(IFileInfo resourceInfo, InternalPluginData metaData)
{
await using var inputStream = resourceInfo.CreateReadStream();
var pluginTypeBasePath = Path.Join(INTERNAL_PLUGINS_ROOT, metaData.Type.GetDirectory());
if (!Directory.Exists(INTERNAL_PLUGINS_ROOT))
Directory.CreateDirectory(INTERNAL_PLUGINS_ROOT);
if (!Directory.Exists(pluginTypeBasePath))
Directory.CreateDirectory(pluginTypeBasePath);
var pluginPath = Path.Join(pluginTypeBasePath, metaData.ResourceName);
if (!Directory.Exists(pluginPath))
Directory.CreateDirectory(pluginPath);
var pluginFilePath = Path.Join(pluginPath, resourceInfo.Name);
await using var outputStream = File.Create(pluginFilePath);
await inputStream.CopyToAsync(outputStream);
}
}

View File

@ -1,102 +1,111 @@
using System.Reflection;
using System.Text;
using AIStudio.Settings;
using Lua;
using Microsoft.Extensions.FileProviders;
using Lua.Standard;
namespace AIStudio.Tools.PluginSystem;
public static class PluginFactory
public static partial class PluginFactory
{
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger("PluginFactory");
private static readonly string DATA_DIR = SettingsManager.DataDirectory!;
public static async Task EnsureInternalPlugins()
{
LOG.LogInformation("Start ensuring internal plugins.");
foreach (var plugin in Enum.GetValues<InternalPlugin>())
{
LOG.LogInformation($"Ensure plugin: {plugin}");
await EnsurePlugin(plugin);
}
}
private static readonly string PLUGINS_ROOT = Path.Join(DATA_DIR, "plugins");
private static async Task EnsurePlugin(InternalPlugin plugin)
{
try
{
#if DEBUG
var basePath = Path.Join(Environment.CurrentDirectory, "Plugins");
var resourceFileProvider = new PhysicalFileProvider(basePath);
#else
var resourceFileProvider = new ManifestEmbeddedFileProvider(Assembly.GetAssembly(type: typeof(Program))!, "Plugins");
#endif
private static readonly string INTERNAL_PLUGINS_ROOT = Path.Join(PLUGINS_ROOT, ".internal");
var metaData = plugin.MetaData();
var mainResourcePath = $"{metaData.ResourcePath}/plugin.lua";
var resourceInfo = resourceFileProvider.GetFileInfo(mainResourcePath);
private static readonly List<IPluginMetadata> AVAILABLE_PLUGINS = [];
if(!resourceInfo.Exists)
/// <summary>
/// A list of all available plugins.
/// </summary>
public static IReadOnlyCollection<IPluginMetadata> AvailablePlugins => AVAILABLE_PLUGINS;
/// <summary>
/// Try to load all plugins from the plugins directory.
/// </summary>
/// <remarks>
/// Loading plugins means:<br/>
/// - Parsing and checking the plugin code<br/>
/// - Check for forbidden plugins<br/>
/// - Creating a new instance of the allowed plugin<br/>
/// - Read the plugin metadata<br/>
/// <br/>
/// Loading a plugin does not mean to start the plugin, though.
/// </remarks>
public static async Task LoadAll(CancellationToken cancellationToken = default)
{
LOG.LogError($"The plugin {plugin} does not exist. This should not happen, since the plugin is an integral part of AI Studio.");
LOG.LogInformation("Start loading plugins.");
if (!Directory.Exists(PLUGINS_ROOT))
{
LOG.LogInformation("No plugins found.");
return;
}
// Ensure that the additional resources exist:
foreach (var content in resourceFileProvider.GetDirectoryContents(metaData.ResourcePath))
//
// The easiest way to load all plugins is to find all `plugin.lua` files and load them.
// By convention, each plugin is enforced to have a `plugin.lua` file.
//
var pluginMainFiles = Directory.EnumerateFiles(PLUGINS_ROOT, "plugin.lua", SearchOption.AllDirectories);
foreach (var pluginMainFile in pluginMainFiles)
{
if(content.IsDirectory)
if (cancellationToken.IsCancellationRequested)
break;
LOG.LogInformation($"Try to load plugin: {pluginMainFile}");
var code = await File.ReadAllTextAsync(pluginMainFile, Encoding.UTF8, cancellationToken);
var pluginPath = Path.GetDirectoryName(pluginMainFile)!;
var plugin = await Load(pluginPath, code, cancellationToken);
switch (plugin)
{
LOG.LogError("The plugin contains a directory. This is not allowed.");
case NoPlugin noPlugin when noPlugin.Issues.Any():
LOG.LogError($"Was not able to load plugin: '{pluginMainFile}'. Reason: {noPlugin.Issues.First()}");
continue;
case NoPlugin:
LOG.LogError($"Was not able to load plugin: '{pluginMainFile}'. Reason: Unknown.");
continue;
case { IsValid: false }:
LOG.LogError($"Was not able to load plugin '{pluginMainFile}', because the Lua code is not a valid AI Studio plugin. There are {plugin.Issues.Count()} issues to fix.");
#if DEBUG
foreach (var pluginIssue in plugin.Issues)
LOG.LogError($"Plugin issue: {pluginIssue}");
#endif
continue;
case { IsMaintained: false }:
LOG.LogWarning($"The plugin '{pluginMainFile}' is not maintained anymore. Please consider to disable it.");
break;
}
await CopyPluginFile(content, metaData);
}
}
catch
{
LOG.LogError($"Was not able to ensure the plugin: {plugin}");
LOG.LogInformation($"Successfully loaded plugin: '{pluginMainFile}' (Id='{plugin.Id}', Type='{plugin.Type}', Name='{plugin.Name}', Version='{plugin.Version}', Authors='{string.Join(", ", plugin.Authors)}')");
AVAILABLE_PLUGINS.Add(new PluginMetadata(plugin));
}
}
private static async Task CopyPluginFile(IFileInfo resourceInfo, InternalPluginData metaData)
{
await using var inputStream = resourceInfo.CreateReadStream();
var pluginsRoot = Path.Join(DATA_DIR, "plugins");
var pluginTypeBasePath = Path.Join(pluginsRoot, metaData.Type.GetDirectory());
if (!Directory.Exists(pluginsRoot))
Directory.CreateDirectory(pluginsRoot);
if (!Directory.Exists(pluginTypeBasePath))
Directory.CreateDirectory(pluginTypeBasePath);
var pluginPath = Path.Join(pluginTypeBasePath, metaData.ResourceName);
if (!Directory.Exists(pluginPath))
Directory.CreateDirectory(pluginPath);
var pluginFilePath = Path.Join(pluginPath, resourceInfo.Name);
await using var outputStream = File.Create(pluginFilePath);
await inputStream.CopyToAsync(outputStream);
}
public static async Task LoadAll()
{
}
public static async Task<PluginBase> Load(string path, string code, CancellationToken cancellationToken = default)
private static async Task<PluginBase> Load(string pluginPath, string code, CancellationToken cancellationToken = default)
{
if(ForbiddenPlugins.Check(code) is { IsForbidden: true } forbiddenState)
return new NoPlugin($"This plugin is forbidden: {forbiddenState.Message}");
var state = LuaState.Create();
// Add the module loader so that the plugin can load other Lua modules:
state.ModuleLoader = new PluginLoader(pluginPath);
// Add some useful libraries:
state.OpenModuleLibrary();
state.OpenStringLibrary();
state.OpenTableLibrary();
state.OpenMathLibrary();
state.OpenBitwiseLibrary();
state.OpenCoroutineLibrary();
try
{
await state.DoStringAsync(code, cancellationToken: cancellationToken);
@ -105,6 +114,10 @@ public static class PluginFactory
{
return new NoPlugin($"Was not able to parse the plugin: {e.Message}");
}
catch (LuaRuntimeException e)
{
return new NoPlugin($"Was not able to run the plugin: {e.Message}");
}
if (!state.Environment["TYPE"].TryRead<string>(out var typeText))
return new NoPlugin("TYPE does not exist or is not a valid string.");
@ -115,9 +128,10 @@ public static class PluginFactory
if(type is PluginType.NONE)
return new NoPlugin($"TYPE is not a valid plugin type. Valid types are: {CommonTools.GetAllEnumValues<PluginType>()}");
var isInternal = pluginPath.StartsWith(INTERNAL_PLUGINS_ROOT, StringComparison.OrdinalIgnoreCase);
return type switch
{
PluginType.LANGUAGE => new PluginLanguage(path, state, type),
PluginType.LANGUAGE => new PluginLanguage(isInternal, state, type),
_ => new NoPlugin("This plugin type is not supported yet. Please try again with a future version of AI Studio.")
};

View File

@ -8,7 +8,7 @@ public sealed class PluginLanguage : PluginBase, ILanguagePlugin
private ILanguagePlugin? baseLanguage;
public PluginLanguage(string path, LuaState state, PluginType type) : base(path, state, type)
public PluginLanguage(bool isInternal, LuaState state, PluginType type) : base(isInternal, state, type)
{
if (this.TryInitUITextContent(out var issue, out var readContent))
this.content = readContent;

View File

@ -0,0 +1,50 @@
namespace AIStudio.Tools.PluginSystem;
public sealed class PluginMetadata(PluginBase plugin) : IPluginMetadata
{
#region Implementation of IPluginMetadata
/// <inheritdoc />
public string IconSVG { get; } = plugin.IconSVG;
/// <inheritdoc />
public PluginType Type { get; } = plugin.Type;
/// <inheritdoc />
public Guid Id { get; } = plugin.Id;
/// <inheritdoc />
public string Name { get; } = plugin.Name;
/// <inheritdoc />
public string Description { get; } = plugin.Description;
/// <inheritdoc />
public PluginVersion Version { get; } = plugin.Version;
/// <inheritdoc />
public string[] Authors { get; } = plugin.Authors;
/// <inheritdoc />
public string SupportContact { get; } = plugin.SupportContact;
/// <inheritdoc />
public string SourceURL { get; } = plugin.SourceURL;
/// <inheritdoc />
public PluginCategory[] Categories { get; } = plugin.Categories;
/// <inheritdoc />
public PluginTargetGroup[] TargetGroups { get; } = plugin.TargetGroups;
/// <inheritdoc />
public bool IsMaintained { get; } = plugin.IsMaintained;
/// <inheritdoc />
public string DeprecationMessage { get; } = plugin.DeprecationMessage;
/// <inheritdoc />
public bool IsInternal { get; } = plugin.IsInternal;
#endregion
}

View File

@ -35,6 +35,20 @@
margin-top: 4px;
}
.plugin-icon-container {
width: var(--mud-icon-size-large);
height: var(--mud-icon-size-large);
}
.plugin-icon-container svg {
width: 100%;
height: 100%;
}
.mud-popover-open.InnerScrollingFix {
left: 0 !important;
}
:root {
--confidence-color: #000000;
}

View File

@ -1,4 +1,6 @@
# v0.9.39, build 214 (2025-03-xx xx:xx UTC)
- Added a feature flag for the plugin system. This flag is disabled by default and can be enabled inside the app settings. Please note that this feature is still in development; there are no plugins available yet.
- Added the Lua library we use for the plugin system to the about page.
- Added the plugin overview page. This page shows all installed plugins and allows you to enable or disable them. It is only available when the plugin preview feature is enabled.
- Fixed the preview tooltip component not showing the correct position when used inside a scrollable container.
- Upgraded to Rust 1.85.1