Skip to content

Commit 780c04b

Browse files
authored
fix: let superusers use as many tokens as they like for page insights (#12469)
Signed-off-by: Matt Krick <matt.krick@gmail.com>
1 parent 50a3e82 commit 780c04b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

packages/server/graphql/public/fields/pageInsights.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TeamMemberId from '../../../../client/shared/gqlIds/TeamMemberId'
55
import {USER_AI_TOKENS_MONTHLY_LIMIT} from '../../../postgres/constants'
66
import getKysely from '../../../postgres/getKysely'
77
import {analytics} from '../../../utils/analytics/analytics'
8-
import {getUserId} from '../../../utils/authorization'
8+
import {getUserId, isSuperUser} from '../../../utils/authorization'
99
import {makeMeetingInsightInput} from '../../../utils/makeMeetingInsightInput'
1010
import OpenAIServerManager from '../../../utils/OpenAIServerManager'
1111
import isValid from '../../isValid'
@@ -24,17 +24,19 @@ export const pageInsights: NonNullable<UserResolvers['pageInsights']> = async (
2424
if (meetingIds.length === 0) throw new GraphQLError('No meetings selected')
2525
if (!prompt || prompt.length < 10) throw new GraphQLError('Prompt too short')
2626
const pg = getKysely()
27-
const aiUsage = await pg
28-
.selectFrom('AIRequest')
29-
.select(pg.fn.coalesce(pg.fn.sum<bigint>('tokenCost'), sql`0`).as('tokenUsage'))
30-
.where('userId', '=', viewerId)
31-
.where('createdAt', '>=', sql<Date>`NOW() - INTERVAL '30 days'`)
32-
.executeTakeFirstOrThrow()
33-
const {tokenUsage} = aiUsage
34-
if (Number(tokenUsage) >= USER_AI_TOKENS_MONTHLY_LIMIT) {
35-
throw new GraphQLError(
36-
'You have exceeded your AI request quota. Please contact sales to increase'
37-
)
27+
if (!isSuperUser(authToken)) {
28+
const aiUsage = await pg
29+
.selectFrom('AIRequest')
30+
.select(pg.fn.coalesce(pg.fn.sum<bigint>('tokenCost'), sql`0`).as('tokenUsage'))
31+
.where('userId', '=', viewerId)
32+
.where('createdAt', '>=', sql<Date>`NOW() - INTERVAL '30 days'`)
33+
.executeTakeFirstOrThrow()
34+
const {tokenUsage} = aiUsage
35+
if (Number(tokenUsage) >= USER_AI_TOKENS_MONTHLY_LIMIT) {
36+
throw new GraphQLError(
37+
'You have exceeded your AI request quota. Please contact sales to increase'
38+
)
39+
}
3840
}
3941
const meetings = (await dataLoader.get('newMeetings').loadMany(meetingIds)).filter(isValid)
4042
const teamIds = [...new Set(meetings.map(({teamId}) => teamId))]

0 commit comments

Comments
 (0)