fix(ai-ui): hide api key field for ollama

This commit is contained in:
Vyacheslav Scherbinin
2025-08-19 23:56:54 +07:00
parent 220576fd63
commit 623fc26de5
@@ -53,7 +53,6 @@ export const HandleAi = ({ aiId }: Props) => {
const utils = api.useUtils(); const utils = api.useUtils();
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [fetchModels, setFetchModels] = useState(false);
const { data, refetch } = api.ai.one.useQuery( const { data, refetch } = api.ai.one.useQuery(
{ {
aiId: aiId || "", aiId: aiId || "",
@@ -90,6 +89,7 @@ export const HandleAi = ({ aiId }: Props) => {
const apiUrl = form.watch("apiUrl"); const apiUrl = form.watch("apiUrl");
const apiKey = form.watch("apiKey"); const apiKey = form.watch("apiKey");
const isOllama = apiUrl.includes(":11434") || apiUrl.includes("ollama");
const { data: models, isLoading: isLoadingServerModels } = const { data: models, isLoading: isLoadingServerModels } =
api.ai.getModels.useQuery( api.ai.getModels.useQuery(
{ {
@@ -97,18 +97,13 @@ export const HandleAi = ({ aiId }: Props) => {
apiKey: apiKey ?? "", apiKey: apiKey ?? "",
}, },
{ {
enabled: fetchModels, enabled: !!apiUrl && (isOllama || !!apiKey),
onError: (error) => { onError: (error) => {
setError(`Failed to fetch models: ${error.message}`); setError(`Failed to fetch models: ${error.message}`);
}, },
}, },
); );
useEffect(() => {
const isOllama = apiUrl.includes(":11434") || apiUrl.includes("ollama");
setFetchModels(!!apiUrl && isOllama || !!apiKey);
}, [apiUrl, apiKey]);
useEffect(() => { useEffect(() => {
const apiUrl = form.watch("apiUrl"); const apiUrl = form.watch("apiUrl");
const apiKey = form.watch("apiKey"); const apiKey = form.watch("apiKey");
@@ -197,6 +192,7 @@ export const HandleAi = ({ aiId }: Props) => {
)} )}
/> />
{!isOllama && (
<FormField <FormField
control={form.control} control={form.control}
name="apiKey" name="apiKey"
@@ -218,6 +214,7 @@ export const HandleAi = ({ aiId }: Props) => {
</FormItem> </FormItem>
)} )}
/> />
)}
{isLoadingServerModels && ( {isLoadingServerModels && (
<span className="text-sm text-muted-foreground"> <span className="text-sm text-muted-foreground">