Skip to content

Commit

Permalink
✨ feat: Import and use constants from "meta.ts" instead of "agentConfig"
Browse files Browse the repository at this point in the history
The changes involve importing and using constants from a new file called "meta.ts" instead of importing them from the "agentConfig" file. The constants include DEFAULT_AVATAR, DEFAULT_USER_AVATAR, DEFAULT_BACKGROUND_COLOR, and DEFAULT_TITLE. The changes also involve updating the usage of these constants in different parts of the code.

- Import and use constants from "meta.ts" instead of "agentConfig"
- Update the usage of constants in various parts of the code
  • Loading branch information
canisminor1990 committed Jul 24, 2023
1 parent 64c8782 commit 1eb6a17
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/const/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const DEFAULT_AVATAR = '🤖';
export const DEFAULT_USER_AVATAR = '😀';
export const DEFAULT_BACKGROUND_COLOR = 'rgba(0,0,0,0)';
3 changes: 1 addition & 2 deletions src/pages/chat/SessionList/List/SessionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Flexbox } from 'react-layout-kit';
import { shallow } from 'zustand/shallow';

import { chatSelectors, sessionSelectors, useSessionStore } from '@/store/session';
import { DEFAULT_TITLE } from '@/store/session/slices/agentConfig';
import { useSettings } from '@/store/settings';

import { useStyles } from './style';
Expand Down Expand Up @@ -96,7 +95,7 @@ const SessionItem: FC<SessionItemProps> = memo(({ id, active = true, loading })
}
loading={loading}
style={{ color: theme.colorText }}
title={title || t(DEFAULT_TITLE)}
title={title || t('defaultSession')}
/>
<Popconfirm
arrow={false}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/chat/[id]/edit/AgentMeta/BackgroundSwatches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Swatches, primaryColorsSwatches } from '@lobehub/ui';
import { memo } from 'react';
import { shallow } from 'zustand/shallow';

import { DEFAULT_BACKGROUND_COLOR } from '@/const/meta';
import { agentSelectors, useSessionStore } from '@/store/session';
import { DEFAULT_BACKGROUND_COLOR } from '@/store/session/slices/agentConfig';

const BackgroundSwatches = memo(() => {
const [backgroundColor, updateAgentMeta] = useSessionStore(
Expand Down
6 changes: 0 additions & 6 deletions src/store/session/slices/agentConfig/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ export const initialLobeAgentConfig: LobeAgentConfig = {
systemRole: '',
};

export const DEFAULT_AVATAR = '🤖';

export const DEFAULT_BACKGROUND_COLOR = 'rgba(0,0,0,0)';

export const DEFAULT_TITLE = 'defaultSession';

export const initialAgentConfigState: AgentConfigState = {
// // loading 中间态
autocompleteLoading: {
Expand Down
3 changes: 2 additions & 1 deletion src/store/session/slices/agentConfig/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { DEFAULT_AVATAR, DEFAULT_BACKGROUND_COLOR } from '@/const/meta';
import { SessionStore } from '@/store/session';
import { LanguageModel } from '@/types/llm';
import { MetaData } from '@/types/meta';
import { LobeAgentConfig } from '@/types/session';

import { sessionSelectors } from '../session';
import { DEFAULT_AVATAR, DEFAULT_BACKGROUND_COLOR, initialLobeAgentConfig } from './initialState';
import { initialLobeAgentConfig } from './initialState';

const currentAgentMeta = (s: SessionStore): MetaData => {
const session = sessionSelectors.currentSession(s);
Expand Down
4 changes: 2 additions & 2 deletions src/store/session/slices/chat/selectors/chat.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DEFAULT_USER_AVATAR } from '@/const/meta';
import { agentSelectors } from '@/store/session';
import { useSettings } from '@/store/settings';
import { ChatMessage } from '@/types/chatMessage';

import type { SessionStore } from '../../../store';
import { DEFAULT_AVATAR } from '../../agentConfig';
import { sessionSelectors } from '../../session';
import { organizeChats } from './utils';

Expand All @@ -14,7 +14,7 @@ export const currentChats = (s: SessionStore): ChatMessage[] => {

return organizeChats(session, {
assistant: agentSelectors.currentAgentAvatar(s),
user: useSettings.getState().settings.avatar || DEFAULT_AVATAR,
user: useSettings.getState().settings.avatar || DEFAULT_USER_AVATAR,
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/store/session/slices/session/selectors/chat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEFAULT_AVATAR } from '@/store/session/slices/agentConfig';
import { DEFAULT_AVATAR } from '@/const/meta';
import { MetaData } from '@/types/meta';

export const getAgentAvatar = (s: MetaData) => s.avatar || DEFAULT_AVATAR;

0 comments on commit 1eb6a17

Please sign in to comment.