Skip to content

Commit 35d5997

Browse files
authored
Updates to display rich and localized tool messages (#407)
1 parent a93d2bc commit 35d5997

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-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: 40 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
}
@@ -242,13 +242,46 @@ export class InstallPackageTool implements LanguageModelTool<IInstallPackageInpu
242242
options: LanguageModelToolInvocationPrepareOptions<IInstallPackageInput>,
243243
_token: CancellationToken,
244244
): 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(', ')}...`;
245+
const workspacePath = options.input.resourcePath ? Uri.file(options.input.resourcePath) : undefined;
246+
247+
const packageCount = options.input.packageList.length;
248+
let envName = '';
249+
try {
250+
const environment = await this.api.getEnvironment(workspacePath);
251+
envName = environment?.displayName || '';
252+
} catch {
253+
//
254+
}
255+
256+
let title = '';
257+
let invocationMessage = '';
258+
const message =
259+
packageCount === 1
260+
? ''
261+
: l10n.t(`The following packages will be installed: {0}`, options.input.packageList.sort().join(', '));
262+
if (envName) {
263+
title =
264+
packageCount === 1
265+
? l10n.t(`Install {0} in {1}?`, options.input.packageList[0], envName)
266+
: l10n.t(`Install packages in {0}?`, envName);
267+
invocationMessage =
268+
packageCount === 1
269+
? l10n.t(`Installing {0} in {1}`, options.input.packageList[0], envName)
270+
: l10n.t(`Installing packages {0} in {1}`, options.input.packageList.sort().join(', '), envName);
271+
} else {
272+
title =
273+
options.input.packageList.length === 1
274+
? l10n.t(`Install Python package '{0}'?`, options.input.packageList[0])
275+
: l10n.t(`Install Python packages?`);
276+
invocationMessage =
277+
packageCount === 1
278+
? l10n.t(`Installing Python package '{0}'`, options.input.packageList[0])
279+
: l10n.t(`Installing Python packages: {0}`, options.input.packageList.sort().join(', '));
280+
}
249281

250282
return {
251-
invocationMessage: message,
283+
confirmationMessages: { title, message },
284+
invocationMessage,
252285
};
253286
}
254287
}

0 commit comments

Comments
 (0)