77from astrbot .core .agent .tool import ToolExecResult
88from astrbot .core .astr_agent_context import AstrAgentContext , AstrMessageEvent
99from astrbot .core .computer .computer_client import get_booter , get_local_booter
10+ from astrbot .core .computer .tools .permissions import check_admin_permission
1011from astrbot .core .message .message_event_result import MessageChain
1112
1213param_schema = {
2627}
2728
2829
29- def _check_admin_permission (context : ContextWrapper [AstrAgentContext ]) -> str | None :
30- cfg = context .context .context .get_config (
31- umo = context .context .event .unified_msg_origin
32- )
33- provider_settings = cfg .get ("provider_settings" , {})
34- require_admin = provider_settings .get ("computer_use_require_admin" , True )
35- if require_admin and context .context .event .role != "admin" :
36- return (
37- "error: Permission denied. Python execution is only allowed for admin users. "
38- "Tell user to set admins in `AstrBot WebUI -> Config -> General Config` by adding their user ID to the admins list if they need this feature."
39- f"User's ID is: { context .context .event .get_sender_id ()} . User's ID can be found by using /sid command."
40- )
41- return None
42-
43-
4430async def handle_result (result : dict , event : AstrMessageEvent ) -> ToolExecResult :
4531 data = result .get ("data" , {})
4632 output = data .get ("output" , {})
@@ -81,7 +67,7 @@ class PythonTool(FunctionTool):
8167 async def call (
8268 self , context : ContextWrapper [AstrAgentContext ], code : str , silent : bool = False
8369 ) -> ToolExecResult :
84- if permission_error := _check_admin_permission (context ):
70+ if permission_error := check_admin_permission (context , "Python execution" ):
8571 return permission_error
8672 sb = await get_booter (
8773 context .context .context ,
@@ -104,7 +90,7 @@ class LocalPythonTool(FunctionTool):
10490 async def call (
10591 self , context : ContextWrapper [AstrAgentContext ], code : str , silent : bool = False
10692 ) -> ToolExecResult :
107- if permission_error := _check_admin_permission (context ):
93+ if permission_error := check_admin_permission (context , "Python execution" ):
10894 return permission_error
10995 sb = get_local_booter ()
11096 try :
0 commit comments