76437db018
Owns one open chat session: subscribes with chat_subscribe, reads the newest history page, folds only this session's chat_event frames, pages older history with the opaque cursor, and replaces the held turn on resync. Failures keep the held transcript and surface an error; disposal only cancels the local stream. Co-authored-by: C2 pipeline <noreply@pipeline.local>
1.9 KiB
1.9 KiB
C2 — Chat thread controller
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.