22 * Copyright (c) Microsoft Corporation. All rights reserved.
33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
5- import type { Attachment , SessionOptions } from '@github/copilot/sdk' ;
5+ import type { Attachment , SessionOptions , SweCustomAgent } from '@github/copilot/sdk' ;
66import * as l10n from '@vscode/l10n' ;
77import * as vscode from 'vscode' ;
88import { ChatExtendedRequestHandler , ChatRequestTurn2 , Uri } from 'vscode' ;
@@ -47,10 +47,10 @@ import { ICopilotCLIChatSessionInitializer, SessionInitOptions } from './copilot
4747import { convertReferenceToVariable } from './copilotCLIPromptReferences' ;
4848import { ICopilotCLITerminalIntegration , TerminalOpenLocation } from './copilotCLITerminalIntegration' ;
4949import { CopilotCloudSessionsProvider } from './copilotCloudSessionsProvider' ;
50+ import { UNTRUSTED_FOLDER_MESSAGE } from './folderRepositoryManagerImpl' ;
5051import { IPullRequestDetectionService } from './pullRequestDetectionService' ;
5152import { getSelectedSessionOptions , ISessionOptionGroupBuilder , OPEN_REPOSITORY_COMMAND_ID , toRepositoryOptionItem , toWorkspaceFolderOptionItem } from './sessionOptionGroupBuilder' ;
5253import { ISessionRequestLifecycle } from './sessionRequestLifecycle' ;
53- import { UNTRUSTED_FOLDER_MESSAGE } from './folderRepositoryManagerImpl' ;
5454
5555/**
5656 * ODO:
@@ -580,7 +580,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
580580 return this . handleRequest . bind ( this ) ;
581581 }
582582
583- private readonly contextForRequest = new Map < string , { prompt : string ; attachments : Attachment [ ] } > ( ) ;
583+ private readonly contextForRequest = new Map < string , { prompt : string ; attachments : Attachment [ ] ; agent ?: string } > ( ) ;
584584
585585 /**
586586 * Outer request handler that supports *yielding* for session steering.
@@ -733,14 +733,14 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
733733 const selectedOptions = getSelectedSessionOptions ( chatSessionContext . inputState ) ;
734734 const sessionResult = await this . getOrCreateSession ( request , chatSessionContext . chatSessionItem . resource , { ...selectedOptions , newBranch : branchNamePromise , stream } , disposables , token ) ;
735735 ( { session } = sessionResult ) ;
736- const { model } = sessionResult ;
736+ const { model, agent } = sessionResult ;
737737 if ( ! session || token . isCancellationRequested ) {
738738 return { } ;
739739 }
740740
741741 sdkSessionId = session . object . sessionId ;
742742
743- await this . sessionRequestLifecycle . startRequest ( sdkSessionId , request , context . history . length === 0 ) ;
743+ await this . sessionRequestLifecycle . startRequest ( sdkSessionId , request , context . history . length === 0 , session . object . workspace , agent ?. name ?? this . contextForRequest . get ( session . object . sessionId ) ?. agent ) ;
744744
745745 if ( request . command === 'delegate' ) {
746746 await this . handleDelegationToCloud ( session . object , request , context , stream , token ) ;
@@ -769,18 +769,18 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
769769 }
770770 }
771771
772- private async getOrCreateSession ( request : vscode . ChatRequest , chatResource : vscode . Uri , options : SessionInitOptions , disposables : DisposableStore , token : vscode . CancellationToken ) : Promise < { session : IReference < ICopilotCLISession > | undefined ; isNewSession : boolean ; model : { model : string ; reasoningEffort ?: string } | undefined ; trusted : boolean } > {
772+ private async getOrCreateSession ( request : vscode . ChatRequest , chatResource : vscode . Uri , options : SessionInitOptions , disposables : DisposableStore , token : vscode . CancellationToken ) : Promise < { session : IReference < ICopilotCLISession > | undefined ; isNewSession : boolean ; model : { model : string ; reasoningEffort ?: string } | undefined ; agent : SweCustomAgent | undefined ; trusted : boolean } > {
773773 const result = await this . sessionInitializer . getOrCreateSession ( request , chatResource , options , disposables , token ) ;
774- const { session, isNewSession, model, trusted } = result ;
774+ const { session, isNewSession, model, agent , trusted } = result ;
775775 if ( ! session || token . isCancellationRequested ) {
776- return { session : undefined , isNewSession, model, trusted } ;
776+ return { session : undefined , isNewSession, model, agent , trusted } ;
777777 }
778778
779779 if ( isNewSession ) {
780780 this . sessionItemProvider . refreshSession ( { reason : 'update' , sessionId : session . object . sessionId } ) ;
781781 }
782782
783- return { session, isNewSession, model, trusted } ;
783+ return { session, isNewSession, model, agent , trusted } ;
784784 }
785785
786786 private async handleDelegationToCloud ( session : ICopilotCLISession , request : vscode . ChatRequest , context : vscode . ChatContext , stream : vscode . ChatResponseStream , token : vscode . CancellationToken ) {
@@ -835,7 +835,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
835835 const { prompt, attachments, references } = await this . promptResolver . resolvePrompt ( request , await requestPromptPromise , ( otherReferences || [ ] ) . concat ( [ ] ) , workspaceInfo , [ ] , token ) ;
836836
837837 const mcpServerMappings = buildMcpServerMappings ( request . tools ) ;
838- const { session, model } = await this . sessionInitializer . createDelegatedSession ( request , workspaceInfo , { mcpServerMappings } , token ) ;
838+ const { session, model, agent } = await this . sessionInitializer . createDelegatedSession ( request , workspaceInfo , { mcpServerMappings } , token ) ;
839+
839840 if ( summary ) {
840841 const summaryRef = await this . chatDelegationSummaryService . trackSummaryUsage ( session . object . sessionId , summary ) ;
841842 if ( summaryRef ) {
@@ -844,7 +845,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
844845 }
845846
846847 try {
847- this . contextForRequest . set ( session . object . sessionId , { prompt, attachments } ) ;
848+ this . contextForRequest . set ( session . object . sessionId , { prompt, attachments, agent : agent ?. name } ) ;
848849 // this.sessionItemProvider.notifySessionsChange();
849850 // TODO @DonJayamanne I don't think we need to refresh the list of session here just yet, or perhaps we do,
850851 // Same as getOrCreate session, we need a dummy title or the initial prompt to show in the sessions list.
0 commit comments