Skip to content

Commit b7ed43e

Browse files
committed
accept cancellationToken
1 parent 8dc2a83 commit b7ed43e

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/github/copilotRemoteAgent.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as pathLib from 'path';
77
import * as marked from 'marked';
8-
import vscode, { CancellationTokenSource, ChatPromptReference } from 'vscode';
8+
import vscode, { ChatPromptReference } from 'vscode';
99
import { parseSessionLogs, parseToolCallDetails, StrReplaceEditorToolData } from '../../common/sessionParsing';
1010
import { COPILOT_ACCOUNTS } from '../common/comment';
1111
import { CopilotRemoteAgentConfig } from '../common/config';
@@ -470,6 +470,7 @@ export class CopilotRemoteAgentManager extends Disposable {
470470
const result = await this.invokeRemoteAgent(
471471
userPrompt,
472472
summary,
473+
undefined,
473474
autoPushAndCommit,
474475
);
475476

@@ -534,7 +535,7 @@ export class CopilotRemoteAgentManager extends Disposable {
534535
return vscode.l10n.t('🚀 Coding agent will continue work in [#{0}]({1}). Track progress [here]({2}).', number, link, webviewUri.toString());
535536
}
536537

537-
async invokeRemoteAgent(prompt: string, problemContext?: string, autoPushAndCommit = true): Promise<RemoteAgentResult> {
538+
async invokeRemoteAgent(prompt: string, problemContext?: string, token?: vscode.CancellationToken, autoPushAndCommit = true): Promise<RemoteAgentResult> {
538539
const capiClient = await this.copilotApi;
539540
if (!capiClient) {
540541
return { error: vscode.l10n.t('Failed to initialize Copilot API'), state: 'error' };
@@ -611,7 +612,7 @@ export class CopilotRemoteAgentManager extends Disposable {
611612
const webviewUri = await toOpenPullRequestWebviewUri({ owner, repo, pullRequestNumber: pull_request.number });
612613
const prLlmString = `The remote agent has begun work and has created a pull request. Details about the pull request are being shown to the user. If the user wants to track progress or iterate on the agent's work, they should use the pull request.`;
613614

614-
await this.waitForQueuedToInProgress(session_id, new CancellationTokenSource().token);
615+
await this.waitForQueuedToInProgress(session_id, token);
615616
return {
616617
state: 'success',
617618
number: pull_request.number,
@@ -798,7 +799,7 @@ export class CopilotRemoteAgentManager extends Disposable {
798799

799800

800801

801-
public async provideNewChatSessionItem(options: { request: vscode.ChatRequest; prompt?: string; history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>; metadata?: any; }, _token: vscode.CancellationToken): Promise<ChatSessionWithPR | ChatSessionFromSummarizedChat> {
802+
public async provideNewChatSessionItem(options: { request: vscode.ChatRequest; prompt?: string; history: ReadonlyArray<vscode.ChatRequestTurn | vscode.ChatResponseTurn>; metadata?: any; }, token: vscode.CancellationToken): Promise<ChatSessionWithPR | ChatSessionFromSummarizedChat> {
802803
const { request, history } = options;
803804
if (!options.prompt) {
804805
throw new Error(`Prompt is expected to provide a new chat session item`);
@@ -832,6 +833,7 @@ export class CopilotRemoteAgentManager extends Disposable {
832833
this.extractFileReferences(request.references),
833834
await this.extractHistory(history)
834835
].join('\n\n').trim(),
836+
token,
835837
false,
836838
);
837839
if (result.state !== 'success') {
@@ -993,6 +995,7 @@ export class CopilotRemoteAgentManager extends Disposable {
993995
const result = await this.invokeRemoteAgent(
994996
prompt,
995997
summary || prompt,
998+
undefined,
996999
false,
9971000
);
9981001
this.ephemeralChatSessions.delete(id); // TODO: Better state management
@@ -1504,7 +1507,7 @@ export class CopilotRemoteAgentManager extends Disposable {
15041507

15051508
private async waitForQueuedToInProgress(
15061509
sessionId: string,
1507-
token: vscode.CancellationToken
1510+
token?: vscode.CancellationToken
15081511
): Promise<SessionInfo | undefined> {
15091512
const capi = await this.copilotApi;
15101513
if (!capi) {
@@ -1521,7 +1524,7 @@ export class CopilotRemoteAgentManager extends Disposable {
15211524
}
15221525

15231526
Logger.appendLine(`Session ${sessionInfo.id} is queued, waiting to start...`, CopilotRemoteAgentManager.ID);
1524-
while (Date.now() - startTime < maxWaitTime && !token.isCancellationRequested) {
1527+
while (Date.now() - startTime < maxWaitTime && (!token || !token.isCancellationRequested)) {
15251528
const sessionInfo = await capi.getSessionInfo(sessionId);
15261529
if (sessionInfo?.state === 'in_progress') {
15271530
Logger.appendLine(`Session ${sessionInfo.id} now in progress.`, CopilotRemoteAgentManager.ID);

0 commit comments

Comments
 (0)