5757 "medium": "pi-medium",
5858 "large": "pi-large",
5959 }
60+ PROFILE_UI_SPECS = {
61+ "small": os.environ.get("PI_PROFILE_SMALL_SPEC", "2 cpu / 8G RAM"),
62+ "medium": os.environ.get("PI_PROFILE_MEDIUM_SPEC", "4 cpu / 16G RAM"),
63+ "large": os.environ.get("PI_PROFILE_LARGE_SPEC", "8 cpu / 32G RAM"),
64+ }
6065
6166 def hub_request(method: str, path: str, **kwargs):
6267 headers = kwargs.pop("headers", {})
@@ -832,17 +837,17 @@ def get(self):
832837 <form method="post" action="{SERVICE_PREFIX}/launch">
833838 <input type="hidden" name="_xsrf" value="{xsrf_token}" />
834839 <input type="hidden" name="size" value="small" />
835- <button class="btn" type="submit">Small<small>2 cpu / 8 GB ram </small></button>
840+ <button class="btn" type="submit">Small<small>{html.escape(str(PROFILE_UI_SPECS.get('small', '')))} </small></button>
836841 </form>
837842 <form method="post" action="{SERVICE_PREFIX}/launch">
838843 <input type="hidden" name="_xsrf" value="{xsrf_token}" />
839844 <input type="hidden" name="size" value="medium" />
840- <button class="btn" type="submit">Medium<small>4 cpu / 16 GB ram </small></button>
845+ <button class="btn" type="submit">Medium<small>{html.escape(str(PROFILE_UI_SPECS.get('medium', '')))} </small></button>
841846 </form>
842847 <form method="post" action="{SERVICE_PREFIX}/launch">
843848 <input type="hidden" name="_xsrf" value="{xsrf_token}" />
844849 <input type="hidden" name="size" value="large" />
845- <button class="btn" type="submit">Large<small>8 cpu / 32 GB ram </small></button>
850+ <button class="btn" type="submit">Large<small>{html.escape(str(PROFILE_UI_SPECS.get('large', '')))} </small></button>
846851 </form>
847852 </div>
848853 <div class="row">
@@ -1590,10 +1595,39 @@ def make_app():
15901595pi_sharing_namespace = str (z2jh .get_config ("custom.pi-sharing-namespace" , "" ) or "" ).strip ()
15911596pi_share_session_max_bytes = str (z2jh .get_config ("custom.pi-share-session-max-bytes" , 1048576 ))
15921597pi_coding_agent_dir = str (z2jh .get_config ("custom.pi-coding-agent-dir" , "/tmp/pi-agent" ) or "/tmp/pi-agent" ).strip ()
1598+
1599+ pi_profiles_cfg = z2jh .get_config ("custom.pi-profiles" , {}) or {}
1600+
1601+ def _format_cpu_value (value ):
1602+ if value is None :
1603+ return ""
1604+ try :
1605+ f = float (value )
1606+ if f .is_integer ():
1607+ return str (int (f ))
1608+ except Exception :
1609+ pass
1610+ return str (value )
1611+
1612+ def _profile_spec_text (size_key , default_text ):
1613+ if isinstance (pi_profiles_cfg , dict ):
1614+ spec = pi_profiles_cfg .get (size_key )
1615+ if isinstance (spec , dict ):
1616+ cpu = _format_cpu_value (spec .get ("cpu_limit" ))
1617+ mem = str (spec .get ("mem_limit" ) or "" ).strip ()
1618+ if cpu and mem :
1619+ return f"{ cpu } cpu / { mem } RAM"
1620+ return default_text
1621+
1622+ pi_profile_small_spec = _profile_spec_text ("small" , "2 cpu / 8G RAM" )
1623+ pi_profile_medium_spec = _profile_spec_text ("medium" , "4 cpu / 16G RAM" )
1624+ pi_profile_large_spec = _profile_spec_text ("large" , "8 cpu / 32G RAM" )
1625+
15931626public_host = z2jh .get_config ("custom.external-url" ) or ""
15941627public_host = str (public_host ).strip ().rstrip ("/" )
15951628if public_host and not public_host .startswith (("http://" , "https://" )):
1596- public_host = f"https://{ public_host } "
1629+ public_scheme = str (z2jh .get_config ("custom.external-url-scheme" , "https" ) or "https" ).strip ()
1630+ public_host = f"{ public_scheme } ://{ public_host } "
15971631pi_launcher_oauth_redirect_uri = f"{ public_host } /services/{ pi_launcher_service_name } /oauth_callback"
15981632
15991633launcher_env = {
@@ -1605,6 +1639,9 @@ def make_app():
16051639 "PI_LIVE_SHARE_ENABLED" : pi_live_share_enabled ,
16061640 "PI_SHARE_SESSION_MAX_BYTES" : pi_share_session_max_bytes ,
16071641 "PI_CODING_AGENT_DIR" : pi_coding_agent_dir ,
1642+ "PI_PROFILE_SMALL_SPEC" : pi_profile_small_spec ,
1643+ "PI_PROFILE_MEDIUM_SPEC" : pi_profile_medium_spec ,
1644+ "PI_PROFILE_LARGE_SPEC" : pi_profile_large_spec ,
16081645}
16091646if pi_sharing_namespace :
16101647 launcher_env ["PI_SHARING_NAMESPACE" ] = pi_sharing_namespace
0 commit comments