feat: Improve model tools auto-selection and lifecycle management
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user