1
>
/*---------------------------------------------------------------------------------------------
confirmationTool.ts
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 { CancellationToken } from '../../../../../../base/common/cancellation.js';
7
>
import { MarkdownString } from '../../../../../../base/common/htmlContent.js';
8
>
import { URI } from '../../../../../../base/common/uri.js';
9
>
import { ConfirmationOptionKind } from '../../../../../../platform/agentHost/common/state/protocol/state.js';
10
>
import { IChatModifiedFilesConfirmationData, IChatTerminalToolInvocationData } from '../../chatService/chatService.js';
11
>
import { CountTokensCallback, IPreparedToolInvocation, IToolData, IToolImpl, IToolInvocation, IToolInvocationPreparationContext, IToolResult, ToolDataSource, ToolInvocationPresentation, ToolProgress } from '../languageModelToolsService.js';
12
>
13
>
export const ConfirmationToolId = 'vscode_get_confirmation';
14
>
export const ConfirmationToolWithOptionsId = 'vscode_get_confirmation_with_options';
15
>
export const ModifiedFilesConfirmationToolId = 'vscode_get_modified_files_confirmation';
16
>
17
>
export const ConfirmationToolData: IToolData = {
18
>
id: ConfirmationToolId,
19
>
displayName: 'Confirmation Tool',
20
>
modelDescription: 'A tool that demonstrates different types of confirmations. Takes a title, message, and confirmation type (basic or terminal).',
21
>
source: ToolDataSource.Internal,
22
>
inputSchema: {
23
>
type: 'object',
24
>
properties: {
25
>
title: {
26
>
type: 'string',
27
>
description: 'Title for the confirmation dialog'
28
>
},
29
>
message: {
30
>
type: 'string',
31
>
description: 'Message to show in the confirmation dialog'
32
>
},
33
>
confirmationType: {
34
>
type: 'string',
35
>
enum: ['basic', 'terminal'],
36
>
description: 'Type of confirmation to show - basic for simple confirmation, terminal for terminal command confirmation'
37
>
},
38
>
terminalCommand: {
39
>
type: 'string',
40
>
description: 'Terminal command to show (only used when confirmationType is "terminal")'
41
>
}
42
>
},
43
>
required: ['title', 'message', 'confirmationType'],
44
>
additionalProperties: false
45
>
}
46
>
};
47
>
48
>
export const ConfirmationToolWithOptionsData: IToolData = {
49
>
id: ConfirmationToolWithOptionsId,
50
>
displayName: 'Confirmation Tool with Options',
51
>
modelDescription: 'A tool that demonstrates different types of confirmations. Takes a title, message, and buttons.',
52
>
source: ToolDataSource.Internal,
53
>
inputSchema: {
54
>
type: 'object',
55
>
properties: {
56
>
title: {
57
>
type: 'string',
58
>
description: 'Title for the confirmation dialog'
59
>
},
60
>
message: {
61
>
type: 'string',
62
>
description: 'Message to show in the confirmation dialog'
63
>
},
64
>
buttons: {
65
>
type: 'array',
66
>
items: { type: 'string' },
67
>
description: 'Custom button labels to display.'
68
>
}
69
>
},
70
>
required: ['title', 'message', 'buttons'],
71
>
additionalProperties: false
72
>
}
73
>
};
74
>
75
>
export const ModifiedFilesConfirmationToolData: IToolData = {
76
>
id: ModifiedFilesConfirmationToolId,
77
>
displayName: 'Modified Files Confirmation Tool',
78
>
modelDescription: 'A tool that shows a modified-files confirmation UI with a split primary button and a hardcoded cancel action.',
79
>
source: ToolDataSource.Internal,
80
>
inputSchema: {
81
>
type: 'object',
82
>
properties: {
83
>
title: {
84
>
type: 'string',
85
>
description: 'Title for the confirmation dialog'
86
>
},
87
>
message: {
88
>
type: 'string',
89
>
description: 'Message to show in the confirmation dialog'
90
>
},
91
>
options: {
92
>
type: 'array',
93
>
items: { type: 'string' },
94
>
minItems: 1,
95
>
description: 'Selectable option labels. The first option is used for the primary split button and the remaining options are placed in the dropdown menu.'
96
>
},
97
>
modifiedFiles: {
98
>
type: 'array',
99
>
items: {
100
>
type: 'object',
101
>
properties: {
102
>
uri: {
103
>
type: 'string',
104
>
description: 'URI of the modified file.'
105
>
},
106
>
originalUri: {
107
>
type: 'string',
108
>
description: 'Optional original URI used when opening a diff.'
109
>
},
110
>
insertions: {
111
>
type: 'number',
112
>
description: 'Optional number of lines added.'
113
>
},
114
>
deletions: {
115
>
type: 'number',
116
>
description: 'Optional number of lines removed.'
117
>
},
118
>
title: {
119
>
type: 'string',
120
>
description: 'Optional title shown in the file tooltip.'
121
>
},
122
>
description: {
123
>
type: 'string',
124
>
description: 'Optional secondary label shown for the file entry.'
125
>
}
126
>
},
127
>
required: ['uri'],
128
>
additionalProperties: false
129
>
},
130
>
description: 'Modified files to show in the confirmation UI.'
131
>
}
132
>
},
133
>
required: ['title', 'message', 'options', 'modifiedFiles'],
134
>
additionalProperties: false
135
>
}
136
>
};
137
>
138
>
export interface IConfirmationToolParams {
139
>
title: string;
140
>
message: string;
141
>
confirmationType?: 'basic' | 'terminal';
142
>
terminalCommand?: string;
143
>
buttons?: string[];
144
>
}
145
>
146
>
export interface IModifiedFilesConfirmationToolParams {
147
>
title: string;
148
>
message: string;
149
>
options: string[];
150
>
modifiedFiles: {
151
>
uri: string;
152
>
originalUri?: string;
153
>
insertions?: number;
154
>
deletions?: number;
155
>
title?: string;
156
>
description?: string;
157
>
}[];
158
>
}
159
>
160
>
export class ConfirmationTool implements IToolImpl {
161
>
async prepareToolInvocation(context: IToolInvocationPreparationContext, token: CancellationToken): Promise<IPreparedToolInvocation | undefined> {
162
const parameters = context.parameters as IConfirmationToolParams;
163
if (!parameters.title || !parameters.message) {