mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 07:57:15 +00:00
feat(agent): add teamId foreign key to agent table and refactor service queries
This commit is contained in:
@@ -50,6 +50,14 @@ export async function createCommentActivity(params: CreateCommentParams) {
|
||||
if (params.sessionId) {
|
||||
const agentId = params.agentId && params.agentId !== 'default' ? params.agentId : 'default'
|
||||
|
||||
// Fetch teamId from asset
|
||||
const asset = await prisma.asset.findUnique({
|
||||
where: { id: params.assetId },
|
||||
include: { project: true },
|
||||
})
|
||||
if (!asset || !asset.project) throw new Error('asset or project not found')
|
||||
const teamId = asset.project.teamId
|
||||
|
||||
// Ensure user exists for agent
|
||||
const userExists = await prisma.user.findUnique({ where: { id: agentId } })
|
||||
if (!userExists) {
|
||||
@@ -69,6 +77,7 @@ export async function createCommentActivity(params: CreateCommentParams) {
|
||||
await prisma.agent.create({
|
||||
data: {
|
||||
id: agentId,
|
||||
teamId,
|
||||
type: 'chat',
|
||||
config: {
|
||||
provider: 'openai',
|
||||
|
||||
@@ -47,12 +47,19 @@ describe('WorkflowService', () => {
|
||||
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',
|
||||
key: 'test/test.mp3',
|
||||
status: 'uploaded',
|
||||
type: 'file',
|
||||
projectId: project.id,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -84,6 +91,12 @@ describe('WorkflowService', () => {
|
||||
}, 15000)
|
||||
|
||||
it('should process ai_embedding task locally', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'Embedding Team' },
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'Embedding Project', teamId: team.id },
|
||||
})
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'test.png',
|
||||
@@ -91,6 +104,7 @@ describe('WorkflowService', () => {
|
||||
status: 'uploaded',
|
||||
type: 'file',
|
||||
mediaType: 'image/png',
|
||||
projectId: project.id,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -99,7 +113,7 @@ describe('WorkflowService', () => {
|
||||
assetId: asset.id,
|
||||
type: WorkflowTaskType.ai_embedding,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
teamId: 'test-team', // Needs a teamId for embeddings
|
||||
teamId: team.id,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user