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,17 +97,12 @@ 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");
@@ -197,27 +192,29 @@ export const HandleAi = ({ aiId }: Props) => {
)} )}
/> />
<FormField {!isOllama && (
control={form.control} <FormField
name="apiKey" control={form.control}
render={({ field }) => ( name="apiKey"
<FormItem> render={({ field }) => (
<FormLabel>API Key</FormLabel> <FormItem>
<FormControl> <FormLabel>API Key</FormLabel>
<Input <FormControl>
type="password" <Input
placeholder="sk-..." type="password"
autoComplete="one-time-code" placeholder="sk-..."
{...field} autoComplete="one-time-code"
/> {...field}
</FormControl> />
<FormDescription> </FormControl>
Your API key for authentication <FormDescription>
</FormDescription> Your API key for authentication
<FormMessage /> </FormDescription>
</FormItem> <FormMessage />
)} </FormItem>
/> )}
/>
)}
{isLoadingServerModels && ( {isLoadingServerModels && (
<span className="text-sm text-muted-foreground"> <span className="text-sm text-muted-foreground">