Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/context/node/resolvers/inlineFixIntentInvocation.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
7
import { BasePromptElementProps } from '@vscode/prompt-tsx';
8
import type { CancellationToken, ChatResponseProgressPart, ChatResponseReferencePart, ChatResponseStream, ChatResult, Progress } from 'vscode';
9
import { IResponsePart } from '../../../../platform/chat/common/chatMLFetcher';
10
import { ChatLocation } from '../../../../platform/chat/common/commonTypes';
11
import { IChatEndpoint } from '../../../../platform/networking/common/networking';
12
import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';
13
import { IBuildPromptContext } from '../../../prompt/common/intents';
14
import { IDocumentContext } from '../../../prompt/node/documentContext';
15
import { IIntent, IIntentInvocation, IResponseProcessorContext, NoopReplyInterpreter, ReplyInterpreter, ReplyInterpreterMetaData } from '../../../prompt/node/intents';
16
import { PromptElementCtor } from '../../../prompts/node/base/promptElement';
17
import { PromptRenderer } from '../../../prompts/node/base/promptRenderer';
18
19
export class InlineFixIntentInvocation implements IIntentInvocation {
20
21
private replyInterpreter: ReplyInterpreter | null = null;
22
23
constructor(
24
readonly intent: IIntent,
25
readonly location: ChatLocation,
26
readonly endpoint: IChatEndpoint,
27
private readonly prompt: PromptElementCtor<InlineFixProps, unknown>,
28
private readonly documentContext: IDocumentContext,
29
private readonly features: IInlineFixFeatures,
30
@IInstantiationService private readonly instantiationService: IInstantiationService,
31
) { }
32
33
async buildPrompt(
34
promptContext: IBuildPromptContext,
35
progress: Progress<ChatResponseReferencePart | ChatResponseProgressPart>,
36
token: CancellationToken
37
) {
38
const renderer = PromptRenderer.create(this.instantiationService, this.endpoint, this.prompt, {
39
documentContext: this.documentContext,
40
promptContext,
41
features: this.features,
42
});
43
const result = await renderer.render(progress, token);
44
this.replyInterpreter = result.metadata.get(ReplyInterpreterMetaData)?.replyInterpreter ?? (result.hasIgnoredFiles ? new NoopReplyInterpreter() : null);
45
return result;
46
}
47
48
processResponse(context: IResponseProcessorContext, inputStream: AsyncIterable<IResponsePart>, outputStream: ChatResponseStream, token: CancellationToken): Promise<ChatResult | void> {
49
if (!this.replyInterpreter) {
50
throw new Error('Could not process response without a reply interpreter.');
51
}
52
return this.replyInterpreter.processResponse(context, inputStream, outputStream, token);
53
}
54
}
55
56
export interface IInlineFixFeatures {
57
readonly useWorkspaceChunksFromSelection: boolean;
58
readonly useWorkspaceChunksFromDiagnostics: boolean;
59
}
60
61
export interface InlineFixProps extends BasePromptElementProps {
62
readonly documentContext: IDocumentContext;
63
readonly promptContext: IBuildPromptContext;
64
readonly features: IInlineFixFeatures;
65
}
66
67