Skip to content

Commit 6731ce5

Browse files
Copilotalexr00
andcommitted
Fix avatar display in comment widget for GitHub Enterprise
Apply isGitHubDotComAvatar check to comment widget code to prevent broken avatar display for GitHub Enterprise users. For enterprise avatars (non-githubusercontent.com URLs), skip fetching the avatar and show no icon instead of a broken image. Fixes: - setReplyAuthor() in utils.ts (reply area avatar) - TemporaryComment constructor in prComment.ts - GHPRComment constructor in prComment.ts Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 6752d71 commit 6731ce5

File tree

5 files changed

+23
-102
lines changed

5 files changed

+23
-102
lines changed

src/@types/vscode.proposed.chatParticipantAdditions.d.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,6 @@ declare module 'vscode' {
223223
};
224224
language: string;
225225

226-
/**
227-
* Overrides for how the command is presented in the UI.
228-
* For example, when a `cd <dir> && <command>` prefix is detected,
229-
* the presentation can show only the actual command.
230-
*/
231-
presentationOverrides?: {
232-
commandLine: string;
233-
language?: string;
234-
};
235-
236226
/**
237227
* Terminal command output. Displayed when the terminal is no longer available.
238228
*/
@@ -1030,6 +1020,8 @@ declare module 'vscode' {
10301020
readonly rawInput?: unknown;
10311021

10321022
readonly chatRequestId?: string;
1023+
/** @deprecated Use {@link chatSessionResource} instead */
1024+
readonly chatSessionId?: string;
10331025
readonly chatSessionResource?: Uri;
10341026
readonly chatInteractionId?: string;
10351027
}
@@ -1063,9 +1055,5 @@ declare module 'vscode' {
10631055
readonly content: string;
10641056
readonly toolReferences?: readonly ChatLanguageModelToolReference[];
10651057
readonly metadata?: Record<string, boolean | string | number>;
1066-
/**
1067-
* Whether the mode is a builtin mode (e.g. Ask, Edit, Agent) rather than a user or extension-defined custom mode.
1068-
*/
1069-
readonly isBuiltin?: boolean;
10701058
}
10711059
}

src/@types/vscode.proposed.chatParticipantPrivate.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,10 @@ declare module 'vscode' {
176176
*/
177177
readonly editedFileEvents?: ChatRequestEditedFileEvent[];
178178

179-
/**
180-
* The identifier of the language model that was used for this request, if known.
181-
*/
182-
readonly modelId?: string;
183-
184179
/**
185180
* @hidden
186181
*/
187-
constructor(prompt: string, command: string | undefined, references: ChatPromptReference[], participant: string, toolReferences: ChatLanguageModelToolReference[], editedFileEvents: ChatRequestEditedFileEvent[] | undefined, id: string | undefined, modelId: string | undefined);
182+
constructor(prompt: string, command: string | undefined, references: ChatPromptReference[], participant: string, toolReferences: ChatLanguageModelToolReference[], editedFileEvents: ChatRequestEditedFileEvent[] | undefined, id: string | undefined);
188183
}
189184

190185
export class ChatResponseTurn2 {
@@ -267,6 +262,8 @@ declare module 'vscode' {
267262

268263
export interface LanguageModelToolInvocationOptions<T> {
269264
chatRequestId?: string;
265+
/** @deprecated Use {@link chatSessionResource} instead */
266+
chatSessionId?: string;
270267
chatSessionResource?: Uri;
271268
chatInteractionId?: string;
272269
terminalCommand?: string;
@@ -292,6 +289,8 @@ declare module 'vscode' {
292289
*/
293290
input: T;
294291
chatRequestId?: string;
292+
/** @deprecated Use {@link chatSessionResource} instead */
293+
chatSessionId?: string;
295294
chatSessionResource?: Uri;
296295
chatInteractionId?: string;
297296
/**

src/@types/vscode.proposed.chatSessionsProvider.d.ts

Lines changed: 9 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ declare module 'vscode' {
3535
/**
3636
* Registers a new {@link ChatSessionItemProvider chat session item provider}.
3737
*
38-
* @deprecated Use {@linkcode createChatSessionItemController} instead.
39-
*
4038
* To use this, also make sure to also add `chatSessions` contribution in the `package.json`.
4139
*
4240
* @param chatSessionType The type of chat session the provider is for.
@@ -48,21 +46,12 @@ declare module 'vscode' {
4846

4947
/**
5048
* Creates a new {@link ChatSessionItemController chat session item controller} with the given unique identifier.
51-
*
52-
* To use this, also make sure to also add `chatSessions` contribution in the `package.json`.
53-
*
54-
* @param chatSessionType The type of chat session the provider is for.
55-
* @param refreshHandler The controller's {@link ChatSessionItemController.refreshHandler refresh handler}.
56-
*
57-
* @returns A new controller instance that can be used to manage chat session items for the given chat session type.
5849
*/
59-
export function createChatSessionItemController(chatSessionType: string, refreshHandler: ChatSessionItemControllerRefreshHandler): ChatSessionItemController;
50+
export function createChatSessionItemController(id: string, refreshHandler: (token: CancellationToken) => Thenable<void>): ChatSessionItemController;
6051
}
6152

6253
/**
6354
* Provides a list of information about chat sessions.
64-
*
65-
* @deprecated Use {@linkcode ChatSessionItemController} instead.
6655
*/
6756
export interface ChatSessionItemProvider {
6857
/**
@@ -88,21 +77,7 @@ declare module 'vscode' {
8877
}
8978

9079
/**
91-
* Extension callback invoked to refresh the collection of chat session items for a {@linkcode ChatSessionItemController}.
92-
*/
93-
export type ChatSessionItemControllerRefreshHandler = (token: CancellationToken) => Thenable<void>;
94-
95-
export interface ChatSessionItemControllerNewItemHandlerContext {
96-
readonly request: ChatRequest;
97-
}
98-
99-
/**
100-
* Extension callback invoked when a new chat session is started.
101-
*/
102-
export type ChatSessionItemControllerNewItemHandler = (context: ChatSessionItemControllerNewItemHandlerContext, token: CancellationToken) => Thenable<ChatSessionItem>;
103-
104-
/**
105-
* Manages chat sessions for a specific chat session type
80+
* Provides a list of information about chat sessions.
10681
*/
10782
export interface ChatSessionItemController {
10883
readonly id: string;
@@ -118,7 +93,7 @@ declare module 'vscode' {
11893
readonly items: ChatSessionItemCollection;
11994

12095
/**
121-
* Creates a new managed chat session item that can be added to the collection.
96+
* Creates a new managed chat session item that be added to the collection.
12297
*/
12398
createChatSessionItem(resource: Uri, label: string): ChatSessionItem;
12499

@@ -127,16 +102,7 @@ declare module 'vscode' {
127102
*
128103
* This is also called on first load to get the initial set of items.
129104
*/
130-
readonly refreshHandler: ChatSessionItemControllerRefreshHandler;
131-
132-
/**
133-
* Invoked when a new chat session is started.
134-
*
135-
* This allows the controller to initialize the chat session item with information from the initial request.
136-
*
137-
* The returned chat session is added to the collection and shown in the UI.
138-
*/
139-
newChatSessionItemHandler?: ChatSessionItemControllerNewItemHandler;
105+
readonly refreshHandler: (token: CancellationToken) => Thenable<void>;
140106

141107
/**
142108
* Fired when an item's archived state changes.
@@ -155,8 +121,7 @@ declare module 'vscode' {
155121

156122
/**
157123
* Replaces the items stored by the collection.
158-
*
159-
* @param items Items to store. If two items have the same resource URI, the last one will be used.
124+
* @param items Items to store.
160125
*/
161126
replace(items: readonly ChatSessionItem[]): void;
162127

@@ -171,42 +136,31 @@ declare module 'vscode' {
171136
/**
172137
* Adds the chat session item to the collection. If an item with the same resource URI already
173138
* exists, it'll be replaced.
174-
*
175139
* @param item Item to add.
176140
*/
177141
add(item: ChatSessionItem): void;
178142

179143
/**
180144
* Removes a single chat session item from the collection.
181-
*
182145
* @param resource Item resource to delete.
183146
*/
184147
delete(resource: Uri): void;
185148

186149
/**
187150
* Efficiently gets a chat session item by resource, if it exists, in the collection.
188-
*
189151
* @param resource Item resource to get.
190-
*
191152
* @returns The found item or undefined if it does not exist.
192153
*/
193154
get(resource: Uri): ChatSessionItem | undefined;
194155
}
195156

196-
/**
197-
* A chat session show in the UI.
198-
*
199-
* This should be created by calling a {@link ChatSessionItemController.createChatSessionItem createChatSessionItem}
200-
* method on the controller. The item can then be added to the controller's {@link ChatSessionItemController.items items collection}
201-
* to show it in the UI.
202-
*/
203157
export interface ChatSessionItem {
204158
/**
205159
* The resource associated with the chat session.
206160
*
207161
* This is uniquely identifies the chat session and is used to open the chat session.
208162
*/
209-
readonly resource: Uri;
163+
resource: Uri;
210164

211165
/**
212166
* Human readable name of the session shown in the UI
@@ -346,15 +300,6 @@ declare module 'vscode' {
346300
}
347301

348302
export interface ChatSession {
349-
/**
350-
* An optional title for the chat session.
351-
*
352-
* When provided, this title is used as the display name for the session
353-
* (e.g. in the editor tab). When not provided, the title defaults to
354-
* the first user message in the session history.
355-
*/
356-
readonly title?: string;
357-
358303
/**
359304
* The full history of the session
360305
*
@@ -390,7 +335,6 @@ declare module 'vscode' {
390335
*/
391336
// TODO: Should we introduce our own type for `ChatRequestHandler` since not all field apply to chat sessions?
392337
// TODO: Revisit this to align with code.
393-
// TODO: pass in options?
394338
readonly requestHandler: ChatRequestHandler | undefined;
395339
}
396340

@@ -456,8 +400,9 @@ declare module 'vscode' {
456400

457401
/**
458402
* Called as soon as you register (call me once)
403+
* @param token
459404
*/
460-
provideChatSessionProviderOptions?(token: CancellationToken): Thenable<ChatSessionProviderOptions>;
405+
provideChatSessionProviderOptions?(token: CancellationToken): Thenable<ChatSessionProviderOptions | ChatSessionProviderOptions>;
461406
}
462407

463408
export interface ChatSessionOptionUpdate {
@@ -490,15 +435,7 @@ declare module 'vscode' {
490435

491436
export interface ChatSessionContext {
492437
readonly chatSessionItem: ChatSessionItem; // Maps to URI of chat session editor (could be 'untitled-1', etc..)
493-
494-
/** @deprecated This will be removed along with the concept of `untitled-` sessions. */
495438
readonly isUntitled: boolean;
496-
497-
/**
498-
* The initial option selections for the session, provided with the first request.
499-
* Contains the options the user selected (or defaults) before the session was created.
500-
*/
501-
readonly initialSessionOptions?: ReadonlyArray<{ optionId: string; value: string | ChatSessionProviderOptionItem }>;
502439
}
503440

504441
export interface ChatSessionCapabilities {
@@ -614,13 +551,6 @@ declare module 'vscode' {
614551
* Provider-defined option groups (0-2 groups supported).
615552
* Examples: models picker, sub-agents picker, etc.
616553
*/
617-
readonly optionGroups?: readonly ChatSessionProviderOptionGroup[];
618-
619-
/**
620-
* The set of default options used for new chat sessions, provided as key-value pairs.
621-
*
622-
* Keys correspond to option group IDs (e.g., 'models', 'subagents').
623-
*/
624-
readonly newSessionOptions?: Record<string, string | ChatSessionProviderOptionItem>;
554+
optionGroups?: ChatSessionProviderOptionGroup[];
625555
}
626556
}

src/github/prComment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class TemporaryComment extends CommentBase {
175175
this.mode = vscode.CommentMode.Preview;
176176
this.originalAuthor = {
177177
name: currentUser.specialDisplayName ?? currentUser.login,
178-
iconPath: currentUser.avatarUrl ? vscode.Uri.parse(`${currentUser.avatarUrl}&s=64`) : undefined,
178+
iconPath: currentUser.avatarUrl && DataUri.isGitHubDotComAvatar(currentUser.avatarUrl) ? vscode.Uri.parse(`${currentUser.avatarUrl}&s=64`) : undefined,
179179
};
180180
this.label = isDraft ? vscode.l10n.t('Pending') : undefined;
181181
this.state = isDraft ? vscode.CommentState.Draft : vscode.CommentState.Published;
@@ -238,12 +238,12 @@ export class GHPRComment extends CommentBase {
238238
this.rawComment = comment;
239239
this.originalAuthor = {
240240
name: comment.user?.specialDisplayName ?? comment.user!.login,
241-
iconPath: comment.user && comment.user.avatarUrl ? vscode.Uri.parse(comment.user.avatarUrl) : undefined,
241+
iconPath: comment.user && comment.user.avatarUrl && DataUri.isGitHubDotComAvatar(comment.user.avatarUrl) ? vscode.Uri.parse(comment.user.avatarUrl) : undefined,
242242
};
243243
const url = vscode.Uri.parse(comment.url);
244244
this.githubRepository = githubRepositories?.find(repo => repo.remote.host === url.authority);
245245

246-
const avatarUrisPromise = comment.user ? DataUri.avatarCirclesAsImageDataUris(context, [comment.user], 28, 28) : Promise.resolve([]);
246+
const avatarUrisPromise = (comment.user && DataUri.isGitHubDotComAvatar(comment.user.avatarUrl)) ? DataUri.avatarCirclesAsImageDataUris(context, [comment.user], 28, 28) : Promise.resolve([]);
247247
this.doSetBody(comment.body, !comment.user).then(async () => { // only refresh if there's no user. If there's a user, we'll refresh in the then.
248248
const avatarUris = await avatarUrisPromise;
249249
if (avatarUris.length > 0) {

src/github/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export function threadRange(startLine: number, endLine: number, endCharacter?: n
104104
export async function setReplyAuthor(thread: vscode.CommentThread | vscode.CommentThread2, currentUser: IAccount, context: vscode.ExtensionContext) {
105105
if (currentUser.avatarUrl) {
106106
const thread2 = thread as vscode.CommentThread2;
107+
if (!DataUri.isGitHubDotComAvatar(currentUser.avatarUrl)) {
108+
thread2.canReply = { name: currentUser.name ?? currentUser.login, iconPath: undefined };
109+
return;
110+
}
107111
thread2.canReply = { name: currentUser.name ?? currentUser.login, iconPath: vscode.Uri.parse(currentUser.avatarUrl) };
108112
const uri = await DataUri.avatarCirclesAsImageDataUris(context, [currentUser], 28, 28);
109113
thread2.canReply = { name: currentUser.name ?? currentUser.login, iconPath: uri[0] };

0 commit comments

Comments
 (0)