feat(app): choose a chat model from the conversation header
Native model control and chooser in the chat thread header, matching the web chat_models/chat_model exchange. Fixes the chat_models list parsing, keeps the accepted server echo across Back/reopen, and resolves the session row for /chat/:id deep links.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
# Chat model picker (native model control)
|
||||
|
||||
The conversation header shows a model control for backends with a verified
|
||||
catalog and switch path (`""`, `opencode`, `codex`), matching
|
||||
`web/src/chatModels.js`. Files:
|
||||
|
||||
- `lib/features/chat/conversation/chat_models.dart` — the web's model helpers:
|
||||
`supportsChatModels`, `chatModelLabel` (recorded model or `Model`, plus
|
||||
` · next turn` while `model_selection == next_turn`),
|
||||
`chatModelSelectionNote` (both backend sentences verbatim), display name with
|
||||
the id fallback, and `filterChatModels` (case-insensitive over name, id and
|
||||
provider, server order kept, blank query keeps the catalog).
|
||||
- `lib/features/chat/conversation/chat_model_control.dart` — the header control.
|
||||
It reads its current facts from the opened row and adopts a replaced row in
|
||||
`didUpdateWidget`; the server echo after an accepted switch is reported to the
|
||||
destination through `onModelChanged`.
|
||||
- `lib/features/chat/conversation/chat_model_chooser.dart` — `SimpleDialog`
|
||||
(Material) or `CupertinoActionSheet` (Cupertino) with the web's `Search models`
|
||||
field, loading/error/empty/no-match states, the check mark and `selected`
|
||||
semantics on the current row, and Cancel. A refusal keeps the chooser open and
|
||||
shows the server's reason. Acceptance applies the server's `chat_model` echo
|
||||
(provider/model/selection) and is reported even when the chooser was dismissed
|
||||
while the request was in flight — the server has already applied it.
|
||||
|
||||
The wire exchange is the web's: `{"chat_query":{"session_id":"…"}}` then
|
||||
`{"chat_model":{"session_id":"…","provider":"…","model":"…"}}` (trimmed). The
|
||||
repository parser treats `chat_models` as the server's list (`[]ChatModel`),
|
||||
returns an empty catalog for a missing/malformed field, and refuses a blank
|
||||
session id.
|
||||
|
||||
`ChatScreen` keeps the row it opened (`_openedSessions`) and the accepted model
|
||||
per session (`_acceptedModels`), so Back then reopening the same row shows the
|
||||
model the server accepted even when the list row still carries the old value.
|
||||
`ChatSessionsScreen.onSessions` reports its loaded rows after a frame, which is
|
||||
how a `/chat/:id` deep link gets the same title and model facts as a tapped row
|
||||
without a second `chat_sessions` request.
|
||||
|
||||
## Checks run for this slice
|
||||
|
||||
`flutter test test/features/chat` (274 passed), `flutter test` (1406 passed),
|
||||
`flutter analyze` (no issues), `flutter build web` (built), `dart format
|
||||
--set-exit-if-changed` on the touched files (0 changed), `git diff --check`
|
||||
(clean).
|
||||
|
||||
`test/features/chat/conversation/chat_model_picker_test.dart` — 16 tests: exact
|
||||
request bodies, refusal, server echo, initial next-turn suffix, provider match
|
||||
on duplicate ids, search and no-match on both hosts, absent control for an
|
||||
unsupported backend, catalog failure, cancel during an in-flight switch, row
|
||||
replacement, and 320px/2x layout.
|
||||
|
||||
`test/features/chat/chat_screen_model_test.dart` — 3 tests: accepted switch
|
||||
survives Back and reopening from the unchanged list row, `/chat/:id` resolves
|
||||
the loaded row (one `chat_sessions` request), and an unsupported backend shows
|
||||
no control. Both regression tests were confirmed to fail with the fix removed
|
||||
before restoring it.
|
||||
|
||||
No browser capture is claimed here, and mobile remains unverified: this lane
|
||||
develops and tests the web target only.
|
||||
Reference in New Issue
Block a user