
    +j                     8   U d Z ddlZddlmZmZ ddlmZ  G d de          Zddd	d
diZe	e
ef         ed<   de
defdZed d dZe	e
ef         ed<   de
de
defdZde	e
ef         fdZdej        dz  dz  dddiidej        dZe	e
ef         ed<   d  e                                            D             Zi eeZe	e
ef         ed<   	 d'd e	e
e	e
ef         f         d!e
d"e
d#edef
d$Zd e	e
e	e
ef         f         d!e
d"e
defd%Zde	e
ef         fd&ZdS )(z
Feature flags module for ComfyUI WebSocket protocol negotiation.

This module handles capability negotiation between frontend and backend,
allowing graceful protocol evolution while maintaining backward compatibility.
    N)Any	TypedDict)argsc                   .    e Zd ZU eed<   eed<   eed<   dS )FeatureFlagInfotypedefaultdescriptionN)__name__
__module____qualname__str__annotations__r        7/home/wildlama/comfy/ComfyUI/comfy_api/feature_flags.pyr   r      s0         
IIILLLr   r   show_signin_buttonboolFz?Show the sign-in button in the frontend even when not signed in)r   r	   r
   CLI_FEATURE_FLAG_REGISTRYvreturnc                 n    |                                  }|dk    rdS |dk    rdS t          d|           )zStrict bool coercion: only 'true'/'false' (case-insensitive).

    Anything else raises ValueError so the caller can warn and drop the flag,
    rather than silently treating typos like 'ture' or 'yes' as False.
    trueTfalseFz expected 'true' or 'false', got )lower
ValueError)r   r   s     r   _coerce_boolr      sF     GGIIEtu
===
>
>>r   c                      t          |           S N)intr   s    r   <lambda>r"   /   s    SVV r   c                      t          |           S r   )floatr!   s    r   r"   r"   0   s    uQxx r   )r   r    r$   _COERCE_FNSkey	raw_valuec                     t                               |           }||S t                              |d                   }||S  ||          S )a9  Coerce a raw string value using the registry type, or keep as string.

    Returns the raw string if the key is unregistered or the type is unknown.
    Raises ValueError/TypeError if the key is registered with a known type but
    the value cannot be coerced; callers are expected to warn and drop the flag.
    Nr   )r   getr%   )r&   r'   infocoerces       r   _coerce_flag_valuer,   4   sR     %((--D|__T&\**F~6)r   c                     i } t          t          dg           D ]}|                    d          \  }}}|                                }|s2|sd}	 t	          ||                                          | |<   ]# t
          t          f$ rc}t                              |i           }t          j
        d||                                |                    dd          |           Y d}~d}~ww xY w| S )aM  Parse --feature-flag key=value pairs from CLI args into a dict.

    Items without '=' default to the value 'true' (bare flag form).
    Flags whose value cannot be coerced to the registered type are dropped
    with a warning, so a typo like '--feature-flag some_bool=ture' does not
    silently take effect as the wrong value.
    feature_flag=r   z@Could not coerce --feature-flag %s=%r to %s (%s); dropping flag.r   ?N)getattrr   	partitionstripr,   r   	TypeErrorr   r)   loggingwarning)resultitemr&   sepr'   er*   s          r   _parse_cli_feature_flagsr;   D   s     Fnb11  "nnS11S)iikk 	 	I	,S)//2C2CDDF3KKI& 	 	 	,00b99DORY__&&(=(=q       	 Ms   %A66C*AC%%C*Ti   managersupports_v4)supports_preview_metadatamax_upload_size	extensionnode_replacementsassets_CORE_FEATURE_FLAGSc                 ,    i | ]\  }}|t           v||S r   )rC   ).0kr   s      r   
<dictcomp>rG   i   s)    bbbtq!QNaEaEaaEaEaEar   SERVER_FEATURE_FLAGSsockets_metadatasidfeature_namer	   c                 n    || vr|S | |                              di                                ||          S )aM  
    Get a feature flag value for a specific connection.

    Args:
        sockets_metadata: Dictionary of socket metadata
        sid: Session ID of the connection
        feature_name: Name of the feature to check
        default: Default value if feature not found

    Returns:
        Feature value or default if not found
    feature_flags)r)   )rI   rJ   rK   r	   s       r   get_connection_featurerN   n   s@    $ """C $$_b99==lGTTTr   c                 *    t          | ||d          du S )a  
    Check if a connection supports a specific feature.

    Args:
        sockets_metadata: Dictionary of socket metadata
        sid: Session ID of the connection
        feature_name: Name of the feature to check

    Returns:
        Boolean indicating if feature is supported
    FT)rN   )rI   rJ   rK   s      r   supports_featurerP      s      ""2CuMMQUUUr   c                  4    t                                           S )zb
    Get the server's feature flags.

    Returns:
        Dictionary of server feature flags
    )rH   copyr   r   r   get_server_featuresrS      s      $$&&&r   )F)__doc__r5   typingr   r   comfy.cli_argsr   r   r   dictr   r   r   r   r%   r,   r;   r?   enable_assetsrC   items
_cli_flagsrH   rN   rP   rS   r   r   r   <module>r[      s      ! ! ! ! ! ! ! !          i    X 9 4_ 45   ?C ?D ? ? ? ?  T#s(^   C C C     $sCx.    : "&+d2T9mT23 ' ' T#s(^    cb7799??AAbbb
'L*='L'L d38n L L L 	U U3S#X./U	U U 	U
 	U U U U0V3S#X./V	V V 
	V V V V&'T#s(^ ' ' ' ' ' 'r   