
    kKj3
                    H    d Z ddlmZ ddlZdZd
dZd
dZddZd
dZdd	Z	y)u  Deterministic tool hashing for backend-tool routing and per-tool resources.

Each FastMCPApp backend tool gets a deterministic hash computed from its
app name + tool name. The hash serves two purposes:

1. **Backend-tool routing.** Tools with ``"app"`` in their visibility are
   callable via ``<hash>_<local_name>``. The dispatcher parses the prefix,
   then walks providers recursively (same pattern as the old ``get_app_tool``)
   to find a tool whose stored hash matches.

2. **Per-tool Prefab renderer URIs.** Each prefab tool gets a unique renderer
   resource at ``ui://prefab/tool/<hash>/renderer.html``. ``list_resources``
   and ``read_resource`` synthesize these on demand from the tool's meta.

The hash is computed at registration time from ``(app_name, tool_name)`` —
both known at that moment — and stored in ``meta["fastmcp"]["_tool_hash"]``.
Deterministic across replicas (same code → same hash), no registry walk
needed.
    )annotationsN   c                    |  d| j                         }t        j                  |      j                         dt         S )zlDeterministic hex hash for a tool in an app.

    Same inputs on every replica produce the same output.
     N)encodehashlibsha256	hexdigestHASH_LENGTH)app_name	tool_namepayloads      t/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/fastmcp/server/providers/addressing.py	hash_toolr      s<    
 
$yk*113G>>'",,.|<<    c                $    t        | |       d| S )zFFormat the universal name for a backend tool: ``<hash>_<local_name>``._r   r   r   s     r   hashed_backend_namer   &   s    ),-Qyk::r   c                    t        |       t        dz   k  ry| dt         }| t           dk7  ryt        d |D              sy|| t        dz   d fS )uK   Parse ``<HASH_LENGTH hex>_<rest>`` → ``(hash, local_tool_name)`` or None.   Nr   c              3  $   K   | ]  }|d v  
 yw0123456789abcdefN .0cs     r   	<genexpr>z,parse_hashed_backend_name.<locals>.<genexpr>2   s     71q&&   )lenr   all)nameprefixs     r   parse_hashed_backend_namer&   +   sY    
4yK!O#,;FKC7774a)***r   c                "    dt        | |       dS )z&Per-tool Prefab renderer resource URI.ui://prefab/tool//renderer.htmlr   r   s     r   hashed_resource_urir*   7   s    y9=>nMMr   c                    d}d}| j                  |      r| j                  |      sy| t        |      t        |        }t        |      t        k7  st	        d |D              sy|S )z5Extract the hash from a Prefab renderer URI, or None.r(   r)   Nc              3  $   K   | ]  }|d v  
 ywr   r   r   s     r   r    z,parse_hashed_resource_uri.<locals>.<genexpr>C   s     'KA-?(?r!   )
startswithendswithr"   r   r#   )urir%   suffixhs       r   parse_hashed_resource_urir2   <   s]     FF>>&!f)=CK3v;,'A
1vC'K'K$KHr   )r   strr   r3   returnr3   )r$   r3   r4   ztuple[str, str] | None)r/   r3   r4   z
str | None)
__doc__
__future__r   r   r   r   r   r&   r*   r2   r   r   r   <module>r7      s3   ( #  =;
	+N
	r   