Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/authentication/common/copilotTokenStore.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import { createServiceIdentifier } from '../../../util/common/services';
6
import { Emitter, Event } from '../../../util/vs/base/common/event';
7
import { Disposable } from '../../../util/vs/base/common/lifecycle';
8
import type { CopilotToken } from './copilotToken';
9
10
11
export const ICopilotTokenStore = createServiceIdentifier<ICopilotTokenStore>('ICopilotTokenStore');
12
13
/**
14
* A simple store that holds the Copilot Token. This is used in the networking & telemetry
15
* services to avoid cyclical dependencies with the auth service.
16
* @important Please use the `IAuthenticationService` for any other usecase.
17
*/
18
export interface ICopilotTokenStore {
19
readonly _serviceBrand: undefined;
20
copilotToken: CopilotToken | undefined;
21
onDidStoreUpdate: Event<void>;
22
}
23
24
export class CopilotTokenStore extends Disposable implements ICopilotTokenStore {
25
declare readonly _serviceBrand: undefined;
26
private _copilotToken: CopilotToken | undefined;
27
private readonly _onDidStoreUpdate = this._register(new Emitter<void>());
28
onDidStoreUpdate: Event<void> = this._onDidStoreUpdate.event;
29
30
get copilotToken(): CopilotToken | undefined {
31
return this._copilotToken;
32
}
33
set copilotToken(token: CopilotToken | undefined) {
34
const oldToken = this._copilotToken?.token;
35
this._copilotToken = token;
36
if (oldToken !== token?.token) {
37
this._onDidStoreUpdate.fire();
38
}
39
}
40
}
41
42