@@ -10,7 +10,7 @@ import {
1010 LanguageModelToolInvocationPrepareOptions ,
1111 LanguageModelToolResult ,
1212 PreparedToolInvocation ,
13- workspace ,
13+ Uri ,
1414} from 'vscode' ;
1515import { PythonExtension } from '../api/types' ;
1616import { IServiceContainer } from '../ioc/types' ;
@@ -20,16 +20,17 @@ import { IProcessServiceFactory, IPythonExecutionFactory } from '../common/proce
2020import {
2121 getEnvironmentDetails ,
2222 getToolResponseIfNotebook ,
23- getUntrustedWorkspaceResponse ,
2423 IResourceReference ,
2524 raceCancellationError ,
2625} from './utils' ;
27- import { resolveFilePath } from './utils' ;
2826import { getPythonPackagesResponse } from './listPackagesTool' ;
2927import { ITerminalHelper } from '../common/terminal/types' ;
3028import { getEnvExtApi , useEnvExtension } from '../envExt/api.internal' ;
29+ import { ErrorWithTelemetrySafeReason } from '../common/errors/errorUtils' ;
30+ import { BaseTool } from './baseTool' ;
3131
32- export class GetEnvironmentInfoTool implements LanguageModelTool < IResourceReference > {
32+ export class GetEnvironmentInfoTool extends BaseTool < IResourceReference >
33+ implements LanguageModelTool < IResourceReference > {
3334 private readonly terminalExecutionService : TerminalCodeExecutionProvider ;
3435 private readonly pythonExecFactory : IPythonExecutionFactory ;
3536 private readonly processServiceFactory : IProcessServiceFactory ;
@@ -39,6 +40,7 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
3940 private readonly api : PythonExtension [ 'environments' ] ,
4041 private readonly serviceContainer : IServiceContainer ,
4142 ) {
43+ super ( GetEnvironmentInfoTool . toolName ) ;
4244 this . terminalExecutionService = this . serviceContainer . get < TerminalCodeExecutionProvider > (
4345 ICodeExecutionService ,
4446 'standard' ,
@@ -48,15 +50,11 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
4850 this . terminalHelper = this . serviceContainer . get < ITerminalHelper > ( ITerminalHelper ) ;
4951 }
5052
51- async invoke (
52- options : LanguageModelToolInvocationOptions < IResourceReference > ,
53+ async invokeImpl (
54+ _options : LanguageModelToolInvocationOptions < IResourceReference > ,
55+ resourcePath : Uri | undefined ,
5356 token : CancellationToken ,
5457 ) : Promise < LanguageModelToolResult > {
55- if ( ! workspace . isTrusted ) {
56- return getUntrustedWorkspaceResponse ( ) ;
57- }
58-
59- const resourcePath = resolveFilePath ( options . input . resourcePath ) ;
6058 const notebookResponse = getToolResponseIfNotebook ( resourcePath ) ;
6159 if ( notebookResponse ) {
6260 return notebookResponse ;
@@ -66,7 +64,10 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
6664 const envPath = this . api . getActiveEnvironmentPath ( resourcePath ) ;
6765 const environment = await raceCancellationError ( this . api . resolveEnvironment ( envPath ) , token ) ;
6866 if ( ! environment || ! environment . version ) {
69- throw new Error ( 'No environment found for the provided resource path: ' + resourcePath ?. fsPath ) ;
67+ throw new ErrorWithTelemetrySafeReason (
68+ 'No environment found for the provided resource path: ' + resourcePath ?. fsPath ,
69+ 'noEnvFound' ,
70+ ) ;
7071 }
7172
7273 let packages = '' ;
@@ -107,11 +108,11 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
107108 return new LanguageModelToolResult ( [ new LanguageModelTextPart ( message ) ] ) ;
108109 }
109110
110- async prepareInvocation ?(
111- options : LanguageModelToolInvocationPrepareOptions < IResourceReference > ,
111+ async prepareInvocationImpl (
112+ _options : LanguageModelToolInvocationPrepareOptions < IResourceReference > ,
113+ resourcePath : Uri | undefined ,
112114 _token : CancellationToken ,
113115 ) : Promise < PreparedToolInvocation > {
114- const resourcePath = resolveFilePath ( options . input . resourcePath ) ;
115116 if ( getToolResponseIfNotebook ( resourcePath ) ) {
116117 return { } ;
117118 }
0 commit comments