mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-19 14:16:29 +00:00
Splits monolithic workflow workers into four decoupled workspaces under the Bun workspaces monorepo: - @shumai/workflow-core containing the core execution engine and utilities. - @shumai/agent containing agent-specific logic, workflows, and activities. - @shumai/transcode containing transcoding workflows, transcoder, and transcode activities. - @shumai/worker-db containing database activities. Introduces a dynamic workflow and activity registration pattern on LocalExecutor to eliminate circular dependencies. Updates worker bootstrapping and test suites to cleanly leverage generic workspace modules.
85 lines
1.9 KiB
TypeScript
85 lines
1.9 KiB
TypeScript
import { prisma } from '@shumai/db'
|
|
import { WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
|
|
import '@shumai/db/src/prisma-json-types'
|
|
|
|
type TransactionClient = Omit<
|
|
typeof prisma,
|
|
'$connect' | '$disconnect' | '$on' | '$transaction' | '$use' | '$extends'
|
|
>
|
|
|
|
export class VideoTranscoder {
|
|
private spec: PrismaJson.TaskSpec = {}
|
|
|
|
constructor(
|
|
private readonly db: TransactionClient,
|
|
private readonly assetId: string,
|
|
private readonly teamId: string,
|
|
private readonly projectId: string,
|
|
) {}
|
|
|
|
setStrategy(strategy: PrismaJson.VideoTranscodeStrategy): this {
|
|
this.spec.videoStrategy = strategy
|
|
return this
|
|
}
|
|
|
|
withSprite(): this {
|
|
this.spec.sprite = true
|
|
return this
|
|
}
|
|
|
|
withPoster(): this {
|
|
this.spec.poster = true
|
|
return this
|
|
}
|
|
|
|
async submit(): Promise<string> {
|
|
const task = await this.db.workflowTask.create({
|
|
data: {
|
|
assetId: this.assetId,
|
|
teamId: this.teamId,
|
|
projectId: this.projectId,
|
|
type: WorkflowTaskType.transcode,
|
|
status: WorkflowTaskStatus.pending,
|
|
payload: {
|
|
projectId: this.projectId,
|
|
transcode: this.spec,
|
|
},
|
|
},
|
|
})
|
|
return task.id
|
|
}
|
|
}
|
|
|
|
export class ImageTranscoder {
|
|
private spec: PrismaJson.TaskSpec = {}
|
|
|
|
constructor(
|
|
private readonly db: TransactionClient,
|
|
private readonly assetId: string,
|
|
private readonly teamId: string,
|
|
private readonly projectId: string,
|
|
) {}
|
|
|
|
withThumbnail(): this {
|
|
this.spec.thumbnail = true
|
|
return this
|
|
}
|
|
|
|
async submit(): Promise<string> {
|
|
const task = await this.db.workflowTask.create({
|
|
data: {
|
|
assetId: this.assetId,
|
|
teamId: this.teamId,
|
|
projectId: this.projectId,
|
|
type: WorkflowTaskType.transcode,
|
|
status: WorkflowTaskStatus.pending,
|
|
payload: {
|
|
projectId: this.projectId,
|
|
transcode: this.spec,
|
|
},
|
|
},
|
|
})
|
|
return task.id
|
|
}
|
|
}
|