pyc • Lines: 1110�
���j�� � �� � d Z ddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlmZ ddlm
Z
mZ ddlZddlmZmZmZ ddlmZmZmZmZmZ dddd d
dd�Zd
� ZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>dZ?dZ@dZAdZBdZCdZDdZEdZFg d�ZGd� ZHd� ZI G d� dej� j� � ZLd� ZMy)a� HTTP API endpoints for the chat web UI.
The request handlers here are the thin web layer over the chat engine in
``chat-webui.py``. All shared application state and helper functions live in the
entrypoint module and are injected here at startup via :func:`set_app_state`,
so nothing has to be duplicated.
The names in ``APP_STATE_NAMES`` are declared as module globals below and
replaced by the real objects when the entrypoint calls ``set_app_state``.
� N)�datetime)�parse_qs�urlparse)�get_current_user�get_identity�identity_from_headers)�COMFYUI_OUTPUT�FORCE_GPU_LANE�IMG_PATH�SELF_CHAT_MODE�UPLOADS_DIR� image/png�
image/jpegz
image/webpz image/gifz image/bmp)z.pngz.jpgz.jpegz.webpz.gifz.bmpc � � | syt | � j }|j d� }d}|j d� rt |t d� d }}nK|j d� rt |t d� d }}n%t t j j |� }}t j j |� }t j j t j j ||� � }||k7 r#|j |t j z � syt j j |� sy|S )u! Resolve an ``/api/image/<id>`` identifier to a local image file path.
Accepts ids shaped like the stored image URLs — ``uploads/<name>`` (user
uploads) or ``output/<rel>`` (ComfyUI generated images) — plus bare
filenames, which are looked up in the uploads dir first.
N�/zuploads/zoutput/)
r �path�lstrip�
startswithr
�lenr �os�basename�realpath�join�sep�isfile)�image_id�raw�base�rel�root�fpaths �'/home/palash/git/local-ai/server/api.py�resolve_image_filer# 0 s� � � ��
�8�
�
!�
!�C�
�*�*�S�/�C��D�
�~�~�j�!���S��_�%5�!6�c�� ��� � "�"�C��I���$8�c������!1�!1�#�!6�c��
�7�7���D�!�D��G�G���R�W�W�\�\�$��4�5�E���}�U�-�-�d�R�V�V�m�<��
�7�7�>�>�%� ���L� )+�ACTIVE_WINDOW_SECONDS�MAX_INPUT_TOKENS�MAX_QUEUE_SIZE�SHARES_FILE�_active_tokens�
_agent_tokens�_agent_users�_user_last_seen�_user_last_seen_lock�
_data_lock� _db_fetch�_effective_contexts�_effective_contexts_lock�_image_url_rel�_load_extra_prompts�_location_events�_queue_conds�_queue_locks�_task_queues�_tokens_lock�active_users�context_token_report�create_share� get_share�get_user_context_path�handle_theme_tool�list_shares�load_shares�model_status_snapshot�read_user_context�revoke_share�
save_sessions�save_shares�sessions�
sessions_meta�set_client_location�shares�task_create�task_delete� task_list�task_update�tasks�write_user_contextc �6 � t � j | � y)z?Inject the application state shared with the entrypoint module.N)�globals�update)�states r"