fetchModelsForEndpoint function

Future<ModelsEndpointInfo> fetchModelsForEndpoint(
  1. String baseUrl, {
  2. required String apiKey,
  3. String? provider,
  4. Client? client,
  5. void onBundledFallback()?,
})

Fetches the model list of baseUrl, picking the wire dialect by registration order. Any failure answers an empty info — callers always keep their manual-entry fallback. When a dialect answers from its bundled catalog instead of the live endpoint (onBundledFallback), the picker can surface the provenance (the bundled-catalog note).

Implementation

Future<ModelsEndpointInfo> fetchModelsForEndpoint(
  String baseUrl, {
  required String apiKey,
  String? provider,
  http.Client? client,
  void Function()? onBundledFallback,
}) async {
  final effectiveClient = client ?? _dispatchHttpClientForTesting;
  for (final dialect in modelListDialects) {
    if (dialect.matches(baseUrl, provider)) {
      return dialect.fetch(
        baseUrl,
        apiKey,
        client: effectiveClient,
        onBundledFallback: onBundledFallback,
      );
    }
  }
  return (const <String>[], const <String, int>{}, const <String, int>{});
}