MCPcopy Index your code
hub / github.com/liuup/claude-code-analysis / prefetchFastModeStatus

Function prefetchFastModeStatus

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

Source from the content-addressed store, hash-verified

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

Callers 2

runFunction · 0.85
callFunction · 0.85

Calls 7

isEssentialTrafficOnlyFunction · 0.85
isFastModeEnabledFunction · 0.85
logForDebuggingFunction · 0.85
getAnthropicApiKeyFunction · 0.85
getGlobalConfigFunction · 0.85
doFetchFunction · 0.85
hasProfileScopeFunction · 0.70

Tested by

no test coverage detected