Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d887a54
Spec batched post-call English coach
Nov 23, 2026
8b5ddf9
Spec coach section of a note: time, no correction, retry
Nov 23, 2026
fbfc9fc
Spec optional live English coach, online providers only
Nov 23, 2026
b1c53c1
Spec Coach anglais page: notes with corrections, recurring mistakes
Nov 23, 2026
8d384c4
Tie live coach results to their note; wait on real end events
Nov 23, 2026
cc226f5
Merge remote-tracking branch 'origin/main' into oats-coach
Nov 23, 2026
92c5192
Spec coach open points: prose no-correction, undecided language, zero…
Nov 23, 2026
b53d8ba
Move remaining coachAfterCall callers to segments; pin franglais skip
Nov 23, 2026
0cfd9aa
Coach a whole meeting in bounded batches, user's English only
Nov 23, 2026
3f9af28
Add the optional live English coach service
Nov 23, 2026
c878398
Wire the live coach and segment-based post-call coach into the live view
Nov 23, 2026
e4189b6
Show time, 'Aucune correction' and unanalyzed parts in a note's coach
Nov 23, 2026
9d9b1dd
Show the live coach switch and its discreet block
Nov 23, 2026
4ac4a77
Fill the Coach anglais page with notes and recurring mistakes
Nov 23, 2026
ad9fed3
Let live options wrap and render the coach screens
Nov 23, 2026
414f918
Never call a live-only note flawless; read lists before objects safely
Nov 23, 2026
8926a47
Merge remote-tracking branch 'origin/main' into oats-coach
Nov 23, 2026
e6c9f54
Spec review points: language tables, nothing-to-analyse, live finding…
Nov 23, 2026
ded28cc
Coach review fixes: fewer false skips, nothing-to-analyse, keep live,…
Nov 23, 2026
d870f85
Render a note with nothing in English to analyse
Nov 23, 2026
7fc55b0
Give the Coach page seeding container its own fakes
Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/app_macos/assets/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@
},
"coach": {
"empty": "Vos retours d'anglais, réunion par réunion, s'afficheront ici. En attendant, ouvrez une note et choisissez « Coach anglais ».",
"unanalyzed": "Une partie de la réunion n'a pas été analysée.",
"corrections": {
"one": "{} correction",
"other": "{} corrections"
},
"no_correction": "Aucune correction",
"nothing_to_analyse": "Rien en anglais à analyser",
"recurring": {
"title": "Erreurs récurrentes",
"notes": {
"one": "dans {} note",
"other": "dans {} notes"
}
},
"live": {
"option": "Coach en direct",
"description": "Corrige votre anglais pendant la réunion, par le service en ligne choisi.",
"unavailable": "Nécessite un service en ligne autorisé : en local, la transcription ralentirait.",
"state_unavailable": "Coach en direct indisponible",
"waiting": "Vos corrections s'afficheront ici."
},
"category": {
"grammar": "Grammaire",
"conjugation": "Conjugaison",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import 'dart:async';

import 'package:core_domain/domain/entities/english_feedback.entity.dart';
import 'package:core_domain/domain/entities/transcript_segment.entity.dart';
import 'package:core_foundation/logging/logger.dart';
import 'package:ici_transcript/application/services/live_answers/live_answers.service.dart'
show LiveAnswerModel;
import 'package:ici_transcript/application/services/llm/meeting_ai.dart';
import 'package:rxdart/rxdart.dart';

/// Écart minimal entre deux requêtes du coach en direct.
const Duration kLiveCoachInterval = Duration(seconds: 20);

/// Ce que le coach en direct a trouvé pendant la note [sessionId].
class LiveCoachSnapshot {
/// Crée un instantané.
const LiveCoachSnapshot({
this.sessionId,
this.corrections = const <EnglishCorrectionEntity>[],
this.unavailable = false,
});

/// Note concernée ; null avant le premier démarrage.
final String? sessionId;

/// Corrections, dans l'ordre où elles ont été trouvées.
final List<EnglishCorrectionEntity> corrections;

/// Dernier lot non envoyé (pas de fournisseur en ligne) ou en échec.
final bool unavailable;
}

/// Coach anglais EN DIRECT : les phrases anglaises finales de l'utilisateur
/// partent par lots, au plus une requête par [interval] (la première sans
/// attendre), et seulement vers un fournisseur en ligne : une génération
/// locale ralentit la transcription (1,8 s → 6–24 s mesurés).
///
/// Ne bloque jamais la transcription : [onSegmentFinalized] est synchrone,
/// un échec ne fait que poser `unavailable`, ses phrases restent pour la
/// passe d'après l'appel (pas dans [coachedSegmentIds]).
class LiveCoachService {
/// Crée le service ; le modèle est relu à chaque lot.
LiveCoachService({
required Future<LiveAnswerModel?> Function() resolveModel,
this.interval = kLiveCoachInterval,
}) : _resolveModel = resolveModel;

final Future<LiveAnswerModel?> Function() _resolveModel;

/// Écart minimal entre deux requêtes.
final Duration interval;

final Log _log = Log.named('LiveCoachService');
final BehaviorSubject<LiveCoachSnapshot> _subject =
BehaviorSubject<LiveCoachSnapshot>.seeded(const LiveCoachSnapshot());
final List<TranscriptSegmentEntity> _pending = <TranscriptSegmentEntity>[];
final Set<String> _coached = <String>{};

bool _running = false;
bool _busy = false;
Timer? _cooldown;
StreamSubscription<String>? _request;
int _run = 0;

/// Dernier état publié.
LiveCoachSnapshot get snapshot => _subject.value;

/// [snapshot] à chaque changement.
Stream<LiveCoachSnapshot> get snapshots => _subject.stream;

/// Phrases déjà corrigées en direct (la passe d'après l'appel les saute).
Set<String> get coachedSegmentIds => Set<String>.unmodifiable(_coached);

/// Ouvre la note [sessionId] : l'état précédent est oublié.
void start(String sessionId) {
_halt();
_coached.clear();
_running = true;
_subject.add(LiveCoachSnapshot(sessionId: sessionId));
}

/// Ferme la note : la requête en vol est abandonnée, ce qui a été trouvé
/// reste lisible jusqu'au prochain [start].
Future<void> stop() async => _halt();

/// Libère le service (fin de l'app).
Future<void> dispose() async {
_halt();
await _subject.close();
}

/// Phrase finale d'une des deux sources ; seules les phrases anglaises de
/// l'utilisateur sont gardées.
void onSegmentFinalized(TranscriptSegmentEntity segment) {
if (!_running || !isCoachable(segment)) return;
_pending.add(segment);
_flush();
}

void _halt() {
_running = false;
_run++;
_cooldown?.cancel();
_cooldown = null;
unawaited(_request?.cancel());
_request = null;
_busy = false;
_pending.clear();
}

void _flush() {
if (!_running || _busy || _cooldown != null || _pending.isEmpty) return;
final List<CoachLine> batch = coachBatches(_pending).first;
final Set<String> ids = batch.map((CoachLine l) => l.id).toSet();
_pending.removeWhere((TranscriptSegmentEntity s) => ids.contains(s.id));
_busy = true;
_cooldown = Timer(interval, () {
_cooldown = null;
_flush();
});
unawaited(_send(batch, ++_run));
}

Future<void> _send(List<CoachLine> batch, int run) async {
final LiveAnswerModel? model;
try {
model = await _resolveModel();
} on Object catch (e) {
return _done(run, error: e);
}
if (run != _run) return;
if (model == null || model.isLocal) {
// Rien ne part : le modèle local ralentirait la transcription.
return _done(run, error: 'aucun fournisseur en ligne');
}
final StringBuffer raw = StringBuffer();
_request = model.provider
.streamChat(coachRequest(batch, preferLowLatency: true))
.listen(
raw.write,
onError: (Object e) => _done(run, error: e),
onDone: () {
try {
final EnglishFeedbackEntity found = parseFeedback('$raw');
_done(run, batch: batch, found: found);
} on Object catch (e) {
_done(run, error: e);
}
},
cancelOnError: true,
);
}

void _done(
int run, {
List<CoachLine>? batch,
EnglishFeedbackEntity? found,
Object? error,
}) {
if (run != _run) return;
_request = null;
_busy = false;
final LiveCoachSnapshot s = snapshot;
if (error != null) {
_log.warning('Coach en direct indisponible : $error');
_subject.add(
LiveCoachSnapshot(
sessionId: s.sessionId,
corrections: s.corrections,
unavailable: true,
),
);
} else {
_coached.addAll(batch!.map((CoachLine l) => l.id));
_subject.add(
LiveCoachSnapshot(
sessionId: s.sessionId,
corrections: <EnglishCorrectionEntity>[
...s.corrections,
...timedCorrections(found!, batch),
],
),
);
}
_flush();
}
}
Loading
Loading