@@ -7,12 +7,12 @@ import vscode from 'vscode';
77import { Repository } from '../api/api' ;
88import { AuthProvider } from '../common/authentication' ;
99import { Disposable } from '../common/lifecycle' ;
10+ import { Remote } from '../common/remote' ;
1011import { CODING_AGENT , CODING_AGENT_AUTO_COMMIT_AND_PUSH , CODING_AGENT_ENABLED } from '../common/settingKeys' ;
1112import { toOpenPullRequestWebviewUri } from '../common/uri' ;
1213import { CopilotApi , RemoteAgentJobPayload } from './copilotApi' ;
1314import { CopilotPRWatcher , CopilotStateModel } from './copilotPrWatcher' ;
1415import { CredentialStore } from './credentials' ;
15- import { PullRequestModel } from './pullRequestModel' ;
1616import { RepositoriesManager } from './repositoriesManager' ;
1717
1818type RemoteAgentSuccessResult = { link : string ; state : 'success' ; number : number ; webviewUri : vscode . Uri ; llmDetails : string } ;
@@ -25,25 +25,29 @@ export interface IAPISessionLogs {
2525}
2626
2727export class CopilotRemoteAgentManager extends Disposable {
28- private readonly _onDidChangeEnabled = new vscode . EventEmitter < boolean > ( ) ;
29- public readonly onDidChangeEnabled : vscode . Event < boolean > = this . _onDidChangeEnabled . event ;
3028 public static ID = 'CopilotRemoteAgentManager' ;
3129 private readonly workflowRunUrlBase = 'https://github.com/microsoft/vscode/actions/runs/' ;
3230
33- constructor ( private credentialStore : CredentialStore , public repositoriesManager : RepositoriesManager , stateModel : CopilotStateModel ) {
31+ private readonly _stateModel : CopilotStateModel ;
32+ private readonly _onDidChangeStates = this . _register ( new vscode . EventEmitter < void > ( ) ) ;
33+ readonly onDidChangeStates = this . _onDidChangeStates . event ;
34+ private readonly _onDidChangeNotifications = this . _register ( new vscode . EventEmitter < void > ( ) ) ;
35+ readonly onDidChangeNotifications = this . _onDidChangeNotifications . event ;
36+ private readonly _onDidCreatePullRequest = this . _register ( new vscode . EventEmitter < number > ( ) ) ;
37+ readonly onDidCreatePullRequest = this . _onDidCreatePullRequest . event ;
38+
39+ constructor ( private credentialStore : CredentialStore , public repositoriesManager : RepositoriesManager ) {
3440 super ( ) ;
3541 this . _register ( this . credentialStore . onDidChangeSessions ( ( e : vscode . AuthenticationSessionsChangeEvent ) => {
3642 if ( e . provider . id === 'github' ) {
3743 this . _copilotApiPromise = undefined ; // Invalidate cached session
3844 }
3945 } ) ) ;
40- this . _register ( vscode . workspace . onDidChangeConfiguration ( e => {
41- if ( e . affectsConfiguration ( `${ CODING_AGENT } .${ CODING_AGENT_ENABLED } ` ) ) {
42- this . _onDidChangeEnabled . fire ( this . enabled ( ) ) ;
43- }
44- } ) ) ;
45- this . _register ( new CopilotPRWatcher ( this . repositoriesManager , stateModel ) ) ;
4646
47+ this . _stateModel = new CopilotStateModel ( ) ;
48+ this . _register ( new CopilotPRWatcher ( this . repositoriesManager , this . _stateModel ) ) ;
49+ this . _register ( this . _stateModel . onDidChangeStates ( ( ) => this . _onDidChangeStates . fire ( ) ) ) ;
50+ this . _register ( this . _stateModel . onDidChangeNotifications ( ( ) => this . _onDidChangeNotifications . fire ( ) ) ) ;
4751 }
4852
4953 private _copilotApiPromise : Promise < CopilotApi | undefined > | undefined ;
@@ -258,6 +262,7 @@ export class CopilotRemoteAgentManager extends Disposable {
258262 const { pull_request } = await capiClient . postRemoteAgentJob ( owner , repo , payload ) ;
259263 const webviewUri = await toOpenPullRequestWebviewUri ( { owner, repo, pullRequestNumber : pull_request . number } ) ;
260264 const prLlmString = `The remote agent has begun work. The user can track progress by visiting ${ pull_request . html_url } or from the PR extension.` ;
265+ this . _onDidCreatePullRequest . fire ( pull_request . number ) ;
261266 return {
262267 state : 'success' ,
263268 number : pull_request . number ,
@@ -267,15 +272,15 @@ export class CopilotRemoteAgentManager extends Disposable {
267272 } ;
268273 }
269274
270- async getSessionLogsFromAction ( pullRequest : PullRequestModel ) {
275+ async getSessionLogsFromAction ( remote : Remote , pullRequestId : number ) {
271276 const capi = await this . copilotApi ;
272277 if ( ! capi ) {
273278 return [ ] ;
274279 }
275- const runs = await capi . getWorkflowRunsFromAction ( pullRequest ) ;
280+ const runs = await capi . getWorkflowRunsFromAction ( remote ) ;
276281 const padawanRuns = runs
277282 . filter ( run => run . path && run . path . startsWith ( 'dynamic/copilot-swe-agent' ) )
278- . filter ( run => run . pull_requests ?. some ( pr => pr . id === pullRequest . id ) ) ;
283+ . filter ( run => run . pull_requests ?. some ( pr => pr . id === pullRequestId ) ) ;
279284
280285 const lastRun = this . getLatestRun ( padawanRuns ) ;
281286
@@ -286,13 +291,13 @@ export class CopilotRemoteAgentManager extends Disposable {
286291 return await capi . getLogsFromZipUrl ( lastRun . logs_url ) ;
287292 }
288293
289- async getSessionLogsFromPullRequest ( pullRequest : PullRequestModel ) : Promise < IAPISessionLogs > {
294+ async getSessionLogsFromPullRequest ( pullRequestId : number ) : Promise < IAPISessionLogs > {
290295 const capi = await this . copilotApi ;
291296 if ( ! capi ) {
292297 return { sessionId : '' , logs : '' } ;
293298 }
294299
295- const sessions = await capi . getAllSessions ( pullRequest ) ;
300+ const sessions = await capi . getAllSessions ( pullRequestId ) ;
296301 const completedSessions = sessions . filter ( s => s . state === 'completed' ) ;
297302 if ( completedSessions . length === 0 ) {
298303 return { sessionId : '' , logs : '' } ;
@@ -302,13 +307,13 @@ export class CopilotRemoteAgentManager extends Disposable {
302307 return { sessionId : mostRecentSession . id , logs } ;
303308 }
304309
305- async getSessionUrlFromPullRequest ( pullRequest : PullRequestModel ) : Promise < string | undefined > {
310+ async getSessionUrlFromPullRequest ( pullRequestId : number | undefined ) : Promise < string | undefined > {
306311 const capi = await this . copilotApi ;
307312 if ( ! capi ) {
308313 return undefined ;
309314 }
310315
311- const sessions = await capi . getAllSessions ( pullRequest ) ;
316+ const sessions = await capi . getAllSessions ( pullRequestId ) ;
312317 const completedSessions = sessions . filter ( s => s . state === 'completed' ) ;
313318 if ( completedSessions . length === 0 ) {
314319 return undefined ;
@@ -336,4 +341,12 @@ export class CopilotRemoteAgentManager extends Disposable {
336341 return dateB - dateA ;
337342 } ) [ 0 ] ;
338343 }
344+
345+ clearNotifications ( ) {
346+ this . _stateModel . clearNotifications ( ) ;
347+ }
348+
349+ get notifications ( ) : ReadonlySet < string > {
350+ return this . _stateModel . notifications ;
351+ }
339352}
0 commit comments