+
    kHàjz  ã                   ób   € R t ^ RIt^ RIt^ RIHtHt ]P                  ! R4      t ! R R4      tR# )aÇ  Route a client-created Telegram DM topic's thread-less opener into that topic (#136567).

Telegram for Android (13.0.x) delivers the opening message of a topic created from the "All
messages" view with no ``message_thread_id``. The ``Message`` carrying ``forum_topic_created`` is then
the only update that names the new topic (``ForumTopicCreated`` itself has only name/icon fields).
Recording authorized, non-bot private-chat creations lets the thread-less messages that follow adopt
the new topic instead of arriving lobby-shaped, where gateway topic recovery would pin them to the
most recently bound topic.

Adoption follows time and per-chat order, never message-id adjacency: private-chat message ids come
from one sequence shared by every private chat of the bot account (bot replies included), so a send
elsewhere between the creation and the opener breaks ``creation + 1``. Per-chat FIFO update
processing guarantees nothing from this chat lands in between.
N)ÚAnyÚOptionalz"plugins.platforms.telegram.adapterc                   óŒ   a € ] tR t^t o RtRtRtRt]V 3R lR l4       t	]V 3R lR l4       t
V 3R	 lR
 ltV 3R lR ltRtV tR# )ÚTelegramTopicRoutingMixinzgTopic-creation bookkeeping for ``TelegramAdapter`` (relies on its ``_chat_type_str``/``_chat_id_str``).g      @é   g     À‚@c                ó    <€ V ^8„  d   QhRS[ /# ©é   Úreturn)Ústr)ÚformatÚ__classdict__s   "€ÚV/home/ubuntu/.hermes/hermes-agent/plugins/platforms/telegram/telegram_topic_routing.pyÚ__annotate__Ú&TelegramTopicRoutingMixin.__annotate__%   s   ø€ ÷ Kñ K¡ñ Kó    c           	     óD   € \        \        \        V R R4      RR4      4      # )Ú	from_userNÚidÚ )r   Úgetattr)Úmessages   &r   Ú_creator_keyÚ&TelegramTopicRoutingMixin._creator_key$   s   € ä”7œ7 7¨K¸Ó>ÀÀbÓIÓJÐJr   c                ó0   <€ V ^8„  d   QhRS[ S[,          /# r   )r   Úfloat)r   r   s   "€r   r   r   )   s   ø€ ÷ Hñ H™X¡e�_ñ Hr   c                ód   € \        V RR4      p\        VR4      '       d   VP                  4       # R# )zUTelegram's send stamp (whole seconds); an edit keeps its message's original ``date``.ÚdateNÚ	timestamp)r   Úhasattrr   )r   r   s   & r   Ú_sent_atÚ"TelegramTopicRoutingMixin._sent_at(   s0   € ô �w ¨Ó-ˆÜ#*¨4°×#=Ò#=ˆt�~‰~ÓÐGÀ4ÐGr   c                ó*   <€ V ^8„  d   QhRS[ RS[ RR/# )r	   ÚupdateÚcontextr
   N)r   )r   r   s   "€r   r   r   .   s'   ø€ ÷ eñ e¹ð eÁcð eÈdñ er   c              ƒ  ój  a"  € \        VRR4      pVe   \        VRR4      f   R# V P                  \        VRR4      4      R8w  d   R# \        VRR4      p\        VRR4      pV P                  V4      pVe   Ve   Ve   \        VRR	4      R
J d   R# V P                  V4      '       g   R# V P                  P                  R/ 4      o\        P                  ! 4       pSP                  4        UU	u. uF'  w  r‰Wy^,          ,
          V P                  8”  g   K%  VNK)  	  up	p F  p
SV
 K  	  \        S4      V P                  8¼  d   S\        SV3R lR7       K.  V P                  V4      p\        V4      Wg3SW°P                  V4      3&   \         P#                  RV P$                  WK4       R# u up	pi 5i)zúRecord an authorized, non-bot private-chat topic creation (#136567).

Routing signal only, never an agent turn. The user-chosen name is NOT cached in ``_dm_topics``:
entries there mark operator-declared topics, which session-title auto-rename skips.
Úeffective_messageNÚforum_topic_createdÚchatÚprivateÚmessage_thread_idr   Úis_botFTÚ_pending_created_topicsc                 ó$   <€ SV ,          ^,          # )r	   © )ÚkÚpendings   &€r   Ú<lambda>ÚGTelegramTopicRoutingMixin._handle_forum_topic_created.<locals>.<lambda>F   s   ø€ °7¸1µ:¸a¶=r   )Úkeyz-[%s] Recorded new Telegram topic %s (chat=%s))r   Ú_chat_type_strr    Ú _is_user_authorized_from_messageÚ__dict__Ú
setdefaultÚtimeÚ	monotonicÚitemsÚ_NEW_TOPIC_RECORD_TTL_SECONDSÚlenÚ_NEW_TOPIC_OPENER_MAX_PENDINGÚminÚ_chat_id_strr   r   ÚloggerÚdebugÚname)Úselfr#   r$   r   Ú	thread_idÚsenderÚsent_atÚnowr/   Úrecr3   Úchat_idr0   s   &&&         @r   Ú_handle_forum_topic_createdÚ5TelegramTopicRoutingMixin._handle_forum_topic_created.   s€  øé € ô ˜&Ð"5°tÓ<ˆØŠ?œg gÐ/DÀdÓKÒSÙà×Ñœw w°¸Ó=Ó>À)ÔKÙÜ˜GÐ%8¸$Ó?ˆ	Ü˜ +¨tÓ4ˆØ—-‘- Ó(ˆØÒ ¢°6²>ÄWÈVÐU]Ð_dÓEeÐimÓEmÙØ×4Ñ4°W×=Ò=ÙØ—-‘-×*Ñ*Ð+DÀbÓIˆÜ�nŠnÓˆØ$+§M¡M¤OÔi¡O™&˜!°sÀ½Vµ|Àd×FhÑFhÑ7h—A�A¡OÕiˆCØ˜’ñ jä�'‹l˜d×@Ñ@Ô@Øœ˜GÔ)@ÔAÒBØ×#Ñ# GÓ,ˆÜ:=¸i».È'Ð9Wˆ�×+Ñ+¨GÓ4Ð5Ñ6Ü�‰ÐDÀdÇiÁiÐQZÖdùó jùs    ƒB&F3Â*AF3Ã0"F-ÄF-ÄBF3c          	      óR   <€ V ^8„  d   QhRS[ RS[RS[S[,          RS[S[,          /# )r	   r   Ú	chat_typerD   r
   )r   r   r   )r   r   s   "€r   r   r   K   s7   ø€ ÷ !ñ !±3ð !Á3ð !ÑS[Ñ\_ÕS`ð !ÑemÑnqÕerñ !r   c           	     ó  € V P                   P                  R4      pVR8w  g	   V'       g   V# V P                  V4      V P                  V4      3pVP                  V4      pV P	                  V4      pVe   Ve   Wv^,          8  d   V# WE Vf   \        VRR4      e   V# Vw  r‰p
Wy,
          V P                  8”  d   V# W‡\        P                  ! 4       3WE&   \        P                  RV P                  \        VRR4      W…^ ,          4       V# )a*  Thread id of the topic this sender just created, for its thread-less follow-up messages.

A threaded message (the topic now routes normally) or a send gap longer than
``_NEW_TOPIC_FOLLOW_SECONDS`` ends the follow; each adoption extends it, so every chunk of a
split opener lands in the same topic.
r,   ÚdmNr*   zF[%s] Thread-less message %s adopted by new Telegram topic %s (chat=%s)Ú
message_idÚ?)r6   Úgetr?   r   r    r   Ú_NEW_TOPIC_FOLLOW_SECONDSr8   r9   r@   ÚinforB   )rC   r   rM   rD   r0   r3   ÚrecordrF   Úcreated_thread_idÚlast_sent_atÚ	_recordeds   &&&&       r   Ú_adopt_created_topic_threadÚ5TelegramTopicRoutingMixin._adopt_created_topic_threadK   s  € ð —-‘-×#Ñ#Ð$=Ó>ˆØ˜Ô§GØÐØ× Ñ  Ó)¨4×+<Ñ+<¸WÓ+EÐFˆØ—‘˜SÓ!ˆØ—-‘- Ó(ˆð Š>˜Wš_°À½)Ô0CØÐØˆLØÒ ¤G¨GÐ5HÈ$Ó$OÒ$[ØÐØ5;Ñ2Ð¨ØÕ! D×$BÑ$BÔBØÐØ)´D·N²NÓ4DÐEˆ‰Ü�‰Ð\Ø—I‘Iœw w°¸cÓBÐDUÐ[\ÕW]ô	_à Ð r   r.   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rS   r=   r;   Ústaticmethodr   r    rJ   rY   Ú__static_attributes__Ú__classdictcell__)r   s   @r   r   r      s\   ø‡ € Ùqð !$ÐØ$'Ð!à$)Ð!à÷Kó ðKð ÷Hó ðH÷
eð e÷:!ö !r   r   )	r_   Úloggingr8   Útypingr   r   Ú	getLoggerr@   r   r.   r   r   Ú<module>rf      s2   ðñó Û ß  à	×	Ò	Ð?Ó	@€÷O!ó O!r   