@@ -35,7 +35,8 @@ import { ExtHostLanguageModels } from './extHostLanguageModels.js';
3535import { ExtHostLanguageModelTools } from './extHostLanguageModelTools.js' ;
3636import * as typeConvert from './extHostTypeConverters.js' ;
3737import * as extHostTypes from './extHostTypes.js' ;
38- import { ICustomAgentQueryOptions , IExternalCustomAgent } from '../../contrib/chat/common/promptSyntax/service/promptsService.js' ;
38+ import { IPromptFileContext , IPromptFileResource } from '../../contrib/chat/common/promptSyntax/service/promptsService.js' ;
39+ import { PromptsType } from '../../contrib/chat/common/promptSyntax/promptTypes.js' ;
3940import { ExtHostDocumentsAndEditors } from './extHostDocumentsAndEditors.js' ;
4041
4142export class ChatAgentResponseStream {
@@ -398,8 +399,8 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS
398399 private static _relatedFilesProviderIdPool = 0 ;
399400 private readonly _relatedFilesProviders = new Map < number , ExtHostRelatedFilesProvider > ( ) ;
400401
401- private static _customAgentsProviderIdPool = 0 ;
402- private readonly _customAgentsProviders = new Map < number , { extension : IExtensionDescription ; provider : vscode . CustomAgentsProvider } > ( ) ;
402+ private static _contributionsProviderIdPool = 0 ;
403+ private readonly _promptFileProviders = new Map < number , { extension : IExtensionDescription ; provider : vscode . CustomAgentProvider | vscode . InstructionsProvider | vscode . PromptFileProvider } > ( ) ;
403404
404405 private readonly _sessionDisposables : DisposableResourceMap < DisposableStore > = this . _register ( new DisposableResourceMap ( ) ) ;
405406 private readonly _completionDisposables : DisposableMap < number , DisposableStore > = this . _register ( new DisposableMap ( ) ) ;
@@ -479,23 +480,41 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS
479480 } ) ;
480481 }
481482
482- registerCustomAgentsProvider ( extension : IExtensionDescription , provider : vscode . CustomAgentsProvider ) : vscode . Disposable {
483- const handle = ExtHostChatAgents2 . _customAgentsProviderIdPool ++ ;
484- this . _customAgentsProviders . set ( handle , { extension, provider } ) ;
485- this . _proxy . $registerCustomAgentsProvider ( handle , extension . identifier ) ;
483+ /**
484+ * Internal method that handles all prompt file provider types.
485+ * Routes custom agents, instructions, and prompt files to the unified internal implementation.
486+ */
487+ registerPromptFileProvider ( extension : IExtensionDescription , type : PromptsType , provider : vscode . CustomAgentProvider | vscode . InstructionsProvider | vscode . PromptFileProvider ) : vscode . Disposable {
488+ const handle = ExtHostChatAgents2 . _contributionsProviderIdPool ++ ;
489+ this . _promptFileProviders . set ( handle , { extension, provider } ) ;
490+ this . _proxy . $registerPromptFileProvider ( handle , type , extension . identifier ) ;
486491
487492 const disposables = new DisposableStore ( ) ;
488493
489494 // Listen to provider change events and notify main thread
490- if ( provider . onDidChangeCustomAgents ) {
491- disposables . add ( provider . onDidChangeCustomAgents ( ( ) => {
492- this . _proxy . $onDidChangeCustomAgents ( handle ) ;
495+ // Check for the appropriate event based on the provider type
496+ let changeEvent : vscode . Event < void > | undefined ;
497+ switch ( type ) {
498+ case PromptsType . agent :
499+ changeEvent = ( provider as vscode . CustomAgentProvider ) . onDidChangeCustomAgents ;
500+ break ;
501+ case PromptsType . instructions :
502+ changeEvent = ( provider as vscode . InstructionsProvider ) . onDidChangeInstructions ;
503+ break ;
504+ case PromptsType . prompt :
505+ changeEvent = ( provider as vscode . PromptFileProvider ) . onDidChangePromptFiles ;
506+ break ;
507+ }
508+
509+ if ( changeEvent ) {
510+ disposables . add ( changeEvent ( ( ) => {
511+ this . _proxy . $onDidChangePromptFiles ( handle ) ;
493512 } ) ) ;
494513 }
495514
496515 disposables . add ( toDisposable ( ( ) => {
497- this . _customAgentsProviders . delete ( handle ) ;
498- this . _proxy . $unregisterCustomAgentsProvider ( handle ) ;
516+ this . _promptFileProviders . delete ( handle ) ;
517+ this . _proxy . $unregisterPromptFileProvider ( handle ) ;
499518 } ) ) ;
500519
501520 return disposables ;
@@ -511,13 +530,21 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS
511530 return await provider . provider . provideRelatedFiles ( extRequestDraft , token ) ?? undefined ;
512531 }
513532
514- async $provideCustomAgents ( handle : number , options : ICustomAgentQueryOptions , token : CancellationToken ) : Promise < IExternalCustomAgent [ ] | undefined > {
515- const providerData = this . _customAgentsProviders . get ( handle ) ;
533+ async $providePromptFiles ( handle : number , type : PromptsType , context : IPromptFileContext , token : CancellationToken ) : Promise < IPromptFileResource [ ] | undefined > {
534+ const providerData = this . _promptFileProviders . get ( handle ) ;
516535 if ( ! providerData ) {
517- return Promise . resolve ( undefined ) ;
536+ return undefined ;
518537 }
519538
520- return await providerData . provider . provideCustomAgents ( options , token ) ?? undefined ;
539+ const provider = providerData . provider ;
540+ switch ( type ) {
541+ case PromptsType . agent :
542+ return await ( provider as vscode . CustomAgentProvider ) . provideCustomAgents ( context , token ) ?? undefined ;
543+ case PromptsType . instructions :
544+ return await ( provider as vscode . InstructionsProvider ) . provideInstructions ( context , token ) ?? undefined ;
545+ case PromptsType . prompt :
546+ return await ( provider as vscode . PromptFileProvider ) . providePromptFiles ( context , token ) ?? undefined ;
547+ }
521548 }
522549
523550 async $detectChatParticipant ( handle : number , requestDto : Dto < IChatAgentRequest > , context : { history : IChatAgentHistoryEntryDto [ ] } , options : { location : ChatAgentLocation ; participants ?: vscode . ChatParticipantMetadata [ ] } , token : CancellationToken ) : Promise < vscode . ChatParticipantDetectionResult | null | undefined > {
0 commit comments