apply ruff formatting

This commit is contained in:
Taylor Wilsdon
2025-12-13 13:49:28 -08:00
parent 1d80a24ca4
commit 6b8352a354
50 changed files with 4010 additions and 2842 deletions

View File

@@ -36,79 +36,136 @@ def create_comment_tools(app_name: str, file_id_param: str):
# Create functions without decorators first, then apply decorators with proper names
if file_id_param == "document_id":
@require_google_service("drive", "drive_read")
@handle_http_errors(read_func_name, service_type="drive")
async def read_comments(service, user_google_email: str, document_id: str) -> str:
async def read_comments(
service, user_google_email: str, document_id: str
) -> str:
"""Read all comments from a Google Document."""
return await _read_comments_impl(service, app_name, document_id)
@require_google_service("drive", "drive_file")
@handle_http_errors(create_func_name, service_type="drive")
async def create_comment(service, user_google_email: str, document_id: str, comment_content: str) -> str:
async def create_comment(
service, user_google_email: str, document_id: str, comment_content: str
) -> str:
"""Create a new comment on a Google Document."""
return await _create_comment_impl(service, app_name, document_id, comment_content)
return await _create_comment_impl(
service, app_name, document_id, comment_content
)
@require_google_service("drive", "drive_file")
@handle_http_errors(reply_func_name, service_type="drive")
async def reply_to_comment(service, user_google_email: str, document_id: str, comment_id: str, reply_content: str) -> str:
async def reply_to_comment(
service,
user_google_email: str,
document_id: str,
comment_id: str,
reply_content: str,
) -> str:
"""Reply to a specific comment in a Google Document."""
return await _reply_to_comment_impl(service, app_name, document_id, comment_id, reply_content)
return await _reply_to_comment_impl(
service, app_name, document_id, comment_id, reply_content
)
@require_google_service("drive", "drive_file")
@handle_http_errors(resolve_func_name, service_type="drive")
async def resolve_comment(service, user_google_email: str, document_id: str, comment_id: str) -> str:
async def resolve_comment(
service, user_google_email: str, document_id: str, comment_id: str
) -> str:
"""Resolve a comment in a Google Document."""
return await _resolve_comment_impl(service, app_name, document_id, comment_id)
return await _resolve_comment_impl(
service, app_name, document_id, comment_id
)
elif file_id_param == "spreadsheet_id":
@require_google_service("drive", "drive_read")
@handle_http_errors(read_func_name, service_type="drive")
async def read_comments(service, user_google_email: str, spreadsheet_id: str) -> str:
async def read_comments(
service, user_google_email: str, spreadsheet_id: str
) -> str:
"""Read all comments from a Google Spreadsheet."""
return await _read_comments_impl(service, app_name, spreadsheet_id)
@require_google_service("drive", "drive_file")
@handle_http_errors(create_func_name, service_type="drive")
async def create_comment(service, user_google_email: str, spreadsheet_id: str, comment_content: str) -> str:
async def create_comment(
service, user_google_email: str, spreadsheet_id: str, comment_content: str
) -> str:
"""Create a new comment on a Google Spreadsheet."""
return await _create_comment_impl(service, app_name, spreadsheet_id, comment_content)
return await _create_comment_impl(
service, app_name, spreadsheet_id, comment_content
)
@require_google_service("drive", "drive_file")
@handle_http_errors(reply_func_name, service_type="drive")
async def reply_to_comment(service, user_google_email: str, spreadsheet_id: str, comment_id: str, reply_content: str) -> str:
async def reply_to_comment(
service,
user_google_email: str,
spreadsheet_id: str,
comment_id: str,
reply_content: str,
) -> str:
"""Reply to a specific comment in a Google Spreadsheet."""
return await _reply_to_comment_impl(service, app_name, spreadsheet_id, comment_id, reply_content)
return await _reply_to_comment_impl(
service, app_name, spreadsheet_id, comment_id, reply_content
)
@require_google_service("drive", "drive_file")
@handle_http_errors(resolve_func_name, service_type="drive")
async def resolve_comment(service, user_google_email: str, spreadsheet_id: str, comment_id: str) -> str:
async def resolve_comment(
service, user_google_email: str, spreadsheet_id: str, comment_id: str
) -> str:
"""Resolve a comment in a Google Spreadsheet."""
return await _resolve_comment_impl(service, app_name, spreadsheet_id, comment_id)
return await _resolve_comment_impl(
service, app_name, spreadsheet_id, comment_id
)
elif file_id_param == "presentation_id":
@require_google_service("drive", "drive_read")
@handle_http_errors(read_func_name, service_type="drive")
async def read_comments(service, user_google_email: str, presentation_id: str) -> str:
async def read_comments(
service, user_google_email: str, presentation_id: str
) -> str:
"""Read all comments from a Google Presentation."""
return await _read_comments_impl(service, app_name, presentation_id)
@require_google_service("drive", "drive_file")
@handle_http_errors(create_func_name, service_type="drive")
async def create_comment(service, user_google_email: str, presentation_id: str, comment_content: str) -> str:
async def create_comment(
service, user_google_email: str, presentation_id: str, comment_content: str
) -> str:
"""Create a new comment on a Google Presentation."""
return await _create_comment_impl(service, app_name, presentation_id, comment_content)
return await _create_comment_impl(
service, app_name, presentation_id, comment_content
)
@require_google_service("drive", "drive_file")
@handle_http_errors(reply_func_name, service_type="drive")
async def reply_to_comment(service, user_google_email: str, presentation_id: str, comment_id: str, reply_content: str) -> str:
async def reply_to_comment(
service,
user_google_email: str,
presentation_id: str,
comment_id: str,
reply_content: str,
) -> str:
"""Reply to a specific comment in a Google Presentation."""
return await _reply_to_comment_impl(service, app_name, presentation_id, comment_id, reply_content)
return await _reply_to_comment_impl(
service, app_name, presentation_id, comment_id, reply_content
)
@require_google_service("drive", "drive_file")
@handle_http_errors(resolve_func_name, service_type="drive")
async def resolve_comment(service, user_google_email: str, presentation_id: str, comment_id: str) -> str:
async def resolve_comment(
service, user_google_email: str, presentation_id: str, comment_id: str
) -> str:
"""Resolve a comment in a Google Presentation."""
return await _resolve_comment_impl(service, app_name, presentation_id, comment_id)
return await _resolve_comment_impl(
service, app_name, presentation_id, comment_id
)
# Set the proper function names and register with server
read_comments.__name__ = read_func_name
@@ -123,10 +180,10 @@ def create_comment_tools(app_name: str, file_id_param: str):
server.tool()(resolve_comment)
return {
'read_comments': read_comments,
'create_comment': create_comment,
'reply_to_comment': reply_to_comment,
'resolve_comment': resolve_comment
"read_comments": read_comments,
"create_comment": create_comment,
"reply_to_comment": reply_to_comment,
"resolve_comment": resolve_comment,
}
@@ -135,13 +192,15 @@ async def _read_comments_impl(service, app_name: str, file_id: str) -> str:
logger.info(f"[read_{app_name}_comments] Reading comments for {app_name} {file_id}")
response = await asyncio.to_thread(
service.comments().list(
service.comments()
.list(
fileId=file_id,
fields="comments(id,content,author,createdTime,modifiedTime,resolved,replies(content,author,id,createdTime,modifiedTime))"
).execute
fields="comments(id,content,author,createdTime,modifiedTime,resolved,replies(content,author,id,createdTime,modifiedTime))",
)
.execute
)
comments = response.get('comments', [])
comments = response.get("comments", [])
if not comments:
return f"No comments found in {app_name} {file_id}"
@@ -149,11 +208,11 @@ async def _read_comments_impl(service, app_name: str, file_id: str) -> str:
output = [f"Found {len(comments)} comments in {app_name} {file_id}:\\n"]
for comment in comments:
author = comment.get('author', {}).get('displayName', 'Unknown')
content = comment.get('content', '')
created = comment.get('createdTime', '')
resolved = comment.get('resolved', False)
comment_id = comment.get('id', '')
author = comment.get("author", {}).get("displayName", "Unknown")
content = comment.get("content", "")
created = comment.get("createdTime", "")
resolved = comment.get("resolved", False)
comment_id = comment.get("id", "")
status = " [RESOLVED]" if resolved else ""
output.append(f"Comment ID: {comment_id}")
@@ -162,14 +221,14 @@ async def _read_comments_impl(service, app_name: str, file_id: str) -> str:
output.append(f"Content: {content}")
# Add replies if any
replies = comment.get('replies', [])
replies = comment.get("replies", [])
if replies:
output.append(f" Replies ({len(replies)}):")
for reply in replies:
reply_author = reply.get('author', {}).get('displayName', 'Unknown')
reply_content = reply.get('content', '')
reply_created = reply.get('createdTime', '')
reply_id = reply.get('id', '')
reply_author = reply.get("author", {}).get("displayName", "Unknown")
reply_content = reply.get("content", "")
reply_created = reply.get("createdTime", "")
reply_id = reply.get("id", "")
output.append(f" Reply ID: {reply_id}")
output.append(f" Author: {reply_author}")
output.append(f" Created: {reply_created}")
@@ -180,69 +239,82 @@ async def _read_comments_impl(service, app_name: str, file_id: str) -> str:
return "\\n".join(output)
async def _create_comment_impl(service, app_name: str, file_id: str, comment_content: str) -> str:
async def _create_comment_impl(
service, app_name: str, file_id: str, comment_content: str
) -> str:
"""Implementation for creating a comment on any Google Workspace file."""
logger.info(f"[create_{app_name}_comment] Creating comment in {app_name} {file_id}")
body = {"content": comment_content}
comment = await asyncio.to_thread(
service.comments().create(
service.comments()
.create(
fileId=file_id,
body=body,
fields="id,content,author,createdTime,modifiedTime"
).execute
fields="id,content,author,createdTime,modifiedTime",
)
.execute
)
comment_id = comment.get('id', '')
author = comment.get('author', {}).get('displayName', 'Unknown')
created = comment.get('createdTime', '')
comment_id = comment.get("id", "")
author = comment.get("author", {}).get("displayName", "Unknown")
created = comment.get("createdTime", "")
return f"Comment created successfully!\\nComment ID: {comment_id}\\nAuthor: {author}\\nCreated: {created}\\nContent: {comment_content}"
async def _reply_to_comment_impl(service, app_name: str, file_id: str, comment_id: str, reply_content: str) -> str:
async def _reply_to_comment_impl(
service, app_name: str, file_id: str, comment_id: str, reply_content: str
) -> str:
"""Implementation for replying to a comment on any Google Workspace file."""
logger.info(f"[reply_to_{app_name}_comment] Replying to comment {comment_id} in {app_name} {file_id}")
logger.info(
f"[reply_to_{app_name}_comment] Replying to comment {comment_id} in {app_name} {file_id}"
)
body = {'content': reply_content}
body = {"content": reply_content}
reply = await asyncio.to_thread(
service.replies().create(
service.replies()
.create(
fileId=file_id,
commentId=comment_id,
body=body,
fields="id,content,author,createdTime,modifiedTime"
).execute
fields="id,content,author,createdTime,modifiedTime",
)
.execute
)
reply_id = reply.get('id', '')
author = reply.get('author', {}).get('displayName', 'Unknown')
created = reply.get('createdTime', '')
reply_id = reply.get("id", "")
author = reply.get("author", {}).get("displayName", "Unknown")
created = reply.get("createdTime", "")
return f"Reply posted successfully!\\nReply ID: {reply_id}\\nAuthor: {author}\\nCreated: {created}\\nContent: {reply_content}"
async def _resolve_comment_impl(service, app_name: str, file_id: str, comment_id: str) -> str:
async def _resolve_comment_impl(
service, app_name: str, file_id: str, comment_id: str
) -> str:
"""Implementation for resolving a comment on any Google Workspace file."""
logger.info(f"[resolve_{app_name}_comment] Resolving comment {comment_id} in {app_name} {file_id}")
logger.info(
f"[resolve_{app_name}_comment] Resolving comment {comment_id} in {app_name} {file_id}"
)
body = {
"content": "This comment has been resolved.",
"action": "resolve"
}
body = {"content": "This comment has been resolved.", "action": "resolve"}
reply = await asyncio.to_thread(
service.replies().create(
service.replies()
.create(
fileId=file_id,
commentId=comment_id,
body=body,
fields="id,content,author,createdTime,modifiedTime"
).execute
fields="id,content,author,createdTime,modifiedTime",
)
.execute
)
reply_id = reply.get('id', '')
author = reply.get('author', {}).get('displayName', 'Unknown')
created = reply.get('createdTime', '')
reply_id = reply.get("id", "")
author = reply.get("author", {}).get("displayName", "Unknown")
created = reply.get("createdTime", "")
return f"Comment {comment_id} has been resolved successfully.\\nResolve reply ID: {reply_id}\\nAuthor: {author}\\nCreated: {created}"
return f"Comment {comment_id} has been resolved successfully.\\nResolve reply ID: {reply_id}\\nAuthor: {author}\\nCreated: {created}"