
    xjz                         d Z defdZd ZdS )a  Usage metric helpers for WebUI display payloads.

Prompt-cache hit percentage is cached prompt reads over the full prompt total
(input + cache reads + cache writes). Keep this calculation in the backend so
browser display code cannot drift across context indicator and per-turn labels.
returnc                 V    	 t          | pd          S # t          t          f$ r Y dS w xY w)N    )int	TypeError
ValueError)values    ,/Users/bertmahoney/hermes-webui/api/usage.py_to_intr
   	   s>    5:Az"   qqs    ((c                     t          |           }t          |          }|dk    s|dk    rdS t          dt          ||z  dz                      S )zReturn cached reads as a percent of full prompt-token total.

    ``prompt_tokens`` must include ordinary input, cache reads, and cache writes
    (matching Agent's ``session_prompt_tokens`` value).
    r   Nd   )r
   minround)cache_read_tokensprompt_tokens
cache_readprompts       r	   prompt_cache_hit_percentr      sW     *++J]##FQ&A++tsE:.#566777    N)__doc__r   r
   r    r   r	   <module>r      sC    c    
8 
8 
8 
8 
8r   