refactor: remove typing chat action

This commit is contained in:
banteg
2025-12-29 02:40:46 +04:00
parent 36f0c7ce42
commit aedebdfac7
2 changed files with 5 additions and 34 deletions
@@ -151,16 +151,6 @@ class ProgressEditor:
self._stop.wait(0.2)
def _typing_loop(bot: TelegramClient, chat_id: int, stop_evt: threading.Event) -> None:
while not stop_evt.is_set():
try:
bot.send_chat_action(chat_id=chat_id, action="typing")
except Exception as e:
log(f"[typing] send_chat_action failed chat_id={chat_id}: {e}")
log_debug(f"[typing] send_chat_action failed chat_id={chat_id}: {e}")
stop_evt.wait(4.0)
class CodexExecRunner:
"""
Runs Codex in non-interactive mode:
@@ -430,15 +420,6 @@ def run(
silent_progress = progress_silent
loud_final = final_notify
typing_stop = threading.Event()
typing_thread = threading.Thread(
target=_typing_loop,
args=(bot, chat_id, typing_stop),
daemon=True,
)
typing_thread.start()
log_debug("[typing] thread started")
started_at = time.monotonic()
session_box: dict[str, Optional[str]] = {"id": resume_session}
progress_renderer = ExecProgressRenderer(max_actions=5)
@@ -488,9 +469,6 @@ def run(
progress.set_markdown(msg)
def _stop_background() -> None:
typing_stop.set()
typing_thread.join(timeout=1.0)
log_debug("[typing] thread stopped")
if progress is not None:
progress.stop()
log_debug("[progress] thread stopped")
@@ -116,13 +116,13 @@ class TelegramClient:
rendered_text, entities = render_markdown(text)
limit = min(chunk_len, TELEGRAM_HARD_LIMIT)
if len(rendered_text) > limit:
# Keep a tail section to preserve the "resume: `...`" line at the end.
# If we truncate, drop entities to avoid offset gymnastics.
# Preserve the final `resume: `...`` line if present.
sep = "\n" + ELLIPSIS + "\n"
tail_len = min(400, max(120, limit // 3))
tail = rendered_text[-tail_len:]
head_len = max(0, limit - len(sep) - len(tail))
rendered_text = rendered_text[:head_len] + sep + tail
lines = rendered_text.splitlines()
tail = lines[-1] if lines else ""
max_head = max(0, limit - len(sep) - len(tail))
rendered_text = "".join([rendered_text[:max_head], sep, tail])
entities = None
msg = self.send_message(
@@ -133,10 +133,3 @@ class TelegramClient:
entities=entities or None,
)
return [msg]
def send_chat_action(self, chat_id: int, action: str = "typing") -> Dict[str, Any]:
params: Dict[str, Any] = {
"chat_id": chat_id,
"action": action,
}
return self._call("sendChatAction", params)