feat: remove all ai transcription related code and schema

This commit is contained in:
yiling
2026-05-28 14:23:02 +08:00
parent 721a9c13d7
commit 5173bb2a01
25 changed files with 38 additions and 281 deletions
@@ -0,0 +1,24 @@
/*
Warnings:
- The values [transcription] on the enum `AgentType` will be removed. If these variants are still used in the database, this will fail.
- The values [ai_transcription] on the enum `WorkflowTaskType` will be removed. If these variants are still used in the database, this will fail.
*/
-- AlterEnum
BEGIN;
CREATE TYPE "AgentType_new" AS ENUM ('chat', 'autofill', 'embedding');
ALTER TABLE "agents" ALTER COLUMN "type" TYPE "AgentType_new" USING ("type"::text::"AgentType_new");
ALTER TYPE "AgentType" RENAME TO "AgentType_old";
ALTER TYPE "AgentType_new" RENAME TO "AgentType";
DROP TYPE "public"."AgentType_old";
COMMIT;
-- AlterEnum
BEGIN;
CREATE TYPE "WorkflowTaskType_new" AS ENUM ('transcode', 'ai_metadata_autofill', 'chat', 'ai_embedding');
ALTER TABLE "workflow_tasks" ALTER COLUMN "type" TYPE "WorkflowTaskType_new" USING ("type"::text::"WorkflowTaskType_new");
ALTER TYPE "WorkflowTaskType" RENAME TO "WorkflowTaskType_old";
ALTER TYPE "WorkflowTaskType_new" RENAME TO "WorkflowTaskType";
DROP TYPE "public"."WorkflowTaskType_old";
COMMIT;
-2
View File
@@ -101,7 +101,6 @@ enum TeamMemberScope {
enum WorkflowTaskType {
transcode
ai_metadata_autofill
ai_transcription
chat
ai_embedding
}
@@ -626,7 +625,6 @@ enum AgentType {
chat
autofill
embedding
transcription
}
model Agent {
+1 -2
View File
@@ -123,9 +123,8 @@ async function sync() {
const outPath = path.join(generatedDir, 'providers.generated.ts')
const outContent = `// This file is auto-generated by scripts/generate-builtin-providers.ts
// Do not edit manually - run 'bun run generate-providers' to update
import type { ProviderConfig } from '@mariozechner/pi-coding-agent'
export const builtinProviders: Record<string, ProviderConfig> = ${JSON.stringify(providers, null, 2)} as unknown as Record<string, ProviderConfig>
export const builtinProviders: Record<string, any> = ${JSON.stringify(providers, null, 2)} as unknown as Record<string, any>
`
fs.writeFileSync(outPath, outContent)
console.log(`Successfully generated builtin providers: ${outPath}`)
+1 -1
View File
@@ -1,6 +1,6 @@
import { z } from 'zod'
export const agentTypeSchema = z.enum(['chat', 'autofill', 'embedding', 'transcription'])
export const agentTypeSchema = z.enum(['chat', 'autofill', 'embedding'])
export type AgentType = z.infer<typeof agentTypeSchema>
export const agentSkillSchema = z.object({
-1
View File
@@ -11,7 +11,6 @@ export const aiProviderSettingsSchema = z.object({
apiKey: z.string().optional(),
baseUrl: z.string().optional(),
chatModels: z.array(z.string()).optional(),
transcribeModels: z.array(z.string()).optional(),
})
export type AiProviderSettings = z.infer<typeof aiProviderSettingsSchema>
+1 -3
View File
@@ -127,7 +127,6 @@ export type TeamMemberScope = (typeof TeamMemberScope)[keyof typeof TeamMemberSc
export const WorkflowTaskType = {
transcode: 'transcode',
ai_metadata_autofill: 'ai_metadata_autofill',
ai_transcription: 'ai_transcription',
chat: 'chat',
ai_embedding: 'ai_embedding'
} as const
@@ -148,8 +147,7 @@ export type WorkflowTaskStatus = (typeof WorkflowTaskStatus)[keyof typeof Workfl
export const AgentType = {
chat: 'chat',
autofill: 'autofill',
embedding: 'embedding',
transcription: 'transcription'
embedding: 'embedding'
} as const
export type AgentType = (typeof AgentType)[keyof typeof AgentType]
File diff suppressed because one or more lines are too long
+2 -3
View File
@@ -1,8 +1,7 @@
// This file is auto-generated by scripts/generate-builtin-providers.ts
// Do not edit manually - run 'bun run generate-providers' to update
import type { ProviderConfig } from '@mariozechner/pi-coding-agent'
export const builtinProviders: Record<string, ProviderConfig> = {
export const builtinProviders: Record<string, any> = {
"openai": {
"name": "openai",
"config": {
@@ -18415,4 +18414,4 @@ export const builtinProviders: Record<string, ProviderConfig> = {
}
]
}
} as unknown as Record<string, ProviderConfig>
} as unknown as Record<string, any>
-1
View File
@@ -41,7 +41,6 @@ declare global {
apiKey?: string
baseUrl?: string
chatModels?: string[]
transcribeModels?: string[]
}
// ----------------------------------------------------------------------
+2 -2
View File
@@ -25,7 +25,7 @@ export class AgentService {
skills,
} = params
if (type === 'embedding' || type === 'transcription' || type === 'autofill') {
if (type === 'embedding' || type === 'autofill') {
const existing = await this.prismaClient.agent.findFirst({
where: {
type,
@@ -129,7 +129,7 @@ export class AgentService {
if (!agent) throw new Error('agent not found')
if (type === 'embedding' || type === 'transcription' || type === 'autofill') {
if (type === 'embedding' || type === 'autofill') {
const existing = await this.prismaClient.agent.findFirst({
where: {
type,
-9
View File
@@ -24,15 +24,6 @@ export class ElevenLabsProvider implements Provider {
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async transcribe(model: string, _audioBuffer: Buffer): Promise<{ text: string; usage: Usage }> {
// TODO: Implement ElevenLabs transcribe
return {
text: 'elevenlabs transcription',
usage: { model, inputTokens: 0, outputTokens: 0 },
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async generateImageEmbedding(_model: string, _imageBuffer: Buffer): Promise<number[]> {
throw new Error('Not implemented')
-9
View File
@@ -67,15 +67,6 @@ export class GeminiProvider implements Provider {
return { text: result.text || '', usage }
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async transcribe(model: string, _audioBuffer: Buffer): Promise<{ text: string; usage: Usage }> {
// TODO: Implement Gemini transcribe
return {
text: 'gemini transcription',
usage: { model, inputTokens: 0, outputTokens: 0 },
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async generateImageEmbedding(_model: string, _imageBuffer: Buffer): Promise<number[]> {
throw new Error('Not implemented')
-9
View File
@@ -76,15 +76,6 @@ export class OpenAiProvider implements Provider {
return { text: chat.choices[0].message.content || '', usage }
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async transcribe(model: string, _audioBuffer: Buffer): Promise<{ text: string; usage: Usage }> {
// TODO: Implement OpenAI transcribe
return {
text: 'openai transcription',
usage: { model, inputTokens: 0, outputTokens: 0 },
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async generateImageEmbedding(_model: string, _imageBuffer: Buffer): Promise<number[]> {
throw new Error('Not implemented')
-2
View File
@@ -13,8 +13,6 @@ export interface Provider {
schema?: any,
): Promise<{ text: string; usage: Usage }>
transcribe(model: string, audioBuffer: Buffer): Promise<{ text: string; usage: Usage }>
generateImageEmbedding(model: string, imageBuffer: Buffer): Promise<number[]>
generateVideoEmbedding(model: string, videoBuffer: Buffer): Promise<number[]>
-24
View File
@@ -262,30 +262,6 @@ export class UploadService {
})
}
const transcriptionAgent = await tx.agent.findFirst({
where: {
type: 'transcription',
enabled: true,
user: { teamMembers: { some: { teamId: team.id } } },
},
})
if (transcriptionAgent) {
await tx.workflowTask.create({
data: {
assetId: asset.id,
type: WorkflowTaskType.ai_transcription,
status: WorkflowTaskStatus.pending,
teamId: team.id,
projectId: asset.projectId,
payload: {
projectId: asset.projectId!,
agent: { agentId: transcriptionAgent.id },
},
},
})
}
// Ai Embedding if enabled via agent
const embeddingAgent = await tx.agent.findFirst({
where: {
-1
View File
@@ -40,7 +40,6 @@ const AI_PLACEHOLDERS: Record<string, string> = {
__CHAT__: 'Generating...',
__AUTOFILL__: 'Autofilling metadata...',
__EMBEDDING__: 'Generating embeddings...',
__TRANSCRIPTION__: 'Transcribing...',
__RUNNING__: 'Generating...',
}
@@ -40,7 +40,7 @@ interface AgentFormDialogProps {
const agentFormSchema = z.object({
name: z.string().min(1, 'Name is required'),
type: z.enum(['chat', 'autofill', 'embedding', 'transcription']),
type: z.enum(['chat', 'autofill', 'embedding']),
avatar: z.string().optional(),
providerId: z.string().optional(),
modelId: z.string().optional(),
@@ -268,7 +268,6 @@ export function AgentFormDialog({
<SelectItem value="chat">Chat</SelectItem>
<SelectItem value="autofill">Autofill</SelectItem>
<SelectItem value="embedding">Embedding</SelectItem>
<SelectItem value="transcription">Transcription</SelectItem>
</SelectContent>
</Select>
</Field>
@@ -12,7 +12,6 @@ import {
MessageSquare,
Zap,
Cpu,
Type,
Puzzle,
} from 'lucide-react'
import { useState } from 'react'
@@ -51,7 +50,6 @@ const AGENT_TYPES: {
{ type: 'chat', label: 'Chat', icon: MessageSquare },
{ type: 'autofill', label: 'Autofill', icon: Zap },
{ type: 'embedding', label: 'Embedding', icon: Cpu },
{ type: 'transcription', label: 'Transcription', icon: Type },
]
export function AgentsSettings({ teamId }: AgentsSettingsProps) {
@@ -65,7 +63,6 @@ export function AgentsSettings({ teamId }: AgentsSettingsProps) {
chat: true,
autofill: true,
embedding: true,
transcription: true,
})
const { data: agents = [], isLoading } = useQuery({
@@ -229,9 +226,7 @@ export function AgentsSettings({ teamId }: AgentsSettingsProps) {
</div>
<div className="flex items-center gap-2">
{!(
(section.type === 'autofill' ||
section.type === 'transcription' ||
section.type === 'embedding') &&
(section.type === 'autofill' || section.type === 'embedding') &&
typeAgents.length > 0
) && (
<Button
+2 -16
View File
@@ -175,7 +175,7 @@ export async function generateEmbeddingActivity(params: GenerateEmbeddingParams)
export interface ExtractAiMetadataParams {
assetKey: string
filePath: string
type: 'autofill' | 'transcription'
type: 'autofill'
isImage: boolean
}
@@ -190,21 +190,7 @@ export async function extractAiMetadataActivity(
const tmpDir = path.dirname(params.filePath)
try {
if (params.type === 'transcription') {
const targetKey = path.join(aiDir, 'audio.mp3')
try {
await s3Service.headObject(bucket, targetKey)
return [targetKey]
} catch {
// Not found
}
const outputFile = path.join(tmpDir, 'audio.mp3')
await transcodeService.extractAudio(params.filePath, outputFile, '16k')
const buffer = fs.readFileSync(outputFile)
await s3Service.putObject(bucket, targetKey, buffer, buffer.length, 'audio/mpeg')
generatedFiles.push(targetKey)
} else if (params.type === 'autofill') {
if (params.type === 'autofill') {
const targetKey = path.join(aiDir, '1.webp')
try {
await s3Service.headObject(bucket, targetKey)
+2 -2
View File
@@ -11,7 +11,7 @@ describe('Task Activities', () => {
const task = await prisma.workflowTask.create({
data: {
assetId: 'asset-1',
type: WorkflowTaskType.ai_transcription,
type: WorkflowTaskType.ai_embedding,
status: WorkflowTaskStatus.pending,
},
})
@@ -48,7 +48,7 @@ describe('Task Activities', () => {
const task = await prisma.workflowTask.create({
data: {
assetId: 'asset-1',
type: WorkflowTaskType.ai_transcription,
type: WorkflowTaskType.ai_embedding,
status: WorkflowTaskStatus.pending,
},
})
-4
View File
@@ -1,7 +1,6 @@
import { prisma } from '@/db'
import { WorkflowTask, WorkflowTaskStatus, WorkflowTaskType } from '@/generated/prisma/client'
import { Executor } from './executor'
import { aiTranscriptionMedia } from './workflows/ai-transcription'
import { agentEmbeddingMedia } from './workflows/agent-embedding'
import { agentAutofillMedia } from './workflows/agent-autofill'
import { agentChat } from './workflows/agent-chat'
@@ -83,9 +82,6 @@ export class LocalExecutor implements Executor {
try {
switch (task.type) {
case WorkflowTaskType.ai_transcription:
await aiTranscriptionMedia(task)
break
case WorkflowTaskType.ai_embedding:
await agentEmbeddingMedia(task)
break
-3
View File
@@ -16,9 +16,6 @@ export class TemporalExecutor implements Executor {
let workflowName: string
switch (task.type) {
case WorkflowTaskType.ai_transcription:
workflowName = 'aiTranscriptionWorkflow'
break
case WorkflowTaskType.ai_embedding:
workflowName = 'agentEmbeddingWorkflow'
break
-50
View File
@@ -2,7 +2,6 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { prisma } from '@/db'
import { workflowService } from './workflow'
import { WorkflowTaskStatus, WorkflowTaskType } from '@/generated/prisma/client'
import { s3Service } from '@/services/s3/s3'
vi.mock('@/services/s3/s3', () => ({
s3Service: {
@@ -41,55 +40,6 @@ describe('WorkflowService', () => {
workflowService.close()
})
it('should process ai_transcription task locally', async () => {
vi.mocked(s3Service.getObject).mockResolvedValue({
buffer: Buffer.from('fake data'),
contentType: 'audio/mpeg',
})
const team = await prisma.team.create({
data: { name: 'Transcription Team' },
})
const project = await prisma.project.create({
data: { name: 'Transcription Project', teamId: team.id },
})
const asset = await prisma.asset.create({
data: {
name: 'test.mp3',
storageKey: { create: { key: 'test/test.mp3' } },
status: 'uploaded',
type: 'file',
project: { connect: { id: project.id } },
},
})
const task = await prisma.workflowTask.create({
data: {
assetId: asset.id,
type: WorkflowTaskType.ai_transcription,
status: WorkflowTaskStatus.pending,
},
})
expect(task.id).toBeDefined()
let completedTask = null
for (let i = 0; i < 20; i++) {
completedTask = await prisma.workflowTask.findUnique({
where: { id: task.id },
})
if (completedTask?.status === WorkflowTaskStatus.completed) {
break
}
if (completedTask?.status === WorkflowTaskStatus.failed) {
throw new Error(`Task failed: ${JSON.stringify(completedTask.output)}`)
}
await new Promise((resolve) => setTimeout(resolve, 500))
}
expect(completedTask?.status).toBe(WorkflowTaskStatus.completed)
}, 15000)
it('should process ai_embedding task locally', async () => {
const team = await prisma.team.create({
data: { name: 'Embedding Team' },
-127
View File
@@ -1,127 +0,0 @@
import { ApplicationFailure } from '@temporalio/workflow'
import type { WorkflowTask } from '@/generated/prisma/client'
import {
getActivities,
executeActivity,
TaskQueueDb,
TaskQueueTranscode,
sleep,
} from '../workflow-utils'
export async function aiTranscriptionMedia(task: WorkflowTask): Promise<void> {
const {
updateTaskStatusActivity,
getAssetActivity,
extractAiMetadataActivity,
createCommentActivity,
updateCommentActivity,
getTranscodeWorkerQueueActivity,
downloadMediaToTmpActivity,
cleanupTmpDirActivity,
} = getActivities()
let placeholderCommentId: string | undefined
let tmpDir: string | undefined
let transcodeWorkerQueue: string | undefined
try {
// Update status to processing
await executeActivity(TaskQueueDb, updateTaskStatusActivity, {
taskId: task.id,
status: 'processing',
})
// 0. Create Placeholder Comment
const payload = task.payload
const placeholder = await executeActivity(TaskQueueDb, createCommentActivity, {
assetId: task.assetId,
message: '__TRANSCRIPTION__',
sessionId: payload?.agent?.sessionId || task.id,
agentId: payload?.agent?.agentId || 'default',
})
placeholderCommentId = placeholder.id
// 1. Get Asset
const asset = await executeActivity(TaskQueueDb, getAssetActivity, task.assetId)
const key = asset?.storageKey?.key
if (!asset || !key) {
throw ApplicationFailure.create({ message: 'Asset not found', nonRetryable: true })
}
// 2. Extract Audio (Requires FFmpeg)
transcodeWorkerQueue = await executeActivity(
TaskQueueTranscode,
getTranscodeWorkerQueueActivity,
)
const download = await executeActivity(transcodeWorkerQueue, downloadMediaToTmpActivity, {
assetKey: key,
})
const { filePath } = download
tmpDir = download.tmpDir
const generatedFiles = await executeActivity(transcodeWorkerQueue, extractAiMetadataActivity, {
assetKey: key,
filePath,
type: 'transcription',
isImage: false,
})
if (generatedFiles.length === 0) {
throw ApplicationFailure.create({
message: 'Failed to extract audio for transcription',
nonRetryable: true,
})
}
// Simulate work
await sleep(2000)
// 7. Update Placeholder Comment
if (placeholderCommentId) {
await executeActivity(TaskQueueDb, updateCommentActivity, {
commentId: placeholderCommentId,
message: 'Transcription completed successfully.',
})
}
// Update status to completed
await executeActivity(TaskQueueDb, updateTaskStatusActivity, {
taskId: task.id,
status: 'completed',
})
} catch (err) {
console.error(`AiTranscriptionMedia failed for task ${task.id}:`, err)
// Update placeholder comment with error message
if (placeholderCommentId) {
try {
await executeActivity(TaskQueueDb, updateCommentActivity, {
commentId: placeholderCommentId,
message: `Transcription failed: ${err instanceof Error ? err.message : String(err)}`,
})
} catch (commentErr) {
console.error('Failed to update error comment:', commentErr)
}
}
// Update status to failed
await executeActivity(TaskQueueDb, updateTaskStatusActivity, {
taskId: task.id,
status: 'failed',
output: { error: err instanceof Error ? err.message : String(err) },
})
throw err
} finally {
if (tmpDir && transcodeWorkerQueue) {
try {
await executeActivity(transcodeWorkerQueue, cleanupTmpDirActivity, { tmpDir })
} catch (cleanupErr) {
console.error('Failed to cleanup tmp dir:', cleanupErr)
}
}
}
}
// For Temporal, we often export as a named workflow
export const aiTranscriptionWorkflow = aiTranscriptionMedia
-1
View File
@@ -1,4 +1,3 @@
export * from './ai-transcription'
export * from './agent-embedding'
export * from './agent-autofill'
export * from './agent-chat'