Ë
    âß²j­  ã                  óf   — d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	 dZ
dd„Zdd„Z G d	„ d
e«      Zy)u›  OpenAI native web search â€” declares the Responses API server-side ``web_search`` built-in.

Config: ``web.search_backend: openai-native`` (or ``web.backend``).
Auth: openai-codex OAuth (``hermes auth add openai-codex``); no API key of its own.

Unlike every other provider here, this one never executes a search itself. Selecting it
tells the Codex Responses transport to declare the provider-executed ``web_search`` tool
(``{"type": "web_search"}``) in place of the client-side ``web_search`` function, so the
model drives search server-side. The transport performs that swap; this class exists so
``web.search_backend`` has a real provider name to point at.

Auth gating lives here rather than in the transport because the transport must stay
reachable for a user who configured this backend but has not signed in yet â€” they get the
clear "sign in" error from :meth:`search` rather than a silently different backend.
é    )ÚannotationsN)ÚAnyÚDict)ÚBaseWebSearchProviderÚsearch_failzéopenai-native declares OpenAI's server-side web_search tool; it cannot run as a client-side search and requires the Codex Responses transport (provider openai-codex). For client-side search use firecrawl (default) or another backend.c                óH   — t        | t        «      r| j                  |«      S d S ©N)Ú
isinstanceÚdictÚget)ÚobjÚkeys     úG/home/ubuntu/.hermes/hermes-agent/plugins/web/openai_native/provider.pyÚ_dgetr      s   € Ü% c¬4Ô0ˆ3�7‰7�3‹<Ð:°dÐ:ó    c                 ó²  — 	 ddl m}   | «       dz  }|j                  «       syt        j                  |j                  d¬«      «      }t        t        t        |d«      d«      d	«      }t        t        |d
«      xs d«      j                  «       ryt        t        |d«      d«      }t        |t        «      xr t        d„ |D «       «      S # t        $ r Y yw xY w)ux  Cheap probe: True when openai-codex OAuth tokens are *likely* usable.

    Mirrors ``tools/xai_http.has_xai_credentials`` â€” deliberately avoids
    ``resolve_codex_runtime_credentials`` (disk locks, OAuth network refresh), because
    this runs on every ``hermes tools`` repaint. Checks, fast-to-slow:
    ``providers.openai-codex.tokens.access_token`` in ``auth.json``, then any
    ``credential_pool.openai-codex`` entry carrying an ``access_token`` (pool-only
    multi-account grants never write the providers singleton). Returns False on any
    exception so a corrupted auth store cannot block other availability scans.
    r   )Úget_hermes_homez	auth.jsonFz	utf-8-sig)ÚencodingÚ	providerszopenai-codexÚtokensÚaccess_tokenÚ TÚcredential_poolc              3  óš   K  — | ]C  }t        |t        «      xr- t        |j                  d d«      xs d«      j	                  «       –— ŒE y­w)r   r   N)r
   r   Ústrr   Ústrip)Ú.0Úes     r   ú	<genexpr>z(has_codex_credentials.<locals>.<genexpr>9   sB   è ø€ ò 1
ØUVŒJ�qœ$ÓÒP¤C¨¯©¨n¸bÓ(AÒ(GÀRÓ$H×$NÑ$NÓ$PÓPñ1
ùs   ‚A	A)Úhermes_constantsr   ÚexistsÚjsonÚloadsÚ	read_textr   r   r   r
   ÚlistÚanyÚ	Exception)r   Ú	auth_pathÚstorer   Úentriess        r   Úhas_codex_credentialsr+   #   sÌ   € ðÝ4á#Ó%¨Ñ3ˆ	Ø×ÑÔ!ØÜ—
‘
˜9×.Ñ.¸Ð.ÓDÓEˆÜ”uœU 5¨+Ó6¸ÓGÈÓRˆÜŒu�V˜^Ó,Ò2°Ó3×9Ñ9Ô;ØÜœ˜eÐ%6Ó7¸ÓHˆÜ˜'¤4Ó(ò 
¬Sñ 1
ØZaô1
ó .
ð 	
øô ò Ùðús   ‚ C
 £A,C
 Â9C
 Ã
	CÃCc                  ó2   — e Zd ZdZdZdZdd„Zd	d
d„Zdd„Zy)ÚOpenAINativeWebSearchProviderz™Marker provider: the Codex Responses transport swaps the client ``web_search``
    function for the server-executed built-in when this backend is active.zopenai-nativez*OpenAI Native Web Search (Codex Responses)c                ó   — t        «       S r	   )r+   )Úselfs    r   Úis_availablez*OpenAINativeWebSearchProvider.is_availableG   s   € Ü$Ó&Ð&r   c                ó    — t        t        «      S )uó   Never called on a successful native turn â€” the transport replaces the tool
        before the request goes out. Reached only when the active transport cannot host
        the built-in, so fail loudly instead of returning an empty result set.)r   Ú_UNSUPPORTED_MSG)r/   ÚqueryÚlimits      r   Úsearchz$OpenAINativeWebSearchProvider.searchJ   s   € ô Ô+Ó,Ð,r   c                ó8   — ddl m}  || j                  ddd«      S )Nr   )Úsetup_schemaÚnativez’Search runs on the provider side (needs the Codex Responses transport + an openai-codex login); search only, extraction still uses another backendr   )Úplugins.web._commonr7   ÚDISPLAY_NAME)r/   r7   s     r   Úget_setup_schemaz.OpenAINativeWebSearchProvider.get_setup_schemaP   s'   € Ý4áØ×ÑØð aØó	
ð 	
r   N©ÚreturnÚbool)é   )r3   r   r4   Úintr=   úDict[str, Any])r=   rA   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚNAMEr:   r0   r5   r;   © r   r   r-   r-   @   s#   „ ñNð €DØ?€Ló'ô-ô
r   r-   )r   r   r   r   r=   r   r<   )rE   Ú
__future__r   r"   Útypingr   r   r9   r   r   r2   r   r+   r-   rG   r   r   ú<module>rJ      s:   ðñõ  #ã ß ç BðXð ó;óô:
Ð$9õ 
r   