Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompt/common/intents.ts
13399 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
import type * as vscode from 'vscode';
7
import { NotebookDocumentSnapshot } from '../../../platform/editing/common/notebookDocumentSnapshot';
8
import { TextDocumentSnapshot } from '../../../platform/editing/common/textDocumentSnapshot';
9
import { OpenAIContextManagementResponse } from '../../../platform/networking/common/openai';
10
import { ThinkingData } from '../../../platform/thinking/common/thinking';
11
import { createServiceIdentifier } from '../../../util/common/services';
12
import { ResourceMap, ResourceSet } from '../../../util/vs/base/common/map';
13
import { generateUuid } from '../../../util/vs/base/common/uuid';
14
import { ChatRequest } from '../../../vscodeTypes';
15
import { getToolName } from '../../tools/common/toolNames';
16
import { IToolGrouping } from '../../tools/common/virtualTools/virtualToolTypes';
17
import { ChatVariablesCollection } from './chatVariablesCollection';
18
import { Conversation, Turn } from './conversation';
19
20
// TODO Move these to Conversation
21
export interface IToolCall {
22
name: string;
23
arguments: string;
24
id: string;
25
}
26
27
export interface IToolCallRound {
28
id: string;
29
summary?: string;
30
response: string;
31
toolInputRetry: number;
32
toolCalls: IToolCall[];
33
thinking?: ThinkingData;
34
statefulMarker?: string;
35
/** Compaction data from the Responses API, round-tripped in outgoing requests */
36
compaction?: OpenAIContextManagementResponse;
37
/** Epoch millis (`Date.now()`) when this round started. */
38
timestamp?: number;
39
/**
40
* Additional context from a hook that was executed after this round completed.
41
* For example, when a stop hook blocks the agent from stopping, this contains
42
* the message to show the model about what requirements must be addressed.
43
*/
44
hookContext?: string;
45
/** The phase of the agent loop during which this tool call round occurred. */
46
phase?: string;
47
/** The model ID that produced the phase value. */
48
phaseModelId?: string;
49
}
50
51
export interface InternalToolReference extends vscode.ChatLanguageModelToolReference {
52
readonly id: string;
53
readonly input?: Object; // Allows to pass input to tool invocations internally
54
}
55
56
export namespace InternalToolReference {
57
export function from(base: vscode.ChatLanguageModelToolReference): InternalToolReference {
58
return {
59
...base,
60
id: generateUuid(),
61
name: getToolName(base.name),
62
};
63
}
64
}
65
66
export interface IBuildPromptContext {
67
readonly requestId?: string;
68
readonly query: string;
69
readonly history: readonly Turn[];
70
readonly chatVariables: ChatVariablesCollection;
71
readonly workingSet?: IWorkingSet;
72
readonly tools?: {
73
readonly toolReferences: readonly InternalToolReference[];
74
readonly toolInvocationToken: vscode.ChatParticipantToolToken;
75
readonly availableTools: readonly vscode.LanguageModelToolInformation[];
76
readonly subAgentInvocationId?: string;
77
readonly subAgentName?: string;
78
};
79
readonly modeInstructions?: vscode.ChatRequestModeInstructions;
80
81
/**
82
* The accumulated tool call rounds for the current ongoing response.
83
*/
84
readonly toolCallRounds?: readonly IToolCallRound[];
85
readonly toolCallResults?: Record<string, vscode.LanguageModelToolResult>;
86
readonly toolGrouping?: IToolGrouping;
87
88
/**
89
* Models are encouraged to make parallel tool calls. Sometimes, they even
90
* do. If this happens for edit calls, because the application of text edits
91
* is async, we need to keep track of the edited versions of documented we
92
* see otherwise there is a race condition that can lead to garbled edits.
93
*
94
* This property is used by edit tools to stash their edited documents within
95
* an edit turn, and will try to reuse a previous tool's version of the
96
* document when available. The map is created anew each turn.
97
*/
98
turnEditedDocuments?: ResourceMap<NotebookDocumentSnapshot | TextDocumentSnapshot>;
99
100
/**
101
* URIs that are explicitly allowed for editing without user confirmation.
102
* This is used by features like inline chat to pre-approve the document
103
* being edited.
104
*/
105
readonly allowedEditUris?: ResourceSet;
106
107
readonly editedFileEvents?: readonly vscode.ChatRequestEditedFileEvent[];
108
readonly conversation?: Conversation;
109
readonly request?: ChatRequest;
110
readonly stream?: vscode.ChatResponseStream;
111
readonly isContinuation?: boolean;
112
/**
113
* True when the query contains a stop hook message that should be rendered
114
* as a user message, even during a continuation. This is used to distinguish
115
* between a normal continuation ("Please continue") and a stop hook
116
* continuation that requires a specific user message.
117
*/
118
readonly hasStopHookQuery?: boolean;
119
/**
120
* Additional context provided by a hook.
121
*/
122
readonly additionalHookContext?: string;
123
/**
124
* The headerRequestId from the most recent parent fetch response.
125
* Used by subagent tools to link their telemetry back to the parent's HTTP request.
126
*/
127
readonly parentHeaderRequestId?: string;
128
}
129
130
export const IBuildPromptContext = createServiceIdentifier<IBuildPromptContext>('IBuildPromptContext');
131
132
export enum WorkingSetEntryState {
133
Initial = 0,
134
Undecided = 1,
135
Accepted = 2,
136
Rejected = 3,
137
}
138
139
export interface ITextDocumentWorkingSetEntry {
140
readonly document: TextDocumentSnapshot;
141
readonly range?: vscode.Range;
142
readonly state: WorkingSetEntryState;
143
readonly isMarkedReadonly: boolean | undefined;
144
}
145
146
export interface INotebookWorkingSetEntry {
147
readonly document: NotebookDocumentSnapshot;
148
readonly range?: vscode.Range;
149
readonly state: WorkingSetEntryState;
150
readonly isMarkedReadonly: boolean | undefined;
151
}
152
153
154
export type IWorkingSetEntry = ITextDocumentWorkingSetEntry | INotebookWorkingSetEntry;
155
156
export type IWorkingSet = readonly IWorkingSetEntry[];
157
158
export function isTextDocumentWorkingSetEntry(entry: IWorkingSetEntry): entry is ITextDocumentWorkingSetEntry {
159
return (entry.document instanceof TextDocumentSnapshot);
160
}
161
162
export function isNotebookWorkingSetEntry(entry: IWorkingSetEntry): entry is INotebookWorkingSetEntry {
163
return (entry.document instanceof NotebookDocumentSnapshot);
164
}
165
166