-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add proposed API for prompt files providers #280426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 30 commits
57e647c
241e775
424a1db
dc9551e
696ef50
2441746
112dc09
25cd745
1ca3933
1600cdf
88bc61c
d31d7ba
4dd999d
6320214
3ce36e7
5a44074
846facc
de3f04c
bc3dc9e
50f719a
d334ac1
057840b
d283548
36346df
2617d68
44f5501
f4e9bc4
a5eec28
c50fcb8
f07a636
1c07b6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,8 @@ import { ExtHostLanguageModels } from './extHostLanguageModels.js'; | |
| import { ExtHostLanguageModelTools } from './extHostLanguageModelTools.js'; | ||
| import * as typeConvert from './extHostTypeConverters.js'; | ||
| import * as extHostTypes from './extHostTypes.js'; | ||
| import { ICustomAgentQueryOptions, IExternalCustomAgent } from '../../contrib/chat/common/promptSyntax/service/promptsService.js'; | ||
| import { IPromptFileContext, IPromptFileResource } from '../../contrib/chat/common/promptSyntax/service/promptsService.js'; | ||
| import { PromptsType } from '../../contrib/chat/common/promptSyntax/promptTypes.js'; | ||
| import { ExtHostDocumentsAndEditors } from './extHostDocumentsAndEditors.js'; | ||
|
|
||
| export class ChatAgentResponseStream { | ||
|
|
@@ -398,8 +399,8 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS | |
| private static _relatedFilesProviderIdPool = 0; | ||
| private readonly _relatedFilesProviders = new Map<number, ExtHostRelatedFilesProvider>(); | ||
|
|
||
| private static _customAgentsProviderIdPool = 0; | ||
| private readonly _customAgentsProviders = new Map<number, { extension: IExtensionDescription; provider: vscode.CustomAgentsProvider }>(); | ||
| private static _contributionsProviderIdPool = 0; | ||
| private readonly _promptFileProviders = new Map<number, { extension: IExtensionDescription; provider: vscode.CustomAgentProvider | vscode.InstructionsProvider | vscode.PromptFileProvider }>(); | ||
|
|
||
| private readonly _sessionDisposables: DisposableResourceMap<DisposableStore> = this._register(new DisposableResourceMap()); | ||
| private readonly _completionDisposables: DisposableMap<number, DisposableStore> = this._register(new DisposableMap()); | ||
|
|
@@ -479,23 +480,37 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS | |
| }); | ||
| } | ||
|
|
||
| registerCustomAgentsProvider(extension: IExtensionDescription, provider: vscode.CustomAgentsProvider): vscode.Disposable { | ||
| const handle = ExtHostChatAgents2._customAgentsProviderIdPool++; | ||
| this._customAgentsProviders.set(handle, { extension, provider }); | ||
| this._proxy.$registerCustomAgentsProvider(handle, extension.identifier); | ||
| /** | ||
| * Internal method that handles all prompt file provider types. | ||
| * Routes custom agents, instructions, and prompt files to the unified internal implementation. | ||
| */ | ||
| registerPromptFileProvider(extension: IExtensionDescription, type: PromptsType, provider: vscode.CustomAgentProvider | vscode.InstructionsProvider | vscode.PromptFileProvider): vscode.Disposable { | ||
| const handle = ExtHostChatAgents2._contributionsProviderIdPool++; | ||
| this._promptFileProviders.set(handle, { extension, provider }); | ||
| this._proxy.$registerPromptFileProvider(handle, type, extension.identifier); | ||
|
|
||
| const disposables = new DisposableStore(); | ||
|
|
||
| // Listen to provider change events and notify main thread | ||
| if (provider.onDidChangeCustomAgents) { | ||
| disposables.add(provider.onDidChangeCustomAgents(() => { | ||
| this._proxy.$onDidChangeCustomAgents(handle); | ||
| // Check for the appropriate event based on the provider type | ||
| let changeEvent: vscode.Event<void> | undefined; | ||
| if ('onDidChangeCustomAgents' in provider) { | ||
| changeEvent = provider.onDidChangeCustomAgents; | ||
| } else if ('onDidChangeInstructions' in provider) { | ||
| changeEvent = provider.onDidChangeInstructions; | ||
| } else if ('onDidChangePromptFiles' in provider) { | ||
| changeEvent = provider.onDidChangePromptFiles; | ||
| } | ||
|
|
||
| if (changeEvent) { | ||
| disposables.add(changeEvent(() => { | ||
| this._proxy.$onDidChangePromptFiles(handle); | ||
| })); | ||
| } | ||
|
|
||
| disposables.add(toDisposable(() => { | ||
| this._customAgentsProviders.delete(handle); | ||
| this._proxy.$unregisterCustomAgentsProvider(handle); | ||
| this._promptFileProviders.delete(handle); | ||
| this._proxy.$unregisterPromptFileProvider(handle); | ||
| })); | ||
|
|
||
| return disposables; | ||
|
|
@@ -511,13 +526,22 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS | |
| return await provider.provider.provideRelatedFiles(extRequestDraft, token) ?? undefined; | ||
| } | ||
|
|
||
| async $provideCustomAgents(handle: number, options: ICustomAgentQueryOptions, token: CancellationToken): Promise<IExternalCustomAgent[] | undefined> { | ||
| const providerData = this._customAgentsProviders.get(handle); | ||
| async $providePromptFiles(handle: number, context: IPromptFileContext, token: CancellationToken): Promise<IPromptFileResource[] | undefined> { | ||
|
||
| const providerData = this._promptFileProviders.get(handle); | ||
| if (!providerData) { | ||
| return Promise.resolve(undefined); | ||
| return undefined; | ||
| } | ||
|
|
||
| return await providerData.provider.provideCustomAgents(options, token) ?? undefined; | ||
| const provider = providerData.provider; | ||
| // Call the appropriate method based on the provider type | ||
| if ('provideCustomAgents' in provider) { | ||
| return await provider.provideCustomAgents(context, token) ?? undefined; | ||
| } else if ('provideInstructions' in provider) { | ||
| return await provider.provideInstructions(context, token) ?? undefined; | ||
| } else if ('providePromptFiles' in provider) { | ||
| return await provider.providePromptFiles(context, token) ?? undefined; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| async $detectChatParticipant(handle: number, requestDto: Dto<IChatAgentRequest>, context: { history: IChatAgentHistoryEntryDto[] }, options: { location: ChatAgentLocation; participants?: vscode.ChatParticipantMetadata[] }, token: CancellationToken): Promise<vscode.ChatParticipantDetectionResult | null | undefined> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use a switch over 'type' to know the name of the event. A instruction provider could also have a field 'onDidChangeCustomAgents'. That would be ok to do