2.3 KiB
C2 — Chat thread controller
Manager integration follow-up: exposes subscribed/subscriptionError separately from history errors, so readable stored history cannot hide a refused live watch. Resync marks history loading while retaining the current transcript. A focused regression covers refused subscribe + successful history, then successful resync. The controller does not claim to fold form events; those are a separate UI slice.
lib/features/chat/conversation/chat_thread_controller.dart owns one open
conversation without any UI. It is constructed with the shared ApiGateway and
one sessionId, reuses ChatRepository for the wire and
domain/chat_transcript.dart for the fold, and exposes messages, running,
loaded, loading, hasMore, cursor and error through
ChangeNotifier.
Behaviour:
load()callschat_subscribewith the exact session body, then reads the newestchat_messagespage withlimit: 200and an empty cursor. A refused subscribe leaves history usable.loadOlder()is explicit only, requireshasMore, passes the server's opaquenext_cursorback verbatim, and prepends the older page by id.- Only
chat_eventenvelopes for this session are folded; replayed/live text, reasoning, tool, step and user frames use the existing domain fold, so unknown message and part fields survive. resync()settles the held turn, re-subscribes, then replaces the transcript, cursor andhasMorewith the newest authoritative page. Activity replayed while re-attaching (for example a running step) survives the replacement. A pushedresyncevent invokes the same path.- History failures set
errorand keep the held transcript; they are never reported as an empty success. Superseded reads and replies after disposal are ignored. - Disposal cancels only the local stream subscription. There is no
chat_unsubscriberequest.
Checks (run from app/):
flutter test test/features/chat/conversation— 10 tests passed.flutter test test/features/chat— 43 tests passed.flutter analyze lib/features/chat test/features/chat— no issues.
Not done: the controller is not yet wired to a screen, so there is no rendered or browser change to capture; mobile builds and device verification were not performed. No shared domain, shell, main, pubspec or server files changed.