@@ -226,6 +226,7 @@ async Task<Connection> StartCoreAsync(CancellationToken ct)
226226
227227 // Verify protocol version compatibility
228228 await VerifyProtocolVersionAsync ( connection , ct ) ;
229+ await ConfigureSessionFsAsync ( ct ) ;
229230
230231 _logger . LogInformation ( "Copilot client connected" ) ;
231232 return connection ;
@@ -474,6 +475,7 @@ public async Task<CopilotSession> CreateSessionAsync(SessionConfig config, Cance
474475 {
475476 session . On ( config . OnEvent ) ;
476477 }
478+ ConfigureSessionFsHandlers ( session , config . CreateSessionFsHandler ) ;
477479 _sessions [ sessionId ] = session ;
478480
479481 try
@@ -594,6 +596,7 @@ public async Task<CopilotSession> ResumeSessionAsync(string sessionId, ResumeSes
594596 {
595597 session . On ( config . OnEvent ) ;
596598 }
599+ ConfigureSessionFsHandlers ( session , config . CreateSessionFsHandler ) ;
597600 _sessions [ sessionId ] = session ;
598601
599602 try
@@ -1078,6 +1081,37 @@ private Task<Connection> EnsureConnectedAsync(CancellationToken cancellationToke
10781081 return ( Task < Connection > ) StartAsync ( cancellationToken ) ;
10791082 }
10801083
1084+ private async Task ConfigureSessionFsAsync ( CancellationToken cancellationToken )
1085+ {
1086+ if ( _options . SessionFs is null )
1087+ {
1088+ return ;
1089+ }
1090+
1091+ await Rpc . SessionFs . SetProviderAsync (
1092+ _options . SessionFs . InitialCwd ,
1093+ _options . SessionFs . SessionStatePath ,
1094+ _options . SessionFs . Conventions ,
1095+ cancellationToken ) ;
1096+ }
1097+
1098+ private void ConfigureSessionFsHandlers ( CopilotSession session , Func < CopilotSession , ISessionFsHandler > ? createSessionFsHandler )
1099+ {
1100+ if ( _options . SessionFs is null )
1101+ {
1102+ return ;
1103+ }
1104+
1105+ if ( createSessionFsHandler is null )
1106+ {
1107+ throw new InvalidOperationException (
1108+ "CreateSessionFsHandler is required in the session config when CopilotClientOptions.SessionFs is configured." ) ;
1109+ }
1110+
1111+ session . ClientSessionApis . SessionFs = createSessionFsHandler ( session )
1112+ ?? throw new InvalidOperationException ( "CreateSessionFsHandler returned null." ) ;
1113+ }
1114+
10811115 private async Task VerifyProtocolVersionAsync ( Connection connection , CancellationToken cancellationToken )
10821116 {
10831117 var maxVersion = SdkProtocolVersion . GetVersion ( ) ;
@@ -1319,6 +1353,11 @@ private async Task<Connection> ConnectToServerAsync(Process? cliProcess, string?
13191353 rpc . AddLocalRpcMethod ( "userInput.request" , handler . OnUserInputRequest ) ;
13201354 rpc . AddLocalRpcMethod ( "hooks.invoke" , handler . OnHooksInvoke ) ;
13211355 rpc . AddLocalRpcMethod ( "systemMessage.transform" , handler . OnSystemMessageTransform ) ;
1356+ ClientSessionApiRegistration . RegisterClientSessionApiHandlers ( rpc , sessionId =>
1357+ {
1358+ var session = GetSession ( sessionId ) ?? throw new ArgumentException ( $ "Unknown session { sessionId } ") ;
1359+ return session . ClientSessionApis ;
1360+ } ) ;
13221361 rpc . StartListening ( ) ;
13231362
13241363 // Transition state to Disconnected if the JSON-RPC connection drops
0 commit comments