MCPcopy
hub / github.com/lingodotdev/lingo.dev / validateLLMKeyDetails

Function validateLLMKeyDetails

packages/compiler/src/index.ts:403–509  ·  view source on GitHub ↗

* Print helpful information about where the LLM API keys for configured providers * were discovered. The compiler looks for the key first in the environment * (incl. .env files) and then in the user-wide configuration. Environment always wins. * @param configuredProviders List of provider IDs det

(configuredProviders: string[])

Source from the content-addressed store, hash-verified

401 * @param configuredProviders List of provider IDs detected in the configuration.
402 */
403function validateLLMKeyDetails(configuredProviders: string[]): void {
404 if (configuredProviders.length === 0) {
405 // No LLM providers configured that we can validate keys for.
406 return;
407 }
408
409 const keyStatuses: Record<
410 string,
411 {
412 foundInEnv: boolean;
413 foundInRc: boolean;
414 details: (typeof providerDetails)[string];
415 }
416 > = {};
417 const missingProviders: string[] = [];
418 const foundProviders: string[] = [];
419
420 for (const providerId of configuredProviders) {
421 const details = providerDetails[providerId];
422 const checkers = keyCheckers[providerId];
423 if (!details || !checkers) continue; // Should not happen due to filter above
424
425 const foundInEnv = !!checkers.checkEnv();
426 const foundInRc = !!checkers.checkRc();
427
428 keyStatuses[providerId] = { foundInEnv, foundInRc, details };
429
430 if (!foundInEnv && !foundInRc) {
431 missingProviders.push(providerId);
432 } else {
433 foundProviders.push(providerId);
434 }
435 }
436
437 if (missingProviders.length > 0) {
438 console.log(dedent`
439 \n
440 💡 Lingo.dev Localization Compiler is configured to use the following LLM provider(s): ${configuredProviders.join(
441 ", ",
442 )}.
443
444 The compiler requires API keys for these providers to work, but the following keys are missing:
445 `);
446
447 for (const providerId of missingProviders) {
448 const status = keyStatuses[providerId];
449 if (!status) continue;
450 console.log(dedent`
451 ⚠️ ${status.details.name} API key is missing. Set ${
452 status.details.apiKeyEnvVar
453 } environment variable.
454
455 👉 You can set the API key in one of the following ways:
456 1. User-wide: Run npx lingo.dev@latest config set ${
457 status.details.apiKeyConfigKey || "<config-key-not-available>"
458 } <your-api-key>
459 2. Project-wide: Add ${
460 status.details.apiKeyEnvVar

Callers 1

index.tsFile · 0.85

Calls 2

logMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected