@@ -828,9 +828,11 @@ function emitSessionRpcClasses(node: Record<string, unknown>, classes: string[])
828828 const groups = Object . entries ( node ) . filter ( ( [ , v ] ) => typeof v === "object" && v !== null && ! isRpcMethod ( v ) ) ;
829829 const topLevelMethods = Object . entries ( node ) . filter ( ( [ , v ] ) => isRpcMethod ( v ) ) ;
830830
831- const srLines = [ `/// <summary>Provides typed session-scoped RPC methods.</summary>` , `public class SessionRpc` , `{` , ` private readonly JsonRpc _rpc;` , ` private readonly string _sessionId;` , "" ] ;
832- srLines . push ( ` internal SessionRpc(JsonRpc rpc, string sessionId)` , ` {` , ` _rpc = rpc;` , ` _sessionId = sessionId;` ) ;
833- for ( const [ groupName ] of groups ) srLines . push ( ` ${ toPascalCase ( groupName ) } = new ${ toPascalCase ( groupName ) } Api(rpc, sessionId);` ) ;
831+ const srLines = [ `/// <summary>Provides typed session-scoped RPC methods.</summary>` , `public class SessionRpc` , `{` , ` private readonly JsonRpc _rpc;` , ` private readonly string _sessionId;` , ` private readonly Action<string>? _onShellExec;` , "" ] ;
832+ srLines . push ( ` internal SessionRpc(JsonRpc rpc, string sessionId, Action<string>? onShellExec = null)` , ` {` , ` _rpc = rpc;` , ` _sessionId = sessionId;` , ` _onShellExec = onShellExec;` ) ;
833+ for ( const [ groupName ] of groups ) srLines . push (
834+ ` ${ toPascalCase ( groupName ) } = new ${ toPascalCase ( groupName ) } Api(rpc, sessionId${ groupName === "shell" ? ", _onShellExec" : "" } );`
835+ ) ;
834836 srLines . push ( ` }` ) ;
835837 for ( const [ groupName ] of groups ) srLines . push ( "" , ` /// <summary>${ toPascalCase ( groupName ) } APIs.</summary>` , ` public ${ toPascalCase ( groupName ) } Api ${ toPascalCase ( groupName ) } { get; }` ) ;
836838
@@ -896,15 +898,22 @@ function emitSessionMethod(key: string, method: RpcMethod, lines: string[], clas
896898
897899 lines . push ( `${ indent } public async Task<${ resultClassName } > ${ methodName } Async(${ sigParams . join ( ", " ) } )` ) ;
898900 lines . push ( `${ indent } {` , `${ indent } var request = new ${ requestClassName } { ${ bodyAssignments . join ( ", " ) } };` ) ;
899- lines . push ( `${ indent } return await CopilotClient.InvokeRpcAsync<${ resultClassName } >(_rpc, "${ method . rpcMethod } ", [request], cancellationToken);` , `${ indent } }` ) ;
901+ if ( method . rpcMethod === "session.shell.exec" ) {
902+ lines . push ( `${ indent } var result = await CopilotClient.InvokeRpcAsync<${ resultClassName } >(_rpc, "${ method . rpcMethod } ", [request], cancellationToken);` ) ;
903+ lines . push ( `${ indent } _onExec?.Invoke(result.ProcessId);` ) ;
904+ lines . push ( `${ indent } return result;` , `${ indent } }` ) ;
905+ } else {
906+ lines . push ( `${ indent } return await CopilotClient.InvokeRpcAsync<${ resultClassName } >(_rpc, "${ method . rpcMethod } ", [request], cancellationToken);` , `${ indent } }` ) ;
907+ }
900908}
901909
902910function emitSessionApiClass ( className : string , node : Record < string , unknown > , classes : string [ ] ) : string {
903911 const displayName = className . replace ( / A p i $ / , "" ) ;
904912 const groupExperimental = isNodeFullyExperimental ( node ) ;
905913 const experimentalAttr = groupExperimental ? `[Experimental(Diagnostics.Experimental)]\n` : "" ;
906- const lines = [ `/// <summary>Provides session-scoped ${ displayName } APIs.</summary>` , `${ experimentalAttr } public class ${ className } ` , `{` , ` private readonly JsonRpc _rpc;` , ` private readonly string _sessionId;` , "" ] ;
907- lines . push ( ` internal ${ className } (JsonRpc rpc, string sessionId)` , ` {` , ` _rpc = rpc;` , ` _sessionId = sessionId;` , ` }` ) ;
914+ const ctorSuffix = className === "ShellApi" ? ", Action<string>? onExec = null" : "" ;
915+ const lines = [ `/// <summary>Provides session-scoped ${ displayName } APIs.</summary>` , `${ experimentalAttr } public class ${ className } ` , `{` , ` private readonly JsonRpc _rpc;` , ` private readonly string _sessionId;` , ...( className === "ShellApi" ? [ ` private readonly Action<string>? _onExec;` ] : [ ] ) , "" ] ;
916+ lines . push ( ` internal ${ className } (JsonRpc rpc, string sessionId${ ctorSuffix } )` , ` {` , ` _rpc = rpc;` , ` _sessionId = sessionId;` , ...( className === "ShellApi" ? [ ` _onExec = onExec;` ] : [ ] ) , ` }` ) ;
908917
909918 for ( const [ key , value ] of Object . entries ( node ) ) {
910919 if ( ! isRpcMethod ( value ) ) continue ;
0 commit comments