55
66import * as dom from '../../../../../../base/browser/dom.js' ;
77import { decodeBase64 } from '../../../../../../base/common/buffer.js' ;
8- import { CancellationToken } from '../../../../../../base/common/cancellation.js' ;
8+ import { CancellationTokenSource } from '../../../../../../base/common/cancellation.js' ;
99import { Codicon } from '../../../../../../base/common/codicons.js' ;
1010import { ThemeIcon } from '../../../../../../base/common/themables.js' ;
1111import { localize } from '../../../../../../nls.js' ;
@@ -18,11 +18,14 @@ import { IChatContentPartRenderContext } from '../chatContentParts.js';
1818import { ChatCustomProgressPart } from '../chatProgressContentPart.js' ;
1919import { BaseChatToolInvocationSubPart } from './chatToolInvocationSubPart.js' ;
2020
21+ // TODO: see if we can reuse existing types instead of adding ChatToolOutputSubPart
2122export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
2223 public readonly domNode : HTMLElement ;
2324
2425 public override readonly codeblocks : IChatCodeBlockInfo [ ] = [ ] ;
2526
27+ private readonly _disposeCts = this . _register ( new CancellationTokenSource ( ) ) ;
28+
2629 constructor (
2730 toolInvocation : IChatToolInvocation | IChatToolInvocationSerialized ,
2831 _context : IChatContentPartRenderContext ,
@@ -44,6 +47,11 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
4447 this . domNode = this . createOutputPart ( details ) ;
4548 }
4649
50+ public override dispose ( ) : void {
51+ this . _disposeCts . dispose ( true ) ;
52+ super . dispose ( ) ;
53+ }
54+
4755 private createOutputPart ( details : IToolResultOutputDetails ) : HTMLElement {
4856 const parent = dom . $ ( 'div.webview-output' ) ;
4957 parent . style . maxHeight = '80vh' ;
@@ -53,7 +61,12 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
5361 const progressPart = this . instantiationService . createInstance ( ChatCustomProgressPart , progressMessage , ThemeIcon . modify ( Codicon . loading , 'spin' ) ) ;
5462 parent . appendChild ( progressPart . domNode ) ;
5563
56- this . chatOutputItemRendererService . renderOutputPart ( details . output . mimeType , details . output . value . buffer , parent , CancellationToken . None ) . then ( ( renderedItem ) => {
64+ // TODO: we also need to show the tool output in the UI
65+ this . chatOutputItemRendererService . renderOutputPart ( details . output . mimeType , details . output . value . buffer , parent , this . _disposeCts . token ) . then ( ( renderedItem ) => {
66+ if ( this . _disposeCts . token . isCancellationRequested ) {
67+ return ;
68+ }
69+
5770 this . _register ( renderedItem ) ;
5871
5972 progressPart . domNode . remove ( ) ;
@@ -62,6 +75,9 @@ export class ChatToolOutputSubPart extends BaseChatToolInvocationSubPart {
6275 this . _register ( renderedItem . onDidChangeHeight ( ( ) => {
6376 this . _onDidChangeHeight . fire ( ) ;
6477 } ) ) ;
78+ } , ( error ) => {
79+ // TODO: show error in UI too
80+ console . error ( 'Error rendering tool output:' , error ) ;
6581 } ) ;
6682
6783 return parent ;
0 commit comments