+
    1bKju                     R    ^RI Ht ^RIHt ^RIHt ^RIHtHt R R lt	R R lt
R	# )
   )LLMGenerationError)reply_system_prompt)get_provider)ChatMessageSuggestResponseRequestc                \    V ^8  d   QhR\         \        ,          R\         \        ,          /# )r   historyreturn)listr   dict)formats   ":C:\xampp\htdocs\meridian\meridian-ai\app\services\reply.py__annotate__r      s#      d;&7 DJ     c                f   . pV  F  pVP                   '       d   RVP                    RVP                   2MVP                  pV'       dE   VR,          R,          VP                  8X  d&   VR,          R;;,          RV,           ,          uu&   K  VP                  RVP                  RV/4       K  	  V# )a  Collapse consecutive same-role turns into one message.

OpenAI tolerates back-to-back "user" messages in the list; Anthropic's Messages
API rejects them outright (it requires strict user/assistant alternation). Since
conversation_history is built from an external source (an inbox thread) rather
than turn-by-turn by this service, it can't be assumed to already alternate -
merging here keeps every provider implementation equally usable instead of only
working by accident with whichever one tolerates the input.
[z] rolecontent
)	timestampr   r   append)r	   mergedmessager   s   &   r   _to_alternating_messagesr      s     F@G@Q@Q@QAg''(7??*;<W^WfWffRj(GLL82Jy!TG^3!MM67<<GDE  Mr   c                0    V ^8  d   QhR\         R\        /# )r   payloadr
   )r   r   )r   s   "r   r   r      s     
T 
T4 
T 
Tr   c                     \        V P                  V P                  R 7      p\        V P                  4      p \        4       P                  W4      #   \         d   p\        R\        T4      4      ThRp?ii ; i))trip_contextnum_suggestionszFailed to suggest a responseN)
r   r   r    r   conversation_historyr   complete_json	Exceptionr   str)r   system_promptmessagesexcs   &   r   suggest_responser(      sp    '))//M ((D(DEHT~++MDD T !?SJPSSTs   A A7A22A7N)
exceptionsr   promptsr   providers.factoryr   schemasr   r   r   r(    r   r   <module>r.      s    + ) , 9(
Tr   