Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions astrbot/core/computer/tools/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@

from ..computer_client import get_booter


def _check_admin_permission(context: ContextWrapper[AstrAgentContext]) -> str | None:
cfg = context.context.context.get_config(
umo=context.context.event.unified_msg_origin
)
provider_settings = cfg.get("provider_settings", {})
require_admin = provider_settings.get("computer_use_require_admin", True)
if require_admin and context.context.event.role != "admin":
return (
"error: Permission denied. File upload/download is only allowed for admin users. "
"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."
f"User's ID is: {context.context.event.get_sender_id()}. User's ID can be found by using /sid command."
)
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
return None
Comment thread
Soulter marked this conversation as resolved.
Outdated


# @dataclass
# class CreateFileTool(FunctionTool):
# name: str = "astrbot_create_file"
Expand Down Expand Up @@ -102,6 +118,8 @@ async def call(
context: ContextWrapper[AstrAgentContext],
local_path: str,
) -> str | None:
if permission_error := _check_admin_permission(context):
return permission_error
Comment thread
Soulter marked this conversation as resolved.
Outdated
sb = await get_booter(
context.context.context,
context.context.event.unified_msg_origin,
Expand Down Expand Up @@ -161,6 +179,8 @@ async def call(
remote_path: str,
also_send_to_user: bool = True,
) -> ToolExecResult:
if permission_error := _check_admin_permission(context):
return permission_error
sb = await get_booter(
context.context.context,
context.context.event.unified_msg_origin,
Expand Down