+
    jHàj‰0  ã                  ó¾   € R t ^ RIHt ^ RIHt ^ RIHtHt ^ RIH	t	 ^ RI
HtHtHtHtHt R R lt] ! R R	4      4       tR
 R ltR R ltR R ltR R ltRR ltR# )zèAzure Foundry wizard (OpenAI-style or Anthropic-style transport, API-key or Entra ID auth).

Imports of hermes_cli.config / azure_detect stay lazy (tests patch them at call time).
Prompt strings and config write order are behavior.
)Úannotations)Úinstall_hint)Ú	dataclassÚfield)Ú clear_model_endpoint_credentials)Ú_HTTPÚ_askÚ_commit_model_configÚ_load_config_model_sectionÚ_sayc               ó    € V ^8„  d   QhRRRR/# )é   ÚmodeÚstrÚreturn© )Úformats   "ÚG/home/ubuntu/.hermes/hermes-agent/hermes_cli/model_setup_flows_azure.pyÚ__annotate__r      s   € ÷ Oñ O˜Cð O Cñ Oó    c                ó   € V R 8X  d   R# R# )Úchat_completionszOpenAI-stylezAnthropic-styler   )r   s   &r   Ú_azure_mode_labelr      s   € Ø!Ð%7Ô7ˆ>ÐNÐ=NÐNr   c                  óp   € ] tR t^t$ RtRtR]R&   RtR]R&   RtR]R&   ]	! ]
R7      tR	]R
&   RtR]R&   RtR# )Ú_AzureCurrentz;The active Azure Foundry settings shown as prompt defaults.Ú r   Úbase_urlÚapi_modeÚapi_keyÚ	auth_mode)Údefault_factoryÚdictÚentrar   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__annotations__r   r   r   r!   r"   r   Ú__static_attributes__r   r   r   r   r      s<   ‡ áEØ€HˆcÓØ€HˆcÓØ€IˆsÓÙ¨Ô-€Eˆ4Ó-Ø€GˆS×r   r   c               ó   € V ^8„  d   QhRR/# )r   r   r   r   )r   s   "r   r   r      s   € ÷ ñ ˜mñ r   c                ó€  € ^ RI Hp \        V! R4      ;'       g    RR7      pV P                  R/ 4      p\	        V\
        4      '       dô   VP                  R4      R8X  dÞ   \        VP                  RR4      ;'       g    R4      Vn        \        VP                  R	R4      ;'       g    R4      Vn        \        VP                  R
4      ;'       g    R4      P                  4       P                  4       ;'       g    RVn        VP                  R4      ;'       g    / p\	        V\
        4      '       d   TM/ Vn        V# )é    )Úget_env_valueÚAZURE_FOUNDRY_API_KEYr   )r   ÚmodelÚproviderúazure-foundryr   r   r   r   r"   )Úhermes_cli.configr-   r   ÚgetÚ
isinstancer!   r   r   r   ÚstripÚlowerr   r"   )Úconfigr-   ÚcurÚ	model_cfgÚ
_cur_entras   &    r   Ú_azure_currentr;      sð   € Ý/ä
¡Ð.EÓ F× LÐ LÈ"Ô
M€CØ—
‘
˜7 BÓ'€IÜ�)œT×"Ò" y§}¡}°ZÓ'@ÀOÔ'SÜ˜9Ÿ=™=¨°RÓ8×>Ð>¸BÓ?ˆŒÜ˜9Ÿ=™=¨°RÓ8×>Ð>¸BÓ?ˆŒÜ˜IŸM™M¨+Ó6×CÐC¸)ÓD×JÑJÓL×RÑRÓT×aÐaÐXaˆŒØ—]‘] 7Ó+×1Ð1¨rˆ
Ü",¨Z¼×">Ò">‘JÀBˆŒ	Ø€Jr   c               ó   € V ^8„  d   QhRR/# )r   Úcurrent_entrar!   r   )r   s   "r   r   r   ,   s   € ÷ 6+ñ 6+¨$ñ 6+r   c           	     óØ  €  ^ RI HpHpHpHpHp \        4        T! 4       '       g   \        RRR	R
\        R4       2R4       / p\        T P                  R4      ;'       g    R4      P                  4       pT;'       g    Tp	T'       d   Y‡R&   \        RR4       T! T	R7      p
T! T
RR7      pTP                  R4      '       dJ   TP                  R4      ;'       g    . pT'       d   RP                  T4      MRp\        RT RT	 R24       M}TP                  R4      ;'       g    RpTP                  R4      ;'       g    Rp\        RT 2RT 24       \        RR R!7      pTf   R# TP                  4       R%9  d   \        R"4       R#  T! T
R#7      pTT3#   \         d   p\        RRT 2R4        Rp?R# Rp?ii ; i  \          d   p\        R$T 24       Rp Rp?TT3# Rp?ii ; i)&z­Entra ID credential preflight. Returns ``(token_provider, entra_overrides)``; ``None``
when the user cancelled; ``False`` when the adapter is missing (fall back to API key).)ÚEntraIdentityConfigÚSCOPE_AI_AZURE_DEFAULTÚbuild_token_providerÚdescribe_active_credentialÚhas_azure_identity_installedr   u-   âš  Could not import azure-identity adapter: z  Falling back to API key auth.NFu6   â—� The 'azure-identity' package is not installed yet.zD  The preflight requests it through PM if lazy installs are enabled.z9  To install explicitly, run from the Hermes environment:z    zazure-identityz  Then restart Hermes.Úscopeu>   â—� Probing Microsoft Entra ID credential chain (up to 10s)...©rD   g      $@)r7   Útimeout_secondsÚokÚenv_sourcesz, zdefault chainu   âœ“ Entra ID token acquired (z, scope=Ú)Úerrorzcredential chain exhaustedÚhintzqRun `az login`, attach a managed identity to this VM, or set AZURE_TENANT_ID/AZURE_CLIENT_ID/AZURE_CLIENT_SECRET.u   âš  z  Hint: z4Save Entra config anyway and validate later? [Y/n]: T©Úrawz
Cancelled.)r7   u0   âš  Could not build token provider for probing: )r   ÚyÚyes)Úagent.azure_identity_adapterr?   r@   rA   rB   rC   ÚImportErrorr   Úprintr   r   r3   r5   Újoinr   r6   Ú	Exception)r=   r?   r@   rA   rB   rC   ÚexcÚentra_overridesÚ_persisted_scope_overrideÚentra_scopeÚ_configÚinforH   ÚtagÚerrrK   ÚansÚtoken_providers   &                 r   Ú_azure_entra_preflightr_   ,   sñ  € ð÷	*õ 	*ô 
„GÙ'×)Ò)ÜÐEØSØHØ”LÐ!1Ó2Ð3Ð4Ø%ô		'ð €OÜ # M×$5Ñ$5°gÓ$>×$DÐ$DÀ"Ó E× KÑ KÓ MÐØ+×EÐEÐ/E€Kß Ø#<˜Ñ äˆÐMÔNÙ!¨Ô4€GÙ%¨WÀdÔK€DØ‡x�x�‡~‚~Ø—h‘h˜}Ó-×3Ð3°ˆß(3ˆd�i‰i˜Ô$¸ˆÜÐ-¨c¨U°(¸;¸-ÀqÐIÕJà�h‰h�wÓ×?Ð?Ð#?ˆØ�x‰x˜Ó÷ 
ð 
Øð 	ô 	ˆt�C�5ˆ\˜X d VÐ,Ô-ÜÐIÈtÔTˆØŠ;ÙØ�9‰9‹;Ð.Ô.Ü�,ÔÙðÙ-°WÔ=ˆð ˜?Ð*Ð*øô_ ô ÜˆRÐ@ÀÀÐFÐHiÔjÝûðûôX ô ÜÐ@ÀÀÐFÔGØŒØ˜?Ð*Ð*ûðús/   ‚F Æ	G ÆF>Æ#F9Æ9F>ÇG)ÇG$Ç$G)c               ó    € V ^8„  d   QhRRRR/# )r   Údiscovered_modelsÚlistÚcurrent_modelr   r   )r   s   "r   r   r   e   s   € ÷ ñ ¨ð ¸cñ r   c                ó”  € V '       g,   \        RT;'       g    R R24      pVf   R# T;'       g    T# \        R4       \        V R,          ^R7       F  w  r4\        RVR	 R
V 24       K  	  \        V 4      ^8”  d    \        R\        V 4      ^,
           R24       \        4        \        RT;'       g
    V ^ ,           R2RR7      pVf   R# V'       g   T;'       g
    V ^ ,          # VP	                  4       '       dI   ^\        V4      u;8:  d   \        \        V 4      ^4      8:  d   M V# V \        V4      ^,
          ,          # V# )z=Model/deployment step of the Azure flow; None when cancelled.zModel / deployment name [ze.g. gpt-5.4, claude-sonnet-4-6ú]: Nz"Available models on this endpoint::Né   N)Ústartz  z>2z. z
  ... and z' more (type name manually if not shown)z+Pick by number, or type a deployment name [TrL   )r   rR   Ú	enumerateÚlenÚisdigitÚintÚmin)ra   rc   Ú
model_nameÚiÚmidÚpicks   &&    r   Ú_azure_pick_modelrq   e   s4  € çÜÐ5°m×6hÐ6hÐGhÐ5iÐilÐmÓnˆ
Ø!Ò)ˆtÐL°
×0KÐ0K¸mÐLÜ	Ð
.Ô/ÜÐ-¨cÕ2¸!×<‰ˆÜ��1�R�&˜˜3˜%Ð Ö!ñ =ä
ÐÓ Ô"Ü�
œ3Ð0Ó1°BÕ6Ð7Ð7^Ð_Ô`Ü	„GÜÐ=¸m×>cÐ>cÐO`ÐabÕOcÐ=dÐdgÐhÐnrÔs€DØ‚|ÙßØ×4Ð4Ð 1°!Õ 4Ð4Ø‡|�|‡~‚~˜!œs 4›yÖK¬C´Ð4EÓ0FÈÓ,KÖKà€Kð !¤ T£¨Q¥Õ/Ð/Ø€Kr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úeffective_urlr   Úeffective_keyÚcurrent_api_moder   )r   s   "r   r   r   z   s'   € ÷ wñ w¨3ð w¸sð wÐfiñ wr   c           	     ó.  € ^ RI Hp \        RR4       VP                  WVR7      p\	        VP
                  4      pVP                  ;'       g    RpV'       df   \        R\        V4       24       VP                  '       d   \        RVP                   R24       V'       d   \        R\        V4       R	24       Wv3# \        R
VP                   2RRRRRR4       VR8X  d   RMRp\        RV R2RR7      p	V	f   R# T	;'       g    TR8X  d   RV3# RV3# )z’Probe the endpoint; returns ``(api_mode, discovered_models)`` (manual pick of the API
format when detection is incomplete) or None when cancelled.©Úazure_detectr   u;   â—� Probing endpoint to auto-detect transport and models...©r   r^   u   âœ“ Detected API transport: z    (rI   u
   âœ“ Found z# deployed model(s) on this endpointu   âš  Auto-detection incomplete: z7Select the API format your Azure Foundry endpoint uses:z.  1. OpenAI-style  (POST /v1/chat/completions)z:     For: GPT models, Llama, Mistral, and most open modelsz)  2. Anthropic-style  (POST /v1/messages)z9     For: Claude models deployed via Anthropic API formatÚanthropic_messagesÚ2Ú1zAPI format [1/2] (ú): TrL   Nr   )Ú
hermes_clirx   r   Údetectrb   Úmodelsr   rR   r   Úreasonri   r   )
rs   rt   r^   ru   rx   Ú	detectionra   r   Údefault_choiceÚmode_choices
   &&&&      r   Ú_azure_detect_transportr…   z   s3  € õ (äˆÐJÔKØ×#Ñ# MÐYgÐ#Óh€IÜ#'¨	×(8Ñ(8Ó#9ÐØ×&Ñ&×,Ð,¨"€HßÜÐ,Ô->¸xÓ-HÐ,IÐJÔKØ××ÐÜ�E˜)×*Ñ*Ð+¨1Ð-Ô.ßÜ�JœsÐ#4Ó5Ð6Ð6YÐZÔ[ØÐ*Ð*ÜÐ*¨9×+;Ñ+;Ð*<Ð	=¸rØ	BØ	9Ø	EØ	4Ø	DôFð -Ð0DÔD‘SÈ#€NÜÐ+¨NÐ+;¸3Ð?ÀTÔJ€KØÒÙØ%0×%BÐ%B°NÀsÔ$JÐ ÐevÐvÐvÐPbÐevÐvÐvr   c                ó  € ^ RI HpHp ^ RIHp \        V 4      p\        RRRBRRRRRR4	       VP                  '       d   \        R	VP                   24       VP                  '       d"   \        R
\        VP                  4       24       VP                  R8X  d   \        R4       M2VP                  '       d!   \        RVP                  R,           R24       \        4        VP                  ;'       g    Rp\        RV R24      pVf   R# T;'       g    VP                  P                  R4      pV'       g   \        R4       R# VP                  \         4      '       g   \        RV R24       R# \        RRRRRR4       VP                  R8X  d   RMRp	\        RV	 R 2R!R"7      p
V
f   R# T
;'       g    T	R8H  pRp/ pRpV'       d)   \#        VP$                  4      pVf   R# VR#J d   R#pMVw  ríV'       gy   \        4        \        R$VP                  '       d   VP                  R,          R%,           MR& R2R!R'7      pVf   R# T;'       g    VP                  pV'       g   \        R(4       R# \'        WŒWåP                  4      pVf   R# Vw  pp\        4        \)        VV4      pVf   R# V'       g   \        R)4       R# VP+                  VWŒVR*7      pV'       g
   V! R+V4       \-        4       w  ppR,VR-&   VVR.&   VVR/&   VVR0&   V'       d   RMR1VR2&   \/        VR#R37       RC Uu/ uF!  pVP1                  V4      ;p'       g   K  VVbK#  	  ppV'       d   V'       d   VVR4&   MVP3                  R4R4       V'       d   VVR5&   \5        V4       \7        V4      V R6&   RD F  pV! V4      '       g   K  V! VR4       K  	  \        RR7R8V 2R9\        V4       2R:V'       d   R;MR< 2R=V 2V'       d   R>VR? R@2MRAR4       R# u upi )EuÂ  Azure Foundry: endpoint, auth mode, API mode, model. Two transports (OpenAI-style
``/v1/chat/completions``, Anthropic-style ``/v1/messages``) and two auth modes: API key
(``AZURE_FOUNDRY_API_KEY``) or Microsoft Entra ID (keyless RBAC via ``azure-identity``; the
``Azure AI User`` role covers both transports). Detection: ``/anthropic`` URL suffix â†’ Anthropic;
``GET <base>/models`` â†’ OpenAI-style + picker; Anthropic Messages probe; manual entry.)r-   Úsave_env_valuerw   r   zAzure Foundry Configurationz9Azure Foundry can host models with either OpenAI-style orz6Anthropic-style API endpoints.  Hermes will probe yourz6endpoint to auto-detect the transport and the deployedzmodels when possible.z  Current endpoint:  z  Current API mode:  Úentra_idz1  Current auth mode: Microsoft Entra ID (keyless)z  Current auth mode: API key (:Né   Nz...)zhe.g. https://<resource>.openai.azure.com/openai/v1 or https://<resource>.services.ai.azure.com/anthropiczAPI endpoint URL [re   NÚ/z$No endpoint URL provided. Cancelled.zInvalid URL: z& (must start with http:// or https://)zAuthentication:z=  1. API key                  (AZURE_FOUNDRY_API_KEY in .env)zO  2. Microsoft Entra ID       (managed identity / workload identity / az login)zY     Recommended by Microsoft. Works for both OpenAI-style and Anthropic-style endpoints.z?     Requires the 'Azure AI User' role on the Foundry resource.r{   r|   zAuthentication mode [1/2] (r}   TrL   Fz	API key [z...Úrequired)ÚsecretzNo API key provided. Cancelled.z"No model name provided. Cancelled.ry   r.   r1   r0   r   r   Údefaultr   r   )Úclear_api_moder"   Úcontext_lengthr/   u   âœ“ Azure Foundry configured:z    Endpoint:       z    API mode:       z    Auth:           zMicrosoft Entra ID (keyless)zAPI keyz    Model:          z    Context length: Ú,z tokenszA    Context length: not auto-detected (will fall back at runtime)z2==================================================rE   )ÚOPENAI_BASE_URLÚOPENAI_API_KEY)r2   r-   r‡   r~   rx   r;   r   r   rR   r   r   r   r   r   ÚrstripÚ
startswithr   r_   r"   r…   rq   Úlookup_context_lengthr
   r   r3   Úpopr	   r!   )r7   rc   r-   r‡   rx   r8   Ú_placeholderr   rs   Ú_auth_defaultÚauth_choiceÚ	use_entrart   rV   r^   Ú	preflightr   Údetectedr   ra   Úeffective_modelÚctx_lenÚcfgr/   ÚkÚvÚclean_entraÚvars   &&                          r   Ú_model_flow_azure_foundryr¤   —   s  € ÷ @Ý'ä
˜Ó
 €CÜˆÐ*¨H°bØ	DØ	AØ	AØ	  "ô	&ð
 ‡|‡|€|ÜÐ% c§l¡l ^Ð4Ô5Ø
‡|‡|€|ÜÐ%Ô&7¸¿¹Ó&EÐ%FÐGÔHØ
‡}�}˜
Ô"ÜÐAÕBØ	��ˆÜÐ.¨s¯{©{¸2­Ð.?¸tÐDÔEÜ	„Gð —<‘<÷ tð tØrð äÐ(¨¨°cÐ:Ó;€HØÒÙØ×-Ð- §¡×5Ñ5°cÓ:€MßÜÐ4Ô5ÙØ×#Ñ#¤E×*Ò*Ü�˜m˜_Ð,RÐSÔTÙô 	ˆÐÐ _Ø	ZØ	dØ	JôLð Ÿ=™=¨JÔ6‘C¸C€MÜÐ4°]°OÀ3ÐGÈTÔR€KØÒÙØ×-Ð- °#Ñ5€Ið €MØ€OØ€NßÜ*¨3¯9©9Ó5ˆ	ØÒÙØ˜ÓØ‰Ià.7Ñ+ˆNßÜŒÜ˜¸c¿k¿k¸k 3§;¡;¨r¥?°UÖ#:ÈzÐ"ZÐZ]Ð^ÐgkÔlˆØŠ?ÙØ×.Ð. 3§;¡;ˆßÜÐ3Ô4Ùô ' }À^×UaÑUaÓb€HØÒÙØ"*Ñ€HÐô 
„GÜ'Ð(9¸=ÓI€OØÒÙßÜÐ2Ô3Ùð ×0Ñ0°À-ð  xFÐ0ó  G€G÷ ÙÐ.°Ô>Ü+Ó-�J€CˆØ'€Eˆ*ÑØ%€Eˆ*ÑØ €Eˆ*ÑØ&€Eˆ)Ñß'0™°i€Eˆ+ÑÜ$ U¸5ÕAá!+ÓM¡˜A°_×5HÑ5HÈÓ5KÐ0K°Ó0K”4�1�a’4¡€KÐMß—[Ø$ˆˆgŠà�	‰	�'˜4Ô ßØ")ˆÐÑÜ˜ÔÜ˜5“k€Fˆ7�Oó 5ˆÙ˜×ÔÙ˜3 Ö#ñ 5ô 	ˆÐ,Ð0DÀ]ÀOÐ.TØÔ 1°(Ó ;Ð<Ð	=ØÇ)Ñ >ÐQZÐ[Ð	\Ø Ð0Ð	1ß6=Ð ¨˜{¨'Ñ	2ð  DGØ	öùò Ns   Ì-PÍPN)r   )r'   Ú
__future__r   Úpmr   Údataclassesr   r   r2   r   Ú#hermes_cli.model_setup_flows_commonr   r   r	   r
   r   r   r   r;   r_   rq   r…   r¤   r   r   r   Ú<module>r©      sY   ðñõ #å ß (å >ß sÕ sõOð ÷ð ó ðõõ6+õrõ*wö:yr   