refactor(server): use feature model (#9932)

This commit is contained in:
forehalo
2025-02-05 10:27:26 +00:00
parent 0ff8d3af6f
commit 7826e2b7c8
121 changed files with 1723 additions and 3826 deletions
@@ -12,8 +12,8 @@ import {
CopilotSessionNotFound,
PrismaTransaction,
} from '../../base';
import { FeatureManagementService } from '../../core/features';
import { QuotaService } from '../../core/quota';
import { Models } from '../../models';
import { ChatMessageCache } from './message';
import { PromptService } from './prompt';
import {
@@ -195,10 +195,10 @@ export class ChatSessionService {
constructor(
private readonly db: PrismaClient,
private readonly feature: FeatureManagementService,
private readonly quota: QuotaService,
private readonly messageCache: ChatMessageCache,
private readonly prompt: PromptService
private readonly prompt: PromptService,
private readonly models: Models
) {}
private async haveSession(
@@ -545,12 +545,15 @@ export class ChatSessionService {
}
async getQuota(userId: string) {
const isCopilotUser = await this.feature.isCopilotUser(userId);
const isCopilotUser = await this.models.userFeature.has(
userId,
'unlimited_copilot'
);
let limit: number | undefined;
if (!isCopilotUser) {
const quota = await this.quota.getUserQuota(userId);
limit = quota.feature.copilotActionLimit;
limit = quota.copilotActionLimit;
}
const used = await this.countUserMessages(userId);