diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs index ca4f6f1e..7717e9e6 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Plugins.Models; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -15,4 +16,6 @@ public interface IBotSharpPlugin bool WithAgent => false; void RegisterDI(IServiceCollection services, IConfiguration config); + + PluginMenuDef[] GetMenus() => new PluginMenuDef[0]; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs index a18486d6..0781d850 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs @@ -11,4 +11,6 @@ public class PluginDef [JsonPropertyName("with_agent")] public bool WithAgent { get; set; } + + public PluginMenuDef[] Menus { get; set; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginMenuDef.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginMenuDef.cs new file mode 100644 index 00000000..44d7a41b --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginMenuDef.cs @@ -0,0 +1,19 @@ +namespace BotSharp.Abstraction.Plugins.Models; + +public class PluginMenuDef +{ + public string Label { get; set; } + public string? Icon { get; set; } + public string? Link { get; set; } + public bool IsHeader { get; set; } + public int Weight { get; set; } + + public PluginMenuDef(string lable, string? link = null, string? icon = null, int weight = 0, bool isHeader = false) + { + Label = lable; + Link = link; + Icon = icon; + Weight = weight; + IsHeader = isHeader; + } +} diff --git a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs index 9667ae90..4b0ed022 100644 --- a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs @@ -56,6 +56,7 @@ public class PluginLoader Assembly = assemblyName, IconUrl = module.IconUrl, WithAgent = module.WithAgent, + Menus = module.GetMenus(), }); Console.Write($"Loaded plugin "); Console.Write(name, Color.Green); diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs index 23ba001b..734421f7 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs @@ -22,4 +22,29 @@ public class PluginController : ControllerBase var loader = _services.GetRequiredService(); return loader.GetPlugins(); } + + [HttpGet("/plugin/menu")] + public List GetPluginMenu() + { + var menus = new List + { + new PluginMenuDef("Dashboard", link: "/page/dashboard", icon: "bx bx-home-circle", weight: 1), + new PluginMenuDef("Agent", isHeader: true, weight: 5), + new PluginMenuDef("Router", link: "/page/agent/router", icon: "bx bx-map-pin", weight: 6), + // new PluginMenuDef("Evaluator", link: "/page/agent/evaluator", icon: "bx bx-task", weight: 7), + new PluginMenuDef("Agents", link: "/page/agent", icon: "bx bx-bot", weight: 8), + new PluginMenuDef("Conversation", isHeader: true, weight: 15), + new PluginMenuDef("Conversations", link: "/page/conversation", icon: "bx bx-conversation", weight: 16), + new PluginMenuDef("System", isHeader: true, weight: 30), + new PluginMenuDef("Plugins", link: "/page/plugin", icon: "bx bx-plug", weight: 31), + new PluginMenuDef("Settings", link: "/page/setting", icon: "bx bx-cog", weight: 32), + }; + var loader = _services.GetRequiredService(); + foreach (var plugin in loader.GetPlugins()) + { + menus.AddRange(plugin.Menus); + } + menus = menus.OrderBy(x => x.Weight).ToList(); + return menus; + } } diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs index e4685843..a9316c54 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Plugins.Models; using Microsoft.Extensions.Configuration; namespace BotSharp.Plugin.KnowledgeBase; @@ -21,4 +22,13 @@ public class KnowledgeBasePlugin : IBotSharpPlugin services.AddScoped(); services.AddSingleton(); } + + public PluginMenuDef[] GetMenus() + { + return new PluginMenuDef[] + { + new PluginMenuDef("RAG", isHeader: true, weight: 20), + new PluginMenuDef("Knowledge Base", link: "/page/knowledge-base", icon: "bx bx-book-open", weight: 21), + }; + } }