import { joinPath } from '../../base/common/resources.js';
import { onUnexpectedError } from '../../base/common/errors.js';
import { ServiceCollection } from '../../platform/instantiation/common/serviceCollection.js';
import { ILogService } from '../../platform/log/common/log.js';
import { IRemoteAuthorityResolverService } from '../../platform/remote/common/remoteAuthorityResolver.js';
import { IStorageService } from '../../platform/storage/common/storage.js';
import { IUriIdentityService } from '../../platform/uriIdentity/common/uriIdentity.js';
import { IAnyWorkspaceIdentifier, IWorkspaceContextService } from '../../platform/workspace/common/workspace.js';
import { IWorkspaceTrustEnablementService, IWorkspaceTrustManagementService } from '../../platform/workspace/common/workspaceTrust.js';
import { IBrowserWorkbenchEnvironmentService } from '../../workbench/services/environment/browser/environmentService.js';
import { IWorkbenchConfigurationService } from '../../workbench/services/configuration/common/configuration.js';
import { IUserDataProfileService } from '../../workbench/services/userDataProfile/common/userDataProfile.js';
import { BrowserUserDataProfilesService } from '../../platform/userDataProfile/browser/userDataProfile.js';
import { FileService } from '../../platform/files/common/fileService.js';
import { IPolicyService } from '../../platform/policy/common/policy.js';
import { IRemoteAgentService } from '../../workbench/services/remote/common/remoteAgentService.js';
import { IWorkspaceEditingService } from '../../workbench/services/workspaces/common/workspaceEditing.js';
import { WorkspaceTrustEnablementService, WorkspaceTrustManagementService } from '../../workbench/services/workspaces/common/workspaceTrust.js';
import { BrowserMain, IBrowserMainWorkbench } from '../../workbench/browser/web.main.js';
import { getWorkspaceIdentifier } from '../../workbench/services/workspaces/browser/workspaces.js';
import { SessionsWorkspaceContextService } from '../services/workspace/browser/workspaceContextService.js';
import { ConfigurationService } from '../services/configuration/browser/configurationService.js';
import { Workbench as SessionsWorkbench } from './workbench.js';
export class SessionsBrowserMain extends BrowserMain {
protected override createWorkbench(domElement: HTMLElement, serviceCollection: ServiceCollection, logService: ILogService): IBrowserMainWorkbench {
return new SessionsWorkbench(domElement, undefined, serviceCollection, logService);
}
protected override async createWorkspaceConfigAndStorageServices(
serviceCollection: ServiceCollection,
_workspace: IAnyWorkspaceIdentifier,
environmentService: IBrowserWorkbenchEnvironmentService,
userDataProfileService: IUserDataProfileService,
_userDataProfilesService: BrowserUserDataProfilesService,
fileService: FileService,
_remoteAgentService: IRemoteAgentService,
uriIdentityService: IUriIdentityService,
policyService: IPolicyService,
logService: ILogService,
remoteAuthorityResolverService: IRemoteAuthorityResolverService,
): Promise<{ configurationService: IWorkbenchConfigurationService; storageService: IStorageService }> {
const sessionsWorkspaceUri = joinPath(environmentService.userRoamingDataHome, 'agent-sessions.code-workspace');
const workspaceIdentifier = getWorkspaceIdentifier(sessionsWorkspaceUri);
const workspaceContextService = new SessionsWorkspaceContextService(workspaceIdentifier, uriIdentityService);
serviceCollection.set(IWorkspaceContextService, workspaceContextService);
serviceCollection.set(IWorkspaceEditingService, workspaceContextService);
const configurationService = new ConfigurationService(
userDataProfileService,
workspaceContextService,
uriIdentityService,
fileService,
policyService,
logService
);
try {
await configurationService.initialize();
} catch (error) {
onUnexpectedError(error);
}
serviceCollection.set(IWorkbenchConfigurationService, configurationService);
const storageService = await this.createStorageService(workspaceIdentifier, logService, userDataProfileService);
serviceCollection.set(IStorageService, storageService);
const workspaceTrustEnablementService = new WorkspaceTrustEnablementService(configurationService, environmentService);
serviceCollection.set(IWorkspaceTrustEnablementService, workspaceTrustEnablementService);
const workspaceTrustManagementService = new WorkspaceTrustManagementService(configurationService, remoteAuthorityResolverService, storageService, uriIdentityService, environmentService, workspaceContextService, workspaceTrustEnablementService, fileService);
serviceCollection.set(IWorkspaceTrustManagementService, workspaceTrustManagementService);
return { configurationService, storageService };
}
}