import 'package:pipelines_app/core/api_gateway.dart'; /// Local-only catalogs for exercising all three header menus with `header=1`. /// No provider or production permission setting is read or changed. class ChatCatalogFixture { static const models = [ {'id': 'openai/gpt-6.1', 'provider': 'openai', 'name': 'GPT 6.1'}, {'id': 'openai/gpt-5.6-luna', 'provider': 'openai', 'name': 'Luna'}, ]; static const modes = [ { 'id': 'default', 'name': 'Ask for permission', 'description': 'Ask before actions that require approval.', }, { 'id': 'plan', 'name': 'Plan only', 'description': 'Inspect and plan without applying changes.', }, { 'id': 'auto', 'name': 'Auto approve', 'description': 'Fixture-only automatic approval mode.', }, ]; final Map _model = {}; final Map _mode = {}; JsonMap rowFields(String sessionId) { final model = _model[sessionId] ?? models.first; final mode = _mode[sessionId] ?? 'default'; return { 'model': model['id'], 'model_provider': model['provider'], if (_model.containsKey(sessionId)) 'model_selection': 'next_turn', 'mode': mode, 'mode_name': modes.firstWhere((item) => item['id'] == mode)['name'], }; } JsonMap? reply(JsonMap request) { switch (request['type']) { case 'chat_models': return {'type': 'chat_models', 'chat_models': models}; case 'chat_modes': final body = request['chat_query']; final session = body is Map ? '${body['session_id'] ?? ''}' : ''; return { 'type': 'chat_modes', 'chat_modes': modes, 'chat_mode': {'mode': rowFields(session)['mode']}, }; case 'chat_model': final body = request['chat_model']; if (body is! Map) return _invalid; final session = '${body['session_id'] ?? ''}'; final model = models .where( (item) => item['id'] == body['model'] && item['provider'] == body['provider'], ) .firstOrNull; if (session.isEmpty || model == null) return _invalid; _model[session] = model; return { 'type': 'chat_model', 'chat_model': { 'session_id': session, 'provider': model['provider'], 'model': model['id'], 'selection': 'next_turn', }, }; case 'chat_mode': final body = request['chat_mode']; if (body is! Map) return _invalid; final session = '${body['session_id'] ?? ''}'; final mode = '${body['mode'] ?? ''}'; if (session.isEmpty || !modes.any((item) => item['id'] == mode)) { return _invalid; } _mode[session] = mode; return { 'type': 'chat_mode', 'chat_mode': {'session_id': session, 'mode': mode}, }; default: return null; } } static const _invalid = { 'type': 'error', 'error': 'Unknown chat catalog fixture selection.', }; }