(options: LanguageModelToolInvocationOptions<T>, token: CancellationToken)
| 49 | constructor(private readonly toolName: string) {} |
| 50 | |
| 51 | public async invoke(options: LanguageModelToolInvocationOptions<T>, token: CancellationToken) { |
| 52 | if (!workspace.isTrusted) { |
| 53 | return new LanguageModelToolResult([ |
| 54 | new LanguageModelTextPart('Cannot use this tool in an untrusted workspace.') |
| 55 | ]); |
| 56 | } |
| 57 | |
| 58 | let error: Error | undefined; |
| 59 | let notebookUri: Uri | undefined; |
| 60 | try { |
| 61 | const notebook = await resolveNotebookFromFilePath(options.input.filePath); |
| 62 | return await this.invokeImpl(options, notebook, token); |
| 63 | } catch (ex) { |
| 64 | error = ex; |
| 65 | throw ex; |
| 66 | } finally { |
| 67 | const isCancelled = token.isCancellationRequested || (error ? isCancellationError(error, true) : false); |
| 68 | const failed = !!error || isCancelled ? 'true' : 'false'; |
| 69 | const failureCategory = isCancelled |
| 70 | ? 'cancelled' |
| 71 | : error |
| 72 | ? error instanceof BaseError |
| 73 | ? error.category |
| 74 | : 'error' |
| 75 | : undefined; |
| 76 | const resourceHash = notebookUri |
| 77 | ? // eslint-disable-next-line local-rules/dont-use-fspath |
| 78 | getTelemetrySafeHashedString(notebookUri.fsPath) |
| 79 | : Promise.resolve(undefined); |
| 80 | void resourceHash.then((resourceHash) => { |
| 81 | sendTelemetryEvent(Telemetry.InvokeTool, undefined, { |
| 82 | toolName: this.toolName, |
| 83 | resourceHash, |
| 84 | failed, |
| 85 | failureCategory |
| 86 | }); |
| 87 | }); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | async prepareInvocation( |
| 92 | options: LanguageModelToolInvocationPrepareOptions<T>, |
nothing calls this directly
no test coverage detected