MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / attachRateLimit

Function attachRateLimit

web/src/server/free-session/public-api.ts:508–542  ·  view source on GitHub ↗

Thread the current quota snapshot onto queued/active/ended views so the * CLI can render "N of M sessions used" — both during the session and on * the post-session banner. Other statuses pass through unchanged. Called on * both POST and GET so the line stays live across polls.

(
  userId: string,
  view: SessionStateResponse,
  deps: SessionDeps,
)

Source from the content-addressed store, hash-verified

506 * the post-session banner. Other statuses pass through unchanged. Called on
507 * both POST and GET so the line stays live across polls. */
508async function attachRateLimit(
509 userId: string,
510 view: SessionStateResponse,
511 deps: SessionDeps,
512): Promise<SessionStateResponse> {
513 if (
514 view.status !== 'queued' &&
515 view.status !== 'active' &&
516 view.status !== 'ended'
517 ) {
518 return view
519 }
520 const accessTier = view.accessTier ?? 'full'
521 const allRateLimitsByModel = await fetchRateLimitsByModel(
522 userId,
523 accessTier,
524 deps,
525 )
526 // The ended view doesn't carry a model id, so it gets the full snapshot
527 // unfiltered — the banner reads any entry's recentCount (they all share the
528 // same daily premium pool). Queued/active filter out unused models so the
529 // landing screen and waiting-room title don't list every premium model with
530 // a "0 used today" hint.
531 if (view.status === 'ended') {
532 return { ...view, rateLimitsByModel: allRateLimitsByModel }
533 }
534 const rateLimit = allRateLimitsByModel[view.model]
535 return {
536 ...view,
537 ...(rateLimit ? { rateLimit } : {}),
538 ...nonEmptyRateLimitsByModel(
539 onlyUsedRateLimitsByModel(allRateLimitsByModel),
540 ),
541 }
542}
543
544/**
545 * Check of the caller's current state. Does not rotate `instance_id`. The CLI

Callers 2

requestSessionFunction · 0.85
getSessionStateFunction · 0.85

Calls 3

fetchRateLimitsByModelFunction · 0.85

Tested by

no test coverage detected