diff --git a/vps_opencode_bot/opencode_bot.py b/vps_opencode_bot/opencode_bot.py
index d0b2f85..73436a0 100644
--- a/vps_opencode_bot/opencode_bot.py
+++ b/vps_opencode_bot/opencode_bot.py
@@ -400,40 +400,30 @@ def procesar_texto(chat, texto):
enviar(chat, f"❌ Error al lanzar OpenCode: {resp}")
return
- vistos_texto = set()
- vistos_tool = set()
+ # Respuesta SIN verbose: no se envian los comandos/tools intermedios ni
+ # fragmentos de streaming. Solo se recoge el texto del assistant generado
+ # en este turno (filtrado por t0 para no repetir mensajes de turnos
+ # anteriores) y se entrega al terminar junto con el tiempo empleado.
+ trozos = {} # pid -> (start, texto)
comienzo = time.time()
terminado = False
while time.time() - comienzo < 900:
- time.sleep(3)
- code, hist = oc_get(f"/session/{sid}/message?limit=4")
+ time.sleep(2)
+ code, hist = oc_get(f"/session/{sid}/message?limit=10")
if code == 200 and isinstance(hist, list):
- for item in reversed(hist[-4:]):
+ for item in reversed(hist[-10:]):
info = item.get("info") or {}
if info.get("role") != "assistant":
continue
for p in item.get("parts") or []:
- t = p.get("type")
- pid = p.get("id") or ""
- if t == "text" and p.get("text") and pid not in vistos_texto:
- vistos_texto.add(pid)
- enviar(chat, formatear_html(p["text"]))
- elif t == "tool" and pid not in vistos_tool:
- vistos_tool.add(pid)
- comando = ((p.get("state") or {}).get("input")
- or {}).get("command")
- if comando:
- corto = comando.strip().replace("\n", " ")[:90]
- try:
- import requests as _rq
- _rq.post(f"{API}/sendMessage",
- data={"chat_id": chat, "text":
- f"⚙️ {html.escape(corto)}",
- "parse_mode": "HTML"},
- timeout=10)
- except Exception:
- pass
- # fin del turno: la sesion deja de estar busy (tras un margen inicial)
+ if p.get("type") != "text" or not p.get("text"):
+ continue
+ inicio = (p.get("time") or {}).get("start") or 0
+ if inicio and inicio < t0:
+ continue # parte de un turno anterior: ignorar
+ pid = p.get("id") or f"{inicio}-{len(p['text'])}"
+ if pid not in trozos:
+ trozos[pid] = (inicio, p["text"])
code2, sts = oc_get("/session/status", timeout=10)
transcurrido = time.time() - comienzo
if (code2 == 200 and isinstance(sts, dict)
@@ -448,6 +438,14 @@ def procesar_texto(chat, texto):
"para cortarla y empezar de nuevo.")
return
+ # Texto consolidado del turno, ordenado por tiempo de inicio.
+ texto_final = "\n".join(t for _, t in
+ sorted(trozos.values(), key=lambda x: x[0]))
+ if texto_final.strip():
+ seg = time.time() - comienzo
+ enviar(chat, formatear_html(texto_final.strip()))
+ enviar(chat, f"⏱️ Hecho en {seg:.1f}s")
+
# ficheros tocados en el turno
adjuntos = []
try: