fix: address PR review round 5 — streaming guard, VC auth, history prefix, auto-TTS control

1. Gate _streaming_api_call to chat_completions mode only — Anthropic and
   Codex fall back to _interruptible_api_call. Preserve Anthropic base_url
   across all client rebuild paths (interrupt, fallback, 401 refresh).

2. Discord VC synthetic events now use chat_type="channel" instead of
   defaulting to "dm" — prevents session bleed into DM context.
   Authorization runs before echoing transcript. Sanitize @everyone/@here
   in voice transcripts.

3. CLI voice prefix ("[Voice input...]") is now API-call-local only —
   stripped from returned history so it never persists to session DB or
   resumed sessions.

4. /voice off now disables base adapter auto-TTS via _auto_tts_disabled_chats
   set — voice input no longer triggers TTS when voice mode is off.
This commit is contained in:
0xbyt4
2026-03-14 10:31:49 +03:00
parent 35748a2fb0
commit cc0a453476
5 changed files with 59 additions and 22 deletions

21
cli.py
View File

@@ -4213,20 +4213,20 @@ class HermesCLI:
if text_queue is not None:
text_queue.put(delta)
# When voice mode is active, prepend a brief instruction to the
# user message so the model responds concisely. This avoids
# modifying the system prompt (which would invalidate the prompt
# cache). The original message in conversation_history stays clean.
agent_message = message
# When voice mode is active, prepend a brief instruction so the
# model responds concisely. The prefix is API-call-local only —
# we strip it from the returned history so it never persists to
# session DB or resumed sessions.
_voice_prefix = ""
if self._voice_mode and isinstance(message, str):
agent_message = (
_voice_prefix = (
"[Voice input — respond concisely and conversationally, "
"2-3 sentences max. No code blocks or markdown.] "
+ message
)
def run_agent():
nonlocal result
agent_message = _voice_prefix + message if _voice_prefix else message
result = self.agent.run_conversation(
user_message=agent_message,
conversation_history=self.conversation_history[:-1], # Exclude the message we just added
@@ -4298,6 +4298,13 @@ class HermesCLI:
# Update history with full conversation
self.conversation_history = result.get("messages", self.conversation_history) if result else self.conversation_history
# Strip voice prefix from history so it never persists
if _voice_prefix and self.conversation_history:
for msg in self.conversation_history:
if msg.get("role") == "user" and isinstance(msg.get("content"), str):
if msg["content"].startswith(_voice_prefix):
msg["content"] = msg["content"][len(_voice_prefix):]
# Get the final response
response = result.get("final_response", "") if result else ""