+
    iHàjº  ã                  ó’   € R t ^ RIHt ^ RIt^ RIt^ RIHtHt ^ RIH	t	 Rt
R R ltR]
/R	 R
 lltR R ltRR/R R lltR R ltR# )a  Codex request identity helpers shared by agent client builders.

Leaf module with no dependency on the large auxiliary-client router, so a
long-lived process can import a newly added client builder without resolving a
new symbol from an older cached ``auxiliary_client`` module.
)ÚannotationsN)ÚAnyÚDict)Úurlparsez%https://chatgpt.com/backend-api/codexc               ó    € V ^8„  d   QhRRRR/# )é   Úbase_urlÚstrÚreturnÚbool© )Úformats   "Ú8/home/ubuntu/.hermes/hermes-agent/agent/codex_headers.pyÚ__annotate__r      s   € ÷ ñ ¨ð °ñ ó    c                óF  €  \        V 4      pVP                  P                  R4      pVP                  R8H  ;'       dM    VP                  R8H  ;'       d6    VP
                  R9   ;'       d    VR8H  ;'       g    VP                  R4      #   \        \        3 d     R# i ; i)zAIdentify OpenAI's Codex endpoint without matching custom proxies.Ú/Úhttpszchatgpt.comz/backend-api/codexz/backend-api/codex/F)Ni»  )	r   ÚpathÚrstripÚschemeÚhostnameÚportÚ
startswithÚ	TypeErrorÚ
ValueError)r   Úparsedr   s   &  r   Úis_official_codex_base_urlr      s¨   € ð
Ü˜(Ó#ˆØ�{‰{×!Ñ! #Ó&ˆà�M‰M˜WÑ$÷ Yð YØ—‘ =Ñ0÷Yð Yà—‘˜{Ñ*÷Yð Yð Ð-Ñ-×WÐW°·±ÐAVÓ1Wð		
øô ”zÐ"ô Úðús(   ‚;B ¾B ÁB Á,B Á9B ÂB ÂB r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úaccess_tokenr	   r   r
   údict[str, str]r   )r   s   "r   r   r   "   s"   € ÷ ñ ¨3ð ¸Sð ÐZhñ r   c               ó¦   € \        V4      '       d    ^ RIHp RRV! 4       P                   2RR/pMRRRR/pVP	                  \        V 4      4       V# )aJ  Identity and account headers for chatgpt.com/backend-api/codex.

OpenAI requires third-party harnesses to identify themselves: the official
endpoint gets Hermes' originator and version, custom endpoints keep the
codex_cli_rs compatibility identity. The account headers come from the
OAuth JWT (see :func:`codex_account_headers`).
)Úget_version_infoz
User-AgentzHermesAgent/Ú
originatorzhermes-agentz!codex_cli_rs/0.0.0 (Hermes Agent)Úcodex_cli_rs)r   Úhermes_cli.version_infor"   Úbase_versionÚupdateÚcodex_account_headers)r   r   r"   Úheaderss   &$  r   Úcodex_cloudflare_headersr*   "   s^   € ô " (×+Ò+Ý<à˜LÑ)9Ó);×)HÑ)HÐ(IÐJØ˜.ð
‰ð
  Ð!DÀlÐTbÐcˆØ‡N�NÔ(¨Ó6Ô7Ø€Nr   c               ó    € V ^8„  d   QhRRRR/# )r   r   r	   r
   r    r   )r   s   "r   r   r   6   s   € ÷ ñ ¨ð °ñ r   c                óÜ  € / p\        V \        4      '       d   V P                  4       '       g   V#  V P                  R4      p\	        V4      ^8  d   V# V^,          R\	        V^,          4      ) ^,          ,          ,           p\
        P                  ! \        P                  ! V4      4      P                  R/ 4      pVP                  R4      p\        V\        4      '       d   V'       d   WQR&   VP                  R4      ;'       g    VP                  R4      p\        V\        4      '       d*   VP                  4       '       d   VP                  4       VR&   V#   \         d     T# i ; i)	uú  Workspace headers the Codex backend derives from the OAuth JWT.

``ChatGPT-Account-ID`` (canonical casing, from codex-rs ``auth.rs``) comes from
``chatgpt_account_id``; ``x-openai-internal-codex-residency`` from
``chatgpt_data_residency`` (fallback ``chatgpt_compute_residency``) â€” without
it residency-enforced workspaces answer 401 "Workspace is not authorized in
this region". A malformed token drops the headers rather than raising, so it
surfaces as a 401 instead of a crash at client construction.
Ú.Ú=zhttps://api.openai.com/authÚchatgpt_account_idzChatGPT-Account-IDÚchatgpt_data_residencyÚchatgpt_compute_residencyz!x-openai-internal-codex-residency)Ú
isinstancer	   ÚstripÚsplitÚlenÚjsonÚloadsÚbase64Úurlsafe_b64decodeÚgetÚ	Exception)r   r)   ÚpartsÚpayload_b64ÚauthÚacct_idÚ	residencys   &      r   r(   r(   6   s+  € ð !€GÜ�l¤C×(Ò(°×0BÑ0B×0DÒ0DØˆðØ×"Ñ" 3Ó'ˆÜˆu‹:˜Œ>ØˆNØ˜A•h ¬¨U°1­X«¨¸Õ(:Õ!;Õ;ˆÜ�zŠzœ&×2Ò2°;Ó?Ó@×DÑDÐEbÐdfÓgˆØ—(‘(Ð/Ó0ˆÜ�gœs×#Ò#¯Ø,3Ð(Ñ)Ø—H‘HÐ5Ó6×_Ð_¸$¿(¹(ÐC^Ó:_ˆ	Ü�i¤×%Ò%¨)¯/©/×*;Ò*;Ø;D¿?¹?Ó;LˆGÐ7Ñ8ð €Nøô ô ØØ€Nðús*   ²"E ÁBE Ã-E Ä	=E ÅE ÅE+Å*E+Ú
async_modeFc               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r	   rA   r   r
   zdict[str, list] | Noner   )r   s   "r   r   r   T   s"   € ÷ )ñ )¨cð )À$ð )ÐSiñ )r   c               ó²   aaa€ \        V 4      '       g   R#  ^ RIHo ^ RIoR TT3R lloT'       g   RS./# R T3R llpRT./#   \         d     R# i ; i)a†  httpx ``event_hooks`` that zstd-compress Responses request bodies for the official Codex backend.

Parity with the official Codex client (zstd on ``/responses`` with ChatGPT auth, default since
openai/codex#10102). Lossless transport encoding: tokens and prompt caching are unchanged. Uses the
stdlib codec (Python 3.14+); without it, or for any other endpoint/proxy, bodies stay raw JSON.
N)Úzstdc               ó    € V ^8„  d   QhRRRR/# ©r   Úrequestzhttpx.Requestr
   ÚNoner   )r   s   "r   r   Ú5codex_request_compression_hooks.<locals>.__annotate__c   s   € ÷ ;ñ ;˜-ð ;¨Dñ ;r   c                ó|  <€ V P                   R 8w  g=   V P                  P                  P                  R4      '       d   RV P                  9   d   R# SP                  V P                  4       4      pSP                  V4      V n        Wn	        RV P                  R&   \        \        V4      4      V P                  R&   R# )ÚPOSTz
/responseszcontent-encodingNrD   zContent-EncodingzContent-Length)ÚmethodÚurlr   Úendswithr)   ÚcompressÚreadÚ
ByteStreamÚstreamÚ_contentr	   r5   )rG   ÚbodyÚhttpxrD   s   & €€r   rO   Ú1codex_request_compression_hooks.<locals>.compressc   sŠ   ø€ Ø�N‰N˜fÔ$¨G¯K©K×,<Ñ,<×,EÑ,EÀl×,SÒ,SØ%¨¯©Ô8ÙØ�}‰}˜WŸ\™\›^Ó,ˆØ×)Ñ)¨$Ó/ˆŒØÔØ.4ˆ�‰Ð*Ñ+Ü,/´°D³	«Nˆ�‰Ð(Ó)r   rG   c               ó    € V ^8„  d   QhRRRR/# rF   r   )r   s   "r   r   rI   p   s   € ÷ ñ  mð ¸ñ r   c              “  ó    <"  € S! V 4       R # 5i)Nr   )rG   rO   s   &€r   Úcompress_asyncÚ7codex_request_compression_hooks.<locals>.compress_asyncp   s   øé € Ù�Öùs   ƒ)r   ÚcompressionrD   rU   ÚImportError)r   rA   rY   rO   rU   rD   s   &$ @@@r   Úcodex_request_compression_hooksr]   T   sh   ú€ ô & h×/Ò/ÙðÝ$Û÷;ñ ;÷ Ø˜H˜:Ð&Ð&÷ð ð ˜Ð'Ð(Ð(øô' ô Úðús   ˜
A ÁAÁAc               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úclient_kwargszdict[str, Any]r   r	   r   r
   rH   r   )r   s   "r   r   r   v   s+   € ÷ 
ñ 
°ð 
ÐQTð 
Ð`cð 
Ðhlñ 
r   c               ób  € \        V4      '       g   R# \        WR7      pV Uu0 uF  qDP                  4       kK  	  ppV P                  R4      ;'       g    / p/ VP	                  4        UUu/ uF'  w  rG\        V4      P                  4       V9  g   K%  WGbK)  	  uppCVCV R&   R# u upi u uppi )zBKeep required Codex identity after user/provider header overrides.N)r   Údefault_headers)r   r*   Úlowerr:   Úitemsr	   )r_   r   r   ÚrequiredÚnameÚrequired_namesÚexistingÚvalues   &$$     r   Úapply_required_codex_headersri   v   s¤   € ä% h×/Ò/ÙÜ'¨ÔH€HÙ/7Ó8©x t—j‘j–l©x€NÐ8Ø× Ñ Ð!2Ó3×9Ð9°r€Hð(Ø*2¯.©.Ô*:Ô
fÑ*:™;˜4¼cÀ$»i¿o¹oÓ>OÐWeÑ>eŒ;ˆ4Š;Ñ*:Ò
fð(à
ð(€MÐ#Ó$ùò 9ùó gs   ¤B&Á-"B+ÂB+)Ú__doc__Ú
__future__r   r8   r6   Útypingr   r   Úurllib.parser   ÚCODEX_AUX_BASE_URLr   r*   r(   r]   ri   r   r   r   Ú<module>ro      sL   ðñõ #ã Û ß Ý !ð =Ð õðÐCU÷ õ(ð<)È÷ )÷D
r   