mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 13:34:33 +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:
@@ -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