@@ -10,26 +10,22 @@ import {
1010 LanguageModelToolInvocationPrepareOptions ,
1111 LanguageModelToolResult ,
1212 PreparedToolInvocation ,
13- workspace ,
13+ Uri ,
1414} from 'vscode' ;
1515import { PythonExtension } from '../api/types' ;
1616import { IServiceContainer } from '../ioc/types' ;
1717import { ICodeExecutionService } from '../terminals/types' ;
1818import { TerminalCodeExecutionProvider } from '../terminals/codeExecution/terminalCodeExecution' ;
1919import { IProcessServiceFactory , IPythonExecutionFactory } from '../common/process/types' ;
20- import {
21- getEnvironmentDetails ,
22- getToolResponseIfNotebook ,
23- getUntrustedWorkspaceResponse ,
24- IResourceReference ,
25- raceCancellationError ,
26- } from './utils' ;
27- import { resolveFilePath } from './utils' ;
20+ import { getEnvironmentDetails , getToolResponseIfNotebook , IResourceReference , raceCancellationError } from './utils' ;
2821import { getPythonPackagesResponse } from './listPackagesTool' ;
2922import { ITerminalHelper } from '../common/terminal/types' ;
3023import { getEnvExtApi , useEnvExtension } from '../envExt/api.internal' ;
24+ import { ErrorWithTelemetrySafeReason } from '../common/errors/errorUtils' ;
25+ import { BaseTool } from './baseTool' ;
3126
32- export class GetEnvironmentInfoTool implements LanguageModelTool < IResourceReference > {
27+ export class GetEnvironmentInfoTool extends BaseTool < IResourceReference >
28+ implements LanguageModelTool < IResourceReference > {
3329 private readonly terminalExecutionService : TerminalCodeExecutionProvider ;
3430 private readonly pythonExecFactory : IPythonExecutionFactory ;
3531 private readonly processServiceFactory : IProcessServiceFactory ;
@@ -39,6 +35,7 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
3935 private readonly api : PythonExtension [ 'environments' ] ,
4036 private readonly serviceContainer : IServiceContainer ,
4137 ) {
38+ super ( GetEnvironmentInfoTool . toolName ) ;
4239 this . terminalExecutionService = this . serviceContainer . get < TerminalCodeExecutionProvider > (
4340 ICodeExecutionService ,
4441 'standard' ,
@@ -48,15 +45,11 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
4845 this . terminalHelper = this . serviceContainer . get < ITerminalHelper > ( ITerminalHelper ) ;
4946 }
5047
51- async invoke (
52- options : LanguageModelToolInvocationOptions < IResourceReference > ,
48+ async invokeImpl (
49+ _options : LanguageModelToolInvocationOptions < IResourceReference > ,
50+ resourcePath : Uri | undefined ,
5351 token : CancellationToken ,
5452 ) : Promise < LanguageModelToolResult > {
55- if ( ! workspace . isTrusted ) {
56- return getUntrustedWorkspaceResponse ( ) ;
57- }
58-
59- const resourcePath = resolveFilePath ( options . input . resourcePath ) ;
6053 const notebookResponse = getToolResponseIfNotebook ( resourcePath ) ;
6154 if ( notebookResponse ) {
6255 return notebookResponse ;
@@ -66,7 +59,10 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
6659 const envPath = this . api . getActiveEnvironmentPath ( resourcePath ) ;
6760 const environment = await raceCancellationError ( this . api . resolveEnvironment ( envPath ) , token ) ;
6861 if ( ! environment || ! environment . version ) {
69- throw new Error ( 'No environment found for the provided resource path: ' + resourcePath ?. fsPath ) ;
62+ throw new ErrorWithTelemetrySafeReason (
63+ 'No environment found for the provided resource path: ' + resourcePath ?. fsPath ,
64+ 'noEnvFound' ,
65+ ) ;
7066 }
7167
7268 let packages = '' ;
@@ -107,11 +103,11 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
107103 return new LanguageModelToolResult ( [ new LanguageModelTextPart ( message ) ] ) ;
108104 }
109105
110- async prepareInvocation ?(
111- options : LanguageModelToolInvocationPrepareOptions < IResourceReference > ,
106+ async prepareInvocationImpl (
107+ _options : LanguageModelToolInvocationPrepareOptions < IResourceReference > ,
108+ resourcePath : Uri | undefined ,
112109 _token : CancellationToken ,
113110 ) : Promise < PreparedToolInvocation > {
114- const resourcePath = resolveFilePath ( options . input . resourcePath ) ;
115111 if ( getToolResponseIfNotebook ( resourcePath ) ) {
116112 return { } ;
117113 }
0 commit comments