diff --git a/packages/frontend/core/src/modules/media/entities/audio-transcription-job-store.ts b/packages/frontend/core/src/modules/media/entities/audio-transcription-job-store.ts index 82ad498f3b..3ef75aa6c7 100644 --- a/packages/frontend/core/src/modules/media/entities/audio-transcription-job-store.ts +++ b/packages/frontend/core/src/modules/media/entities/audio-transcription-job-store.ts @@ -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) { diff --git a/packages/frontend/core/src/modules/media/entities/audio-transcription-job.ts b/packages/frontend/core/src/modules/media/entities/audio-transcription-job.ts index 2a5d1a0eea..22fef885c4 100644 --- a/packages/frontend/core/src/modules/media/entities/audio-transcription-job.ts +++ b/packages/frontend/core/src/modules/media/entities/audio-transcription-job.ts @@ -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,