mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 04:44:28 +00:00
feat(chatbot): remove agentId from request and resolve it via team settings, toggle chatbot icon with tooltip guard
This commit is contained in:
@@ -14,7 +14,7 @@ describe('ChatService', () => {
|
||||
const team = await prisma.team.create({
|
||||
data: {
|
||||
name: 'Test Team',
|
||||
settings: { transcode: { videoStrategy: 'best_match' } },
|
||||
settings: { transcode: { videoStrategy: 'best_match' }, chatbotAgentId: 'test-agent-id' },
|
||||
sandbox: { create: {} },
|
||||
},
|
||||
})
|
||||
@@ -73,10 +73,9 @@ describe('ChatService', () => {
|
||||
}
|
||||
|
||||
it('should start a new chat session and trigger workflow', async () => {
|
||||
const { user, project, rootFolder, agent } = await setupBasicData()
|
||||
const { user, project, rootFolder } = await setupBasicData()
|
||||
|
||||
const { sessionId, taskId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: agent.id,
|
||||
textPrompt: 'hello world',
|
||||
projectId: project.id,
|
||||
})
|
||||
@@ -117,11 +116,10 @@ describe('ChatService', () => {
|
||||
})
|
||||
|
||||
it('should continue an existing chat session', async () => {
|
||||
const { user, project, agent } = await setupBasicData()
|
||||
const { user, project } = await setupBasicData()
|
||||
|
||||
// Start
|
||||
const { sessionId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: agent.id,
|
||||
textPrompt: 'first message',
|
||||
projectId: project.id,
|
||||
})
|
||||
@@ -130,7 +128,6 @@ describe('ChatService', () => {
|
||||
const { sessionId: nextSessionId, taskId: nextTaskId } = await chatService.startOrContinueChat(
|
||||
user,
|
||||
{
|
||||
agentId: agent.id,
|
||||
textPrompt: 'second message',
|
||||
sessionId,
|
||||
},
|
||||
@@ -156,7 +153,7 @@ describe('ChatService', () => {
|
||||
})
|
||||
|
||||
it('should inject context of referenced assets and attached files', async () => {
|
||||
const { user, project, rootFolder, agent } = await setupBasicData()
|
||||
const { user, project, rootFolder } = await setupBasicData()
|
||||
|
||||
const childFolder = await prisma.asset.create({
|
||||
data: {
|
||||
@@ -187,7 +184,6 @@ describe('ChatService', () => {
|
||||
})
|
||||
|
||||
const { taskId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: agent.id,
|
||||
textPrompt: 'process file',
|
||||
projectId: project.id,
|
||||
assetIds: [childFolder.id],
|
||||
@@ -207,16 +203,14 @@ describe('ChatService', () => {
|
||||
})
|
||||
|
||||
it('should list sessions of a user', async () => {
|
||||
const { user, project, agent } = await setupBasicData()
|
||||
const { user, project } = await setupBasicData()
|
||||
|
||||
await chatService.startOrContinueChat(user, {
|
||||
agentId: agent.id,
|
||||
textPrompt: 'chat 1',
|
||||
projectId: project.id,
|
||||
})
|
||||
|
||||
await chatService.startOrContinueChat(user, {
|
||||
agentId: agent.id,
|
||||
textPrompt: 'chat 2',
|
||||
projectId: project.id,
|
||||
})
|
||||
@@ -226,10 +220,9 @@ describe('ChatService', () => {
|
||||
})
|
||||
|
||||
it('should list messages mapped correctly', async () => {
|
||||
const { user, project, agent } = await setupBasicData()
|
||||
const { user, project } = await setupBasicData()
|
||||
|
||||
const { sessionId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: agent.id,
|
||||
textPrompt: 'hello',
|
||||
projectId: project.id,
|
||||
})
|
||||
@@ -263,10 +256,9 @@ describe('ChatService', () => {
|
||||
})
|
||||
|
||||
it('should delete session and cascade', async () => {
|
||||
const { user, project, agent } = await setupBasicData()
|
||||
const { user, project } = await setupBasicData()
|
||||
|
||||
const { sessionId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: agent.id,
|
||||
textPrompt: 'to delete',
|
||||
projectId: project.id,
|
||||
})
|
||||
|
||||
@@ -129,7 +129,6 @@ export class ChatService {
|
||||
req: ChatRequest,
|
||||
): Promise<{ sessionId: string; taskId: string }> {
|
||||
const {
|
||||
agentId,
|
||||
textPrompt,
|
||||
attachedFiles = [],
|
||||
assetIds = [],
|
||||
@@ -232,21 +231,32 @@ export class ChatService {
|
||||
const teamId = asset.project.teamId
|
||||
const projectId = asset.project.id
|
||||
|
||||
let agentId: string
|
||||
let activeSessionId = passedSessionId
|
||||
|
||||
if (activeSessionId) {
|
||||
const sessionExists = await tx.agentSession.findUnique({
|
||||
where: { id: activeSessionId },
|
||||
select: { id: true, agentId: true },
|
||||
})
|
||||
if (!sessionExists) throw new Error('Session not found')
|
||||
agentId = sessionExists.agentId
|
||||
} else {
|
||||
const teamSettings = (asset.project.team.settings || {}) as Record<string, unknown>
|
||||
const settingsAgentId = teamSettings.chatbotAgentId as string | undefined
|
||||
if (!settingsAgentId) {
|
||||
throw new Error('No chatbot agent configured for the team')
|
||||
}
|
||||
agentId = settingsAgentId
|
||||
}
|
||||
|
||||
// Ensure AI agent configuration exists
|
||||
const agent = await tx.agent.findUnique({ where: { id: agentId } })
|
||||
if (!agent) {
|
||||
throw new Error(`Agent with ID "${agentId}" not found`)
|
||||
}
|
||||
|
||||
let activeSessionId = passedSessionId
|
||||
|
||||
if (activeSessionId) {
|
||||
const sessionExists = await tx.agentSession.findUnique({
|
||||
where: { id: activeSessionId },
|
||||
select: { id: true },
|
||||
})
|
||||
if (!sessionExists) throw new Error('Session not found')
|
||||
} else {
|
||||
if (!activeSessionId) {
|
||||
const newSession = await tx.agentSession.create({
|
||||
data: {
|
||||
agentId,
|
||||
|
||||
Reference in New Issue
Block a user