Ë
    uPêjg  ã            	       óö  — U d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZmZ erddlmZ dd	lmZ  e
e«      j,                  d
z  Zeed<   h d£Zeed<   d%d„Zdeeef   dz  fd„Zdeeef   ddfd„Z G d„ de«      Z edd¬«       G d„ d«      «       Z dddddedz  fd„Z!ddddde"e   dedz  fd„Z#de fd „Z$ee$fd!e
d"eg e f   de%fd#„Z&e'd$k(  r ejP                   e&«       «       yy)&ak  
Per-feature OpenAPI snapshot for lazy-loaded routers.

The committed JSON is generated by `python -m litellm.proxy._lazy_openapi_snapshot`
and consumed at runtime so /openapi.json can show full route info for unloaded
features without importing them. check-ui-api-types.yml (mirrored locally by
`make check`) regenerates this file and fails when the committed copy differs,
then rebuilds schema.d.ts from app.openapi() with the snapshot injected. After
changing any lazily loaded route or this generator, rerun the module and commit
the JSON, then run `npm run gen:api` in ui/litellm-dashboard and commit schema.d.ts.
é    N)ÚCallableÚMapping)Ú	dataclass)ÚPath)ÚTYPE_CHECKINGÚFinal)ÚReadOnlyÚ	TypedDict)ÚFastAPI)ÚLazyFeaturez_lazy_openapi_snapshot.jsonÚSNAPSHOT_FILE>   ÚgetÚputÚheadÚpostÚpatchÚtraceÚdeleteÚoptionsÚHTTP_METHOD_SUFFIXESÚreturnc                 ó  — | D ]†  }t        t        |dd«      xs g «      }t        |«      dk  st        |dd«      sŒ9|j                  › |j                  › �}t        j                  dd|«      }|› d|d   j                  «       › �|_        Œˆ y)zGFastAPI derives route IDs from a set of methods; make snapshots stable.ÚmethodsNé   Úpath_formatz\WÚ_r   )	ÚsortedÚgetattrÚlenÚnamer   ÚreÚsubÚlowerÚ	unique_id)ÚroutesÚrouter   Úoperation_ids       úi/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/_lazy_openapi_snapshot.pyÚ!_stabilize_multi_method_route_idsr)   )   s’   € ð ò AˆÜœ ¨	°4Ó8Ò>¸BÓ?ˆÜˆw‹<˜1Ò¤G¨E°=À$Ô$GØàŸ*™*˜ e×&7Ñ&7Ð%8Ð9ˆÜ—v‘v˜e S¨,Ó7ˆØ)˜N¨!¨G°A©J×,<Ñ,<Ó,>Ð+?Ð@ˆ�ñAó    c                  óê   — t         j                  «       sy 	 t         j                  «       5 } t        j                  | «      cd d d «       S # 1 sw Y   y xY w# t        j
                  t        f$ r Y y w xY w©N)r   ÚexistsÚopenÚjsonÚloadÚJSONDecodeErrorÚOSError)Úfs    r(   Úload_snapshotr4   6   s`   € Ü×ÑÔ!ØðÜ×ÑÓ!ð 	  QÜ—9‘9˜Q“<÷	 ÷ 	 ò 	 ûä× Ñ ¤'Ð*ò Ùðús.   —A «A
Á 	A Á
AÁA ÁA ÁA2Á1A2Úpathsc                 ó¤  — | j                  «       D ]¸  }t        |t        «      sŒ|D �ch c]  }|t        v sŒ|’Œ }}|sŒ/|j	                  «       D ]w  \  }}|t        vst        |t        «      sŒ|j                  d«      }t        |t        «      sŒA|D ]2  }d|› �}|j                  |«      sŒ|dt        |«        d|› �z   |d<    Œw Œy Œº yc c}w )a\  Make FastAPI-generated operation IDs stable for multi-method routes.

    FastAPI derives the default operation ID suffix from the first item in the
    route's methods set. For routes registered with several HTTP methods, that
    set iteration order can vary between processes, which makes the snapshot
    drift even when no routes changed.
    ÚoperationIdr   N)	ÚvaluesÚ
isinstanceÚdictr   Úitemsr   ÚstrÚendswithr   )r5   Úpath_opsÚmethodr   Ú	operationr'   ÚsuffixÚsuffix_tokens           r(   Ú_normalize_operation_idsrC   @   sì   € ð —L‘L“Nò ˆÜ˜(¤DÔ)Øà(0ÖS˜f°FÔ>RÒ4R’6ÐSˆÐSÙØà!)§¡Ó!1ò 	ÑˆF�IØÔ1Ñ1¼ÀIÌtÔ9TØà$Ÿ=™=¨Ó7ˆLÜ˜l¬CÔ0Øà!ò �Ø!" 6 (˜|�Ø×(Ñ(¨Õ6Ø/;Ð<P¼sÀ<Ó?PÐ>PÐ/QÐVWÐX^ÐW_ÐT`Ñ/`�I˜mÑ,Ùñ	ñ	ñùò Ts
   ©C·Cc                   óV   — e Zd ZU eeeeeef   f      ed<   eeeeeef   f      ed<   y)ÚSnapshotFragmentr5   Ú
componentsN)Ú__name__Ú
__module__Ú__qualname__r	   r   r<   ÚobjectÚ__annotations__© r*   r(   rE   rE   _   s>   … Ø�G˜C ¨¨f¨Ñ!5Ð5Ñ6Ñ7Ó7Ø˜  g¨c°6¨kÑ&:Ð!:Ñ;Ñ<Ô<r*   rE   T)ÚfrozenÚslotsc                   ó6   — e Zd ZU eeef   ed<   eedf   ed<   y)ÚSnapshotResultÚ	fragments.ÚskippedN)rG   rH   rI   r   r<   rE   rK   ÚtuplerL   r*   r(   rP   rP   d   s!   … à�sÐ,Ð,Ñ-Ó-Ø�3˜�8‰_Ôr*   rP   Úappr   Úfeatr   c                 ó  — dd l }	 |j                  | |j                  |j                  «      «       y # t        $ rF}t
        j                  j                  d|j                  › d|› d�«       |j                  cY d }~S d }~ww xY w)Nr   zwarning: skip z: ú
)	Ú	importlibÚregister_fnÚimport_moduleÚmodule_pathÚ	ExceptionÚsysÚstderrÚwriter    )rT   rU   rX   Úexcs       r(   Ú_register_featurera   j   sq   € ÛðØ×Ñ˜˜i×5Ñ5°d×6FÑ6FÓGÔHð øô ò Ü�
‰
×Ñ˜>¨$¯)©)¨°B°s°e¸2Ð>Ô?Ø�y‰yÕûðús   †+2 ²	B»;A<Á6BÁ<BÚused_operation_idsc           
      óÎ  — ddl m} ddlm} | j                  D �cg c]!  }|j                  t        |dd«      «      sŒ |‘Œ# }}|sy t        |«        || j                  | j                  |¬«      }|j                  di «      }t        |«       |j                  «       D ]’  }	|	j                  «       D ]}  \  }
}t        |t        «      sŒ|j                  d«      }t        |t         «      r6t"        D ]-  }|j%                  d	|› �«      sŒ|d t'        |«        |
z   |d<    n |j(                  g|d
<   Œ Œ”  |||«      }|d|j                  di «      j                  di «      idœS c c}w )Nr   )Úget_openapi)Ú#ensure_unique_openapi_operation_idsÚpathÚ )ÚtitleÚversionr%   r5   r7   r   ÚtagsÚschemasrF   )r5   rF   )Úfastapi.openapi.utilsrd   Úlitellm.proxy.proxy_serverre   r%   Úmatchesr   r)   rh   ri   r   rC   r8   r;   r9   r:   r<   r   r=   r   r    )rT   rU   rb   rd   re   ÚrÚfeat_routesÚfullr5   r>   r?   Úopr'   rA   Úuniques                  r(   Ú_feature_fragmentrt   u   sV  € Ý1åNà%(§Z¡ZÖX °4·<±<ÄÈÈ6ÐSUÓ@VÕ3Wš!ÐX€KÐXÙØÜ% kÔ2Ù C§I¡I°s·{±{È;ÔW€DØ—8‘8˜G RÓ(€EÜ˜UÔ#Ø—L‘L“Nò 	)ˆØ"Ÿ.™.Ó*ò 	)‰JˆF�BÜ˜"œdÕ#Ø!Ÿv™v mÓ4�Ü˜l¬CÔ0Ü"6ò "˜Ø'×0Ñ0°1°V°H°Õ>Ø0<¸^ÄÀFÃ¸|Ð0LÈvÑ0U˜B˜}Ñ-Ù!ð"ð #Ÿi™i˜[��6’
ñ	)ð	)ñ 8¸Ð>PÓQ€FàØ  &§*¡*¨\¸2Ó">×"BÑ"BÀ9ÈbÓ"QÐRñð ùò% Ys
   ›!E"½E"c                  óÒ   ‡‡— ddl m}  ddlmŠ t	        ˆˆfd„| D «       «      }t        «       }| D �ci c]  }t        ‰||«      x}�|j                  |“Œ  }}t        ||¬«      S c c}w )Nr   )ÚLAZY_FEATURES)rT   c              3   ó@   •K  — | ]  }t        ‰|«      xŠ€Œ‰–— Œ y ­wr,   )ra   )Ú.0rU   rT   r    s     €€r(   ú	<genexpr>z$generate_snapshot.<locals>.<genexpr>–   s%   øè ø€ Òp DÔFWÐX[Ð]aÓFbÐ>b¸dÑ=oœ4Ñpùs   ƒ—)rQ   rR   )	Úlitellm.proxy._lazy_featuresrv   rm   rT   rS   Úsetrt   r    rP   )rv   rR   rb   rU   ÚfragmentrQ   rT   r    s         @@r(   Úgenerate_snapshotr}   ’   sr   ù€ Ý:Ý.äÔp¨MÔpÓp€GÜ*-«%Ðð "öàÜ)¨#¨tÐ5GÓHÐHˆHÐUð 	�	‰	�8Ñð€Ið ô
  I°wÔ?Ð?ùòs   ²#A$Úsnapshot_fileÚgeneratec                 óª  —  |«       }|j                   rSt        j                  j                  dt	        |j                   «      › ddj                  |j                   «      › d�«       y| j                  t        j                  |j                  dd¬«      dz   «       t        j                  j                  d	t	        |j                  «      › d
| › d�«       y)Nzerror: zQ feature(s) failed to import, so their fragments would vanish from the snapshot: z, rW   r   é   T)ÚindentÚ	sort_keyszwrote z feature fragments to r   )rR   r]   r^   r_   r   ÚjoinÚ
write_textr/   ÚdumpsrQ   Ústdout)r~   r   Úresults      r(   Úmainr‰       s°   € Ù“J€FØ‡~‚~Ü�
‰
×ÑØ”c˜&Ÿ.™.Ó)Ð*ð +ØŸ™ 6§>¡>Ó2Ð3°2ð7ô	
ð Ø×ÑœTŸZ™Z¨×(8Ñ(8ÀÈdÔSÐVZÑZÔ[Ü‡J�J×Ñ�vœc &×"2Ñ"2Ó3Ð4Ð4JÈ=È/ÐY[Ð\Ô]Ør*   Ú__main__)r   N))Ú__doc__r/   r!   r]   Úcollections.abcr   r   Údataclassesr   Úpathlibr   Útypingr   r   Útyping_extensionsr	   r
   Úfastapir   rz   r   Ú__file__Úparentr   rK   r   r)   r:   r<   r4   rC   rE   rP   ra   r{   rt   r}   Úintr‰   rG   ÚexitrL   r*   r(   ú<module>r–      sa  ðò
ó Û 	Û 
ß -Ý !Ý ß 'ç 1áÝå8á˜H“~×,Ñ,Ð/LÑL€ˆuÓ Lò	Ð �eó 	ó
Að�t˜C ˜I‘¨Ñ-ó ð D¨¨d¨¡Oð ¸ó ô>=�yô =ñ
 �$˜dÔ#÷ð ó $ðð
˜9ð ¨Mð ¸cÀD¹jó ð˜9ð ¨Mð ÈsÐSVÉxð Ð\lÐosÑ\só ð:@˜>ó @ð  -ÐWhñ 
˜ð 
¸ÀÀ^ÐASÑ8Tð 
Ðmpó 
ð ˆzÒØ€C‡H�H‰T‹VÕð r*   