
    `gje                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZ ddlmZ  ej                  e      Zdd	Zdd
ZddZddZy)z=Gateway runtime wiring for the Teams meeting pipeline plugin.    )annotationsN)Any)Platform)TeamsMeetingPipeline)TeamsPipelineStore!resolve_teams_pipeline_store_path)build_graph_clientc                0   t        |j                  d      xs( |j                  d      xs | j                  d      xs d      j                         j                         }|dk(  r-t	        |j                  d      xs | j                  d            S |dk(  r|j                  d      xs | j                  d      }|j                  d      xs | j                  d      }|j                  d	      xs | j                  d	      }t	        |xs |xr |      S y
)Nmodedelivery_mode incoming_webhookincoming_webhook_urlgraphchat_idteam_id
channel_idF)strgetstriplowerbool)teams_extrateams_deliveryr   r   r   r   s         Q/root/.hermes/venv/lib/python3.12/site-packages/plugins/teams_pipeline/runtime.py_teams_delivery_is_configuredr      s   6" 	o.	???+	 	
 egeeg  **56 756
 	
  $$Y/M;??93M $$Y/M;??93M#''5V9V
G7 6J88    c                   | j                   j                  t        d            }t        |r|j                  xs i ni       }t        |j                  d      xs i       }|r|j
                  rt        |j                  d      xs i       }t        |j                  d      xs d      j                         }|r||d<   dD ]  }|j                  |      }|dvs|||<    |rt        ||      |d	<   ||d<   |S )
zBuild pipeline config from gateway platform config.

    Pipeline-specific knobs live under ``teams.extra.meeting_pipeline`` while
    Teams delivery continues to source its target details from the existing
    Teams platform config.
    teamsmeeting_pipeliner   r   r   r   )r   access_tokenr   r   r   >   Nr   enabled)		platformsr   r   dictextrar"   r   r   r   )gateway_configteams_configr   pipeline_configr   r   keyvalues           r   build_pipeline_runtime_configr+   &   s     "++//0ABL\**0brJK;??+=>D"EO,,o112BCIrJKOOO<BCIIK%2N6"
 		,C  OOC(EJ&&+s#		, (EkSa(bN9%0>O,-r   c                   d }| j                   j                  j                  t        d            }t	        | j                         }t        |j                  d      xs i       }|r-|j                  r!|j                  d      r	 ddlm}  ||      }t        t               t        t                     ||      S # t        $ r t        j                  d       Y Hw xY w)	Nr   r   r"   r   )TeamsSummaryWriter)platform_configzlTeamsSummaryWriter unavailable; Teams outbound delivery remains disabled until the adapter layer is present.)graph_clientstoreconfigteams_sender)r1   r#   r   r   r+   r$   r"   plugins.platforms.teams.adapterr-   ImportErrorloggerdebugr   r	   r   r   )gatewayr2   r'   r(   r   r-   s         r   build_pipeline_runtimer8   K   s    L>>++//0ABL3GNNCO/--.>?E2FN,,1C1CI1N	LJ .lKL') !B!DE!	   	LL~	s   B; ;CCc                   | j                   j                  t        j                        }|yt	        | dd      y	 t        |       dfd}|j                  |       | _        d| _        y# t        $ rG}t        |      }|| _        t        j                  d|       dd}|j                  |       Y d}~yd}~ww xY w)	zAAttach the Teams pipeline runtime to the msgraph webhook adapter.NF_teams_pipeline_runtimeTzTeams pipeline runtime unavailable: %s. Installing a drop-scheduler so Graph notifications ack cleanly without piling up unbound.c                v   K   t         j                  d| j                  d      | j                  d             y w)NzMDropping Graph notification because runtime is unavailable: id=%s resource=%sidresource)r5   r6   r   )notificationevents     r   _dropz#bind_gateway_runtime.<locals>._dropw   s1     LL_  &  ,s   79c                D   K   j                  |        d {    y 7 w)N)run_notification)r>   r?   runtimes     r   	_schedulez'bind_gateway_runtime.<locals>._schedule   s     &&|444s     )r>   dict[str, Any]r?   r   returnNone)adaptersr   r   MSGRAPH_WEBHOOKgetattrr8   	Exceptionr   _teams_pipeline_runtime_errorr5   warningset_notification_schedulerr:   )r7   adapterexcerror_messager@   rD   rC   s         @r   bind_gateway_runtimerR   b   s     ""8#;#;<Gw148D(1(5 &&y1&-G#,0G)3  C0=-L	
	 	**51#s   A. .	B>7=B99B>)r   rE   r   rE   rF   r   )r&   r   rF   rE   )r7   r   rF   r   )r7   r   rF   r   )__doc__
__future__r   loggingtypingr   gateway.configr   plugins.teams_pipeline.pipeliner   plugins.teams_pipeline.storer   r   $plugins.teams_pipeline.subscriptionsr	   	getLogger__name__r5   r   r+   r8   rR    r   r   <module>r^      sD    C "   # @ ^ C			8	$,"J.%r   