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:
@@ -15,25 +15,40 @@ class ChatRepository {
|
||||
|
||||
Future<List<JsonMap>> sessions() async =>
|
||||
_maps((await gateway.call('chat_sessions'))['chat_sessions']);
|
||||
Future<JsonMap> models(String sessionId) async {
|
||||
|
||||
/// The models the session's harness offers, in the server's order.
|
||||
///
|
||||
/// `chat_models` is a JSON list, the same shape the web client reads. A
|
||||
/// missing or wrong-typed field is an empty catalog, never invented rows.
|
||||
Future<List<JsonMap>> models(String sessionId) async {
|
||||
final session = sessionId.trim();
|
||||
if (session.isEmpty) {
|
||||
throw ArgumentError('Select a chat session first.');
|
||||
}
|
||||
final reply = await gateway.call('chat_models', {
|
||||
'chat_query': {'session_id': sessionId},
|
||||
'chat_query': {'session_id': session},
|
||||
});
|
||||
final value = reply['chat_models'];
|
||||
return value is List ? _maps(value) : const [];
|
||||
}
|
||||
|
||||
Future<JsonMap> selectModel(String sessionId, String provider, String model) {
|
||||
final session = sessionId.trim();
|
||||
if (session.isEmpty) {
|
||||
throw ArgumentError('Select a chat session first.');
|
||||
}
|
||||
if (provider.trim().isEmpty || model.trim().isEmpty) {
|
||||
throw ArgumentError('Choose a model first.');
|
||||
}
|
||||
return gateway.call('chat_model', {
|
||||
'chat_model': {
|
||||
'session_id': session,
|
||||
'provider': provider.trim(),
|
||||
'model': model.trim(),
|
||||
},
|
||||
});
|
||||
final catalog = reply['chat_models'];
|
||||
return catalog is Map ? Map<String, dynamic>.from(catalog) : {};
|
||||
}
|
||||
|
||||
Future<JsonMap> selectModel(
|
||||
String sessionId,
|
||||
String provider,
|
||||
String model,
|
||||
) => gateway.call('chat_model', {
|
||||
'chat_model': {
|
||||
'session_id': sessionId,
|
||||
'provider': provider,
|
||||
'model': model,
|
||||
},
|
||||
});
|
||||
Future<List<JsonMap>> shells(String sessionId) async => _maps(
|
||||
(await gateway.call('chat_shells', {
|
||||
'chat_query': {'session_id': sessionId},
|
||||
|
||||
Reference in New Issue
Block a user