Add remove_google_account tool
This commit is contained in:
@@ -139,6 +139,45 @@ def list_google_accounts() -> str:
|
||||
return 'Connected Google accounts: ' + ', '.join(parts)
|
||||
|
||||
|
||||
@tool
|
||||
def remove_google_account(label: str) -> str:
|
||||
"""Remove a connected Google account by label (e.g. 'work', 'personal')."""
|
||||
actor_id = _current_actor_id
|
||||
if not actor_id:
|
||||
return 'Cannot determine actor_id.'
|
||||
|
||||
safe_actor_id = actor_id.replace(':', '-')
|
||||
ddb = boto3.resource('dynamodb', region_name='us-east-1')
|
||||
table = ddb.Table(USERS_TABLE_NAME)
|
||||
|
||||
resp = table.get_item(Key={'actor_id': actor_id})
|
||||
accounts = resp.get('Item', {}).get('google_accounts', {})
|
||||
|
||||
if label not in accounts:
|
||||
return f'No Google account with label "{label}" found.'
|
||||
if len(accounts) <= 1:
|
||||
return 'Cannot remove the last Google account. At least one must remain.'
|
||||
|
||||
email = accounts.get(label, label)
|
||||
|
||||
sm = boto3.client('secretsmanager', region_name='us-east-1')
|
||||
try:
|
||||
sm.delete_secret(
|
||||
SecretId=f'agent-claw/google-credentials/{safe_actor_id}/{label}',
|
||||
ForceDeleteWithoutRecovery=True,
|
||||
)
|
||||
except Exception:
|
||||
pass # secret may already be gone
|
||||
|
||||
table.update_item(
|
||||
Key={'actor_id': actor_id},
|
||||
UpdateExpression='REMOVE google_accounts.#label',
|
||||
ExpressionAttributeNames={'#label': label},
|
||||
)
|
||||
|
||||
return f'Disconnected {label} ({email}) from your Google accounts.'
|
||||
|
||||
|
||||
@tool
|
||||
def manage_service(action: str, service: str, config: dict | None = None) -> str:
|
||||
"""Enroll, update, remove, or list external services for your account.
|
||||
@@ -316,7 +355,7 @@ async def main(payload: dict, context):
|
||||
)
|
||||
|
||||
base_tools = [web_search, web_fetch, read_workspace_file, write_workspace_file,
|
||||
home_assistant, connect_google_account, list_google_accounts,
|
||||
home_assistant, connect_google_account, list_google_accounts, remove_google_account,
|
||||
manage_service, schedule_reminder, list_reminders, cancel_reminder,
|
||||
list_calendars, get_calendar_events, list_gmail_messages, get_gmail_message]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user