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
+1
View File
@@ -33,6 +33,7 @@ describe('useChatbotStore', () => {
messages: [],
historySessions: [],
isStreaming: false,
selectedAgentId: 'agent-1',
})
})
+16
View File
@@ -26,6 +26,8 @@ interface ChatbotState {
setHistorySessions: (sessions: ChatSessionInfo[]) => void
isStreaming: boolean
setIsStreaming: (streaming: boolean) => void
selectedAgentId: string | null
setSelectedAgentId: (id: string | null) => void
fetchHistorySessions: () => Promise<void>
loadSession: (sessionId: string) => Promise<void>
@@ -59,6 +61,8 @@ export const useChatbotStore = create<ChatbotState>((set) => ({
setHistorySessions: (sessions) => set({ historySessions: sessions }),
isStreaming: false,
setIsStreaming: (streaming) => set({ isStreaming: streaming }),
selectedAgentId: null,
setSelectedAgentId: (id) => set({ selectedAgentId: id }),
fetchHistorySessions: async () => {
try {
@@ -81,10 +85,15 @@ export const useChatbotStore = create<ChatbotState>((set) => ({
})
if (res.ok) {
const messages = await res.json()
const sessionInfo = useChatbotStore
.getState()
.historySessions.find((s) => s.id === sessionId)
const agentId = sessionInfo?.agentId || null
set({
currentSessionId: sessionId,
messages: messages as ChatMessage[],
isHistoryMode: false,
...(agentId ? { selectedAgentId: agentId } : {}),
})
} else {
throw new Error('Failed to load session messages')
@@ -164,9 +173,16 @@ export const useChatbotStore = create<ChatbotState>((set) => ({
const assetIds = state.chatAssets.map((a) => a.id)
const agentId = state.selectedAgentId
if (!agentId) {
toast.error('No agent selected')
return
}
try {
const res = await client.api.chat.$post({
json: {
agentId,
textPrompt: text,
assetIds,
sessionId: state.currentSessionId || undefined,