install method

Future<AgentSdkInstallOutcome> install({
  1. void onProgress(
    1. String line
    )?,
})

Installs the server of the candidate that reported AgentSdkUnavailableKind.notInstalled, then retries selection, so a successful install opens the gate without a second action.

Only ever called because the user asked (: the SDK is downloaded on the user's request, never on the app's initiative). Never throws; a second call while one runs answers a failure rather than starting two npm cis into the same folder.

Implementation

Future<AgentSdkInstallOutcome> install({
  void Function(String line)? onProgress,
}) async {
  final target = _installable;
  if (target == null) {
    return const AgentSdkInstallOutcome.failed(
      'no AI server is waiting to be installed',
    );
  }
  if (_installing) {
    return const AgentSdkInstallOutcome.failed(
      'an install is already running',
    );
  }
  _installing = true;
  try {
    final outcome = await target.install(onProgress: onProgress);
    if (outcome.ok) await retry();
    return outcome;
  } finally {
    _installing = false;
  }
}