π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(chat-input): stop Attachments menu crashing on files the user can no longer see (#21488)
Lobehub Coder599f13cbef20
diff --git a/src/components/FileIcon/index.tsx b/src/components/FileIcon/index.tsxindex dcf53b86584..b2ebf7882c8 100644--- a/src/components/FileIcon/index.tsx+++ b/src/components/FileIcon/index.tsx@@ -23,6 +23,10 @@ const FileIcon = memo<FileListProps>(({ fileName, size, variant = 'raw', isDirec/>);+ // MaterialFileTypeIcon calls `filename.split`, so a missing name would crash the tree.+ if (!fileName)+ return <MaterialFileTypeIcon filename={''} size={size} type={'file'} variant={variant} />;+if (Object.keys(mimeTypeMap).some((key) => fileName?.toLowerCase().endsWith(`.${key}`))) {const ext = fileName.split('.').pop()?.toLowerCase() as string;diff --git a/src/store/agent/selectors/agentByIdSelectors.test.ts b/src/store/agent/selectors/agentByIdSelectors.test.tsindex dfb1fc03f1d..98c00e96b88 100644--- a/src/store/agent/selectors/agentByIdSelectors.test.ts+++ b/src/store/agent/selectors/agentByIdSelectors.test.ts@@ -85,6 +85,39 @@ describe('agentByIdSelectors', () => {});});+ describe('attached knowledge', () => {+ // Regression: the server keeps the mount row but nulls the file / library+ // when the caller can no longer see it; rendering that row crashed the+ // Attachments menu (FileIcon -> `filename.split` on undefined).+ it('drops mounts whose file or library is no longer visible', () => {+ const state = createState({+ agentMap: {+ 'agent-1': {+ files: [+ { enabled: true, id: null, name: null } as any,+ { enabled: true, id: 'file-1', name: 'Brief.pdf' } as any,+ ],+ knowledgeBases: [+ { enabled: true, id: null, name: null } as any,+ { enabled: false, id: 'kb-1', name: 'Handbook' } as any,+ ],+ },+ },+ });++ expect(+ agentByIdSelectors+ .getAgentFilesById('agent-1')(state)+ .map((item) => item.id),+ ).toEqual(['file-1']);+ expect(+ agentByIdSelectors+ .getAgentKnowledgeBasesById('agent-1')(state)+ .map((item) => item.id),+ ).toEqual(['kb-1']);+ });+ });+describe('agent mode', () => {it('should default to agent mode when enableAgentMode is not explicitly false', () => {const state = createState({diff --git a/src/store/agent/selectors/agentByIdSelectors.ts b/src/store/agent/selectors/agentByIdSelectors.tsindex 3a2a885d520..17d2c88acf6 100644--- a/src/store/agent/selectors/agentByIdSelectors.ts+++ b/src/store/agent/selectors/agentByIdSelectors.ts@@ -62,11 +62,14 @@ const getAgentConfigErrorById =(s: AgentStoreState): string | undefined =>agentId ? s.agentConfigErrorMap[agentId] : undefined;+// A mount whose file / library the caller can no longer see (flipped back to+// private, another member's private item) comes back from the server with the+// entity fields nulled out β drop it so menus never render a nameless row.const getAgentFilesById = (agentId: string) => (s: AgentStoreState) =>- agentSelectors.getAgentConfigById(agentId)(s)?.files || [];+ (agentSelectors.getAgentConfigById(agentId)(s)?.files || []).filter((item) => !!item.id);const getAgentKnowledgeBasesById = (agentId: string) => (s: AgentStoreState) =>- agentSelectors.getAgentConfigById(agentId)(s)?.knowledgeBases || [];+ (agentSelectors.getAgentConfigById(agentId)(s)?.knowledgeBases || []).filter((item) => !!item.id);/*** The config fetch settled on `null` β the agent doesn't exist or the caller