fix(voice): route voice turns through the same backend pipeline as chat

Voice interactions still called OpenRouter directly from the main
process with a leftover pre-redesign system prompt ("coach de
formation vocal"), bypassing Max API's intent router and the new
PERSONALITY_PROMPT entirely - causing Max to misrepresent himself in
spoken conversation. voice-turn now calls routeMessage() (the same
POST /sessions/messages entry point the chat window uses), so voice
and text share one personality and one pipeline.

The leaked-boilerplate/degenerate-text safety checks that used to live
alongside the old direct OpenRouter call move to a focused
speechSafety.ts module, still applied to the reply before it's spoken.
getAssistantReply() and its model-fallback plumbing are deleted - that
logic now lives server-side in Max API's OpenRouterService.

A learn-intent voice command (e.g. saying "apprends-moi React out
loud") now opens the pipeline stepper and syncs session status exactly
like typing it in chat, via a handleRouteMessageResult() helper shared
between voice-turn and sessions:route-message.

Known limitations (unchanged from the text-chat intent router, now
just consistent across both channels): casual chat-intent turns have
no cross-turn memory (no pre-session history storage server-side yet),
and a voice-started session's messages don't appear in the chat
window's own transcript if opened afterwards (per-window state only).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-11-01 09:33:24 +01:00
co-authored by Claude Sonnet 5
parent 78d6547037
commit 73bc2587b8
5 changed files with 117 additions and 231 deletions
+42
View File
@@ -0,0 +1,42 @@
// Marqueurs pour detecter une fuite de "boilerplate" interne du modele (constate en test reel :
// "Use the results below to formulate an answer..." prononce a voix haute au lieu d'une vraie
// reponse de Max) : present si ca ressemble a de l'anglais generique sans aucun mot-outil francais.
const ENGLISH_LEAK_MARKERS =
/\b(the|unless|below|formulate|additional|information|needed|answer the|user question)\b/i
const FRENCH_MARKERS =
/\b(le|la|les|de|des|et|un|une|est|tu|je|pour|dans|avec|qui|que|ce|ton|ta)\b/i
export function containsLeakedBoilerplate(text: string): boolean {
return ENGLISH_LEAK_MARKERS.test(text) && !FRENCH_MARKERS.test(text)
}
/**
* Le modele peut "decrocher" et renvoyer un texte corrompu (constate en test reel : " foia" +
* caracteres chinois/bengalis a la place d'une vraie phrase). Detecte via la part de caracteres
* non-latins/non-imprimables dans le texte.
*/
export function isDegenerateText(text: string): boolean {
const trimmed = text.trim()
if (!trimmed) return false
let latinCount = 0
for (const char of trimmed) {
const code = char.codePointAt(0) ?? 0
if ((code >= 0x20 && code <= 0x7e) || (code >= 0xa0 && code <= 0x24f)) latinCount++
}
return latinCount / trimmed.length < 0.7 || (trimmed.length > 15 && latinCount < 8)
}
export const SPEECH_FALLBACK_REPLY =
"Voila, j'ai bien avance avec toi sur ce sujet. Dis-moi si tu veux qu'on continue."
/**
* A appliquer sur tout texte destine a etre prononce a voix haute (voir voice-turn dans
* src/main/index.ts) avant de l'envoyer a la synthese vocale : remplace une reponse
* fuyante/corrompue par une phrase de secours plutot que de la lire telle quelle a l'utilisateur.
*/
export function sanitizeForSpeech(text: string): string {
if (containsLeakedBoilerplate(text) || isDegenerateText(text)) {
return SPEECH_FALLBACK_REPLY
}
return text
}