Skip to content

Commit 954b09e

Browse files
authored
Merge pull request #22 from CoolSpring8/settings-modal-refine
Refactor settings management with provider-based configuration
2 parents ca34189 + 5728bf9 commit 954b09e

5 files changed

Lines changed: 748 additions & 190 deletions

File tree

src/App.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,50 @@ import { useEnsureSystemMessage } from "./hooks/useEnsureSystemMessage";
1818
import { useProviderReadiness } from "./hooks/useProviderReadiness";
1919
import { useTextCompletion } from "./hooks/useTextCompletion";
2020
import { useSettingsStore } from "./state/useSettingsStore";
21-
import type { AppView } from "./types";
21+
import type { AppView, ModelInfo } from "./types";
2222

2323
const defaultSystemPrompt = "You are a helpful assistant.";
24+
const emptyModels: ModelInfo[] = [];
2425

2526
const App = () => {
2627
const {
27-
baseURL,
28-
apiKey,
29-
models,
30-
activeModel,
28+
providers,
29+
activeProviderId,
3130
setActiveModel,
32-
providerKind,
31+
enableBeforeUnloadWarning,
3332
builtInAvailability,
3433
hydrate,
3534
refreshBuiltInAvailability,
3635
} = useSettingsStore(
3736
useShallow((state) => ({
38-
baseURL: state.baseURL,
39-
apiKey: state.apiKey,
40-
models: state.models,
41-
activeModel: state.activeModel,
37+
providers: state.providers,
38+
activeProviderId: state.activeProviderId,
4239
setActiveModel: state.setActiveModel,
43-
providerKind: state.providerKind,
40+
enableBeforeUnloadWarning: state.enableBeforeUnloadWarning,
4441
builtInAvailability: state.builtInAvailability,
4542
hydrate: state.hydrate,
4643
refreshBuiltInAvailability: state.refreshBuiltInAvailability,
4744
})),
4845
);
4946
const [view, setView] = useState<AppView>("chat");
5047

48+
const activeProvider = useMemo(
49+
() => providers.find((p) => p.id === activeProviderId),
50+
[providers, activeProviderId],
51+
);
52+
53+
const models = activeProvider?.models ?? emptyModels;
54+
const activeModel = activeProvider?.activeModelId ?? null;
55+
56+
const providerKind = activeProvider?.kind ?? "openai-compatible";
57+
5158
const openAIProvider = useMemo(
5259
() =>
5360
buildOpenAICompatibleProvider({
54-
baseURL,
55-
apiKey,
61+
baseURL: activeProvider?.config.baseURL ?? "",
62+
apiKey: activeProvider?.config.apiKey ?? "",
5663
}),
57-
[apiKey, baseURL],
64+
[activeProvider],
5865
);
5966

6067
const getBuiltInChatModel = useCallback(() => builtInAI(), []);
@@ -155,7 +162,7 @@ const App = () => {
155162
typeof editingMessageId !== "undefined" ||
156163
chatMessages.length > 1;
157164

158-
useBeforeUnloadGuard(hasSessionState);
165+
useBeforeUnloadGuard(enableBeforeUnloadWarning && hasSessionState);
159166

160167
const handleClearConversation = useCallback(() => {
161168
clearConversation();

0 commit comments

Comments
 (0)