Skip to content

Commit 5ea58f1

Browse files
committed
fix: update openaiApiKey handling to refresh model list and cache (#107)
1 parent 50a5f0b commit 5ea58f1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

webapp/_webapp/src/views/settings/setting-text-input.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { useCallback, useEffect, useState } from "react";
2+
import { useQueryClient } from "@tanstack/react-query";
23
import { Button, cn } from "@heroui/react";
34
import { useSettingStore } from "../../stores/setting-store";
45
import { Settings } from "../../pkg/gen/apiclient/user/v1/user_pb";
56
import { PlainMessage } from "../../query/types";
67
import { useConversationStore } from "../../stores/conversation/conversation-store";
78
import { listSupportedModels } from "../../query/api";
9+
import { queryKeys } from "../../query/keys";
810

911
type SettingKey = keyof PlainMessage<Settings>;
1012

@@ -28,6 +30,7 @@ export function createSettingsTextInput<K extends SettingKey>(settingKey: K) {
2830
multiline = true,
2931
password = false,
3032
}: SettingsTextInputProps) {
33+
const queryClient = useQueryClient();
3134
const { settings, isUpdating, updateSettings } = useSettingStore();
3235
const { setCurrentConversation } = useConversationStore();
3336
const [value, setValue] = useState<string>("");
@@ -55,9 +58,10 @@ export function createSettingsTextInput<K extends SettingKey>(settingKey: K) {
5558
setOriginalValue(value.trim());
5659
setIsEditing(false);
5760

58-
// If openaiApiKey was updated, fetch new model list and update current model slug
61+
// If openaiApiKey was updated, fetch new model list, update React Query cache (so chat UI shows correct disabled state e.g. grey out BYOK-only models when key is removed), and update current model slug
5962
if (settingKey === "openaiApiKey") {
6063
const response = await listSupportedModels({});
64+
queryClient.setQueryData(queryKeys.chats.listSupportedModels().queryKey, response);
6165
if (response.models?.length) {
6266
const { currentConversation: latest } = useConversationStore.getState();
6367
// try to find a model that matches the current slug
@@ -78,7 +82,7 @@ export function createSettingsTextInput<K extends SettingKey>(settingKey: K) {
7882
}
7983
}
8084
}
81-
}, [value, settingKey, updateSettings]); // settingKey is an outer scope value, not a dependency
85+
}, [value, updateSettings, queryClient, setCurrentConversation]); // settingKey is an outer scope value, not a dependency
8286

8387
const handleEdit = useCallback(() => {
8488
setIsEditing(true);

0 commit comments

Comments
 (0)