TOOL_NAME = "createsubfolders"
TOOL_DESCRIPTION = """Creates 'pdf' and 'image' subfolders inside a specified directory."""
TOOL_ARGS = '{"type":"object","properties":{"folder_path":{"type":"string","description":"Path to the parent folder where subfolders will be created."}},"required":["folder_path"]}'

from tools._std import tool_error, tool_ok

def run(args: dict) -> str:
    import os
    folder_path = args.get('folder_path')
    if not folder_path:
        return tool_error('folder_path not provided.')
    if not os.path.isdir(folder_path):
        return tool_error(
            f'The specified folder "{folder_path}" does not exist.',
            {'folder_path': folder_path},
        )
    subfolders = ['pdf', 'image']
    ensured = []
    for sub in subfolders:
        sub_path = os.path.join(folder_path, sub)
        try:
            os.makedirs(sub_path, exist_ok=True)
            ensured.append(sub)
        except Exception as e:
            return tool_error(
                f'Error creating subfolder "{sub}": {e}',
                {'folder_path': folder_path, 'subfolder': sub},
            )
    return tool_ok(
        {'folder_path': folder_path, 'subfolders': ensured},
        f'Successfully ensured subfolders {", ".join(ensured)} exist in "{folder_path}".',
    )
