src/vs/platform/agentHost/common/githubEndpoints.ts
125 LOC · 121 covered · 4 uncovered · 20 ranges · 2609 concepts · 10 introducers · 1277 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
githubEndpoints.ts ×4
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from '../../../base/common/uri.js';
import { ProtectedResourceMetadata } from './state/protocol/state.js';
/**
* The GitHub endpoints an agent host talks to, derived from an optional
* GitHub Enterprise base URI. All values are string URIs with no trailing slash.
*/
export interface IGitHubEndpoints {
/** REST API base (e.g. `https://api.github.com`), used as the resource identifier and the REST host. */
readonly apiBaseUri: string;
/** GraphQL endpoint (distinct from `apiBaseUri` for on-prem: `/api/graphql`, not `/api/v3/graphql`). */
readonly graphQlUri: string;
/** OAuth authorization server URI, advertised in `authorization_servers`. */
readonly oauthServer: string;
/**
* The configured GitHub Enterprise host (authority only, e.g. `acme.ghe.com`),
* or `undefined` for github.com. Used to point the Copilot CLI at an enterprise
* host via `COPILOT_GH_HOST`.
*/
readonly enterpriseHost: string | undefined;
}
const GITHUB_DOT_COM_COPILOT_API_BASE_URI = 'https://api.githubcopilot.com';
/** Canonical github.com endpoints, used when no enterprise URI is configured. */
const GITHUB_DOT_COM_ENDPOINTS: IGitHubEndpoints = {
apiBaseUri: 'https://api.github.com',
graphQlUri: 'https://api.github.com/graphql',
oauthServer: 'https://github.com/login/oauth',
enterpriseHost: undefined,
};
/**
* Derives the {@link IGitHubEndpoints} for a GitHub Enterprise base URI, mirroring
* the URL derivation in the built-in `github-authentication` extension
* (`githubServer.ts` / `common/env.ts`):
*
* - unset / empty / unparseable → github.com defaults (byte-for-byte, preserving
* the resource identifiers used by every non-enterprise install).
* - GitHub Enterprise **Cloud** (authority ends in `.ghe.com`) → API on an `api.`
* subdomain: `https://api.<authority>`.
* - GitHub Enterprise **Server** (on-prem) → API under `/api/v3`, GraphQL under
* `/api/graphql`.
*
* The OAuth server is always `<scheme>://<authority>/login/oauth` for enterprise.
*/
export function deriveGitHubEndpoints(enterpriseUri: string | undefined): IGitHubEndpoints {
}
let uri: URI;
try {
uri = URI.parse(enterpriseUri);
} catch {
return GITHUB_DOT_COM_ENDPOINTS;
}
const authority = uri.authority;
if (!authority) {
}
// A github.com authority is never a GitHub Enterprise host — treat it as the
// default rather than deriving a nonsensical `github.com/api/v3`. Guards the
// case where the enterprise host can't be resolved and falls back to github.com.
if (authority === 'github.com' || authority === 'www.github.com' || authority === 'api.github.com') {
githubEndpoints.ts ×3
}
const scheme = uri.scheme || 'https';
return {
apiBaseUri: isCloud ? `${scheme}://api.${authority}` : `${scheme}://${authority}/api/v3`,
graphQlUri: isCloud ? `${scheme}://api.${authority}/graphql` : `${scheme}://${authority}/api/graphql`,
oauthServer: `${scheme}://${authority}/login/oauth`,
enterpriseHost: authority,
};
}
/**
* Derives the official GitHub MCP server URL from the per-user Copilot API
* endpoint returned by `/copilot_internal/user`.
*/
export function gitHubMcpServerUrl(copilotApiBaseUri: string | undefined): string | undefined {
const uri = URI.parse(copilotApiBaseUri ?? GITHUB_DOT_COM_COPILOT_API_BASE_URI, true);
if (!uri.authority) {
return undefined;
}
return uri.with({ path: '/mcp', query: null, fragment: null }).toString(true);
githubEndpoints.ts ×3
} catch {
}
/**
* The GitHub Copilot protected resource for the given endpoints. Shared by the
* endpoint service and tests so the resource identity is defined once.
*/
export function gitHubCopilotResource(endpoints: IGitHubEndpoints): ProtectedResourceMetadata {
resource: endpoints.apiBaseUri,
resource_name: 'GitHub Copilot',
authorization_servers: [endpoints.oauthServer],
scopes_supported: ['read:user', 'user:email'],
required: true,
};
}
/** The GitHub repository protected resource for the given endpoints. */
export function gitHubRepoResource(endpoints: IGitHubEndpoints): ProtectedResourceMetadata {
resource: `${endpoints.apiBaseUri}/repos`,
resource_name: 'GitHub Repository',
authorization_servers: [endpoints.oauthServer],
scopes_supported: ['repo'],
required: false,
};
}