🤯 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(inbox): restore inbox avatar fallback after deletion (#13752)
Inneif2ee67c3c5dd
diff --git a/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.tsx b/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.tsxindex 430845c45a5..6ef60609a96 100644--- a/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.tsx+++ b/src/routes/(main)/agent/profile/features/ProfileEditor/AgentHeader.tsx@@ -75,7 +75,7 @@ const AgentHeader = memo(() => {// Handle avatar deleteconst handleAvatarDelete = useCallback(() => {- updateMeta({ avatar: undefined });+ updateMeta({ avatar: null });}, [updateMeta]);// Handle background color change (immediate save)diff --git a/src/routes/(main)/group/profile/features/MemberProfile/AgentHeader.tsx b/src/routes/(main)/group/profile/features/MemberProfile/AgentHeader.tsxindex b370ad26839..4cbb6d33d61 100644--- a/src/routes/(main)/group/profile/features/MemberProfile/AgentHeader.tsx+++ b/src/routes/(main)/group/profile/features/MemberProfile/AgentHeader.tsx@@ -87,7 +87,7 @@ const AgentHeader = memo<AgentHeaderProps>(({ readOnly }) => {// Handle avatar deleteconst handleAvatarDelete = useCallback(() => {- optimisticUpdateAgentMeta(agentId, { avatar: undefined });+ optimisticUpdateAgentMeta(agentId, { avatar: null });}, [optimisticUpdateAgentMeta, agentId]);// Handle background color change (immediate save) - save to agent store (supervisor agent)diff --git a/src/services/agent.ts b/src/services/agent.tsindex 0ae028d7d40..8a9027eec6e 100644--- a/src/services/agent.ts+++ b/src/services/agent.ts@@ -1,4 +1,4 @@-import { type AgentItem, type LobeAgentConfig, type MetaData } from '@lobechat/types';+import { type AgentItem, type LobeAgentConfig } from '@lobechat/types';import { type PartialDeep } from 'type-fest';import { lambdaClient } from '@/libs/trpc/client';@@ -14,6 +14,13 @@ type MarketAgentModel =provider?: LobeAgentConfig['provider'];};+type AgentMetaUpdate = Partial<+ Pick<+ AgentItem,+ 'avatar' | 'backgroundColor' | 'description' | 'marketIdentifier' | 'tags' | 'title'+ >+>;+/*** Normalize market agent config to standard agent config.* Handles the case where market returns model as an object instead of string.@@ -182,7 +189,7 @@ class AgentService {/*** Update agent meta and return the updated agent data*/- updateAgentMeta = async (agentId: string, meta: Partial<MetaData>, signal?: AbortSignal) => {+ updateAgentMeta = async (agentId: string, meta: AgentMetaUpdate, signal?: AbortSignal) => {return lambdaClient.agent.updateAgentConfig.mutate({ agentId, value: meta }, { signal });};diff --git a/src/store/agent/selectors/selectors.test.ts b/src/store/agent/selectors/selectors.test.tsindex c2066a1f8eb..20aacdd999f 100644--- a/src/store/agent/selectors/selectors.test.ts+++ b/src/store/agent/selectors/selectors.test.ts@@ -2,6 +2,7 @@ import { DEFAULT_PROVIDER } from '@lobechat/business-const';import {DEFAULT_AGENT_CONFIG,DEFAULT_AVATAR,+ DEFAULT_INBOX_AVATAR,DEFAULT_MODEL,DEFAUTT_AGENT_TTS_CONFIG,INBOX_SESSION_ID,@@ -136,6 +137,18 @@ describe('agentSelectors', () => {expect(meta.avatar).toBe(DEFAULT_AVATAR);});++ it('should return inbox avatar fallback for inbox agent with no custom avatar', () => {+ const state = createState({+ activeAgentId: 'inbox-agent',+ agentMap: { 'inbox-agent': {} },+ builtinAgentIdMap: { [INBOX_SESSION_ID]: 'inbox-agent' },+ });++ const meta = agentSelectors.currentAgentMeta(state);++ expect(meta.avatar).toBe(DEFAULT_INBOX_AVATAR);+ });});describe('getAgentMetaById', () => {@@ -161,6 +174,17 @@ describe('agentSelectors', () => {expect(meta).toEqual({});});++ it('should return inbox avatar fallback for inbox agent with no custom avatar', () => {+ const state = createState({+ agentMap: { 'inbox-agent': {} },+ builtinAgentIdMap: { [INBOX_SESSION_ID]: 'inbox-agent' },+ });++ const meta = agentSelectors.getAgentMetaById('inbox-agent')(state);++ expect(meta.avatar).toBe(DEFAULT_INBOX_AVATAR);+ });});describe('currentAgentPlugins', () => {diff --git a/src/store/agent/selectors/selectors.ts b/src/store/agent/selectors/selectors.tsindex 015509eb954..f73e928137f 100644--- a/src/store/agent/selectors/selectors.ts+++ b/src/store/agent/selectors/selectors.ts@@ -3,6 +3,7 @@ import {DEFAULT_AGENT_CONFIG,DEFAULT_AVATAR,DEFAULT_BACKGROUND_COLOR,+ DEFAULT_INBOX_AVATAR,DEFAULT_MODEL,DEFAUTT_AGENT_TTS_CONFIG,isDesktop,@@ -33,7 +34,14 @@ const currentAgentData = (s: AgentStoreState) =>const currentAgentTitle = (s: AgentStoreState) => currentAgentData(s)?.title;-const currentAgentAvatar = (s: AgentStoreState) => currentAgentData(s)?.avatar || DEFAULT_AVATAR;+const getDefaultAvatarByAgentId = (s: AgentStoreState, agentId?: string) => {+ const inboxAgentId = builtinAgentSelectors.inboxAgentId(s);++ return agentId && inboxAgentId === agentId ? DEFAULT_INBOX_AVATAR : DEFAULT_AVATAR;+};++const currentAgentAvatar = (s: AgentStoreState) =>+ currentAgentData(s)?.avatar || getDefaultAvatarByAgentId(s, s.activeAgentId);const currentAgentDescription = (s: AgentStoreState) => currentAgentData(s)?.description;@@ -49,7 +57,7 @@ const currentAgentTags = (s: AgentStoreState) => currentAgentData(s)?.tags || []const currentAgentMeta = (s: AgentStoreState): MetaData => {const data = currentAgentData(s);return {- avatar: data?.avatar || DEFAULT_AVATAR,+ avatar: data?.avatar || getDefaultAvatarByAgentId(s, s.activeAgentId),backgroundColor: data?.backgroundColor || DEFAULT_BACKGROUND_COLOR,description: data?.description || undefined,marketIdentifier: data?.marketIdentifier || undefined,@@ -69,7 +77,7 @@ const getAgentMetaById =if (!data) return {};return {- avatar: data.avatar || DEFAULT_AVATAR,+ avatar: data.avatar || getDefaultAvatarByAgentId(s, agentId),backgroundColor: data.backgroundColor || DEFAULT_BACKGROUND_COLOR,description: data.description || undefined,marketIdentifier: data.marketIdentifier || undefined,diff --git a/src/store/agent/slices/agent/action.test.ts b/src/store/agent/slices/agent/action.test.tsindex 14e45067959..c9dc129855a 100644--- a/src/store/agent/slices/agent/action.test.ts+++ b/src/store/agent/slices/agent/action.test.ts@@ -266,6 +266,29 @@ describe('AgentSlice Actions', () => {expect.any(AbortSignal),);});++ it('should preserve explicit null when clearing avatar', async () => {+ const { result } = renderHook(() => useAgentStore());++ vi.mocked(agentService.updateAgentMeta).mockResolvedValue({+ agent: { avatar: null } as any,+ success: true,+ });++ act(() => {+ useAgentStore.setState({ activeAgentId: 'agent-1' });+ });++ await act(async () => {+ await result.current.updateAgentMeta({ avatar: null });+ });++ expect(agentService.updateAgentMeta).toHaveBeenCalledWith(+ 'agent-1',+ { avatar: null },+ expect.any(AbortSignal),+ );+ });});describe('updateAgentChatConfig', () => {diff --git a/src/store/agent/slices/agent/action.ts b/src/store/agent/slices/agent/action.tsindex 41932d9d5cf..c284a730ef2 100644--- a/src/store/agent/slices/agent/action.ts+++ b/src/store/agent/slices/agent/action.ts@@ -20,8 +20,12 @@ import {import type { StoreSetter } from '@/store/types';import { getUserStoreState } from '@/store/user';import { userProfileSelectors } from '@/store/user/selectors';-import type { LobeAgentChatConfig, LobeAgentConfig, RuntimeEnvConfig } from '@/types/agent';-import type { MetaData } from '@/types/meta';+import type {+ AgentItem,+ LobeAgentChatConfig,+ LobeAgentConfig,+ RuntimeEnvConfig,+} from '@/types/agent';import { merge } from '@/utils/merge';import type { AgentStore } from '../../store';@@ -29,6 +33,12 @@ import { setLocalAgentWorkingDirectory } from '../../utils/localAgentWorkingDireimport type { AgentSliceState, LoadingState, SaveStatus } from './initialState';const FETCH_AGENT_CONFIG_KEY = 'FETCH_AGENT_CONFIG';+type AgentMetaUpdate = Partial<+ Pick<+ AgentItem,+ 'avatar' | 'backgroundColor' | 'description' | 'marketIdentifier' | 'tags' | 'title'+ >+>;/*** Agent Slice Actions@@ -227,7 +237,7 @@ export class AgentSliceActionImpl {}};- updateAgentMeta = async (meta: Partial<MetaData>): Promise<void> => {+ updateAgentMeta = async (meta: AgentMetaUpdate): Promise<void> => {const { activeAgentId } = this.#get();if (!activeAgentId) return;@@ -369,7 +379,7 @@ export class AgentSliceActionImpl {optimisticUpdateAgentMeta = async (id: string,- meta: Partial<MetaData>,+ meta: AgentMetaUpdate,signal?: AbortSignal,): Promise<void> => {const { internal_dispatchAgentMap, updateSaveStatus } = this.#get();