diff --git a/app/lib/features/chat/conversation/chat_model_control.dart b/app/lib/features/chat/conversation/chat_model_control.dart index 5baa1b00..75a22ace 100644 --- a/app/lib/features/chat/conversation/chat_model_control.dart +++ b/app/lib/features/chat/conversation/chat_model_control.dart @@ -21,8 +21,13 @@ class ChatModelControl extends StatefulWidget { required this.sessionId, required this.session, this.onChanged, + this.answeredBy = '', }); + /// The model the latest reply recorded, shown when the session itself has + /// no model on record. + final String answeredBy; + final ApiGateway gateway; final String sessionId; @@ -104,7 +109,12 @@ class _ChatModelControlState extends State { Widget build(BuildContext context) { final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino; - final label = chatModelLabel(_model, _selection); + final backend = '${widget.session['backend'] ?? ''}'.trim(); + final label = _model.isNotEmpty + ? chatModelLabel(_model, _selection) + : widget.answeredBy.isNotEmpty + ? widget.answeredBy + : '${backend.isEmpty ? 'opencode' : backend} default'; final content = Row( mainAxisSize: MainAxisSize.min, children: [ diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index 545fcae5..5d64db58 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -683,6 +683,7 @@ class _ChatThreadViewState extends State { sessionId: widget.sessionId, session: session, onChanged: widget.onModelChanged, + answeredBy: latestReplyModel(_controller.messages), ), ), ChatBarAction( diff --git a/app/lib/features/chat/domain/chat_transcript.dart b/app/lib/features/chat/domain/chat_transcript.dart index 77337c6c..bbe0ce06 100644 --- a/app/lib/features/chat/domain/chat_transcript.dart +++ b/app/lib/features/chat/domain/chat_transcript.dart @@ -56,6 +56,7 @@ List transcriptRows( }) { final rows = []; String? key; + String model = ''; final ids = []; final parts = []; final activity = []; @@ -77,9 +78,12 @@ List transcriptRows( 'key': key, 'messageIds': List.of(ids), 'parts': List.of(parts), + // The model that answered, as the server recorded it on the reply. + if (model.isNotEmpty) 'model': model, }); } key = null; + model = ''; ids.clear(); parts.clear(); activity.clear(); @@ -90,6 +94,8 @@ List transcriptRows( if (message['role'] == 'assistant') { final id = '${message['id'] ?? ''}'.trim(); key ??= id; + final recorded = '${message['model'] ?? ''}'.trim(); + if (recorded.isNotEmpty) model = recorded; if (id.isNotEmpty) ids.add(id); for (final part in (message['parts'] as List? ?? const [])) { if (part is! Map) continue; @@ -339,3 +345,13 @@ class ChatSendQueue { return result; } } + +/// The model of the latest stored reply, or empty when none recorded one. +String latestReplyModel(List messages) { + for (final message in messages.reversed) { + if (message['role'] != 'assistant') continue; + final model = '${message['model'] ?? ''}'.trim(); + if (model.isNotEmpty) return model; + } + return ''; +} diff --git a/app/lib/features/chat/ui/transcript/chat_message_view.dart b/app/lib/features/chat/ui/transcript/chat_message_view.dart index 5cf8f4eb..294f411f 100644 --- a/app/lib/features/chat/ui/transcript/chat_message_view.dart +++ b/app/lib/features/chat/ui/transcript/chat_message_view.dart @@ -202,18 +202,30 @@ class ChatMessageView extends StatelessWidget { for (final part in parts) if (isChatToolPart(part)) part, ]; + final model = '${row['model'] ?? ''}'.trim(); return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ if (content.isNotEmpty) bubble, // Reasoning and tool calls share one quiet row below the answer. - if (reasoning.isNotEmpty || tools.isNotEmpty) + if (reasoning.isNotEmpty || tools.isNotEmpty || model.isNotEmpty) Wrap( spacing: 8, + crossAxisAlignment: WrapCrossAlignment.center, children: [ if (reasoning.isNotEmpty) ChatReasoningChip(steps: reasoning), if (tools.isNotEmpty) ChatToolCallsChip(calls: tools), + // Which model answered, quietly, after the chips. + if (model.isNotEmpty) + Text( + model, + key: const Key('chat-reply-model'), + style: TextStyle( + fontSize: 12, + color: _secondaryColor(context, _isCupertino(context)), + ), + ), ], ), ], diff --git a/app/test/features/chat/conversation/chat_model_label_test.dart b/app/test/features/chat/conversation/chat_model_label_test.dart new file mode 100644 index 00000000..edc2946a --- /dev/null +++ b/app/test/features/chat/conversation/chat_model_label_test.dart @@ -0,0 +1,61 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/core/api_gateway.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_model_control.dart'; +import 'package:pipelines_app/features/chat/domain/chat_transcript.dart'; + +class _Gateway implements ApiGateway { + @override + Stream get frames => const Stream.empty(); + + @override + Future call(String type, [JsonMap fields = const {}]) async => {}; +} + +Future _pump(WidgetTester tester, JsonMap session, String answeredBy) => + tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: ChatModelControl( + gateway: _Gateway(), + sessionId: 's', + session: session, + answeredBy: answeredBy, + ), + ), + ), + ); + +void main() { + test('each reply carries the model that answered it', () { + final messages = [ + {'id': 'u1', 'role': 'user', 'parts': []}, + { + 'id': 'a1', + 'role': 'assistant', + 'model': 'claude-opus', + 'parts': [ + {'type': 'text', 'text': 'Hi'}, + ], + }, + ]; + final rows = transcriptRows(messages); + expect(rows.last['model'], 'claude-opus'); + expect(latestReplyModel(messages), 'claude-opus'); + expect(latestReplyModel(const []), ''); + }); + + testWidgets('the model control names a model, never just "Model"', ( + tester, + ) async { + await _pump(tester, {'backend': 'claude', 'model': 'opus'}, 'sonnet'); + expect(find.text('opus'), findsOneWidget); + + await _pump(tester, {'backend': 'claude'}, 'sonnet'); + expect(find.text('sonnet'), findsOneWidget); + + await _pump(tester, {'backend': 'claude'}, ''); + expect(find.text('claude default'), findsOneWidget); + expect(find.text('Model'), findsNothing); + }); +}