+
    jHàj-æ  ã                  óL  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ]P$                  ! R4      tR	R R
R RR!RR!RR"RR#RR$/tR%R R lltRRR
RRRRR/tR R ltR R lt]P2                   ! R R4      4       t^tR R lt ! R R4      tR# )&a8  Gateway slash commands that switch or tune the model route:
/model, /codex-runtime, /reasoning, /fast, /personality.

Split out of ``gateway/slash_commands.py``; bound onto ``GatewayRunner`` through
``GatewaySlashCommandsMixin``. Origin internals are imported lazily inside the bodies to avoid
the import cycle.
)ÚannotationsN)ÚAnyÚOptional©Út)ÚMessageEvent)Úatomic_config_write)Úbase_url_host_matcheszgateway.runÚfastÚonÚnormalÚoffÚautoÚcoldÚ	ultrafastc               ó(   € V ^8„  d   QhRRRRRRRR/# )	é   ÚmodelÚstrÚruntimeÚdictÚtierúOptional[str]ÚreturnÚbool© )Úformats   "ÚA/home/ubuntu/.hermes/hermes-agent/gateway/slash_commands_model.pyÚ__annotate__r   $   s/   € ÷ jñ j ð j¨dð j¸-ð jÐSWñ jó    c                ód   € ^ RI Hp V! WP                  R4      VP                  R4      VR7      RJ# )z¼The turn's own gate (``run_turn.py::_resolve_turn_agent_config``): a tier /fast accepts must be
one the session's next request actually carries, so proxies and other providers are refused.)Úresolve_fast_mode_overridesÚproviderÚbase_url)r"   r#   r   N)Úhermes_cli.modelsr!   Úget)r   r   r   r!   s   &&& r   Ú_fast_route_supportsr&   $   s9   € õ >á&ØŸ™ JÓ/¸'¿+¹+ÀjÓ:QÐX\ô^Øeiðjð jr   ÚshowTÚhideFc               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r   1   s   € ÷ ñ  -ñ r   c            	     óh   € ^ RI Hp  V ! 4       pV'       g   R# Vw  r#\        R\        RW#R7      R7      # )zµRefuse a model switch when the gateway is running stale code: a first-time lazy import on
a new code path can crash on a stale cached dependency. Scoped to the highest-risk trigger.)Údetect_code_skewNúgateway.model.error_prefixzgateway.model.err_skew)Úboot_revÚdisk_rev©Úerror)Úgateway.code_skewr+   r   )r+   Úskewr-   r.   s       r   Ú_model_switch_skew_guardr3   1   s8   € õ 3áÓ€DßÙØÑ€HÜØ$ÜÐ(°8ÔOôð r   c               ó   € V ^8„  d   QhRR/# ©r   r   ÚNoner   )r   s   "r   r   r   @   s   € ÷ Jñ JÀ$ñ Jr   c              ƒ  ó\   "  € ^ RI Hp \        P                  ! W V4      G Rj  x€L
  R#  L5i)z–Write-through a resolved /model switch to the profile config at ``config_path``, off the
event loop (the route comparison can do cold-start disk I/O).)Úpersist_model_selectionN)Úhermes_cli.model_switchr8   ÚasyncioÚ	to_thread)ÚresultÚconfig_pathr8   s   && r   Ú_persist_model_switch_to_configr>   @   s"   é € õ @Ü
×
Ò
Ð3¸[Ó
I×IÔIùs   ‚!,£*¤,c                  ó  € ] tR t^Gt$ RtR]R&   R]R&   R]R&   R]R&   R	tR]R
&   RtR]R&   RtR]R&   Rt	R]R&   Rt
R]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   ]P"                  ! ]R7      tR]R&   R R ltR R ltR tR# )!Ú_ModelSwitchContextzWEverything a /model switch needs beyond the target: current route + persistence policy.r   Úsession_keyr   Úsourcer=   r   Úpersist_globalFÚone_turnÚ Úreasoning_effortNzOptional[dict]Úrestore_snapshotÚcurrent_modelÚ
openrouterÚcurrent_providerr   Úroute_providerÚcurrent_base_urlÚcurrent_api_keyÚ
user_provsÚcustom_provs)Údefault_factoryÚlistÚexcluded_provsc               ó   € V ^8„  d   QhRR/# r5   r   )r   s   "r   r   Ú _ModelSwitchContext.__annotate__]   s   € ÷ ñ ˜Tñ r   c                ó¬  € ^ RI Hp  V! V P                  R7      pV'       g   R# VP                  R/ 4      p\	        V\
        4      '       df   VP                  RR4      V n        VP                  RV P                  4      V n        VP                  R4      V n        VP                  RR4      V n	        TP                  R	4      V n
         ^ R
IHp V! V4      V n        VP                  R/ 4      P                  R4      p\	        V\        4      '       d	   WPn        R# R#   \         d    TP                  R4      T n         Ldi ; i  \         d     R# i ; i)zGFill the current route from ``config_path``; fail-open to the defaults.©Ú_load_gateway_config©r=   Nr   ÚdefaultrE   r"   r#   Ú	providers)Úget_compatible_custom_providersÚcustom_providersÚmodel_catalogÚexcluded_providers)Úgateway.runrW   r=   r%   Ú
isinstancer   rH   rJ   rK   rL   rN   Úhermes_cli.configr[   rO   Ú	ExceptionrQ   rR   )ÚselfrW   ÚcfgÚ	model_cfgr[   Úexcls   &     r   Úread_configÚ_ModelSwitchContext.read_config]   s!  € å4ð	Ù&°4×3CÑ3CÔDˆCßÙØŸ™ ¨Ó,ˆIÜ˜)¤T×*Ò*Ø%.§]¡]°9¸bÓ%A�Ô"Ø(1¯©°jÀ$×BWÑBWÓ(X�Ô%Ø&/§m¡m°JÓ&?�Ô#Ø(1¯©°jÀ"Ó(E�Ô%Ø!Ÿg™g kÓ2ˆDŒOð@ÝMÙ$CÀCÓ$H�Ô!ð —7‘7˜?¨BÓ/×3Ñ3Ð4HÓIˆDÜ˜$¤×%Ò%Ø&*Ö#ñ &øô ô @Ø$'§G¡GÐ,>Ó$?�Ö!ð@ûô
 ô 	Úð	ús;   ˆE ¥B#E Ã	D Ã=E Ä!EÄ>E Å EÅE ÅEÅEc               ó    € V ^8„  d   QhRRRR/# )r   Úoverrider   r   r6   r   )r   s   "r   r   rT   v   s   € ÷ Qñ Q tð Q°ñ Qr   c                ód  € V'       d¨   VP                  RV P                  4      V n        VP                  RV P                  4      V n        VP                  RV P                  4      V n        VP                  RV P                  4      V n        VP                  RV P
                  4      V n        R# R# )z:A session /model override supersedes the configured route.r   r"   r#   Úapi_keyN)r%   rH   rJ   rK   rL   rM   )rc   rj   s   &&r   Úapply_overrideÚ"_ModelSwitchContext.apply_overridev   s‡   € çØ!)§¡¨g°t×7IÑ7IÓ!JˆDÔØ$,§L¡L°¸T×=RÑ=RÓ$SˆDÔ!Ø"*§,¡,¨z¸4×;NÑ;NÓ"OˆDÔØ$,§L¡L°¸T×=RÑ=RÓ$SˆDÔ!Ø#+§<¡<°	¸4×;OÑ;OÓ#PˆDÖ ñ r   )rM   rL   rH   rJ   rO   rR   rK   rN   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__rD   rF   rG   rH   rJ   rK   rL   rM   rN   rO   ÚdataclassesÚfieldrQ   rR   rg   rm   Ú__static_attributes__r   r   r   r@   r@   G   s¬   ‡ áaàÓØƒKØÓØÓØ€HˆdÓØÐ�cÓØ'+Ð�nÓ+Ø€M�3ÓØ(Ð�cÓ(ð %)€N�MÓ(ØÐ�cÓØ€O�SÓØ€J�ÓØ€L�#ÓØ&×,Ò,¸TÔB€N�DÓBõ÷2Qñ Qr   r@   c               ó   € V ^8„  d   QhRR/# )r   r   z	list[str]r   )r   s   "r   r   r   „   s   € ÷ ñ °	ñ r   c           
     ó,  € . pV  EF
  pVR,          '       d   \        R4      MRpVP                  RVR,           RVR,           RV R	24       VR
,          '       do   VR
,          R\         pRP                  R V 4       4      pVR,          \	        V4      ,
          pV^ 8”  d   \        RVR7      MRpVP                  RV V 24       M3VP                  R4      '       d   VP                  RVR,           R24       VP                  R4       EK  	  V# )zIText-list body for ``/model`` with no args on platforms without a picker.Ú
is_currentzgateway.model.current_tagrE   z**Únamez** `--provider ÚslugÚ`Ú:ÚmodelsNú, c              3  ó.   "  € T F  pR V R 2x € K  	  R# 5i©r}   Nr   )Ú.0Úms   & r   Ú	<genexpr>Ú0_model_provider_listing_lines.<locals>.<genexpr>Œ   s   é € Ð";±U° Q q c¨¥8³Uùó   ‚Útotal_modelsz gateway.model.more_models_suffix)Úcountz  Úapi_urlz  `)r   ÚappendÚ_TEXT_LISTING_MODELSÚjoinÚlenr%   )rZ   ÚlinesÚpÚtagÚshownÚ
model_strsÚhiddenÚextras   &       r   Ú_model_provider_listing_linesr–   „   sú   € à€EÜˆØ01°,·´ŒaÐ+Ô,ÀRˆØ�‰�r˜!˜F�)˜ O°A°fµI°;¸aÀ¸uÀAÐFÔGØˆX�;Œ;Ø�h•KÐ 5Ô!5Ð6ˆEØŸ™Ñ";±UÓ";Ó;ˆJØ�~Õ&¬¨U«Õ3ˆFØKQÐTUÌ:”AÐ8ÀÕGÐ[]ˆEØ�L‰L˜2˜j˜\¨%¨Ð1Õ2Ø�U‰U�9×ÒØ�L‰L˜3˜q �|˜n¨AÐ.Ô/Ø�‰�R×ñ ð €Lr   c                  ó˜  € ] tR t^–tRtR R ltR R ltR R ltRR	/R
 R lltRR/R R llt	R t
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R  ltR!R"R#R	/R$ R% lltRBR& R' lltR( R) ltR*R	/R+ R, lltRBR- R. lltR/ R0 ltR1 R2 ltR3 R4 ltR5 R6 ltRCR7 R8 lltR9 R: ltR; R< ltRCR= R> lltR? R@ lt RAt!R	# )DÚGatewayModelCommandsMixinzUModel-route slash commands (/model, /codex-runtime, /reasoning, /fast, /personality).c               ó    € V ^8„  d   QhRRRR/# )r   Úctxr@   Ú	raw_inputr   r   )r   s   "r   r   Ú&GatewayModelCommandsMixin.__annotate__›   s   € ÷ ñ Ø&ðØ36ñr   c              ƒ  óh  "  € ^ RI Hp ^ RIHp \	        4       pV'       d   RV3# \
        P                  ! WbVP                  VP                  VP                  VP                  VP                  W1P                  VP                  R7
      G Rj  x€L
 pVP                  '       g   R\        RVP                   R7      3#  ^ RIHp	 \
        P                  ! W˜WP&                  WAP                  VR7      G Rj  x€L
  VR3#  Lp L
  \(         d$   p
\*        P-                  R	T
4        Rp
?
TR3# Rp
?
ii ; i5i)
zWResolve a /model switch off-loop. Returns ``(result, None)`` or ``(None, error_text)``.rV   )Úswitch_modelN)	r›   rJ   rH   rL   rM   Ú	is_globalÚexplicit_providerÚuser_providersr\   r,   r/   )Ú(enrich_model_switch_warnings_for_gateway)rA   rB   r\   Úload_gateway_configz/preflight-compression switch warning failed: %s)r_   rW   r9   rž   r3   r:   r;   rJ   rH   rL   rM   rC   rN   rO   Úsuccessr   Úerror_messageÚhermes_cli.context_switch_guardr¢   rA   rb   ÚloggerÚdebug)rc   rš   r›   r    rB   rW   rž   Ú
skew_errorr<   r¢   Úexcs   &&&&&      r   Ú_perform_model_switchÚ/GatewayModelCommandsMixin._perform_model_switch›   s  é € õ 	5Ý8ä-Ó/ˆ
ßØ˜Ð#Ð#ä×(Ò(ØÀ×@TÑ@TØ×+Ñ+¸c×>RÑ>RØ×/Ñ/¸3×;MÑ;MØ/ÇÁØ ×-Ñ-ô
÷ 
ˆð �~�~ˆ~ØœÐ7¸v×?SÑ?SÔTÐTÐTð		QÝ`ä×#Ò#Ø8À$×TcÑTcØ×0@Ñ0@Ø$8ô÷ ð ð �tˆ|Ðñ'
ñøô
 ô 	QÜ�L‰LÐJÈC×PÐPØ�tˆ|Ðûð	QüsT   ‚B
D2ÂC=ÂD2Â#D2Â=7D Ã4C?Ã5D Ã9D2Ã?D ÄD/ÄD*Ä"D2Ä*D/Ä/D2c               ó$   € V ^8„  d   QhRRRRRR/# )r   rš   r@   Úpickerr   r   r   r   )r   s   "r   r   rœ   »   s$   € ÷ ñ Ð6Ið ÐSWð Ð\iñ r   c                ó¾  € V P                  VP                  4      pVf   R#  VP                  VP                  VP                  VP
                  VP                  VP                  \        VRR4      R7       R#   \         dY   p\        P                  RT'       d   RMRT4       \        R\        RTP                  YRP                  R	7      R
7      u Rp?# Rp?ii ; i)zóIn-place swap on the cached agent; returns the error reply when it failed.

The agent rolls back to the OLD model/client and re-raises; the commit (DB, override,
eviction, config) is aborted so the next message doesn't rebuild a broken agent.
NÚruntime_capabilities)Ú	new_modelÚnew_providerrl   r#   Úapi_modeÚcapabilitiesz+%s model switch failed for cached agent: %sÚPickerzIn-placer,   zgateway.model.err_switch_failed)r   r0   Úcurrentr/   )Ú_cached_agent_forrA   rž   r±   Útarget_providerrl   r#   r³   Úgetattrrb   r§   Úwarningr   rH   )rc   r<   rš   r®   Úcached_agentrª   s   &&&&  r   Ú_switch_cached_agent_modelÚ4GatewayModelCommandsMixin._switch_cached_agent_model»   sÆ   € ð ×-Ñ-¨c¯o©oÓ>ˆØÒÙð	Ø×%Ñ%Ø ×*Ñ*¸×9OÑ9OØŸ™°·±È6Ï?É?Ü$ VÐ-CÀTÓJð &ô ñ øô ô 	Ü�N‰NØ=Ï6¹xÐWaÐcfôô Ø,ÜÐ9À×AQÑAQÐY\×fwÑfwÔxôõ ûð		ús   £AA9 Á9CÂACÃCÃCc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rš   r@   rD   r   r®   r   r   r   )r   s   "r   r   rœ   Ô   s2   € ÷ Xñ XØ.ðXØEIðXØSWðXà	ñXr   c             ƒ  ó¼  "  € ^ RI Hp \        V RR4      pVe—    V P                  P	                  V4      G Rj  x€L
 pV'       g   \        VRR4      '       d   RVn        VP                  VP                  VP                  VP                  VP                  VP                  R7      G Rj  x€L
  \        V R4      '       g   / V n        R	V! VP"                  4       R
V! VP                  4       RVP$                  ;'       g    VP                   RV'       d   RMR R2	V P                   VP&                  &   RVP                  RVP                  RVP(                  RVP                  RVP                  R\+        VP,                  ;'       g    / 4      R\+        VP.                  ;'       g    / 4      /V P0                  VP&                  &   V'       d(   V P3                  VP&                  VP4                  4       M@V'       g9   \        V R4      '       d'   V P6                  P9                  VP&                  R4       Rp
VP:                  '       d    \=        WP>                  4      G Rj  x€L
  VP:                  '       dn   V
fj   V PK                  V4      fW    V P                  PM                  VP&                  R4      G Rj  x€L
  V P0                  P9                  VP&                  R4       MRV'       gK    V P                  PM                  VP&                  V P0                  VP&                  ,          4      G Rj  x€L
  V PO                  VP&                  4       V
#  EL  EL±  \         d"   p	\        P                  RT	4        Rp	?	ELÖRp	?	ii ; i EL(  \         dU   p\        PA                  RT4       \C        R\E        T4      ;'       g    \G        T4      PH                  R7      p
 Rp?EL€Rp?ii ; i EL5  \         d.   p\        PA                  RT4       \C        RTR7      p
 Rp?LíRp?ii ; i Lù  \         d    \        P                  RRR7        ELi ; i5i) a  Persist a committed switch: session DB, next-turn note, config write-through, override map.

Returns the warning for a ``--global`` switch whose ``config.yaml`` write or stale-override
cleanup failed (the switch then stays a session override), else ``None``.
)Úformat_model_for_displayÚ_session_dbNÚwas_auto_resetF)r"   r#   r³   z(Failed to persist model switch to DB: %sÚ_pending_model_notesz$[Note: model was just switched from z to z via z. z-This override applies to the next turn only. rE   z-Adjust your self-identification accordingly.]r   r"   rl   r#   r³   Úrequest_overridesr´   Ú _pending_one_turn_model_restoresz"Failed to persist model switch: %sú$gateway.model.err_config_not_updatedr/   z4Failed to clear persisted session model override: %sz gateway.model.err_stale_overridez(Failed to persist session model overrideT©Úexc_info)(r9   rÀ   r¹   Úasync_session_storeÚget_or_create_sessionrÂ   Úupdate_session_modelÚ
session_idr±   r¸   r#   r³   rb   r§   r¨   ÚhasattrrÃ   rH   Úprovider_labelrA   rl   r   rÄ   r°   Ú_session_model_overridesÚ_claim_one_turn_restorerG   rÅ   ÚpoprC   r>   r=   rº   r   r   Útypero   Ú_channel_override_forÚset_model_overrideÚ_evict_cached_agent)rc   r<   rš   rB   rD   r®   rÀ   Ú_sess_dbÚ_sess_entryrª   Úglobal_errorÚes   &&&$$$      r   Ú_record_model_switchÚ.GatewayModelCommandsMixin._record_model_switchÔ   s¹  é € õ 	Eô ˜4 °Ó5ˆØÒðNØ$(×$<Ñ$<×$RÑ$RÐSYÓ$Z×Z�÷ ¤'¨+Ð7GÈ×"OÒ"Oà16�KÔ.Ø×3Ñ3Ø×*Ñ*¨F×,<Ñ,<Àv×G]ÑG]Ø#Ÿ_™_°v·±ð 4ó ÷ ð ô �tÐ3×4Ò4Ø(*ˆDÔ%à2Ñ3KÈC×L]ÑL]Ó3^Ð2_Ð_cÙ'¨×(8Ñ(8Ó9Ð:ð ;Ø×(Ñ(×BÐB¨F×,BÑ,BÐCÀ2ßBJÑ>ÐPRÐSØ;ð	=ð 	×!Ñ! #§/¡/Ñ2ð �V×%Ñ% z°6×3IÑ3IÈ9ÐV\×VdÑVdØ˜Ÿ™¨°V·_±_Ø¤ f×&>Ñ&>×&DÐ&DÀ"Ó!EØœD ×!<Ñ!<×!BÐ!BÀÓCð	:
ˆ×%Ñ% c§o¡oÑ6÷ ð ×(Ñ(¨¯©¸#×:NÑ:NÕOßœG DÐ*L×MÒMØ×1Ñ1×5Ñ5°c·o±oÀtÔLð
 '+ˆØ××ÐðkÜ5°f¿o¹oÓN×NÐNð ××Ð ,Ò"6¸4×;UÑ;UÐV\Ó;]Ò;eðIØ×.Ñ.×AÑAÀ#Ç/Á/ÐSWÓX×XÐXð ×-Ñ-×1Ñ1°#·/±/À4ÕH÷ ðXØ×.Ñ.×AÑAØ—O‘O T×%BÑ%BÀ3Ç?Á?Õ%Só÷ ð ð
 	× Ñ  §¡Ô1ØÐòU [òøô ô NÜ—‘ÐGÈ×MÒMûðNúò@ OøÜô kÜ—‘ÐCÀQÔGÜ Ð!GÌsÐSTËv×OiÐOiÔY]Ð^_ÓY`×YiÑYiÔj–ûðkúò YøÜô Nä—‘ÐUÐWXÔYÜ Ð!CÈ1ÔM•ûðNúñ"øô ô XÜ—‘ÐGÐRV�×WðXüs4  ‚Q›M ¹MºM ÁA%M Â+MÂ,M Â0AQÄQÄA2QÆQÆ+&QÇ.QÈAQÉN É&NÉ'N É+QÉ=QÊ)O6 Ê>O3Ê?O6 Ë.QË3AP3 Ì7P1Ì8P3 Ì<QÍM ÍM ÍNÍ*NÎ QÎNÎQÎN ÎO0ÎA	O+Ï%QÏ+O0Ï0QÏ3O6 Ï6P.Ð#P)Ð$QÐ)P.Ð.QÐ1P3 Ð3"QÑQÑQÑQrØ   Nc          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   rš   r@   rD   r   r®   rØ   r   r   r   r   )r   s   "r   r   rœ   .  s6   € ÷ 8 ñ 8 Ø.ð8 Ø=Að8 ØKOð8 à#ð8 ð 
ñ8 r   c             ƒ  ó`  "  € ^ RI Hp ^ RIHpHp \        RV! VP                  4      R7      \        RVP                  ;'       g    VP                  R7      .p	VP                  p
/ pRp\        P                  ! \        4      ;_uu_ 4        V! 4       P                  R/ 4      p\        V\        4      '       d&   VP                  R	4      e   \!        VR	,          4      pRRR4       \        V\        4      '       g   / pT! VP                  VP                  VP"                  ;'       g    VP$                  ;'       g    R
VP&                  ;'       g    VP(                  ;'       g    R
T
VP*                  TVP                  R4      ;'       g    VP                  R4      VP                  R4      VP                  R4      R7
      G Rj  x€L
 pV'       d   V	P-                  \        RVR R7      4       V
'       d;   V
P.                  '       d)   V	P-                  \        RV
P.                  R R7      4       V
'       d+   V	P-                  \        RV
P1                  4       R7      4       \3        VP"                  ;'       g    R
R4      ;'       d    RVP                  P5                  4       9   pV'       g4   V'       g   VP6                  R8X  d   V	P-                  \        R4      4       VP8                  '       d'   V	P-                  \        RVP8                  R7      4       \;        VRR
4      '       d   V	P-                  RVP<                   24       VP>                  '       d<   Ve8   V	P-                  \        RVR7      4       V	P-                  \        R4      4       MjVP>                  '       d   V	P-                  \        R4      4       M=V'       d   V	P-                  \        R4      4       MV	P-                  \        R4      4       R PA                  V	4      #   + '       g   i     ELB; i ELd5i)!zQConfirmation text with full metadata (display form shortens opaque Palantir IDs).rV   )rÀ   Ú$resolve_display_context_length_asynczgateway.model.switched©r   zgateway.model.provider_label)r"   Nr   Úcontext_lengthrE   rY   r"   r#   )r#   rl   Ú
model_infor\   Úconfig_context_lengthÚconfigured_modelÚconfigured_providerÚconfigured_base_urlzgateway.model.context_labelÚ,)Útokenszgateway.model.max_output_labelz gateway.model.capabilities_label)r´   zopenrouter.aiÚclaudeÚanthropic_messagesz$gateway.model.prompt_caching_enabledzgateway.model.warning_prefix)rº   Úusage_noticeu   âš ï¸� zgateway.model.session_only_hintzgateway.model.saved_globalzgateway.model.next_turn_onlyÚ
)!r_   rW   r9   rÀ   rÞ   r   r±   rÎ   r¸   rá   Ú
contextlibÚsuppressrb   r%   r`   r   Úintr#   rL   rl   rM   rO   r‹   Ú
max_outputÚformat_capabilitiesr	   Úlowerr³   Úwarning_messager¹   rê   rC   r�   )rc   r<   rš   rD   r®   rØ   rW   rÀ   rÞ   r�   Úmire   Ú
config_ctxÚctx_lenÚopenrouter_claudes   &&&$$$         r   Ú_model_switch_confirmationÚ4GatewayModelCommandsMixin._model_switch_confirmation.  s  é € õ
 	5ßjô Ð&Ñ.FÀv×GWÑGWÓ.XÔYÜÐ,°v×7LÑ7L×7fÐ7fÐPV×PfÑPfÔgð
ˆð
 ×ÑˆØˆ	Øˆ
Ü× Ò ¤×+Õ+Ù,Ó.×2Ñ2°7¸BÓ?ˆIÜ˜)¤T×*Ò*¨y¯}©}Ð=MÓ/NÒ/ZÜ  Ð+;Õ!<Ó=�
÷ ,ô ˜)¤T×*Ò*ØˆIÙ<Ø×Ñ˜f×4Ñ4Ø—_‘_×BÐB¨×(<Ñ(<×BÐBÀØ—N‘N×?Ð? c×&9Ñ&9×?Ð?¸RÈBØ ×-Ñ-ÀZØ&Ÿ]™]¨9Ó5×OÐO¸¿¹ÀwÓ9OØ )§¡¨jÓ 9Ø )§¡¨jÓ 9ô
÷ 
ˆ÷ Ø�L‰LœÐ8ÀGÈAÀ;ÔPÔQß�"—-—-�-Ø�L‰LœÐ;ÀrÇ}Á}ÐUVÐFWÔYÔZßØ�L‰LœÐ=ÈB×LbÑLbÓLdÔeÔfä! &§/¡/×"7Ð"7°R¸ÓI×rÐrÈhÐZ`×ZjÑZj×ZpÑZpÓZrÑNrð 	÷ ×,°·±ÐCWÔ0WØ�L‰LœÐAÓBÔCØ×!×!Ð!Ø�L‰LœÐ9À6×CYÑCYÔZÔ[Ü�6˜>¨2×.Ò.Ø�L‰L˜7 6×#6Ñ#6Ð"7Ð8Ô9Ø××Ð ,Ò":à�L‰LœÐ9À<ÔPÔQØ�L‰LœÐ<Ó=Õ>Ø××ÐØ�L‰LœÐ7Ó8Õ9ßØ�L‰LœÐ9Ó:Õ;à�L‰LœÐ<Ó=Ô>Ø�y‰y˜ÓÐ÷Q ,×+Ð+úò
ùs–   ‚B	P.ÂAPÃA
P.Ä)P.Ä=P.ÅP.Å&&P.Æ:P.ÇP+ÇP.Ç%P.Ç:P.È/P.È<AP.É>P.Ê%P.Ê3P.Ê;<P.Ë8A(P.Í!AP.Î."P.ÏAP.ÐP(	Ð"
P.r®   Fc               ó$   € V ^8„  d   QhRRRRRR/# ©r   rš   r@   r®   r   r   r   r   )r   s   "r   r   rœ   h  s)   € ÷ 	eñ 	eØ.ð	eØCGð	eà	ñ	er   c          	   ƒ  óì   "  € V P                  4       ;_uu_4       GRj  x€L
  V P                  WW4R7      G Rj  x€L
 uuRRR4      GRj  x€L
  #  L1 L L	  + GRj  x€L 
 '       g   i     R# ; i5i)aO  Apply a resolved switch (cached agent, session, config) and build the confirmation; shared
by the typed path and the picker callback (``picker=True`` never carries --once).

Entry for the picker / cost-confirm callbacks, which fire outside ``_handle_model_command``
and take the switch lock themselves; the typed path already holds it.N©rB   r®   )Ú_model_switch_lockÚ_commit_model_switch_locked)rc   r<   rš   rB   r®   s   &&&$$r   Ú_commit_model_switchÚ.GatewayModelCommandsMixin._commit_model_switchh  sK   é € ð ×*Ñ*×,×,Õ,Ø×9Ñ9¸&ÈfÐ9Ód×d÷ -×,Ô,Ùd÷ -×,×,Ó,üsY   ‚A4ŸA A4£AºA»A¾A4ÁAÁA4ÁAÁA4ÁA1	ÁA Á
A1	Á)A1	Á+	A4c                óh  € ^ RI Hp \        V RR4      pV'       d   Vf   R# T! Y1P                  VP                  '       d   \        VP                  4      MR\        VRR4      '       d   \        VP                  4      MR\        VRR4      '       d   \        VP                  4      R7      # RR7      # )zBThis chat's ``channel_overrides`` entry (model/provider), or None.)Ú_get_channel_overrideÚconfigNrE   Ú	thread_idÚparent_chat_id)r  Ú	parent_id)r_   r  r¹   ÚplatformÚchat_idr   r  r  )rc   rB   r  rd   s   &&  r   rÓ   Ú/GatewayModelCommandsMixin._channel_override_fors  s”   € å5Ü�d˜H dÓ+ˆß�f’nÙÙ$Ø—‘¸¿¿¸¤# f§n¡nÔ"5ÈRÜ/6°v¸{ÈD×/QÒ/Q”c˜&×*Ñ*Ô+ÐW[Ü4;¸FÐDTÐVZ×4[Ò4[”c˜&×/Ñ/Ó0ô
ð 	
ð bfô
ð 	
r   c               ó   € V ^8„  d   QhRR/# )r   r   zasyncio.Lockr   )r   s   "r   r   rœ     s   € ÷ 	ñ 	 Lñ 	r   c                óŠ   € V P                   P                  R4      pVf$   \        P                  ! 4       ;qP                   R&   V# )a®  Runner-wide lock over a /model command's read-resolve-commit. Slash commands bypass the busy
guard while no agent runs, so a second /model on the same (or another) session otherwise
interleaves with the first's store/config awaits: two ``--global`` picks left config.yaml on
whichever thread wrote last and a ``--global`` cleanup wiped a session pick issued after it
(#100314). Lazy: the runner is built without __init__ in tests.Ú_model_switch_lock_obj)Ú__dict__r%   r:   ÚLock)rc   Úlocks   & r   rý   Ú,GatewayModelCommandsMixin._model_switch_lock  s;   € ð �}‰}× Ñ Ð!9Ó:ˆØŠ<Ü=D¿\º\»^ÐKˆD—=‘=Ð!9Ñ:Øˆr   c               ó    € V ^8„  d   QhRRRR/# )r   rš   r@   r   r6   r   )r   s   "r   r   rœ   Š  s   € ÷ 2ñ 2Ð2Eð 2ÐRVñ 2r   c                óš  € ^ RI Hp ^ RIHpHp Rp\        \        V RR4      RR4      '       d=   \        P                  ! \        4      ;_uu_ 4        V P                  V4      pRRR4       Rp\        P                  ! \        4      ;_uu_ 4        \        V P                  VP                  4      RR4      pRRR4       V'       d   V! \        V4      4      MRp	 V! VP                  VP                  RVP                  VR	7       V	e   V! V	4       R# R#   + '       g   i     Lº; i  + '       g   i     Lz; i  T	e
   T! T	4       i i ; i)
zšSlash dispatch does not install the routed profile's scope, so a multiplexed runner binds
the owning home for the switch row and its switch_away friction.)Úrecord_model_switch)Úreset_hermes_home_overrideÚset_hermes_home_overrideNr  Úmultiplex_profilesFrÌ   Úgateway)Úfrom_providerÚto_providerÚsurfaceÚ
from_modelrÌ   )Ú.hermes_cli.observability.shared_metrics_eventsr  Úhermes_constantsr  r  r¹   rì   rí   rb   Ú _resolve_profile_home_for_sourcer·   rA   r   rK   r¸   rH   )
rc   r<   rš   rB   r  r  r  ÚhomerÌ   Útokens
   &&&&      r   Ú_record_switch_metricsÚ0GatewayModelCommandsMixin._record_switch_metricsŠ  s  € õ 	WßYàˆÜ”7˜4 ¨4Ó0Ð2FÈ×NÒNÜ×$Ò$¤Y×/Õ/Ø×<Ñ<¸VÓD�÷ 0àˆ
Ü× Ò ¤×+Õ+Ü  ×!7Ñ!7¸¿¹Ó!HÈ,ÐX\Ó]ˆJ÷ ,ç7;Ñ(¬¨T«Ô3Àˆð	2ÙØ!×0Ñ0¸f×>TÑ>TÐ^gØ×,Ñ,¸õEð Ò Ù*¨5Ö1ñ !÷ 0×/ú÷ ,×+ûð Ò Ù*¨5Õ1ð !ús$   ÁDÂ'D(Ã+D; ÄD%	Ä(D8	Ä;E
c               ó$   € V ^8„  d   QhRRRRRR/# rú   r   )r   s   "r   r   rœ      s)   € ÷ -_ñ -_Ð=Pð -_Ðeið -_Ðnqñ -_r   c          	   ƒ  	ó   "  € V'       d   R MVP                   p^ RIHpHp V! W4      w  r‰Rp
V	eË   V'       d   \	        R\	        R4      R7      # ^ RIHp VP                  ;'       g    RP                  4       P                  4       pV! V4      e   TMRp
\        P                  ! WhW‘V
4      G Rj  x€L
  V P                  WV4       RpVP                  '       d     \        WP                  4      G Rj  x€L
  MGMFV P-                  WV4      pVe   V# V P                  WV4       V P/                  WW5VR7      G Rj  x€L
 pV P1                  WWTVR7      G Rj  x€L
 pV
'       dY   VP                  ;'       d    VRJ ;'       d    V P3                  RV
4      pTR\	        V'       d   RMRV
R7      ,           ,          pM}VP                  '       dl   V'       gd   ^ RIHp TRT P9                  VP:                  V! VP<                  4      VP                  VP                  ;'       d    VRJ R7      ,           ,          pTV	e   R\	        R4      ,           ,           # R,           #  EL¯ ELn  \          dV   p\"        P%                  RR	R
7       \	        R\'        T4      ;'       g    \)        T4      P*                  R7      p Rp?ELRp?ii ; i ELŒ ELs5i)F)Údefer_local_model_pickÚlocal_authority_liverE   Nr,   zgateway.model.err_once_localr/   ©Úparse_reasoning_effortzFailed to persist model switchTrÇ   rÆ   )rB   rD   r®   )rD   r®   rØ   úagent.reasoning_effortrë   úgateway.reasoning.set_globalúgateway.reasoning.set_session©Úeffort©Ú_platform_config_key©rC   zgateway.model.local_next_turn)rD   Ú gateway.session_setting_commandsr%  r&  r   r  r(  rF   Ústriprñ   r:   r;   r!  rC   r>   r=   rb   r§   rº   r   rÒ   ro   r¼   rÚ   r÷   Ú_save_gateway_config_keyr_   r/  Ú_apply_reasoning_selectionrA   r  )rc   r<   rš   rB   r®   rD   r%  r&  Ú	authorityÚliveÚlevelr(  r-  rØ   rÙ   r0   ÚreplyÚsavedr/  s   &&&$$              r   rþ   Ú5GatewayModelCommandsMixin._commit_model_switch_locked   s¤  é € ß"‘5¨¯©ˆßaÙ.¨tÓ<‰ˆ	ØˆØÒ÷ ÜÐ5¼QÐ?]Ó=^Ô_Ð_Ý?Ø×*Ñ*×0Ð0¨b×7Ñ7Ó9×?Ñ?ÓAˆFÙ4°VÓ<ÒH‘FÈbˆEÜ×#Ò#Ð$:ÀtÐUZÓ[×[Ð[Ø×'Ñ'¨°VÔ<ØˆLØ×!×!Ð!ðoÜ9¸&Ç/Á/ÓR×RÑRð "ð ×3Ñ3°FÀÓHˆEØÒ Ø�Ø×'Ñ'¨°VÔ<Ø!%×!:Ñ!:Ø FÀfð ";ó "N÷ NˆLà×5Ñ5Ø (Èð 6ó 
÷ 
ˆ÷ à×'Ñ'÷ Xð X¨L¸DÐ,@÷ Xð XØ×6Ñ6Ð7OÐQVÓWð à�TœAÇÑ<ÐKjØ%*ô,õ ,õ ,‰Eà×!×!Ð!¯(õ 9Ø�T˜D×;Ñ;Ø—‘Ñ!5°f·o±oÓ!FÈ×H\ÑH\Ø"×1Ñ1×JÐJ°lÀdÐ6Jð <ó Lõ Lõ LˆEð ÀTÒEU˜œqÐ!@ÓAÕAÕ^Ð^Ð[]Õ^Ð^òA \ò
 SøÜ ô oÜ—N‘NÐ#CÈd�NÔSÜ#$Ð%KÔSVÐWXÓSY×SmÐSmÔ]aÐbcÓ]d×]mÑ]mÔ#n–LûðoúòNò
ùsŸ   ‚6K¹.KÁ(AKÂ0IÂ1*KÃI% Ã4I"Ã5I% Ã9AKÄ<KÄ=KÅKÅKÅ%KÅ8KÆA
KÇKÇAKÈ$<KÉ"I% É%KÉ0A
K Ê:KË KËKËKc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   Úeventr   rA   r   Úlisting_kwargsr   r   r   r   )r   s   "r   r   rœ   Ï  s/   € ÷ $ñ $¨lð $ÐZ]ð $Ðosð $ð  LPñ $r   c              ƒ  óv  "  € ^ RI Hp  \        P                  ! V3R^2RR/VB G Rj  x€L
 pV'       g   R# VP                  VP                  VVR,          VR,          VVV P                  W P                  V4      4      R	7      G Rj  x€L
 p	\        V	P                  4      #  Ly  \         d    . p L†i ; i L.5i)
z´Send the interactive /model picker; False when nothing was sent (text fallback). *source*
is session-key-normalized so the picker's thread metadata lands where the next turn reads.)Úlist_picker_providersÚ
max_modelsÚinclude_moaTNFrH   rJ   )r  rZ   rH   rJ   rA   Úon_model_selectedÚmetadata)Ú!hermes_cli.model_switch_providersr?  r:   r;   rb   Úsend_model_pickerr  Ú_thread_metadata_for_sourceÚ_reply_anchor_for_eventr   r¤   )
rc   r<  rB   ÚadapterrA   r=  rB  r?  rZ   r<   s
   &&&&&&&   r   Ú_send_model_pickerÚ,GatewayModelCommandsMixin._send_model_pickerÏ  sÌ   é € õ 	Lð	Ü%×/Ò/Ø%ñØ24ðØBFðØJXñ÷ ˆI÷
 ÙØ×0Ñ0Ø—N‘N¨iØ(¨Õ9Ø+Ð,>Õ?È[Ø/Ø×5Ñ5°f×>ZÑ>ZÐ[`Ó>aÓbð 1ó 
÷ 
ˆô �F—N‘NÓ#Ð#ñøô ô 	ØŠIð	úñ
ùsI   ‚B9ŠB$ ¨B"©B$ ­B9µAB9ÂB7Â	B9Â"B$ Â$B4Â1B9Â3B4Â4B9c               ó$   € V ^8„  d   QhRRRRRR/# )r   r<  r   rš   r@   r   r   r   )r   s   "r   r   rœ   ä  s$   € ÷ - ñ - Ø!ð- Ø(;ð- à	ñ- r   c              ƒ  ó¸  a aaaa"  € ^ RI Hp ^ RIHp \	        SP
                  SP                  SP                  SP                  SP                  SP                  RRRR7	      pS P                  SP                  4      pVeg   \        \        V4      RR4      eO   R VVV 3R	 lloR
 VV3R llpS P                  SSP                  VSP                   Wh4      G Rj  x€L
 '       d   R# \#        RSP                  ;'       g    \#        R4      V! SP
                  4      R7      R.p	 \$        P&                  ! V3R\(        /VB G Rj  x€L
 p
V	P+                  \-        V
4      4       V	P1                  \#        R4      4       V	P1                  \#        R4      4       V	P1                  \#        R4      4       RP3                  V	4      #  Lè L  \.         d     Lpi ; i5i)zP``/model`` with no args: interactive picker where supported, else the text list.)Úlist_authenticated_providers)Ú	get_labelTF)	rJ   rL   rH   r¡   r\   r^   Únon_blocking_catalogsÚprobe_custom_providersÚprobe_current_custom_providerNrE  c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úmodel_idr   Úprovider_slugr   r   )r   s   "r   r   ÚDGatewayModelCommandsMixin._model_listing_reply.<locals>.__annotate__ö  s&   € ÷ fñ f¨sð fÀ3ð fÈ3ñ fr   c              “  ó¼   <"  € SP                  SWSP                  4      G R j  x€L
 w  r#Ve   V# SP                  VSSP                  RR7      G R j  x€L
 #  L3 L5i)NTrü   )r«   rB   rÿ   )rS  rT  r<   r0   rš   r<  rc   s   &&  €€€r   Ú_picker_switchÚFGatewayModelCommandsMixin._model_listing_reply.<locals>._picker_switchö  s_   øé € à&*×&@Ñ&@ÀÀhÐ_d×_kÑ_kÓ&l× l‘�ØÒ$Ø �LØ!×6Ñ6°v¸sÈ5Ï<É<Ð`dÐ6Óe×eÐeñ !mñ fùs!   ƒ!A¤A¥.AÁAÁAÁAc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Ú_chat_idr   rS  rT  r   r   )r   s   "r   r   rU  ý  s0   € ÷ Iñ I°3ð IÀ#ð IÐVYð IÐ^añ Ir   c              “  óÆ   <"  € Sf   S! W4      G R j  x€L
 # ^ RI Hp V! S4      ;_uu_ 4        S! W4      G R j  x€L
 uuR R R 4       #  L5 L  + '       g   i     R # ; i5i)N©Ú_profile_runtime_scope)r_   r]  )rZ  rS  rT  r]  rW  Úprofile_homes   &&& €€r   Ú_on_model_selectedÚJGatewayModelCommandsMixin._model_listing_reply.<locals>._on_model_selectedý  sR   øé € ØÒ'Ù!/°Ó!H×HÐHÝ>Ù+¨L×9Õ9Ù!/°Ó!H×H÷ :Ò9ñ Iñ I÷ :×9Ð9üs5   ƒA!“A	”A!®AºA»A¾A!ÁAÁA	Á	A!zgateway.model.current_labelúgateway.shared.unknown_value)r   r"   rE   r@  z gateway.model.usage_switch_modelz#gateway.model.usage_switch_providerzgateway.model.usage_persistrë   )r9   rM  Úhermes_cli.providersrN  r   rJ   rL   rH   rN   rO   rR   Ú_delivery_adapter_forrB   r¹   rÒ   rI  rA   r   r:   r;   rŒ   Úextendr–   rb   r‹   r�   )rc   r<  rš   r^  rM  rN  r=  rH  r_  r�   rZ   rW  s   ffff       @r   Ú_model_listing_replyÚ.GatewayModelCommandsMixin._model_listing_replyä  s¦  üé € õ 	IÝ2äØ ×1Ñ1ÀC×DXÑDXØ×+Ñ+¸C¿N¹NØ ×-Ñ-À#×BTÑBTð #'¸uÐdhô
ˆð ×,Ñ,¨S¯Z©ZÓ8ˆØÒ¤7¬4°«=Ð:MÈtÓ#TÒ#`÷fò f÷Iñ Ið ×,Ñ,¨U°C·J±JÀÈÏÉÐZhÓ}×}Ö}ÙäÐ0¸×8IÑ8I×8nÐ8nÌQÐOmÓMnÙ% c×&:Ñ&:Ó;ô=Ø>@ðBˆð	Ü%×/Ò/Ð0Lñ  AÔYmð  AÐqñ  A÷  AˆIØ�L‰LÔ6°yÓAÔBð 	�‰”QÐ9Ó:Ô;Ø�‰”QÐ<Ó=Ô>Ø�‰”QÐ4Ó5Ô6Ø�y‰y˜ÓÐñ ~ñ Aøäô 	Ùð	üsU   ‡CGÃGÃ	GÃ'GÄ$GÄ' G	 ÅGÅG	 Å&A GÇG	 Ç	GÇGÇGÇGc               ó$   € V ^8„  d   QhRRRRRR/# )r   r<  r   rš   r@   r   ztuple[bool, Optional[str]]r   )r   s   "r   r   rœ     s$   € ÷ !
ñ !
Ø!ð!
Ø(;ð!
à	#ñ!
r   c              ƒ  ó¸  a aa"  €  ^ RI HpHp \        P                  ! TSP
                  SP                  SP                  ;'       g    SP                  ;'       g    RSP                  ;'       g    SP                  ;'       g    RSP                  V! S P                  SP                  4      4      R7      G Rj  x€L
 pVf   R# R VVV 3R llpS P                  VP                   P"                  4      p\%        RVP&                  VP(                  VR7      p	R	S P+                  VR
VP&                  W—R7      G Rj  x€L
 3#  L†  \         d    Rp L“i ; i L5i)u-  Selection-guard confirmation for the typed path (pickers confirm via their own UI).

The unified registry (cost + data-policy guards) runs off-loop â€” pricing lookups may hit
models.dev on a cache miss. Returns ``(fired, reply)``; the reply is None when the platform
rendered confirm buttons itself.
)Úcombined_selection_warningÚselection_context_for_agentrE   )r"   r#   rl   rá   Úselection_contextNc               ó    € V ^8„  d   QhRRRR/# )r   Úchoicer   r   r   )r   s   "r   r   ÚLGatewayModelCommandsMixin._model_selection_guard_reply.<locals>.__annotate__*  s   € ÷ 	Sñ 	S¨3ð 	S°3ñ 	Sr   c              “  ó¾   <"  € V R 8X  d+   \        RSP                  ;'       g    \        R4      R7      # SP                  SSSP                  R7      G Rj  x€L
 #  L5i)Úcancelzgateway.model.switch_cancelledra  rß   )rB   N)r   rH   rÿ   rB   )rm  rš   r<   rc   s   &€€€r   Ú_on_cost_confirmÚPGatewayModelCommandsMixin._model_selection_guard_reply.<locals>._on_cost_confirm*  sS   øé € Ø˜Ô!ÜÐ9À×ARÑAR×AwÐAwÔVWÐXvÓVwÔxÐxà×2Ñ2°6¸3ÀsÇzÁzÐ2ÓR×RÐRÑRùs   ƒ A¤2AÁAÁAzgateway.model.guard_confirm)ÚtitleÚmessageÚprefixTr   )r<  Úcommandrs  rt  Úhandler)FN)Ú!hermes_cli.model_selection_guardsri  rj  r:   r;   r±   r¸   r#   rL   rl   rM   rá   r·   rA   rb   Ú_typed_command_prefix_forrB   r  r   rs  rt  Ú_request_slash_confirm)
rc   r<  rš   r<   ri  rj  rº   rq  Ú_prt  s
   f&ff      r   Ú_model_selection_guard_replyÚ6GatewayModelCommandsMixin._model_selection_guard_reply  s9  úé € ð
	÷Iä#×-Ò-Ø*¨F×,<Ñ,<Àv×G]ÑG]ØŸ™×FÐF¨C×,@Ñ,@×FÐFÀBØŸ™×CÐC¨#×*=Ñ*=×CÐCÀÐPV×PaÑPaÙ"=¸d×>TÑ>TÐUX×UdÑUdÓ>eÓ"fô	÷ ˆGð Š?ØÐ÷	Sò 	Sð ×+Ñ+¨E¯L©L×,AÑ,AÓBˆÜÐ1¸¿¹ÐPW×P_ÑP_ÐhjÔkˆØ˜4×6Ñ6Ø °·±Àwð 7ó 
÷ 
ð 
ð 	
ñ'øô ô 	ØŠGð	úñ
ùsZ   …E‡AE ÁE Á2E Â6E Â<EÂ=E ÃA<EÄ=EÄ>EÅE ÅEÅEÅEÅEc               ó    € V ^8„  d   QhRRRR/# ©r   r<  r   r   r   r   )r   s   "r   r   rœ   6  s   € ÷ Bñ B°ð BÀ-ñ Br   c              ƒ  óè   "  € V P                  4       ;_uu_4       GRj  x€L
  V P                  V4      G Rj  x€L
 uuRRR4      GRj  x€L
  #  L/ L L	  + GRj  x€L 
 '       g   i     R# ; i5i)u¥   Handle /model command â€” switch model. Taken under the switch lock BEFORE the first await so
concurrent commands commit in issue order (see ``_model_switch_lock``).N)rý   Ú_handle_model_command_locked)rc   r<  s   &&r   Ú_handle_model_commandÚ/GatewayModelCommandsMixin._handle_model_command6  sF   é € ð ×*Ñ*×,×,Õ,Ø×:Ñ:¸5ÓA×A÷ -×,Ô,ÙA÷ -×,×,Ó,üsY   ‚A2ŸA A2£A¸A¹A¼A2Á	AÁ
A2ÁAÁA2ÁA/	ÁAÁ
A/	Á'A/	Á)	A2c               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rœ   <  s   € ÷ 5`ñ 5`¸ð 5`Èñ 5`r   c              ƒ  	ó’  "  € ^ RI Hp ^ RIHpHp Rp\        \        V RR4      RR4      '       d   V P                  VP                  4      pV! VP                  4       P                  4       4      pVP                  '       d   RVP                  4       ^ ,           2# VP                  '       d9   \        P                  ! \        4      ;_uu_ 4        ^ RIHp V! 4        RRR4       \$        P&                  ! V P(                  VP                  4      G Rj  x€L
 pV P+                  V4      p	\-        T	TT;'       g    TR	,          V! VP.                  VP0                  VP2                  VP4                  R
7      VP2                  VP6                  VP2                  '       d   V P9                  V	4      MRR7      p
V
P;                  4        V
P=                  V P>                  PA                  V	/ 4      4       VPB                  '       g-   VP4                  '       g   V PE                  WV4      G Rj  x€L
 # V PG                  W¦PB                  VP4                  V4      G Rj  x€L
 w  r¼Ve   V# V PI                  WV4      G Rj  x€L
 w  rÞV'       d   V# V PK                  WºVRR7      G Rj  x€L
 #   + '       g   i     ELÓ; i EL¨ L” Lg LG L!5i)é    ©Ú_hermes_home)Úparse_model_switch_argsÚresolve_persist_behaviorNr  r  Fõ   â�Œ )Úclear_provider_models_cacheúconfig.yaml)Úis_oncer    )rA   rB   r=   rC   rD   rF   rG   rü   )&r_   rˆ  r9   r‰  rŠ  r¹   r  rB   Úget_command_argsr2  ÚerrorsÚerror_messagesÚforce_refreshrì   rí   rb   r$   rŒ  r:   r;   Ú!_normalize_source_for_session_keyÚ_session_key_for_sourcer@   rŸ   Ú
is_sessionrŽ  r    rF   Ú _snapshot_session_model_overriderg   rm   rÏ   r%   Útargetre  r«   r|  rþ   )rc   r<  rˆ  r‰  rŠ  r^  ÚrequestrŒ  rB   rA   rš   r<   r0   Úguard_firedÚguard_replys   &&             r   r�  Ú6GatewayModelCommandsMixin._handle_model_command_locked<  sA  é € Ý,ß]àˆÜ”7˜4 ¨4Ó0Ð2FÈ×NÒNØ×@Ñ@ÀÇÁÓNˆLÙ)¨%×*@Ñ*@Ó*B×*HÑ*HÓ*JÓKˆØ�>�>ˆ>Ø˜'×0Ñ0Ó2°1Õ5Ð6Ð7Ð7Ø× × Ð Ü×$Ò$¤Y×/Õ/ÝIÙ+Ô-÷ 0ô ×(Ò(¨×)OÑ)OÐQV×Q]ÑQ]Ó^×^ˆØ×2Ñ2°6Ó:ˆÜ!ð $ØØ%×5Ð5¨¸ÕFÙ3Ø×!Ñ! 7×#5Ñ#5¸w¿¹Ø")×";Ñ";ôð —_‘_Ø$×5Ñ5ØSZ×Sb×SbÐSb˜T×BÑBÀ;ÔOÐhlô-
ˆð0 	�‰ÔØ×Ñ˜4×8Ñ8×<Ñ<¸[È"ÓMÔNØ�~�~ˆ~ g×&?×&?Ð&?Ø×2Ñ2°5¸|ÓL×LÐLØ"×8Ñ8¸¿n¹nÈg×NgÑNgÐioÓp×p‰ˆØÒØˆLØ)-×)JÑ)JÈ5ÐW]Ó)^×#^Ñ ˆßØÐØ×5Ñ5°fÈ&ÐY^Ð5Ó_×_Ð_÷U 0×/Ð/úò _ñ: MÙpñ $_ñ `ùs˜   ‚A?KÂ+KÂ."KÃJ(Ã6KÄJ<Ä$KÄ:A#KÆA$KÈKÈKÈ*J?È+.KÉKÉ!KÉ;KÉ<'KÊ#KÊ$KÊ(J9	Ê3
KÊ?KËKËKËKrA   rE   Ú
generationc          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   r<  r   Úlimitr   rA   r   rœ  úOptional[int]r   r6   r   )r   s   "r   r   rœ   u  s9   € ÷ Oñ O°ð OÀdð OÐ\_ð OØ0=ðOØIMñOr   c               óp  a aaa€  SP                   e   S P                  SP                   4      MRp\        VRR4      pV'       d&   \        V4      '       d   V! VVVVV 3R lSR7       R# S P	                  S P                  SSS4      4       R#   \         d    \        P                  RRR7        R# i ; i)a  After a usage-window refusal's reply: offer the plan's recommended model as a button where the
platform already has quick-choice buttons, else one line of text.

Runs as the adapter's post-delivery callback, so the offer always lands under the reply (the reply
is sent after this turn returns). The tap switches this session only (never the default) and
re-sends the refused message, like /retry. No credits button in a chat: anyone in the room could
spend the owner's credits, so the Portal is named instead. Hermes never switches on its own.NÚregister_post_delivery_callbackc                 ó*   <€ SP                  S SS4      # ©N)Ú_offer_usage_limit_switch)r<  rœ  rž  rc   s   €€€€r   Ú<lambda>ÚGGatewayModelCommandsMixin._schedule_usage_limit_offer.<locals>.<lambda>‚  s   ø€ ¨d×.LÑ.LÈUÐTYÐ[eÔ.fr   )rœ  z#usage-limit offer scheduling failedTrÇ   )	rB   rc  r¹   ÚcallableÚ_track_background_taskr¤  rb   r§   r¨   )rc   r<  rž  rA   rœ  rH  Úregisters   fff$d  r   Ú_schedule_usage_limit_offerÚ5GatewayModelCommandsMixin._schedule_usage_limit_offeru  s˜   û€ ð		OØBGÇ,Á,ÒBZ�d×0Ñ0°·±Ô>Ð`dˆGÜ˜wÐ(IÈ4ÓPˆHßœx¨×1Ò1Ù˜×&fØ$.õ0áØ×'Ñ'¨×(FÑ(FÀuÈeÐU_Ó(`ÖaøÜô 	OÜ�L‰LÐ>ÈˆL×Nð	Oús   †B ”AB Á+"B Â"B5Â4B5c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r<  r   rž  r   rœ  rŸ  r   r6   r   )r   s   "r   r   rœ   ‰  s0   € ÷ Dñ D°\ð DÈ$ð DØ4AðDØMQñDr   c              ƒ  	óF  a aaa"  € ^ RI Hp  VP                  R4      ;'       g    .  Uu. uF6  p\        V\        4      '       g   K  VP                  R4      '       g   K4  VNK8  	  ppSP
                  pVf   R# S P                  VP                  4      pS P                  V4      p	S P                  V4      oV'       dÖ   V	eÒ   \        \        V	4      RR4      eº   R VVV V3R llp
V Uu. uFr  pR\        VR,          4      R	\        R
\        VP                  R	4      ;'       g
    VR,          4      \        VP                  R4      ;'       g    R4      R7      RR/NKt  	  ppS P                  SS\        R4      VV
R7      G Rj  x€L
 '       d   R# V! W( R2RRR7      pV	eB   V'       d8   V	P                  VP                   VS P#                  S4      R7      G Rj  x€L
  R# R# R# u upi u upi  Lk L  \$         d    \&        P)                  RRR7        R# i ; i5i)r†  )Úlimit_next_steps_from_payloadÚsuggestionsr   NÚsend_choice_pickerc               ó$   € V ^8„  d   QhRRRRRR/# ©r   rZ  r   Úvaluer   r   )r   s   "r   r   ÚIGatewayModelCommandsMixin._offer_usage_limit_switch.<locals>.__annotate__•  s&   € ÷ gñ g¨sð g¸3ð gÀ3ñ gr   c              “  ó¦   <"  € Se$   SP                  SS4      '       d   \        R4      # SP                  STSf   R MSS3R7      G R j  x€L
 #  L5i)Nz&platform.discord.picker.choice_expired)Úoffer)Ú_usage_limit_offer_is_staler   Ú_accept_usage_limit_switch)rZ  r³  r<  rœ  rc   rA   s   &&€€€€r   Ú
_on_choiceÚGGatewayModelCommandsMixin._offer_usage_limit_switch.<locals>._on_choice•  sg   øé € Ø!Ò-°$×2RÑ2RÐS^Ð`j×2kÒ2kä Ð!IÓJÐJØ!%×!@Ñ!@Ø˜u°JÒ4F©DÈ[ÐZdÐLeð "Aó "g÷ gð gñ gùs   ƒA *AÁ
AÁAr³  Úlabelz!gateway.usage_limit.switch_choiceÚnoterE   )r   r¼  rz   Fz gateway.usage_limit.picker_title©rs  ÚchoicesÚon_choice_selectedT)Úmodel_commandÚtopup_commandÚportal)rC  zusage-limit offer failedrÇ   )Úagent.plan_limitsr®  r%   r`   r   rB   ry  r  rc  r”  r¹   rÒ   r   r   Ú_try_send_choice_pickerÚsendr  Ú_reply_metadatarb   r§   r¨   )rc   r<  rž  rœ  r®  Úsr¯  rB   ru  rH  r¹  r¾  ÚtextrA   s   ff&f         @r   r¤  Ú3GatewayModelCommandsMixin._offer_usage_limit_switch‰  s  ûé € åCð	DØ',§y¡y°Ó'?×'EÐ'EÀ2Ð'EÓqÑ'E Ì*ÐUVÔX\×J]œ1Ðbc×bgÑbgÐho×bpŸ1˜1Ñ'EˆKÐqØ—\‘\ˆFØŠ~ÙØ×3Ñ3°F·O±OÓDˆFØ×0Ñ0°Ó8ˆGØ×6Ñ6°vÓ>ˆKß˜wÒ2´w¼tÀG»}ÐNbÐdhÓ7iÒ7u÷gó gñ ;FóGñ ;F°Qð $¤S¨¨7­£_Ø#¤QÐ'JÔRUÐVW×V[ÑV[Ð\cÓVd×VrÐVrÐhiÐjqÕhrÓRsÜ,/°·±°f³×0CÐ0CÀÓ,Dô&Fà(¨%ó1ñ ;Fð ð Gð ×5Ñ5Ø˜{´!Ð4VÓ2WÐahØ+5ð 6ó 7÷ 7ö 7ñ Ù0°ÈÐPUÐFVÐfjÐswÔxˆDØÒ"§tØ—l‘l 6§>¡>°4À$×BVÑBVÐW\ÓB]�lÓ^×^Ò^ñ (,Ñ"ùò1 rùòGñ7ñ _øÜô 	DÜ�L‰LÐ3¸dˆL×Cð	Düs›   †H!ŽG8 «G*ÁG*Á!G*Á'G8 Á9H!Á;AG8 Ã ,G8 Ã,A$G/ÅG/Å$$G8 ÆG4Æ		G8 ÆH!ÆG8 Æ/0G8 ÇG6Ç G8 Ç$H!Ç*G8 Ç6G8 Ç8"HÈH!ÈHÈH!c               ó$   € V ^8„  d   QhRRRRRR/# )r   rA   r   rœ  rî   r   r   r   )r   s   "r   r   rœ   ª  s"   € ÷ ñ °sð Èð ÐPTñ r   c                ó¼   €  \        V P                  V4      P                  P                  4      \        V4      8g  #   \        \
        \        \        3 d     R# i ; i)z[True once the session has started a newer run than the refused one. Fails open (not stale).F)rî   Ú_session_stateÚ
persistentÚrun_generationÚAttributeErrorÚKeyErrorÚ	TypeErrorÚ
ValueError)rc   rA   rœ  s   &&&r   r·  Ú5GatewayModelCommandsMixin._usage_limit_offer_is_staleª  sP   € ð	Ü�t×*Ñ*¨;Ó7×BÑB×QÑQÓRÔVYÐZdÓVeÑeÐeøÜ¤¬)´ZÐ@ô 	Úð	ús   ‚9< ¼AÁAr¶  c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r<  r   rS  r   r¶  úOptional[tuple[str, int]]r   r   )r   s   "r   r   rœ   ±  s*   € ÷ #ñ #°lð #Ècð #Ø0Ið#ØUXñ#r   c             ƒ  óH  a aaaa"  € ^ RI Hp \        P                  ! S P                  SP
                  4      G Rj  x€L
 pS P                  V4      oRp\        \        S RR4      RR4      '       d   S P                  SP
                  4      p\        STT;'       g    TR,          RR7      oR VVVV V3R	 llpS P                  P                  S4      pVf   V! 4       G Rj  x€L
 p	M.^ R
I Hp
 V
! V4      ;_uu_ 4        V! 4       G Rj  x€L
 p	RRR4       S P                  P                  S4      pVRJ;'       d     W¸J;'       d    VP                  R4      R8H  pV'       d"   S P                  S P                  SV4      4       X	#  ELL L§ L‚  + '       g   i     Lˆ; i5i)z˜The tap: switch this session to *model_id* on Nous, then re-send the refused message.
``offer`` is the refused turn's ``(session_key, run_generation)``.r‡  Nr  r  Fr�  )rA   rB   r=   rC   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   ÚJGatewayModelCommandsMixin._accept_usage_limit_switch.<locals>.__annotate__¾  s   € ÷ 	bñ 	b˜sñ 	br   c               “  ó4  <"  € SP                  4        SP                  SP                  P                  S/ 4      4       SP	                  SSR SP
                  4      G Rj  x€L
 w  rVe   V# SP                  V SSP
                  RR7      G Rj  x€L
 #  L3 L5i)ÚnousNTrü   )rg   rm   rÏ   r%   r«   rB   rÿ   )r<   r0   rš   r<  rS  rc   rA   s     €€€€€r   Ú_switchÚEGatewayModelCommandsMixin._accept_usage_limit_switch.<locals>._switch¾  sŒ   øé € Ø�O‰OÔØ×Ñ˜t×<Ñ<×@Ñ@ÀÈbÓQÔRØ"&×"<Ñ"<¸SÀ(ÈFÐTY×T`ÑT`Ó"a×a‰MˆFØÒ Ø�Ø×2Ñ2°6¸3ÀuÇ|Á|Ð\`Ð2Óa×aÐañ bñ bùs$   ƒABÁ BÁ!.BÂBÂBÂBr\  r"   rÚ  )r_   rˆ  r:   r;   r“  rB   r”  r¹   r  r@   rÏ   r%   r]  r¨  Ú_dispatch_usage_limit_retry)rc   r<  rS  r¶  rˆ  rB   r^  rÛ  Úbeforer8  r]  ÚafterÚswitchedrš   rA   s   fff$         @@r   r¸  Ú4GatewayModelCommandsMixin._accept_usage_limit_switch±  s`  üé € õ 	-Ü×(Ò(¨×)OÑ)OÐQV×Q]ÑQ]Ó^×^ˆØ×2Ñ2°6Ó:ˆØˆÜ”7˜4 ¨4Ó0Ð2FÈ×NÒNØ×@Ñ@ÀÇÁÓNˆLÜ!¨kÀ&Ø/;×/KÐ/K¸|È}Õ.\Ðmrôtˆ÷	bô 	bð ×.Ñ.×2Ñ2°;Ó?ˆØÒÙ!›)—O‰Eå:Ù'¨×5Õ5Ù%›iŸ�÷ 6à×-Ñ-×1Ñ1°+Ó>ˆØ Ð$×`Ð`¨Ð)<×`Ð`ÀÇÁÈ:ÓAVÐZ`ÑA`ˆßð ×'Ñ'¨×(HÑ(HÈÐPUÓ(VÔWØˆò= _ñ$ $ñ (÷ 6×5üse   ‡5F"¼F½AF"ÂAF"Ã#FÃ$F"Ã?FÄ
FÄFÄ-F"Ä=
F"ÅF"Å%$F"ÆF"ÆFÆF	ÆF"c               ó$   € V ^8„  d   QhRRRRRR/# )r   r<  r   r¶  rÕ  r   r6   r   )r   s   "r   r   rœ   Ö  s(   € ÷ Mñ M°|ð MÐLeð MÐquñ Mr   c           
   ƒ  	ó†  "  € ^ RI Hp V P                  VP                  4      pVe   Ve   V P                  ! V!  '       d   R#  VP                  \        RVP                  VP                  VP                  VP                  R7      4      G Rj  x€L
  R#  L  \         d    \        P                  RRR7        R# i ; i5i)r†  )ÚMessageTypeNz/retry)rÈ  Úmessage_typerB   Úraw_messageÚchannel_promptz!usage-limit retry dispatch failedTrÇ   )Úgateway.platforms.eventrä  rc  rB   r·  Úhandle_messager   ÚTEXTræ  rç  rb   r§   r¨   )rc   r<  r¶  rä  rH  s   &&&  r   rÝ  Ú5GatewayModelCommandsMixin._dispatch_usage_limit_retryÖ  sª   é € Ý7Ø×,Ñ,¨U¯\©\Ó:ˆð Š?˜uÒ0°T×5UÒ5UÐW\×5]Ð5]Ùð	MØ×(Ñ(¬Ø¨K×,<Ñ,<ÀUÇ\Á\Ø!×-Ñ-¸e×>RÑ>Rô*Tó U÷ Uô Uøô ô 	MÜ�L‰LÐ<ÀtˆL×Lð	MüsB   ‚?CÁCÁA
B ÂBÂB ÂCÂB Â"B>Â:CÂ=B>Â>Cc               ó    € V ^8„  d   QhRRRR/# ©r   r<  r   r   r   r   )r   s   "r   r   rœ   æ  s   € ÷ Hñ H¸ð HÈ#ñ Hr   c              ƒ  ó   "  € ^ RI Hp TP                  V'       d   VP                  4       P	                  4       MR4      w  r4V'       d   RRP                  V4      ,           #  ^ RIHpHp TP                  T! 4       Y3e   TMRR	7      pTP                  '       dB   Te>   TP                  '       d,    T P                  T P                  TP                   4      4       TP                  '       d   RMR RTP&                   2#   \         d   p\        RTR7      u Rp?# Rp?ii ; i  \         d    \"        P%                  R
RR7        Lni ; i5i)zœHandle /codex-runtime; a real change evicts the cached agent so the new api_mode applies
on the next message (avoids prompt-cache invalidation mid-session).)Úcodex_runtime_switchrE   r‹  u   
â�Œ )Úload_configÚsave_configz(gateway.codex_runtime.config_load_failedr/   N)Úpersist_callbackz7could not evict cached agent after codex-runtime changeTrÇ   u   âœ“u   âœ—Ú )Ú
hermes_clirï  Ú
parse_argsr�  r2  r�   ra   rð  rñ  rb   r   Úapplyr¤   Úrequires_new_sessionrÕ   r”  rB   r§   r¨   rt  )	rc   r<  ÚcrsÚ	new_valuer�  rð  rñ  rª   r<   s	   &&       r   Ú_handle_codex_runtime_commandÚ7GatewayModelCommandsMixin._handle_codex_runtime_commandæ  s  é € õ 	;àŸN™NÏu¨5×+AÑ+AÓ+C×+IÑ+IÔ+KÐZ\Ó]Ñˆ	ßØ˜HŸM™M¨&Ó1Õ1Ð1ð	LßBð —‘Ù‹M˜9ÒG\¹Ðbfð ó 
ˆð �>�>ˆ>˜iÒ3¸×8S×8SÐ8SðgØ×(Ñ(¨×)EÑ)EÀeÇlÁlÓ)SÔTð "Ÿ>Ÿ>˜>‘%¨uÐ5°Q°v·~±~Ð6FÐGÐGøô ô 	LÜÐ?ÀsÔKÕKûð	Lûô ô gÜ—‘ÐVÐae�Öfðgüsf   ‚A EÁ#D Á+/EÂEÂ2*D& ÃEÃ.EÄD#ÄDÄD#ÄEÄD#Ä#EÄ&"EÅEÅ
EÅEc               ó    € V ^8„  d   QhRRRR/# rí  r   )r   s   "r   r   rœ   ü  s   € ÷ &:ñ &:°|ð &:Èñ &:r   c           
   ƒ  ó$  "  € ^ RI Hp ^ RIHpHpHpHpHp VP                  4       P                  4       p V! 4       p	V! V	4      p
V'       g”   V! V	4      p\        R4      \        R4      .pV
P                  4        F6  w  rÞWÛ8X  d   RMRpVP                  \        RV V 2V! V4      R7      4       K8  	  VP                  \        R	4      4       R
P                  V4      #  V! W‰4      w  ppT! T4      '       g   \        R\        R4      R7      # T'       g   \        R4      # \        RTR7      #   \         d    / p	 ELi ; i  \         d?    RRP                  R T
 4       4      ,           p\        RTP!                  4       TR7      u # i ; i5i)uZ   Handle /personality â€” list or set a personality (hermes_cli.personality owns the state).rV   )Úactive_personality_nameÚavailable_personalitiesÚdescribe_personalityÚpersist_personalityÚresolve_personalityzgateway.personality.headerzgateway.personality.none_optionu    âœ“rE   zgateway.personality.item)r{   Úpreviewzgateway.personality.usagerë   z`none`, r€   c              3  ó.   "  € T F  pR V R 2x € K  	  R# 5ir‚   r   )rƒ   Úns   & r   r…   ÚHGatewayModelCommandsMixin._handle_personality_command.<locals>.<genexpr>  s   é € Ð.OÁ¸A°°1°#°Q­xÃùr‡   zgateway.personality.unknown)r{   Ú	availablezgateway.personality.save_failedz$gateway.personality.err_config_writer/   zgateway.personality.clearedzgateway.personality.set_to)r{   )r_   rW   Úhermes_cli.personalityrþ  rÿ  r   r  r  r�  r2  rb   r   Úitemsr‹   r�   rÒ  rñ   )rc   r<  rW   rþ  rÿ  r   r  r  Úargsr  Úpersonalitiesr¶   r�   r{   ÚpromptÚmarkerÚ_new_promptr  s   &&                r   Ú_handle_personality_commandÚ5GatewayModelCommandsMixin._handle_personality_commandü  s}  é € å4÷	
õ 	
ð ×%Ñ%Ó'×-Ñ-Ó/ˆð	Ù)Ó+ˆFñ 0°Ó7ˆßÙ-¨fÓ5ˆGÜÐ3Ó4´aÐ8YÓ6ZÐ[ˆEØ -× 3Ñ 3Ö 5‘�Ø#'¤?™¸�Ø—‘ÜÐ0¸$¸À¸xÐ7HÑRfÐgmÓRnÔoöñ !6ð
 �L‰LœÐ6Ó7Ô8Ø—9‘9˜UÓ#Ð#ð	\Ù 3°DÓ AÑˆD�+ñ # 4×(Ò(ÜÐ6¼aÐ@fÓ>gÔhÐhßÜÐ2Ó3Ð3ÜÐ-°DÔ9Ð9øô1 ô 	Ø‹Fð	ûô ô 	\Ø" T§Y¡YÑ.OÁÓ.OÓ%OÕOˆIÜÐ2¸¿¹»ÐQZÔ[Ò[ð	\üs_   ‚3F¶D0 ½FÁBFÃ!E Ã,FÃ:FÄFÄ0EÄ=FÅ EÅFÅAFÆ
FÆFÆFc               ó    € V ^8„  d   QhRRRR/# )r   Úkey_pathr   r   r   r   )r   s   "r   r   rœ   &  s   € ÷ ñ °ð Àñ r   c                ó
  € ^ RI Hp ^ RIHp ^ RIHp V! 4       R,          p V! V4      pVP                  R4      Ev r‰W#! V.VO5!  V	&   \        Wg4       R#   \         d"   p
\        P                  RY4        Rp
?
R	# Rp
?
ii ; i)
zXSave a dot-separated key to config.yaml (shared by /reasoning, /fast and their pickers).)Ú_nested_dict)Ú_gateway_config_home)Úread_user_config_rawr�  Ú.Tz Failed to save config key %s: %sNF)Úgateway.slash_commandsr  r_   r  ra   r  Úsplitr   rb   r§   r0   )rc   r  r³  r  r  r  r=   Úuser_configÚparentsÚleafrÙ   s   &&&        r   r3  Ú2GatewayModelCommandsMixin._save_gateway_config_key&  sx   € å7Ý4Ý:Ù*Ó,¨}Õ<ˆð	Ù.¨{Ó;ˆKØ%Ÿ^™^¨CÓ0‰NˆWØ8=ˆL˜Ð/ wÓ/°Ñ5Ü Ô9ÙøÜô 	Ü�L‰LÐ;¸XÔIÝûð	ús   ¢2A ÁBÁ!A=Á=Bc               ó    € V ^8„  d   QhRRRR/# )r   rA   r   r   r6   r   )r   s   "r   r   rœ   6  s   € ÷ .ñ .°3ð .À$ñ .r   c                óJ   € V P                  W4       V P                  V4       R# )zTStore (or clear with None) the session reasoning override and drop the cached agent.N)Ú_set_session_reasoning_overriderÕ   )rc   rA   r³  s   &&&r   Ú_set_reasoning_overrideÚ1GatewayModelCommandsMixin._set_reasoning_override6  s   € à×,Ñ,¨[Ô@Ø× Ñ  Ö-r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )r   rA   r   Úplatform_keyr³  rC   r   r   r   )r   s   "r   r   rœ   ;  s;   € ÷ %@ñ %@Øð%@Ø.1ð%@Ø:=ð%@ØOSð%@à	ñ%@r   c                ó   € ^ RI Hp T;'       g    RP                  4       P                  4       p^ RIHp V! W4      p\        P                  V4      pVe?   W€n        Ve   W‡n	        V P                  RV R2V4       V'       d   RMRp	\        W’R	7      # VR
8X  dW   V'       d   \        R4      # V P                  VR4       V P                  4       V n        V P                  V4       \        R4      # V! V4      p
V
f   \        RVR7      # W n        V'       d[   V P                  RV4      '       d%   T P!                  Ye   T
MR4       \        RVR7      # V P!                  W4       \        RVR7      # V P!                  W4       \        RVR7      # )zCApply a /reasoning argument (typed or picked) and return the reply.r'  rE   ©Úlocal_live_for_routeNzdisplay.platforms.z.show_reasoningz gateway.reasoning.display_set_onz!gateway.reasoning.display_set_off)r  Úresetz*gateway.reasoning.reset_global_unsupportedzgateway.reasoning.reset_donezgateway.reasoning.unknown_arg©Úargr)  r*  r,  z(gateway.reasoning.set_global_save_failedr+  )r  r(  r2  rñ   r1  r'  Ú_REASONING_DISPLAY_TOGGLESr%   Ú_show_reasoningÚshow_reasoningr3  r   r   Ú_load_reasoning_configÚ_reasoning_configrÕ   r!  )rc   rA   r$  r³  rC   r(  r'  r6  r'   ÚkeyÚparseds   &&&&&      r   r4  Ú4GatewayModelCommandsMixin._apply_reasoning_selection;  sr  € õ 	<à—�˜"×#Ñ#Ó%×+Ñ+Ó-ˆÝIÙ# DÓ6ˆÜ)×-Ñ-¨eÓ4ˆØÒØ#'Ô ØÒØ&*Ô#Ø×)Ñ)Ð,>¸|¸nÈOÐ*\Ð^bÔcß8<Ñ4ÐBeˆCÜ�SÔ0Ð0Ø�GÔßÜÐEÓFÐFØ×0Ñ0°¸dÔCØ%)×%@Ñ%@Ó%BˆDÔ"Ø×$Ñ$ [Ô1ÜÐ3Ó4Ð4á'¨Ó.ˆØŠ>ÜÐ4¸%Ô@Ð@Ø!'ÔßØ×,Ñ,Ð-EÀu×MÒMà×,Ñ,¨[ÒDT¹&ÐZ^Ô_ÜÐ7ÀÔFÐFØ×(Ñ(¨Ô=ÜÐ?ÈÔNÐNØ×$Ñ$ [Ô9ÜÐ0¸Ô?Ð?r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   r<  r   rA   r   rs  r¾  rQ   r   r   r   )r   s   "r   r   rœ   b  s4   € ÷ ñ Ø!ðØ03ðØ<?ðØJNðà	ñr   c           
   ƒ  óŒ  "  € V P                  VP                  4      pVe   \        \        V4      RR4      f   R#  VP	                  VP                  P
                  W4VWPP                  V4      R7      G Rj  x€L
 p\        \        VRR4      4      #  L  \         d"   p\        P                  RT4        Rp?R# Rp?ii ; i5i)z™Send an interactive choice picker when the adapter *type* supports it (the /model gate);
a failed send returns False (text fallback) instead of erroring.Nr°  F)r  rs  r¾  rA   r¿  rC  r¤   z3send_choice_picker failed, falling back to text: %s)rc  rB   r¹   rÒ   r°  r  rÆ  r   rb   r§   rº   )	rc   r<  rA   rs  r¾  r¿  rH  r<   rÙ   s	   &&&&&&   r   rÄ  Ú1GatewayModelCommandsMixin._try_send_choice_pickerb  sµ   é € ð
 ×,Ñ,¨U¯\©\Ó:ˆØŠ?œg¤d¨7£mÐ5IÈ4ÓPÒXÙð	Ø"×5Ñ5ØŸ™×,Ñ,°EÐXcØ#5×@TÑ@TÐUZÓ@[ð 6ó ÷ ˆFô œ ¨	°5Ó9Ó:Ð:ñ	øô
 ô 	Ü�N‰NÐPÐRSÔTÝûð	üs@   ‚:C½;B Á8BÁ9B ÂCÂB ÂCÂ B<Â6CÂ<CÃCc               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rœ   t  s"   € ÷ E^ñ E^°\ð E^Àmñ E^r   c              ƒ  ó¦  a aaaaa"  € ^ RI Hp ^ RIHp VP	                  4       P                  4       pS P                  V4      w  rV\        P                  ! S P                  VP                  4      G Rj  x€L
 pS P                  V4      oS P                  4       S n        ^ RIHp V! S VP                  4      ;p	e   \!        V	RR4      RJ S n        \#        \!        S R/ 4      ;'       g    / P%                  S4      ;'       g    / P%                  R4      ;'       g    R	4      p
S P'                  VP                  SV
R
7      S n        V! VP                  P*                  4      oV'       d   S P-                  SSWVR7      # S P(                  p^ RIHo ^ RI Hp ^ RIHp \!        S R/ 4      ;'       g    / P%                  S4      ;'       g    / p/ p\8        P:                  ! \<        4      ;_uu_ 4        V! S P>                  R7      P%                  R/ 4      ;'       g    / pRRR4       VP%                  R4      ;'       g    VP%                  R4      T
;'       g+    VP%                  R4      ;'       g    VP%                  R4      V! RV/4      3oVf   \A        R4      RupoM@VP%                  R4      RJ d   \A        R4      RupoMVP%                  RR4      oS! S.SO5!  pS P                  '       d   \A        R4      M
\A        R4      pS\!        S R/ 4      ;'       g    / 9   pV'       d   \A        R4      M
\A        R4      pR VV V3R llpS PC                  VS\A        R VVVR!7      R"RR#\A        R$4      R%SR8H  /.VVV3R& lV 4       OR' R* 4       OVR(7      G Rj  x€L
 pV'       d   R# \A        R)VVVR!7      #  ELD  + '       g   i     EL§; i L45i)+uI   Handle /reasoning command â€” manage reasoning effort and display toggle.r.  )ÚVALID_REASONING_EFFORTSN)Ú
local_liver-  TrÏ   r   rE   )rB   rA   r   r0  )Úeffort_display_labelrV   )Úget_current_runtimerX   r"   rY   zgateway.reasoning.level_defaultÚmediumÚenabledFz gateway.reasoning.level_disabledÚnoner-  zgateway.reasoning.display_onzgateway.reasoning.display_offÚ_session_reasoning_overrideszgateway.reasoning.scope_sessionzgateway.reasoning.scope_globalc               ó$   € V ^8„  d   QhRRRRRR/# r²  r   )r   s   "r   r   ÚIGatewayModelCommandsMixin._handle_reasoning_command.<locals>.__annotate__§  s&   € ÷ 	Uñ 	U°ð 	U¸Sð 	UÀSñ 	Ur   c              “  ó2   <"  € SP                  SSV4      # 5ir£  )r4  )rZ  r³  r$  rc   rA   s   &&€€€r   Ú_on_reasoning_choiceÚQGatewayModelCommandsMixin._handle_reasoning_command.<locals>._on_reasoning_choice§  s   øé € Ø×2Ñ2°;ÀÈeÓTÐTùs   ƒzgateway.reasoning.picker_title)r7  ÚscopeÚdisplayr³  r»  zgateway.reasoning.choice_nonerz   c              3  óJ   <"  € T F  pR VRS! V.SO5!  RVS8H  /x € K  	  R# 5i)r³  r»  rz   Nr   )rƒ   ÚlvÚ_routeÚcurrent_effortr:  s   & €€€r   r…   ÚFGatewayModelCommandsMixin._handle_reasoning_command.<locals>.<genexpr>°  s7   øé € ð 5Ù3�bð ˜B Ñ)=¸bÐ)JÀ6Ó)JÈLÐZ\Ð`nÑZnÕoÛ3ùs   ƒ #c              3  óJ   "  € T F  pR VR\        RV 24      RR/x € K  	  R# 5i)r³  r»  zgateway.reasoning.choice_rz   FNr   )rƒ   Úvs   & r   r…   rK  ²  s2   é € ð 6Ù4�að ˜A˜w¬Ð,EÀaÀSÐ*IÓ(JÈLÐZ_Õ`Û4ùs   ‚!#r½  zgateway.reasoning.status)r(  r'   r(   )"r_   r/  r  r8  r�  r2  Ú_parse_reasoning_command_argsr:   r;   r“  rB   r”  Ú_load_show_reasoningr,  r1  r9  r¹   r   r%   Ú!_resolve_session_reasoning_configr/  r  r4  Úagent.reasoning_effortr:  rW   Úhermes_cli.codex_runtime_switchr;  rì   rí   rb   r=   r   rÄ  )rc   r<  r/  r8  Úraw_argsr
  rC   Ú_reasoning_sourcer9  Ú_liveÚ_session_modelÚrcrW   r;  Ú_session_routeÚ
_model_cfgr7  Údisplay_stateÚhas_session_overriderE  rC  Úpicker_sentrI  rJ  r:  r$  rA   s   f&                    @@@@@r   Ú_handle_reasoning_commandÚ3GatewayModelCommandsMixin._handle_reasoning_commandt  s–  ýé € å4Ý<à×)Ñ)Ó+×1Ñ1Ó3ˆØ#×AÑAÀ(ÓKÑˆô #*×"3Ò"3°D×4ZÑ4ZÐ\a×\hÑ\hÓ"i×iÐØ×2Ñ2Ð3DÓEˆØ#×8Ñ8Ó:ˆÔÝ?Ù  e§l¡lÓ3Ð3ˆEÒ@Ü#*¨5Ð2BÀDÓ#IÈTÐ#QˆDÔ äÜ�dÐ6¸Ó;×AÐA¸r×FÑFÀ{ÓS×YÐYÐWY×^Ñ^Ð_fÓg×mÐmÐkmó
ˆð "&×!GÑ!GØ—<‘<¨[Àð "Hó "
ˆÔñ ,¨E¯L©L×,AÑ,AÓBˆßØ×2Ñ2°;ÀÈdÐ2ÓrÐrØ×#Ñ#ˆõ 	@Ý4ÝGÜ" 4Ð)CÀRÓH×NÐNÈB×SÑSÐT_Ó`×fÐfÐdfˆØˆ
Ü× Ò ¤×+Õ+Ù-¸$×:JÑ:JÔK×OÑOÐPWÐY[Ó\×bÐbÐ`bˆJ÷ ,ð ×Ñ˜zÓ*×HÐH¨j¯n©n¸ZÓ.HØ×RÐR˜jŸn™n¨YÓ7×RÐR¸:¿>¹>È'Ó;RÙ ¨*Ð 5Ó6ð
ˆð
 Š:Ü$%Ð&GÓ$HÈ(Ð!ˆE‘>Ø�V‰V�IÓ %Ó'Ü$%Ð&HÓ$IÈ6Ð!ˆE‘>àŸV™V H¨hÓ7ˆNÙ(¨ÐA¸&ÓAˆEØ=A×=Q×=QÐ=QœÐ8Ô9ÔWXÐYxÓWyˆØ*¬w°tÐ=[Ð]_Ó/`×/fÐ/fÐdfÑgÐß8L”Ð3Ô4ÔRSÐTtÓRuˆ÷	Uò 	Uð !×8Ñ8ØØÜÐ4¸EÈÐXeÔfà˜& '¬1Ð-LÓ+MÈ|Ð]kÐouÑ]uÐvðö5Ù3ó5ðñ6Ù4ó6ð	ð  4ð 9ó 
÷ 
ˆ÷ ÙÜÐ+°5ÀÈ}Ô]Ð]òy j÷0 ,×+Ð+úñ*
ùs‰   ˆA,OÁ4N8Á5A3OÃ)OÄOÄAOÅ)AOÆ/OÇ'OÇ/.N;ÈOÈ=OÉOÉ0B OË1*OÌOÌ)A1OÎOÎOÎ'OÎ;O	Ï
Oc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rA   r   r³  Úpersistr   r   r   )r   s   "r   r   rœ   »  s)   € ÷ ;ñ ;°ð ;¸Sð ;È4ð ;Ð\_ñ ;r   c                óð  € \         P                  V4      pVf   \        RVR7      # Vw  rVpV'       d   \        V4      MVP                  4       pWPn        ^ RIHp	 V'       dg   V P                  RV4      '       dO   V	! W4      e   V P                  W4       MV P                  VRRR7       V P                  V4       \        RVR	7      # V P                  W4       V P                  V4       \        R
VR	7      # )z>Apply a /fast argument (typed or picked) and return the reply.Nzgateway.fast.unknown_argr)  r&  zagent.service_tierT)Úclearzgateway.fast.saved)r»  zgateway.fast.session_only)
Ú_FAST_SELECTIONSr%   r   ÚupperÚ_service_tierr1  r'  r3  Ú"_set_session_service_tier_overriderÕ   )
rc   rA   r³  r`  Ú	selectionr   Úsaved_valueÚ	label_keyr»  r'  s
   &&&&      r   Ú_apply_fast_selectionÚ/GatewayModelCommandsMixin._apply_fast_selection»  s×   € ä$×(Ñ(¨Ó/ˆ	ØÒÜÐ/°UÔ;Ð;Ø'0Ñ$ˆ˜9ß )”�)”¨u¯{©{«}ˆØ!ÔÝIß�t×4Ñ4Ð5IÈ;×WÒWÙ# DÓ6ÒBà×7Ñ7¸ÕJà×7Ñ7¸ÀTÐQUÐ7ÔVØ×$Ñ$ [Ô1ÜÐ)°Ô7Ð7à×/Ñ/°ÔBØ× Ñ  Ô-ÜÐ,°EÔ:Ð:r   c               ó    € V ^8„  d   QhRRRR/# r  r   )r   s   "r   r   rœ   Ñ  s   € ÷ 15ñ 15°ð 15Àñ 15r   c              ƒ  óà  a aa"  € ^ RI HpHp ^ RIHpHp S P                  VP                  4       P                  4       P                  4       4      w  po\        P                  ! S P                  VP                  4      G Rj  x€L
 pS P                  V4      oS P                  SR7      S n        V! 4       p \        P                  ! S P"                  VSVR7      G Rj  x€L
 w  rš\'        Wš4      '       g   \)        R4      # TP+                  Wf4      p^ RIHp V! WšP+                  R4      V
P+                  R	4      V
P+                  R
4      R7      pVR8X  d   V'       g   \)        RV	R7      # V'       d   VR8w  d   S P1                  SVSR7      # V! S P                   4      pR\)        R4      R\)        R4      /P+                  WÝ4      pR VV V3R llpS P3                  TS\)        RVR7      . ROV'       d   R MR!O Uu. uF  pRVR\)        RV 24      RVV8H  /NK  	  upVR7      G Rj  x€L
 pV'       d   R# \)        RVR7      #  ELÄ ELk  \$         d    T! T4      / r© EL~i ; iu upi  LA5i)"uŠ   Handle /fast â€” the CLI Priority Processing toggle; session-scoped unless ``--global``
(persists agent.service_tier, parity with /model).)ÚFAST_ARG_ALIASESÚservice_tier_word)rW   Ú_resolve_gateway_modelN)rA   )rB   rA   r  zgateway.fast.not_supported)Úultrafast_offeredr"   r#   rl   )r"   r#   Úaccess_tokenr   z$gateway.fast.ultrafast_not_supportedrß   Ústatus©r`  r
   zgateway.fast.status_fastr   zgateway.fast.status_normalc               ó$   € V ^8„  d   QhRRRRRR/# r²  r   )r   s   "r   r   ÚDGatewayModelCommandsMixin._handle_fast_command.<locals>.__annotate__ó  s&   € ÷ 	Zñ 	Z¨Cð 	Z¸ð 	ZÀñ 	Zr   c              “  ó4   <"  € SP                  SVSR 7      # 5i)rt  )rj  )rZ  r³  rC   rc   rA   s   &&€€€r   Ú_on_fast_choiceÚGGatewayModelCommandsMixin._handle_fast_command.<locals>._on_fast_choiceó  s   øé € Ø×-Ñ-¨k¸5È.Ð-ÓYÐYùs   ƒzgateway.fast.picker_title)Úmoder³  r»  zgateway.fast.choice_rz   r½  zgateway.fast.status)r
   r   r   r   )r   r   )Úagent.fast_modern  ro  r_   rW   rp  rN  r�  r2  rñ   r:   r;   r“  rB   r”  Ú_resolve_session_service_tierre  Ú_resolve_session_agent_runtimerb   r&   r   r%   Úagent.codex_service_tiersrq  rj  rÄ  )rc   r<  rn  ro  rW   rp  r
  rB   r  r   r   rq  r   rz  rs  rx  rM  r\  rC   rA   s   f&                @@r   Ú_handle_fast_commandÚ.GatewayModelCommandsMixin._handle_fast_commandÑ  sa  úé € ÷ 	HßLð  $×AÑAÀ%×BXÑBXÓBZ×B`ÑB`ÓBb×BhÑBhÓBjÓkÑˆˆnô ×(Ò(¨×)OÑ)OÐQV×Q]ÑQ]Ó^×^ˆØ×2Ñ2°6Ó:ˆØ!×?Ñ?ÈKÐ?ÓXˆÔÙ*Ó,ˆð	Eä#*×#4Ò#4Ø×3Ñ3¸FÐP[Ðitô$v÷ v‰NˆEô
 $ E×3Ò3ÜÐ1Ó2Ð2Ø×#Ñ# DÓ/ˆÝ?Ù% e·k±kÀ*Ó6MÐX_×XcÑXcÐdnÓXoØ3:·;±;¸yÓ3IôKˆ	à�;Ô§yÜÐ;À5ÔIÐIß�D˜HÔ$Ø×-Ñ-¨k¸4ÈÐ-ÓXÐXÙ  ×!3Ñ!3Ó4ˆØœ!Ð6Ó7¸Ä1ÐEaÓCbÐc×gÑgÐhlÓsˆ÷	Zò 	Zð !×8Ñ8ØØÜÐ/°fÔ=ò d×PY¹nÐ_aÑcóác�Að ˜!˜W¤aÐ*>¸q¸cÐ(BÓ&CÀ\ÐSWÐ[\ÑS\Ó]Ùcñð  /ð 9ó 	
÷ 	
ˆ÷ ÙÜÐ&¨VÔ4Ð4òO _òvøäô 	Eá3°KÓ@À"“7ð	Eüò.ñ		
ùst   …A=I.ÂIÂ3I.Â7'I ÃI	ÃI Ã%A9I.ÅI.Å4B
I.Ç> I'ÈI.È*I,È+I.È7I.É	I ÉI$É I.É#I$É$	I.)rÃ   r/  re  r,  r£  )F)"ro   rp   rq   rr   rs   r«   r¼   rÚ   r÷   rÿ   rÓ   rý   r!  rþ   rI  re  r|  r‚  r�  rª  r¤  r·  r¸  rÝ  rú  r  r3  r!  r4  rÄ  r]  rj  r  rw   r   r   r   r˜   r˜   –   sÙ   † Ù_õõ@õ2Xðt8 à&*÷8 ðt	eØJO÷	eò

õ	õ2õ,-_õ^$õ*- õ^!
õFBõ5`ðrOÐbdð OØ@D÷O÷(DõBð#ØLP÷#÷JMõ Hõ,&:õTõ .÷
%@õNõ$E^÷N;÷,15ñ 15r   r˜   )Úpriorityr
   zgateway.fast.label_fast)Nr   zgateway.fast.label_normal)r   r   N)r   r   N)r   r   Nr£  )rs   Ú
__future__r   r:   rì   ru   ÚloggingÚtypingr   r   Ú
agent.i18nr   rè  r   ra   r   Úutilsr	   Ú	getLoggerr§   rc  r&   r+  r3   r>   Ú	dataclassr@   rŒ   r–   r˜   r   r   r   Ú<module>r‰     sÔ   ðñõ #ã Û Û Û ß  å Ý 0Ý 1Ý 'à	×	Ò	˜=Ó	)€ð Ð;ØÐ
9ØÐ;Ø	Ð8Ø
Ð"Ø
Ð"ØÐ1ðÐ ÷jð % d¨D°$¸ÀÀuÈeÐTÐ õõJð ×Ñ÷5Qð 5Qó ð5Qðr Ð õ÷$l5ó l5r   