MCPcopy Create free account
hub / github.com/Noumena-Network/code / getApiKeyFromApiKeyHelper

Function getApiKeyFromApiKeyHelper

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

Source from the content-addressed store, hash-verified

541}
542
543export async function getApiKeyFromApiKeyHelper(
544 isNonInteractiveSession: boolean,
545): Promise<string | null> {
546 if (!getConfiguredApiKeyHelper()) return null
547 const ttl = calculateApiKeyHelperTTL()
548 if (_apiKeyHelperCache) {
549 if (Date.now() - _apiKeyHelperCache.timestamp < ttl) {
550 return _apiKeyHelperCache.value
551 }
552 // Stale — return stale value now, refresh in the background.
553 // `??=` banned here by eslint no-nullish-assign-object-call (bun bug).
554 if (!_apiKeyHelperInflight) {
555 _apiKeyHelperInflight = {
556 promise: _runAndCache(
557 isNonInteractiveSession,
558 false,
559 _apiKeyHelperEpoch,
560 ),
561 startedAt: null,
562 }
563 }
564 return _apiKeyHelperCache.value
565 }
566 // Cold cache — deduplicate concurrent calls
567 if (_apiKeyHelperInflight) return _apiKeyHelperInflight.promise
568 _apiKeyHelperInflight = {
569 promise: _runAndCache(isNonInteractiveSession, true, _apiKeyHelperEpoch),
570 startedAt: Date.now(),
571 }
572 return _apiKeyHelperInflight.promise
573}
574
575async function _runAndCache(
576 isNonInteractiveSession: boolean,

Calls 3

calculateApiKeyHelperTTLFunction · 0.85
_runAndCacheFunction · 0.85

Tested by

no test coverage detected