Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3323,7 +3323,7 @@
"type": "string",
"description": "The repo in which the issue/PR is located"
},
"unreadComments": {
"comments": {
"type": "array",
"items": {
"type": "object",
Expand Down Expand Up @@ -3380,13 +3380,15 @@
},
"required": [
"title",
"unreadComments",
"comments",
"lastUpdatedAt",
"unread",
"threadId",
"notificationKey",
"owner",
"repo"
"repo",
"itemNumber",
"itemType"
]
},
"when": "config.githubPullRequests.experimental.chat"
Expand Down
22 changes: 11 additions & 11 deletions src/lm/tools/fetchNotificationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ export interface FetchNotificationResult {
unread: boolean;
title: string;
body: string;
unreadComments: {
comments?: {
author: string;
body: string;
}[];
Comment thread
aiday-mar marked this conversation as resolved.
owner: string;
repo: string;
itemNumber: string;
itemType: 'issue' | 'pr';
itemNumber?: string;
itemType?: 'issue' | 'pr';
fileChanges?: FileChange[];
threadId: number,
notificationKey: string
threadId?: number,
notificationKey?: string
}

export class FetchNotificationTool extends RepoToolBase<FetchNotificationToolParameters> {
Expand Down Expand Up @@ -73,20 +73,20 @@ export class FetchNotificationTool extends RepoToolBase<FetchNotificationToolPar
}
const itemType = issueOrPR instanceof PullRequestModel ? 'pr' : 'issue';
const notificationKey = getNotificationKey(owner, name, String(issueOrPR.number));
const comments = issueOrPR.item.comments ?? [];
let unreadComments: { body: string; author: string }[];
if (lastReadAt !== undefined && comments) {
unreadComments = comments.filter(comment => {
const itemComments = issueOrPR.item.comments ?? [];
let comments: { body: string; author: string }[];
if (lastReadAt !== undefined && itemComments) {
comments = itemComments.filter(comment => {
return comment.createdAt > lastReadAt;
}).map(comment => { return { body: comment.body, author: comment.author.login }; });
} else {
unreadComments = comments.map(comment => { return { body: comment.body, author: comment.author.login }; });
comments = itemComments.map(comment => { return { body: comment.body, author: comment.author.login }; });
}
const result: FetchNotificationResult = {
lastReadAt,
lastUpdatedAt,
unread,
unreadComments,
comments,
threadId,
notificationKey,
title: issueOrPR.title,
Expand Down
46 changes: 26 additions & 20 deletions src/lm/tools/summarizeNotificationsTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export class NotificationSummarizationTool implements vscode.LanguageModelTool<F

async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<FetchNotificationResult>): Promise<vscode.PreparedToolInvocation> {
const parameters = options.parameters;
if (!parameters.itemType || !parameters.itemNumber) {
return {
invocationMessage: vscode.l10n.t('Summarizing notification')
};
}
const type = parameters.itemType === 'issue' ? 'issues' : 'pull';
const url = `https://github.com/${parameters.owner}/${parameters.repo}/${type}/${parameters.itemNumber}`;
return {
Expand Down Expand Up @@ -44,47 +49,48 @@ Patch: ${fileChange.patch}
}
}

const unreadComments = options.parameters.unreadComments;
if (unreadComments.length > 0) {
const unreadComments = options.parameters.comments;
if (unreadComments && unreadComments.length > 0) {
notificationInfo += `
The following are the unread comments of the thread:
`;
}
for (const [index, comment] of unreadComments.entries()) {
notificationInfo += `
for (const [index, comment] of unreadComments.entries()) {
notificationInfo += `
Comment ${index} :
Author: ${comment.author}
Body: ${comment.body}
`;
}
}
const models = await vscode.lm.selectChatModels({
vendor: 'copilot',
family: 'gpt-4o'
});
const model = models[0];
const markAsReadCommand: vscode.Command = {
title: 'Mark As Read',
command: 'notification.markAsRead',
arguments: [{
threadId: options.parameters.threadId,
notificationKey: options.parameters.notificationKey
}]
};
const content: vscode.LanguageModelTextPart[] = [];
const threadId = options.parameters.threadId;
const notificationKey = options.parameters.notificationKey;
if (threadId && notificationKey) {
const markAsReadCommand = {
title: 'Mark As Read',
command: 'notification.markAsRead',
arguments: [{ threadId, notificationKey }]
};
content.push(new vscode.LanguageModelTextPart(TOOL_COMMAND_RESULT));
content.push(new vscode.LanguageModelTextPart(JSON.stringify(markAsReadCommand)));
}
if (model) {
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(options.parameters.owner, options.parameters.repo))];
messages.push(vscode.LanguageModelChatMessage.User(`The notification information is as follows:`));
messages.push(vscode.LanguageModelChatMessage.User(notificationInfo));
const response = await model.sendRequest(messages, {});
const responseText = await concatAsyncIterable(response.text);

return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart(TOOL_COMMAND_RESULT),
new vscode.LanguageModelTextPart(JSON.stringify(markAsReadCommand)),
new vscode.LanguageModelTextPart(responseText)]);
content.push(new vscode.LanguageModelTextPart(responseText));
} else {
return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart(TOOL_COMMAND_RESULT),
new vscode.LanguageModelTextPart(JSON.stringify(markAsReadCommand)),
new vscode.LanguageModelTextPart(notificationInfo)]);
content.push(new vscode.LanguageModelTextPart(notificationInfo));
}
content.push(new vscode.LanguageModelTextPart('Above is a summary of the notification. Extract and output this notification summary directly as is to the user. Do not output the result from the call to the fetch notification tool.'));
return new vscode.LanguageModelToolResult(content);
}

private summarizeInstructions(owner: string, repo: string): string {
Expand Down