Path: blob/main/extensions/copilot/src/platform/authentication/common/copilotTokenStore.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*--------------------------------------------------------------------------------------------*/4import { createServiceIdentifier } from '../../../util/common/services';5import { Emitter, Event } from '../../../util/vs/base/common/event';6import { Disposable } from '../../../util/vs/base/common/lifecycle';7import type { CopilotToken } from './copilotToken';8910export const ICopilotTokenStore = createServiceIdentifier<ICopilotTokenStore>('ICopilotTokenStore');1112/**13* A simple store that holds the Copilot Token. This is used in the networking & telemetry14* services to avoid cyclical dependencies with the auth service.15* @important Please use the `IAuthenticationService` for any other usecase.16*/17export interface ICopilotTokenStore {18readonly _serviceBrand: undefined;19copilotToken: CopilotToken | undefined;20onDidStoreUpdate: Event<void>;21}2223export class CopilotTokenStore extends Disposable implements ICopilotTokenStore {24declare readonly _serviceBrand: undefined;25private _copilotToken: CopilotToken | undefined;26private readonly _onDidStoreUpdate = this._register(new Emitter<void>());27onDidStoreUpdate: Event<void> = this._onDidStoreUpdate.event;2829get copilotToken(): CopilotToken | undefined {30return this._copilotToken;31}32set copilotToken(token: CopilotToken | undefined) {33const oldToken = this._copilotToken?.token;34this._copilotToken = token;35if (oldToken !== token?.token) {36this._onDidStoreUpdate.fire();37}38}39}404142