findChatGptExportEntry function

CustomProviderEntry? findChatGptExportEntry(
  1. List<CustomProviderEntry> entries,
  2. String name
)

Resolves the saved ChatGPT entry for name: the registry's own lookup (case-insensitive, alias spellings), narrowed to chatgpt-codex-kind entries. Null when no saved login of that kind matches.

Implementation

CustomProviderEntry? findChatGptExportEntry(
  List<CustomProviderEntry> entries,
  String name,
) {
  final spec = resolveCliProviderSpec(name);
  if (spec?.kind == 'chatgpt-codex') {
    // The kind itself (`chatgpt` / `chatgpt-codex`): the saved entry is
    // located by its apiType, first match.
    for (final entry in entries) {
      if (resolveCliProviderSpec(entry.apiType)?.kind == 'chatgpt-codex') {
        return entry;
      }
    }
    return null;
  }
  final entry = CustomProviderRegistry(entries).find(name);
  if (entry == null) return null;
  return resolveCliProviderSpec(entry.apiType)?.kind == 'chatgpt-codex'
      ? entry
      : null;
}