Assistant Builder improvements (#851)
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (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, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (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,app,updater, dmg) (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, nsis) (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,updater, appimage) (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

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
nilskruthoffandThorsten Sommer authored and GitHub committed 2026-07-15 21:00:25 +02:00
1 parent b1459523d9
commit 88aab302a2
37 files changed
+4098 -482

No files matched your search

@@ -140,7 +140,7 @@ public partial class AssistantPluginAuditDialog : MSGComponentBase
{
x => x.Message,
string.Format(
T("The assistant plugin \"{0}\" was audited with the level \"{1}\", which is below the required safety level \"{2}\". Your current settings still allow activation, but this may be unsafe. Do you really want to enable this plugin?"),
T("The assistant plugin '{0}' was audited with the level '{1}', which is below the required safety level '{2}'. Your current settings still allow activation, but this may be unsafe. Do you really want to enable this plugin?"),
this.plugin?.Name ?? T("Unknown plugin"),
this.audit?.Level.GetName() ?? T("Unknown"),
this.MinimumLevelLabel)
@@ -0,0 +1,57 @@
@inherits MSGComponentBase
<MudDialog DefaultFocus="DefaultFocus.None">
<DialogContent>
<MudStack Spacing="2">
@if (!string.IsNullOrWhiteSpace(this.issue))
{
<MudAlert Severity="Severity.Error" Dense="true">
@this.issue
</MudAlert>
}
@if (this.isLoading)
{
<MudProgressLinear Indeterminate="true" Color="Color.Primary" />
}
else if (this.plugin is not null)
{
<MudText Typo="Typo.h6">@this.plugin.Name</MudText>
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween" Spacing="1">
<MudLink OnClick="@(async () => await this.CopyToClipboard())">
<MudText Typo="Typo.caption" Class="mud-text-secondary">
@this.pluginFile
</MudText>
</MudLink>
<MudTooltip Text="@this.FullscreenLabel">
<MudIconButton Icon="@this.FullscreenIcon"
OnClick="@this.ToggleFullscreenAsync"
Size="Size.Medium"/>
</MudTooltip>
</MudStack>
<CodeEditor @ref="this.codeEditor" Value="@this.luaCode" Language="CodeEditorLanguage.LUA" Class="mt-n3"/>
}
</MudStack>
</DialogContent>
<DialogActions>
<MudButton OnClick="@this.Cancel" Disabled="@this.isSaving" Size="Size.Small">
@T("Cancel")
</MudButton>
<MudButton OnClick="@this.SaveAsync"
Disabled="@(!this.CanSave)"
Color="Color.Primary"
Variant="Variant.Filled"
StartIcon="@Icons.Material.Filled.Save"
Size="Size.Small">
@if (this.isSaving)
{
@T("Saving...")
}
else
{
@T("Save")
}
</MudButton>
</DialogActions>
</MudDialog>
@@ -0,0 +1,153 @@
using System.Text;
using AIStudio.Components;
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Dialogs;
public sealed record AssistantPluginEditorDialogResult(Guid PluginId, string PluginName);
public partial class AssistantPluginEditorDialog : MSGComponentBase
{
[Inject]
protected RustService RustService { get; init; } = null!;
[Inject]
protected ISnackbar Snackbar { get; init; } = null!;
private const string PLUGIN_FILE_NAME = "plugin.lua";
private static readonly ILogger LOGGER = Program.LOGGER_FACTORY.CreateLogger(nameof(AssistantPluginEditorDialog));
private readonly MudBlazor.DialogOptions optionsFullscreen = new()
{
BackdropClick = false,
CloseButton = true,
FullScreen = true,
FullWidth = true,
NoHeader = true,
};
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = null!;
[Inject]
private AssistantPluginInstallService AssistantPluginInstallService { get; init; } = null!;
[Parameter]
public Guid PluginId { get; set; }
[Parameter]
public string PluginLocalPath { get; set; } = string.Empty;
private IAvailablePlugin? plugin;
private CodeEditor? codeEditor;
private string pluginFile = string.Empty;
private string luaCode = string.Empty;
private string issue = string.Empty;
private bool isLoading = true;
private bool isSaving;
private bool isFullscreen;
private bool CanSave => this.plugin is not null && !this.isLoading && !this.isSaving;
private string FullscreenIcon => this.isFullscreen ? Icons.Material.Filled.FullscreenExit : Icons.Material.Filled.Fullscreen;
private string FullscreenLabel => this.isFullscreen ? T("Exit fullscreen") : T("Fullscreen");
private Func<string> Result2Copy => () => string.IsNullOrEmpty(this.pluginFile) ? string.Empty : this.pluginFile;
protected override async Task OnInitializedAsync()
{
try
{
this.plugin = PluginFactory.AvailablePlugins
.OfType<IAvailablePlugin>()
.FirstOrDefault(x => x.Id == this.PluginId && AreSamePath(x.LocalPath, this.PluginLocalPath));
if (this.plugin is null)
{
this.issue = T("The assistant plugin could not be resolved.");
return;
}
if (this.plugin is { IsInternal: true } || this.plugin.Type is not PluginType.ASSISTANT || string.IsNullOrWhiteSpace(this.plugin.LocalPath))
{
this.issue = T("This plugin cannot be edited.");
return;
}
this.pluginFile = Path.Join(this.plugin.LocalPath, PLUGIN_FILE_NAME);
if (!File.Exists(this.pluginFile))
{
this.issue = T("The plugin.lua file could not be found.");
return;
}
this.luaCode = await File.ReadAllTextAsync(this.pluginFile, Encoding.UTF8);
}
catch (Exception e)
{
this.issue = string.Format(T("The assistant plugin could not be loaded: {0}"), e.Message);
}
finally
{
this.isLoading = false;
}
await base.OnInitializedAsync();
}
private async Task SaveAsync()
{
if (!this.CanSave || this.plugin is null || this.codeEditor is null)
return;
this.isSaving = true;
this.issue = string.Empty;
await this.InvokeAsync(this.StateHasChanged);
try
{
var editedLua = await this.codeEditor.GetCodeAsync();
var result = await this.AssistantPluginInstallService.UpdateInstalledAssistantAsync(this.plugin, editedLua, CancellationToken.None);
if (!result.Success)
{
LOGGER.LogError($"Failed to update assistant plugin '{result.PluginName}' ({result.PluginId}) in '{result.PluginDirectory}' with issue '{result.Issue}'.");
this.issue = result.Issue;
return;
}
this.MudDialog.Close(DialogResult.Ok(new AssistantPluginEditorDialogResult(result.PluginId, result.PluginName)));
}
finally
{
this.isSaving = false;
if (!string.IsNullOrWhiteSpace(this.issue))
await this.InvokeAsync(this.StateHasChanged);
}
}
private async Task ToggleFullscreenAsync()
{
this.isFullscreen = !this.isFullscreen;
await this.MudDialog.SetOptionsAsync(this.isFullscreen ? this.optionsFullscreen : DialogOptions.BLOCKING_FULLSCREEN);
}
private void Cancel() => this.MudDialog.Cancel();
private async Task CopyToClipboard() => await this.RustService.CopyText2Clipboard(this.Snackbar, this.Result2Copy());
private static bool AreSamePath(string left, string right)
{
if (string.IsNullOrWhiteSpace(left) || string.IsNullOrWhiteSpace(right))
return false;
var comparison = OperatingSystem.IsWindows()
? StringComparison.OrdinalIgnoreCase
: StringComparison.Ordinal;
return string.Equals(
Path.GetFullPath(left).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar),
Path.GetFullPath(right).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar),
comparison);
}
}
@@ -0,0 +1,106 @@
@inherits MSGComponentBase
<MudDialog DefaultFocus="DefaultFocus.None">
<DialogContent>
<MudStack Spacing="3">
@if (!string.IsNullOrWhiteSpace(this.issue))
{
<MudAlert Severity="Severity.Error" Dense="true">
@this.issue
</MudAlert>
}
@if (this.isLoading)
{
<MudProgressLinear Indeterminate="true" Color="Color.Primary" />
}
else if (this.assistantPlugin is not null)
{
<MudText Typo="Typo.h6">@this.assistantPlugin.AssistantTitle</MudText>
<MudText Typo="Typo.body2" Class="mud-text-secondary">@T("Describe what should change after trying the assistant. AI Studio will revise the installed plugin while keeping the same assistant ID.")</MudText>
<MudTextField T="string"
@bind-Text="@this.changeRequest"
Label="@T("Requested changes")"
Placeholder="@T("Add a field for the target audience and make the final answer shorter.")"
Variant="Variant.Outlined"
Lines="5"
AutoGrow="true"
MaxLines="12"
Immediate="true"
Disabled="@(this.isGenerating || this.isApplying)" />
<CascadingValue Value="Components.META_ASSISTANT">
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider" Disabled="@(this.isGenerating || this.isApplying)" />
</CascadingValue>
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
StartIcon="@Icons.Material.Filled.AutoFixHigh"
Disabled="@(!this.CanGenerate)"
OnClick="@(async () => await this.GenerateRevisionAsync())">
@if (this.isGenerating)
{
@T("Creating revision...")
}
else
{
@T("Create revision")
}
</MudButton>
@if (this.isGenerating)
{
<MudProgressLinear Indeterminate="true" Color="Color.Primary" />
}
@if (this.revisionCheckResult?.Success is true)
{
<MudAlert Severity="Severity.Success" Dense="true" Icon="@Icons.Material.Filled.CheckCircle">
@string.Format(T("The revised assistant '{0}' is valid and ready to update."), string.IsNullOrWhiteSpace(this.revisedPluginName) ? this.revisionCheckResult.PluginName : this.revisedPluginName)
</MudAlert>
}
@if (!string.IsNullOrWhiteSpace(this.revisedLua))
{
<MudExpansionPanels Dense="true" Elevation="0">
<MudExpansionPanel Dense="true" Class="border-solid border rounded pt-n4" Style="border-color: #BDBDBD">
<TitleContent>
<div class="d-flex align-center">
<MudIcon Icon="@Icons.Material.Filled.Code" Class="mr-3" Color="Color.Primary" />
<MudText Typo="Typo.button">
@T("Revised Lua plugin")
</MudText>
</div>
</TitleContent>
<ChildContent>
<MudTextField T="string" Text="@this.revisedLua" ReadOnly="true" Variant="Variant.Outlined" Lines="18" Class="mt-2" Style="font-family: monospace" />
</ChildContent>
</MudExpansionPanel>
</MudExpansionPanels>
}
@if (this.isApplying || this.isAuditing)
{
<MudProgressLinear Indeterminate="true" Color="Color.Primary" />
<MudText Typo="Typo.body2">
@(this.isAuditing ? T("Running security audit...") : T("Updating assistant..."))
</MudText>
}
}
</MudStack>
</DialogContent>
<DialogActions>
<MudButton OnClick="@this.Cancel" Disabled="@(this.isGenerating || this.isApplying || this.isAuditing)" Size="Size.Small">
@T("Cancel")
</MudButton>
<MudButton OnClick="@(async () => await this.ApplyRevisionAsync())"
Disabled="@(!this.CanApply)"
Color="Color.Primary"
Variant="Variant.Filled"
StartIcon="@Icons.Material.Filled.Save"
Size="Size.Small">
@T("Update assistant")
</MudButton>
</DialogActions>
</MudDialog>
@@ -0,0 +1,255 @@
using System.Text;
using AIStudio.Agents.AssistantAudit;
using AIStudio.Components;
using AIStudio.Provider;
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.PluginSystem.Assistants;
using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Dialogs;
public sealed record AssistantPluginRevisionDialogResult(Guid PluginId, string PluginName, PluginAssistantAudit? Audit);
public partial class AssistantPluginRevisionDialog : MSGComponentBase
{
private const string PLUGIN_FILE_NAME = "plugin.lua";
private static readonly ILogger LOGGER = Program.LOGGER_FACTORY.CreateLogger(nameof(AssistantPluginRevisionDialog));
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = null!;
[Inject]
private AssistantPluginGenerationService AssistantPluginGenerationService { get; init; } = null!;
[Inject]
private AssistantPluginInstallService AssistantPluginInstallService { get; init; } = null!;
[Inject]
private AssistantPluginAuditService AssistantPluginAuditService { get; init; } = null!;
[Parameter]
public Guid PluginId { get; set; }
[Parameter]
public string PluginLocalPath { get; set; } = string.Empty;
[Parameter]
public string TestContext { get; set; } = string.Empty;
private IAvailablePlugin? availablePlugin;
private PluginAssistants? assistantPlugin;
private AIStudio.Settings.Provider providerSettings = AIStudio.Settings.Provider.NONE;
private string pluginFile = string.Empty;
private string currentLua = string.Empty;
private string changeRequest = string.Empty;
private string revisedLua = string.Empty;
private string revisedPluginName = string.Empty;
private string issue = string.Empty;
private AssistantPluginCheckResult? revisionCheckResult;
private bool isLoading = true;
private bool isGenerating;
private bool isApplying;
private bool isAuditing;
private bool CanGenerate => this.assistantPlugin is not null &&
!this.isLoading &&
!this.isGenerating &&
!this.isApplying &&
!string.IsNullOrWhiteSpace(this.changeRequest);
private bool CanApply => this.availablePlugin is not null &&
this.assistantPlugin is not null &&
!this.isGenerating &&
!this.isApplying &&
!this.isAuditing &&
this.revisionCheckResult?.Success is true &&
!string.IsNullOrWhiteSpace(this.revisedLua);
protected override async Task OnInitializedAsync()
{
try
{
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.META_ASSISTANT);
this.availablePlugin = PluginFactory.AvailablePlugins
.OfType<IAvailablePlugin>()
.FirstOrDefault(x => x.Id == this.PluginId && AreSamePath(x.LocalPath, this.PluginLocalPath));
this.assistantPlugin = PluginFactory.RunningPlugins
.OfType<PluginAssistants>()
.FirstOrDefault(x => x.Id == this.PluginId && AreSamePath(x.PluginPath, this.PluginLocalPath));
if (this.availablePlugin is null || this.assistantPlugin is null)
{
this.issue = T("The assistant plugin could not be resolved.");
return;
}
if (!CanReviseAssistantPlugin(this.availablePlugin, this.assistantPlugin))
{
this.issue = T("Only locally managed assistant plugins can be revised with AI.");
return;
}
this.pluginFile = Path.Join(this.availablePlugin.LocalPath, PLUGIN_FILE_NAME);
if (!File.Exists(this.pluginFile))
{
this.issue = T("The plugin.lua file could not be found.");
return;
}
this.currentLua = await File.ReadAllTextAsync(this.pluginFile, Encoding.UTF8);
}
catch (Exception e)
{
this.issue = string.Format(T("The assistant plugin could not be loaded: {0}"), e.Message);
}
finally
{
this.isLoading = false;
}
await base.OnInitializedAsync();
}
private async Task GenerateRevisionAsync()
{
if (!this.CanGenerate || this.assistantPlugin is null)
return;
this.isGenerating = true;
this.issue = string.Empty;
this.revisedLua = string.Empty;
this.revisionCheckResult = null;
await this.InvokeAsync(this.StateHasChanged);
try
{
var draft = await this.AssistantPluginGenerationService.GenerateRevisionAsync(
this.assistantPlugin,
this.currentLua,
this.changeRequest,
this.providerSettings,
this.TestContext,
CancellationToken.None);
if (!draft.Success)
{
this.issue = draft.Issue;
return;
}
this.revisedLua = draft.Lua;
this.revisedPluginName = draft.PluginName;
if (this.availablePlugin is null)
return;
this.revisionCheckResult = await this.AssistantPluginInstallService.CheckInstalledAssistantUpdateAsync(this.availablePlugin, this.revisedLua, CancellationToken.None);
if (this.revisionCheckResult.Success)
return;
this.issue = this.revisionCheckResult.Issue;
}
finally
{
this.isGenerating = false;
await this.InvokeAsync(this.StateHasChanged);
}
}
private async Task ApplyRevisionAsync()
{
if (!this.CanApply || this.availablePlugin is null)
return;
this.isApplying = true;
this.issue = string.Empty;
await this.InvokeAsync(this.StateHasChanged);
try
{
var result = await this.AssistantPluginInstallService.UpdateInstalledAssistantAsync(this.availablePlugin, this.revisedLua, CancellationToken.None);
if (!result.Success)
{
LOGGER.LogError($"Failed to revise assistant plugin '{result.PluginName}' ({result.PluginId}) in '{result.PluginDirectory}' with issue '{result.Issue}'.");
this.issue = result.Issue;
return;
}
PluginAssistantAudit? audit = null;
if (this.SettingsManager.ConfigurationData.AssistantPluginAudit.AutomaticallyAuditAssistants)
audit = await this.TryRunAuditAsync(result.PluginId);
this.MudDialog.Close(DialogResult.Ok(new AssistantPluginRevisionDialogResult(result.PluginId, result.PluginName, audit)));
}
finally
{
this.isApplying = false;
if (!string.IsNullOrWhiteSpace(this.issue))
await this.InvokeAsync(this.StateHasChanged);
}
}
private async Task<PluginAssistantAudit?> TryRunAuditAsync(Guid pluginId)
{
var updatedPlugin = PluginFactory.RunningPlugins.OfType<PluginAssistants>().FirstOrDefault(x => x.Id == pluginId);
if (updatedPlugin is null)
return null;
this.isAuditing = true;
await this.InvokeAsync(this.StateHasChanged);
try
{
var audit = await this.AssistantPluginAuditService.RunAuditAsync(updatedPlugin);
if (audit.Level is AssistantAuditLevel.UNKNOWN)
return audit;
UpsertAudit(this.SettingsManager.ConfigurationData.AssistantPluginAudits, audit);
await this.SettingsManager.StoreSettings();
return audit;
}
finally
{
this.isAuditing = false;
}
}
private string? ValidatingProvider(AIStudio.Settings.Provider provider)
{
if (provider.UsedLLMProvider == LLMProviders.NONE)
return T("Please select a provider.");
return null;
}
private void Cancel() => this.MudDialog.Cancel();
private static bool CanReviseAssistantPlugin(IAvailablePlugin availablePlugin, PluginAssistants assistantPlugin) =>
availablePlugin is { IsInternal: false, IsManagedByConfigServer: false, Type: PluginType.ASSISTANT } &&
!string.IsNullOrWhiteSpace(availablePlugin.LocalPath) &&
assistantPlugin is { IsInternal: false, IsManagedByConfigServer: false };
private static void UpsertAudit(IList<PluginAssistantAudit> audits, PluginAssistantAudit audit)
{
var existingIndex = audits.ToList().FindIndex(x => x.PluginId == audit.PluginId);
if (existingIndex >= 0)
audits[existingIndex] = audit;
else
audits.Add(audit);
}
private static bool AreSamePath(string left, string right)
{
if (string.IsNullOrWhiteSpace(left) || string.IsNullOrWhiteSpace(right))
return false;
var comparison = OperatingSystem.IsWindows()
? StringComparison.OrdinalIgnoreCase
: StringComparison.Ordinal;
return string.Equals(
Path.GetFullPath(left).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar),
Path.GetFullPath(right).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar),
comparison);
}
}