@@ -154,6 +154,14 @@ def registry_install(name: str, registry_url: str = None, models_dir: str = None
154154 _api_url = api_url or os .environ .get ("OPENMODELSTUDIO_API_URL" ) or _load_api_url ()
155155 _token = token or os .environ .get ("OPENMODELSTUDIO_TOKEN" )
156156
157+ # Auto-detect local platform if no api_url is configured
158+ if not _api_url :
159+ _api_url = _auto_detect_api_url ()
160+
161+ # Auto-login if we have an api_url but no token
162+ if _api_url and not _token :
163+ _token = _auto_login (_api_url )
164+
157165 if _api_url :
158166 try :
159167 main_file = files [0 ]
@@ -196,6 +204,32 @@ def _load_api_url() -> str:
196204 return ""
197205
198206
207+ def _auto_detect_api_url () -> str :
208+ """Auto-detect local platform API (K8s NodePort at localhost:31001)."""
209+ try :
210+ resp = requests .get ("http://localhost:31001/healthz" , timeout = 2 )
211+ if resp .ok :
212+ return "http://localhost:31001"
213+ except Exception :
214+ pass
215+ return ""
216+
217+
218+ def _auto_login (api_url : str ) -> str :
219+ """Auto-login with default credentials to get a token for registration."""
220+ try :
221+ resp = requests .post (
222+ f"{ api_url } /auth/login" ,
223+ json = {"email" : "test@openmodel.studio" , "password" : "Test1234" },
224+ timeout = 10 ,
225+ )
226+ if resp .ok :
227+ return resp .json ().get ("access_token" , "" )
228+ except Exception :
229+ pass
230+ return ""
231+
232+
199233def registry_uninstall (name : str , models_dir : str = None ,
200234 api_url : str = None , token : str = None ) -> bool :
201235 """Uninstall a locally installed model.
@@ -222,6 +256,10 @@ def registry_uninstall(name: str, models_dir: str = None,
222256 # Also unregister from platform API
223257 _api_url = api_url or os .environ .get ("OPENMODELSTUDIO_API_URL" ) or _load_api_url ()
224258 _token = token or os .environ .get ("OPENMODELSTUDIO_TOKEN" )
259+ if not _api_url :
260+ _api_url = _auto_detect_api_url ()
261+ if _api_url and not _token :
262+ _token = _auto_login (_api_url )
225263 if _api_url :
226264 try :
227265 headers = {"Content-Type" : "application/json" }
0 commit comments