
    `gj&                    @    d Z ddlmZ ddlmZmZ dZd	dZd
dZddZ	y)uH   ACP auth helpers — detect and advertise Hermes authentication methods.    )annotations)AnyOptionalzhermes-setupc                    	 ddl m}   |        }|j                  d      }|j                  d      }t        |t              r|j                         syt        |t              xr |j                         }t        |      xr t        |t               }|s|r|j                         j                         S 	 y# t        $ r Y yw xY w)u  Resolve the active Hermes runtime provider, or None if unavailable.

    Treats a ``Callable`` ``api_key`` (Azure Foundry Entra ID bearer
    token provider — see :mod:`agent.azure_identity_adapter`) as a valid
    credential. Without this, ACP sessions for Entra-configured Foundry
    deployments silently default to ``"openrouter"`` and the ACP auth
    handshake rejects the legitimate provider.
    r   )resolve_runtime_providerapi_keyproviderN)	hermes_cli.runtime_providerr   get
isinstancestrstripcallablelower	Exception)r   runtimer   r	   is_string_keyis_callable_providers         C/root/.hermes/venv/lib/python3.12/site-packages/acp_adapter/auth.pydetect_providerr      s    H*,++i(;;z*(C(0@"7C0DW]]_'0QGS9Q5Q0>>#))++ 1   s   AB6 A!B6 6	CCc                     t               duS )zCReturn True if Hermes can resolve any runtime provider credentials.N)r        r   has_providerr   $   s    D((r   c            	         ddl m} m} g }t               }|r!|j	                   | || dd| d             |j	                   |t
        ddd	d
g             |S )a  Return registry-compatible ACP auth methods for Hermes.

    The official ACP registry validates that agents advertise at least one
    usable auth method during the initial handshake. A fresh Zed install may
    not have Hermes provider credentials configured yet, so Hermes always
    advertises a terminal setup method. When credentials are already present,
    it also advertises the resolved provider as the default agent-managed
    runtime credential method.
    r   )AuthMethodAgentTerminalAuthMethodz runtime credentialsz3Authenticate Hermes using the currently configured z runtime credentials.)idnamedescriptionzConfigure Hermes providerz~Open Hermes' interactive model/provider setup in a terminal. Use this when Hermes has not been configured on this machine yet.terminalz--setup)r   r   r    typeargs)
acp.schemar   r   r   appendTERMINAL_SETUP_AUTH_METHOD_ID)r   r   methodsr	   s       r   build_auth_methodsr(   )   s|     ?G H z!56Ij 57			
 NN,,T 		
 Nr   N)returnzOptional[str])r)   bool)r)   z	list[Any])
__doc__
__future__r   typingr   r   r&   r   r   r(   r   r   r   <module>r.      s%    N "   !/ 2)
&r   