fix: two-step DynamoDB update for google_accounts; live SM lookup in list_google_accounts
This commit is contained in:
@@ -110,6 +110,28 @@ def connect_google_account(label: str = 'primary') -> str:
|
||||
@tool
|
||||
def list_google_accounts() -> str:
|
||||
"""List all connected Google accounts and their labels."""
|
||||
actor_id = _current_actor_id
|
||||
if actor_id:
|
||||
try:
|
||||
safe_actor_id = actor_id.replace(':', '-')
|
||||
prefix = f'agent-claw/google-credentials/{safe_actor_id}/'
|
||||
sm = boto3.client('secretsmanager', region_name='us-east-1')
|
||||
paginator = sm.get_paginator('list_secrets')
|
||||
accounts = {}
|
||||
for page in paginator.paginate(Filters=[{'Key': 'name', 'Values': [prefix]}]):
|
||||
for s in page['SecretList']:
|
||||
label = s['Name'][len(prefix):]
|
||||
try:
|
||||
import json as _json
|
||||
val = _json.loads(sm.get_secret_value(SecretId=s['Name'])['SecretString'])
|
||||
accounts[label] = val.get('email', s['Name'])
|
||||
except Exception:
|
||||
accounts[label] = s['Name']
|
||||
if accounts:
|
||||
parts = [f'{label} ({email})' for label, email in accounts.items()]
|
||||
return 'Connected Google accounts: ' + ', '.join(parts)
|
||||
except Exception as e:
|
||||
print(f'[list_google_accounts] SM lookup failed, falling back: {e}')
|
||||
accounts = _gws._current_google_accounts
|
||||
if not accounts:
|
||||
return 'No Google accounts connected. Use connect_google_account to add one.'
|
||||
|
||||
Reference in New Issue
Block a user