feat(core): allow retry transcription (#11416)

This commit is contained in:
pengx17
2025-04-02 14:05:12 +00:00
parent c5c6978136
commit 2adb8e1404
2 changed files with 24 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import {
claimAudioTranscriptionMutation,
getAudioTranscriptionQuery,
retryAudioTranscriptionMutation,
submitAudioTranscriptionMutation,
} from '@affine/graphql';
import { Entity } from '@toeverything/infra';
@@ -55,6 +56,24 @@ export class AudioTranscriptionJobStore extends Entity<{
return response.submitAudioTranscription;
};
retryAudioTranscription = async (jobId: string) => {
const graphqlService = this.graphqlService;
if (!graphqlService) {
throw new Error('No graphql service available');
}
const response = await graphqlService.gql({
query: retryAudioTranscriptionMutation,
variables: {
jobId,
workspaceId: this.currentWorkspaceId,
},
});
if (!response.retryAudioTranscription) {
throw new Error('Failed to retry audio transcription');
}
return response.retryAudioTranscription;
};
getAudioTranscription = async (blobId: string, jobId?: string) => {
const graphqlService = this.graphqlService;
if (!graphqlService) {

View File

@@ -146,6 +146,11 @@ export class AudioTranscriptionJob extends Entity<{
if (!job) {
logger.debug('No existing job found, submitting new transcription job');
job = await this.store.submitAudioTranscription();
} else if (job.status === AiJobStatus.failed) {
logger.debug('Found existing failed job, retrying', {
jobId: job.id,
});
job = await this.store.retryAudioTranscription(job.id);
} else {
logger.debug('Found existing job', {
jobId: job.id,