skills
This commit is contained in:
46
tools.py
46
tools.py
@@ -147,12 +147,58 @@ def cronos_query(arg: str) -> str:
|
||||
target_dir = os.path.join(MEMORY_ROOT, folder)
|
||||
return run_bash_command(f"grep -rniI '{query}' {target_dir} | head -n 20")
|
||||
|
||||
def list_gmail_emails(account: str) -> str:
|
||||
"""Lista os últimos 5 e-mails com Título e Remetente. Aceita apelidos: ma, mr, adm, 4r."""
|
||||
mapping = {
|
||||
"ma": "gws-mr", "mr": "gws-mr", "marcos": "gws-mr",
|
||||
"adm": "gws-adm", "empresa": "gws-adm",
|
||||
"4r": "gws-4r", "familia": "gws-4r", "fam": "gws-4r"
|
||||
}
|
||||
|
||||
clean_account = account.strip().lower().replace("gws-", "")
|
||||
account = mapping.get(clean_account, f"gws-{clean_account}" if not clean_account.startswith("gws") else clean_account)
|
||||
|
||||
# 1. Obtém a lista de IDs
|
||||
list_cmd = f"{account} gmail users messages list --params '{{\"userId\": \"me\", \"maxResults\": 5}}'"
|
||||
res = run_bash_command(list_cmd)
|
||||
|
||||
try:
|
||||
data = json.loads(res)
|
||||
messages = data.get("messages", [])
|
||||
if not messages:
|
||||
return "Nenhum e-mail encontrado."
|
||||
|
||||
result_text = "📧 **Últimos E-mails:**\n"
|
||||
for i, msg in enumerate(messages, 1):
|
||||
msg_id = msg["id"]
|
||||
# 2. Busca detalhes de cada e-mail (Metadata apenas para ser rápido)
|
||||
details_cmd = f"{account} gmail users messages get --params '{{\"userId\": \"me\", \"id\": \"{msg_id}\", \"format\": \"metadata\", \"metadataHeaders\": [\"Subject\", \"From\"]}}'"
|
||||
details_res = run_bash_command(details_cmd)
|
||||
|
||||
try:
|
||||
details = json.loads(details_res)
|
||||
headers = details.get("payload", {}).get("headers", [])
|
||||
subject = next((h["value"] for h in headers if h["name"] == "Subject"), "Sem Assunto")
|
||||
sender = next((h["value"] for h in headers if h["name"] == "From"), "Desconhecido")
|
||||
|
||||
result_text += f"{i}. **De:** {sender}\n **Assunto:** {subject}\n **ID:** `{msg_id}`\n\n"
|
||||
except:
|
||||
result_text += f"{i}. [Erro ao carregar detalhes do ID: {msg_id}]\n\n"
|
||||
|
||||
return result_text
|
||||
except Exception as e:
|
||||
return f"Erro ao listar e-mails: {str(e)}\nResposta bruta: {res[:200]}"
|
||||
|
||||
# Mapeamento para o Agente entender quais tools ele possui (será usado no loop ReAct)
|
||||
AVAILABLE_TOOLS = {
|
||||
"run_bash_command": {
|
||||
"description": "Executa comandos Linux na VPS. Use para docker, git, mkdir, touch, etc.",
|
||||
"func": run_bash_command
|
||||
},
|
||||
"list_gmail_emails": {
|
||||
"description": "Lista os 5 e-mails mais recentes de uma conta (gws-mr, gws-adm, gws-4r) com título e remetente.",
|
||||
"func": list_gmail_emails
|
||||
},
|
||||
"get_system_health": {
|
||||
"description": "Verifica RAM, CPU e Disco globais da VPS.",
|
||||
"func": get_system_health
|
||||
|
||||
Reference in New Issue
Block a user