MCPcopy Index your code
hub / github.com/codeaashu/claude-code / scheduleFromExpiresIn

Function scheduleFromExpiresIn

src/bridge/jwtUtils.ts:147–163  ·  view source on GitHub ↗

* Schedule refresh using an explicit TTL (seconds until expiry) rather * than decoding a JWT's exp claim. Used by callers whose JWT is opaque * (e.g. POST /v1/code/sessions/{id}/bridge returns expires_in directly).

(
    sessionId: string,
    expiresInSeconds: number,
  )

Source from the content-addressed store, hash-verified

145 * (e.g. POST /v1/code/sessions/{id}/bridge returns expires_in directly).
146 */
147 function scheduleFromExpiresIn(
148 sessionId: string,
149 expiresInSeconds: number,
150 ): void {
151 const existing = timers.get(sessionId)
152 if (existing) clearTimeout(existing)
153 const gen = nextGeneration(sessionId)
154 // Clamp to 30s floor — if refreshBufferMs exceeds the server's expires_in
155 // (e.g. very large buffer for frequent-refresh testing, or server shortens
156 // expires_in unexpectedly), unclamped delayMs ≤ 0 would tight-loop.
157 const delayMs = Math.max(expiresInSeconds * 1000 - refreshBufferMs, 30_000)
158 logForDebugging(
159 `[${label}:token] Scheduled token refresh for sessionId=${sessionId} in ${formatDuration(delayMs)} (expires_in=${expiresInSeconds}s, buffer=${refreshBufferMs / 1000}s)`,
160 )
161 const timer = setTimeout(doRefresh, delayMs, sessionId, gen)
162 timers.set(sessionId, timer)
163 }
164
165 async function doRefresh(sessionId: string, gen: number): Promise<void> {
166 let oauthToken: string | undefined

Callers

nothing calls this directly

Calls 6

nextGenerationFunction · 0.85
logForDebuggingFunction · 0.85
maxMethod · 0.80
formatDurationFunction · 0.70
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected