Skip to content

Commit

Permalink
Merge pull request #457 from zAlweNy26/more-plugin-infos
Browse files Browse the repository at this point in the history
Add list of hooks and tools when fetching plugins
  • Loading branch information
pieroit authored Sep 18, 2023
2 parents 44c75ca + 9d2a480 commit 8926196
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/cat/mad_hatter/decorators/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class CatTool(Tool):
def augment_tool(self, cat_instance):

self.cat = cat_instance

self.name = self.func.__name__

# Tool docstring, is also available under self.func.__doc__
self.docstring = self.func.__doc__
Expand Down
10 changes: 8 additions & 2 deletions core/cat/routes/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ async def get_available_plugins(
# get manifest
manifest = deepcopy(p.manifest) # we make a copy to avoid modifying the plugin obj
manifest["active"] = p.id in active_plugins # pass along if plugin is active or not
manifest["hooks"] = [{ "name": hook.name, "priority": hook.priority } for hook in p.hooks]
manifest["tools"] = [{ "name": tool.name } for tool in p.tools]

# filter by query
plugin_text = [str(field) for field in manifest.values()]
Expand All @@ -48,7 +50,7 @@ async def get_available_plugins(
installed_plugins.append(manifest)

# do not show already installed plugins among registry plugins
registry_plugins_index.pop( manifest["plugin_url"], None )
registry_plugins_index.pop(manifest["plugin_url"], None)

return {
"filters": {
Expand Down Expand Up @@ -172,9 +174,13 @@ async def get_plugin_details(plugin_id: str, request: Request) -> Dict:

active_plugins = ccat.mad_hatter.load_active_plugins_from_db()

plugin = ccat.mad_hatter.plugins[plugin_id]

# get manifest and active True/False. We make a copy to avoid modifying the original obj
plugin_info = deepcopy(ccat.mad_hatter.plugins[plugin_id].manifest)
plugin_info = deepcopy(plugin.manifest)
plugin_info["active"] = plugin_id in active_plugins
plugin_info["hooks"] = [{ "name": hook.name, "priority": hook.priority } for hook in plugin.hooks]
plugin_info["tools"] = [{ "name": tool.name } for tool in plugin.tools]

return {
"data": plugin_info
Expand Down

0 comments on commit 8926196

Please sign in to comment.