Refactor menu for UI.
This commit is contained in:
parent
b07117ea6f
commit
a42653375d
|
|
@ -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];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,4 +11,6 @@ public class PluginDef
|
|||
|
||||
[JsonPropertyName("with_agent")]
|
||||
public bool WithAgent { get; set; }
|
||||
|
||||
public PluginMenuDef[] Menus { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -22,4 +22,29 @@ public class PluginController : ControllerBase
|
|||
var loader = _services.GetRequiredService<PluginLoader>();
|
||||
return loader.GetPlugins();
|
||||
}
|
||||
|
||||
[HttpGet("/plugin/menu")]
|
||||
public List<PluginMenuDef> GetPluginMenu()
|
||||
{
|
||||
var menus = new List<PluginMenuDef>
|
||||
{
|
||||
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<PluginLoader>();
|
||||
foreach (var plugin in loader.GetPlugins())
|
||||
{
|
||||
menus.AddRange(plugin.Menus);
|
||||
}
|
||||
menus = menus.OrderBy(x => x.Weight).ToList();
|
||||
return menus;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<IKnowledgeService, KnowledgeService>();
|
||||
services.AddSingleton<IPdf2TextConverter, PigPdf2TextConverter>();
|
||||
}
|
||||
|
||||
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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue