@@ -2,6 +2,8 @@ import { useEffect, useState } from "react";
22import { ApiBaseUrlField , ApiKeyField } from "./connect-fields" ;
33import type { ProviderConnectFormProps } from "./provider-metadata" ;
44
5+ const OPTIONAL_API_KEY_PROVIDERS = new Set ( [ "ollama_chat" , "lm_studio" , "openai_compatible" ] ) ;
6+
57function baseUrlHint ( provider : string ) {
68 if ( provider === "ollama_chat" || provider === "lm_studio" ) {
79 return "For local servers, use host.docker.internal instead of localhost." ;
@@ -28,13 +30,14 @@ export function DefaultConnectForm({
2830} : ProviderConnectFormProps ) {
2931 const [ baseUrl , setBaseUrl ] = useState ( defaultBaseUrl ) ;
3032 const [ apiKey , setApiKey ] = useState ( "" ) ;
31- const isOllama = provider === "ollama_chat" ;
33+ const isApiKeyOptional = OPTIONAL_API_KEY_PROVIDERS . has ( provider ) ;
3234 const hint = baseUrlHint ( provider ) ;
33- const canSubmit = ! ( baseUrlRequired && ! baseUrl . trim ( ) ) ;
35+ const apiKeyValue = apiKey . trim ( ) ;
36+ const canSubmit = ! ( baseUrlRequired && ! baseUrl . trim ( ) ) && ( isApiKeyOptional || Boolean ( apiKeyValue ) ) ;
3437
3538 useEffect ( ( ) => {
36- onDraftChange ( { base_url : baseUrl || null , api_key : apiKey || null , extra : { } } , canSubmit ) ;
37- } , [ apiKey , baseUrl , canSubmit , onDraftChange ] ) ;
39+ onDraftChange ( { base_url : baseUrl || null , api_key : apiKeyValue || null , extra : { } } , canSubmit ) ;
40+ } , [ apiKeyValue , baseUrl , canSubmit , onDraftChange ] ) ;
3841
3942 return (
4043 < div className = "flex flex-col gap-4" >
@@ -47,8 +50,8 @@ export function DefaultConnectForm({
4750 < ApiKeyField
4851 value = { apiKey }
4952 onChange = { setApiKey }
50- label = { isOllama ? "API Key (optional)" : "API Key" }
51- placeholder = { isOllama ? "Optional for Ollama" : " API key"}
53+ label = { isApiKeyOptional ? "API Key (optional)" : "API Key" }
54+ placeholder = "Enter your API key"
5255 />
5356 </ div >
5457 ) ;
0 commit comments