|
1 | 1 | import { |
2 | 2 | CancellationToken, |
| 3 | + l10n, |
3 | 4 | LanguageModelTextPart, |
4 | 5 | LanguageModelTool, |
5 | 6 | LanguageModelToolInvocationOptions, |
@@ -130,21 +131,16 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere |
130 | 131 | _options: LanguageModelToolInvocationPrepareOptions<IResourceReference>, |
131 | 132 | _token: CancellationToken, |
132 | 133 | ): Promise<PreparedToolInvocation> { |
133 | | - const message = 'Preparing to fetch Python environment information...'; |
134 | 134 | return { |
135 | | - invocationMessage: message, |
| 135 | + invocationMessage: l10n.t('Fetching Python environment information'), |
136 | 136 | }; |
137 | 137 | } |
138 | 138 | } |
139 | 139 |
|
140 | 140 | function BuildEnvironmentInfoContent(envInfo: EnvironmentInfo): LanguageModelTextPart { |
141 | 141 | // Create a formatted string that looks like JSON but preserves comments |
142 | | - let envTypeDescriptor: string = `This environment is managed by ${envInfo.type} environment manager. Use the install tool to install packages into this environment.`; |
| 142 | + const envTypeDescriptor: string = `This environment is managed by ${envInfo.type} environment manager. Use the install tool to install packages into this environment.`; |
143 | 143 |
|
144 | | - if (envInfo.type === 'system') { |
145 | | - envTypeDescriptor = |
146 | | - '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.'; |
147 | | - } |
148 | 144 | const content = `{ |
149 | 145 | // ${JSON.stringify(envTypeDescriptor)} |
150 | 146 | "environmentType": ${JSON.stringify(envInfo.type)}, |
@@ -242,13 +238,46 @@ export class InstallPackageTool implements LanguageModelTool<IInstallPackageInpu |
242 | 238 | options: LanguageModelToolInvocationPrepareOptions<IInstallPackageInput>, |
243 | 239 | _token: CancellationToken, |
244 | 240 | ): 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(', ')}...`; |
| 241 | + const workspacePath = options.input.resourcePath ? Uri.file(options.input.resourcePath) : undefined; |
| 242 | + |
| 243 | + const packageCount = options.input.packageList.length; |
| 244 | + let envName = ''; |
| 245 | + try { |
| 246 | + const environment = await this.api.getEnvironment(workspacePath); |
| 247 | + envName = environment?.displayName || ''; |
| 248 | + } catch { |
| 249 | + // |
| 250 | + } |
| 251 | + |
| 252 | + let title = ''; |
| 253 | + let invocationMessage = ''; |
| 254 | + const message = |
| 255 | + packageCount === 1 |
| 256 | + ? '' |
| 257 | + : l10n.t(`The following packages will be installed: {0}`, options.input.packageList.sort().join(', ')); |
| 258 | + if (envName) { |
| 259 | + title = |
| 260 | + packageCount === 1 |
| 261 | + ? l10n.t(`Install {0} in {1}?`, options.input.packageList[0], envName) |
| 262 | + : l10n.t(`Install packages in {0}?`, envName); |
| 263 | + invocationMessage = |
| 264 | + packageCount === 1 |
| 265 | + ? l10n.t(`Installing {0} in {1}`, options.input.packageList[0], envName) |
| 266 | + : l10n.t(`Installing packages {0} in {1}`, options.input.packageList.sort().join(', '), envName); |
| 267 | + } else { |
| 268 | + title = |
| 269 | + options.input.packageList.length === 1 |
| 270 | + ? l10n.t(`Install Python package '{0}'?`, options.input.packageList[0]) |
| 271 | + : l10n.t(`Install Python packages?`); |
| 272 | + invocationMessage = |
| 273 | + packageCount === 1 |
| 274 | + ? l10n.t(`Installing Python package '{0}'`, options.input.packageList[0]) |
| 275 | + : l10n.t(`Installing Python packages: {0}`, options.input.packageList.sort().join(', ')); |
| 276 | + } |
249 | 277 |
|
250 | 278 | return { |
251 | | - invocationMessage: message, |
| 279 | + confirmationMessages: { title, message }, |
| 280 | + invocationMessage, |
252 | 281 | }; |
253 | 282 | } |
254 | 283 | } |
0 commit comments