MCPcopy Create free account
hub / github.com/ACM-VIT/conclave / takeTranscriptRateLimit

Function takeTranscriptRateLimit

apps/web/transcript-worker/src/rate-limit.ts:29–47  ·  view source on GitHub ↗
(
  state: TranscriptRateLimitState,
  bucket: TranscriptRateBucketName,
  now = Date.now(),
)

Source from the content-addressed store, hash-verified

27 qa: { max: 10, windowMs: 60_000 },
28 session: { max: 8, windowMs: 60_000 },
29};
30
31export const takeTranscriptRateLimit = (
32 state: TranscriptRateLimitState,
33 bucket: TranscriptRateBucketName,
34 now = Date.now(),
35): boolean => {
36 const limit = limits[bucket];
37 const current = state[bucket];
38 if (!current || current.resetAt <= now) {
39 state[bucket] = {
40 count: 1,
41 resetAt: now + limit.windowMs,
42 };
43 return true;
44 }
45
46 if (current.count >= limit.max) return false;
47 current.count += 1;
48 return true;
49};

Callers 2

handleMessageMethod · 0.90

Calls 1

nowMethod · 0.80

Tested by

no test coverage detected