MCPcopy
hub / github.com/CodebuffAI/codebuff / getFreebuffSession

Function getFreebuffSession

web/src/app/api/v1/freebuff/session/_handlers.ts:273–319  ·  view source on GitHub ↗
(
  req: NextRequest,
  deps: FreebuffSessionDeps,
)

Source from the content-addressed store, hash-verified

271 * caller's instance id (via X-Freebuff-Instance-Id) is used to detect
272 * takeover by another CLI on the same account. */
273export async function getFreebuffSession(
274 req: NextRequest,
275 deps: FreebuffSessionDeps,
276): Promise<NextResponse> {
277 const auth = await resolveUser(req, deps)
278 if ('error' in auth) return auth.error
279
280 try {
281 const countryAccess = await getCountryAccess(auth.userId, req, deps)
282 logCountryAccess('GET', auth.userId, countryAccess, deps)
283 if (shouldHardBlockFreeModeAccess(countryAccess)) {
284 await endSessionForHardBlock(auth, deps)
285 return hardBlockedResponse(countryAccess)
286 }
287 const accessTier = getFreeModeAccessTier(countryAccess)
288
289 const claimedInstanceId =
290 req.headers.get(FREEBUFF_INSTANCE_HEADER) ?? undefined
291 const state = await getSessionState({
292 userId: auth.userId,
293 accessTier,
294 userEmail: auth.userEmail,
295 userBanned: auth.userBanned,
296 claimedInstanceId,
297 deps: deps.sessionDeps,
298 })
299 if (state.status === 'none') {
300 return NextResponse.json(
301 {
302 status: 'none',
303 accessTier: state.accessTier,
304 message: 'Call POST to join the waiting room.',
305 queueDepthByModel: state.queueDepthByModel,
306 rateLimitsByModel: state.rateLimitsByModel,
307 ...toLimitedModeReason(countryAccess),
308 },
309 { status: 200 },
310 )
311 }
312 // banned is terminal; 403 for the same reason as country_blocked — older
313 // CLIs that don't know this status treat it as a generic error.
314 const status = state.status === 'banned' ? 403 : 200
315 return NextResponse.json(state, { status })
316 } catch (error) {
317 return serverError(deps, 'GET', auth.userId, error)
318 }
319}
320
321/** DELETE /api/v1/freebuff/session — end session / leave queue immediately. */
322export async function deleteFreebuffSession(

Callers 2

GETFunction · 0.90
session.test.tsFile · 0.90

Calls 11

getFreeModeAccessTierFunction · 0.90
getSessionStateFunction · 0.90
resolveUserFunction · 0.85
getCountryAccessFunction · 0.85
logCountryAccessFunction · 0.85
endSessionForHardBlockFunction · 0.85
hardBlockedResponseFunction · 0.85
toLimitedModeReasonFunction · 0.85
serverErrorFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected