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

Function getApiKeyFromApiKeyHelper

src/utils/auth.ts:469–499  ·  view source on GitHub ↗
(
  isNonInteractiveSession: boolean,
)

Source from the content-addressed store, hash-verified

467}
468
469export async function getApiKeyFromApiKeyHelper(
470 isNonInteractiveSession: boolean,
471): Promise<string | null> {
472 if (!getConfiguredApiKeyHelper()) return null
473 const ttl = calculateApiKeyHelperTTL()
474 if (_apiKeyHelperCache) {
475 if (Date.now() - _apiKeyHelperCache.timestamp < ttl) {
476 return _apiKeyHelperCache.value
477 }
478 // Stale — return stale value now, refresh in the background.
479 // `??=` banned here by eslint no-nullish-assign-object-call (bun bug).
480 if (!_apiKeyHelperInflight) {
481 _apiKeyHelperInflight = {
482 promise: _runAndCache(
483 isNonInteractiveSession,
484 false,
485 _apiKeyHelperEpoch,
486 ),
487 startedAt: null,
488 }
489 }
490 return _apiKeyHelperCache.value
491 }
492 // Cold cache — deduplicate concurrent calls
493 if (_apiKeyHelperInflight) return _apiKeyHelperInflight.promise
494 _apiKeyHelperInflight = {
495 promise: _runAndCache(isNonInteractiveSession, true, _apiKeyHelperEpoch),
496 startedAt: Date.now(),
497 }
498 return _apiKeyHelperInflight.promise
499}
500
501async function _runAndCache(
502 isNonInteractiveSession: boolean,

Callers 3

configureApiKeyHeadersFunction · 0.85
useApiKeyVerificationFunction · 0.85

Calls 3

calculateApiKeyHelperTTLFunction · 0.85
_runAndCacheFunction · 0.85

Tested by

no test coverage detected