|
6 | 6 |
|
7 | 7 | import * as vscode from 'vscode'; |
8 | 8 | import { FetchIssueResult } from './fetchIssueTool'; |
9 | | -import { concatAsyncIterable } from './toolsUtils'; |
| 9 | +import { concatAsyncIterable, TOOL_COMMAND_RESULT } from './toolsUtils'; |
10 | 10 |
|
11 | 11 | export class IssueSummarizationTool implements vscode.LanguageModelTool<FetchIssueResult> { |
12 | 12 | public static readonly toolId = 'github-pull-request_issue_summarize'; |
@@ -58,17 +58,34 @@ Body: ${comment.body} |
58 | 58 | const model = models[0]; |
59 | 59 | const repo = options.input.repo; |
60 | 60 | const owner = options.input.owner; |
| 61 | + const content: vscode.LanguageModelTextPart[] = []; |
| 62 | + |
| 63 | + // Add Open command if we have the necessary information |
| 64 | + const issueNumber = options.input.issueNumber; |
| 65 | + const itemType = options.input.itemType; |
| 66 | + if (owner && repo && issueNumber && itemType) { |
| 67 | + const type = itemType === 'issue' ? 'issues' : 'pull'; |
| 68 | + const url = `https://github.com/${owner}/${repo}/${type}/${issueNumber}`; |
| 69 | + const openCommand: vscode.Command = { |
| 70 | + title: 'Open', |
| 71 | + command: 'vscode.open', |
| 72 | + arguments: [vscode.Uri.parse(url)] |
| 73 | + }; |
| 74 | + content.push(new vscode.LanguageModelTextPart(TOOL_COMMAND_RESULT)); |
| 75 | + content.push(new vscode.LanguageModelTextPart(JSON.stringify(openCommand))); |
| 76 | + } |
61 | 77 |
|
62 | 78 | if (model && repo && owner) { |
63 | 79 | const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(repo, owner))]; |
64 | 80 | messages.push(vscode.LanguageModelChatMessage.User(`The issue or pull request information is as follows:`)); |
65 | 81 | messages.push(vscode.LanguageModelChatMessage.User(issueOrPullRequestInfo)); |
66 | 82 | const response = await model.sendRequest(messages, {}); |
67 | 83 | const responseText = await concatAsyncIterable(response.text); |
68 | | - return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart(responseText)]); |
| 84 | + content.push(new vscode.LanguageModelTextPart(responseText)); |
69 | 85 | } else { |
70 | | - return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart(issueOrPullRequestInfo)]); |
| 86 | + content.push(new vscode.LanguageModelTextPart(issueOrPullRequestInfo)); |
71 | 87 | } |
| 88 | + return new vscode.LanguageModelToolResult(content); |
72 | 89 | } |
73 | 90 |
|
74 | 91 | private summarizeInstructions(repo: string, owner: string): string { |
|
0 commit comments