()
| 83 | } |
| 84 | |
| 85 | export async function refreshModelCapabilities(): Promise<void> { |
| 86 | if (!isModelCapabilitiesEligible()) return |
| 87 | if (isEssentialTrafficOnly()) return |
| 88 | |
| 89 | try { |
| 90 | const anthropic = await getAnthropicClient({ maxRetries: 1 }) |
| 91 | const betas = isClaudeAISubscriber() ? [OAUTH_BETA_HEADER] : undefined |
| 92 | const parsed: ModelCapability[] = [] |
| 93 | for await (const entry of anthropic.models.list({ betas })) { |
| 94 | const result = ModelCapabilitySchema().safeParse(entry) |
| 95 | if (result.success) parsed.push(result.data) |
| 96 | } |
| 97 | if (parsed.length === 0) return |
| 98 | |
| 99 | const path = getCachePath() |
| 100 | const models = sortForMatching(parsed) |
| 101 | if (isEqual(loadCache(path), models)) { |
| 102 | logForDebugging('[modelCapabilities] cache unchanged, skipping write') |
| 103 | return |
| 104 | } |
| 105 | |
| 106 | await mkdir(getCacheDir(), { recursive: true }) |
| 107 | await writeFile(path, jsonStringify({ models, timestamp: Date.now() }), { |
| 108 | encoding: 'utf-8', |
| 109 | mode: 0o600, |
| 110 | }) |
| 111 | loadCache.cache.delete(path) |
| 112 | logForDebugging(`[modelCapabilities] cached ${models.length} models`) |
| 113 | } catch (error) { |
| 114 | logForDebugging( |
| 115 | `[modelCapabilities] fetch failed: ${error instanceof Error ? error.message : 'unknown'}`, |
| 116 | ) |
| 117 | } |
| 118 | } |
| 119 |
no test coverage detected