a digital person for bluesky
1#!/usr/bin/env python3 2""" 3Delete all groups in the current project. 4""" 5 6import os 7import sys 8from dotenv import load_dotenv 9from letta_client import Letta 10from rich.console import Console 11from rich.prompt import Confirm 12 13# Add parent directory to path for imports 14sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 15from config_loader import get_config 16 17load_dotenv() 18 19def main(): 20 console = Console() 21 22 try: 23 # Initialize configuration and client 24 config = get_config() 25 26 client = Letta( 27 base_url=config.get('letta.base_url', os.environ.get('LETTA_BASE_URL')), 28 token=config.get('letta.api_key', os.environ.get('LETTA_API_KEY')), 29 timeout=config.get('letta.timeout', 30) 30 ) 31 32 project_id = config.get('letta.project_id', os.environ.get('LETTA_PROJECT_ID')) 33 34 # Get all groups 35 console.print("[blue]Finding all groups...[/blue]") 36 37 try: 38 if project_id: 39 groups = client.groups.list() 40 else: 41 groups = client.groups.list() 42 except: 43 # Try without project_id as fallback 44 try: 45 groups = client.groups.list() 46 except Exception as e: 47 console.print(f"[red]Error listing groups: {e}[/red]") 48 return 49 50 if not groups: 51 console.print("[yellow]No groups found.[/yellow]") 52 return 53 54 console.print(f"[yellow]Found {len(groups)} groups:[/yellow]") 55 for group in groups: 56 description = group.description[:50] + "..." if group.description and len(group.description) > 50 else (group.description or "No description") 57 console.print(f"{group.id[:12]}... - {description}") 58 59 # Confirm deletion 60 if not Confirm.ask(f"\n[bold red]Delete all {len(groups)} groups?[/bold red]"): 61 console.print("[yellow]Cancelled.[/yellow]") 62 return 63 64 # Delete each group 65 deleted_count = 0 66 for group in groups: 67 try: 68 client.groups.delete(group_id=group.id) 69 console.print(f"[green]✅ Deleted group: {group.id[:12]}[/green]") 70 deleted_count += 1 71 except Exception as e: 72 console.print(f"[red]❌ Failed to delete group {group.id[:12]}: {e}[/red]") 73 74 console.print(f"\n[green]Successfully deleted {deleted_count}/{len(groups)} groups.[/green]") 75 76 except Exception as e: 77 console.print(f"[red]Error: {e}[/red]") 78 sys.exit(1) 79 80if __name__ == "__main__": 81 main()