Ë
    ãß²j  ã                  ó®   — d dl mZ d dlZd dlmZmZmZmZmZ  ej                  e
«      ZdZdZeez   Z eddh«      Zdd„Zdd	„Zdd
„Zdd„Zdd„Zdd„Zy)é    )ÚannotationsN)ÚAnyÚListÚOptionalÚSetÚTuple)ÚstatusÚconnectÚ	reconnect)ÚinstallÚenableÚ	authorizeÚnameÚmcpc                ój  — | €g g d fS t        | t        t        f«      r| g} t        | t        «      sg g dfS g }g }| D ]ñ  }t        |t        «      r�t	        t        |«      t        z
  «      }|rg g ddj                  |«      › d�fc S t        |j                  d«      xs d«      j                  «       j                  «       }t        |j                  dd«      «      }n-t        |xs d«      j                  «       j                  «       d}}|sg g d	fc S |r|n|}||vsŒá|j                  |«       Œó ||d fS )
Nz<'connectors' must be a list of names or {name, mcp} objects.zunknown target field(s) ú, z›: a target is {"name": "<slug>"} or {"name": "<server>", "mcp": true}. Transport, URLs and credentials come from the catalog manifest, never from the call.r   Ú r   Fz&every target needs a non-empty 'name'.)Ú
isinstanceÚstrÚdictÚlistÚsortedÚsetÚ_TARGET_FIELDSÚjoinÚgetÚstripÚlowerÚboolÚappend)ÚrawÚmanagedr   ÚitemÚunknownr   Úis_mcpÚbuckets           ú=/home/ubuntu/.hermes/hermes-agent/tools/connectors/targets.pyÚnormalize_targetsr(      sG  € Ø
€{Ø�2�tˆ|ÐÜ�#œœT�{Ô#ØˆeˆÜ�cœ4Ô Ø�2ÐUÐUÐUØ€GØ€CØò  ˆÜ�dœDÔ!ÜœS ›Y¬Ñ7Ó8ˆGÙØ˜2Ø.¨t¯y©y¸Ó/AÐ.Bð C`ð `ðò ô
 �t—x‘x Ó'Ò-¨2Ó.×4Ñ4Ó6×<Ñ<Ó>ˆDÜ˜$Ÿ(™( 5¨%Ó0Ó1‰Fä˜tšz r›?×0Ñ0Ó2×8Ñ8Ó:¸E�&ˆDÙØ�rÐCÐCÒCÙ‘ GˆØ�vÒØ�M‰M˜$Õð# ð$ �C˜ÐÐó    c                ó(  — | t         vr/ddj                  t         «      › ddj                  t        «      › d�S | t        v r#|rd| › ddj                  |«      › d�S |sd| › d�S y |r.d| › d	dj                  |«      › d
dj                  t        «      › d�S y )Nzaction must be one of r   z. zÉ apply to local MCP servers (targets {"name": ..., "mcp": true}); the rest apply to managed connectors. Disconnecting an account is done by the user in the Nous Portal dashboard, not through this tool.ú'zR' is an MCP action: every target must carry "mcp": true (got managed connector(s) z7). Managed connectors use connect / reconnect / status.zX' requires 'connectors': the MCP server name(s), e.g. [{"name": "linear", "mcp": true}].z.' is a managed-connector action; MCP targets (z) use ú.)ÚALL_ACTIONSr   ÚMCP_ACTIONS)Úactionr"   r   s      r'   Úvalidate_actionr0   -   sÓ   € Ø”[Ñ à$ T§Y¡Y¬{Ó%;Ð$<¸BØ�y‰yœÓ%Ð&ð '!ð!ð	
ð ”ÑÙà�F�8ð -Ø-1¯Y©Y°wÓ-?Ð,@ð A0ð0ðñ
 à�F�8ð ;ð ;ðð ñ 
à�ˆxÐEÀdÇiÁiÐPSÃnÐEUÐU[Ø�y‰yœÓ%Ð& að)ð	
ð r)   c                 óÄ   — 	 ddl m}   | «       D �ch c]  }|j                  ’Œ c}S c c}w # t        $ r*}t        j                  d|«       t        «       cY d }~S d }~ww xY w)Nr   )Úlist_catalogz,MCP catalog for the routing check failed: %s)Úhermes_cli.mcp_catalogr2   r   Ú	ExceptionÚloggerÚdebugr   )r2   ÚeÚexcs      r'   Úcatalog_namesr9   J   sJ   € ðÝ7á ,£Ö/˜1�—“Ò/Ð/ùÒ/øÜò Ü�‰ÐCÀSÔIÜ‹u�ûðús&   ‚, ‘'¤, §, ¬	AµAÁAÁAc            	     óB  — 	 ddl m}  ddlm}  |«       sy  | «       j	                  «       D �ch c];  }t        |t        «      r)t        |j                  dd«      «      j                  «       ’Œ= c}S c c}w # t        $ r }t        j                  d|«       Y d }~y d }~ww xY w)Nr   )ÚConnectorClient)Úconnectors_availableÚ	connectorr   z/connector list for the routing check failed: %s)Útools.connectors.gateway.clientr;   Útools.connectors.gateway.configr<   Úlist_connectorsr   r   r   r   r   r4   r5   r6   )r;   r<   r#   r8   s       r'   Úhosted_namesrA   T   s‹   € ð
ÝCÝHá#Ô%Øá+Ó-×=Ñ=Ó?ö[ØÄ:ÈdÔTXÔCYô �D—H‘H˜[¨"Ó-Ó.×4Ñ4Õ6ò [ð 	[ùò [øäò Ü�‰ÐFÈÔLÜûðús.   ‚A5 –A5 ­A A0Á-A5 Á0A5 Á5	BÁ>BÂBc                ó   — | › d| › d�S )Nz~ is a local MCP server, not a hosted connector account. Call manage_connections with action install and connectors [{"name": "z", "mcp": true}].© )r   s    r'   Úmisrouted_to_hosted_errorrD   b   s   € àˆ&ð à˜Ð4ð	6ðr)   c                ó   — |› d| › d|› d�S )Nz< is a hosted connector account, not a local MCP server, so 'zO' does not apply. Call manage_connections with action connect and connectors ["z"].rC   )r/   r   s     r'   Úmisrouted_to_mcp_errorrF   j   s)   € àˆ&ÐLÈVÈHð UYØY]ÐX^Ð^bð	dðr)   )r!   r   Úreturnz*Tuple[List[str], List[str], Optional[str]])r/   r   r"   ú	List[str]r   rH   rG   zOptional[str])rG   zSet[str])rG   zOptional[Set[str]])r   r   rG   r   )r/   r   r   r   rG   r   )Ú
__future__r   ÚloggingÚtypingr   r   r   r   r   Ú	getLoggerÚ__name__r5   ÚCONNECTOR_ACTIONSr.   r-   Ú	frozensetr   r(   r0   r9   rA   rD   rF   rC   r)   r'   ú<module>rP      sd   ðÝ "ã ß 2Õ 2à	ˆ×	Ñ	˜8Ó	$€à6Ð Ø0€Ø +Ñ-€á˜F E˜?Ó+€óó<ó:óóôr)   