Files

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() calls chat_subscribe with the exact session body, then reads the newest chat_messages page with limit: 200 and an empty cursor. A refused subscribe leaves history usable.
  • loadOlder() is explicit only, requires hasMore, passes the server's opaque next_cursor back verbatim, and prepends the older page by id.
  • Only chat_event envelopes 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 and hasMore with the newest authoritative page. Activity replayed while re-attaching (for example a running step) survives the replacement. A pushed resync event invokes the same path.
  • History failures set error and 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_unsubscribe request.

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.