Skip to content

Commit

Permalink
Merged
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkbrnd committed Jan 24, 2025
2 parents 849fc6e + 30069ee commit 762dc43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions phi/tools/clickup_tool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import json
import re
from typing import Optional, List, Dict, Any, Union, Tuple
from typing import Optional, List, Dict, Any

from phi.tools import Toolkit
from phi.utils.log import logger
Expand Down Expand Up @@ -52,7 +52,9 @@ def __init__(
if list_lists:
self.register(self.list_lists)

def _make_request(self, method: str, endpoint: str, params: Dict = None, data: Dict = None) -> Dict[str, Any]:
def _make_request(
self, method: str, endpoint: str, params: Optional[Dict] = None, data: Optional[Dict] = None
) -> Dict[str, Any]:
"""Make a request to the ClickUp API."""
url = f"{self.base_url}/{endpoint}"
try:
Expand All @@ -63,13 +65,12 @@ def _make_request(self, method: str, endpoint: str, params: Dict = None, data: D
logger.error(f"Error making request to {url}: {e}")
return {"error": str(e)}

def _find_by_name(self, items: List[Dict[str, Any]], name: str, item_type: str) -> Union[Dict[str, Any], None]:
def _find_by_name(self, items: List[Dict[str, Any]], name: str) -> Optional[Dict[str, Any]]:
"""Find an item in a list by name using exact match or regex pattern.
Args:
items: List of items to search through
name: Name to search for
item_type: Type of item (for error message)
Returns:
Matching item or None if not found
Expand All @@ -87,7 +88,7 @@ def _find_by_name(self, items: List[Dict[str, Any]], name: str, item_type: str)
return item
return None

def _get_space(self, space_name: str = None) -> Dict[str, Any]:
def _get_space(self, space_name: str) -> Dict[str, Any]:
"""Get space information by name."""
spaces = self._make_request("GET", f"team/{self.master_space_id}/space")
if "error" in spaces:
Expand All @@ -97,12 +98,12 @@ def _get_space(self, space_name: str = None) -> Dict[str, Any]:
if not spaces_list:
return {"error": "No spaces found"}

space = self._find_by_name(spaces_list, space_name, "space")
space = self._find_by_name(spaces_list, space_name)
if not space:
return {"error": f"Space '{space_name}' not found"}
return space

def _get_list(self, space_id: str, list_name: str = None) -> Dict[str, Any]:
def _get_list(self, space_id: str, list_name: str) -> Dict[str, Any]:
"""Get list information by name."""
lists = self._make_request("GET", f"space/{space_id}/list")
if "error" in lists:
Expand All @@ -112,21 +113,18 @@ def _get_list(self, space_id: str, list_name: str = None) -> Dict[str, Any]:
if not lists_data:
return {"error": "No lists found in space"}

list_item = self._find_by_name(lists_data, list_name, "list")
list_item = self._find_by_name(lists_data, list_name)
if not list_item:
return {"error": f"List '{list_name}' not found"}
return list_item

def _get_tasks(self, list_id: str, task_name: str = None) -> List[Dict[str, Any]]:
def _get_tasks(self, list_id: str) -> List[Dict[str, Any]]:
"""Get tasks in a list, optionally filtered by name."""
tasks = self._make_request("GET", f"list/{list_id}/task")
if "error" in tasks:
return []

tasks_data = tasks.get("tasks", [])
if task_name:
task = self._find_by_name(tasks_data, task_name, "task")
return [task] if task else []
return tasks_data

def list_tasks(self, space_name: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion phi/tools/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_channel_history(self, channel: str, limit: int = 100) -> str:
"""
try:
response = self.client.conversations_history(channel=channel, limit=limit)
messages: List[Dict[str, Any]] = [
messages: List[Dict[str, Any]] = [ # type: ignore
{
"text": msg.get("text", ""),
"user": "webhook" if msg.get("subtype") == "bot_message" else msg.get("user", "unknown"),
Expand Down

0 comments on commit 762dc43

Please sign in to comment.