Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🔎 feat: Filter Agent Builder Selector to Authored Agents (#17439)
Marco Beretta952e9b6049bb
diff --git a/client/src/components/Agents/MineFilterToggle.tsx b/client/src/components/Agents/MineFilterToggle.tsxindex 667787a98d..76e97e2e8b 100644--- a/client/src/components/Agents/MineFilterToggle.tsx+++ b/client/src/components/Agents/MineFilterToggle.tsx@@ -1,28 +1,34 @@-import { UserRound } from 'lucide-react';+import { UserRound, UserRoundCheck } from 'lucide-react';import { Button, TooltipAnchor } from '@librechat/client';import { useLocalize } from '~/hooks';interface MineFilterToggleProps {+ iconOnly?: boolean;checked: boolean;onCheckedChange: (checked: boolean) => void;}-const MineFilterToggle: React.FC<MineFilterToggleProps> = ({ checked, onCheckedChange }) => {+const MineFilterToggle: React.FC<MineFilterToggleProps> = ({+ checked,+ onCheckedChange,+ iconOnly = false,+}) => {const localize = useLocalize();+ const Icon = iconOnly && checked ? UserRoundCheck : UserRound;return (<TooltipAnchordescription={localize('com_agents_filter_mine')}render={<Button- variant="outline-toggle"+ variant={iconOnly ? 'ghost' : 'outline-toggle'}aria-label={localize('com_agents_my_agents')}- size="compact"+ size={iconOnly ? 'icon-sm' : 'compact'}aria-pressed={checked}onClick={() => onCheckedChange(!checked)}>- <UserRound className="size-3.5" aria-hidden="true" />- {localize('com_agents_my_agents')}+ <Icon className="size-3.5" aria-hidden="true" />+ {!iconOnly && localize('com_agents_my_agents')}</Button>}/>diff --git a/client/src/components/SidePanel/Agents/AgentSelect.tsx b/client/src/components/SidePanel/Agents/AgentSelect.tsxindex 5bb58798bb..0dd1524fde 100644--- a/client/src/components/SidePanel/Agents/AgentSelect.tsx+++ b/client/src/components/SidePanel/Agents/AgentSelect.tsx@@ -1,4 +1,5 @@-import { memo, useCallback, useEffect, useRef } from 'react';+import { memo, useCallback, useEffect, useRef, useMemo } from 'react';+import { atom, useAtom } from 'jotai';import { EarthIcon } from 'lucide-react';import { ControlCombobox } from '@librechat/client';import { useFormContext, Controller } from 'react-hook-form';@@ -13,6 +14,7 @@ import type { TAgentCapabilities, AgentForm } from '~/common';import { cn, createProviderOption, processAgentOption, getDefaultAgentFormValues } from '~/utils';import { useListAgentsQuery, useGetStartupConfig } from '~/data-provider';import { useLocalize, useAgentDefaultPermissionLevel } from '~/hooks';+import MineFilterToggle from '~/components/Agents/MineFilterToggle';import { mergeDirtyToolsWithServerActions } from './agentTools';const keys = new Set(Object.keys(defaultAgentFormValues));@@ -42,6 +44,8 @@ function AgentSelect({instructionsPromptReady?: boolean;}) {const localize = useLocalize();+ const mineAtom = useMemo(() => atom(false), []);+ const [mine, setMine] = useAtom(mineAtom);const lastSelectedAgent = useRef<string | null>(null);const {control,@@ -58,8 +62,8 @@ function AgentSelect({const { data: startupConfig } = useGetStartupConfig();const selectorLimit = normalizeAgentSelectorLimit(startupConfig?.interface?.agentSelectorLimit);- const { data: agents = null } = useListAgentsQuery(- { requiredPermission: permissionLevel },+ const { data: listedAgents = null } = useListAgentsQuery(+ { requiredPermission: permissionLevel, ...(mine ? { mine: 1 as const } : {}) },{select: (res) =>res.data.map((agent) =>@@ -73,6 +77,24 @@ function AgentSelect({},);+ const agents = useMemo(() => {+ const currentAgent = agentQuery.data;+ if (+ !mine ||+ !currentAgent ||+ currentAgent.id !== selectedAgentId ||+ listedAgents?.some((agent) => agent.id === selectedAgentId)+ ) {+ return listedAgents;+ }+ return [+ ...(listedAgents ?? []),+ processAgentOption({+ agent: { ...currentAgent, name: currentAgent.name || currentAgent.id },+ }),+ ];+ }, [listedAgents, mine, agentQuery.data, selectedAgentId]);+const resetAgentForm = useCallback((fullAgent: Agent, preserveDirtyValues = false) => {const isGlobal = fullAgent.isPublic ?? false;@@ -309,6 +331,7 @@ function AgentSelect({selectPlaceholder={field?.value?.value ?? createAgent}iconSide="right"searchPlaceholder={localize('com_agents_search_name')}+ searchActions={<MineFilterToggle iconOnly checked={mine} onCheckedChange={setMine} />}popoverMaxHeight={SELECTOR_MAX_HEIGHT}unsearchedLimit={selectorLimit}SelectIcon={field?.value?.icon}diff --git a/client/src/components/SidePanel/Agents/__tests__/AgentSelect.spec.tsx b/client/src/components/SidePanel/Agents/__tests__/AgentSelect.spec.tsxindex ad1cce2108..488ceb2aec 100644--- a/client/src/components/SidePanel/Agents/__tests__/AgentSelect.spec.tsx+++ b/client/src/components/SidePanel/Agents/__tests__/AgentSelect.spec.tsx@@ -1,14 +1,18 @@import React from 'react';import { useForm, FormProvider } from 'react-hook-form';-import { render, waitFor } from '@testing-library/react';+import { fireEvent, render, screen, waitFor } from '@testing-library/react';import type { UseMutationResult, QueryObserverResult } from '@tanstack/react-query';import type { Agent, AgentCreateParams } from 'librechat-data-provider';import type { UseFormReturn } from 'react-hook-form';import type { AgentForm } from '~/common';import AgentSelect from '../AgentSelect';+const mockListAgents = jest.fn<{ data: { id: string; name: string }[] }, unknown[]>(() => ({+ data: [],+}));+jest.mock('~/data-provider', () => ({- useListAgentsQuery: () => ({ data: [] }),+ useListAgentsQuery: (...args: unknown[]) => mockListAgents(...args),useGetStartupConfig: () => ({ data: undefined }),}));@@ -18,7 +22,24 @@ jest.mock('~/hooks', () => ({}));jest.mock('@librechat/client', () => ({- ControlCombobox: () => <div data-testid="agent-select-combobox" />,+ ControlCombobox: ({+ searchActions,+ items,+ }: {+ searchActions?: React.ReactNode;+ items: { label: string; value: string }[];+ }) => (+ <div data-testid="agent-select-combobox">+ {searchActions}+ {items.map((item) => (+ <span key={item.value}>{item.label}</span>+ ))}+ </div>+ ),+ Button: ({ children, ...props }: React.ComponentProps<'button'>) => (+ <button {...props}>{children}</button>+ ),+ TooltipAnchor: ({ render }: { render: React.ReactNode }) => render,}));/**@@ -32,7 +53,9 @@ function Harness({onMethods,instructionsPromptReady,defaultValues,+ selectedAgentId = null,}: {+ selectedAgentId?: string | null;agent: Agent;onMethods: (methods: UseFormReturn<AgentForm>) => void;instructionsPromptReady?: boolean;@@ -45,11 +68,8 @@ function Harness({<FormProvider {...methods}><AgentSelectagentQuery={{ data: agent, isSuccess: true } as unknown as QueryObserverResult<Agent>}- /** `null`, not `agent.id`: a non-null value with no matching row in the (empty,- * mocked) agent list schedules `onSelect`'s "not found" timer, which would reset- * the whole form back to defaults out from under this test. The load effect this- * test targets keys off `agentQuery.data` alone. */- selectedAgentId={null}+ /** Form-reset tests leave this null to avoid scheduling selection from an empty list. */+ selectedAgentId={selectedAgentId}setCurrentAgentId={jest.fn()}createMutation={{ reset: jest.fn() } as unknown as UseMutationResult<Agent, Error, AgentCreateParams>@@ -148,3 +168,57 @@ describe('AgentSelect resetAgentForm', () => {});});});++describe('AgentSelect ownership filter', () => {+ it('renders an icon-only ghost filter with an accessible name', () => {+ render(<Harness agent={createAgent()} onMethods={() => undefined} />);+ const toggle = screen.getByRole('button', { name: 'com_agents_my_agents' });+ expect(toggle.textContent).toBe('');+ expect(toggle).toHaveAttribute('variant', 'ghost');+ });++ it('changes the icon when ownership filtering is active', () => {+ render(<Harness agent={createAgent()} onMethods={() => undefined} />);+ const toggle = screen.getByRole('button', { name: 'com_agents_my_agents' });+ fireEvent.click(toggle);+ expect(toggle.querySelector('.lucide-user-round-check')).toBeInTheDocument();+ });++ it('defaults to the original query and an unpressed filter', () => {+ render(<Harness agent={createAgent()} onMethods={() => undefined} />);+ expect(mockListAgents).toHaveBeenLastCalledWith({ requiredPermission: 1 }, expect.any(Object));+ expect(screen.getByRole('button', { name: 'com_agents_my_agents' })).toHaveAttribute(+ 'aria-pressed',+ 'false',+ );+ });++ it('requests only authored agents when the filter is enabled', () => {+ render(<Harness agent={createAgent()} onMethods={() => undefined} />);+ fireEvent.click(screen.getByRole('button', { name: 'com_agents_my_agents' }));+ expect(mockListAgents).toHaveBeenLastCalledWith(+ { requiredPermission: 1, mine: 1 },+ expect.any(Object),+ );+ });++ it('restores the original query when the filter is disabled', () => {+ render(<Harness agent={createAgent()} onMethods={() => undefined} />);+ const toggle = screen.getByRole('button', { name: 'com_agents_my_agents' });+ fireEvent.click(toggle);+ fireEvent.click(toggle);+ expect(mockListAgents).toHaveBeenLastCalledWith({ requiredPermission: 1 }, expect.any(Object));+ });++ it('keeps the current agent available when absent from the filtered list', () => {+ render(+ <Harness+ selectedAgentId="agent_1"+ agent={createAgent({ name: 'Shared agent' })}+ onMethods={() => undefined}+ />,+ );+ fireEvent.click(screen.getByRole('button', { name: 'com_agents_my_agents' }));+ expect(screen.getByText('Shared agent')).toBeInTheDocument();+ });+});diff --git a/client/src/data-provider/Agents/__tests__/mutations.test.ts b/client/src/data-provider/Agents/__tests__/mutations.test.tsindex f79a405d93..fce8494452 100644--- a/client/src/data-provider/Agents/__tests__/mutations.test.ts+++ b/client/src/data-provider/Agents/__tests__/mutations.test.ts@@ -5,6 +5,8 @@ import { dataService, PermissionBits, QueryKeys } from 'librechat-data-provider'import type { Agent, AgentListResponse, GraphEdge } from 'librechat-data-provider';import type { ReactNode } from 'react';import {+ useCreateAgentMutation,+ useUpdateAgentAction,useDeleteAgentMutation,useDuplicateAgentMutation,useUpdateAgentMutation,@@ -16,6 +18,8 @@ jest.mock('librechat-data-provider', () => {...actual,dataService: {...actual.dataService,+ createAgent: jest.fn(),+ updateAgentAction: jest.fn(),deleteAgent: jest.fn(),updateAgent: jest.fn(),duplicateAgent: jest.fn(),@@ -258,3 +262,145 @@ describe('useDuplicateAgentMutation', () => {expect(listRes?.data[1]).toMatchObject({ id: sourceId, isEditable: false });});});++describe('authored agent selector caches', () => {+ const listKey = [QueryKeys.agents, { requiredPermission: PermissionBits.EDIT, mine: 1 }];+ const seed = (client: QueryClient) =>+ client.setQueryData(listKey, {+ object: 'list',+ data: [createAgent('agent_owned')],+ first_id: 'agent_owned',+ last_id: 'agent_owned',+ has_more: false,+ } satisfies AgentListResponse);++ it('updates the filtered option after a rename', async () => {+ const client = new QueryClient();+ seed(client);+ jest+ .mocked(dataService.updateAgent)+ .mockResolvedValue({ ...createAgent('agent_owned'), name: 'Renamed' });+ const { result } = renderHook(() => useUpdateAgentMutation(), {+ wrapper: createWrapper(client),+ });+ await act(async () => {+ await result.current.mutateAsync({ agent_id: 'agent_owned', data: { name: 'Renamed' } });+ });+ expect(client.getQueryData<AgentListResponse>(listKey)?.data[0].name).toBe('Renamed');+ client.clear();+ });++ it('removes a deleted agent from the filtered options', async () => {+ const client = new QueryClient();+ seed(client);+ jest.mocked(dataService.deleteAgent).mockResolvedValue();+ const { result } = renderHook(() => useDeleteAgentMutation(), {+ wrapper: createWrapper(client),+ });+ await act(async () => {+ await result.current.mutateAsync({ agent_id: 'agent_owned' });+ });+ expect(client.getQueryData<AgentListResponse>(listKey)?.data).toEqual([]);+ client.clear();+ });+});++describe('agent mutation callback invariants', () => {+ it('calls create success once with absent list caches', async () => {+ const client = new QueryClient();+ const onSuccess = jest.fn();+ jest.mocked(dataService.createAgent).mockResolvedValue(createAgent('new'));+ const { result } = renderHook(() => useCreateAgentMutation({ onSuccess }), {+ wrapper: createWrapper(client),+ });+ await act(async () => {+ await result.current.mutateAsync({+ name: 'new',+ provider: 'openAI',+ model: 'test-model',+ model_parameters: createAgent('new').model_parameters,+ });+ });+ expect(onSuccess).toHaveBeenCalledTimes(1);+ client.clear();+ });++ it('calls update success once with absent list caches', async () => {+ const client = new QueryClient();+ const onSuccess = jest.fn();+ jest.mocked(dataService.updateAgent).mockResolvedValue(createAgent('owned'));+ const { result } = renderHook(() => useUpdateAgentMutation({ onSuccess }), {+ wrapper: createWrapper(client),+ });+ await act(async () => {+ await result.current.mutateAsync({ agent_id: 'owned', data: { name: 'new' } });+ });+ expect(onSuccess).toHaveBeenCalledTimes(1);+ client.clear();+ });++ it('calls delete success once with absent list caches', async () => {+ const client = new QueryClient();+ const onSuccess = jest.fn();+ jest.mocked(dataService.deleteAgent).mockResolvedValue();+ const { result } = renderHook(() => useDeleteAgentMutation({ onSuccess }), {+ wrapper: createWrapper(client),+ });+ await act(async () => {+ await result.current.mutateAsync({ agent_id: 'owned' });+ });+ expect(onSuccess).toHaveBeenCalledTimes(1);+ client.clear();+ });++ it('returns shared agents for deletion fallback instead of the authored subset', async () => {+ const client = new QueryClient();+ const onSuccess = jest.fn();+ const shared = createAgent('shared');+ for (const params of [+ { requiredPermission: PermissionBits.EDIT },+ { requiredPermission: PermissionBits.EDIT, mine: 1 },+ ]) {+ client.setQueryData([QueryKeys.agents, params], {+ object: 'list',+ data: params.mine ? [createAgent('owned')] : [createAgent('owned'), shared],+ first_id: 'owned',+ last_id: 'shared',+ has_more: false,+ });+ }+ jest.mocked(dataService.deleteAgent).mockResolvedValue();+ const { result } = renderHook(() => useDeleteAgentMutation({ onSuccess }), {+ wrapper: createWrapper(client),+ });+ await act(async () => {+ await result.current.mutateAsync({ agent_id: 'owned' });+ });+ expect(onSuccess.mock.calls.at(-1)?.[2]).toEqual([shared]);+ client.clear();+ });+});++it('calls action update success once with absent list caches', async () => {+ const client = new QueryClient();+ const onSuccess = jest.fn();+ jest+ .mocked(dataService.updateAgentAction)+ .mockResolvedValue([+ createAgent('owned'),+ { agent_id: 'owned', action_id: 'action', version: 1, metadata: { domain: 'example.com' } },+ ]);+ const { result } = renderHook(() => useUpdateAgentAction({ onSuccess }), {+ wrapper: createWrapper(client),+ });+ await act(async () => {+ await result.current.mutateAsync({+ agent_id: 'owned',+ action_id: 'action',+ metadata: { domain: 'example.com' },+ functions: [],+ });+ });+ expect(onSuccess).toHaveBeenCalledTimes(1);+ client.clear();+});diff --git a/client/src/data-provider/Agents/mutations.ts b/client/src/data-provider/Agents/mutations.tsindex c60c7d24bb..29b4f00535 100644--- a/client/src/data-provider/Agents/mutations.ts+++ b/client/src/data-provider/Agents/mutations.ts@@ -9,6 +9,8 @@ import type * as t from 'librechat-data-provider';export const allAgentViewAndEditQueryKeys: t.AgentListParams[] = [{ requiredPermission: PermissionBits.VIEW },{ requiredPermission: PermissionBits.EDIT },+ { requiredPermission: PermissionBits.VIEW, mine: 1 },+ { requiredPermission: PermissionBits.EDIT, mine: 1 },];const edgeEndpointIncludesAgent = (endpoint: string | string[], agentId: string): boolean =>@@ -82,7 +84,7 @@ export const useCreateAgentMutation = (keys.forEach((key) => {const listRes = queryClient.getQueryData<t.AgentListResponse>([QueryKeys.agents, key]);if (!listRes) {- return options?.onSuccess?.(newAgent, variables, context);+ return;}/** The create succeeded, so the caller can edit it. Mutation responses carry no* `isEditable`; without this the cached row loses the field the list sets. */@@ -129,7 +131,7 @@ export const useUpdateAgentMutation = (const listRes = queryClient.getQueryData<t.AgentListResponse>([QueryKeys.agents, key]);if (!listRes) {- return options?.onSuccess?.(updatedAgent, variables, context);+ return;}queryClient.setQueryData<t.AgentListResponse>([QueryKeys.agents, key], {@@ -171,24 +173,28 @@ export const useDeleteAgentMutation = ({onMutate: (variables) => options?.onMutate?.(variables),onError: (error, variables, context) => options?.onError?.(error, variables, context),- onSuccess: (_data, variables, context) => {+ onSuccess: (_data, variables) => {const data = ((keys: t.AgentListParams[]) => {let data: t.Agent[] = [];keys.forEach((key) => {const listRes = queryClient.getQueryData<t.AgentListResponse>([QueryKeys.agents, key]);if (!listRes) {- return options?.onSuccess?.(_data, variables, context);+ return;}- data = listRes.data+ const remainingAgents = listRes.data.filter((agent) => agent.id !== variables.agent_id).map((agent) => pruneAgentEdges(agent, variables.agent_id));queryClient.setQueryData<t.AgentListResponse>([QueryKeys.agents, key], {...listRes,- data,+ data: remainingAgents,});+ // Filtered lists are updated, but never drive post-delete selection.+ if (key.mine !== 1) {+ data = remainingAgents;+ }});return data;})(allAgentViewAndEditQueryKeys);@@ -331,7 +337,7 @@ export const useUpdateAgentAction = (const listRes = queryClient.getQueryData<t.AgentListResponse>([QueryKeys.agents, key]);if (!listRes) {- return options?.onSuccess?.(updateAgentActionResponse, variables, context);+ return;}queryClient.setQueryData<t.AgentListResponse>([QueryKeys.agents, key], {...listRes,diff --git a/packages/client/src/components/ControlCombobox.spec.tsx b/packages/client/src/components/ControlCombobox.spec.tsxindex 31a253bb95..40dba1f8dc 100644--- a/packages/client/src/components/ControlCombobox.spec.tsx+++ b/packages/client/src/components/ControlCombobox.spec.tsx@@ -404,3 +404,28 @@ describe('ControlCombobox portal placement', () => {expect(screen.queryByRole('option', { name: 'Option A' })).not.toBeInTheDocument();});});++describe('ControlCombobox search actions', () => {+ it('renders an actionable filter beside search without selecting an option', () => {+ const onFilter = jest.fn();+ const onSelect = jest.fn();+ render(+ <ControlCombobox+ selectedValue="a"+ items={items}+ setValue={onSelect}+ ariaLabel="Test combobox"+ isCollapsed={false}+ searchActions={<button onClick={onFilter}>My agents</button>}+ />,+ );+ openPopover();+ fireEvent.click(screen.getByRole('button', { name: 'My agents' }));+ expect(onFilter).toHaveBeenCalledTimes(1);+ expect(onSelect).not.toHaveBeenCalled();+ expect(screen.getByRole('combobox', { name: 'Test combobox' })).toHaveAttribute(+ 'aria-expanded',+ 'true',+ );+ });+});diff --git a/packages/client/src/components/ControlCombobox.tsx b/packages/client/src/components/ControlCombobox.tsxindex 82a7cdb7e4..3fde30ff65 100644--- a/packages/client/src/components/ControlCombobox.tsx+++ b/packages/client/src/components/ControlCombobox.tsx@@ -29,6 +29,8 @@ interface ControlComboboxProps {ariaInvalid?: boolean;ariaDescribedBy?: string;searchPlaceholder?: string;+ /** Optional controls beside the search field, outside the option list. */+ searchActions?: React.ReactNode;selectPlaceholder?: string;isCollapsed: boolean;SelectIcon?: React.ReactNode;@@ -79,6 +81,7 @@ function ControlCombobox({ariaInvalid,ariaDescribedBy,searchPlaceholder,+ searchActions,selectPlaceholder,containerClassName,isCollapsed,@@ -282,8 +285,8 @@ function ControlCombobox({minWidth: matchTriggerWidth ? undefined : 'min(16rem, 90vw)',}}>- <div className="shrink-0 py-1.5">- <div className="relative">+ <div className="flex shrink-0 items-center gap-2 py-1.5">+ <div className="relative min-w-0 flex-1"><Search className="text-text-primary absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2" /><Ariakit.Comboboxstore={combobox}@@ -292,6 +295,7 @@ function ControlCombobox({className="bg-surface-secondary text-text-primary w-full rounded-md py-2 ps-9 pe-3 text-sm focus:outline-hidden"/></div>+ {searchActions != null && <div className="shrink-0 pe-2">{searchActions}</div>}</div><divclassName={cn(