feat(app): a chat names its model (recorded, last reply's, or the agent default) and each reply shows the model that answered
This commit is contained in:
@@ -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<ChatModelControl> {
|
||||
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: [
|
||||
|
||||
@@ -683,6 +683,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
sessionId: widget.sessionId,
|
||||
session: session,
|
||||
onChanged: widget.onModelChanged,
|
||||
answeredBy: latestReplyModel(_controller.messages),
|
||||
),
|
||||
),
|
||||
ChatBarAction(
|
||||
|
||||
@@ -56,6 +56,7 @@ List<JsonMap> transcriptRows(
|
||||
}) {
|
||||
final rows = <JsonMap>[];
|
||||
String? key;
|
||||
String model = '';
|
||||
final ids = <String>[];
|
||||
final parts = <JsonMap>[];
|
||||
final activity = <JsonMap>[];
|
||||
@@ -77,9 +78,12 @@ List<JsonMap> transcriptRows(
|
||||
'key': key,
|
||||
'messageIds': List<String>.of(ids),
|
||||
'parts': List<JsonMap>.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<JsonMap> 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<JsonMap> messages) {
|
||||
for (final message in messages.reversed) {
|
||||
if (message['role'] != 'assistant') continue;
|
||||
final model = '${message['model'] ?? ''}'.trim();
|
||||
if (model.isNotEmpty) return model;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -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)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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<JsonMap> get frames => const Stream.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async => {};
|
||||
}
|
||||
|
||||
Future<void> _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 = <JsonMap>[
|
||||
{'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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user