refac
This commit is contained in:
@@ -492,7 +492,7 @@ async def manage_deployment(
|
|||||||
"""
|
"""
|
||||||
action = action.lower().strip()
|
action = action.lower().strip()
|
||||||
if action == "create":
|
if action == "create":
|
||||||
if not description:
|
if description is None or description.strip() == "":
|
||||||
raise ValueError("description is required for create action")
|
raise ValueError("description is required for create action")
|
||||||
return await _create_deployment_impl(
|
return await _create_deployment_impl(
|
||||||
service, user_google_email, script_id, description, version_description
|
service, user_google_email, script_id, description, version_description
|
||||||
@@ -500,7 +500,7 @@ async def manage_deployment(
|
|||||||
elif action == "update":
|
elif action == "update":
|
||||||
if not deployment_id:
|
if not deployment_id:
|
||||||
raise ValueError("deployment_id is required for update action")
|
raise ValueError("deployment_id is required for update action")
|
||||||
if description is None or description == "":
|
if description is None or description.strip() == "":
|
||||||
raise ValueError("description is required for update action")
|
raise ValueError("description is required for update action")
|
||||||
return await _update_deployment_impl(
|
return await _update_deployment_impl(
|
||||||
service, user_google_email, script_id, deployment_id, description
|
service, user_google_email, script_id, deployment_id, description
|
||||||
|
|||||||
@@ -249,7 +249,6 @@ async def list_contacts(
|
|||||||
"""
|
"""
|
||||||
logger.info(f"[list_contacts] Invoked. Email: '{user_google_email}'")
|
logger.info(f"[list_contacts] Invoked. Email: '{user_google_email}'")
|
||||||
|
|
||||||
try:
|
|
||||||
params: Dict[str, Any] = {
|
params: Dict[str, Any] = {
|
||||||
"resourceName": "people/me",
|
"resourceName": "people/me",
|
||||||
"personFields": DEFAULT_PERSON_FIELDS,
|
"personFields": DEFAULT_PERSON_FIELDS,
|
||||||
@@ -272,7 +271,9 @@ async def list_contacts(
|
|||||||
if not connections:
|
if not connections:
|
||||||
return f"No contacts found for {user_google_email}."
|
return f"No contacts found for {user_google_email}."
|
||||||
|
|
||||||
response = f"Contacts for {user_google_email} ({len(connections)} of {total_people}):\n\n"
|
response = (
|
||||||
|
f"Contacts for {user_google_email} ({len(connections)} of {total_people}):\n\n"
|
||||||
|
)
|
||||||
|
|
||||||
for person in connections:
|
for person in connections:
|
||||||
response += _format_contact(person) + "\n\n"
|
response += _format_contact(person) + "\n\n"
|
||||||
@@ -283,15 +284,6 @@ async def list_contacts(
|
|||||||
logger.info(f"Found {len(connections)} contacts for {user_google_email}")
|
logger.info(f"Found {len(connections)} contacts for {user_google_email}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Contacts'."
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool()
|
@server.tool()
|
||||||
@require_google_service("people", "contacts_read")
|
@require_google_service("people", "contacts_read")
|
||||||
@@ -321,7 +313,6 @@ async def get_contact(
|
|||||||
f"[get_contact] Invoked. Email: '{user_google_email}', Contact: {resource_name}"
|
f"[get_contact] Invoked. Email: '{user_google_email}', Contact: {resource_name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
person = await asyncio.to_thread(
|
person = await asyncio.to_thread(
|
||||||
service.people()
|
service.people()
|
||||||
.get(resourceName=resource_name, personFields=DETAILED_PERSON_FIELDS)
|
.get(resourceName=resource_name, personFields=DETAILED_PERSON_FIELDS)
|
||||||
@@ -334,19 +325,6 @@ async def get_contact(
|
|||||||
logger.info(f"Retrieved contact {resource_name} for {user_google_email}")
|
logger.info(f"Retrieved contact {resource_name} for {user_google_email}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
if error.resp.status == 404:
|
|
||||||
message = f"Contact not found: {contact_id}"
|
|
||||||
logger.warning(message)
|
|
||||||
raise Exception(message)
|
|
||||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Contacts'."
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool()
|
@server.tool()
|
||||||
@require_google_service("people", "contacts_read")
|
@require_google_service("people", "contacts_read")
|
||||||
@@ -372,7 +350,6 @@ async def search_contacts(
|
|||||||
f"[search_contacts] Invoked. Email: '{user_google_email}', Query: '{query}'"
|
f"[search_contacts] Invoked. Email: '{user_google_email}', Query: '{query}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
# Warm up the search cache if needed
|
# Warm up the search cache if needed
|
||||||
await _warmup_search_cache(service, user_google_email)
|
await _warmup_search_cache(service, user_google_email)
|
||||||
|
|
||||||
@@ -402,15 +379,6 @@ async def search_contacts(
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Contacts'."
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool()
|
@server.tool()
|
||||||
@require_google_service("people", "contacts")
|
@require_google_service("people", "contacts")
|
||||||
@@ -457,7 +425,6 @@ async def manage_contact(
|
|||||||
f"[manage_contact] Invoked. Action: '{action}', Email: '{user_google_email}'"
|
f"[manage_contact] Invoked. Action: '{action}', Email: '{user_google_email}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
if action == "create":
|
if action == "create":
|
||||||
body = _build_person_body(
|
body = _build_person_body(
|
||||||
given_name=given_name,
|
given_name=given_name,
|
||||||
@@ -566,21 +533,6 @@ async def manage_contact(
|
|||||||
logger.info(f"Deleted contact {resource_name} for {user_google_email}")
|
logger.info(f"Deleted contact {resource_name} for {user_google_email}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except UserInputError:
|
|
||||||
raise
|
|
||||||
except HttpError as error:
|
|
||||||
if error.resp.status == 404:
|
|
||||||
message = f"Contact not found: {contact_id}"
|
|
||||||
logger.warning(message)
|
|
||||||
raise Exception(message)
|
|
||||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Contacts'."
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Extended Tier Tools
|
# Extended Tier Tools
|
||||||
@@ -609,7 +561,6 @@ async def list_contact_groups(
|
|||||||
"""
|
"""
|
||||||
logger.info(f"[list_contact_groups] Invoked. Email: '{user_google_email}'")
|
logger.info(f"[list_contact_groups] Invoked. Email: '{user_google_email}'")
|
||||||
|
|
||||||
try:
|
|
||||||
params: Dict[str, Any] = {
|
params: Dict[str, Any] = {
|
||||||
"pageSize": min(page_size, 1000),
|
"pageSize": min(page_size, 1000),
|
||||||
"groupFields": CONTACT_GROUP_FIELDS,
|
"groupFields": CONTACT_GROUP_FIELDS,
|
||||||
@@ -646,15 +597,6 @@ async def list_contact_groups(
|
|||||||
logger.info(f"Found {len(groups)} contact groups for {user_google_email}")
|
logger.info(f"Found {len(groups)} contact groups for {user_google_email}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Contacts'."
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool()
|
@server.tool()
|
||||||
@require_google_service("people", "contacts_read")
|
@require_google_service("people", "contacts_read")
|
||||||
@@ -686,7 +628,6 @@ async def get_contact_group(
|
|||||||
f"[get_contact_group] Invoked. Email: '{user_google_email}', Group: {resource_name}"
|
f"[get_contact_group] Invoked. Email: '{user_google_email}', Group: {resource_name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
result = await asyncio.to_thread(
|
result = await asyncio.to_thread(
|
||||||
service.contactGroups()
|
service.contactGroups()
|
||||||
.get(
|
.get(
|
||||||
@@ -717,19 +658,6 @@ async def get_contact_group(
|
|||||||
logger.info(f"Retrieved contact group {resource_name} for {user_google_email}")
|
logger.info(f"Retrieved contact group {resource_name} for {user_google_email}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
if error.resp.status == 404:
|
|
||||||
message = f"Contact group not found: {group_id}"
|
|
||||||
logger.warning(message)
|
|
||||||
raise Exception(message)
|
|
||||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Contacts'."
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Complete Tier Tools
|
# Complete Tier Tools
|
||||||
@@ -774,12 +702,9 @@ async def manage_contacts_batch(
|
|||||||
f"[manage_contacts_batch] Invoked. Action: '{action}', Email: '{user_google_email}'"
|
f"[manage_contacts_batch] Invoked. Action: '{action}', Email: '{user_google_email}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
if action == "create":
|
if action == "create":
|
||||||
if not contacts:
|
if not contacts:
|
||||||
raise UserInputError(
|
raise UserInputError("contacts parameter is required for 'create' action.")
|
||||||
"contacts parameter is required for 'create' action."
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(contacts) > 200:
|
if len(contacts) > 200:
|
||||||
raise UserInputError("Maximum 200 contacts can be created in a batch.")
|
raise UserInputError("Maximum 200 contacts can be created in a batch.")
|
||||||
@@ -825,9 +750,7 @@ async def manage_contacts_batch(
|
|||||||
|
|
||||||
if action == "update":
|
if action == "update":
|
||||||
if not updates:
|
if not updates:
|
||||||
raise UserInputError(
|
raise UserInputError("updates parameter is required for 'update' action.")
|
||||||
"updates parameter is required for 'update' action."
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(updates) > 200:
|
if len(updates) > 200:
|
||||||
raise UserInputError("Maximum 200 contacts can be updated in a batch.")
|
raise UserInputError("Maximum 200 contacts can be updated in a batch.")
|
||||||
@@ -924,9 +847,7 @@ async def manage_contacts_batch(
|
|||||||
|
|
||||||
# action == "delete"
|
# action == "delete"
|
||||||
if not contact_ids:
|
if not contact_ids:
|
||||||
raise UserInputError(
|
raise UserInputError("contact_ids parameter is required for 'delete' action.")
|
||||||
"contact_ids parameter is required for 'delete' action."
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(contact_ids) > 500:
|
if len(contact_ids) > 500:
|
||||||
raise UserInputError("Maximum 500 contacts can be deleted in a batch.")
|
raise UserInputError("Maximum 500 contacts can be deleted in a batch.")
|
||||||
@@ -945,22 +866,9 @@ async def manage_contacts_batch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
response = f"Batch deleted {len(contact_ids)} contacts for {user_google_email}."
|
response = f"Batch deleted {len(contact_ids)} contacts for {user_google_email}."
|
||||||
logger.info(
|
logger.info(f"Batch deleted {len(contact_ids)} contacts for {user_google_email}")
|
||||||
f"Batch deleted {len(contact_ids)} contacts for {user_google_email}"
|
|
||||||
)
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except UserInputError:
|
|
||||||
raise
|
|
||||||
except HttpError as error:
|
|
||||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Contacts'."
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool()
|
@server.tool()
|
||||||
@require_google_service("people", "contacts")
|
@require_google_service("people", "contacts")
|
||||||
@@ -1004,7 +912,6 @@ async def manage_contact_group(
|
|||||||
f"[manage_contact_group] Invoked. Action: '{action}', Email: '{user_google_email}'"
|
f"[manage_contact_group] Invoked. Action: '{action}', Email: '{user_google_email}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
if action == "create":
|
if action == "create":
|
||||||
if not name:
|
if not name:
|
||||||
raise UserInputError("name is required for 'create' action.")
|
raise UserInputError("name is required for 'create' action.")
|
||||||
@@ -1055,9 +962,7 @@ async def manage_contact_group(
|
|||||||
response += f"Name: {updated_name}\n"
|
response += f"Name: {updated_name}\n"
|
||||||
response += f"ID: {group_id}\n"
|
response += f"ID: {group_id}\n"
|
||||||
|
|
||||||
logger.info(
|
logger.info(f"Updated contact group {resource_name} for {user_google_email}")
|
||||||
f"Updated contact group {resource_name} for {user_google_email}"
|
|
||||||
)
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
if action == "delete":
|
if action == "delete":
|
||||||
@@ -1067,17 +972,13 @@ async def manage_contact_group(
|
|||||||
.execute
|
.execute
|
||||||
)
|
)
|
||||||
|
|
||||||
response = (
|
response = f"Contact group {group_id} has been deleted for {user_google_email}."
|
||||||
f"Contact group {group_id} has been deleted for {user_google_email}."
|
|
||||||
)
|
|
||||||
if delete_contacts:
|
if delete_contacts:
|
||||||
response += " Contacts in the group were also deleted."
|
response += " Contacts in the group were also deleted."
|
||||||
else:
|
else:
|
||||||
response += " Contacts in the group were preserved."
|
response += " Contacts in the group were preserved."
|
||||||
|
|
||||||
logger.info(
|
logger.info(f"Deleted contact group {resource_name} for {user_google_email}")
|
||||||
f"Deleted contact group {resource_name} for {user_google_email}"
|
|
||||||
)
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# action == "modify_members"
|
# action == "modify_members"
|
||||||
@@ -1133,18 +1034,3 @@ async def manage_contact_group(
|
|||||||
f"Modified contact group members for {resource_name} for {user_google_email}"
|
f"Modified contact group members for {resource_name} for {user_google_email}"
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except UserInputError:
|
|
||||||
raise
|
|
||||||
except HttpError as error:
|
|
||||||
if error.resp.status == 404:
|
|
||||||
message = f"Contact group not found: {group_id}"
|
|
||||||
logger.warning(message)
|
|
||||||
raise Exception(message)
|
|
||||||
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Contacts'."
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|||||||
@@ -204,7 +204,6 @@ async def _create_task_list_impl(
|
|||||||
f"[create_task_list] Invoked. Email: '{user_google_email}', Title: '{title}'"
|
f"[create_task_list] Invoked. Email: '{user_google_email}', Title: '{title}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
body = {"title": title}
|
body = {"title": title}
|
||||||
|
|
||||||
result = await asyncio.to_thread(service.tasklists().insert(body=body).execute)
|
result = await asyncio.to_thread(service.tasklists().insert(body=body).execute)
|
||||||
@@ -220,15 +219,6 @@ async def _create_task_list_impl(
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = _format_reauth_message(error, user_google_email)
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
async def _update_task_list_impl(
|
async def _update_task_list_impl(
|
||||||
service: Resource, user_google_email: str, task_list_id: str, title: str
|
service: Resource, user_google_email: str, task_list_id: str, title: str
|
||||||
@@ -238,7 +228,6 @@ async def _update_task_list_impl(
|
|||||||
f"[update_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, New Title: '{title}'"
|
f"[update_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, New Title: '{title}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
body = {"id": task_list_id, "title": title}
|
body = {"id": task_list_id, "title": title}
|
||||||
|
|
||||||
result = await asyncio.to_thread(
|
result = await asyncio.to_thread(
|
||||||
@@ -255,15 +244,6 @@ async def _update_task_list_impl(
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = _format_reauth_message(error, user_google_email)
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
async def _delete_task_list_impl(
|
async def _delete_task_list_impl(
|
||||||
service: Resource, user_google_email: str, task_list_id: str
|
service: Resource, user_google_email: str, task_list_id: str
|
||||||
@@ -273,25 +253,13 @@ async def _delete_task_list_impl(
|
|||||||
f"[delete_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}"
|
f"[delete_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
await asyncio.to_thread(service.tasklists().delete(tasklist=task_list_id).execute)
|
||||||
await asyncio.to_thread(
|
|
||||||
service.tasklists().delete(tasklist=task_list_id).execute
|
|
||||||
)
|
|
||||||
|
|
||||||
response = f"Task list {task_list_id} has been deleted for {user_google_email}. All tasks in this list have also been deleted."
|
response = f"Task list {task_list_id} has been deleted for {user_google_email}. All tasks in this list have also been deleted."
|
||||||
|
|
||||||
logger.info(f"Deleted task list {task_list_id} for {user_google_email}")
|
logger.info(f"Deleted task list {task_list_id} for {user_google_email}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = _format_reauth_message(error, user_google_email)
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
async def _clear_completed_tasks_impl(
|
async def _clear_completed_tasks_impl(
|
||||||
service: Resource, user_google_email: str, task_list_id: str
|
service: Resource, user_google_email: str, task_list_id: str
|
||||||
@@ -301,7 +269,6 @@ async def _clear_completed_tasks_impl(
|
|||||||
f"[clear_completed_tasks] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}"
|
f"[clear_completed_tasks] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
await asyncio.to_thread(service.tasks().clear(tasklist=task_list_id).execute)
|
await asyncio.to_thread(service.tasks().clear(tasklist=task_list_id).execute)
|
||||||
|
|
||||||
response = f"All completed tasks have been cleared from task list {task_list_id} for {user_google_email}. The tasks are now hidden and won't appear in default task list views."
|
response = f"All completed tasks have been cleared from task list {task_list_id} for {user_google_email}. The tasks are now hidden and won't appear in default task list views."
|
||||||
@@ -311,15 +278,6 @@ async def _clear_completed_tasks_impl(
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = _format_reauth_message(error, user_google_email)
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
# --- Consolidated manage_task_list tool ---
|
# --- Consolidated manage_task_list tool ---
|
||||||
|
|
||||||
@@ -710,7 +668,6 @@ async def _create_task_impl(
|
|||||||
f"[create_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Title: '{title}'"
|
f"[create_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Title: '{title}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
body = {"title": title}
|
body = {"title": title}
|
||||||
if notes:
|
if notes:
|
||||||
body["notes"] = notes
|
body["notes"] = notes
|
||||||
@@ -743,15 +700,6 @@ async def _create_task_impl(
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = _format_reauth_message(error, user_google_email)
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
async def _update_task_impl(
|
async def _update_task_impl(
|
||||||
service: Resource,
|
service: Resource,
|
||||||
@@ -768,7 +716,6 @@ async def _update_task_impl(
|
|||||||
f"[update_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
|
f"[update_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
# First get the current task to build the update body
|
# First get the current task to build the update body
|
||||||
current_task = await asyncio.to_thread(
|
current_task = await asyncio.to_thread(
|
||||||
service.tasks().get(tasklist=task_list_id, task=task_id).execute
|
service.tasks().get(tasklist=task_list_id, task=task_id).execute
|
||||||
@@ -793,9 +740,7 @@ async def _update_task_impl(
|
|||||||
body["due"] = current_task["due"]
|
body["due"] = current_task["due"]
|
||||||
|
|
||||||
result = await asyncio.to_thread(
|
result = await asyncio.to_thread(
|
||||||
service.tasks()
|
service.tasks().update(tasklist=task_list_id, task=task_id, body=body).execute
|
||||||
.update(tasklist=task_list_id, task=task_id, body=body)
|
|
||||||
.execute
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response = f"""Task Updated for {user_google_email}:
|
response = f"""Task Updated for {user_google_email}:
|
||||||
@@ -814,15 +759,6 @@ async def _update_task_impl(
|
|||||||
logger.info(f"Updated task {task_id} for {user_google_email}")
|
logger.info(f"Updated task {task_id} for {user_google_email}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = _format_reauth_message(error, user_google_email)
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
async def _delete_task_impl(
|
async def _delete_task_impl(
|
||||||
service: Resource, user_google_email: str, task_list_id: str, task_id: str
|
service: Resource, user_google_email: str, task_list_id: str, task_id: str
|
||||||
@@ -832,7 +768,6 @@ async def _delete_task_impl(
|
|||||||
f"[delete_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
|
f"[delete_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
await asyncio.to_thread(
|
await asyncio.to_thread(
|
||||||
service.tasks().delete(tasklist=task_list_id, task=task_id).execute
|
service.tasks().delete(tasklist=task_list_id, task=task_id).execute
|
||||||
)
|
)
|
||||||
@@ -842,15 +777,6 @@ async def _delete_task_impl(
|
|||||||
logger.info(f"Deleted task {task_id} for {user_google_email}")
|
logger.info(f"Deleted task {task_id} for {user_google_email}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = _format_reauth_message(error, user_google_email)
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
async def _move_task_impl(
|
async def _move_task_impl(
|
||||||
service: Resource,
|
service: Resource,
|
||||||
@@ -866,7 +792,6 @@ async def _move_task_impl(
|
|||||||
f"[move_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
|
f"[move_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
params = {"tasklist": task_list_id, "task": task_id}
|
params = {"tasklist": task_list_id, "task": task_id}
|
||||||
if parent:
|
if parent:
|
||||||
params["parent"] = parent
|
params["parent"] = parent
|
||||||
@@ -902,15 +827,6 @@ async def _move_task_impl(
|
|||||||
logger.info(f"Moved task {task_id} for {user_google_email}")
|
logger.info(f"Moved task {task_id} for {user_google_email}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except HttpError as error:
|
|
||||||
message = _format_reauth_message(error, user_google_email)
|
|
||||||
logger.error(message, exc_info=True)
|
|
||||||
raise Exception(message)
|
|
||||||
except Exception as e:
|
|
||||||
message = f"Unexpected error: {e}."
|
|
||||||
logger.exception(message)
|
|
||||||
raise Exception(message)
|
|
||||||
|
|
||||||
|
|
||||||
# --- Consolidated manage_task tool ---
|
# --- Consolidated manage_task tool ---
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user