mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-24 20:52:11 +00:00
add share plugin functionality to Plugins page leveraging PluginShareService
This commit is contained in:
parent
3cd913aa7f
commit
c3f91f6828
@ -107,6 +107,13 @@
|
|||||||
<MudIconButton Icon="@Icons.Material.Filled.Code" Size="Size.Medium" OnClick="@(() => this.OpenAssistantPluginEditorDialogAsync(editablePlugin))"/>
|
<MudIconButton Icon="@Icons.Material.Filled.Code" Size="Size.Medium" OnClick="@(() => this.OpenAssistantPluginEditorDialogAsync(editablePlugin))"/>
|
||||||
</MudTooltip>
|
</MudTooltip>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@if (context is IAvailablePlugin shareablePlugin && CanSharePlugin(shareablePlugin))
|
||||||
|
{
|
||||||
|
<MudTooltip Text="@T("Share plugin archive")">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.IosShare" Size="Size.Medium" OnClick="@(() => this.SharePluginAsync(shareablePlugin))"/>
|
||||||
|
</MudTooltip>
|
||||||
|
}
|
||||||
|
|
||||||
@if (context is IAvailablePlugin revisionPlugin && CanReviseAssistantPlugin(revisionPlugin))
|
@if (context is IAvailablePlugin revisionPlugin && CanReviseAssistantPlugin(revisionPlugin))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,7 @@ using AIStudio.Dialogs;
|
|||||||
using AIStudio.Settings.DataModel;
|
using AIStudio.Settings.DataModel;
|
||||||
using AIStudio.Tools.PluginSystem.Assistants;
|
using AIStudio.Tools.PluginSystem.Assistants;
|
||||||
using AIStudio.Tools.PluginSystem;
|
using AIStudio.Tools.PluginSystem;
|
||||||
|
using AIStudio.Tools.Services;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using DialogOptions = AIStudio.Dialogs.DialogOptions;
|
using DialogOptions = AIStudio.Dialogs.DialogOptions;
|
||||||
|
|
||||||
@ -27,7 +27,12 @@ public partial class Plugins : MSGComponentBase
|
|||||||
[Inject]
|
[Inject]
|
||||||
private AssistantPluginAuditService AssistantPluginAuditService { get; init; } = null!;
|
private AssistantPluginAuditService AssistantPluginAuditService { get; init; } = null!;
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
private PluginShareService PluginShareService { get; init; } = null!;
|
||||||
|
|
||||||
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger(nameof(Plugins));
|
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger(nameof(Plugins));
|
||||||
|
|
||||||
|
private static bool IS_SHARING_PLUGIN;
|
||||||
|
|
||||||
#region Overrides of ComponentBase
|
#region Overrides of ComponentBase
|
||||||
|
|
||||||
@ -184,15 +189,18 @@ public partial class Plugins : MSGComponentBase
|
|||||||
: this.T("Enable plugin");
|
: this.T("Enable plugin");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CanEditAssistantPlugin(IAvailablePlugin plugin) => plugin is { IsInternal: false, Type: PluginType.ASSISTANT } && !string.IsNullOrWhiteSpace(plugin.LocalPath);
|
private static bool CanEditAssistantPlugin(IAvailablePlugin plugin) => plugin is { IsInternal: false, Type: PluginType.ASSISTANT } &&
|
||||||
|
!string.IsNullOrWhiteSpace(plugin.LocalPath) && !IS_SHARING_PLUGIN;
|
||||||
|
|
||||||
private static bool CanReviseAssistantPlugin(IAvailablePlugin plugin)
|
private static bool CanReviseAssistantPlugin(IAvailablePlugin plugin)
|
||||||
{
|
{
|
||||||
var assistantPlugin = PluginFactory.RunningPlugins.OfType<PluginAssistants>().FirstOrDefault(x => x.Id == plugin.Id);
|
var assistantPlugin = PluginFactory.RunningPlugins.OfType<PluginAssistants>().FirstOrDefault(x => x.Id == plugin.Id);
|
||||||
return plugin is { IsInternal: false, IsManagedByConfigServer: false, Type: PluginType.ASSISTANT } &&
|
return plugin is { IsInternal: false, IsManagedByConfigServer: false, Type: PluginType.ASSISTANT } &&
|
||||||
!string.IsNullOrWhiteSpace(plugin.LocalPath) &&
|
!string.IsNullOrWhiteSpace(plugin.LocalPath) && assistantPlugin?.IsManagedByConfigServer is false && !IS_SHARING_PLUGIN;
|
||||||
assistantPlugin?.IsManagedByConfigServer is false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool CanSharePlugin(IAvailablePlugin plugin) => plugin is { IsInternal: false, IsManagedByConfigServer: false } &&
|
||||||
|
!string.IsNullOrWhiteSpace(plugin.LocalPath) && !IS_SHARING_PLUGIN;
|
||||||
|
|
||||||
private async Task OpenAssistantPluginEditorDialogAsync(IAvailablePlugin plugin)
|
private async Task OpenAssistantPluginEditorDialogAsync(IAvailablePlugin plugin)
|
||||||
{
|
{
|
||||||
@ -233,6 +241,32 @@ public partial class Plugins : MSGComponentBase
|
|||||||
await this.InvokeAsync(this.StateHasChanged);
|
await this.InvokeAsync(this.StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SharePluginAsync(IAvailablePlugin plugin)
|
||||||
|
{
|
||||||
|
if (IS_SHARING_PLUGIN)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IS_SHARING_PLUGIN = true;
|
||||||
|
// invoke a state change right away to guard action buttons
|
||||||
|
await this.InvokeAsync(this.StateHasChanged);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var shareResult = await this.PluginShareService.ShareAsync(plugin, CancellationToken.None);
|
||||||
|
if (!shareResult.Success)
|
||||||
|
{
|
||||||
|
LOG.LogError($"Sharing the plugin '{shareResult.PluginName}' from archive '{shareResult.ArchivePath}' failed with Issue: '{shareResult.Issue}'.");
|
||||||
|
await this.MessageBus.SendError(new(Icons.Material.Filled.ReportProblem, T("An error occurred while sharing the plugin.")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IS_SHARING_PLUGIN = false;
|
||||||
|
await this.InvokeAsync(this.StateHasChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static bool IsSendingMail(string sourceUrl) => sourceUrl.TrimStart().StartsWith("mailto:", StringComparison.OrdinalIgnoreCase);
|
private static bool IsSendingMail(string sourceUrl) => sourceUrl.TrimStart().StartsWith("mailto:", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
private PluginAssistants? TryGetAssistantPlugin(Guid pluginId) => PluginFactory.RunningPlugins.OfType<PluginAssistants>().FirstOrDefault(x => x.Id == pluginId);
|
private PluginAssistants? TryGetAssistantPlugin(Guid pluginId) => PluginFactory.RunningPlugins.OfType<PluginAssistants>().FirstOrDefault(x => x.Id == pluginId);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user