Skip to content

Self-improving AI Employees for everyone

feat(plugin): add per-plugin meta.json resolver for color (F2)

trohitg796d36572ba1
diff --git a/server/nodes/_visuals.py b/server/nodes/_visuals.py
index 95e97dc8..842008d8 100644
--- a/server/nodes/_visuals.py
+++ b/server/nodes/_visuals.py
@@ -68,6 +68,10 @@ def get_color(node_type: str) -> str:
Color strings are arbitrary CSS color literals — the canvas node
components apply them as-is to gradients, borders, and badges.
+
+ Falls back to ``visuals.json`` for legacy entries that haven't been
+ migrated to per-plugin ``meta.json`` yet (F2 cleanup of the plugin
+ authoring RFC).
"""
entry = _VISUALS.get(node_type)
if not entry:
@@ -75,6 +79,49 @@ def get_color(node_type: str) -> str:
return str(entry.get("color", ""))
+def get_plugin_meta(node_type: str, key: Optional[str] = None) -> Optional[dict | str]:
+ """Read the plugin's co-located ``meta.json`` file.
+
+ Same folder-resolution path as :func:`get_plugin_icon_path` — uses
+ :func:`inspect.getfile` on the plugin class to locate the folder,
+ then loads ``meta.json`` if present.
+
+ Returns the value at ``key`` (str) when given, the whole dict when
+ ``key`` is ``None``, or ``None`` when the file or key is absent.
+ Callers fall back to :func:`get_color` / other ``visuals.json`` keys
+ for legacy entries.
+
+ Per RFC §6.2 / F2 of the deferred follow-ups: ``meta.json`` mirrors
+ ``icon.svg`` co-location so a plugin's entire visual surface area
+ lives in one folder. The previous central ``visuals.json`` color
+ map remains as a transitional fallback for entries without a
+ per-plugin ``meta.json``.
+ """
+ from services.node_registry import get_node_class
+
+ cls = get_node_class(node_type)
+ if cls is None:
+ return None
+ try:
+ plugin_dir = Path(inspect.getfile(cls)).resolve().parent
+ except (TypeError, OSError):
+ return None
+ meta_path = plugin_dir / "meta.json"
+ if not meta_path.exists():
+ return None
+ try:
+ with meta_path.open("r", encoding="utf-8") as fh:
+ data = json.load(fh)
+ except (OSError, json.JSONDecodeError):
+ return None
+ if not isinstance(data, dict):
+ return None
+ if key is None:
+ return data
+ value = data.get(key)
+ return None if value is None else str(value)
+
+
def get_plugin_icon_path(node_type: str, variant: str = "light") -> Optional[Path]:
"""Return the on-disk path to a plugin's co-located ``icon.svg``.
diff --git a/server/services/plugin/base.py b/server/services/plugin/base.py
index 9984742a..754f27bd 100644
--- a/server/services/plugin/base.py
+++ b/server/services/plugin/base.py
@@ -205,17 +205,24 @@ class BaseNode:
emitted as a URL routed through ``GET /api/schemas/nodes/<type>/icon``.
2. Fallback to ``visuals.json`` (emoji / ``lobehub:<brand>``).
- ``color`` continues to come from ``visuals.json`` (orthogonal
- to icon source; a future ``meta.json`` may eventually move
- colors per-folder too — deferred).
+ Color resolution (per RFC §6.6 / F2):
+ 1. Per-plugin ``meta.json`` ``color`` field, co-located with the
+ plugin folder. Mirrors icon co-location.
+ 2. Fallback to ``visuals.json`` for legacy entries that have
+ not been migrated yet.
"""
- from nodes._visuals import get_icon, get_color, get_plugin_icon_path
+ from nodes._visuals import (
+ get_icon,
+ get_color,
+ get_plugin_icon_path,
+ get_plugin_meta,
+ )
if get_plugin_icon_path(cls.type) is not None:
icon = f"/api/schemas/nodes/{cls.type}/icon"
else:
icon = get_icon(cls.type)
- color = get_color(cls.type)
+ color = get_plugin_meta(cls.type, "color") or get_color(cls.type)
meta: Dict[str, Any] = {
"displayName": cls.display_name or cls.type,
"icon": icon,