mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 16:46:22 +08:00
feat(server): refactor for byok (#14911)
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
sniffMime,
|
||||
} from '../../../base';
|
||||
import { Models } from '../../../models';
|
||||
import { ConversationPolicy } from '../conversation/policy';
|
||||
import { CopilotAccessPolicy } from '../access';
|
||||
import { PromptService } from '../prompt';
|
||||
import { CopilotProviderType } from '../providers/types';
|
||||
import { ActionRuntimeBridge } from '../runtime/action-runtime-bridge';
|
||||
@@ -62,7 +62,7 @@ export class CopilotTranscriptionService {
|
||||
private readonly tasks: TaskPolicy,
|
||||
private readonly prompts: PromptService,
|
||||
private readonly actionBridge: ActionRuntimeBridge,
|
||||
@Optional() private readonly conversationPolicy?: ConversationPolicy
|
||||
@Optional() private readonly access?: CopilotAccessPolicy
|
||||
) {}
|
||||
|
||||
private parseTaskPayload(payload: unknown): TranscriptionPayloadV2 {
|
||||
@@ -223,6 +223,12 @@ export class CopilotTranscriptionService {
|
||||
throw new CopilotTranscriptionJobExists();
|
||||
}
|
||||
|
||||
await this.access?.assertQuotaOrByok({
|
||||
userId,
|
||||
workspaceId,
|
||||
featureKind: 'transcript',
|
||||
});
|
||||
|
||||
const { model, strategy } = await this.resolveTranscriptStrategy(
|
||||
userId,
|
||||
input?.strategy ?? undefined
|
||||
@@ -270,6 +276,12 @@ export class CopilotTranscriptionService {
|
||||
);
|
||||
}
|
||||
|
||||
await this.access?.assertQuotaOrByok({
|
||||
userId,
|
||||
workspaceId,
|
||||
featureKind: 'transcript',
|
||||
});
|
||||
|
||||
const payload = this.parseTaskPayload(task.protectedResult);
|
||||
const { model } = await this.resolveTranscriptStrategy(
|
||||
userId,
|
||||
@@ -307,13 +319,17 @@ export class CopilotTranscriptionService {
|
||||
return null;
|
||||
}
|
||||
|
||||
const settled =
|
||||
task.status === 'settled'
|
||||
? task
|
||||
: await (async () => {
|
||||
await this.conversationPolicy?.checkQuota(userId);
|
||||
return await this.models.copilotTranscriptTask.settle(task.id);
|
||||
})();
|
||||
if (task.status === 'settled') {
|
||||
return this.taskToJob(task);
|
||||
}
|
||||
|
||||
await this.access?.assertQuotaOrByok({
|
||||
userId,
|
||||
workspaceId,
|
||||
featureKind: 'transcript',
|
||||
});
|
||||
|
||||
const settled = await this.models.copilotTranscriptTask.settle(task.id);
|
||||
return this.taskToJob(settled);
|
||||
}
|
||||
|
||||
@@ -378,6 +394,13 @@ export class CopilotTranscriptionService {
|
||||
stepId: 'transcribe',
|
||||
modelId,
|
||||
messages,
|
||||
options: {
|
||||
user: task.userId,
|
||||
workspace: task.workspaceId,
|
||||
taskId,
|
||||
billingUnitId: taskId,
|
||||
featureKind: 'transcript',
|
||||
},
|
||||
prefer: CopilotProviderType.Gemini,
|
||||
responseContract: TranscriptActionResultContract,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user