fetchRemoteModelsCatalog function
Fetches the remote catalog. Honours a 10-second connect/idle budget
(matches the other lightweight endpoint reads in models_endpoint)
and never throws — every error returns null, the host falls back to
bundledRemoteModelsCatalog + the endpoint's own /v1/models.
Implementation
Future<RemoteModelsCatalog?> fetchRemoteModelsCatalog({
Uri? url,
http.Client? client,
}) async {
final target = url ?? Uri.parse(defaultRemoteCatalogUrl);
final httpClient = client ?? http.Client();
final ownsClient = client == null;
try {
final response = await httpClient
.get(target, headers: {'Accept': 'application/json'})
.timeout(const Duration(seconds: 10));
if (response.statusCode != 200) return null;
final decoded = jsonDecode(response.body);
return RemoteModelsCatalog.fromJson(decoded);
} on Object {
return null;
} finally {
if (ownsClient) httpClient.close();
}
}