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

Function handleCatalogAdd

apps/kimi-code/src/cli/sub/provider.ts:291–397  ·  view source on GitHub ↗
(
  deps: ProviderDeps,
  providerId: string,
  opts: CatalogAddOptions,
)

Source from the content-addressed store, hash-verified

289 * the catalog's normalized metadata to fill in context limits and capabilities.
290 */
291export async function handleCatalogAdd(
292 deps: ProviderDeps,
293 providerId: string,
294 opts: CatalogAddOptions,
295): Promise<void> {
296 const apiKey = resolveApiKey(opts.apiKey, deps.env);
297 if (apiKey === undefined) {
298 deps.stderr.write(
299 'Missing API key. Pass --api-key <key> or set KIMI_REGISTRY_API_KEY.\n',
300 );
301 deps.exit(1);
302 }
303
304 const url = opts.url ?? DEFAULT_CATALOG_URL;
305 const catalog = await loadCatalogOrExit(deps, url);
306
307 const entry = catalog[providerId];
308 if (entry === undefined) {
309 deps.stderr.write(`Provider "${providerId}" not found in catalog at ${url}.\n`);
310 deps.exit(1);
311 }
312
313 const wire = inferWireType(entry);
314 if (wire === undefined) {
315 deps.stderr.write(`Provider "${providerId}" has an unsupported wire type in the catalog.\n`);
316 deps.exit(1);
317 }
318
319 const models = catalogProviderModels(entry);
320 if (models.length === 0) {
321 deps.stderr.write(`Provider "${providerId}" lists no usable models in this catalog.\n`);
322 deps.exit(1);
323 }
324
325 if (opts.defaultModel !== undefined && !models.some((m) => m.id === opts.defaultModel)) {
326 deps.stderr.write(
327 `Model "${opts.defaultModel}" is not in provider "${providerId}". Run "kimi provider catalog list ${providerId}" to see available ids.\n`,
328 );
329 deps.exit(1);
330 }
331
332 const harness = deps.getHarness();
333 await harness.ensureConfigFile();
334
335 let config = await harness.getConfig();
336
337 // Capture defaults BEFORE `removeProvider`, because that call clears
338 // `defaultModel` when it points at one of this provider's aliases (see
339 // `core-impl.ts removeKimiProvider`). Without this, re-importing an
340 // already-configured provider would lose the user's previously-set default
341 // even when `--default-model` is not supplied.
342 const previousDefaultModel = config.defaultModel;
343 const previousThinking = config.thinking;
344
345 if (config.providers[providerId] !== undefined) {
346 config = await harness.removeProvider(providerId);
347 }
348

Callers 2

provider.test.tsFile · 0.90
registerProviderCommandFunction · 0.85

Calls 12

resolveApiKeyFunction · 0.85
loadCatalogOrExitFunction · 0.85
inferWireTypeFunction · 0.85
catalogProviderModelsFunction · 0.85
catalogBaseUrlFunction · 0.85
applyCatalogProviderFunction · 0.85
writeMethod · 0.65
exitMethod · 0.65
getConfigMethod · 0.65
removeProviderMethod · 0.65
setConfigMethod · 0.65
ensureConfigFileMethod · 0.45

Tested by

no test coverage detected