1- use super :: Bridge ;
1+ use super :: { Bridge , js_request } ;
22use crate :: error:: map_nats_error;
33use crate :: nats:: { self , FlushClient , PublishClient , RequestClient , session} ;
44use crate :: session_id:: AcpSessionId ;
55use agent_client_protocol:: { Error , ErrorCode , ForkSessionRequest , ForkSessionResponse , Result } ;
66use tracing:: { Span , info, instrument} ;
7+ use trogon_nats:: jetstream:: { JetStreamConsumerFactory , JetStreamPublisher } ;
78use trogon_std:: time:: GetElapsed ;
89
910#[ instrument(
1011 name = "acp.session.fork" ,
1112 skip( bridge, args) ,
1213 fields( session_id = %args. session_id, new_session_id = tracing:: field:: Empty )
1314) ]
14- pub async fn handle < N : RequestClient + PublishClient + FlushClient , C : GetElapsed , J > (
15+ pub async fn handle <
16+ N : RequestClient + PublishClient + FlushClient ,
17+ C : GetElapsed ,
18+ J : JetStreamPublisher + JetStreamConsumerFactory ,
19+ > (
1520 bridge : & Bridge < N , C , J > ,
1621 args : ForkSessionRequest ,
1722) -> Result < ForkSessionResponse > {
@@ -28,17 +33,33 @@ pub async fn handle<N: RequestClient + PublishClient + FlushClient, C: GetElapse
2833 format ! ( "Invalid session ID: {}" , e) ,
2934 )
3035 } ) ?;
31- let nats = bridge. nats ( ) ;
32- let subject = session:: agent:: fork ( bridge. config . acp_prefix ( ) , session_id. as_str ( ) ) ;
33-
34- let result = nats:: request_with_timeout :: < N , ForkSessionRequest , ForkSessionResponse > (
35- nats,
36- & subject,
37- & args,
38- bridge. config . operation_timeout ,
39- )
40- . await
41- . map_err ( map_nats_error) ;
36+ let prefix = bridge. config . acp_prefix ( ) ;
37+ let subject = session:: agent:: fork ( prefix, session_id. as_str ( ) ) ;
38+
39+ let result = match bridge. js ( ) {
40+ Some ( js) => {
41+ let req_id = uuid:: Uuid :: new_v4 ( ) . to_string ( ) ;
42+ js_request:: js_request :: < J , _ , ForkSessionResponse , _ > (
43+ js,
44+ & subject,
45+ & args,
46+ & trogon_std:: StdJsonSerialize ,
47+ prefix,
48+ session_id. as_str ( ) ,
49+ & req_id,
50+ bridge. config . operation_timeout ,
51+ )
52+ . await
53+ }
54+ None => nats:: request_with_timeout :: < N , ForkSessionRequest , ForkSessionResponse > (
55+ bridge. nats ( ) ,
56+ & subject,
57+ & args,
58+ bridge. config . operation_timeout ,
59+ )
60+ . await
61+ . map_err ( map_nats_error) ,
62+ } ;
4263
4364 if let Ok ( ref response) = result {
4465 Span :: current ( ) . record ( "new_session_id" , response. session_id . to_string ( ) . as_str ( ) ) ;
0 commit comments