Path: blob/main/extensions/copilot/src/platform/env/common/envService.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type { Event, WindowState } from 'vscode';6import { createServiceIdentifier } from '../../../util/common/services';7import { env } from '../../../util/vs/base/common/process';8import { URI } from '../../../util/vs/base/common/uri';9import { isPreRelease, isProduction, packageJson } from './packagejson';1011export enum OperatingSystem {12Windows = 'Windows',13Macintosh = 'Mac',14Linux = 'Linux'15}161718export class NameAndVersion {19constructor(20readonly name: string,21readonly version: string22) { }2324format(): string {25return `${this.name}/${this.version}`;26}27}282930export const IEnvService = createServiceIdentifier<IEnvService>('IEnvService');3132export interface IEnvService {33readonly _serviceBrand: undefined;34readonly language: string | undefined;35readonly sessionId: string;36readonly machineId: string;37readonly devDeviceId: string;38readonly vscodeVersion: string;39/**40* Whether the current session is considered active41* @see vscode.window.state.active42*/43readonly isActive: boolean;44/**45* @see vscode.env.remoteName46*/47readonly remoteName: string | undefined;48readonly uiKind: 'desktop' | 'web';49readonly OS: OperatingSystem;50readonly uriScheme: string;51readonly extensionId: string;52readonly appRoot: string;53readonly shell: string;54/**55* @see vscode.window.onDidChangeWindowState56*/57readonly onDidChangeWindowState: Event<WindowState>;58isProduction(): boolean;59isPreRelease(): boolean;60isSimulation(): boolean;61getBuildType(): 'prod' | 'dev';62getVersion(): string;63getBuild(): string;64getName(): string;65getEditorInfo(): NameAndVersion;66getEditorPluginInfo(): NameAndVersion;67openExternal(target: URI): Promise<boolean>;68}6970export const INativeEnvService = createServiceIdentifier<INativeEnvService>('INativeEnvService');71export interface INativeEnvService extends IEnvService {72readonly _serviceBrand: undefined;73userHome: URI;74}7576export abstract class AbstractEnvService implements IEnvService {77language: string | undefined;78declare _serviceBrand: undefined;7980abstract get sessionId(): string;81abstract get vscodeVersion(): string;82abstract get extensionId(): string;83abstract get machineId(): string;84abstract get devDeviceId(): string;85abstract get remoteName(): string | undefined;86abstract get uiKind(): 'desktop' | 'web';87abstract get OS(): OperatingSystem;88abstract get uriScheme(): string;89abstract get appRoot(): string;90abstract get shell(): string;91abstract get isActive(): boolean;92abstract get onDidChangeWindowState(): Event<WindowState>;9394/**95* @returns true if this is a build for end users.96*/97isProduction(): boolean {98return isProduction;99}100101isPreRelease(): boolean {102return isPreRelease;103}104105isSimulation(): boolean {106return env['SIMULATION'] === '1';107}108109getBuildType(): 'prod' | 'dev' {110return packageJson.buildType;111}112113getVersion(): string {114return packageJson.version;115}116117getBuild(): string {118return packageJson.build;119}120121getName(): string {122return packageJson.name;123}124125/**126* The name and version of the editor itself.127* `{ name : 'vscode', version: '1.63.2' }`.128*/129abstract getEditorInfo(): NameAndVersion;130131/**132* The name and version of the Copilot chat plugin.133* or `{ name: 'copilot-chat', version: '1.7.21' }`.134*/135abstract getEditorPluginInfo(): NameAndVersion;136137getEditorVersionHeaders(): { [key: string]: string } {138return {139'Editor-Version': this.getEditorInfo().format(),140'Editor-Plugin-Version': this.getEditorPluginInfo().format(),141};142}143144abstract openExternal(target: URI): Promise<boolean>;145}146147// FIXME: This needs to be used in locations where the EnvService is not yet available, so it's148// not part of the env service itself.149export const isScenarioAutomation = env['IS_SCENARIO_AUTOMATION'] === '1';150151