Ë
    ãß²jÿ  ã                   óœ  — d Z ddlmZmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZ ddlmZmZ ddddddd	œd
eeef   deeg ef      dee   dee   dee   deeeeef   gee   f      deeg ef      defd„Zdddd ee«      ddœddddidddidddœdœd gd!d"œgid#d$œdd%dœd&œg d'œd(œZ ej4                  dd)ed*„ d+„ d,¬-«       y).z‹Connection lifecycle tool for managed gateway accounts and local MCP servers.

Disconnecting accounts remains a portal-only user decision.
é    )ÚAnyÚCallableÚDictÚOptional)Úconfig)Úrun_managed_action)Úrun_mcp_operation)ÚALL_ACTIONSÚMCP_ACTIONSÚnormalize_targetsÚvalidate_action)ÚregistryÚ
tool_errorN)Úclient_factoryÚmcp_backendÚ
session_idÚtool_call_idÚconnection_callbackÚconnectors_availableÚargsr   r   r   r   r   r   Úreturnc          
      óX  — t        | j                  d«      xs d«      j                  «       j                  «       }t	        | j                  d«      «      \  }}	}
|
rt        |
«      S t        |||	«      }|rt        |«      S |t        v rt        |	|||||¬«      S t        ||| |||||¬«      S )NÚactionÚstatusÚ
connectors)Úbackendr   r   r   )r   r   r   r   r   )
ÚstrÚgetÚstripÚlowerr   r   r   r   r	   r   )r   r   r   r   r   r   r   r   ÚmanagedÚmcp_targetsÚtarget_errorÚaction_errors               ú:/home/ubuntu/.hermes/hermes-agent/tools/connectors/tool.pyÚmanage_connectionsr&      s¹   € ô �—‘˜(Ó#Ò/ xÓ0×6Ñ6Ó8×>Ñ>Ó@€FÜ):¸4¿8¹8ÀLÓ;QÓ)RÑ&€Gˆ[˜,ÙÜ˜,Ó'Ð'Ü" 6¨7°KÓ@€LÙÜ˜,Ó'Ð'à”ÑÜ Ø˜¨Ø 3À
ÐYeô
ð 	
ô
 Ø�˜Ø%°*È<Ø/ÐFZôð ó    r&   u¼	  Connect the user to apps. Two kinds: a hosted connector account (Gmail, Notion, ...) served through the tool gateway, and a local MCP server from the bundled catalog. Targets go in 'connectors': a bare slug or {"name": "gmail"} is a hosted connector account; {"name": "linear", "mcp": true} is a local MCP server. Many names exist on both sides, so the user's own words decide. Pass "mcp": true only when the user asks for an MCP server, a local server or an install, or when the name exists only as a catalog entry; otherwise the target is hosted. 'connect' and 'reconnect' are hosted actions; 'install', 'enable' and 'authorize' are MCP actions. A target the other side owns is refused with the call that does work. Hosted actions: 'status' lists connectors and whether each is connected; 'connect' starts an authorization for the given connectors; 'reconnect' checks each one and repairs only what is not connected ('force': true restarts even a working one, for an account switch). Pass SEVERAL slugs in one call. In the desktop app, the terminal UI and the interactive CLI the call shows the user a card and blocks until every app is connected, skipped, or the deadline passes; the result lists each target as connected / skipped / not_connected and never carries a link. Where no card exists (a one-shot run, a scheduled job, a messaging platform) the result carries a connect_url per app for the USER to open in a browser (never open it yourself); ask them to say when they are done, then use 'status'. When a hosted connector tool call returns CONNECTION_REQUIRED, use 'connect'. MCP actions (every target must carry "mcp": true): 'install' adds a catalog entry, 'enable' re-enables a disabled configured server, 'authorize' runs its OAuth. They show the user an approval card and block until it settles. Never hand-edit mcp_servers config â€” always use this tool. After a skip or a timeout, do not re-ask on your own: continue without the app or ask in chat. A later request from the USER for that same app is not a re-ask â€” run it. A connected server's tools are named in the result and are callable at once through tool_describe/tool_call. Where no card exists an MCP target runs at once and the result says what happened, with a link for the user to open when one is needed. This tool can NOT disconnect, delete, or revoke an account â€” that is deliberately user-only. When asked, say so and direct the user to the Nous Portal (their org's Connectors page) or the desktop app.ÚobjectÚstringz…Defaults to status. connect and reconnect take hosted connector slugs only. install, enable and authorize take mcp:true targets only.)ÚtypeÚenumÚdescriptionÚarrayÚanyOfr*   ÚbooleanzYtrue = a local MCP server from the catalog; absent or false = a hosted connector account.)r*   r,   )ÚnameÚmcpr0   F)r*   Ú
propertiesÚrequiredÚadditionalPropertieszØTargets. REQUIRED for every action but status (e.g. ["gmail", {"name": "linear", "mcp": true}]); optional filter for status. A bare slug is a hosted connector, so an MCP server needs the object form with "mcp": true.)r*   Úitemsr,   zXreconnect only: restart the authorization even if the app is connected (account switch).)r   r   Úforce)r*   r2   r3   )r0   r,   Ú
parametersÚconnectionsc                 óX   — t        | |j                  d«      t        j                  ¬«      S )Nr   )r   r   )r&   r   Úgateway_configr   )r   Úkws     r%   ú<lambda>r<   Œ   s"   € Ô1Ø˜Ÿ™ Ó-ÄN×DgÑDgô € r'   c                  ó*   — t        j                  «       S )N)r:   r   © r'   r%   r<   r<   �   s   € ”^×8Ñ8Ó:€ r'   u   ðŸ”—)r0   ÚtoolsetÚschemaÚhandlerÚcheck_fnÚemoji)Ú__doc__Útypingr   r   r   r   Útools.connectors.gatewayr   r:   Útools.connectors.managedr   Útools.connectors.mcpr	   Útools.connectors.targetsr
   r   r   r   Útools.registryr   r   r   Úboolr&   ÚlistÚMANAGE_CONNECTIONS_SCHEMAÚregisterr>   r'   r%   ú<module>rO      s¦  ðñ÷
 1Ó 0å =Ý 7Ý 2ß aÓ aß /ð 37Ø!%Ø $Ø"&ØOSØ9=òØ
ˆs�Cˆx‰.ðð ˜X b¨# gÑ.Ñ/ðð ˜#‘ð	ð
 ˜‘ðð ˜3‘-ðð " (¨D°°c°©NÐ+;¸XÀc¹]Ð+JÑ"KÑLðð # 8¨B°¨HÑ#5Ñ6ðð 	óð@ !ð	Hð@ ð !Ù˜[Ó)ðPñ	ð  àØ Ð*à$,à)/°Ð(:à,5ð)Nñ("ñ	+ð *0¨Ø49ñððð*/ñ/ð< "ØyññM*
ðV ñ[.ñEQÐ ðh €× Ñ Ø	ØØ$ññ ;Ø
ör'   