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
>
6
>
import { Emitter, Event } from '../../../base/common/event.js';
7
>
import { Disposable } from '../../../base/common/lifecycle.js';
8
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
9
>
import { ILogService } from '../../log/common/log.js';
10
>
import { AgentHostConfigKey, agentHostCustomizationConfigSchema } from '../common/agentHostCustomizationConfig.js';
11
>
import { deriveGitHubEndpoints, gitHubCopilotResource, gitHubRepoResource, IGitHubEndpoints } from '../common/githubEndpoints.js';
12
>
import { ProtectedResourceMetadata } from '../common/state/protocol/state.js';
13
>
import { IAgentConfigurationService } from './agentConfigurationService.js';
14
>
15
>
export const IAgentHostGitHubEndpointService = createDecorator<IAgentHostGitHubEndpointService>('agentHostGitHubEndpointService');
16
>
17
>
/**
18
>
* Single source of truth for the GitHub endpoints (protected resources + REST /
19
>
* GraphQL hosts) the agent host talks to. Computed from the optional
20
>
* `githubEnterpriseUri` root config so that every consumer — agent
21
>
* `authenticate` / `getProtectedResources`, changeset operation `getAuthToken`
22
>
* lookups, and the REST client — agrees on the same resource identifiers and API
23
>
* base. With no enterprise URI configured, the values are byte-for-byte the
24
>
* github.com defaults.
25
>
*/
26
>
export interface IAgentHostGitHubEndpointService {
27
>
readonly _serviceBrand: undefined;
28
>
29
>
/**
30
>
* Fires when the configured GitHub endpoints change (e.g. `githubEnterpriseUri`
31
>
* was set, cleared, or repointed). Does NOT fire for unrelated root-config
32
>
* changes.
33
>
*/
34
>
readonly onDidChange: Event<void>;
35
>
36
>
/** The GitHub Copilot protected resource, computed against the configured endpoints. */
37
>
getCopilotResource(): ProtectedResourceMetadata;
38
>
39
>
/** The GitHub repository protected resource, computed against the configured endpoints. */
40
>
getRepoResource(): ProtectedResourceMetadata;
41
>
42
>
/** The REST API base URI (no trailing slash), e.g. `https://api.github.com`. */
43
>
getApiBaseUri(): string;
44
>
45
>
/** The GraphQL endpoint URI, e.g. `https://api.github.com/graphql`. */
46
>
getGraphQlUri(): string;
47
>
48
>
/**
49
>
* The configured GitHub Enterprise host (authority only, e.g. `acme.ghe.com`),
50
>
* or `undefined` for github.com. Used to set `COPILOT_GH_HOST` for the Copilot CLI.
51
>
*/
52
>
getEnterpriseHost(): string | undefined;
53
>
54
>
/**
55
>
* The raw configured GitHub Enterprise base URI (e.g. `https://acme.ghe.com`),
56
>
* or `undefined` for github.com. This is the value the `@vscode/copilot-api`
57
>
* `CAPIClient.updateDomains(..., enterpriseUrlConfig)` expects: it derives the
58
>
* GitHub API host (`api.<host>`) used for `copilot_internal` endpoints (token
59
>
* mint, etc.) from it. Distinct from {@link getApiBaseUri} (the already-derived
60
>
* `api.` host) - the package does that derivation itself.
61
>
*/
62
>
getEnterpriseUri(): string | undefined;
63
>
}
64
>
65
>
export class AgentHostGitHubEndpointService extends Disposable implements IAgentHostGitHubEndpointService {
66
>
67
>
declare readonly _serviceBrand: undefined;
68
>
69
>
private readonly _onDidChange = this._register(new Emitter<void>());
70
>
readonly onDidChange = this._onDidChange.event;
71
>
72
>
private _endpoints: IGitHubEndpoints;
73
>
private _enterpriseUri: string | undefined;
74
>
75
>
constructor(
76
@IAgentConfigurationService private readonly _configurationService: IAgentConfigurationService,
77
@ILogService private readonly _logService: ILogService,