Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ refactor: refactor and clean global store and chat store #774

Merged
merged 3 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🔥 refactor: clean deprecated code
  • Loading branch information
arvinxx committed Dec 23, 2023
commit 3329df68dbe89d861b45521e07273f130665fde1
4 changes: 2 additions & 2 deletions src/services/_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { useGlobalStore } from '@/store/global';
export const createHeaderWithOpenAI = (header?: HeadersInit): HeadersInit => {
const openai = useGlobalStore.getState().settings.languageModel.openAI;

const apiKey = openai.OPENAI_API_KEY || useGlobalStore.getState().settings.OPENAI_API_KEY || '';
const endpoint = openai.endpoint || useGlobalStore.getState().settings.endpoint || '';
const apiKey = openai.OPENAI_API_KEY || '';
const endpoint = openai.endpoint || '';

// eslint-disable-next-line no-undef
const result: HeadersInit = {
Expand Down
2 changes: 1 addition & 1 deletion src/store/global/slices/settings/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
importAppSettings: (importAppSettings) => {
const { setSettings } = get();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { OPENAI_API_KEY: _, password: __, ...settings } = importAppSettings;
const { password: _, ...settings } = importAppSettings;

Check warning on line 51 in src/store/global/slices/settings/action.ts

View check run for this annotation

Codecov / codecov/patch

src/store/global/slices/settings/action.ts#L51

Added line #L51 was not covered by tests

setSettings({
...settings,
Expand Down
5 changes: 2 additions & 3 deletions src/store/global/slices/settings/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

const defaultAgentMeta = (s: GlobalStore) => merge(DEFAULT_AGENT_META, defaultAgent(s).meta);

const openAIAPIKeySelectors = (s: GlobalStore) =>
s.settings.languageModel.openAI.OPENAI_API_KEY || s.settings.OPENAI_API_KEY;
const openAIAPIKeySelectors = (s: GlobalStore) => s.settings.languageModel.openAI.OPENAI_API_KEY;

const openAIProxyUrlSelectors = (s: GlobalStore) => s.settings.languageModel.openAI.endpoint;

Expand Down Expand Up @@ -68,7 +67,7 @@

export const exportSettings = (s: GlobalStore) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { OPENAI_API_KEY: _, password: __, ...settings } = s.settings;
const { password: _, ...settings } = s.settings;

Check warning on line 70 in src/store/global/slices/settings/selectors.ts

View check run for this annotation

Codecov / codecov/patch

src/store/global/slices/settings/selectors.ts#L70

Added line #L70 was not covered by tests

return settings as GlobalSettings;
};
Expand Down
14 changes: 1 addition & 13 deletions src/store/global/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,12 @@
if (!draft.defaultAgent) {
draft.defaultAgent = DEFAULT_AGENT;
}
delete draft.enableMaxTokens;
delete draft.enableHistoryCount;
delete draft.historyCount;
delete draft.enableCompressThreshold;
delete draft.compressThreshold;

// migration to new data model
if (!draft.languageModel) {
draft.languageModel = {
openAI: {
...DEFAULT_LLM_CONFIG.openAI,
OPENAI_API_KEY: draft.OPENAI_API_KEY || DEFAULT_LLM_CONFIG.openAI.OPENAI_API_KEY,
endpoint: draft.endpoint || DEFAULT_LLM_CONFIG.openAI.OPENAI_API_KEY,
},
openAI: DEFAULT_LLM_CONFIG.openAI,

Check warning on line 43 in src/store/global/store.ts

View check run for this annotation

Codecov / codecov/patch

src/store/global/store.ts#L43

Added line #L43 was not covered by tests
};

delete draft.OPENAI_API_KEY;
delete draft.endpoint;
}
}),
};
Expand Down
29 changes: 0 additions & 29 deletions src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,8 @@ import { LocaleMode } from '@/types/locale';
import type { LobeAgentSession } from '@/types/session';

export interface GlobalBaseSettings {
/**
* @deprecated
*/
OPENAI_API_KEY?: string;

avatar: string;
/**
* @deprecated
*/
compressThreshold?: number;
/**
* @deprecated
*/
enableCompressThreshold?: boolean;
/**
* @deprecated
*/
enableHistoryCount?: boolean;
/**
* @deprecated
*/
enableMaxTokens?: boolean;
/**
* @deprecated
*/
endpoint?: string;
fontSize: number;
/**
* @deprecated
*/
historyCount?: number;
language: LocaleMode;
neutralColor?: NeutralColors;
password: string;
Expand Down
Loading