import 'package:shared_preferences/shared_preferences.dart'; import '../core/api_gateway.dart'; import '../core/servers/server_scope.dart'; const openInChatPreferenceKey = 'pipelines.openInChat.v1'; /// The harness and model Open in chat starts its chats with, per server and /// device. Empty fields mean the default: the New chat dialog's harness and /// the harness's own default model. class OpenInChatPreferences { const OpenInChatPreferences({ this.harness = '', this.provider = '', this.model = '', }); final String harness; final String provider; final String model; bool get hasModel => provider.isNotEmpty && model.isNotEmpty; static String _key(ApiGateway gateway) => scopedServerKey( openInChatPreferenceKey, serverStorageScope(serverIdentity(gateway)), ); static Future load(ApiGateway gateway) async { final values = (await SharedPreferences.getInstance()).getStringList(_key(gateway)) ?? const []; String at(int index) => index < values.length ? values[index].trim() : ''; return OpenInChatPreferences(harness: at(0), provider: at(1), model: at(2)); } Future save(ApiGateway gateway) async => (await SharedPreferences.getInstance()).setStringList(_key(gateway), [ harness, provider, model, ]); }