feat: enhance model and tools integration with auto-selection functionality

- Added a new `toolIds` field to the `Model` class to support tool identification.
- Implemented `modelToolsAutoSelectionProvider` to automatically apply model-specific tools when the selected model changes.
- Enhanced the logic to filter and set valid tool IDs based on available tools, improving user experience by ensuring relevant tools are automatically selected.
- Updated the default model auto-selection provider to initialize the new tools auto-selection feature, ensuring seamless integration within the app's lifecycle.
This commit is contained in:
cogwheel0
2025-10-11 13:27:39 +05:30
parent 7a8bd54dba
commit 1333b10cd8
2 changed files with 51 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ sealed class Model with _$Model {
Map<String, dynamic>? capabilities,
Map<String, dynamic>? metadata,
List<String>? supportedParameters,
List<String>? toolIds,
}) = _Model;
factory Model.fromJson(Map<String, dynamic> json) {
@@ -111,6 +112,18 @@ sealed class Model with _$Model {
mergedMetadata['info'] = {...existingInfo, ...infoSection};
}
// Extract toolIds from info.meta.toolIds (OpenWebUI format)
List<String>? toolIds;
final infoMeta = (infoSection?['meta'] as Map<String, dynamic>?) ??
(metaSection) ??
(mergedMetadata['meta'] as Map<String, dynamic>?);
if (infoMeta != null) {
final toolIdsData = infoMeta['toolIds'];
if (toolIdsData is List) {
toolIds = toolIdsData.map((e) => e.toString()).toList();
}
}
return Model(
id: json['id'] as String,
name: json['name'] as String,
@@ -126,6 +139,7 @@ sealed class Model with _$Model {
'supported_parameters': supportedParamsList ?? supportedParams,
},
metadata: mergedMetadata,
toolIds: toolIds,
);
}
}