copilotApiService.ts ×9

Frontier kind: Joint frontier

unlabeled · c_60569016be80

1 test · 20211 LOC · 84 files · introduces 1 test · 69 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
9 ranges69 lines · 1 files
Tests
1 test

Contains — complete concept membership

All code (extent)
1607 ranges20211 lines · 84 files · Browse complete extent
All tests (intent)
1 testBrowse 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.

1 test introduced at this concept.

Introduced code

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

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

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

Open complete file

896 */
897 async resolveRestrictedTelemetryContext(githubToken: string): Promise<IRestrictedTelemetryContext> {
898 > const token = await this._getCopilotTokenEntry(githubToken); copilotApiService.ts
899 > const client = await this._getEntryForToken(githubToken);
900 > const fields = parseCopilotTokenFields(token.token);
901 > const restrictedTelemetryEnabled = fields.get('rt') === '1';
902 > const trackingId = fields.get('tid');
903 > const telemetryEndpoint = restrictedTelemetryEnabled
904 > ? client.telemetryEndpoint
905 : undefined;
906 > return { copilotApiService.ts
907 > restrictedTelemetryEnabled,
908 > trackingId,
909 > telemetryEndpoint,
910 > isInternal: token.isInternal,
911 > userName: client.login,
912 > isVscodeTeamMember: token.isVscodeTeamMember,
913 > copilotIgnoreEnabled: client.copilotIgnoreEnabled,
914 > };
915 > }
916
917 async resolveApiEndpoint(githubToken: string): Promise<string | undefined> {
1041
1042 private _getCopilotTokenEntry(githubToken: string): Promise<ICachedCopilotToken> {
1043 > const nowSeconds = Date.now() / 1000; copilotApiService.ts
1044 > const existing = this._copilotTokensByGithub.get(githubToken);
1045 > if (existing) {
1046 return existing.then(entry => {
1047 if (entry.expiresAt - nowSeconds > COPILOT_TOKEN_REFRESH_BUFFER_SECONDS) {
1063 });
1064 }
1066 > const pending: Promise<ICachedCopilotToken> = this._buildCopilotToken(githubToken).catch(err => {
1067 if (this._copilotTokensByGithub.get(githubToken) === pending) {
1068 this._copilotTokensByGithub.delete(githubToken);
1069 }
1070 throw err;
1072 > this._copilotTokensByGithub.set(githubToken, pending);
1073 > return pending;
1074 > }
1075
1076 private _invalidateCopilotTokenForGithub(githubToken: string): void {
1079
1080 private async _buildCopilotToken(githubToken: string): Promise<ICachedCopilotToken> {
1081 > const capiClient = await this._getClientForToken(githubToken); copilotApiService.ts
1082 >
1083 > this._logService.debug('[CopilotApiService] Minting Copilot session token');
1084 >
1085 > const response = await capiClient.makeRequest<Response>(
1086 > {
1087 > method: 'GET',
1088 > headers: {
1089 > 'Authorization': `token ${githubToken}`,
1090 > 'X-GitHub-Api-Version': USER_API_VERSION,
1091 > },
1092 > },
1093 > { type: RequestType.CopilotToken },
1094 > );
1095 >
1096 > if (!response.ok) {
1097 const text = await response.text().catch(() => '');
1098 throw new Error(`Copilot session token mint failed: ${response.status} ${response.statusText} \u2014 ${text}`);
1099 }
1101 > const envelope = await response.json() as ICopilotTokenEnvelope;
1102 > if (typeof envelope.token !== 'string' || typeof envelope.expires_at !== 'number') {
1103 throw new Error('Copilot session token mint returned malformed envelope');
1104 }
1106 > // Prefer `now + refresh_in` over the server-reported `expires_at`:
1107 > // users with a fast local clock can see `expires_at` already in the
1108 > // past, which would cause us to re-mint on every call. Mirror what
1109 > // the Copilot Chat extension's `RefreshableCopilotTokenManager`
1110 > // does. Floor at `now + 60s` so a malformed/short `refresh_in`
1111 > // can't trigger a tight re-mint loop.
1112 > const nowSeconds = Date.now() / 1000;
1113 > const refreshIn = typeof envelope.refresh_in === 'number' ? envelope.refresh_in : undefined;
1114 > const organizationList = Array.isArray(envelope.organization_list)
1115 > ? envelope.organization_list.filter((organization): organization is string => typeof organization === 'string')
1116 : [];
1117 > const expiresAt = Math.max( copilotApiService.ts
1118 > refreshIn !== undefined ? nowSeconds + refreshIn : envelope.expires_at,
1119 > nowSeconds + 60,
1120 > );
1121 >
1122 > return {
1123 > token: envelope.token,
1124 > expiresAt,
1125 > modelIdsByFamily: new Map(),
1126 > isInternal: organizationList.some(organization => INTERNAL_COPILOT_ORGANIZATIONS.has(organization)),
1127 > isVscodeTeamMember: organizationList.some(organization => VSCODE_COPILOT_ORGANIZATIONS.has(organization)),
1128 > };
1129 > }
1130
1131 /**