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

Function prefetchFastModeStatus

src/utils/fastMode.ts:408–539  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

406}
407
408export async function prefetchFastModeStatus(): Promise<void> {
409 // Skip network requests if nonessential traffic is disabled
410 if (isEssentialTrafficOnly()) {
411 return
412 }
413
414 if (!isFastModeEnabled()) {
415 return
416 }
417
418 if (inflightPrefetch) {
419 logForDebugging(
420 'Fast mode prefetch in progress, returning in-flight promise',
421 )
422 return inflightPrefetch
423 }
424
425 // Service key OAuth sessions lack user:profile scope → endpoint 403s.
426 // Resolve orgStatus from cache and bail before burning the throttle window.
427 // API key auth is unaffected.
428 const authRuntime = getAuthRuntime()
429 const initialSession = authRuntime.getCurrentSession()
430 const initialAuth = resolveFastModeFetchAuth(initialSession)
431 if (!initialAuth) {
432 const isAnt = isInternalBuild()
433 const cachedEnabled = getGlobalConfig().penguinModeOrgEnabled === true
434 orgStatus =
435 isAnt || cachedEnabled
436 ? { status: 'enabled' }
437 : { status: 'disabled', reason: 'preference' }
438 return
439 }
440
441 const now = Date.now()
442 if (now - lastPrefetchAt < PREFETCH_MIN_INTERVAL_MS) {
443 logForDebugging('Skipping fast mode prefetch, fetched recently')
444 return
445 }
446 lastPrefetchAt = now
447
448 const fetchWithCurrentAuth = async (): Promise<FastModeResponse> => {
449 const session = await authRuntime.resolveSession({ allowRefresh: true })
450 const auth = resolveFastModeFetchAuth(session)
451 if (!auth) {
452 throw new Error('No auth available')
453 }
454 return fetchFastModeStatus(auth)
455 }
456
457 async function doFetch(): Promise<void> {
458 try {
459 let status: FastModeResponse
460 try {
461 status = await fetchWithCurrentAuth()
462 } catch (err) {
463 const isAuthError =
464 axios.isAxiosError(err) &&
465 (err.response?.status === 401 ||

Callers 2

runStartupPrefetchesFunction · 0.85
callFunction · 0.85

Calls 9

isEssentialTrafficOnlyFunction · 0.85
isFastModeEnabledFunction · 0.85
getAuthRuntimeFunction · 0.85
resolveFastModeFetchAuthFunction · 0.85
isInternalBuildFunction · 0.85
doFetchFunction · 0.85
logForDebuggingFunction · 0.70
getGlobalConfigFunction · 0.70
getCurrentSessionMethod · 0.65

Tested by

no test coverage detected