@@ -13,9 +13,8 @@ import { IVSCodeExtensionContext } from '../../../platform/extContext/common/ext
1313import { IGitService } from '../../../platform/git/common/gitService' ;
1414import { toGitUri } from '../../../platform/git/common/utils' ;
1515import { ILogService } from '../../../platform/log/common/logService' ;
16- import { ParsedPromptFile , PromptFileParser } from '../../../platform/promptFiles/common/promptsService' ;
16+ import { IPromptsService , ParsedPromptFile } from '../../../platform/promptFiles/common/promptsService' ;
1717import { ITelemetryService } from '../../../platform/telemetry/common/telemetry' ;
18- import { IWorkspaceService } from '../../../platform/workspace/common/workspaceService' ;
1918import { disposableTimeout } from '../../../util/vs/base/common/async' ;
2019import { isCancellationError } from '../../../util/vs/base/common/errors' ;
2120import { Emitter , Event } from '../../../util/vs/base/common/event' ;
@@ -414,7 +413,7 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
414413 @IConfigurationService private readonly configurationService : IConfigurationService ,
415414 @ICopilotCLISDK private readonly copilotCLISDK : ICopilotCLISDK ,
416415 @ILogService private readonly logService : ILogService ,
417- @IWorkspaceService private readonly workspaceService : IWorkspaceService ,
416+ @IPromptsService private readonly promptsService : IPromptsService ,
418417 ) {
419418 super ( ) ;
420419 }
@@ -458,8 +457,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
458457 const additionalReferences = this . previousReferences . get ( id ) || [ ] ;
459458 this . previousReferences . delete ( id ) ;
460459 const [ modelId , agent ] = await Promise . all ( [
461- this . getModelId ( id , request ) ,
462- this . getAgent ( id , request ) ,
460+ this . getModelId ( id , request , token ) ,
461+ this . getAgent ( id , request , token ) ,
463462 ] ) ;
464463 const session = await this . getOrCreateSession ( request , chatSessionContext , modelId , agent , stream , disposables , token ) ;
465464 if ( ! session || token . isCancellationRequested ) {
@@ -511,8 +510,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
511510 * If opening an existing session, then uses the agent associated with that session.
512511 * If creating a new session with a prompt file that specifies an agent, then uses that agent.
513512 */
514- private async getAgent ( sessionId : string | undefined , request : vscode . ChatRequest | undefined ) : Promise < SweCustomAgent | undefined > {
515- const promptFile = request ? await this . getPromptInfoFromRequest ( request ) : undefined ;
513+ private async getAgent ( sessionId : string | undefined , request : vscode . ChatRequest | undefined , token : vscode . CancellationToken ) : Promise < SweCustomAgent | undefined > {
514+ const promptFile = request ? await this . getPromptInfoFromRequest ( request , token ) : undefined ;
516515 if ( promptFile ?. header ?. agent ) {
517516 const agent = await this . copilotCLIAgents . resolveAgent ( promptFile . header . agent ) ;
518517 if ( agent ) {
@@ -527,14 +526,13 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
527526 return this . copilotCLIAgents . resolveAgent ( sessionAgent ?? defaultAgent ) ;
528527 }
529528
530- private async getPromptInfoFromRequest ( request : vscode . ChatRequest ) : Promise < ParsedPromptFile | undefined > {
529+ private async getPromptInfoFromRequest ( request : vscode . ChatRequest , token : vscode . CancellationToken ) : Promise < ParsedPromptFile | undefined > {
531530 const promptFile = new ChatVariablesCollection ( request . references ) . find ( isPromptFile ) ;
532531 if ( ! promptFile || ! URI . isUri ( promptFile . reference . value ) ) {
533532 return undefined ;
534533 }
535534 try {
536- const doc = await this . workspaceService . openTextDocument ( promptFile . reference . value ) ;
537- return new PromptFileParser ( ) . parse ( promptFile . reference . value , doc . getText ( ) ) ;
535+ return await this . promptsService . parseFile ( promptFile . reference . value , token ) ;
538536 } catch ( ex ) {
539537 this . logService . error ( `Failed to parse the prompt file: ${ promptFile . reference . value . toString ( ) } ` , ex ) ;
540538 return undefined ;
@@ -571,8 +569,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
571569 return session ;
572570 }
573571
574- private async getModelId ( sessionId : string | undefined , request : vscode . ChatRequest | undefined ) : Promise < string | undefined > {
575- const promptFile = request ? await this . getPromptInfoFromRequest ( request ) : undefined ;
572+ private async getModelId ( sessionId : string | undefined , request : vscode . ChatRequest | undefined , token : vscode . CancellationToken ) : Promise < string | undefined > {
573+ const promptFile = request ? await this . getPromptInfoFromRequest ( request , token ) : undefined ;
576574 if ( promptFile ?. header ?. model ) {
577575 const model = await this . copilotCLIModels . resolveModel ( promptFile . header . model ) ;
578576 if ( model ) {
@@ -812,8 +810,8 @@ export class CopilotCLIChatSessionParticipant extends Disposable {
812810 }
813811 const [ { prompt, attachments } , model , agent ] = await Promise . all ( [
814812 this . promptResolver . resolvePrompt ( request , requestPrompt , ( references || [ ] ) . concat ( [ ] ) , isolationEnabled , token ) ,
815- this . getModelId ( undefined , undefined ) ,
816- this . getAgent ( undefined , undefined ) ,
813+ this . getModelId ( undefined , undefined , token ) ,
814+ this . getAgent ( undefined , undefined , token ) ,
817815 ] ) ;
818816
819817 const session = await this . sessionService . createSession ( { workingDirectory, isolationEnabled, agent, model } , token ) ;
0 commit comments