MCPcopy Index your code
hub / github.com/Noumena-Network/code / refreshModelCapabilities

Function refreshModelCapabilities

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

Source from the content-addressed store, hash-verified

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

Callers 1

startDeferredPrefetchesFunction · 0.85

Calls 13

isEssentialTrafficOnlyFunction · 0.85
getInferenceClientFunction · 0.85
sortForMatchingFunction · 0.85
mkdirFunction · 0.85
getCacheDirFunction · 0.85
jsonStringifyFunction · 0.85
deleteMethod · 0.80
getCachePathFunction · 0.70
listModelsMethod · 0.65
getAuthHeadersFunction · 0.50

Tested by

no test coverage detected