datasette
datasette copied to clipboard
/-/plugins should list permissions registered by each plugin
Would make the display of plugins more useful as their permissions would be self-documenting.
e.g. this:
{
"name": "datasette-upload-dbs",
"static": false,
"templates": true,
"version": "0.3.2",
"hooks": [
"menu_links",
"permission_allowed",
"register_permissions",
"register_routes",
"startup"
]
}
Could include this:
{
"permissions" ["upload-dbs"]
}
Maybe with more info than that too.
The tricky thing here is that plugin hooks in Pluggy don't by default tell you which plugin called them - and we need register_permissions() to track that.
Thanks to o4-mini-high https://chatgpt.com/share/680c5fa2-81ac-8006-9997-12de7fc14a7c I have a hint as to how to do that:
from llm.plugins import pm
caller = pm.hook.register_models
caller.get_hookimpls() # Initially empty
# Import CLI and register commands
from llm.cli import cli
pm.hook.register_commands(cli=cli)
# Check hook implementations after registration
caller.get_hookimpls() # Now populated
len(caller.get_hookimpls()) # 12
# List plugin names
[impl.plugin_name for impl in caller.get_hookimpls()]
# Examine plugin implementation details
impl = caller.get_hookimpls()[0]
dir(impl) # View available attributes
# Get plugin name and function pairs
[(impl.plugin_name, impl.function) for impl in caller.get_hookimpls()]
[
('github', <function register_models at 0x105b5cd30>),
('openai', <function register_models at 0x105d651b0>),
('anthropic', <function register_models at 0x1079701f0>),
('cerebras', <function register_models at 0x11010b880>),
('mistral', <function register_models at 0x11059e560>),
('mlx', <function register_models at 0x1107d9fc0>),
('ollama', <function register_models at 0x1107da830>),
('openrouter', <function register_models at 0x11094be20>),
('gemini', <function register_models at 0x11099cdc0>),
('logging_debug', <function register_models at 0x1109c2ef0>),
('echo', <function register_models at 0x1109c3130>),
('llm.default_plugins.openai_models', <function register_models at 0x11094b1c0>)
]
Hi @simonw Is this issue still worth to take? If it is then is it okay for me make a pr for this?