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

Function fetchSessionQuotaSnapshot

web/src/server/free-session/public-api.ts:111–138  ·  view source on GitHub ↗
(
  userId: string,
  config: SessionQuotaConfig,
  deps: SessionDeps,
)

Source from the content-addressed store, hash-verified

109}
110
111async function fetchSessionQuotaSnapshot(
112 userId: string,
113 config: SessionQuotaConfig,
114 deps: SessionDeps,
115): Promise<SessionQuotaSnapshot> {
116 const now = nowOf(deps)
117 const day = getZonedDayBounds(now, config.resetTimeZone)
118 const admits = await deps.listRecentPremiumAdmits({
119 userId,
120 since: day.startsAt,
121 models: config.models,
122 accessTier: config.accessTier,
123 })
124 const recentCount = roundSessionUnits(
125 admits.reduce((sum, admit) => sum + admit.sessionUnits, 0),
126 )
127 return {
128 info: {
129 limit: config.limit,
130 period: config.period,
131 resetTimeZone: config.resetTimeZone,
132 resetAt: day.resetsAt.toISOString(),
133 windowHours: config.windowHours,
134 recentCount,
135 },
136 resetsAt: day.resetsAt,
137 }
138}
139
140function toRateLimitInfo(
141 model: string,

Callers 2

fetchRateLimitSnapshotFunction · 0.85
fetchRateLimitsByModelFunction · 0.85

Calls 3

getZonedDayBoundsFunction · 0.90
nowOfFunction · 0.85
roundSessionUnitsFunction · 0.85

Tested by

no test coverage detected