44 *--------------------------------------------------------------------------------------------*/
55
66import { Disposable , DisposableMap , DisposableStore , toDisposable } from '../../../../base/common/lifecycle.js' ;
7+ import { isWeb } from '../../../../base/common/platform.js' ;
78import * as nls from '../../../../nls.js' ;
89import { IRemoteAgentHostService , RemoteAgentHostConnectionStatus , RemoteAgentHostsEnabledSettingId } from '../../../../platform/agentHost/common/remoteAgentHostService.js' ;
910import { ITunnelAgentHostService , TUNNEL_ADDRESS_PREFIX , type ITunnelInfo } from '../../../../platform/agentHost/common/tunnelAgentHost.js' ;
1011import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js' ;
1112import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js' ;
13+ import { ILogService } from '../../../../platform/log/common/log.js' ;
1214import { INotificationService , Severity } from '../../../../platform/notification/common/notification.js' ;
1315import { IWorkbenchContribution , registerWorkbenchContribution2 , WorkbenchPhase } from '../../../../workbench/common/contributions.js' ;
16+ import { IAuthenticationService } from '../../../../workbench/services/authentication/common/authentication.js' ;
1417import { ISessionsProvidersService } from '../../../services/sessions/browser/sessionsProvidersService.js' ;
1518import { RemoteAgentHostSessionsProvider } from './remoteAgentHostSessionsProvider.js' ;
1619
@@ -33,6 +36,8 @@ export class TunnelAgentHostContribution extends Disposable implements IWorkbenc
3336 @IConfigurationService private readonly _configurationService : IConfigurationService ,
3437 @IInstantiationService private readonly _instantiationService : IInstantiationService ,
3538 @INotificationService private readonly _notificationService : INotificationService ,
39+ @ILogService private readonly _logService : ILogService ,
40+ @IAuthenticationService private readonly _authenticationService : IAuthenticationService ,
3641 ) {
3742 super ( ) ;
3843
@@ -50,6 +55,15 @@ export class TunnelAgentHostContribution extends Disposable implements IWorkbenc
5055 this . _reconcileProviders ( ) ;
5156 } ) ) ;
5257
58+ // Re-run discovery when a GitHub session becomes available
59+ // (e.g. after the walkthrough completes sign-in).
60+ this . _register ( this . _authenticationService . onDidChangeSessions ( e => {
61+ if ( e . providerId === 'github' ) {
62+ this . _logService . info ( '[TunnelAgentHost] GitHub sessions changed, retrying discovery...' ) ;
63+ this . _silentStatusCheck ( ) ;
64+ }
65+ } ) ) ;
66+
5367 // Silently check status of cached tunnels on startup
5468 this . _silentStatusCheck ( ) ;
5569 }
@@ -219,6 +233,15 @@ export class TunnelAgentHostContribution extends Disposable implements IWorkbenc
219233 }
220234 }
221235
236+ // Auto-cache online tunnels that aren't cached yet so they
237+ // appear in the UI on first discovery (e.g. fresh web session).
238+ const cachedIds = new Set ( cached . map ( t => t . tunnelId ) ) ;
239+ for ( const tunnel of onlineTunnels ) {
240+ if ( ! cachedIds . has ( tunnel . tunnelId ) && tunnel . hostConnectionCount > 0 ) {
241+ this . _tunnelService . cacheTunnel ( tunnel ) ;
242+ }
243+ }
244+
222245 // Update online/offline status based on hostConnectionCount.
223246 // For tunnels, Connected means "host is online" (clickable to connect),
224247 // Disconnected means "host is offline". Actual relay connection
@@ -241,6 +264,23 @@ export class TunnelAgentHostContribution extends Disposable implements IWorkbenc
241264 provider . setConnectionStatus ( RemoteAgentHostConnectionStatus . Disconnected ) ;
242265 }
243266 }
267+
268+ // Auto-connect online tunnels that aren't connected yet.
269+ // On web there is no workspace picker to trigger manual connection,
270+ // so we connect eagerly when a tunnel is discovered and online.
271+ if ( isWeb ) {
272+ for ( const tunnel of onlineTunnels ) {
273+ if ( tunnel . hostConnectionCount > 0 ) {
274+ const address = `${ TUNNEL_ADDRESS_PREFIX } ${ tunnel . tunnelId } ` ;
275+ const alreadyConnected = this . _remoteAgentHostService . connections . some (
276+ c => c . address === address && c . status === RemoteAgentHostConnectionStatus . Connected
277+ ) ;
278+ if ( ! alreadyConnected ) {
279+ this . _connectTunnel ( address ) ;
280+ }
281+ }
282+ }
283+ }
244284 }
245285 }
246286}
0 commit comments