mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 06:54:28 +00:00
Merge pull request #31 from shumaiOne/remove-ai-transcription
feat: remove AI transcription functionality
This commit is contained in:
@@ -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;
|
||||||
@@ -101,7 +101,6 @@ enum TeamMemberScope {
|
|||||||
enum WorkflowTaskType {
|
enum WorkflowTaskType {
|
||||||
transcode
|
transcode
|
||||||
ai_metadata_autofill
|
ai_metadata_autofill
|
||||||
ai_transcription
|
|
||||||
chat
|
chat
|
||||||
ai_embedding
|
ai_embedding
|
||||||
}
|
}
|
||||||
@@ -626,7 +625,6 @@ enum AgentType {
|
|||||||
chat
|
chat
|
||||||
autofill
|
autofill
|
||||||
embedding
|
embedding
|
||||||
transcription
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model Agent {
|
model Agent {
|
||||||
|
|||||||
@@ -123,9 +123,8 @@ async function sync() {
|
|||||||
const outPath = path.join(generatedDir, 'providers.generated.ts')
|
const outPath = path.join(generatedDir, 'providers.generated.ts')
|
||||||
const outContent = `// This file is auto-generated by scripts/generate-builtin-providers.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
|
// 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)
|
fs.writeFileSync(outPath, outContent)
|
||||||
console.log(`Successfully generated builtin providers: ${outPath}`)
|
console.log(`Successfully generated builtin providers: ${outPath}`)
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import { z } from 'zod'
|
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 type AgentType = z.infer<typeof agentTypeSchema>
|
||||||
|
|
||||||
export const agentSkillSchema = z.object({
|
export const agentSkillSchema = z.object({
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ export const aiProviderSettingsSchema = z.object({
|
|||||||
apiKey: z.string().optional(),
|
apiKey: z.string().optional(),
|
||||||
baseUrl: z.string().optional(),
|
baseUrl: z.string().optional(),
|
||||||
chatModels: z.array(z.string()).optional(),
|
chatModels: z.array(z.string()).optional(),
|
||||||
transcribeModels: z.array(z.string()).optional(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export type AiProviderSettings = z.infer<typeof aiProviderSettingsSchema>
|
export type AiProviderSettings = z.infer<typeof aiProviderSettingsSchema>
|
||||||
|
|||||||
Generated
+1
-3
@@ -127,7 +127,6 @@ export type TeamMemberScope = (typeof TeamMemberScope)[keyof typeof TeamMemberSc
|
|||||||
export const WorkflowTaskType = {
|
export const WorkflowTaskType = {
|
||||||
transcode: 'transcode',
|
transcode: 'transcode',
|
||||||
ai_metadata_autofill: 'ai_metadata_autofill',
|
ai_metadata_autofill: 'ai_metadata_autofill',
|
||||||
ai_transcription: 'ai_transcription',
|
|
||||||
chat: 'chat',
|
chat: 'chat',
|
||||||
ai_embedding: 'ai_embedding'
|
ai_embedding: 'ai_embedding'
|
||||||
} as const
|
} as const
|
||||||
@@ -148,8 +147,7 @@ export type WorkflowTaskStatus = (typeof WorkflowTaskStatus)[keyof typeof Workfl
|
|||||||
export const AgentType = {
|
export const AgentType = {
|
||||||
chat: 'chat',
|
chat: 'chat',
|
||||||
autofill: 'autofill',
|
autofill: 'autofill',
|
||||||
embedding: 'embedding',
|
embedding: 'embedding'
|
||||||
transcription: 'transcription'
|
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export type AgentType = (typeof AgentType)[keyof typeof AgentType]
|
export type AgentType = (typeof AgentType)[keyof typeof AgentType]
|
||||||
|
|||||||
Generated
+1
-1
File diff suppressed because one or more lines are too long
Generated
+2
-3
@@ -1,8 +1,7 @@
|
|||||||
// This file is auto-generated by scripts/generate-builtin-providers.ts
|
// This file is auto-generated by scripts/generate-builtin-providers.ts
|
||||||
// Do not edit manually - run 'bun run generate-providers' to update
|
// 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": {
|
"openai": {
|
||||||
"name": "openai",
|
"name": "openai",
|
||||||
"config": {
|
"config": {
|
||||||
@@ -18415,4 +18414,4 @@ export const builtinProviders: Record<string, ProviderConfig> = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
} as unknown as Record<string, ProviderConfig>
|
} as unknown as Record<string, any>
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ declare global {
|
|||||||
apiKey?: string
|
apiKey?: string
|
||||||
baseUrl?: string
|
baseUrl?: string
|
||||||
chatModels?: string[]
|
chatModels?: string[]
|
||||||
transcribeModels?: string[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export class AgentService {
|
|||||||
skills,
|
skills,
|
||||||
} = params
|
} = params
|
||||||
|
|
||||||
if (type === 'embedding' || type === 'transcription' || type === 'autofill') {
|
if (type === 'embedding' || type === 'autofill') {
|
||||||
const existing = await this.prismaClient.agent.findFirst({
|
const existing = await this.prismaClient.agent.findFirst({
|
||||||
where: {
|
where: {
|
||||||
type,
|
type,
|
||||||
@@ -129,7 +129,7 @@ export class AgentService {
|
|||||||
|
|
||||||
if (!agent) throw new Error('agent not found')
|
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({
|
const existing = await this.prismaClient.agent.findFirst({
|
||||||
where: {
|
where: {
|
||||||
type,
|
type,
|
||||||
|
|||||||
@@ -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
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
async generateImageEmbedding(_model: string, _imageBuffer: Buffer): Promise<number[]> {
|
async generateImageEmbedding(_model: string, _imageBuffer: Buffer): Promise<number[]> {
|
||||||
throw new Error('Not implemented')
|
throw new Error('Not implemented')
|
||||||
|
|||||||
@@ -67,15 +67,6 @@ export class GeminiProvider implements Provider {
|
|||||||
return { text: result.text || '', usage }
|
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
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
async generateImageEmbedding(_model: string, _imageBuffer: Buffer): Promise<number[]> {
|
async generateImageEmbedding(_model: string, _imageBuffer: Buffer): Promise<number[]> {
|
||||||
throw new Error('Not implemented')
|
throw new Error('Not implemented')
|
||||||
|
|||||||
@@ -76,15 +76,6 @@ export class OpenAiProvider implements Provider {
|
|||||||
return { text: chat.choices[0].message.content || '', usage }
|
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
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
async generateImageEmbedding(_model: string, _imageBuffer: Buffer): Promise<number[]> {
|
async generateImageEmbedding(_model: string, _imageBuffer: Buffer): Promise<number[]> {
|
||||||
throw new Error('Not implemented')
|
throw new Error('Not implemented')
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ export interface Provider {
|
|||||||
schema?: any,
|
schema?: any,
|
||||||
): Promise<{ text: string; usage: Usage }>
|
): Promise<{ text: string; usage: Usage }>
|
||||||
|
|
||||||
transcribe(model: string, audioBuffer: Buffer): Promise<{ text: string; usage: Usage }>
|
|
||||||
|
|
||||||
generateImageEmbedding(model: string, imageBuffer: Buffer): Promise<number[]>
|
generateImageEmbedding(model: string, imageBuffer: Buffer): Promise<number[]>
|
||||||
|
|
||||||
generateVideoEmbedding(model: string, videoBuffer: Buffer): Promise<number[]>
|
generateVideoEmbedding(model: string, videoBuffer: Buffer): Promise<number[]>
|
||||||
|
|||||||
@@ -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
|
// Ai Embedding if enabled via agent
|
||||||
const embeddingAgent = await tx.agent.findFirst({
|
const embeddingAgent = await tx.agent.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ const AI_PLACEHOLDERS: Record<string, string> = {
|
|||||||
__CHAT__: 'Generating...',
|
__CHAT__: 'Generating...',
|
||||||
__AUTOFILL__: 'Autofilling metadata...',
|
__AUTOFILL__: 'Autofilling metadata...',
|
||||||
__EMBEDDING__: 'Generating embeddings...',
|
__EMBEDDING__: 'Generating embeddings...',
|
||||||
__TRANSCRIPTION__: 'Transcribing...',
|
|
||||||
__RUNNING__: 'Generating...',
|
__RUNNING__: 'Generating...',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ interface AgentFormDialogProps {
|
|||||||
|
|
||||||
const agentFormSchema = z.object({
|
const agentFormSchema = z.object({
|
||||||
name: z.string().min(1, 'Name is required'),
|
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(),
|
avatar: z.string().optional(),
|
||||||
providerId: z.string().optional(),
|
providerId: z.string().optional(),
|
||||||
modelId: z.string().optional(),
|
modelId: z.string().optional(),
|
||||||
@@ -268,7 +268,6 @@ export function AgentFormDialog({
|
|||||||
<SelectItem value="chat">Chat</SelectItem>
|
<SelectItem value="chat">Chat</SelectItem>
|
||||||
<SelectItem value="autofill">Autofill</SelectItem>
|
<SelectItem value="autofill">Autofill</SelectItem>
|
||||||
<SelectItem value="embedding">Embedding</SelectItem>
|
<SelectItem value="embedding">Embedding</SelectItem>
|
||||||
<SelectItem value="transcription">Transcription</SelectItem>
|
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</Field>
|
</Field>
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
MessageSquare,
|
MessageSquare,
|
||||||
Zap,
|
Zap,
|
||||||
Cpu,
|
Cpu,
|
||||||
Type,
|
|
||||||
Puzzle,
|
Puzzle,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
@@ -51,7 +50,6 @@ const AGENT_TYPES: {
|
|||||||
{ type: 'chat', label: 'Chat', icon: MessageSquare },
|
{ type: 'chat', label: 'Chat', icon: MessageSquare },
|
||||||
{ type: 'autofill', label: 'Autofill', icon: Zap },
|
{ type: 'autofill', label: 'Autofill', icon: Zap },
|
||||||
{ type: 'embedding', label: 'Embedding', icon: Cpu },
|
{ type: 'embedding', label: 'Embedding', icon: Cpu },
|
||||||
{ type: 'transcription', label: 'Transcription', icon: Type },
|
|
||||||
]
|
]
|
||||||
|
|
||||||
export function AgentsSettings({ teamId }: AgentsSettingsProps) {
|
export function AgentsSettings({ teamId }: AgentsSettingsProps) {
|
||||||
@@ -65,7 +63,6 @@ export function AgentsSettings({ teamId }: AgentsSettingsProps) {
|
|||||||
chat: true,
|
chat: true,
|
||||||
autofill: true,
|
autofill: true,
|
||||||
embedding: true,
|
embedding: true,
|
||||||
transcription: true,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const { data: agents = [], isLoading } = useQuery({
|
const { data: agents = [], isLoading } = useQuery({
|
||||||
@@ -229,9 +226,7 @@ export function AgentsSettings({ teamId }: AgentsSettingsProps) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{!(
|
{!(
|
||||||
(section.type === 'autofill' ||
|
(section.type === 'autofill' || section.type === 'embedding') &&
|
||||||
section.type === 'transcription' ||
|
|
||||||
section.type === 'embedding') &&
|
|
||||||
typeAgents.length > 0
|
typeAgents.length > 0
|
||||||
) && (
|
) && (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ export async function generateEmbeddingActivity(params: GenerateEmbeddingParams)
|
|||||||
export interface ExtractAiMetadataParams {
|
export interface ExtractAiMetadataParams {
|
||||||
assetKey: string
|
assetKey: string
|
||||||
filePath: string
|
filePath: string
|
||||||
type: 'autofill' | 'transcription'
|
type: 'autofill'
|
||||||
isImage: boolean
|
isImage: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,21 +190,7 @@ export async function extractAiMetadataActivity(
|
|||||||
const tmpDir = path.dirname(params.filePath)
|
const tmpDir = path.dirname(params.filePath)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (params.type === 'transcription') {
|
if (params.type === 'autofill') {
|
||||||
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') {
|
|
||||||
const targetKey = path.join(aiDir, '1.webp')
|
const targetKey = path.join(aiDir, '1.webp')
|
||||||
try {
|
try {
|
||||||
await s3Service.headObject(bucket, targetKey)
|
await s3Service.headObject(bucket, targetKey)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ describe('Task Activities', () => {
|
|||||||
const task = await prisma.workflowTask.create({
|
const task = await prisma.workflowTask.create({
|
||||||
data: {
|
data: {
|
||||||
assetId: 'asset-1',
|
assetId: 'asset-1',
|
||||||
type: WorkflowTaskType.ai_transcription,
|
type: WorkflowTaskType.ai_embedding,
|
||||||
status: WorkflowTaskStatus.pending,
|
status: WorkflowTaskStatus.pending,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -48,7 +48,7 @@ describe('Task Activities', () => {
|
|||||||
const task = await prisma.workflowTask.create({
|
const task = await prisma.workflowTask.create({
|
||||||
data: {
|
data: {
|
||||||
assetId: 'asset-1',
|
assetId: 'asset-1',
|
||||||
type: WorkflowTaskType.ai_transcription,
|
type: WorkflowTaskType.ai_embedding,
|
||||||
status: WorkflowTaskStatus.pending,
|
status: WorkflowTaskStatus.pending,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { prisma } from '@/db'
|
import { prisma } from '@/db'
|
||||||
import { WorkflowTask, WorkflowTaskStatus, WorkflowTaskType } from '@/generated/prisma/client'
|
import { WorkflowTask, WorkflowTaskStatus, WorkflowTaskType } from '@/generated/prisma/client'
|
||||||
import { Executor } from './executor'
|
import { Executor } from './executor'
|
||||||
import { aiTranscriptionMedia } from './workflows/ai-transcription'
|
|
||||||
import { agentEmbeddingMedia } from './workflows/agent-embedding'
|
import { agentEmbeddingMedia } from './workflows/agent-embedding'
|
||||||
import { agentAutofillMedia } from './workflows/agent-autofill'
|
import { agentAutofillMedia } from './workflows/agent-autofill'
|
||||||
import { agentChat } from './workflows/agent-chat'
|
import { agentChat } from './workflows/agent-chat'
|
||||||
@@ -83,9 +82,6 @@ export class LocalExecutor implements Executor {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
switch (task.type) {
|
switch (task.type) {
|
||||||
case WorkflowTaskType.ai_transcription:
|
|
||||||
await aiTranscriptionMedia(task)
|
|
||||||
break
|
|
||||||
case WorkflowTaskType.ai_embedding:
|
case WorkflowTaskType.ai_embedding:
|
||||||
await agentEmbeddingMedia(task)
|
await agentEmbeddingMedia(task)
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ export class TemporalExecutor implements Executor {
|
|||||||
|
|
||||||
let workflowName: string
|
let workflowName: string
|
||||||
switch (task.type) {
|
switch (task.type) {
|
||||||
case WorkflowTaskType.ai_transcription:
|
|
||||||
workflowName = 'aiTranscriptionWorkflow'
|
|
||||||
break
|
|
||||||
case WorkflowTaskType.ai_embedding:
|
case WorkflowTaskType.ai_embedding:
|
||||||
workflowName = 'agentEmbeddingWorkflow'
|
workflowName = 'agentEmbeddingWorkflow'
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|||||||
import { prisma } from '@/db'
|
import { prisma } from '@/db'
|
||||||
import { workflowService } from './workflow'
|
import { workflowService } from './workflow'
|
||||||
import { WorkflowTaskStatus, WorkflowTaskType } from '@/generated/prisma/client'
|
import { WorkflowTaskStatus, WorkflowTaskType } from '@/generated/prisma/client'
|
||||||
import { s3Service } from '@/services/s3/s3'
|
|
||||||
|
|
||||||
vi.mock('@/services/s3/s3', () => ({
|
vi.mock('@/services/s3/s3', () => ({
|
||||||
s3Service: {
|
s3Service: {
|
||||||
@@ -41,55 +40,6 @@ describe('WorkflowService', () => {
|
|||||||
workflowService.close()
|
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 () => {
|
it('should process ai_embedding task locally', async () => {
|
||||||
const team = await prisma.team.create({
|
const team = await prisma.team.create({
|
||||||
data: { name: 'Embedding Team' },
|
data: { name: 'Embedding Team' },
|
||||||
|
|||||||
@@ -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,4 +1,3 @@
|
|||||||
export * from './ai-transcription'
|
|
||||||
export * from './agent-embedding'
|
export * from './agent-embedding'
|
||||||
export * from './agent-autofill'
|
export * from './agent-autofill'
|
||||||
export * from './agent-chat'
|
export * from './agent-chat'
|
||||||
|
|||||||
Reference in New Issue
Block a user