MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / refreshProviderModels

Function refreshProviderModels

packages/oauth/src/refreshProviderModels.ts:344–652  ·  view source on GitHub ↗
(
  host: RefreshProviderHost,
  options: RefreshProviderOptions = {},
)

Source from the content-addressed store, hash-verified

342 * single provider; pass `scope: 'oauth'` to refresh only the managed provider.
343 */
344export async function refreshProviderModels(
345 host: RefreshProviderHost,
346 options: RefreshProviderOptions = {},
347): Promise<RefreshResult> {
348 const changed: ProviderChange[] = [];
349 const unchanged: string[] = [];
350 const failed: Array<{ provider: string; reason: string }> = [];
351 const scope = options.scope ?? 'all';
352 const targetId = options.providerId;
353
354 let config = await host.getConfig();
355
356 // ---------------------------------------------------------------------------
357 // 1. Managed Kimi Code (OAuth)
358 // ---------------------------------------------------------------------------
359 const managedProvider = readProvider(config, KIMI_CODE_PROVIDER_NAME);
360 const managedWanted = targetId === undefined || targetId === KIMI_CODE_PROVIDER_NAME;
361 if (
362 managedWanted &&
363 managedProvider !== undefined &&
364 managedProvider.type === 'kimi' &&
365 managedProvider.oauth !== undefined
366 ) {
367 try {
368 const auth = resolveKimiCodeRuntimeAuth({
369 configuredBaseUrl: managedProvider.baseUrl,
370 configuredOAuthRef: managedProvider.oauth,
371 });
372 const accessToken = await host.resolveOAuthToken(KIMI_CODE_PROVIDER_NAME, auth.oauthRef);
373 const models = await fetchManagedKimiCodeModels({
374 accessToken,
375 baseUrl: auth.baseUrl,
376 });
377 if (models.length > 0) {
378 const next = structuredClone(config);
379 applyManagedKimiCodeConfig(next, {
380 models,
381 baseUrl: auth.baseUrl,
382 oauthKey: auth.oauthRef.key,
383 oauthHost: auth.oauthRef.oauthHost,
384 preserveDefaultModel: true,
385 });
386 const refreshedAliasKeys = providerRefreshAliasKeys(
387 config,
388 next,
389 KIMI_CODE_PROVIDER_NAME,
390 `${KIMI_CODE_PLATFORM_ID}/`,
391 );
392 restoreProviderAliases(
393 next,
394 preserveUserProviderAliases(config, KIMI_CODE_PROVIDER_NAME, refreshedAliasKeys),
395 );
396 restoreDefaultSelection(next, config.defaultModel, config.thinking?.enabled);
397 clampDanglingDefault(next);
398 clearDefaultThinkingWhenDefaultRemoved(next, config.defaultModel);
399
400 if (providerModelsEqual(config, next, KIMI_CODE_PROVIDER_NAME, refreshedAliasKeys)) {
401 unchanged.push(KIMI_CODE_PROVIDER_NAME);

Callers 2

refreshAllProviderModelsFunction · 0.85

Calls 15

isOpenPlatformIdFunction · 0.90
getOpenPlatformByIdFunction · 0.90
fetchOpenPlatformModelsFunction · 0.90
filterModelsByPrefixFunction · 0.90
applyOpenPlatformConfigFunction · 0.90
readProviderFunction · 0.85
providerRefreshAliasKeysFunction · 0.85

Tested by

no test coverage detected