mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 19:34:38 +00:00
feat(chat): allow user to choose chatbot in sidebar
- Remove chatbotAgentId from team settings and schema definition - Make agentId a required parameter in ChatRequest DTO and chatService - Fetch chatbot agents on chatbot sidebar mount and default to first enabled chat agent - Render an agent selector dropdown inside the message input area - Update existing chat sessions to follow the selected agent when continuing a conversation
This commit is contained in:
@@ -76,6 +76,7 @@ describe('ChatService', () => {
|
||||
const { user, project, rootFolder } = await setupBasicData()
|
||||
|
||||
const { sessionId, taskId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: 'test-agent-id',
|
||||
textPrompt: 'hello world',
|
||||
projectId: project.id,
|
||||
})
|
||||
@@ -120,6 +121,7 @@ describe('ChatService', () => {
|
||||
|
||||
// Start
|
||||
const { sessionId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: 'test-agent-id',
|
||||
textPrompt: 'first message',
|
||||
projectId: project.id,
|
||||
})
|
||||
@@ -128,6 +130,7 @@ describe('ChatService', () => {
|
||||
const { sessionId: nextSessionId, taskId: nextTaskId } = await chatService.startOrContinueChat(
|
||||
user,
|
||||
{
|
||||
agentId: 'test-agent-id',
|
||||
textPrompt: 'second message',
|
||||
sessionId,
|
||||
},
|
||||
@@ -184,6 +187,7 @@ describe('ChatService', () => {
|
||||
})
|
||||
|
||||
const { taskId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: 'test-agent-id',
|
||||
textPrompt: 'process file',
|
||||
projectId: project.id,
|
||||
assetIds: [childFolder.id],
|
||||
@@ -206,11 +210,13 @@ describe('ChatService', () => {
|
||||
const { user, project } = await setupBasicData()
|
||||
|
||||
await chatService.startOrContinueChat(user, {
|
||||
agentId: 'test-agent-id',
|
||||
textPrompt: 'chat 1',
|
||||
projectId: project.id,
|
||||
})
|
||||
|
||||
await chatService.startOrContinueChat(user, {
|
||||
agentId: 'test-agent-id',
|
||||
textPrompt: 'chat 2',
|
||||
projectId: project.id,
|
||||
})
|
||||
@@ -234,6 +240,7 @@ describe('ChatService', () => {
|
||||
const { user, project } = await setupBasicData()
|
||||
|
||||
const { sessionId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: 'test-agent-id',
|
||||
textPrompt: 'hello',
|
||||
projectId: project.id,
|
||||
})
|
||||
@@ -270,6 +277,7 @@ describe('ChatService', () => {
|
||||
const { user, project } = await setupBasicData()
|
||||
|
||||
const { sessionId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: 'test-agent-id',
|
||||
textPrompt: 'hello',
|
||||
projectId: project.id,
|
||||
})
|
||||
@@ -369,6 +377,7 @@ describe('ChatService', () => {
|
||||
const { user, project } = await setupBasicData()
|
||||
|
||||
const { sessionId } = await chatService.startOrContinueChat(user, {
|
||||
agentId: 'test-agent-id',
|
||||
textPrompt: 'to delete',
|
||||
projectId: project.id,
|
||||
})
|
||||
|
||||
@@ -144,6 +144,7 @@ export class ChatService {
|
||||
req: ChatRequest,
|
||||
): Promise<{ sessionId: string; taskId: string }> {
|
||||
const {
|
||||
agentId,
|
||||
textPrompt,
|
||||
attachedFiles = [],
|
||||
assetIds = [],
|
||||
@@ -246,32 +247,27 @@ 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`)
|
||||
}
|
||||
|
||||
if (!activeSessionId) {
|
||||
if (activeSessionId) {
|
||||
const sessionExists = await tx.agentSession.findUnique({
|
||||
where: { id: activeSessionId },
|
||||
select: { id: true },
|
||||
})
|
||||
if (!sessionExists) throw new Error('Session not found')
|
||||
|
||||
// Update the session's agentId to match the selected agent
|
||||
await tx.agentSession.update({
|
||||
where: { id: activeSessionId },
|
||||
data: { agentId },
|
||||
})
|
||||
} else {
|
||||
const newSession = await tx.agentSession.create({
|
||||
data: {
|
||||
agentId,
|
||||
|
||||
Reference in New Issue
Block a user