ensureModelReadyFromSpec method

  1. @override
Future<void> ensureModelReadyFromSpec(
  1. ModelSpec spec
)
override

Modern API: Ensures a model spec is ready for use

Phase 5.1: This method now delegates to ServiceRegistry (Modern API) instead of manually managing state. All installation is handled by source handlers through the ServiceRegistry pattern.

Implementation

@override
Future<void> ensureModelReadyFromSpec(ModelSpec spec) async {
  await _ensureInitialized();

  // Phase 5: Delegate to ServiceRegistry (Modern API)
  final registry = ServiceRegistry.instance;
  final handlerRegistry = registry.sourceHandlerRegistry;
  final repository = registry.modelRepository;

  // Check if already installed via repository
  bool allFilesInstalled = true;
  for (final file in spec.files) {
    if (!await repository.isInstalled(file.filename)) {
      allFilesInstalled = false;
      break;
    }
  }

  if (!allFilesInstalled) {
    // Install via Modern API handlers
    for (final file in spec.files) {
      final handler = handlerRegistry.getHandler(file.source);
      if (handler == null) {
        throw ModelStorageException(
          'No handler for ${file.source.runtimeType}',
          null,
          'ensureModelReadyFromSpec',
        );
      }
      await handler.install(file.source);
    }
  }

  setActiveModel(spec);
}