feat(discord): persistent typing indicator for DMs
Based on PR #2427 by @oxngon (core feature extracted, reformatting and unrelated changes dropped). Discord's TYPING_START gateway event is unreliable for bot DMs. This adds a background typing loop that hits POST /channels/{id}/typing every 8 seconds (indicator lasts ~10s) until the response is sent. - send_typing() starts a per-channel background loop (idempotent) - stop_typing() cancels it (called after _run_agent returns) - Base adapter gets stop_typing() as a no-op default - Per-channel tracking via _typing_tasks dict prevents duplicates
This commit is contained in:
parent
ffa8b562e9
commit
ab3cbfc99d
3 changed files with 68 additions and 8 deletions
|
|
@ -2125,7 +2125,15 @@ class GatewayRunner:
|
|||
session_id=session_entry.session_id,
|
||||
session_key=session_key
|
||||
)
|
||||
|
||||
|
||||
# Stop persistent typing indicator now that the agent is done
|
||||
try:
|
||||
_typing_adapter = self.adapters.get(source.platform)
|
||||
if _typing_adapter and hasattr(_typing_adapter, "stop_typing"):
|
||||
await _typing_adapter.stop_typing(source.chat_id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
response = agent_result.get("final_response") or ""
|
||||
agent_messages = agent_result.get("messages", [])
|
||||
|
||||
|
|
@ -2325,6 +2333,13 @@ class GatewayRunner:
|
|||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Stop typing indicator on error too
|
||||
try:
|
||||
_err_adapter = self.adapters.get(source.platform)
|
||||
if _err_adapter and hasattr(_err_adapter, "stop_typing"):
|
||||
await _err_adapter.stop_typing(source.chat_id)
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Agent error in session %s", session_key)
|
||||
error_type = type(e).__name__
|
||||
error_detail = str(e)[:300] if str(e) else "no details available"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue