🚀 Auto-deploy: BotVPS atualizado em 02/05/2026 15:37:40

This commit is contained in:
2026-05-02 15:37:40 +00:00
parent 1c1fac3735
commit 912763b3f1
613 changed files with 169969 additions and 60 deletions

48
main.py
View File

@@ -113,8 +113,13 @@ async def run_action(data: dict, is_auth: bool = Depends(verify_password)):
# Reinicia os serviços relevantes via PM2
os.system("pm2 restart bridge-telegram")
return {"status": "success", "message": "Bot do Telegram reiniciado."}
if action_type == "clear_cache":
# Limpa caches de sistema e temporários
os.system("rm -rf /tmp/vps_bot_cache/*")
os.system("sync; echo 3 > /proc/sys/vm/drop_caches") # Limpa cache de RAM (requer sudo/root)
return {"status": "success", "message": "Cache do servidor limpo com sucesso."}
if action_type == "reboot_vps":
return {"status": "error", "message": "Reboot bloqueado via Web por segurança."}
return {"status": "error", "message": "⚠️ Reboot via Web desabilitado por segurança. Use o terminal SSH."}
return {"status": "error", "message": f"Ação {action_type} desconhecida."}
@app.get("/api/test_llm")
@@ -179,18 +184,35 @@ async def get_audio_file(filename: str):
@app.post("/api/orchestrate")
async def orchestrate_task(task_data: dict, is_auth: bool = Depends(verify_password)):
from session_manager import set_orchestrator_pending, clear_orchestrator_pending
task = task_data.get("task", "")
confirmed = task_data.get("confirmed", False)
result = await orchestrate_async(task, user_confirmed=confirmed)
chat_id = task_data.get("chat_id", 0)
# Se confirmou, tenta recuperar o plano pendente para reutilizar
plan = None
if confirmed:
from session_manager import get_orchestrator_pending
pending_data = get_orchestrator_pending(chat_id)
if pending_data:
plan = pending_data.get("plan")
clear_orchestrator_pending(chat_id)
result = await orchestrate_async(task, user_confirmed=confirmed, plan=plan)
if result["status"] == "needs_confirmation":
# Salva o plano pendente para possível confirmação posterior
if chat_id:
set_orchestrator_pending(chat_id, {
"task": task,
"plan": result.get("plan", {})
})
return {
"status": "needs_confirmation",
"plan": result["plan"],
"message": format_confirmation_message(result)
}
return {
"status": "completed",
"results": result.get("results", []),
@@ -205,12 +227,24 @@ async def get_orch_status(is_auth: bool = Depends(verify_password)):
async def call_hermes_direct(task_data: dict, is_auth: bool = Depends(verify_password)):
from core_tools import delegate_to_hermes
task = task_data.get("task", "")
user_id = task_data.get("user_id", "unknown")
chat_id = task_data.get("chat_id", 0)
history = task_data.get("history", [])
if not task:
return {"reply": "Tarefa vazia enviada para o Hermes."}
# Contexto pro Hermes saber quem está falando
user_context = f"[chat_id={chat_id}, user_id={user_id}]"
if history:
recent = "; ".join([f"Usuário: {h['user'][:50]} -> Bot: {h['bot'][:50]}" for h in history[-5:]])
user_context += f"\nHistórico recente: {recent}"
full_task = f"{user_context}\n\nTarefa: {task}"
try:
# Roda a tool que faz a chamada sincrona do subprocess em uma thread
result = await run_in_threadpool(delegate_to_hermes, task)
result = await run_in_threadpool(delegate_to_hermes, full_task)
return {"reply": f"🤖 **Hermes Agent:**\n\n{result}"}
except Exception as e:
return {"reply": f"❌ **Erro no Hermes:** {str(e)}"}