Skip to content

Commit 8bae860

Browse files
osortegarebornix
andauthored
Agent web: Build system for agent sessions and fixes (#310202)
* Build system for agent sessions * Discovery fixes * better npe fix. --------- Co-authored-by: Peng Lyu <penn.lv@gmail.com>
1 parent f563e5b commit 8bae860

6 files changed

Lines changed: 69 additions & 0 deletions

File tree

build/buildfile.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export const workbenchDesktop = [
3333

3434
export const workbenchWeb = createModuleDescription('vs/workbench/workbench.web.main.internal');
3535

36+
export const sessionsWeb = createModuleDescription('vs/sessions/sessions.web.main.internal');
37+
3638
export const keyboardMaps = [
3739
createModuleDescription('vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.linux'),
3840
createModuleDescription('vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.darwin'),
@@ -73,6 +75,7 @@ const buildfile = {
7375
workerBackgroundTokenization,
7476
workbenchDesktop,
7577
workbenchWeb,
78+
sessionsWeb,
7679
keyboardMaps,
7780
code,
7881
codeWeb,

build/gulpfile.vscode.web.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const vscodeWebEntryPoints = [
116116
buildfile.workerBackgroundTokenization,
117117
buildfile.keyboardMaps,
118118
buildfile.workbenchWeb,
119+
buildfile.sessionsWeb,
119120
].flat();
120121

121122
/**

build/lib/mangle/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ const skippedExportMangledFiles = [
321321
buildfile.workerBackgroundTokenization,
322322
buildfile.workbenchDesktop,
323323
buildfile.workbenchWeb,
324+
buildfile.sessionsWeb,
324325
buildfile.code,
325326
buildfile.codeWeb
326327
].flat().map(x => x.name),

build/next/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ const webEntryPoints = [
119119
'vs/code/browser/workbench/workbench',
120120
];
121121

122+
// Additional web-only entry points (CDN build only, not in server-web)
123+
const webOnlyEntryPoints = [
124+
'vs/sessions/sessions.web.main.internal',
125+
];
126+
122127
const keyboardMapEntryPoints = [
123128
'vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.linux',
124129
'vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.darwin',
@@ -173,6 +178,7 @@ function getEntryPointsForTarget(target: BuildTarget): string[] {
173178
case 'web':
174179
return [
175180
...workerEntryPoints,
181+
...webOnlyEntryPoints,
176182
'vs/workbench/workbench.web.main.internal', // web workbench only (no browser shell)
177183
...keyboardMapEntryPoints,
178184
];
@@ -220,6 +226,7 @@ function getCssBundleEntryPointsForTarget(target: BuildTarget): Set<string> {
220226
case 'web':
221227
return new Set([
222228
'vs/workbench/workbench.web.main.internal',
229+
'vs/sessions/sessions.web.main.internal',
223230
]);
224231
default:
225232
throw new Error(`Unknown target: ${target}`);

src/vs/sessions/contrib/remoteAgentHost/browser/tunnelAgentHost.contribution.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Disposable, DisposableMap, DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js';
7+
import { isWeb } from '../../../../base/common/platform.js';
78
import * as nls from '../../../../nls.js';
89
import { IRemoteAgentHostService, RemoteAgentHostConnectionStatus, RemoteAgentHostsEnabledSettingId } from '../../../../platform/agentHost/common/remoteAgentHostService.js';
910
import { ITunnelAgentHostService, TUNNEL_ADDRESS_PREFIX, type ITunnelInfo } from '../../../../platform/agentHost/common/tunnelAgentHost.js';
1011
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
1112
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
13+
import { ILogService } from '../../../../platform/log/common/log.js';
1214
import { INotificationService, Severity } from '../../../../platform/notification/common/notification.js';
1315
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../../workbench/common/contributions.js';
16+
import { IAuthenticationService } from '../../../../workbench/services/authentication/common/authentication.js';
1417
import { ISessionsProvidersService } from '../../../services/sessions/browser/sessionsProvidersService.js';
1518
import { 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
}

src/vs/workbench/contrib/chat/common/customizationHarnessService.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ const EMPTY_FILTER: IStorageSourceFilter = {
269269
sources: [],
270270
};
271271

272+
/**
273+
* Empty descriptor returned when no harness is registered yet.
274+
*/
275+
const EMPTY_DESCRIPTOR: IHarnessDescriptor = {
276+
id: '',
277+
label: '',
278+
icon: Codicon.sparkle,
279+
getStorageSourceFilter: () => ({ sources: [] }),
280+
};
281+
282+
272283
/**
273284
* Hooks filter — local, user, and plugin sources.
274285
*/
@@ -502,13 +513,19 @@ export class CustomizationHarnessServiceBase implements ICustomizationHarnessSer
502513
getStorageSourceFilter(type: PromptsType): IStorageSourceFilter {
503514
const activeId = this._activeHarness.get();
504515
const all = this._getAllHarnesses();
516+
if (all.length === 0) {
517+
return EMPTY_FILTER;
518+
}
505519
const descriptor = all.find(h => h.id === activeId) ?? all[0];
506520
return descriptor?.getStorageSourceFilter(type) ?? EMPTY_FILTER;
507521
}
508522

509523
getActiveDescriptor(): IHarnessDescriptor {
510524
const activeId = this._activeHarness.get();
511525
const all = this._getAllHarnesses();
526+
if (all.length === 0) {
527+
return EMPTY_DESCRIPTOR;
528+
}
512529
return all.find(h => h.id === activeId) ?? all[0];
513530
}
514531
}

0 commit comments

Comments
 (0)