fetchModelsForEndpoint function
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>{});
}