Skip to content

Commit 3546591

Browse files
authored
Context actions for chat sessions (#7627)
1 parent 0cfb8e8 commit 3546591

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,16 @@
17381738
"title": "%command.pr.refreshChatSessions.title%",
17391739
"icon": "$(refresh)",
17401740
"category": "%command.pull.request.category%"
1741+
},
1742+
{
1743+
"command": "pr.closeChatSessionPullRequest",
1744+
"title": "%command.pr.closeChatSessionPullRequest.title%",
1745+
"category": "%command.pull.request.category%"
1746+
},
1747+
{
1748+
"command": "pr.cancelCodingAgent",
1749+
"title": "%command.pr.cancelCodingAgent.title%",
1750+
"category": "%command.pull.request.category%"
17411751
}
17421752
],
17431753
"viewsWelcome": [
@@ -3379,6 +3389,16 @@
33793389
"command": "pr.openDescription",
33803390
"when": "chatSessionType == copilot-swe-agent",
33813391
"group": "inline"
3392+
},
3393+
{
3394+
"command": "pr.closeChatSessionPullRequest",
3395+
"when": "chatSessionType == copilot-swe-agent",
3396+
"group": "context"
3397+
},
3398+
{
3399+
"command": "pr.cancelCodingAgent",
3400+
"when": "chatSessionType == copilot-swe-agent",
3401+
"group": "context"
33823402
}
33833403
]
33843404
},

package.nls.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@
321321
"command.notifications.configureNotificationsViewlet.title": "Configure...",
322322
"command.notification.chatSummarizeNotification.title": "Summarize With Copilot",
323323
"command.codingAgent.openSessionLog.title": "Open Coding Agent Session Log",
324+
"command.pr.closeChatSessionPullRequest.title": "Close Pull Request",
325+
"command.pr.cancelCodingAgent.title": "Cancel Coding Agent",
324326
"welcome.github.login.contents": {
325327
"message": "You have not yet signed in with GitHub\n[Sign in](command:pr.signin)",
326328
"comment": [

src/commands.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,41 @@ export function registerCommands(
946946
await openDescription(telemetry, issueModel, descriptionNode, folderManager, revealDescription, !(argument instanceof RepositoryChangesNode), tree.notificationProvider);
947947
}
948948

949+
async function closeChatSessionPullRequest(argument: ChatSessionWithPR) {
950+
const pr = argument.pullRequest;
951+
if (!pr) {
952+
Logger.warn(`No pull request found in chat session`, logId);
953+
return;
954+
}
955+
pr.close();
956+
copilotRemoteAgentManager.refreshChatSessions();
957+
}
958+
959+
async function cancelCodingAgent(argument: ChatSessionWithPR) {
960+
const pr = argument.pullRequest;
961+
if (!pr) {
962+
Logger.warn(`No pull request found in chat session`, logId);
963+
return;
964+
}
965+
966+
copilotRemoteAgentManager.cancelMostRecentChatSession(pr);
967+
// TODO: show a progress icon until the cancelation is finished
968+
}
969+
970+
context.subscriptions.push(
971+
vscode.commands.registerCommand(
972+
'pr.closeChatSessionPullRequest',
973+
closeChatSessionPullRequest
974+
)
975+
);
976+
977+
context.subscriptions.push(
978+
vscode.commands.registerCommand(
979+
'pr.cancelCodingAgent',
980+
cancelCodingAgent
981+
)
982+
);
983+
949984
context.subscriptions.push(
950985
vscode.commands.registerCommand(
951986
'pr.openDescription',

src/github/copilotRemoteAgent.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,4 +1249,27 @@ export class CopilotRemoteAgentManager extends Disposable {
12491249
public refreshChatSessions(): void {
12501250
this._onDidChangeChatSessions.fire();
12511251
}
1252+
1253+
public async cancelMostRecentChatSession(pullRequest: PullRequestModel): Promise<void> {
1254+
const capi = await this.copilotApi;
1255+
if (!capi) {
1256+
Logger.warn(`No Copilot API instance found`);
1257+
return;
1258+
}
1259+
1260+
const folderManager = this.repositoriesManager.getManagerForIssueModel(pullRequest) ?? this.repositoriesManager.folderManagers[0];
1261+
if (!folderManager) {
1262+
Logger.warn(`No folder manager found for pull request`);
1263+
return;
1264+
}
1265+
1266+
const sessions = await capi.getAllSessions(pullRequest.id);
1267+
if (sessions.length > 0) {
1268+
const mostRecentSession = sessions[sessions.length - 1];
1269+
const folder = folderManager.gitHubRepositories.find(repo => repo.remote.remoteName === pullRequest.remote.remoteName);
1270+
folder?.cancelWorkflow(mostRecentSession.workflow_run_id);
1271+
} else {
1272+
Logger.warn(`No active chat session found for pull request ${pullRequest.id}`);
1273+
}
1274+
}
12521275
}

0 commit comments

Comments
 (0)