(apiKey)
| 86215 | (0, import_fs5.writeFileSync)(MODEL_CACHE_PATH, JSON.stringify(cache, null, 2), "utf8"); |
| 86216 | } catch { |
| 86217 | } |
| 86218 | } |
| 86219 | function isCacheValid(cache) { |
| 86220 | if (!cache) return false; |
| 86221 | return Date.now() - cache.timestamp < CACHE_TTL_MS; |
| 86222 | } |
| 86223 | async function fetchOpenAIModels(apiKey) { |
| 86224 | try { |
| 86225 | const response = await fetch("https://api.openai.com/v1/models", { |
| 86226 | headers: { |
| 86227 | Authorization: `Bearer ${apiKey}` |
| 86228 | } |
| 86229 | }); |
| 86230 | if (!response.ok) { |
| 86231 | return MODEL_LIST.openai; |
| 86232 | } |
| 86233 | const data = await response.json(); |
| 86234 | const models = data.data.map((m5) => m5.id).filter( |
| 86235 | (id) => id.startsWith("gpt-") || id.startsWith("o1") || id.startsWith("o3") || id.startsWith("o4") |
| 86236 | ).sort(); |
| 86237 | return models.length > 0 ? models : MODEL_LIST.openai; |
| 86238 | } catch { |
no test coverage detected
searching dependent graphs…