Skip to content

Commit cc539b7

Browse files
committed
Updates to display rich and localized tool messages
1 parent 6170c64 commit cc539b7

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@
514514
"displayName": "Get Python Environment Information",
515515
"modelDescription": "Provides details about the Python environment for a specified file or workspace, including environment type, Python version, run command, and installed packages with their versions. Use this tool to determine the correct command for executing Python code in this workspace.",
516516
"toolReferenceName": "pythonGetEnvironmentInfo",
517-
"tags": [],
517+
"tags": [
518+
"ms-python.python"
519+
],
518520
"icon": "$(files)",
519521
"canBeReferencedInPrompt": true,
520522
"inputSchema": {
@@ -533,9 +535,12 @@
533535
{
534536
"name": "python_install_package",
535537
"displayName": "Install Python Package",
538+
"userDescription": "Installs Python packages in the given workspace",
536539
"modelDescription": "Installs Python packages in the given workspace. Use this tool to install packages in the user's chosen environment.",
537540
"toolReferenceName": "pythonInstallPackage",
538-
"tags": [],
541+
"tags": [
542+
"ms-python.python"
543+
],
539544
"icon": "$(package)",
540545
"canBeReferencedInPrompt": true,
541546
"inputSchema": {
@@ -607,4 +612,4 @@
607612
"vscode-jsonrpc": "^9.0.0-next.5",
608613
"which": "^4.0.0"
609614
}
610-
}
615+
}

src/features/copilotTools.ts

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
CancellationToken,
3+
l10n,
34
LanguageModelTextPart,
45
LanguageModelTool,
56
LanguageModelToolInvocationOptions,
@@ -130,9 +131,8 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
130131
_options: LanguageModelToolInvocationPrepareOptions<IResourceReference>,
131132
_token: CancellationToken,
132133
): Promise<PreparedToolInvocation> {
133-
const message = 'Preparing to fetch Python environment information...';
134134
return {
135-
invocationMessage: message,
135+
invocationMessage: l10n.t('Fetching Python environment information'),
136136
};
137137
}
138138
}
@@ -141,6 +141,7 @@ function BuildEnvironmentInfoContent(envInfo: EnvironmentInfo): LanguageModelTex
141141
// Create a formatted string that looks like JSON but preserves comments
142142
let envTypeDescriptor: string = `This environment is managed by ${envInfo.type} environment manager. Use the install tool to install packages into this environment.`;
143143

144+
// TODO: If this is setup as python.defaultInterpreterPath, then do not include this message.
144145
if (envInfo.type === 'system') {
145146
envTypeDescriptor =
146147
'System pythons are pythons that ship with the OS or are installed globally. These python installs may be used by the OS for running services and core functionality. Confirm with the user before installing packages into this environment, as it can lead to issues with any services on the OS.';
@@ -242,13 +243,46 @@ export class InstallPackageTool implements LanguageModelTool<IInstallPackageInpu
242243
options: LanguageModelToolInvocationPrepareOptions<IInstallPackageInput>,
243244
_token: CancellationToken,
244245
): Promise<PreparedToolInvocation> {
245-
const packageList = options.input.packageList || [];
246-
const packageCount = packageList.length;
247-
const packageText = packageCount === 1 ? 'package' : 'packages';
248-
const message = `Preparing to install Python ${packageText}: ${packageList.join(', ')}...`;
246+
const workspacePath = options.input.resourcePath ? Uri.file(options.input.resourcePath) : undefined;
247+
248+
const packageCount = options.input.packageList.length;
249+
let envName = '';
250+
try {
251+
const environment = await this.api.getEnvironment(workspacePath);
252+
envName = environment?.displayName || '';
253+
} catch {
254+
//
255+
}
256+
257+
let title = '';
258+
let invocationMessage = '';
259+
const message =
260+
packageCount === 1
261+
? ''
262+
: l10n.t(`The following packages will be installed: {0}`, options.input.packageList.sort().join(', '));
263+
if (envName) {
264+
title =
265+
packageCount === 1
266+
? l10n.t(`Install {0} in {1}?`, options.input.packageList[0], envName)
267+
: l10n.t(`Install packages in {0}?`, envName);
268+
invocationMessage =
269+
packageCount === 1
270+
? l10n.t(`Installing {0} in {1}`, options.input.packageList[0], envName)
271+
: l10n.t(`Installing packages {0} in {1}`, options.input.packageList.sort().join(', '), envName);
272+
} else {
273+
title =
274+
options.input.packageList.length === 1
275+
? l10n.t(`Install Python package '{0}'?`, options.input.packageList[0])
276+
: l10n.t(`Install Python packages?`);
277+
invocationMessage =
278+
packageCount === 1
279+
? l10n.t(`Installing Python package '{0}'`, options.input.packageList[0])
280+
: l10n.t(`Installing Python packages: {0}`, options.input.packageList.sort().join(', '));
281+
}
249282

250283
return {
251-
invocationMessage: message,
284+
confirmationMessages: { title, message },
285+
invocationMessage,
252286
};
253287
}
254288
}

0 commit comments

Comments
 (0)