MCPcopy
hub / github.com/codeaashu/claude-code / refreshModelCapabilities

Function refreshModelCapabilities

src/utils/model/modelCapabilities.ts:85–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83}
84
85export 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

Callers 1

startDeferredPrefetchesFunction · 0.85

Calls 13

isEssentialTrafficOnlyFunction · 0.85
getAnthropicClientFunction · 0.85
sortForMatchingFunction · 0.85
logForDebuggingFunction · 0.85
mkdirFunction · 0.85
getCacheDirFunction · 0.85
jsonStringifyFunction · 0.85
getCachePathFunction · 0.70
listMethod · 0.65
deleteMethod · 0.65
isClaudeAISubscriberFunction · 0.50

Tested by

no test coverage detected