diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs index d3e0a8f3..06dc4992 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs @@ -25,5 +25,5 @@ public interface IBotSharpPlugin void RegisterDI(IServiceCollection services, IConfiguration config); - PluginMenuDef[] GetMenus() => new PluginMenuDef[0]; + bool AttachMenu(List menu) => true; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs index 7b3eface..17849c18 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs @@ -6,6 +6,9 @@ public class PluginDef public string Name { get; set; } public string Description { get; set; } public string Assembly { get; set; } + [JsonPropertyName("is_core")] + public bool IsCore => Assembly == "BotSharp.Core"; + [JsonPropertyName("icon_url")] public string? IconUrl { get; set; } @@ -17,6 +20,4 @@ public class PluginDef public IBotSharpPlugin Module { get; set; } public bool Enabled { 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 index 44d7a41b..bd5a1d88 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginMenuDef.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginMenuDef.cs @@ -2,18 +2,36 @@ namespace BotSharp.Abstraction.Plugins.Models; public class PluginMenuDef { + [JsonIgnore] + public string Id { get; set; } + public string Label { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Icon { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Link { get; set; } - public bool IsHeader { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public bool? IsHeader { get; set; } + + [JsonIgnore] public int Weight { get; set; } - public PluginMenuDef(string lable, string? link = null, string? icon = null, int weight = 0, bool isHeader = false) + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? SubMenu { get; set; } + + public PluginMenuDef(string lable, string? link = null, string? icon = null, int weight = 0) { Label = lable; Link = link; Icon = icon; Weight = weight; - IsHeader = isHeader; + } + + public override string ToString() + { + return $"{Label} {Link} {Weight}"; } } diff --git a/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs b/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs index d9a0405e..d5e7ce0f 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.MLTasks; +using BotSharp.Abstraction.Plugins.Models; using BotSharp.Abstraction.Settings; using Microsoft.Extensions.Configuration; @@ -26,4 +27,20 @@ public class AgentPlugin : IBotSharpPlugin return settingService.Bind("Agent"); }); } + + public bool AttachMenu(List menu) + { + var section = menu.First(x => x.Label == "Apps"); + menu.Add(new PluginMenuDef("Agent", icon: "bx bx-bot", weight: section.Weight + 1) + { + SubMenu = new List + { + new PluginMenuDef("Router", link: "/page/agent/router"), // icon: "bx bx-map-pin" + new PluginMenuDef("Evaluator", link: "/page/agent/evaluator"), // icon: "bx bx-task" + new PluginMenuDef("Agents", link: "/page/agent"), // icon: "bx bx-bot" + } + }); + + return true; + } } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs b/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs index a846aa7d..0353cb62 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs @@ -1,6 +1,7 @@ using BotSharp.Abstraction.Instructs; using BotSharp.Abstraction.Messaging; using BotSharp.Abstraction.Planning; +using BotSharp.Abstraction.Plugins.Models; using BotSharp.Abstraction.Settings; using BotSharp.Abstraction.Templating; using BotSharp.Core.Instructs; @@ -45,4 +46,11 @@ public class ConversationPlugin : IBotSharpPlugin services.AddScoped(); services.AddScoped(); } + + public bool AttachMenu(List menu) + { + var section = menu.First(x => x.Label == "Apps"); + menu.Add(new PluginMenuDef("Conversation", link: "/page/conversation", icon: "bx bx-conversation", weight: section.Weight + 5)); + return true; + } } diff --git a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs index 17e740d2..98d934cb 100644 --- a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs @@ -57,8 +57,7 @@ public class PluginLoader Description = module.Description, Assembly = assemblyName, IconUrl = module.IconUrl, - AgentIds = module.AgentIds, - Menus = module.GetMenus(), + AgentIds = module.AgentIds }); Console.Write($"Loaded plugin "); Console.Write(name, Color.Green); @@ -85,7 +84,7 @@ public class PluginLoader var config = db.GetPluginConfig(); foreach (var plugin in _plugins) { - plugin.Enabled = config.EnabledPlugins.Contains(plugin.Id); + plugin.Enabled = plugin.IsCore || config.EnabledPlugins.Contains(plugin.Id); } return _plugins; } diff --git a/src/Infrastructure/BotSharp.Core/data/plugins/config.json b/src/Infrastructure/BotSharp.Core/data/plugins/config.json index a68ea077..ab574671 100644 --- a/src/Infrastructure/BotSharp.Core/data/plugins/config.json +++ b/src/Infrastructure/BotSharp.Core/data/plugins/config.json @@ -4,6 +4,6 @@ "058094a7-4ad3-4284-b94d-ac1373cf63d8", "65185362-392c-44fd-a023-95a198824436", "5b18ca9b-82ed-494b-b121-e3499661edb0", - "6e52d42d-1e23-406b-8599-36af36c83209" + "6e52d42d-1e23-406b-8599-36af36c83209" ] } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs index f695d882..01c2dda2 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs @@ -26,19 +26,21 @@ public class PluginController : ControllerBase [HttpGet("/plugin/menu")] public List GetPluginMenu() { - var menus = new List + var menu = 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("Apps", weight: 5) + { + IsHeader = true, + }, + new PluginMenuDef("System", weight: 30) + { + IsHeader = true + }, 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(_services)) { @@ -46,10 +48,10 @@ public class PluginController : ControllerBase { continue; } - menus.AddRange(plugin.Menus); + plugin.Module.AttachMenu(menu); } - menus = menus.OrderBy(x => x.Weight).ToList(); - return menus; + menu = menu.OrderBy(x => x.Weight).ToList(); + return menu; } [HttpPost("/plugin/{id}/enable")] diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs index c1e6a080..70cddede 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs @@ -27,12 +27,10 @@ public class KnowledgeBasePlugin : IBotSharpPlugin services.AddSingleton(); } - public PluginMenuDef[] GetMenus() + public bool AttachMenu(List menu) { - 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), - }; + var section = menu.First(x => x.Label == "Apps"); + menu.Add(new PluginMenuDef("Knowledge Base", link: "/page/knowledge-base", icon: "bx bx-book-open", weight: section.Weight + 1)); + return true; } }