copilotApiService.ts ×9

Frontier kind: Code frontier

unlabeled · c_fad960b36f92

88 tests · 20100 LOC · 84 files · introduces 0 tests · 76 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
9 ranges76 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1585 ranges20100 lines · 84 files · Browse complete extent
All tests (intent)
88 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 76 introduced LOC across 9 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/shared/copilotApiService.ts 76 introduced LOC · 9 ranges

Open complete file

744
745 private _getCapiBase(): Promise<ICapiBase> {
746 > if (!this._capiBasePromise) { copilotApiService.ts
747 > this._capiBasePromise = this._buildCapiBase().catch(err => {
748 this._capiBasePromise = null;
749 throw err;
751 > }
752 > return this._capiBasePromise;
753 > }
754
755 private async _buildCapiBase(): Promise<ICapiBase> {
756 > const [machineId, deviceId] = await Promise.all([ copilotApiService.ts
757 > getMachineId(err => this._logService.warn('[CopilotApiService] getMachineId failed', err)),
758 > getDevDeviceId(err => this._logService.warn('[CopilotApiService] getDevDeviceId failed', err)),
759 > ]);
760 >
761 > const extensionInfo: IExtensionInformation = {
762 > name: 'agent-host',
763 > sessionId: generateUuid(),
764 > machineId,
765 > deviceId,
766 > vscodeVersion: this._productService.version,
767 > version: this._productService.version,
768 > buildType: this._productService.quality === 'stable' ? 'prod' : 'dev',
769 > };
770 >
771 > // Copilot endpoint discovery: GET `/copilot_internal/user` on the GitHub API
772 > // host. For GitHub Enterprise the host is derived from `githubEnterpriseUri`
773 > // (via the endpoint service); the response's `endpoints.api` then carries the
774 > // enterprise CAPI base that CAPIClient routes through. Defaults to
775 > // api.github.com when no enterprise URI is set. (GHE Cloud `*.ghe.com` is
776 > // handled; GHE Server on-prem `/copilot_internal` routing is unverified.)
777 > const userUrl = `${this._gitHubEndpointService.getApiBaseUri()}/copilot_internal/user`;
778 >
779 > return { extensionInfo, userUrl };
780 > }
781
782 // #endregion
924
925 private _getEntryForToken(githubToken: string): Promise<ICachedClient> {
926 > const nowSeconds = Date.now() / 1000; copilotApiService.ts
927 > const existing = this._clientsByToken.get(githubToken);
928 > if (existing) {
929 return existing.then(entry => {
930 if (entry.expiresAt - nowSeconds > CAPI_CONTEXT_REFRESH_BUFFER_SECONDS) {
940 });
941 }
943 > // Omit the caller's signal here: a deduped build is shared across
944 > // concurrent callers, so aborting one must not cancel it for the
945 > // others. Each caller still forwards its signal to the API call.
946 > const pending = this._buildClientForToken(githubToken).catch(err => {
947 this._clientsByToken.delete(githubToken);
948 throw err;
950 > this._clientsByToken.set(githubToken, pending);
951 > return pending;
952 > }
953
954 private _invalidateClientForToken(githubToken: string): void {
957
958 private async _buildClientForToken(githubToken: string): Promise<ICachedClient> {
959 > const { extensionInfo, userUrl } = await this._getCapiBase(); copilotApiService.ts
960 > const fetch = this._fetch;
961 > const capiClient = new CAPIClient(extensionInfo, COPILOT_LICENSE_AGREEMENT, {
962 > fetch: (url, options) => fetch(url, {
963 method: options.method ?? 'GET',
964 headers: options.headers,
966 signal: options.signal as AbortSignal | undefined,
967 }),
969 >
970 > this._logService.debug('[CopilotApiService] Discovering CAPI endpoints via /copilot_internal/user');
971 >
972 > // Test/debug override: skip api.github.com discovery for an allowed local
973 > // or smoke-proxy URL. Every other non-loopback value is ignored because
974 > // subsequent CAPI calls carry the GitHub bearer token.
975 > const overrideApi = process.env[CAPI_URL_OVERRIDE_ENV];
976 > if (overrideApi) {
977 if (isAllowedCapiUrlOverride(overrideApi)) {
978 this._logService.info(`[CopilotApiService] Using CAPI URL override ${overrideApi}; skipping endpoint discovery`);
1004
1005 capiClient.updateDomains(
1006 > { endpoints: envelope.endpoints ?? {}, sku: envelope.access_type_sku ?? '' }, copilotApiService.ts
1007 > // Enterprise base URI (e.g. `https://acme.ghe.com`), or `undefined` for
1008 > // github.com. The package derives the GitHub API host (`api.<host>`) from
1009 > // this for `copilot_internal` endpoints - notably the Copilot session
1010 > // token mint (`/copilot_internal/v2/token`). Omitting it strands the mint
1011 > // on `api.github.com`, which 401s an enterprise token ("Bad credentials").
1012 > this._gitHubEndpointService.getEnterpriseUri(),
1013 > );
1014 >
1015 > this._logService.debug('[CopilotApiService] CAPI endpoint discovered, api=', envelope.endpoints?.api);
1016 >
1017 > return {
1018 > capiClient,
1019 > expiresAt: Date.now() / 1000 + CAPI_CONTEXT_TTL_SECONDS,
1020 > login: envelope.login,
1021 > telemetryEndpoint: envelope.endpoints?.telemetry,
1022 > apiEndpoint: envelope.endpoints?.api,
1023 > copilotIgnoreEnabled: envelope.copilotignore_enabled,
1024 > };
1025 > }
1026
1027 // #endregion