1616
1717# Team ID validation pattern: CUID (v1)
1818TEAM_ID_PATTERN = re .compile (r"^c[a-z0-9]{24}$" )
19+ PROFILE_OVERRIDE_ENV_VARS = (
20+ "PRIME_API_KEY" ,
21+ "PRIME_TEAM_ID" ,
22+ "PRIME_USER_ID" ,
23+ "PRIME_API_BASE_URL" ,
24+ "PRIME_BASE_URL" ,
25+ "PRIME_FRONTEND_URL" ,
26+ "PRIME_INFERENCE_URL" ,
27+ "PRIME_CONTEXT" ,
28+ )
1929
2030
2131def validate_team_id (team_id : str ) -> bool :
@@ -32,6 +42,23 @@ def validate_team_id(team_id: str) -> bool:
3242 return bool (TEAM_ID_PATTERN .match (team_id ))
3343
3444
45+ def _active_profile_override_env_vars () -> list [str ]:
46+ return [name for name in PROFILE_OVERRIDE_ENV_VARS if (os .getenv (name ) or "" ).strip ()]
47+
48+
49+ def _require_profile_env_unset (command : str ) -> None :
50+ names = _active_profile_override_env_vars ()
51+ if not names :
52+ return
53+ joined = ", " .join (names )
54+ console .print (
55+ f"[red]Error:[/red] { joined } { 'is' if len (names ) == 1 else 'are' } set in your "
56+ f"environment, so [bold]prime config { command } [/bold] cannot make a saved profile "
57+ "active. Unset the environment override and rerun the command."
58+ )
59+ raise typer .Exit (1 )
60+
61+
3562@app .command ()
3663def view () -> None :
3764 """View current configuration"""
@@ -126,6 +153,7 @@ def set_api_key(
126153 )
127154
128155 config = Config ()
156+ config .use_production_environment ()
129157 config .set_api_key (api_key )
130158
131159 if api_key :
@@ -140,7 +168,6 @@ def set_api_key(
140168 user_id = data .get ("id" )
141169 if user_id :
142170 config .set_user_id (user_id )
143- config .update_current_environment_file ()
144171 except (APIError , Exception ):
145172 pass
146173
@@ -186,6 +213,7 @@ def set_team_id(
186213 except (APIError , Exception ):
187214 pass
188215
216+ config .use_production_environment ()
189217 config .set_team (team_id , team_name = team_name , team_role = team_role )
190218 if team_id :
191219 if team_name :
@@ -200,6 +228,7 @@ def set_team_id(
200228def remove_team_id () -> None :
201229 """Remove team ID to use personal account"""
202230 config = Config ()
231+ config .use_production_environment ()
203232 config .set_team (None )
204233 console .print ("[green]Team ID removed. Using personal account.[/green]" )
205234
@@ -278,6 +307,7 @@ def _set_environment(
278307 env : str ,
279308) -> None :
280309 """Set URLs for a specific environment"""
310+ _require_profile_env_unset (f"use { env } " )
281311 config = Config ()
282312
283313 # Try to load the environment (handles both built-in and custom)
@@ -384,7 +414,7 @@ def reset(
384414 config .set_base_url (Config .DEFAULT_BASE_URL )
385415 config .set_frontend_url (Config .DEFAULT_FRONTEND_URL )
386416 config .set_ssh_key_path (Config .DEFAULT_SSH_KEY_PATH )
387- config .set_current_environment ( "production" )
417+ config .use_production_environment ( )
388418 console .print ("[green]Configuration reset to defaults![/green]" )
389419
390420
0 commit comments