mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 19:04:23 +00:00
feat(workflow): integrate temporal workflow bundles and support dev/prod mode
This commit is contained in:
@@ -3,7 +3,11 @@ import { DatabaseSessionStorage } from '../database-session-storage'
|
||||
import { prisma, AssetType, Prisma, type Skill } from '@shumai/db'
|
||||
import { logger } from '@shumai/core/src/logger'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { type AgentTool, type AgentMessage, type SessionTreeEntry } from '@earendil-works/pi-agent-core'
|
||||
import {
|
||||
type AgentTool,
|
||||
type AgentMessage,
|
||||
type SessionTreeEntry,
|
||||
} from '@earendil-works/pi-agent-core'
|
||||
import { type ImageContent } from '@earendil-works/pi-ai'
|
||||
import { ApplicationFailure } from '@temporalio/activity'
|
||||
import { assetService } from '@shumai/core/src/asset/asset'
|
||||
|
||||
@@ -261,10 +261,7 @@ export async function extractAiMetadataActivity(
|
||||
return generatedFiles
|
||||
}
|
||||
|
||||
export async function getEmbeddingContextActivity(params: {
|
||||
teamId: string
|
||||
assetId: string
|
||||
}) {
|
||||
export async function getEmbeddingContextActivity(params: { teamId: string; assetId: string }) {
|
||||
const team = await prisma.team.findUnique({
|
||||
where: { id: params.teamId },
|
||||
})
|
||||
|
||||
@@ -93,7 +93,11 @@ export async function agentAutofillMedia(task: WorkflowTask): Promise<void> {
|
||||
}
|
||||
|
||||
// 3. Get Project Autofill Fields
|
||||
const fields = await executeActivity(TaskQueueAgent, getProjectAutofillFieldsActivity, projectId)
|
||||
const fields = await executeActivity(
|
||||
TaskQueueAgent,
|
||||
getProjectAutofillFieldsActivity,
|
||||
projectId,
|
||||
)
|
||||
if (fields.length === 0) {
|
||||
if (placeholderCommentId) {
|
||||
await executeActivity(TaskQueueAgent, updateCommentActivity, {
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { registerWorkflow, registerActivities } from '@shumai/workflow-core'
|
||||
import { WorkflowTaskType } from '@shumai/db'
|
||||
import { transcodeMedia } from './workflows/transcode'
|
||||
import { registerActivities, registerWorkflow } from '@shumai/workflow-core'
|
||||
import * as transcodeActivities from './activities/transcode'
|
||||
import { transcodeMedia } from './workflows/transcode'
|
||||
|
||||
export function initTranscodeWorkflows() {
|
||||
registerWorkflow(WorkflowTaskType.transcode, transcodeMedia)
|
||||
registerActivities(transcodeActivities)
|
||||
}
|
||||
|
||||
export * from './transcoder'
|
||||
export * from './transcode'
|
||||
export * from './workflows/transcode'
|
||||
export * from './activities/transcode'
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { WorkflowTask } from '@shumai/db'
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import {
|
||||
getActivities,
|
||||
executeActivity,
|
||||
TaskQueueTranscode,
|
||||
} from '@shumai/workflow-core'
|
||||
executeActivity,
|
||||
getActivities,
|
||||
TaskQueueTranscode,
|
||||
} from '@shumai/workflow-core/src/workflow-utils'
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
|
||||
export async function transcodeMedia(task: WorkflowTask): Promise<void> {
|
||||
const {
|
||||
|
||||
@@ -9,7 +9,9 @@ export async function getAgentWorkerQueueActivity(): Promise<string> {
|
||||
return 'agent_queue'
|
||||
}
|
||||
|
||||
export async function getAssetStatusActivity(params: { assetId: string }): Promise<AssetStatus | null> {
|
||||
export async function getAssetStatusActivity(params: {
|
||||
assetId: string
|
||||
}): Promise<AssetStatus | null> {
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: params.assetId },
|
||||
select: { status: true },
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { WorkflowTask } from '@shumai/db'
|
||||
import { prisma, registerWorkflowTrigger, WorkflowTask } from '@shumai/db'
|
||||
import path from 'path'
|
||||
import { Executor } from './executor'
|
||||
import { LocalExecutor } from './local-executor'
|
||||
import { TemporalExecutor } from './temporal-executor'
|
||||
import { prisma, registerWorkflowTrigger } from '@shumai/db'
|
||||
|
||||
export class WorkflowService {
|
||||
private executor: Executor
|
||||
@@ -56,7 +56,10 @@ export class WorkflowService {
|
||||
}
|
||||
|
||||
// Starts Temporal workers for specific task queues
|
||||
async startWorkers(queue: string): Promise<void> {
|
||||
async startWorkers(
|
||||
queue: string,
|
||||
options: { workflowBundle?: unknown; workflowsPath?: string } = {},
|
||||
): Promise<void> {
|
||||
const type = process.env.WORKFLOW_EXECUTOR || 'local'
|
||||
if (type === 'temporal') {
|
||||
const { Worker, NativeConnection } = await import('@temporalio/worker')
|
||||
@@ -85,10 +88,31 @@ export class WorkflowService {
|
||||
sharedActivities.getTranscodeWorkerQueueActivity = async () => workerSpecificQueue
|
||||
}
|
||||
|
||||
const { workflowBundle, workflowsPath } = options
|
||||
|
||||
const sharedWorker = await Worker.create({
|
||||
connection,
|
||||
// The workflowBundle is a pre-bundled set of workflows, its internal structure
|
||||
// is managed by the Temporal worker and doesn't need explicit typing here.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
...(workflowBundle ? { workflowBundle: workflowBundle as any } : {}),
|
||||
...(workflowsPath ? { workflowsPath } : {}),
|
||||
activities: sharedActivities,
|
||||
taskQueue: queue,
|
||||
|
||||
bundlerOptions: {
|
||||
webpackConfigHook: (config) => {
|
||||
config.resolve = config.resolve || {}
|
||||
config.resolve.alias = {
|
||||
...config.resolve.alias,
|
||||
// Find the exact absolute path to the package directory
|
||||
'@temporalio/workflow': path.dirname(
|
||||
require.resolve('@temporalio/workflow/package.json'),
|
||||
),
|
||||
}
|
||||
return config
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const specificWorker = await Worker.create({
|
||||
@@ -96,6 +120,19 @@ export class WorkflowService {
|
||||
// No workflows needed for the unique queue
|
||||
activities,
|
||||
taskQueue: workerSpecificQueue,
|
||||
bundlerOptions: {
|
||||
webpackConfigHook: (config) => {
|
||||
config.resolve = config.resolve || {}
|
||||
config.resolve.alias = {
|
||||
...config.resolve.alias,
|
||||
// Find the exact absolute path to the package directory
|
||||
'@temporalio/workflow': path.dirname(
|
||||
require.resolve('@temporalio/workflow/package.json'),
|
||||
),
|
||||
}
|
||||
return config
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await Promise.all([sharedWorker.run(), specificWorker.run()])
|
||||
|
||||
Reference in New Issue
Block a user