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
33 changes: 18 additions & 15 deletions src/lm/tools/fetchIssueTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,42 @@ import { PullRequestModel } from '../../github/pullRequestModel';
import { RepoToolBase } from './toolsUtils';

interface FetchIssueToolParameters {
issueNumber: number;
issueNumber?: number;
repo?: {
owner: string;
name: string;
owner?: string;
name?: string;
};
}

interface FileChange {
fileName: string;
patch: string;
fileName?: string;
patch?: string;
}

export interface FetchIssueResult {
title: string;
body: string;
comments: {
author: string;
body: string;
title?: string;
body?: string;
comments?: {
author?: string;
body?: string;
}[];
owner: string;
repo: string;
owner?: string;
repo?: string;
fileChanges?: FileChange[];
}

export class FetchIssueTool extends RepoToolBase<FetchIssueToolParameters> {
public static readonly toolId = 'github-pull-request_issue_fetch';

async invoke(options: vscode.LanguageModelToolInvocationOptions<FetchIssueToolParameters>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult> {
const issueNumber = options.input.issueNumber;
if (!issueNumber) {
throw new Error('No issue/PR number provided.');
}
const { owner, name, folderManager } = await this.getRepoInfo({ owner: options.input.repo?.owner, name: options.input.repo?.name });
const issueOrPullRequest = await folderManager.resolveIssueOrPullRequest(owner, name, options.input.issueNumber);
const issueOrPullRequest = await folderManager.resolveIssueOrPullRequest(owner, name, issueNumber);
if (!issueOrPullRequest) {
throw new Error(`No issue or PR found for ${owner}/${name}/${options.input.issueNumber}. Make sure the issue or PR exists.`);
throw new Error(`No issue or PR found for ${owner}/${name}/${issueNumber}. Make sure the issue or PR exists.`);
}
const result: FetchIssueResult = {
owner,
Expand Down Expand Up @@ -79,6 +83,5 @@ export class FetchIssueTool extends RepoToolBase<FetchIssueToolParameters> {
return {
invocationMessage: url ? vscode.l10n.t('Fetching item [#{0}]({1}) from GitHub', options.input.issueNumber, url) : vscode.l10n.t('Fetching item #{0} from GitHub', options.input.issueNumber),
};

}
}
25 changes: 14 additions & 11 deletions src/lm/tools/fetchNotificationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ import { getNotificationKey } from '../../github/utils';
import { RepoToolBase } from './toolsUtils';

interface FetchNotificationToolParameters {
thread_id: number;
thread_id?: number;
}

interface FileChange {
fileName: string;
patch: string;
fileName?: string;
patch?: string;
}

export interface FetchNotificationResult {
lastReadAt?: string;
lastUpdatedAt: string;
unread: boolean;
title: string;
body: string;
lastUpdatedAt?: string;
unread?: boolean;
title?: string;
body?: string;
comments?: {
author: string;
body: string;
author?: string;
body?: string;
}[];
owner: string;
repo: string;
owner?: string;
repo?: string;
itemNumber?: string;
itemType?: 'issue' | 'pr';
fileChanges?: FileChange[];
Expand All @@ -53,6 +53,9 @@ export class FetchNotificationTool extends RepoToolBase<FetchNotificationToolPar
return undefined;
}
const threadId = options.input.thread_id;
if (threadId === undefined) {
return undefined;
}
const thread = await github.octokit.api.activity.getThread({
thread_id: threadId
});
Expand Down
12 changes: 8 additions & 4 deletions src/lm/tools/summarizeIssueTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ Patch: ${fileChange.patch}
}
}
const comments = options.input.comments;
for (const [index, comment] of comments.entries()) {
issueOrPullRequestInfo += `
if (comments) {
for (const [index, comment] of comments.entries()) {
issueOrPullRequestInfo += `
Comment ${index} :
Author: ${comment.author}
Body: ${comment.body}
`;
}
}
const models = await vscode.lm.selectChatModels({
vendor: 'copilot',
family: 'gpt-4o'
});
const model = models[0];
const repo = options.input.repo;
const owner = options.input.owner;

if (model) {
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(options.input.repo, options.input.owner))];
if (model && repo && owner) {
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(repo, owner))];
messages.push(vscode.LanguageModelChatMessage.User(`The issue or pull request information is as follows:`));
messages.push(vscode.LanguageModelChatMessage.User(issueOrPullRequestInfo));
const response = await model.sendRequest(messages, {});
Expand Down
6 changes: 4 additions & 2 deletions src/lm/tools/summarizeNotificationsTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ Body: ${comment.body}
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.input.owner, options.input.repo))];
const owner = options.input.owner;
const repo = options.input.repo;
if (model && owner && repo) {
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(owner, repo))];
messages.push(vscode.LanguageModelChatMessage.User(`The notification information is as follows:`));
messages.push(vscode.LanguageModelChatMessage.User(notificationInfo));
const response = await model.sendRequest(messages, {});
Expand Down