Personal Telegram developer console for GitHub

feat: add plugin registry

davoodmehraban89 committed Oct 3, 2026 at 01:21 UTC 3f644caef41a9136cb5f0a78b0c66798238a257d
1 file changed +56
src/core/plugin-registry.js new
+56
@@ -0,0 +1,56 @@
1 +const ALLOWED_RISKS = new Set(['READ', 'WRITE', 'DESTRUCTIVE']);
2 +
3 +export class PluginRegistry {
4 + constructor(plugins = []) {
5 + this.plugins = [];
6 + this.pluginsById = new Map();
7 + this.actionsById = new Map();
8 +
9 + for (const plugin of plugins) {
10 + this.register(plugin);
11 + }
12 + }
13 +
14 + register(plugin) {
15 + const pluginId = plugin?.manifest?.id;
16 + if (!pluginId) {
17 + throw new Error('Plugin manifest id is required');
18 + }
19 + if (this.pluginsById.has(pluginId)) {
20 + throw new Error(`Duplicate plugin id: ${pluginId}`);
21 + }
22 +
23 + const actions = plugin.manifest.actions || {};
24 + for (const [actionId, descriptor] of Object.entries(actions)) {
25 + if (this.actionsById.has(actionId)) {
26 + throw new Error(`Duplicate action id: ${actionId}`);
27 + }
28 + if (!ALLOWED_RISKS.has(descriptor?.risk)) {
29 + throw new Error(`Invalid action risk for ${actionId}: ${descriptor?.risk}`);
30 + }
31 + }
32 +
33 + this.plugins.push(plugin);
34 + this.pluginsById.set(pluginId, plugin);
35 +
36 + for (const [actionId, descriptor] of Object.entries(actions)) {
37 + this.actionsById.set(actionId, Object.freeze({
38 + pluginId,
39 + actionId,
40 + risk: descriptor.risk
41 + }));
42 + }
43 + }
44 +
45 + getPlugins() {
46 + return [...this.plugins];
47 + }
48 +
49 + getPlugin(pluginId) {
50 + return this.pluginsById.get(pluginId) || null;
51 + }
52 +
53 + getAction(actionId) {
54 + return this.actionsById.get(actionId) || null;
55 + }
56 +}