Skip to content

Commit 280dba1

Browse files
authored
add prepare invocation (#6409)
1 parent 68de69e commit 280dba1

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,14 @@
33133313
"type": "string",
33143314
"description": "The key of the notification"
33153315
},
3316+
"itemNumber": {
3317+
"type": "string",
3318+
"description": "The number of the issue/PR in the notification"
3319+
},
3320+
"itemType": {
3321+
"type": "string",
3322+
"description": "The type of the item in the notification - whether it is an issue or a PR"
3323+
},
33163324
"fileChanges": {
33173325
"type": "array",
33183326
"items": {

src/lm/tools/fetchNotificationTool.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export interface FetchNotificationResult {
3030
}[];
3131
owner: string;
3232
repo: string;
33+
itemNumber: string;
34+
itemType: 'issue' | 'pr';
3335
fileChanges?: FileChange[];
3436
threadId: number,
3537
notificationKey: string
@@ -54,8 +56,8 @@ export class FetchNotificationTool extends RepoToolBase<FetchNotificationToolPar
5456
thread_id: threadId
5557
});
5658
const threadData = thread.data;
57-
const issueNumber = threadData.subject.url.split('/').pop();
58-
if (issueNumber === undefined) {
59+
const itemNumber = threadData.subject.url.split('/').pop();
60+
if (itemNumber === undefined) {
5961
return undefined;
6062
}
6163
const lastUpdatedAt = threadData.updated_at;
@@ -64,10 +66,11 @@ export class FetchNotificationTool extends RepoToolBase<FetchNotificationToolPar
6466
const owner = threadData.repository.owner.login;
6567
const name = threadData.repository.name;
6668
const { folderManager } = await this.getRepoInfo({ owner, name });
67-
const issueOrPR = await folderManager.resolveIssueOrPullRequest(owner, name, Number(issueNumber));
69+
const issueOrPR = await folderManager.resolveIssueOrPullRequest(owner, name, Number(itemNumber));
6870
if (!issueOrPR) {
6971
throw new Error(`No notification found with thread ID #${threadId}.`);
7072
}
73+
const itemType = issueOrPR instanceof PullRequestModel ? 'pr' : 'issue';
7174
const notificationKey = getNotificationKey(owner, name, String(issueOrPR.number));
7275
const comments = issueOrPR.item.comments ?? [];
7376
let unreadComments: { body: string; }[];
@@ -88,7 +91,9 @@ export class FetchNotificationTool extends RepoToolBase<FetchNotificationToolPar
8891
title: issueOrPR.title,
8992
body: issueOrPR.body,
9093
owner,
91-
repo: name
94+
repo: name,
95+
itemNumber,
96+
itemType
9297
};
9398
if (issueOrPR instanceof PullRequestModel) {
9499
const fileChanges = await issueOrPR.getFileChangesInfo();

src/lm/tools/summarizeNotificationsTool.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ import { concatAsyncIterable, TOOL_COMMAND_RESULT } from './toolsUtils';
1111
export class NotificationSummarizationTool implements vscode.LanguageModelTool<FetchNotificationResult> {
1212
public static readonly toolId = 'github-pull-request_notification_summarize';
1313

14+
async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<FetchNotificationResult>): Promise<vscode.PreparedToolInvocation> {
15+
const parameters = options.parameters;
16+
const type = parameters.itemType === 'issue' ? 'issues' : 'pull';
17+
const url = `https://github.com/${parameters.owner}/${parameters.repo}/${type}/${parameters.itemNumber}`;
18+
return {
19+
invocationMessage: vscode.l10n.t('Fetching item [#{0}]({1}) from GitHub', parameters.itemNumber, url)
20+
};
21+
}
22+
1423
async invoke(options: vscode.LanguageModelToolInvocationOptions<FetchNotificationResult>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
1524
let notificationInfo: string = '';
1625
const lastReadAt = options.parameters.lastReadAt;

0 commit comments

Comments
 (0)