mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 21:49:19 +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.
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import type { WorkflowTask } from '@shumai/db'
|
|
import { getActivities, executeActivity, TaskQueueDb } from '@shumai/workflow-core'
|
|
|
|
export async function queryEmbeddingForSearch(task: WorkflowTask): Promise<void> {
|
|
const { generateTextEmbeddingActivity, updateWorkflowTaskActivity } = getActivities()
|
|
|
|
const payload = task.payload as PrismaJson.WorkflowTaskPayload | null
|
|
const text = payload?.queryEmbeddingForSearch?.text
|
|
|
|
if (!text) {
|
|
throw new Error('Missing text in query_embedding_for_search task payload')
|
|
}
|
|
|
|
try {
|
|
// 1. Mark as processing
|
|
await executeActivity(TaskQueueDb, updateWorkflowTaskActivity, {
|
|
taskId: task.id,
|
|
status: 'processing',
|
|
heartbeat: true,
|
|
})
|
|
|
|
// 2. Generate embedding
|
|
const result = await generateTextEmbeddingActivity({
|
|
text,
|
|
teamId: task.teamId!,
|
|
})
|
|
|
|
// 3. Save output and complete
|
|
await executeActivity(TaskQueueDb, updateWorkflowTaskActivity, {
|
|
taskId: task.id,
|
|
status: 'completed',
|
|
output: { embedding: result.embedding },
|
|
inputTokens: result.usage.inputTokens,
|
|
outputTokens: result.usage.outputTokens,
|
|
model: result.usage.model,
|
|
})
|
|
} catch (err) {
|
|
console.error(`queryEmbeddingForSearch failed for task ${task.id}:`, err)
|
|
await executeActivity(TaskQueueDb, updateWorkflowTaskActivity, {
|
|
taskId: task.id,
|
|
status: 'failed',
|
|
output: {
|
|
error: err instanceof Error ? err.message : String(err),
|
|
},
|
|
})
|
|
throw err
|
|
}
|
|
}
|