Team Ai
Apppublic

Yash030/claude-code-proxy

sourceHugging Faceupdated 5mo agoView on Hugging Face
2likes
runtime.cpython-314.pyc98 linesDownload Raw Back to __pycache__
1+
2��j�<��@�Rt^RIHt^RIt^RIt^RIHtHt^RIH	t	H3t4^RIHt^RI
Ht^RIHtHt^RIHt^R	IHt]	'd^R5IHt^RIHt^RIHt^R
IHtRt]3RR/RRllltRRlt RRlt!RRlt"RRlt#]!RR7!RR44t$R#)z8Application runtime composition and lifecycle ownership.)�annotationsN)�	dataclass�field)�
TYPE_CHECKING�Any)�FastAPI)�logger)�Settings�get_settings)�ServiceUnavailableError)�ProviderRegistry��CLISessionManager��ClaudeMessageHandler)�MessagingPlatform��SessionStore�@�log_verbose_errorsFc6�,�V^8�dQhRRRRRRRRR	R7/#)��name�str�	awaitabler�	timeout_s�floatr�bool�return�None�)�formats"�6C:\Users\yashw\.claude\claude-code-free\api\runtime.py�__annotate__r#s:����8
������9��10�
�c��"�\P!WR7GRjx�L11R#L \d\P!RY4R#\12dqpT'd3\P!RT\
T4PT4Rp?R#\P!RT\
T4P4Rp?R#Rp?ii;i5i)z9Run a shutdown step with timeout; never raise to callers.��timeoutNz!Shutdown step timed out: {} ({}s)z Shutdown step failed: {}: {}: {}z%Shutdown step failed: {}: exc_type={})�asyncio�wait_for�TimeoutErrorr�warning�	Exception�type�__name__)rrrr�es&&&$ r"�best_effortr0s��������y�<�<�<���M����:�D�L��
���N�N�2���Q�� � ��	
�
�
�N�N�7���Q�� � �
�
��
�sU�C	�'�%�'�C	�'�"C�	C	�C�C�4C�13C	�+C�;C	�C�C	c� �V^8�dQhRRRR/#)r�settingsr	rrr )r!s"r"r#r#6s��14�15��16�d�17r$c�b�VP4'd\P!R4R#R#)z>Warn when server auth was implicitly inherited from the shell.z�ANTHROPIC_AUTH_TOKEN is set in the process environment but not in a configured .env file. The proxy will require that token. Add ANTHROPIC_AUTH_TOKEN= to .env to disable proxy auth, or set the same token in .env to make server auth explicit.N)�!uses_process_anthropic_auth_tokenrr+)r2s&r"�warn_if_process_auth_tokenr56s'���1�1�3�3����
?�	18�4r$c�$�V^8�dQhRRRRRR/#)rr2r	�excr,rrr )r!s"r"r#r#As!��1�1�(�1��1�t�1r$c�J�\W4p\P!RV4R#)zTLog startup failures without traceback noise unless verbose diagnostics are enabled.zStartup failed:19{}N)�startup_failure_messager�error)r2r7�messages&& r"�log_startup_failurer<As��%�h�4�G�20�L�L�&��0r$c�$�V^8�dQhRRRRRR/#)rr2r	r7r,rrr )r!s"r"r#r#Gs&��C�C�h�C�Y�C�3�Cr$c���\V\4'd%VPP4;'gR#VP'd\V4PRV2#R\V4P2#)zLReturn a concise startup failure message for logs and ASGI lifespan failure.zServer startup failed.z: z Server startup failed: exc_type=)�21isinstancerr;�strip�log_api_error_tracebacksr-r.)r2r7s&&r"r9r9Gsl���#�.�/�/��{�{� � �"�>�>�&>�>��(�(�(��s�)�$�$�%�R��u�-�-�
-�d�3�i�.@�.@�-A�B�Br$c� �V^8�dQhRRRR/#)rr7r,rrr )r!s"r"r#r#Rs��/�/��/�t�/r$c��\V\4'gR#VP;'g\V4P	4pRV9#)azReturn whether a model-validation failure should be downgraded to a warning.22 23Provider discovery can fail transiently or due to local environment issues24(for example, a missing runtime dependency in the provider's process path).25We keep startup alive in those cases so the configured proxy can still serve26requests and advertise the models that are already known from settings.27Fzproblem=query failure:)r?rr;r�lower)r7r;s& r"�/_should_continue_after_model_validation_failurerERs>���c�2�3�3���{�{�&�&�c�#�h�-�-�/�G�#�w�.�.r$T)�slotsc���]tRt^at$RtR]R&R]R&]!RRR7tR	]R28&RtR]R&Rt	R
]R&Rt29R]R&]R&RRll4tRRlt
RRltRRltRRltRRltRRltRR ltR!R"ltR#R$ltR%tR#)'�30AppRuntimezEOwn optional messaging, CLI, session, and provider runtime resources.r�appr	r2NF)�default�initzProviderRegistry | None�_provider_registryzMessagingPlatform | None�messaging_platformzClaudeMessageHandler | None�message_handlerzCLISessionManager | None�cli_managerc�$�V^8�dQhRRRRRR/#)rrIrr2zSettings | NonerrHr )r!s"r"r#�AppRuntime.__annotate__ms-��A�A�
�A�"�A�31�	Ar$c	�8�T!Y;'g\4R7#)�rIr2)r32)�clsrIr2s&&&r"�for_app�AppRuntime.for_appls���s�%?�%?���@�@r$c��V^8�dQhRR/#�rrrr )r!s"r"r#rQts����t�r$c�	�"�\P!R4\4VnVPVPP33n\VP4\P!VPPVP4RR7GRjx�L34VPP#VP4VP%4GRjx�L35VP'4GRjx�L36VP)4R#Lk \dHp\P!R\T4;'g\T4P 4Rp?L�Rp?ii;iL�Lo \d`p\+TPT4\-RTPP/4TPP0R7GRjx�L37hRp?ii;i5i)zStarting Claude Code Proxy...g.@r&NzRStartup model validation skipped or timed out: continuing in lazy mode. Reason: {}�provider_registry.cleanup�r)r�inforrLrI�state�provider_registryr5r2r(r)�validate_configured_modelsr,r+rr-r.�start_model_list_refresh�_warmup_providers�_start_messaging_if_configured�_publish_stater<r0�cleanuprA)�selfr7s& r"�startup�AppRuntime.startuptsj������3�4�"2�"4���+/�+B�+B������(�	�&�t�}�}�5�
��&�&��+�+�F�F�t�}�}�U� ����
�#�#�<�<�T�]�]�K��(�(�*�*�*��5�5�7�7�7����!����
����!���H�2�2��S�	� 2� 2����
��
+�7���	���
�
�s�3��+��'�'�/�/�1�#'�=�=�#I�#I��
�
�38
��	�s��AG�E)�$>D�"D�#D�'8E)�E%� E)�7E'�8E)�G�D�E"�=E�E)�E"�"E)�'E)�)G�4AG�G39�G�G�Gc��V^8�dQhRR/#rXr )r!s"r"r#rQ�s��"0�"0��"0r$c�	�"�VPPpVPe&VPPP	4\P!R4VP'd/\RVPP4VR7GRjx�L40VP'd/\RVPP4VR7GRjx�L41VP e/\RVP P#4VR7GRjx�L42VP%4GRjx�L43\P!R4R# \44d[pT'd\P!RT4Rp?EL2\P!R\T4P4Rp?ELbRp?ii;iELL�L�L�5i)	Nz#Session store flush on shutdown: {}z,Session store flush on shutdown: exc_type={}z"Shutdown requested, cleaning up...zmessaging_platform.stopr[zcli_manager.stop_allrZzServer shut down cleanly)r2rArN�
session_store�flush_pending_saver,rr+r-r.r\rMr0�stoprO�stop_allrLrd�_shutdown_limiter)re�verboser/s&  r"�shutdown�AppRuntime.shutdown�so����-�-�8�8�����+�	
��$�$�2�2�E�E�G�	���8�9��"�"�"��)��'�'�,�,�.�#*��
�
�45�����&�� � �)�)�+�#*��
�
�46�"�"�.��+��'�'�/�/�1�#*��
�
�47�$�$�&�&�&����.�/��;�
���N�N�#H�!�L�L��N�N�F��Q��(�(����	
��
�
�
�48	'�s��%F?�$E�'F?�4)F?�F6�F?�4)F?�F9�;F?�F;�F?�1F=�2F?�F3�F.�8F?�>*F.�(F?�.F3�3F?�9F?�;F?�=F?c��V^8�dQhRR/#rXr )r!s"r"r#rQ�s��/�/�d�/r$c�	�$"�^RIHpHpV!VPPV!VPP49VPPVPPVPPVPPVPPVPPVPPVPPVPPVPPVPP VPP"R7
4VnVP'dVP%4GRjx�L50R#R#L \&dopTPP"'d\(P*!RT4Rp?R#\(P*!R\-T4P.4Rp?R#Rp?i\0d�pTPP"'dF\(P2!RT4^RIp\(P2!TP744Rp?R#\(P2!R\-T4P.4Rp?R#Rp?ii;i5i)�)�MessagingPlatformOptions�create_messaging_platform)
�telegram_bot_token�allowed_telegram_user_id�discord_bot_token�allowed_discord_channels�voice_note_enabled�
whisper_model�whisper_device�hf_token�nvidia_nim_api_key�messaging_rate_limit�messaging_rate_window�log_raw_messaging_contentrANz!Messaging module import error: {}z*Messaging module import error: exc_type={}z&Failed to start messaging platform: {}z/Failed to start messaging platform: exc_type={})�messaging.platforms.factoryrurvr2rMrwrxryrzr{r|r}r~�nvidia_nim_api_key_qwenr�r�r�rA�_start_message_handler�ImportErrorrr+r-r.r,r:�	traceback�51format_exc)rerurvr/r�s&    r"rb�)AppRuntime._start_messaging_if_configured�s����.	�
�52'@��
�
�0�0�(�'+�}�}�'G�'G�-1�]�]�-S�-S�&*�m�m�&E�&E�-1�]�]�-S�-S�'+�}�}�'G�'G�"&�-�-�"=�"=�#'�=�=�#?�#?�!�]�]�3�3�'+�}�}�'L�'L�)-���)K�)K�*.�-�-�*M�*M�.2�m�m�.U�.U�-1�]�]�-S�-S��'�D�#�&�&�&�&��1�1�3�3�3�'�3���	��}�}�5�5�5����B�A�F�F����@���G�$�$�����53	��}�}�5�5�5����E�q�I� ����Y�1�1�3�4�4����E���G�$�$����54	�sr�J�E&E5�*E3�+E5�/J�3E5�5J
�3G)�3J�9*G)�#J�)J
�6J
�7AJ�J�*J�J�J
�
Jc��V^8�dQhRR/#rXr )r!s"r"r#rQ�s��3N�3N�d�3Nr$c�	�l"�^RIHp^RIHp^RIHpVPP'd4\PPVPP4M\P!4p\P!VRR7\PPVPP4p\P!VRR7RVPPRVPPR2pVPP'dV.M.p\PP\PP!VPPR	44p\PP#W�4p	V!VVVV	VPP$VPP&VPP(R557VnV!\PP!VR4VPP,R7p56VP.pVfQhV!VVP*V57VPP0VPP2VPP4VPP&VPP(R7VnVP9V584VP;VP6P<4VP?4GR
jx�L59\@PB!VPDR24R
#L)5i)rtr
rrT)�exist_okzhttp://�:z/v1�plans)�workspace_path�api_url�allowed_dirs�plans_directory�60claude_bin�log_raw_cli_diagnostics�log_messaging_error_detailsz
sessions.json)�storage_path�message_log_capN)�platformrOrj�debug_platform_edits�debug_subagent_stackr�r�r�z& platform started with message handler)#�cli.managerr�messaging.handlerr�messaging.sessionrr2�allowed_dir�os�path�abspath�getcwd�makedirs�claude_workspace�host�port�join�relpath�claude_cli_binr�r�rO� max_message_log_entries_per_chatrMr�r�r�rN�_restore_tree_state�61on_message�handle_message�startrr\r)rerrr�	workspace�	data_pathr�r��
plans_dir_absr�rjr�s&           r"r��!AppRuntime._start_message_handler�s@���1�:�2��}�}�(�(�(�
�G�G�O�O�D�M�M�5�5�6�����	�62	���I��-��G�G�O�O�D�M�M�$B�$B�C�	�63���I��-��D�M�M�.�.�/�q����1C�1C�0D�C�H��&*�m�m�&?�&?�&?�	�{�R��������G�G�L�L����7�7��A�64�
��'�'�/�/�-�C��,�$��%�+��}�}�3�3�$(�M�M�$I�$I�(,�
�
�(Q�(Q�65���%������i��A� �M�M�J�J�66�
��*�*���#�#�#�3���(�(�'�!%���!C�!C�!%���!C�!C�&*�m�m�&M�&M�$(�M�M�$I�$I�(,�
�
�(Q�(Q�	 67���	
� � ��/����D�0�0�?�?�@��n�n�������x�}�}�o�%K�L�M�	�s�D&L4�)GL4�L2�	*L4c��V^8�dQhRR/#rXr )r!s"r"r#rQs��=�=��=r$c�
�<"�\P!R4^RIHpRR.p.pVFVpV!W@PVP68R7p\
VR4'd#VPVPWT44KVKX	V'dM\P!\P!VRR/R	R697GRjx�L70\P!R4R#R# \dK�i;iL0 \d#p\P!R
T4Rp?R#Rp?ii;i5i)zEPre-establish HTTP connections to providers for faster first request.z"Warming up provider connections...)�resolve_provider�zen�71nvidia_nimrS�_client�return_exceptionsTrr&NzProvider warmup completezProvider warmup skipped: {})rr\�api.dependenciesr�rIr2�hasattr�append�_warmup_providerr,r(r)�gatherr+)rer��provider_types�warmup_tasks�
provider_type�providerr/s&      r"ra�AppRuntime._warmup_providerss������8�9�	=�9�$�\�2�N��L�!/�
�72�/�%�8�8�d�m�m� �H��x��3�3�$�+�+� �1�1�(�J��4�
"0���&�&��N�N�L�I�D�I�SV�������6�7���!�����73���	=��N�N�8�!�<�<��	=�sd�D�C,�AC�<
C,�74/C,�9C*�:C,�D�C'�#C,�&C'�'C,�,D�7D�D�D�Dc� �V^8�dQhRRRR/#)rr�rrrr )r!s"r"r#rQ=s����c��d�r$c�
�"�\VR4'd\P!RV4R#R# \dR#i;i5i)z*Trigger provider connection establishment.�preflight_streamz!Provider {} connection pre-warmedN)r�r�debugr,)rer�r�s&&&r"r��AppRuntime._warmup_provider=s=���	��x�!3�4�4����@�-�P�5���	��	�s#�A�)1�A�A�A�A�Ac� �V^8�dQhRRRR/#)rrjrrrr )r!s"r"r#rQEs������$�r$c		�X�VP4pV'gR#VPfR#\P!R\	V4R24^RIHpVPPVPRVRVP4/VPPVPPR74VPPP4^8�dGVPPP4pVPVR,VR,4R#R#)Nz75Restoring z conversation trees...)�TreeQueueManager�trees�node_to_tree)�queue_update_callback�node_started_callback)�
get_all_treesrNrr\�len�messaging.trees.queue_managerr��replace_tree_queue�	from_dict�get_node_mapping�update_queue_positions�mark_node_processing�76tree_queue�cleanup_stale_nodes�to_dict�sync_from_tree_data)rerj�saved_treesr��	tree_datas&&   r"r��AppRuntime._restore_tree_stateEs���#�1�1�3�������'�����j��[�!1� 2�2H�I�J�B����/�/��&�&��[�"�M�$B�$B�$D��'+�&:�&:�&Q�&Q�&*�&:�&:�&O�&O�

'�
�		77����*�*�>�>�@�1�D��,�,�7�7�?�?�A�I��-�-��'�"�I�n�$=�
�Er$c��V^8�dQhRR/#rXr )r!s"r"r#rQ_s��6�6��6r$c	���VPVPPnVPVPPnVPVPPnR#�N)rMrIr]rNrO)res&r"rc�AppRuntime._publish_state_sD��,0�,C�,C������)�)-�)=�)=������&�%)�%5�%5������"r$c��V^8�dQhRR/#rXr )r!s"r"r#rQds��78�79��80r$c�	�"�VPPp^RIHp\RTP4RTR7GRjx�L81R# \djpT'd-\82P!R\T4PT4M*\83P!R\T4P4Rp?R#Rp?ii;iL}5i)rt)�MessagingRateLimiterz5Rate limiter shutdown skipped (import failed): {}: {}z:Rate limiter shutdown skipped (import failed): exc_type={}Nz&MessagingRateLimiter.shutdown_instanceg@)rr)r2rA�messaging.limiterr�r,rr�r-r.r0�shutdown_instance)reror�r/s&   r"rn�AppRuntime._shutdown_limiterds�����-�-�8�8��	�>��4� �2�2�4��&�	84�	85�	86���	�����K���G�$�$������P���G�$�$��
��	��	87�s:�C�A� C�B>�C�B;�AB6�0C�6B;�;C)rLrOrNrMr�)r.�88__module__�__qualname__�__firstlineno__�__doc__�__annotations__rrLrMrNrO�classmethodrUrfrprbr�rar�r�rcrn�__static_attributes__r r$r"rHrHas���O�	�L���27��5�2Q��/�Q�37��0�7�37�O�0�7�,0�K�)�0��A��A��@"0�H/�b3N�j=�>��46�8990�91r$rH)%r��92__future__rr(r��dataclassesrr�typingrr�fastapir�logurur�config.settingsr	r93�providers.exceptionsr�providers.registryrr�rr�r�messaging.platforms.baserr�r�_SHUTDOWN_TIMEOUT_Sr0r5r<r9rErHr r$r"�<module>r�s���>�"��	�(�%���2�8�/��-�6�:�.���+��94 %���895�1�C�/����Y96�Y97��Y98r$