124 lines
4.3 KiB
Python
124 lines
4.3 KiB
Python
"""Tool registry and definitions."""
|
|
from dataclasses import dataclass
|
|
from typing import Callable, Any, Dict
|
|
from functools import partial
|
|
|
|
from infrastructure.persistence.memory import Memory
|
|
from .tools.filesystem import set_path_for_folder, list_folder
|
|
from .tools.api import find_media_imdb_id, find_torrent, add_torrent_to_qbittorrent
|
|
|
|
|
|
@dataclass
|
|
class Tool:
|
|
"""Represents a tool that can be used by the agent."""
|
|
name: str
|
|
description: str
|
|
func: Callable[..., Dict[str, Any]]
|
|
parameters: Dict[str, Any] # JSON Schema des paramètres
|
|
|
|
|
|
def make_tools(memory: Memory) -> Dict[str, Tool]:
|
|
"""
|
|
Create all available tools with memory bound to them.
|
|
|
|
Args:
|
|
memory: Memory instance to be used by the tools
|
|
|
|
Returns:
|
|
Dictionary mapping tool names to Tool instances
|
|
"""
|
|
# Create partial functions with memory pre-bound for filesystem tools
|
|
set_path_func = partial(set_path_for_folder, memory)
|
|
list_folder_func = partial(list_folder, memory)
|
|
|
|
tools = [
|
|
Tool(
|
|
name="set_path_for_folder",
|
|
description="Sets a path in the configuration (download_folder, tvshow_folder, movie_folder, or torrent_folder).",
|
|
func=set_path_func,
|
|
parameters={
|
|
"type": "object",
|
|
"properties": {
|
|
"folder_name": {
|
|
"type": "string",
|
|
"description": "Name of folder to set",
|
|
"enum": ["download", "tvshow", "movie", "torrent"]
|
|
},
|
|
"path_value": {
|
|
"type": "string",
|
|
"description": "Absolute path to the folder (e.g., /home/user/downloads)"
|
|
}
|
|
},
|
|
"required": ["folder_name", "path_value"]
|
|
}
|
|
),
|
|
Tool(
|
|
name="list_folder",
|
|
description="Lists the contents of a specified folder (download, tvshow, movie, or torrent).",
|
|
func=list_folder_func,
|
|
parameters={
|
|
"type": "object",
|
|
"properties": {
|
|
"folder_type": {
|
|
"type": "string",
|
|
"description": "Type of folder to list: 'download', 'tvshow', 'movie', or 'torrent'",
|
|
"enum": ["download", "tvshow", "movie", "torrent"]
|
|
},
|
|
"path": {
|
|
"type": "string",
|
|
"description": "Relative path within the folder (default: '.' for root)",
|
|
"default": "."
|
|
}
|
|
},
|
|
"required": ["folder_type"]
|
|
}
|
|
),
|
|
Tool(
|
|
name="find_media_imdb_id",
|
|
description="Finds the IMDb ID for a given media title using TMDB API.",
|
|
func=find_media_imdb_id,
|
|
parameters={
|
|
"type": "object",
|
|
"properties": {
|
|
"media_title": {
|
|
"type": "string",
|
|
"description": "Title of the media to find the IMDb ID for"
|
|
},
|
|
},
|
|
"required": ["media_title"]
|
|
}
|
|
),
|
|
Tool(
|
|
name="find_torrents",
|
|
description="Finds torrents for a given media title using Knaben API.",
|
|
func=find_torrent,
|
|
parameters={
|
|
"type": "object",
|
|
"properties": {
|
|
"media_title": {
|
|
"type": "string",
|
|
"description": "Title of the media to find torrents for"
|
|
},
|
|
},
|
|
"required": ["media_title"]
|
|
}
|
|
),
|
|
Tool(
|
|
name="add_torrent_to_qbittorrent",
|
|
description="Adds a torrent to qBittorrent client.",
|
|
func=add_torrent_to_qbittorrent,
|
|
parameters={
|
|
"type": "object",
|
|
"properties": {
|
|
"magnet_link": {
|
|
"type": "string",
|
|
"description": "Title of the media to find torrents for"
|
|
},
|
|
},
|
|
"required": ["magnet_link"]
|
|
}
|
|
),
|
|
]
|
|
|
|
return {t.name: t for t in tools}
|