Path: blob/main/extensions/copilot/src/extension/prompt/common/intents.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type * as vscode from 'vscode';6import { NotebookDocumentSnapshot } from '../../../platform/editing/common/notebookDocumentSnapshot';7import { TextDocumentSnapshot } from '../../../platform/editing/common/textDocumentSnapshot';8import { OpenAIContextManagementResponse } from '../../../platform/networking/common/openai';9import { ThinkingData } from '../../../platform/thinking/common/thinking';10import { createServiceIdentifier } from '../../../util/common/services';11import { ResourceMap, ResourceSet } from '../../../util/vs/base/common/map';12import { generateUuid } from '../../../util/vs/base/common/uuid';13import { ChatRequest } from '../../../vscodeTypes';14import { getToolName } from '../../tools/common/toolNames';15import { IToolGrouping } from '../../tools/common/virtualTools/virtualToolTypes';16import { ChatVariablesCollection } from './chatVariablesCollection';17import { Conversation, Turn } from './conversation';1819// TODO Move these to Conversation20export interface IToolCall {21name: string;22arguments: string;23id: string;24}2526export interface IToolCallRound {27id: string;28summary?: string;29response: string;30toolInputRetry: number;31toolCalls: IToolCall[];32thinking?: ThinkingData;33statefulMarker?: string;34/** Compaction data from the Responses API, round-tripped in outgoing requests */35compaction?: OpenAIContextManagementResponse;36/** Epoch millis (`Date.now()`) when this round started. */37timestamp?: number;38/**39* Additional context from a hook that was executed after this round completed.40* For example, when a stop hook blocks the agent from stopping, this contains41* the message to show the model about what requirements must be addressed.42*/43hookContext?: string;44/** The phase of the agent loop during which this tool call round occurred. */45phase?: string;46/** The model ID that produced the phase value. */47phaseModelId?: string;48}4950export interface InternalToolReference extends vscode.ChatLanguageModelToolReference {51readonly id: string;52readonly input?: Object; // Allows to pass input to tool invocations internally53}5455export namespace InternalToolReference {56export function from(base: vscode.ChatLanguageModelToolReference): InternalToolReference {57return {58...base,59id: generateUuid(),60name: getToolName(base.name),61};62}63}6465export interface IBuildPromptContext {66readonly requestId?: string;67readonly query: string;68readonly history: readonly Turn[];69readonly chatVariables: ChatVariablesCollection;70readonly workingSet?: IWorkingSet;71readonly tools?: {72readonly toolReferences: readonly InternalToolReference[];73readonly toolInvocationToken: vscode.ChatParticipantToolToken;74readonly availableTools: readonly vscode.LanguageModelToolInformation[];75readonly subAgentInvocationId?: string;76readonly subAgentName?: string;77};78readonly modeInstructions?: vscode.ChatRequestModeInstructions;7980/**81* The accumulated tool call rounds for the current ongoing response.82*/83readonly toolCallRounds?: readonly IToolCallRound[];84readonly toolCallResults?: Record<string, vscode.LanguageModelToolResult>;85readonly toolGrouping?: IToolGrouping;8687/**88* Models are encouraged to make parallel tool calls. Sometimes, they even89* do. If this happens for edit calls, because the application of text edits90* is async, we need to keep track of the edited versions of documented we91* see otherwise there is a race condition that can lead to garbled edits.92*93* This property is used by edit tools to stash their edited documents within94* an edit turn, and will try to reuse a previous tool's version of the95* document when available. The map is created anew each turn.96*/97turnEditedDocuments?: ResourceMap<NotebookDocumentSnapshot | TextDocumentSnapshot>;9899/**100* URIs that are explicitly allowed for editing without user confirmation.101* This is used by features like inline chat to pre-approve the document102* being edited.103*/104readonly allowedEditUris?: ResourceSet;105106readonly editedFileEvents?: readonly vscode.ChatRequestEditedFileEvent[];107readonly conversation?: Conversation;108readonly request?: ChatRequest;109readonly stream?: vscode.ChatResponseStream;110readonly isContinuation?: boolean;111/**112* True when the query contains a stop hook message that should be rendered113* as a user message, even during a continuation. This is used to distinguish114* between a normal continuation ("Please continue") and a stop hook115* continuation that requires a specific user message.116*/117readonly hasStopHookQuery?: boolean;118/**119* Additional context provided by a hook.120*/121readonly additionalHookContext?: string;122/**123* The headerRequestId from the most recent parent fetch response.124* Used by subagent tools to link their telemetry back to the parent's HTTP request.125*/126readonly parentHeaderRequestId?: string;127}128129export const IBuildPromptContext = createServiceIdentifier<IBuildPromptContext>('IBuildPromptContext');130131export enum WorkingSetEntryState {132Initial = 0,133Undecided = 1,134Accepted = 2,135Rejected = 3,136}137138export interface ITextDocumentWorkingSetEntry {139readonly document: TextDocumentSnapshot;140readonly range?: vscode.Range;141readonly state: WorkingSetEntryState;142readonly isMarkedReadonly: boolean | undefined;143}144145export interface INotebookWorkingSetEntry {146readonly document: NotebookDocumentSnapshot;147readonly range?: vscode.Range;148readonly state: WorkingSetEntryState;149readonly isMarkedReadonly: boolean | undefined;150}151152153export type IWorkingSetEntry = ITextDocumentWorkingSetEntry | INotebookWorkingSetEntry;154155export type IWorkingSet = readonly IWorkingSetEntry[];156157export function isTextDocumentWorkingSetEntry(entry: IWorkingSetEntry): entry is ITextDocumentWorkingSetEntry {158return (entry.document instanceof TextDocumentSnapshot);159}160161export function isNotebookWorkingSetEntry(entry: IWorkingSetEntry): entry is INotebookWorkingSetEntry {162return (entry.document instanceof NotebookDocumentSnapshot);163}164165166