uninstallModel static method

Future<void> uninstallModel(
  1. String modelId
)

Uninstall a model

Removes model metadata and files (if not protected).

Parameters:

  • modelId: Model filename to uninstall

Implementation

static Future<void> uninstallModel(String modelId) async {
  final registry = ServiceRegistry.instance;
  final repository = registry.modelRepository;
  final fileSystem = registry.fileSystemService;

  // Get model info
  final modelInfo = await repository.loadModel(modelId);
  if (modelInfo == null) {
    throw Exception('Model not found: $modelId');
  }

  // Delete files first (if not external/protected) so a file-delete failure
  // leaves the metadata intact and the uninstall retryable — mirrors the
  // safe order used by uninstallEmbedder/Stt/Tts (delete then clear).
  if (modelInfo.source is! FileSource) {
    final targetPath = await fileSystem.getReadTargetPath(modelId);
    await fileSystem.deleteFile(targetPath);
  }

  // Delete metadata last.
  await repository.deleteModel(modelId);
}