Ë
    ãß²jÒ
  ã                   óä   — U d Z ddlZddlmZmZ ddlmZ ddlmZ da	eee
e
egdf      ed<   deee
e
egdf      ddfd	„Zdefd
„Zde
dedefd„Zde
dedefd„Zde
dede
de
dede
fd„Zde
fd„Zy)a>  Bridge desktop-only tools to Hermes-desktop renderer events.

The desktop ``tui_gateway`` installs an emitter via :func:`set_emitter`; elsewhere it
stays ``None`` and tools report "desktop only". Routing keys off ``HERMES_UI_SESSION_ID``
so the event lands on the window that owns the turn (the sink is lock-guarded).
é    N)ÚCallableÚOptional)Úget_session_env)Ú
tool_errorÚ_emitÚfnÚreturnc                 ó   — | a y)zJInstall (or clear) the renderer-event sink. Called by the desktop gateway.N©r   )r   s    ú5/home/ubuntu/.hermes/hermes-agent/tools/desktop_ui.pyÚset_emitterr      s	   € ð �Eó    c                  ó   — t         duS )z>True when running under the desktop app (an emitter is wired).Nr   © r   r   Ú	availabler      s   € ä˜ÐÐr   ÚsettingÚdefaultc                 ó¾   — 	 ddl m}  |«       j                  d«      }t	        |t
        «      r| |vr|S t        |j                  | «      «      S # t        $ r |cY S w xY w)a{  Read a desktop Appearance switch from ``display.<setting>``. The renderer mirrors
    these toggles onto the CONNECTED gateway's config, so this is the user's real answer
    for local/SSH/URL/cloud gateways alike; ``check_fn``s use it to withdraw a tool from
    the schema. Unreadable config -> ``default`` so a shipped-on feature does not vanish
    on a transient read error.r   )Úload_config_readonlyÚdisplay)Úhermes_cli.configr   ÚgetÚ	ExceptionÚ
isinstanceÚdictÚbool)r   r   r   r   s       r   Úuser_enabledr      s_   € ðÝ:Ù&Ó(×,Ñ,¨YÓ7ˆô �gœtÔ$¨°wÑ(>ØˆÜ�—‘˜GÓ$Ó%Ð%øô	 ò ØŠðús   ‚A ÁAÁAÚeventÚpayloadc                 ó@   — t         €yt        t        dd«      | |«       y)zMRoute ``event`` to the window owning the current turn; False when no emitter.FÚHERMES_UI_SESSION_IDÚ T)r   r   )r   r   s     r   Úemitr#   .   s!   € ä€}ØÜ	Œ/Ð0°"Ó
5°u¸gÔFØr   Úfail_prefixÚdesktop_onlyÚresultc                 ó®   — 	 t        | |«      }|rt        j                  |d¬«      S t        |«      S # t        $ r}t        |› |› �«      cY d}~S d}~ww xY w)zÒEmit ``event``; ``tool_error`` text on failure (``fail_prefix`` + exception, or
    ``desktop_only`` when no emitter), else ``result`` as JSON. Calls ``emit`` via the
    module attribute so tests can patch it.NF©Úensure_ascii)r#   r   r   ÚjsonÚdumps)r   r   r$   r%   r&   ÚokÚexcs          r   Úemit_or_errorr.   6   sX   € ð1Ü�%˜Ó!ˆñ 68Œ4�:‰:�f¨5Ô1ÐU¼ZÈÓ=UÐUøô ò 1Ü˜[˜M¨#¨Ð/Ó0Õ0ûð1ús   ‚2 ²	A»AÁ	AÁAc                 óÆ   — 	 t        j                  t        j                  | «      d¬«      S # t        t        f$ r% t        j                  dt        | «      id¬«      cY S w xY w)zLDesktop answers with a JSON object; pass it through, else wrap the raw text.Fr(   Útext)r*   r+   ÚloadsÚ	TypeErrorÚ
ValueErrorÚstr)Úraws    r   Úpassthrough_jsonr6   A   sQ   € ðBÜ�z‰zœ$Ÿ*™* S›/¸Ô>Ð>øÜ”zÐ"ò BÜ�z‰z˜6¤3 s£8Ð,¸5ÔAÒAðBús   ‚), ¬1A ÁA )Ú__doc__r*   Útypingr   r   Úgateway.session_contextr   Útools.registryr   r   r4   r   Ú__annotations__r   r   r   r   r#   r.   r6   r   r   r   ú<module>r<      sé   ðòó ß %å 3Ý %ð 59€€x�˜#˜s DÐ)¨4Ð/Ñ0Ñ1Ó 8ð�H˜X s¨C°Ð&6¸Ð&<Ñ=Ñ>ð À4ó ð�4ó ð
&˜#ð &¨ð &°ó &ð �ð ˜dð  tó ðV˜ð V tð V¸#ð VÈSð VÐZ^ð VÐcfó VðB˜Sô Br   