From 60c499c153e1fe73558ba5da258c7adab969b73f Mon Sep 17 00:00:00 2001 From: yiling Date: Mon, 15 Jun 2026 11:23:56 +0800 Subject: [PATCH] refactor(webui): fetch agents in mention input list dynamically --- .../webui/components/chat/message-input.tsx | 207 +++++++++++------- .../components/file-viewer-right-sidebar.tsx | 1 - packages/webui/stores/members.ts | 6 +- 3 files changed, 131 insertions(+), 83 deletions(-) diff --git a/packages/webui/components/chat/message-input.tsx b/packages/webui/components/chat/message-input.tsx index 84b102b7..39907195 100644 --- a/packages/webui/components/chat/message-input.tsx +++ b/packages/webui/components/chat/message-input.tsx @@ -5,6 +5,9 @@ import { client } from '@/ui/api/client' import { useAnnotationStore } from '@/ui/stores/annotation-store' import type { Annotation } from '@/ui/types' import { useMutation } from '@tanstack/react-query' +import { Skeleton } from '../ui/skeleton' +import { useMemberStore } from '@/ui/stores/members' +import { useTeamContextStore } from '@/ui/stores/team-context' import { ArrowLeft, ArrowUp, @@ -45,7 +48,6 @@ interface ChatInputProps { ) => void replyingTo?: CommentInfo | null onCancelReply?: () => void - users?: UserInfo[] bots?: BotInfo[] initialText?: string hideAnnotationControl?: boolean @@ -76,7 +78,6 @@ export const ChatInput = React.forwardRef( onSendMessage, replyingTo, onCancelReply, - users = [], bots = [], initialText = '', hideAnnotationControl = false, @@ -91,6 +92,15 @@ export const ChatInput = React.forwardRef( const [viewingFile, setViewingFile] = useState(null) const [isTimestampEnabled, setIsTimestampEnabled] = useState(true) + const { teamId, ensureTeamIdForProject } = useTeamContextStore() + const { members: storeMembers, loading: membersLoading, fetchMembers } = useMemberStore() + + useEffect(() => { + if (projectId && !teamId) { + ensureTeamIdForProject(projectId) + } + }, [projectId, teamId, ensureTeamIdForProject]) + // Annotation Store const { isDrawing, @@ -171,7 +181,7 @@ export const ChatInput = React.forwardRef( }, [setIsDrawing]) const filteredAgents = [ - ...users + ...storeMembers .filter( (u) => u.type === 'agent' && u.name?.toLowerCase().startsWith(mentionQuery.toLowerCase()), ) @@ -181,7 +191,7 @@ export const ChatInput = React.forwardRef( .map((b) => ({ type: 'bot' as const, data: b })), ] - const filteredHumans = users + const filteredHumans = storeMembers .filter( (u) => u.type !== 'agent' && u.name?.toLowerCase().startsWith(mentionQuery.toLowerCase()), ) @@ -230,6 +240,10 @@ export const ChatInput = React.forwardRef( setMentionQuery(query) setShowMentionList(true) + if (teamId) { + fetchMembers(teamId, true, true) + } + // Save the range for later insertion const mentionRange = document.createRange() mentionRange.setStart(node, lastAtPos) @@ -443,85 +457,120 @@ export const ChatInput = React.forwardRef( cursor: text; } `} - {showMentionList && (filteredAgents.length > 0 || filteredHumans.length > 0) && ( + {showMentionList && (membersLoading || filteredAgents.length > 0 || filteredHumans.length > 0) && (
- {filteredAgents.length > 0 && ( + {membersLoading ? ( +
+ {/* Agents Skeleton */} +
+
+ +
+
+ + +
+
+ + +
+
+ {/* Members Skeleton */} +
+
+ +
+
+ + +
+
+ + +
+
+
+ ) : ( <> - - {!collapsedSections.bots && - filteredAgents.map((item, index) => { - const actualIndex = index - return ( - - ) - })} - - )} + {filteredAgents.length > 0 && ( + <> + + {!collapsedSections.bots && + filteredAgents.map((item, index) => { + const actualIndex = index + return ( + + ) + })} + + )} - {filteredHumans.length > 0 && ( - <> - - {!collapsedSections.users && - filteredHumans.map((item, index) => { - const actualIndex = - (collapsedSections.bots ? 0 : filteredAgents.length) + index - return ( - - ) - })} + {filteredHumans.length > 0 && ( + <> + + {!collapsedSections.users && + filteredHumans.map((item, index) => { + const actualIndex = + (collapsedSections.bots ? 0 : filteredAgents.length) + index + return ( + + ) + })} + + )} )}
diff --git a/packages/webui/components/file-viewer-right-sidebar.tsx b/packages/webui/components/file-viewer-right-sidebar.tsx index 3032a9a4..b77a31db 100644 --- a/packages/webui/components/file-viewer-right-sidebar.tsx +++ b/packages/webui/components/file-viewer-right-sidebar.tsx @@ -404,7 +404,6 @@ export function FileViewerRightSidebar({ onSendMessage={handleSendMessage} replyingTo={replyingTo} onCancelReply={() => setReplyingTo(null)} - users={members} bots={enabledBots} hideAnnotationControl={hideAnnotationControl} disableMentions={isPublic} diff --git a/packages/webui/stores/members.ts b/packages/webui/stores/members.ts index 1a3a873b..c515db4f 100644 --- a/packages/webui/stores/members.ts +++ b/packages/webui/stores/members.ts @@ -9,7 +9,7 @@ interface MemberState { loadedTeamId?: string loadedWithAgents?: boolean loading: boolean - fetchMembers: (teamId: string, includeAgents?: boolean) => Promise + fetchMembers: (teamId: string, includeAgents?: boolean, force?: boolean) => Promise } export const useMemberStore = create()( @@ -17,8 +17,8 @@ export const useMemberStore = create()( immer((set, get) => ({ members: [], loading: false, - fetchMembers: async (teamId, includeAgents) => { - if (get().loadedTeamId === teamId && get().loadedWithAgents === includeAgents) { + fetchMembers: async (teamId, includeAgents, force) => { + if (!force && get().loadedTeamId === teamId && get().loadedWithAgents === includeAgents) { return }