Merge pull request #207 from cogwheel0/improve-model-tools-selection

feat: Improve model tools auto-selection and lifecycle management
This commit is contained in:
cogwheel
2025-12-02 16:32:11 +05:30
committed by GitHub
3 changed files with 17 additions and 0 deletions

View File

@@ -139,6 +139,14 @@ sealed class Model with _$Model {
}
}
// Fallback to top-level toolIds (for cached models serialized via toJson)
if (toolIds == null || toolIds.isEmpty) {
final topLevelToolIds = json['toolIds'];
if (topLevelToolIds is List) {
toolIds = topLevelToolIds.map((e) => e.toString()).toList();
}
}
final idRaw = json['id'];
final id = idRaw?.toString();
if (id == null || id.isEmpty) {

View File

@@ -812,6 +812,9 @@ final _settingsWatcherProvider = Provider<void>((ref) {
// Auto-apply model-specific tools when model changes or tools load
final modelToolsAutoSelectionProvider = Provider<void>((ref) {
// Prevent disposal so listeners remain active throughout app lifecycle
ref.keepAlive();
Future<void> applyTools(Model? model) async {
if (model == null) {
final current = ref.read(selectedToolIdsProvider);
@@ -894,6 +897,9 @@ final modelToolsAutoSelectionProvider = Provider<void>((ref) {
// Auto-apply default model from settings when it changes (and not manually overridden)
// keepAlive to maintain listener throughout app lifecycle
final defaultModelAutoSelectionProvider = Provider<void>((ref) {
// Prevent disposal so listeners remain active throughout app lifecycle
ref.keepAlive();
// Initialize the model tools auto-selection
ref.watch(modelToolsAutoSelectionProvider);

View File

@@ -173,6 +173,9 @@ class AppStartupFlow extends _$AppStartupFlow {
keepAlive(appIntentCoordinatorProvider);
keepAlive(quickActionsCoordinatorProvider);
// Ensure model tools auto-selection is active throughout app lifecycle
keepAlive(defaultModelAutoSelectionProvider);
// Kick background model loading flow (non-blocking)
Future<void>.delayed(const Duration(milliseconds: 120), () {
if (!ref.mounted) return;