mergeWithRemoteCatalog function
ModelsEndpointInfo
mergeWithRemoteCatalog({
- required ModelsEndpointInfo endpointInfo,
- required String? providerKind,
- required RemoteModelsCatalog? catalog,
- List<
String> mediaSlot = const [],
Folds a remote catalog into the per-endpoint fetch result.
Without a mediaSlot the merge is chat-only: the catalog's
contextWindows fill gaps the endpoint didn't report, the chat id
list stays exactly as the endpoint reported it (the catalog never
seeds chat ids — /v1/models is the source of truth).
With mediaSlot the merge flips to media-only: the chat id list
from the endpoint is DISCARDED (chat ids like MiniMax-M3 are
useless in the image picker), and the merged id list contains
exactly the catalog's per-slot media ids. The catalog is the only
source of media ids for providers whose chat endpoint never
publishes them.
Implementation
ModelsEndpointInfo mergeWithRemoteCatalog({
required ModelsEndpointInfo endpointInfo,
required String? providerKind,
required RemoteModelsCatalog? catalog,
List<String> mediaSlot = const [],
}) {
if (catalog == null) return endpointInfo;
final entry = catalog.providers[providerKind ?? ''];
if (entry == null) return endpointInfo;
final (_, windows, maxTokens) = endpointInfo;
final List<String> mergedIds;
if (mediaSlot.isEmpty) {
// Chat path: keep the endpoint's id list verbatim, the catalog
// never augments chat ids.
mergedIds = <String>[...endpointInfo.$1];
} else {
// Media path: drop the chat list, answer exactly the catalog's
// per-slot media ids. Picker sees only the right model kind.
mergedIds = <String>[];
for (final slot in mediaSlot) {
final seed = entry.media[slot];
if (seed == null) continue;
for (final id in seed) {
if (!mergedIds.contains(id)) mergedIds.add(id);
}
}
}
final mergedWindows = <String, int>{
...entry.contextWindows,
...windows, // endpoint reported limits override catalog defaults
};
final mergedMaxTokens = <String, int>{...maxTokens};
return (mergedIds, mergedWindows, mergedMaxTokens);
}