Skip to content

Commit a426533

Browse files
committed
Refactor menu for UI.
1 parent b07117e commit a426533

6 files changed

Lines changed: 60 additions & 0 deletions

File tree

‎src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using BotSharp.Abstraction.Plugins.Models;
12
using Microsoft.Extensions.Configuration;
23
using Microsoft.Extensions.DependencyInjection;
34

@@ -15,4 +16,6 @@ public interface IBotSharpPlugin
1516
bool WithAgent => false;
1617

1718
void RegisterDI(IServiceCollection services, IConfiguration config);
19+
20+
PluginMenuDef[] GetMenus() => new PluginMenuDef[0];
1821
}

‎src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public class PluginDef
1111

1212
[JsonPropertyName("with_agent")]
1313
public bool WithAgent { get; set; }
14+
15+
public PluginMenuDef[] Menus { get; set; }
1416
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace BotSharp.Abstraction.Plugins.Models;
2+
3+
public class PluginMenuDef
4+
{
5+
public string Label { get; set; }
6+
public string? Icon { get; set; }
7+
public string? Link { get; set; }
8+
public bool IsHeader { get; set; }
9+
public int Weight { get; set; }
10+
11+
public PluginMenuDef(string lable, string? link = null, string? icon = null, int weight = 0, bool isHeader = false)
12+
{
13+
Label = lable;
14+
Link = link;
15+
Icon = icon;
16+
Weight = weight;
17+
IsHeader = isHeader;
18+
}
19+
}

‎src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public void Load(Action<Assembly> loaded)
5656
Assembly = assemblyName,
5757
IconUrl = module.IconUrl,
5858
WithAgent = module.WithAgent,
59+
Menus = module.GetMenus(),
5960
});
6061
Console.Write($"Loaded plugin ");
6162
Console.Write(name, Color.Green);

‎src/Infrastructure/BotSharp.OpenAPI/Controllers/PluginController.cs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,29 @@ public List<PluginDef> GetPlugins()
2222
var loader = _services.GetRequiredService<PluginLoader>();
2323
return loader.GetPlugins();
2424
}
25+
26+
[HttpGet("/plugin/menu")]
27+
public List<PluginMenuDef> GetPluginMenu()
28+
{
29+
var menus = new List<PluginMenuDef>
30+
{
31+
new PluginMenuDef("Dashboard", link: "/page/dashboard", icon: "bx bx-home-circle", weight: 1),
32+
new PluginMenuDef("Agent", isHeader: true, weight: 5),
33+
new PluginMenuDef("Router", link: "/page/agent/router", icon: "bx bx-map-pin", weight: 6),
34+
// new PluginMenuDef("Evaluator", link: "/page/agent/evaluator", icon: "bx bx-task", weight: 7),
35+
new PluginMenuDef("Agents", link: "/page/agent", icon: "bx bx-bot", weight: 8),
36+
new PluginMenuDef("Conversation", isHeader: true, weight: 15),
37+
new PluginMenuDef("Conversations", link: "/page/conversation", icon: "bx bx-conversation", weight: 16),
38+
new PluginMenuDef("System", isHeader: true, weight: 30),
39+
new PluginMenuDef("Plugins", link: "/page/plugin", icon: "bx bx-plug", weight: 31),
40+
new PluginMenuDef("Settings", link: "/page/setting", icon: "bx bx-cog", weight: 32),
41+
};
42+
var loader = _services.GetRequiredService<PluginLoader>();
43+
foreach (var plugin in loader.GetPlugins())
44+
{
45+
menus.AddRange(plugin.Menus);
46+
}
47+
menus = menus.OrderBy(x => x.Weight).ToList();
48+
return menus;
49+
}
2550
}

‎src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using BotSharp.Abstraction.Plugins.Models;
12
using Microsoft.Extensions.Configuration;
23

34
namespace BotSharp.Plugin.KnowledgeBase;
@@ -21,4 +22,13 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
2122
services.AddScoped<IKnowledgeService, KnowledgeService>();
2223
services.AddSingleton<IPdf2TextConverter, PigPdf2TextConverter>();
2324
}
25+
26+
public PluginMenuDef[] GetMenus()
27+
{
28+
return new PluginMenuDef[]
29+
{
30+
new PluginMenuDef("RAG", isHeader: true, weight: 20),
31+
new PluginMenuDef("Knowledge Base", link: "/page/knowledge-base", icon: "bx bx-book-open", weight: 21),
32+
};
33+
}
2434
}

0 commit comments

Comments
 (0)