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:
yiling
2026-07-13 10:10:56 +08:00
parent bad93466ae
commit 61c49b4d7f
16 changed files with 194 additions and 141 deletions
+14 -18
View File
@@ -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,