
    )j                        d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ  ed          Z ed          Zd	Zd
Z ed           G d d                      Zd#dZd$dZd%dZdddddd&d"ZdS )'zBExpensive-model confirmation helpers for model selection surfaces.    )annotations)	dataclass)DecimalInvalidOperation)Optional)	ModelInfo20100zopenai/gpt-5.5-proz&did you mean to select openai/gpt-5.5?T)frozenc                  P    e Zd ZU dZded<   ded<   ded<   ded<   ded<   ded	<   d
S )ExpensiveModelWarningz=Confirmation payload for models above Hermes' cost guardrail.strmodelproviderOptional[Decimal]input_cost_per_millionoutput_cost_per_millionsourcemessageN)__name__
__module____qualname____doc____annotations__     B/home/wildlama/.hermes/hermes-agent/hermes_cli/model_cost_guard.pyr   r      sR         GGJJJMMM----....KKKLLLLLr   r   valueobjectreturnr   c                t    | d S 	 t          t          |                     S # t          t          f$ r Y d S w xY w)N)r   r   r   
ValueErrorr   s    r   _to_decimalr$      sL    }ts5zz"""j)   tts   " 77r   c                    | dS d| ddS )Nunknown$z.2fz/Mr   r#   s    r   _format_moneyr(   '   s     }yur   
model_infoOptional[ModelInfo]0tuple[Optional[Decimal], Optional[Decimal], str]c                    | |                                  sdS t          | j                  t          | j                  dfS )N)NN z
models.dev)has_cost_datar$   
cost_inputcost_output)r)   s    r   _pricing_from_model_infor1   -   sI     !9!9!;!;~J)**J*++ r   N)r   base_urlapi_keyr)   
model_namer   Optional[str]r2   r3   Optional[ExpensiveModelWarning]c          
     B   | pd                                 }|sdS t          |          \  }}}|9|7|r5	 ddlm}	 t           |	||                    \  }}}n# t          $ r Y nw xY w|B|@	 ddlm}
  |
||||          }n# t          $ r d}Y nw xY w||j        }|j        }|j	        }|duo
|t          k    }|duo
|t          k    }|s|sdS dd| dd	t          |           d
t          |           dg}|r|                    d| d           |                                t          k    r|                    t                      |                    d           t#          ||pd                                 |||pdd                    |                    S )zReturn a warning payload when known pricing exceeds safety thresholds.

    The guard only triggers when pricing is known. Callers should use this after
    model resolution so aliases and provider-specific model IDs have settled.
    r-   Nr   )get_model_info)get_pricing_entry)r   r2   r3   z!!! EXPENSIVE MODEL WARNING !!!z2 has known pricing above Hermes' safety threshold.zInput tokens: zOutput tokens: zJThreshold: more than $20/M input tokens or more than $100/M output tokens.zPricing source: .z-Confirm only if you intend to use this model.r&   
)r   r   r   r   r   r   )stripr1   agent.models_devr8   	Exceptionagent.usage_pricingr9   r   r   r   INPUT_COST_WARNING_THRESHOLDOUTPUT_COST_WARNING_THRESHOLDr(   appendlowerGPT55_PRO_OPENROUTER_IDGPT55_SUGGESTIONr   join)r4   r   r2   r3   r)   r   
input_costoutput_costr   r8   r9   entry
over_inputover_outputliness                  r   expensive_model_warningrM   9   sq    2$$&&E t&>z&J&J#JVk1h1	777777.Fx/// /+JVV  	 	 	D	k1
	======%%!!	  EE  	 	 	EEE	5J7K\F 	$L:0L#L  	4OK2O$O   k t 	*
DDD4z22446-4466$
E  31111222{{}}///%&&&	LL@AAA .b''))) +"		%     s#   #A 
A&%A&.B BB)r   r   r    r   )r   r   r    r   )r)   r*   r    r+   )r4   r   r   r5   r2   r5   r3   r5   r)   r*   r    r6   )r   
__future__r   dataclassesr   decimalr   r   typingr   r=   r   r@   rA   rD   rE   r   r$   r(   r1   rM   r   r   r   <module>rR      sQ   H H " " " " " " ! ! ! ! ! ! - - - - - - - -       & & & & & &  'wt}}  ' . ;  $             	 	 	 	 #"!&*M M M M M M M Mr   